precedence_as.carbon 4.0 KB

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