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
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
ConstructorDescriptionStandard constructor which tries to load all required extensions via Eclipse. -
Method Summary
Modifier and TypeMethodDescriptionReturns the result of interpreting the object as an instance of 'Boolean Operator Expression'.Infers the type of an bool literal to BOOL.Result of a compare expression is always of type BOOL_PMF.Infers the type of an double literal to DOUBLE.caseFunctionLiteral
(FunctionLiteral object) Returns the result of interpreting the object as an instance of 'Function Literal'.caseIfElseExpression
(IfElseExpression object) Returns the result of interpreting the object as an instance of 'If Else Expression'.Infers the type of an int literal to INT.Returns the result of interpreting the object as an instance of 'Negative Expression'.caseNotExpression
(NotExpression object) Returns the result of interpreting the object as an instance of 'Not Expression'.caseParenthesis
(Parenthesis parenthesis) Infers the type of an parenthesis to its inner encapsulated expression.Result of a power expression so far only be of type DOUBLE, as the power operation is only allowed on NUMBERs, not PMFs.Infers the type of a probability function literal.Result of a product expression can be of type INT, DOUBLE, INT_PMF, DOUBLE_PMF, ANY_PMF, DOUBLE_PDF depending on the operands.caseStringLiteral
(StringLiteral object) Returns the result of interpreting the object as an instance of 'String Literal'.Result of a term expression can be of type INT, DOUBLE, INT_PMF, DOUBLE_PMF, ANY_PMF, DOUBLE_PDF depending on the operands.caseVariable
(Variable var) Infers the type of a variable depending on its characterisation type.protected Optional<ITypeInference>
Finds anITypeInference
service.Return the inferred type of the passed expression node.Getter for the type annotation hashmap.protected boolean
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
-
Constructor Details
-
ExpressionInferTypeVisitor
public ExpressionInferTypeVisitor()Standard constructor which tries to load all required extensions via Eclipse.
-
-
Method Details
-
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
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:
-
caseProductExpression
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:
-
casePowerExpression
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:
-
caseNegativeExpression
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:
-
caseBooleanOperatorExpression
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:
-
caseNotExpression
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:
-
caseTermExpression
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:
-
caseProbabilityFunctionLiteral
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:
-
caseIntLiteral
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:
-
caseDoubleLiteral
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:
-
caseVariable
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:
-
caseBoolLiteral
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:
-
caseParenthesis
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:
-
isNumeric
-
getTypeAnnotation
Getter for the type annotation hashmap.- Returns:
-
setTypeAnnotation
Setter for the type annotation hashmap.- Parameters:
typeAnnotation
-
-
getType
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
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:
-
caseIfElseExpression
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:
-
caseStringLiteral
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:
-