Debian Codegraph @

mcs/tools/cil-strip/Mono.Cecil/ParameterDefinition.cs

raw
1 //
2 // ParameterDefinition.cs
3 //
4 // Author:
5 // Jb Evain ([email protected])
6 //
7 // (C) 2005 - 2007 Jb Evain
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 namespace Mono.Cecil {
30
31 internal 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;
43
44 public ParameterAttributes Attributes {
45 get { return m_attributes; }
46 set { m_attributes = value; }
47 }
48
49 public bool HasConstant {
50 get { return m_hasConstant; }
51 }
52
53 public object Constant {
54 get { return m_const; }
55 set {
56 m_hasConstant = true;
57 m_const = value;
58 }
59 }
60
61 public MethodReference Method {
62 get { return m_method; }
63 set { m_method = value; }
64 }
65
66 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 }
88 }
89
90 #region ParameterAttributes
91
92 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 }
100 }
101
102 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 }
120 }
121
122 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 }
130 }
131
132 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 }
140 }
141
142 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 }
150 }
151
152 #endregion
153
154 public ParameterDefinition (TypeReference paramType) :
155 this (string.Empty, -1, (ParameterAttributes) 0, paramType)
156 {
157 }
158
159 public override ParameterDefinition Resolve ()
160 {
161 return this;
162 }
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 }
204 }