parse_node_kind.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #ifndef CARBON_TOOLCHAIN_PARSER_PARSE_NODE_KIND_H_
  5. #define CARBON_TOOLCHAIN_PARSER_PARSE_NODE_KIND_H_
  6. #include <cstdint>
  7. #include "common/enum_base.h"
  8. namespace Carbon {
  9. CARBON_DEFINE_RAW_ENUM_CLASS(ParseNodeKind, uint8_t) {
  10. #define CARBON_PARSE_NODE_KIND(Name) CARBON_RAW_ENUM_ENUMERATOR(Name)
  11. #include "toolchain/parser/parse_node_kind.def"
  12. };
  13. // A class wrapping an enumeration of the different kinds of nodes in the parse
  14. // tree.
  15. class ParseNodeKind : public CARBON_ENUM_BASE(ParseNodeKind) {
  16. public:
  17. #define CARBON_PARSE_NODE_KIND(Name) CARBON_ENUM_CONSTANT_DECLARATION(Name)
  18. #include "toolchain/parser/parse_node_kind.def"
  19. // Returns true if the node is bracketed; otherwise, child_count is used.
  20. auto has_bracket() const -> bool;
  21. // Returns the bracketing node kind for the current node kind. Requires that
  22. // has_bracket is true.
  23. auto bracket() const -> ParseNodeKind;
  24. // Returns the number of children that the node must have, often 0. Requires
  25. // that has_bracket is false.
  26. auto child_count() const -> int32_t;
  27. using EnumBase::Create;
  28. };
  29. #define CARBON_PARSE_NODE_KIND(Name) \
  30. CARBON_ENUM_CONSTANT_DEFINITION(ParseNodeKind, Name)
  31. #include "toolchain/parser/parse_node_kind.def"
  32. // We expect the parse node kind to fit compactly into 8 bits.
  33. static_assert(sizeof(ParseNodeKind) == 1, "Kind objects include padding!");
  34. } // namespace Carbon
  35. #endif // CARBON_TOOLCHAIN_PARSER_PARSE_NODE_KIND_H_