static bool CheckType(TypeSpec ret, TypeContainer parent, out TypeSpec original_iterator_type, out bool is_enumerable) { original_iterator_type = null; is_enumerable = false; if (ret.BuiltinType == BuiltinTypeSpec.Type.IEnumerable) { original_iterator_type = parent.Compiler.BuiltinTypes.Object; is_enumerable = true; return(true); } if (ret.BuiltinType == BuiltinTypeSpec.Type.IEnumerator) { original_iterator_type = parent.Compiler.BuiltinTypes.Object; is_enumerable = false; return(true); } InflatedTypeSpec inflated = ret as InflatedTypeSpec; if (inflated == null) { return(false); } var member_definition = inflated.MemberDefinition; PredefinedType ptype = parent.Module.PredefinedTypes.IEnumerableGeneric; if (ptype.Define() && ptype.TypeSpec.MemberDefinition == member_definition) { original_iterator_type = inflated.TypeArguments[0]; is_enumerable = true; return(true); } ptype = parent.Module.PredefinedTypes.IEnumeratorGeneric; if (ptype.Define() && ptype.TypeSpec.MemberDefinition == member_definition) { original_iterator_type = inflated.TypeArguments[0]; is_enumerable = false; return(true); } return(false); }
public T Get() { if (member != null) { return(member); } if (declaring_type == null) { if (!declaring_type_predefined.Define()) { return(null); } declaring_type = declaring_type_predefined.TypeSpec; } if (parameters_predefined != null) { TypeSpec[] types = new TypeSpec [parameters_predefined.Length]; for (int i = 0; i < types.Length; ++i) { var p = parameters_predefined [i]; if (!p.Define()) { return(null); } types[i] = p.TypeSpec; } if (filter.Kind == MemberKind.Field) { filter = new MemberFilter(filter.Name, filter.Arity, filter.Kind, null, types [0]); } else { filter = new MemberFilter(filter.Name, filter.Arity, filter.Kind, ParametersCompiled.CreateFullyResolved(types), filter.MemberType); } } member = MemberCache.FindMember(declaring_type, filter, BindingRestriction.DeclaredOnly) as T; if (member == null) { return(null); } if (!member.IsAccessible(module)) { return(null); } return(member); }
public T Get() { if (member != null) { return(member); } if (declaring_type == null) { if (!declaring_type_predefined.Define()) { return(null); } declaring_type = declaring_type_predefined.TypeSpec; } if (filter_builder != null) { var types = filter_builder(); if (filter.Kind == MemberKind.Field) { filter = new MemberFilter(filter.Name, filter.Arity, filter.Kind, null, types [0]); } else { filter = new MemberFilter(filter.Name, filter.Arity, filter.Kind, ParametersCompiled.CreateFullyResolved(types), filter.MemberType); } } member = MemberCache.FindMember(declaring_type, filter, BindingRestriction.DeclaredOnly) as T; if (member == null) { return(null); } if (!member.IsAccessible(module)) { return(null); } return(member); }
public PredefinedTypes (ModuleContainer module) { TypedReference = new PredefinedType (module, MemberKind.Struct, "System", "TypedReference"); ArgIterator = new PredefinedType (module, MemberKind.Struct, "System", "ArgIterator"); MarshalByRefObject = new PredefinedType (module, MemberKind.Class, "System", "MarshalByRefObject"); RuntimeHelpers = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "RuntimeHelpers"); IAsyncResult = new PredefinedType (module, MemberKind.Interface, "System", "IAsyncResult"); AsyncCallback = new PredefinedType (module, MemberKind.Delegate, "System", "AsyncCallback"); RuntimeArgumentHandle = new PredefinedType (module, MemberKind.Struct, "System", "RuntimeArgumentHandle"); CharSet = new PredefinedType (module, MemberKind.Enum, "System.Runtime.InteropServices", "CharSet"); IsVolatile = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "IsVolatile"); IEnumeratorGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IEnumerator", 1); IListGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IList", 1); ICollectionGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "ICollection", 1); IEnumerableGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IEnumerable", 1); Nullable = new PredefinedType (module, MemberKind.Struct, "System", "Nullable", 1); Activator = new PredefinedType (module, MemberKind.Class, "System", "Activator"); Interlocked = new PredefinedType (module, MemberKind.Class, "System.Threading", "Interlocked"); Monitor = new PredefinedType (module, MemberKind.Class, "System.Threading", "Monitor"); NotSupportedException = new PredefinedType (module, MemberKind.Class, "System", "NotSupportedException"); RuntimeFieldHandle = new PredefinedType (module, MemberKind.Struct, "System", "RuntimeFieldHandle"); RuntimeMethodHandle = new PredefinedType (module, MemberKind.Struct, "System", "RuntimeMethodHandle"); Expression = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "Expression"); ExpressionGeneric = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "Expression", 1); ParameterExpression = new PredefinedType (module, MemberKind.Class, "System.Linq.Expressions", "ParameterExpression"); FieldInfo = new PredefinedType (module, MemberKind.Class, "System.Reflection", "FieldInfo"); MethodBase = new PredefinedType (module, MemberKind.Class, "System.Reflection", "MethodBase"); MethodInfo = new PredefinedType (module, MemberKind.Class, "System.Reflection", "MethodInfo"); ConstructorInfo = new PredefinedType (module, MemberKind.Class, "System.Reflection", "ConstructorInfo"); CallSite = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite"); CallSiteGeneric = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite", 1); Binder = new PredefinedType (module, MemberKind.Class, "Microsoft.CSharp.RuntimeBinder", "Binder"); BinderFlags = new PredefinedType (module, MemberKind.Enum, "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags"); // // Define types which are used for comparison. It does not matter // if they don't exist as no error report is needed // TypedReference.Define (); ArgIterator.Define (); MarshalByRefObject.Define (); CharSet.Define (); IEnumerableGeneric.Define (); IListGeneric.Define (); ICollectionGeneric.Define (); IEnumerableGeneric.Define (); IEnumeratorGeneric.Define (); Nullable.Define (); ExpressionGeneric.Define (); // Deal with obsolete static types // TODO: remove TypeManager.typed_reference_type = TypedReference.TypeSpec; TypeManager.arg_iterator_type = ArgIterator.TypeSpec; TypeManager.mbr_type = MarshalByRefObject.TypeSpec; TypeManager.generic_ilist_type = IListGeneric.TypeSpec; TypeManager.generic_icollection_type = ICollectionGeneric.TypeSpec; TypeManager.generic_ienumerator_type = IEnumeratorGeneric.TypeSpec; TypeManager.generic_ienumerable_type = IEnumerableGeneric.TypeSpec; TypeManager.generic_nullable_type = Nullable.TypeSpec; TypeManager.expression_type = ExpressionGeneric.TypeSpec; }
public PredefinedTypes(ModuleContainer module) { TypedReference = new PredefinedType(module, MemberKind.Struct, "System", "TypedReference"); ArgIterator = new PredefinedType(module, MemberKind.Struct, "System", "ArgIterator"); MarshalByRefObject = new PredefinedType(module, MemberKind.Class, "System", "MarshalByRefObject"); RuntimeHelpers = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "RuntimeHelpers"); IAsyncResult = new PredefinedType(module, MemberKind.Interface, "System", "IAsyncResult"); AsyncCallback = new PredefinedType(module, MemberKind.Delegate, "System", "AsyncCallback"); RuntimeArgumentHandle = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeArgumentHandle"); CharSet = new PredefinedType(module, MemberKind.Enum, "System.Runtime.InteropServices", "CharSet"); IsVolatile = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "IsVolatile"); IEnumeratorGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IEnumerator", 1); IListGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IList", 1); ICollectionGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "ICollection", 1); IEnumerableGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IEnumerable", 1); Nullable = new PredefinedType(module, MemberKind.Struct, "System", "Nullable", 1); Activator = new PredefinedType(module, MemberKind.Class, "System", "Activator"); Interlocked = new PredefinedType(module, MemberKind.Class, "System.Threading", "Interlocked"); Monitor = new PredefinedType(module, MemberKind.Class, "System.Threading", "Monitor"); NotSupportedException = new PredefinedType(module, MemberKind.Class, "System", "NotSupportedException"); RuntimeFieldHandle = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeFieldHandle"); RuntimeMethodHandle = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeMethodHandle"); SecurityAction = new PredefinedType(module, MemberKind.Enum, "System.Security.Permissions", "SecurityAction"); Dictionary = new PredefinedType(module, MemberKind.Class, "System.Collections.Generic", "Dictionary", 2); Hashtable = new PredefinedType(module, MemberKind.Class, "System.Collections", "Hashtable"); Expression = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "Expression"); ExpressionGeneric = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "Expression", 1); MemberBinding = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "MemberBinding"); ParameterExpression = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "ParameterExpression"); FieldInfo = new PredefinedType(module, MemberKind.Class, "System.Reflection", "FieldInfo"); MethodBase = new PredefinedType(module, MemberKind.Class, "System.Reflection", "MethodBase"); MethodInfo = new PredefinedType(module, MemberKind.Class, "System.Reflection", "MethodInfo"); ConstructorInfo = new PredefinedType(module, MemberKind.Class, "System.Reflection", "ConstructorInfo"); CallSite = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite"); CallSiteGeneric = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite", 1); Binder = new PredefinedType(module, MemberKind.Class, "Microsoft.CSharp.RuntimeBinder", "Binder"); BinderFlags = new PredefinedType(module, MemberKind.Enum, "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags"); Action = new PredefinedType(module, MemberKind.Delegate, "System", "Action"); AsyncVoidMethodBuilder = new PredefinedType(module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncVoidMethodBuilder"); AsyncTaskMethodBuilder = new PredefinedType(module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncTaskMethodBuilder"); AsyncTaskMethodBuilderGeneric = new PredefinedType(module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncTaskMethodBuilder", 1); Task = new PredefinedType(module, MemberKind.Class, "System.Threading.Tasks", "Task"); TaskGeneric = new PredefinedType(module, MemberKind.Class, "System.Threading.Tasks", "Task", 1); // // Define types which are used for comparison. It does not matter // if they don't exist as no error report is needed // if (TypedReference.Define()) { TypedReference.TypeSpec.IsSpecialRuntimeType = true; } if (ArgIterator.Define()) { ArgIterator.TypeSpec.IsSpecialRuntimeType = true; } if (IEnumerableGeneric.Define()) { IEnumerableGeneric.TypeSpec.IsGenericIterateInterface = true; } if (IListGeneric.Define()) { IListGeneric.TypeSpec.IsGenericIterateInterface = true; } if (ICollectionGeneric.Define()) { ICollectionGeneric.TypeSpec.IsGenericIterateInterface = true; } if (Nullable.Define()) { Nullable.TypeSpec.IsNullableType = true; } if (ExpressionGeneric.Define()) { ExpressionGeneric.TypeSpec.IsExpressionTreeType = true; } Task.Define(); if (TaskGeneric.Define()) { TaskGeneric.TypeSpec.IsGenericTask = true; } }
public PredefinedTypes(ModuleContainer module) { TypedReference = new PredefinedType(module, MemberKind.Struct, "System", "TypedReference"); ArgIterator = new PredefinedType(module, MemberKind.Struct, "System", "ArgIterator"); MarshalByRefObject = new PredefinedType(module, MemberKind.Class, "System", "MarshalByRefObject"); RuntimeHelpers = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "RuntimeHelpers"); IAsyncResult = new PredefinedType(module, MemberKind.Interface, "System", "IAsyncResult"); AsyncCallback = new PredefinedType(module, MemberKind.Delegate, "System", "AsyncCallback"); RuntimeArgumentHandle = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeArgumentHandle"); CharSet = new PredefinedType(module, MemberKind.Enum, "System.Runtime.InteropServices", "CharSet"); IsVolatile = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "IsVolatile"); IEnumeratorGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IEnumerator", 1); IListGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IList", 1); ICollectionGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "ICollection", 1); IEnumerableGeneric = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IEnumerable", 1); Nullable = new PredefinedType(module, MemberKind.Struct, "System", "Nullable", 1); Activator = new PredefinedType(module, MemberKind.Class, "System", "Activator"); Interlocked = new PredefinedType(module, MemberKind.Class, "System.Threading", "Interlocked"); Monitor = new PredefinedType(module, MemberKind.Class, "System.Threading", "Monitor"); NotSupportedException = new PredefinedType(module, MemberKind.Class, "System", "NotSupportedException"); RuntimeFieldHandle = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeFieldHandle"); RuntimeMethodHandle = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeMethodHandle"); SecurityAction = new PredefinedType(module, MemberKind.Enum, "System.Security.Permissions", "SecurityAction"); Expression = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "Expression"); ExpressionGeneric = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "Expression", 1); ParameterExpression = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "ParameterExpression"); FieldInfo = new PredefinedType(module, MemberKind.Class, "System.Reflection", "FieldInfo"); MethodBase = new PredefinedType(module, MemberKind.Class, "System.Reflection", "MethodBase"); MethodInfo = new PredefinedType(module, MemberKind.Class, "System.Reflection", "MethodInfo"); ConstructorInfo = new PredefinedType(module, MemberKind.Class, "System.Reflection", "ConstructorInfo"); CallSite = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite"); CallSiteGeneric = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite", 1); Binder = new PredefinedType(module, MemberKind.Class, "Microsoft.CSharp.RuntimeBinder", "Binder"); BinderFlags = new PredefinedType(module, MemberKind.Enum, "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags"); // // Define types which are used for comparison. It does not matter // if they don't exist as no error report is needed // TypedReference.Define(); ArgIterator.Define(); MarshalByRefObject.Define(); CharSet.Define(); IEnumerableGeneric.Define(); IListGeneric.Define(); ICollectionGeneric.Define(); IEnumerableGeneric.Define(); IEnumeratorGeneric.Define(); Nullable.Define(); ExpressionGeneric.Define(); // Deal with obsolete static types // TODO: remove TypeManager.typed_reference_type = TypedReference.TypeSpec; TypeManager.arg_iterator_type = ArgIterator.TypeSpec; TypeManager.mbr_type = MarshalByRefObject.TypeSpec; TypeManager.generic_ilist_type = IListGeneric.TypeSpec; TypeManager.generic_icollection_type = ICollectionGeneric.TypeSpec; TypeManager.generic_ienumerator_type = IEnumeratorGeneric.TypeSpec; TypeManager.generic_ienumerable_type = IEnumerableGeneric.TypeSpec; TypeManager.generic_nullable_type = Nullable.TypeSpec; TypeManager.expression_type = ExpressionGeneric.TypeSpec; }