Class Type4Ast

java.lang.Object
de.monticore.types3.Type4Ast

public class Type4Ast extends Object
Stores the type of expressions and type identifiers, as such they do not need to be calculated again. get the type of an expression (e.g., "1+2") using getTypeOfExpression(de.monticore.expressions.expressionsbasis._ast.ASTExpression). get the type of a type identifier (e.g., "int") using getTypeOfTypeIdentifier(de.monticore.types.mcbasictypes._ast.ASTMCType). The getters marked with "Partial" and the setters are used by the type traverser filling the map. Setting a null value will remove the entry.
  • Field Details

    • LOG_NAME

      protected static final String LOG_NAME
      See Also:
    • expr2type

      protected Map<de.monticore.ast.ASTNode,SymTypeExpression> expr2type
      the actual map from expression to types, strictly seperated from the map for type identifiers we use ASTNode to support non-ASTExpression Nodes (e.g., literals) however, we do NOT support non-expression ASTNodes, e.g. in MyClass.myMethod(): the "MyClass" is not an expression by itself
    • typeID2type

      protected Map<de.monticore.ast.ASTNode,SymTypeExpression> typeID2type
      the actual map from type identifier to types, strictly seperated from the map for expressions we use ASTNode to support non-ASTMCType Nodes (e.g. qualified Names) however, we do NOT support expression ASTNodes, e.g. other qualified names that represent a variable, rather than a type
  • Constructor Details

    • Type4Ast

      public Type4Ast()
  • Method Details

    • getExpression2Type

      protected Map<de.monticore.ast.ASTNode,SymTypeExpression> getExpression2Type()
    • getTypeIdentifier2Type

      protected Map<de.monticore.ast.ASTNode,SymTypeExpression> getTypeIdentifier2Type()
    • reset

      public void reset()
    • reset

      public void reset(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.
    • hasTypeOfExpression

      public boolean hasTypeOfExpression(ASTExpression astExpr)
      whether a type has been calculated for the expression
    • hasTypeOfExpression

      public boolean hasTypeOfExpression(ASTLiteral astLit)
      whether a type has been calculated for the literal
    • internal_hasTypeOfExpression

      protected boolean internal_hasTypeOfExpression(de.monticore.ast.ASTNode node)
    • hasPartialTypeOfExpression

      public boolean hasPartialTypeOfExpression(ASTExpression astExpr)
    • hasPartialTypeOfExpression

      public boolean hasPartialTypeOfExpression(ASTLiteral astLit)
    • internal_hasPartialTypeOfExpression

      protected boolean internal_hasPartialTypeOfExpression(de.monticore.ast.ASTNode node)
    • hasTypeOfTypeIdentifier

      public boolean hasTypeOfTypeIdentifier(ASTMCType mcType)
    • hasTypeOfTypeIdentifier

      public boolean hasTypeOfTypeIdentifier(ASTMCReturnType mcReturnType)
    • hasTypeOfTypeIdentifier

      public boolean hasTypeOfTypeIdentifier(ASTMCQualifiedName mcQName)
    • hasTypeOfTypeIdentifier

      public boolean hasTypeOfTypeIdentifier(ASTMCTypeArgument mcTypeArg)
    • hasTypeOfTypeIdentifierForName

      public boolean hasTypeOfTypeIdentifierForName(ASTExpression nameExpr)
    • internal_hasTypeOfTypeIdentifier

      protected boolean internal_hasTypeOfTypeIdentifier(de.monticore.ast.ASTNode node)
      whether a type has been calculated for the type identifier
    • hasPartialTypeOfTypeIdentifier

      public boolean hasPartialTypeOfTypeIdentifier(ASTMCType mcType)
    • hasPartialTypeOfTypeIdentifier

      public boolean hasPartialTypeOfTypeIdentifier(ASTMCReturnType mcReturnType)
    • hasPartialTypeOfTypeIdentifier

      public boolean hasPartialTypeOfTypeIdentifier(ASTMCQualifiedName mcQName)
    • hasPartialTypeOfTypeIdentifier

      public boolean hasPartialTypeOfTypeIdentifier(ASTMCTypeArgument mcTypeArg)
    • hasPartialTypeOfTypeIdentifierForName

      public boolean hasPartialTypeOfTypeIdentifierForName(ASTExpression nameExpr)
    • internal_hasPartialTypeOfTypeIdentifier

      protected boolean internal_hasPartialTypeOfTypeIdentifier(de.monticore.ast.ASTNode node)
      whether a type has been calculated for the type identifier
    • getTypeOfExpression

      public SymTypeExpression getTypeOfExpression(ASTExpression astExpr)
      gets the type information of the expression
    • getTypeOfExpression

      public SymTypeExpression getTypeOfExpression(ASTLiteral astLit)
      gets the type information of the literal
    • internal_getTypeOfExpression

      protected SymTypeExpression internal_getTypeOfExpression(de.monticore.ast.ASTNode node)
    • getPartialTypeOfExpr

      public SymTypeExpression getPartialTypeOfExpr(ASTExpression astExpr)
    • getPartialTypeOfExpr

      public SymTypeExpression getPartialTypeOfExpr(ASTLiteral astLit)
    • internal_getPartialTypeOfExpr

      protected SymTypeExpression internal_getPartialTypeOfExpr(de.monticore.ast.ASTNode node)
      returns potentially partial type information of the expression internally used by type deriver
    • getTypeOfTypeIdentifier

      public SymTypeExpression getTypeOfTypeIdentifier(ASTMCType mcType)
    • getTypeOfTypeIdentifier

      public SymTypeExpression getTypeOfTypeIdentifier(ASTMCReturnType mcReturnType)
    • getTypeOfTypeIdentifier

      public SymTypeExpression getTypeOfTypeIdentifier(ASTMCQualifiedName qName)
    • getTypeOfTypeIdentifier

      public SymTypeExpression getTypeOfTypeIdentifier(ASTMCTypeArgument typeArg)
    • internal_getTypeOfTypeIdentifier

      protected SymTypeExpression internal_getTypeOfTypeIdentifier(de.monticore.ast.ASTNode node)
      gets the type of the type identifier if it has been calculated
    • getPartialTypeOfTypeId

      public SymTypeExpression getPartialTypeOfTypeId(ASTMCType mcType)
    • getPartialTypeOfTypeId

      public SymTypeExpression getPartialTypeOfTypeId(ASTMCReturnType mcReturnType)
    • getPartialTypeOfTypeId

      public SymTypeExpression getPartialTypeOfTypeId(ASTMCQualifiedName qName)
    • getPartialTypeOfTypeId

      public SymTypeExpression getPartialTypeOfTypeId(ASTMCTypeArgument typeArg)
    • getPartialTypeOfTypeIdForName

      public SymTypeExpression getPartialTypeOfTypeIdForName(ASTExpression nameExpr)
    • internal_getPartialTypeOfTypeId2

      @Deprecated public SymTypeExpression internal_getPartialTypeOfTypeId2(de.monticore.ast.ASTNode node)
      Deprecated.
      do not use, only here until fix in grammar
    • internal_getPartialTypeOfTypeId

      protected SymTypeExpression internal_getPartialTypeOfTypeId(de.monticore.ast.ASTNode node)
      returns potentially partial type information of the type identifier used by type deriver
    • setTypeOfExpression

      public void setTypeOfExpression(ASTExpression astExpr, SymTypeExpression typeExpr)
      sets the type information of the expression, information may be partial
    • setTypeOfExpression

      public void setTypeOfExpression(ASTLiteral astLit, SymTypeExpression typeExpr)
      sets the type information of the literal, information may be partial
    • internal_setTypeOfExpression

      protected void internal_setTypeOfExpression(de.monticore.ast.ASTNode node, SymTypeExpression typeExpr)
    • setTypeOfTypeIdentifier

      public void setTypeOfTypeIdentifier(ASTMCType mcType, SymTypeExpression type)
    • setTypeOfTypeIdentifier

      public void setTypeOfTypeIdentifier(ASTMCReturnType mcReturnType, SymTypeExpression type)
    • setTypeOfTypeIdentifier

      public void setTypeOfTypeIdentifier(ASTMCQualifiedName qName, SymTypeExpression type)
    • setTypeOfTypeIdentifierForName

      public void setTypeOfTypeIdentifierForName(ASTFieldAccessExpression qName, SymTypeExpression type)
    • setTypeOfTypeIdentifierForName

      public void setTypeOfTypeIdentifierForName(ASTNameExpression name, SymTypeExpression type)
      a special case of the MCQualifiedName

      this is only used in cases there the type identifier 1. was parsed as an expression (instead of a MCQualifiedName) and 2. the AST can not be transformed to accommodate without non-conservative grammar changes

      In our Java-esque languages, this usually happens before ".", e.g., C in C.staticVar, C.staticMethod() C.this.var, C.super.method(), ... As the type id has been parsed as an expression, and nothing further is known without reflection, getting the type information cannot be type safe ("type safe" as in (partially) ensuring correct usage by the type checker), thus the uniqueness of the methods' names. note that (technically) not even ASTExpression applicable enough, due to some grammar extension points The getter is getPartialTypeOfTypeIdForName(ASTExpression)

    • setTypeOfTypeIdentifier

      public void setTypeOfTypeIdentifier(ASTMCTypeArgument typeArg, SymTypeExpression type)
    • internal_setTypeOfTypeIdentifier2

      @Deprecated public void internal_setTypeOfTypeIdentifier2(de.monticore.ast.ASTNode node, SymTypeExpression type)
      Deprecated.
      do not use, remove after fix of grammars
    • internal_setTypeOfTypeIdentifier

      protected void internal_setTypeOfTypeIdentifier(de.monticore.ast.ASTNode node, SymTypeExpression typeExpr)
      sets the type information of the type identifier, information may be partial
    • assertNoInferenceVars

      protected void assertNoInferenceVars(de.monticore.ast.ASTNode node, SymTypeExpression type)
      If there are any inference variables to be (indirectly) stored in Type4Ast, either an internal programming error occurred, or no Type inference traverser has run and replaced it with an instantiation.
    • isQNameExpr

      protected boolean isQNameExpr(ASTExpression expr)
      whether the expression represents a qualified name
    • node2InfoString

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