X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Filasm%2Fcodegen%2FPeapiTypeRef.cs;h=704ba2df08699924cbae80fbe0e3d0a1a93ed0fd;hb=53e266903ec6b2d822cf5b0c566f6374df5307a4;hp=b31c3f342cf1ed2847c552b0c07ae29ed996209e;hpb=fd99828c88b8679946738335a95575a9037be9e0;p=mono.git diff --git a/mcs/ilasm/codegen/PeapiTypeRef.cs b/mcs/ilasm/codegen/PeapiTypeRef.cs index b31c3f342cf..704ba2df086 100644 --- a/mcs/ilasm/codegen/PeapiTypeRef.cs +++ b/mcs/ilasm/codegen/PeapiTypeRef.cs @@ -12,6 +12,31 @@ using System; using System.Collections; namespace Mono.ILASM { + public class Pair { + private PEAPI.Type type; + private string sig; + + public Pair (PEAPI.Type type, string sig) + { + this.type = type; + this.sig = sig; + } + + public override int GetHashCode () + { + return type.GetHashCode () ^ sig.GetHashCode (); + } + + public override bool Equals (Object o) + { + Pair p = o as Pair; + + if (p == null) + return false; + + return (p.type == this.type && p.sig == this.sig); + } + } public class PeapiTypeRef { @@ -21,6 +46,8 @@ namespace Mono.ILASM { private bool is_ref; private bool use_type_spec; + private static Hashtable type_table = new Hashtable (); + public PeapiTypeRef (PEAPI.Type peapi_type) { this.peapi_type = peapi_type; @@ -52,76 +79,138 @@ namespace Mono.ILASM { public void MakeArray () { + PEAPI.Type type; + use_type_spec = true; - peapi_type = new PEAPI.ZeroBasedArray (peapi_type); is_array = true; + + Pair p = new Pair (peapi_type, "[]"); + type = type_table [p] as PEAPI.Type; + if (type == null) { + type = new PEAPI.ZeroBasedArray (peapi_type); + type_table [p] = type; + } + peapi_type = type; } public void MakeBoundArray (ArrayList bound_list) { use_type_spec = true; + is_array = true; int dimen = bound_list.Count; int[] lower_array = new int[dimen]; int[] size_array = new int[dimen]; - bool lower_set = false; - bool size_set = false; - bool prev_lower_set = true; - bool prev_size_set = true; + int [] lobounds = null; + int [] sizes = null; + int num_lower, num_sizes; + string sigmod = ""; + PEAPI.Type type; + Pair p; + + sigmod += "["; + for (int i=0; i 0) { + lobounds = new int [num_lower]; + Array.Copy (lower_array, lobounds, num_lower); } - is_array = true; + + if (num_sizes > 0) { + sizes = new int [num_sizes]; + Array.Copy (size_array, sizes, num_sizes); + } + + peapi_type = new PEAPI.BoundArray (peapi_type, + (uint) dimen, lobounds, sizes); + type_table [p] = peapi_type; } public void MakeManagedPointer () { + PEAPI.Type type; use_type_spec = true; - - peapi_type = new PEAPI.ManagedPointer (peapi_type); is_ref = true; + + Pair p = new Pair (peapi_type, "&"); + type = type_table [p] as PEAPI.Type; + if (type == null) { + type = new PEAPI.ManagedPointer (peapi_type); + type_table [p] = type; + } + peapi_type = type; } public void MakeUnmanagedPointer () { + PEAPI.Type type; use_type_spec = true; - peapi_type = new PEAPI.UnmanagedPointer (peapi_type); + Pair p = new Pair (peapi_type, "*"); + type = type_table [p] as PEAPI.Type; + if (type == null) { + type = new PEAPI.UnmanagedPointer (peapi_type); + type_table [p] = type; + } + peapi_type = type; } public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier, - IClassRef klass) + BaseClassRef klass) { - use_type_spec = true; + PEAPI.Type type; - klass.Resolve (code_gen); - peapi_type = new PEAPI.CustomModifiedType (peapi_type, + use_type_spec = true; + + Pair p = new Pair (peapi_type, modifier.ToString ()); + type = type_table [p] as PEAPI.Type; + if (type == null) { + klass.Resolve (code_gen); + type = new PEAPI.CustomModifiedType (peapi_type, modifier, klass.PeapiClass); + type_table [p] = type; + } + peapi_type = type; } public void MakePinned ()