* InstrTable.cs: Add Calli, detabify
[mono.git] / mcs / ilasm / codegen / ClassTable.cs
index 6d7dcd2938c19ad29b5f01a634b0255e65318159..02df198ab5ec50e93998295773a1b191407650e6 100644 (file)
@@ -22,14 +22,18 @@ namespace Mono.ILASM {
                        private int flags;
 
                        public ArrayList LocationList;
-                       public Class Class;
+                       public ClassDef Class;
+                       public MethodTable method_table;
+                       public FieldTable field_table;
 
-                       public ClassTableItem (Class klass, Location location)
+                       public ClassTableItem (ClassDef klass, Location location)
                        {
                                flags = 0;
                                Class = klass;
                                LocationList = new ArrayList ();
                                LocationList.Add (location);
+                               method_table = new MethodTable (klass);
+                               field_table = new FieldTable (klass);
                        }
                
                        public bool Defined {
@@ -41,6 +45,29 @@ namespace Mono.ILASM {
                                                flags ^= DefinedFlag;
                                }
                        }
+
+                       public bool CheckDefined ()
+                       {
+                               if (!Defined)
+                                       return false;
+                               
+                               if (!FieldTable.CheckDefined ())
+                                       return false;
+                               
+                               if (!MethodTable.CheckDefined ())
+                                       return false;
+                               
+                               return true;
+                       }
+
+                       public MethodTable MethodTable {
+                               get { return method_table; }
+                       }
+
+                       public FieldTable FieldTable {
+                               get { return field_table; }
+                       }
+                       
                }
 
                protected readonly TypeAttr DefaultAttr;
@@ -75,31 +102,103 @@ namespace Mono.ILASM {
                        
                        string name_space, name;                        
                        GetNameAndNamespace (full_name, out name_space, out name);
-                       Class klass = pefile.AddClass (DefaultAttr, name_space, name);
+                       ClassDef klass = pefile.AddClass (DefaultAttr, name_space, name);
                        AddReference (full_name, klass, location);
-                       
        
                        return klass;
                }
 
+               public MethodTable GetMethodTable (string full_name, Location location)
+               {
+                       ClassTableItem item = table[full_name] as ClassTableItem;
+                       
+                       if (item == null) {
+                               GetReference (full_name, location);
+                               return GetMethodTable (full_name, location);
+                       }
+
+                       return item.MethodTable;
+               }
+
+               public FieldTable GetFieldTable (string full_name, Location location)
+               {
+                       ClassTableItem item = table[full_name] as ClassTableItem;
+                       
+                       if (item == null) {
+                               GetReference (full_name, location);
+                               return GetFieldTable (full_name, location);
+                       }
+
+                       return item.FieldTable;
+               }
+
                public ClassDef AddDefinition (string name_space, string name, 
                        TypeAttr attr, Location location) 
                {
                        string full_name = String.Format ("{0}.{1}", name_space, name);
+                       
+                       ClassTableItem item = (ClassTableItem) table[full_name];
+
+                       if (item == null) {
+                               ClassDef klass = pefile.AddClass (attr, name_space, name);
+                               AddDefined (full_name, klass, location);
+                               return klass;
+                       }
+
+                       item.Class.AddAttribute (attr);
+                       item.Defined = true;
+
+                       return item.Class;
+               }
+
+               public ClassDef AddDefinition (string name_space, string name, 
+                       TypeAttr attr, Class parent, Location location) 
+               {
+                       string full_name = String.Format ("{0}.{1}", name_space, name);
+
+                       ClassTableItem item = (ClassTableItem) table[full_name];
+
+                       if (item == null) {
+                               ClassDef klass = pefile.AddClass (attr, name_space, name, parent);
+                               AddDefined (full_name, klass, location);
+                               return klass;
+                       }
+                       
+                       /// TODO: Need to set parent, will need to modify PEAPI for this.
+                       item.Class.AddAttribute (attr);
+                       item.Defined = true;
+
+                       return item.Class;
+               }
+
+               /// <summary>
+               ///  When there is no code left to compile, check to make sure referenced types where defined
+               ///  TODO: Proper error reporting
+               /// </summary>
+               public void CheckForUndefined ()
+               {
+                       foreach (DictionaryEntry dic_entry in table) {
+                               ClassTableItem table_item = (ClassTableItem) dic_entry.Value;
+                               if (table_item.CheckDefined ())
+                                       continue;
+                               throw new Exception (String.Format ("Type: {0} is not defined.", dic_entry.Key));
+                       }
+               }
+
+               /// <summary>
+               ///  If a type is allready defined throw an Error
+               /// </summary>
+               protected void CheckExists (string full_name) 
+               {
                        ClassTableItem item = table[full_name] as ClassTableItem;
                        
                        if ((item != null) && (item.Defined)) {
                                throw new Exception (String.Format ("Class: {0} defined in multiple locations.", 
                                        full_name));
                        }
-                       
-                       ClassDef klass = pefile.AddClass (attr, name_space, name);
-                       AddDefined (full_name, klass, location);
-
-                       return klass;
                }
 
-               protected void AddDefined (string full_name, Class klass, Location location)
+               protected void AddDefined (string full_name, ClassDef klass, Location location)
                {
                        if (table.Contains (full_name))
                                return; 
@@ -110,7 +209,7 @@ namespace Mono.ILASM {
                        table[full_name] = item;
                }
 
-               protected void AddReference (string full_name, Class klass, Location location)
+               protected void AddReference (string full_name, ClassDef klass, Location location)
                {
                        if (table.Contains (full_name))
                                return;