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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        public bool IsDefined(IType attributeType)
        {
            ExternalType type = attributeType as ExternalType;

            if (null == type)
            {
                return(false);
            }
            return(MetadataUtil.IsAttributeDefined(_memberInfo, type.ActualType));
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
        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))
                   );
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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;
 }
Exemplo n.º 12
0
 public ExternalGenericTypeInfo(IReflectionTypeSystemProvider provider, ExternalType type) : base(provider)
 {
     _type = type;
 }
Exemplo n.º 13
0
 public ExternalConstructedTypeInfo(IReflectionTypeSystemProvider tss, ExternalType type)
 {
     _type = type;
     _tss  = tss;
 }
Exemplo n.º 14
0
 public ExternalConstructedTypeInfo(TypeSystemServices tss, ExternalType type)
 {
     _type = type;
     _tss  = tss;
 }
Exemplo n.º 15
0
 public ExternalGenericTypeInfo(TypeSystemServices tss, ExternalType type)
 {
     _type = type;
     _tss  = tss;
 }
Exemplo n.º 16
0
 public ExternalGenericMapping(ExternalType constructedType, IType[] arguments) : base(constructedType, arguments)
 {
     _constructedType = constructedType;
 }
Exemplo n.º 17
0
 public ExternalGenericTypeInfo(TypeSystemServices tss, ExternalType type) : base(tss)
 {
     _type = type;
 }
Exemplo n.º 18
0
 void Cache(ExternalType tag)
 {
     _entityCache[tag.ActualType] = tag;
 }
Exemplo n.º 19
0
 protected void AddPrimitiveType(string name, ExternalType type)
 {
     _primitives[name]  = type;
     type.PrimitiveName = name;
 }
Exemplo n.º 20
0
        protected override IMember CreateMappedMember(IMember source)
        {
            ExternalType targetType = _constructedType;

            return(FindByMetadataToken(source, _constructedType));
        }
Exemplo n.º 21
0
        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();
        }
Exemplo n.º 22
0
 protected void Cache(ExternalType tag)
 {
     _entityCache[tag.ActualType] = tag;
 }
Exemplo n.º 23
0
 protected void AddPrimitiveType(string name, ExternalType type)
 {
     _primitives[name] = type;
     type.PrimitiveName = name;
 }