Exemplo n.º 1
0
        public override void VisitSwitchSection(SwitchSectionSyntax node)
        {
            var patternBinder = new ExpressionVariableBinder(node, _enclosing);

            AddToMap(node, patternBinder);

            foreach (SwitchLabelSyntax label in node.Labels)
            {
                switch (label.Kind())
                {
                case SyntaxKind.CasePatternSwitchLabel:
                {
                    var switchLabel = (CasePatternSwitchLabelSyntax)label;
                    Visit(switchLabel.Pattern, patternBinder);
                    if (switchLabel.WhenClause != null)
                    {
                        Visit(switchLabel.WhenClause.Condition, patternBinder);
                    }
                    break;
                }

                case SyntaxKind.CaseSwitchLabel:
                {
                    var switchLabel = (CaseSwitchLabelSyntax)label;
                    Visit(switchLabel.Value, patternBinder);
                    break;
                }
                }
            }

            foreach (StatementSyntax statement in node.Statements)
            {
                Visit(statement, patternBinder);
            }
        }
Exemplo n.º 2
0
        public override void VisitEqualsValueClause(EqualsValueClauseSyntax node)
        {
            var valueBinder = new ExpressionVariableBinder(node, _enclosing);

            AddToMap(node, valueBinder);
            Visit(node.Value, valueBinder);
        }
Exemplo n.º 3
0
        public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
        {
            var arrowBinder = new ExpressionVariableBinder(node, _enclosing);

            AddToMap(node, arrowBinder);
            Visit(node.Expression, arrowBinder);
        }
Exemplo n.º 4
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 <SyntaxNode, Binder> BuildMap(
            Symbol containingMemberOrLambda,
            SyntaxNode syntax,
            Binder enclosing,
            ArrayBuilder <SyntaxNode> methodsWithYields,
            Action <Binder, SyntaxNode> binderUpdatedHandler = null)
        {
            var builder = new LocalBinderFactory(containingMemberOrLambda, syntax, enclosing, methodsWithYields);

            StatementSyntax statement;
            var             expressionSyntax = syntax as ExpressionSyntax;

            if (expressionSyntax != null)
            {
                enclosing = new ExpressionVariableBinder(syntax, enclosing);

                if ((object)binderUpdatedHandler != null)
                {
                    binderUpdatedHandler(enclosing, syntax);
                }

                builder.AddToMap(syntax, enclosing);
                builder.Visit(expressionSyntax, enclosing);
            }
            else if (syntax.Kind() != SyntaxKind.Block && (statement = syntax as StatementSyntax) != null)
            {
                CSharpSyntaxNode embeddedScopeDesignator;
                enclosing = builder.GetBinderForPossibleEmbeddedStatement(statement, enclosing, out embeddedScopeDesignator);

                if ((object)binderUpdatedHandler != null)
                {
                    binderUpdatedHandler(enclosing, embeddedScopeDesignator);
                }

                if (embeddedScopeDesignator != null)
                {
                    builder.AddToMap(embeddedScopeDesignator, enclosing);
                }

                builder.Visit(statement, enclosing);
            }
            else
            {
                if ((object)binderUpdatedHandler != null)
                {
                    binderUpdatedHandler(enclosing, null);
                }

                builder.Visit((CSharpSyntaxNode)syntax, enclosing);
            }

            // the other place this is possible is in a local function
            if (builder._sawYield)
            {
                methodsWithYields.Add(syntax);
            }
            return(builder._map);
        }
Exemplo n.º 5
0
        public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
        {
            Binder enclosing = new ExpressionVariableBinder(node, _enclosing);

            AddToMap(node, enclosing);

            Visit(node.Initializer, enclosing);
            Visit(node.Body, enclosing);
            Visit(node.ExpressionBody, enclosing);
        }
Exemplo n.º 6
0
        public override void VisitForStatement(ForStatementSyntax node)
        {
            Debug.Assert((object)_containingMemberOrLambda == _enclosing.ContainingMemberOrLambda);
            var patternBinder = new ExpressionVariableBinder(node.Expression, _enclosing);

            AddToMap(node.Expression, patternBinder);
            Visit(node.Expression, patternBinder);

            var binder = new ForEachLoopBinder(patternBinder, node);

            AddToMap(node, binder);

            VisitPossibleEmbeddedStatement(node.Statement, binder);
        }
Exemplo n.º 7
0
        public override void VisitAttribute(AttributeSyntax node)
        {
            var attrBinder = new ExpressionVariableBinder(node, _enclosing);

            AddToMap(node, attrBinder);

            if (node.ArgumentList?.Arguments.Count > 0)
            {
                foreach (AttributeArgumentSyntax argument in node.ArgumentList.Arguments)
                {
                    Visit(argument.Expression, attrBinder);
                }
            }
        }
Exemplo n.º 8
0
        public override void VisitConstructorInitializer(ConstructorInitializerSyntax node)
        {
            var binder = _enclosing.WithAdditionalFlags(BinderFlags.ConstructorInitializer);

            AddToMap(node, binder);

            if (node.ArgumentList != null)
            {
                if (_root == node)
                {
                    binder = new ExpressionVariableBinder(node.ArgumentList, binder);
                    AddToMap(node.ArgumentList, binder);
                }

                Visit(node.ArgumentList, binder);
            }
        }
Exemplo n.º 9
0
        public override void VisitSwitchExpression(SwitchExpressionSyntax node)
        {
            var switchExpressionBinder = new SwitchExpressionBinder(node, _enclosing);

            AddToMap(node, switchExpressionBinder);
            Visit(node.GoverningExpression, switchExpressionBinder);
            foreach (SwitchExpressionArmSyntax arm in node.Arms)
            {
                var armScopeBinder = new ExpressionVariableBinder(arm, switchExpressionBinder);
                var armBinder      = new SwitchExpressionArmBinder(arm, armScopeBinder, switchExpressionBinder);
                AddToMap(arm, armBinder);
                Visit(arm.Pattern, armBinder);
                if (arm.WhenClause != null)
                {
                    Visit(arm.WhenClause, armBinder);
                }

                Visit(arm.Expression, armBinder);
            }
        }
Exemplo n.º 10
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 ExpressionVariableBinder(body, _enclosing);
                AddToMap(body, binder);
                Visit(body, binder);
            }
        }
Exemplo n.º 11
0
 public SwitchExpressionArmBinder(SwitchExpressionArmSyntax arm, ExpressionVariableBinder armScopeBinder, SwitchExpressionBinder switchExpressionBinder) : base(armScopeBinder)
 {
     this._arm                    = arm;
     this._armScopeBinder         = armScopeBinder;
     this._switchExpressionBinder = switchExpressionBinder;
 }