SemanticAnalysis

class SemanticAnalysis

Semantic analysis

Class which contains all functions used to aid semantic analysis. Any errors are thrown and held in the error handler.

Constructors

SemanticAnalysis
Link copied to clipboard
fun SemanticAnalysis()
Create empty Semantic analysis

Functions

allExpressionsAreSameTypeCheck
Link copied to clipboard
fun allExpressionsAreSameTypeCheck(expected: Type, expressions: List<ExpressionNode>, currentSymbolTable: SymbolTableVisitor, ctx: ParserRuleContext)
All expressions are same type check
array2DDimensionsMatchCheck
Link copied to clipboard
fun array2DDimensionsMatchCheck(initialiser: InitialiserNode, dataStructureType: DataStructureType, ctx: ParserRuleContext)
Array2d dimensions match check
breakOrContinueOutsideLoopCheck
Link copied to clipboard
fun breakOrContinueOutsideLoopCheck(action: String, inLoop: Boolean, ctx: ParserRuleContext)
Break or continue outside loop check
checkAnnotationArguments
Link copied to clipboard
fun checkAnnotationArguments(ctx: ParserRuleContext, symbolTable: SymbolTableVisitor, arguments: List<ExpressionNode>): List<Type>
Check annotation arguments
checkArrayConstructorItemLengthsMatch
Link copied to clipboard
fun checkArrayConstructorItemLengthsMatch(openConstructorSize: Int, closeConstructorSize: Int, ctx: ParserRuleContext)
Check array constructor item lengths match
fun checkArrayDimensionsMatchConstructorArguments(dataStructureType: DataStructureType, argumentsSize: Int, ctx: ParserRuleContext)
Check array dimensions match constructor arguments
checkArrayDimensionsNotGreaterThanTwo
Link copied to clipboard
fun checkArrayDimensionsNotGreaterThanTwo(arrayDimension: Int, ctx: ParserRuleContext)
Check array dimensions not greater than two
checkArrayElemHasCorrectNumberOfIndices
Link copied to clipboard
fun checkArrayElemHasCorrectNumberOfIndices(indices: List<ExpressionNode>, is2DArray: Boolean, ctx: ParserRuleContext)
Check array elem has correct number of indices
checkArrayElemIndexTypes
Link copied to clipboard
fun checkArrayElemIndexTypes(indices: List<ExpressionNode>, currentSymbolTable: SymbolTableVisitor, ctx: ParserRuleContext)
Check array elem index types
checkExpressionTypeWithExpectedType
Link copied to clipboard
fun checkExpressionTypeWithExpectedType(expression: ExpressionNode, expected: Type, currentSymbolTable: SymbolTableVisitor, ctx: ParserRuleContext)
Check expression type with expected type
checkExpressionTypeWithExpectedTypes
Link copied to clipboard
fun checkExpressionTypeWithExpectedTypes(expression: ExpressionNode, expected: Set<Type>, currentSymbolTable: SymbolTableVisitor, ctx: ParserRuleContext)
Check expression type with expected types
datastructureConstructorCheck
Link copied to clipboard
fun datastructureConstructorCheck(dataStructureType: DataStructureType, initialValue: List<ExpressionNode>, argumentTypes: List<Type>, ctx: VAlgoLangParser.DataStructureConstructorContext)
Datastructure constructor check
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
fun forLoopIdentifierNotBeingReassignedCheck(identifier: String, forLoopIdentifiers: Set<String>, ctx: ParserRuleContext)
For loop identifier not being reassigned check
forLoopRangeTypeCheck
Link copied to clipboard
fun forLoopRangeTypeCheck(symbolTable: SymbolTableVisitor, startExpr: ExpressionNode, endExpr: ExpressionNode, ctx: VAlgoLangParser.RangeHeaderContext)
For loop range type check
forLoopRangeUpdateNumberTypeCheck
Link copied to clipboard
fun forLoopRangeUpdateNumberTypeCheck(symbolTable: SymbolTableVisitor, change: ExpressionNode, ctx: ParserRuleContext)
For loop range update number type check
globalReturnCheck
Link copied to clipboard
fun globalReturnCheck(inFunction: Boolean, ctx: VAlgoLangParser.ReturnStatementContext)
Global return check
hashCode
Link copied to clipboard
open fun hashCode(): Int
incompatibleArgumentTypesCheck
Link copied to clipboard
fun incompatibleArgumentTypesCheck(dataStructureType: DataStructureType, argumentTypes: List<Type>, dataStructureMethod: DataStructureMethod, ctx: ParserRuleContext)
Incompatible argument types check
fun incompatibleArgumentTypesForFunctionsCheck(identifier: String, currentSymbolTable: SymbolTableVisitor, argTypes: List<Type>, ctx: VAlgoLangParser.FunctionCallContext)
Incompatible argument types for functions check
incompatibleInitialiserCheck
Link copied to clipboard
fun incompatibleInitialiserCheck(dataStructureType: DataStructureType, initialiser: ASTNode, ctx: ParserRuleContext)
Incompatible initialiser check
incompatibleMultipleFunctionCall
Link copied to clipboard
fun incompatibleMultipleFunctionCall(identifier: String, functionData: FunctionData, lhsType: Type, ctx: ParserRuleContext)
Incompatible multiple function call
incompatibleOperatorTypeCheck
Link copied to clipboard
fun incompatibleOperatorTypeCheck(operator: String, opExpr: ExpressionNode, currentSymbolTable: SymbolTableVisitor, ctx: VAlgoLangParser.ExprContext)
Incompatible operator type check
incompatibleReturnTypesCheck
Link copied to clipboard
fun incompatibleReturnTypesCheck(currentSymbolTable: SymbolTableVisitor, functionReturnType: Type, expression: ExpressionNode, ctx: VAlgoLangParser.ReturnStatementContext)
Incompatible return types check
incompatibleTypesCheck
Link copied to clipboard
fun incompatibleTypesCheck(lhsType: Type, rhsType: Type, text: String, ctx: ParserRuleContext)
Incompatible types check
inferType
Link copied to clipboard
fun inferType(currentSymbolTable: SymbolTableVisitor, expression: ExpressionNode): Type
Infer typeInfers type of expression
invalidArrayElemAssignment
Link copied to clipboard
fun invalidArrayElemAssignment(identifier: String, type: Type, ctx: VAlgoLangParser.Assignment_lhsContext)
Invalid array elem assignment
fun invalidNumberOfArgumentsForFunctionsCheck(identifier: String, currentSymbolTable: SymbolTableVisitor, numArgs: Int, ctx: VAlgoLangParser.FunctionCallContext)
Invalid number of arguments for functions check
missingReturnCheck
Link copied to clipboard
fun missingReturnCheck(identifier: String, statements: List<StatementNode>, type: Type, ctx: VAlgoLangParser.FunctionContext)
Missing return check
notDataStructureCheck
Link copied to clipboard
fun notDataStructureCheck(currentSymbolTable: SymbolTableVisitor, identifier: String, ctx: ParserRuleContext)
Not data structure check
notValidMethodNameForDataStructureCheck
Link copied to clipboard
fun notValidMethodNameForDataStructureCheck(currentSymbolTable: SymbolTableVisitor, identifier: String, method: String, ctx: ParserRuleContext, overrideType: Type = ErrorType): Boolean
Not valid method name for data structure check
primitiveArgTypesCheck
Link copied to clipboard
fun primitiveArgTypesCheck(argTypes: List<Type>, methodName: String, dataStructureType: DataStructureType, ctx: VAlgoLangParser.MethodCallContext)
Primitive arg types check
fun primitiveInternalTypeForDataStructureCheck(internalType: Type, ctx: ParserRuleContext)
Primitive internal type for data structure check
redeclaredFunctionCheck
Link copied to clipboard
fun redeclaredFunctionCheck(currentSymbolTable: SymbolTableVisitor, identifier: String, returnType: Type, parameters: List<ParameterNode>, ctx: ParserRuleContext)
Redeclared function check
redeclaredVariableCheck
Link copied to clipboard
fun redeclaredVariableCheck(currentSymbolTable: SymbolTableVisitor, identifier: String, ctx: ParserRuleContext)
Redeclared variable check
tooManyInferredFunctionsCheck
Link copied to clipboard
fun tooManyInferredFunctionsCheck(currentSymbolTable: SymbolTableVisitor, ctx: ParserRuleContext)
Too many inferred functions check
toString
Link copied to clipboard
open fun toString(): String
unableToInferTypeCheck
Link copied to clipboard
fun unableToInferTypeCheck(rhsType: Type, ctx: ParserRuleContext)
Unable to infer type check
undeclaredFunctionCheck
Link copied to clipboard
fun undeclaredFunctionCheck(currentSymbolTable: SymbolTableVisitor, identifier: String, inFunction: Boolean, argTypes: List<Type>, ctx: ParserRuleContext)
Undeclared function check
undeclaredIdentifierCheck
Link copied to clipboard
fun undeclaredIdentifierCheck(currentSymbolTable: SymbolTableVisitor, identifier: String, ctx: ParserRuleContext)
Undeclared identifier check
voidTypeDeclarationCheck
Link copied to clipboard
fun voidTypeDeclarationCheck(rhsType: Type, identifier: String, ctx: ParserRuleContext)
Void type declaration check