public override void ExitWhile_statement(DecafParser.While_statementContext context) { if (!TypeHelper.isBoolean(getNodeType(context.expression()))) throw new Exception("Boolean expression expected " + getNodeType(context.expression()).ToString() + " found instead."); }
public override void ExitRel_op_expression(DecafParser.Rel_op_expressionContext context) { if (TypeHelper.isNumeric(getNodeType(context.expression(0)), getNodeType(context.expression(1)))) setNodeType(context, SymbolType.Tboolean); else throw new Exception("The expressions have incompatible types."); }
public override void ExitReturn_statement(DecafParser.Return_statementContext context) { if (context.expression() != null) { setNodeType(context, getNodeType(context.expression())); if (!theScopeManager.HasReturn) theScopeManager.ReturnType = getNodeType(context.expression()); else if (!TypeHelper.isEquivalentType(theScopeManager.ReturnType, getNodeType(context.expression()))) throw new Exception("Result type mismatch"); } }
public override void ExitNot_expression(DecafParser.Not_expressionContext context) { if (TypeHelper.isBoolean(getNodeType(context.expression()))) setNodeType(context, SymbolType.Tboolean); else throw new Exception("Incompatible type. Boolean expected. " + getNodeType(context.expression()).ToString() + " found instead."); }
public override void ExitParens_expression(DecafParser.Parens_expressionContext context) { setNodeType(context, getNodeType(context.expression())); }
public override void ExitExpression_statement(DecafParser.Expression_statementContext context) { if (context.expression() != null) { setNodeType(context, getNodeType(context.expression())); } else setNodeType(context, SymbolType.Tvoid); }
public override void ExitNegative_expression(DecafParser.Negative_expressionContext context) { if (TypeHelper.isNumeric(getNodeType(context.expression()))) setNodeType(context, SymbolType.Tint); else throw new Exception("Incompatible type. Numeric expected. " + getNodeType(context.expression()).ToString() + " found instead."); }
public override void ExitChar_assign_statement(DecafParser.Char_assign_statementContext context) { SymbolType locationType = getNodeType(context.location()); SymbolType expressionType = getNodeType(context.expression()); if (TypeHelper.isNumeric(expressionType)) if (TypeHelper.isNumeric(locationType)) setNodeType(context, SymbolType.Tchar); else throw new Exception("Incompatible types, found location with type " + locationType.ToString() + " and expression with type " + expressionType.ToString()); }
public override void ExitAssign_statement(DecafParser.Assign_statementContext context) { SymbolType locationType = getNodeType(context.location()); SymbolType expressionType = getNodeType(context.expression()); if (TypeHelper.isEquivalentType(locationType, expressionType)) setNodeType(context, TypeHelper.getGreatestType(locationType, expressionType)); else throw new Exception("Incompatible types, found location with type " + locationType.ToString() + " and expression with type " + expressionType.ToString()); }
public override void ExitArray_location(DecafParser.Array_locationContext context) { // Finds the current symbol reference. Symbol tempSymbol = theScopeManager.FindSymbol(context.Id().GetText(), symbolCategory.Cvariable); if (context.location() != null) { StructArraySymbol typedSymbol = tempSymbol as StructArraySymbol; string structDecName = typedSymbol.ParentStructName; // Gets the struct definition symbol. StructDeclSymbol typedParent = theScopeManager.FindSymbol(structDecName, symbolCategory.CstructDecl) as StructDeclSymbol; theScopeManager.PushSymbolTable(typedParent.Members); setNodeType(context, getNodeType(context.location())); if (getNodeValue(context.expression()) > 0) { if (getNodeValue(context.expression()) > typedSymbol.length) { throw new Exception("Out of bounds exception"); } } } else { ArraySymbol typedSymbol = tempSymbol as ArraySymbol; setNodeType(context, typedSymbol.InternalType); } }
public override void ExitArith_expression(DecafParser.Arith_expressionContext context) { if (TypeHelper.isNumeric(getNodeType(context.expression(0)), getNodeType(context.expression(1)))) setNodeType(context, SymbolType.Tint); else throw new Exception("Incompatible type. Numeric expected."); }
public override void ExitArg(DecafParser.ArgContext context) { setNodeType(context, getNodeType(context.expression())); }