Add more async predefined members
[mono-project.git] / mcs / mcs / typemanager.cs
blob88dbc3b26c9b81a12ba13cb743ed669349585818
1 //
2 // typemanager.cs: C# type manager
3 //
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 // Ravi Pratap (ravi@ximian.com)
6 // Marek Safar (marek.safar@gmail.com)
7 //
8 // Dual licensed under the terms of the MIT X11 or GNU GPL
9 //
10 // Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
11 // Copyright 2003-2011 Novell, Inc.
12 // Copyright 2011 Xamarin Inc
15 using System;
16 using System.Globalization;
17 using System.Collections.Generic;
18 using System.Text;
19 using System.IO;
21 namespace Mono.CSharp
24 // All compiler built-in types (they have to exist otherwise the compiler will not work)
26 public class BuiltinTypes
28 public readonly BuiltinTypeSpec Object;
29 public readonly BuiltinTypeSpec ValueType;
30 public readonly BuiltinTypeSpec Attribute;
32 public readonly BuiltinTypeSpec Int;
33 public readonly BuiltinTypeSpec UInt;
34 public readonly BuiltinTypeSpec Long;
35 public readonly BuiltinTypeSpec ULong;
36 public readonly BuiltinTypeSpec Float;
37 public readonly BuiltinTypeSpec Double;
38 public readonly BuiltinTypeSpec Char;
39 public readonly BuiltinTypeSpec Short;
40 public readonly BuiltinTypeSpec Decimal;
41 public readonly BuiltinTypeSpec Bool;
42 public readonly BuiltinTypeSpec SByte;
43 public readonly BuiltinTypeSpec Byte;
44 public readonly BuiltinTypeSpec UShort;
45 public readonly BuiltinTypeSpec String;
47 public readonly BuiltinTypeSpec Enum;
48 public readonly BuiltinTypeSpec Delegate;
49 public readonly BuiltinTypeSpec MulticastDelegate;
50 public readonly BuiltinTypeSpec Void;
51 public readonly BuiltinTypeSpec Array;
52 public readonly BuiltinTypeSpec Type;
53 public readonly BuiltinTypeSpec IEnumerator;
54 public readonly BuiltinTypeSpec IEnumerable;
55 public readonly BuiltinTypeSpec IDisposable;
56 public readonly BuiltinTypeSpec IntPtr;
57 public readonly BuiltinTypeSpec UIntPtr;
58 public readonly BuiltinTypeSpec RuntimeFieldHandle;
59 public readonly BuiltinTypeSpec RuntimeTypeHandle;
60 public readonly BuiltinTypeSpec Exception;
63 // These are internal buil-in types which depend on other
64 // build-in type (mostly object)
66 public readonly BuiltinTypeSpec Dynamic;
68 // Predefined operators tables
69 public readonly Binary.PredefinedOperator[] OperatorsBinaryStandard;
70 public readonly Binary.PredefinedOperator[] OperatorsBinaryEquality;
71 public readonly Binary.PredefinedOperator[] OperatorsBinaryUnsafe;
72 public readonly TypeSpec[][] OperatorsUnary;
73 public readonly TypeSpec[] OperatorsUnaryMutator;
75 public readonly TypeSpec[] BinaryPromotionsTypes;
76 public readonly TypeSpec[] SwitchUserTypes;
78 readonly BuiltinTypeSpec[] types;
80 public BuiltinTypes ()
82 Object = new BuiltinTypeSpec (MemberKind.Class, "System", "Object", BuiltinTypeSpec.Type.Object);
83 ValueType = new BuiltinTypeSpec (MemberKind.Class, "System", "ValueType", BuiltinTypeSpec.Type.ValueType);
84 Attribute = new BuiltinTypeSpec (MemberKind.Class, "System", "Attribute", BuiltinTypeSpec.Type.Attribute);
86 Int = new BuiltinTypeSpec (MemberKind.Struct, "System", "Int32", BuiltinTypeSpec.Type.Int);
87 Long = new BuiltinTypeSpec (MemberKind.Struct, "System", "Int64", BuiltinTypeSpec.Type.Long);
88 UInt = new BuiltinTypeSpec (MemberKind.Struct, "System", "UInt32", BuiltinTypeSpec.Type.UInt);
89 ULong = new BuiltinTypeSpec (MemberKind.Struct, "System", "UInt64", BuiltinTypeSpec.Type.ULong);
90 Byte = new BuiltinTypeSpec (MemberKind.Struct, "System", "Byte", BuiltinTypeSpec.Type.Byte);
91 SByte = new BuiltinTypeSpec (MemberKind.Struct, "System", "SByte", BuiltinTypeSpec.Type.SByte);
92 Short = new BuiltinTypeSpec (MemberKind.Struct, "System", "Int16", BuiltinTypeSpec.Type.Short);
93 UShort = new BuiltinTypeSpec (MemberKind.Struct, "System", "UInt16", BuiltinTypeSpec.Type.UShort);
95 IEnumerator = new BuiltinTypeSpec (MemberKind.Interface, "System.Collections", "IEnumerator", BuiltinTypeSpec.Type.IEnumerator);
96 IEnumerable = new BuiltinTypeSpec (MemberKind.Interface, "System.Collections", "IEnumerable", BuiltinTypeSpec.Type.IEnumerable);
97 IDisposable = new BuiltinTypeSpec (MemberKind.Interface, "System", "IDisposable", BuiltinTypeSpec.Type.IDisposable);
99 Char = new BuiltinTypeSpec (MemberKind.Struct, "System", "Char", BuiltinTypeSpec.Type.Char);
100 String = new BuiltinTypeSpec (MemberKind.Class, "System", "String", BuiltinTypeSpec.Type.String);
101 Float = new BuiltinTypeSpec (MemberKind.Struct, "System", "Single", BuiltinTypeSpec.Type.Float);
102 Double = new BuiltinTypeSpec (MemberKind.Struct, "System", "Double", BuiltinTypeSpec.Type.Double);
103 Decimal = new BuiltinTypeSpec (MemberKind.Struct, "System", "Decimal", BuiltinTypeSpec.Type.Decimal);
104 Bool = new BuiltinTypeSpec (MemberKind.Struct, "System", "Boolean", BuiltinTypeSpec.Type.Bool);
105 IntPtr = new BuiltinTypeSpec (MemberKind.Struct, "System", "IntPtr", BuiltinTypeSpec.Type.IntPtr);
106 UIntPtr = new BuiltinTypeSpec (MemberKind.Struct, "System", "UIntPtr", BuiltinTypeSpec.Type.UIntPtr);
108 MulticastDelegate = new BuiltinTypeSpec (MemberKind.Class, "System", "MulticastDelegate", BuiltinTypeSpec.Type.MulticastDelegate);
109 Delegate = new BuiltinTypeSpec (MemberKind.Class, "System", "Delegate", BuiltinTypeSpec.Type.Delegate);
110 Enum = new BuiltinTypeSpec (MemberKind.Class, "System", "Enum", BuiltinTypeSpec.Type.Enum);
111 Array = new BuiltinTypeSpec (MemberKind.Class, "System", "Array", BuiltinTypeSpec.Type.Array);
112 Void = new BuiltinTypeSpec (MemberKind.Void, "System", "Void", BuiltinTypeSpec.Type.Other);
113 Type = new BuiltinTypeSpec (MemberKind.Class, "System", "Type", BuiltinTypeSpec.Type.Type);
114 Exception = new BuiltinTypeSpec (MemberKind.Class, "System", "Exception", BuiltinTypeSpec.Type.Exception);
115 RuntimeFieldHandle = new BuiltinTypeSpec (MemberKind.Struct, "System", "RuntimeFieldHandle", BuiltinTypeSpec.Type.Other);
116 RuntimeTypeHandle = new BuiltinTypeSpec (MemberKind.Struct, "System", "RuntimeTypeHandle", BuiltinTypeSpec.Type.Other);
118 // TODO: Maybe I should promote it to different kind for faster compares
119 Dynamic = new BuiltinTypeSpec ("dynamic", BuiltinTypeSpec.Type.Dynamic);
121 OperatorsBinaryStandard = Binary.CreateStandardOperatorsTable (this);
122 OperatorsBinaryEquality = Binary.CreateEqualityOperatorsTable (this);
123 OperatorsBinaryUnsafe = Binary.CreatePointerOperatorsTable (this);
124 OperatorsUnary = Unary.CreatePredefinedOperatorsTable (this);
125 OperatorsUnaryMutator = UnaryMutator.CreatePredefinedOperatorsTable (this);
127 BinaryPromotionsTypes = ConstantFold.CreateBinaryPromotionsTypes (this);
128 SwitchUserTypes = Switch.CreateSwitchUserTypes (this);
130 types = new BuiltinTypeSpec[] {
131 Object, ValueType, Attribute,
132 Int, UInt, Long, ULong, Float, Double, Char, Short, Decimal, Bool, SByte, Byte, UShort, String,
133 Enum, Delegate, MulticastDelegate, Void, Array, Type, IEnumerator, IEnumerable, IDisposable,
134 IntPtr, UIntPtr, RuntimeFieldHandle, RuntimeTypeHandle, Exception };
137 public BuiltinTypeSpec[] AllTypes {
138 get {
139 return types;
143 public bool CheckDefinitions (ModuleContainer module)
145 var ctx = module.Compiler;
146 foreach (var p in types) {
147 var found = PredefinedType.Resolve (module, p.Kind, p.Namespace, p.Name, p.Arity);
148 if (found == null || found == p)
149 continue;
151 var tc = found.MemberDefinition as TypeDefinition;
152 if (tc != null) {
153 var ns = module.GlobalRootNamespace.GetNamespace (p.Namespace, false);
154 ns.SetBuiltinType (p);
156 tc.SetPredefinedSpec (p);
157 p.SetDefinition (found);
161 if (ctx.Report.Errors != 0)
162 return false;
164 // Set internal build-in types
165 Dynamic.SetDefinition (Object);
167 return true;
172 // Compiler predefined types. Usually used for compiler generated
173 // code or for comparison against well known framework type. They
174 // may not exist as they are optional
176 class PredefinedTypes
178 public readonly PredefinedType ArgIterator;
179 public readonly PredefinedType TypedReference;
180 public readonly PredefinedType MarshalByRefObject;
181 public readonly PredefinedType RuntimeHelpers;
182 public readonly PredefinedType IAsyncResult;
183 public readonly PredefinedType AsyncCallback;
184 public readonly PredefinedType RuntimeArgumentHandle;
185 public readonly PredefinedType CharSet;
186 public readonly PredefinedType IsVolatile;
187 public readonly PredefinedType IEnumeratorGeneric;
188 public readonly PredefinedType IListGeneric;
189 public readonly PredefinedType ICollectionGeneric;
190 public readonly PredefinedType IEnumerableGeneric;
191 public readonly PredefinedType Nullable;
192 public readonly PredefinedType Activator;
193 public readonly PredefinedType Interlocked;
194 public readonly PredefinedType Monitor;
195 public readonly PredefinedType NotSupportedException;
196 public readonly PredefinedType RuntimeFieldHandle;
197 public readonly PredefinedType RuntimeMethodHandle;
198 public readonly PredefinedType SecurityAction;
199 public readonly PredefinedType Dictionary;
200 public readonly PredefinedType Hashtable;
203 // C# 3.0
205 public readonly PredefinedType Expression;
206 public readonly PredefinedType ExpressionGeneric;
207 public readonly PredefinedType ParameterExpression;
208 public readonly PredefinedType FieldInfo;
209 public readonly PredefinedType MethodBase;
210 public readonly PredefinedType MethodInfo;
211 public readonly PredefinedType ConstructorInfo;
212 public readonly PredefinedType MemberBinding;
215 // C# 4.0
217 public readonly PredefinedType Binder;
218 public readonly PredefinedType CallSite;
219 public readonly PredefinedType CallSiteGeneric;
220 public readonly PredefinedType BinderFlags;
223 // C# 5.0
225 public readonly PredefinedType AsyncVoidMethodBuilder;
226 public readonly PredefinedType AsyncTaskMethodBuilder;
227 public readonly PredefinedType AsyncTaskMethodBuilderGeneric;
228 public readonly PredefinedType Action;
229 public readonly PredefinedType Task;
230 public readonly PredefinedType TaskGeneric;
231 public readonly PredefinedType IAsyncStateMachine;
232 public readonly PredefinedType INotifyCompletion;
233 public readonly PredefinedType ICriticalNotifyCompletion;
235 public PredefinedTypes (ModuleContainer module)
237 TypedReference = new PredefinedType (module, MemberKind.Struct, "System", "TypedReference");
238 ArgIterator = new PredefinedType (module, MemberKind.Struct, "System", "ArgIterator");
240 MarshalByRefObject = new PredefinedType (module, MemberKind.Class, "System", "MarshalByRefObject");
241 RuntimeHelpers = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "RuntimeHelpers");
242 IAsyncResult = new PredefinedType (module, MemberKind.Interface, "System", "IAsyncResult");
243 AsyncCallback = new PredefinedType (module, MemberKind.Delegate, "System", "AsyncCallback");
244 RuntimeArgumentHandle = new PredefinedType (module, MemberKind.Struct, "System", "RuntimeArgumentHandle");
245 CharSet = new PredefinedType (module, MemberKind.Enum, "System.Runtime.InteropServices", "CharSet");
246 IsVolatile = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "IsVolatile");
247 IEnumeratorGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IEnumerator", 1);
248 IListGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IList", 1);
249 ICollectionGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "ICollection", 1);
250 IEnumerableGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IEnumerable", 1);
251 Nullable = new PredefinedType (module, MemberKind.Struct, "System", "Nullable", 1);
252 Activator = new PredefinedType (module, MemberKind.Class, "System", "Activator");
253 Interlocked = new PredefinedType (module, MemberKind.Class, "System.Threading", "Interlocked");
254 Monitor = new PredefinedType (module, MemberKind.Class, "System.Threading", "Monitor");
255 NotSupportedException = new PredefinedType (module, MemberKind.Class, "System", "NotSupportedException");
256 RuntimeFieldHandle = new PredefinedType (module, MemberKind.Struct, "System", "RuntimeFieldHandle");
257 RuntimeMethodHandle = new PredefinedType (module, MemberKind.Struct, "System", "RuntimeMethodHandle");
258 SecurityAction = new PredefinedType (module, MemberKind.Enum, "System.Security.Permissions", "SecurityAction");
259 Dictionary = new PredefinedType (module, MemberKind.Class, "System.Collections.Generic", "Dictionary", 2);
260 Hashtable = new PredefinedType (module, MemberKind.Class, "System.Collections", "Hashtable");
262 Expression = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "Expression");
263 ExpressionGeneric = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "Expression", 1);
264 MemberBinding = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "MemberBinding");
265 ParameterExpression = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "ParameterExpression");
266 FieldInfo = new PredefinedType (module, MemberKind.Class, "System.Reflection", "FieldInfo");
267 MethodBase = new PredefinedType (module, MemberKind.Class, "System.Reflection", "MethodBase");
268 MethodInfo = new PredefinedType (module, MemberKind.Class, "System.Reflection", "MethodInfo");
269 ConstructorInfo = new PredefinedType (module, MemberKind.Class, "System.Reflection", "ConstructorInfo");
271 CallSite = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite");
272 CallSiteGeneric = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite", 1);
273 Binder = new PredefinedType (module, MemberKind.Class, "Microsoft.CSharp.RuntimeBinder", "Binder");
274 BinderFlags = new PredefinedType (module, MemberKind.Enum, "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags");
276 Action = new PredefinedType (module, MemberKind.Delegate, "System", "Action");
277 AsyncVoidMethodBuilder = new PredefinedType (module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncVoidMethodBuilder");
278 AsyncTaskMethodBuilder = new PredefinedType (module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncTaskMethodBuilder");
279 AsyncTaskMethodBuilderGeneric = new PredefinedType (module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncTaskMethodBuilder", 1);
280 Task = new PredefinedType (module, MemberKind.Class, "System.Threading.Tasks", "Task");
281 TaskGeneric = new PredefinedType (module, MemberKind.Class, "System.Threading.Tasks", "Task", 1);
282 IAsyncStateMachine = new PredefinedType (module, MemberKind.Interface, "System.Runtime.CompilerServices", "IAsyncStateMachine");
283 INotifyCompletion = new PredefinedType (module, MemberKind.Interface, "System.Runtime.CompilerServices", "INotifyCompletion");
284 ICriticalNotifyCompletion = new PredefinedType (module, MemberKind.Interface, "System.Runtime.CompilerServices", "ICriticalNotifyCompletion");
287 // Define types which are used for comparison. It does not matter
288 // if they don't exist as no error report is needed
290 if (TypedReference.Define ())
291 TypedReference.TypeSpec.IsSpecialRuntimeType = true;
293 if (ArgIterator.Define ())
294 ArgIterator.TypeSpec.IsSpecialRuntimeType = true;
296 if (IEnumerableGeneric.Define ())
297 IEnumerableGeneric.TypeSpec.IsGenericIterateInterface = true;
299 if (IListGeneric.Define ())
300 IListGeneric.TypeSpec.IsGenericIterateInterface = true;
302 if (ICollectionGeneric.Define ())
303 ICollectionGeneric.TypeSpec.IsGenericIterateInterface = true;
305 if (Nullable.Define ())
306 Nullable.TypeSpec.IsNullableType = true;
308 if (ExpressionGeneric.Define ())
309 ExpressionGeneric.TypeSpec.IsExpressionTreeType = true;
311 Task.Define ();
312 if (TaskGeneric.Define ())
313 TaskGeneric.TypeSpec.IsGenericTask = true;
317 class PredefinedMembers
319 public readonly PredefinedMember<MethodSpec> ActivatorCreateInstance;
320 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderCreate;
321 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderSetResult;
322 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderSetException;
323 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderSetStateMachine;
324 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderOnCompleted;
325 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderOnCompletedUnsafe;
326 public readonly PredefinedMember<PropertySpec> AsyncTaskMethodBuilderTask;
327 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderGenericCreate;
328 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderGenericSetResult;
329 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderGenericSetException;
330 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderGenericSetStateMachine;
331 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderGenericOnCompleted;
332 public readonly PredefinedMember<MethodSpec> AsyncTaskMethodBuilderGenericOnCompletedUnsafe;
333 public readonly PredefinedMember<PropertySpec> AsyncTaskMethodBuilderGenericTask;
334 public readonly PredefinedMember<MethodSpec> AsyncVoidMethodBuilderCreate;
335 public readonly PredefinedMember<MethodSpec> AsyncVoidMethodBuilderSetException;
336 public readonly PredefinedMember<MethodSpec> AsyncVoidMethodBuilderSetResult;
337 public readonly PredefinedMember<MethodSpec> AsyncVoidMethodBuilderSetStateMachine;
338 public readonly PredefinedMember<MethodSpec> AsyncVoidMethodBuilderOnCompleted;
339 public readonly PredefinedMember<MethodSpec> AsyncVoidMethodBuilderOnCompletedUnsafe;
340 public readonly PredefinedMember<MethodSpec> DebuggerBrowsableAttributeCtor;
341 public readonly PredefinedMember<MethodSpec> DecimalCtor;
342 public readonly PredefinedMember<MethodSpec> DecimalCtorInt;
343 public readonly PredefinedMember<MethodSpec> DecimalCtorLong;
344 public readonly PredefinedMember<MethodSpec> DecimalConstantAttributeCtor;
345 public readonly PredefinedMember<MethodSpec> DefaultMemberAttributeCtor;
346 public readonly PredefinedMember<MethodSpec> DelegateCombine;
347 public readonly PredefinedMember<MethodSpec> DelegateEqual;
348 public readonly PredefinedMember<MethodSpec> DelegateInequal;
349 public readonly PredefinedMember<MethodSpec> DelegateRemove;
350 public readonly PredefinedMember<MethodSpec> DynamicAttributeCtor;
351 public readonly PredefinedMember<MethodSpec> FieldInfoGetFieldFromHandle;
352 public readonly PredefinedMember<MethodSpec> FieldInfoGetFieldFromHandle2;
353 public readonly PredefinedMember<MethodSpec> IDisposableDispose;
354 public readonly PredefinedMember<MethodSpec> IEnumerableGetEnumerator;
355 public readonly PredefinedMember<MethodSpec> InterlockedCompareExchange;
356 public readonly PredefinedMember<MethodSpec> InterlockedCompareExchange_T;
357 public readonly PredefinedMember<MethodSpec> FixedBufferAttributeCtor;
358 public readonly PredefinedMember<MethodSpec> MethodInfoGetMethodFromHandle;
359 public readonly PredefinedMember<MethodSpec> MethodInfoGetMethodFromHandle2;
360 public readonly PredefinedMember<MethodSpec> MonitorEnter;
361 public readonly PredefinedMember<MethodSpec> MonitorEnter_v4;
362 public readonly PredefinedMember<MethodSpec> MonitorExit;
363 public readonly PredefinedMember<PropertySpec> RuntimeCompatibilityWrapNonExceptionThrows;
364 public readonly PredefinedMember<MethodSpec> RuntimeHelpersInitializeArray;
365 public readonly PredefinedMember<PropertySpec> RuntimeHelpersOffsetToStringData;
366 public readonly PredefinedMember<ConstSpec> SecurityActionRequestMinimum;
367 public readonly PredefinedMember<FieldSpec> StringEmpty;
368 public readonly PredefinedMember<MethodSpec> StringEqual;
369 public readonly PredefinedMember<MethodSpec> StringInequal;
370 public readonly PredefinedMember<MethodSpec> StructLayoutAttributeCtor;
371 public readonly PredefinedMember<FieldSpec> StructLayoutCharSet;
372 public readonly PredefinedMember<FieldSpec> StructLayoutSize;
373 public readonly PredefinedMember<MethodSpec> TypeGetTypeFromHandle;
375 public PredefinedMembers (ModuleContainer module)
377 var types = module.PredefinedTypes;
378 var atypes = module.PredefinedAttributes;
379 var btypes = module.Compiler.BuiltinTypes;
381 var tp = new TypeParameter (0, new MemberName ("T"), null, null, Variance.None);
383 ActivatorCreateInstance = new PredefinedMember<MethodSpec> (module, types.Activator,
384 MemberFilter.Method ("CreateInstance", 1, ParametersCompiled.EmptyReadOnlyParameters, null));
386 AsyncTaskMethodBuilderCreate = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilder,
387 MemberFilter.Method ("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncTaskMethodBuilder.TypeSpec));
389 AsyncTaskMethodBuilderSetResult = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilder,
390 MemberFilter.Method ("SetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, btypes.Void));
392 AsyncTaskMethodBuilderSetStateMachine = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilder,
393 "SetStateMachine", MemberKind.Method, () => new[] {
394 types.IAsyncStateMachine.TypeSpec
395 }, btypes.Void);
397 AsyncTaskMethodBuilderSetException = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilder,
398 MemberFilter.Method ("SetException", 0,
399 ParametersCompiled.CreateFullyResolved (btypes.Exception), btypes.Void));
401 AsyncTaskMethodBuilderOnCompleted = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilder,
402 MemberFilter.Method ("AwaitOnCompleted", 2,
403 new ParametersImported (
404 new[] {
405 new ParameterData (null, Parameter.Modifier.REF),
406 new ParameterData (null, Parameter.Modifier.REF)
408 new[] {
409 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
410 new TypeParameterSpec (1, tp, SpecialConstraint.None, Variance.None, null)
411 }, false),
412 btypes.Void));
414 AsyncTaskMethodBuilderOnCompletedUnsafe = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilder,
415 MemberFilter.Method ("AwaitUnsafeOnCompleted", 2,
416 new ParametersImported (
417 new[] {
418 new ParameterData (null, Parameter.Modifier.REF),
419 new ParameterData (null, Parameter.Modifier.REF)
421 new[] {
422 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
423 new TypeParameterSpec (1, tp, SpecialConstraint.None, Variance.None, null)
424 }, false),
425 btypes.Void));
427 AsyncTaskMethodBuilderTask = new PredefinedMember<PropertySpec> (module, types.AsyncTaskMethodBuilder,
428 MemberFilter.Property ("Task", null));
430 AsyncTaskMethodBuilderGenericCreate = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
431 MemberFilter.Method ("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncVoidMethodBuilder.TypeSpec));
433 AsyncTaskMethodBuilderGenericSetResult = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
434 "SetResult", MemberKind.Method, () => new TypeSpec[] {
435 types.AsyncTaskMethodBuilderGeneric.TypeSpec.MemberDefinition.TypeParameters[0]
436 }, btypes.Void);
438 AsyncTaskMethodBuilderGenericSetStateMachine = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
439 "SetStateMachine", MemberKind.Method, () => new[] {
440 types.IAsyncStateMachine.TypeSpec
441 }, btypes.Void);
443 AsyncTaskMethodBuilderGenericSetException = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
444 MemberFilter.Method ("SetException", 0,
445 ParametersCompiled.CreateFullyResolved (btypes.Exception), btypes.Void));
447 AsyncTaskMethodBuilderGenericOnCompleted = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
448 MemberFilter.Method ("AwaitOnCompleted", 2,
449 new ParametersImported (
450 new[] {
451 new ParameterData (null, Parameter.Modifier.REF),
452 new ParameterData (null, Parameter.Modifier.REF)
454 new[] {
455 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
456 new TypeParameterSpec (1, tp, SpecialConstraint.None, Variance.None, null)
457 }, false),
458 btypes.Void));
460 AsyncTaskMethodBuilderGenericOnCompletedUnsafe = new PredefinedMember<MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
461 MemberFilter.Method ("AwaitUnsafeOnCompleted", 2,
462 new ParametersImported (
463 new[] {
464 new ParameterData (null, Parameter.Modifier.REF),
465 new ParameterData (null, Parameter.Modifier.REF)
467 new[] {
468 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
469 new TypeParameterSpec (1, tp, SpecialConstraint.None, Variance.None, null)
470 }, false),
471 btypes.Void));
473 AsyncTaskMethodBuilderGenericTask = new PredefinedMember<PropertySpec> (module, types.AsyncTaskMethodBuilderGeneric,
474 MemberFilter.Property ("Task", null));
476 AsyncVoidMethodBuilderCreate = new PredefinedMember<MethodSpec> (module, types.AsyncVoidMethodBuilder,
477 MemberFilter.Method ("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncVoidMethodBuilder.TypeSpec));
479 AsyncVoidMethodBuilderSetException = new PredefinedMember<MethodSpec> (module, types.AsyncVoidMethodBuilder,
480 MemberFilter.Method ("SetException", 0, null, btypes.Void));
482 AsyncVoidMethodBuilderSetResult = new PredefinedMember<MethodSpec> (module, types.AsyncVoidMethodBuilder,
483 MemberFilter.Method ("SetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, btypes.Void));
485 AsyncVoidMethodBuilderSetStateMachine = new PredefinedMember<MethodSpec> (module, types.AsyncVoidMethodBuilder,
486 "SetStateMachine", MemberKind.Method, () => new[] {
487 types.IAsyncStateMachine.TypeSpec
488 }, btypes.Void);
490 AsyncVoidMethodBuilderOnCompleted = new PredefinedMember<MethodSpec> (module, types.AsyncVoidMethodBuilder,
491 MemberFilter.Method ("AwaitOnCompleted", 2,
492 new ParametersImported (
493 new[] {
494 new ParameterData (null, Parameter.Modifier.REF),
495 new ParameterData (null, Parameter.Modifier.REF)
497 new[] {
498 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
499 new TypeParameterSpec (1, tp, SpecialConstraint.None, Variance.None, null)
500 }, false),
501 btypes.Void));
503 AsyncVoidMethodBuilderOnCompletedUnsafe = new PredefinedMember<MethodSpec> (module, types.AsyncVoidMethodBuilder,
504 MemberFilter.Method ("AwaitUnsafeOnCompleted", 2,
505 new ParametersImported (
506 new[] {
507 new ParameterData (null, Parameter.Modifier.REF),
508 new ParameterData (null, Parameter.Modifier.REF)
510 new[] {
511 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
512 new TypeParameterSpec (1, tp, SpecialConstraint.None, Variance.None, null)
513 }, false),
514 btypes.Void));
516 DebuggerBrowsableAttributeCtor = new PredefinedMember<MethodSpec> (module, atypes.DebuggerBrowsable,
517 MemberFilter.Constructor (null));
519 DecimalCtor = new PredefinedMember<MethodSpec> (module, btypes.Decimal,
520 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (
521 btypes.Int, btypes.Int, btypes.Int, btypes.Bool, btypes.Byte)));
523 DecimalCtorInt = new PredefinedMember<MethodSpec> (module, btypes.Decimal,
524 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (btypes.Int)));
526 DecimalCtorLong = new PredefinedMember<MethodSpec> (module, btypes.Decimal,
527 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (btypes.Long)));
529 DecimalConstantAttributeCtor = new PredefinedMember<MethodSpec> (module, atypes.DecimalConstant,
530 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (
531 btypes.Byte, btypes.Byte, btypes.UInt, btypes.UInt, btypes.UInt)));
533 DefaultMemberAttributeCtor = new PredefinedMember<MethodSpec> (module, atypes.DefaultMember,
534 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (btypes.String)));
536 DelegateCombine = new PredefinedMember<MethodSpec> (module, btypes.Delegate, "Combine", btypes.Delegate, btypes.Delegate);
537 DelegateRemove = new PredefinedMember<MethodSpec> (module, btypes.Delegate, "Remove", btypes.Delegate, btypes.Delegate);
539 DelegateEqual = new PredefinedMember<MethodSpec> (module, btypes.Delegate,
540 new MemberFilter (Operator.GetMetadataName (Operator.OpType.Equality), 0, MemberKind.Operator, null, btypes.Bool));
542 DelegateInequal = new PredefinedMember<MethodSpec> (module, btypes.Delegate,
543 new MemberFilter (Operator.GetMetadataName (Operator.OpType.Inequality), 0, MemberKind.Operator, null, btypes.Bool));
545 DynamicAttributeCtor = new PredefinedMember<MethodSpec> (module, atypes.Dynamic,
546 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (
547 ArrayContainer.MakeType (module, btypes.Bool))));
549 FieldInfoGetFieldFromHandle = new PredefinedMember<MethodSpec> (module, types.FieldInfo,
550 "GetFieldFromHandle", MemberKind.Method, types.RuntimeFieldHandle);
552 FieldInfoGetFieldFromHandle2 = new PredefinedMember<MethodSpec> (module, types.FieldInfo,
553 "GetFieldFromHandle", MemberKind.Method, types.RuntimeFieldHandle, new PredefinedType (btypes.RuntimeTypeHandle));
555 FixedBufferAttributeCtor = new PredefinedMember<MethodSpec> (module, atypes.FixedBuffer,
556 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (btypes.Type, btypes.Int)));
558 IDisposableDispose = new PredefinedMember<MethodSpec> (module, btypes.IDisposable, "Dispose", TypeSpec.EmptyTypes);
560 IEnumerableGetEnumerator = new PredefinedMember<MethodSpec> (module, btypes.IEnumerable,
561 "GetEnumerator", TypeSpec.EmptyTypes);
563 InterlockedCompareExchange = new PredefinedMember<MethodSpec> (module, types.Interlocked,
564 MemberFilter.Method ("CompareExchange", 0,
565 new ParametersImported (
566 new[] {
567 new ParameterData (null, Parameter.Modifier.REF),
568 new ParameterData (null, Parameter.Modifier.NONE),
569 new ParameterData (null, Parameter.Modifier.NONE)
571 new[] {
572 btypes.Int, btypes.Int, btypes.Int
574 false),
575 btypes.Int));
577 InterlockedCompareExchange_T = new PredefinedMember<MethodSpec> (module, types.Interlocked,
578 MemberFilter.Method ("CompareExchange", 1,
579 new ParametersImported (
580 new[] {
581 new ParameterData (null, Parameter.Modifier.REF),
582 new ParameterData (null, Parameter.Modifier.NONE),
583 new ParameterData (null, Parameter.Modifier.NONE)
585 new[] {
586 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
587 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
588 new TypeParameterSpec (0, tp, SpecialConstraint.None, Variance.None, null),
589 }, false),
590 null));
592 MethodInfoGetMethodFromHandle = new PredefinedMember<MethodSpec> (module, types.MethodBase,
593 "GetMethodFromHandle", MemberKind.Method, types.RuntimeMethodHandle);
595 MethodInfoGetMethodFromHandle2 = new PredefinedMember<MethodSpec> (module, types.MethodBase,
596 "GetMethodFromHandle", MemberKind.Method, types.RuntimeMethodHandle, new PredefinedType (btypes.RuntimeTypeHandle));
598 MonitorEnter = new PredefinedMember<MethodSpec> (module, types.Monitor, "Enter", btypes.Object);
600 MonitorEnter_v4 = new PredefinedMember<MethodSpec> (module, types.Monitor,
601 MemberFilter.Method ("Enter", 0,
602 new ParametersImported (new[] {
603 new ParameterData (null, Parameter.Modifier.NONE),
604 new ParameterData (null, Parameter.Modifier.REF)
606 new[] {
607 btypes.Object, btypes.Bool
608 }, false), null));
610 MonitorExit = new PredefinedMember<MethodSpec> (module, types.Monitor, "Exit", btypes.Object);
612 RuntimeCompatibilityWrapNonExceptionThrows = new PredefinedMember<PropertySpec> (module, atypes.RuntimeCompatibility,
613 MemberFilter.Property ("WrapNonExceptionThrows", btypes.Bool));
615 RuntimeHelpersInitializeArray = new PredefinedMember<MethodSpec> (module, types.RuntimeHelpers,
616 "InitializeArray", btypes.Array, btypes.RuntimeFieldHandle);
618 RuntimeHelpersOffsetToStringData = new PredefinedMember<PropertySpec> (module, types.RuntimeHelpers,
619 MemberFilter.Property ("OffsetToStringData", btypes.Int));
621 SecurityActionRequestMinimum = new PredefinedMember<ConstSpec> (module, types.SecurityAction, "RequestMinimum",
622 MemberKind.Field, types.SecurityAction);
624 StringEmpty = new PredefinedMember<FieldSpec> (module, btypes.String, MemberFilter.Field ("Empty", btypes.String));
626 StringEqual = new PredefinedMember<MethodSpec> (module, btypes.String,
627 new MemberFilter (Operator.GetMetadataName (Operator.OpType.Equality), 0, MemberKind.Operator, null, btypes.Bool));
629 StringInequal = new PredefinedMember<MethodSpec> (module, btypes.String,
630 new MemberFilter (Operator.GetMetadataName (Operator.OpType.Inequality), 0, MemberKind.Operator, null, btypes.Bool));
632 StructLayoutAttributeCtor = new PredefinedMember<MethodSpec> (module, atypes.StructLayout,
633 MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved (btypes.Short)));
635 StructLayoutCharSet = new PredefinedMember<FieldSpec> (module, atypes.StructLayout, "CharSet",
636 MemberKind.Field, types.CharSet);
638 StructLayoutSize = new PredefinedMember<FieldSpec> (module, atypes.StructLayout,
639 MemberFilter.Field ("Size", btypes.Int));
641 TypeGetTypeFromHandle = new PredefinedMember<MethodSpec> (module, btypes.Type, "GetTypeFromHandle", btypes.RuntimeTypeHandle);
645 public class PredefinedType
647 readonly string name;
648 readonly string ns;
649 readonly int arity;
650 readonly MemberKind kind;
651 protected readonly ModuleContainer module;
652 protected TypeSpec type;
654 public PredefinedType (ModuleContainer module, MemberKind kind, string ns, string name, int arity)
655 : this (module, kind, ns, name)
657 this.arity = arity;
660 public PredefinedType (ModuleContainer module, MemberKind kind, string ns, string name)
662 this.module = module;
663 this.kind = kind;
664 this.name = name;
665 this.ns = ns;
668 public PredefinedType (BuiltinTypeSpec type)
670 this.kind = type.Kind;
671 this.name = type.Name;
672 this.ns = type.Namespace;
673 this.type = type;
676 #region Properties
678 public int Arity {
679 get {
680 return arity;
684 public bool IsDefined {
685 get {
686 return type != null;
690 public string Name {
691 get {
692 return name;
696 public string Namespace {
697 get {
698 return ns;
702 public TypeSpec TypeSpec {
703 get {
704 return type;
708 #endregion
710 public bool Define ()
712 if (type != null)
713 return true;
715 type = Resolve (module, kind, ns, name, arity, false);
716 return type != null;
719 public string GetSignatureForError ()
721 return ns + "." + name;
724 public static TypeSpec Resolve (ModuleContainer module, MemberKind kind, string ns, string name, int arity)
726 return Resolve (module, kind, ns, name, arity, true);
729 public static TypeSpec Resolve (ModuleContainer module, MemberKind kind, string ns, string name, int arity, bool reportErrors)
731 Namespace type_ns = module.GlobalRootNamespace.GetNamespace (ns, true);
732 var found = type_ns.GetAllTypes (name);
733 if (found == null) {
734 if (reportErrors)
735 module.Compiler.Report.Error (518, "The predefined type `{0}.{1}' is not defined or imported", ns, name);
737 return null;
740 TypeSpec best_match = null;
741 foreach (var candidate in found) {
742 if (candidate.Kind != kind) {
743 if (candidate.Kind == MemberKind.Struct && kind == MemberKind.Void && candidate.MemberDefinition is TypeContainer) {
744 // Void is declared as struct but we keep it internally as
745 // special kind, the swap will be done by caller
746 } else {
747 continue;
751 if (candidate.Arity != arity)
752 continue;
754 if ((candidate.Modifiers & Modifiers.INTERNAL) != 0 && !candidate.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly))
755 continue;
757 if (best_match == null) {
758 best_match = candidate;
759 continue;
762 var other_match = best_match;
763 if (!best_match.MemberDefinition.IsImported &&
764 module.Compiler.BuiltinTypes.Object.MemberDefinition.DeclaringAssembly == candidate.MemberDefinition.DeclaringAssembly) {
765 best_match = candidate;
768 string location;
769 if (best_match.MemberDefinition is MemberCore) {
770 location = ((MemberCore) best_match.MemberDefinition).Location.Name;
771 } else {
772 var assembly = (ImportedAssemblyDefinition) best_match.MemberDefinition.DeclaringAssembly;
773 location = Path.GetFileName (assembly.Location);
776 module.Compiler.Report.SymbolRelatedToPreviousError (other_match);
777 module.Compiler.Report.SymbolRelatedToPreviousError (candidate);
779 module.Compiler.Report.Warning (1685, 1,
780 "The predefined type `{0}.{1}' is defined multiple times. Using definition from `{2}'",
781 ns, name, location);
783 break;
786 if (best_match == null && reportErrors) {
787 Location loc;
788 if (found[0].MemberDefinition is MemberCore) {
789 loc = ((MemberCore) found[0].MemberDefinition).Location;
790 } else {
791 loc = Location.Null;
792 module.Compiler.Report.SymbolRelatedToPreviousError (found[0]);
795 module.Compiler.Report.Error (520, loc, "The predefined type `{0}.{1}' is not declared correctly", ns, name);
798 return best_match;
801 public TypeSpec Resolve ()
803 if (type == null)
804 type = Resolve (module, kind, ns, name, arity);
806 return type;
810 class PredefinedMember<T> where T : MemberSpec
812 readonly ModuleContainer module;
813 T member;
814 TypeSpec declaring_type;
815 readonly PredefinedType declaring_type_predefined;
816 MemberFilter filter;
817 readonly Func<TypeSpec[]> filter_builder;
819 public PredefinedMember (ModuleContainer module, PredefinedType type, MemberFilter filter)
821 this.module = module;
822 this.declaring_type_predefined = type;
823 this.filter = filter;
826 public PredefinedMember (ModuleContainer module, TypeSpec type, MemberFilter filter)
828 this.module = module;
829 this.declaring_type = type;
830 this.filter = filter;
833 public PredefinedMember (ModuleContainer module, PredefinedType type, string name, params TypeSpec[] types)
834 : this (module, type, MemberFilter.Method (name, 0, ParametersCompiled.CreateFullyResolved (types), null))
838 public PredefinedMember (ModuleContainer module, PredefinedType type, string name, MemberKind kind, params PredefinedType[] types)
839 : this (module, type, new MemberFilter (name, 0, kind, null, null))
841 filter_builder = () => {
842 var ptypes = new TypeSpec[types.Length];
843 for (int i = 0; i < ptypes.Length; ++i) {
844 var p = types[i];
845 if (!p.Define ())
846 return null;
848 ptypes[i] = p.TypeSpec;
851 return ptypes;
855 public PredefinedMember (ModuleContainer module, PredefinedType type, string name, MemberKind kind, Func<TypeSpec[]> typesBuilder, TypeSpec returnType)
856 : this (module, type, new MemberFilter (name, 0, kind, null, returnType))
858 filter_builder = typesBuilder;
861 public PredefinedMember (ModuleContainer module, BuiltinTypeSpec type, string name, params TypeSpec[] types)
862 : this (module, type, MemberFilter.Method (name, 0, ParametersCompiled.CreateFullyResolved (types), null))
866 public T Get ()
868 if (member != null)
869 return member;
871 if (declaring_type == null) {
872 if (!declaring_type_predefined.Define ())
873 return null;
875 declaring_type = declaring_type_predefined.TypeSpec;
878 if (filter_builder != null) {
879 var types = filter_builder ();
881 if (filter.Kind == MemberKind.Field)
882 filter = new MemberFilter (filter.Name, filter.Arity, filter.Kind, null, types [0]);
883 else
884 filter = new MemberFilter (filter.Name, filter.Arity, filter.Kind,
885 ParametersCompiled.CreateFullyResolved (types), filter.MemberType);
888 member = MemberCache.FindMember (declaring_type, filter, BindingRestriction.DeclaredOnly) as T;
889 if (member == null)
890 return null;
892 if (!member.IsAccessible (module))
893 return null;
895 return member;
898 public T Resolve (Location loc)
900 if (member != null)
901 return member;
903 if (Get () != null)
904 return member;
906 if (declaring_type == null) {
907 if (declaring_type_predefined.Resolve () == null)
908 return null;
911 if (filter_builder != null) {
912 filter = new MemberFilter (filter.Name, filter.Arity, filter.Kind,
913 ParametersCompiled.CreateFullyResolved (filter_builder ()), filter.MemberType);
916 string method_args = null;
917 if (filter.Parameters != null)
918 method_args = filter.Parameters.GetSignatureForError ();
920 module.Compiler.Report.Error (656, loc, "The compiler required member `{0}.{1}{2}' could not be found or is inaccessible",
921 declaring_type.GetSignatureForError (), filter.Name, method_args);
923 return null;
927 partial class TypeManager {
929 /// <summary>
930 /// Returns the C# name of a type if possible, or the full type name otherwise
931 /// </summary>
932 static public string CSharpName (TypeSpec t)
934 return t.GetSignatureForError ();
937 static public string CSharpName (IList<TypeSpec> types)
939 if (types.Count == 0)
940 return string.Empty;
942 StringBuilder sb = new StringBuilder ();
943 for (int i = 0; i < types.Count; ++i) {
944 if (i > 0)
945 sb.Append (",");
947 sb.Append (CSharpName (types [i]));
949 return sb.ToString ();
952 static public string GetFullNameSignature (MemberSpec mi)
954 return mi.GetSignatureForError ();
957 static public string CSharpSignature (MemberSpec mb)
959 return mb.GetSignatureForError ();
962 public static bool IsFamilyAccessible (TypeSpec type, TypeSpec parent)
964 // TypeParameter tparam = LookupTypeParameter (type);
965 // TypeParameter pparam = LookupTypeParameter (parent);
967 if (type.Kind == MemberKind.TypeParameter && parent.Kind == MemberKind.TypeParameter) { // (tparam != null) && (pparam != null)) {
968 if (type == parent)
969 return true;
971 throw new NotImplementedException ("net");
972 // return tparam.IsSubclassOf (parent);
975 do {
976 if (IsInstantiationOfSameGenericType (type, parent))
977 return true;
979 type = type.BaseType;
980 } while (type != null);
982 return false;
986 // Checks whether `type' is a nested child of `parent'.
988 public static bool IsNestedChildOf (TypeSpec type, ITypeDefinition parent)
990 if (type == null)
991 return false;
993 if (type.MemberDefinition == parent)
994 return false;
996 type = type.DeclaringType;
997 while (type != null) {
998 if (type.MemberDefinition == parent)
999 return true;
1001 type = type.DeclaringType;
1004 return false;
1007 public static TypeSpec GetElementType (TypeSpec t)
1009 return ((ElementTypeSpec)t).Element;
1012 /// <summary>
1013 /// This method is not implemented by MS runtime for dynamic types
1014 /// </summary>
1015 public static bool HasElementType (TypeSpec t)
1017 return t is ElementTypeSpec;
1020 /// <summary>
1021 /// Utility function that can be used to probe whether a type
1022 /// is managed or not.
1023 /// </summary>
1024 public static bool VerifyUnmanaged (ModuleContainer rc, TypeSpec t, Location loc)
1026 if (t.IsUnmanaged)
1027 return true;
1029 while (t.IsPointer)
1030 t = ((ElementTypeSpec) t).Element;
1032 rc.Compiler.Report.SymbolRelatedToPreviousError (t);
1033 rc.Compiler.Report.Error (208, loc,
1034 "Cannot take the address of, get the size of, or declare a pointer to a managed type `{0}'",
1035 CSharpName (t));
1037 return false;
1039 #region Generics
1040 // This method always return false for non-generic compiler,
1041 // while Type.IsGenericParameter is returned if it is supported.
1042 public static bool IsGenericParameter (TypeSpec type)
1044 return type.IsGenericParameter;
1047 public static bool IsGenericType (TypeSpec type)
1049 return type.IsGeneric;
1052 public static TypeSpec[] GetTypeArguments (TypeSpec t)
1054 // TODO: return empty array !!
1055 return t.TypeArguments;
1058 /// <summary>
1059 /// Check whether `type' and `parent' are both instantiations of the same
1060 /// generic type. Note that we do not check the type parameters here.
1061 /// </summary>
1062 public static bool IsInstantiationOfSameGenericType (TypeSpec type, TypeSpec parent)
1064 return type == parent || type.MemberDefinition == parent.MemberDefinition;
1066 #endregion