Change TokenKind's Print overload to a format_provider. (#2534)

Fundamentally this `.Print()` is wrong for debug output at present because `.fixed_spelling()` can be empty. It's also inconsistent with other enums to use it. We frequently print tokens for debugging, and it's easy to forget to specify `.name()` there.

Diagnostics use formatv, so we can provide a format_provider and address it in one spot that way. It also makes it harder to just forget to do the right thing.
This commit is contained in:
Jon Ross-Perkins
2023-01-18 12:20:56 -08:00
committed by GitHub
parent b936bf9e04
commit 94872ef6da
9 changed files with 36 additions and 37 deletions
+4 -4
View File
@@ -77,8 +77,8 @@ class Parser::PrettyStackTraceParseState : public llvm::PrettyStackTraceEntry {
auto line = parser_->tokens_->GetLine(token);
output << " @ " << parser_->tokens_->GetLineNumber(line) << ":"
<< parser_->tokens_->GetColumnNumber(token) << ":"
<< " token " << token << " : "
<< parser_->tokens_->GetKind(token).name() << "\n";
<< " token " << token << " : " << parser_->tokens_->GetKind(token)
<< "\n";
}
const Parser* parser_;
@@ -97,7 +97,7 @@ Parser::Parser(ParseTree& tree, TokenizedBuffer& tokens,
--end_;
CARBON_CHECK(tokens_->GetKind(*end_) == TokenKind::EndOfFile)
<< "TokenizedBuffer should end with EndOfFile, ended with "
<< tokens_->GetKind(*end_).name();
<< tokens_->GetKind(*end_);
}
auto Parser::AddLeafNode(ParseNodeKind kind, TokenizedBuffer::Token token,
@@ -164,7 +164,7 @@ auto Parser::ConsumeAndAddLeafNodeIf(TokenKind token_kind,
auto Parser::ConsumeChecked(TokenKind kind) -> TokenizedBuffer::Token {
CARBON_CHECK(PositionIs(kind))
<< "Required " << kind.name() << ", found " << PositionKind().name();
<< "Required " << kind << ", found " << PositionKind();
return Consume();
}