public override void CaseANamespaceDecl(ANamespaceDecl node)
            {
                if (isFirst)
                {
                    base.CaseANamespaceDecl(node);
                    return;
                }
                NamespaceDescription ns = new NamespaceDescription(node);

                Namespaces.Add(ns);
            }
Exemple #2
0
        public static List <string> GetFullNamespace(Node node)
        {
            List <string>  currentNamespace = new List <string>();
            ANamespaceDecl n = GetAncestor <ANamespaceDecl>(node);

            while (n != null)
            {
                currentNamespace.Add(n.GetName().Text);
                n = GetAncestor <ANamespaceDecl>(n.Parent());
            }
            currentNamespace.Reverse();
            return(currentNamespace);
        }
Exemple #3
0
            public override void CaseANamedType(ANamedType node)
            {
                AAName name = (AAName)node.GetName();

                if (name.GetIdentifier().Count > 2)
                {
                    return;
                }
                if (name.GetIdentifier().Count == 2 && ((TIdentifier)name.GetIdentifier()[0]).Text != "Dialogs")
                {
                    return;
                }
                if (name.GetIdentifier().Count == 1)
                {
                    bool         foundDialogs = false;
                    AASourceFile file         = Util.GetAncestor <AASourceFile>(node);
                    foreach (AUsingDecl usingDecl in file.GetUsings())
                    {
                        if (usingDecl.GetNamespace().Count == 1)
                        {
                            TIdentifier identifer = (TIdentifier)usingDecl.GetNamespace()[0];
                            if (identifer.Text == "Dialogs")
                            {
                                foundDialogs = true;
                                break;
                            }
                        }
                    }
                    if (!foundDialogs)
                    {
                        ANamespaceDecl ns = Util.GetAncestor <ANamespaceDecl>(node);
                        if (!Util.HasAncestor <ANamespaceDecl>(ns.Parent()) && ns.GetName().Text == "Dialogs")
                        {
                            foundDialogs = true;
                        }
                    }
                    if (!foundDialogs)
                    {
                        return;
                    }
                }
                if (((TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]).Text == oldName)
                {
                    types.Add((TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]);
                }
            }
Exemple #4
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);
        }
        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);
        }
        public NamespaceDescription(ANamespaceDecl ns)
        {
            decl     = ns;
            LineFrom = decl.GetToken().Line;
            if (decl.GetEndToken() == null)
            {
                LineTo = int.MaxValue;
            }
            else
            {
                LineTo = decl.GetEndToken().Line;
            }
            SourceFileContents.Parser parser = new SourceFileContents.Parser(ns);

            //if (Structs.Count != parser.Structs.Count && Form1.Form.CurrentOpenFile != null && Form1.Form.CurrentOpenFile.OpenFile != null)
            //  Form1.Form.CurrentOpenFile.OpenFile.Editor.Restyle();


            Methods = parser.Methods;
            foreach (MethodDescription method in Methods)
            {
                method.ParentFile = this;
            }
            Fields = parser.Fields;
            foreach (VariableDescription field in Fields)
            {
                field.ParentFile = this;
            }
            Structs = parser.Structs;
            foreach (StructDescription structDescription in Structs)
            {
                foreach (MethodDescription method in structDescription.Methods)
                {
                    method.ParentFile = this;
                }
                foreach (VariableDescription field in structDescription.Fields)
                {
                    field.ParentFile = this;
                }
                structDescription.ParentFile = this;
            }
            Enrichments = parser.Enrichments;
            foreach (EnrichmentDescription structDescription in Enrichments)
            {
                structDescription.ParentFile = this;
                foreach (MethodDescription method in structDescription.Methods)
                {
                    method.ParentFile = this;
                }
                foreach (VariableDescription field in structDescription.Fields)
                {
                    field.ParentFile = this;
                }
            }
            Typedefs = parser.Typedefs;
            foreach (TypedefDescription typedef in Typedefs)
            {
                typedef.ParentFile = this;
            }
            Usings     = parser.Usings;
            Namespaces = parser.Namespaces;
            foreach (NamespaceDescription namespaceDescription in Namespaces)
            {
                namespaceDescription.Parent = this;
            }
            Position = TextPoint.FromCompilerCoords(ns.GetName());
        }
Exemple #7
0
        private static void GetMatchingTypes(ANamedType node, List <string> names, List <ATypedefDecl> typeDefs, List <AStructDecl> structs, List <AMethodDecl> delegates, List <ANamespaceDecl> namespaces, List <TIdentifier> generics)
        {
            List <IList>  decls             = new List <IList>();
            List <string> currentNamespace  = Util.GetFullNamespace(node);
            AASourceFile  currentSourceFile = Util.GetAncestor <AASourceFile>(node);

            if (names.Count == 1)
            {
                string name = names[0];
                //Check generic vars
                AStructDecl currentStruct = Util.GetAncestor <AStructDecl>(node);
                if (currentStruct != null)
                {
                    foreach (TIdentifier genericVar in currentStruct.GetGenericVars())
                    {
                        if (genericVar.Text == name)
                        {
                            generics.Add(genericVar);
                        }
                    }
                }
                //Get all type decls and namespaces matching this name, visible from this location
                List <IList> visibleDecls = Util.GetVisibleDecls(node, ((AAName)node.GetName()).GetIdentifier().Count == 1);
                foreach (IList declList in visibleDecls)
                {
                    bool sameFile = false;
                    if (declList.Count > 0)
                    {
                        sameFile = currentSourceFile == Util.GetAncestor <AASourceFile>((PDecl)declList[0]);
                    }
                    foreach (PDecl decl in declList)
                    {
                        bool sameNS = Util.NamespacesEquals(currentNamespace, Util.GetFullNamespace(decl));
                        if (decl is ANamespaceDecl)
                        {
                            ANamespaceDecl aDecl = (ANamespaceDecl)decl;
                            if (aDecl.GetName().Text == name)
                            {
                                namespaces.Add(aDecl);
                            }
                            continue;
                        }
                        if (decl is ATypedefDecl)
                        {
                            if (Util.IsAncestor(node, decl))
                            {
                                continue;
                            }
                            ATypedefDecl aDecl = (ATypedefDecl)decl;
                            if (aDecl.GetStatic() != null && !sameFile ||
                                aDecl.GetVisibilityModifier() is APrivateVisibilityModifier && !sameNS)
                            {
                                continue;
                            }
                            ANamedType namedType = (ANamedType)aDecl.GetName();
                            AAName     aName     = (AAName)namedType.GetName();
                            string     n         = ((TIdentifier)aName.GetIdentifier()[0]).Text;
                            if (n == name)
                            {
                                typeDefs.Add(aDecl);
                            }
                            continue;
                        }
                        if (decl is AStructDecl)
                        {
                            AStructDecl aDecl = (AStructDecl)decl;
                            if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier)
                            {
                                continue;
                            }
                            if (aDecl.GetName().Text == name)
                            {
                                structs.Add(aDecl);
                            }
                            continue;
                        }
                        if (decl is AMethodDecl)
                        {
                            AMethodDecl aDecl = (AMethodDecl)decl;
                            if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier ||
                                !sameFile && aDecl.GetStatic() != null)
                            {
                                continue;
                            }
                            if (aDecl.GetDelegate() != null && aDecl.GetName().Text == name)
                            {
                                delegates.Add(aDecl);
                            }
                            continue;
                        }
                    }
                }
            }
            else
            {
                string name = names[names.Count - 1];
                List <ANamespaceDecl> baseNamespaces = new List <ANamespaceDecl>();
                List <string>         baseNames      = new List <string>();
                baseNames.AddRange(names);
                baseNames.RemoveAt(baseNames.Count - 1);
                GetMatchingTypes(node, baseNames, new List <ATypedefDecl>(), new List <AStructDecl>(), new List <AMethodDecl>(), baseNamespaces, generics);
                foreach (ANamespaceDecl ns in baseNamespaces)
                {
                    bool sameFile = currentSourceFile == Util.GetAncestor <AASourceFile>(ns);
                    foreach (PDecl decl in ns.GetDecl())
                    {
                        bool sameNS = Util.NamespacesEquals(currentNamespace, Util.GetFullNamespace(decl));
                        if (decl is ANamespaceDecl)
                        {
                            ANamespaceDecl aDecl = (ANamespaceDecl)decl;
                            if (aDecl.GetName().Text == name)
                            {
                                namespaces.Add(aDecl);
                            }
                            continue;
                        }
                        if (decl is ATypedefDecl)
                        {
                            ATypedefDecl aDecl     = (ATypedefDecl)decl;
                            ANamedType   namedType = (ANamedType)aDecl.GetName();
                            AAName       aName     = (AAName)namedType.GetName();
                            string       n         = ((TIdentifier)aName.GetIdentifier()[0]).Text;
                            if (n == name)
                            {
                                typeDefs.Add(aDecl);
                            }
                            continue;
                        }
                        if (decl is AStructDecl)
                        {
                            AStructDecl aDecl = (AStructDecl)decl;
                            if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier)
                            {
                                continue;
                            }
                            if (aDecl.GetName().Text == name)
                            {
                                structs.Add(aDecl);
                            }
                            continue;
                        }
                        if (decl is AMethodDecl)
                        {
                            AMethodDecl aDecl = (AMethodDecl)decl;
                            if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier ||
                                !sameFile && aDecl.GetStatic() != null)
                            {
                                continue;
                            }
                            if (aDecl.GetDelegate() != null && aDecl.GetName().Text == name)
                            {
                                delegates.Add(aDecl);
                            }
                            continue;
                        }
                    }
                }
            }
        }
Exemple #8
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);
        }