Beispiel #1
0
        /*public override void InAMethodDecl(AMethodDecl node)
         * {
         *  AABlock block = (AABlock) node.GetBlock();
         *  if (block != null)
         *  {
         *      if (!data.Locals.ContainsKey(block))
         *          data.Locals.Add(block, new List<AALocalDecl>());
         *      foreach (AALocalDecl formal in node.GetFormals())
         *      {
         *          data.Locals[block].Add(formal);
         *      }
         *  }
         * }
         *
         * public override void InAConstructorDecl(AConstructorDecl node)
         * {
         *  AABlock block = (AABlock)node.GetBlock();
         *  if (block != null)
         *  {
         *      if (!data.Locals.ContainsKey(block))
         *          data.Locals.Add(block, new List<AALocalDecl>());
         *      foreach (AALocalDecl formal in node.GetFormals())
         *      {
         *          data.Locals[block].Add(formal);
         *      }
         *  }
         * }*/

        public override void OutAMethodDecl(AMethodDecl node)
        {
            AStructDecl     parentStruct     = Util.GetAncestor <AStructDecl>(node);
            AEnrichmentDecl parentEnrichment = Util.GetAncestor <AEnrichmentDecl>(node);

            if (parentStruct != null)
            {
                //Struct method
                data.StructMethods[parentStruct].Add(node);
            }
            else if (parentEnrichment == null)
            {//Global method
                //Dont care about abstract methods - will add them later
                if (node.GetBlock() != null || node.GetNative() != null)
                {
                    data.Methods.Add(new SharedData.DeclItem <AMethodDecl>(currentSourceFile, node));
                    data.UserMethods.Add(node);
                }
                else if (node.GetDelegate() != null)
                {
                    data.Delegates.Add(new SharedData.DeclItem <AMethodDecl>(currentSourceFile, node));
                }
                else
                {
                    node.Parent().RemoveChild(node);
                    return;
                }
            }
            base.OutAMethodDecl(node);
        }
Beispiel #2
0
        public MethodDescription(AMethodDecl method)
        {
            Parser parser = new Parser(method);


            Start      = parser.Start;
            End        = parser.End;
            ReturnType = parser.ReturnType;
            Name       = parser.Name;
            Formals    = parser.Formals;
            Locals     = parser.Locals;
            if (method.Parent() != null)
            {
                method.Parent().RemoveChild(method);
            }
            IsDelegate = method.GetDelegate() != null;
            //if (!IsDelegate)
            Decl       = method;
            IsStatic   = method.GetStatic() != null;
            Visibility = method.GetVisibilityModifier();
            realType   = (PType)method.GetReturnType().Clone();
            Position   = TextPoint.FromCompilerCoords(method.GetName());
        }
Beispiel #3
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;
                        }
                    }
                }
            }
        }