public override void EnterStructDeclaration(DecafParser.StructDeclarationContext context) { StructSymbol ss = new StructSymbol(context.Id().GetText(), currentScope); currentScope.define(ss); setNodeScope(context, ss); setNodeSymbol(context, ss); currentScope = ss; }
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 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 EnterInt_methodDeclaration(DecafParser.Int_methodDeclarationContext context) { parameterList = new List<SymbolType>(); theScopeManager.AddSymbol(context.Id().GetText(), new MethodSymbol(SymbolType.Tint)); theScopeManager.EnterScope(); }
public override void ExitVoid_methodDeclaration(DecafParser.Void_methodDeclarationContext context) { parameterList = null; SymbolType theReturnType = SymbolType.Tvoid; List<SymbolType> theParameters = new List<SymbolType>(); theScopeManager.GetAndExitScope(); DecafParser.ParameterContext[] parameterGroup = context.parameter(); foreach (DecafParser.ParameterContext item in parameterGroup) theParameters.Add(getNodeType(item)); MethodSymbol theSymbolRepresentation = new MethodSymbol(theReturnType, theParameters); theScopeManager.AddSymbol(context.Id().GetText(), theSymbolRepresentation); if (theScopeManager.HasReturn) { if (!(TypeHelper.isEquivalentType(theScopeManager.ReturnType, SymbolType.Tvoid))) { throw new Exception("Return Type Mismatch"); } } theScopeManager.resetReturn(); }
public override void ExitStructImpl_varType(DecafParser.StructImpl_varTypeContext context) { setNodeType(context, SymbolType.TstructImpl); setNodeSymbol(context, new StructImpl(context.Id().GetText())); }
public override void ExitStructDeclaration(DecafParser.StructDeclarationContext context) { SymbolTable theScope = theScopeManager.ExitScope(); StructDeclSymbol theSymbolRepresentation = new StructDeclSymbol(theScope); theScopeManager.AddSymbol(context.Id().GetText(), theSymbolRepresentation); }
public override void ExitSingle_varDeclaration(DecafParser.Single_varDeclarationContext context) { SymbolType theType = getNodeType(context.varType()); Symbol theSymbolRepresentation; if (theType != SymbolType.TstructImpl) theSymbolRepresentation = new Symbol(theType); else theSymbolRepresentation = getNodeSymbol(context.varType()); theScopeManager.AddSymbol(context.Id().GetText(), theSymbolRepresentation); }
public override void ExitSingle_parameterDeclaration(DecafParser.Single_parameterDeclarationContext context) { SymbolType theParameterType = getNodeType(context.parameterType()); Symbol theSymbolRepresentation = new Symbol(theParameterType); KeyValuePair<string, Symbol> theKeyValuePairRepresentaion = new KeyValuePair<string, Symbol>(context.Id().GetText(), theSymbolRepresentation); theScopeManager.AddSymbol(theKeyValuePairRepresentaion); parameterList.Add(theParameterType); setNodeSymbolTableEntry(context, theKeyValuePairRepresentaion); setNodeType(context, theParameterType); }
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 ExitMethodCall(DecafParser.MethodCallContext context) { string theId = context.Id().GetText(); if (!theScopeManager.CheckScope(context.Id().GetText(), symbolCategory.Cmethod)) //checks if the method is already declared { int line = context.start.Line; throw new Exception("Undeclared Identifier at line " + line.ToString()); } else { MethodSymbol theSymbol = theScopeManager.FindSymbol(context.Id().GetText(), symbolCategory.Cmethod) as MethodSymbol; List<SymbolType> MyparameterList = new List<SymbolType>(); #region methodCall parameter handling for (int i = 0; i < context.arg().Length; i++) { DecafParser.ArgContext argument = context.arg(i); MyparameterList.Add(getNodeType(argument)); } if (!theSymbol.checkParameterList(MyparameterList)) if (!TypeHelper.checkLists(MyparameterList, parameterList)) { throw new Exception("Argument Mismatch Errror"); } #endregion setNodeType(context, theSymbol.Type); } }
public override void ExitArray_varDeclaration(DecafParser.Array_varDeclarationContext context) { SymbolType theType = getNodeType(context.varType()); string num = context.Num().GetText(); ArraySymbol theSymbolRepresentation; if (theType != SymbolType.TstructImpl) theSymbolRepresentation = new ArraySymbol(theType, Convert.ToInt32(num)); else { StructImpl theSymbol = getNodeSymbol(context.varType()) as StructImpl; theSymbolRepresentation = new StructArraySymbol(theType, Convert.ToInt32(num), theSymbol.ParentStructName); } theScopeManager.AddSymbol(context.Id().GetText(), theSymbolRepresentation); }
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); } }