public override void EnterArray_location(DecafParser.Array_locationContext context) { //Get 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; //Find the current struct declaration name. StructDeclSymbol typedParent = theScopeManager.FindSymbol(structDecName, symbolCategory.CstructDecl) as StructDeclSymbol; theScopeManager.PushSymbolTable(typedParent.Members); } }
public override void EnterSingle_location(DecafParser.Single_locationContext context) { theScopeManager.GetEnclosingScope(); Symbol tempSymbol = theScopeManager.FindSymbol(context.Id().GetText(), symbolCategory.Cvariable); if (context.location() != null) { StructImpl typedStruct = tempSymbol as StructImpl; string structDecName = typedStruct.ParentStructName; StructDeclSymbol typedParent = theScopeManager.FindSymbol(structDecName, symbolCategory.CstructDecl) as StructDeclSymbol; theScopeManager.PushSymbolTable(typedParent.Members); } }
public override void ExitVar_location_expression(DecafParser.Var_location_expressionContext context) { setNodeType(context, getNodeType(context.location())); }
public override void ExitSingle_location(DecafParser.Single_locationContext context) { string symbolName = context.Id().GetText(); Symbol tempSymbol = theScopeManager.FindSymbol(context.Id().GetText(), symbolCategory.Cvariable); if (context.location() != null) { setNodeType(context, getNodeType(context.location())); theScopeManager.GetAndExitScope(); } else { setNodeType(context, tempSymbol.Type); } }
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); } }