else.carbon 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/if/else.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/if/else.carbon
  10. fn F() {
  11. if (a) {
  12. if (b) {
  13. c;
  14. } else {
  15. d;
  16. }
  17. } else {
  18. e;
  19. }
  20. if (x) { f; }
  21. else if (x) { g; }
  22. else { h; }
  23. }
  24. // CHECK:STDOUT: - filename: else.carbon
  25. // CHECK:STDOUT: parse_tree: [
  26. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  27. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  28. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  29. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  30. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  31. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
  32. // CHECK:STDOUT: {kind: 'IfConditionStart', text: '('},
  33. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'a'},
  34. // CHECK:STDOUT: {kind: 'IfCondition', text: ')', subtree_size: 3},
  35. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  36. // CHECK:STDOUT: {kind: 'IfConditionStart', text: '('},
  37. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'b'},
  38. // CHECK:STDOUT: {kind: 'IfCondition', text: ')', subtree_size: 3},
  39. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  40. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'c'},
  41. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 2},
  42. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 4},
  43. // CHECK:STDOUT: {kind: 'IfStatementElse', text: 'else'},
  44. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  45. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'd'},
  46. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 2},
  47. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 4},
  48. // CHECK:STDOUT: {kind: 'IfStatement', text: 'if', subtree_size: 13},
  49. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 15},
  50. // CHECK:STDOUT: {kind: 'IfStatementElse', text: 'else'},
  51. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  52. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'e'},
  53. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 2},
  54. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 4},
  55. // CHECK:STDOUT: {kind: 'IfStatement', text: 'if', subtree_size: 24},
  56. // CHECK:STDOUT: {kind: 'IfConditionStart', text: '('},
  57. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'x'},
  58. // CHECK:STDOUT: {kind: 'IfCondition', text: ')', subtree_size: 3},
  59. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  60. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'f'},
  61. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 2},
  62. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 4},
  63. // CHECK:STDOUT: {kind: 'IfStatementElse', text: 'else'},
  64. // CHECK:STDOUT: {kind: 'IfConditionStart', text: '('},
  65. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'x'},
  66. // CHECK:STDOUT: {kind: 'IfCondition', text: ')', subtree_size: 3},
  67. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  68. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'g'},
  69. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 2},
  70. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 4},
  71. // CHECK:STDOUT: {kind: 'IfStatementElse', text: 'else'},
  72. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  73. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'h'},
  74. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 2},
  75. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 4},
  76. // CHECK:STDOUT: {kind: 'IfStatement', text: 'if', subtree_size: 13},
  77. // CHECK:STDOUT: {kind: 'IfStatement', text: 'if', subtree_size: 22},
  78. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 52},
  79. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  80. // CHECK:STDOUT: ]