Debian Codegraph @

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

raw
1 //
2 // PInvokeInfo.cs
3 //
4 // Author:
5 // Jb Evain ([email protected])
6 //
7 // (C) 2005 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 PInvokeInfo : IReflectionVisitable {
32
33 MethodDefinition m_meth;
34
35 PInvokeAttributes m_attributes;
36 string m_entryPoint;
37 ModuleReference m_module;
38
39 public MethodDefinition Method {
40 get { return m_meth; }
41 }
42
43 public PInvokeAttributes Attributes {
44 get { return m_attributes; }
45 set { m_attributes = value; }
46 }
47
48 public string EntryPoint {
49 get { return m_entryPoint; }
50 set { m_entryPoint = value; }
51 }
52
53 public ModuleReference Module {
54 get { return m_module; }
55 set { m_module = value; }
56 }
57
58 #region PInvokeAttributes
59
60 public bool IsNoMangle {
61 get { return (m_attributes & PInvokeAttributes.NoMangle) != 0; }
62 set {
63 if (value)
64 m_attributes |= PInvokeAttributes.NoMangle;
65 else
66 m_attributes &= ~PInvokeAttributes.NoMangle;
67 }
68 }
69
70 public bool IsCharSetNotSpec {
71 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetNotSpec; }
72 set {
73 if (value) {
74 m_attributes &= ~PInvokeAttributes.CharSetMask;
75 m_attributes |= PInvokeAttributes.CharSetNotSpec;
76 } else
77 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetNotSpec);
78 }
79 }
80
81 public bool IsCharSetAnsi {
82 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAnsi; }
83 set {
84 if (value) {
85 m_attributes &= ~PInvokeAttributes.CharSetMask;
86 m_attributes |= PInvokeAttributes.CharSetAnsi;
87 } else
88 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAnsi);
89 }
90 }
91
92 public bool IsCharSetUnicode {
93 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetUnicode; }
94 set {
95 if (value) {
96 m_attributes &= ~PInvokeAttributes.CharSetMask;
97 m_attributes |= PInvokeAttributes.CharSetUnicode;
98 } else
99 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetUnicode);
100 }
101 }
102
103 public bool IsCharSetAuto {
104 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAuto; }
105 set {
106 if (value) {
107 m_attributes &= ~PInvokeAttributes.CharSetMask;
108 m_attributes |= PInvokeAttributes.CharSetAuto;
109 } else
110 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAuto);
111 }
112 }
113
114 public bool SupportsLastError {
115 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.SupportsLastError; }
116 set {
117 if (value) {
118 m_attributes &= ~PInvokeAttributes.CharSetMask;
119 m_attributes |= PInvokeAttributes.SupportsLastError;
120 } else
121 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.SupportsLastError);
122 }
123 }
124
125 public bool IsCallConvWinapi {
126 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvWinapi; }
127 set {
128 if (value) {
129 m_attributes &= ~PInvokeAttributes.CallConvMask;
130 m_attributes |= PInvokeAttributes.CallConvWinapi;
131 } else
132 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvWinapi);
133 }
134 }
135
136 public bool IsCallConvCdecl {
137 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvCdecl; }
138 set {
139 if (value) {
140 m_attributes &= ~PInvokeAttributes.CallConvMask;
141 m_attributes |= PInvokeAttributes.CallConvCdecl;
142 } else
143 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvCdecl);
144 }
145 }
146
147 public bool IsCallConvStdCall {
148 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvStdCall; }
149 set {
150 if (value) {
151 m_attributes &= ~PInvokeAttributes.CallConvMask;
152 m_attributes |= PInvokeAttributes.CallConvStdCall;
153 } else
154 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvStdCall);
155 }
156 }
157
158 public bool IsCallConvThiscall {
159 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvThiscall; }
160 set {
161 if (value) {
162 m_attributes &= ~PInvokeAttributes.CallConvMask;
163 m_attributes |= PInvokeAttributes.CallConvThiscall;
164 } else
165 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvThiscall);
166 }
167 }
168
169 public bool IsCallConvFastcall {
170 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvFastcall; }
171 set {
172 if (value) {
173 m_attributes &= ~PInvokeAttributes.CallConvMask;
174 m_attributes |= PInvokeAttributes.CallConvFastcall;
175 } else
176 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvFastcall);
177 }
178 }
179
180 #endregion
181
182 public PInvokeInfo (MethodDefinition meth)
183 {
184 m_meth = meth;
185 }
186
187 public PInvokeInfo (MethodDefinition meth, PInvokeAttributes attrs,
188 string entryPoint, ModuleReference mod) : this (meth)
189 {
190 m_attributes = attrs;
191 m_entryPoint = entryPoint;
192 m_module = mod;
193 }
194
195 public void Accept (IReflectionVisitor visitor)
196 {
197 visitor.VisitPInvokeInfo (this);
198 }
199 }
200 }