Package errors

Class SemanticError


  • public final class SemanticError
    extends Error
    The SemanticError class is used to represent an error that occurred during the semantic analysis stage of compilation.

    Static methods for generating SemanticErrors are stored here, each of which uses a set of pre-defined input Strings.

    Since:
    1.0
    • Constructor Detail

      • SemanticError

        public SemanticError​(SourceSpan span,
                             java.lang.String problem,
                             java.lang.String solution)
    • Method Detail

      • undefinedUnaryOperator

        public static SemanticError undefinedUnaryOperator​(SourceSpan span,
                                                           java.lang.String syntax,
                                                           ObjectType type)
        Generate and return a SemanticError for an incompatible unary operator.
        Parameters:
        span - The location information for where an error occurred
        syntax - The syntax of the operator
        type - The ObjectType of the operand
        Returns:
        A SemanticError containing information about an error that occurred
      • undefinedBinaryOperator

        public static SemanticError undefinedBinaryOperator​(SourceSpan span,
                                                            java.lang.String syntax,
                                                            ObjectType leftType,
                                                            ObjectType rightType)
        Generate and return a SemanticError for an incompatible binary operator.
        Parameters:
        span - The location information for where an error occurred
        syntax - The syntax of the operator
        leftType - The ObjectType of the left operand
        rightType - The ObjectType of the right operand
        Returns:
        A SemanticError containing information about an error that occurred
      • undefinedAssignmentOperator

        public static SemanticError undefinedAssignmentOperator​(SourceSpan span,
                                                                java.lang.String syntax,
                                                                ObjectType symbolType,
                                                                ObjectType assignmentType)
        Generate and return a SemanticError for an incompatible assignment operator.
        Parameters:
        span - The location information for where an error occurred
        syntax - The syntax of the operator
        symbolType - The ObjectType of the symbol
        assignmentType - The ObjectType of the assignment
        Returns:
        A SemanticError containing information about an error that occurred
      • undefinedIdentifier

        public static SemanticError undefinedIdentifier​(SourceSpan span,
                                                        java.lang.String syntax)
        Generate and return a SemanticError for an undeclared symbol.
        Parameters:
        span - The location information for where an error occurred
        syntax - The syntax of the identifier
        Returns:
        A SemanticError containing information about an error that occurred
      • invalidExpressionTypes

        public static SemanticError invalidExpressionTypes​(SourceSpan span,
                                                           ObjectType actualType,
                                                           ObjectType[] targetTypes)
        Generate and return a SemanticError for invalid expression type(s).
        Parameters:
        span - The location information for where an error occurred
        actualType - The actual ObjectType of the expression
        targetTypes - The expected ObjectType of the expression
        Returns:
        A SemanticError containing information about an error that occurred