Class InferenceContext4Ast

java.lang.Object
de.monticore.types3.generics.context.InferenceContext4Ast

public class InferenceContext4Ast extends 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 Details

    • LOG_NAME

      protected static final String LOG_NAME
      See Also:
    • expr2ctx

      protected 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 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 Details

    • InferenceContext4Ast

      public InferenceContext4Ast()
  • Method Details

    • getExpression2Context

      protected 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!

    • getContextOfExpression

      public InferenceContext getContextOfExpression(ASTExpression node)
    • 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
    • setResolvedOfExpression

      public void setResolvedOfExpression(ASTExpression astExpr, SymTypeExpression resolved)
    • hasResolvedOfExpression

      public boolean hasResolvedOfExpression(ASTExpression astExpr)
    • getResolvedOfExpression

      public SymTypeExpression getResolvedOfExpression(ASTExpression astExpr)
    • node2InfoString

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