precedence_as.carbon 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/operators/precedence_as.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/operators/precedence_as.carbon
  10. fn F(n: i32) {
  11. // Type operators and unary operators are higher precedence than `as`.
  12. -n as const i32;
  13. &n as i32*;
  14. // `as` is higher precedence than relational comparisons and
  15. // logical operators.
  16. if (1 as i32 < 2 as i32 and true as bool and false as bool) {}
  17. }
  18. // CHECK:STDOUT: - filename: precedence_as.carbon
  19. // CHECK:STDOUT: parse_tree: [
  20. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  21. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  22. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'F'},
  23. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  24. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
  25. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  26. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  27. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 5},
  28. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 8},
  29. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'n'},
  30. // CHECK:STDOUT: {kind: 'PrefixOperatorMinus', text: '-', subtree_size: 2},
  31. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  32. // CHECK:STDOUT: {kind: 'PrefixOperatorConst', text: 'const', subtree_size: 2},
  33. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', subtree_size: 5},
  34. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 6},
  35. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'n'},
  36. // CHECK:STDOUT: {kind: 'PrefixOperatorAmp', text: '&', subtree_size: 2},
  37. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  38. // CHECK:STDOUT: {kind: 'PostfixOperatorStar', text: '*', subtree_size: 2},
  39. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', subtree_size: 5},
  40. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 6},
  41. // CHECK:STDOUT: {kind: 'IfConditionStart', text: '('},
  42. // CHECK:STDOUT: {kind: 'IntLiteral', text: '1'},
  43. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  44. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', subtree_size: 3},
  45. // CHECK:STDOUT: {kind: 'IntLiteral', text: '2'},
  46. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  47. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', subtree_size: 3},
  48. // CHECK:STDOUT: {kind: 'InfixOperatorLess', text: '<', subtree_size: 7},
  49. // CHECK:STDOUT: {kind: 'ShortCircuitOperandAnd', text: 'and', subtree_size: 8},
  50. // CHECK:STDOUT: {kind: 'BoolLiteralTrue', text: 'true'},
  51. // CHECK:STDOUT: {kind: 'BoolTypeLiteral', text: 'bool'},
  52. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', subtree_size: 3},
  53. // CHECK:STDOUT: {kind: 'ShortCircuitOperatorAnd', text: 'and', subtree_size: 12},
  54. // CHECK:STDOUT: {kind: 'ShortCircuitOperandAnd', text: 'and', subtree_size: 13},
  55. // CHECK:STDOUT: {kind: 'BoolLiteralFalse', text: 'false'},
  56. // CHECK:STDOUT: {kind: 'BoolTypeLiteral', text: 'bool'},
  57. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', subtree_size: 3},
  58. // CHECK:STDOUT: {kind: 'ShortCircuitOperatorAnd', text: 'and', subtree_size: 17},
  59. // CHECK:STDOUT: {kind: 'IfCondition', text: ')', subtree_size: 19},
  60. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  61. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 2},
  62. // CHECK:STDOUT: {kind: 'IfStatement', text: 'if', subtree_size: 22},
  63. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 43},
  64. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  65. // CHECK:STDOUT: ]