~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Mono.Cecil/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:
5
5
//   Jb Evain (jbevain@gmail.com)
6
6
//
7
 
// (C) 2005 - 2007 Jb Evain
 
7
// Copyright (c) 2008 - 2010 Jb Evain
8
8
//
9
9
// Permission is hereby granted, free of charge, to any person obtaining
10
10
// a copy of this software and associated documentation files (the
26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
27
//
28
28
 
 
29
using Mono.Collections.Generic;
 
30
 
29
31
namespace Mono.Cecil {
30
32
 
31
 
        public sealed class ParameterDefinition : ParameterReference, IHasMarshalSpec,
32
 
                IMetadataTokenProvider, ICustomAttributeProvider, IHasConstant {
33
 
 
34
 
                ParameterAttributes m_attributes;
35
 
 
36
 
                bool m_hasConstant;
37
 
                object m_const;
38
 
 
39
 
                MethodReference m_method;
40
 
                CustomAttributeCollection m_customAttrs;
41
 
 
42
 
                MarshalSpec m_marshalDesc;
 
33
        public sealed class ParameterDefinition : ParameterReference, ICustomAttributeProvider, IConstantProvider, IMarshalInfoProvider {
 
34
 
 
35
                ushort attributes;
 
36
 
 
37
                internal IMethodSignature method;
 
38
 
 
39
                object constant = Mixin.NotResolved;
 
40
                Collection<CustomAttribute> custom_attributes;
 
41
                MarshalInfo marshal_info;
43
42
 
44
43
                public ParameterAttributes Attributes {
45
 
                        get { return m_attributes; }
46
 
                        set { m_attributes = value; }
 
44
                        get { return (ParameterAttributes) attributes; }
 
45
                        set { attributes = (ushort) value; }
 
46
                }
 
47
 
 
48
                public IMethodSignature Method {
 
49
                        get { return method; }
47
50
                }
48
51
 
49
52
                public bool HasConstant {
50
 
                        get { return m_hasConstant; }
 
53
                        get {
 
54
                                ResolveConstant ();
 
55
 
 
56
                                return constant != Mixin.NoValue;
 
57
                        }
 
58
                        set { if (!value) constant = Mixin.NoValue; }
51
59
                }
52
60
 
53
61
                public object Constant {
54
 
                        get { return m_const; }
55
 
                        set {
56
 
                                m_hasConstant = true;
57
 
                                m_const = value;
58
 
                        }
 
62
                        get { return HasConstant ? constant : null;     }
 
63
                        set { constant = value; }
59
64
                }
60
65
 
61
 
                public MethodReference Method {
62
 
                        get { return m_method; }
63
 
                        set { m_method = value; }
 
66
                void ResolveConstant ()
 
67
                {
 
68
                        if (constant != Mixin.NotResolved)
 
69
                                return;
 
70
 
 
71
                        this.ResolveConstant (ref constant, parameter_type.Module);
64
72
                }
65
73
 
66
74
                public bool HasCustomAttributes {
67
 
                        get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
68
 
                }
69
 
 
70
 
                public CustomAttributeCollection CustomAttributes {
71
 
                        get {
72
 
                                if (m_customAttrs == null)
73
 
                                        m_customAttrs = new CustomAttributeCollection (this);
74
 
 
75
 
                                return m_customAttrs;
76
 
                        }
77
 
                }
78
 
 
79
 
                public MarshalSpec MarshalSpec {
80
 
                        get { return m_marshalDesc; }
81
 
                        set {
82
 
                                m_marshalDesc = value;
83
 
                                if (value != null)
84
 
                                        m_attributes |= ParameterAttributes.HasFieldMarshal;
85
 
                                else
86
 
                                        m_attributes &= ~ParameterAttributes.HasFieldMarshal;
87
 
                        }
 
75
                        get {
 
76
                                if (custom_attributes != null)
 
77
                                        return custom_attributes.Count > 0;
 
78
 
 
79
                                return this.GetHasCustomAttributes (parameter_type.Module);
 
80
                        }
 
81
                }
 
82
 
 
83
                public Collection<CustomAttribute> CustomAttributes {
 
84
                        get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (parameter_type.Module)); }
 
85
                }
 
86
 
 
87
                public bool HasMarshalInfo {
 
88
                        get {
 
89
                                if (marshal_info != null)
 
90
                                        return true;
 
91
 
 
92
                                return this.GetHasMarshalInfo (parameter_type.Module);
 
93
                        }
 
94
                }
 
95
 
 
96
                public MarshalInfo MarshalInfo {
 
97
                        get { return marshal_info ?? (marshal_info = this.GetMarshalInfo (parameter_type.Module)); }
 
98
                        set { marshal_info = value; }
88
99
                }
89
100
 
90
101
                #region ParameterAttributes
91
102
 
92
103
                public bool IsIn {
93
 
                        get { return (m_attributes & ParameterAttributes.In) != 0; }
94
 
                        set {
95
 
                                if (value)
96
 
                                        m_attributes |= ParameterAttributes.In;
97
 
                                else
98
 
                                        m_attributes &= ~ParameterAttributes.In;
99
 
                        }
 
104
                        get { return attributes.GetAttributes ((ushort) ParameterAttributes.In); }
 
105
                        set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.In, value); }
100
106
                }
101
107
 
102
108
                public bool IsOut {
103
 
                        get { return (m_attributes & ParameterAttributes.Out) != 0; }
104
 
                        set {
105
 
                                if (value)
106
 
                                        m_attributes |= ParameterAttributes.Out;
107
 
                                else
108
 
                                        m_attributes &= ~ParameterAttributes.Out;
109
 
                        }
110
 
                }
111
 
 
112
 
                public bool IsRetval {
113
 
                        get { return (m_attributes & ParameterAttributes.Retval) != 0; }
114
 
                        set {
115
 
                                if (value)
116
 
                                        m_attributes |= ParameterAttributes.Retval;
117
 
                                else
118
 
                                        m_attributes &= ~ParameterAttributes.Retval;
119
 
                        }
 
109
                        get { return attributes.GetAttributes ((ushort) ParameterAttributes.Out); }
 
110
                        set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Out, value); }
120
111
                }
121
112
 
122
113
                public bool IsLcid {
123
 
                        get { return (m_attributes & ParameterAttributes.Lcid) != 0; }
124
 
                        set {
125
 
                                if (value)
126
 
                                        m_attributes |= ParameterAttributes.Lcid;
127
 
                                else
128
 
                                        m_attributes &= ~ParameterAttributes.Lcid;
129
 
                        }
 
114
                        get { return attributes.GetAttributes ((ushort) ParameterAttributes.Lcid); }
 
115
                        set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Lcid, value); }
 
116
                }
 
117
 
 
118
                public bool IsReturnValue {
 
119
                        get { return attributes.GetAttributes ((ushort) ParameterAttributes.Retval); }
 
120
                        set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Retval, value); }
130
121
                }
131
122
 
132
123
                public bool IsOptional {
133
 
                        get { return (m_attributes & ParameterAttributes.Optional) != 0; }
134
 
                        set {
135
 
                                if (value)
136
 
                                        m_attributes |= ParameterAttributes.Optional;
137
 
                                else
138
 
                                        m_attributes &= ~ParameterAttributes.Optional;
139
 
                        }
 
124
                        get { return attributes.GetAttributes ((ushort) ParameterAttributes.Optional); }
 
125
                        set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.Optional, value); }
140
126
                }
141
127
 
142
128
                public bool HasDefault {
143
 
                        get { return (m_attributes & ParameterAttributes.HasDefault) != 0; }
144
 
                        set {
145
 
                                if (value)
146
 
                                        m_attributes |= ParameterAttributes.HasDefault;
147
 
                                else
148
 
                                        m_attributes &= ~ParameterAttributes.HasDefault;
149
 
                        }
 
129
                        get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasDefault); }
 
130
                        set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasDefault, value); }
 
131
                }
 
132
 
 
133
                public bool HasFieldMarshal {
 
134
                        get { return attributes.GetAttributes ((ushort) ParameterAttributes.HasFieldMarshal); }
 
135
                        set { attributes = attributes.SetAttributes ((ushort) ParameterAttributes.HasFieldMarshal, value); }
150
136
                }
151
137
 
152
138
                #endregion
153
139
 
154
 
                public ParameterDefinition (TypeReference paramType) :
155
 
                        this (string.Empty, -1, (ParameterAttributes) 0, paramType)
156
 
                {
 
140
                public ParameterDefinition (TypeReference parameterType)
 
141
                        : this (string.Empty, ParameterAttributes.None, parameterType)
 
142
                {
 
143
                }
 
144
 
 
145
                public ParameterDefinition (string name, ParameterAttributes attributes, TypeReference parameterType)
 
146
                        : base (name, parameterType)
 
147
                {
 
148
                        this.attributes = (ushort) attributes;
 
149
                        this.token = new MetadataToken (TokenType.Param);
157
150
                }
158
151
 
159
152
                public override ParameterDefinition Resolve ()
160
153
                {
161
154
                        return this;
162
155
                }
163
 
 
164
 
                public ParameterDefinition (string name, int seq, ParameterAttributes attrs, TypeReference paramType) : base (name, seq, paramType)
165
 
                {
166
 
                        m_attributes = attrs;
167
 
                }
168
 
 
169
 
                public ParameterDefinition Clone ()
170
 
                {
171
 
                        return Clone (this, new ImportContext (NullReferenceImporter.Instance, m_method));
172
 
                }
173
 
 
174
 
                internal static ParameterDefinition Clone (ParameterDefinition param, ImportContext context)
175
 
                {
176
 
                        ParameterDefinition np = new ParameterDefinition (
177
 
                                param.Name,
178
 
                                param.Sequence,
179
 
                                param.Attributes,
180
 
                                context.Import (param.ParameterType));
181
 
 
182
 
                        if (param.HasConstant)
183
 
                                np.Constant = param.Constant;
184
 
 
185
 
                        if (param.MarshalSpec != null)
186
 
                                np.MarshalSpec = param.MarshalSpec.CloneInto (np);
187
 
 
188
 
                        foreach (CustomAttribute ca in param.CustomAttributes)
189
 
                                np.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
190
 
 
191
 
                        return np;
192
 
                }
193
 
 
194
 
                public override void Accept (IReflectionVisitor visitor)
195
 
                {
196
 
                        visitor.VisitParameterDefinition (this);
197
 
 
198
 
                        if (this.MarshalSpec != null)
199
 
                                this.MarshalSpec.Accept (visitor);
200
 
 
201
 
                        this.CustomAttributes.Accept (visitor);
202
 
                }
203
156
        }
204
157
}