Ejemplo n.º 1
0
 public void InsertParameterModifier(
     Name pName,
     CType pElementType,
     ParameterModifierType pParameterModifier)
 {
     Debug.Assert(LookupParameterModifier(pName, pElementType) == null);
     _pParameterModifierTable.Add(new KeyPair <CType, Name>(pElementType, pName), pParameterModifier);
 }
Ejemplo n.º 2
0
        public ParameterModifierType CreateParameterModifier(Name name, CType pParameterType)
        {
            ParameterModifierType type = new ParameterModifierType();

            type.SetName(name);
            type.SetParameterType(pParameterType);

            type.SetTypeKind(TypeKind.TK_ParameterModifierType);
            return(type);
        }
Ejemplo n.º 3
0
        private static Type CalculateAssociatedSystemType(CType src)
        {
            Type result = null;

            switch (src.GetTypeKind())
            {
            case TypeKind.TK_ArrayType:
                ArrayType a           = (ArrayType)src;
                Type      elementType = a.GetElementType().AssociatedSystemType;
                result = a.IsSZArray ? elementType.MakeArrayType() : elementType.MakeArrayType(a.rank);
                break;

            case TypeKind.TK_NullableType:
                NullableType n = (NullableType)src;
                Type         underlyingType = n.GetUnderlyingType().AssociatedSystemType;
                result = typeof(Nullable <>).MakeGenericType(underlyingType);
                break;

            case TypeKind.TK_PointerType:
                PointerType p            = (PointerType)src;
                Type        referentType = p.GetReferentType().AssociatedSystemType;
                result = referentType.MakePointerType();
                break;

            case TypeKind.TK_ParameterModifierType:
                ParameterModifierType r = (ParameterModifierType)src;
                Type parameterType      = r.GetParameterType().AssociatedSystemType;
                result = parameterType.MakeByRefType();
                break;

            case TypeKind.TK_AggregateType:
                result = CalculateAssociatedSystemTypeForAggregate((AggregateType)src);
                break;

            case TypeKind.TK_TypeParameterType:
                TypeParameterType t = (TypeParameterType)src;
                if (t.IsMethodTypeParameter())
                {
                    MethodInfo meth = ((MethodSymbol)t.GetOwningSymbol()).AssociatedMemberInfo as MethodInfo;
                    result = meth.GetGenericArguments()[t.GetIndexInOwnParameters()];
                }
                else
                {
                    Type parentType = ((AggregateSymbol)t.GetOwningSymbol()).AssociatedSystemType;
                    result = parentType.GetGenericArguments()[t.GetIndexInOwnParameters()];
                }
                break;
            }

            Debug.Assert(result != null || src.GetTypeKind() == TypeKind.TK_AggregateType);
            return(result);
        }
Ejemplo n.º 4
0
        public ParameterModifierType GetParameterModifier(CType paramType, bool isOut)
        {
            ParameterModifierType pParamModifier = _typeTable.LookupParameterModifier(paramType, isOut);

            if (pParamModifier == null)
            {
                // No existing parammod symbol. Create a new one.
                pParamModifier = new ParameterModifierType(paramType, isOut);
                _typeTable.InsertParameterModifier(paramType, isOut, pParamModifier);
            }

            Debug.Assert(pParamModifier.ParameterType == paramType);

            return(pParamModifier);
        }
Ejemplo n.º 5
0
        public ParameterModifierType GetParameterModifier(CType paramType, bool isOut)
        {
            Name name = NameManager.GetPredefinedName(isOut ? PredefinedName.PN_OUTPARAM : PredefinedName.PN_REFPARAM);
            ParameterModifierType pParamModifier = _typeTable.LookupParameterModifier(name, paramType);

            if (pParamModifier == null)
            {
                // No existing parammod symbol. Create a new one.
                pParamModifier       = _typeFactory.CreateParameterModifier(name, paramType);
                pParamModifier.isOut = isOut;
                _typeTable.InsertParameterModifier(name, paramType, pParamModifier);
            }

            Debug.Assert(pParamModifier.GetParameterType() == paramType);

            return(pParamModifier);
        }
Ejemplo n.º 6
0
        private static Type CalculateAssociatedSystemType(CType src)
        {
            Type result = null;

            switch (src.GetTypeKind())
            {
            case TypeKind.TK_ArrayType:
                ArrayType a           = src.AsArrayType();
                Type      elementType = a.GetElementType().AssociatedSystemType;
                if (a.rank == 1)
                {
                    result = elementType.MakeArrayType();
                }
                else
                {
                    result = elementType.MakeArrayType(a.rank);
                }
                break;

            case TypeKind.TK_NullableType:
                NullableType n = src.AsNullableType();
                Type         underlyingType = n.GetUnderlyingType().AssociatedSystemType;
                result = typeof(Nullable <>).MakeGenericType(underlyingType);
                break;

            case TypeKind.TK_PointerType:
                PointerType p            = src.AsPointerType();
                Type        referentType = p.GetReferentType().AssociatedSystemType;
                result = referentType.MakePointerType();
                break;

            case TypeKind.TK_ParameterModifierType:
                ParameterModifierType r = src.AsParameterModifierType();
                Type parameterType      = r.GetParameterType().AssociatedSystemType;
                result = parameterType.MakeByRefType();
                break;

            case TypeKind.TK_AggregateType:
                result = CalculateAssociatedSystemTypeForAggregate(src.AsAggregateType());
                break;

            case TypeKind.TK_TypeParameterType:
                TypeParameterType t = src.AsTypeParameterType();
                Type parentType     = null;
                if (t.IsMethodTypeParameter())
                {
                    MethodInfo meth = t.GetOwningSymbol().AsMethodSymbol().AssociatedMemberInfo as MethodInfo;
                    result = meth.GetGenericArguments()[t.GetIndexInOwnParameters()];
                }
                else
                {
                    parentType = t.GetOwningSymbol().AsAggregateSymbol().AssociatedSystemType;
                    result     = parentType.GetTypeInfo().GenericTypeParameters[t.GetIndexInOwnParameters()];
                }
                break;

            case TypeKind.TK_ArgumentListType:
            case TypeKind.TK_BoundLambdaType:
            case TypeKind.TK_ErrorType:
            case TypeKind.TK_MethodGroupType:
            case TypeKind.TK_NaturalIntegerType:
            case TypeKind.TK_NullType:
            case TypeKind.TK_OpenTypePlaceholderType:
            case TypeKind.TK_UnboundLambdaType:
            case TypeKind.TK_VoidType:

            default:
                break;
            }

            Debug.Assert(result != null || src.GetTypeKind() == TypeKind.TK_AggregateType);
            return(result);
        }
Ejemplo n.º 7
0
        private CType SubstTypeCore(CType type, SubstContext pctx)
        {
            CType typeSrc;
            CType typeDst;

            switch (type.GetTypeKind())
            {
            default:
                Debug.Assert(false);
                return(type);

            case TypeKind.TK_NullType:
            case TypeKind.TK_VoidType:
            case TypeKind.TK_MethodGroupType:
            case TypeKind.TK_ArgumentListType:
                return(type);

            case TypeKind.TK_ParameterModifierType:
                ParameterModifierType mod = (ParameterModifierType)type;
                typeDst = SubstTypeCore(typeSrc = mod.GetParameterType(), pctx);
                return((typeDst == typeSrc) ? type : GetParameterModifier(typeDst, mod.isOut));

            case TypeKind.TK_ArrayType:
                var arr = (ArrayType)type;
                typeDst = SubstTypeCore(typeSrc = arr.GetElementType(), pctx);
                return((typeDst == typeSrc) ? type : GetArray(typeDst, arr.rank, arr.IsSZArray));

            case TypeKind.TK_PointerType:
                typeDst = SubstTypeCore(typeSrc = ((PointerType)type).GetReferentType(), pctx);
                return((typeDst == typeSrc) ? type : GetPointer(typeDst));

            case TypeKind.TK_NullableType:
                typeDst = SubstTypeCore(typeSrc = ((NullableType)type).GetUnderlyingType(), pctx);
                return((typeDst == typeSrc) ? type : GetNullable(typeDst));

            case TypeKind.TK_AggregateType:
                AggregateType ats = (AggregateType)type;
                if (ats.GetTypeArgsAll().Count > 0)
                {
                    TypeArray typeArgs = SubstTypeArray(ats.GetTypeArgsAll(), pctx);
                    if (ats.GetTypeArgsAll() != typeArgs)
                    {
                        return(GetAggregate(ats.getAggregate(), typeArgs));
                    }
                }
                return(type);

            case TypeKind.TK_ErrorType:
                ErrorType err = (ErrorType)type;
                if (err.HasParent)
                {
                    Debug.Assert(err.nameText != null && err.typeArgs != null);
                    TypeArray typeArgs = SubstTypeArray(err.typeArgs, pctx);
                    if (typeArgs != err.typeArgs)
                    {
                        return(GetErrorType(err.nameText, typeArgs));
                    }
                }

                return(type);

            case TypeKind.TK_TypeParameterType:
            {
                TypeParameterSymbol tvs = ((TypeParameterType)type).GetTypeParameterSymbol();
                int index = tvs.GetIndexInTotalParameters();
                if (tvs.IsMethodTypeParameter())
                {
                    if ((pctx.grfst & SubstTypeFlags.DenormMeth) != 0 && tvs.parent != null)
                    {
                        return(type);
                    }
                    Debug.Assert(tvs.GetIndexInOwnParameters() == tvs.GetIndexInTotalParameters());
                    if (index < pctx.ctypeMeth)
                    {
                        Debug.Assert(pctx.prgtypeMeth != null);
                        return(pctx.prgtypeMeth[index]);
                    }
                    else
                    {
                        return((pctx.grfst & SubstTypeFlags.NormMeth) != 0 ? GetStdMethTypeVar(index) : type);
                    }
                }
                if ((pctx.grfst & SubstTypeFlags.DenormClass) != 0 && tvs.parent != null)
                {
                    return(type);
                }
                return(index < pctx.ctypeCls ? pctx.prgtypeCls[index] :
                       ((pctx.grfst & SubstTypeFlags.NormClass) != 0 ? GetStdClsTypeVar(index) : type));
            }
            }
        }
Ejemplo n.º 8
0
        public ParameterModifierType CreateParameterModifier(Name name, CType pParameterType)
        {
            ParameterModifierType type = new ParameterModifierType();
            type.SetName(name);
            type.SetParameterType(pParameterType);

            type.SetTypeKind(TypeKind.TK_ParameterModifierType);
            return type;
        }
 public static void InsertParameterModifier(CType elementType, bool isOut, ParameterModifierType parameterModifier)
 {
     RuntimeBinder.EnsureLockIsTaken();
     Debug.Assert(LookupParameterModifier(elementType, isOut) == null);
     s_parameterModifierTable.Add(new KeyPair <CType, bool>(elementType, isOut), parameterModifier);
 }
Ejemplo n.º 10
0
        private CType SubstTypeCore(CType type, SubstContext pctx)
        {
            CType typeSrc;
            CType typeDst;

            switch (type.TypeKind)
            {
            default:
                Debug.Assert(false);
                return(type);

            case TypeKind.TK_NullType:
            case TypeKind.TK_VoidType:
            case TypeKind.TK_MethodGroupType:
            case TypeKind.TK_ArgumentListType:
                return(type);

            case TypeKind.TK_ParameterModifierType:
                ParameterModifierType mod = (ParameterModifierType)type;
                typeDst = SubstTypeCore(typeSrc = mod.ParameterType, pctx);
                return((typeDst == typeSrc) ? type : GetParameterModifier(typeDst, mod.IsOut));

            case TypeKind.TK_ArrayType:
                var arr = (ArrayType)type;
                typeDst = SubstTypeCore(typeSrc = arr.ElementType, pctx);
                return((typeDst == typeSrc) ? type : GetArray(typeDst, arr.Rank, arr.IsSZArray));

            case TypeKind.TK_PointerType:
                typeDst = SubstTypeCore(typeSrc = ((PointerType)type).ReferentType, pctx);
                return((typeDst == typeSrc) ? type : GetPointer(typeDst));

            case TypeKind.TK_NullableType:
                typeDst = SubstTypeCore(typeSrc = ((NullableType)type).UnderlyingType, pctx);
                return((typeDst == typeSrc) ? type : GetNullable(typeDst));

            case TypeKind.TK_AggregateType:
                return(SubstTypeCore((AggregateType)type, pctx));

            case TypeKind.TK_TypeParameterType:
            {
                TypeParameterSymbol tvs = ((TypeParameterType)type).Symbol;
                int index = tvs.GetIndexInTotalParameters();
                if (tvs.IsMethodTypeParameter())
                {
                    if ((pctx.grfst & SubstTypeFlags.DenormMeth) != 0 && tvs.parent != null)
                    {
                        return(type);
                    }
                    Debug.Assert(tvs.GetIndexInOwnParameters() == tvs.GetIndexInTotalParameters());
                    if (index < pctx.ctypeMeth)
                    {
                        Debug.Assert(pctx.prgtypeMeth != null);
                        return(pctx.prgtypeMeth[index]);
                    }
                    else
                    {
                        return((pctx.grfst & SubstTypeFlags.NormMeth) != 0 ? GetStdMethTypeVar(index) : type);
                    }
                }
                if ((pctx.grfst & SubstTypeFlags.DenormClass) != 0 && tvs.parent != null)
                {
                    return(type);
                }
                return(index < pctx.ctypeCls ? pctx.prgtypeCls[index] :
                       ((pctx.grfst & SubstTypeFlags.NormClass) != 0 ? GetStdClsTypeVar(index) : type));
            }
            }
        }
Ejemplo n.º 11
0
 public void InsertParameterModifier(CType pElementType, bool isOut, ParameterModifierType pParameterModifier)
 {
     Debug.Assert(LookupParameterModifier(pElementType, isOut) == null);
     _pParameterModifierTable.Add(new KeyPair <CType, bool>(pElementType, isOut), pParameterModifier);
 }
Ejemplo n.º 12
0
 public static void InsertParameterModifier(CType elementType, bool isOut, ParameterModifierType parameterModifier)
 {
     Debug.Assert(LookupParameterModifier(elementType, isOut) == null);
     s_parameterModifierTable.Add(new KeyPair <CType, bool>(elementType, isOut), parameterModifier);
 }