2 // Mono.ILASM.FieldTable.cs
5 // Jackson Harper (Jackson@LatitudeGeo.com)
7 // (C) 2003 Jackson Harper, All rights reserved
13 using System.Collections;
15 namespace Mono.ILASM {
17 public class FieldTable {
19 private class FieldTableItem {
21 private static readonly int DefinedFlag = 2;
25 public ArrayList LocationList;
26 public FieldDef Field;
28 public FieldTableItem (FieldDef field, Location location)
32 LocationList = new ArrayList ();
33 LocationList.Add (location);
37 get { return ((flags & DefinedFlag) != 0); }
47 protected Hashtable table;
48 protected ClassDef parent_class;
50 public FieldTable (ClassDef parent_class)
52 this.parent_class = parent_class;
53 table = new Hashtable ();
56 public Field GetReference (TypeRef type, string name, Location location)
58 FieldTableItem item = table[name] as FieldTableItem;
61 item.LocationList.Add (location);
65 FieldDef field = parent_class.AddField (name, type.Type);
66 AddReferenced (name, field, location);
71 public FieldDef AddDefinition (FieldAttr field_attr, string name,
72 TypeRef type, Location location)
74 FieldTableItem item = (FieldTableItem) table[name];
77 FieldDef field = parent_class.AddField (field_attr, name, type.Type);
78 AddDefined (name, field, location);
82 item.Field.AddFieldAttr (field_attr);
88 public bool CheckDefined ()
90 foreach (DictionaryEntry dic_entry in table) {
91 FieldTableItem table_item = (FieldTableItem) dic_entry.Value;
92 if (table_item.Defined)
94 throw new Exception (String.Format ("Field: {0} is not defined.", dic_entry.Key));
99 protected void AddDefined (string signature, FieldDef field, Location location)
101 if (table.Contains (signature))
104 FieldTableItem item = new FieldTableItem (field, location);
107 table[signature] = item;
110 protected void AddReferenced (string signature, FieldDef field, Location location)
112 FieldTableItem item = new FieldTableItem (field, location);
114 table[signature] = item;
118 /// If a field is allready defined throw an Error
120 protected void CheckExists (string signature)
122 FieldTableItem item = table[signature] as FieldTableItem;
124 if ((item != null) && (item.Defined)) {
125 throw new Exception (String.Format ("Field: {0} defined in multiple locations.",