Pārlūkot izejas kodu

Replace assert with CHECK (#1098)

Jon Meow 4 gadi atpakaļ
vecāks
revīzija
eecf4a34b3

+ 3 - 0
toolchain/lexer/BUILD

@@ -65,6 +65,7 @@ cc_test(
     deps = [
         ":numeric_literal",
         ":test_helpers",
+        "//common:check",
         "//common:ostream",
         "//toolchain/diagnostics:diagnostic_emitter",
         "@com_google_googletest//:gtest_main",
@@ -117,6 +118,7 @@ cc_test(
     deps = [
         ":string_literal",
         ":test_helpers",
+        "//common:check",
         "//common:ostream",
         "//toolchain/diagnostics:diagnostic_emitter",
         "@com_google_googletest//:gtest_main",
@@ -160,6 +162,7 @@ cc_library(
     hdrs = ["tokenized_buffer_test_helpers.h"],
     deps = [
         ":tokenized_buffer",
+        "//common:check",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],

+ 2 - 1
toolchain/lexer/numeric_literal_test.cpp

@@ -11,6 +11,7 @@
 #include <memory>
 #include <vector>
 
+#include "common/check.h"
 #include "common/ostream.h"
 #include "toolchain/diagnostics/diagnostic_emitter.h"
 #include "toolchain/lexer/test_helpers.h"
@@ -30,7 +31,7 @@ class NumericLiteralTest : public ::testing::Test {
 
   auto Lex(llvm::StringRef text) -> LexedNumericLiteral {
     llvm::Optional<LexedNumericLiteral> result = LexedNumericLiteral::Lex(text);
-    assert(result);
+    CHECK(result);
     EXPECT_EQ(result->Text(), text);
     return *result;
   }

+ 2 - 1
toolchain/lexer/string_literal_test.cpp

@@ -7,6 +7,7 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+#include "common/check.h"
 #include "common/ostream.h"
 #include "toolchain/diagnostics/diagnostic_emitter.h"
 #include "toolchain/lexer/test_helpers.h"
@@ -20,7 +21,7 @@ class StringLiteralTest : public ::testing::Test {
 
   auto Lex(llvm::StringRef text) -> LexedStringLiteral {
     llvm::Optional<LexedStringLiteral> result = LexedStringLiteral::Lex(text);
-    assert(result);
+    CHECK(result);
     EXPECT_EQ(result->Text(), text);
     return *result;
   }

+ 6 - 6
toolchain/lexer/tokenized_buffer.cpp

@@ -169,7 +169,7 @@ class TokenizedBuffer::Lexer {
         default:
           // If we find a non-whitespace character without exhausting the
           // buffer, return true to continue lexing.
-          assert(!IsSpace(source_text.front()));
+          CHECK(!IsSpace(source_text.front()));
           if (whitespace_start != source_text.begin()) {
             NoteWhitespace();
           }
@@ -243,8 +243,8 @@ class TokenizedBuffer::Lexer {
               buffer_.literal_int_storage_.size();
           buffer_.literal_int_storage_.push_back(std::move(value.mantissa));
           buffer_.literal_int_storage_.push_back(std::move(value.exponent));
-          assert(buffer_.GetRealLiteral(token).IsDecimal() ==
-                 (value.radix == 10));
+          CHECK(buffer_.GetRealLiteral(token).IsDecimal() ==
+                (value.radix == 10));
           return token;
         },
         [&](LexedNumericLiteral::UnrecoverableError) {
@@ -876,9 +876,9 @@ auto TokenizedBuffer::TokenIterator::Print(llvm::raw_ostream& output) const
 
 auto TokenizedBuffer::SourceBufferLocationTranslator::GetLocation(
     const char* loc) -> Diagnostic::Location {
-  assert(llvm::is_sorted(std::array{buffer_->source_->Text().begin(), loc,
-                                    buffer_->source_->Text().end()}) &&
-         "location not within buffer");
+  CHECK(llvm::is_sorted(std::array{buffer_->source_->Text().begin(), loc,
+                                   buffer_->source_->Text().end()}))
+      << "location not within buffer";
   int64_t offset = loc - buffer_->source_->Text().begin();
 
   // Find the first line starting after the given location. Note that we can't

+ 3 - 2
toolchain/lexer/tokenized_buffer_test_helpers.h

@@ -7,6 +7,7 @@
 
 #include <gmock/gmock.h>
 
+#include "common/check.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/YAMLParser.h"
@@ -130,8 +131,8 @@ MATCHER_P(HasTokens, raw_all_expected, "") {
       matches = false;
     }
 
-    assert(!expected.string_contents ||
-           expected.kind == TokenKind::StringLiteral());
+    CHECK(!expected.string_contents ||
+          expected.kind == TokenKind::StringLiteral());
     if (expected.string_contents && actual_kind == TokenKind::StringLiteral()) {
       llvm::StringRef actual_contents = buffer.GetStringLiteral(token);
       if (actual_contents != *expected.string_contents) {

+ 1 - 1
toolchain/parser/parser_impl.cpp

@@ -1216,7 +1216,7 @@ auto ParseTree::Parser::ParseKeywordStatement(ParseNodeKind kind,
     -> llvm::Optional<Node> {
   RETURN_IF_STACK_LIMITED(llvm::None);
   auto keyword_kind = NextTokenKind();
-  assert(keyword_kind.IsKeyword());
+  CHECK(keyword_kind.IsKeyword());
 
   auto start = GetSubtreeStartPosition();
   auto keyword = Consume(keyword_kind);