precedence_as.carbon 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. fn F(n: i32) {
  7. // Type operators and unary operators are lower precedence than `as`.
  8. -n as const i32;
  9. &n as i32*;
  10. // `as` is lower precedence than relational comparisons and logical operators.
  11. if (1 as i32 < 2 as i32 and true as bool and false as bool) {}
  12. }
  13. // CHECK:STDOUT: [
  14. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  15. // CHECK:STDOUT: {kind: 'Name', text: 'F'},
  16. // CHECK:STDOUT: {kind: 'ParameterListStart', text: '('},
  17. // CHECK:STDOUT: {kind: 'Name', text: 'n'},
  18. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  19. // CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3},
  20. // CHECK:STDOUT: {kind: 'ParameterList', text: ')', subtree_size: 5},
  21. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 8},
  22. // CHECK:STDOUT: {kind: 'NameExpression', text: 'n'},
  23. // CHECK:STDOUT: {kind: 'PrefixOperator', text: '-', subtree_size: 2},
  24. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  25. // CHECK:STDOUT: {kind: 'PrefixOperator', text: 'const', subtree_size: 2},
  26. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', subtree_size: 5},
  27. // CHECK:STDOUT: {kind: 'ExpressionStatement', text: ';', subtree_size: 6},
  28. // CHECK:STDOUT: {kind: 'NameExpression', text: 'n'},
  29. // CHECK:STDOUT: {kind: 'PrefixOperator', text: '&', subtree_size: 2},
  30. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  31. // CHECK:STDOUT: {kind: 'PostfixOperator', text: '*', subtree_size: 2},
  32. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', subtree_size: 5},
  33. // CHECK:STDOUT: {kind: 'ExpressionStatement', text: ';', subtree_size: 6},
  34. // CHECK:STDOUT: {kind: 'IfConditionStart', text: '('},
  35. // CHECK:STDOUT: {kind: 'Literal', text: '1'},
  36. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  37. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', subtree_size: 3},
  38. // CHECK:STDOUT: {kind: 'Literal', text: '2'},
  39. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  40. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', subtree_size: 3},
  41. // CHECK:STDOUT: {kind: 'InfixOperator', text: '<', subtree_size: 7},
  42. // CHECK:STDOUT: {kind: 'ShortCircuitOperand', text: 'and', subtree_size: 8},
  43. // CHECK:STDOUT: {kind: 'Literal', text: 'true'},
  44. // CHECK:STDOUT: {kind: 'Literal', text: 'bool'},
  45. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', subtree_size: 3},
  46. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'and', subtree_size: 12},
  47. // CHECK:STDOUT: {kind: 'ShortCircuitOperand', text: 'and', subtree_size: 13},
  48. // CHECK:STDOUT: {kind: 'Literal', text: 'false'},
  49. // CHECK:STDOUT: {kind: 'Literal', text: 'bool'},
  50. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', subtree_size: 3},
  51. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'and', subtree_size: 17},
  52. // CHECK:STDOUT: {kind: 'IfCondition', text: ')', subtree_size: 19},
  53. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  54. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 2},
  55. // CHECK:STDOUT: {kind: 'IfStatement', text: 'if', subtree_size: 22},
  56. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 43},
  57. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  58. // CHECK:STDOUT: ]