/// <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_resolved;
+ 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;
- conversion_list = new ArrayList ();
- is_resolved = false;
- }
-
- public string FullName {
- get { return full_name; }
- }
-
- public bool IsPinned {
- get { return is_pinned; }
- }
-
- 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 ()
+ 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)
{
- conversion_list.Add (ConversionMethod.MakeArray);
- }
-
- public void MakeBoundArray (ArrayList bounds)
- {
- conversion_list.Add (ConversionMethod.MakeBoundArray);
- conversion_list.Add (bounds);
- }
-
- public void MakeManagedPointer ()
- {
- conversion_list.Add (ConversionMethod.MakeManagedPointer);
- }
-
- public void MakeUnmanagedPointer ()
- {
- conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
- }
-
- public void MakeCustomModified (PEAPI.CustomModifier modifier)
- {
- conversion_list.Add (ConversionMethod.MakeCustomModified);
- conversion_list.Add (modifier);
+ this.location = location;
}
-
- public void MakePinned ()
+
+ public override BaseClassRef Clone ()
{
- is_pinned = true;
+ return new TypeRef (full_name, is_valuetype, location, (ArrayList) ConversionList.Clone (), sig_mod);
}
- public IMethodRef GetMethodRef (ITypeRef ret_type,
- string name, ITypeRef[] param)
+ protected override BaseMethodRef CreateMethodRef (BaseTypeRef ret_type,
+ PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
{
- return new MethodRef (this, ret_type, name, param);
+ 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 IFieldRef GetFieldRef (ITypeRef ret_type, string name)
+ protected override IFieldRef CreateFieldRef (BaseTypeRef ret_type, string name)
{
- return new FieldRef (this, ret_type, 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 ((PEAPI.CustomModifier) conversion_list[++i]);
- break;
- }
- }
-
- resolved_type = peapi_type.PeapiType;
+ type = Modify (code_gen, base_type);
is_resolved = true;
}
+ public BaseClassRef AsClassRef (CodeGen code_gen)
+ {
+ return this;
+ }
+
public override string ToString ()
{
return FullName;