Inheritance: IAssemblyResolver
Ejemplo n.º 1
0
 MethodKey[] GetVirtualMethods(AssemblyCache cache, TypeDefinition type)
 {
     HashSet<MethodKey> methods = new HashSet<MethodKey> ();
     GetVirtualMethods (cache, methods, type);
     return new List<MethodKey> (methods).ToArray ();
 }
Ejemplo n.º 2
0
        public InheritMap(Project project)
        {
            this.project = project;

            // cache for assemblies not in the project
            AssemblyCache cache = new AssemblyCache (project);
            //string[] lPaths = project.
            cache.ExtraFolders.AddRange (project.ExtraPaths);

            foreach (AssemblyInfo info in project) {
                cache.ExtraFolders.Add (System.IO.Path.GetDirectoryName (info.Filename));
                foreach (TypeDefinition type in info.GetAllTypeDefinitions()) {
                    if (type.FullName == "<Module>")
                        continue;

                    TypeKey typeKey = new TypeKey (type);

                    baseTypes [typeKey] = GetBaseTypes (type);

                    int i = 0;
                    int j;

                    MethodKey[] methods = GetVirtualMethods (cache, type);
                    while (i < methods.Length) {
                        MethodGroup group;
                        if (!methodGroups.TryGetValue (methods [i], out group))
                            group = null;

                        for (j = i + 1; j < methods.Length; j++) {
                            if (!MethodsMatch(methods, i, j))
                                continue;

                            // found an override

                            // see if either method is already in a group
                            if (group != null)
                                group = AddToGroup (group, methods [j]);
                            else if (methodGroups.TryGetValue (methods [j], out group))
                                group = AddToGroup (group, methods [i]);
                            else {
                                group = new MethodGroup ();

                                group = AddToGroup (group, methods [i]);
                                group = AddToGroup (group, methods [j]);
                            }

                            // if the group isn't already external, see if it should be
                            Debug.Assert (group != null, "should have a group by now");
                            if (!group.External && !project.Contains (methods [j].TypeKey))
                                group.External = true;
                        }

                        // if the group isn't already external, see if it should be
                        if (group != null && !group.External && !project.Contains (methods [i].TypeKey))
                            group.External = true;

                        // move on to the next thing that doesn't match
                        i++;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void GetVirtualMethods(AssemblyCache cache, HashSet<MethodKey> methods, TypeDefinition type)
        {
            // check the interfaces
            foreach (TypeReference ifaceRef in type.Interfaces) {
                TypeDefinition iface = project.GetTypeDefinition (ifaceRef);

                // if it's not in the project, try to get it via the cache
                if (iface == null)
                    iface = cache.GetTypeDefinition (ifaceRef);

                // search interface
                if (iface != null)
                    GetVirtualMethods (cache, methods, iface);
            }

            // check the base type unless it isn't in the project, or we don't have one
            TypeDefinition baseType = project.GetTypeDefinition (type.BaseType);

            // if it's not in the project, try to get it via the cache
            if (baseType == null)
                baseType = cache.GetTypeDefinition (type.BaseType);

            // search base
            if (baseType != null)
                GetVirtualMethods (cache, methods, baseType);

            foreach (MethodDefinition method in type.Methods) {
                if (method.IsVirtual)
                    methods.Add (new MethodKey (method));
            }
        }
Ejemplo n.º 4
0
 MethodKey[] GetVirtualMethods( AssemblyCache cache, TypeDefinition type )
 {
     C5.TreeSet<MethodKey> methods = new C5.TreeSet<MethodKey>( );
     GetVirtualMethods( cache, methods, type );
     return methods.ToArray( );
 }
Ejemplo n.º 5
0
        public InheritMap(Project project)
        {
            this.project = project;

            // cache for assemblies not in the project
            AssemblyCache cache = new AssemblyCache(project);

            foreach (AssemblyInfo info in project)
            {
                foreach (TypeDefinition type in info.GetAllTypeDefinitions())
                {
                    if (type.FullName == "<Module>")
                    {
                        continue;
                    }

                    TypeKey typeKey = new TypeKey(type);

                    baseTypes[typeKey] = GetBaseTypes(type);

                    int i = 0;
                    int j;

                    MethodKey[] methods = GetVirtualMethods(cache, type);
                    while (i < methods.Length)
                    {
                        MethodGroup group;
                        if (!methodGroups.TryGetValue(methods[i], out group))
                        {
                            group = null;
                        }

                        for (j = i + 1; j < methods.Length && MethodsMatch(methods, i, j); j++)
                        {
                            // found an override

                            // see if either method is already in a group
                            if (group != null)
                            {
                                group = AddToGroup(group, methods[j]);
                            }
                            else if (methodGroups.TryGetValue(methods[j], out group))
                            {
                                group = AddToGroup(group, methods[i]);
                            }
                            else
                            {
                                group = new MethodGroup();

                                group = AddToGroup(group, methods[i]);
                                group = AddToGroup(group, methods[j]);
                            }

                            // if the group isn't already external, see if it should be
                            Debug.Assert(group != null, "should have a group by now");
                            if (!group.External && !project.Contains(methods[j].TypeKey))
                            {
                                group.External = true;
                            }
                        }

                        // if the group isn't already external, see if it should be
                        if (group != null && !group.External && !project.Contains(methods[i].TypeKey))
                        {
                            group.External = true;
                        }

                        // move on to the next thing that doesn't match
                        i = j;
                    }
                }
            }
        }
Ejemplo n.º 6
0
 MethodKey[] GetVirtualMethods(AssemblyCache cache, TypeDefinition type)
 {
     C5.TreeSet <MethodKey> methods = new C5.TreeSet <MethodKey>();
     GetVirtualMethods(cache, methods, type);
     return(methods.ToArray());
 }
Ejemplo n.º 7
0
        void GetVirtualMethods(AssemblyCache cache, HashSet <MethodKey> methods, TypeDefinition type)
        {
            // check the interfaces
            foreach (var ifaceRef in type.Interfaces)
            {
                TypeDefinition iface = project.GetTypeDefinition(ifaceRef.InterfaceType);

                // if it's not in the project, try to get it via the cache
                if (iface == null)
                {
                    iface = cache.GetTypeDefinition(ifaceRef.InterfaceType);
                }

                // search interface
                if (iface != null)
                {
                    GetVirtualMethods(cache, methods, iface);
                }
            }

            // check the base type unless it isn't in the project, or we don't have one
            TypeDefinition baseType = project.GetTypeDefinition(type.BaseType);

            // if it's not in the project, try to get it via the cache
            if (baseType == null)
            {
                baseType = cache.GetTypeDefinition(type.BaseType);
            }

            // search base
            if (baseType != null)
            {
                GetVirtualMethods(cache, methods, baseType);
            }

            foreach (MethodDefinition method in type.Methods)
            {
                if (method.IsVirtual)
                {
                    methods.Add(new MethodKey(method));
                }
            }

            foreach (PropertyDefinition property in type.Properties)
            {
                if (property.GetMethod != null && property.GetMethod.IsVirtual)
                {
                    methods.Add(new MethodKey(property.GetMethod));
                }

                if (property.SetMethod != null && property.SetMethod.IsVirtual)
                {
                    methods.Add(new MethodKey(property.SetMethod));
                }
            }

            foreach (EventDefinition @event in type.Events)
            {
                if (@event.AddMethod != null && @event.AddMethod.IsVirtual)
                {
                    methods.Add(new MethodKey(@event.AddMethod));
                }

                if (@event.RemoveMethod != null && @event.RemoveMethod.IsVirtual)
                {
                    methods.Add(new MethodKey(@event.RemoveMethod));
                }
            }
        }