private MethodMemberBuilder(NamedTypeSymbol container, Binder enclosing, MemberDeclarationSyntax syntax, DiagnosticBag diagnostics)
            : base(enclosing.Location(syntax) as SourceLocation, container, enclosing)
        {
            Debug.Assert(syntax != null);
            this.syntax = syntax;

            // Make a binder context in which each type parameter binds to a corresponding numbered type parameter
            Binder parametersContext = Enclosing;
            if (syntax.Kind == SyntaxKind.MethodDeclaration)
            {
                var methodSyntax = syntax as MethodDeclarationSyntax;
                int arity = methodSyntax.Arity;
                if (arity != 0)
                {
                    var typeParamMap = new MultiDictionary<string, TypeParameterSymbol>();
                    var typeParams = methodSyntax.TypeParameterListOpt.Parameters;

                    for (int iParam = 0; iParam < typeParams.Count; iParam++)
                    {
                        var arg = typeParams[iParam];
                        var symbol = IndexedTypeParameterSymbol.GetTypeParameter(iParam);
                        typeParamMap.Add(arg.Identifier.ValueText, symbol);
                    }

                    parametersContext = new WithDummyTypeParametersBinder(typeParamMap, Enclosing);
                }

                if (methodSyntax.ExplicitInterfaceSpecifierOpt != null)
                {
                    this.explicitInterfaceType = enclosing.BindType(methodSyntax.ExplicitInterfaceSpecifierOpt.Name, diagnostics);
                }
            }

            // TODOngafter 1: recast this code using ReadOnlyArray.
            IEnumerable<ParameterSyntax> parameters = SyntaxParameters.HasValue ? SyntaxParameters.Value : SpecializedCollections.EmptyEnumerable<ParameterSyntax>();
            declaredParameterTypes = parameters.Select(p =>
            {
                if (p.TypeOpt == null)
                    return new CSErrorTypeSymbol(enclosing.Compilation.GlobalNamespace, "ErrorType", 0, diagnostics.Add(ErrorCode.ERR_NotYetImplementedInRoslyn, new SourceLocation(Tree, p)));
                return parametersContext.BindType(p.TypeOpt, diagnostics);
            }).ToList();

            var parameterRefs = parameters.Select(p => p.Modifiers.GetRefKind()).ToList();

            switch (syntax.Kind)
            {
                case SyntaxKind.ConstructorDeclaration:
                    Binder original = parametersContext; // TODOngafter 1: worry about diagnostic reporting and suppression here.
                    declaredReturnType = Enclosing.GetSpecialType(SpecialType.System_Void, diagnostics, syntax);
                    break;
                default:
                    declaredReturnType = parametersContext.BindType(SyntaxReturnType, diagnostics);
                    break;
            }

            TypeSymbol explType = null;
            var explSyntax = ExplicitInterface;
            if (explSyntax != null)
            {
                explType = parametersContext.BindType(explSyntax, diagnostics);
            }

            // TODOngafter 3: map dynamic->object for the signature
            this.signature = new MethodSignature(Name, SyntaxArity, declaredParameterTypes, parameterRefs, explType);
        }
예제 #2
0
        private MethodMemberBuilder(NamedTypeSymbol container, Binder enclosing, MemberDeclarationSyntax syntax, DiagnosticBag diagnostics)
            : base(enclosing.Location(syntax) as SourceLocation, container, enclosing)
        {
            Debug.Assert(syntax != null);
            this.syntax = syntax;

            // Make a binder context in which each type parameter binds to a corresponding numbered type parameter
            Binder parametersContext = Enclosing;

            if (syntax.Kind == SyntaxKind.MethodDeclaration)
            {
                var methodSyntax = syntax as MethodDeclarationSyntax;
                int arity        = methodSyntax.Arity;
                if (arity != 0)
                {
                    var typeParamMap = new MultiDictionary <string, TypeParameterSymbol>();
                    var typeParams   = methodSyntax.TypeParameterListOpt.Parameters;

                    for (int iParam = 0; iParam < typeParams.Count; iParam++)
                    {
                        var arg    = typeParams[iParam];
                        var symbol = IndexedTypeParameterSymbol.GetTypeParameter(iParam);
                        typeParamMap.Add(arg.Identifier.ValueText, symbol);
                    }

                    parametersContext = new WithDummyTypeParametersBinder(typeParamMap, Enclosing);
                }

                if (methodSyntax.ExplicitInterfaceSpecifierOpt != null)
                {
                    this.explicitInterfaceType = enclosing.BindType(methodSyntax.ExplicitInterfaceSpecifierOpt.Name, diagnostics);
                }
            }

            // TODOngafter 1: recast this code using ReadOnlyArray.
            IEnumerable <ParameterSyntax> parameters = SyntaxParameters.HasValue ? SyntaxParameters.Value : SpecializedCollections.EmptyEnumerable <ParameterSyntax>();

            declaredParameterTypes = parameters.Select(p =>
            {
                if (p.TypeOpt == null)
                {
                    return(new CSErrorTypeSymbol(enclosing.Compilation.GlobalNamespace, "ErrorType", 0, diagnostics.Add(ErrorCode.ERR_NotYetImplementedInRoslyn, new SourceLocation(Tree, p))));
                }
                return(parametersContext.BindType(p.TypeOpt, diagnostics));
            }).ToList();

            var parameterRefs = parameters.Select(p => p.Modifiers.GetRefKind()).ToList();

            switch (syntax.Kind)
            {
            case SyntaxKind.ConstructorDeclaration:
                Binder original = parametersContext;     // TODOngafter 1: worry about diagnostic reporting and suppression here.
                declaredReturnType = Enclosing.GetSpecialType(SpecialType.System_Void, diagnostics, syntax);
                break;

            default:
                declaredReturnType = parametersContext.BindType(SyntaxReturnType, diagnostics);
                break;
            }

            TypeSymbol explType   = null;
            var        explSyntax = ExplicitInterface;

            if (explSyntax != null)
            {
                explType = parametersContext.BindType(explSyntax, diagnostics);
            }

            // TODOngafter 3: map dynamic->object for the signature
            this.signature = new MethodSignature(Name, SyntaxArity, declaredParameterTypes, parameterRefs, explType);
        }