node_stack.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 parse_node_kind = parse_tree_->node_kind(entry.parse_node);
  20. output << "\t" << i << ".\t" << parse_node_kind;
  21. switch (parse_node_kind) {
  22. #define CARBON_PARSE_NODE_KIND(Kind) \
  23. case Parse::NodeKind::Kind: \
  24. print_id.operator()<ParseNodeKindToIdKind(Parse::NodeKind::Kind)>( \
  25. entry.id); \
  26. break;
  27. #include "toolchain/parse/node_kind.def"
  28. }
  29. output << "\n";
  30. }
  31. }
  32. } // namespace Carbon::Check