diff options
author | Krzysztof Kosiński <krzysio@google.com> | 2022-11-09 01:42:45 +0000 |
---|---|---|
committer | Krzysztof Kosiński <krzysio@google.com> | 2022-11-09 01:44:02 +0000 |
commit | 5b1e2804b43c9be30c098fe6df9ded88d7058a1e (patch) | |
tree | 39cecf39ce96c1278d07d693dfd479c45defca1f | |
parent | fd98e22a59d339148d9b68c6339fbf69157a82c9 (diff) | |
download | kythe-5b1e2804b43c9be30c098fe6df9ded88d7058a1e.tar.gz |
Replace google::protobuf::string with std::string.
google::protobuf::string has been removed in recent releases of
Protocol Buffers library.
Bug: 203713560
Test: OUT_DIR=out prebuilts/clang-tools/build-prebuilts.sh
Change-Id: I813648da19aa6e892a81a3f326cd42257f162657
-rw-r--r-- | kythe/cxx/common/kythe_metadata_file.cc | 6 | ||||
-rw-r--r-- | kythe/cxx/extractor/testdata/claim_pragma_test.cc | 22 | ||||
-rw-r--r-- | kythe/cxx/indexer/cxx/KytheIndexerUnitTest.cc | 10 | ||||
-rw-r--r-- | kythe/cxx/indexer/cxx/proto_conversions.h | 2 | ||||
-rw-r--r-- | kythe/cxx/verifier/verifier.cc | 2 | ||||
-rw-r--r-- | kythe/cxx/verifier/verifier.h | 2 | ||||
-rw-r--r-- | kythe/cxx/verifier/verifier_unit_test.cc | 48 |
7 files changed, 45 insertions, 47 deletions
diff --git a/kythe/cxx/common/kythe_metadata_file.cc b/kythe/cxx/common/kythe_metadata_file.cc index 3d2536e2f..3f82c6e8c 100644 --- a/kythe/cxx/common/kythe_metadata_file.cc +++ b/kythe/cxx/common/kythe_metadata_file.cc @@ -46,7 +46,7 @@ bool CheckVName(const proto::VName& vname) { absl::optional<std::string> LoadCommentMetadata(absl::string_view buf_string, size_t comment_slash_pos, size_t data_start_pos) { - google::protobuf::string raw_data; + std::string raw_data; // Over-reserves--though we expect the comment to be the only thing in the // file or the last thing in the file, so this approximation is reasonable. raw_data.reserve(buf_string.size() - comment_slash_pos); @@ -74,9 +74,9 @@ absl::optional<std::string> LoadCommentMetadata(absl::string_view buf_string, } break; } - google::protobuf::string decoded; + std::string decoded; return absl::Base64Unescape(raw_data, &decoded) - ? absl::optional<std::string>(std::string(decoded)) + ? absl::optional<std::string>(decoded) : absl::nullopt; } diff --git a/kythe/cxx/extractor/testdata/claim_pragma_test.cc b/kythe/cxx/extractor/testdata/claim_pragma_test.cc index 077ec4f55..97dc9f8eb 100644 --- a/kythe/cxx/extractor/testdata/claim_pragma_test.cc +++ b/kythe/cxx/extractor/testdata/claim_pragma_test.cc @@ -22,8 +22,6 @@ using ::google::protobuf::util::DefaultFieldComparator; using ::google::protobuf::util::MessageDifferencer; using ::testing::ElementsAre; -using pbstring = ::google::protobuf::string; - constexpr char kExpectedContents[] = R"( v_name { language: "c++" @@ -113,7 +111,7 @@ entry_context: "hash0" // {"message", "inner", "field"}); const FieldDescriptor* FindNestedFieldByLowercasePath( const google::protobuf::Descriptor* descriptor, - const std::vector<pbstring>& field_names) { + const std::vector<std::string>& field_names) { const FieldDescriptor* field = nullptr; for (const auto& name : field_names) { if (descriptor == nullptr) return nullptr; @@ -147,7 +145,7 @@ class CanonicalHashComparator : public DefaultFieldComparator { } private: - using HashMap = std::unordered_map<pbstring, size_t>; + using HashMap = std::unordered_map<std::string, size_t>; ComparisonResult Compare( const Message& message_1, const Message& message_2, @@ -163,8 +161,8 @@ class CanonicalHashComparator : public DefaultFieldComparator { if (field->is_repeated()) { // Allocate scratch strings to store the result if a conversion is // needed. - pbstring scratch1; - pbstring scratch2; + std::string scratch1; + std::string scratch2; return CompareCanonicalHash(reflection_1->GetRepeatedStringReference( message_1, field, index_1, &scratch1), reflection_2->GetRepeatedStringReference( @@ -172,23 +170,23 @@ class CanonicalHashComparator : public DefaultFieldComparator { } else { // Allocate scratch strings to store the result if a conversion is // needed. - pbstring scratch1; - pbstring scratch2; + std::string scratch1; + std::string scratch2; return CompareCanonicalHash( reflection_1->GetStringReference(message_1, field, &scratch1), reflection_2->GetStringReference(message_2, field, &scratch2)); } } - ComparisonResult CompareCanonicalHash(const pbstring& string_1, - const pbstring& string_2) { + ComparisonResult CompareCanonicalHash(const std::string& string_1, + const std::string& string_2) { return HashIndex(&left_message_hashes_, string_1) == HashIndex(&right_message_hashes_, string_2) ? SAME : DIFFERENT; } - static size_t HashIndex(HashMap* canonical_map, const pbstring& hash) { + static size_t HashIndex(HashMap* canonical_map, const std::string& hash) { size_t index = canonical_map->size(); // We use an index equivalent to the visitation order of the hashes. // This is potentially fragile as we really only care if a protocol buffer @@ -231,7 +229,7 @@ class FakeCompilationWriterSink : public kythe::CompilationWriterSink { kythe::proto::CompilationUnit expected; ASSERT_TRUE(TextFormat::ParseFromString(kExpectedContents, &expected)); - google::protobuf::string diffs; + std::string diffs; diff.ReportDifferencesToString(&diffs); EXPECT_TRUE(diff.Compare(expected, unit)) << diffs; diff --git a/kythe/cxx/indexer/cxx/KytheIndexerUnitTest.cc b/kythe/cxx/indexer/cxx/KytheIndexerUnitTest.cc index ca8764289..d2807ea59 100644 --- a/kythe/cxx/indexer/cxx/KytheIndexerUnitTest.cc +++ b/kythe/cxx/indexer/cxx/KytheIndexerUnitTest.cc @@ -277,9 +277,9 @@ TEST(KytheIndexerUnitTest, GraphRecorderEdgeOrdinal) { EXPECT_EQ(vname_target.DebugString(), entry.target().DebugString()); } -static void WriteStringToStackAndBuffer(const google::protobuf::string& value, +static void WriteStringToStackAndBuffer(const std::string& value, kythe::BufferStack* stack, - google::protobuf::string* buffer) { + std::string* buffer) { unsigned char* bytes = stack->WriteToTop(value.size()); memcpy(bytes, value.data(), value.size()); if (buffer) { @@ -289,7 +289,7 @@ static void WriteStringToStackAndBuffer(const google::protobuf::string& value, TEST(KytheIndexerUnitTest, BufferStackWrite) { kythe::BufferStack stack; - google::protobuf::string expected, actual; + std::string expected, actual; { google::protobuf::io::StringOutputStream stream(&actual); stack.Push(0); @@ -305,7 +305,7 @@ TEST(KytheIndexerUnitTest, BufferStackWrite) { TEST(KytheIndexerUnitTest, BufferStackMergeDown) { kythe::BufferStack stack; - google::protobuf::string actual; + std::string actual; { google::protobuf::io::StringOutputStream stream(&actual); stack.Push(0); @@ -344,7 +344,7 @@ TEST(KytheIndexerUnitTest, BufferStackMergeDown) { TEST(KytheIndexerUnitTest, BufferStackMergeFailures) { kythe::BufferStack stack; - google::protobuf::string actual; + std::string actual; { google::protobuf::io::StringOutputStream stream(&actual); ASSERT_FALSE(stack.MergeDownIfTooSmall(0, 2048)); // too few on the stack diff --git a/kythe/cxx/indexer/cxx/proto_conversions.h b/kythe/cxx/indexer/cxx/proto_conversions.h index 59e0ab169..71670932d 100644 --- a/kythe/cxx/indexer/cxx/proto_conversions.h +++ b/kythe/cxx/indexer/cxx/proto_conversions.h @@ -25,7 +25,7 @@ namespace kythe { /// \brief Wrap a protobuf string in a StringRef. /// \param string The string to wrap. /// \return The wrapped string (which should not outlive `string`). -inline llvm::StringRef ToStringRef(const google::protobuf::string& string) { +inline llvm::StringRef ToStringRef(const std::string& string) { return llvm::StringRef(string.c_str(), string.size()); } } // namespace kythe diff --git a/kythe/cxx/verifier/verifier.cc b/kythe/cxx/verifier/verifier.cc index 1d05b7cdd..8f253aca3 100644 --- a/kythe/cxx/verifier/verifier.cc +++ b/kythe/cxx/verifier/verifier.cc @@ -1288,7 +1288,7 @@ AstNode* Verifier::NewUniqueVName(const yy::location& loc) { } AstNode* Verifier::ConvertCodeFact(const yy::location& loc, - const google::protobuf::string& code_data) { + const std::string& code_data) { proto::common::MarkedSource marked_source; if (!marked_source.ParseFromString(code_data)) { std::cerr << loc << ": can't parse code protobuf" << std::endl; diff --git a/kythe/cxx/verifier/verifier.h b/kythe/cxx/verifier/verifier.h index 212dd1e46..4db76b4d1 100644 --- a/kythe/cxx/verifier/verifier.h +++ b/kythe/cxx/verifier/verifier.h @@ -208,7 +208,7 @@ class Verifier { /// \return null if something went wrong; otherwise, an AstNode corresponding /// to a VName of a synthetic node for `code_data`. AstNode* ConvertCodeFact(const yy::location& loc, - const google::protobuf::string& code_data); + const std::string& code_data); /// \brief Converts a MarkedSource message to a form that's useful /// to the verifier. diff --git a/kythe/cxx/verifier/verifier_unit_test.cc b/kythe/cxx/verifier/verifier_unit_test.cc index c5300081f..20c7f3fe0 100644 --- a/kythe/cxx/verifier/verifier_unit_test.cc +++ b/kythe/cxx/verifier/verifier_unit_test.cc @@ -2652,10 +2652,10 @@ fact_value: "//- A->node/kind file\n" TEST(VerifierUnitTest, DontConvertMarkedSource) { Verifier v; MarkedSource source; - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2673,10 +2673,10 @@ TEST(VerifierUnitTest, ConvertMarkedSource) { Verifier v; v.ConvertMarkedSource(); MarkedSource source; - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2708,10 +2708,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceKindEnums) { v.ConvertMarkedSource(); MarkedSource source; source.set_kind(kind_enum); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2732,10 +2732,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceLinks) { v.ConvertMarkedSource(); MarkedSource source; source.add_link()->add_definition("kythe://corpus#sig"); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2754,10 +2754,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceLinksBadUri) { v.ConvertMarkedSource(); MarkedSource source; source.add_link()->add_definition("kythe:/&bad"); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_FALSE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2772,10 +2772,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceLinksMissingUri) { v.ConvertMarkedSource(); MarkedSource source; source.add_link(); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_FALSE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2792,10 +2792,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceLinksMultipleUri) { auto* link = source.add_link(); link->add_definition("kythe://corpus#sig"); link->add_definition("kythe://corpus#sig2"); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_FALSE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2813,10 +2813,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceChildren) { child->set_kind(MarkedSource::IDENTIFIER); child = source.add_child(); child->set_kind(MarkedSource::CONTEXT); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2841,10 +2841,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceBadChildren) { auto* link = child->add_link(); link->add_definition("kythe://corpus#sig"); link->add_definition("kythe://corpus#sig2"); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(parent.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_FALSE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2864,10 +2864,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceFields) { source.set_lookup_index(42); source.set_default_children_count(43); source.set_add_final_list_token(true); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2890,10 +2890,10 @@ TEST(VerifierUnitTest, DontConvertMarkedSourceDuplicateFactsWellFormed) { Verifier v; MarkedSource source; v.IgnoreDuplicateFacts(); - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } @@ -2914,10 +2914,10 @@ TEST(VerifierUnitTest, ConvertMarkedSourceDuplicateFactsWellFormed) { Verifier v; v.ConvertMarkedSource(); MarkedSource source; - google::protobuf::string source_string; + std::string source_string; ASSERT_TRUE(source.SerializeToString(&source_string)); google::protobuf::TextFormat::FieldValuePrinter printer; - google::protobuf::string enc_source = printer.PrintBytes(source_string); + std::string enc_source = printer.PrintBytes(source_string); ASSERT_TRUE(v.LoadInlineProtoFile(R"( entries { source { signature:"test" } |