Exemplo n.º 1
0
 public override void VisitNamespaceDecl(NamespaceDecl x)
 {
     using (new ScopeHelper(this, x))
     {
         base.VisitNamespaceDecl(x);
     }
 }
Exemplo n.º 2
0
        public override void VisitNamespaceDecl(NamespaceDecl x)
        {
            _naming  = x.Naming;
            _current = Connect(_current, NewBlock());   // create new block with new naming

            base.VisitNamespaceDecl(x);
        }
Exemplo n.º 3
0
        private void InitializeFields()
        {
            strBufStack.Clear();
            //docCommentStack = null;
            condLevel = 0;

            Debug.Assert(sourceUnit != null);

            if (sourceUnit.CurrentNamespace.HasValue && sourceUnit.CurrentNamespace.Value.Namespaces.Length > 0)
            {   // J: inject current namespace from sourceUnit:
                this.currentNamespace = new AST.NamespaceDecl(Position.Initial, sourceUnit.CurrentNamespace.Value.ToStringList(), true);

                // add aliases into the namespace:
                if (sourceUnit.Aliases.Count > 0)
                {
                    foreach (var alias in sourceUnit.Aliases)
                    {
                        this.currentNamespace.Aliases.Add(alias.Key, alias.Value);
                    }
                }
            }
            else
            {
                this.currentNamespace = null;
            }
        }
Exemplo n.º 4
0
 public void Typecheck()
 {
     foreach (InstrNode node in ast.Instructions)
     {
         NamespaceDecl nmsp = ((NamespaceDecl)node.Value);
         topLevelEnvironment.AddEntry(nmsp.Name.Seq, new Namespace(), node.Position);
         new NamespaceChecker(nmsp.Block, topLevelEnvironment).Typecheck();
     }
 }
Exemplo n.º 5
0
            public override void VisitNamespaceDecl(NamespaceDecl x)
            {
                VisitSpecificElementProlog();

                SerializeToken(nameof(x.QualifiedName), x.QualifiedName.ToString(), x.QualifiedName.Span);
                SerializeToken(nameof(x.IsAnonymous), x.IsAnonymous.ToString(), null);

                base.VisitNamespaceDecl(x);
            }
Exemplo n.º 6
0
 /// <summary>
 /// Visit namespace statements.
 /// </summary>
 /// <param name="x"></param>
 override public void VisitNamespaceDecl(NamespaceDecl x)
 {
     _serializer.StartSerialize(typeof(NamespaceDecl).Name, SerializeSpan(x.Span),
                                new NodeObj("Name", x.QualifiedName.QualifiedName.NamespacePhpName),
                                new NodeObj("SimpleSyntax", x.IsSimpleSyntax.ToString()),
                                SerializeNamingContext(x.Naming));
     SerializePHPDoc(x.PHPDoc);
     SerializeOptionalProperty("Body", x.Body);
     _serializer.EndSerialize();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Visit declaration of namespace.
 /// </summary>
 /// <param name="x">NamespaceDecl</param>
 public override void VisitNamespaceDecl(NamespaceDecl x)
 {
     if (x.Statements != null)
     {
         foreach (Statement s in x.Statements)
         {
             s.VisitMe(this);
         }
     }
 }
Exemplo n.º 8
0
 // Looks up a namespace in the list of current namespaces in scope
 string LookupNamespace(string prefix, NamespaceDecl namespacesInScope)
 {
     while (namespacesInScope != null)
     {
         if (prefix == namespacesInScope.prefix)
         {
             return(namespacesInScope.namespaceUri);
         }
         namespacesInScope = namespacesInScope.previousDecl;
     }
     return(null);
 }
Exemplo n.º 9
0
//
// Constructor
//
        public XmlBookmarkReader(XmlReader reader)
        {
            this.reader = reader;

            // initialize namespaces
            XmlNameTable nt = reader.NameTable;

            currentNamespacesInScope = new NamespaceDecl(nt.Add("xml"), nt.Add("http://www.w3.org/XML/1998/namespace"), null);
            currentNamespacesInScope = new NamespaceDecl(nt.Add("xmlns"), nt.Add("http://www.w3.org/2000/xmlns/"), currentNamespacesInScope);
            currentNamespacesInScope = new NamespaceDecl(nt.Add(string.Empty), nt.Add(string.Empty), currentNamespacesInScope);
            currentNamespacesInScope.scopeCount++;
            nextNamespacesInScope = currentNamespacesInScope;

            bookmarks = new Hashtable();
        }
Exemplo n.º 10
0
            internal CachedXmlNode(XmlNodeType nodeType, string name, string localName, string prefix, string namespaceUri, string value, int depth, NamespaceDecl namespacesInScope, CachedXmlNode next)
            {
                this.nodeType          = nodeType;
                this.name              = name;
                this.localName         = localName;
                this.prefix            = prefix;
                this.namespaceUri      = namespaceUri;
                this.value             = value;
                this.depth             = depth;
                this.namespacesInScope = namespacesInScope;
                this.next              = next;

                isDefaultOrEmpty = false;
                this.attributes  = null;
            }
Exemplo n.º 11
0
        // On element start tag it walks though the attributes of an element to find all namespace declaration and adds them to the namespace tree.
        // On End tag it adjusts the reference to the next namespace scope which will be applies on the next Read
        void ProcessNamespaces()
        {
            NamespaceDecl originalNamespaces = currentNamespacesInScope;
            XmlNodeType   nodeType           = reader.NodeType;

            switch (nodeType)
            {
            case XmlNodeType.Element:
                if (reader.MoveToFirstAttribute())
                {
                    do
                    {
                        if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                        {
                            // add namespace
                            string prefix = (reader.Prefix.Length == 0) ? string.Empty : reader.LocalName;
                            currentNamespacesInScope = new NamespaceDecl(prefix, reader.NameTable.Add(reader.Value), currentNamespacesInScope);
                        }
                    } while (reader.MoveToNextAttribute());
                    reader.MoveToElement();
                }
                if (reader.IsEmptyElement)
                {
                    nextNamespacesInScope = originalNamespaces;
                }
                else
                {
                    nextNamespacesInScope = currentNamespacesInScope;
                    // push scope
                    currentNamespacesInScope.scopeCount++;
                }
                break;

            case XmlNodeType.EndElement:
                // pop scope
                NamespaceDecl decl = currentNamespacesInScope;
                decl.scopeCount--;
                while (decl.scopeCount == 0)
                {
                    decl = decl.previousDecl;
                }
                nextNamespacesInScope = decl;
                break;
            }
        }
Exemplo n.º 12
0
        public override bool Read()
        {
            // have current node -> we are replaying
            if (curNode != null)
            {
                // recover from iterating over attributes
                if (curAttrParent != null)
                {
                    curNode = curAttrParent;
                    if (attributeTextValue != null)
                    {
                        attributeTextValue.next = null;
                    }
                }
                // move to next node in the list
                if (curNode.next != null)
                {
                    SetCurrentNode(curNode.next);
                    return(true);
                }
                // end of cached nodes
                else
                {
                    curNode = null;
                }
            }

            // pop namespace scope if previous node was an end element or an empty element
            currentNamespacesInScope = nextNamespacesInScope;

            // read next node from the reader
            if (!reader.Read())
            {
                return(false);
            }
            // save namespaces
            ProcessNamespaces();

            // have some bookmark need to cache the node
            if (bookmarks.Count > 0)
            {
                CacheCurrentNode();
            }
            return(true);
        }
Exemplo n.º 13
0
        private static void ListPrepend <T>(object /*!*/ list, object /*!*/ item)
        {
            Debug.Assert(list != null);
            Debug.Assert(item != null);
            Debug.Assert(item is T);

            var tlist = (List <T>)list;

            // little hack when prepending simple syntaxed namespace before some statements:

            // namespace A;  // == {item}
            // stmt1; stmt2; // <-- add these stamenents into namespace A
            // namespace B;

            NamespaceDecl nsitem = item as NamespaceDecl;

            if (nsitem != null && nsitem.IsSimpleSyntax)
            {
                Debug.Assert(list is List <Statement>);
                var slist = (List <Statement>)list;

                // move statements into nsitem namespace:
                int i = 0;  // find how many Statements from tlist move to nsitem.Statements
                while (i < slist.Count && !(slist[i] is NamespaceDecl))
                {
                    ++i;
                }

                if (i > 0)
                {
                    nsitem.Statements.AddRange(slist.Take(i));
                    //nsitem.UpdatePosition(Position.CombinePositions(nsitem.Position, slist[i - 1].Position));
                    tlist.RemoveRange(0, i);
                }
            }

            // prepend the item:
            tlist.Insert(0, (T)item);
        }
Exemplo n.º 14
0
        public override void VisitNamespaceDecl(NamespaceDecl x)
        {
            ConsumeToken(Tokens.T_NAMESPACE, "namespace", x.Span.Start);

            if (x.QualifiedName.HasValue)
            {
                VisitQualifiedName(x.QualifiedName.QualifiedName.WithFullyQualified(false));
            }

            if (x.IsSimpleSyntax)
            {
                // namespace QNAME; BODY
                ConsumeToken(Tokens.T_SEMI, ";");
                VisitList(x.Body.Statements);
            }
            else
            {
                // namespace QNAME { BODY }
            }

            VisitElement(x.Body);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Combines name and its namespace.
 /// </summary>
 /// <param name="name">Name.</param>
 /// <param name="ns">Can be <c>null</c>.</param>
 /// <returns></returns>
 public static QualifiedName MakeQualifiedName(Name name, NamespaceDecl ns)
 {
     return (ns != null && ns.QualifiedName.HasValue)
         ? new QualifiedName(name, ns.QualifiedName.QualifiedName.Namespaces)
         : new QualifiedName(name);
 }
Exemplo n.º 16
0
 public override void VisitNamespaceDecl(NamespaceDecl x)
 {
     _statementContext = VariableKind.GlobalVariable;
     base.VisitNamespaceDecl(x);
 }
Exemplo n.º 17
0
 public void NamespaceDeclReduced(Parser parser, NamespaceDecl decl)
 {
 }
Exemplo n.º 18
0
 void PopNamespaces(NamespaceDecl firstInScopeChain) {
     NamespaceDecl decl = firstInScopeChain;
     while (null != decl) {
         if (null == decl.prevLink)
             this.namespaces.Remove(decl.prefix);
         else
             this.namespaces[decl.prefix] = decl.prevLink;
         NamespaceDecl next = decl.scopeLink;
         // unlink chains for better gc behaviour 
         decl.prevLink = null;
         decl.scopeLink = null;
         decl = next;
     }
 }
Exemplo n.º 19
0
        static SymbolDecl[] ParseSymbolInternal(string[] tokens, ref int index)
        {
            if (CppParser.Token(tokens, ref index, "public") || CppParser.Token(tokens, ref index, "protected") || CppParser.Token(tokens, ref index, "private"))
            {
                index--;
                return(null);
            }
            TemplateDecl templateDecl = null;

            if (CppParser.Token(tokens, ref index, "template"))
            {
                templateDecl = new TemplateDecl
                {
                    TypeParameters = new List <TypeParameterDecl>(),
                    Specialization = new List <TypeDecl>(),
                };
                CppParser.EnsureToken(tokens, ref index, "<");
                if (!CppParser.Token(tokens, ref index, ">"))
                {
                    while (true)
                    {
                        string token = null;
                        CppParser.SkipUntilInTemplate(tokens, ref index, out token, ",", ">", "=");

                        index -= 2;
                        templateDecl.TypeParameters.Add(new TypeParameterDecl
                        {
                            Name = CppParser.EnsureId(tokens, ref index),
                        });
                        index++;

                        if (token == "=")
                        {
                            CppParser.SkipUntilInTemplate(tokens, ref index, out token, ",", ">");
                        }

                        if (token == ">")
                        {
                            break;
                        }
                    }
                }
            }

            if (CppParser.Token(tokens, ref index, "friend"))
            {
                int    oldIndex = index - 1;
                string token    = null;
                CppParser.SkipUntil(tokens, ref index, out token, ";", "{");
                if (token == ";")
                {
                    return(null);
                }
                else
                {
                    index         = oldIndex;
                    tokens[index] = "static";
                }
            }

            if (CppParser.Token(tokens, ref index, "namespace"))
            {
                if (templateDecl != null)
                {
                    throw new ArgumentException("Failed to parse.");
                }
                var decl = new NamespaceDecl();
                decl.Name = CppParser.EnsureId(tokens, ref index);

                CppParser.EnsureToken(tokens, ref index, "{");
                ParseSymbols(tokens, ref index, decl);
                CppParser.EnsureToken(tokens, ref index, "}");

                return(new SymbolDecl[] { decl });
            }
            else if (CppParser.Token(tokens, ref index, "using"))
            {
                if (CppParser.Token(tokens, ref index, "namespace"))
                {
                    if (templateDecl != null)
                    {
                        throw new ArgumentException("Failed to parse.");
                    }
                    var decl = new UsingNamespaceDecl();
                    decl.Path = new List <string>();
                    decl.Path.Add(CppParser.EnsureId(tokens, ref index));

                    while (!CppParser.Token(tokens, ref index, ";"))
                    {
                        CppParser.EnsureToken(tokens, ref index, ":");
                        CppParser.EnsureToken(tokens, ref index, ":");
                        decl.Path.Add(CppParser.EnsureId(tokens, ref index));
                    }

                    return(new SymbolDecl[] { decl });
                }
                else
                {
                    string name = null;
                    if (CppParser.Id(tokens, ref index, out name))
                    {
                        if (templateDecl != null)
                        {
                            if (CppParser.Token(tokens, ref index, "<"))
                            {
                                while (true)
                                {
                                    templateDecl.Specialization.Add(CppTypeParser.EnsureTypeWithoutName(tokens, ref index));
                                    if (CppParser.Token(tokens, ref index, ">"))
                                    {
                                        break;
                                    }
                                    CppParser.EnsureToken(tokens, ref index, ",");
                                }
                            }
                        }
                        if (CppParser.Token(tokens, ref index, "="))
                        {
                            SymbolDecl decl = new TypedefDecl
                            {
                                Name = name,
                                Type = CppTypeParser.EnsureTypeWithoutName(tokens, ref index),
                            };
                            CppParser.EnsureToken(tokens, ref index, ";");

                            if (templateDecl != null)
                            {
                                templateDecl.Element = decl;
                                decl = templateDecl;
                            }
                            return(new SymbolDecl[] { decl });
                        }
                    }
                    if (templateDecl != null)
                    {
                        throw new ArgumentException("Failed to parse.");
                    }
                    CppParser.SkipUntil(tokens, ref index, ";");
                }
            }
            else if (CppParser.Token(tokens, ref index, "typedef"))
            {
                if (templateDecl != null)
                {
                    throw new ArgumentException("Failed to parse.");
                }
                string name = null;
                var    type = CppTypeParser.EnsureTypeWithName(tokens, ref index, out name);
                CppParser.EnsureToken(tokens, ref index, ";");

                var decl = new TypedefDecl();
                decl.Name = name;
                decl.Type = type;
                return(new SymbolDecl[] { decl });
            }
            else if (CppParser.Token(tokens, ref index, "enum"))
            {
                if (templateDecl != null)
                {
                    throw new ArgumentException("Failed to parse.");
                }
                bool   enumClass = CppParser.Token(tokens, ref index, "class");
                string name      = CppParser.EnsureId(tokens, ref index);
                if (CppParser.Token(tokens, ref index, ":"))
                {
                    CppTypeParser.EnsureTypeWithoutName(tokens, ref index);
                }
                if (!CppParser.Token(tokens, ref index, ";"))
                {
                    CppParser.EnsureToken(tokens, ref index, "{");
                    var decl = new EnumDecl
                    {
                        Name      = name,
                        EnumClass = enumClass,
                        Children  = new List <SymbolDecl>(),
                    };

                    while (true)
                    {
                        if (CppParser.Token(tokens, ref index, "}"))
                        {
                            break;
                        }

                        while (index < tokens.Length && tokens[index].Length >= 3 && tokens[index].StartsWith("///"))
                        {
                            index++;
                        }
                        decl.Children.Add(new EnumItemDecl
                        {
                            Name = CppParser.EnsureId(tokens, ref index),
                        });

                        string token = null;
                        CppParser.SkipUntil(tokens, ref index, out token, ",", "}");
                        if (token == "}")
                        {
                            break;
                        }
                    }

                    if (CppParser.Id(tokens, ref index, out name))
                    {
                        var varDecl = new VarDecl
                        {
                            Static = false,
                            Name   = name,
                            Type   = new RefTypeDecl
                            {
                                Name = decl.Name,
                            },
                        };
                        CppParser.EnsureToken(tokens, ref index, ";");
                        return(new SymbolDecl[] { decl, varDecl });
                    }
                    else
                    {
                        CppParser.EnsureToken(tokens, ref index, ";");
                        return(new SymbolDecl[] { decl });
                    }
                }
            }
            else if (CppParser.Token(tokens, ref index, "struct") || CppParser.Token(tokens, ref index, "class") || CppParser.Token(tokens, ref index, "union"))
            {
                if (CppParser.Token(tokens, ref index, "{"))
                {
                    if (tokens[index - 2] == "class")
                    {
                        throw new ArgumentException("Failed to parse.");
                    }

                    var decl = new GroupedFieldDecl
                    {
                        Grouping = tokens[index - 2] == "struct" ? Grouping.Struct : Grouping.Union,
                    };
                    ParseSymbols(tokens, ref index, decl);
                    CppParser.EnsureToken(tokens, ref index, "}");
                    CppParser.EnsureToken(tokens, ref index, ";");
                    return(new SymbolDecl[] { decl });
                }
                else
                {
                    string name = CppParser.EnsureId(tokens, ref index);
                    if (!CppParser.Token(tokens, ref index, ";"))
                    {
                        var classDecl = new ClassDecl
                        {
                            ClassType =
                                tokens[index - 2] == "struct" ? ClassType.Struct :
                                tokens[index - 2] == "class" ? ClassType.Class :
                                ClassType.Union,
                            BaseTypes = new List <BaseTypeDecl>(),
                            Name      = name,
                        };

                        if (templateDecl != null)
                        {
                            if (CppParser.Token(tokens, ref index, "<"))
                            {
                                if (!CppParser.Token(tokens, ref index, ">"))
                                {
                                    while (true)
                                    {
                                        int oldIndex = index;
                                        try
                                        {
                                            templateDecl.Specialization.Add(CppTypeParser.EnsureTypeWithoutName(tokens, ref index));
                                        }
                                        catch (ArgumentException)
                                        {
                                            index = oldIndex;
                                            CppParser.SkipUntilInTemplate(tokens, ref index, ",", ">");
                                            index--;

                                            templateDecl.Specialization.Add(new ConstantTypeDecl
                                            {
                                                Value = tokens
                                                        .Skip(oldIndex)
                                                        .Take(index - oldIndex)
                                                        .Aggregate((a, b) => a + " " + b),
                                            });
                                        }
                                        if (CppParser.Token(tokens, ref index, ">"))
                                        {
                                            break;
                                        }
                                        CppParser.EnsureToken(tokens, ref index, ",");
                                    }
                                }
                            }
                        }

                        CppParser.Token(tokens, ref index, "abstract");
                        if (CppParser.Token(tokens, ref index, ":"))
                        {
                            while (true)
                            {
                                Access access = classDecl.ClassType == ClassType.Class ? Access.Private : Access.Public;
                                CppParser.Token(tokens, ref index, "virtual");
                                if (CppParser.Token(tokens, ref index, "private"))
                                {
                                    access = Access.Private;
                                }
                                else if (CppParser.Token(tokens, ref index, "protected"))
                                {
                                    access = Access.Protected;
                                }
                                else if (CppParser.Token(tokens, ref index, "public"))
                                {
                                    access = Access.Public;
                                }
                                CppParser.Token(tokens, ref index, "virtual");
                                classDecl.BaseTypes.Add(new BaseTypeDecl
                                {
                                    Access = access,
                                    Type   = CppTypeParser.EnsureTypeWithoutName(tokens, ref index),
                                });
                                if (!CppParser.Token(tokens, ref index, ","))
                                {
                                    break;
                                }
                            }
                        }

                        CppParser.EnsureToken(tokens, ref index, "{");
                        while (true)
                        {
                            if (CppParser.Token(tokens, ref index, "}"))
                            {
                                break;
                            }

                            Access access = classDecl.ClassType == ClassType.Class ? Access.Private : Access.Public;
                            if (CppParser.Token(tokens, ref index, "private"))
                            {
                                access = Access.Private;
                                CppParser.EnsureToken(tokens, ref index, ":");
                            }
                            else if (CppParser.Token(tokens, ref index, "protected"))
                            {
                                access = Access.Protected;
                                CppParser.EnsureToken(tokens, ref index, ":");
                            }
                            else if (CppParser.Token(tokens, ref index, "public"))
                            {
                                access = Access.Public;
                                CppParser.EnsureToken(tokens, ref index, ":");
                            }
                            ParseSymbols(tokens, ref index, classDecl, access);
                        }

                        SymbolDecl decl = classDecl;
                        if (templateDecl != null)
                        {
                            templateDecl.Element = decl;
                            decl = templateDecl;
                        }

                        if (CppParser.Id(tokens, ref index, out name))
                        {
                            var varDecl = new VarDecl
                            {
                                Static = false,
                                Name   = name,
                                Type   = new RefTypeDecl
                                {
                                    Name = classDecl.Name,
                                },
                            };
                            CppParser.EnsureToken(tokens, ref index, ";");
                            return(new SymbolDecl[] { decl, varDecl });
                        }
                        else
                        {
                            CppParser.EnsureToken(tokens, ref index, ";");
                            return(new SymbolDecl[] { decl });
                        }
                    }
                }
            }
            else if (!CppParser.Token(tokens, ref index, ";"))
            {
                Function function = Function.Function;
                {
                    int    oldIndex = index;
                    string name     = null;
                    if (CppParser.Id(tokens, ref index, out name))
                    {
                        if (CppParser.Token(tokens, ref index, "("))
                        {
                            CppParser.SkipUntil(tokens, ref index, ")");
                            if (CppParser.Token(tokens, ref index, ";") || CppParser.Token(tokens, ref index, "=") || CppParser.Token(tokens, ref index, ":") || CppParser.Token(tokens, ref index, "{"))
                            {
                                function = Function.Constructor;
                            }
                        }
                        index = oldIndex;
                    }
                    else if (CppParser.Token(tokens, ref index, "~"))
                    {
                        function = Function.Destructor;
                    }
                }

                if (function == Function.Function)
                {
                    Virtual virtualFunction = Virtual.Normal;
                    CppParser.Token(tokens, ref index, "extern");
                    CppParser.Token(tokens, ref index, "mutable");
                    if (CppParser.Token(tokens, ref index, "virtual"))
                    {
                        virtualFunction = Virtual.Virtual;
                    }
                    else if (CppParser.Token(tokens, ref index, "static"))
                    {
                        virtualFunction = Virtual.Static;
                    }
                    CppParser.Token(tokens, ref index, "inline");
                    CppParser.Token(tokens, ref index, "__forceinline");

                    if (CppParser.Token(tokens, ref index, "operator"))
                    {
                        TypeDecl returnType = null;
                        {
                            int oldIndex = index;
                            CppParser.SkipUntilInTemplate(tokens, ref index, "(");
                            int modify = --index;

                            tokens[modify] = "$";
                            index          = oldIndex;
                            returnType     = CppTypeParser.EnsureTypeWithoutName(tokens, ref index);
                            if (index != modify)
                            {
                                throw new ArgumentException("Failed to parse.");
                            }
                            tokens[modify] = "(";
                        }
                        var decl = new FuncDecl
                        {
                            Virtual  = Virtual.Normal,
                            Name     = "operator",
                            Function = function,
                        };

                        TypeDecl          functionType      = null;
                        Action <TypeDecl> continuation      = null;
                        CallingConvention callingConvention = CallingConvention.Default;
                        CppTypeParser.ParseTypeContinueAfterName(tokens, ref index, ref callingConvention, out functionType, out continuation);
                        continuation(returnType);
                        decl.Type = functionType;

                        if (!CppParser.Token(tokens, ref index, ";"))
                        {
                            CppParser.EnsureToken(tokens, ref index, "{");
                            CppParser.SkipUntil(tokens, ref index, "}");
                        }

                        if (templateDecl != null)
                        {
                            templateDecl.Element = decl;
                            return(new SymbolDecl[] { templateDecl });
                        }
                        else
                        {
                            return(new SymbolDecl[] { decl });
                        }
                    }
                    else
                    {
                        string   name = null;
                        TypeDecl type = null;
                        if (CppTypeParser.ParseType(tokens, ref index, out type, out name))
                        {
                            if (name == null)
                            {
                                throw new ArgumentException("Failed to parse.");
                            }

                            if (type is FunctionTypeDecl)
                            {
                                if (CppParser.Token(tokens, ref index, "="))
                                {
                                    if (CppParser.Token(tokens, ref index, "0"))
                                    {
                                        virtualFunction = Virtual.Abstract;
                                    }
                                    else
                                    {
                                        CppParser.EnsureToken(tokens, ref index, "default", "delete");
                                    }
                                }

                                var decl = new FuncDecl
                                {
                                    Virtual  = virtualFunction,
                                    Name     = name,
                                    Type     = type,
                                    Function = Function.Function,
                                };
                                if (!CppParser.Token(tokens, ref index, ";"))
                                {
                                    CppParser.EnsureToken(tokens, ref index, "{");
                                    CppParser.SkipUntil(tokens, ref index, "}");
                                }

                                if (templateDecl != null)
                                {
                                    templateDecl.Element = decl;
                                    return(new SymbolDecl[] { templateDecl });
                                }
                                else
                                {
                                    return(new SymbolDecl[] { decl });
                                }
                            }
                            else
                            {
                                if (virtualFunction != Virtual.Normal && virtualFunction != Virtual.Static)
                                {
                                    throw new ArgumentException("Failed to parse.");
                                }
                                if (CppParser.Token(tokens, ref index, "="))
                                {
                                    CppParser.SkipUntil(tokens, ref index, ";");
                                }
                                else
                                {
                                    CppParser.EnsureToken(tokens, ref index, ";");
                                }

                                if (!(type is ClassMemberTypeDecl))
                                {
                                    var decl = new VarDecl
                                    {
                                        Static = virtualFunction == Virtual.Static,
                                        Name   = name,
                                        Type   = type,
                                    };
                                    return(new SymbolDecl[] { decl });
                                }
                            }
                        }
                    }
                }
                else
                {
                    var decl = new FuncDecl
                    {
                        Virtual  = Virtual.Normal,
                        Name     = (function == Function.Constructor ? "" : "~") + CppParser.EnsureId(tokens, ref index),
                        Function = function,
                    };

                    TypeDecl          functionType      = null;
                    Action <TypeDecl> continuation      = null;
                    CallingConvention callingConvention = CallingConvention.Default;
                    CppTypeParser.ParseTypeContinueAfterName(tokens, ref index, ref callingConvention, out functionType, out continuation);
                    continuation(new RefTypeDecl
                    {
                        Name = "void"
                    });
                    decl.Type = functionType;

                    if (CppParser.Token(tokens, ref index, "="))
                    {
                        CppParser.EnsureToken(tokens, ref index, "default", "delete");
                    }

                    if (!CppParser.Token(tokens, ref index, ";"))
                    {
                        if (CppParser.Token(tokens, ref index, ":"))
                        {
                            CppParser.SkipUntil(tokens, ref index, "{");
                        }
                        else
                        {
                            CppParser.EnsureToken(tokens, ref index, "{");
                        }
                        CppParser.SkipUntil(tokens, ref index, "}");
                    }

                    if (templateDecl != null)
                    {
                        templateDecl.Element = decl;
                        return(new SymbolDecl[] { templateDecl });
                    }
                    else
                    {
                        return(new SymbolDecl[] { decl });
                    }
                }
            }
            return(null);
        }
Exemplo n.º 20
0
 public NamespaceDecl(string prefix, string nsuri,
                     NamespaceDecl nextInScope, NamespaceDecl prevDecl,
                     int scope, bool implied) {
     this.prefix = prefix;
     this.uri = nsuri;
     this.scopeLink = nextInScope;
     this.prevLink = prevDecl;
     this.scope = scope;
     this.implied = implied;
 }
Exemplo n.º 21
0
 void PushNamespace(string prefix, string ns, bool implied) {
     if (prefix == "xml")
         return;
     int elemDepth = this.elemDepth;
     NamespaceDecl curDecl;
     this.namespaces.TryGetValue(prefix, out curDecl);
     if (null != curDecl) {
         if (curDecl.uri == ns) {
             // if we see the nsdecl after we saw the first reference in this scope
             // fix up 'implied' flag
             if (!implied && curDecl.implied
                 && (curDecl.scope == elemDepth)) {
                 curDecl.implied = false;
             }
             return;
         }
         // check that this doesn't conflict
         this.qnameElement.CheckPrefixNS(prefix, ns);
         if (prefix.Length != 0) {
             for (int i = 0; i < this.attrCount; i++) {
                 if (this.attributes[i].name.prefix.Length != 0)
                     this.attributes[i].name.CheckPrefixNS(prefix, ns);
             }
         }
     }
     // actually add ns decl
     NamespaceDecl decl = new NamespaceDecl(prefix, ns,
         this.elementStack[elemDepth].nsdecls,
         curDecl, elemDepth, implied);
     this.elementStack[elemDepth].nsdecls = decl;
     this.namespaces[prefix] = decl;
 }
Exemplo n.º 22
0
 public SourceNamespaceSymbol(SourceModuleSymbol module, NamespaceDecl ns)
 {
     _sourceModule = module;
     _name         = ns.QualifiedName.QualifiedName.ClrName();
 }
Exemplo n.º 23
0
 internal NamespaceDecl(string prefix, string namespaceUri, NamespaceDecl previousDecl)
 {
     this.prefix       = prefix;
     this.namespaceUri = namespaceUri;
     this.previousDecl = previousDecl;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Combines name and its namespace.
 /// </summary>
 /// <param name="name">Name.</param>
 /// <param name="ns">Can be <c>null</c>.</param>
 /// <returns></returns>
 public static QualifiedName MakeQualifiedName(Name name, NamespaceDecl ns)
 {
     return((ns != null && ns.QualifiedName.HasValue)
         ? new QualifiedName(name, ns.QualifiedName.QualifiedName.Namespaces)
         : new QualifiedName(name));
 }
Exemplo n.º 25
0
 void SymbolDecl.IVisitor.Visit(NamespaceDecl decl)
 {
     throw new ArgumentOutOfRangeException();
 }
 private void PushNamespace(string prefix, string ns, bool implied)
 {
     if (prefix != "xml")
     {
         NamespaceDecl decl;
         int elemDepth = this.elemDepth;
         this.namespaces.TryGetValue(prefix, out decl);
         if (decl != null)
         {
             if (decl.uri == ns)
             {
                 if ((!implied && decl.implied) && (decl.scope == elemDepth))
                 {
                     decl.implied = false;
                 }
                 return;
             }
             this.qnameElement.CheckPrefixNS(prefix, ns);
             if (prefix.Length != 0)
             {
                 for (int i = 0; i < this.attrCount; i++)
                 {
                     if (this.attributes[i].name.prefix.Length != 0)
                     {
                         this.attributes[i].name.CheckPrefixNS(prefix, ns);
                     }
                 }
             }
         }
         NamespaceDecl decl2 = new NamespaceDecl(prefix, ns, this.elementStack[elemDepth].nsdecls, decl, elemDepth, implied);
         this.elementStack[elemDepth].nsdecls = decl2;
         this.namespaces[prefix] = decl2;
     }
 }
 private void PopNamespaces(NamespaceDecl firstInScopeChain)
 {
     NamespaceDecl scopeLink;
     for (NamespaceDecl decl = firstInScopeChain; decl != null; decl = scopeLink)
     {
         if (decl.prevLink == null)
         {
             this.namespaces.Remove(decl.prefix);
         }
         else
         {
             this.namespaces[decl.prefix] = decl.prevLink;
         }
         scopeLink = decl.scopeLink;
         decl.prevLink = null;
         decl.scopeLink = null;
     }
 }
Exemplo n.º 28
0
 /// <summary>
 /// Create naming context.
 /// </summary>
 /// <param name="ns">Current namespace declaration. In case it is <c>null</c>, context for global code is created.</param>
 /// <param name="unit">Global code used when <paramref name="ns"/> is <c>null</c>.</param>
 /// <returns>Naming context. Cannot be <c>null</c>.</returns>
 public static NamingContext GetNamingContext(NamespaceDecl ns, SourceUnit unit)
 {
     return (ns != null) ? ns.Naming : unit.Naming;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Create naming context.
 /// </summary>
 /// <param name="ns">Current namespace declaration. In case it is <c>null</c>, context for global code is created.</param>
 /// <param name="unit">Global code used when <paramref name="ns"/> is <c>null</c>.</param>
 /// <returns>Naming context. Cannot be <c>null</c>.</returns>
 public static NamingContext GetNamingContext(NamespaceDecl ns, SourceUnit unit)
 {
     return((ns != null) ? ns.Naming : unit.Naming);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Combines name and its namespace.
 /// </summary>
 /// <param name="name">Name.</param>
 /// <param name="ns">Can be <c>null</c>.</param>
 /// <returns></returns>
 public static QualifiedName MakeQualifiedName(Name name, NamespaceDecl ns)
 {
     return((ns == null || ns.QualifiedName.Namespaces.Length == 0) ?
            new QualifiedName(name) :
            new QualifiedName(name, ns.QualifiedName.Namespaces));
 }
Exemplo n.º 31
0
 /// <summary>
 /// Visit namespace statements.
 /// </summary>
 /// <param name="x"></param>
 virtual public void VisitNamespaceDecl(NamespaceDecl x)
 {
     VisitElement(x.Body);
 }
Exemplo n.º 32
0
 /// <summary>
 /// Visit a namespace declaration
 /// </summary>
 private void VisitNamespaceDecl(NamespaceDecl namespaceDecl, TraversalData traversalData)
 {
     traversalData.AddNamespace(namespaceDecl.ToString());
     Visit(namespaceDecl.Decls, traversalData);
     traversalData.RemoveNamespace();
 }
Exemplo n.º 33
0
 void AddInitNamespace(string prefix, string uri) {
     NamespaceDecl nsdecl = new NamespaceDecl(prefix, uri, this.elementStack[0].nsdecls, null, -1, true);
     this.elementStack[0].nsdecls = nsdecl;
     this.namespaces.Add(prefix, nsdecl);
 }
Exemplo n.º 34
0
 internal CachedXmlNode(XmlReader reader, NamespaceDecl namespacesInScope, CachedXmlNode next) :
     this(reader.NodeType, reader.Name, reader.LocalName, reader.Prefix, reader.NamespaceURI, reader.Value, reader.Depth, namespacesInScope, next)
 {
 }
Exemplo n.º 35
0
 /// <summary>
 /// Create naming context.
 /// </summary>
 /// <param name="ns">Current namespace declaration. In case it is <c>null</c>, context for global code is created.</param>
 /// <param name="ast">Global code used when <paramref name="ns"/> is <c>null</c>.</param>
 /// <returns>Naming context. Cannot be <c>null</c>.</returns>
 public static NamingContext GetNamingContext(NamespaceDecl ns, GlobalCode ast)
 {
     return((ns != null)
         ? ns.Naming
         : ast.SourceUnit.Naming);
 }
Exemplo n.º 36
0
 public NamespaceDecl Clear() {
     NamespaceDecl nsdecls = this.nsdecls;
     this.nsdecls = null;
     return nsdecls;
 }