[amd64] Save missing register
[mono.git] / mcs / ilasm / codegen / PropertyDef.cs
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 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public class PropertyDef : ICustomAttrTarget {
17
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;
25
26                 private MethodRef _get;
27                 private MethodRef _set;
28                 private ArrayList other_list;
29                 private PEAPI.Constant init_value;
30
31                 public PropertyDef (FeatureAttr attr, BaseTypeRef type, string name, ArrayList arg_list)
32                 {
33                         this.attr = attr;
34                         this.name = name;
35                         this.type = type;
36                         this.arg_list = arg_list;
37                         is_resolved = false;
38                 }
39
40                 public void AddCustomAttribute (CustomAttr customattr)
41                 {
42                         if (customattr_list == null)
43                                 customattr_list = new ArrayList ();
44
45                         customattr_list.Add (customattr);
46                 }
47
48                 public PEAPI.Property Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
49                 {
50                         if (is_resolved)
51                                 return prop_def;
52
53                         PEAPI.Type[] type_list = new PEAPI.Type[arg_list.Count];
54
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;
59                         }
60
61                         type.Resolve (code_gen);
62                         prop_def = classdef.AddProperty (name, type.PeapiType, type_list);
63
64                         if ((attr & FeatureAttr.Rtspecialname) != 0)
65                                 prop_def.SetRTSpecialName ();
66
67                         if ((attr & FeatureAttr.Specialname) != 0)
68                                 prop_def.SetSpecialName ();
69
70                         prop_def.SetInstance ((attr & FeatureAttr.Instance) != 0);
71
72                         if (customattr_list != null)
73                                 foreach (CustomAttr customattr in customattr_list)
74                                         customattr.AddTo (code_gen, prop_def);
75
76
77                         is_resolved = true;
78
79                         return prop_def;
80                 }
81                 
82                 private PEAPI.MethodDef AsMethodDef (PEAPI.Method method, string type)
83                 {
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;
88                 }
89
90                 public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
91                 {
92                         if (!is_resolved)
93                                 Resolve (code_gen, classdef);
94
95                         if (_get != null) {
96                                 _get.Resolve (code_gen);
97                                 prop_def.AddGetter (AsMethodDef (_get.PeapiMethod, "get"));
98                         }
99
100                         if (_set != null) {
101                                 _set.Resolve (code_gen);
102                                 prop_def.AddSetter (AsMethodDef (_set.PeapiMethod, "set"));
103                         }
104
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"));
109                                 }
110                         }
111
112                         if (init_value != null)
113                                 prop_def.AddInitValue (init_value);
114                 }
115
116                 public void AddGet (MethodRef _get)
117                 {
118                         this._get = _get;
119                 }
120
121                 public void AddSet (MethodRef _set)
122                 {
123                         this._set = _set;
124                 }
125
126                 public void AddOther (MethodRef other)
127                 {
128                         if (other_list == null)
129                                 other_list = new ArrayList ();
130                         other_list.Add (other);
131                 }
132
133                 public void AddInitValue (PEAPI.Constant init_value)
134                 {
135                         this.init_value = init_value;
136                 }
137         }
138
139 }
140