Class TypeCheck3

  • Direct Known Subclasses:
    MapBasedTypeCheck3

    public abstract class TypeCheck3
    extends java.lang.Object
    This 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 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.

    • Constructor Detail

      • TypeCheck3

        public TypeCheck3()
    • 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,
                                               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 type List<int> as additional information, allows to additionally derive the type argument int, resulting in deriving List<int> to be the expression []'s type.

        Note: it is up to the concrete implementation, whether the target type is used.

      • setDelegate

        protected static void setDelegate​(TypeCheck3 delegate)
      • resetDelegate

        protected static void resetDelegate()
      • getDelegate

        protected static TypeCheck3 getDelegate()