Ejemplo n.º 1
0
        /// <summary>
        /// If representative member is non-null and is contained in a constructed type, then find
        /// other members in the same type with the same signature.  If this is an override member,
        /// add them to the overridden and runtime overridden lists.  Otherwise, add them to the
        /// hidden list.
        /// </summary>
        private static void FindRelatedMembers(
            bool isOverride,
            bool overridingMemberIsFromSomeCompilation,
            LanguageSymbolKind overridingMemberKind,
            Symbol representativeMember,
            out ImmutableArray <Symbol> overriddenMembers,
            out ImmutableArray <Symbol> runtimeOverriddenMembers,
            ref ArrayBuilder <Symbol> hiddenBuilder)
        {
            overriddenMembers        = ImmutableArray <Symbol> .Empty;
            runtimeOverriddenMembers = ImmutableArray <Symbol> .Empty;

            if ((object)representativeMember != null)
            {
                bool needToSearchForRelated = !representativeMember.ContainingType.IsDefinition;

                if (isOverride)
                {
                    if (needToSearchForRelated)
                    {
                        ArrayBuilder <Symbol> overriddenBuilder = ArrayBuilder <Symbol> .GetInstance();

                        ArrayBuilder <Symbol> runtimeOverriddenBuilder = ArrayBuilder <Symbol> .GetInstance();

                        overriddenBuilder.Add(representativeMember);
                        runtimeOverriddenBuilder.Add(representativeMember);

                        FindOtherOverriddenMethodsInContainingType(representativeMember, overridingMemberIsFromSomeCompilation, overriddenBuilder, runtimeOverriddenBuilder);

                        overriddenMembers        = overriddenBuilder.ToImmutableAndFree();
                        runtimeOverriddenMembers = runtimeOverriddenBuilder.ToImmutableAndFree();
                    }
                    else
                    {
                        overriddenMembers        = ImmutableArray.Create <Symbol>(representativeMember);
                        runtimeOverriddenMembers = overriddenMembers;
                    }
                }
                else
                {
                    AddHiddenMemberIfApplicable(ref hiddenBuilder, overridingMemberKind, representativeMember);

                    if (needToSearchForRelated)
                    {
                        FindOtherHiddenMembersInContainingType(overridingMemberKind, representativeMember, ref hiddenBuilder);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public virtual CSharpSymbolKind ToCSharpKind(LanguageSymbolKind kind)
        {
            switch (kind.Switch())
            {
            case LanguageSymbolKind.Assembly:
                return(CSharpSymbolKind.Assembly);

            case LanguageSymbolKind.NetModule:
                return(CSharpSymbolKind.NetModule);

            case LanguageSymbolKind.Alias:
                return(CSharpSymbolKind.Alias);

            case LanguageSymbolKind.Namespace:
                return(CSharpSymbolKind.Namespace);

            case LanguageSymbolKind.NamedType:
                return(CSharpSymbolKind.NamedType);

            case LanguageSymbolKind.Property:
                return(CSharpSymbolKind.Property);

            case LanguageSymbolKind.Operation:
                return(CSharpSymbolKind.Method);

            case LanguageSymbolKind.ErrorType:
                return(CSharpSymbolKind.ErrorType);

            case LanguageSymbolKind.Name:
                return(CSharpSymbolKind.Namespace);

            case LanguageSymbolKind.DynamicType:
                return(CSharpSymbolKind.DynamicType);

            case LanguageSymbolKind.ConstructedType:
                return(CSharpSymbolKind.ArrayType);

            case LanguageSymbolKind.None:
                return(CSharpSymbolKind.ErrorType);

            default:
                throw new ArgumentException("Unexpected symbol kind: " + kind.ToString(), nameof(kind));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Look for overridden or hidden members in a specific type.
        /// </summary>
        /// <param name="member">Member that is hiding or overriding.</param>
        /// <param name="memberIsFromSomeCompilation">True if member is from the current compilation.</param>
        /// <param name="memberContainingType">The type that contains member (member.ContainingType).</param>
        /// <param name="currType">The type to search.</param>
        /// <param name="currTypeBestMatch">
        /// A member with the same signature if currTypeHasExactMatch is true,
        /// a member with (a minimal number of) different custom modifiers if there is one,
        /// and null otherwise.</param>
        /// <param name="currTypeHasSameKindNonMatch">True if there's a member with the same name and kind that is not a match.</param>
        /// <param name="hiddenBuilder">Hidden members (same name, different kind) will be added to this builder.</param>
        /// <remarks>
        /// There is some similarity between this member and TypeSymbol.FindPotentialImplicitImplementationMemberDeclaredInType.
        /// When making changes to this member, think about whether or not they should also be applied in TypeSymbol.
        ///
        /// In incorrect or imported code, it is possible that both currTypeBestMatch and hiddenBuilder will be populated.
        /// </remarks>
        private static void FindOverriddenOrHiddenMembersInType(
            Symbol member,
            bool memberIsFromSomeCompilation,
            NamedTypeSymbol memberContainingType,
            NamedTypeSymbol currType,
            out Symbol currTypeBestMatch,
            out bool currTypeHasSameKindNonMatch,
            out ArrayBuilder <Symbol> hiddenBuilder)
        {
            currTypeBestMatch           = null;
            currTypeHasSameKindNonMatch = false;
            hiddenBuilder = null;

            bool currTypeHasExactMatch    = false;
            LanguageSymbolKind memberKind = member.Kind;

            foreach (Symbol otherMember in currType.GetMembers(member.Name))
            {
                if (!IsOverriddenSymbolAccessible(otherMember, memberContainingType))
                {
                    //do nothing
                }
                else if (otherMember.Kind != memberKind)
                {
                    //do nothing
                }
                else if (!currTypeHasExactMatch)
                {
                    if (MatchesOverride(member, otherMember))
                    {
                        currTypeHasExactMatch = true;
                        currTypeBestMatch     = otherMember;
                    }
                    else
                    {
                        currTypeHasSameKindNonMatch = true;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Having found that we are hiding a method with exactly the same signature
 /// (including custom modifiers), we want to find methods with the same signature
 /// on the declaring type because they will also be hidden.
 /// (If the declaring type is constructed, it's possible that two or more
 /// methods have the same signature (including custom modifiers).)
 /// (If the representative member is an indexer, it's possible that two or more
 /// properties have the same signature (including custom modifiers, even in a
 /// non-generic type).
 /// </summary>
 /// <param name="hidingMemberKind">
 /// This kind of the hiding member.
 /// </param>
 /// <param name="representativeMember">
 /// The member that we consider to be hidden (must have exactly the same custom modifiers as the hiding member).
 /// Assumed to already be in hiddenBuilder.
 /// </param>
 /// <param name="hiddenBuilder">
 /// Will have all other members with the same signature (including custom modifiers) as
 /// representativeMember added.
 /// </param>
 private static void FindOtherHiddenMembersInContainingType(LanguageSymbolKind hidingMemberKind, Symbol representativeMember, ref ArrayBuilder <Symbol> hiddenBuilder)
 {
     Debug.Assert((object)representativeMember != null);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Some kinds of methods are not considered to be hideable by certain kinds of members.
 /// Specifically, methods, properties, and types cannot hide constructors, destructors,
 /// operators, conversions, or accessors.
 /// </summary>
 private static void AddHiddenMemberIfApplicable(ref ArrayBuilder <Symbol> hiddenBuilder, LanguageSymbolKind hidingMemberKind, Symbol hiddenMember)
 {
     Debug.Assert((object)hiddenMember != null);
     AccessOrGetInstance(ref hiddenBuilder).Add(hiddenMember);
 }