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();

                PatternVariableFinder.FindPatternVariables(this, locals, expressionSyntax);
                return(locals.ToImmutableAndFree());
            }
            else
            {
                var locals = ArrayBuilder <LocalSymbol> .GetInstance(declarationSyntax.Variables.Count);

                foreach (VariableDeclaratorSyntax declarator in declarationSyntax.Variables)
                {
                    locals.Add(MakeLocal(RefKind.None, declarationSyntax, declarator, LocalDeclarationKind.UsingVariable));

                    if (declarator.Initializer != null)
                    {
                        PatternVariableFinder.FindPatternVariables(this, locals, declarator.Initializer.Value);
                    }
                }

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

            PatternVariableFinder.FindPatternVariables(this, builder, (CSharpSyntaxNode)ScopeDesignator);
            return(builder.ToImmutableAndFree());
        }
Ejemplo n.º 3
0
        override protected ImmutableArray <LocalSymbol> BuildLocals()
        {
            var locals = ArrayBuilder <LocalSymbol> .GetInstance();

            var refKind = _syntax.RefKeyword.Kind().GetRefKind();

            // Deconstruction, Declaration, and Initializers are mutually exclusive.
            if (_syntax.Deconstruction != null)
            {
                CollectLocalsFromDeconstruction(_syntax.Deconstruction.VariableComponent, LocalDeclarationKind.ForInitializerVariable, locals);
                PatternVariableFinder.FindPatternVariables(this, locals, _syntax.Deconstruction.Value);
            }
            else if (_syntax.Declaration != null)
            {
                foreach (var vdecl in _syntax.Declaration.Variables)
                {
                    var localSymbol = MakeLocal(refKind, _syntax.Declaration, vdecl, LocalDeclarationKind.ForInitializerVariable);
                    locals.Add(localSymbol);
                    PatternVariableFinder.FindPatternVariables(this, locals, vdecl.Initializer?.Value);
                }
            }
            else
            {
                PatternVariableFinder.FindPatternVariables(this, locals, _syntax.Initializers);
            }

            PatternVariableFinder.FindPatternVariables(this, locals, node: _syntax.Condition);
            PatternVariableFinder.FindPatternVariables(this, locals, _syntax.Incrementors);
            return(locals.ToImmutableAndFree());
        }
Ejemplo n.º 4
0
        override protected ImmutableArray <LocalSymbol> BuildLocals()
        {
            var locals = ArrayBuilder <LocalSymbol> .GetInstance();

            var declaration = _syntax.Declaration;

            if (declaration != null)
            {
                if (!declaration.IsDeconstructionDeclaration)
                {
                    var refKind = _syntax.RefKeyword.Kind().GetRefKind();

                    foreach (var variable in declaration.Variables)
                    {
                        var localSymbol = MakeLocal(refKind,
                                                    declaration,
                                                    variable,
                                                    LocalDeclarationKind.ForInitializerVariable);
                        locals.Add(localSymbol);

                        if (variable.Initializer != null)
                        {
                            PatternVariableFinder.FindPatternVariables(this, locals, variable.Initializer.Value);
                        }
                    }
                }
                else
                {
                    CollectLocalsFromDeconstruction(declaration, declaration.Type, LocalDeclarationKind.ForInitializerVariable, locals);
                }
            }
            else
            {
                PatternVariableFinder.FindPatternVariables(this, locals, _syntax.Initializers);
            }

            if (_syntax.Condition != null)
            {
                PatternVariableFinder.FindPatternVariables(this, locals, node: _syntax.Condition);
            }

            PatternVariableFinder.FindPatternVariables(this, locals, _syntax.Incrementors);

            return(locals.ToImmutableAndFree());
        }
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)
            {
                PatternVariableFinder.FindPatternVariables(this, locals, _syntax.Filter.FilterExpression);
            }

            return(locals.ToImmutableAndFree());
        }
Ejemplo n.º 6
0
        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(RefKind.None, _syntax.Declaration, declarator, LocalDeclarationKind.FixedVariable));

                    if (declarator.Initializer != null)
                    {
                        PatternVariableFinder.FindPatternVariables(this, locals, declarator.Initializer.Value);
                    }
                }

                return(locals.ToImmutable());
            }

            return(ImmutableArray <LocalSymbol> .Empty);
        }