* ExternTypeRef.cs: New file - Represents a reference to a type in
[mono.git] / mcs / ilasm / codegen / FieldDef.cs
1 //
2 // Mono.ILASM.FieldDef
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10
11 using System;
12
13 namespace Mono.ILASM {
14
15         public class FieldDef {
16
17                 private string name;
18                 private ITypeRef type;
19                 private PEAPI.FieldAttr attr;
20                 private PEAPI.FieldDef field_def;
21
22                 private bool offset_set;
23                 private bool datavalue_set;
24                 private bool value_set;
25
26                 private uint offset;
27
28                 public FieldDef (PEAPI.FieldAttr attr, string name,
29                                 ITypeRef type)
30                 {
31                         this.attr = attr;
32                         this.name = name;
33                         this.type = type;
34
35                         offset_set = false;
36                         datavalue_set = false;
37                         value_set = false;
38                 }
39
40                 public string Name {
41                         get { return name; }
42                 }
43
44                 public PEAPI.FieldDef FieldDef {
45                         get { return field_def; }
46                 }
47
48                 public void SetOffset (uint val) {
49                         offset_set = true;
50                         offset = val;
51                 }
52
53                 /// <summary>
54                 ///  Define a global field
55                 /// </summary>
56                 public void Define (CodeGen code_gen)
57                 {
58                         type.Resolve (code_gen);
59
60                         field_def = code_gen.PEFile.AddField (attr, name, type.PeapiType);
61
62                         if (offset_set) {
63                                 field_def.SetOffset (offset);
64
65                         }
66                 }
67
68                 /// <summary>
69                 ///  Define a field member of the specified class
70                 /// </summary>
71                 public void Define (CodeGen code_gen, PEAPI.ClassDef class_def)
72                 {
73                         type.Resolve (code_gen);
74
75                         class_def.AddField (attr, name, type.PeapiType);
76                 }
77         }
78
79 }
80
81
82