protected void VisitNode(LocalVarDecls node)
        {
            // Correlates variable names with stack position
            Dictionary <string, int> localVars = new Dictionary <string, int>();
            int localVarIdx = 0;
            // We want to add some variables to the .il file
            // Visit all of DclName children
            List <DclName> declNameChildren = Utilities.GetChildren(node, typeof(DclName)).Cast <DclName>().ToList();
            String         declString       = "";

            if (declNameChildren.Count > 0)
            {
                declString = String.Format(".locals init (\n");
            }
            foreach (DclName d in declNameChildren)
            {
                String varType = Utilities.TypeDescToString(d.attrRef);
                String varName = d.Name.Split(' ')[2];

                declString += String.Format("[{0}]\t{1}\t{2}", localVarIdx,
                                            varType, varName);
                localVars.Add(varName, localVarIdx);
                localVarIdx++;
                if (localVarIdx > 0 && localVarIdx != declNameChildren.Count)
                {
                    declString += ",";
                }
                declString += "\n";

                // Store the stack order of this variable
            }
            localVarNumber.Add(methodName, localVars);
            InsertIntoFile(declString + ")\n");
            // commas
        }
Beispiel #2
0
        public void VisitNode(LocalVarDeclStmt node)
        {
            // Type of this declaration
            Type type = null;

            // See if we have a primitive type
            var primitiveTypeChildren = Utilities.GetChildren(node, typeof(PrimitiveType)).Cast <PrimitiveType>().ToList();

            // If we have a primitive type go visit it
            if (primitiveTypeChildren.Count > 0)
            {
                TypeVisitor t = new TypeVisitor();
                primitiveTypeChildren[0].Accept(t);
                Attributes a = primitiveTypeChildren[0].attrRef;
                type = a.typeInfo.GetType();
            }
            // Otherwise we better have a qualified name
            else
            {
                var qualNameChildren = Utilities.GetChildren(node, typeof(QualifiedName)).Cast <QualifiedName>().ToList();
                // If we have a qualified name go visit it
                if (qualNameChildren.Count > 0)
                {
                    TypeVisitor t = new TypeVisitor();
                    qualNameChildren[0].Accept(t);
                    Attributes a = qualNameChildren[0].attrRef;
                    type = a.typeInfo.GetType();
                }
            }
            // Now we have a type. Could be error, or a valid type.

            Attributes myAttr = new Attributes("VarDcl");

            myAttr.typeInfo = type;
            node.attrRef    = myAttr;
            // Go to LocalVarDecls and Get all DclName children
            LocalVarDecls  dclsNode         = Utilities.GetChildren(node, typeof(LocalVarDecls)).Cast <LocalVarDecls>().ToList()[0];
            List <DclName> matchingChildren = Utilities.GetChildren(dclsNode, typeof(DclName)).Cast <DclName>().ToList();

            foreach (DclName d in matchingChildren)
            {
                // Enter these children into the symbol table
                // Extract the name (ugly but the name is currently "LocalVar -> xxxx" and we want xxxx)
                String name = d.Name.Split(' ')[2];
                name = Utilities.FilterOutKeywords(name);
                currentSymbolTable.enter(name, myAttr);

                // Also, go ahead and record the type for all of these nodes for printing
                d.attrRef = myAttr;
            }
        }