private int flags;
public ArrayList LocationList;
- public Class Class;
+ public ClassDef Class;
+ public MethodTable method_table;
+ public FieldTable field_table;
- public ClassTableItem (Class klass, Location location)
+ public ClassTableItem (ClassDef klass, Location location)
{
flags = 0;
Class = klass;
LocationList = new ArrayList ();
LocationList.Add (location);
+ method_table = new MethodTable (klass);
+ field_table = new FieldTable (klass);
}
public bool Defined {
flags ^= DefinedFlag;
}
}
+
+ public bool CheckDefined ()
+ {
+ if (!Defined)
+ return false;
+
+ if (!FieldTable.CheckDefined ())
+ return false;
+
+ if (!MethodTable.CheckDefined ())
+ return false;
+
+ return true;
+ }
+
+ public MethodTable MethodTable {
+ get { return method_table; }
+ }
+
+ public FieldTable FieldTable {
+ get { return field_table; }
+ }
+
}
protected readonly TypeAttr DefaultAttr;
string name_space, name;
GetNameAndNamespace (full_name, out name_space, out name);
- Class klass = pefile.AddClass (DefaultAttr, name_space, name);
+ ClassDef klass = pefile.AddClass (DefaultAttr, name_space, name);
AddReference (full_name, klass, location);
-
return klass;
}
+ public MethodTable GetMethodTable (string full_name, Location location)
+ {
+ ClassTableItem item = table[full_name] as ClassTableItem;
+
+ if (item == null) {
+ GetReference (full_name, location);
+ return GetMethodTable (full_name, location);
+ }
+
+ return item.MethodTable;
+ }
+
+ public FieldTable GetFieldTable (string full_name, Location location)
+ {
+ ClassTableItem item = table[full_name] as ClassTableItem;
+
+ if (item == null) {
+ GetReference (full_name, location);
+ return GetFieldTable (full_name, location);
+ }
+
+ return item.FieldTable;
+ }
+
public ClassDef AddDefinition (string name_space, string name,
TypeAttr attr, Location location)
{
string full_name = String.Format ("{0}.{1}", name_space, name);
- ClassTableItem item = table[full_name] as ClassTableItem;
- if ((item != null) && (item.Defined)) {
- throw new Exception (String.Format ("Class: {0} defined in multiple locations.",
- full_name));
+ ClassTableItem item = (ClassTableItem) table[full_name];
+
+ if (item == null) {
+ ClassDef klass = pefile.AddClass (attr, name_space, name);
+ AddDefined (full_name, klass, location);
+ return klass;
+ }
+
+ item.Class.AddAttribute (attr);
+ item.Defined = true;
+
+ return item.Class;
+ }
+
+ public ClassDef AddDefinition (string name_space, string name,
+ TypeAttr attr, Class parent, Location location)
+ {
+ string full_name = String.Format ("{0}.{1}", name_space, name);
+
+ ClassTableItem item = (ClassTableItem) table[full_name];
+
+ if (item == null) {
+ ClassDef klass = pefile.AddClass (attr, name_space, name, parent);
+ AddDefined (full_name, klass, location);
+ return klass;
}
- ClassDef klass = pefile.AddClass (attr, name_space, name);
- AddDefined (full_name, klass, location);
+ /// TODO: Need to set parent, will need to modify PEAPI for this.
+ item.Class.AddAttribute (attr);
+ item.Defined = true;
- return klass;
+ return item.Class;
}
/// <summary>
{
foreach (DictionaryEntry dic_entry in table) {
ClassTableItem table_item = (ClassTableItem) dic_entry.Value;
- if (table_item.Defined)
+ if (table_item.CheckDefined ())
continue;
throw new Exception (String.Format ("Type: {0} is not defined.", dic_entry.Key));
}
}
- protected void AddDefined (string full_name, Class klass, Location location)
+ /// <summary>
+ /// If a type is allready defined throw an Error
+ /// </summary>
+ protected void CheckExists (string full_name)
+ {
+ ClassTableItem item = table[full_name] as ClassTableItem;
+
+ if ((item != null) && (item.Defined)) {
+ throw new Exception (String.Format ("Class: {0} defined in multiple locations.",
+ full_name));
+ }
+ }
+
+ protected void AddDefined (string full_name, ClassDef klass, Location location)
{
if (table.Contains (full_name))
return;
table[full_name] = item;
}
- protected void AddReference (string full_name, Class klass, Location location)
+ protected void AddReference (string full_name, ClassDef klass, Location location)
{
if (table.Contains (full_name))
return;