node_stack.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include "toolchain/check/node_stack.h"
  5. #include "llvm/ADT/STLExtras.h"
  6. namespace Carbon::Check {
  7. auto NodeStack::PrintForStackDump(llvm::raw_ostream& output) const -> void {
  8. auto print_id = [&]<Id::Kind Kind>(Id id) {
  9. if constexpr (Kind == Id::Kind::None) {
  10. output << " -> no value";
  11. } else if constexpr (Kind == Id::Kind::Invalid) {
  12. CARBON_FATAL() << "Should not be in node stack";
  13. } else {
  14. output << " -> " << id.As<Kind>();
  15. }
  16. };
  17. output << "NodeStack:\n";
  18. for (auto [i, entry] : llvm::enumerate(stack_)) {
  19. auto node_kind = parse_tree_->node_kind(entry.node_id);
  20. output << "\t" << i << ".\t" << node_kind;
  21. switch (node_kind) {
  22. #define CARBON_PARSE_NODE_KIND(Kind) \
  23. case Parse::NodeKind::Kind: \
  24. print_id.operator()<NodeKindToIdKind(Parse::NodeKind::Kind)>(entry.id); \
  25. break;
  26. #include "toolchain/parse/node_kind.def"
  27. }
  28. output << "\n";
  29. }
  30. }
  31. } // namespace Carbon::Check