Пример #1
0
        internal static BoundNode Rewrite(CSharpCompilation compilation, EENamedTypeSymbol container, HashSet <LocalSymbol> declaredLocals, BoundNode node)
        {
            var builder = ArrayBuilder <BoundStatement> .GetInstance();

            bool hasChanged;

            // Rewrite top-level declarations only.
            switch (node.Kind)
            {
            case BoundKind.LocalDeclaration:
                RewriteLocalDeclaration(compilation, container, declaredLocals, builder, (BoundLocalDeclaration)node);
                hasChanged = true;
                break;

            case BoundKind.MultipleLocalDeclarations:
                foreach (var declaration in ((BoundMultipleLocalDeclarations)node).LocalDeclarations)
                {
                    RewriteLocalDeclaration(compilation, container, declaredLocals, builder, declaration);
                }
                hasChanged = true;
                break;

            default:
                hasChanged = false;
                break;
            }

            if (hasChanged)
            {
                node = BoundBlock.SynthesizedNoLocals(node.Syntax, builder.ToImmutable());
            }

            builder.Free();
            return(node);
        }
Пример #2
0
        internal static BoundStatement Rewrite(
            CSharpCompilation compilation,
            EENamedTypeSymbol container,
            HashSet <LocalSymbol> declaredLocals,
            BoundStatement node,
            ImmutableArray <LocalSymbol> declaredLocalsArray,
            DiagnosticBag diagnostics
            )
        {
            var builder = ArrayBuilder <BoundStatement> .GetInstance();

            foreach (var local in declaredLocalsArray)
            {
                CreateLocal(compilation, declaredLocals, builder, local, node.Syntax, diagnostics);
            }

            // Rewrite top-level declarations only.
            switch (node.Kind)
            {
            case BoundKind.LocalDeclaration:
                Debug.Assert(
                    declaredLocals.Contains(((BoundLocalDeclaration)node).LocalSymbol)
                    );
                RewriteLocalDeclaration(builder, (BoundLocalDeclaration)node);
                break;

            case BoundKind.MultipleLocalDeclarations:
                foreach (
                    var declaration in ((BoundMultipleLocalDeclarations)node).LocalDeclarations
                    )
                {
                    Debug.Assert(declaredLocals.Contains(declaration.LocalSymbol));
                    RewriteLocalDeclaration(builder, declaration);
                }
                break;

            default:
                if (builder.Count == 0)
                {
                    builder.Free();
                    return(node);
                }

                builder.Add(node);
                break;
            }

            return(BoundBlock.SynthesizedNoLocals(node.Syntax, builder.ToImmutableAndFree()));
        }