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 FieldDef : ICustomAttrTarget {
19 private ITypeRef type;
20 private PEAPI.FieldAttr attr;
21 private PEAPI.FieldDef field_def;
22 private ArrayList customattr_list;
23 private PEAPI.NativeType native_type;
25 private bool offset_set;
26 private bool datavalue_set;
27 private bool value_set;
29 private bool is_resolved;
32 private PEAPI.Constant constant;
33 private string at_data_id;
35 public FieldDef (PEAPI.FieldAttr attr, string name,
43 datavalue_set = false;
55 public PEAPI.FieldDef PeapiFieldDef {
56 get { return field_def; }
59 public bool IsStatic {
60 get { return (attr & PEAPI.FieldAttr.Static) != 0; }
63 public PEAPI.FieldAttr Attributes {
68 public ITypeRef Type {
72 public void SetOffset (uint val)
78 public void SetValue (PEAPI.Constant constant)
81 this.constant = constant;
84 public void AddDataValue (string at_data_id)
86 this.at_data_id = at_data_id;
89 public void AddCustomAttribute (CustomAttr customattr)
91 if (customattr_list == null)
92 customattr_list = new ArrayList ();
94 customattr_list.Add (customattr);
97 public void AddMarshalInfo (PEAPI.NativeType native_type)
99 this.native_type = native_type;
102 public PEAPI.FieldDef Resolve (CodeGen code_gen)
107 type.Resolve (code_gen);
108 field_def = code_gen.PEFile.AddField (attr, name, type.PeapiType);
115 public PEAPI.FieldDef Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
120 type.Resolve (code_gen);
121 field_def = classdef.AddField (attr, name, type.PeapiType);
123 if (customattr_list != null)
124 foreach (CustomAttr customattr in customattr_list)
125 customattr.AddTo (code_gen, field_def);
127 if (native_type != null)
128 field_def.SetMarshalInfo (native_type);
136 /// Define a global field
138 public void Define (CodeGen code_gen)
141 WriteCode (code_gen, field_def);
145 /// Define a field member of the specified class
147 public void Define (CodeGen code_gen, PEAPI.ClassDef class_def)
149 Resolve (code_gen, class_def);
150 WriteCode (code_gen, field_def);
153 protected void WriteCode (CodeGen code_gen, PEAPI.FieldDef field_def)
156 field_def.SetOffset (offset);
159 PEAPI.ByteArrConst dc = constant as PEAPI.ByteArrConst;
161 dc.Type = type.PeapiType;
162 field_def.AddValue (constant);
165 if (at_data_id != null) {
166 PEAPI.DataConstant dc = code_gen.GetDataConst (at_data_id);
167 field_def.AddDataValue (dc);