Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PropertyDef.cs « codegen « ilasm « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef35adcae30e131215c06269fe960d350fd7193e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// Mono.ILASM.PropertyDef
//
// Author(s):
//  Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All right reserved
//


using System;
using System.Collections;

namespace Mono.ILASM {

        public class PropertyDef : ICustomAttrTarget {

                private FeatureAttr attr;
                private string name;
                private BaseTypeRef type;
                private ArrayList arg_list;
                private PEAPI.Property prop_def;
                private bool is_resolved;
                private ArrayList customattr_list;

                private MethodRef _get;
                private MethodRef _set;
                private MethodRef other;
                private PEAPI.Constant init_value;

                public PropertyDef (FeatureAttr attr, BaseTypeRef type, string name, ArrayList arg_list)
                {
                        this.attr = attr;
                        this.name = name;
                        this.type = type;
                        this.arg_list = arg_list;
                        is_resolved = false;
                }

                public void AddCustomAttribute (CustomAttr customattr)
                {
                        if (customattr_list == null)
                                customattr_list = new ArrayList ();

                        customattr_list.Add (customattr);
                }

                public PEAPI.Property Resolve (CodeGen code_gen, PEAPI.ClassDef classdef)
                {
                        if (is_resolved)
                                return prop_def;

                        PEAPI.Type[] type_list = new PEAPI.Type[arg_list.Count];

                        for (int i=0; i<type_list.Length; i++) {
                                BaseTypeRef arg_type = (BaseTypeRef) arg_list[i];
                                arg_type.Resolve (code_gen);
                                type_list[i] = arg_type.PeapiType;
                        }

                        type.Resolve (code_gen);
                        prop_def = classdef.AddProperty (name, type.PeapiType, type_list);

                        if ((attr & FeatureAttr.Rtspecialname) != 0)
                                prop_def.SetRTSpecialName ();

                        if ((attr & FeatureAttr.Specialname) != 0)
                                prop_def.SetSpecialName ();

                        prop_def.SetInstance ((attr & FeatureAttr.Instance) != 0);

                        if (customattr_list != null)
                                foreach (CustomAttr customattr in customattr_list)
                                        customattr.AddTo (code_gen, prop_def);


                        is_resolved = true;

                        return prop_def;
                }
                
                private PEAPI.MethodDef AsMethodDef (PEAPI.Method method, string type)
                {
                        PEAPI.MethodDef methoddef = method as PEAPI.MethodDef;
                        if (methoddef == null)
                                Report.Error (type + " method of property " + name + " not found");
                        return methoddef;
                }

                public void Define (CodeGen code_gen, PEAPI.ClassDef classdef)
                {
                        if (!is_resolved)
                                Resolve (code_gen, classdef);

                        if (_get != null) {
                                _get.Resolve (code_gen);
                                prop_def.AddGetter (AsMethodDef (_get.PeapiMethod, "get"));
                        }

                        if (_set != null) {
                                _set.Resolve (code_gen);
                                prop_def.AddSetter (AsMethodDef (_set.PeapiMethod, "set"));
                        }

                        if (other != null) {
                                other.Resolve (code_gen);
                                prop_def.AddOther (AsMethodDef (other.PeapiMethod, "other"));
                        }

                        if (init_value != null)
                                prop_def.AddInitValue (init_value);
                }

                public void AddGet (MethodRef _get)
                {
                        this._get = _get;
                }

                public void AddSet (MethodRef _set)
                {
                        this._set = _set;
                }

                public void AddOther (MethodRef other)
                {
                        this.other = other;
                }

                public void AddInitValue (PEAPI.Constant init_value)
                {
                        this.init_value = init_value;
                }
        }

}