From 8480a0bbd6a5e6ed5f07b59425e911dca7e9f96a Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Wed, 30 Nov 2022 10:24:09 -0800 Subject: [PATCH] Fix a couple debug output issues (#2415) Make `.run` targets include symbol information, and include token names on CHECK output in more places. --- bazel/sh_run/rules.bzl | 3 +++ toolchain/lexer/tokenized_buffer.cpp | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bazel/sh_run/rules.bzl b/bazel/sh_run/rules.bzl index 30b418313d9c..9b3c94af97bd 100644 --- a/bazel/sh_run/rules.bzl +++ b/bazel/sh_run/rules.bzl @@ -4,6 +4,8 @@ """Rules for building fuzz tests.""" +load("//bazel/cc_toolchains:defs.bzl", "cc_env") + def sh_run(name, args, **kwargs): """Produces a target which can run with the given args.""" @@ -27,5 +29,6 @@ def glob_sh_run(file_exts, args, data, run_ext = "run", **kwargs): name = "%s.%s" % (f, run_ext), args = args + ["$(location %s)" % f], data = data + [f], + env = cc_env(), **kwargs ) diff --git a/toolchain/lexer/tokenized_buffer.cpp b/toolchain/lexer/tokenized_buffer.cpp index a711ea0d6ac6..266bc673f3ed 100644 --- a/toolchain/lexer/tokenized_buffer.cpp +++ b/toolchain/lexer/tokenized_buffer.cpp @@ -653,14 +653,14 @@ auto TokenizedBuffer::GetTokenText(Token token) const -> llvm::StringRef { } CARBON_CHECK(token_info.kind == TokenKind::Identifier()) - << "Only identifiers have stored text!"; + << token_info.kind.Name(); return GetIdentifierText(token_info.id); } auto TokenizedBuffer::GetIdentifier(Token token) const -> Identifier { const auto& token_info = GetTokenInfo(token); CARBON_CHECK(token_info.kind == TokenKind::Identifier()) - << "The token must be an identifier!"; + << token_info.kind.Name(); return token_info.id; } @@ -668,14 +668,14 @@ auto TokenizedBuffer::GetIntegerLiteral(Token token) const -> const llvm::APInt& { const auto& token_info = GetTokenInfo(token); CARBON_CHECK(token_info.kind == TokenKind::IntegerLiteral()) - << "The token must be an integer literal!"; + << token_info.kind.Name(); return literal_int_storage_[token_info.literal_index]; } auto TokenizedBuffer::GetRealLiteral(Token token) const -> RealLiteralValue { const auto& token_info = GetTokenInfo(token); CARBON_CHECK(token_info.kind == TokenKind::RealLiteral()) - << "The token must be a real literal!"; + << token_info.kind.Name(); // Note that every real literal is at least three characters long, so we can // safely look at the second character to determine whether we have a @@ -691,15 +691,14 @@ auto TokenizedBuffer::GetRealLiteral(Token token) const -> RealLiteralValue { auto TokenizedBuffer::GetStringLiteral(Token token) const -> llvm::StringRef { const auto& token_info = GetTokenInfo(token); CARBON_CHECK(token_info.kind == TokenKind::StringLiteral()) - << "The token must be a string literal!"; + << token_info.kind.Name(); return literal_string_storage_[token_info.literal_index]; } auto TokenizedBuffer::GetTypeLiteralSize(Token token) const -> const llvm::APInt& { const auto& token_info = GetTokenInfo(token); - CARBON_CHECK(token_info.kind.IsSizedTypeLiteral()) - << "The token must be a sized type literal!"; + CARBON_CHECK(token_info.kind.IsSizedTypeLiteral()) << token_info.kind.Name(); return literal_int_storage_[token_info.literal_index]; } @@ -707,7 +706,7 @@ auto TokenizedBuffer::GetMatchedClosingToken(Token opening_token) const -> Token { const auto& opening_token_info = GetTokenInfo(opening_token); CARBON_CHECK(opening_token_info.kind.IsOpeningSymbol()) - << "The token must be an opening group symbol!"; + << opening_token_info.kind.Name(); return opening_token_info.closing_token; } @@ -715,7 +714,7 @@ auto TokenizedBuffer::GetMatchedOpeningToken(Token closing_token) const -> Token { const auto& closing_token_info = GetTokenInfo(closing_token); CARBON_CHECK(closing_token_info.kind.IsClosingSymbol()) - << "The token must be an closing group symbol!"; + << closing_token_info.kind.Name(); return closing_token_info.opening_token; }