[PEAPI] Don't add mscorlib reference when no type needs it
authorMarek Safar <marek.safar@gmail.com>
Tue, 29 Aug 2017 17:47:37 +0000 (19:47 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 29 Aug 2017 17:51:08 +0000 (19:51 +0200)
mcs/class/PEAPI/Metadata.cs

index 8132ecab518ced13773b2427f7a2400654a54e6d..eca297380bcdc92386e6067a43e5b686447f67dd 100644 (file)
@@ -1641,6 +1641,7 @@ namespace PEAPI {
        public class ClassDef : Class {
 
                Class superType;
+               bool setSuperType;
                ArrayList fields = new ArrayList();
                ArrayList methods = new ArrayList();
                ArrayList events;
@@ -1656,9 +1657,6 @@ namespace PEAPI {
                                MetaData md) : base(nsName, name, md) 
                {
                        metaData = md;
-                       if (! ((nsName == "" && name == "<Module>") || (nsName == "System" && name == "Object")) ) {
-                               superType = metaData.mscorlib.GetSpecialSystemClass(PrimitiveType.Object);
-                       }
                        flags = (uint)attrSet;
                        tabIx = MDTable.TypeDef;
                }
@@ -1666,6 +1664,7 @@ namespace PEAPI {
                internal void SetSuper(Class sClass) 
                {
                        superType = sClass;
+                       setSuperType = true;
                        if (! (sClass is GenericTypeInst))
                                typeIndexChecked = false;
                }
@@ -1677,12 +1676,13 @@ namespace PEAPI {
                        else  
                                superType = metaData.mscorlib.ValueType();
 
+                       setSuperType = true;
                        typeIndex = PrimitiveType.ValueType.GetTypeIndex ();
                }
 
                public void SpecialNoSuper() 
                {
-                       superType = null;
+                       setSuperType = true;
                }
 
                /// <summary>
@@ -1924,8 +1924,13 @@ namespace PEAPI {
 
                internal sealed override void BuildTables(MetaData md) 
                {
-                       if (done) return;
-                       if ((flags & (uint)TypeAttr.Interface) != 0) { superType = null; }
+                       if (done) 
+                               return;
+                       
+                       if ((flags & (uint)TypeAttr.Interface) != 0) {
+                               superType = null;
+                               setSuperType = true;
+                       }
                        // Console.WriteLine("Building tables for " + name);
                        if (layout != null) md.AddToTable(MDTable.ClassLayout,layout);
                        // Console.WriteLine("adding methods " + methods.Count);
@@ -1958,6 +1963,10 @@ namespace PEAPI {
                                                        ((Property)properties[0]).Row,MDTable.Property));
                        }
                        // Console.WriteLine("End of building tables");
+
+                       if (!setSuperType)
+                               superType = metaData.mscorlib.GetSpecialSystemClass(PrimitiveType.Object);
+
                        done = true;
                }
 
@@ -5052,7 +5061,7 @@ namespace PEAPI {
                private byte heapSizes = 0;
                MetaDataElement entryPoint;
                BinaryWriter output;
-               public MSCorLib mscorlib;
+               MSCorLib _mscorlib;
                private TypeSpec[] systemTypeSpecs = new TypeSpec[PrimitiveType.NumSystemTypes];
                long mdStart;
                private ArrayList cattr_list;
@@ -5077,9 +5086,15 @@ namespace PEAPI {
                        for (int i=0; i < lgeCIx.Length; i++) {
                                lgeCIx[i] = false;
                        }
-                       mscorlib = new MSCorLib(this);
                }
 
+               public MSCorLib mscorlib {
+                       get {
+                               return _mscorlib ?? (_mscorlib = new MSCorLib (this));
+                       }
+               }
+
+
                internal TypeSpec GetPrimitiveTypeSpec(int ix) 
                {
                        return systemTypeSpecs[ix];