mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
- Enhance toolchain/parse/node_kind.def with category x-macros (CARBON_PARSE_NODE_KIND_DECLARATION, CARBON_PARSE_NODE_KIND_EXPRESSION, CARBON_PARSE_NODE_KIND_PATTERN, CARBON_PARSE_NODE_KIND_STATEMENT) that default to CARBON_PARSE_NODE_KIND, keeping node_kind.def as the single source of truth without manual expansion divergence. - Decompose the monolithic toolchain/parse/extract.cpp translation unit into separate compilation units for declarations, expressions, patterns, and statements by expanding respective category x-macros. - Forward-declare Tree and TokenizedBuffer in parse and lex dump headers to reduce header inclusion depth. Assisted-by: Antigravity with Gemini
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#include "toolchain/parse/dump.h"
|
|
|
|
#include <string>
|
|
|
|
#include "common/raw_string_ostream.h"
|
|
#include "toolchain/lex/dump.h"
|
|
#include "toolchain/parse/context.h"
|
|
#include "toolchain/parse/tree.h"
|
|
|
|
namespace Carbon::Parse {
|
|
|
|
static LLVM_DUMP_METHOD auto Dump(const Tree& tree) -> std::string {
|
|
return PrintToString(tree);
|
|
}
|
|
|
|
LLVM_DUMP_METHOD auto Dump(const Tree& tree, Lex::TokenIndex token)
|
|
-> std::string {
|
|
return Lex::Dump(tree.tokens(), token);
|
|
}
|
|
|
|
LLVM_DUMP_METHOD auto Dump(const Tree& tree, NodeId node_id) -> std::string {
|
|
RawStringOstream out;
|
|
if (!node_id.has_value()) {
|
|
out << "NodeId(<none>)";
|
|
return out.TakeStr();
|
|
}
|
|
|
|
auto kind = tree.node_kind(node_id);
|
|
auto token = tree.node_token(node_id);
|
|
|
|
out << "NodeId(kind: " << kind
|
|
<< ", token: " << Lex::Dump(tree.tokens(), token) << ")";
|
|
return out.TakeStr();
|
|
}
|
|
|
|
static LLVM_DUMP_METHOD auto Dump(const Context& context, Lex::TokenIndex token)
|
|
-> std::string {
|
|
return Dump(context.tree(), token);
|
|
}
|
|
|
|
static LLVM_DUMP_METHOD auto Dump(const Context& context, NodeId node_id)
|
|
-> std::string {
|
|
return Dump(context.tree(), node_id);
|
|
}
|
|
|
|
} // namespace Carbon::Parse
|
|
|
|
#endif // NDEBUG
|