Files
carbon-lang/toolchain/lex/dump.cpp
T
Chandler Carruth f58de06c0d parse, lex: Decompose AST extraction and forward-declare dump types (#7645)
- 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
2026-08-17 17:39:42 +00:00

42 lines
1.0 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/lex/dump.h"
#include <string>
#include "common/raw_string_ostream.h"
#include "toolchain/lex/tokenized_buffer.h"
namespace Carbon::Lex {
static LLVM_DUMP_METHOD auto Dump(const TokenizedBuffer& tokens)
-> std::string {
return PrintToString(tokens);
}
LLVM_DUMP_METHOD auto Dump(const TokenizedBuffer& tokens, TokenIndex token)
-> std::string {
RawStringOstream out;
if (!token.has_value()) {
out << "TokenIndex(<none>)";
return out.TakeStr();
}
auto kind = tokens.GetKind(token);
auto line = tokens.GetLineNumber(token);
auto col = tokens.GetColumnNumber(token);
out << "TokenIndex(kind: " << kind
<< ", loc: " << FormatEscaped(tokens.source().filename()) << ":" << line
<< ":" << col << ")";
return out.TakeStr();
}
} // namespace Carbon::Lex
#endif // NDEBUG