-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFieldTable.cs
More file actions
130 lines (101 loc) · 2.79 KB
/
Copy pathFieldTable.cs
File metadata and controls
130 lines (101 loc) · 2.79 KB
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
//
// Mono.ILASM.FieldTable.cs
//
// Author(s):
// Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//
using PEAPI;
using System;
using System.Text;
using System.Collections;
namespace Mono.ILASM {
public class FieldTable {
private class FieldTableItem {
private static readonly int DefinedFlag = 2;
private int flags;
public ArrayList LocationList;
public FieldDef Field;
public FieldTableItem (FieldDef field, Location location)
{
flags = 0;
Field = field;
LocationList = new ArrayList ();
LocationList.Add (location);
}
public bool Defined {
get { return ((flags & DefinedFlag) != 0); }
set {
if (value)
flags |= DefinedFlag;
else
flags ^= DefinedFlag;
}
}
}
protected Hashtable table;
protected ClassDef parent_class;
public FieldTable (ClassDef parent_class)
{
this.parent_class = parent_class;
table = new Hashtable ();
}
public Field GetReference (TypeRef type, string name, Location location)
{
FieldTableItem item = table[name] as FieldTableItem;
if (item != null) {
item.LocationList.Add (location);
return item.Field;
}
FieldDef field = parent_class.AddField (name, type.Type);
AddReferenced (name, field, location);
return field;
}
public FieldDef AddDefinition (FieldAttr field_attr, string name,
TypeRef type, Location location)
{
FieldTableItem item = (FieldTableItem) table[name];
if (item == null) {
FieldDef field = parent_class.AddField (field_attr, name, type.Type);
AddDefined (name, field, location);
return field;
}
item.Field.AddFieldAttr (field_attr);
item.Defined = true;
return item.Field;
}
public bool CheckDefined ()
{
foreach (DictionaryEntry dic_entry in table) {
FieldTableItem table_item = (FieldTableItem) dic_entry.Value;
if (table_item.Defined)
continue;
Report.Error (String.Format ("Field: {0} is not defined.", dic_entry.Key));
}
return true;
}
protected void AddDefined (string signature, FieldDef field, Location location)
{
if (table.Contains (signature))
return;
FieldTableItem item = new FieldTableItem (field, location);
item.Defined = true;
table[signature] = item;
}
protected void AddReferenced (string signature, FieldDef field, Location location)
{
FieldTableItem item = new FieldTableItem (field, location);
table[signature] = item;
}
/// <summary>
/// If a field is allready defined throw an Error
/// </summary>
protected void CheckExists (string signature)
{
FieldTableItem item = table[signature] as FieldTableItem;
if ((item != null) && (item.Defined))
Report.Error ("Field: " + signature + " defined in multiple locations.");
}
}
}