public override void CaseANamespaceDecl(ANamespaceDecl node)
        {
            string lastNamespace = currentNamespace;

            currentNamespace += node.GetName().Text + "_";
            base.CaseANamespaceDecl(node);
            currentNamespace = lastNamespace;
            while (node.GetDecl().Count > 0)
            {
                PDecl decl = (PDecl)node.GetDecl()[0];
                node.RemoveChild(decl);
                if (node.Parent() is ANamespaceDecl)
                {
                    ANamespaceDecl parent = (ANamespaceDecl)node.Parent();
                    parent.GetDecl().Insert(parent.GetDecl().IndexOf(node), decl);
                }
                else
                {
                    AASourceFile parent = (AASourceFile)node.Parent();
                    parent.GetDecl().Insert(parent.GetDecl().IndexOf(node), decl);
                }
            }
            node.Parent().RemoveChild(node);
        }
Exemple #2
0
        public override void CaseATempNamespaceDecl(ATempNamespaceDecl node)
        {
            ANamespaceDecl replacer = null;
            Node           parent   = node.Parent();
            IList          declList;

            if (parent is ANamespaceDecl)
            {
                declList = ((ANamespaceDecl)parent).GetDecl();
            }
            else
            {
                declList = ((AASourceFile)parent).GetDecl();
            }
            parent.RemoveChild(node);

            List <TIdentifier> identifiers = new List <TIdentifier>();

            foreach (TIdentifier identifier in node.GetName())
            {
                identifiers.Add(identifier);
            }

            foreach (TIdentifier identifier in identifiers)
            {
                TRBrace endToken = null;
                if (node.GetEndToken() != null)
                {
                    endToken = new TRBrace("}", node.GetEndToken().Line, node.GetEndToken().Pos);
                }
                ANamespaceDecl ns = new ANamespaceDecl(new TNamespace("namespace", node.GetToken().Line, node.GetToken().Pos), identifier, new ArrayList(), endToken);
                if (replacer == null)
                {
                    replacer = ns;
                }
                declList.Add(ns);
                declList = ns.GetDecl();
            }
            while (node.GetDecl().Count > 0)
            {
                declList.Add(node.GetDecl()[0]);
            }
            replacer.Apply(this);
        }
Exemple #3
0
        public static List <IList> GetVisibleDecls(Node node, bool includeUsings)
        {
            List <IList>          returner          = new List <IList>();
            AASourceFile          currentSourceFile = GetAncestor <AASourceFile>(node);
            List <List <string> > usedNamespaces    = new List <List <string> >();

            if (includeUsings)
            {
                foreach (AUsingDecl usingDecl in currentSourceFile.GetUsings())
                {
                    List <string> ns = new List <string>();
                    foreach (TIdentifier identifier in usingDecl.GetNamespace())
                    {
                        ns.Add(identifier.Text);
                    }
                    // ns.Reverse();
                    usedNamespaces.Add(ns);
                }
            }
            {
                List <string> currentNS = GetFullNamespace(node);
                if (currentNS.Count > 0)
                {
                    usedNamespaces.Add(currentNS);
                }
            }
            List <IList> currentList = new List <IList>();
            List <IList> nextList    = new List <IList>();
            AAProgram    program     = GetAncestor <AAProgram>(currentSourceFile);

            foreach (AASourceFile sourceFile in program.GetSourceFiles())
            {
                currentList.Add(sourceFile.GetDecl());
                returner.Add(sourceFile.GetDecl());
            }
            while (currentList.Count > 0)
            {
                foreach (IList declList in currentList)
                {
                    foreach (PDecl decl in declList)
                    {
                        if (decl is ANamespaceDecl)
                        {
                            ANamespaceDecl aDecl  = (ANamespaceDecl)decl;
                            List <string>  ns     = GetFullNamespace(decl);
                            bool           prefix = false;
                            bool           match  = false;
                            foreach (List <string> usedNamespace in usedNamespaces)
                            {
                                if (NamespacePrefix(ns, usedNamespace))
                                {
                                    prefix = true;
                                    if (NamespacesEquals(ns, usedNamespace))
                                    {
                                        match = true;
                                        break;
                                    }
                                }
                            }
                            if (prefix)
                            {
                                nextList.Add(aDecl.GetDecl());
                            }
                            if (match)
                            {
                                returner.Add(aDecl.GetDecl());
                            }
                        }
                    }
                }
                currentList = nextList;
                nextList    = new List <IList>();
            }
            return(returner);
        }