コード例 #1
0
        internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
        {
            if ((object)this == (object)t2)
            {
                return true;
            }

            ByRefReturnErrorTypeSymbol other = t2 as ByRefReturnErrorTypeSymbol;
            return (object)other != null && _referencedType.Equals(other._referencedType, comparison) &&
                   ((comparison & TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds) != 0 || _countOfCustomModifiersPrecedingByRef == other._countOfCustomModifiersPrecedingByRef);
        }
コード例 #2
0
 public static bool Equals(this ITypeSymbol first, ITypeSymbol second, TypeCompareKind typeCompareKind)
 {
     return(first.Equals(second, new Microsoft.CodeAnalysis.SymbolEqualityComparer(typeCompareKind)));
 }
コード例 #3
0
 private SymbolEqualityComparer(TypeCompareKind compareKind)
 {
     CompareKind = compareKind;
 }
コード例 #4
0
 public static bool HaveSameReturnTypes(MethodSymbol member1, MethodSymbol member2, TypeCompareKind typeComparison)
 {
     return(HaveSameReturnTypes(member1, GetTypeMap(member1), member2, GetTypeMap(member2), typeComparison));
 }
コード例 #5
0
 internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
 {
     return((object)t2 == this);
 }
コード例 #6
0
 internal bool Equals(FunctionPointerParameterSymbol other, TypeCompareKind compareKind, IReadOnlyDictionary <TypeParameterSymbol, bool>?isValueTypeOverride)
 => other.Ordinal == Ordinal &&
 _containingSymbol.Equals(other._containingSymbol, compareKind, isValueTypeOverride);
コード例 #7
0
 internal abstract override bool Equals(TypeSymbol t2, TypeCompareKind comparison);
コード例 #8
0
            internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
            {
                if (ReferenceEquals(this, t2))
                {
                    return true;
                }

                // if ignoring dynamic, then treat dynamic the same as the type 'object'
                if ((comparison & TypeCompareKind.IgnoreDynamic) != 0 &&
                    (object)t2 != null &&
                    t2.TypeKind == TypeKind.Dynamic &&
                    this.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_Object)
                {
                    return true;
                }

                var other = t2 as TopLevel;

                return (object)other != null &&
                    string.Equals(MetadataName, other.MetadataName, StringComparison.Ordinal) &&
                    arity == other.arity &&
                    string.Equals(_namespaceName, other.NamespaceName, StringComparison.Ordinal) &&
                    _containingModule.Equals(other._containingModule);
            }
コード例 #9
0
        private static bool HaveSameParameterTypes(
            ImmutableArray <ParameterSymbol> params1,
            TypeMap typeMap1,
            ImmutableArray <ParameterSymbol> params2,
            TypeMap typeMap2,
            bool considerRefKindDifferences,
            TypeCompareKind typeComparison
            )
        {
            Debug.Assert(params1.Length == params2.Length);

            var numParams = params1.Length;

            for (int i = 0; i < numParams; i++)
            {
                var param1 = params1[i];
                var param2 = params2[i];

                var type1 = SubstituteType(typeMap1, param1.TypeWithAnnotations);
                var type2 = SubstituteType(typeMap2, param2.TypeWithAnnotations);

                if (!type1.Equals(type2, typeComparison))
                {
                    return(false);
                }

                if (
                    (
                        typeComparison
                        & TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds
                    ) == 0 &&
                    !HaveSameCustomModifiers(
                        param1.RefCustomModifiers,
                        typeMap1,
                        param2.RefCustomModifiers,
                        typeMap2
                        )
                    )
                {
                    return(false);
                }

                var refKind1 = param1.RefKind;
                var refKind2 = param2.RefKind;

                // Metadata signatures don't distinguish ref/out, but C# does - even when comparing metadata method signatures.
                if (considerRefKindDifferences)
                {
                    if (refKind1 != refKind2)
                    {
                        return(false);
                    }
                }
                else
                {
                    if ((refKind1 == RefKind.None) != (refKind2 == RefKind.None))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #10
0
 /// <summary>
 /// Helper for more complicated cases of Equals like when we have generic instantiations or types nested within them.
 /// </summary>
 protected virtual bool EqualsComplicatedCases(NamedTypeSymbol other, TypeCompareKind comparison)
 {
     return(true);
 }
コード例 #11
0
        /// <summary>
        /// Compares this type to another type.
        /// </summary>
        public override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
        {
            Debug.Assert(!this.IsTupleType);

            if ((object)t2 == this)
            {
                return(true);
            }
            if ((object)t2 == null)
            {
                return(false);
            }

            if ((comparison & TypeCompareKind.IgnoreDynamic) != 0)
            {
                if (t2.TypeKind == LanguageTypeKind.Dynamic)
                {
                    // if ignoring dynamic, then treat dynamic the same as the type 'object'
                    if (this.SpecialType == SpecialType.System_Object)
                    {
                        return(true);
                    }
                }
            }

            NamedTypeSymbol other = t2 as NamedTypeSymbol;

            if ((object)other == null)
            {
                return(false);
            }

            // Compare OriginalDefinitions.
            var thisOriginalDefinition  = this.OriginalDefinition;
            var otherOriginalDefinition = other.OriginalDefinition;

            bool thisIsOriginalDefinition  = ((object)this == (object)thisOriginalDefinition);
            bool otherIsOriginalDefinition = ((object)other == (object)otherOriginalDefinition);

            if (thisIsOriginalDefinition && otherIsOriginalDefinition)
            {
                // If we continue, we either return false, or get into a cycle.
                return(false);
            }

            if ((thisIsOriginalDefinition || otherIsOriginalDefinition) &&
                (comparison & (TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.AllNullableIgnoreOptions)) == 0)
            {
                return(false);
            }

            // CONSIDER: original definitions are not unique for missing metadata type
            // symbols.  Therefore this code may not behave correctly if 'this' is List<int>
            // where List`1 is a missing metadata type symbol, and other is similarly List<int>
            // but for a reference-distinct List`1.
            if (!TypeSymbol.Equals(thisOriginalDefinition, otherOriginalDefinition, TypeCompareKind.ConsiderEverything2))
            {
                return(false);
            }

            // The checks above are supposed to handle the vast majority of cases.
            // More complicated cases are handled in a special helper to make the common case scenario simple/fast (fewer locals and smaller stack frame)
            return(EqualsComplicatedCases(other, comparison));
        }
コード例 #12
0
ファイル: TypeCompareKind.cs プロジェクト: soldetres/roslyn
 public static TypeCompareKind AddIgnoreTupleNames(this TypeCompareKind self, bool condition)
 {
     return(condition ? (self | TypeCompareKind.IgnoreTupleNames) : self);
 }
コード例 #13
0
ファイル: TypeCompareKind.cs プロジェクト: soldetres/roslyn
 public static TypeCompareKind AddIgnoreDynamic(this TypeCompareKind self, bool condition)
 {
     return(condition ? (self | TypeCompareKind.IgnoreDynamic) : self);
 }
コード例 #14
0
ファイル: TypeCompareKind.cs プロジェクト: soldetres/roslyn
 public static TypeCompareKind AddIgnoreCustomModifiersAndArraySizesAndLowerBounds(this TypeCompareKind self, bool condition)
 {
     return(condition ? (self | TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds) : self);
 }
コード例 #15
0
 internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
 {
     return(this.Equals(t2 as PointerTypeSymbol, comparison));
 }
コード例 #16
0
 internal bool Equals(FunctionPointerParameterSymbol other, TypeCompareKind compareKind)
 => other.Ordinal == Ordinal &&
 _containingSymbol.Equals(other._containingSymbol, compareKind);
コード例 #17
0
        internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
        {
            if (ReferenceEquals(this, t2))
            {
                return true;
            }

            if ((object)t2 == null)
            {
                return false;
            }

            CrefTypeParameterSymbol other = t2 as CrefTypeParameterSymbol;
            return (object)other != null &&
                other._name == _name &&
                other._ordinal == _ordinal &&
                other._declaringSyntax.GetSyntax() == _declaringSyntax.GetSyntax();
        }
コード例 #18
0
 // These object are unique (per index).
 internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
 {
     return ReferenceEquals(this, t2);
 }
コード例 #19
0
 public override bool Equals(Symbol obj, TypeCompareKind compareKind) =>
 obj is SynthesizedNamespaceSymbol other && Equals(other, compareKind);
コード例 #20
0
 /// <summary>
 /// For scenarios such as overriding with differing ref kinds (such as out vs in or ref)
 /// we need to compare function pointer parameters assuming that Ref matches RefReadonly/In
 /// and Out. This is done because you cannot overload on ref vs out vs in in regular method
 /// signatures, and we are disallowing similar overloads in source with function pointers.
 /// </summary>
 internal static bool RefKindEquals(TypeCompareKind compareKind, RefKind refKind1, RefKind refKind2)
 => (compareKind & TypeCompareKind.FunctionPointerRefMatchesOutInRefReadonly) != 0
        ? (refKind1 == RefKind.None) == (refKind2 == RefKind.None)
        : refKind1 == refKind2;
コード例 #21
0
 internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison, IReadOnlyDictionary <TypeParameterSymbol, bool>?isValueTypeOverrideOpt = null)
 {
     return(ReferenceEquals(this, t2));
 }
コード例 #22
0
ファイル: TupleErrorFieldSymbol.cs プロジェクト: zuvys/roslyn
 public override bool Equals(Symbol obj, TypeCompareKind compareKind)
 {
     return(Equals(obj as TupleErrorFieldSymbol, compareKind));
 }
コード例 #23
0
 private MetadataEntityReferenceComparer(TypeCompareKind compareKind)
 {
     _compareKind = compareKind;
 }
コード例 #24
0
 internal SymbolEqualityComparer(TypeCompareKind compareKind)
 {
     CompareKind = compareKind;
 }
コード例 #25
0
        internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
        {
            if (ReferenceEquals(this, t2))
            {
                return true;
            }

            var other = t2 as ExtendedErrorTypeSymbol;
            if ((object)other == null || _unreported || other._unreported)
            {
                return false;
            }

            return
                ((object)this.ContainingType != null ? this.ContainingType.Equals(other.ContainingType, comparison) :
                 (object)this.ContainingSymbol == null ? (object)other.ContainingSymbol == null : this.ContainingSymbol.Equals(other.ContainingSymbol)) &&
                this.Name == other.Name && this.Arity == other.Arity;
        }
コード例 #26
0
        private static bool HaveSameReturnTypes(Symbol member1, TypeMap typeMap1, Symbol member2, TypeMap typeMap2, TypeCompareKind typeComparison)
        {
            RefKind                         refKind1;
            TypeWithAnnotations             unsubstitutedReturnType1;
            ImmutableArray <CustomModifier> refCustomModifiers1;

            member1.GetTypeOrReturnType(out refKind1, out unsubstitutedReturnType1, out refCustomModifiers1);

            RefKind                         refKind2;
            TypeWithAnnotations             unsubstitutedReturnType2;
            ImmutableArray <CustomModifier> refCustomModifiers2;

            member2.GetTypeOrReturnType(out refKind2, out unsubstitutedReturnType2, out refCustomModifiers2);

            // short-circuit type map building in the easiest cases
            if (refKind1 != refKind2)
            {
                return(false);
            }

            var isVoid1 = unsubstitutedReturnType1.IsVoidType();
            var isVoid2 = unsubstitutedReturnType2.IsVoidType();

            if (isVoid1 != isVoid2)
            {
                return(false);
            }

            if (isVoid1)
            {
                if ((typeComparison & TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds) != 0 ||
                    (unsubstitutedReturnType1.CustomModifiers.IsEmpty && unsubstitutedReturnType2.CustomModifiers.IsEmpty))
                {
                    return(true);
                }
            }

            var returnType1 = SubstituteType(typeMap1, unsubstitutedReturnType1);
            var returnType2 = SubstituteType(typeMap2, unsubstitutedReturnType2);

            if (!returnType1.Equals(returnType2, typeComparison))
            {
                return(false);
            }

            if (((typeComparison & TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds) == 0) &&
                !HaveSameCustomModifiers(refCustomModifiers1, typeMap1, refCustomModifiers2, typeMap2))
            {
                return(false);
            }

            return(true);
        }
コード例 #27
0
 public override bool Equals(Symbol obj, TypeCompareKind compareKind)
 {
     return(Equals(obj as TuplePropertySymbol, compareKind));
 }
コード例 #28
0
 public override bool Equals(Symbol?other, TypeCompareKind comparison) => NativeIntegerTypeSymbol.EqualsHelper(this, other, comparison, symbol => symbol._underlyingProperty);
コード例 #29
0
ファイル: DiscardSymbol.cs プロジェクト: manoj-23/roslyn
 public override bool Equals(Symbol?obj, TypeCompareKind compareKind) => obj is DiscardSymbol other && this.TypeWithAnnotations.Equals(other.TypeWithAnnotations, compareKind);
コード例 #30
0
 public override bool Equals(Symbol obj, TypeCompareKind compareKind)
 {
     return(Equals(obj as TupleParameterSymbol));
 }
コード例 #31
0
            internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
            {
                if (ReferenceEquals(this, t2))
                {
                    return true;
                }

                var other = t2 as ErrorTypeParameterSymbol;
                return (object)other != null &&
                    other._ordinal == _ordinal &&
                    other.ContainingType.Equals(this.ContainingType, comparison);
            }
コード例 #32
0
 internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison, IReadOnlyDictionary <TypeParameterSymbol, bool> isValueTypeOverrideOpt = null)
 {
     return(this.Equals(t2 as TypeParameterSymbol, comparison, isValueTypeOverrideOpt));
 }
コード例 #33
0
 internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
 {
     return(ReferenceEquals(this, t2));
 }
コード例 #34
0
 internal bool MethodEqualityChecks(FunctionPointerParameterSymbol other, TypeCompareKind compareKind)
 => FunctionPointerTypeSymbol.RefKindEquals(compareKind, RefKind, other.RefKind) &&
 ((compareKind & TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds) != 0 ||
  RefCustomModifiers.SequenceEqual(other.RefCustomModifiers)) &&
 TypeWithAnnotations.Equals(other.TypeWithAnnotations, compareKind);
コード例 #35
0
 public override bool Equals(Symbol obj, TypeCompareKind compareKind)
 {
     return(Equals(obj as MissingAssemblySymbol));
 }
コード例 #36
0
            internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
            {
                if (ReferenceEquals(this, t2))
                {
                    return true;
                }

                var other = t2 as Nested;
                return (object)other != null && string.Equals(MetadataName, other.MetadataName, StringComparison.Ordinal) &&
                    arity == other.arity &&
                    _containingType.Equals(other._containingType, comparison);
            }
コード例 #37
0
ファイル: DiscardSymbol.cs プロジェクト: belav/roslyn
 public override bool Equals(Symbol?obj, TypeCompareKind compareKind) =>
 obj is DiscardSymbol other &&
コード例 #38
0
            internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
            {
                if (ReferenceEquals(this, t2))
                {
                    return true;
                }

                var other = t2 as AnonymousTypePublicSymbol;
                return (object)other != null && this.TypeDescriptor.Equals(other.TypeDescriptor, comparison);
            }
コード例 #39
0
ファイル: UnboundGenericType.cs プロジェクト: Rickinio/roslyn
        internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
        {
            if ((object)t2 == (object)this)
            {
                return true;
            }

            UnboundArgumentErrorTypeSymbol other = t2 as UnboundArgumentErrorTypeSymbol;
            return (object)other != null && string.Equals(other._name, _name, StringComparison.Ordinal) && object.Equals(other._errorInfo, _errorInfo);
        }