2 // Mono.ILASM.ClassTable.cs
5 // Jackson Harper (Jackson@LatitudeGeo.com)
7 // (C) 2003 Jackson Harper, All rights reserved
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class ClassTable {
18 private class ClassTableItem {
20 private static readonly int DefinedFlag = 2;
24 public ArrayList LocationList;
27 public ClassTableItem (Class klass, Location location)
31 LocationList = new ArrayList ();
32 LocationList.Add (location);
36 get { return ((flags & DefinedFlag) != 0); }
46 protected readonly TypeAttr DefaultAttr;
47 protected Hashtable table;
48 protected PEFile pefile;
50 public ClassTable (PEFile pefile)
52 DefaultAttr = TypeAttr.Public;
54 table = new Hashtable ();
57 public Class Get (string full_name)
59 ClassTableItem item = table[full_name] as ClassTableItem;
67 public Class GetReference (string full_name, Location location)
69 ClassTableItem item = table[full_name] as ClassTableItem;
72 item.LocationList.Add (location);
76 string name_space, name;
77 GetNameAndNamespace (full_name, out name_space, out name);
79 Class klass = pefile.AddClass (DefaultAttr, name_space, name);
80 AddReference (full_name, klass, location);
85 public void AddDefined (string full_name, Class klass, Location location)
87 ClassTableItem item = table[full_name] as ClassTableItem;
90 item = new ClassTableItem (klass, location);
91 } else if (item.Defined) {
92 throw new Exception (String.Format
93 ("Class: {0} defined in multiple locations.", full_name));
99 protected void AddReference (string full_name, Class klass, Location location)
101 if (table.Contains (full_name))
104 ClassTableItem item = new ClassTableItem (klass, location);
106 table[full_name] = item;
109 protected void GetNameAndNamespace (string full_name,
110 out string name_space, out string name) {
112 int last_dot = full_name.LastIndexOf ('.');
115 name_space = String.Empty;
120 name_space = full_name.Substring (0, last_dot);
121 name = full_name.Substring (last_dot + 1);