Exemplo n.º 1
0
        //------------------------------------------------------------
        // MemberLookup.LookupExtensionMethodInInterfaces
        //
        /// <summary></summary>
        /// <param name="startAggTypeSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        private bool LookupExtensionMethodInInterfaces(AGGTYPESYM startAggTypeSym)
        {
            //DebugUtil.Assert(this.firstSymWithType == null || this.isMulti);
            //DebugUtil.Assert(startAggTypeSym != null);
            if (startAggTypeSym == null)
            {
                return(false);
            }
            if (this.firstSymWithType != null && this.firstSymWithType.IsNotNull)
            {
                return(false);
            }

            //DebugUtil.Assert(startAggTypeSym == null || startAggTypeSym.IsInterfaceType());
            //DebugUtil.Assert(startAggTypeSym != null || interfaceTypeArray.Count > 0);
            //DebugUtil.Assert((this.flags &
            //    (MemLookFlagsEnum.Ctor | MemLookFlagsEnum.Operator | MemLookFlagsEnum.BaseCall))
            //    == 0);

            TypeArray interfaceTypeArray = startAggTypeSym.GetIfacesAll();

            if (interfaceTypeArray == null || interfaceTypeArray.Count == 0)
            {
                return(false);
            }

            // Clear all the hidden flags. Anything found in a class hides any other
            // kind of member in all the interfaces.
            if (startAggTypeSym != null)
            {
                startAggTypeSym.AllHidden  = false;
                startAggTypeSym.DiffHidden = (this.firstSymWithType != null);
            }

            for (int i = 0; i < interfaceTypeArray.Count; ++i)
            {
                AGGTYPESYM type = interfaceTypeArray[i] as AGGTYPESYM;
                DebugUtil.Assert(type.IsInterfaceType());

                type.AllHidden  = false;
                type.DiffHidden = (this.firstSymWithType != null);
            }

            if (startAggTypeSym != null)
            {
                Compiler.EnsureState(startAggTypeSym, AggStateEnum.Prepared);
            }
            if (interfaceTypeArray != null)
            {
                Compiler.EnsureState(interfaceTypeArray, AggStateEnum.Prepared);
            }

            //--------------------------------------------------------
            // Loop through the interfaces.
            //--------------------------------------------------------
            bool       hideObject = false;
            int        index      = 0;
            AGGTYPESYM currentSym = interfaceTypeArray[index++] as AGGTYPESYM;

            DebugUtil.Assert(currentSym != null);

            for (; ;)
            {
                DebugUtil.Assert(currentSym != null && currentSym.IsInterfaceType());
                bool hideByName = false;

                if (!currentSym.AllHidden && SearchSingleType(currentSym, out hideByName))
                {
                    SYM fsym = this.firstSymWithType.Sym;
                    DebugUtil.Assert(fsym != null);

                    if (fsym.Kind == SYMKIND.METHSYM &&
                        (fsym as METHSYM).IsInstanceExtensionMethod)
                    {
                        hideByName |= !this.isMulti;

                        // Mark base interfaces appropriately.
                        TypeArray interfaceArray = currentSym.GetIfacesAll();
                        for (int i = 0; i < interfaceArray.Count; ++i)
                        {
                            AGGTYPESYM sym = interfaceArray[i] as AGGTYPESYM;
                            DebugUtil.Assert(sym.IsInterfaceType());

                            if (hideByName)
                            {
                                sym.AllHidden = true;
                            }
                            sym.DiffHidden = true;
                        }

                        // If we hide all base types, that includes object!
                        if (hideByName)
                        {
                            hideObject = true;
                        }
                    }
                }
                this.flags &= ~MemLookFlagsEnum.TypeVarsAllowed;

                if (index >= interfaceTypeArray.Count)
                {
                    return(!hideObject);
                }

                // Substitution has already been done.
                currentSym = interfaceTypeArray[index++] as AGGTYPESYM;
            }
        }