private Type GetSystemType(IType type) { // Get system type from external types ExternalType et = type as ExternalType; if (null != et) { return(et.ActualType); } // Get system array types from arrays of external types ArrayType arrayType = type as ArrayType; if (arrayType != null) { Type elementType = GetSystemType(arrayType.ElementType); int rank = arrayType.Rank; // Calling MakeArrayType(1) gives a multi-dimensional array with 1 dimensions, // which is (surprisingly) not the same as calling MakeArrayType() which gives // a single-dimensional array return(rank == 1 ? elementType.MakeArrayType() : elementType.MakeArrayType(rank)); } // This shouldn't happen since we only call GetSystemType on external types or arrays of such return(null); }
public IType Map(Type type) { ExternalType entity = (ExternalType)_entityCache[type]; if (null == entity) { if (type.IsArray) { return(GetArrayType(Map(type.GetElementType()), type.GetArrayRank())); } else { if (type.IsSubclassOf(Types.MulticastDelegate)) { entity = new ExternalCallableType(this, type); } else { entity = new ExternalType(this, type); } } Cache(entity); } return(entity); }
public TypeSystemServices(CompilerContext context) { if (null == context) { throw new ArgumentNullException("context"); } _context = context; CodeBuilder = new BooCodeBuilder(this); Cache(typeof(Builtins.duck), DuckType = new DuckTypeImpl(this)); Cache(IQuackFuType = new ExternalType(this, typeof(IQuackFu))); Cache(VoidType = new VoidTypeImpl(this)); Cache(ObjectType = new ExternalType(this, Types.Object)); Cache(RegexType = new ExternalType(this, Types.Regex)); Cache(ValueTypeType = new ExternalType(this, typeof(ValueType))); Cache(EnumType = new ExternalType(this, typeof(Enum))); Cache(ArrayType = new ExternalType(this, Types.Array)); Cache(TypeType = new ExternalType(this, Types.Type)); Cache(StringType = new ExternalType(this, Types.String)); Cache(BoolType = new ExternalType(this, Types.Bool)); Cache(SByteType = new ExternalType(this, Types.SByte)); Cache(CharType = new ExternalType(this, Types.Char)); Cache(ShortType = new ExternalType(this, Types.Short)); Cache(IntType = new ExternalType(this, Types.Int)); Cache(LongType = new ExternalType(this, Types.Long)); Cache(ByteType = new ExternalType(this, Types.Byte)); Cache(UShortType = new ExternalType(this, Types.UShort)); Cache(UIntType = new ExternalType(this, Types.UInt)); Cache(ULongType = new ExternalType(this, Types.ULong)); Cache(SingleType = new ExternalType(this, Types.Single)); Cache(DoubleType = new ExternalType(this, Types.Double)); Cache(DecimalType = new ExternalType(this, Types.Decimal)); Cache(TimeSpanType = new ExternalType(this, Types.TimeSpan)); Cache(DateTimeType = new ExternalType(this, Types.DateTime)); Cache(RuntimeServicesType = new ExternalType(this, Types.RuntimeServices)); Cache(BuiltinsType = new ExternalType(this, Types.Builtins)); Cache(ListType = new ExternalType(this, Types.List)); Cache(HashType = new ExternalType(this, Types.Hash)); Cache(ICallableType = new ExternalType(this, Types.ICallable)); Cache(IEnumerableType = new ExternalType(this, Types.IEnumerable)); Cache(IEnumeratorType = new ExternalType(this, typeof(IEnumerator))); Cache(ICollectionType = new ExternalType(this, Types.ICollection)); Cache(IListType = new ExternalType(this, Types.IList)); Cache(IDictionaryType = new ExternalType(this, Types.IDictionary)); Cache(ApplicationExceptionType = new ExternalType(this, Types.ApplicationException)); Cache(ExceptionType = new ExternalType(this, Types.Exception)); Cache(IntPtrType = new ExternalType(this, Types.IntPtr)); Cache(MulticastDelegateType = new ExternalType(this, Types.MulticastDelegate)); Cache(DelegateType = new ExternalType(this, Types.Delegate)); ObjectArrayType = GetArrayType(ObjectType, 1); PreparePrimitives(); PrepareBuiltinFunctions(); }
public bool IsDefined(IType attributeType) { ExternalType type = attributeType as ExternalType; if (null == type) { return(false); } return(MetadataUtil.IsAttributeDefined(_memberInfo, type.ActualType)); }
public MixedGenericType(TypeSystemServices tss, ExternalType definition, IType[] arguments) : base(tss, definition.ActualType) { _definition = definition; _arguments = arguments; _constructed = IsConstructed(); _typeMapper = new GenericTypeMapper( tss, definition.GenericTypeDefinitionInfo.GenericParameters, arguments); }
public virtual bool IsSubclassOf(IType other) { ExternalType external = other as ExternalType; if (null == external /*|| _typeSystemServices.VoidType == other*/) { return(false); } return(_type.IsSubclassOf(external._type) || (external.IsInterface && external._type.IsAssignableFrom(_type)) ); }
public IType Map(Type type) { ExternalType entity = (ExternalType)_entityCache[type]; if (null == entity) { if (type.IsArray) { return(GetArrayType(Map(type.GetElementType()), type.GetArrayRank())); } entity = CreateEntityForType(type); Cache(entity); } return(entity); }
private bool IsWideningPromotion(IType paramType, IType argumentType) { ExternalType expected = paramType as ExternalType; if (null == expected) { return(false); } ExternalType actual = argumentType as ExternalType; if (null == actual) { return(false); } return(Boo.Lang.Runtime.NumericTypes.IsWideningPromotion(expected.ActualType, actual.ActualType)); }
public virtual bool IsAssignableFrom(IType other) { ExternalType external = other as ExternalType; if (null == external) { if (EntityType.Null == other.EntityType) { return(!IsValueType); } return(other.IsSubclassOf(this)); } if (other == _typeSystemServices.VoidType) { return(false); } return(_type.IsAssignableFrom(external._type)); }
private IMember FindByMetadataToken(IMember source, ExternalType targetType) { // HACK: since the API doesn't provide a way to correlate members on a generic type // with the mapped members on a constructed type, we have to rely on them sharing the same // metadata token. MemberInfo sourceMemberInfo = ((IExternalEntity)source).MemberInfo; MemberFilter filter = delegate(MemberInfo candidate, object metadataToken) { return(candidate.MetadataToken.Equals(metadataToken)); }; BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly; bindingFlags |= (source.IsStatic ? BindingFlags.Static : BindingFlags.Instance); MemberInfo[] mappedMemberInfos = targetType.ActualType.FindMembers( sourceMemberInfo.MemberType, bindingFlags, filter, sourceMemberInfo.MetadataToken); return((IMember)TypeSystemServices.Map(mappedMemberInfos[0])); }
public ExternalConstructedTypeInfo(TypeSystemServices tss, ExternalType type) { _type = type; _tss = tss; }
public ExternalGenericTypeInfo(IReflectionTypeSystemProvider provider, ExternalType type) : base(provider) { _type = type; }
public ExternalConstructedTypeInfo(IReflectionTypeSystemProvider tss, ExternalType type) { _type = type; _tss = tss; }
public ExternalConstructedTypeInfo(TypeSystemServices tss, ExternalType type) { _type = type; _tss = tss; }
public ExternalGenericTypeInfo(TypeSystemServices tss, ExternalType type) { _type = type; _tss = tss; }
public ExternalGenericMapping(ExternalType constructedType, IType[] arguments) : base(constructedType, arguments) { _constructedType = constructedType; }
public ExternalGenericTypeInfo(TypeSystemServices tss, ExternalType type) : base(tss) { _type = type; }
void Cache(ExternalType tag) { _entityCache[tag.ActualType] = tag; }
protected void AddPrimitiveType(string name, ExternalType type) { _primitives[name] = type; type.PrimitiveName = name; }
protected override IMember CreateMappedMember(IMember source) { ExternalType targetType = _constructedType; return(FindByMetadataToken(source, _constructedType)); }
public TypeSystemServices(CompilerContext context) { if (null == context) throw new ArgumentNullException("context"); _context = context; _anonymousCallablesManager = new AnonymousCallablesManager(this); _genericsServices = new GenericsServices(context); CodeBuilder = new BooCodeBuilder(this); Cache(typeof(Builtins.duck), DuckType = new DuckTypeImpl(this)); Cache(IQuackFuType = new ExternalType(this, typeof(IQuackFu))); Cache(VoidType = new VoidTypeImpl(this)); Cache(ObjectType = new ExternalType(this, Types.Object)); Cache(RegexType = new ExternalType(this, Types.Regex)); Cache(ValueTypeType = new ExternalType(this, typeof(ValueType))); Cache(EnumType = new ExternalType(this, typeof(Enum))); Cache(ArrayType = new ExternalType(this, Types.Array)); Cache(TypeType = new ExternalType(this, Types.Type)); Cache(StringType = new ExternalType(this, Types.String)); Cache(BoolType = new ExternalType(this, Types.Bool)); Cache(SByteType = new ExternalType(this, Types.SByte)); Cache(CharType = new ExternalType(this, Types.Char)); Cache(ShortType = new ExternalType(this, Types.Short)); Cache(IntType = new ExternalType(this, Types.Int)); Cache(LongType = new ExternalType(this, Types.Long)); Cache(ByteType = new ExternalType(this, Types.Byte)); Cache(UShortType = new ExternalType(this, Types.UShort)); Cache(UIntType = new ExternalType(this, Types.UInt)); Cache(ULongType = new ExternalType(this, Types.ULong)); Cache(SingleType = new ExternalType(this, Types.Single)); Cache(DoubleType = new ExternalType(this, Types.Double)); Cache(DecimalType = new ExternalType(this, Types.Decimal)); Cache(TimeSpanType = new ExternalType(this, Types.TimeSpan)); Cache(DateTimeType = new ExternalType(this, Types.DateTime)); Cache(RuntimeServicesType = new ExternalType(this, Types.RuntimeServices)); Cache(BuiltinsType = new ExternalType(this, Types.Builtins)); Cache(ListType = new ExternalType(this, Types.List)); Cache(HashType = new ExternalType(this, Types.Hash)); Cache(ICallableType = new ExternalType(this, Types.ICallable)); Cache(IEnumerableType = new ExternalType(this, Types.IEnumerable)); Cache(IEnumeratorType = new ExternalType(this, typeof(IEnumerator))); Cache(ICollectionType = new ExternalType(this, Types.ICollection)); Cache(IListType = new ExternalType(this, Types.IList)); Cache(IDictionaryType = new ExternalType(this, Types.IDictionary)); Cache(IntPtrType = new ExternalType(this, Types.IntPtr)); Cache(UIntPtrType = new ExternalType(this, Types.UIntPtr)); Cache(MulticastDelegateType = new ExternalType(this, Types.MulticastDelegate)); Cache(DelegateType = new ExternalType(this, Types.Delegate)); Cache(SystemAttribute = new ExternalType(this, typeof(System.Attribute))); Cache(ConditionalAttribute = new ExternalType(this, typeof(System.Diagnostics.ConditionalAttribute))); Cache(IEnumerableGenericType = new ExternalType(this, typeof(System.Collections.Generic.IEnumerable<>))); Cache(IEnumeratorGenericType = new ExternalType(this, typeof(System.Collections.Generic.IEnumerator<>))); ObjectArrayType = GetArrayType(ObjectType, 1); PreparePrimitives(); PrepareBuiltinFunctions(); }
protected void Cache(ExternalType tag) { _entityCache[tag.ActualType] = tag; }
protected void AddPrimitiveType(string name, ExternalType type) { _primitives[name] = type; type.PrimitiveName = name; }