Class InferenceContext4Ast


  • public class InferenceContext4Ast
    extends java.lang.Object
    Stores context information for expressions and type identifiers, which are used (in some instances) to calculate the corresponding SymTypes.

    The Type System uses contextual typing, i.e., the type of an expression can be dependent on the context, e.g.: List<A> as = new ArrayList<>(); List<B> bs = new ArrayList<>();

    The information stored are also used to make free type variable replacement reproducible

    • Field Detail

      • expr2ctx

        protected java.util.Map<de.monticore.ast.ASTNode,​InferenceContext> expr2ctx
        the actual map from context to types, we use ASTNode to support non-ASTExpression Nodes, however, we do NOT support non-expression ASTNodes, e.g., in MyClass.myMethod(), the "MyClass" is not an expression by itself.
      • expr2resolved

        protected java.util.Map<de.monticore.ast.ASTNode,​SymTypeExpression> expr2resolved
        Used to make free type variable replacement reproducible; Any SymTypeExpression that has been resolved or acquired in a comparable context is stored here. Do not rely on this information for any other case!
    • Constructor Detail

      • InferenceContext4Ast

        public InferenceContext4Ast()
    • Method Detail

      • getExpression2Context

        protected java.util.Map<de.monticore.ast.ASTNode,​InferenceContext> getExpression2Context()
      • reset

        public void reset()
      • resetContexts

        public void resetContexts​(de.monticore.ast.ASTNode rootNode)
        This removes the stored values of every node below and including the provided root. This can be required to, e.g., rerun the type checker multiple times during type inference.

        Does NOT reset the information required to make free type variable replacement reproducible!

      • setContextOfExpression

        public void setContextOfExpression​(ASTExpression astExpr,
                                           InferenceContext context)
        sets the type information of the expression, information may be partial
      • setTargetTypeOfExpression

        public void setTargetTypeOfExpression​(ASTExpression astExpr,
                                              SymTypeExpression targetType)
        QOL method: sets the target type for a given expression
      • hasResolvedOfExpression

        public boolean hasResolvedOfExpression​(ASTExpression astExpr)
      • node2InfoString

        protected java.lang.String node2InfoString​(de.monticore.ast.ASTNode node)
        helps with logging.