* MethodDef.cs: Report when defining methods just like MS.
[mono.git] / mcs / ilasm / codegen / TypeDef.cs
index c7e6e02a77270bf9f18fc1ac98ffa194ab0fb299..2aee3ebd80ae915c71fa40505ff70a9987fef852 100644 (file)
@@ -15,6 +15,11 @@ namespace Mono.ILASM {
 
         public class TypeDef {
 
+                protected class GenericInfo {
+                        public string Id;
+                        public ArrayList ConstraintList;
+                }
+
                 private PEAPI.TypeAttr attr;
                 private string name_space;
                 private string name;
@@ -25,14 +30,12 @@ namespace Mono.ILASM {
                 private PEAPI.ClassDef classdef;
                 private Hashtable field_table;
                 private Hashtable method_table;
-                private ArrayList data_list;
                 private ArrayList customattr_list;
                 private ArrayList event_list;
                 private ArrayList property_list;
                 private ArrayList typar_list;
                 private ArrayList override_list;
                 private ArrayList override_long_list;
-                private Hashtable constraint_table;
                 private TypeDef outer;
 
                 private EventDef current_event;
@@ -54,7 +57,6 @@ namespace Mono.ILASM {
                         this.impl_list = impl_list;
                         field_table = new Hashtable ();
                         method_table = new Hashtable ();
-                        data_list = new ArrayList ();
 
                         size = -1;
                         pack = -1;
@@ -145,20 +147,6 @@ namespace Mono.ILASM {
                         field_table.Add (fielddef.Name, fielddef);
                 }
 
-                public void AddDataDef (DataDef datadef)
-                {
-                        data_list.Add (datadef);
-                }
-
-                public DataDef GetDataDef (string name)
-                {
-                        foreach (DataDef def in data_list) {
-                                if (def.Name == name)
-                                        return def;
-                        }
-                        return null;
-                }
-
                 public void AddMethodDef (MethodDef methoddef)
                 {
                         method_table.Add (methoddef.Signature, methoddef);
@@ -211,15 +199,19 @@ namespace Mono.ILASM {
                         if (typar_list == null)
                                 typar_list = new ArrayList ();
 
-                        typar_list.Add (id);
+                        GenericInfo gi = new GenericInfo ();
+                        gi.Id = id;
+
+                        typar_list.Add (gi);
                 }
 
                 public void AddGenericConstraint (int index, ITypeRef constraint)
                 {
-                        if (constraint_table == null)
-                                constraint_table = new Hashtable ();
+                        GenericInfo gi = (GenericInfo) typar_list[index];
 
-                        constraint_table.Add (index, constraint);
+                        if (gi.ConstraintList == null)
+                                gi.ConstraintList = new ArrayList ();
+                        gi.ConstraintList.Add (constraint);
                 }
 
                 public void Define (CodeGen code_gen)
@@ -277,15 +269,22 @@ namespace Mono.ILASM {
                         if (size != -1)
                                 classdef.AddLayoutInfo (pack, size);
 
+                        if (impl_list != null) {
+                                foreach (IClassRef impl in impl_list) {
+                                        impl.Resolve (code_gen);
+                                        classdef.AddImplementedInterface (impl.PeapiClass);
+                                }
+                        }
+
                         if (typar_list != null) {
                                 short index = 0;
-                                foreach (string id in typar_list) {
-                                        if (constraint_table != null && constraint_table.Contains ((int) index)) {
-                                                ITypeRef constraint = (ITypeRef) constraint_table[(int) index];
-                                                constraint.Resolve (code_gen);
-                                                classdef.AddGenericParameter (index++, id, constraint.PeapiType);
-                                        } else {
-                                                classdef.AddGenericParameter (index++, id);
+                                foreach (GenericInfo gi in typar_list) {
+                                        PEAPI.GenericParameter gp = classdef.AddGenericParameter (index++, gi.Id);
+                                        if (gi.ConstraintList != null) {
+                                                foreach (ITypeRef cnst in gi.ConstraintList) {
+                                                        cnst.Resolve (code_gen);
+                                                        gp.AddConstraint (cnst.PeapiType);
+                                                }
                                         }
                                 }
                         }
@@ -303,7 +302,7 @@ namespace Mono.ILASM {
                         }
 
                         foreach (MethodDef methoddef in method_table.Values) {
-                                methoddef.Define (code_gen, classdef);
+                                methoddef.Define (code_gen, this);
                         }
 
                         if (event_list != null) {
@@ -355,6 +354,11 @@ namespace Mono.ILASM {
                 {
                         MethodDef methoddef = (MethodDef) method_table[signature];
 
+                        if (methoddef == null) {
+                                code_gen.Report.Error ("Unable to resolve method: " + signature);
+                                Environment.Exit (1);
+                        }
+
                         return methoddef.Resolve (code_gen, classdef);
                 }
 
@@ -362,8 +366,13 @@ namespace Mono.ILASM {
                                 CodeGen code_gen, PEAPI.Type[] opt)
                 {
                         MethodDef methoddef = (MethodDef) method_table[signature];
-                        methoddef.Resolve (code_gen, classdef);
 
+                        if (methoddef == null) {
+                                code_gen.Report.Error ("Unable to resolve method: " + signature);
+                                Environment.Exit (1);
+                        }
+
+                        methoddef.Resolve (code_gen, classdef);
                         return methoddef.GetVarargSig (opt);
                 }