Ejemplo n.º 1
0
        override protected ImmutableArray <LocalSymbol> BuildLocals()
        {
            ExpressionSyntax          expressionSyntax  = TargetExpressionSyntax;
            VariableDeclarationSyntax declarationSyntax = _syntax.Declaration;

            Debug.Assert((expressionSyntax == null) ^ (declarationSyntax == null)); // Can't have both or neither.

            if (expressionSyntax != null)
            {
                var locals = ArrayBuilder <LocalSymbol> .GetInstance();

                ExpressionVariableFinder.FindExpressionVariables(this, locals, expressionSyntax);
                return(locals.ToImmutableAndFree());
            }
            else
            {
                var locals = ArrayBuilder <LocalSymbol> .GetInstance(1);

                {
                    locals.Add(MakeLocal(declarationSyntax, LocalDeclarationKind.UsingVariable));

                    // also gather expression-declared variables from the bracketed argument lists and the initializers
                    ExpressionVariableFinder.FindExpressionVariables(this, locals, declarationSyntax);
                }

                return(locals.ToImmutableAndFree());
            }
        }
Ejemplo n.º 2
0
        protected override ImmutableArray <LocalSymbol> BuildLocals()
        {
            var builder = ArrayBuilder <LocalSymbol> .GetInstance();

            ExpressionVariableFinder.FindExpressionVariables(this, builder, _expressions);
            return(builder.ToImmutableAndFree());
        }
Ejemplo n.º 3
0
        protected override ImmutableArray <LocalSymbol> BuildLocals()
        {
            var builder = ArrayBuilder <LocalSymbol> .GetInstance();

            ExpressionVariableFinder.FindExpressionVariables(this, builder, (CSharpSyntaxNode)ScopeDesignator,
                                                             GetBinder((CSharpSyntaxNode)ScopeDesignator));
            return(builder.ToImmutableAndFree());
        }
Ejemplo n.º 4
0
        override protected ImmutableArray <LocalSymbol> BuildLocals()
        {
            if (_syntax.Declaration != null)
            {
                var locals = new ArrayBuilder <LocalSymbol>(1);
                locals.Add(MakeLocal(_syntax.Declaration, LocalDeclarationKind.FixedVariable));

                // also gather expression-declared variables from the bracketed argument lists and the initializers
                ExpressionVariableFinder.FindExpressionVariables(this, locals, _syntax.Declaration);

                return(locals.ToImmutable());
            }

            return(ImmutableArray <LocalSymbol> .Empty);
        }
Ejemplo n.º 5
0
        override protected ImmutableArray <LocalSymbol> BuildLocals()
        {
            var locals = ArrayBuilder <LocalSymbol> .GetInstance();

            var declarationOpt = _syntax.Declaration;

            if ((declarationOpt != null) && (declarationOpt.Identifier.Kind() != SyntaxKind.None))
            {
                locals.Add(SourceLocalSymbol.MakeLocal(this.ContainingMemberOrLambda, this, RefKind.None, declarationOpt.Type, declarationOpt.Identifier, LocalDeclarationKind.CatchVariable));
            }

            if (_syntax.Filter != null)
            {
                ExpressionVariableFinder.FindExpressionVariables(this, locals, _syntax.Filter.FilterExpression);
            }

            return(locals.ToImmutableAndFree());
        }
Ejemplo n.º 6
0
        override protected ImmutableArray <LocalSymbol> BuildLocals()
        {
            var locals = ArrayBuilder <LocalSymbol> .GetInstance();

            ExpressionSyntax condition;

            switch (_syntax.Kind())
            {
            case SyntaxKind.WhileStatement:
                condition = ((WhileStatementSyntax)_syntax).Condition;
                break;

            case SyntaxKind.DoStatement:
                condition = ((DoStatementSyntax)_syntax).Condition;
                break;

            default:
                throw ExceptionUtilities.UnexpectedValue(_syntax.Kind());
            }

            ExpressionVariableFinder.FindExpressionVariables(this, locals, node: condition);
            return(locals.ToImmutableAndFree());
        }
Ejemplo n.º 7
0
        protected ImmutableArray <LocalSymbol> BuildLocals(SyntaxList <StatementSyntax> statements, Binder enclosingBinder)
        {
#if DEBUG
            Binder currentBinder = enclosingBinder;

            while (true)
            {
                if (this == currentBinder)
                {
                    break;
                }

                currentBinder = currentBinder.Next;
            }
#endif

            ArrayBuilder <LocalSymbol> locals = ArrayBuilder <LocalSymbol> .GetInstance();

            foreach (var statement in statements)
            {
                var innerStatement = statement;

                // drill into any LabeledStatements -- atomic LabelStatements have been bound into
                // wrapped LabeledStatements by this point
                while (innerStatement.Kind() == SyntaxKind.LabeledStatement)
                {
                    innerStatement = ((LabeledStatementSyntax)innerStatement).Statement;
                }

                switch (innerStatement.Kind())
                {
                case SyntaxKind.LocalDeclarationStatement:
                {
                    Binder localDeclarationBinder = enclosingBinder.GetBinder(innerStatement) ?? enclosingBinder;
                    var    decl = (LocalDeclarationStatementSyntax)innerStatement;
                    LocalDeclarationKind kind;
                    if (decl.IsConst)
                    {
                        kind = LocalDeclarationKind.Constant;
                    }
                    else if (decl.UsingKeyword != default(SyntaxToken))
                    {
                        kind = LocalDeclarationKind.UsingVariable;
                    }
                    else if (decl.IsLet)
                    {
                        kind = LocalDeclarationKind.LetVariable;
                    }
                    else
                    {
                        kind = LocalDeclarationKind.RegularVariable;
                    }

                    var localSymbol = MakeLocal(decl.Declaration, kind, localDeclarationBinder);
                    locals.Add(localSymbol);

                    // also gather expression-declared variables from the bracketed argument lists and the initializers
                    ExpressionVariableFinder.FindExpressionVariables(this, locals, decl.Declaration, localDeclarationBinder);
                }
                break;

                case SyntaxKind.ExpressionStatement:
                case SyntaxKind.IfStatement:
                case SyntaxKind.YieldReturnStatement:
                case SyntaxKind.ReturnStatement:
                case SyntaxKind.ThrowStatement:
                    ExpressionVariableFinder.FindExpressionVariables(this, locals, innerStatement, enclosingBinder.GetBinder(innerStatement) ?? enclosingBinder);
                    break;

                case SyntaxKind.SwitchStatement:
                    var switchStatement = (SwitchStatementSyntax)innerStatement;
                    ExpressionVariableFinder.FindExpressionVariables(this, locals, innerStatement, enclosingBinder.GetBinder(switchStatement.Expression) ?? enclosingBinder);
                    break;

                case SyntaxKind.LockStatement:
                    Binder statementBinder = enclosingBinder.GetBinder(innerStatement);
                    Debug.Assert(statementBinder != null);     // Lock always has a binder.
                    ExpressionVariableFinder.FindExpressionVariables(this, locals, innerStatement, statementBinder);
                    break;

                default:
                    // no other statement introduces local variables into the enclosing scope
                    break;
                }
            }

            return(locals.ToImmutableAndFree());
        }