Exemplo n.º 1
0
            public List <BasicBlock> Build(BoundBlockStatement block)
            {
                foreach (var statement in block.Statements)
                {
                    switch (statement.Kind)
                    {
                    case BoundNodeKind.LabelStatement:
                        StartBlock();
                        _statements.Add(statement);
                        break;

                    case BoundNodeKind.GotoStatement:
                    case BoundNodeKind.ConditionalGotoStatement:
                    case BoundNodeKind.ReturnStatement:
                        _statements.Add(statement);
                        StartBlock();
                        break;

                    case BoundNodeKind.NopStatement:
                    case BoundNodeKind.VariableDeclaration:
                    case BoundNodeKind.SequencePointStatement:
                    case BoundNodeKind.ExpressionStatement:
                        _statements.Add(statement);
                        break;

                    default:
                        throw new Exception($"Unexpected statement: {statement.Kind}");
                    }
                }

                EndBlock();

                return(_blocks.ToList());
            }
Exemplo n.º 2
0
        private static void WriteBlockStatement(BoundBlockStatement node, IndentedTextWriter writer)
        {
            writer.WritePunctuation(SyntaxKind.OpenBraceToken);
            writer.WriteLine();
            writer.Indent++;

            foreach (var s in node.Statements)
            {
                s.WriteTo(writer);
            }

            writer.Indent--;
            writer.WritePunctuation(SyntaxKind.CloseBraceToken);
            writer.WriteLine();
        }