Beispiel #1
0
    public static void LookupSymbolsSimpleName(
        this Microsoft.CodeAnalysis.CSharp.Binder binder,
        LookupResult result,
        NamespaceOrTypeSymbol qualifierOpt,
        string plainName,
        int arity,
        ConsList <TypeSymbol> basesBeingResolved,
        LookupOptions options,
        bool diagnose,
        ref HashSet <DiagnosticInfo> useSiteDiagnostics
        )
    {
        CompoundUseSiteInfo <AssemblySymbol> useSiteInfo = default;

        binder.LookupSymbolsSimpleName(
            result,
            qualifierOpt,
            plainName,
            arity,
            basesBeingResolved,
            options,
            diagnose,
            ref useSiteInfo
            );
        AddDiagnosticInfos(ref useSiteDiagnostics, useSiteInfo);
    }
Beispiel #2
0
        internal void CollectLocalsFromDeconstruction(
            ExpressionSyntax declaration,
            LocalDeclarationKind kind,
            ArrayBuilder<LocalSymbol> locals,
            SyntaxNode deconstructionStatement,
            Binder enclosingBinderOpt = null)
        {
            switch (declaration.Kind())
            {
                case SyntaxKind.TupleExpression:
                    {
                        var tuple = (TupleExpressionSyntax)declaration;
                        foreach (var arg in tuple.Arguments)
                        {
                            CollectLocalsFromDeconstruction(arg.Expression, kind, locals, deconstructionStatement, enclosingBinderOpt);
                        }
                        break;
                    }
                case SyntaxKind.DeclarationExpression:
                    {
                        var declarationExpression = (DeclarationExpressionSyntax)declaration;
                        CollectLocalsFromDeconstruction(
                            declarationExpression.Designation, declarationExpression.Type,
                            kind, locals, deconstructionStatement, enclosingBinderOpt);

                        break;
                    }
                case SyntaxKind.IdentifierName:
                    break;
                default:
                    // In broken code, we can have an arbitrary expression here. Collect its expression variables.
                    ExpressionVariableFinder.FindExpressionVariables(this, locals, declaration);
                    break;
            }
        }
        internal void CollectLocalsFromDeconstruction(
            ExpressionSyntax declaration,
            LocalDeclarationKind kind,
            ArrayBuilder<LocalSymbol> locals,
            SyntaxNode deconstructionStatement,
            Binder enclosingBinderOpt = null)
        {
            switch (declaration.Kind())
            {
                case SyntaxKind.TupleExpression:
                    {
                        var tuple = (TupleExpressionSyntax)declaration;
                        foreach (var arg in tuple.Arguments)
                        {
                            CollectLocalsFromDeconstruction(arg.Expression, kind, locals, deconstructionStatement, enclosingBinderOpt);
                        }
                        break;
                    }
                case SyntaxKind.DeclarationExpression:
                    {
                        var declarationExpression = (DeclarationExpressionSyntax)declaration;
                        CollectLocalsFromDeconstruction(
                            declarationExpression.Designation, declarationExpression.Type,
                            kind, locals, deconstructionStatement, enclosingBinderOpt);

                        break;
                    }
                case SyntaxKind.IdentifierName:
                    break;
                default:
                    throw ExceptionUtilities.UnexpectedValue(declaration.Kind());
            }
        }
 public QueryUnboundLambdaState(Binder binder, RangeVariableMap rangeVariableMap, ImmutableArray<RangeVariableSymbol> parameters, LambdaBodyFactory bodyFactory)
     : base(binder, unboundLambdaOpt: null)
 {
     _parameters = parameters;
     _rangeVariableMap = rangeVariableMap;
     _bodyFactory = bodyFactory;
 }
        internal override BoundStatement BindLockStatementParts(DiagnosticBag diagnostics, Binder originalBinder)
        {
            // Allow method groups during binding and then rule them out when we check that the expression has
            // a reference type.
            ExpressionSyntax exprSyntax = TargetExpressionSyntax;
            BoundExpression expr = BindTargetExpression(diagnostics);
            TypeSymbol exprType = expr.Type;

            bool hasErrors = false;

            if ((object)exprType == null)
            {
                if (expr.ConstantValue != ConstantValue.Null || Compilation.FeatureStrictEnabled) // Dev10 allows the null literal.
                {
                    Error(diagnostics, ErrorCode.ERR_LockNeedsReference, exprSyntax, expr.Display);
                    hasErrors = true;
                }
            }
            else if (!exprType.IsReferenceType && (exprType.IsValueType || Compilation.FeatureStrictEnabled))
            {
                Error(diagnostics, ErrorCode.ERR_LockNeedsReference, exprSyntax, exprType);
                hasErrors = true;
            }

            BoundStatement stmt = originalBinder.BindPossibleEmbeddedStatement(_syntax.Statement, diagnostics);
            Debug.Assert(this.Locals.IsDefaultOrEmpty);
            return new BoundLockStatement(_syntax, expr, stmt, hasErrors);
        }
Beispiel #6
0
 internal ExecutableCodeBinder(CSharpSyntaxNode root, Symbol memberSymbol, Binder next, BinderFlags additionalFlags)
     : base(next, (next.Flags | additionalFlags) & ~BinderFlags.AllClearedAtExecutableCodeBoundary)
 {
     this.memberSymbol = memberSymbol;
     this.root = root;
     this.owner = memberSymbol as MethodSymbol;
 }
Beispiel #7
0
            internal BinderWithConditionalReceiver(Binder next, BoundExpression receiverExpression)
                : base(next)
            {
                Debug.Assert(receiverExpression != null);

                _receiverExpression = receiverExpression;
            }
 public WithConstructorInitializerLocalsBinder(Binder enclosing, ConstructorDeclarationSyntax declaration)
     : base(enclosing, enclosing.Flags)
 {
     Debug.Assert(declaration.Initializer != null);
     this.scope = declaration;
     this.initializerArgumentList = declaration.Initializer.ArgumentList;
 }
Beispiel #9
0
        public BoundLambda(CSharpSyntaxNode syntax, BoundBlock body, ImmutableArray<Diagnostic> diagnostics, Binder binder, TypeSymbol delegateType, bool inferReturnType)
            : this(syntax, (LambdaSymbol)binder.ContainingMemberOrLambda, body, diagnostics, binder, delegateType)
        {
            if (inferReturnType)
            {
                this._inferredReturnType = InferReturnType(
                    this.Body,
                    this.Binder,
                    delegateType,
                    this.Symbol.IsAsync,
                    ref this._inferredReturnTypeUseSiteDiagnostics,
                    out this._refKind,
                    out this._inferredFromSingleType);

#if DEBUG
                _hasInferredReturnType = true;
#endif
            }

            Debug.Assert(
                syntax.IsAnonymousFunction() ||                                                                 // lambda expressions
                syntax is ExpressionSyntax && LambdaUtilities.IsLambdaBody(syntax, allowReducedLambdas: true) || // query lambdas
                LambdaUtilities.IsQueryPairLambda(syntax)                                                       // "pair" lambdas in queries
            );
        }
Beispiel #10
0
        private BoundForStatement BindForParts(ForStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
        {
            BoundStatement initializer;
            if (node.Declaration != null)
            {
                Debug.Assert(node.Initializers.Count == 0);
                if (node.Declaration.IsDeconstructionDeclaration)
                {
                    initializer = originalBinder.BindDeconstructionDeclaration(node.Declaration, node.Declaration, diagnostics);
                }
                else
                {
                    ImmutableArray<BoundLocalDeclaration> unused;
                    initializer = originalBinder.BindForOrUsingOrFixedDeclarations(node.Declaration, LocalDeclarationKind.ForInitializerVariable, diagnostics, out unused);
                }
            }
            else
            {
                initializer = originalBinder.BindStatementExpressionList(node.Initializers, diagnostics);
            }

            var condition = (node.Condition != null) ? originalBinder.BindBooleanExpression(node.Condition, diagnostics) : null;
            var increment = originalBinder.BindStatementExpressionList(node.Incrementors, diagnostics);
            var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);

            Debug.Assert(this.Locals == this.GetDeclaredLocalsForScope(node));
            return new BoundForStatement(node,
                                         this.Locals,
                                         initializer,
                                         condition,
                                         increment,
                                         body,
                                         this.BreakLabel,
                                         this.ContinueLabel);
        }
 public WithConstructorInitializerLocalsBinder(Binder enclosing, ArgumentListSyntax initializerArgumentList)
     : base(enclosing, enclosing.Flags)
 {
     Debug.Assert(initializerArgumentList != null);
     this.scope = initializerArgumentList;
     this.initializerArgumentList = initializerArgumentList;
 }
Beispiel #12
0
 internal Binder(Binder next)
 {
     Debug.Assert(next != null);
     _next = next;
     this.Flags = next.Flags;
     this.Compilation = next.Compilation;
 }
Beispiel #13
0
 public static SmallDictionary<CSharpSyntaxNode, Binder> BuildMap(MethodSymbol method, CSharpSyntaxNode syntax, Binder enclosing, out bool sawYield)
 {
     var builder = new LocalBinderFactory(method, enclosing);
     builder.Visit(syntax);
     sawYield = builder._sawYield;
     return builder._map;
 }
Beispiel #14
0
 private LocalBinderFactory(MethodSymbol method, Binder enclosing)
 {
     Debug.Assert((object)method != null);
     _map = new SmallDictionary<CSharpSyntaxNode, Binder>(ReferenceEqualityComparer.Instance);
     _method = method;
     _enclosing = enclosing;
 }
 public QueryUnboundLambdaState(UnboundLambda unbound, Binder binder, RangeVariableMap rangeVariableMap, ImmutableArray<RangeVariableSymbol> parameters, ExpressionSyntax body)
     : this(unbound, binder, rangeVariableMap, parameters, (LambdaSymbol lambdaSymbol, ExecutableCodeBinder lambdaBodyBinder, DiagnosticBag diagnostics) =>
 {
     BoundExpression expression = lambdaBodyBinder.BindValue(body, diagnostics, BindValueKind.RValue);
     return lambdaBodyBinder.WrapExpressionLambdaBody(expression, body, diagnostics);
 })
 { }
        protected override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.MustBeInvocableIfMember)) != 0)
            {
                return;
            }

            Debug.Assert(result.IsClear);

            var count = parameterMap.GetCountForKey(name);
            if (count == 1)
            {
                ParameterSymbol p;
                parameterMap.TryGetSingleValue(name, out p);
                result.MergeEqual(originalBinder.CheckViability(p, arity, options, null, diagnose, ref useSiteDiagnostics));
            }
            else if (count > 1)
            {
                var parameters = parameterMap[name];
                foreach (var sym in parameters)
                {
                    result.MergeEqual(originalBinder.CheckViability(sym, arity, options, null, diagnose, ref useSiteDiagnostics));
                }
            }
        }
 public QueryUnboundLambdaState(UnboundLambda unbound, Binder binder, RangeVariableMap rangeVariableMap, ImmutableArray<RangeVariableSymbol> parameters, LambdaBodyResolver bodyResolver)
     : base(unbound, binder)
 {
     this.parameters = parameters;
     this.bodyResolver = bodyResolver;
     this.rangeVariableMap = rangeVariableMap;
 }
        internal WithPrimaryConstructorParametersBinder(MethodSymbol primaryCtor, Binder next)
            : base(next)
        {
            Debug.Assert((object)primaryCtor != null);
            this.primaryCtor = primaryCtor;
            var parameters = primaryCtor.Parameters;

            var definitionMap = new SmallDictionary<string, ParameterSymbol>();

            for (int i = parameters.Length - 1; i >= 0; i--)
            {
                var parameter = parameters[i];
                definitionMap[parameter.Name] = parameter;
            }

            this.definitionMap = definitionMap;

            var parameterMap = new MultiDictionary<string, ParameterSymbol>(parameters.Length, EqualityComparer<string>.Default);

            foreach (var parameter in parameters)
            {
                parameterMap.Add(parameter.Name, parameter);
            }

            this.parameterMap = parameterMap;
        }
Beispiel #19
0
            internal BinderWithContainingMemberOrLambda(Binder next, BinderFlags flags, Symbol containingMemberOrLambda)
                : base(next, flags)
            {
                Debug.Assert(containingMemberOrLambda != null);

                _containingMemberOrLambda = containingMemberOrLambda;
            }
 public QueryUnboundLambdaState(UnboundLambda unbound, Binder binder, RangeVariableMap rangeVariableMap, ImmutableArray<RangeVariableSymbol> parameters, ExpressionSyntax body)
     : this(unbound, binder, rangeVariableMap, parameters, (LambdaSymbol lambdaSymbol, ref Binder lambdaBodyBinder, DiagnosticBag diagnostics) =>
 {
     lambdaBodyBinder = new ScopedExpressionBinder(lambdaBodyBinder, body);
     return lambdaBodyBinder.BindLambdaExpressionAsBlock(body, diagnostics);
 })
 { }
 private MethodBodySemanticModel(CSharpCompilation compilation, Symbol owner, Binder rootBinder, CSharpSyntaxNode syntax, SyntaxTreeSemanticModel parentSemanticModelOpt = null, int speculatedPosition = 0)
     : base(compilation, syntax, owner, rootBinder, parentSemanticModelOpt, speculatedPosition)
 {
     Debug.Assert((object)owner != null);
     Debug.Assert(owner.Kind == SymbolKind.Method);
     Debug.Assert(syntax != null);
     Debug.Assert(owner.ContainingType.IsScriptClass || syntax.Kind != SyntaxKind.CompilationUnit);
 }
 public BoundDiscardExpression FailInference(Binder binder, DiagnosticBag diagnosticsOpt)
 {
     if (diagnosticsOpt != null)
     {
         Binder.Error(diagnosticsOpt, ErrorCode.ERR_DiscardTypeInferenceFailed, this.Syntax);
     }
     return this.Update(binder.CreateErrorType("var"));
 }
        internal LockOrUsingStatementExpressionHandler(ExpressionSyntax expressionSyntax, Binder binder)
        {
            Debug.Assert(expressionSyntax != null);
            Debug.Assert(binder != null);

            this.expressionSyntax = expressionSyntax;
            this.binder = binder;
        }
        /// <summary>
        /// Creates a binder with given imports.
        /// </summary>
        internal InContainerBinder(NamespaceOrTypeSymbol container, Binder next, Imports imports = null)
            : base(next)
        {
            Debug.Assert((object)container != null);

            _container = container;
            _imports = imports ?? Imports.Empty;
        }
        /// <summary>
        /// Creates a speculative AttributeSemanticModel that allows asking semantic questions about an attribute node that did not appear in the original source code.
        /// </summary>
        public static AttributeSemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, AttributeSyntax syntax, NamedTypeSymbol attributeType, AliasSymbol aliasOpt, Binder rootBinder, int position)
        {
            Debug.Assert(parentSemanticModel != null);
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            return new AttributeSemanticModel(parentSemanticModel.Compilation, syntax, attributeType, aliasOpt, rootBinder, parentSemanticModel, position);
        }
Beispiel #26
0
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     var hostObjectType = GetHostObjectType();
     if (hostObjectType.Kind != SymbolKind.ErrorType)
     {
         AddMemberLookupSymbolsInfo(result, hostObjectType, options, originalBinder);
     }
 }
 internal override BoundNode Bind(Binder binder, CSharpSyntaxNode node, DiagnosticBag diagnostics)
 {
     if (node.Kind() == SyntaxKind.ArrowExpressionClause)
     {
         return binder.BindExpressionBodyAsBlock((ArrowExpressionClauseSyntax)node, diagnostics);
     }
     return base.Bind(binder, node, diagnostics);
 }
Beispiel #28
0
        /// <summary>
        /// Creates a binder with given import computation function.
        /// </summary>
        internal InContainerBinder(Binder next, Func<ConsList<Symbol>, Imports> computeImports)
            : base(next)
        {
            Debug.Assert(computeImports != null);

            _container = null;
            _computeImports = computeImports;
        }
        internal override BoundDoStatement BindDoParts(DiagnosticBag diagnostics, Binder originalBinder)
        {
            var node = (DoStatementSyntax)syntax;

            var condition = BindBooleanExpression(node.Condition, diagnostics);
            var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);
            return new BoundDoStatement(node, this.Locals, condition, body, this.BreakLabel, this.ContinueLabel);
        }
Beispiel #30
0
 internal TypeofBinder(ExpressionSyntax typeExpression, Binder next)
     // Unsafe types are not unsafe in typeof, so it is effectively an unsafe region.
     // Since we only depend on existence of nameable members and nameof(x) produces a constant
     // string expression usable in an early attribute, we use early attribute binding.
     : base(next, next.Flags | BinderFlags.UnsafeRegion | BinderFlags.EarlyAttributeBinding)
 {
     OpenTypeVisitor.Visit(typeExpression, out _allowedMap, out _isTypeExpressionOpen);
 }
Beispiel #31
0
        protected override void AddLookupSymbolsInfoInSingleBinder(
            LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            // Add types within namespaces imported through usings, but don't add nested namespaces.
            LookupOptions usingOptions = (options & ~(LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly)) | LookupOptions.MustNotBeNamespace;

            Imports.AddLookupSymbolsInfoInUsings(ConsolidatedUsings, this, result, usingOptions);
        }
Beispiel #32
0
 public static BoundExpression BindExpression(
     this Microsoft.CodeAnalysis.CSharp.Binder binder,
     ExpressionSyntax node,
     DiagnosticBag diagnostics
     )
 {
     return(binder.BindExpression(
                node,
                new Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag(diagnostics)
                ));
 }
Beispiel #33
0
 public static BoundBlock BindEmbeddedBlock(
     this Microsoft.CodeAnalysis.CSharp.Binder binder,
     BlockSyntax node,
     DiagnosticBag diagnostics
     )
 {
     return(binder.BindEmbeddedBlock(
                node,
                new Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag(diagnostics)
                ));
 }
Beispiel #34
0
 public static ImmutableArray <Symbol> BindCref(
     this Microsoft.CodeAnalysis.CSharp.Binder binder,
     CrefSyntax syntax,
     out Symbol ambiguityWinner,
     DiagnosticBag diagnostics
     )
 {
     return(binder.BindCref(
                syntax,
                out ambiguityWinner,
                new Microsoft.CodeAnalysis.CSharp.BindingDiagnosticBag(diagnostics)
                ));
 }
Beispiel #35
0
        private static void AddLookupSymbolsInfoInUsings(
            ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            if (originalBinder.Flags.Includes(BinderFlags.InScriptUsing))
            {
                return;
            }

            Debug.Assert(!options.CanConsiderNamespaces());

            // look in all using namespaces
            foreach (var namespaceSymbol in usings)
            {
                foreach (var member in namespaceSymbol.NamespaceOrType.GetMembersUnordered())
                {
                    if (IsValidLookupCandidateInUsings(member) && originalBinder.CanAddLookupSymbolInfo(member, options, result, null))
                    {
                        result.AddSymbol(member, member.Name, member.GetArity());
                    }
                }
            }
        }
Beispiel #36
0
        internal void LookupExtensionMethodsInUsings(
            ArrayBuilder <MethodSymbol> methods,
            string name,
            int arity,
            LookupOptions options,
            Binder originalBinder
            )
        {
            var binderFlags = originalBinder.Flags;

            if (binderFlags.Includes(BinderFlags.InScriptUsing))
            {
                return;
            }

            Debug.Assert(methods.Count == 0);

            bool callerIsSemanticModel = binderFlags.Includes(BinderFlags.SemanticModel);

            // We need to avoid collecting multiple candidates for an extension method imported both through a namespace and a static class
            // We will look for duplicates only if both of the following flags are set to true
            bool seenNamespaceWithExtensionMethods   = false;
            bool seenStaticClassWithExtensionMethods = false;

            foreach (var nsOrType in this.Usings)
            {
                switch (nsOrType.NamespaceOrType.Kind)
                {
                case SymbolKind.Namespace:
                {
                    var count = methods.Count;
                    ((NamespaceSymbol)nsOrType.NamespaceOrType).GetExtensionMethods(
                        methods,
                        name,
                        arity,
                        options
                        );

                    // If we found any extension methods, then consider this using as used.
                    if (methods.Count != count)
                    {
                        MarkImportDirective(nsOrType.UsingDirective, callerIsSemanticModel);
                        seenNamespaceWithExtensionMethods = true;
                    }
                    break;
                }

                case SymbolKind.NamedType:
                {
                    var count = methods.Count;
                    ((NamedTypeSymbol)nsOrType.NamespaceOrType).GetExtensionMethods(
                        methods,
                        name,
                        arity,
                        options
                        );

                    // If we found any extension methods, then consider this using as used.
                    if (methods.Count != count)
                    {
                        MarkImportDirective(nsOrType.UsingDirective, callerIsSemanticModel);
                        seenStaticClassWithExtensionMethods = true;
                    }
                    break;
                }
                }
            }

            if (seenNamespaceWithExtensionMethods && seenStaticClassWithExtensionMethods)
            {
                methods.RemoveDuplicates();
            }
        }
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     if (options.CanConsiderLocals())
     {
         foreach (var parameter in _parameters)
         {
             if (originalBinder.CanAddLookupSymbolInfo(parameter, options, result, null))
             {
                 result.AddSymbol(parameter, parameter.Name, 0);
             }
         }
     }
 }
Beispiel #38
0
 internal override BoundStatement BindForEachDeconstruction(DiagnosticBag diagnostics, Binder originalBinder)
 {
     // There's supposed to be a ForEachLoopBinder (or other overrider of this method) in the chain.
     throw ExceptionUtilities.Unreachable;
 }
Beispiel #39
0
 protected abstract BoundBlock BindLambdaBody(LambdaSymbol lambdaSymbol, ref Binder lambdaBodyBinder, DiagnosticBag diagnostics);
Beispiel #40
0
        public BoundLambda(CSharpSyntaxNode syntax, BoundBlock body, ImmutableArray <Diagnostic> diagnostics, Binder binder, TypeSymbol type, bool inferReturnType)
            : this(syntax, (LambdaSymbol)binder.ContainingMemberOrLambda, body, diagnostics, binder, type)
        {
            if (inferReturnType)
            {
                _inferredReturnType = InferReturnType(this.Body, this.Binder, this.Symbol.IsAsync, ref _inferredReturnTypeUseSiteDiagnostics, out _inferredFromSingleType);

#if DEBUG
                _hasInferredReturnType = true;
#endif
            }

            Debug.Assert(
                syntax.IsAnonymousFunction() ||                                                 // lambda expressions
                syntax is ExpressionSyntax && LambdaUtilities.IsLambdaBody(syntax) ||           // query lambdas
                LambdaUtilities.IsQueryPairLambda(syntax)                                       // "pair" lambdas in queries
                );
        }
Beispiel #41
0
        internal void AddLookupSymbolsInfoInAliases(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            foreach (var(_, usingAlias) in this.UsingAliases)
            {
                AddAliasSymbolToResult(result, usingAlias.Alias, options, originalBinder);
            }

            foreach (var externAlias in this.ExternAliases)
            {
                AddAliasSymbolToResult(result, externAlias.Alias, options, originalBinder);
            }
        }
Beispiel #42
0
        /// <summary>
        /// Creates a speculative AttributeSemanticModel that allows asking semantic questions about an attribute node that did not appear in the original source code.
        /// </summary>
        public static AttributeSemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, AttributeSyntax syntax, NamedTypeSymbol attributeType, AliasSymbol aliasOpt, Binder rootBinder, int position)
        {
            Debug.Assert(parentSemanticModel != null);
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            return(new AttributeSemanticModel(syntax, attributeType, aliasOpt, rootBinder, parentSemanticModelOpt: parentSemanticModel, speculatedPosition: position));
        }
 /// <summary>
 /// Creates a speculative SemanticModel for a TypeSyntax node at a position within an existing MemberSemanticModel.
 /// </summary>
 public SpeculativeMemberSemanticModel(SyntaxTreeSemanticModel parentSemanticModel, Symbol owner, TypeSyntax root, Binder rootBinder, int position)
     : base(root, owner, rootBinder, containingSemanticModelOpt: null, parentSemanticModelOpt: parentSemanticModel, speculatedPosition: position)
 {
 }
Beispiel #44
0
        private Binder XSLookupSymbolsInternal(
            LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics)
        {
            Debug.Assert(result.IsClear);
            Debug.Assert(options.AreValid());

            // X# looks for functions first
            //if (Compilation.Options.HasRuntime)
            {
                // check for function calls method calls outside the current class
                bool check = (options.HasFlag(LookupOptions.MustNotBeInstance) && !options.HasFlag(LookupOptions.MustNotBeMethod));
                if (check)
                {
                    var funcOptions = options;
                    funcOptions |= LookupOptions.MustBeInvocableIfMember;
                    Binder scope = this;
                    while (scope != null)
                    {
                        if (scope is InContainerBinder && scope.ContainingType == null) // at the namespace level, so outside of all types
                        {
                            scope.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, funcOptions, this, diagnose, ref useSiteDiagnostics);
                            FilterResults(result, options);
                            if (!result.IsClear)
                            {
                                break;
                            }
                        }
                        scope = scope.Next;
                    }
                }
            }
            LookupResult functionResults = LookupResult.GetInstance();

            if (!result.IsClear)
            {
                foreach (var symbol in result.Symbols)
                {
                    if (symbol is MethodSymbol)
                    {
                        var ms = symbol as MethodSymbol;
                        if (ms.IsStatic && ms.ContainingType.Name.EndsWith("Functions", XSharpString.Comparison))
                        {
                            SingleLookupResult single = new SingleLookupResult(LookupResultKind.Viable, ms, null);
                            functionResults.MergeEqual(single);
                        }
                    }
                }
                result.Clear();
            }
            Binder binder = null;

            for (var scope = this; scope != null && !result.IsMultiViable; scope = scope.Next)
            {
                if (binder != null)
                {
                    var tmp = LookupResult.GetInstance();
                    scope.LookupSymbolsInSingleBinder(tmp, name, arity, basesBeingResolved, options, this, diagnose, ref useSiteDiagnostics);
                    FilterResults(tmp, options);
                    result.MergeEqual(tmp);
                    tmp.Free();
                }
                else
                {
                    scope.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, this, diagnose, ref useSiteDiagnostics);
                    FilterResults(result, options);
                    if (!result.IsClear)
                    {
                        binder = scope;
                    }
                }
            }
            if (!functionResults.IsClear)
            {
                // compare the function results with the overall results found
                // create a list of functions and methods
                // function first and then the methods
                LookupResult mergedResults = LookupResult.GetInstance();
                mergedResults.MergeEqual(functionResults);
                // now add the symbols from result that do not exist
                for (int j = 0; j < result.Symbols.Count; j++)
                {
                    var sym   = result.Symbols[j];
                    var found = false;
                    for (int i = 0; i < mergedResults.Symbols.Count; i++)
                    {
                        if (sym == mergedResults.Symbols[i])
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        SingleLookupResult single = new SingleLookupResult(LookupResultKind.Viable, sym, null);
                        mergedResults.MergeEqual(single);
                    }
                }
                result.Clear();
                result.MergeEqual(mergedResults);
            }
            // C563 Make sure the error is generated for Inaccessible types.
            if (!result.IsClear && result.Kind == LookupResultKind.Inaccessible && result.Error != null)
            {
                // we only want to add this for internal fields (globals)
                if (result.Symbols[0].Kind == SymbolKind.Field)
                {
                    if (useSiteDiagnostics == null)
                    {
                        useSiteDiagnostics = new HashSet <DiagnosticInfo>();
                    }
                    useSiteDiagnostics.Add(result.Error);
                }
            }
            return(binder);
        }
Beispiel #45
0
 internal override BoundExpression BindSwitchExpressionCore(SwitchExpressionSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
 {
     // There's supposed to be a SwitchExpressionBinder (or other overrider of this method) in the chain.
     throw ExceptionUtilities.Unreachable;
 }
        /// <summary>
        /// Creates a SemanticModel that creates and owns the ExecutableCodeBinder for the method of which it is a model.
        /// </summary>
        internal static MethodBodySemanticModel Create(CSharpCompilation compilation, MethodSymbol owner, Binder rootBinder, CSharpSyntaxNode syntax)
        {
            var executableCodeBinder = new ExecutableCodeBinder(syntax, owner, rootBinder);

            return(new MethodBodySemanticModel(compilation, owner, executableCodeBinder, syntax));
        }
 internal WithParametersBinder(ImmutableArray <ParameterSymbol> parameters, Binder next)
     : base(next)
 {
     Debug.Assert(!parameters.IsDefaultOrEmpty);
     _parameters = parameters;
 }
Beispiel #48
0
        internal void LookupSymbolInAliases(
            Binder originalBinder,
            LookupResult result,
            string name,
            int arity,
            ConsList <TypeSymbol> basesBeingResolved,
            LookupOptions options,
            bool diagnose,
            ref CompoundUseSiteInfo <AssemblySymbol> useSiteInfo
            )
        {
            bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder;

            AliasAndUsingDirective alias;

            if (this.UsingAliases.TryGetValue(name, out alias))
            {
                // Found a match in our list of normal aliases.  Mark the alias as being seen so that
                // it won't be reported to the user as something that can be removed.
                var res = originalBinder.CheckViability(
                    alias.Alias,
                    arity,
                    options,
                    null,
                    diagnose,
                    ref useSiteInfo,
                    basesBeingResolved
                    );
                if (res.Kind == LookupResultKind.Viable)
                {
                    MarkImportDirective(alias.UsingDirective, callerIsSemanticModel);
                }

                result.MergeEqual(res);
            }

            foreach (var a in this.ExternAliases)
            {
                if (a.Alias.Name == name)
                {
                    // Found a match in our list of extern aliases.  Mark the extern alias as being
                    // seen so that it won't be reported to the user as something that can be
                    // removed.
                    var res = originalBinder.CheckViability(
                        a.Alias,
                        arity,
                        options,
                        null,
                        diagnose,
                        ref useSiteInfo,
                        basesBeingResolved
                        );
                    if (res.Kind == LookupResultKind.Viable)
                    {
                        MarkImportDirective(a.ExternAliasDirective, callerIsSemanticModel);
                    }

                    result.MergeEqual(res);
                }
            }
        }
Beispiel #49
0
        private static void AddAliasSymbolToResult(LookupSymbolsInfo result, AliasSymbol aliasSymbol, LookupOptions options, Binder originalBinder)
        {
            var targetSymbol = aliasSymbol.GetAliasTarget(basesBeingResolved: null);

            if (originalBinder.CanAddLookupSymbolInfo(targetSymbol, options, result, accessThroughType: null, aliasSymbol: aliasSymbol))
            {
                result.AddSymbol(aliasSymbol, aliasSymbol.Name, 0);
            }
        }
Beispiel #50
0
 private Conversions(Binder binder, int currentRecursionDepth, bool includeNullability, Conversions otherNullabilityOpt)
     : base(binder.Compilation.Assembly.CorLibrary, currentRecursionDepth, includeNullability, otherNullabilityOpt)
 {
     _binder = binder;
 }
Beispiel #51
0
 public virtual Binder ParameterBinder(LambdaSymbol lambdaSymbol, Binder binder)
 {
     return(new WithLambdaParametersBinder(lambdaSymbol, binder));
 }
Beispiel #52
0
 public Conversions(Binder binder)
     : this(binder, currentRecursionDepth : 0, includeNullability : false, otherNullabilityOpt : null)
 {
 }
Beispiel #53
0
        // Note: we do not mark nodes when looking up arities or names.  This is because these two
        // types of lookup are only around to make the public
        // SemanticModel.LookupNames/LookupSymbols work and do not count as usages of the directives
        // when the actual code is bound.

        internal void AddLookupSymbolsInfo(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            AddLookupSymbolsInfoInAliases(result, options, originalBinder);

            // Add types within namespaces imported through usings, but don't add nested namespaces.
            LookupOptions usingOptions = (options & ~(LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly)) | LookupOptions.MustNotBeNamespace;

            AddLookupSymbolsInfoInUsings(this.Usings, result, usingOptions, originalBinder);
        }
        internal override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList <TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.MustBeInvocableIfMember)) != 0)
            {
                return;
            }

            Debug.Assert(result.IsClear);

            foreach (ParameterSymbol parameter in _parameters)
            {
                if (parameter.Name == name)
                {
                    result.MergeEqual(originalBinder.CheckViability(parameter, arity, options, null, diagnose, ref useSiteDiagnostics));
                }
            }
        }
 internal LockOrUsingBinder(Binder enclosing)
     : base(enclosing)
 {
 }
Beispiel #56
0
 internal override BoundStatement BindLockStatementParts(DiagnosticBag diagnostics, Binder originalBinder)
 {
     // There's supposed to be a LockBinder (or other overrider of this method) in the chain.
     throw ExceptionUtilities.Unreachable;
 }
        /// <summary>
        /// Creates a speculative SemanticModel for an expression body that did not appear in the original source code.
        /// </summary>
        internal static MethodBodySemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, MethodSymbol owner, ArrowExpressionClauseSyntax syntax, Binder rootBinder, int position)
        {
            Debug.Assert(parentSemanticModel != null);
            Debug.Assert(syntax != null);
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            return(new MethodBodySemanticModel(parentSemanticModel.Compilation, owner, rootBinder, syntax, parentSemanticModel, position));
        }
 internal LocalInProgressBinder(LocalSymbol inProgress, Binder next)
     : base(next)
 {
     this.inProgress = inProgress;
 }
Beispiel #59
0
 private static MethodGroupResolution ResolveDelegateOrFunctionPointerMethodGroup(Binder binder, BoundMethodGroup source, MethodSymbol delegateInvokeMethodOpt, bool isFunctionPointer, in CallingConventionInfo callingConventionInfo, ref CompoundUseSiteInfo <AssemblySymbol> useSiteInfo)
Beispiel #60
0
 /// <summary>
 /// Creates an AttributeSemanticModel that allows asking semantic questions about an attribute node.
 /// </summary>
 public static AttributeSemanticModel Create(SyntaxTreeSemanticModel containingSemanticModel, AttributeSyntax syntax, NamedTypeSymbol attributeType, AliasSymbol aliasOpt, Binder rootBinder)
 {
     return(new AttributeSemanticModel(syntax, attributeType, aliasOpt, rootBinder, containingSemanticModel));
 }