node_kind.def 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. // This is an X-macro header. It does not use `#include` guards, and instead is
  6. // designed to be `#include`ed after the x-macro is defined in order for its
  7. // inclusion to expand to the desired output. Macro definitions are cleaned up
  8. // at the end of this file.
  9. //
  10. // Supported x-macros are:
  11. // - CARBON_PARSE_NODE_KIND(Name)
  12. // Used as a fallback if other macros are missing. No kinds should use this
  13. // directly.
  14. // - CARBON_PARSE_NODE_KIND_BRACKET(Name, BracketName, LexTokenKinds)
  15. // Defines a bracketed node kind. BracketName should refer to the node
  16. // kind that is the _start_ of the bracketed range.
  17. // - CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ChildCount, LexTokenKinds)
  18. // Defines a parse node with a set number of children, often 0. This count
  19. // must be correct even when the node contains errors.
  20. //
  21. // In both cases, LexTokenKinds says which Lex::TokenKind values that this
  22. // parse node can correspond to, and is a sequence of:
  23. // - CARBON_TOKEN(kind): This node can correspond to this kind of token.
  24. // - CARBON_ANY_TOKEN: This node can correspond to any token.
  25. // - CARBON_IF_ERROR(LexTokenKinds): This node can additionally correspond
  26. // to the given kinds of tokens if its `has_error` flag is set.
  27. //
  28. // This tree represents the subset relationship between these macros, where if a
  29. // specific x-macro isn't defined, it'll fall back to the parent macro.
  30. //
  31. // Parse nodes are clustered based on language feature. Comments will show their
  32. // relationship in postorder, using indentation for child node relationships.
  33. #if !(defined(CARBON_PARSE_NODE_KIND) || \
  34. (defined(CARBON_PARSE_NODE_KIND_BRACKET) && \
  35. defined(CARBON_PARSE_NODE_KIND_CHILD_COUNT)))
  36. #error "Must define CARBON_PARSE_NODE_KIND family x-macros to use this file."
  37. #endif
  38. // The BRACKET and CHILD_COUNT macros will use CARBON_PARSE_NODE_KIND by default
  39. // when undefined.
  40. #ifndef CARBON_PARSE_NODE_KIND_BRACKET
  41. #define CARBON_PARSE_NODE_KIND_BRACKET(Name, ...) CARBON_PARSE_NODE_KIND(Name)
  42. #endif
  43. #ifndef CARBON_PARSE_NODE_KIND_CHILD_COUNT
  44. #define CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ...) \
  45. CARBON_PARSE_NODE_KIND(Name)
  46. #endif
  47. // The start of the file.
  48. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileStart, 0, CARBON_TOKEN(StartOfFile))
  49. // The end of the file.
  50. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileEnd, 0, CARBON_TOKEN(EndOfFile))
  51. // An invalid parse. Used to balance the parse tree. Always has an error.
  52. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InvalidParse, 0,
  53. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  54. // An empty declaration, such as `;`.
  55. CARBON_PARSE_NODE_KIND_CHILD_COUNT(EmptyDeclaration, 0,
  56. CARBON_TOKEN(Semi)
  57. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  58. // A name in a non-expression context, such as a declaration.
  59. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, 0,
  60. CARBON_TOKEN(Identifier)
  61. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  62. // A name in an expression context.
  63. CARBON_PARSE_NODE_KIND_CHILD_COUNT(NameExpression, 0, CARBON_TOKEN(Identifier))
  64. // `package`:
  65. // PackageIntroducer
  66. // _external_: Name
  67. // _external_: Literal
  68. // PackageLibrary
  69. // PackageApi or PackageImpl
  70. // PackageDirective
  71. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageIntroducer, 0, CARBON_TOKEN(Package))
  72. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageApi, 0, CARBON_TOKEN(Api))
  73. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageImpl, 0, CARBON_TOKEN(Impl))
  74. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageLibrary, 1, CARBON_TOKEN(Library))
  75. CARBON_PARSE_NODE_KIND_BRACKET(PackageDirective, PackageIntroducer,
  76. CARBON_TOKEN(Semi)
  77. CARBON_IF_ERROR(CARBON_TOKEN(Package)))
  78. // `namespace`:
  79. // NamespaceStart
  80. // _external_: Name or QualifiedDeclaration
  81. // Namespace
  82. CARBON_PARSE_NODE_KIND_CHILD_COUNT(NamespaceStart, 0, CARBON_TOKEN(Namespace))
  83. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Namespace, 2, CARBON_TOKEN(Semi))
  84. // A code block:
  85. // CodeBlockStart
  86. // _external_: statements
  87. // CodeBlock
  88. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CodeBlockStart, 0,
  89. CARBON_TOKEN(OpenCurlyBrace)
  90. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  91. CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart,
  92. CARBON_TOKEN(CloseCurlyBrace)
  93. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  94. // `fn`:
  95. // FunctionIntroducer
  96. // _external_: Name or QualifiedDeclaration
  97. // _external_: ParameterList
  98. // _external_: type expression
  99. // ReturnType
  100. // FunctionDefinitionStart
  101. // _external_: statements
  102. // FunctionDefinition
  103. //
  104. // The above is the structure for a definition; for a declaration,
  105. // FunctionDefinitionStart and later nodes are removed and replaced by
  106. // FunctionDeclaration.
  107. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FunctionIntroducer, 0, CARBON_TOKEN(Fn))
  108. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnType, 1, CARBON_TOKEN(MinusGreater))
  109. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinitionStart, FunctionIntroducer,
  110. CARBON_TOKEN(OpenCurlyBrace))
  111. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinition, FunctionDefinitionStart,
  112. CARBON_TOKEN(CloseCurlyBrace))
  113. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDeclaration, FunctionIntroducer,
  114. CARBON_TOKEN(Semi)
  115. CARBON_IF_ERROR(CARBON_TOKEN(Fn)))
  116. // A parameter list, possibly deduced:
  117. // [Deduced]ParamertListStart
  118. // _external_: [Generic]PatternBinding
  119. // ParameterListComma
  120. // [Deduced]ParameterList
  121. //
  122. // Expressions and ParameterListComma may repeat with ParameterListComma as a
  123. // separator.
  124. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListStart, 0,
  125. CARBON_TOKEN(OpenParen))
  126. CARBON_PARSE_NODE_KIND_CHILD_COUNT(DeducedParameterListStart, 0,
  127. CARBON_TOKEN(OpenSquareBracket))
  128. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListComma, 0, CARBON_TOKEN(Comma))
  129. CARBON_PARSE_NODE_KIND_BRACKET(ParameterList, ParameterListStart,
  130. CARBON_TOKEN(CloseParen))
  131. CARBON_PARSE_NODE_KIND_BRACKET(DeducedParameterList, DeducedParameterListStart,
  132. CARBON_TOKEN(CloseSquareBracket))
  133. // An array type, such as `[i32; 3]` or `[i32;]`:
  134. // ArrayExpressionStart
  135. // _external_: type expression
  136. // ArrayExpressionSemi
  137. // _external_: expression
  138. // ArrayExpression
  139. //
  140. // The bound expression is optional.
  141. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ArrayExpressionStart, 0,
  142. CARBON_TOKEN(OpenSquareBracket))
  143. // May be associated with a `]` token on error.
  144. CARBON_PARSE_NODE_KIND_CHILD_COUNT(
  145. ArrayExpressionSemi, 2,
  146. CARBON_TOKEN(Semi) CARBON_IF_ERROR(CARBON_TOKEN(CloseSquareBracket)))
  147. CARBON_PARSE_NODE_KIND_BRACKET(ArrayExpression, ArrayExpressionSemi,
  148. CARBON_TOKEN(CloseSquareBracket))
  149. // A pattern binding, such as `name: Type`:
  150. // Name
  151. // _external_: type expression
  152. // [Generic]PatternBinding
  153. //
  154. // Address and Template may be parents to [Generic]PatternBinding, in that
  155. // order.
  156. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PatternBinding, 2,
  157. CARBON_TOKEN(Colon)
  158. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  159. CARBON_PARSE_NODE_KIND_CHILD_COUNT(GenericPatternBinding, 2,
  160. CARBON_TOKEN(ColonExclaim))
  161. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Address, 1, CARBON_TOKEN(Addr))
  162. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Template, 1, CARBON_TOKEN(Template))
  163. // `let`:
  164. // LetIntroducer
  165. // _external_: PatternBinding
  166. // LetInitializer
  167. // _external_: expression
  168. // LetDeclaration
  169. CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetIntroducer, 0, CARBON_TOKEN(Let))
  170. CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetInitializer, 0, CARBON_TOKEN(Equal))
  171. CARBON_PARSE_NODE_KIND_BRACKET(LetDeclaration, LetIntroducer,
  172. CARBON_TOKEN(Semi))
  173. // `var`:
  174. // VariableIntroducer
  175. // _external_: PatternBinding
  176. // optional VariableInitializer
  177. // optional _external_: expression
  178. // VariableDeclaration
  179. //
  180. // The VariableInitializer and following expression are paired: either both will
  181. // be present, or neither will.
  182. CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableIntroducer, 0, CARBON_TOKEN(Var))
  183. CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableInitializer, 0, CARBON_TOKEN(Equal))
  184. CARBON_PARSE_NODE_KIND_BRACKET(VariableDeclaration, VariableIntroducer,
  185. CARBON_TOKEN(Semi)
  186. CARBON_IF_ERROR(CARBON_TOKEN(Var)))
  187. // An expression statement:
  188. // _external_: expression
  189. // ExpressionStatement
  190. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ExpressionStatement, 1, CARBON_TOKEN(Semi))
  191. // `break`:
  192. // BreakStatementStart
  193. // BreakStatement
  194. CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatementStart, 0, CARBON_TOKEN(Break))
  195. CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatement, 1,
  196. CARBON_TOKEN(Semi)
  197. CARBON_IF_ERROR(CARBON_TOKEN(Break)))
  198. // `continue`:
  199. // ContinueStatementStart
  200. // ContinueStatement
  201. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatementStart, 0,
  202. CARBON_TOKEN(Continue))
  203. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatement, 1,
  204. CARBON_TOKEN(Semi)
  205. CARBON_IF_ERROR(CARBON_TOKEN(Continue)))
  206. // `return`:
  207. // ReturnStatementStart
  208. // _external_: expression
  209. // ReturnStatement
  210. //
  211. // The child expression is optional.
  212. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnStatementStart, 0,
  213. CARBON_TOKEN(Return))
  214. CARBON_PARSE_NODE_KIND_BRACKET(ReturnStatement, ReturnStatementStart,
  215. CARBON_TOKEN(Semi)
  216. CARBON_IF_ERROR(CARBON_TOKEN(Return)))
  217. // `for`:
  218. // ForHeaderStart
  219. // VariableIntroducer
  220. // _external_: PatternBinding
  221. // _external_: type expression
  222. // ForIn
  223. // _external_: expression
  224. // ForHeader
  225. // _external_: CodeBlock
  226. // ForStatement
  227. //
  228. // Versus a normal `var`, ForIn replaces VariableDeclaration.
  229. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForHeaderStart, 0,
  230. CARBON_TOKEN(OpenParen)
  231. CARBON_IF_ERROR(CARBON_TOKEN(For)))
  232. CARBON_PARSE_NODE_KIND_BRACKET(ForIn, VariableIntroducer,
  233. CARBON_TOKEN(In)
  234. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  235. CARBON_PARSE_NODE_KIND_BRACKET(ForHeader, ForHeaderStart,
  236. CARBON_TOKEN(CloseParen)
  237. CARBON_IF_ERROR(CARBON_TOKEN(For)))
  238. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForStatement, 2, CARBON_TOKEN(For))
  239. // `if` statement + `else`:
  240. // IfConditionStart
  241. // _external_: expression
  242. // IfCondition
  243. // _external_: CodeBlock
  244. // IfStatementElse
  245. // _external_: CodeBlock or IfStatement
  246. // IfStatement
  247. //
  248. // IfStatementElse and the following node are optional based on `else` presence.
  249. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfConditionStart, 0,
  250. CARBON_TOKEN(OpenParen)
  251. CARBON_IF_ERROR(CARBON_TOKEN(If)))
  252. CARBON_PARSE_NODE_KIND_BRACKET(IfCondition, IfConditionStart,
  253. CARBON_TOKEN(CloseParen)
  254. CARBON_IF_ERROR(CARBON_TOKEN(If)))
  255. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfStatementElse, 0, CARBON_TOKEN(Else))
  256. CARBON_PARSE_NODE_KIND_BRACKET(IfStatement, IfCondition, CARBON_TOKEN(If))
  257. // `while`:
  258. // WhileConditionStart
  259. // _external_: expression
  260. // WhileCondition
  261. // _external_: CodeBlock
  262. // WhileStatement
  263. CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileConditionStart, 0,
  264. CARBON_TOKEN(OpenParen))
  265. CARBON_PARSE_NODE_KIND_BRACKET(WhileCondition, WhileConditionStart,
  266. CARBON_TOKEN(CloseParen))
  267. CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileStatement, 2, CARBON_TOKEN(While))
  268. // Index expressions, such as `a[1]`:
  269. // _external_: expression
  270. // IndexExpressionStart
  271. // _external_: expression
  272. // IndexExpression
  273. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IndexExpressionStart, 1,
  274. CARBON_TOKEN(OpenSquareBracket))
  275. CARBON_PARSE_NODE_KIND_BRACKET(IndexExpression, IndexExpressionStart,
  276. CARBON_TOKEN(CloseSquareBracket))
  277. // Parenthesized expressions, such as `(2)`:
  278. // ParenExpressionOrTupleLiteralStart
  279. // _external_: expression
  280. // ParenExpression
  281. //
  282. // Tuples, such as `(1, 2)`:
  283. // ParenExpressionOrTupleLiteralStart
  284. // _external_: expression
  285. // TupleLiteralComma
  286. // TupleLiteral
  287. //
  288. // Expressions and TupleLiteralComma may repeat with TupleLiteralComma as a
  289. // separator.
  290. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParenExpressionOrTupleLiteralStart, 0,
  291. CARBON_TOKEN(OpenParen))
  292. CARBON_PARSE_NODE_KIND_BRACKET(ParenExpression,
  293. ParenExpressionOrTupleLiteralStart,
  294. CARBON_TOKEN(CloseParen))
  295. CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteralComma, 0, CARBON_TOKEN(Comma))
  296. CARBON_PARSE_NODE_KIND_BRACKET(TupleLiteral, ParenExpressionOrTupleLiteralStart,
  297. CARBON_TOKEN(CloseParen))
  298. // Call expressions, such as `a()`:
  299. // _external_: expression
  300. // CallExpressionStart
  301. // _external_: expression
  302. // CallExpressionComma
  303. // CallExpression
  304. //
  305. // Expressions and CallExpressionComma may repeat with CallExpressionComma as a
  306. // separator.
  307. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpressionStart, 1,
  308. CARBON_TOKEN(OpenParen))
  309. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpressionComma, 0, CARBON_TOKEN(Comma))
  310. CARBON_PARSE_NODE_KIND_BRACKET(CallExpression, CallExpressionStart,
  311. CARBON_TOKEN(CloseParen))
  312. // A qualified declaration, such as `a.b`:
  313. // _external_: NameExpression or QualifiedDeclaration
  314. // _external_: Name
  315. // QualifiedDeclaration
  316. //
  317. // TODO: This will eventually more general expressions, for example with
  318. // `GenericType(type_args).ChildType(child_type_args).Name`.
  319. CARBON_PARSE_NODE_KIND_CHILD_COUNT(QualifiedDeclaration, 2,
  320. CARBON_TOKEN(Period))
  321. // A member access expression, such as `a.b` or
  322. // `GetObject().(Interface.member)`:
  323. // _external_: lhs expression
  324. // _external_: rhs expression
  325. // QualifiedExpression
  326. CARBON_PARSE_NODE_KIND_CHILD_COUNT(MemberAccessExpression, 2,
  327. CARBON_TOKEN(Period))
  328. // A pointer member access expression, such as `a->b` or
  329. // `GetObject()->(Interface.member)`:
  330. // _external_: lhs expression
  331. // _external_: rhs expression
  332. // QualifiedExpression
  333. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PointerMemberAccessExpression, 2,
  334. CARBON_TOKEN(MinusGreater))
  335. // clang-format off
  336. // A literal.
  337. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Literal, 0,
  338. CARBON_TOKEN(False)
  339. CARBON_TOKEN(True)
  340. CARBON_TOKEN(IntegerLiteral)
  341. CARBON_TOKEN(RealLiteral)
  342. CARBON_TOKEN(StringLiteral)
  343. CARBON_TOKEN(Bool)
  344. CARBON_TOKEN(IntegerTypeLiteral)
  345. CARBON_TOKEN(UnsignedIntegerTypeLiteral)
  346. CARBON_TOKEN(FloatingPointTypeLiteral)
  347. CARBON_TOKEN(StringTypeLiteral)
  348. CARBON_TOKEN(Type))
  349. // A prefix operator:
  350. // _external_: expression
  351. // PrefixOperator
  352. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PrefixOperator, 1,
  353. CARBON_TOKEN(Star)
  354. CARBON_TOKEN(Amp)
  355. CARBON_TOKEN(Not)
  356. CARBON_TOKEN(Minus)
  357. CARBON_TOKEN(MinusMinus)
  358. CARBON_TOKEN(PlusPlus)
  359. CARBON_TOKEN(Caret)
  360. CARBON_TOKEN(Const))
  361. // An infix operator:
  362. // _external_: lhs expression
  363. // _external_: rhs expression
  364. // InfixOperator
  365. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InfixOperator, 2,
  366. CARBON_TOKEN(Amp)
  367. CARBON_TOKEN(AmpEqual)
  368. CARBON_TOKEN(And)
  369. CARBON_TOKEN(As)
  370. CARBON_TOKEN(Caret)
  371. CARBON_TOKEN(CaretEqual)
  372. CARBON_TOKEN(Equal)
  373. CARBON_TOKEN(EqualEqual)
  374. CARBON_TOKEN(ExclaimEqual)
  375. CARBON_TOKEN(Greater)
  376. CARBON_TOKEN(GreaterEqual)
  377. CARBON_TOKEN(GreaterGreater)
  378. CARBON_TOKEN(GreaterGreaterEqual)
  379. CARBON_TOKEN(Less)
  380. CARBON_TOKEN(LessEqual)
  381. CARBON_TOKEN(LessLess)
  382. CARBON_TOKEN(LessLessEqual)
  383. CARBON_TOKEN(Minus)
  384. CARBON_TOKEN(MinusEqual)
  385. CARBON_TOKEN(Or)
  386. CARBON_TOKEN(Percent)
  387. CARBON_TOKEN(PercentEqual)
  388. CARBON_TOKEN(Pipe)
  389. CARBON_TOKEN(PipeEqual)
  390. CARBON_TOKEN(Plus)
  391. CARBON_TOKEN(PlusEqual)
  392. CARBON_TOKEN(Slash)
  393. CARBON_TOKEN(SlashEqual)
  394. CARBON_TOKEN(Star)
  395. CARBON_TOKEN(StarEqual))
  396. // clang-format on
  397. // The first operand of a short-circuiting infix operator:
  398. // _external_: expression
  399. // ShortCircuitOperand
  400. // _external_: expression
  401. // _external_: InfixOperator
  402. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ShortCircuitOperand, 1,
  403. CARBON_TOKEN(And) CARBON_TOKEN(Or))
  404. // A postfix operator:
  405. // _external_: expression
  406. // PostfixOperator
  407. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PostfixOperator, 1, CARBON_TOKEN(Star))
  408. // `if` expression + `then` + `else`:
  409. // _external_: expression
  410. // IfExpressionIf
  411. // _external_: expression
  412. // IfExpressionThen
  413. // _external_: expression
  414. // IfExpressionElse
  415. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExpressionIf, 1, CARBON_TOKEN(If))
  416. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExpressionThen, 1, CARBON_TOKEN(Then))
  417. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExpressionElse, 3,
  418. CARBON_TOKEN(Else)
  419. CARBON_IF_ERROR(CARBON_TOKEN(If)))
  420. // Struct literals, such as `{.a = 0}`:
  421. // StructLiteralOrStructTypeLiteralStart
  422. // _external_: Name
  423. // StructFieldDesignator
  424. // _external_: expression
  425. // StructFieldValue
  426. // StructComma
  427. // StructLiteral
  428. //
  429. // Struct type literals, such as `{.a: i32}`:
  430. // _external_: Name
  431. // StructFieldDesignator
  432. // _external_: type expression
  433. // StructFieldType
  434. // StructComma
  435. // StructTypeLiteral
  436. //
  437. // Elements (StructFieldValue and StructFieldType, respectively) and StructComma
  438. // may repeat with StructComma as a separator.
  439. //
  440. // When a valid StructFieldType or StructFieldValue cannot be formed, elements
  441. // may be replaced by StructFieldUnknown, which may have a preceding sibling
  442. // StructFieldDesignator if one was successfully parsed.
  443. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructLiteralOrStructTypeLiteralStart, 0,
  444. CARBON_TOKEN(OpenCurlyBrace))
  445. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldDesignator, 1,
  446. CARBON_TOKEN(Period))
  447. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldValue, 2, CARBON_TOKEN(Equal))
  448. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldType, 2, CARBON_TOKEN(Colon))
  449. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldUnknown, 0,
  450. CARBON_IF_ERROR(CARBON_ANY_TOKEN))
  451. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructComma, 0, CARBON_TOKEN(Comma))
  452. CARBON_PARSE_NODE_KIND_BRACKET(StructLiteral,
  453. StructLiteralOrStructTypeLiteralStart,
  454. CARBON_TOKEN(CloseCurlyBrace))
  455. CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral,
  456. StructLiteralOrStructTypeLiteralStart,
  457. CARBON_TOKEN(CloseCurlyBrace))
  458. // `class`:
  459. // ClassIntroducer
  460. // _external_: Name or QualifiedDeclaration
  461. // ClassDefinitionStart
  462. // _external_: declarations
  463. // ClassDefinition
  464. //
  465. // The above is the structure for a definition; for a declaration,
  466. // ClassDefinitionStart and later nodes are removed and replaced by
  467. // ClassDeclaration.
  468. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ClassIntroducer, 0, CARBON_TOKEN(Class))
  469. CARBON_PARSE_NODE_KIND_BRACKET(ClassDefinitionStart, ClassIntroducer,
  470. CARBON_TOKEN(OpenCurlyBrace))
  471. CARBON_PARSE_NODE_KIND_BRACKET(ClassDefinition, ClassDefinitionStart,
  472. CARBON_TOKEN(CloseCurlyBrace))
  473. CARBON_PARSE_NODE_KIND_BRACKET(ClassDeclaration, ClassIntroducer,
  474. CARBON_TOKEN(Semi)
  475. CARBON_IF_ERROR(CARBON_TOKEN(Class)))
  476. // `interface`:
  477. // InterfaceIntroducer
  478. // _external_: Name or QualifiedDeclaration
  479. // InterfaceDefinitionStart
  480. // _external_: declarations
  481. // InterfaceDefinition
  482. //
  483. // The above is the structure for a definition; for a declaration,
  484. // InterfaceDefinitionStart and later nodes are removed and replaced by
  485. // InterfaceDeclaration.
  486. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceIntroducer, 0,
  487. CARBON_TOKEN(Interface))
  488. CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinitionStart, InterfaceIntroducer,
  489. CARBON_TOKEN(OpenCurlyBrace))
  490. CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinition, InterfaceDefinitionStart,
  491. CARBON_TOKEN(CloseCurlyBrace))
  492. CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDeclaration, InterfaceIntroducer,
  493. CARBON_TOKEN(Semi)
  494. CARBON_IF_ERROR(CARBON_TOKEN(Interface)))
  495. // `constraint`:
  496. // NamedConstraintIntroducer
  497. // _external_: Name or QualifiedDeclaration
  498. // NamedConstraintDefinitionStart
  499. // _external_: declarations
  500. // NamedConstraintDefinition
  501. //
  502. // The above is the structure for a definition; for a declaration,
  503. // NamedConstraintDefinitionStart and later nodes are removed and replaced by
  504. // NamedConstraintDeclaration.
  505. CARBON_PARSE_NODE_KIND_CHILD_COUNT(NamedConstraintIntroducer, 0,
  506. CARBON_TOKEN(Constraint))
  507. CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDefinitionStart,
  508. NamedConstraintIntroducer,
  509. CARBON_TOKEN(OpenCurlyBrace))
  510. CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDefinition,
  511. NamedConstraintDefinitionStart,
  512. CARBON_TOKEN(CloseCurlyBrace))
  513. CARBON_PARSE_NODE_KIND_BRACKET(NamedConstraintDeclaration,
  514. NamedConstraintIntroducer, CARBON_TOKEN(Semi))
  515. // The `self` value and `Self` type identifier keywords. Typically of the form
  516. // `self: Self`:
  517. // SelfValueName
  518. // SelfTypeNameExpression
  519. // PatternBinding
  520. CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfValueName, 0,
  521. CARBON_TOKEN(SelfValueIdentifier))
  522. CARBON_PARSE_NODE_KIND_CHILD_COUNT(SelfTypeNameExpression, 0,
  523. CARBON_TOKEN(SelfTypeIdentifier))
  524. #undef CARBON_PARSE_NODE_KIND
  525. #undef CARBON_PARSE_NODE_KIND_BRACKET
  526. #undef CARBON_PARSE_NODE_KIND_CHILD_COUNT
  527. #undef CARBON_TOKEN
  528. #undef CARBON_ANY_TOKEN
  529. #undef CARBON_IF_ERROR