mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Because this is an `__attribute__((used))` method in a templated base class it forces a _huge_ amount of template instantiation in every translation unit. Often this was just printing the members of the type, which is still useful in some cases (such as test output), but adds no value in the debugger. A more successful pattern for dumping has been namespace level functions, and particularly static ones that more transparently don't expand the non-debugger API surface. Add the few missing functions there that cover `Printable` types with more interesting contents. For several of these, it just gives us a "dump the whole thing" function as a compliment to "dump this entity in the thing". These probably aren't especially high value, but moving them here they become cheap, so I've left them in. For a couple, this expands the rich dumping support of SemIR constructs, which should be substantially more useful than the previous `Dump` behavior. This reduces `check` cumulative object file size by another 14%. Assisted-by: Antigravity with Gemini
41 lines
1003 B
C++
41 lines
1003 B
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"
|
|
|
|
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
|