parse_node_kind.def 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // Note that this is an X-macro header.
  6. //
  7. // It does not use `#include` guards, and instead is designed to be `#include`ed
  8. // after the x-macro is defined in order for its inclusion to expand to the
  9. // desired output.
  10. //
  11. // x-macros come in three forms:
  12. // CARBON_PARSE_NODE_KIND(Name)
  13. // Used as a fallback if other macros are missing.
  14. // CARBON_PARSE_NODE_KIND_BRACKET(Name, BracketName)
  15. // Defines a bracketed node kind. BracketName should refer to the node kind
  16. // that is the _start_ of the bracketed range.
  17. // CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ChildCount)
  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. // Macro definitions will be removed at the end of this file to clean up.
  22. //
  23. // TODO: Using CHILD_COUNT(..., TodoFixParseNode) to indicate nodes which need to be fixed,
  24. // sometimes due to inconsistent output in error modes. This is also handled in
  25. // ParseNodeKind::child_count() and ParseTree::Verify(). All of that can be
  26. // cleaned up once remainining nodes are fixed.
  27. #if !(defined(CARBON_PARSE_NODE_KIND) || \
  28. (defined(CARBON_PARSE_NODE_KIND_BRACKET) && \
  29. defined(CARBON_PARSE_NODE_KIND_CHILD_COUNT)))
  30. #error "Must define CARBON_PARSE_NODE_KIND family x-macros to use this file."
  31. #endif
  32. // The BRACKET and CHILD_COUNT macros will use CARBON_PARSE_NODE_KIND by default
  33. // when undefined.
  34. #ifndef CARBON_PARSE_NODE_KIND_BRACKET
  35. #define CARBON_PARSE_NODE_KIND_BRACKET(Name, ...) CARBON_PARSE_NODE_KIND(Name)
  36. #endif
  37. #ifndef CARBON_PARSE_NODE_KIND_CHILD_COUNT
  38. #define CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ...) \
  39. CARBON_PARSE_NODE_KIND(Name)
  40. #endif
  41. // Declarations.
  42. CARBON_PARSE_NODE_KIND_CHILD_COUNT(DeclarationEnd, 0)
  43. CARBON_PARSE_NODE_KIND_CHILD_COUNT(EmptyDeclaration, 0)
  44. CARBON_PARSE_NODE_KIND_CHILD_COUNT(DeclaredName, 0)
  45. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageDirective, TodoFixParseNode)
  46. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageApi, 0)
  47. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageImpl, 0)
  48. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageLibrary, 1)
  49. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageEnd, 0)
  50. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FunctionIntroducer, 0)
  51. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDeclaration, FunctionIntroducer)
  52. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinition, FunctionDefinitionStart)
  53. CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinitionStart, FunctionIntroducer)
  54. CARBON_PARSE_NODE_KIND_BRACKET(ParameterList, ParameterListStart)
  55. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListStart, 0)
  56. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListComma, 0)
  57. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PatternBinding, 2)
  58. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnType, 1)
  59. CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableDeclaration, TodoFixParseNode)
  60. CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableInitializer, 1)
  61. CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileEnd, 0)
  62. // Statements.
  63. CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart)
  64. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CodeBlockStart, 0)
  65. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ExpressionStatement, 1)
  66. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfStatement, TodoFixParseNode)
  67. CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfStatementElse, 0)
  68. CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileStatement, TodoFixParseNode)
  69. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Condition, TodoFixParseNode)
  70. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ConditionEnd, 0)
  71. CARBON_PARSE_NODE_KIND_BRACKET(ContinueStatement, ContinueStatementStart)
  72. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatementStart, 0)
  73. CARBON_PARSE_NODE_KIND_BRACKET(BreakStatement, BreakStatementStart)
  74. CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatementStart, 0)
  75. CARBON_PARSE_NODE_KIND_BRACKET(ReturnStatement, ReturnStatementStart)
  76. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnStatementStart, 0)
  77. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForStatement, TodoFixParseNode)
  78. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForHeader, TodoFixParseNode)
  79. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForHeaderEnd, 0)
  80. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForIn, 0)
  81. // Expressions.
  82. CARBON_PARSE_NODE_KIND_CHILD_COUNT(Literal, 0)
  83. CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteral, TodoFixParseNode)
  84. CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteralComma, 0)
  85. CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteralEnd, 0)
  86. CARBON_PARSE_NODE_KIND_CHILD_COUNT(NameReference, 0)
  87. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParenExpression, TodoFixParseNode)
  88. CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParenExpressionEnd, 0)
  89. CARBON_PARSE_NODE_KIND_CHILD_COUNT(DesignatorExpression, TodoFixParseNode)
  90. CARBON_PARSE_NODE_KIND_CHILD_COUNT(DesignatedName, 0)
  91. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpression, TodoFixParseNode)
  92. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpressionComma, 0)
  93. CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpressionEnd, 0)
  94. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PrefixOperator, 1)
  95. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InfixOperator, 2)
  96. CARBON_PARSE_NODE_KIND_CHILD_COUNT(PostfixOperator, 1)
  97. // Struct literals.
  98. CARBON_PARSE_NODE_KIND_BRACKET(StructLiteral,
  99. StructLiteralOrStructTypeLiteralStart)
  100. CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral,
  101. StructLiteralOrStructTypeLiteralStart)
  102. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructLiteralOrStructTypeLiteralStart, 0)
  103. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldDesignator, TodoFixParseNode)
  104. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldValue, TodoFixParseNode)
  105. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldType, TodoFixParseNode)
  106. CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructComma, 0)
  107. // Interfaces
  108. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceDefinition, TodoFixParseNode)
  109. CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceBodyStart, 0)
  110. CARBON_PARSE_NODE_KIND_BRACKET(InterfaceBody, InterfaceBodyStart)
  111. #undef CARBON_PARSE_NODE_KIND
  112. #undef CARBON_PARSE_NODE_KIND_BRACKET
  113. #undef CARBON_PARSE_NODE_KIND_CHILD_COUNT