Switch the driver to print ParseTree postorder by default (#2371)

The ParseTree comments say that preorder is "easier to visualize and read". The problem is, both the ParseTree and Semantics need to operate on the postorder traversal: the ParseTree during construction, and the Semantics during processing. As a consequence, understanding the postorder traversal is important, but it's also very hard to decipher when presented preorder. This PR provides a way to see the postorder, with helpful indents to show subtrees.

This retains the preorder printing as an option for people who prefer that. I'm pretty sure it'll be easier to debug tests if we can see the postorder, so I'm making that the default.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
Jon Ross-Perkins
2022-11-08 10:08:42 -08:00
committed by GitHub
co-authored by Chandler Carruth
parent 7c102d3726
commit e21449edff
56 changed files with 1026 additions and 976 deletions
@@ -5,12 +5,12 @@
// AUTOUPDATE
// RUN: %{carbon-run-parser}
// CHECK:STDOUT: [
// CHECK:STDOUT: {node_index: 4, kind: 'FunctionDeclaration', text: ';', subtree_size: 5, children: [
// CHECK:STDOUT: {node_index: 0, kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {node_index: 1, kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {node_index: 3, kind: 'ParameterList', text: '(', subtree_size: 2, children: [
// CHECK:STDOUT: {node_index: 2, kind: 'ParameterListEnd', text: ')'}]}]},
// CHECK:STDOUT: {node_index: 5, kind: 'FileEnd', text: ''},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'DeclaredName', text: 'F'},
// CHECK:STDOUT: {kind: 'ParameterListEnd', text: ')'},
// CHECK:STDOUT: {kind: 'ParameterList', text: '(', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDeclaration', text: ';', subtree_size: 5},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
fn F();