Class TypeCheck3
- java.lang.Object
-
- de.monticore.types3.TypeCheck3
-
- Direct Known Subclasses:
MapBasedTypeCheck3
public abstract class TypeCheck3 extends java.lang.ObjectThis class is intended to provide type-checking functionality.It is designed as functional class (no state), allowing to plug in the appropriate implementation through subclasses. Those subclasses can deal with variants of Expression, Literal, and Type-classes that are used in the respective project. This class only knows about the three top Level grammars, ExpressionsBasis, MCLiteralsBasis, and MCBasicTypes, because it includes their main non-terminals in the signature.
The provided methods return the SymTypeExpression that corresponds to the provided AST-node. SymTypeExpressions are independent of the AST and can be stored in the symbol table, etc.
-
-
Field Summary
Fields Modifier and Type Field Description protected static TypeCheck3delegateStatic delegate responsible for ALL methods of this class; No further fields ought to be added to this class.
-
Constructor Summary
Constructors Constructor Description TypeCheck3()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract SymTypeExpression_symTypeFromAST(ASTMCQualifiedName mcQualifiedName)protected abstract SymTypeExpression_symTypeFromAST(ASTMCReturnType mcReturnType)protected abstract SymTypeExpression_symTypeFromAST(ASTMCType mcType)protected abstract SymTypeExpression_symTypeFromAST(ASTMCVoidType mcVoidType)protected abstract SymTypeExpression_typeOf(ASTExpression expr)protected SymTypeExpression_typeOf(ASTExpression expr, SymTypeExpression targetType)protected abstract SymTypeExpression_typeOf(ASTLiteral lit)protected static TypeCheck3getDelegate()protected static voidresetDelegate()protected static voidsetDelegate(TypeCheck3 delegate)static SymTypeExpressionsymTypeFromAST(ASTMCQualifiedName mcQualifiedName)Extracts the SymTypeExpression corresponding to the ASTMCQualifiedName.static SymTypeExpressionsymTypeFromAST(ASTMCReturnType mcReturnType)Extracts the SymTypeExpression corresponding to the return type.static SymTypeExpressionsymTypeFromAST(ASTMCType mcType)Extracts the SymTypeExpression corresponding to the ASTMCType.static SymTypeExpressionsymTypeFromAST(ASTMCVoidType mcVoidType)Extracts the SymTypeExpression corresponding to "void".static SymTypeExpressiontypeOf(ASTExpression expr)Derive the type of the expression.static SymTypeExpressiontypeOf(ASTExpression expr, SymTypeExpression targetType)Derives the type of the expression, using the expected target type as additional information.static SymTypeExpressiontypeOf(ASTLiteral lit)Derives the type of the literal.
-
-
-
Field Detail
-
delegate
protected static TypeCheck3 delegate
Static delegate responsible for ALL methods of this class; No further fields ought to be added to this class.This has to be initialized by an implementing subclass.
-
-
Method Detail
-
symTypeFromAST
public static SymTypeExpression symTypeFromAST(ASTMCType mcType)
Extracts the SymTypeExpression corresponding to the ASTMCType.
-
symTypeFromAST
public static SymTypeExpression symTypeFromAST(ASTMCVoidType mcVoidType)
Extracts the SymTypeExpression corresponding to "void". "void" is not part of the ASTMCType-Hierarchy, while it is included in the SymTypeExpressions.
-
symTypeFromAST
public static SymTypeExpression symTypeFromAST(ASTMCReturnType mcReturnType)
Extracts the SymTypeExpression corresponding to the return type. ASTMCReturnType is not part of the ASTMCType-Hierarchy, while it is included in the SymTypeExpressions.
-
symTypeFromAST
public static SymTypeExpression symTypeFromAST(ASTMCQualifiedName mcQualifiedName)
Extracts the SymTypeExpression corresponding to the ASTMCQualifiedName.
-
typeOf
public static SymTypeExpression typeOf(ASTExpression expr)
Derive the type of the expression. Each typeable expression, in a fixed context, has exactly one type.Whenever possible, instead use
typeOf(ASTExpression, SymTypeExpression).
-
typeOf
public static SymTypeExpression typeOf(ASTExpression expr, SymTypeExpression targetType)
Derives the type of the expression, using the expected target type as additional information.E.g.:
List<int> myList = [];// [] returns an empty list Here, the type of [] is to be calculated. Without target type, it is known that a List is returned. However, the type argument of List is unknown. Using the target typeList<int>as additional information, allows to additionally derive the type argument int, resulting in derivingList<int>to be the expression []'s type.Note: it is up to the concrete implementation, whether the target type is used.
-
typeOf
public static SymTypeExpression typeOf(ASTLiteral lit)
Derives the type of the literal.
-
_symTypeFromAST
protected abstract SymTypeExpression _symTypeFromAST(ASTMCType mcType)
-
_symTypeFromAST
protected abstract SymTypeExpression _symTypeFromAST(ASTMCVoidType mcVoidType)
-
_symTypeFromAST
protected abstract SymTypeExpression _symTypeFromAST(ASTMCReturnType mcReturnType)
-
_symTypeFromAST
protected abstract SymTypeExpression _symTypeFromAST(ASTMCQualifiedName mcQualifiedName)
-
_typeOf
protected abstract SymTypeExpression _typeOf(ASTExpression expr)
-
_typeOf
protected SymTypeExpression _typeOf(ASTExpression expr, SymTypeExpression targetType)
-
_typeOf
protected abstract SymTypeExpression _typeOf(ASTLiteral lit)
-
setDelegate
protected static void setDelegate(TypeCheck3 delegate)
-
resetDelegate
protected static void resetDelegate()
-
getDelegate
protected static TypeCheck3 getDelegate()
-
-