2006-11-14 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / ilasm / codegen / TypeRef.cs
index d1467b04167739cf4dd303d8f3afa52b83679452..08846715f99e621f0d2bdcca96a59df6c1d79282 100644 (file)
@@ -15,174 +15,62 @@ namespace Mono.ILASM {
         /// <summary>
         /// Reference to a type in the module being compiled.
         /// </summary>
-        public class TypeRef : IClassRef {
-
-                private enum ConversionMethod {
-                        MakeArray,
-                        MakeBoundArray,
-                        MakeManagedPointer,
-                        MakeUnmanagedPointer,
-                        MakeCustomModified
-                }
+        public class TypeRef : BaseClassRef {
 
                 private Location location;
-                private string full_name;
-                private PEAPI.Type resolved_type;
-                private ArrayList conversion_list;
-                private bool is_pinned;
-                private bool is_ref;
-                private bool is_array;
-                private bool use_type_spec;
-
-                private bool is_resolved;
-
-                public static readonly TypeRef Ellipsis = new TypeRef ("ELLIPSIS", null);
-                public static readonly TypeRef Any = new TypeRef ("any", null);
+                public static readonly TypeRef Ellipsis = new TypeRef ("ELLIPSIS", false, null);
+                public static readonly TypeRef Any = new TypeRef ("any", false, null);
 
-                public TypeRef (string full_name, Location location)
+                public TypeRef (string full_name, bool is_valuetype, Location location)
+                        : this (full_name, is_valuetype, location, null, null)
                 {
-                        this.full_name = full_name;
-                        this.location = location;
-                        is_pinned = false;
-                        is_ref = false;
-                        is_array = false;
-                        conversion_list = new ArrayList ();
-                        is_resolved = false;
-                        use_type_spec = false;
-                }
-
-                public string FullName {
-                        get { return full_name; }
-                }
-
-                public bool IsPinned {
-                        get { return is_pinned; }
-                }
-
-                public bool IsArray {
-                        get { return is_array; }
                 }
 
-                public bool IsRef {
-                        get { return is_ref; }
-                }
-
-                public bool UseTypeSpec {
-                        get { return use_type_spec; }
-                }
-
-                public PEAPI.Type PeapiType {
-                        get { return resolved_type; }
-                }
-
-                public PEAPI.Class PeapiClass {
-                        get { return resolved_type as PEAPI.Class; }
-                }
-
-                public bool IsResolved {
-                        get { return is_resolved; }
-                }
-
-                public void MakeArray ()
-                {
-                        use_type_spec = true;
-                        conversion_list.Add (ConversionMethod.MakeArray);
-                        is_array = true;
-                }
-
-                public void MakeBoundArray (ArrayList bounds)
-                {
-                        use_type_spec = true;
-                        conversion_list.Add (ConversionMethod.MakeBoundArray);
-                        conversion_list.Add (bounds);
-                        is_array = true;
-                }
-
-                public void MakeManagedPointer ()
-                {
-                        use_type_spec = true;
-                        conversion_list.Add (ConversionMethod.MakeManagedPointer);
-                        is_ref = true;
-                }
-
-                public void MakeUnmanagedPointer ()
+                public TypeRef (string full_name, bool is_valuetype, Location location, ArrayList conv_list, string sig_mod)
+                        : base (full_name, is_valuetype, conv_list, sig_mod)
                 {
-                        use_type_spec = true;
-                        conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
+                        this.location = location;
                 }
-
-                public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier,
-                                IClassRef klass)
+                
+                public override BaseClassRef Clone ()
                 {
-                        use_type_spec = true;
-                        conversion_list.Add (ConversionMethod.MakeCustomModified);
-                        conversion_list.Add (klass);
-                        conversion_list.Add (modifier);
+                        return new TypeRef (full_name, is_valuetype, location, (ArrayList) ConversionList.Clone (), sig_mod);
                 }
 
-                public void MakePinned ()
+                protected override BaseMethodRef CreateMethodRef (BaseTypeRef ret_type,
+                        PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
                 {
-                        use_type_spec = true;
-                        is_pinned = true;
+                        if (SigMod == null | SigMod == "")
+                                return new MethodRef (this, call_conv, ret_type, name, param, gen_param_count);
+                        else
+                                return new TypeSpecMethodRef (this, call_conv, ret_type, name, param, gen_param_count);
                 }
 
-                public  IMethodRef GetMethodRef (ITypeRef ret_type,
-                        PEAPI.CallConv call_conv, string name, ITypeRef[] param)
+                protected override IFieldRef CreateFieldRef (BaseTypeRef ret_type, string name)
                 {
-                        return new MethodRef (this, call_conv, ret_type, name, param);
+                         return new FieldRef (this, ret_type, name);
                 }
 
-                public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
-                {
-                        return new FieldRef (this, ret_type, name);
-                }
-
-                public void Resolve (CodeGen code_gen)
+                public override void Resolve (CodeGen code_gen)
                 {
                         if (is_resolved)
                                 return;
 
                         PEAPI.Type base_type;
-                        PeapiTypeRef peapi_type;
-                        int count = conversion_list.Count;
 
                         base_type = code_gen.TypeManager.GetPeapiType (full_name);
 
-                        /// TODO: Proper error message
                         if (base_type == null) {
-                                Console.WriteLine ("Type not defined: {0} {1}", full_name, location);
+                                Report.Error ("Reference to undefined class '" +
+                                                       FullName + "'");
                                 return;
                         }
-
-                        peapi_type = new PeapiTypeRef (base_type, full_name);
-
-                        for (int i=0; i<count; i++) {
-                                switch ((ConversionMethod) conversion_list[i]) {
-                                case ConversionMethod.MakeArray:
-                                        peapi_type.MakeArray ();
-                                        break;
-                                case ConversionMethod.MakeBoundArray:
-                                        peapi_type.MakeBoundArray ((ArrayList) conversion_list[++i]);
-                                        break;
-                                case ConversionMethod.MakeManagedPointer:
-                                        peapi_type.MakeManagedPointer ();
-                                        break;
-                                case ConversionMethod.MakeUnmanagedPointer:
-                                        peapi_type.MakeUnmanagedPointer ();
-                                        break;
-                                case ConversionMethod.MakeCustomModified:
-                                        peapi_type.MakeCustomModified (code_gen, (PEAPI.CustomModifier) conversion_list[++i],
-                                                (IClassRef) conversion_list[++i]);
-                                        break;
-                                }
-                        }
-
-                        resolved_type = peapi_type.PeapiType;
+                        type = Modify (code_gen, base_type);
 
                         is_resolved = true;
                 }
 
-                public IClassRef AsClassRef (CodeGen code_gen)
+                public BaseClassRef AsClassRef (CodeGen code_gen)
                 {
                         return this;
                 }