Esempio n. 1
0
        public ExprMemberGroup CreateMemGroup(EXPRFLAG nFlags, Name pName, TypeArray pTypeArgs, SYMKIND symKind, CType pTypePar, MethodOrPropertySymbol pMPS, Expr pObject, CMemberLookupResults memberLookupResults)
        {
            Debug.Assert(0 == (nFlags & ~(
                                   EXPRFLAG.EXF_CTOR | EXPRFLAG.EXF_INDEXER | EXPRFLAG.EXF_OPERATOR | EXPRFLAG.EXF_NEWOBJCALL |
                                   EXPRFLAG.EXF_BASECALL | EXPRFLAG.EXF_DELEGATE | EXPRFLAG.EXF_USERCALLABLE | EXPRFLAG.EXF_MASK_ANY
                                   )
                               ));
            ExprMemberGroup rval = new ExprMemberGroup();

            rval.Kind                = ExpressionKind.EK_MEMGRP;
            rval.Type                = GetTypes().GetMethGrpType();
            rval.Flags               = nFlags;
            rval.Name                = pName;
            rval.TypeArgs            = pTypeArgs;
            rval.SymKind             = symKind;
            rval.ParentType          = pTypePar;
            rval.OptionalObject      = pObject;
            rval.MemberLookupResults = memberLookupResults;
            rval.OptionalLHS         = null;
            if (rval.TypeArgs == null)
            {
                rval.TypeArgs = BSYMMGR.EmptyTypeArray();
            }
            Debug.Assert(rval != null);
            return(rval);
        }
Esempio n. 2
0
        public TypeManager()
        {
            _predefTypes = null; // Initialized via the Init call.
            _BSymmgr     = null; // Initialized via the Init call.
            _typeFactory = new TypeFactory();
            _typeTable   = new TypeTable();

            // special types with their own symbol kind.
            _errorType    = _typeFactory.CreateError(null, null, null, null, null);
            _voidType     = _typeFactory.CreateVoid();
            _nullType     = _typeFactory.CreateNull();
            _typeUnit     = _typeFactory.CreateUnit();
            _typeAnonMeth = _typeFactory.CreateAnonMethod();
            _typeMethGrp  = _typeFactory.CreateMethodGroup();
            _argListType  = _typeFactory.CreateArgList();

            InitType(_errorType);
            _errorType.SetErrors(true);

            InitType(_voidType);
            InitType(_nullType);
            InitType(_typeUnit);
            InitType(_typeAnonMeth);
            InitType(_typeMethGrp);

            _stvcMethod = new StdTypeVarColl();
            _stvcClass  = new StdTypeVarColl();
        }
Esempio n. 3
0
 public NullableType(CType underlyingType, BSYMMGR symmgr, TypeManager typeManager)
     : base(TypeKind.TK_NullableType)
 {
     UnderlyingType = underlyingType;
     _symmgr        = symmgr;
     _typeManager   = typeManager;
 }
Esempio n. 4
0
        public AggregateType GetAggregate(AggregateSymbol agg, AggregateType atsOuter, TypeArray typeArgs)
        {
            Debug.Assert(agg.GetTypeManager() == this);
            Debug.Assert(atsOuter == null || atsOuter.getAggregate() == agg.Parent, "");

            if (typeArgs == null)
            {
                typeArgs = BSYMMGR.EmptyTypeArray();
            }

            Debug.Assert(agg.GetTypeVars().Count == typeArgs.Count);
            AggregateType pAggregate = _typeTable.LookupAggregate(agg, atsOuter, typeArgs);

            if (pAggregate == null)
            {
                pAggregate = _typeFactory.CreateAggregateType(
                    agg,
                    typeArgs,
                    atsOuter
                    );

                Debug.Assert(!pAggregate.fConstraintsChecked && !pAggregate.fConstraintError);

                _typeTable.InsertAggregate(agg, atsOuter, typeArgs, pAggregate);
            }

            Debug.Assert(pAggregate.getAggregate() == agg);
            Debug.Assert(pAggregate.GetTypeArgsThis() != null && pAggregate.GetTypeArgsAll() != null);
            Debug.Assert(pAggregate.GetTypeArgsThis() == typeArgs);

            return(pAggregate);
        }
        public EXPRMEMGRP CreateMemGroup(EXPRFLAG nFlags, Name pName, TypeArray pTypeArgs, SYMKIND symKind, CType pTypePar, MethodOrPropertySymbol pMPS, EXPR pObject, CMemberLookupResults memberLookupResults)
        {
            Debug.Assert(0 == (nFlags & ~(
                                   EXPRFLAG.EXF_CTOR | EXPRFLAG.EXF_INDEXER | EXPRFLAG.EXF_OPERATOR | EXPRFLAG.EXF_NEWOBJCALL |
                                   EXPRFLAG.EXF_BASECALL | EXPRFLAG.EXF_DELEGATE | EXPRFLAG.EXF_USERCALLABLE | EXPRFLAG.EXF_MASK_ANY
                                   )
                               ));
            EXPRMEMGRP rval = new EXPRMEMGRP();

            rval.kind     = ExpressionKind.EK_MEMGRP;
            rval.type     = GetTypes().GetMethGrpType();
            rval.flags    = nFlags;
            rval.name     = pName;
            rval.typeArgs = pTypeArgs;
            rval.sk       = symKind;
            rval.SetParentType(pTypePar);
            rval.SetOptionalObject(pObject);
            rval.SetMemberLookupResults(memberLookupResults);
            rval.SetOptionalLHS(null);
            if (rval.typeArgs == null)
            {
                rval.typeArgs = BSYMMGR.EmptyTypeArray();
            }
            Debug.Assert(rval != null);
            return(rval);
        }
Esempio n. 6
0
        public AggregateType GetAggregate(AggregateSymbol agg, AggregateType atsOuter, TypeArray typeArgs)
        {
            Debug.Assert(agg.GetTypeManager() == this);
            Debug.Assert(atsOuter == null || atsOuter.OwningAggregate == agg.Parent, "");

            if (typeArgs == null)
            {
                typeArgs = BSYMMGR.EmptyTypeArray();
            }

            Debug.Assert(agg.GetTypeVars().Count == typeArgs.Count);
            AggregateType pAggregate = _typeTable.LookupAggregate(agg, atsOuter, typeArgs);

            if (pAggregate == null)
            {
                pAggregate = new AggregateType(agg, typeArgs, atsOuter);

                Debug.Assert(!pAggregate.ConstraintError.HasValue);

                _typeTable.InsertAggregate(agg, atsOuter, typeArgs, pAggregate);
            }

            Debug.Assert(pAggregate.OwningAggregate == agg);
            Debug.Assert(pAggregate.TypeArgsThis != null && pAggregate.TypeArgsAll != null);
            Debug.Assert(pAggregate.TypeArgsThis == typeArgs);

            return(pAggregate);
        }
        public void SetTypeVars(TypeArray typeVars)
        {
            if (typeVars == null)
            {
                _typeVarsThis = null;
                _typeVarsAll  = null;
            }
            else
            {
                TypeArray outerTypeVars;
                if (GetOuterAgg() != null)
                {
                    Debug.Assert(GetOuterAgg().GetTypeVars() != null);
                    Debug.Assert(GetOuterAgg().GetTypeVarsAll() != null);

                    outerTypeVars = GetOuterAgg().GetTypeVarsAll();
                }
                else
                {
                    outerTypeVars = BSYMMGR.EmptyTypeArray();
                }

                _typeVarsThis = typeVars;
                _typeVarsAll  = _pTypeManager.ConcatenateTypeArrays(outerTypeVars, typeVars);
            }
        }
Esempio n. 8
0
        public ErrorType GetErrorType(
            Name nameText,
            TypeArray typeArgs)
        {
            Debug.Assert(nameText != null);
            if (typeArgs == null)
            {
                typeArgs = BSYMMGR.EmptyTypeArray();
            }

            Name name = _BSymmgr.GetNameFromPtrs(nameText, typeArgs);

            Debug.Assert(name != null);

            ErrorType pError = _typeTable.LookupError(name);

            if (pError == null)
            {
                // No existing error symbol. Create a new one.
                pError = _typeFactory.CreateError(name, nameText, typeArgs);
                pError.SetErrors(true);
                _typeTable.InsertError(name, pError);
            }
            else
            {
                Debug.Assert(pError.HasErrors());
                Debug.Assert(pError.nameText == nameText);
                Debug.Assert(pError.typeArgs == typeArgs);
            }

            return(pError);
        }
Esempio n. 9
0
        public TypeManager(BSYMMGR bsymmgr, PredefinedTypes predefTypes)
        {
            _typeTable = new TypeTable();

            _stvcMethod  = new StdTypeVarColl();
            _BSymmgr     = bsymmgr;
            _predefTypes = predefTypes;
        }
Esempio n. 10
0
        public GlobalSymbolContext(NameManager namemgr)
        {
            GlobalSymbols = new BSYMMGR(namemgr);
            _predefTypes  = new PredefinedTypes(GlobalSymbols);
            TypeManager   = new TypeManager(GlobalSymbols, _predefTypes);

            _nameManager = namemgr;
        }
Esempio n. 11
0
        public ErrorType GetErrorType(
            CType pParentType,
            AssemblyQualifiedNamespaceSymbol pParentNS,
            Name nameText,
            TypeArray typeArgs)
        {
            Debug.Assert(nameText != null);
            Debug.Assert(pParentType == null || pParentNS == null);
            if (pParentType == null && pParentNS == null)
            {
                // Use the root namespace as the parent.
                pParentNS = _BSymmgr.GetRootNsAid();
            }
            if (typeArgs == null)
            {
                typeArgs = BSYMMGR.EmptyTypeArray();
            }

            Name name = _BSymmgr.GetNameFromPtrs(nameText, typeArgs);

            Debug.Assert(name != null);

            ErrorType pError = null;

            if (pParentType != null)
            {
                pError = _typeTable.LookupError(name, pParentType);
            }
            else
            {
                Debug.Assert(pParentNS != null);
                pError = _typeTable.LookupError(name, pParentNS);
            }

            if (pError == null)
            {
                // No existing error symbol. Create a new one.
                pError = _typeFactory.CreateError(name, pParentType, pParentNS, nameText, typeArgs);
                pError.SetErrors(true);
                if (pParentType != null)
                {
                    _typeTable.InsertError(name, pParentType, pError);
                }
                else
                {
                    _typeTable.InsertError(name, pParentNS, pError);
                }
            }
            else
            {
                Debug.Assert(pError.HasErrors());
                Debug.Assert(pError.nameText == nameText);
                Debug.Assert(pError.typeArgs == typeArgs);
            }

            return(pError);
        }
Esempio n. 12
0
        public GlobalSymbolContext(NameManager namemgr)
        {
            TypeManager   = new TypeManager();
            GlobalSymbols = new BSYMMGR(namemgr, TypeManager);
            m_predefTypes = new PredefinedTypes(GlobalSymbols);
            TypeManager.Init(GlobalSymbols, m_predefTypes);
            GlobalSymbols.Init();

            m_nameManager = namemgr;
        }
Esempio n. 13
0
 public CMemberLookupResults(
     TypeArray containingTypes,
     Name name)
 {
     _pName          = name;
     ContainingTypes = containingTypes;
     if (ContainingTypes == null)
     {
         ContainingTypes = BSYMMGR.EmptyTypeArray();
     }
 }
Esempio n. 14
0
        public NullableType CreateNullable(Name name, CType pUnderlyingType, BSYMMGR symmgr, TypeManager typeManager)
        {
            NullableType type = new NullableType();

            type.SetName(name);
            type.SetUnderlyingType(pUnderlyingType);
            type.symmgr      = symmgr;
            type.typeManager = typeManager;

            type.SetTypeKind(TypeKind.TK_NullableType);
            return(type);
        }
Esempio n. 15
0
 public ExprMemberGroup(CType type, EXPRFLAG flags, Name name, TypeArray typeArgs, SYMKIND symKind, CType parentType, MethodOrPropertySymbol pMPS, Expr optionalObject, CMemberLookupResults memberLookupResults)
     : base(ExpressionKind.MemberGroup, type)
 {
     Debug.Assert(
         (flags & ~(EXPRFLAG.EXF_CTOR | EXPRFLAG.EXF_INDEXER | EXPRFLAG.EXF_OPERATOR | EXPRFLAG.EXF_NEWOBJCALL
                    | EXPRFLAG.EXF_BASECALL | EXPRFLAG.EXF_DELEGATE | EXPRFLAG.EXF_USERCALLABLE
                    | EXPRFLAG.EXF_MASK_ANY)) == 0);
     Flags               = flags;
     Name                = name;
     TypeArgs            = typeArgs ?? BSYMMGR.EmptyTypeArray();
     SymKind             = symKind;
     ParentType          = parentType;
     OptionalObject      = optionalObject;
     MemberLookupResults = memberLookupResults;
 }
Esempio n. 16
0
        public TypeManager(BSYMMGR bsymmgr, PredefinedTypes predefTypes)
        {
            _typeFactory = new TypeFactory();
            _typeTable   = new TypeTable();

            // special types with their own symbol kind.
            _voidType    = _typeFactory.CreateVoid();
            _nullType    = _typeFactory.CreateNull();
            _typeMethGrp = _typeFactory.CreateMethodGroup();
            _argListType = _typeFactory.CreateArgList();

            _stvcMethod  = new StdTypeVarColl();
            _stvcClass   = new StdTypeVarColl();
            _BSymmgr     = bsymmgr;
            _predefTypes = predefTypes;
        }
Esempio n. 17
0
        public void SetTypeArgsThis(TypeArray pTypeArgsThis)
        {
            TypeArray pOuterTypeArgs;
            if (outerType != null)
            {
                Debug.Assert(outerType.GetTypeArgsThis() != null);
                Debug.Assert(outerType.GetTypeArgsAll() != null);

                pOuterTypeArgs = outerType.GetTypeArgsAll();
            }
            else
            {
                pOuterTypeArgs = BSYMMGR.EmptyTypeArray();
            }

            Debug.Assert(pTypeArgsThis != null);
            _pTypeArgsThis = pTypeArgsThis;
            SetTypeArgsAll(pOuterTypeArgs);
        }
Esempio n. 18
0
        private CType LoadTypeFromSignature(int[] signature, ref int indexIntoSignatures, TypeArray classTyVars)
        {
            Debug.Assert(signature != null);

            MethodSignatureEnum current = (MethodSignatureEnum)signature[indexIntoSignatures];

            indexIntoSignatures++;

            switch (current)
            {
            case MethodSignatureEnum.SIG_SZ_ARRAY:
                return(GetTypeManager()
                       .GetArray(LoadTypeFromSignature(signature, ref indexIntoSignatures, classTyVars), 1, true));

            case MethodSignatureEnum.SIG_METH_TYVAR:
                return(GetTypeManager().GetStdMethTypeVar(signature[indexIntoSignatures++]));

            case MethodSignatureEnum.SIG_CLASS_TYVAR:
                return(classTyVars[signature[indexIntoSignatures++]]);

            case (MethodSignatureEnum)PredefinedType.PT_VOID:
                return(VoidType.Instance);

            default:
                Debug.Assert(current >= 0 && (int)current < (int)PredefinedType.PT_COUNT);
                AggregateSymbol agg       = GetPredefAgg((PredefinedType)current);
                int             typeCount = agg.GetTypeVars().Count;
                if (typeCount == 0)
                {
                    return(GetTypeManager().GetAggregate(agg, BSYMMGR.EmptyTypeArray()));
                }

                CType[] typeArgs = new CType[typeCount];
                for (int iTypeArg = 0; iTypeArg < typeArgs.Length; iTypeArg++)
                {
                    typeArgs[iTypeArg] = LoadTypeFromSignature(signature, ref indexIntoSignatures, classTyVars);
                }

                return(GetTypeManager().GetAggregate(agg, getBSymmgr().AllocParams(typeArgs)));
            }
        }
Esempio n. 19
0
        public ExprCall BindNew(Expr pExprSrc)
        {
            Debug.Assert(pExprSrc != null);

            NullableType pNubSourceType = GetSymbolLoader().GetTypeManager().GetNullable(pExprSrc.Type);

            AggregateType pSourceType = pNubSourceType.GetAts();
            MethodSymbol  meth        = GetSymbolLoader().getBSymmgr().methNubCtor;

            if (meth == null)
            {
                meth = GetSymbolLoader().getPredefinedMembers().GetMethod(PREDEFMETH.PM_G_OPTIONAL_CTOR);
                Debug.Assert(meth != null);
                GetSymbolLoader().getBSymmgr().methNubCtor = meth;
            }

            MethWithInst    methwithinst = new MethWithInst(meth, pSourceType, BSYMMGR.EmptyTypeArray());
            ExprMemberGroup memgroup     = GetExprFactory().CreateMemGroup(null, methwithinst);

            return(GetExprFactory().CreateCall(EXPRFLAG.EXF_NEWOBJCALL | EXPRFLAG.EXF_CANTBENULL, pNubSourceType, pExprSrc, memgroup, methwithinst));
        }
        private AggregateSymbol FindPredefinedTypeCore(Name name, NamespaceOrAggregateSymbol bag, KAID aid, AggKindEnum aggKind, int arity,
                                                       out AggregateSymbol paggAmbig, out AggregateSymbol paggBad)
        {
            AggregateSymbol aggFound = null;

            paggAmbig = null;
            paggBad   = null;

            for (AggregateSymbol aggCur = _pBSymmgr.LookupGlobalSymCore(name, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol();
                 aggCur != null;
                 aggCur = BSYMMGR.LookupNextSym(aggCur, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol())
            {
                if (!aggCur.InAlias(aid) || aggCur.GetTypeVarsAll().size != arity)
                {
                    continue;
                }
                if (aggCur.AggKind() != aggKind)
                {
                    if (paggBad == null)
                    {
                        paggBad = aggCur;
                    }
                    continue;
                }
                if (aggFound != null)
                {
                    Debug.Assert(paggAmbig == null);
                    paggAmbig = aggCur;
                    break;
                }
                aggFound = aggCur;
                if (paggAmbig == null)
                {
                    break;
                }
            }

            return(aggFound);
        }
Esempio n. 21
0
        public EXPRCALL BindNew(EXPR pExprSrc)
        {
            Debug.Assert(pExprSrc != null);

            NullableType pNubSourceType = GetSymbolLoader().GetTypeManager().GetNullable(pExprSrc.type);

            AggregateType pSourceType = pNubSourceType.GetAts(GetErrorContext());

            if (pSourceType == null)
            {
                MethWithInst mwi       = new MethWithInst(null, null);
                EXPRMEMGRP   pMemGroup = GetExprFactory().CreateMemGroup(pExprSrc, mwi);
                EXPRCALL     rval      = GetExprFactory().CreateCall(0, pNubSourceType, null, pMemGroup, null);
                rval.SetError();
                return(rval);
            }

            // UNDONE: move this to transform pass
            MethodSymbol meth = GetSymbolLoader().getBSymmgr().methNubCtor;

            if (meth == null)
            {
                meth = GetSymbolLoader().getPredefinedMembers().GetMethod(PREDEFMETH.PM_G_OPTIONAL_CTOR);
                GetSymbolLoader().getBSymmgr().methNubCtor = meth;
            }

            MethWithInst methwithinst = new MethWithInst(meth, pSourceType, BSYMMGR.EmptyTypeArray());
            EXPRMEMGRP   memgroup     = GetExprFactory().CreateMemGroup(null, methwithinst);
            EXPRCALL     pExprRes     = GetExprFactory().CreateCall(EXPRFLAG.EXF_NEWOBJCALL | EXPRFLAG.EXF_CANTBENULL, pNubSourceType, pExprSrc, memgroup, methwithinst);

            if (meth == null)
            {
                pExprRes.SetError();
            }

            return(pExprRes);
        }
Esempio n. 22
0
        public AggregateType(AggregateSymbol parent, TypeArray typeArgsThis, AggregateType outerType)
            : base(TypeKind.TK_AggregateType)
        {
            Debug.Assert(typeArgsThis != null);
            OuterType       = outerType;
            OwningAggregate = parent;
            TypeArgsThis    = typeArgsThis;

            // Here we need to check our current type args. If we have an open placeholder,
            // then we need to have all open placeholders, and we want to flush
            // our outer type args so that they're open placeholders.
            //
            // This is because of the following scenario:
            //
            // class B<T>
            // {
            //     class C<U>
            //     {
            //     }
            //     class D
            //     {
            //         void Foo()
            //         {
            //             Type T = typeof(C<>);
            //         }
            //     }
            // }
            //
            // The outer type will be B<T>, but the inner type will be C<>. However,
            // this will eventually be represented in IL as B<>.C<>. As such, we should
            // keep our data structures clear - if we have one open type argument, then
            // all of them must be open type arguments.
            //
            // Ensure that invariant here.

            Debug.Assert(outerType == null || outerType.TypeArgsAll != null);
            TypeArgsAll = parent.GetTypeManager()
                          .ConcatenateTypeArrays(outerType != null ? outerType.TypeArgsAll : BSYMMGR.EmptyTypeArray(), typeArgsThis);
        }
Esempio n. 23
0
        /***************************************************************************************************
        *   Lookup must be called before anything else can be called.
        *
        *   typeSrc - Must be an AggregateType or TypeParameterType.
        *   obj - the expression through which the member is being accessed. This is used for accessibility
        *       of protected members and for constructing a MEMGRP from the results of the lookup.
        *       It is legal for obj to be an EK_CLASS, in which case it may be used for accessibility, but
        *       will not be used for MEMGRP construction.
        *   symWhere - the symbol from with the name is being accessed (for checking accessibility).
        *   name - the name to look for.
        *   arity - the number of type args specified. Only members that support this arity are found.
        *       Note that when arity is zero, all methods are considered since we do type argument
        *       inferencing.
        *
        *   flags - See MemLookFlags.
        *       TypeVarsAllowed only applies to the most derived type (not base types).
        ***************************************************************************************************/
        public bool Lookup(CSemanticChecker checker, CType typeSrc, EXPR obj, ParentSymbol symWhere, Name name, int arity, MemLookFlags flags)
        {
            Debug.Assert((flags & ~MemLookFlags.All) == 0);
            Debug.Assert(obj == null || obj.type != null);
            Debug.Assert(typeSrc.IsAggregateType() || typeSrc.IsTypeParameterType());
            Debug.Assert(checker != null);

            _prgtype = _rgtypeStart;

            // Save the inputs for error handling, etc.
            _pSemanticChecker = checker;
            _pSymbolLoader    = checker.GetSymbolLoader();
            _typeSrc          = typeSrc;
            _obj      = (obj != null && !obj.isCLASS()) ? obj : null;
            _symWhere = symWhere;
            _name     = name;
            _arity    = arity;
            _flags    = flags;

            if ((_flags & MemLookFlags.BaseCall) != 0)
            {
                _typeQual = null;
            }
            else if ((_flags & MemLookFlags.Ctor) != 0)
            {
                _typeQual = _typeSrc;
            }
            else if (obj != null)
            {
                _typeQual = (CType)obj.type;
            }
            else
            {
                _typeQual = null;
            }

            // Determine what to search.
            AggregateType typeCls1  = null;
            AggregateType typeIface = null;
            TypeArray     ifaces    = BSYMMGR.EmptyTypeArray();
            AggregateType typeCls2  = null;

            if (typeSrc.IsTypeParameterType())
            {
                Debug.Assert((_flags & (MemLookFlags.Ctor | MemLookFlags.NewObj | MemLookFlags.Operator | MemLookFlags.BaseCall | MemLookFlags.TypeVarsAllowed)) == 0);
                _flags  &= ~MemLookFlags.TypeVarsAllowed;
                ifaces   = typeSrc.AsTypeParameterType().GetInterfaceBounds();
                typeCls1 = typeSrc.AsTypeParameterType().GetEffectiveBaseClass();
                if (ifaces.size > 0 && typeCls1.isPredefType(PredefinedType.PT_OBJECT))
                {
                    typeCls1 = null;
                }
            }
            else if (!typeSrc.isInterfaceType())
            {
                typeCls1 = typeSrc.AsAggregateType();

                if (typeCls1.IsWindowsRuntimeType())
                {
                    ifaces = typeCls1.GetWinRTCollectionIfacesAll(GetSymbolLoader());
                }
            }
            else
            {
                Debug.Assert(typeSrc.isInterfaceType());
                Debug.Assert((_flags & (MemLookFlags.Ctor | MemLookFlags.NewObj | MemLookFlags.Operator | MemLookFlags.BaseCall)) == 0);
                typeIface = typeSrc.AsAggregateType();
                ifaces    = typeIface.GetIfacesAll();
            }

            if (typeIface != null || ifaces.size > 0)
            {
                typeCls2 = GetSymbolLoader().GetReqPredefType(PredefinedType.PT_OBJECT);
            }

            // Search the class first (except possibly object).
            if (typeCls1 == null || LookupInClass(typeCls1, ref typeCls2))
            {
                // Search the interfaces.
                if ((typeIface != null || ifaces.size > 0) && LookupInInterfaces(typeIface, ifaces) && typeCls2 != null)
                {
                    // Search object last.
                    Debug.Assert(typeCls2 != null && typeCls2.isPredefType(PredefinedType.PT_OBJECT));

                    AggregateType result = null;
                    LookupInClass(typeCls2, ref result);
                }
            }

            // if we are requested with extension methods
            _results = new CMemberLookupResults(GetAllTypes(), _name);

            return(!FError());
        }
        KAID aidMsCorLib;             // The assembly ID for all predefined types.

        public PredefinedTypes(BSYMMGR pBSymmgr)
        {
            this.pBSymmgr    = pBSymmgr;
            this.aidMsCorLib = KAID.kaidNil;
            this.runtimeBinderSymbolTable = null;
        }
Esempio n. 25
0
        private AggregateSymbol[] _predefSyms;    // array of predefined symbol types.

        public PredefinedTypes(BSYMMGR symbolManager)
        {
            _symbolManager            = symbolManager;
            _runtimeBinderSymbolTable = null;
        }
Esempio n. 26
0
        /***************************************************************************************************
        *   Lookup must be called before anything else can be called.
        *
        *   typeSrc - Must be an AggregateType or TypeParameterType.
        *   obj - the expression through which the member is being accessed. This is used for accessibility
        *       of protected members and for constructing a MEMGRP from the results of the lookup.
        *       It is legal for obj to be an EK_CLASS, in which case it may be used for accessibility, but
        *       will not be used for MEMGRP construction.
        *   symWhere - the symbol from with the name is being accessed (for checking accessibility).
        *   name - the name to look for.
        *   arity - the number of type args specified. Only members that support this arity are found.
        *       Note that when arity is zero, all methods are considered since we do type argument
        *       inferencing.
        *
        *   flags - See MemLookFlags.
        *       TypeVarsAllowed only applies to the most derived type (not base types).
        ***************************************************************************************************/
        public bool Lookup(CSemanticChecker checker, CType typeSrc, Expr obj, ParentSymbol symWhere, Name name, int arity, MemLookFlags flags)
        {
            Debug.Assert((flags & ~MemLookFlags.All) == 0);
            Debug.Assert(obj == null || obj.Type != null);
            Debug.Assert(typeSrc is AggregateType);
            Debug.Assert(checker != null);

            _prgtype = _rgtypeStart;

            // Save the inputs for error handling, etc.
            _pSemanticChecker = checker;
            _pSymbolLoader    = checker.SymbolLoader;
            _typeSrc          = typeSrc;
            _obj      = obj is ExprClass ? null : obj;
            _symWhere = symWhere;
            _name     = name;
            _arity    = arity;
            _flags    = flags;

            _typeQual = (_flags & MemLookFlags.Ctor) != 0 ? _typeSrc : obj?.Type;

            // Determine what to search.
            AggregateType typeCls1  = null;
            AggregateType typeIface = null;
            TypeArray     ifaces    = BSYMMGR.EmptyTypeArray();
            AggregateType typeCls2  = null;

            if (!typeSrc.IsInterfaceType)
            {
                typeCls1 = (AggregateType)typeSrc;

                if (typeCls1.IsWindowsRuntimeType)
                {
                    ifaces = typeCls1.GetWinRTCollectionIfacesAll(GetSymbolLoader());
                }
            }
            else
            {
                Debug.Assert((_flags & (MemLookFlags.Ctor | MemLookFlags.NewObj | MemLookFlags.Operator | MemLookFlags.BaseCall)) == 0);
                typeIface = (AggregateType)typeSrc;
                ifaces    = typeIface.IfacesAll;
            }

            if (typeIface != null || ifaces.Count > 0)
            {
                typeCls2 = GetSymbolLoader().GetPredefindType(PredefinedType.PT_OBJECT);
            }

            // Search the class first (except possibly object).
            if (typeCls1 == null || LookupInClass(typeCls1, ref typeCls2))
            {
                // Search the interfaces.
                if ((typeIface != null || ifaces.Count > 0) && LookupInInterfaces(typeIface, ifaces) && typeCls2 != null)
                {
                    // Search object last.
                    Debug.Assert(typeCls2 != null && typeCls2.IsPredefType(PredefinedType.PT_OBJECT));

                    AggregateType result = null;
                    LookupInClass(typeCls2, ref result);
                }
            }

            return(!FError());
        }
        private KAID _aidMsCorLib;             // The assembly ID for all predefined types.

        public PredefinedTypes(BSYMMGR pBSymmgr)
        {
            _pBSymmgr    = pBSymmgr;
            _aidMsCorLib = KAID.kaidNil;
            _runtimeBinderSymbolTable = null;
        }
Esempio n. 28
0
 public static Symbol LookupNextSym(Symbol sym, ParentSymbol parent, symbmask_t kindmask)
 => BSYMMGR.LookupNextSym(sym, parent, kindmask);
Esempio n. 29
0
 public Symbol LookupNextSym(Symbol sym, ParentSymbol parent, symbmask_t kindmask)
 {
     return(BSYMMGR.LookupNextSym(sym, parent, kindmask));
 }
Esempio n. 30
0
        public AggregateType GetAggregate(AggregateSymbol agg, AggregateType atsOuter, TypeArray typeArgs)
        {
            Debug.Assert(agg.GetTypeManager() == this);
            Debug.Assert(atsOuter == null || atsOuter.getAggregate() == agg.Parent, "");

            if (typeArgs == null)
            {
                typeArgs = BSYMMGR.EmptyTypeArray();
            }

            Debug.Assert(agg.GetTypeVars().Count == typeArgs.Count);

            Name name = _BSymmgr.GetNameFromPtrs(typeArgs, atsOuter);

            Debug.Assert(name != null);

            AggregateType pAggregate = _typeTable.LookupAggregate(name, agg);

            if (pAggregate == null)
            {
                pAggregate = _typeFactory.CreateAggregateType(
                    name,
                    agg,
                    typeArgs,
                    atsOuter
                    );

                Debug.Assert(!pAggregate.fConstraintsChecked && !pAggregate.fConstraintError);

                pAggregate.SetErrors(false);
                _typeTable.InsertAggregate(name, agg, pAggregate);

                // If we have a generic type definition, then we need to set the
                // base class to be our current base type, and use that to calculate
                // our agg type and its base, then set it to be the generic version of the
                // base type. This is because:
                //
                // Suppose we have Foo<T> : IFoo<T>
                //
                // Initially, the BaseType will be IFoo<Foo.T>, which gives us the substitution
                // that we want to use for our agg type's base type. However, in the Symbol chain,
                // we want the base type to be IFoo<IFoo.T>. Thats why we need to do this little trick.
                //
                // If we don't have a generic type definition, then we just need to set our base
                // class. This is so that if we have a base type that's generic, we'll be
                // getting the correctly instantiated base type.

                var baseType = pAggregate.AssociatedSystemType?.BaseType;
                if (baseType != null)
                {
                    // Store the old base class.

                    AggregateType oldBaseType = agg.GetBaseClass();
                    agg.SetBaseClass(_symbolTable.GetCTypeFromType(baseType) as AggregateType);
                    pAggregate.GetBaseClass(); // Get the base type for the new agg type we're making.

                    agg.SetBaseClass(oldBaseType);
                }
            }
            else
            {
                Debug.Assert(!pAggregate.HasErrors());
            }

            Debug.Assert(pAggregate.getAggregate() == agg);
            Debug.Assert(pAggregate.GetTypeArgsThis() != null && pAggregate.GetTypeArgsAll() != null);
            Debug.Assert(pAggregate.GetTypeArgsThis() == typeArgs);

            return(pAggregate);
        }