//
// Mono.ILASM.TypeRef
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using System;
using System.Collections;
namespace Mono.ILASM {
///
/// Reference to a type in the module being compiled.
///
public class TypeRef : IClassRef {
private enum ConversionMethod {
MakeArray,
MakeBoundArray,
MakeManagedPointer,
MakeUnmanagedPointer,
MakeCustomModified
}
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 is_resolved;
public TypeRef (string full_name, Location location)
{
this.full_name = full_name;
this.location = location;
is_pinned = false;
is_ref = false;
is_array = false;
conversion_list = new ArrayList ();
is_resolved = 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 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 ()
{
conversion_list.Add (ConversionMethod.MakeArray);
is_array = true;
}
public void MakeBoundArray (ArrayList bounds)
{
conversion_list.Add (ConversionMethod.MakeBoundArray);
conversion_list.Add (bounds);
is_array = true;
}
public void MakeManagedPointer ()
{
conversion_list.Add (ConversionMethod.MakeManagedPointer);
is_ref = true;
}
public void MakeUnmanagedPointer ()
{
conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
}
public void MakeCustomModified (PEAPI.CustomModifier modifier)
{
conversion_list.Add (ConversionMethod.MakeCustomModified);
conversion_list.Add (modifier);
}
public void MakePinned ()
{
is_pinned = true;
}
public IMethodRef GetMethodRef (ITypeRef ret_type,
PEAPI.CallConv call_conv, string name, ITypeRef[] param)
{
return new MethodRef (this, ret_type, name, param);
}
public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
{
return new FieldRef (this, ret_type, name);
}
public 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);
return;
}
peapi_type = new PeapiTypeRef (base_type, full_name);
for (int i=0; i