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().
  • Constructor Details

    • ExpressionInferTypeVisitor

      public ExpressionInferTypeVisitor()
      Standard constructor which tries to load all required extensions via Eclipse.
  • Method Details

    • findTypeInferenceExtension

      protected Optional<ITypeInference> findTypeInferenceExtension()
      Finds an ITypeInference service. The method either tries to find the service via the extension point registry or via a ServiceLoader.
      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 class StoexSwitch<Object>
      Parameters:
      expr - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Compare Expression'.
      See Also:
    • 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 class StoexSwitch<Object>
      Parameters:
      expr - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Product Expression'.
      See Also:
    • 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 class StoexSwitch<Object>
      Parameters:
      expr - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Power Expression'.
      See Also:
    • 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 class StoexSwitch<Object>
      Parameters:
      object - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Negative Expression'.
      See Also:
    • 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 class StoexSwitch<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

      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 class StoexSwitch<Object>
      Parameters:
      object - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Not Expression'.
      See Also:
    • 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 class StoexSwitch<Object>
      Parameters:
      expr - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Term Expression'.
      See Also:
    • caseProbabilityFunctionLiteral

      public Object caseProbabilityFunctionLiteral(ProbabilityFunctionLiteral pfl)
      Infers the type of a probability function literal.
      Overrides:
      caseProbabilityFunctionLiteral in class StoexSwitch<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

      public Object caseIntLiteral(IntLiteral il)
      Infers the type of an int literal to INT.
      Overrides:
      caseIntLiteral in class StoexSwitch<Object>
      Parameters:
      il - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Int Literal'.
      See Also:
    • caseDoubleLiteral

      public Object caseDoubleLiteral(DoubleLiteral dl)
      Infers the type of an double literal to DOUBLE.
      Overrides:
      caseDoubleLiteral in class StoexSwitch<Object>
      Parameters:
      dl - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Double Literal'.
      See Also:
    • 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 the ExpressionSolveVisitor 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 in ExpressionSolveVisitor.extractIPMFFromLiteral(de.uka.ipd.sdq.stoex.Expression) needs to be adjusted, too.
      Overrides:
      caseVariable in class StoexSwitch<Object>
      Parameters:
      var - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Variable'.
      See Also:
    • caseBoolLiteral

      public Object caseBoolLiteral(BoolLiteral bl)
      Infers the type of an bool literal to BOOL.
      Overrides:
      caseBoolLiteral in class StoexSwitch<Object>
      Parameters:
      bl - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Bool Literal'.
      See Also:
    • caseParenthesis

      public Object caseParenthesis(Parenthesis parenthesis)
      Infers the type of an parenthesis to its inner encapsulated expression.
      Overrides:
      caseParenthesis in class StoexSwitch<Object>
      Parameters:
      parenthesis - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Parenthesis'.
      See Also:
    • 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 class StoexSwitch<Object>
      Parameters:
      object - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'Function Literal'.
      See Also:
    • 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 class StoexSwitch<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

      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 class StoexSwitch<Object>
      Parameters:
      object - the target of the switch.
      Returns:
      the result of interpreting the object as an instance of 'String Literal'.
      See Also: