示例#1
0
            protected override TypeSymbol MakeReturnType(Binder bodyBinder, DelegateDeclarationSyntax syntax, DiagnosticBag diagnostics)
            {
                TypeSymbol returnType = bodyBinder.BindType(syntax.ReturnType, diagnostics);

                if (returnType.IsRestrictedType())
                {
                    // Method or delegate cannot return type '{0}'
                    diagnostics.Add(ErrorCode.ERR_MethodReturnCantBeRefAny, syntax.ReturnType.Location, returnType);
                }

                return(returnType);
            }
            protected override TypeSymbol MakeReturnType(Binder bodyBinder, DelegateDeclarationSyntax syntax, DiagnosticBag diagnostics)
            {
                TypeSymbol returnType = bodyBinder.BindType(syntax.ReturnType, diagnostics);

                if (returnType.IsRestrictedType())
                {
                    // Method or delegate cannot return type '{0}'
                    diagnostics.Add(ErrorCode.ERR_MethodReturnCantBeRefAny, syntax.ReturnType.Location, returnType);
                }

                return returnType;
            }
        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);
        }
 protected override TypeSymbol MakeReturnType(Binder bodyBinder, DelegateDeclarationSyntax syntax, DiagnosticBag diagnostics)
 {
     return bodyBinder.BindType(syntax.ReturnType, diagnostics);
 }
 protected override TypeSymbol MakeReturnType(Binder bodyBinder, DelegateDeclarationSyntax syntax, DiagnosticBag diagnostics)
 {
     return(bodyBinder.BindType(syntax.ReturnType, diagnostics));
 }
示例#6
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);
        }