Class ExpressionInferTypeVisitor
- java.lang.Object
-
- org.eclipse.emf.ecore.util.Switch<T>
-
- de.uka.ipd.sdq.stoex.util.StoexSwitch<Object>
-
- de.uka.ipd.sdq.stoex.analyser.visitors.ExpressionInferTypeVisitor
-
- Direct Known Subclasses:
NonProbabilisticExpressionInferTypeVisitor
public class ExpressionInferTypeVisitor extends StoexSwitch<Object>
A visitor for stochastic expression, which infers the types before evaluating these expressions. For example, it infers the result type of an operation add on a INT and a INT_PMF to a INT_PMF, as the add operation with a constant shifts the INT_PMF. It stores the inferred types for each expression in a hashmap, which can be retrieved via getTypeAnnotation().
-
-
Field Summary
-
Fields inherited from class de.uka.ipd.sdq.stoex.util.StoexSwitch
copyright, modelPackage
-
-
Constructor Summary
Constructors Constructor Description ExpressionInferTypeVisitor()
Standard constructor which tries to load all required extensions via Eclipse.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
caseBooleanOperatorExpression(BooleanOperatorExpression object)
Returns the result of interpreting the object as an instance of 'Boolean Operator Expression'.Object
caseBoolLiteral(BoolLiteral bl)
Infers the type of an bool literal to BOOL.Object
caseCompareExpression(CompareExpression expr)
Result of a compare expression is always of type BOOL_PMF.Object
caseDoubleLiteral(DoubleLiteral dl)
Infers the type of an double literal to DOUBLE.Object
caseFunctionLiteral(FunctionLiteral object)
Returns the result of interpreting the object as an instance of 'Function Literal'.Object
caseIfElseExpression(IfElseExpression object)
Returns the result of interpreting the object as an instance of 'If Else Expression'.Object
caseIntLiteral(IntLiteral il)
Infers the type of an int literal to INT.Object
caseNegativeExpression(NegativeExpression object)
Returns the result of interpreting the object as an instance of 'Negative Expression'.Object
caseNotExpression(NotExpression object)
Returns the result of interpreting the object as an instance of 'Not Expression'.Object
caseParenthesis(Parenthesis parenthesis)
Infers the type of an parenthesis to its inner encapsulated expression.Object
casePowerExpression(PowerExpression expr)
Result of a power expression so far only be of type DOUBLE, as the power operation is only allowed on NUMBERs, not PMFs.Object
caseProbabilityFunctionLiteral(ProbabilityFunctionLiteral pfl)
Infers the type of a probability function literal.Object
caseProductExpression(ProductExpression expr)
Result of a product expression can be of type INT, DOUBLE, INT_PMF, DOUBLE_PMF, ANY_PMF, DOUBLE_PDF depending on the operands.Object
caseStringLiteral(StringLiteral object)
Returns the result of interpreting the object as an instance of 'String Literal'.Object
caseTermExpression(TermExpression expr)
Result of a term expression can be of type INT, DOUBLE, INT_PMF, DOUBLE_PMF, ANY_PMF, DOUBLE_PDF depending on the operands.Object
caseVariable(Variable var)
Infers the type of a variable depending on its characterisation type.protected Optional<ITypeInference>
findTypeInferenceExtension()
Finds anITypeInference
service.TypeEnum
getType(Expression e)
Return the inferred type of the passed expression node.HashMap<Expression,TypeEnum>
getTypeAnnotation()
Getter for the type annotation hashmap.protected boolean
isNumeric(TypeEnum type)
void
setTypeAnnotation(HashMap<Expression,TypeEnum> typeAnnotation)
Setter for the type annotation hashmap.-
Methods inherited from class de.uka.ipd.sdq.stoex.util.StoexSwitch
caseAbstractNamedReference, caseAtom, caseBooleanExpression, caseComparison, caseExpression, caseIfElse, caseNamespaceReference, caseNumericLiteral, casePower, caseProduct, caseRandomVariable, caseTerm, caseUnary, caseUnitCarryingElement, caseVariableReference, defaultCase, doSwitch, isSwitchFor
-
-
-
-
Method Detail
-
findTypeInferenceExtension
protected Optional<ITypeInference> findTypeInferenceExtension()
Finds anITypeInference
service. The method either tries to find the service via the extension point registry or via aServiceLoader
.- Returns:
- The service instance or an empty result.
-
caseCompareExpression
public Object caseCompareExpression(CompareExpression expr)
Result of a compare expression is always of type BOOL_PMF.- Overrides:
caseCompareExpression
in classStoexSwitch<Object>
- Parameters:
expr
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Compare Expression'.
- See Also:
doSwitch(EObject)
-
caseProductExpression
public Object caseProductExpression(ProductExpression expr)
Result of a product expression can be of type INT, DOUBLE, INT_PMF, DOUBLE_PMF, ANY_PMF, DOUBLE_PDF depending on the operands.- Overrides:
caseProductExpression
in classStoexSwitch<Object>
- Parameters:
expr
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Product Expression'.
- See Also:
doSwitch(EObject)
-
casePowerExpression
public Object casePowerExpression(PowerExpression expr)
Result of a power expression so far only be of type DOUBLE, as the power operation is only allowed on NUMBERs, not PMFs.- Overrides:
casePowerExpression
in classStoexSwitch<Object>
- Parameters:
expr
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Power Expression'.
- See Also:
doSwitch(EObject)
-
caseNegativeExpression
public Object caseNegativeExpression(NegativeExpression object)
Description copied from class:StoexSwitch
Returns the result of interpreting the object as an instance of 'Negative Expression'. This implementation returns null; returning a non-null result will terminate the switch.- Overrides:
caseNegativeExpression
in classStoexSwitch<Object>
- Parameters:
object
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Negative Expression'.
- See Also:
doSwitch(EObject)
-
caseBooleanOperatorExpression
public Object caseBooleanOperatorExpression(BooleanOperatorExpression object)
Description copied from class:StoexSwitch
Returns the result of interpreting the object as an instance of 'Boolean Operator Expression'. This implementation returns null; returning a non-null result will terminate the switch.- Overrides:
caseBooleanOperatorExpression
in classStoexSwitch<Object>
- Parameters:
object
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Boolean Operator Expression'.
- See Also:
doSwitch(EObject)
-
caseNotExpression
public Object caseNotExpression(NotExpression object)
Description copied from class:StoexSwitch
Returns the result of interpreting the object as an instance of 'Not Expression'. This implementation returns null; returning a non-null result will terminate the switch.- Overrides:
caseNotExpression
in classStoexSwitch<Object>
- Parameters:
object
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Not Expression'.
- See Also:
doSwitch(EObject)
-
caseTermExpression
public Object caseTermExpression(TermExpression expr)
Result of a term expression can be of type INT, DOUBLE, INT_PMF, DOUBLE_PMF, ANY_PMF, DOUBLE_PDF depending on the operands.- Overrides:
caseTermExpression
in classStoexSwitch<Object>
- Parameters:
expr
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Term Expression'.
- See Also:
doSwitch(EObject)
-
caseProbabilityFunctionLiteral
public Object caseProbabilityFunctionLiteral(ProbabilityFunctionLiteral pfl)
Infers the type of a probability function literal.- Overrides:
caseProbabilityFunctionLiteral
in classStoexSwitch<Object>
- Parameters:
pfl
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Probability Function Literal'.
- See Also:
doSwitch(EObject)
-
caseIntLiteral
public Object caseIntLiteral(IntLiteral il)
Infers the type of an int literal to INT.- Overrides:
caseIntLiteral
in classStoexSwitch<Object>
- Parameters:
il
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Int Literal'.
- See Also:
doSwitch(EObject)
-
caseDoubleLiteral
public Object caseDoubleLiteral(DoubleLiteral dl)
Infers the type of an double literal to DOUBLE.- Overrides:
caseDoubleLiteral
in classStoexSwitch<Object>
- Parameters:
dl
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Double Literal'.
- See Also:
doSwitch(EObject)
-
caseVariable
public Object caseVariable(Variable var)
Infers the type of a variable depending on its characterisation type. Infers VALUE, DATATYPE, STRUCUTURE to ANY_PMF, while NUMBER_OF_ELEMENTS and BYTESIZE to INT_PMF. If later in theExpressionSolveVisitor
the result is solved and the supposed INT_PMF turns out to be something else, an exception is thrown. If the behaviour is changed here, the exception handling inExpressionSolveVisitor.extractIPMFFromLiteral(de.uka.ipd.sdq.stoex.Expression)
needs to be adjusted, too.- Overrides:
caseVariable
in classStoexSwitch<Object>
- Parameters:
var
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Variable'.
- See Also:
doSwitch(EObject)
-
caseBoolLiteral
public Object caseBoolLiteral(BoolLiteral bl)
Infers the type of an bool literal to BOOL.- Overrides:
caseBoolLiteral
in classStoexSwitch<Object>
- Parameters:
bl
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Bool Literal'.
- See Also:
doSwitch(EObject)
-
caseParenthesis
public Object caseParenthesis(Parenthesis parenthesis)
Infers the type of an parenthesis to its inner encapsulated expression.- Overrides:
caseParenthesis
in classStoexSwitch<Object>
- Parameters:
parenthesis
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Parenthesis'.
- See Also:
doSwitch(EObject)
-
isNumeric
protected boolean isNumeric(TypeEnum type)
-
getTypeAnnotation
public HashMap<Expression,TypeEnum> getTypeAnnotation()
Getter for the type annotation hashmap.- Returns:
-
setTypeAnnotation
public void setTypeAnnotation(HashMap<Expression,TypeEnum> typeAnnotation)
Setter for the type annotation hashmap.- Parameters:
typeAnnotation
-
-
getType
public TypeEnum getType(Expression e)
Return the inferred type of the passed expression node. The type annotation is automatically stored in the Map if it has not been inferred before.- Parameters:
e
- The node whose type should be returned.- Returns:
- The inferred type of the expression.
-
caseFunctionLiteral
public Object caseFunctionLiteral(FunctionLiteral object)
Description copied from class:StoexSwitch
Returns the result of interpreting the object as an instance of 'Function Literal'. This implementation returns null; returning a non-null result will terminate the switch.- Overrides:
caseFunctionLiteral
in classStoexSwitch<Object>
- Parameters:
object
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'Function Literal'.
- See Also:
doSwitch(EObject)
-
caseIfElseExpression
public Object caseIfElseExpression(IfElseExpression object)
Description copied from class:StoexSwitch
Returns the result of interpreting the object as an instance of 'If Else Expression'. This implementation returns null; returning a non-null result will terminate the switch.- Overrides:
caseIfElseExpression
in classStoexSwitch<Object>
- Parameters:
object
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'If Else Expression'.
- See Also:
doSwitch(EObject)
-
caseStringLiteral
public Object caseStringLiteral(StringLiteral object)
Description copied from class:StoexSwitch
Returns the result of interpreting the object as an instance of 'String Literal'. This implementation returns null; returning a non-null result will terminate the switch.- Overrides:
caseStringLiteral
in classStoexSwitch<Object>
- Parameters:
object
- the target of the switch.- Returns:
- the result of interpreting the object as an instance of 'String Literal'.
- See Also:
doSwitch(EObject)
-
-