// methodsWithYields will contain all function-declaration-like CSharpSyntaxNodes with yield statements contained within them. // Currently the types of these are restricted to only be whatever the syntax parameter is, plus any LocalFunctionStatementSyntax contained within it. // This may change if the language is extended to allow iterator lambdas, in which case the lambda would also be returned. // (lambdas currently throw a diagnostic in WithLambdaParametersBinder.GetIteratorElementType when a yield is used within them) public static SmallDictionary<CSharpSyntaxNode, Binder> BuildMap(Symbol containingMemberOrLambda, CSharpSyntaxNode syntax, Binder enclosing, ArrayBuilder<CSharpSyntaxNode> methodsWithYields) { var builder = new LocalBinderFactory(containingMemberOrLambda, syntax, enclosing, methodsWithYields); if (syntax is ExpressionSyntax) { var binder = new PatternVariableBinder(syntax, enclosing); builder.AddToMap(syntax, binder); builder.Visit(syntax, binder); } else { builder.Visit(syntax); } // the other place this is possible is in a local function if (builder._sawYield) methodsWithYields.Add(syntax); return builder._map; }
// methodsWithYields will contain all function-declaration-like CSharpSyntaxNodes with yield statements contained within them. // Currently the types of these are restricted to only be whatever the syntax parameter is, plus any LocalFunctionStatementSyntax contained within it. // This may change if the language is extended to allow iterator lambdas, in which case the lambda would also be returned. // (lambdas currently throw a diagnostic in WithLambdaParametersBinder.GetIteratorElementType when a yield is used within them) public static SmallDictionary <CSharpSyntaxNode, Binder> BuildMap(Symbol containingMemberOrLambda, CSharpSyntaxNode syntax, Binder enclosing, ArrayBuilder <CSharpSyntaxNode> methodsWithYields) { var builder = new LocalBinderFactory(containingMemberOrLambda, syntax, enclosing, methodsWithYields); if (syntax is ExpressionSyntax) { var binder = new PatternVariableBinder(syntax, enclosing); builder.AddToMap(syntax, binder); builder.Visit(syntax, binder); } else { builder.Visit(syntax); } // the other place this is possible is in a local function if (builder._sawYield) { methodsWithYields.Add(syntax); } return(builder._map); }
public override void VisitSwitchSection(SwitchSectionSyntax node) { var patternBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, patternBinder); foreach (var label in node.Labels) { var match = label as CasePatternSwitchLabelSyntax; if (match != null) { Visit(match.Pattern, patternBinder); if (match.WhenClause != null) { Visit(match.WhenClause.Condition, patternBinder); } } } foreach (StatementSyntax statement in node.Statements) { Visit(statement, patternBinder); } }
public override void VisitIfStatement(IfStatementSyntax node) { var ifBinder = new PatternVariableBinder(node.Condition, _enclosing); AddToMap(node.Condition, ifBinder); Visit(node.Condition, ifBinder); VisitPossibleEmbeddedStatement(node.Statement, ifBinder); // pattern variables from the condition are not in scope within the else clause if (node.Else != null) AddToMap(node.Else.Statement, _enclosing); Visit(node.Else, _enclosing); }
public override void VisitSwitchSection(SwitchSectionSyntax node) { var patternBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, patternBinder); foreach (var label in node.Labels) { var match = label as CasePatternSwitchLabelSyntax; if (match != null) { Visit(match.Pattern, patternBinder); if (match.WhenClause != null) { Visit(match.WhenClause.Condition, patternBinder); } } } foreach (StatementSyntax statement in node.Statements) { Visit(statement, patternBinder); } }
public override void VisitSwitchStatement(SwitchStatementSyntax node) { Debug.Assert((object)_containingMemberOrLambda == _enclosing.ContainingMemberOrLambda); var patternBinder = new PatternVariableBinder(node.Expression, _enclosing); AddToMap(node.Expression, patternBinder); Visit(node.Expression, patternBinder); var switchBinder = new SwitchBinder(patternBinder, node); AddToMap(node, switchBinder); foreach (SwitchSectionSyntax section in node.Sections) { Visit(section, switchBinder); } }
public override void VisitLockStatement(LockStatementSyntax node) { var patternBinder = new PatternVariableBinder(node, _enclosing); var lockBinder = new LockBinder(patternBinder, node); AddToMap(node, lockBinder); Visit(node.Expression, lockBinder); StatementSyntax statement = node.Statement; var statementBinder = lockBinder.WithAdditionalFlags(BinderFlags.InLockBody); if (statementBinder != lockBinder) { AddToMap(statement, statementBinder); } VisitPossibleEmbeddedStatement(statement, statementBinder); }
public override void VisitForEachStatement(ForEachStatementSyntax node) { Debug.Assert((object)_containingMemberOrLambda == _enclosing.ContainingMemberOrLambda); var patternBinder = new PatternVariableBinder(node.Expression, _enclosing); AddToMap(node.Expression, patternBinder); Visit(node.Expression, patternBinder); var binder = new ForEachLoopBinder(patternBinder, node); AddToMap(node, binder); VisitPossibleEmbeddedStatement(node.Statement, binder); }
public override void VisitArgumentList(ArgumentListSyntax node) { if (_root == node) { // We are supposed to get here only for constructor initializers Debug.Assert(node.Parent is ConstructorInitializerSyntax); var argBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, argBinder); foreach (var arg in node.Arguments) { Visit(arg.Expression, argBinder); } } else { base.VisitArgumentList(node); } }
public override void VisitAttribute(AttributeSyntax node) { var attrBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, attrBinder); if (node.ArgumentList?.Arguments.Count > 0) { foreach (var argument in node.ArgumentList.Arguments) { Visit(argument.Expression, attrBinder); } } }
public override void VisitEqualsValueClause(EqualsValueClauseSyntax node) { var valueBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, valueBinder); Visit(node.Value, valueBinder); }
public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node) { var arrowBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, arrowBinder); Visit(node.Expression, arrowBinder); }
private void VisitLambdaExpression(LambdaExpressionSyntax node) { // Do not descend into a lambda unless it is a root node if (_root != node) { return; } CSharpSyntaxNode body = node.Body; if (body.Kind() == SyntaxKind.Block) { VisitBlock((BlockSyntax)body); } else { var binder = new PatternVariableBinder(body, _enclosing); AddToMap(body, binder); Visit(body, binder); } }
public override void VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) { var patternBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, patternBinder); foreach (var decl in node.Declaration.Variables) { var value = decl.Initializer?.Value; if (value != null) { Visit(value, patternBinder); } } }
public override void VisitDoStatement(DoStatementSyntax node) { Debug.Assert((object)_containingMemberOrLambda == _enclosing.ContainingMemberOrLambda); var patternBinder = new PatternVariableBinder(node, _enclosing); var whileBinder = new WhileBinder(patternBinder, node); AddToMap(node, whileBinder); Visit(node.Condition, whileBinder); VisitPossibleEmbeddedStatement(node.Statement, whileBinder); }
public override void VisitThrowStatement(ThrowStatementSyntax node) { if (node.Expression != null) { var patternBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, patternBinder); Visit(node.Expression, patternBinder); } }
public override void VisitDeconstructionDeclarationStatement(DeconstructionDeclarationStatementSyntax node) { var patternBinder = new PatternVariableBinder(node, _enclosing); AddToMap(node, patternBinder); Visit(node.Assignment.Value, patternBinder); }