Example #1
0
        private void VisitNode(LocalVariableDeclarationStatement node)
        {
            // catch errors prior to entering local var decl stmt
            ErrorDescriptor err = node.TypeDescriptor as ErrorDescriptor;

            if (err != null)
            {
                PrintError(err);
                return;
            }

            AbstractNode typeSpecifier            = node.Child;
            AbstractNode localVariableDeclarators = typeSpecifier.Sib;

            string        type  = GetIlType(typeSpecifier);
            List <String> names = GetLocalVarDeclNames(localVariableDeclarators);

            SetLocalVarDeclNames(names);

            File.WriteLine(".locals init(");
            int count = 0;
            int location;

            foreach (var name in names)
            {
                location = _localVariables.GetVarLocation(name);
                File.Write($"   [{location}] {type} {name}");
                File.WriteLine((count < names.Count - 1) ? "," : "");
                ++count;
            }
            File.WriteLine(")");
        }
Example #2
0
        private void VisitNode(LocalVariableDeclarationStatement node)
        {
            AbstractNode typeSpecifier            = node.Child;
            AbstractNode localVariableDeclarators = typeSpecifier.Sib;

            typeSpecifier.Accept(this);
            TypeDescriptor declType = typeSpecifier.TypeDescriptor;

            AbstractNode identifier = localVariableDeclarators.Child;

            while (identifier != null)
            {
                Identifier id = (Identifier)identifier;
                if (Table.isDeclaredLocally(id.ID))
                {
                    id.TypeDescriptor = new ErrorDescriptor("Symbol table " +
                                                            "already contains id: " + id.ID);
                    id.AttributesRef = null;
                }
                else
                {
                    VariableDeclarationAttributes attr =
                        new VariableDeclarationAttributes();
                    attr.Kind           = Kind.VariableAttributes;
                    attr.TypeDescriptor = declType;
                    attr.IsAssignable   = true;
                    attr.Modifiers      = null;
                    Table.enter(id.ID, attr);
                    id.TypeDescriptor = declType;
                    id.AttributesRef  = attr;
                }
                identifier = identifier.Sib;
            }
        }