[corlib] Assume UTC if no $TZ set. Fixes #30360
[mono.git] / mcs / ilasm / codegen / FieldTable.cs
1 //
2 // Mono.ILASM.FieldTable.cs
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10 using PEAPI;
11 using System;
12 using System.Text;
13 using System.Collections;
14
15 namespace Mono.ILASM {
16
17         public class FieldTable {
18
19                 private class FieldTableItem {
20                 
21                         private static readonly int DefinedFlag = 2;
22         
23                         private int flags;
24
25                         public ArrayList LocationList;
26                         public FieldDef Field;
27
28                         public FieldTableItem (FieldDef field, Location location)
29                         {
30                                 flags = 0;
31                                 Field = field;
32                                 LocationList = new ArrayList ();
33                                 LocationList.Add (location);
34                         }
35                 
36                         public bool Defined {
37                                 get { return ((flags & DefinedFlag) != 0); }
38                                 set {
39                                         if (value)
40                                                 flags |= DefinedFlag;
41                                         else
42                                                 flags ^= DefinedFlag;
43                                 }
44                         }
45                 }
46
47                 protected Hashtable table;
48                 protected ClassDef parent_class;
49                 
50                 public FieldTable (ClassDef parent_class)
51                 {
52                         this.parent_class = parent_class;
53                         table = new Hashtable ();
54                 }
55
56                 public Field GetReference (TypeRef type, string name, Location location)
57                 {
58                         FieldTableItem item = table[name] as FieldTableItem;
59                         
60                         if (item != null) {
61                                 item.LocationList.Add (location);
62                                 return item.Field;
63                         }
64                         
65                         FieldDef field = parent_class.AddField (name, type.Type);
66                         AddReferenced (name, field, location);
67
68                         return field;
69                 }
70         
71                 public FieldDef AddDefinition (FieldAttr field_attr, string name, 
72                         TypeRef type, Location location) 
73                 {
74                         FieldTableItem item = (FieldTableItem) table[name];
75                         
76                         if (item == null) {
77                                 FieldDef field = parent_class.AddField (field_attr, name, type.Type);
78                                 AddDefined (name, field, location);
79                                 return field;
80                         }
81                         
82                         item.Field.AddFieldAttr (field_attr);
83                         item.Defined = true;
84                         
85                         return item.Field;
86                 }
87
88                 public bool CheckDefined ()
89                 {
90                         foreach (DictionaryEntry dic_entry in table) {
91                                 FieldTableItem table_item = (FieldTableItem) dic_entry.Value;
92                                 if (table_item.Defined)
93                                         continue;
94                                 Report.Error (String.Format ("Field: {0} is not defined.", dic_entry.Key));
95                         }
96                         return true;
97                 }
98                         
99                 protected void AddDefined (string signature, FieldDef field, Location location)
100                 {
101                         if (table.Contains (signature))
102                                 return; 
103
104                         FieldTableItem item = new FieldTableItem (field, location);
105                         item.Defined = true;
106
107                         table[signature] = item;
108                 }
109
110                 protected void AddReferenced (string signature, FieldDef field, Location location)
111                 {
112                         FieldTableItem item = new FieldTableItem (field, location);
113                         
114                         table[signature] = item;
115                 }
116
117                 /// <summary>
118                 ///  If a field is allready defined throw an Error
119                 /// </summary>
120                 protected void CheckExists (string signature) 
121                 {
122                         FieldTableItem item = table[signature] as FieldTableItem;
123                         
124                         if ((item != null) && (item.Defined))
125                                 Report.Error ("Field: " + signature + " defined in multiple locations.");
126                 }
127         }
128
129 }
130