1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
//
// Mono.ILASM.ModifiableType
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper (Jackson@LatitudeGeo.com)
//
using System;
using System.Collections;
namespace Mono.ILASM {
public abstract class ModifiableType {
private ArrayList conversion_list;
private bool is_pinned;
private bool is_ref;
private bool is_array;
private bool use_type_spec;
private enum ConversionMethod {
MakeArray,
MakeBoundArray,
MakeManagedPointer,
MakeUnmanagedPointer,
MakeCustomModified
}
public ModifiableType ()
{
conversion_list = new ArrayList (5);
}
public abstract string SigMod {
get;
set;
}
protected ArrayList ConversionList {
get { return conversion_list; }
set { conversion_list = value; }
}
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 void MakeArray ()
{
use_type_spec = true;
conversion_list.Add (ConversionMethod.MakeArray);
is_array = true;
SigMod += "[]";
}
public void MakeBoundArray (ArrayList bounds)
{
use_type_spec = true;
conversion_list.Add (ConversionMethod.MakeBoundArray);
conversion_list.Add (bounds);
is_array = true;
SigMod += "[";
for (int i=0; i<bounds.Count; i++) {
DictionaryEntry e = (DictionaryEntry) bounds [i];
if (e.Key != TypeRef.Ellipsis)
SigMod += e.Key;
SigMod += "...";
if (e.Value != TypeRef.Ellipsis)
SigMod += e.Value;
if (i + 1 < bounds.Count)
SigMod += ", ";
}
SigMod += "]";
}
public void MakeManagedPointer ()
{
use_type_spec = true;
conversion_list.Add (ConversionMethod.MakeManagedPointer);
is_ref = true;
SigMod += "&";
}
public void MakeUnmanagedPointer ()
{
use_type_spec = true;
conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
SigMod += "*";
}
public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier,
BaseClassRef klass)
{
use_type_spec = true;
conversion_list.Add (ConversionMethod.MakeCustomModified);
conversion_list.Add (modifier);
conversion_list.Add (klass);
}
public void MakePinned ()
{
use_type_spec = true;
is_pinned = true;
}
protected PEAPI.Type Modify (CodeGen code_gen, PEAPI.Type type)
{
PeapiTypeRef peapi_type = new PeapiTypeRef (type);
int count = conversion_list.Count;
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],
(BaseClassRef) conversion_list[++i]);
break;
}
}
return peapi_type.PeapiType;
}
}
}
|