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(declarationSyntax.Variables.Count); foreach (VariableDeclaratorSyntax declarator in declarationSyntax.Variables) { locals.Add(MakeLocal(declarationSyntax, declarator, LocalDeclarationKind.UsingVariable)); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, declarator); } return(locals.ToImmutableAndFree()); } }
protected override ImmutableArray <LocalSymbol> BuildLocals() { var builder = ArrayBuilder <LocalSymbol> .GetInstance(); ExpressionVariableFinder.FindExpressionVariables(this, builder, _expressions); return(builder.ToImmutableAndFree()); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { var locals = ArrayBuilder <LocalSymbol> .GetInstance(); // Declaration and Initializers are mutually exclusive. if (_syntax.Declaration != null) { _syntax.Declaration.Type.VisitRankSpecifiers((rankSpecifier, args) => { foreach (var size in rankSpecifier.Sizes) { if (size.Kind() != SyntaxKind.OmittedArraySizeExpression) { ExpressionVariableFinder.FindExpressionVariables(args.binder, args.locals, size); } } }, (binder: this, locals: locals)); foreach (var vdecl in _syntax.Declaration.Variables) { var localSymbol = MakeLocal(_syntax.Declaration, vdecl, LocalDeclarationKind.RegularVariable); locals.Add(localSymbol); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, vdecl); } } else { ExpressionVariableFinder.FindExpressionVariables(this, locals, _syntax.Initializers); } return(locals.ToImmutableAndFree()); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { if (_syntax.Declaration != null) { var locals = new ArrayBuilder <LocalSymbol>(_syntax.Declaration.Variables.Count); _syntax.Declaration.Type.VisitRankSpecifiers((rankSpecifier, args) => { foreach (var size in rankSpecifier.Sizes) { if (size.Kind() != SyntaxKind.OmittedArraySizeExpression) { ExpressionVariableFinder.FindExpressionVariables(args.binder, args.locals, size); } } }, (binder: this, locals: locals)); foreach (VariableDeclaratorSyntax declarator in _syntax.Declaration.Variables) { locals.Add(MakeLocal(_syntax.Declaration, declarator, LocalDeclarationKind.FixedVariable)); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, declarator); } return(locals.ToImmutable()); } return(ImmutableArray <LocalSymbol> .Empty); }
protected override 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, false, declarationOpt.Type, declarationOpt.Identifier, LocalDeclarationKind.CatchVariable ) ); } if (_syntax.Filter != null) { ExpressionVariableFinder.FindExpressionVariables( this, locals, _syntax.Filter.FilterExpression ); } return locals.ToImmutableAndFree(); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { var locals = ArrayBuilder <LocalSymbol> .GetInstance(); // Deconstruction, Declaration, and Initializers are mutually exclusive. if (_syntax.Deconstruction != null) { CollectLocalsFromDeconstruction( _syntax.Deconstruction.VariableComponent, LocalDeclarationKind.ForInitializerVariable, locals, _syntax); ExpressionVariableFinder.FindExpressionVariables(this, locals, _syntax.Deconstruction.Value); } else if (_syntax.Declaration != null) { foreach (var vdecl in _syntax.Declaration.Variables) { var localSymbol = MakeLocal(_syntax.Declaration, vdecl, LocalDeclarationKind.ForInitializerVariable); locals.Add(localSymbol); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, vdecl); } } else { ExpressionVariableFinder.FindExpressionVariables(this, locals, _syntax.Initializers); } ExpressionVariableFinder.FindExpressionVariables(this, locals, node: _syntax.Condition); ExpressionVariableFinder.FindExpressionVariables(this, locals, _syntax.Incrementors); return(locals.ToImmutableAndFree()); }
protected override ImmutableArray <LocalSymbol> BuildLocals() { var builder = ArrayBuilder <LocalSymbol> .GetInstance(); ExpressionVariableFinder.FindExpressionVariables(this, builder, (CSharpSyntaxNode)ScopeDesignator, GetBinder((CSharpSyntaxNode)ScopeDesignator)); return(builder.ToImmutableAndFree()); }
protected override 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( declarationSyntax.Variables.Count ); // gather expression-declared variables from invalid array dimensions. eg. using(int[x is var y] z = new int[0]) declarationSyntax.Type.VisitRankSpecifiers( (rankSpecifier, args) => { foreach (var size in rankSpecifier.Sizes) { if (size.Kind() != SyntaxKind.OmittedArraySizeExpression) { ExpressionVariableFinder.FindExpressionVariables( args.binder, args.locals, size ); } } }, (binder: this, locals: locals) ); foreach (VariableDeclaratorSyntax declarator in declarationSyntax.Variables) { locals.Add( MakeLocal(declarationSyntax, declarator, LocalDeclarationKind.UsingVariable) ); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, declarator); } return(locals.ToImmutableAndFree()); } }
override protected ImmutableArray <LocalSymbol> BuildLocals() { if (_syntax.Declaration != null) { var locals = new ArrayBuilder <LocalSymbol>(_syntax.Declaration.Variables.Count); foreach (VariableDeclaratorSyntax declarator in _syntax.Declaration.Variables) { locals.Add(MakeLocal(_syntax.Declaration, declarator, LocalDeclarationKind.FixedVariable)); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, declarator); } return(locals.ToImmutable()); } return(ImmutableArray <LocalSymbol> .Empty); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { if (_syntax.Declaration != null) { var locals = new ArrayBuilder <LocalSymbol>(_syntax.Declaration.Variables.Count); foreach (VariableDeclaratorSyntax declarator in _syntax.Declaration.Variables) { locals.Add(MakeLocal(_syntax.Declaration, declarator, LocalDeclarationKind.FixedVariable)); if (declarator.Initializer != null) { ExpressionVariableFinder.FindExpressionVariables(this, locals, declarator.Initializer.Value); } } return(locals.ToImmutable()); } return(ImmutableArray <LocalSymbol> .Empty); }
protected override 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()); }
override protected ImmutableArray <LocalSymbol> BuildLocals() { var locals = ArrayBuilder <LocalSymbol> .GetInstance(); // Declaration and Initializers are mutually exclusive. if (_syntax.Declaration != null) { foreach (var vdecl in _syntax.Declaration.Variables) { var localSymbol = MakeLocal(_syntax.Declaration, vdecl, LocalDeclarationKind.RegularVariable); locals.Add(localSymbol); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, vdecl); } } else { ExpressionVariableFinder.FindExpressionVariables(this, locals, _syntax.Initializers); } return(locals.ToImmutableAndFree()); }
internal void BuildLocals(Binder enclosingBinder, StatementSyntax statement, ArrayBuilder <LocalSymbol> locals) { 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; decl.Declaration.Type.VisitRankSpecifiers((rankSpecifier, args) => { foreach (var expression in rankSpecifier.Sizes) { if (expression.Kind() != SyntaxKind.OmittedArraySizeExpression) { ExpressionVariableFinder.FindExpressionVariables(args.localScopeBinder, args.locals, expression, args.localDeclarationBinder); } } }, (localScopeBinder: this, locals: locals, localDeclarationBinder: localDeclarationBinder)); LocalDeclarationKind kind; if (decl.IsConst) { kind = LocalDeclarationKind.Constant; } else if (decl.UsingKeyword != default(SyntaxToken)) { kind = LocalDeclarationKind.UsingVariable; } else { kind = LocalDeclarationKind.RegularVariable; } foreach (var vdecl in decl.Declaration.Variables) { var localSymbol = MakeLocal(decl.Declaration, vdecl, kind, localDeclarationBinder); locals.Add(localSymbol); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, vdecl, localDeclarationBinder); } } break; case SyntaxKind.ExpressionStatement: case SyntaxKind.IfStatement: case SyntaxKind.YieldReturnStatement: case SyntaxKind.ReturnStatement: case SyntaxKind.ThrowStatement: case SyntaxKind.GotoCaseStatement: 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; } }
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 = decl.IsConst ? LocalDeclarationKind.Constant : LocalDeclarationKind.RegularVariable; foreach (var vdecl in decl.Declaration.Variables) { var localSymbol = MakeLocal(decl.Declaration, vdecl, kind, localDeclarationBinder); locals.Add(localSymbol); // also gather expression-declared variables from the bracketed argument lists and the initializers ExpressionVariableFinder.FindExpressionVariables(this, locals, vdecl, 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()); }
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.DeconstructionDeclarationStatement: { var decl = (DeconstructionDeclarationStatementSyntax)innerStatement; CollectLocalsFromDeconstruction( decl.Assignment.VariableComponent, LocalDeclarationKind.RegularVariable, locals, innerStatement); break; } case SyntaxKind.LocalDeclarationStatement: { enclosingBinder = enclosingBinder.GetBinder(innerStatement) ?? enclosingBinder; var decl = (LocalDeclarationStatementSyntax)innerStatement; LocalDeclarationKind kind = decl.IsConst ? LocalDeclarationKind.Constant : LocalDeclarationKind.RegularVariable; foreach (var vdecl in decl.Declaration.Variables) { var localSymbol = MakeLocal(decl.Declaration, vdecl, kind, enclosingBinder); locals.Add(localSymbol); ExpressionVariableFinder.FindExpressionVariables(this, locals, vdecl.Initializer?.Value, enclosingBinder); } } 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.WhileStatement: case SyntaxKind.DoStatement: case SyntaxKind.LockStatement: enclosingBinder = enclosingBinder.GetBinder(innerStatement); Debug.Assert(enclosingBinder != null); // Do and while loops always have binders. ExpressionVariableFinder.FindExpressionVariables(this, locals, innerStatement, enclosingBinder); break; default: // no other statement introduces local variables into the enclosing scope break; } } return(locals.ToImmutableAndFree()); }