Ejemplo n.º 1
0
        // 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;
        }
Ejemplo n.º 2
0
        // 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);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        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);
                }
            }
        }
Ejemplo n.º 11
0
 public override void VisitEqualsValueClause(EqualsValueClauseSyntax node)
 {
     var valueBinder = new PatternVariableBinder(node, _enclosing);
     AddToMap(node, valueBinder);
     Visit(node.Value, valueBinder);
 }
Ejemplo n.º 12
0
 public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
 {
     var arrowBinder = new PatternVariableBinder(node, _enclosing);
     AddToMap(node, arrowBinder);
     Visit(node.Expression, arrowBinder);
 }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 14
0
        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);
                }
            }
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
 public override void VisitThrowStatement(ThrowStatementSyntax node)
 {
     if (node.Expression != null)
     {
         var patternBinder = new PatternVariableBinder(node, _enclosing);
         AddToMap(node, patternBinder);
         Visit(node.Expression, patternBinder);
     }
 }
Ejemplo n.º 17
0
 public override void VisitDeconstructionDeclarationStatement(DeconstructionDeclarationStatementSyntax node)
 {
     var patternBinder = new PatternVariableBinder(node, _enclosing);
     AddToMap(node, patternBinder);
     Visit(node.Assignment.Value, patternBinder);
 }