Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 public override void EnterInt_methodDeclaration(DecafParser.Int_methodDeclarationContext context)
 {
     parameterList = new List<SymbolType>();
     theScopeManager.AddSymbol(context.Id().GetText(), new MethodSymbol(SymbolType.Tint));
     theScopeManager.EnterScope();
 }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
 public override void ExitStructImpl_varType(DecafParser.StructImpl_varTypeContext context)
 {
     setNodeType(context, SymbolType.TstructImpl);
     setNodeSymbol(context, new StructImpl(context.Id().GetText()));
 }
Exemplo n.º 7
0
        public override void ExitStructDeclaration(DecafParser.StructDeclarationContext context)
        {
            SymbolTable theScope = theScopeManager.ExitScope();
            StructDeclSymbol theSymbolRepresentation = new StructDeclSymbol(theScope);

            theScopeManager.AddSymbol(context.Id().GetText(), theSymbolRepresentation);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
 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);
     }
 }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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);
     }
 }