dlr bug
[mcs.git] / ilasm / codegen / PropertyDef.cs
blob33b7035c65c0fed93327c6a8c02e02e7e816b11c
1 //
2 // Mono.ILASM.PropertyDef
3 //
4 // Author(s):
5 // Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All right reserved
8 //
11 using System;
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class PropertyDef : ICustomAttrTarget {
18 private FeatureAttr attr;
19 private string name;
20 private BaseTypeRef type;
21 private ArrayList arg_list;
22 private PEAPI.Property prop_def;
23 private bool is_resolved;
24 private ArrayList customattr_list;
26 private MethodRef _get;
27 private MethodRef _set;
28 private ArrayList other_list;
29 private PEAPI.Constant init_value;
31 public PropertyDef (FeatureAttr attr, BaseTypeRef type, string name, ArrayList arg_list)
33 this.attr = attr;
34 this.name = name;
35 this.type = type;
36 this.arg_list = arg_list;
37 is_resolved = false;
40 public void AddCustomAttribute (CustomAttr customattr)
42 if (customattr_list == null)
43 customattr_list = new ArrayList ();
45 customattr_list.Add (customattr);
48 public PEAPI.Property Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
50 if (is_resolved)
51 return prop_def;
53 PEAPI.Type[] type_list = new PEAPI.Type[arg_list.Count];
55 for (int i=0; i<type_list.Length; i++) {
56 BaseTypeRef arg_type = (BaseTypeRef) arg_list[i];
57 arg_type.Resolve (code_gen);
58 type_list[i] = arg_type.PeapiType;
61 type.Resolve (code_gen);
62 prop_def = classdef.AddProperty (name, type.PeapiType, type_list);
64 if ((attr & FeatureAttr.Rtspecialname) != 0)
65 prop_def.SetRTSpecialName ();
67 if ((attr & FeatureAttr.Specialname) != 0)
68 prop_def.SetSpecialName ();
70 prop_def.SetInstance ((attr & FeatureAttr.Instance) != 0);
72 if (customattr_list != null)
73 foreach (CustomAttr customattr in customattr_list)
74 customattr.AddTo (code_gen, prop_def);
77 is_resolved = true;
79 return prop_def;
82 private PEAPI.MethodDef AsMethodDef (PEAPI.Method method, string type)
84 PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
85 if (methoddef == null)
86 Report.Error (type + " method of property " + name + " not found");
87 return methoddef;
90 public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
92 if (!is_resolved)
93 Resolve (code_gen, classdef);
95 if (_get != null) {
96 _get.Resolve (code_gen);
97 prop_def.AddGetter (AsMethodDef (_get.PeapiMethod, "get"));
100 if (_set != null) {
101 _set.Resolve (code_gen);
102 prop_def.AddSetter (AsMethodDef (_set.PeapiMethod, "set"));
105 if (other_list != null) {
106 foreach (MethodRef otherm in other_list) {
107 otherm.Resolve (code_gen);
108 prop_def.AddOther (AsMethodDef (otherm.PeapiMethod, "other"));
112 if (init_value != null)
113 prop_def.AddInitValue (init_value);
116 public void AddGet (MethodRef _get)
118 this._get = _get;
121 public void AddSet (MethodRef _set)
123 this._set = _set;
126 public void AddOther (MethodRef other)
128 if (other_list == null)
129 other_list = new ArrayList ();
130 other_list.Add (other);
133 public void AddInitValue (PEAPI.Constant init_value)
135 this.init_value = init_value;