Class Type4Ast
- java.lang.Object
-
- de.monticore.types3.Type4Ast
-
public class Type4Ast extends java.lang.ObjectStores 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") usinggetTypeOfExpression(de.monticore.expressions.expressionsbasis._ast.ASTExpression). get the type of a type identifier (e.g., "int") usinggetTypeOfTypeIdentifier(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 Summary
Fields Modifier and Type Field Description protected java.util.Map<de.monticore.ast.ASTNode,SymTypeExpression>expr2typethe 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.protected static java.lang.StringLOG_NAMEprotected java.util.Map<de.monticore.ast.ASTNode,SymTypeExpression>typeID2typethe actual map from type identifier to types, strictly seperated from the map for expressions we use ASTNode to support non-ASTMCType Nodes (e.g.
-
Constructor Summary
Constructors Constructor Description Type4Ast()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidassertNoInferenceVars(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.protected java.util.Map<de.monticore.ast.ASTNode,SymTypeExpression>getExpression2Type()SymTypeExpressiongetPartialTypeOfExpr(ASTExpression astExpr)SymTypeExpressiongetPartialTypeOfExpr(ASTLiteral astLit)SymTypeExpressiongetPartialTypeOfTypeId(ASTMCQualifiedName qName)SymTypeExpressiongetPartialTypeOfTypeId(ASTMCReturnType mcReturnType)SymTypeExpressiongetPartialTypeOfTypeId(ASTMCType mcType)SymTypeExpressiongetPartialTypeOfTypeId(ASTMCTypeArgument typeArg)SymTypeExpressiongetPartialTypeOfTypeIdForName(ASTExpression nameExpr)A special case for specific MCQualifiedNames s.protected java.util.Map<de.monticore.ast.ASTNode,SymTypeExpression>getTypeIdentifier2Type()SymTypeExpressiongetTypeOfExpression(ASTExpression astExpr)gets the type information of the expressionSymTypeExpressiongetTypeOfExpression(ASTLiteral astLit)gets the type information of the literalSymTypeExpressiongetTypeOfTypeIdentifier(ASTMCQualifiedName qName)SymTypeExpressiongetTypeOfTypeIdentifier(ASTMCReturnType mcReturnType)SymTypeExpressiongetTypeOfTypeIdentifier(ASTMCType mcType)SymTypeExpressiongetTypeOfTypeIdentifier(ASTMCTypeArgument typeArg)booleanhasPartialTypeOfExpression(ASTExpression astExpr)booleanhasPartialTypeOfExpression(ASTLiteral astLit)booleanhasPartialTypeOfTypeIdentifier(ASTMCQualifiedName mcQName)booleanhasPartialTypeOfTypeIdentifier(ASTMCReturnType mcReturnType)booleanhasPartialTypeOfTypeIdentifier(ASTMCType mcType)booleanhasPartialTypeOfTypeIdentifier(ASTMCTypeArgument mcTypeArg)booleanhasPartialTypeOfTypeIdentifierForName(ASTExpression nameExpr)booleanhasTypeOfExpression(ASTExpression astExpr)whether a type has been calculated for the expressionbooleanhasTypeOfExpression(ASTLiteral astLit)whether a type has been calculated for the literalbooleanhasTypeOfTypeIdentifier(ASTMCQualifiedName mcQName)booleanhasTypeOfTypeIdentifier(ASTMCReturnType mcReturnType)booleanhasTypeOfTypeIdentifier(ASTMCType mcType)booleanhasTypeOfTypeIdentifier(ASTMCTypeArgument mcTypeArg)booleanhasTypeOfTypeIdentifierForName(ASTExpression nameExpr)protected SymTypeExpressioninternal_getPartialTypeOfExpr(de.monticore.ast.ASTNode node)returns potentially partial type information of the expression internally used by type deriverprotected SymTypeExpressioninternal_getPartialTypeOfTypeId(de.monticore.ast.ASTNode node)returns potentially partial type information of the type identifier used by type deriverSymTypeExpressioninternal_getPartialTypeOfTypeId2(de.monticore.ast.ASTNode node)Deprecated.do not use, only here until fix in grammarprotected SymTypeExpressioninternal_getTypeOfExpression(de.monticore.ast.ASTNode node)protected SymTypeExpressioninternal_getTypeOfTypeIdentifier(de.monticore.ast.ASTNode node)gets the type of the type identifier if it has been calculatedprotected booleaninternal_hasPartialTypeOfExpression(de.monticore.ast.ASTNode node)protected booleaninternal_hasPartialTypeOfTypeIdentifier(de.monticore.ast.ASTNode node)whether a type has been calculated for the type identifierprotected booleaninternal_hasTypeOfExpression(de.monticore.ast.ASTNode node)protected booleaninternal_hasTypeOfTypeIdentifier(de.monticore.ast.ASTNode node)whether a type has been calculated for the type identifierprotected voidinternal_setTypeOfExpression(de.monticore.ast.ASTNode node, SymTypeExpression typeExpr)protected voidinternal_setTypeOfTypeIdentifier(de.monticore.ast.ASTNode node, SymTypeExpression typeExpr)sets the type information of the type identifier, information may be partialvoidinternal_setTypeOfTypeIdentifier2(de.monticore.ast.ASTNode node, SymTypeExpression type)Deprecated.do not use, remove after fix of grammarsprotected booleanisQNameExpr(ASTExpression expr)whether the expression represents a qualified nameprotected java.lang.Stringnode2InfoString(de.monticore.ast.ASTNode node)helps with logging.voidreset()voidreset(de.monticore.ast.ASTNode rootNode)This removes the stored values of every node below and including the provided root.voidsetTypeOfExpression(ASTExpression astExpr, SymTypeExpression typeExpr)sets the type information of the expression, information may be partialvoidsetTypeOfExpression(ASTLiteral astLit, SymTypeExpression typeExpr)sets the type information of the literal, information may be partialvoidsetTypeOfTypeIdentifier(ASTMCQualifiedName qName, SymTypeExpression type)voidsetTypeOfTypeIdentifier(ASTMCReturnType mcReturnType, SymTypeExpression type)voidsetTypeOfTypeIdentifier(ASTMCType mcType, SymTypeExpression type)voidsetTypeOfTypeIdentifier(ASTMCTypeArgument typeArg, SymTypeExpression type)voidsetTypeOfTypeIdentifierForName(ASTFieldAccessExpression qName, SymTypeExpression type)a special case of the MCQualifiedName s.voidsetTypeOfTypeIdentifierForName(ASTNameExpression name, SymTypeExpression type)a special case of the MCQualifiedName
-
-
-
Field Detail
-
LOG_NAME
protected static final java.lang.String LOG_NAME
- See Also:
- Constant Field Values
-
expr2type
protected java.util.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 java.util.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
-
-
Method Detail
-
getExpression2Type
protected java.util.Map<de.monticore.ast.ASTNode,SymTypeExpression> getExpression2Type()
-
getTypeIdentifier2Type
protected java.util.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)
A special case for specific MCQualifiedNames s.setTypeOfTypeIdentifierForName( ASTFieldAccessExpression, SymTypeExpression)
-
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)
a special case of the MCQualifiedName s.setTypeOfTypeIdentifierForName( ASTNameExpression, SymTypeExpression)
-
setTypeOfTypeIdentifierForName
public void setTypeOfTypeIdentifierForName(ASTNameExpression name, SymTypeExpression type)
a special case of the MCQualifiedNamethis 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 java.lang.String node2InfoString(de.monticore.ast.ASTNode node)
helps with logging.
-
-