Class 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 Detail

      • ExpressionInferTypeVisitor

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

      • 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.
      • 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:
        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 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:
        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 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:
        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 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:
        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 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:
        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 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:
        doSwitch(EObject)
      • 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:
        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 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:
        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 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:
        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 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:
        doSwitch(EObject)