Example #1
0
        private void ComputeParameters()
        {
            if (_lazyParametersAndDiagnostics != null)
            {
                return;
            }

            var         diagnostics = DiagnosticBag.GetInstance();
            SyntaxToken arglistToken;
            var         parameters = ParameterHelpers.MakeParameters(_binder, this, _syntax.ParameterList, true, out arglistToken, diagnostics, true);
            var         isVararg   = (arglistToken.Kind() == SyntaxKind.ArgListKeyword);

            if (IsAsync && diagnostics.IsEmptyWithoutResolution)
            {
                SourceMemberMethodSymbol.ReportAsyncParameterErrors(parameters, diagnostics, this.Locations[0]);
            }
            var value = new ParametersAndDiagnostics(parameters, isVararg, diagnostics.ToReadOnlyAndFree());

            Interlocked.CompareExchange(ref _lazyParametersAndDiagnostics, value, null);
        }
Example #2
0
        /// <summary>
        /// Returns true if the two partial methods have the same constraints.
        /// </summary>
        private static bool HaveSameConstraints(SourceMemberMethodSymbol part1, SourceMemberMethodSymbol part2)
        {
            Debug.Assert(!ReferenceEquals(part1, part2));
            Debug.Assert(part1.Arity == part2.Arity);

            var typeParameters1 = part1.TypeParameters;

            int arity = typeParameters1.Length;

            if (arity == 0)
            {
                return(true);
            }

            var typeParameters2       = part2.TypeParameters;
            var indexedTypeParameters = IndexedTypeParameterSymbol.Take(arity);
            var typeMap1 = new TypeMap(typeParameters1, indexedTypeParameters, allowAlpha: true);
            var typeMap2 = new TypeMap(typeParameters2, indexedTypeParameters, allowAlpha: true);

            return(MemberSignatureComparer.HaveSameConstraints(typeParameters1, typeMap1, typeParameters2, typeMap2));
        }
        /// <summary>
        /// Returns true if the method is a constructor and has a this() constructor initializer.
        /// </summary>
        internal static bool HasThisConstructorInitializer(this MethodSymbol method)
        {
            if ((object)method != null && method.MethodKind == MethodKind.Constructor)
            {
                SourceMemberMethodSymbol sourceMethod = method as SourceMemberMethodSymbol;
                if ((object)sourceMethod != null)
                {
                    ConstructorDeclarationSyntax constructorSyntax = sourceMethod.SyntaxNode as ConstructorDeclarationSyntax;
                    if (constructorSyntax != null)
                    {
                        ConstructorInitializerSyntax initializerSyntax = constructorSyntax.Initializer;
                        if (initializerSyntax != null)
                        {
                            return(initializerSyntax.Kind() == SyntaxKind.ThisConstructorInitializer);
                        }
                    }
                }
            }

            return(false);
        }
        public override ImmutableArray <Symbol> GetMembers()
        {
            // @t-mawind
            //   Not making this lazy results in new symbols being created every
            //   time we call GetMembers(), which is not only inefficient but
            //   breaks reference equality.
            if (_members.IsDefault)
            {
                var mb = ArrayBuilder <Symbol> .GetInstance();

                mb.AddRange(base.GetMembers());

                // @t-mawind
                //   This is slightly wrong, but we don't have any syntax to
                //   cling onto apart from this...
                var binder = DeclaringCompilation.GetBinder(ContainingType.GetNonNullSyntaxNode());

                var diagnostics = DiagnosticBag.GetInstance();

                var memberSyntax = _concept.GetConceptDefaultMethods();
                foreach (var m in memberSyntax)
                {
                    var ms = m.GetSyntax() as MethodDeclarationSyntax;
                    if (ms == null)
                    {
                        continue;
                    }

                    mb.Add(SourceMemberMethodSymbol.CreateMethodSymbol(this, binder, ms, diagnostics));
                }

                AddDeclarationDiagnostics(diagnostics);

                ImmutableInterlocked.InterlockedInitialize(ref _members, mb.ToImmutableAndFree());
            }
            return(_members);
        }
 public ExplicitInterfaceMethodTypeParameterMap(SourceMemberMethodSymbol implementationMethod)
     : base(implementationMethod)
 {
     Debug.Assert(implementationMethod.IsExplicitInterfaceImplementation);
 }
 protected override MethodSymbol GetOverriddenMethod(SourceMemberMethodSymbol overridingMethod)
 {
     MethodSymbol method = overridingMethod;
     Debug.Assert(method.IsOverride);
     do
     {
         method = method.OverriddenMethod;
     } while (((object)method != null) && method.IsOverride);
     // OverriddenMethod may be null in error situations.
     return method;
 }
 public OverriddenMethodTypeParameterMap(SourceMemberMethodSymbol overridingMethod)
     : base(overridingMethod)
 {
     Debug.Assert(overridingMethod.IsOverride);
 }
 protected abstract MethodSymbol GetOverriddenMethod(SourceMemberMethodSymbol overridingMethod);
 public SourceMethodTypeParameterSymbol(SourceMemberMethodSymbol owner, string name, int ordinal, ImmutableArray<Location> locations, ImmutableArray<SyntaxReference> syntaxRefs)
     : base(name, ordinal, locations, syntaxRefs)
 {
     this.owner = owner;
 }
Example #10
0
        /// <summary>
        /// Returns true if the two partial methods have the same constraints.
        /// </summary>
        private static bool HaveSameConstraints(SourceMemberMethodSymbol part1, SourceMemberMethodSymbol part2)
        {
            Debug.Assert(!ReferenceEquals(part1, part2));
            Debug.Assert(part1.Arity == part2.Arity);

            var typeParameters1 = part1.TypeParameters;

            int arity = typeParameters1.Length;
            if (arity == 0)
            {
                return true;
            }

            var typeParameters2 = part2.TypeParameters;
            var indexedTypeParameters = IndexedTypeParameterSymbol.Take(arity);
            var typeMap1 = new TypeMap(typeParameters1, indexedTypeParameters, allowAlpha: true);
            var typeMap2 = new TypeMap(typeParameters2, indexedTypeParameters, allowAlpha: true);

            return MemberSignatureComparer.HaveSameConstraints(typeParameters1, typeMap1, typeParameters2, typeMap2);
        }
Example #11
0
 public OverriddenMethodTypeParameterMap(SourceMemberMethodSymbol overridingMethod)
     : base(overridingMethod)
 {
     Debug.Assert(overridingMethod.IsOverride);
 }
Example #12
0
 protected abstract MethodSymbol GetOverriddenMethod(SourceMemberMethodSymbol overridingMethod);
Example #13
0
 protected OverriddenMethodTypeParameterMapBase(SourceMemberMethodSymbol overridingMethod)
 {
     _overridingMethod = overridingMethod;
 }
Example #14
0
 public SourceMethodTypeParameterSymbol(SourceMemberMethodSymbol owner, string name, int ordinal, ImmutableArray <Location> locations, ImmutableArray <SyntaxReference> syntaxRefs)
     : base(name, ordinal, locations, syntaxRefs)
 {
     _owner = owner;
 }
        protected override MethodSymbol GetOverriddenMethod(SourceMemberMethodSymbol overridingMethod)
        {
            var explicitImplementations = overridingMethod.ExplicitInterfaceImplementations;
            Debug.Assert(explicitImplementations.Length <= 1);

            // ExplicitInterfaceImplementations may be empty in error situations.
            return (explicitImplementations.Length > 0) ? explicitImplementations[0] : null;
        }
Example #16
0
        /// <summary>
        /// Report differences between the defining and implementing
        /// parts of a partial method. Diagnostics are reported on the
        /// implementing part, matching Dev10 behavior.
        /// </summary>
        private static void PartialMethodChecks(SourceMemberMethodSymbol definition, SourceMemberMethodSymbol implementation, DiagnosticBag diagnostics)
        {
            Debug.Assert(!ReferenceEquals(definition, implementation));

            if (definition.IsStatic != implementation.IsStatic)
            {
                diagnostics.Add(ErrorCode.ERR_PartialMethodStaticDifference, implementation.Locations[0]);
            }

            if (definition.IsExtensionMethod != implementation.IsExtensionMethod)
            {
                diagnostics.Add(ErrorCode.ERR_PartialMethodExtensionDifference, implementation.Locations[0]);
            }

            if (definition.IsUnsafe != implementation.IsUnsafe && definition.CompilationAllowsUnsafe()) // Don't cascade.
            {
                diagnostics.Add(ErrorCode.ERR_PartialMethodUnsafeDifference, implementation.Locations[0]);
            }

            if (definition.IsParams() != implementation.IsParams())
            {
                diagnostics.Add(ErrorCode.ERR_PartialMethodParamsDifference, implementation.Locations[0]);
            }

            if (!HaveSameConstraints(definition, implementation))
            {
                diagnostics.Add(ErrorCode.ERR_PartialMethodInconsistentConstraints, implementation.Locations[0], implementation);
            }
        }
Example #17
0
 public ExplicitInterfaceMethodTypeParameterMap(SourceMemberMethodSymbol implementationMethod)
     : base(implementationMethod)
 {
     Debug.Assert(implementationMethod.IsExplicitInterfaceImplementation);
 }
Example #18
0
        internal static void InitializePartialMethodParts(SourceMemberMethodSymbol definition, SourceMemberMethodSymbol implementation)
        {
            Debug.Assert(definition.IsPartialDefinition);
            Debug.Assert(implementation.IsPartialImplementation);
            Debug.Assert((object)definition._otherPartOfPartial == null);
            Debug.Assert((object)implementation._otherPartOfPartial == null);

            definition._otherPartOfPartial = implementation;
            implementation._otherPartOfPartial = definition;
        }
 public SourceMethodTypeParameterSymbol(SourceMemberMethodSymbol owner, string name, int ordinal, NullabilityPreservationKind preservationKind, ImmutableArray<Location> locations, ImmutableArray<SyntaxReference> syntaxRefs)
     : base(name, ordinal, preservationKind, locations, syntaxRefs)
 {
     _owner = owner;
 }
Example #20
0
        internal static void InitializePartialMethodParts(SourceMemberMethodSymbol definition, SourceMemberMethodSymbol implementation)
        {
            Debug.Assert(definition.IsPartialDefinition);
            Debug.Assert(implementation.IsPartialImplementation);
            Debug.Assert((object)definition._otherPartOfPartial == null);
            Debug.Assert((object)implementation._otherPartOfPartial == null);

            definition._otherPartOfPartial     = implementation;
            implementation._otherPartOfPartial = definition;
        }
 protected OverriddenMethodTypeParameterMapBase(SourceMemberMethodSymbol overridingMethod)
 {
     _overridingMethod = overridingMethod;
 }