diff --git a/CHANGES.txt b/CHANGES.txt index cd2fbcc42f..9593319d0e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,15 @@ * Use table-driven parser for reflection based objects. * Update Map's InternalSwap() to take a pointer to the other Map. * Add ARM-optimized Varint decoding functions. + * Minor optimization for parsing groups + * Declare ReflectiveProtoHook class + * Reduce size of VarintParse code in protocol buffers, by calling the shared + routine after handling just one-byte varint encoding inline, rather than + handling one-byte and two-byte varints inline. + * Avoid inlining some large heavily duplicated routines in repeated_ptr_field.h + * Add ReflectiveProtoHook to Reflection. + * Turns on table-driven parser for reflection based objects. + Kotlin * Suppress deprecation warnings in Kotlin generated code. diff --git a/cmake/abseil-cpp.cmake b/cmake/abseil-cpp.cmake index b8dd22d8ee..c1c4c16279 100644 --- a/cmake/abseil-cpp.cmake +++ b/cmake/abseil-cpp.cmake @@ -33,6 +33,7 @@ set(protobuf_ABSL_USED_TARGETS absl::algorithm absl::base absl::bind_front + absl::bits absl::cleanup absl::cord absl::core_headers @@ -43,6 +44,7 @@ set(protobuf_ABSL_USED_TARGETS absl::flat_hash_set absl::function_ref absl::hash + absl::layout absl::memory absl::optional absl::span diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 52443ab0fc..7accca3ea3 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -30,15 +30,15 @@ #include "binary_json_conformance_suite.h" -#include -#include -#include -#include +#include "google/protobuf/text_format.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/util/json_util.h" +#include "google/protobuf/util/type_resolver_util.h" #include "absl/status/status.h" #include "third_party/jsoncpp/json.h" #include "conformance_test.h" -#include -#include +#include "google/protobuf/test_messages_proto2.pb.h" +#include "google/protobuf/test_messages_proto3.pb.h" namespace proto2_messages = protobuf_test_messages::proto2; @@ -765,7 +765,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( : cat(tag(field->number(), wire_type), values[i].second); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest( absl::StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED, @@ -787,7 +788,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( cat(tag(field->number(), wire_type), values.back().second); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest("RepeatedScalarSelectsLast" + type_name, REQUIRED, proto, text, is_proto3); @@ -848,7 +850,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(default_proto_packed_expected); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); // Ensures both packed and unpacked data can be parsed. RunValidProtobufTest( @@ -897,7 +900,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( } std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataRepeated", type_name), REQUIRED, proto, text, is_proto3); @@ -974,7 +978,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key1_data, value1_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, value_type_name, ".Default"), REQUIRED, proto, text, is_proto3); @@ -987,7 +992,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim("")); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, value_type_name, ".MissingDefault"), REQUIRED, proto, text, is_proto3); @@ -1000,7 +1006,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key2_data, value2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, value_type_name, ".NonDefault"), REQUIRED, proto, text, is_proto3); @@ -1013,7 +1020,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(value2_data, key2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, value_type_name, ".Unordered"), REQUIRED, proto, text, is_proto3); @@ -1030,7 +1038,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( string proto = cat(proto1, proto2); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto2); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, value_type_name, ".DuplicateKey"), REQUIRED, proto, text, is_proto3); @@ -1043,7 +1052,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key1_data, key2_data, value2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest( absl::StrCat("ValidDataMap", key_type_name, value_type_name, ".DuplicateKeyInMapEntry"), @@ -1057,7 +1067,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key2_data, value1_data, value2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest( absl::StrCat("ValidDataMap", key_type_name, value_type_name, ".DuplicateValueInMapEntry"), @@ -1097,7 +1108,8 @@ void BinaryAndJsonConformanceSuite::TestOverwriteMessageValueMap() { string proto = cat(proto1, proto2); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto2); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest("ValidDataMap.STRING.MESSAGE.MergeValue", REQUIRED, proto, text, is_proto3); } @@ -1122,7 +1134,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( const string proto = default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest( absl::StrCat("ValidDataOneof", type_name, ".DefaultValue"), REQUIRED, @@ -1137,7 +1150,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( const string proto = non_default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest( absl::StrCat("ValidDataOneof", type_name, ".NonDefaultValue"), @@ -1153,7 +1167,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( const string expected_proto = non_default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataOneof", type_name, ".MultipleValuesForSameField"), @@ -1179,7 +1194,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( const string expected_proto = non_default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest(absl::StrCat("ValidDataOneof", type_name, ".MultipleValuesForDifferentField"), @@ -1224,7 +1240,8 @@ void BinaryAndJsonConformanceSuite::TestMergeOneofMessage() { std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text = test_message->DebugString(); + string text; + TextFormat::PrintToString(*test_message, &text); RunValidProtobufTest("ValidDataOneof.MESSAGE.Merge", REQUIRED, proto, text, is_proto3); RunValidBinaryProtobufTest("ValidDataOneofBinary.MESSAGE.Merge", diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc index 695628567a..eef8a40ff8 100644 --- a/conformance/conformance_cpp.cc +++ b/conformance/conformance_cpp.cc @@ -36,24 +36,24 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/message.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/util/json_util.h" +#include "google/protobuf/util/type_resolver_util.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "conformance/conformance.pb.h" #include "conformance/conformance.pb.h" -#include -#include -#include -#include -#include +#include "google/protobuf/test_messages_proto2.pb.h" +#include "google/protobuf/test_messages_proto3.pb.h" +#include "google/protobuf/test_messages_proto3.pb.h" +#include "google/protobuf/util/type_resolver.h" +#include "google/protobuf/stubs/status_macros.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index 3848ade94a..03b8a4cda1 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -36,12 +36,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/stringprintf.h" +#include "google/protobuf/message.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/util/field_comparator.h" +#include "google/protobuf/util/json_util.h" +#include "google/protobuf/util/message_differencer.h" #include "conformance/conformance.pb.h" using conformance::ConformanceRequest; diff --git a/conformance/conformance_test.h b/conformance/conformance_test.h index f072888edf..5adf3f9420 100644 --- a/conformance/conformance_test.h +++ b/conformance/conformance_test.h @@ -42,9 +42,9 @@ #include #include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/util/type_resolver.h" #include "conformance/conformance.pb.h" namespace conformance { diff --git a/conformance/conformance_test_runner.cc b/conformance/conformance_test_runner.cc index ee7f653f4d..47e91a785a 100644 --- a/conformance/conformance_test_runner.cc +++ b/conformance/conformance_test_runner.cc @@ -62,7 +62,7 @@ #include #include -#include +#include "google/protobuf/stubs/stringprintf.h" #include "conformance/conformance.pb.h" #include "conformance_test.h" diff --git a/conformance/text_format_conformance_suite.cc b/conformance/text_format_conformance_suite.cc index 15a0f6d034..999f333509 100644 --- a/conformance/text_format_conformance_suite.cc +++ b/conformance/text_format_conformance_suite.cc @@ -30,11 +30,11 @@ #include "text_format_conformance_suite.h" -#include -#include +#include "google/protobuf/any.pb.h" +#include "google/protobuf/text_format.h" #include "conformance_test.h" -#include -#include +#include "google/protobuf/test_messages_proto2.pb.h" +#include "google/protobuf/test_messages_proto3.pb.h" namespace proto2_messages = protobuf_test_messages::proto2; diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index e276c88884..427f29fb60 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -115,6 +115,6 @@ def protobuf_deps(): _github_archive( name = "upb", repo = "https://github.com/protocolbuffers/upb", - commit = "470f06cccbf26f98dd2df7ddecf24a78f140fe11", - sha256 = "c3137f3da811142d33d2ad278d093152610d3a773b17839d272bca4b1a6e304b", + commit = "5485645125ba3783ae2b597bd7b77679721cb1c6", + sha256 = "86de85c58eb3cb04b0987a7642ce84e55629f704ab4a9a0210a660a1115f1dd0", ) diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 2b003a4799..3c604dd31d 100644 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -889,6 +889,7 @@ class MessageTest(unittest.TestCase): def testOneofClearField(self, message_module): m = message_module.TestAllTypes() + m.ClearField('oneof_field') m.oneof_uint32 = 11 m.ClearField('oneof_field') if message_module is unittest_pb2: diff --git a/python/google/protobuf/internal/python_protobuf.cc b/python/google/protobuf/internal/python_protobuf.cc index 26e3a8b98d..95c6d2b3fd 100644 --- a/python/google/protobuf/internal/python_protobuf.cc +++ b/python/google/protobuf/internal/python_protobuf.cc @@ -30,7 +30,7 @@ // Author: qrczak@google.com (Marcin Kowalczyk) -#include +#include "google/protobuf/python/python_protobuf.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 99cf21f57c..996ef65a3e 100644 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -2485,6 +2485,5 @@ class OptionalColonMessageToStringTest(unittest.TestCase): - if __name__ == '__main__': unittest.main() diff --git a/python/google/protobuf/proto_api.h b/python/google/protobuf/proto_api.h index 784a0c743f..4e910e07cb 100644 --- a/python/google/protobuf/proto_api.h +++ b/python/google/protobuf/proto_api.h @@ -48,8 +48,8 @@ #define PY_SSIZE_T_CLEAN #include -#include -#include +#include "google/protobuf/descriptor_database.h" +#include "google/protobuf/message.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 9689adf36f..fc83acf01a 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -30,7 +30,7 @@ // Author: petar@google.com (Petar Petrov) -#include +#include "google/protobuf/pyext/descriptor.h" #define PY_SSIZE_T_CLEAN #include @@ -40,15 +40,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/pyext/descriptor_containers.h" +#include "google/protobuf/pyext/descriptor_pool.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/io/coded_stream.h" #define PyString_AsStringAndSize(ob, charpp, sizep) \ (PyUnicode_Check(ob) \ diff --git a/python/google/protobuf/pyext/descriptor.h b/python/google/protobuf/pyext/descriptor.h index a115ef4ed4..8559c660e6 100644 --- a/python/google/protobuf/pyext/descriptor.h +++ b/python/google/protobuf/pyext/descriptor.h @@ -36,7 +36,7 @@ #define PY_SSIZE_T_CLEAN #include -#include +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/descriptor_containers.cc b/python/google/protobuf/pyext/descriptor_containers.cc index e6d675c74a..8c038e9dc9 100644 --- a/python/google/protobuf/pyext/descriptor_containers.cc +++ b/python/google/protobuf/pyext/descriptor_containers.cc @@ -54,13 +54,13 @@ // This inclusion must appear before all the others. #include -#include +#include "google/protobuf/pyext/descriptor_containers.h" // clang-format on -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/descriptor_pool.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #include "absl/strings/string_view.h" #define PyString_AsStringAndSize(ob, charpp, sizep) \ diff --git a/python/google/protobuf/pyext/descriptor_database.cc b/python/google/protobuf/pyext/descriptor_database.cc index f87f23d772..7ef94b3860 100644 --- a/python/google/protobuf/pyext/descriptor_database.cc +++ b/python/google/protobuf/pyext/descriptor_database.cc @@ -31,15 +31,15 @@ // This file defines a C++ DescriptorDatabase, which wraps a Python Database // and delegate all its operations to Python methods. -#include +#include "google/protobuf/pyext/descriptor_database.h" #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/descriptor_database.h b/python/google/protobuf/pyext/descriptor_database.h index 5621a229ef..598466e981 100644 --- a/python/google/protobuf/pyext/descriptor_database.h +++ b/python/google/protobuf/pyext/descriptor_database.h @@ -34,7 +34,7 @@ #define PY_SSIZE_T_CLEAN #include -#include +#include "google/protobuf/descriptor_database.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index c69a113320..0f25ed3539 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -35,13 +35,13 @@ #define PY_SSIZE_T_CLEAN #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/descriptor_database.h" +#include "google/protobuf/pyext/descriptor_pool.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #include "absl/strings/string_view.h" #define PyString_AsStringAndSize(ob, charpp, sizep) \ diff --git a/python/google/protobuf/pyext/descriptor_pool.h b/python/google/protobuf/pyext/descriptor_pool.h index 5d3c3a95cc..851cf31e87 100644 --- a/python/google/protobuf/pyext/descriptor_pool.h +++ b/python/google/protobuf/pyext/descriptor_pool.h @@ -35,7 +35,7 @@ #include #include -#include +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/extension_dict.cc b/python/google/protobuf/pyext/extension_dict.cc index 6eed0e83fd..d03ad87d23 100644 --- a/python/google/protobuf/pyext/extension_dict.cc +++ b/python/google/protobuf/pyext/extension_dict.cc @@ -31,23 +31,23 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include +#include "google/protobuf/pyext/extension_dict.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/message.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/pyext/repeated_composite_container.h" +#include "google/protobuf/pyext/repeated_scalar_container.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #include "absl/strings/string_view.h" #define PyString_AsStringAndSize(ob, charpp, sizep) \ diff --git a/python/google/protobuf/pyext/extension_dict.h b/python/google/protobuf/pyext/extension_dict.h index 86d2451a00..c5c2875936 100644 --- a/python/google/protobuf/pyext/extension_dict.h +++ b/python/google/protobuf/pyext/extension_dict.h @@ -37,7 +37,7 @@ #define PY_SSIZE_T_CLEAN #include -#include +#include "google/protobuf/pyext/message.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/field.cc b/python/google/protobuf/pyext/field.cc index 0d3b0b9607..daa95d0069 100644 --- a/python/google/protobuf/pyext/field.cc +++ b/python/google/protobuf/pyext/field.cc @@ -28,11 +28,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/pyext/field.h" -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/message.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/map_container.cc b/python/google/protobuf/pyext/map_container.cc index e8a6888e22..e5496105bb 100644 --- a/python/google/protobuf/pyext/map_container.cc +++ b/python/google/protobuf/pyext/map_container.cc @@ -30,21 +30,20 @@ // Author: haberman@google.com (Josh Haberman) -#include +#include "google/protobuf/pyext/map_container.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/map.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/message.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/pyext/repeated_composite_container.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/map_container.h b/python/google/protobuf/pyext/map_container.h index af334d2e77..d90d3a554a 100644 --- a/python/google/protobuf/pyext/map_container.h +++ b/python/google/protobuf/pyext/map_container.h @@ -36,9 +36,9 @@ #include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/message.h" +#include "google/protobuf/pyext/message.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 650f4913b3..13495851f5 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -31,7 +31,7 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include +#include "google/protobuf/pyext/message.h" #include // A Python header file. @@ -41,7 +41,7 @@ #include #include -#include +#include "google/protobuf/stubs/strutil.h" #ifndef PyVarObject_HEAD_INIT #define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, @@ -49,34 +49,33 @@ #ifndef Py_TYPE #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/message.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/descriptor_pool.h" +#include "google/protobuf/pyext/extension_dict.h" +#include "google/protobuf/pyext/field.h" +#include "google/protobuf/pyext/map_container.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/pyext/repeated_composite_container.h" +#include "google/protobuf/pyext/repeated_scalar_container.h" +#include "google/protobuf/pyext/safe_numerics.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include "google/protobuf/pyext/unknown_field_set.h" +#include "google/protobuf/pyext/unknown_fields.h" +#include "google/protobuf/util/message_differencer.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/strtod.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on #define PyString_AsString(ob) \ @@ -2677,22 +2676,22 @@ CMessage* CMessage::BuildSubMessageFromPointer( if (!this->child_submessages) { this->child_submessages = new CMessage::SubMessagesMap(); } - CMessage* cmsg = FindPtrOrNull( - *this->child_submessages, sub_message); - if (cmsg) { - Py_INCREF(cmsg); - } else { - cmsg = cmessage::NewEmptyMessage(message_class); + auto it = this->child_submessages->find(sub_message); + if (it != this->child_submessages->end()) { + Py_INCREF(it->second); + return it->second; + } - if (cmsg == nullptr) { - return nullptr; - } - cmsg->message = sub_message; - Py_INCREF(this); - cmsg->parent = this; - cmsg->parent_field_descriptor = field_descriptor; - cmessage::SetSubmessage(this, cmsg); + CMessage* cmsg = cmessage::NewEmptyMessage(message_class); + + if (cmsg == nullptr) { + return nullptr; } + cmsg->message = sub_message; + Py_INCREF(this); + cmsg->parent = this; + cmsg->parent_field_descriptor = field_descriptor; + cmessage::SetSubmessage(this, cmsg); return cmsg; } @@ -2700,11 +2699,10 @@ CMessage* CMessage::MaybeReleaseSubMessage(Message* sub_message) { if (!this->child_submessages) { return nullptr; } - CMessage* released = FindPtrOrNull( - *this->child_submessages, sub_message); - if (!released) { - return nullptr; - } + auto it = this->child_submessages->find(sub_message); + if (it == this->child_submessages->end()) return nullptr; + CMessage* released = it->second; + // The target message will now own its content. Py_CLEAR(released->parent); released->parent_field_descriptor = nullptr; diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index b17daa5806..1b0172f9a4 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -42,7 +42,7 @@ #include #include -#include +#include "google/protobuf/stubs/common.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/message_factory.cc b/python/google/protobuf/pyext/message_factory.cc index bc44dd4572..bcbd7d8d7b 100644 --- a/python/google/protobuf/pyext/message_factory.cc +++ b/python/google/protobuf/pyext/message_factory.cc @@ -33,11 +33,11 @@ #define PY_SSIZE_T_CLEAN #include -#include -#include -#include -#include -#include +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #define PyString_AsStringAndSize(ob, charpp, sizep) \ (PyUnicode_Check(ob) \ diff --git a/python/google/protobuf/pyext/message_factory.h b/python/google/protobuf/pyext/message_factory.h index 7dfe425dd5..1d911a827d 100644 --- a/python/google/protobuf/pyext/message_factory.h +++ b/python/google/protobuf/pyext/message_factory.h @@ -35,8 +35,8 @@ #include #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/pyext/descriptor_pool.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/message_module.cc b/python/google/protobuf/pyext/message_module.cc index 2d3c1d2087..f4692066d8 100644 --- a/python/google/protobuf/pyext/message_module.cc +++ b/python/google/protobuf/pyext/message_module.cc @@ -31,12 +31,12 @@ #define PY_SSIZE_T_CLEAN #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/message_lite.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/descriptor_pool.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/proto_api.h" namespace { diff --git a/python/google/protobuf/pyext/repeated_composite_container.cc b/python/google/protobuf/pyext/repeated_composite_container.cc index 0b63f82256..a191670876 100644 --- a/python/google/protobuf/pyext/repeated_composite_container.cc +++ b/python/google/protobuf/pyext/repeated_composite_container.cc @@ -31,22 +31,21 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include +#include "google/protobuf/pyext/repeated_composite_container.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/message.h" +#include "google/protobuf/reflection.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/descriptor_pool.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/message_factory.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/repeated_composite_container.h b/python/google/protobuf/pyext/repeated_composite_container.h index 6fa6e176f1..8964374dbc 100644 --- a/python/google/protobuf/pyext/repeated_composite_container.h +++ b/python/google/protobuf/pyext/repeated_composite_container.h @@ -37,7 +37,7 @@ #define PY_SSIZE_T_CLEAN #include -#include +#include "google/protobuf/pyext/message.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/repeated_scalar_container.cc b/python/google/protobuf/pyext/repeated_scalar_container.cc index f4a8df2c4a..1a39468e96 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.cc +++ b/python/google/protobuf/pyext/repeated_scalar_container.cc @@ -31,20 +31,20 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include +#include "google/protobuf/pyext/repeated_scalar_container.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/message.h" +#include "google/protobuf/pyext/descriptor.h" +#include "google/protobuf/pyext/descriptor_pool.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #define PyString_AsString(ob) \ (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob)) diff --git a/python/google/protobuf/pyext/repeated_scalar_container.h b/python/google/protobuf/pyext/repeated_scalar_container.h index 67423ab4ce..0189886c52 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.h +++ b/python/google/protobuf/pyext/repeated_scalar_container.h @@ -37,8 +37,8 @@ #define PY_SSIZE_T_CLEAN #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/pyext/message.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/safe_numerics.h b/python/google/protobuf/pyext/safe_numerics.h index 93ae640e8b..0d4dd25d59 100644 --- a/python/google/protobuf/pyext/safe_numerics.h +++ b/python/google/protobuf/pyext/safe_numerics.h @@ -34,8 +34,8 @@ #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/unknown_field_set.cc b/python/google/protobuf/pyext/unknown_field_set.cc index 42f9bbcb04..5cc48e714b 100644 --- a/python/google/protobuf/pyext/unknown_field_set.cc +++ b/python/google/protobuf/pyext/unknown_field_set.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/pyext/unknown_field_set.h" #define PY_SSIZE_T_CLEAN #include @@ -36,11 +36,11 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/message.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/unknown_field_set.h b/python/google/protobuf/pyext/unknown_field_set.h index 3fa764d01e..92a889dc59 100644 --- a/python/google/protobuf/pyext/unknown_field_set.h +++ b/python/google/protobuf/pyext/unknown_field_set.h @@ -37,7 +37,7 @@ #include #include -#include +#include "google/protobuf/pyext/message.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/unknown_fields.cc b/python/google/protobuf/pyext/unknown_fields.cc index dcd63b2e29..9f27f26c37 100644 --- a/python/google/protobuf/pyext/unknown_fields.cc +++ b/python/google/protobuf/pyext/unknown_fields.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/pyext/unknown_fields.h" #define PY_SSIZE_T_CLEAN #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/message.h" +#include "google/protobuf/pyext/message.h" +#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format_lite.h" namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/unknown_fields.h b/python/google/protobuf/pyext/unknown_fields.h index e7b0b35c41..81ee1a9139 100644 --- a/python/google/protobuf/pyext/unknown_fields.h +++ b/python/google/protobuf/pyext/unknown_fields.h @@ -37,7 +37,7 @@ #include #include -#include +#include "google/protobuf/pyext/message.h" namespace google { namespace protobuf { diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 43e978d7e3..220ffe0cb3 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -16,6 +16,7 @@ set(libprotobuf_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer.cc @@ -61,7 +62,6 @@ set(libprotobuf_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc @@ -100,6 +100,7 @@ set(libprotobuf_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.h @@ -162,10 +163,7 @@ set(libprotobuf_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/macros.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/map_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/mathutil.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h @@ -211,6 +209,7 @@ set(libprotobuf_hdrs set(libprotobuf_lite_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.cc @@ -231,7 +230,6 @@ set(libprotobuf_lite_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc @@ -242,6 +240,7 @@ set(libprotobuf_lite_srcs set(libprotobuf_lite_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/any.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.h @@ -274,10 +273,7 @@ set(libprotobuf_lite_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/macros.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/map_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/mathutil.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h @@ -788,6 +784,7 @@ set(test_plugin_files set(io_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer_death_test.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/io/tokenizer_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_sink_test.cc @@ -845,7 +842,6 @@ set(util_test_protos_files set(stubs_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid_unittest.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil_unittest.cc diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 114b67cb89..7a6fc12db6 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -115,9 +115,11 @@ cc_library( name = "arena", srcs = [ "arena.cc", + "arena_config.cc", ], hdrs = [ "arena.h", + "arena_config.h", "arena_impl.h", "arenaz_sampler.h", ], @@ -136,6 +138,7 @@ cc_library( name = "protobuf_lite", srcs = [ "any_lite.cc", + "arena_config.cc", "arenastring.cc", "arenaz_sampler.cc", "extension_set.cc", @@ -154,6 +157,7 @@ cc_library( hdrs = [ "any.h", "arena.h", + "arena_config.h", "arena_impl.h", "arenastring.h", "arenaz_sampler.h", @@ -199,6 +203,8 @@ cc_library( "//src/google/protobuf/io", "//src/google/protobuf/stubs:lite", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/numeric:bits", + "@com_google_absl//absl/strings:internal", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", ], @@ -288,6 +294,7 @@ cc_library( "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/hash", + "@com_google_absl//absl/strings:internal", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", ], diff --git a/src/google/protobuf/any.cc b/src/google/protobuf/any.cc index a3efd762e8..1f6ef876db 100644 --- a/src/google/protobuf/any.cc +++ b/src/google/protobuf/any.cc @@ -28,15 +28,15 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/any.h" -#include -#include -#include -#include +#include "google/protobuf/arenastring.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/message.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -79,4 +79,4 @@ bool GetAnyFieldDescriptors(const Message& message, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/any.h b/src/google/protobuf/any.h index 78d30ef641..ab71a6c58e 100644 --- a/src/google/protobuf/any.h +++ b/src/google/protobuf/any.h @@ -33,12 +33,12 @@ #include -#include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/message_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -152,6 +152,6 @@ bool GetAnyFieldDescriptors(const Message& message, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_ANY_H__ diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index b7ffd2d714..2aa32b8423 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -367,4 +367,4 @@ PROTOBUF_NAMESPACE_CLOSE #if defined(__llvm__) #pragma clang diagnostic pop #endif // __llvm__ -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 31e1663db8..8347eada75 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,19 +19,19 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fany_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -294,11 +294,11 @@ inline const std::string& Any::_internal_type_url() const { return _impl_.type_url_.Get(); } inline void Any::_internal_set_type_url(const std::string& value) { - + _impl_.type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Any::_internal_mutable_type_url() { - + return _impl_.type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Any::release_type_url() { @@ -307,9 +307,9 @@ inline std::string* Any::release_type_url() { } inline void Any::set_allocated_type_url(std::string* type_url) { if (type_url != nullptr) { - + } else { - + } _impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -344,11 +344,11 @@ inline const std::string& Any::_internal_value() const { return _impl_.value_.Get(); } inline void Any::_internal_set_value(const std::string& value) { - + _impl_.value_.Set(value, GetArenaForAllocation()); } inline std::string* Any::_internal_mutable_value() { - + return _impl_.value_.Mutable(GetArenaForAllocation()); } inline std::string* Any::release_value() { @@ -357,9 +357,9 @@ inline std::string* Any::release_value() { } inline void Any::set_allocated_value(std::string* value) { if (value != nullptr) { - + } else { - + } _impl_.value_.SetAllocated(value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -380,5 +380,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh diff --git a/src/google/protobuf/any_lite.cc b/src/google/protobuf/any_lite.cc index 767ed7e198..fb812d70fe 100644 --- a/src/google/protobuf/any_lite.cc +++ b/src/google/protobuf/any_lite.cc @@ -28,12 +28,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include +#include "google/protobuf/any.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/any_test.cc b/src/google/protobuf/any_test.cc index 49685dbb97..7e6ecb277d 100644 --- a/src/google/protobuf/any_test.cc +++ b/src/google/protobuf/any_test.cc @@ -28,14 +28,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include +#include "google/protobuf/any_test.pb.h" +#include "google/protobuf/unittest.pb.h" #include #include "absl/strings/str_cat.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -192,4 +192,4 @@ TEST(AnyTest, PackSelfDeath) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index f0828f7a17..080a47e49c 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -1312,4 +1312,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Mixin >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 94f588af8e..c26209da77 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,21 +19,21 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" #include #include // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fapi_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -766,11 +766,11 @@ inline const std::string& Api::_internal_name() const { return _impl_.name_.Get(); } inline void Api::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Api::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Api::release_name() { @@ -779,9 +779,9 @@ inline std::string* Api::release_name() { } inline void Api::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -893,11 +893,11 @@ inline const std::string& Api::_internal_version() const { return _impl_.version_.Get(); } inline void Api::_internal_set_version(const std::string& value) { - + _impl_.version_.Set(value, GetArenaForAllocation()); } inline std::string* Api::_internal_mutable_version() { - + return _impl_.version_.Mutable(GetArenaForAllocation()); } inline std::string* Api::release_version() { @@ -906,9 +906,9 @@ inline std::string* Api::release_version() { } inline void Api::set_allocated_version(std::string* version) { if (version != nullptr) { - + } else { - + } _impl_.version_.SetAllocated(version, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -942,9 +942,9 @@ inline void Api::unsafe_arena_set_allocated_source_context( } _impl_.source_context_ = source_context; if (source_context) { - + } else { - + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.source_context) } @@ -996,9 +996,9 @@ inline void Api::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCon source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, source_context, submessage_arena); } - + } else { - + } _impl_.source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.source_context) @@ -1092,11 +1092,11 @@ inline const std::string& Method::_internal_name() const { return _impl_.name_.Get(); } inline void Method::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Method::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Method::release_name() { @@ -1105,9 +1105,9 @@ inline std::string* Method::release_name() { } inline void Method::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1142,11 +1142,11 @@ inline const std::string& Method::_internal_request_type_url() const { return _impl_.request_type_url_.Get(); } inline void Method::_internal_set_request_type_url(const std::string& value) { - + _impl_.request_type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Method::_internal_mutable_request_type_url() { - + return _impl_.request_type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Method::release_request_type_url() { @@ -1155,9 +1155,9 @@ inline std::string* Method::release_request_type_url() { } inline void Method::set_allocated_request_type_url(std::string* request_type_url) { if (request_type_url != nullptr) { - + } else { - + } _impl_.request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1180,7 +1180,7 @@ inline bool Method::request_streaming() const { return _internal_request_streaming(); } inline void Method::_internal_set_request_streaming(bool value) { - + _impl_.request_streaming_ = value; } inline void Method::set_request_streaming(bool value) { @@ -1212,11 +1212,11 @@ inline const std::string& Method::_internal_response_type_url() const { return _impl_.response_type_url_.Get(); } inline void Method::_internal_set_response_type_url(const std::string& value) { - + _impl_.response_type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Method::_internal_mutable_response_type_url() { - + return _impl_.response_type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Method::release_response_type_url() { @@ -1225,9 +1225,9 @@ inline std::string* Method::release_response_type_url() { } inline void Method::set_allocated_response_type_url(std::string* response_type_url) { if (response_type_url != nullptr) { - + } else { - + } _impl_.response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1250,7 +1250,7 @@ inline bool Method::response_streaming() const { return _internal_response_streaming(); } inline void Method::_internal_set_response_streaming(bool value) { - + _impl_.response_streaming_ = value; } inline void Method::set_response_streaming(bool value) { @@ -1343,11 +1343,11 @@ inline const std::string& Mixin::_internal_name() const { return _impl_.name_.Get(); } inline void Mixin::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Mixin::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Mixin::release_name() { @@ -1356,9 +1356,9 @@ inline std::string* Mixin::release_name() { } inline void Mixin::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1393,11 +1393,11 @@ inline const std::string& Mixin::_internal_root() const { return _impl_.root_.Get(); } inline void Mixin::_internal_set_root(const std::string& value) { - + _impl_.root_.Set(value, GetArenaForAllocation()); } inline std::string* Mixin::_internal_mutable_root() { - + return _impl_.root_.Mutable(GetArenaForAllocation()); } inline std::string* Mixin::release_root() { @@ -1406,9 +1406,9 @@ inline std::string* Mixin::release_root() { } inline void Mixin::set_allocated_root(std::string* root) { if (root != nullptr) { - + } else { - + } _impl_.root_.SetAllocated(root, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1433,5 +1433,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index 610d9f7a17..0eb8cc9016 100644 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/arena.h" #include #include @@ -38,9 +38,9 @@ #include #include "absl/synchronization/mutex.h" -#include -#include -#include +#include "google/protobuf/arena_impl.h" +#include "google/protobuf/arenaz_sampler.h" +#include "google/protobuf/port.h" #ifdef ADDRESS_SANITIZER @@ -48,7 +48,7 @@ #endif // ADDRESS_SANITIZER // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -105,20 +105,20 @@ class GetDeallocator { size_t* space_allocated_; }; -SerialArena::SerialArena(Block* b, void* owner) : space_allocated_(b->size()) { - owner_ = owner; +SerialArena::SerialArena(Block* b, ThreadSafeArena& parent) + : parent_(parent), space_allocated_(b->size()) { set_head(b); set_ptr(b->Pointer(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize)); limit_ = b->Pointer(b->size() & static_cast(-8)); } -SerialArena* SerialArena::New(Memory mem, void* owner, - ThreadSafeArenaStats* stats) { +SerialArena* SerialArena::New(Memory mem, ThreadSafeArena& parent) { GOOGLE_DCHECK_LE(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize, mem.size); - ThreadSafeArenaStats::RecordAllocateStats( - stats, /*used=*/0, /*allocated=*/mem.size, /*wasted=*/0); + ThreadSafeArenaStats::RecordAllocateStats(parent.arena_stats_.MutableStats(), + /*used=*/0, /*allocated=*/mem.size, + /*wasted=*/0); auto b = new (mem.ptr) Block{nullptr, mem.size}; - return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, owner); + return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, parent); } template @@ -134,33 +134,27 @@ SerialArena::Memory SerialArena::Free(Deallocator deallocator) { } PROTOBUF_NOINLINE -void* SerialArena::AllocateAlignedFallback(size_t n, - const AllocationPolicy* policy, - ThreadSafeArenaStats* stats) { - AllocateNewBlock(n, policy, stats); +void* SerialArena::AllocateAlignedFallback(size_t n) { + AllocateNewBlock(n); return AllocateFromExisting(n); } PROTOBUF_NOINLINE void* SerialArena::AllocateAlignedWithCleanupFallback( - size_t n, size_t align, void (*destructor)(void*), - const AllocationPolicy* policy, ThreadSafeArenaStats* stats) { + size_t n, size_t align, void (*destructor)(void*)) { size_t required = AlignUpTo(n, align) + cleanup::Size(destructor); - AllocateNewBlock(required, policy, stats); + AllocateNewBlock(required); return AllocateFromExistingWithCleanupFallback(n, align, destructor); } PROTOBUF_NOINLINE -void SerialArena::AddCleanupFallback(void* elem, void (*destructor)(void*), - const AllocationPolicy* policy, - ThreadSafeArenaStats* stats) { +void SerialArena::AddCleanupFallback(void* elem, void (*destructor)(void*)) { size_t required = cleanup::Size(destructor); - AllocateNewBlock(required, policy, stats); + AllocateNewBlock(required); AddCleanupFromExisting(elem, destructor); } -void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy, - ThreadSafeArenaStats* stats) { +void SerialArena::AllocateNewBlock(size_t n) { // Sync limit to block head()->cleanup_nodes = limit_; @@ -175,14 +169,15 @@ void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy, // but with a CPU regression. The regression might have been an artifact of // the microbenchmark. - auto mem = AllocateMemory(policy, head()->size(), n); + auto mem = AllocateMemory(parent_.AllocPolicy(), head()->size(), n); // We don't want to emit an expensive RMW instruction that requires // exclusive access to a cacheline. Hence we write it in terms of a // regular add. space_allocated_.store( space_allocated_.load(std::memory_order_relaxed) + mem.size, std::memory_order_relaxed); - ThreadSafeArenaStats::RecordAllocateStats(stats, /*used=*/used, + ThreadSafeArenaStats::RecordAllocateStats(parent_.arena_stats_.MutableStats(), + /*used=*/used, /*allocated=*/mem.size, wasted); set_head(new (mem.ptr) Block{head(), mem.size}); set_ptr(head()->Pointer(kBlockHeaderSize)); @@ -257,6 +252,160 @@ void SerialArena::CleanupList() { } while (b); } +// Stores arrays of void* and SerialArena* instead of linked list of +// SerialArena* to speed up traversing all SerialArena. The cost of walk is non +// trivial when there are many nodes. Separately storing "ids" minimizes cache +// footprints and more efficient when looking for matching arena. +// +// Uses absl::container_internal::Layout to emulate the following: +// +// struct SerialArenaChunk { +// SerialArenaChunk* next_chunk; +// const uint32_t capacity; +// std::atomic size; +// std::atomic ids[]; +// std::atomic arenas[]; +// }; +// +// where the size of "ids" and "arenas" is determined at runtime; hence the use +// of Layout. +class ThreadSafeArena::SerialArenaChunk { + public: + explicit SerialArenaChunk(uint32_t capacity) { + set_next(nullptr); + set_capacity(capacity); + new (&size()) std::atomic{0}; + + for (unsigned i = 0; i < capacity; ++i) { + new (&id(i)) std::atomic{nullptr}; + } + + for (unsigned i = 0; i < capacity; ++i) { + new (&arena(i)) std::atomic{nullptr}; + } + } + + SerialArenaChunk(uint32_t capacity, void* me, SerialArena* serial) { + set_next(nullptr); + set_capacity(capacity); + new (&size()) std::atomic{1}; + + new (&id(0)) std::atomic{me}; + for (unsigned i = 1; i < capacity; ++i) { + new (&id(i)) std::atomic{nullptr}; + } + + new (&arena(0)) std::atomic{serial}; + for (unsigned i = 1; i < capacity; ++i) { + new (&arena(i)) std::atomic{nullptr}; + } + } + + // next_chunk + const SerialArenaChunk* next_chunk() const { + return *layout_type::Partial().Pointer(ptr()); + } + SerialArenaChunk* next_chunk() { + return *layout_type::Partial().Pointer(ptr()); + } + void set_next(SerialArenaChunk* next_chunk) { + *layout_type::Partial().Pointer(ptr()) = next_chunk; + } + + // capacity + uint32_t capacity() const { + return *layout_type::Partial(1u).Pointer(ptr()); + } + void set_capacity(uint32_t capacity) { + *layout_type::Partial(1u).Pointer(ptr()) = capacity; + } + + // ids: returns up to size(). + absl::Span> ids() const { + return Layout(capacity()).Slice(ptr()).first(safe_size()); + } + absl::Span> ids() { + return Layout(capacity()).Slice(ptr()).first(safe_size()); + } + std::atomic& id(unsigned i) { + GOOGLE_DCHECK_LT(i, capacity()); + return Layout(capacity()).Pointer(ptr())[i]; + } + + // arenas: returns up to size(). + absl::Span> arenas() const { + return Layout(capacity()).Slice(ptr()).first(safe_size()); + } + absl::Span> arenas() { + return Layout(capacity()).Slice(ptr()).first(safe_size()); + } + std::atomic& arena(unsigned i) { + GOOGLE_DCHECK_LT(i, capacity()); + return Layout(capacity()).Pointer(ptr())[i]; + } + + // Tries to insert {id, serial} to head chunk. Returns false if the head is + // already full. + // + // Note that the updating "size", "id", "arena" is individually atomic but + // those are not protected by a mutex. This is acceptable because concurrent + // lookups from SpaceUsed or SpaceAllocated accept inaccuracy due to race. On + // other paths, either race is not possible (GetSerialArenaFallback) or must + // be prevented by users (CleanupList, Free). + bool insert(void* me, SerialArena* serial) { + uint32_t idx = size().fetch_add(1, std::memory_order_relaxed); + // Bail out if this chunk is full. + if (idx >= capacity()) { + // Write old value back to avoid potential overflow. + size().store(capacity(), std::memory_order_relaxed); + return false; + } + + id(idx).store(me, std::memory_order_relaxed); + arena(idx).store(serial, std::memory_order_relaxed); + return true; + } + + constexpr static size_t AllocSize(size_t n) { return Layout(n).AllocSize(); } + + private: + constexpr static int kNextChunk = 0; + constexpr static int kCapacity = 1; + constexpr static int kSize = 2; + constexpr static int kIds = 3; + constexpr static int kArenas = 4; + + using layout_type = absl::container_internal::Layout< + SerialArenaChunk*, uint32_t, std::atomic, std::atomic, + std::atomic>; + + const char* ptr() const { return reinterpret_cast(this); } + char* ptr() { return reinterpret_cast(this); } + + std::atomic& size() { + return *layout_type::Partial(1u, 1u).Pointer(ptr()); + } + + const std::atomic& size() const { + return *layout_type::Partial(1u, 1u).Pointer(ptr()); + } + + // Returns the size capped by the capacity as fetch_add may result in a size + // greater than capacity. + uint32_t safe_size() const { + return std::min(capacity(), size().load(std::memory_order_relaxed)); + } + + constexpr static layout_type Layout(size_t n) { + return layout_type( + /*next_chunk*/ 1, + /*capacity*/ 1, + /*size*/ 1, + /*ids*/ n, + /*arenas*/ n); + } +}; + ThreadSafeArena::CacheAlignedLifecycleIdGenerator ThreadSafeArena::lifecycle_id_generator_; @@ -326,9 +475,8 @@ void ThreadSafeArena::InitializeWithPolicy(void* mem, size_t size, mem = tmp.ptr; size = tmp.size; } - SetInitialBlock(mem, size); + SerialArena* sa = SetInitialBlock(mem, size); - auto sa = threads_.load(std::memory_order_relaxed); // We ensured enough space so this cannot fail. void* p; if (!sa || !sa->MaybeAllocateAligned(kAPSize, &p)) { @@ -362,6 +510,64 @@ uint64_t ThreadSafeArena::GetNextLifeCycleId() { return id; } +// We assume that #threads / arena is bimodal; i.e. majority small ones are +// single threaded but some big ones are highly concurrent. To balance between +// memory overhead and minimum pointer chasing, we start with few entries and +// exponentially (4x) grow with a limit (255 entries). Note that parameters are +// picked for x64 architectures as hint and the actual size is calculated by +// Layout. +ThreadSafeArena::SerialArenaChunk* ThreadSafeArena::NewSerialArenaChunk( + uint32_t prev_capacity, void* id, SerialArena* serial) { + constexpr size_t kMaxBytes = 4096; // Can hold up to 255 entries. + constexpr size_t kGrowthFactor = 4; + constexpr size_t kHeaderSize = SerialArenaChunk::AllocSize(0); + constexpr size_t kEntrySize = SerialArenaChunk::AllocSize(1) - kHeaderSize; + + // On x64 arch: {4, 16, 64, 256, 256, ...} * 16. + size_t prev_bytes = SerialArenaChunk::AllocSize(prev_capacity); + size_t next_bytes = std::min(kMaxBytes, prev_bytes * kGrowthFactor); + uint32_t next_capacity = + static_cast(next_bytes - kHeaderSize) / kEntrySize; + // Growth based on bytes needs to be adjusted by AllocSize. + next_bytes = SerialArenaChunk::AllocSize(next_capacity); + void* mem; + mem = ::operator new(next_bytes); + if (serial == nullptr) { + return new (mem) SerialArenaChunk{next_capacity}; + } + + return new (mem) SerialArenaChunk{next_capacity, id, serial}; +} + +// Tries to reserve an entry by atomic fetch_add. If the head chunk is already +// full (size >= capacity), acquires the mutex and adds a new head. +void ThreadSafeArena::AddSerialArena(void* id, SerialArena* serial) { + SerialArenaChunk* head = head_.load(std::memory_order_acquire); + GOOGLE_DCHECK_NE(head, nullptr); + // Fast path without acquiring mutex. + if (head->insert(id, serial)) { + return; + } + + // Slow path with acquiring mutex. + absl::MutexLock lock(&mutex_); + + // Refetch and if someone else installed a new head, try allocating on that! + SerialArenaChunk* new_head = head_.load(std::memory_order_acquire); + if (new_head != head) { + if (new_head->insert(id, serial)) return; + // Update head to link to the latest one. + head = new_head; + } + + new_head = NewSerialArenaChunk(head->capacity(), id, serial); + new_head->set_next(head); + + // Use "std::memory_order_release" to make sure prior stores are visible after + // this one. + head_.store(new_head, std::memory_order_release); +} + void ThreadSafeArena::Init() { const bool message_owned = IsMessageOwned(); if (!message_owned) { @@ -370,17 +576,17 @@ void ThreadSafeArena::Init() { } else { GOOGLE_DCHECK_EQ(tag_and_id_, kMessageOwnedArena); } - threads_.store(nullptr, std::memory_order_relaxed); + auto* empty_chunk = NewSerialArenaChunk(0, nullptr, nullptr); + head_.store(empty_chunk, std::memory_order_relaxed); GOOGLE_DCHECK_EQ(message_owned, IsMessageOwned()); arena_stats_ = Sample(); } -void ThreadSafeArena::SetInitialBlock(void* mem, size_t size) { - SerialArena* serial = SerialArena::New({mem, size}, &thread_cache(), - arena_stats_.MutableStats()); - serial->set_next(nullptr); - threads_.store(serial, std::memory_order_relaxed); +SerialArena* ThreadSafeArena::SetInitialBlock(void* mem, size_t size) { + SerialArena* serial = SerialArena::New({mem, size}, *this); + AddSerialArena(&thread_cache(), serial); CacheSerialArena(serial); + return serial; } ThreadSafeArena::~ThreadSafeArena() { @@ -408,6 +614,14 @@ SerialArena::Memory ThreadSafeArena::Free(size_t* space_allocated) { if (mem.ptr) deallocator(mem); mem = a->Free(deallocator); }); + // Free chunks that stored SerialArena. + SerialArenaChunk* chunk = head_.load(std::memory_order_relaxed); + while (chunk != nullptr) { + SerialArenaChunk* next_chunk = chunk->next_chunk(); + internal::SizedDelete(chunk, + SerialArenaChunk::AllocSize(chunk->capacity())); + chunk = next_chunk; + } return mem; } @@ -449,8 +663,7 @@ void* ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, size_t align, void (*destructor)(void*)) { SerialArena* arena; if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - return arena->AllocateAlignedWithCleanup( - n, align, destructor, alloc_policy_.get(), arena_stats_.MutableStats()); + return arena->AllocateAlignedWithCleanup(n, align, destructor); } else { return AllocateAlignedWithCleanupFallback(n, align, destructor); } @@ -459,7 +672,7 @@ void* ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, size_t align, void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) { SerialArena* arena; if (PROTOBUF_PREDICT_FALSE(!GetSerialArenaFast(&arena))) { - arena = GetSerialArenaFallback(&thread_cache()); + arena = GetSerialArenaFallback(); } arena->AddCleanup(elem, cleanup, AllocPolicy(), arena_stats_.MutableStats()); } @@ -467,26 +680,71 @@ void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) { PROTOBUF_NOINLINE void* ThreadSafeArena::AllocateAlignedWithCleanupFallback( size_t n, size_t align, void (*destructor)(void*)) { - return GetSerialArenaFallback(&thread_cache()) - ->AllocateAlignedWithCleanup(n, align, destructor, alloc_policy_.get(), - arena_stats_.MutableStats()); + return GetSerialArenaFallback()->AllocateAlignedWithCleanup(n, align, + destructor); } -uint64_t ThreadSafeArena::SpaceAllocated() const { - SerialArena* serial = threads_.load(std::memory_order_acquire); - uint64_t res = 0; - for (; serial; serial = serial->next()) { - res += serial->SpaceAllocated(); +template +void ThreadSafeArena::PerConstSerialArena(Functor fn) const { + const SerialArenaChunk* chunk = head_.load(std::memory_order_acquire); + + for (; chunk; chunk = chunk->next_chunk()) { + absl::Span> span = chunk->arenas(); + // Walks arenas backward to handle the first serial arena the last. This is + // necessary to special-case the initial block. + for (auto it = span.crbegin(); it != span.crend(); ++it) { + const SerialArena* serial = it->load(std::memory_order_relaxed); + // It is possible that newly added SerialArena is not updated although + // size was. This is acceptable for SpaceAllocated and SpaceUsed. + if (serial == nullptr) continue; + fn(serial); + } } - return res; } +template +void ThreadSafeArena::PerSerialArena(Functor fn) { + // By omitting an Acquire barrier we help the sanitizer that any user code + // that doesn't properly synchronize Reset() or the destructor will throw a + // TSAN warning. + SerialArenaChunk* chunk = head_.load(std::memory_order_relaxed); + + for (; chunk; chunk = chunk->next_chunk()) { + absl::Span> span = chunk->arenas(); + // Walks arenas backward to handle the first serial arena the last. This is + // necessary to special-case the initial block. + for (auto it = span.rbegin(); it != span.rend(); ++it) { + SerialArena* serial = it->load(std::memory_order_relaxed); + GOOGLE_DCHECK_NE(serial, nullptr); + if (serial == nullptr) continue; + fn(serial); + } + } +} + +uint64_t ThreadSafeArena::SpaceAllocated() const { + uint64_t space_allocated = 0; + PerConstSerialArena([&space_allocated](const SerialArena* serial) { + space_allocated += serial->SpaceAllocated(); + }); + return space_allocated; +} + +template +PROTOBUF_NOINLINE void* ThreadSafeArena::AllocateAlignedFallback(size_t n) { + return GetSerialArenaFallback()->AllocateAligned(n); +} + +template void* ThreadSafeArena::AllocateAlignedFallback< + AllocationClient::kDefault>(size_t); +template void* + ThreadSafeArena::AllocateAlignedFallback(size_t); + uint64_t ThreadSafeArena::SpaceUsed() const { - SerialArena* serial = threads_.load(std::memory_order_acquire); uint64_t space_used = 0; - for (; serial; serial = serial->next()) { + PerConstSerialArena([&space_used](const SerialArena* serial) { space_used += serial->SpaceUsed(); - } + }); return space_used - (alloc_policy_.get() ? sizeof(AllocationPolicy) : 0); } @@ -495,12 +753,20 @@ void ThreadSafeArena::CleanupList() { } PROTOBUF_NOINLINE -SerialArena* ThreadSafeArena::GetSerialArenaFallback(void* me) { - // Look for this SerialArena in our linked list. - SerialArena* serial = threads_.load(std::memory_order_acquire); - for (; serial; serial = serial->next()) { - if (serial->owner() == me) { - break; +SerialArena* ThreadSafeArena::GetSerialArenaFallback() { + void* const id = &thread_cache(); + SerialArena* serial = nullptr; + + // Search matching SerialArena. + SerialArenaChunk* chunk = head_.load(std::memory_order_acquire); + for (; chunk; chunk = chunk->next_chunk()) { + absl::Span> ids = chunk->ids(); + for (unsigned i = 0; i < ids.size(); ++i) { + if (ids[i].load(std::memory_order_relaxed) == id) { + serial = chunk->arena(i).load(std::memory_order_relaxed); + GOOGLE_DCHECK_NE(serial, nullptr); + break; + } } } @@ -508,14 +774,9 @@ SerialArena* ThreadSafeArena::GetSerialArenaFallback(void* me) { // This thread doesn't have any SerialArena, which also means it doesn't // have any blocks yet. So we'll allocate its first block now. serial = SerialArena::New( - AllocateMemory(alloc_policy_.get(), 0, kSerialArenaSize), me, - arena_stats_.MutableStats()); + AllocateMemory(alloc_policy_.get(), 0, kSerialArenaSize), *this); - SerialArena* head = threads_.load(std::memory_order_relaxed); - do { - serial->set_next(head); - } while (!threads_.compare_exchange_weak( - head, serial, std::memory_order_release, std::memory_order_relaxed)); + AddSerialArena(id, serial); } CacheSerialArena(serial); @@ -538,4 +799,4 @@ void* Arena::AllocateAlignedWithCleanup(size_t n, size_t align, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 5a665a7535..4bc39948e3 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -49,11 +49,12 @@ using type_info = ::type_info; #endif #include -#include -#include +#include "google/protobuf/arena_config.h" +#include "google/protobuf/arena_impl.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -143,7 +144,7 @@ struct ArenaOptions { ArenaOptions() : start_block_size(internal::AllocationPolicy::kDefaultStartBlockSize), - max_block_size(internal::AllocationPolicy::kDefaultMaxBlockSize), + max_block_size(internal::GetDefaultArenaMaxBlockSize()), initial_block(nullptr), initial_block_size(0), block_alloc(nullptr), @@ -770,6 +771,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_ARENA_H__ diff --git a/src/google/protobuf/arena_config.cc b/src/google/protobuf/arena_config.cc new file mode 100644 index 0000000000..813f7d02f0 --- /dev/null +++ b/src/google/protobuf/arena_config.cc @@ -0,0 +1,53 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "google/protobuf/arena_config.h" + +#include +#include + +// Must be included last. +#include "google/protobuf/port_def.inc" + +namespace google { +namespace protobuf { +namespace internal { + +PROTOBUF_CONSTINIT const size_t kDefaultDefaultArenaMaxBlockSize = 8 << 10; + +namespace arena_config_internal { + +std::atomic default_arena_max_block_size{ + kDefaultDefaultArenaMaxBlockSize}; + +} // namespace arena_config_internal +} // namespace internal +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/arena_config.h b/src/google/protobuf/arena_config.h new file mode 100644 index 0000000000..f16d86a5ec --- /dev/null +++ b/src/google/protobuf/arena_config.h @@ -0,0 +1,73 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef GOOGLE_PROTOBUF_ARENA_CONFIG_H__ +#define GOOGLE_PROTOBUF_ARENA_CONFIG_H__ + +#include +#include + +// Must be included last. +#include "google/protobuf/port_def.inc" + +namespace google { +namespace protobuf { +namespace internal { +namespace arena_config_internal { + +// We use an atomic here only for correctness so that we can read/write +// concurrently. We don't have memory order requirements so we use relaxed +// memory ordering. +PROTOBUF_EXPORT extern std::atomic default_arena_max_block_size; + +} // namespace arena_config_internal + +// The default value to use for DefaultArenaMaxBlockSize when +// SetDefaultArenaMaxBlockSize hasn't been called. +PROTOBUF_EXPORT extern const size_t kDefaultDefaultArenaMaxBlockSize; + +// The default value to use for arena max block size when no value is provided +// in ArenaOptions. +inline size_t GetDefaultArenaMaxBlockSize() { + return arena_config_internal::default_arena_max_block_size.load( + std::memory_order_relaxed); +} +inline void SetDefaultArenaMaxBlockSize(size_t default_arena_max_block_size) { + return arena_config_internal::default_arena_max_block_size.store( + default_arena_max_block_size, std::memory_order_relaxed); +} + +} // namespace internal +} // namespace protobuf +} // namespace google + +#include "google/protobuf/port_undef.inc" + +#endif // GOOGLE_PROTOBUF_ARENA_CONFIG_H__ diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h index d8fdd3d14e..2eb6c505ad 100644 --- a/src/google/protobuf/arena_impl.h +++ b/src/google/protobuf/arena_impl.h @@ -38,19 +38,22 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "absl/numeric/bits.h" +#include "absl/synchronization/mutex.h" +#include "google/protobuf/port.h" #ifdef ADDRESS_SANITIZER #include #endif // ADDRESS_SANITIZER -#include +#include "google/protobuf/arena_config.h" +#include "google/protobuf/arenaz_sampler.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { @@ -243,17 +246,16 @@ class PROTOBUF_EXPORT ArenaMetricsCollector { struct AllocationPolicy { static constexpr size_t kDefaultStartBlockSize = 256; - static constexpr size_t kDefaultMaxBlockSize = 8192; size_t start_block_size = kDefaultStartBlockSize; - size_t max_block_size = kDefaultMaxBlockSize; + size_t max_block_size = GetDefaultArenaMaxBlockSize(); void* (*block_alloc)(size_t) = nullptr; void (*block_dealloc)(void*, size_t) = nullptr; bool IsDefault() const { return start_block_size == kDefaultStartBlockSize && - max_block_size == kDefaultMaxBlockSize && block_alloc == nullptr && - block_dealloc == nullptr; + max_block_size == GetDefaultArenaMaxBlockSize() && + block_alloc == nullptr && block_dealloc == nullptr; } }; @@ -317,6 +319,8 @@ class TaggedAllocationPolicyPtr { enum class AllocationClient { kDefault, kArray }; +class ThreadSafeArena; + // A simple arena allocator. Calls to allocate functions must be properly // serialized by the caller, hence this class cannot be used as a general // purpose allocator in a multi-threaded program. It serves as a building block @@ -350,7 +354,7 @@ class PROTOBUF_EXPORT SerialArena { if (PROTOBUF_PREDICT_FALSE(size < 16)) return nullptr; // We round up to the next larger block in case the memory doesn't match // the pattern we are looking for. - const size_t index = Bits::Log2FloorNonZero64(size - 1) - 3; + const size_t index = absl::bit_width(size - 1) - 4; if (index >= cached_block_length_) return nullptr; auto& cached_head = cached_blocks_[index]; @@ -372,8 +376,7 @@ class PROTOBUF_EXPORT SerialArena { // the right size. We can statically know if the allocation size can benefit // from it. template - void* AllocateAligned(size_t n, const AllocationPolicy* policy, - ThreadSafeArenaStats* stats) { + void* AllocateAligned(size_t n) { GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. GOOGLE_DCHECK_GE(limit_, ptr()); @@ -384,7 +387,7 @@ class PROTOBUF_EXPORT SerialArena { } if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) { - return AllocateAlignedFallback(n, policy, stats); + return AllocateAlignedFallback(n); } return AllocateFromExisting(n); } @@ -407,13 +410,13 @@ class PROTOBUF_EXPORT SerialArena { if (sizeof(void*) < 8) { if (PROTOBUF_PREDICT_FALSE(size < 16)) return; } else { - GOOGLE_DCHECK(size >= 16); + PROTOBUF_ASSUME(size >= 16); } // We round down to the next smaller block in case the memory doesn't match // the pattern we are looking for. eg, someone might have called Reserve() // on the repeated field. - const size_t index = Bits::Log2FloorNonZero64(size) - 4; + const size_t index = absl::bit_width(size) - 5; if (PROTOBUF_PREDICT_FALSE(index >= cached_block_length_)) { // We can't put this object on the freelist so make this object the @@ -485,13 +488,10 @@ class PROTOBUF_EXPORT SerialArena { PROTOBUF_ALWAYS_INLINE void* AllocateAlignedWithCleanup(size_t n, size_t align, - void (*destructor)(void*), - const AllocationPolicy* policy, - ThreadSafeArenaStats* stats) { + void (*destructor)(void*)) { size_t required = AlignUpTo(n, align) + cleanup::Size(destructor); if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) { - return AllocateAlignedWithCleanupFallback(n, align, destructor, policy, - stats); + return AllocateAlignedWithCleanupFallback(n, align, destructor); } return AllocateFromExistingWithCleanupFallback(n, align, destructor); } @@ -501,7 +501,7 @@ class PROTOBUF_EXPORT SerialArena { const AllocationPolicy* policy, ThreadSafeArenaStats* stats) { size_t required = cleanup::Size(destructor); if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) { - return AddCleanupFallback(elem, destructor, policy, stats); + return AddCleanupFallback(elem, destructor); } AddCleanupFromExisting(elem, destructor); } @@ -533,18 +533,14 @@ class PROTOBUF_EXPORT SerialArena { cleanup::CreateNode(tag, limit_, elem, destructor); } - public: - void* owner() const { return owner_; } - SerialArena* next() const { return next_; } - void set_next(SerialArena* next) { next_ = next; } - private: friend class ThreadSafeArena; // Creates a new SerialArena inside mem using the remaining memory as for // future allocations. - static SerialArena* New(SerialArena::Memory mem, void* owner, - ThreadSafeArenaStats* stats); + // The `parent` arena must outlive the serial arena, which is guaranteed + // because the parent manages the lifetime of the serial arenas. + static SerialArena* New(SerialArena::Memory mem, ThreadSafeArena& parent); // Free SerialArena returning the memory passed in to New template Memory Free(Deallocator deallocator); @@ -570,9 +566,8 @@ class PROTOBUF_EXPORT SerialArena { // data follows }; - void* owner_; // &ThreadCache of this thread; + ThreadSafeArena& parent_; std::atomic head_; // Head of linked list of blocks. - SerialArena* next_; // Next SerialArena in this linked list. std::atomic space_used_{0}; // Necessary for metrics. std::atomic space_allocated_; @@ -609,18 +604,12 @@ class PROTOBUF_EXPORT SerialArena { CachedBlock** cached_blocks_ = nullptr; // Constructor is private as only New() should be used. - inline SerialArena(Block* b, void* owner); - void* AllocateAlignedFallback(size_t n, const AllocationPolicy* policy, - ThreadSafeArenaStats* stats); + inline SerialArena(Block* b, ThreadSafeArena& parent); + void* AllocateAlignedFallback(size_t n); void* AllocateAlignedWithCleanupFallback(size_t n, size_t align, - void (*destructor)(void*), - const AllocationPolicy* policy, - ThreadSafeArenaStats* stats); - void AddCleanupFallback(void* elem, void (*destructor)(void*), - const AllocationPolicy* policy, - ThreadSafeArenaStats* stats); - void AllocateNewBlock(size_t n, const AllocationPolicy* policy, - ThreadSafeArenaStats* stats); + void (*destructor)(void*)); + void AddCleanupFallback(void* elem, void (*destructor)(void*)); + void AllocateNewBlock(size_t n); public: static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(Block)); @@ -677,11 +666,9 @@ class PROTOBUF_EXPORT ThreadSafeArena { void* AllocateAligned(size_t n) { SerialArena* arena; if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - return arena->AllocateAligned(n, AllocPolicy(), - arena_stats_.MutableStats()); + return arena->AllocateAligned(n); } else { - return GetSerialArenaFallback(&thread_cache()) - ->AllocateAligned(n, AllocPolicy(), arena_stats_.MutableStats()); + return AllocateAlignedFallback(n); } } @@ -717,9 +704,21 @@ class PROTOBUF_EXPORT ThreadSafeArena { } private: + friend class ArenaBenchmark; friend class TcParser; + friend class SerialArena; static uint64_t GetNextLifeCycleId(); + class SerialArenaChunk; + + // Returns a new SerialArenaChunk that has {id, serial} at slot 0. It may + // grow based on "prev_num_slots". + static SerialArenaChunk* NewSerialArenaChunk(uint32_t prev_capacity, void* id, + SerialArena* serial); + + // Adds SerialArena to the chunked list. May create a new chunk. + void AddSerialArena(void* id, SerialArena* serial); + // Unique for each arena. Changes on Reset(). uint64_t tag_and_id_ = 0; // The LSB of tag_and_id_ indicates if the arena is message-owned. @@ -729,8 +728,11 @@ class PROTOBUF_EXPORT ThreadSafeArena { static_assert(std::is_trivially_destructible{}, "SerialArena needs to be trivially destructible."); - // Pointer to a linked list of SerialArena. - std::atomic threads_; + // Pointer to a linked list of SerialArenaChunk. + std::atomic head_; + + // Adding a new chunk to head_ must be protected by mutex_. + absl::Mutex mutex_; const AllocationPolicy* AllocPolicy() const { return alloc_policy_.get(); } void InitializeFrom(void* mem, size_t size); @@ -739,7 +741,7 @@ class PROTOBUF_EXPORT ThreadSafeArena { void (*destructor)(void*)); void Init(); - void SetInitialBlock(void* mem, size_t size); + SerialArena* SetInitialBlock(void* mem, size_t size); // Delete or Destruct all objects owned by the arena. void CleanupList(); @@ -762,16 +764,22 @@ class PROTOBUF_EXPORT ThreadSafeArena { } return false; } - SerialArena* GetSerialArenaFallback(void* me); + // Finds SerialArena or creates one if not found. + SerialArena* GetSerialArenaFallback(); + + template + void* AllocateAlignedFallback(size_t n); + + // Executes callback function over chunked list of SerialArena in reverse + // chronological order. Passes const SerialArena*. template - void PerSerialArena(Functor fn) { - // By omitting an Acquire barrier we ensure that any user code that doesn't - // properly synchronize Reset() or the destructor will throw a TSAN warning. - SerialArena* serial = threads_.load(std::memory_order_relaxed); + void PerConstSerialArena(Functor fn) const; - for (; serial; serial = serial->next()) fn(serial); - } + // Executes callback function over chunked list of SerialArena in reverse + // chronological order. + template + void PerSerialArena(Functor fn); // Releases all memory except the first block which it returns. The first // block might be owned by the user and thus need some extra checks before @@ -847,6 +855,6 @@ class PROTOBUF_EXPORT ThreadSafeArena { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_ARENA_IMPL_H__ diff --git a/src/google/protobuf/arena_test_util.cc b/src/google/protobuf/arena_test_util.cc index 2cb5075564..50f20a1469 100644 --- a/src/google/protobuf/arena_test_util.cc +++ b/src/google/protobuf/arena_test_util.cc @@ -28,10 +28,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/arena_test_util.h" -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #define EXPECT_EQ GOOGLE_CHECK_EQ diff --git a/src/google/protobuf/arena_test_util.h b/src/google/protobuf/arena_test_util.h index 6e42d4bc22..0c00e76f24 100644 --- a/src/google/protobuf/arena_test_util.h +++ b/src/google/protobuf/arena_test_util.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__ -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index fe4bb5c0a8..c576a35a2f 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/arena.h" #include #include @@ -39,29 +39,29 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_arena.pb.h" #include #include #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/arena_test_util.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/message.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/test_util.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format_lite.h" #include "absl/synchronization/mutex.h" // Must be included last -#include +#include "google/protobuf/port_def.inc" using proto2_arena_unittest::ArenaMessage; using protobuf_unittest::ForeignMessage; @@ -1575,4 +1575,4 @@ TEST(ArenaTest, SpaceReusePoisonsAndUnpoisonsMemory) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index b393d42475..2a183d3d9d 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -28,21 +28,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/arenastring.h" #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" -#include -#include -#include +#include "google/protobuf/message_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/stubs/stl_util.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on namespace google { @@ -277,4 +277,4 @@ const char* EpsCopyInputStream::ReadArenaString(const char* ptr, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 547d432f13..519e50d00c 100644 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -36,15 +36,15 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/port.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/explicitly_constructed.h" // must be last: -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -476,6 +476,6 @@ inline std::string* ArenaStringPtr::UnsafeMutablePointer() { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_ARENASTRING_H__ diff --git a/src/google/protobuf/arenastring_unittest.cc b/src/google/protobuf/arenastring_unittest.cc index 7f7aa71c97..efb4bf3ce9 100644 --- a/src/google/protobuf/arenastring_unittest.cc +++ b/src/google/protobuf/arenastring_unittest.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/arenastring.h" #include #include @@ -37,18 +37,18 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/message_lite.h" #include #include "absl/strings/string_view.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -151,4 +151,4 @@ TEST_P(DualArena, Swap) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/arenaz_sampler.cc b/src/google/protobuf/arenaz_sampler.cc index ef675182f9..44e53e527a 100644 --- a/src/google/protobuf/arenaz_sampler.cc +++ b/src/google/protobuf/arenaz_sampler.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/arenaz_sampler.h" #include #include @@ -37,7 +37,7 @@ // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/arenaz_sampler.h b/src/google/protobuf/arenaz_sampler.h index c608bcd77d..23ab83a761 100644 --- a/src/google/protobuf/arenaz_sampler.h +++ b/src/google/protobuf/arenaz_sampler.h @@ -39,7 +39,7 @@ // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -257,5 +257,5 @@ void SetThreadSafeArenazGlobalNextSample(int64_t next_sample); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_SRC_PROTOBUF_ARENAZ_SAMPLER_H__ diff --git a/src/google/protobuf/arenaz_sampler_test.cc b/src/google/protobuf/arenaz_sampler_test.cc index ec9429f137..98ff0427bf 100644 --- a/src/google/protobuf/arenaz_sampler_test.cc +++ b/src/google/protobuf/arenaz_sampler_test.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/arenaz_sampler.h" #include #include @@ -42,7 +42,7 @@ // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/annotation_test_util.cc b/src/google/protobuf/compiler/annotation_test_util.cc index f0815c5639..76d39abce9 100644 --- a/src/google/protobuf/compiler/annotation_test_util.cc +++ b/src/google/protobuf/compiler/annotation_test_util.cc @@ -28,20 +28,20 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/annotation_test_util.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/testing/googletest.h" #include namespace google { diff --git a/src/google/protobuf/compiler/annotation_test_util.h b/src/google/protobuf/compiler/annotation_test_util.h index b7c6ddd319..b8356c2e9e 100644 --- a/src/google/protobuf/compiler/annotation_test_util.h +++ b/src/google/protobuf/compiler/annotation_test_util.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_ANNOTATION_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_COMPILER_ANNOTATION_TEST_UTIL_H__ -#include -#include +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/testing/googletest.h" #include // Utilities that assist in writing tests for generator annotations. diff --git a/src/google/protobuf/compiler/code_generator.cc b/src/google/protobuf/compiler/code_generator.cc index 5e9b4f6da1..6c1a967a11 100644 --- a/src/google/protobuf/compiler/code_generator.cc +++ b/src/google/protobuf/compiler/code_generator.cc @@ -32,13 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/code_generator.h" -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/compiler/plugin.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_split.h" namespace google { diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h index 6e46618d45..55b510ab69 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -41,10 +41,11 @@ #include #include #include -#include + +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -200,6 +201,6 @@ PROTOC_EXPORT std::string StripProto(const std::string& filename); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index b6757cf42d..09d82f039b 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -32,11 +32,12 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/command_line_interface.h" -#include +#include "google/protobuf/stubs/platform_macros.h" #include +#include #include #ifdef major #undef major @@ -58,6 +59,10 @@ #include // For PATH_MAX #include +#include +#include +#include +#include #if defined(__APPLE__) #include @@ -65,30 +70,30 @@ #include #endif -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/compiler/subprocess.h" +#include "google/protobuf/compiler/plugin.pb.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/stubs/stringprintf.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/importer.h" +#include "google/protobuf/compiler/zip_writer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/stubs/stl_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1298,9 +1303,9 @@ bool CommandLineInterface::ParseInputFiles( direct_dependencies_.end()) { indirect_imports = true; std::cerr << parsed_file->name() << ": " - << StringReplace(direct_dependencies_violation_msg_, "%s", - parsed_file->dependency(i)->name(), - true /* replace_all */) + << absl::StrReplaceAll( + direct_dependencies_violation_msg_, + {{"%s", parsed_file->dependency(i)->name()}}) << std::endl; } } @@ -1945,6 +1950,23 @@ CommandLineInterface::InterpretArgument(const std::string& name, } mode_ = MODE_PRINT; print_mode_ = PRINT_FREE_FIELDS; + } else if (name == "--enable_codegen_trace") { + // We use environment variables here so that subprocesses see this setting + // when we spawn them. + // + // Setting environment variables is more-or-less asking for a data race, + // because C got this wrong and did not mandate synchronization. + // In practice, this code path is "only" in the main thread of protoc, and + // it is common knowledge that touching setenv in a library is asking for + // life-ruining bugs *anyways*. As such, there is a reasonable probability + // that there isn't another thread kicking environment variables at this + // moment. + +#ifdef _WIN32 + ::_putenv(absl::StrCat(io::Printer::kProtocCodegenTrace, "=yes").c_str()); +#else + ::setenv(io::Printer::kProtocCodegenTrace.data(), "yes", 0); +#endif } else { // Some other flag. Look it up in the generators list. const GeneratorInfo* generator_info = FindGeneratorByFlag(name); @@ -2070,7 +2092,10 @@ Parse PROTO_FILES and generate output based on the options given: defined in the given proto files. Groups share the same field number space with the parent message. Extension ranges are counted as - occupied fields numbers.)"; + occupied fields numbers. + --enable_codegen_trace Enables tracing which parts of protoc are + responsible for what codegen output. Not supported + by all backends or on all platforms.)"; if (!plugin_prefix_.empty()) { std::cout << R"( --plugin=EXECUTABLE Specifies a plugin executable to use. diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 8e2359b2a3..6965e1a2df 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -49,11 +49,11 @@ #include #include -#include #include "absl/strings/string_view.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -465,6 +465,6 @@ class PROTOC_EXPORT CommandLineInterface { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 0a6dc00936..6b330b8ff1 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -45,35 +45,35 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/stringprintf.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/any.pb.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_custom_options.pb.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/status/status.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/compiler/mock_code_generator.h" +#include "google/protobuf/compiler/subprocess.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" -#include +#include "google/protobuf/stubs/strutil.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -372,8 +372,8 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector args) { std::unique_ptr argv(new const char*[args.size()]); - for (int i = 0; i < args.size(); i++) { - args[i] = StringReplace(args[i], "$tmpdir", temp_directory_, true); + for (size_t i = 0; i < args.size(); i++) { + args[i] = absl::StrReplaceAll(args[i], {{"$tmpdir", temp_directory_}}); argv[i] = args[i].c_str(); } @@ -410,7 +410,7 @@ void CommandLineInterfaceTest::CreateTempFile(const std::string& name, // Write file. std::string full_name = temp_directory_ + "/" + name; GOOGLE_CHECK_OK(File::SetContents( - full_name, StringReplace(contents, "$tmpdir", temp_directory_, true), + full_name, absl::StrReplaceAll(contents, {{"$tmpdir", temp_directory_}}), true)); } @@ -429,7 +429,7 @@ void CommandLineInterfaceTest::ExpectNoErrors() { void CommandLineInterfaceTest::ExpectErrorText( const std::string& expected_text) { EXPECT_NE(0, return_code_); - EXPECT_EQ(StringReplace(expected_text, "$tmpdir", temp_directory_, true), + EXPECT_EQ(absl::StrReplaceAll(expected_text, {{"$tmpdir", temp_directory_}}), error_text_); } @@ -542,7 +542,7 @@ void CommandLineInterfaceTest::ExpectFileContent(const std::string& filename, std::string file_contents; GOOGLE_CHECK_OK(File::GetContents(path, &file_contents, true)); - EXPECT_EQ(StringReplace(content, "$tmpdir", temp_directory_, true), + EXPECT_EQ(absl::StrReplaceAll(content, {{"$tmpdir", temp_directory_}}), file_contents); } @@ -2785,7 +2785,7 @@ INSTANTIATE_TEST_SUITE_P(FileDescriptorSetSource, EncodeDecodeTest, #endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN -#include +#include "google/protobuf/port_undef.inc" } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/cpp/BUILD.bazel b/src/google/protobuf/compiler/cpp/BUILD.bazel index 1182a3a934..1798fce624 100644 --- a/src/google/protobuf/compiler/cpp/BUILD.bazel +++ b/src/google/protobuf/compiler/cpp/BUILD.bazel @@ -58,6 +58,7 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/container:layout", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", ], diff --git a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc index b7900d6b23..4685c0ae25 100644 --- a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc @@ -44,19 +44,19 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/compiler/cpp/generator.h" +#include "google/protobuf/compiler/importer.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/container/flat_hash_map.h" #include "absl/strings/substitute.h" -#include -#include +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/stubs/stl_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.h b/src/google/protobuf/compiler/cpp/cpp_generator.h index 1716ab20de..b3364533df 100644 --- a/src/google/protobuf/compiler/cpp/cpp_generator.h +++ b/src/google/protobuf/compiler/cpp/cpp_generator.h @@ -1,6 +1,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ #define GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ -#include +#include "google/protobuf/compiler/cpp/generator.h" #endif // GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ diff --git a/src/google/protobuf/compiler/cpp/enum.cc b/src/google/protobuf/compiler/cpp/enum.cc index a6539c34b0..2cd152abe9 100644 --- a/src/google/protobuf/compiler/cpp/enum.cc +++ b/src/google/protobuf/compiler/cpp/enum.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/enum.h" #include #include @@ -40,10 +40,10 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/names.h" namespace google { namespace protobuf { @@ -51,9 +51,9 @@ namespace compiler { namespace cpp { namespace { -// The GOOGLE_ARRAYSIZE constant is the max enum value plus 1. If the max enum value -// is kint32max, GOOGLE_ARRAYSIZE will overflow. In such cases we should omit the -// generation of the GOOGLE_ARRAYSIZE constant. +// The ARRAYSIZE constant is the max enum value plus 1. If the max enum value +// is kint32max, ARRAYSIZE will overflow. In such cases we should omit the +// generation of the ARRAYSIZE constant. bool ShouldGenerateArraySize(const EnumDescriptor* descriptor) { int32_t max_value = descriptor->value(0)->number(); for (int i = 0; i < descriptor->value_count(); i++) { diff --git a/src/google/protobuf/compiler/cpp/enum.h b/src/google/protobuf/compiler/cpp/enum.h index 88cbd6a74d..33ec3103d0 100644 --- a/src/google/protobuf/compiler/cpp/enum.h +++ b/src/google/protobuf/compiler/cpp/enum.h @@ -39,8 +39,8 @@ #include #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/cpp/options.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/enum_field.cc b/src/google/protobuf/compiler/cpp/enum_field.cc index 1e4389bfe9..2a0397ff59 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.cc +++ b/src/google/protobuf/compiler/cpp/enum_field.cc @@ -32,13 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/enum_field.h" -#include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/compiler/cpp/field.h" +#include "google/protobuf/compiler/cpp/helpers.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/enum_field.h b/src/google/protobuf/compiler/cpp/enum_field.h index 56e046802d..e5d476c4a1 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.h +++ b/src/google/protobuf/compiler/cpp/enum_field.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/cpp/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/extension.cc b/src/google/protobuf/compiler/cpp/extension.cc index 9770413568..4166b08d71 100644 --- a/src/google/protobuf/compiler/cpp/extension.cc +++ b/src/google/protobuf/compiler/cpp/extension.cc @@ -32,16 +32,16 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/extension.h" #include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" -#include -#include +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { @@ -79,7 +79,6 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, type_traits_.append(" >"); break; } - SetCommonVars(options, &variables_); SetCommonMessageDataVariables(descriptor_->containing_type(), &variables_); variables_["extendee"] = QualifiedClassName(descriptor_->containing_type(), options_); @@ -161,7 +160,8 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) { // it in the header which would be annoying for other reasons. So we // replace :: with _ in the name and declare it as a global. default_str = - StringReplace(variables_["scoped_name"], "::", "_", true) + "_default"; + absl::StrReplaceAll(variables_["scoped_name"], {{"::", "_"}}) + + "_default"; format("const std::string $1$($2$);\n", default_str, DefaultValue(options_, descriptor_)); } else if (descriptor_->message_type()) { diff --git a/src/google/protobuf/compiler/cpp/extension.h b/src/google/protobuf/compiler/cpp/extension.h index d6d73152f0..1c0e020b99 100644 --- a/src/google/protobuf/compiler/cpp/extension.h +++ b/src/google/protobuf/compiler/cpp/extension.h @@ -38,8 +38,8 @@ #include #include -#include -#include +#include "google/protobuf/compiler/cpp/options.h" +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index 5c373282e9..bc93afa21a 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/field.h" #include #include @@ -41,18 +41,18 @@ #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/primitive_field.h" +#include "google/protobuf/compiler/cpp/string_field.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/compiler/cpp/enum_field.h" +#include "google/protobuf/compiler/cpp/map_field.h" +#include "google/protobuf/compiler/cpp/message_field.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { @@ -155,7 +155,6 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, std::string field_member = (*variables)["field"]; const google::protobuf::OneofDescriptor* oneof_member = descriptor->real_containing_oneof(); - const std::string proto_ns = (*variables)["proto_ns"]; const std::string substitute_template_prefix = absl::StrCat(" ", (*variables)["tracker"], ".$1<$0>(this, "); std::string prepared_template; @@ -183,7 +182,7 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, } else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { if (oneof_member) { prepared_template = GenerateTemplateForOneofString( - descriptor, (*variables)["proto_ns"], field_member); + descriptor, ProtobufNamespace(options), field_member); } else { prepared_template = GenerateTemplateForSingleString(descriptor, field_member); @@ -237,7 +236,6 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, void SetCommonFieldVariables(const FieldDescriptor* descriptor, std::map* variables, const Options& options) { - SetCommonVars(options, variables); SetCommonMessageDataVariables(descriptor->containing_type(), variables); (*variables)["ns"] = Namespace(descriptor, options); diff --git a/src/google/protobuf/compiler/cpp/field.h b/src/google/protobuf/compiler/cpp/field.h index dbd6db09d0..b23a2a680f 100644 --- a/src/google/protobuf/compiler/cpp/field.h +++ b/src/google/protobuf/compiler/cpp/field.h @@ -40,9 +40,9 @@ #include #include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/options.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 647884895e..dff09a8690 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/file.h" #include #include @@ -42,20 +42,20 @@ #include #include -#include +#include "google/protobuf/compiler/scc.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/cpp/enum.h" +#include "google/protobuf/compiler/cpp/extension.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/message.h" +#include "google/protobuf/compiler/cpp/service.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -110,7 +110,6 @@ inline void UnmuteWuninitialized(Formatter& format) { FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) : file_(file), options_(options), scc_analyzer_(options) { // These variables are the same on a file level - SetCommonVars(options, &variables_); variables_["dllexport_decl"] = options.dllexport_decl; variables_["tablename"] = UniqueName("TableStruct", file_, options_); variables_["file_level_metadata"] = @@ -258,7 +257,8 @@ void FileGenerator::GenerateProtoHeader(io::Printer* printer, return; } - GenerateTopHeaderGuard(printer, false); + GenerateTopHeaderGuard(printer, + google::protobuf::compiler::cpp::GeneratedFileType::kProtoH); if (!options_.opensource_runtime) { format( @@ -286,13 +286,15 @@ void FileGenerator::GenerateProtoHeader(io::Printer* printer, GenerateHeader(printer); - GenerateBottomHeaderGuard(printer, false); + GenerateBottomHeaderGuard(printer, + google::protobuf::compiler::cpp::GeneratedFileType::kProtoH); } void FileGenerator::GeneratePBHeader(io::Printer* printer, const std::string& info_path) { Formatter format(printer, variables_); - GenerateTopHeaderGuard(printer, true); + GenerateTopHeaderGuard(printer, + google::protobuf::compiler::cpp::GeneratedFileType::kPbH); if (options_.proto_h) { std::string target_basename = StripProto(file_->name()); @@ -331,7 +333,8 @@ void FileGenerator::GeneratePBHeader(io::Printer* printer, "\n"); } - GenerateBottomHeaderGuard(printer, true); + GenerateBottomHeaderGuard(printer, + google::protobuf::compiler::cpp::GeneratedFileType::kPbH); } void FileGenerator::DoIncludeFile(const std::string& google3_name, @@ -347,7 +350,7 @@ void FileGenerator::DoIncludeFile(const std::string& google3_name, path = StringReplace(path, "proto/", "", false); path = StringReplace(path, "public/", "", false); if (options_.runtime_include_base.empty()) { - format("#include ", path); + format("#include \"google/protobuf/$1$\"", path); } else { format("#include \"$1$google/protobuf/$2$\"", options_.runtime_include_base, path); @@ -1084,7 +1087,8 @@ void FileGenerator::GenerateForwardDeclarations(io::Printer* printer) { format("PROTOBUF_NAMESPACE_CLOSE\n"); } -void FileGenerator::GenerateTopHeaderGuard(io::Printer* printer, bool pb_h) { +void FileGenerator::GenerateTopHeaderGuard( + io::Printer* printer, google::protobuf::compiler::cpp::GeneratedFileType file_type) { Formatter format(printer, variables_); // Generate top of header. format( @@ -1096,7 +1100,7 @@ void FileGenerator::GenerateTopHeaderGuard(io::Printer* printer, bool pb_h) { "\n" "#include \n" "#include \n", - IncludeGuard(file_, pb_h, options_)); + IncludeGuard(file_, file_type, options_)); if (!options_.opensource_runtime && !enum_generators_.empty()) { // Add header to provide std::is_integral for safe Enum_Name() function. format("#include \n"); @@ -1104,10 +1108,11 @@ void FileGenerator::GenerateTopHeaderGuard(io::Printer* printer, bool pb_h) { format("\n"); } -void FileGenerator::GenerateBottomHeaderGuard(io::Printer* printer, bool pb_h) { +void FileGenerator::GenerateBottomHeaderGuard( + io::Printer* printer, google::protobuf::compiler::cpp::GeneratedFileType file_type) { Formatter format(printer, variables_); format("#endif // $GOOGLE_PROTOBUF$_INCLUDED_$1$\n", - IncludeGuard(file_, pb_h, options_)); + IncludeGuard(file_, file_type, options_)); } void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/cpp/file.h b/src/google/protobuf/compiler/cpp/file.h index 063610f2f6..072b9138af 100644 --- a/src/google/protobuf/compiler/cpp/file.h +++ b/src/google/protobuf/compiler/cpp/file.h @@ -41,11 +41,12 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/compiler/cpp/field.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/port.h" +#include "google/protobuf/compiler/scc.h" +#include "google/protobuf/compiler/cpp/options.h" namespace google { namespace protobuf { @@ -136,8 +137,10 @@ class FileGenerator { void GenerateForwardDeclarations(io::Printer* printer); // Generates top or bottom of a header file. - void GenerateTopHeaderGuard(io::Printer* printer, bool pb_h); - void GenerateBottomHeaderGuard(io::Printer* printer, bool pb_h); + void GenerateTopHeaderGuard( + io::Printer* printer, google::protobuf::compiler::cpp::GeneratedFileType file_type); + void GenerateBottomHeaderGuard( + io::Printer* printer, google::protobuf::compiler::cpp::GeneratedFileType file_type); // Generates #include directives. void GenerateLibraryIncludes(io::Printer* printer); diff --git a/src/google/protobuf/compiler/cpp/generator.cc b/src/google/protobuf/compiler/cpp/generator.cc index fa33bf3720..3c25ec84d1 100644 --- a/src/google/protobuf/compiler/cpp/generator.cc +++ b/src/google/protobuf/compiler/cpp/generator.cc @@ -32,41 +32,69 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/generator.h" #include #include #include #include -#include -#include -#include +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" -#include -#include -#include +#include "google/protobuf/compiler/cpp/file.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { namespace compiler { namespace cpp { - -CppGenerator::CppGenerator() {} -CppGenerator::~CppGenerator() {} - namespace { -std::string NumberedCcFileName(const std::string& basename, int number) { +std::string NumberedCcFileName(absl::string_view basename, int number) { return absl::StrCat(basename, ".out/", number, ".cc"); } + +absl::flat_hash_map CommonVars( + const Options& options) { + bool is_oss = options.opensource_runtime; + return { + {"proto_ns", ProtobufNamespace(options)}, + {"string", "std::string"}, + {"int8", "int8_t"}, + {"int32", "int32_t"}, + {"int64", "int64_t"}, + {"uint8", "uint8_t"}, + {"uint32", "uint32_t"}, + {"uint64", "uint64_t"}, + + // Warning: there is some clever naming/splitting here to avoid extract + // script rewrites. The names of these variables must not be things that + // the extract script will rewrite. That's why we use "CHK" (for example) + // instead of "GOOGLE_CHECK". + // + // These values are things the extract script would rewrite if we did not + // split them. It might not strictly matter since we don't generate + // google3 code in open-source. But it's good to prevent surprising + // things from happening. + {"GOOGLE_PROTOBUF", is_oss ? "GOOGLE_PROTOBUF" + : "GOOGLE3_PROTOBU" + "F"}, + {"CHK", is_oss ? "GOOGLE_CHECK" + : "CHECK"}, + {"DCHK", is_oss ? "GOOGLE_DCHECK" + : "DCHECK"}, + }; +} } // namespace bool CppGenerator::Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* generator_context, std::string* error) const { - std::vector > options; + std::vector> options; ParseGeneratorParameter(parameter, &options); // ----------------------------------------------------------------- @@ -95,68 +123,70 @@ bool CppGenerator::Generate(const FileDescriptor* file, file_options.opensource_runtime = opensource_runtime_; file_options.runtime_include_base = runtime_include_base_; - for (int i = 0; i < options.size(); i++) { - if (options[i].first == "dllexport_decl") { - file_options.dllexport_decl = options[i].second; - } else if (options[i].first == "safe_boundary_check") { + for (const auto& option : options) { + const auto& key = option.first; + const auto& value = option.second; + + if (key == "dllexport_decl") { + file_options.dllexport_decl = value; + } else if (key == "safe_boundary_check") { file_options.safe_boundary_check = true; - } else if (options[i].first == "annotate_headers") { + } else if (key == "annotate_headers") { file_options.annotate_headers = true; - } else if (options[i].first == "annotation_pragma_name") { - file_options.annotation_pragma_name = options[i].second; - } else if (options[i].first == "annotation_guard_name") { - file_options.annotation_guard_name = options[i].second; - } else if (options[i].first == "speed") { + } else if (key == "annotation_pragma_name") { + file_options.annotation_pragma_name = value; + } else if (key == "annotation_guard_name") { + file_options.annotation_guard_name = value; + } else if (key == "speed") { file_options.enforce_mode = EnforceOptimizeMode::kSpeed; - } else if (options[i].first == "code_size") { + } else if (key == "code_size") { file_options.enforce_mode = EnforceOptimizeMode::kCodeSize; - } else if (options[i].first == "lite") { + } else if (key == "lite") { file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime; - } else if (options[i].first == "lite_implicit_weak_fields") { + } else if (key == "lite_implicit_weak_fields") { file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime; file_options.lite_implicit_weak_fields = true; - if (!options[i].second.empty()) { - file_options.num_cc_files = - strto32(options[i].second.c_str(), nullptr, 10); + if (!value.empty()) { + file_options.num_cc_files = strto32(value.c_str(), nullptr, 10); } - } else if (options[i].first == "proto_h") { + } else if (key == "proto_h") { file_options.proto_h = true; - } else if (options[i].first == "annotate_accessor") { + } else if (key == "annotate_accessor") { file_options.annotate_accessor = true; - } else if (options[i].first == "inject_field_listener_events") { + } else if (key == "inject_field_listener_events") { file_options.field_listener_options.inject_field_listener_events = true; - } else if (options[i].first == "forbidden_field_listener_events") { + } else if (key == "forbidden_field_listener_events") { std::size_t pos = 0; do { - std::size_t next_pos = options[i].second.find_first_of("+", pos); + std::size_t next_pos = value.find_first_of("+", pos); if (next_pos == std::string::npos) { - next_pos = options[i].second.size(); + next_pos = value.size(); } if (next_pos > pos) file_options.field_listener_options.forbidden_field_listener_events - .insert(options[i].second.substr(pos, next_pos - pos)); + .insert(value.substr(pos, next_pos - pos)); pos = next_pos + 1; - } while (pos < options[i].second.size()); - } else if (options[i].first == "unverified_lazy_message_sets") { + } while (pos < value.size()); + } else if (key == "unverified_lazy_message_sets") { file_options.unverified_lazy_message_sets = true; - } else if (options[i].first == "message_owned_arena_trial") { + } else if (key == "message_owned_arena_trial") { file_options.message_owned_arena_trial = true; - } else if (options[i].first == "force_eagerly_verified_lazy") { + } else if (key == "force_eagerly_verified_lazy") { file_options.force_eagerly_verified_lazy = true; - } else if (options[i].first == "experimental_tail_call_table_mode") { - if (options[i].second == "never") { + } else if (key == "experimental_tail_call_table_mode") { + if (value == "never") { file_options.tctable_mode = Options::kTCTableNever; - } else if (options[i].second == "guarded") { + } else if (value == "guarded") { file_options.tctable_mode = Options::kTCTableGuarded; - } else if (options[i].second == "always") { + } else if (value == "always") { file_options.tctable_mode = Options::kTCTableAlways; } else { - *error = "Unknown value for experimental_tail_call_table_mode: " + - options[i].second; + *error = + "Unknown value for experimental_tail_call_table_mode: " + value; return false; } } else { - *error = "Unknown generator option: " + options[i].first; + *error = "Unknown generator option: " + key; return false; } } @@ -183,39 +213,51 @@ bool CppGenerator::Generate(const FileDescriptor* file, // Generate header(s). if (file_options.proto_h) { - std::unique_ptr output( - generator_context->Open(basename + ".proto.h")); + auto output = absl::WrapUnique( + generator_context->Open(absl::StrCat(basename, ".proto.h"))); + GeneratedCodeInfo annotations; io::AnnotationProtoCollector annotation_collector( &annotations); - std::string info_path = basename + ".proto.h.meta"; - io::Printer printer( - output.get(), '$', - file_options.annotate_headers ? &annotation_collector : nullptr); + io::Printer::Options options; + if (file_options.annotate_headers) { + options.annotation_collector = &annotation_collector; + } + + io::Printer p(output.get(), options); + auto v = p.WithVars(CommonVars(file_options)); + + std::string info_path = absl::StrCat(basename, ".proto.h.meta"); file_generator.GenerateProtoHeader( - &printer, file_options.annotate_headers ? info_path : ""); + &p, file_options.annotate_headers ? info_path : ""); + if (file_options.annotate_headers) { - std::unique_ptr info_output( - generator_context->Open(info_path)); + auto info_output = absl::WrapUnique(generator_context->Open(info_path)); annotations.SerializeToZeroCopyStream(info_output.get()); } } { - std::unique_ptr output( - generator_context->Open(basename + ".pb.h")); + auto output = absl::WrapUnique( + generator_context->Open(absl::StrCat(basename, ".pb.h"))); + GeneratedCodeInfo annotations; io::AnnotationProtoCollector annotation_collector( &annotations); - std::string info_path = basename + ".pb.h.meta"; - io::Printer printer( - output.get(), '$', - file_options.annotate_headers ? &annotation_collector : nullptr); + io::Printer::Options options; + if (file_options.annotate_headers) { + options.annotation_collector = &annotation_collector; + } + + io::Printer p(output.get(), options); + auto v = p.WithVars(CommonVars(file_options)); + + std::string info_path = absl::StrCat(basename, ".pb.h.meta"); file_generator.GeneratePBHeader( - &printer, file_options.annotate_headers ? info_path : ""); + &p, file_options.annotate_headers ? info_path : ""); + if (file_options.annotate_headers) { - std::unique_ptr info_output( - generator_context->Open(info_path)); + auto info_output = absl::WrapUnique(generator_context->Open(info_path)); annotations.SerializeToZeroCopyStream(info_output.get()); } } @@ -225,10 +267,12 @@ bool CppGenerator::Generate(const FileDescriptor* file, { // This is the global .cc file, containing // enum/services/tables/reflection - std::unique_ptr output( - generator_context->Open(basename + ".pb.cc")); - io::Printer printer(output.get(), '$'); - file_generator.GenerateGlobalSource(&printer); + auto output = absl::WrapUnique( + generator_context->Open(absl::StrCat(basename, ".pb.cc"))); + io::Printer p(output.get()); + auto v = p.WithVars(CommonVars(file_options)); + + file_generator.GenerateGlobalSource(&p); } int num_cc_files = @@ -244,35 +288,43 @@ bool CppGenerator::Generate(const FileDescriptor* file, "and extensions."; num_cc_files = file_options.num_cc_files; } + int cc_file_number = 0; - for (int i = 0; i < file_generator.NumMessages(); i++) { - std::unique_ptr output(generator_context->Open( + for (int i = 0; i < file_generator.NumMessages(); ++i) { + auto output = absl::WrapUnique(generator_context->Open( NumberedCcFileName(basename, cc_file_number++))); - io::Printer printer(output.get(), '$'); - file_generator.GenerateSourceForMessage(i, &printer); + io::Printer p(output.get()); + auto v = p.WithVars(CommonVars(file_options)); + + file_generator.GenerateSourceForMessage(i, &p); } - for (int i = 0; i < file_generator.NumExtensions(); i++) { - std::unique_ptr output(generator_context->Open( + + for (int i = 0; i < file_generator.NumExtensions(); ++i) { + auto output = absl::WrapUnique(generator_context->Open( NumberedCcFileName(basename, cc_file_number++))); - io::Printer printer(output.get(), '$'); - file_generator.GenerateSourceForExtension(i, &printer); + io::Printer p(output.get()); + auto v = p.WithVars(CommonVars(file_options)); + + file_generator.GenerateSourceForExtension(i, &p); } + // Create empty placeholder files if necessary to match the expected number // of files. - for (; cc_file_number < num_cc_files; ++cc_file_number) { - std::unique_ptr output(generator_context->Open( - NumberedCcFileName(basename, cc_file_number))); + while (cc_file_number < num_cc_files) { + (void)absl::WrapUnique(generator_context->Open( + NumberedCcFileName(basename, cc_file_number++))); } } else { - std::unique_ptr output( - generator_context->Open(basename + ".pb.cc")); - io::Printer printer(output.get(), '$'); - file_generator.GenerateSource(&printer); + auto output = absl::WrapUnique( + generator_context->Open(absl::StrCat(basename, ".pb.cc"))); + io::Printer p(output.get()); + auto v = p.WithVars(CommonVars(file_options)); + + file_generator.GenerateSource(&p); } return true; } - } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/cpp/generator.h b/src/google/protobuf/compiler/cpp/generator.h index 4f3da26c4c..aa4ee82f15 100644 --- a/src/google/protobuf/compiler/cpp/generator.h +++ b/src/google/protobuf/compiler/cpp/generator.h @@ -38,26 +38,27 @@ #define GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ #include -#include +#include + +#include "google/protobuf/compiler/code_generator.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { namespace compiler { namespace cpp { - // CodeGenerator implementation which generates a C++ source file and // header. If you create your own protocol compiler binary and you want // it to support C++ output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. class PROTOC_EXPORT CppGenerator : public CodeGenerator { public: - CppGenerator(); + CppGenerator() = default; CppGenerator(const CppGenerator&) = delete; CppGenerator& operator=(const CppGenerator&) = delete; - ~CppGenerator() override; + ~CppGenerator() override = default; enum class Runtime { kGoogle3, // Use the internal google3 runtime. @@ -76,33 +77,29 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator { // If set to a non-empty string, generated code will do: // #include "/google/protobuf/message.h" // instead of: - // #include + // #include "google/protobuf/message.h" // This has no effect if opensource_runtime = false. - void set_runtime_include_base(const std::string& base) { - runtime_include_base_ = base; + void set_runtime_include_base(std::string base) { + runtime_include_base_ = std::move(base); } - // implements CodeGenerator ---------------------------------------- bool Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* generator_context, std::string* error) const override; uint64_t GetSupportedFeatures() const override { - // We don't fully support this yet, but this is needed to unblock the tests, - // and we will have full support before the experimental flag is removed. return FEATURE_PROTO3_OPTIONAL; } private: - bool opensource_runtime_ = true; + bool opensource_runtime_ = PROTO2_IS_OSS; std::string runtime_include_base_; }; - } // namespace cpp } // namespace compiler } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/cpp/helpers.cc b/src/google/protobuf/compiler/cpp/helpers.cc index 46d6f87b4e..bba2ff5221 100644 --- a/src/google/protobuf/compiler/cpp/helpers.cc +++ b/src/google/protobuf/compiler/cpp/helpers.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/helpers.h" #include #include @@ -41,18 +41,20 @@ #include #include #include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/compiler/scc.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" @@ -62,13 +64,13 @@ #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "absl/synchronization/mutex.h" -#include -#include -#include +#include "google/protobuf/compiler/cpp/names.h" +#include "google/protobuf/compiler/cpp/options.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -80,8 +82,8 @@ namespace { static const char kAnyMessageName[] = "Any"; static const char kAnyProtoFile[] = "google/protobuf/any.proto"; -std::string DotsToColons(const std::string& name) { - return StringReplace(name, ".", "::", true); +std::string DotsToColons(absl::string_view name) { + return absl::StrReplaceAll(name, {{".", "::"}}); } static const char* const kKeywordList[] = { @@ -199,17 +201,13 @@ std::string IntTypeName(const Options& options, const std::string& type) { return type + "_t"; } -void SetIntVar(const Options& options, const std::string& type, - std::map* variables) { - (*variables)[type] = IntTypeName(options, type); -} - // Returns true if the message can potentially allocate memory for its field. // This is used to determine if message-owned arena will be useful. bool AllocExpected(const Descriptor* descriptor) { return false; } + } // namespace bool IsLazy(const FieldDescriptor* field, const Options& options, @@ -236,43 +234,6 @@ bool IsLazilyVerifiedLazy(const FieldDescriptor* field, return false; } -void SetCommonVars(const Options& options, - std::map* variables) { - (*variables)["proto_ns"] = ProtobufNamespace(options); - - // Warning: there is some clever naming/splitting here to avoid extract script - // rewrites. The names of these variables must not be things that the extract - // script will rewrite. That's why we use "CHK" (for example) instead of - // "GOOGLE_CHECK". - if (options.opensource_runtime) { - (*variables)["GOOGLE_PROTOBUF"] = "GOOGLE_PROTOBUF"; - (*variables)["CHK"] = "GOOGLE_CHECK"; - (*variables)["DCHK"] = "GOOGLE_DCHECK"; - } else { - // These values are things the extract script would rewrite if we did not - // split them. It might not strictly matter since we don't generate google3 - // code in open-source. But it's good to prevent surprising things from - // happening. - (*variables)["GOOGLE_PROTOBUF"] = - "GOOGLE3" - "_PROTOBUF"; - (*variables)["CHK"] = - "CH" - "ECK"; - (*variables)["DCHK"] = - "DCH" - "ECK"; - } - - SetIntVar(options, "int8", variables); - SetIntVar(options, "uint8", variables); - SetIntVar(options, "uint32", variables); - SetIntVar(options, "uint64", variables); - SetIntVar(options, "int32", variables); - SetIntVar(options, "int64", variables); - (*variables)["string"] = "std::string"; -} - void SetCommonMessageDataVariables( const Descriptor* descriptor, std::map* variables) { @@ -840,8 +801,8 @@ std::string QualifiedFileLevelSymbol(const FileDescriptor* file, } // Escape C++ trigraphs by escaping question marks to \? -std::string EscapeTrigraphs(const std::string& to_escape) { - return StringReplace(to_escape, "?", "\\?", true); +std::string EscapeTrigraphs(absl::string_view to_escape) { + return absl::StrReplaceAll(to_escape, {{"?", "\\?"}}); } // Escaped function name to eliminate naming conflict. @@ -1375,70 +1336,64 @@ bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context, // Adjust basename, but don't abort code generation. *basename = bootstrap_basename; return false; - } else { - const std::string& forward_to_basename = bootstrap_basename; - - // Generate forwarding headers and empty .pb.cc. - { - std::unique_ptr output( - generator_context->Open(*basename + ".pb.h")); - io::Printer printer(output.get(), '$', nullptr); - printer.Print( - "#ifndef PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n" - "#define PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n" - "#include \"$forward_to_basename$.pb.h\" // IWYU pragma: export\n" - "#endif // PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n", - "forward_to_basename", forward_to_basename, "filename_identifier", - FilenameIdentifier(*basename)); - - if (!options.opensource_runtime) { - // HACK HACK HACK, tech debt from the deeps of proto1 and SWIG - // protocoltype is SWIG'ed and we need to forward - if (*basename == "net/proto/protocoltype") { - printer.Print( - "#ifdef SWIG\n" - "%include \"$forward_to_basename$.pb.h\"\n" - "#endif // SWIG\n", - "forward_to_basename", forward_to_basename); - } - } - } - - { - std::unique_ptr output( - generator_context->Open(*basename + ".proto.h")); - io::Printer printer(output.get(), '$', nullptr); - printer.Print( - "#ifndef PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PROTO_H\n" - "#define PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PROTO_H\n" - "#include \"$forward_to_basename$.proto.h\" // IWYU pragma: " - "export\n" - "#endif // " - "PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PROTO_H\n", - "forward_to_basename", forward_to_basename, "filename_identifier", - FilenameIdentifier(*basename)); - } - - { - std::unique_ptr output( - generator_context->Open(*basename + ".pb.cc")); - io::Printer printer(output.get(), '$', nullptr); - printer.Print("\n"); - } - - { - std::unique_ptr output( - generator_context->Open(*basename + ".pb.h.meta")); - } - - { - std::unique_ptr output( - generator_context->Open(*basename + ".proto.h.meta")); - } - - // Abort code generation. - return true; } + + auto pb_h = absl::WrapUnique( + generator_context->Open(absl::StrCat(*basename, ".pb.h"))); + + io::Printer p(pb_h.get()); + p.Emit( + { + {"fwd_to", bootstrap_basename}, + {"file", FilenameIdentifier(*basename)}, + {"fwd_to_suffix", options.opensource_runtime ? "pb" : "proto"}, + {"swig_evil", + [&] { + if (options.opensource_runtime) { + return; + } + p.Emit(R"( + #ifdef SWIG + %include "$fwd_to$.pb.h" + #endif // SWIG + )"); + }}, + }, + R"( + #ifndef PROTOBUF_INCLUDED_$file$_FORWARD_PB_H + #define PROTOBUF_INCLUDED_$file$_FORWARD_PB_H + #include "$fwd_to$.$fwd_to_suffix$.h" // IWYU pragma: export + #endif // PROTOBUF_INCLUDED_$file$_FORWARD_PB_H + $swig_evil$; + )"); + + auto proto_h = absl::WrapUnique( + generator_context->Open(absl::StrCat(*basename, ".proto.h"))); + io::Printer(proto_h.get()) + .Emit( + { + {"fwd_to", bootstrap_basename}, + {"file", FilenameIdentifier(*basename)}, + }, + R"( + #ifndef PROTOBUF_INCLUDED_$file$_FORWARD_PROTO_H + #define PROTOBUF_INCLUDED_$file$_FORWARD_PROTO_H + #include "$fwd_to$.proto.h" // IWYU pragma: export + #endif // PROTOBUF_INCLUDED_$file$_FORWARD_PROTO_H + )"); + + auto pb_cc = absl::WrapUnique( + generator_context->Open(absl::StrCat(*basename, ".pb.cc"))); + io::Printer(pb_cc.get()).PrintRaw("\n"); + + (void)absl::WrapUnique( + generator_context->Open(absl::StrCat(*basename, ".pb.h.meta"))); + + (void)absl::WrapUnique( + generator_context->Open(absl::StrCat(*basename, ".proto.h.meta"))); + + // Abort code generation. + return true; } static bool HasExtensionFromFile(const Message& msg, const FileDescriptor* file, diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index 3f13ebf800..55fe178cdc 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -41,20 +41,21 @@ #include #include -#include -#include +#include "google/protobuf/compiler/scc.h" +#include "google/protobuf/compiler/code_generator.h" +#include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/cpp/names.h" +#include "google/protobuf/compiler/cpp/options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/port.h" #include "absl/strings/str_cat.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -86,9 +87,6 @@ inline std::string DeprecatedAttribute(const Options& /* options */, extern const char kThickSeparator[]; extern const char kThinSeparator[]; -void SetCommonVars(const Options& options, - std::map* variables); - // Variables to access message data from the message scope. void SetCommonMessageDataVariables( const Descriptor* descriptor, @@ -298,7 +296,7 @@ std::string QualifiedFileLevelSymbol(const FileDescriptor* file, const Options& options); // Escape C++ trigraphs by escaping question marks to \? -std::string EscapeTrigraphs(const std::string& to_escape); +std::string EscapeTrigraphs(absl::string_view to_escape); // Escaped function name to eliminate naming conflict. std::string SafeFunctionName(const Descriptor* descriptor, @@ -518,12 +516,26 @@ bool IsAnyMessage(const Descriptor* descriptor, const Options& options); bool IsWellKnownMessage(const FileDescriptor* descriptor); -inline std::string IncludeGuard(const FileDescriptor* file, bool pb_h, +enum class GeneratedFileType : int { kPbH, kProtoH, kProtoStaticReflectionH }; + +inline std::string IncludeGuard(const FileDescriptor* file, + GeneratedFileType file_type, const Options& options) { // If we are generating a .pb.h file and the proto_h option is enabled, then // the .pb.h gets an extra suffix. - std::string filename_identifier = FilenameIdentifier( - file->name() + (pb_h && options.proto_h ? ".pb.h" : "")); + std::string extension; + switch (file_type) { + case GeneratedFileType::kPbH: + extension = ".pb.h"; + break; + case GeneratedFileType::kProtoH: + extension = ".proto.h"; + break; + case GeneratedFileType::kProtoStaticReflectionH: + extension = ".proto.static_reflection.h"; + } + std::string filename_identifier = + FilenameIdentifier(file->name() + extension); if (IsWellKnownMessage(file)) { // For well-known messages we need third_party/protobuf and net/proto2 to @@ -1000,6 +1012,6 @@ bool HasMessageFieldOrExtension(const Descriptor* desc); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ diff --git a/src/google/protobuf/compiler/cpp/map_field.cc b/src/google/protobuf/compiler/cpp/map_field.cc index c2438184fc..ab8501d72b 100644 --- a/src/google/protobuf/compiler/cpp/map_field.cc +++ b/src/google/protobuf/compiler/cpp/map_field.cc @@ -28,13 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/cpp/map_field.h" -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" -#include +#include "google/protobuf/compiler/cpp/helpers.h" namespace google { diff --git a/src/google/protobuf/compiler/cpp/map_field.h b/src/google/protobuf/compiler/cpp/map_field.h index 9bb63d74ba..06f3e0abc0 100644 --- a/src/google/protobuf/compiler/cpp/map_field.h +++ b/src/google/protobuf/compiler/cpp/map_field.h @@ -34,8 +34,8 @@ #include #include -#include -#include +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/message_field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index b559ff34ad..e779bc61a9 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/message.h" #include #include @@ -45,31 +45,31 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/map_entry_lite.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stringprintf.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/cpp/enum.h" +#include "google/protobuf/compiler/cpp/extension.h" +#include "google/protobuf/compiler/cpp/field.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/padding_optimizer.h" +#include "google/protobuf/compiler/cpp/parse_function_generator.h" +#include "google/protobuf/descriptor.pb.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -410,7 +410,6 @@ class ColdChunkSkipper { has_bit_indices_(has_bit_indices), access_info_map_(options.access_info_map), cold_threshold_(cold_threshold) { - SetCommonVars(options, &variables_); SetCommonMessageDataVariables(descriptor, &variables_); } @@ -4450,4 +4449,4 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* printer) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/cpp/message.h b/src/google/protobuf/compiler/cpp/message.h index c5a2051bd5..3b087d3fda 100644 --- a/src/google/protobuf/compiler/cpp/message.h +++ b/src/google/protobuf/compiler/cpp/message.h @@ -41,11 +41,11 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/cpp/field.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/message_layout_helper.h" +#include "google/protobuf/compiler/cpp/options.h" +#include "google/protobuf/compiler/cpp/parse_function_generator.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/message_field.cc b/src/google/protobuf/compiler/cpp/message_field.cc index a51ad9fdb7..74cca18955 100644 --- a/src/google/protobuf/compiler/cpp/message_field.cc +++ b/src/google/protobuf/compiler/cpp/message_field.cc @@ -32,13 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/message_field.h" -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/compiler/cpp/field.h" +#include "google/protobuf/compiler/cpp/helpers.h" -#include +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { @@ -73,7 +73,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, QualifiedDefaultInstancePtr(descriptor->message_type(), options), implicit_weak); (*variables)["type_reference_function"] = - implicit_weak ? (" ::" + (*variables)["proto_ns"] + + implicit_weak ? (" ::" + ProtobufNamespace(options) + "::internal::StrongReference(reinterpret_cast(\n" + (*variables)["type_default_instance"] + "));\n") diff --git a/src/google/protobuf/compiler/cpp/message_field.h b/src/google/protobuf/compiler/cpp/message_field.h index 4f6d9101aa..39efe28b01 100644 --- a/src/google/protobuf/compiler/cpp/message_field.h +++ b/src/google/protobuf/compiler/cpp/message_field.h @@ -38,8 +38,8 @@ #include #include -#include -#include +#include "google/protobuf/compiler/cpp/field.h" +#include "google/protobuf/compiler/cpp/helpers.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/message_layout_helper.h b/src/google/protobuf/compiler/cpp/message_layout_helper.h index a8813a1f22..7727e67466 100644 --- a/src/google/protobuf/compiler/cpp/message_layout_helper.h +++ b/src/google/protobuf/compiler/cpp/message_layout_helper.h @@ -35,8 +35,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_LAYOUT_HELPER_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_LAYOUT_HELPER_H__ -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/cpp/options.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/message_size_unittest.cc b/src/google/protobuf/compiler/cpp/message_size_unittest.cc index 761988bf66..a75d77a70c 100644 --- a/src/google/protobuf/compiler/cpp/message_size_unittest.cc +++ b/src/google/protobuf/compiler/cpp/message_size_unittest.cc @@ -28,10 +28,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/unittest.pb.h" #include #include -#include +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/metadata_test.cc b/src/google/protobuf/compiler/cpp/metadata_test.cc index 1ffd357484..2a516553e6 100644 --- a/src/google/protobuf/compiler/cpp/metadata_test.cc +++ b/src/google/protobuf/compiler/cpp/metadata_test.cc @@ -30,15 +30,15 @@ #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/compiler/cpp/generator.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/testing/googletest.h" #include -#include -#include +#include "google/protobuf/compiler/annotation_test_util.h" +#include "google/protobuf/compiler/cpp/helpers.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/move_unittest.cc b/src/google/protobuf/compiler/cpp/move_unittest.cc index eb7cd1c775..e723346291 100644 --- a/src/google/protobuf/compiler/cpp/move_unittest.cc +++ b/src/google/protobuf/compiler/cpp/move_unittest.cc @@ -28,9 +28,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/test_util.h" +#include "google/protobuf/unittest.pb.h" #include #if LANG_CXX11 diff --git a/src/google/protobuf/compiler/cpp/names.h b/src/google/protobuf/compiler/cpp/names.h index 7404ac530f..d83cabbac0 100644 --- a/src/google/protobuf/compiler/cpp/names.h +++ b/src/google/protobuf/compiler/cpp/names.h @@ -34,7 +34,7 @@ #include // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -92,6 +92,6 @@ PROTOC_EXPORT std::string StripProto(const std::string& filename); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ diff --git a/src/google/protobuf/compiler/cpp/padding_optimizer.cc b/src/google/protobuf/compiler/cpp/padding_optimizer.cc index c04488ee63..74804b2966 100644 --- a/src/google/protobuf/compiler/cpp/padding_optimizer.cc +++ b/src/google/protobuf/compiler/cpp/padding_optimizer.cc @@ -28,9 +28,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/cpp/padding_optimizer.h" -#include +#include "google/protobuf/compiler/cpp/helpers.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/padding_optimizer.h b/src/google/protobuf/compiler/cpp/padding_optimizer.h index 9c76f38c47..4f55e649a3 100644 --- a/src/google/protobuf/compiler/cpp/padding_optimizer.h +++ b/src/google/protobuf/compiler/cpp/padding_optimizer.h @@ -35,7 +35,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PADDING_OPTIMIZER_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_PADDING_OPTIMIZER_H__ -#include +#include "google/protobuf/compiler/cpp/message_layout_helper.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index cb813a7e21..e4f057f48b 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/cpp/parse_function_generator.h" #include #include #include #include -#include +#include "google/protobuf/wire_format.h" #include "absl/strings/str_cat.h" -#include -#include -#include +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/generated_message_tctable_gen.h" +#include "google/protobuf/generated_message_tctable_impl.h" namespace google { namespace protobuf { @@ -120,7 +120,6 @@ ParseFunctionGenerator::ParseFunctionGenerator( descriptor_, ordered_fields_, GeneratedOptionProvider(this), has_bit_indices, inlined_string_indices)); } - SetCommonVars(options_, &variables_); SetCommonMessageDataVariables(descriptor_, &variables_); SetUnknownFieldsVariable(descriptor_, options_, &variables_); variables_["classname"] = ClassName(descriptor, false); @@ -621,6 +620,10 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) { } if (info.func_name.empty()) { format("{::_pbi::TcParser::MiniParse, {}},\n"); + } else if (info.field == nullptr) { + // Fast slot that is not associated with a field. Eg end group tags. + format("{$1$, {$2$, $3$}},\n", info.func_name, info.coded_tag, + info.nonfield_info); } else { GOOGLE_CHECK(!ShouldSplit(info.field, options_)); diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.h b/src/google/protobuf/compiler/cpp/parse_function_generator.h index 5646059dbf..b55feda112 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.h +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.h @@ -35,12 +35,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/options.h" +#include "google/protobuf/generated_message_tctable_gen.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/plugin_unittest.cc b/src/google/protobuf/compiler/cpp/plugin_unittest.cc index f023dcf7ca..30bd3742b1 100644 --- a/src/google/protobuf/compiler/cpp/plugin_unittest.cc +++ b/src/google/protobuf/compiler/cpp/plugin_unittest.cc @@ -36,13 +36,13 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/compiler/cpp/generator.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/testing/googletest.h" #include namespace google { diff --git a/src/google/protobuf/compiler/cpp/primitive_field.cc b/src/google/protobuf/compiler/cpp/primitive_field.cc index 8bde8549bc..bad879536b 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/primitive_field.cc @@ -32,13 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/primitive_field.h" -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/compiler/cpp/helpers.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/primitive_field.h b/src/google/protobuf/compiler/cpp/primitive_field.h index a307b1840f..b39c8464ed 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.h +++ b/src/google/protobuf/compiler/cpp/primitive_field.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/cpp/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/service.cc b/src/google/protobuf/compiler/cpp/service.cc index 6f9df3bebc..eae9e77512 100644 --- a/src/google/protobuf/compiler/cpp/service.cc +++ b/src/google/protobuf/compiler/cpp/service.cc @@ -32,291 +32,280 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/service.h" -#include -#include -#include +#include +#include + +#include "absl/strings/str_cat.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { namespace compiler { namespace cpp { - -namespace { - -void InitMethodVariables(const MethodDescriptor* method, const Options& options, - Formatter* format) { - format->Set("name", method->name()); - format->Set("input_type", QualifiedClassName(method->input_type(), options)); - format->Set("output_type", - QualifiedClassName(method->output_type(), options)); -} - -} // namespace - -ServiceGenerator::ServiceGenerator( - const ServiceDescriptor* descriptor, - const std::map& vars, const Options& options) - : descriptor_(descriptor), vars_(vars), options_(options) { - vars_["classname"] = descriptor_->name(); - vars_["full_name"] = descriptor_->full_name(); -} - -ServiceGenerator::~ServiceGenerator() {} - void ServiceGenerator::GenerateDeclarations(io::Printer* printer) { - Formatter format(printer, vars_); - // Forward-declare the stub type. - format( - "class $classname$_Stub;\n" - "\n"); - - GenerateInterface(printer); - GenerateStubDefinition(printer); -} - -void ServiceGenerator::GenerateInterface(io::Printer* printer) { - Formatter format(printer, vars_); - format( - "class $dllexport_decl $$classname$ : public ::$proto_ns$::Service {\n" - " protected:\n" - " // This class should be treated as an abstract interface.\n" - " inline $classname$() {};\n" - " public:\n" - " $classname$(const $classname$&) = delete;\n" - " $classname$& operator=(const $classname$&) = delete;\n" - " virtual ~$classname$();\n"); - printer->Indent(); - - format( - "\n" - "typedef $classname$_Stub Stub;\n" - "\n" - "static const ::$proto_ns$::ServiceDescriptor* descriptor();\n" - "\n"); - - GenerateMethodSignatures(VIRTUAL, printer); - - format( - "\n" - "// implements Service ----------------------------------------------\n" - "\n" - "const ::$proto_ns$::ServiceDescriptor* GetDescriptor();\n" - "void CallMethod(const ::$proto_ns$::MethodDescriptor* method,\n" - " ::$proto_ns$::RpcController* controller,\n" - " const ::$proto_ns$::Message* request,\n" - " ::$proto_ns$::Message* response,\n" - " ::google::protobuf::Closure* done);\n" - "const ::$proto_ns$::Message& GetRequestPrototype(\n" - " const ::$proto_ns$::MethodDescriptor* method) const;\n" - "const ::$proto_ns$::Message& GetResponsePrototype(\n" - " const ::$proto_ns$::MethodDescriptor* method) const;\n"); - - printer->Outdent(); - format( - "\n" - "};\n" - "\n"); -} - -void ServiceGenerator::GenerateStubDefinition(io::Printer* printer) { - Formatter format(printer, vars_); - format( - "class $dllexport_decl $$classname$_Stub : public $classname$ {\n" - " public:\n"); - - printer->Indent(); - - format( - "$classname$_Stub(::$proto_ns$::RpcChannel* channel);\n" - "$classname$_Stub(::$proto_ns$::RpcChannel* channel,\n" - " ::$proto_ns$::Service::ChannelOwnership ownership);\n" - "$classname$_Stub(const $classname$_Stub&) = delete;\n" - "$classname$_Stub& operator=(const $classname$_Stub&) = delete;\n" - "~$classname$_Stub();\n" - "\n" - "inline ::$proto_ns$::RpcChannel* channel() { return channel_; }\n" - "\n" - "// implements $classname$ ------------------------------------------\n" - "\n"); - - GenerateMethodSignatures(NON_VIRTUAL, printer); - - printer->Outdent(); - format( - " private:\n" - " ::$proto_ns$::RpcChannel* channel_;\n" - " bool owns_channel_;\n" - "};\n" - "\n"); + auto vars = printer->WithVars(&vars_); + printer->Emit( + { + {"virts", [&] { GenerateMethodSignatures(kVirtual, printer); }}, + {"impls", [&] { GenerateMethodSignatures(kNonVirtual, printer); }}, + }, + R"cc( + class $classname$_Stub; + class $dllexport_decl $$classname$ : public ::$proto_ns$::Service { + protected: + $classname$() = default; + + public: + using Stub = $classname$_Stub; + + $classname$(const $classname$&) = delete; + $classname$& operator=(const $classname$&) = delete; + virtual ~$classname$() = default; + + static const ::$proto_ns$::ServiceDescriptor* descriptor(); + + $virts$; + + // implements Service ---------------------------------------------- + const ::$proto_ns$::ServiceDescriptor* GetDescriptor() override; + + void CallMethod(const ::$proto_ns$::MethodDescriptor* method, + ::$proto_ns$::RpcController* controller, + const ::$proto_ns$::Message* request, + ::$proto_ns$::Message* response, + ::google::protobuf::Closure* done) override; + + const ::$proto_ns$::Message& GetRequestPrototype( + const ::$proto_ns$::MethodDescriptor* method) const override; + + const ::$proto_ns$::Message& GetResponsePrototype( + const ::$proto_ns$::MethodDescriptor* method) const override; + }; + + class $dllexport_decl $$classname$_Stub : public $classname$ { + public: + $classname$_Stub(::$proto_ns$::RpcChannel* channel); + $classname$_Stub(::$proto_ns$::RpcChannel* channel, + ::$proto_ns$::Service::ChannelOwnership ownership); + + $classname$_Stub(const $classname$_Stub&) = delete; + $classname$_Stub& operator=(const $classname$_Stub&) = delete; + + ~$classname$_Stub() override; + + inline ::$proto_ns$::RpcChannel* channel() { return channel_; } + + // implements $classname$ ------------------------------------------ + $impls$; + + private: + ::$proto_ns$::RpcChannel* channel_; + bool owns_channel_; + }; + )cc"); } -void ServiceGenerator::GenerateMethodSignatures(VirtualOrNon virtual_or_non, +void ServiceGenerator::GenerateMethodSignatures(VirtualOrNot virtual_or_not, io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); i++) { + for (int i = 0; i < descriptor_->method_count(); ++i) { const MethodDescriptor* method = descriptor_->method(i); - Formatter format(printer, vars_); - InitMethodVariables(method, options_, &format); - format.Set("virtual", virtual_or_non == VIRTUAL ? "virtual " : ""); - format( - "$virtual$void $name$(::$proto_ns$::RpcController* controller,\n" - " const $input_type$* request,\n" - " $output_type$* response,\n" - " ::google::protobuf::Closure* done);\n"); + + printer->Emit( + { + {"name", method->name()}, + {"input", QualifiedClassName(method->input_type(), *options_)}, + {"output", QualifiedClassName(method->output_type(), *options_)}, + {"virtual", virtual_or_not == kVirtual ? "virtual" : ""}, + {"override", virtual_or_not != kVirtual ? "override" : ""}, + }, + // No cc, clang-format does not format this string well due to the + // $ override$ substitution. + R"( + $virtual $void $name$(::$proto_ns$::RpcController* controller, + const $input$* request, + $output$* response, + ::google::protobuf::Closure* done)$ override$; + )"); } } // =================================================================== void ServiceGenerator::GenerateImplementation(io::Printer* printer) { - Formatter format(printer, vars_); - format( - "$classname$::~$classname$() {}\n" - "\n" - "const ::$proto_ns$::ServiceDescriptor* $classname$::descriptor() {\n" - " " - "::$proto_ns$::internal::AssignDescriptors(&$desc_table$);\n" - " return $file_level_service_descriptors$[$1$];\n" - "}\n" - "\n" - "const ::$proto_ns$::ServiceDescriptor* $classname$::GetDescriptor() {\n" - " return descriptor();\n" - "}\n" - "\n", - index_in_metadata_); - - // Generate methods of the interface. - GenerateNotImplementedMethods(printer); - GenerateCallMethod(printer); - GenerateGetPrototype(REQUEST, printer); - GenerateGetPrototype(RESPONSE, printer); - - // Generate stub implementation. - format( - "$classname$_Stub::$classname$_Stub(::$proto_ns$::RpcChannel* channel)\n" - " : channel_(channel), owns_channel_(false) {}\n" - "$classname$_Stub::$classname$_Stub(\n" - " ::$proto_ns$::RpcChannel* channel,\n" - " ::$proto_ns$::Service::ChannelOwnership ownership)\n" - " : channel_(channel),\n" - " owns_channel_(ownership == " - "::$proto_ns$::Service::STUB_OWNS_CHANNEL) " - "{}\n" - "$classname$_Stub::~$classname$_Stub() {\n" - " if (owns_channel_) delete channel_;\n" - "}\n" - "\n"); - - GenerateStubMethods(printer); + auto vars = printer->WithVars(&vars_); + printer->Emit( + { + {"index", absl::StrCat(index_in_metadata_)}, + {"no_impl_methods", [&] { GenerateNotImplementedMethods(printer); }}, + {"call_method", [&] { GenerateCallMethod(printer); }}, + {"get_request", [&] { GenerateGetPrototype(kRequest, printer); }}, + {"get_response", [&] { GenerateGetPrototype(kResponse, printer); }}, + {"stub_methods", [&] { GenerateStubMethods(printer); }}, + }, + R"cc( + const ::$proto_ns$::ServiceDescriptor* $classname$::descriptor() { + ::$proto_ns$::internal::AssignDescriptors(&$desc_table$); + return $file_level_service_descriptors$[$index$]; + } + + const ::$proto_ns$::ServiceDescriptor* $classname$::GetDescriptor() { + return descriptor(); + } + + $no_impl_methods$; + + $call_method$; + + $get_request$; + + $get_response$; + + $classname$_Stub::$classname$_Stub(::$proto_ns$::RpcChannel* channel) + : channel_(channel), owns_channel_(false) {} + + $classname$_Stub::$classname$_Stub( + ::$proto_ns$::RpcChannel* channel, + ::$proto_ns$::Service::ChannelOwnership ownership) + : channel_(channel), + owns_channel_(ownership == + ::$proto_ns$::Service::STUB_OWNS_CHANNEL) {} + + $classname$_Stub::~$classname$_Stub() { + if (owns_channel_) delete channel_; + } + + $stub_methods$; + )cc"); } void ServiceGenerator::GenerateNotImplementedMethods(io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); i++) { + for (int i = 0; i < descriptor_->method_count(); ++i) { const MethodDescriptor* method = descriptor_->method(i); - Formatter format(printer, vars_); - InitMethodVariables(method, options_, &format); - format( - "void $classname$::$name$(::$proto_ns$::RpcController* controller,\n" - " const $input_type$*,\n" - " $output_type$*,\n" - " ::google::protobuf::Closure* done) {\n" - " controller->SetFailed(\"Method $name$() not implemented.\");\n" - " done->Run();\n" - "}\n" - "\n"); + + printer->Emit( + { + {"name", method->name()}, + {"input", QualifiedClassName(method->input_type(), *options_)}, + {"output", QualifiedClassName(method->output_type(), *options_)}, + }, + R"cc( + void $classname$::$name$(::$proto_ns$::RpcController* controller, + const $input$*, $output$*, ::google::protobuf::Closure* done) { + controller->SetFailed("Method $name$() not implemented."); + done->Run(); + } + )cc"); } } void ServiceGenerator::GenerateCallMethod(io::Printer* printer) { - Formatter format(printer, vars_); - format( - "void $classname$::CallMethod(const ::$proto_ns$::MethodDescriptor* " - "method,\n" - " ::$proto_ns$::RpcController* controller,\n" - " const ::$proto_ns$::Message* request,\n" - " ::$proto_ns$::Message* response,\n" - " ::google::protobuf::Closure* done) {\n" - " GOOGLE_DCHECK_EQ(method->service(), $file_level_service_descriptors$[$1$]);\n" - " switch(method->index()) {\n", - index_in_metadata_); - - for (int i = 0; i < descriptor_->method_count(); i++) { - const MethodDescriptor* method = descriptor_->method(i); - Formatter format_method(printer, vars_); - InitMethodVariables(method, options_, &format_method); - format_method( - " case $1$:\n" - " $name$(controller,\n" - " ::$proto_ns$::internal::DownCast(\n" - " request),\n" - " ::$proto_ns$::internal::DownCast<$output_type$*>(\n" - " response),\n" - " done);\n" - " break;\n", - i); - } - - format( - " default:\n" - " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen.\";\n" - " break;\n" - " }\n" - "}\n" - "\n"); + printer->Emit( + { + {"index", absl::StrCat(index_in_metadata_)}, + {"cases", [&] { GenerateCallMethodCases(printer); }}, + }, + R"cc( + void $classname$::CallMethod( + const ::$proto_ns$::MethodDescriptor* method, + ::$proto_ns$::RpcController* controller, + const ::$proto_ns$::Message* request, + ::$proto_ns$::Message* response, ::google::protobuf::Closure* done) { + GOOGLE_DCHECK_EQ(method->service(), $file_level_service_descriptors$[$index$]); + switch (method->index()) { + $cases$; + + default: + GOOGLE_LOG(FATAL) << "Bad method index; this should never happen."; + break; + } + } + )cc"); } void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, io::Printer* printer) { - Formatter format(printer, vars_); - if (which == REQUEST) { - format("const ::$proto_ns$::Message& $classname$::GetRequestPrototype(\n"); - } else { - format("const ::$proto_ns$::Message& $classname$::GetResponsePrototype(\n"); - } - - format( - " const ::$proto_ns$::MethodDescriptor* method) const {\n" - " GOOGLE_DCHECK_EQ(method->service(), descriptor());\n" - " switch(method->index()) {\n"); + printer->Emit( + { + {"which", which == kRequest ? "Request" : "Response"}, + {"which_type", which == kRequest ? "input" : "output"}, + {"cases", + [&] { + for (int i = 0; i < descriptor_->method_count(); ++i) { + const MethodDescriptor* method = descriptor_->method(i); + const Descriptor* type = which == kRequest + ? method->input_type() + : method->output_type(); + + printer->Emit( + { + {"index", absl::StrCat(i)}, + {"type", QualifiedClassName(type, *options_)}, + }, + R"cc( + case $index$: + return $type$::default_instance(); + )cc"); + } + }}, + }, + R"cc( + const ::$proto_ns$::Message& $classname$::Get$which$Prototype( + const ::$proto_ns$::MethodDescriptor* method) const { + GOOGLE_DCHECK_EQ(method->service(), descriptor()); + switch (method->index()) { + $cases$; + + default: + GOOGLE_LOG(FATAL) << "Bad method index; this should never happen."; + return *::$proto_ns$::MessageFactory::generated_factory() + ->GetPrototype(method->$which_type$_type()); + } + } + )cc"); +} - for (int i = 0; i < descriptor_->method_count(); i++) { +void ServiceGenerator::GenerateCallMethodCases(io::Printer* printer) { + for (int i = 0; i < descriptor_->method_count(); ++i) { const MethodDescriptor* method = descriptor_->method(i); - const Descriptor* type = - (which == REQUEST) ? method->input_type() : method->output_type(); - - format( - " case $1$:\n" - " return $2$::default_instance();\n", - i, QualifiedClassName(type, options_)); + printer->Emit( + { + {"name", method->name()}, + {"input", QualifiedClassName(method->input_type(), *options_)}, + {"output", QualifiedClassName(method->output_type(), *options_)}, + {"index", absl::StrCat(i)}, + }, + R"cc( + case $index$: + $name$(controller, + ::$proto_ns$::internal::DownCast(request), + ::$proto_ns$::internal::DownCast<$output$*>(response), done); + break; + )cc"); } - - format( - " default:\n" - " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen.\";\n" - " return *::$proto_ns$::MessageFactory::generated_factory()\n" - " ->GetPrototype(method->$1$_type());\n" - " }\n" - "}\n" - "\n", - which == REQUEST ? "input" : "output"); } void ServiceGenerator::GenerateStubMethods(io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); i++) { + for (int i = 0; i < descriptor_->method_count(); ++i) { const MethodDescriptor* method = descriptor_->method(i); - Formatter format(printer, vars_); - InitMethodVariables(method, options_, &format); - format( - "void $classname$_Stub::$name$(::$proto_ns$::RpcController* " - "controller,\n" - " const $input_type$* request,\n" - " $output_type$* response,\n" - " ::google::protobuf::Closure* done) {\n" - " channel_->CallMethod(descriptor()->method($1$),\n" - " controller, request, response, done);\n" - "}\n", - i); + + printer->Emit( + { + {"name", method->name()}, + {"input", QualifiedClassName(method->input_type(), *options_)}, + {"output", QualifiedClassName(method->output_type(), *options_)}, + {"index", absl::StrCat(i)}, + }, + R"cc( + void $classname$_Stub::$name$(::$proto_ns$::RpcController* controller, + const $input$* request, + $output$* response, ::google::protobuf::Closure* done) { + channel_->CallMethod(descriptor()->method($index$), controller, + request, response, done); + } + )cc"); } } diff --git a/src/google/protobuf/compiler/cpp/service.h b/src/google/protobuf/compiler/cpp/service.h index 00057638c8..34b891423b 100644 --- a/src/google/protobuf/compiler/cpp/service.h +++ b/src/google/protobuf/compiler/cpp/service.h @@ -38,62 +38,48 @@ #include #include -#include -#include - -namespace google { -namespace protobuf { -namespace io { -class Printer; // printer.h -} -} // namespace protobuf -} // namespace google +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/cpp/options.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { namespace compiler { namespace cpp { - class ServiceGenerator { public: // See generator.cc for the meaning of dllexport_decl. - explicit ServiceGenerator(const ServiceDescriptor* descriptor, - const std::map& vars, - const Options& options); + ServiceGenerator(const ServiceDescriptor* descriptor, + const std::map& vars, + const Options& options) + : descriptor_(descriptor), options_(&options), vars_(vars) { + vars_["classname"] = descriptor_->name(); + vars_["full_name"] = descriptor_->full_name(); + } + ServiceGenerator(const ServiceGenerator&) = delete; ServiceGenerator& operator=(const ServiceGenerator&) = delete; - ~ServiceGenerator(); + ServiceGenerator(ServiceGenerator&&) = delete; + ServiceGenerator& operator=(ServiceGenerator&&) = delete; - // Header stuff. + ~ServiceGenerator() = default; // Generate the class definitions for the service's interface and the // stub implementation. void GenerateDeclarations(io::Printer* printer); - // Source file stuff. - // Generate implementations of everything declared by // GenerateDeclarations(). void GenerateImplementation(io::Printer* printer); private: - enum RequestOrResponse { REQUEST, RESPONSE }; - enum VirtualOrNon { VIRTUAL, NON_VIRTUAL }; - - // Header stuff. - - // Generate the service abstract interface. - void GenerateInterface(io::Printer* printer); - - // Generate the stub class definition. - void GenerateStubDefinition(io::Printer* printer); + enum RequestOrResponse { kRequest, kResponse }; + enum VirtualOrNot { kVirtual, kNonVirtual }; // Prints signatures for all methods in the - void GenerateMethodSignatures(VirtualOrNon virtual_or_non, + void GenerateMethodSignatures(VirtualOrNot virtual_or_not, io::Printer* printer); - // Source file stuff. - // Generate the default implementations of the service methods, which // produce a "not implemented" error. void GenerateNotImplementedMethods(io::Printer* printer); @@ -104,18 +90,20 @@ class ServiceGenerator { // Generate the Get{Request,Response}Prototype() methods. void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); + // Generate the cases in CallMethod(). + void GenerateCallMethodCases(io::Printer* printer); + // Generate the stub's implementations of the service methods. void GenerateStubMethods(io::Printer* printer); const ServiceDescriptor* descriptor_; + const Options* options_; std::map vars_; - const Options& options_; int index_in_metadata_; friend class FileGenerator; }; - } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/cpp/string_field.cc b/src/google/protobuf/compiler/cpp/string_field.cc index 090224df8d..3b05c36f5c 100644 --- a/src/google/protobuf/compiler/cpp/string_field.cc +++ b/src/google/protobuf/compiler/cpp/string_field.cc @@ -32,13 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/cpp/string_field.h" -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/descriptor.pb.h" namespace google { @@ -53,7 +53,7 @@ void SetStringVariables(const FieldDescriptor* descriptor, const Options& options) { SetCommonFieldVariables(descriptor, variables, options); - const std::string kNS = "::" + (*variables)["proto_ns"] + "::internal::"; + const std::string kNS = "::" + ProtobufNamespace(options) + "::internal::"; const std::string kArenaStringPtr = kNS + "ArenaStringPtr"; (*variables)["default"] = DefaultValue(options, descriptor); @@ -80,7 +80,6 @@ void SetStringVariables(const FieldDescriptor* descriptor, descriptor->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; (*variables)["setter"] = descriptor->type() == FieldDescriptor::TYPE_BYTES ? "SetBytes" : "Set"; - (*variables)["null_check"] = (*variables)["DCHK"] + "(value != nullptr);\n"; // NOTE: Escaped here to unblock proto1->proto2 migration. // TODO(liujisi): Extend this to apply for other conflicting methods. (*variables)["release_name"] = @@ -804,7 +803,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions( " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "inline void $classname$::set_$name$(int index, const char* value) {\n" - " $null_check$" + " $DCHK$(value != nullptr);" " $field$.Mutable(index)->assign(value);\n" "$annotate_set$" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" @@ -841,7 +840,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions( " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" "inline void $classname$::add_$name$(const char* value) {\n" - " $null_check$" + " $DCHK$(value != nullptr);" " $field$.Add()->assign(value);\n" "$annotate_add$" " // @@protoc_insertion_point(field_add_char:$full_name$)\n" diff --git a/src/google/protobuf/compiler/cpp/string_field.h b/src/google/protobuf/compiler/cpp/string_field.h index b89c9a6c4c..02bee858f3 100644 --- a/src/google/protobuf/compiler/cpp/string_field.h +++ b/src/google/protobuf/compiler/cpp/string_field.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/cpp/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/unittest.cc b/src/google/protobuf/compiler/cpp/unittest.cc index e2730d7d55..a52280dbf0 100644 --- a/src/google/protobuf/compiler/cpp/unittest.cc +++ b/src/google/protobuf/compiler/cpp/unittest.cc @@ -44,12 +44,12 @@ // correctly and produces the interfaces we expect, which is why this test // is written this way. -#include +#include "google/protobuf/compiler/cpp/unittest.h" -#include -#include -#include -#include +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_embed_optimize_for.pb.h" +#include "google/protobuf/unittest_optimize_for.pb.h" +#include "google/protobuf/test_util.h" #define MESSAGE_TEST_NAME MessageTest #define GENERATED_DESCRIPTOR_TEST_NAME GeneratedDescriptorTest @@ -64,7 +64,7 @@ #define UNITTEST_IMPORT ::protobuf_unittest_import // Must include after the above macros. -#include +#include "google/protobuf/compiler/cpp/unittest.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/unittest.inc b/src/google/protobuf/compiler/cpp/unittest.inc index cff77680d0..2d65eaddf6 100644 --- a/src/google/protobuf/compiler/cpp/unittest.inc +++ b/src/google/protobuf/compiler/cpp/unittest.inc @@ -49,36 +49,36 @@ #include #include -#include +#include "google/protobuf/compiler/cpp/unittest.h" #include "absl/strings/string_view.h" #ifndef _MSC_VER // We exclude this large proto because it's too large for // visual studio to compile (report internal errors). -#include +#include "google/protobuf/unittest_enormous_descriptor.pb.h" #endif -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/unittest_no_generic_services.pb.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/base/casts.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/arena.h" +#include "google/protobuf/compiler/cpp/test_bad_identifiers.pb.h" +#include "google/protobuf/compiler/importer.h" +#include "google/protobuf/compiler/scc.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/stubs/stl_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -2222,4 +2222,4 @@ TEST(DESCRIPTOR_INIT_TEST_NAME, Initialized) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index 9ac89e3441..315f595446 100644 --- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -37,23 +37,22 @@ // "generate_descriptor_proto.sh" and add the changed files under // csharp/src/ to your changelist. -#include - #include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/googletest.h" +#include "google/protobuf/stubs/strutil.h" #include #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/substitute.h" -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_generator.h" +#include "google/protobuf/compiler/importer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/stubs/stl_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc b/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc index f820bf143c..72a4c12bc8 100644 --- a/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc +++ b/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc @@ -31,14 +31,15 @@ // Author: kenton@google.com (Kenton Varda) // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" + +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" +#include "absl/strings/str_split.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { @@ -58,8 +59,7 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) { } // XML escaping... no need for apostrophes etc as the whole text is going to be a child // node of a summary element, not part of an attribute. - comments = StringReplace(comments, "&", "&", true); - comments = StringReplace(comments, "<", "<", true); + comments = absl::StrReplaceAll(comments, {{"&", "&"}, {"<", "<"}}); std::vector lines; lines = absl::StrSplit(comments, "\n", absl::AllowEmpty()); // TODO: We really should work out which part to put in the summary and which to put in the remarks... diff --git a/src/google/protobuf/compiler/csharp/csharp_doc_comment.h b/src/google/protobuf/compiler/csharp/csharp_doc_comment.h index 75eb0ea04d..40c35ec0a7 100644 --- a/src/google/protobuf/compiler/csharp/csharp_doc_comment.h +++ b/src/google/protobuf/compiler/csharp/csharp_doc_comment.h @@ -32,8 +32,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_DOC_COMMENT_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_DOC_COMMENT_H__ -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_enum.cc b/src/google/protobuf/compiler/csharp/csharp_enum.cc index 8ee38bcd1e..2b2bcf8872 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum.cc +++ b/src/google/protobuf/compiler/csharp/csharp_enum.cc @@ -28,23 +28,27 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_enum.h" #include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_enum.h b/src/google/protobuf/compiler/csharp/csharp_enum.h index e409c2e4b2..098102b3a5 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum.h +++ b/src/google/protobuf/compiler/csharp/csharp_enum.h @@ -33,10 +33,10 @@ #include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc index 3709908e83..065e1cc5e9 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_enum_field.h" #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_enum_field.h index 0c6b023b13..c31d55f4af 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_ENUM_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_primitive_field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index 716fa770c2..e808b7d573 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -28,29 +28,33 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_field_base.h" #include #include #include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_names.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -470,4 +474,4 @@ std::string FieldGeneratorBase::capitalized_type_name() { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index b6b21b6e63..9eecde9fec 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -32,16 +32,20 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_FIELD_BASE_H__ #include -#include +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc index 32ef2492d5..8a3286e1fb 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator.cc @@ -28,24 +28,28 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_generator.h" #include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_names.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/compiler/csharp/csharp_reflection_class.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.h b/src/google/protobuf/compiler/csharp/csharp_generator.h index f41f9b8358..ea2746e520 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator.h +++ b/src/google/protobuf/compiler/csharp/csharp_generator.h @@ -35,9 +35,9 @@ #include -#include +#include "google/protobuf/compiler/code_generator.h" -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -65,6 +65,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc index 052c92f655..ca4fb9d7c8 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc @@ -30,13 +30,13 @@ #include -#include -#include +#include "google/protobuf/any.pb.h" +#include "google/protobuf/compiler/command_line_interface.h" #include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index a52599533c..dd60eb714e 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -32,37 +32,36 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include #include #include #include -#include -#include #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_enum_field.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include "google/protobuf/compiler/csharp/csharp_map_field.h" +#include "google/protobuf/compiler/csharp/csharp_message_field.h" +#include "google/protobuf/compiler/csharp/csharp_names.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/compiler/csharp/csharp_primitive_field.h" +#include "google/protobuf/compiler/csharp/csharp_repeated_enum_field.h" +#include "google/protobuf/compiler/csharp/csharp_repeated_message_field.h" +#include "google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h" +#include "google/protobuf/compiler/csharp/csharp_wrapper_field.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -360,7 +359,7 @@ std::string ToCSharpName(const std::string& name, const FileDescriptor* file) { // the C# namespace. classname = name.substr(file->package().size() + 1); } - result += StringReplace(classname, ".", ".Types.", true); + result += absl::StrReplaceAll(classname, {{".", ".Types."}}); return "global::" + result; } @@ -469,7 +468,8 @@ std::string GetOutputFile(const FileDescriptor* descriptor, } } - std::string namespace_dir = StringReplace(namespace_suffix, ".", "/", true); + std::string namespace_dir = + absl::StrReplaceAll(namespace_suffix, {{".", "/"}}); if (!namespace_dir.empty()) { namespace_dir += "/"; } @@ -640,4 +640,4 @@ bool IsNullable(const FieldDescriptor* descriptor) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index bcb64a4453..55660b7499 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -37,13 +37,13 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/port_def.inc" +#include "google/protobuf/port.h" namespace google { namespace protobuf { @@ -195,6 +195,6 @@ inline bool RequiresPresenceBit(const FieldDescriptor* descriptor) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__ diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index 054984836d..34ea3e9b72 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -28,22 +28,26 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_map_field.h" #include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.h b/src/google/protobuf/compiler/csharp/csharp_map_field.h index 23b3619913..c4713d0e10 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 9a1f684d07..993e9d6d27 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -28,33 +28,37 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_message.h" #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_enum.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_names.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -785,4 +789,4 @@ FieldGeneratorBase* MessageGenerator::CreateFieldGeneratorInternal( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/csharp/csharp_message.h b/src/google/protobuf/compiler/csharp/csharp_message.h index d02767e44b..86025dcd90 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.h +++ b/src/google/protobuf/compiler/csharp/csharp_message.h @@ -34,9 +34,9 @@ #include #include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_message_field.cc index a37f4c8ae5..9d70bd013a 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.cc @@ -28,25 +28,29 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_message_field.h" #include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.h b/src/google/protobuf/compiler/csharp/csharp_message_field.h index e76dfd20a3..fbbe4c4ffa 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_names.h b/src/google/protobuf/compiler/csharp/csharp_names.h index 240c993334..61f4b7b0eb 100644 --- a/src/google/protobuf/compiler/csharp/csharp_names.h +++ b/src/google/protobuf/compiler/csharp/csharp_names.h @@ -39,10 +39,10 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ #include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/stubs/common.h" -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -104,6 +104,6 @@ std::string PROTOC_EXPORT GetOutputFile(const FileDescriptor* descriptor, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc index ae8a8f810e..f42ff90048 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc @@ -28,23 +28,27 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_primitive_field.h" #include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h index 6d495d55e1..d6fb715c6a 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_PRIMITIVE_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc b/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc index e86ec7092d..b767c9d75d 100644 --- a/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc +++ b/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc @@ -28,29 +28,33 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_reflection_class.h" #include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/csharp/csharp_enum.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_message.h" +#include "google/protobuf/compiler/csharp/csharp_names.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -335,4 +339,4 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/csharp/csharp_reflection_class.h b/src/google/protobuf/compiler/csharp/csharp_reflection_class.h index 9554727766..daffb32b41 100644 --- a/src/google/protobuf/compiler/csharp/csharp_reflection_class.h +++ b/src/google/protobuf/compiler/csharp/csharp_reflection_class.h @@ -33,10 +33,10 @@ #include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc index 2c732dc1b6..1a9fd1d893 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_repeated_enum_field.h" #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h index 2379f38e21..08ce9924d7 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_ENUM_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc index a7cf56c060..6ac7e2d6a0 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc @@ -28,19 +28,19 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_repeated_message_field.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_message_field.h" +#include "google/protobuf/compiler/csharp/csharp_wrapper_field.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h index 026efea85e..f2c935ad9a 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_MESSAGE_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc index 4c3dba351c..df97ccf3db 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h" #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h index bdd12a02f8..92485a2a9d 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_PRIMITIVE_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc b/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc index a6331e61a4..0d4b639e64 100644 --- a/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_names.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h b/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h index 17a5269160..01b0187e26 100644 --- a/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h @@ -33,8 +33,8 @@ #include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc index 02c9430505..25690822a1 100644 --- a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/csharp/csharp_wrapper_field.h" #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" +#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include "google/protobuf/compiler/csharp/csharp_options.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h index cc8a3137d6..6b15aa0eb0 100644 --- a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/csharp/csharp_field_base.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc index 202210e8e8..287b22e67f 100644 --- a/src/google/protobuf/compiler/importer.cc +++ b/src/google/protobuf/compiler/importer.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/importer.h" #ifdef _MSC_VER #include @@ -48,14 +48,15 @@ #include #include -#include +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_join.h" +#include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/parser.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #ifdef _WIN32 #include @@ -75,7 +76,7 @@ using google::protobuf::io::win32::open; // Returns true if the text looks like a Windows-style absolute path, starting // with a drive letter. Example: "C:\foo". TODO(kenton): Share this with // copy in command_line_interface.cc? -static bool IsWindowsAbsolutePath(const std::string& text) { +static bool IsWindowsAbsolutePath(absl::string_view text) { #if defined(_WIN32) || defined(__CYGWIN__) return text.size() >= 3 && text[1] == ':' && isalpha(text[0]) && (text[2] == '/' || text[2] == '\\') && text.find_last_of(':') == 1; @@ -275,17 +276,19 @@ DiskSourceTree::~DiskSourceTree() {} // then if foo/bar is a symbolic link, foo/bar/baz.proto will canonicalize // to a path which does not appear to be under foo, and thus the compiler // will complain that baz.proto is not inside the --proto_path. -static std::string CanonicalizePath(std::string path) { +static std::string CanonicalizePath(absl::string_view path) { #ifdef _WIN32 // The Win32 API accepts forward slashes as a path delimiter even though // backslashes are standard. Let's avoid confusion and use only forward // slashes. + std::string path_str; if (HasPrefixString(path, "\\\\")) { // Avoid converting two leading backslashes. - path = "\\\\" + StringReplace(path.substr(2), "\\", "/", true); + path_str = "\\\\" + absl::StrReplaceAll(path.substr(2), {{"\\", "/"}}); } else { - path = StringReplace(path, "\\", "/", true); + path_str = absl::StrReplaceAll(path, {{"\\", "/"}}); } + path = path_str; #endif std::vector canonical_parts; @@ -302,9 +305,9 @@ static std::string CanonicalizePath(std::string path) { return absl::StrJoin(canonical_parts, "/"); } -static inline bool ContainsParentReference(const std::string& path) { +static inline bool ContainsParentReference(absl::string_view path) { return path == ".." || HasPrefixString(path, "../") || - HasSuffixString(path, "/..") || path.find("/../") != std::string::npos; + HasSuffixString(path, "/..") || absl::StrContains(path, "/../"); } // Maps a file from an old location to a new one. Typically, old_prefix is @@ -324,9 +327,9 @@ static inline bool ContainsParentReference(const std::string& path) { // assert(!ApplyMapping("foo/bar", "baz", "qux", &result)); // assert(!ApplyMapping("foo/bar", "baz", "qux", &result)); // assert(!ApplyMapping("foobar", "foo", "baz", &result)); -static bool ApplyMapping(const std::string& filename, - const std::string& old_prefix, - const std::string& new_prefix, std::string* result) { +static bool ApplyMapping(absl::string_view filename, + absl::string_view old_prefix, + absl::string_view new_prefix, std::string* result) { if (old_prefix.empty()) { // old_prefix matches any relative path. if (ContainsParentReference(filename)) { @@ -337,15 +340,15 @@ static bool ApplyMapping(const std::string& filename, // This is an absolute path, so it isn't matched by the empty string. return false; } - result->assign(new_prefix); + result->assign(std::string(new_prefix)); if (!result->empty()) result->push_back('/'); - result->append(filename); + result->append(std::string(filename)); return true; } else if (HasPrefixString(filename, old_prefix)) { // old_prefix is a prefix of the filename. Is it the whole filename? if (filename.size() == old_prefix.size()) { // Yep, it's an exact match. - *result = new_prefix; + *result = std::string(new_prefix); return true; } else { // Not an exact match. Is the next character a '/'? Otherwise, @@ -362,14 +365,14 @@ static bool ApplyMapping(const std::string& filename, if (after_prefix_start != -1) { // Yep. So the prefixes are directories and the filename is a file // inside them. - std::string after_prefix = filename.substr(after_prefix_start); + absl::string_view after_prefix = filename.substr(after_prefix_start); if (ContainsParentReference(after_prefix)) { // We do not allow the file name to use "..". return false; } - result->assign(new_prefix); + result->assign(std::string(new_prefix)); if (!result->empty()) result->push_back('/'); - result->append(after_prefix); + result->append(std::string(after_prefix)); return true; } } @@ -378,13 +381,14 @@ static bool ApplyMapping(const std::string& filename, return false; } -void DiskSourceTree::MapPath(const std::string& virtual_path, - const std::string& disk_path) { - mappings_.push_back(Mapping(virtual_path, CanonicalizePath(disk_path))); +void DiskSourceTree::MapPath(absl::string_view virtual_path, + absl::string_view disk_path) { + mappings_.push_back( + Mapping(std::string(virtual_path), CanonicalizePath(disk_path))); } DiskSourceTree::DiskFileToVirtualFileResult -DiskSourceTree::DiskFileToVirtualFile(const std::string& disk_file, +DiskSourceTree::DiskFileToVirtualFile(absl::string_view disk_file, std::string* virtual_file, std::string* shadowing_disk_file) { int mapping_index = -1; @@ -428,14 +432,14 @@ DiskSourceTree::DiskFileToVirtualFile(const std::string& disk_file, return SUCCESS; } -bool DiskSourceTree::VirtualFileToDiskFile(const std::string& virtual_file, +bool DiskSourceTree::VirtualFileToDiskFile(absl::string_view virtual_file, std::string* disk_file) { std::unique_ptr stream( OpenVirtualFile(virtual_file, disk_file)); return stream != nullptr; } -io::ZeroCopyInputStream* DiskSourceTree::Open(const std::string& filename) { +io::ZeroCopyInputStream* DiskSourceTree::Open(absl::string_view filename) { return OpenVirtualFile(filename, nullptr); } @@ -444,7 +448,7 @@ std::string DiskSourceTree::GetLastErrorMessage() { } io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile( - const std::string& virtual_file, std::string* disk_file) { + absl::string_view virtual_file, std::string* disk_file) { if (virtual_file != CanonicalizePath(virtual_file) || ContainsParentReference(virtual_file)) { // We do not allow importing of paths containing things like ".." or @@ -481,11 +485,11 @@ io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile( } io::ZeroCopyInputStream* DiskSourceTree::OpenDiskFile( - const std::string& filename) { + absl::string_view filename) { struct stat sb; int ret = 0; do { - ret = stat(filename.c_str(), &sb); + ret = stat(std::string(filename).c_str(), &sb); } while (ret != 0 && errno == EINTR); #if defined(_WIN32) if (ret == 0 && sb.st_mode & S_IFDIR) { @@ -500,7 +504,7 @@ io::ZeroCopyInputStream* DiskSourceTree::OpenDiskFile( #endif int file_descriptor; do { - file_descriptor = open(filename.c_str(), O_RDONLY); + file_descriptor = open(std::string(filename).c_str(), O_RDONLY); } while (file_descriptor < 0 && errno == EINTR); if (file_descriptor >= 0) { io::FileInputStream* result = new io::FileInputStream(file_descriptor); diff --git a/src/google/protobuf/compiler/importer.h b/src/google/protobuf/compiler/importer.h index 8f119d539c..bab4b73d14 100644 --- a/src/google/protobuf/compiler/importer.h +++ b/src/google/protobuf/compiler/importer.h @@ -42,12 +42,12 @@ #include #include -#include -#include -#include +#include "google/protobuf/compiler/parser.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor_database.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -221,11 +221,17 @@ class PROTOBUF_EXPORT SourceTree { SourceTree& operator=(const SourceTree&) = delete; virtual ~SourceTree(); + // This is a temporary typedef alias to allow migrating the argument type of + // Open in an atomic change without touching certain directories which are + // restricted for various reasons. This must match the argument type used + // below. + using SourceTreeOpenArgumentType = absl::string_view; + // Open the given file and return a stream that reads it, or NULL if not // found. The caller takes ownership of the returned object. The filename // must be a path relative to the root of the source tree and must not // contain "." or ".." components. - virtual io::ZeroCopyInputStream* Open(const std::string& filename) = 0; + virtual io::ZeroCopyInputStream* Open(absl::string_view filename) = 0; // If Open() returns NULL, calling this method immediately will return an // description of the error. @@ -261,7 +267,7 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { // // disk_path may be an absolute path or relative to the current directory, // just like a path you'd pass to open(). - void MapPath(const std::string& virtual_path, const std::string& disk_path); + void MapPath(absl::string_view virtual_path, absl::string_view disk_path); // Return type for DiskFileToVirtualFile(). enum DiskFileToVirtualFileResult { @@ -292,17 +298,17 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { // * NO_MAPPING: Indicates that no mapping was found which contains this // file. DiskFileToVirtualFileResult DiskFileToVirtualFile( - const std::string& disk_file, std::string* virtual_file, + absl::string_view disk_file, std::string* virtual_file, std::string* shadowing_disk_file); // Given a virtual path, find the path to the file on disk. // Return true and update disk_file with the on-disk path if the file exists. // Return false and leave disk_file untouched if the file doesn't exist. - bool VirtualFileToDiskFile(const std::string& virtual_file, + bool VirtualFileToDiskFile(absl::string_view virtual_file, std::string* disk_file); // implements SourceTree ------------------------------------------- - io::ZeroCopyInputStream* Open(const std::string& filename) override; + io::ZeroCopyInputStream* Open(absl::string_view filename) override; std::string GetLastErrorMessage() override; @@ -311,26 +317,26 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { std::string virtual_path; std::string disk_path; - inline Mapping(const std::string& virtual_path_param, - const std::string& disk_path_param) - : virtual_path(virtual_path_param), disk_path(disk_path_param) {} + inline Mapping(std::string virtual_path_param, std::string disk_path_param) + : virtual_path(std::move(virtual_path_param)), + disk_path(std::move(disk_path_param)) {} }; std::vector mappings_; std::string last_error_message_; // Like Open(), but returns the on-disk path in disk_file if disk_file is // non-NULL and the file could be successfully opened. - io::ZeroCopyInputStream* OpenVirtualFile(const std::string& virtual_file, + io::ZeroCopyInputStream* OpenVirtualFile(absl::string_view virtual_file, std::string* disk_file); // Like Open() but given the actual on-disk path. - io::ZeroCopyInputStream* OpenDiskFile(const std::string& filename); + io::ZeroCopyInputStream* OpenDiskFile(absl::string_view filename); }; } // namespace compiler } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ diff --git a/src/google/protobuf/compiler/importer_unittest.cc b/src/google/protobuf/compiler/importer_unittest.cc index f5b29cb070..21044c7c13 100644 --- a/src/google/protobuf/compiler/importer_unittest.cc +++ b/src/google/protobuf/compiler/importer_unittest.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/importer.h" #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/container/flat_hash_map.h" #include "absl/strings/substitute.h" -#include +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { @@ -98,7 +98,7 @@ class MockSourceTree : public SourceTree { } // implements SourceTree ------------------------------------------- - io::ZeroCopyInputStream* Open(const std::string& filename) override { + io::ZeroCopyInputStream* Open(absl::string_view filename) override { auto it = files_.find(filename); if (it == files_.end()) return nullptr; return new io::ArrayInputStream(it->second, diff --git a/src/google/protobuf/compiler/java/context.cc b/src/google/protobuf/compiler/java/context.cc index 53b5d1e024..d9bc0fe2a8 100644 --- a/src/google/protobuf/compiler/java/context.cc +++ b/src/google/protobuf/compiler/java/context.cc @@ -28,14 +28,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/java/context.h" -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include +#include "google/protobuf/compiler/java/field.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/context.h b/src/google/protobuf/compiler/java/context.h index 43091846a1..4697c8ce86 100644 --- a/src/google/protobuf/compiler/java/context.h +++ b/src/google/protobuf/compiler/java/context.h @@ -34,9 +34,9 @@ #include #include -#include #include "absl/container/flat_hash_map.h" -#include +#include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/doc_comment.cc b/src/google/protobuf/compiler/java/doc_comment.cc index 299b4c0411..a515eb20ce 100644 --- a/src/google/protobuf/compiler/java/doc_comment.cc +++ b/src/google/protobuf/compiler/java/doc_comment.cc @@ -32,16 +32,16 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/doc_comment.h" #include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_split.h" -#include -#include +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/doc_comment.h b/src/google/protobuf/compiler/java/doc_comment.h index acfdfcd643..de8e6bf008 100644 --- a/src/google/protobuf/compiler/java/doc_comment.h +++ b/src/google/protobuf/compiler/java/doc_comment.h @@ -35,10 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ -#include +#include "google/protobuf/descriptor.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -104,6 +104,6 @@ PROTOC_EXPORT std::string EscapeJavadoc(const std::string& input); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ diff --git a/src/google/protobuf/compiler/java/doc_comment_unittest.cc b/src/google/protobuf/compiler/java/doc_comment_unittest.cc index 3fcdf07430..687b25fb6a 100644 --- a/src/google/protobuf/compiler/java/doc_comment_unittest.cc +++ b/src/google/protobuf/compiler/java/doc_comment_unittest.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include +#include "google/protobuf/compiler/java/doc_comment.h" #include diff --git a/src/google/protobuf/compiler/java/enum.cc b/src/google/protobuf/compiler/java/enum.cc index 2a4b325920..f3e1b4243e 100644 --- a/src/google/protobuf/compiler/java/enum.cc +++ b/src/google/protobuf/compiler/java/enum.cc @@ -32,22 +32,22 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/enum.h" #include #include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -408,4 +408,4 @@ bool EnumGenerator::CanUseEnumValues() { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/enum.h b/src/google/protobuf/compiler/java/enum.h index 3dd7708f56..8868e47459 100644 --- a/src/google/protobuf/compiler/java/enum.h +++ b/src/google/protobuf/compiler/java/enum.h @@ -37,7 +37,7 @@ #include #include -#include +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/enum_field.cc b/src/google/protobuf/compiler/java/enum_field.cc index 0ef9ef5393..ea74d8bc6f 100644 --- a/src/google/protobuf/compiler/java/enum_field.cc +++ b/src/google/protobuf/compiler/java/enum_field.cc @@ -32,24 +32,24 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/enum_field.h" #include #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1178,4 +1178,4 @@ std::string RepeatedImmutableEnumFieldGenerator::GetBoxedType() const { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/enum_field.h b/src/google/protobuf/compiler/java/enum_field.h index 3a5bec313f..db2aa75edf 100644 --- a/src/google/protobuf/compiler/java/enum_field.h +++ b/src/google/protobuf/compiler/java/enum_field.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/enum_field_lite.cc b/src/google/protobuf/compiler/java/enum_field_lite.cc index 3b0f866a45..713f805f98 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/enum_field_lite.cc @@ -32,25 +32,25 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/enum_field_lite.h" #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -963,4 +963,4 @@ std::string RepeatedImmutableEnumFieldLiteGenerator::GetBoxedType() const { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/enum_field_lite.h b/src/google/protobuf/compiler/java/enum_field_lite.h index 23f88ce6cc..8d7a7d1cf4 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.h +++ b/src/google/protobuf/compiler/java/enum_field_lite.h @@ -39,7 +39,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/enum_lite.cc b/src/google/protobuf/compiler/java/enum_lite.cc index 5357d1391e..a04f814972 100644 --- a/src/google/protobuf/compiler/java/enum_lite.cc +++ b/src/google/protobuf/compiler/java/enum_lite.cc @@ -32,19 +32,19 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/enum_lite.h" #include #include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/enum_lite.h b/src/google/protobuf/compiler/java/enum_lite.h index 1857a82301..13306b1398 100644 --- a/src/google/protobuf/compiler/java/enum_lite.h +++ b/src/google/protobuf/compiler/java/enum_lite.h @@ -37,7 +37,7 @@ #include #include -#include +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/extension.cc b/src/google/protobuf/compiler/java/extension.cc index 58a5eb809b..0e42a01777 100644 --- a/src/google/protobuf/compiler/java/extension.cc +++ b/src/google/protobuf/compiler/java/extension.cc @@ -32,18 +32,18 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/extension.h" -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -178,4 +178,4 @@ int ImmutableExtensionGenerator::GenerateRegistrationCode( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/extension.h b/src/google/protobuf/compiler/java/extension.h index 1998af8d93..b9dc99597b 100644 --- a/src/google/protobuf/compiler/java/extension.h +++ b/src/google/protobuf/compiler/java/extension.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/extension_lite.cc b/src/google/protobuf/compiler/java/extension_lite.cc index 2914c2776c..4c3b83a230 100644 --- a/src/google/protobuf/compiler/java/extension_lite.cc +++ b/src/google/protobuf/compiler/java/extension_lite.cc @@ -28,17 +28,17 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/java/extension_lite.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -119,4 +119,4 @@ int ImmutableExtensionLiteGenerator::GenerateRegistrationCode( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/extension_lite.h b/src/google/protobuf/compiler/java/extension_lite.h index f346c5e1bf..015f2ee856 100644 --- a/src/google/protobuf/compiler/java/extension_lite.h +++ b/src/google/protobuf/compiler/java/extension_lite.h @@ -34,8 +34,8 @@ #include #include -#include -#include +#include "google/protobuf/compiler/java/extension.h" +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/field.cc b/src/google/protobuf/compiler/java/field.cc index dfe70aaa08..dd5e16cb5b 100644 --- a/src/google/protobuf/compiler/java/field.cc +++ b/src/google/protobuf/compiler/java/field.cc @@ -32,28 +32,28 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/field.h" #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/enum_field.h" +#include "google/protobuf/compiler/java/enum_field_lite.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/map_field.h" +#include "google/protobuf/compiler/java/map_field_lite.h" +#include "google/protobuf/compiler/java/message_field.h" +#include "google/protobuf/compiler/java/message_field_lite.h" +#include "google/protobuf/compiler/java/primitive_field.h" +#include "google/protobuf/compiler/java/primitive_field_lite.h" +#include "google/protobuf/compiler/java/string_field.h" +#include "google/protobuf/compiler/java/string_field_lite.h" namespace google { diff --git a/src/google/protobuf/compiler/java/field.h b/src/google/protobuf/compiler/java/field.h index 2dc189e64d..4743f59539 100644 --- a/src/google/protobuf/compiler/java/field.h +++ b/src/google/protobuf/compiler/java/field.h @@ -40,9 +40,10 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/file.cc b/src/google/protobuf/compiler/java/file.cc index 09d8e58d65..20949d0ec8 100644 --- a/src/google/protobuf/compiler/java/file.cc +++ b/src/google/protobuf/compiler/java/file.cc @@ -32,31 +32,31 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/file.h" #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/enum.h" +#include "google/protobuf/compiler/java/enum_lite.h" +#include "google/protobuf/compiler/java/extension.h" +#include "google/protobuf/compiler/java/generator_factory.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/message.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/compiler/java/service.h" +#include "google/protobuf/compiler/java/shared_code_generator.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -747,4 +747,4 @@ bool FileGenerator::ShouldIncludeDependency(const FileDescriptor* descriptor, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/file.h b/src/google/protobuf/compiler/java/file.h index e640039f92..bf1e23ba1f 100644 --- a/src/google/protobuf/compiler/java/file.h +++ b/src/google/protobuf/compiler/java/file.h @@ -39,8 +39,8 @@ #include #include -#include -#include +#include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/generator.cc b/src/google/protobuf/compiler/java/generator.cc index 84d8307020..52bca03ea9 100644 --- a/src/google/protobuf/compiler/java/generator.cc +++ b/src/google/protobuf/compiler/java/generator.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/generator.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/stubs/stringprintf.h" +#include "google/protobuf/compiler/java/file.h" +#include "google/protobuf/compiler/java/generator_factory.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/compiler/java/shared_code_generator.h" +#include "google/protobuf/descriptor.pb.h" + +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/generator.h b/src/google/protobuf/compiler/java/generator.h index e940c599a8..fc7755c2b8 100644 --- a/src/google/protobuf/compiler/java/generator.h +++ b/src/google/protobuf/compiler/java/generator.h @@ -38,10 +38,10 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ #include -#include +#include "google/protobuf/compiler/code_generator.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -78,6 +78,6 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/java/generator_factory.cc b/src/google/protobuf/compiler/java/generator_factory.cc index dd526ba7c7..86baf0b06d 100644 --- a/src/google/protobuf/compiler/java/generator_factory.cc +++ b/src/google/protobuf/compiler/java/generator_factory.cc @@ -30,17 +30,17 @@ // Author: liujisi@google.com (Pherl Liu) -#include +#include "google/protobuf/compiler/java/generator_factory.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/enum_field.h" +#include "google/protobuf/compiler/java/extension.h" +#include "google/protobuf/compiler/java/extension_lite.h" +#include "google/protobuf/compiler/java/field.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/message.h" +#include "google/protobuf/compiler/java/message_lite.h" +#include "google/protobuf/compiler/java/service.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/generator_factory.h b/src/google/protobuf/compiler/java/generator_factory.h index 5febb11944..b2fb0546e9 100644 --- a/src/google/protobuf/compiler/java/generator_factory.h +++ b/src/google/protobuf/compiler/java/generator_factory.h @@ -33,7 +33,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ -#include +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index 0c41c51e9f..625ff18b2e 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -32,30 +32,30 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/helpers.h" #include #include #include #include -#include -#include +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stringprintf.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" -#include -#include -#include +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/compiler/java/names.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -298,7 +298,7 @@ std::string EscapeKotlinKeywords(std::string name) { } std::string UniqueFileScopeIdentifier(const Descriptor* descriptor) { - return "static_" + StringReplace(descriptor->full_name(), ".", "_", true); + return "static_" + absl::StrReplaceAll(descriptor->full_name(), {{".", "_"}}); } std::string CamelCaseFieldName(const FieldDescriptor* field) { @@ -335,7 +335,7 @@ std::string FileJavaPackage(const FileDescriptor* file, Options options) { } std::string JavaPackageToDir(std::string package_name) { - std::string package_dir = StringReplace(package_name, ".", "/", true); + std::string package_dir = absl::StrReplaceAll(package_name, {{".", "/"}}); if (!package_dir.empty()) package_dir += "/"; return package_dir; } @@ -1131,4 +1131,4 @@ void EscapeUtf16ToString(uint16_t code, std::string* output) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index 25e419ff41..eb16096aca 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -38,15 +38,15 @@ #include #include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" #include "absl/strings/string_view.h" -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -485,5 +485,5 @@ std::pair GetTableDrivenNumberOfEntriesAndLookUpStartFieldNumber( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ diff --git a/src/google/protobuf/compiler/java/java_generator.h b/src/google/protobuf/compiler/java/java_generator.h index 294b1bde02..205837172c 100644 --- a/src/google/protobuf/compiler/java/java_generator.h +++ b/src/google/protobuf/compiler/java/java_generator.h @@ -1,6 +1,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ #define GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ -#include +#include "google/protobuf/compiler/java/generator.h" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ diff --git a/src/google/protobuf/compiler/java/kotlin_generator.cc b/src/google/protobuf/compiler/java/kotlin_generator.cc index 1af548a9ea..3470ccbb2f 100644 --- a/src/google/protobuf/compiler/java/kotlin_generator.cc +++ b/src/google/protobuf/compiler/java/kotlin_generator.cc @@ -28,13 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/java/kotlin_generator.h" -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/java/file.h" +#include "google/protobuf/compiler/java/generator.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/options.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/kotlin_generator.h b/src/google/protobuf/compiler/java/kotlin_generator.h index 28b3fa22fb..312b653a7b 100644 --- a/src/google/protobuf/compiler/java/kotlin_generator.h +++ b/src/google/protobuf/compiler/java/kotlin_generator.h @@ -35,10 +35,10 @@ #include -#include +#include "google/protobuf/compiler/code_generator.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -68,6 +68,6 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/java/map_field.cc b/src/google/protobuf/compiler/java/map_field.cc index 23bcfce95b..66d7fbb9c5 100644 --- a/src/google/protobuf/compiler/java/map_field.cc +++ b/src/google/protobuf/compiler/java/map_field.cc @@ -28,16 +28,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/java/map_field.h" -#include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -920,4 +920,4 @@ std::string ImmutableMapFieldGenerator::GetBoxedType() const { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/map_field.h b/src/google/protobuf/compiler/java/map_field.h index 7d39c9f1bb..646c35a16e 100644 --- a/src/google/protobuf/compiler/java/map_field.h +++ b/src/google/protobuf/compiler/java/map_field.h @@ -31,7 +31,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MAP_FIELD_H__ -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/map_field_lite.cc b/src/google/protobuf/compiler/java/map_field_lite.cc index 29736ad641..e116d1ebb6 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.cc +++ b/src/google/protobuf/compiler/java/map_field_lite.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/java/map_field_lite.h" #include -#include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -957,4 +957,4 @@ std::string ImmutableMapFieldLiteGenerator::GetBoxedType() const { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/map_field_lite.h b/src/google/protobuf/compiler/java/map_field_lite.h index 964f0982b9..46a2d9f884 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.h +++ b/src/google/protobuf/compiler/java/map_field_lite.h @@ -33,7 +33,7 @@ #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index c60880fd3d..52768bb477 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/message.h" #include #include @@ -40,27 +40,27 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/enum.h" +#include "google/protobuf/compiler/java/extension.h" +#include "google/protobuf/compiler/java/generator_factory.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/message_builder.h" +#include "google/protobuf/compiler/java/message_builder_lite.h" +#include "google/protobuf/compiler/java/message_serialization.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1772,4 +1772,4 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/message.h b/src/google/protobuf/compiler/java/message.h index 56d4ba3a5f..0380eab8fa 100644 --- a/src/google/protobuf/compiler/java/message.h +++ b/src/google/protobuf/compiler/java/message.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_builder.cc b/src/google/protobuf/compiler/java/message_builder.cc index 48c8e1ea9c..0184ee843d 100644 --- a/src/google/protobuf/compiler/java/message_builder.cc +++ b/src/google/protobuf/compiler/java/message_builder.cc @@ -32,31 +32,31 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/message_builder.h" #include #include #include #include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/enum.h" +#include "google/protobuf/compiler/java/extension.h" +#include "google/protobuf/compiler/java/generator_factory.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -720,4 +720,4 @@ void MessageBuilderGenerator::GenerateIsInitialized(io::Printer* printer) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/message_builder.h b/src/google/protobuf/compiler/java/message_builder.h index 27d85b35f3..5ecbb91bbc 100644 --- a/src/google/protobuf/compiler/java/message_builder.h +++ b/src/google/protobuf/compiler/java/message_builder.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_builder_lite.cc b/src/google/protobuf/compiler/java/message_builder_lite.cc index b4e6a4e747..c444794c9e 100644 --- a/src/google/protobuf/compiler/java/message_builder_lite.cc +++ b/src/google/protobuf/compiler/java/message_builder_lite.cc @@ -32,30 +32,30 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/message_builder_lite.h" #include #include #include #include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/enum.h" +#include "google/protobuf/compiler/java/extension.h" +#include "google/protobuf/compiler/java/generator_factory.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -154,4 +154,4 @@ void MessageBuilderLiteGenerator::GenerateCommonBuilderMethods( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/message_builder_lite.h b/src/google/protobuf/compiler/java/message_builder_lite.h index fd64d0c0e3..f21aec6402 100644 --- a/src/google/protobuf/compiler/java/message_builder_lite.h +++ b/src/google/protobuf/compiler/java/message_builder_lite.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 3bd651df8f..32da1b74eb 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -32,21 +32,21 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/message_field.h" #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1514,4 +1514,4 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/message_field.h b/src/google/protobuf/compiler/java/message_field.h index 88214a9893..65ce3733bf 100644 --- a/src/google/protobuf/compiler/java/message_field.h +++ b/src/google/protobuf/compiler/java/message_field.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_field_lite.cc b/src/google/protobuf/compiler/java/message_field_lite.cc index dc1cd31887..ad685eb26d 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/src/google/protobuf/compiler/java/message_field_lite.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/message_field_lite.h" #include #include #include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -908,4 +908,4 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/message_field_lite.h b/src/google/protobuf/compiler/java/message_field_lite.h index 6ed2404c9c..c5387a6ffe 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.h +++ b/src/google/protobuf/compiler/java/message_field_lite.h @@ -39,7 +39,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index 5e1f78c6bc..fc98ef5009 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/message_lite.h" #include #include @@ -40,26 +40,26 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/enum_lite.h" +#include "google/protobuf/compiler/java/extension_lite.h" +#include "google/protobuf/compiler/java/generator_factory.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/message_builder.h" +#include "google/protobuf/compiler/java/message_builder_lite.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.pb.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1030,4 +1030,4 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/message_lite.h b/src/google/protobuf/compiler/java/message_lite.h index a9c1733108..279404099e 100644 --- a/src/google/protobuf/compiler/java/message_lite.h +++ b/src/google/protobuf/compiler/java/message_lite.h @@ -35,8 +35,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ -#include -#include +#include "google/protobuf/compiler/java/field.h" +#include "google/protobuf/compiler/java/message.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_serialization.cc b/src/google/protobuf/compiler/java/message_serialization.cc index 776ade79c5..d0a0fe26f4 100644 --- a/src/google/protobuf/compiler/java/message_serialization.cc +++ b/src/google/protobuf/compiler/java/message_serialization.cc @@ -28,10 +28,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/java/message_serialization.h" -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" #include "absl/strings/str_cat.h" namespace google { diff --git a/src/google/protobuf/compiler/java/message_serialization.h b/src/google/protobuf/compiler/java/message_serialization.h index 15dc515a85..3b11c47f6d 100644 --- a/src/google/protobuf/compiler/java/message_serialization.h +++ b/src/google/protobuf/compiler/java/message_serialization.h @@ -35,10 +35,10 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/compiler/java/field.h" +#include "google/protobuf/compiler/java/helpers.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_serialization_unittest.cc b/src/google/protobuf/compiler/java/message_serialization_unittest.cc index ed42d5738e..2ef73099ef 100644 --- a/src/google/protobuf/compiler/java/message_serialization_unittest.cc +++ b/src/google/protobuf/compiler/java/message_serialization_unittest.cc @@ -33,18 +33,18 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include -#include -#include +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/compiler/java/generator.h" +#include "google/protobuf/test_util2.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/name_resolver.cc b/src/google/protobuf/compiler/java/name_resolver.cc index cd9f61e3a1..84e74ffddc 100644 --- a/src/google/protobuf/compiler/java/name_resolver.cc +++ b/src/google/protobuf/compiler/java/name_resolver.cc @@ -28,21 +28,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/java/name_resolver.h" #include #include -#include +#include "google/protobuf/compiler/code_generator.h" #include "absl/strings/ascii.h" #include "absl/strings/str_replace.h" #include "absl/strings/substitute.h" -#include -#include +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/names.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -385,4 +385,4 @@ std::string ClassNameResolver::GetDowngradedClassName( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/name_resolver.h b/src/google/protobuf/compiler/java/name_resolver.h index 6d2ec0143d..d73b355702 100644 --- a/src/google/protobuf/compiler/java/name_resolver.h +++ b/src/google/protobuf/compiler/java/name_resolver.h @@ -34,12 +34,13 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/port.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -159,6 +160,6 @@ class ClassNameResolver { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ diff --git a/src/google/protobuf/compiler/java/names.h b/src/google/protobuf/compiler/java/names.h index bf1465b90f..f9c4b95384 100644 --- a/src/google/protobuf/compiler/java/names.h +++ b/src/google/protobuf/compiler/java/names.h @@ -40,7 +40,7 @@ #include -#include +#include "google/protobuf/compiler/java/options.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/options.h b/src/google/protobuf/compiler/java/options.h index 6dfb2a85dc..79d90fd9ca 100644 --- a/src/google/protobuf/compiler/java/options.h +++ b/src/google/protobuf/compiler/java/options.h @@ -33,7 +33,7 @@ #include -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -73,5 +73,5 @@ struct Options { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__ diff --git a/src/google/protobuf/compiler/java/plugin_unittest.cc b/src/google/protobuf/compiler/java/plugin_unittest.cc index 203bc492ff..7fcfd87069 100644 --- a/src/google/protobuf/compiler/java/plugin_unittest.cc +++ b/src/google/protobuf/compiler/java/plugin_unittest.cc @@ -33,13 +33,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/compiler/java/generator.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/java/primitive_field.cc b/src/google/protobuf/compiler/java/primitive_field.cc index 83a20b9650..3706ef164f 100644 --- a/src/google/protobuf/compiler/java/primitive_field.cc +++ b/src/google/protobuf/compiler/java/primitive_field.cc @@ -32,22 +32,22 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/primitive_field.h" #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/primitive_field.h b/src/google/protobuf/compiler/java/primitive_field.h index 1df9dcfe28..914772cf4b 100644 --- a/src/google/protobuf/compiler/java/primitive_field.h +++ b/src/google/protobuf/compiler/java/primitive_field.h @@ -38,7 +38,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.cc b/src/google/protobuf/compiler/java/primitive_field_lite.cc index 254a3a3bce..28066bb6b2 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/primitive_field_lite.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/primitive_field_lite.h" #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.h b/src/google/protobuf/compiler/java/primitive_field_lite.h index 0cddbed43d..410b7d608f 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.h +++ b/src/google/protobuf/compiler/java/primitive_field_lite.h @@ -39,7 +39,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/service.cc b/src/google/protobuf/compiler/java/service.cc index 3478a59aa7..ab1d52cd08 100644 --- a/src/google/protobuf/compiler/java/service.cc +++ b/src/google/protobuf/compiler/java/service.cc @@ -32,18 +32,18 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/service.h" -#include -#include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" // Must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -481,4 +481,4 @@ void ImmutableServiceGenerator::GenerateBlockingMethodSignature( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/java/service.h b/src/google/protobuf/compiler/java/service.h index 22fcd3c8c5..06f50ff873 100644 --- a/src/google/protobuf/compiler/java/service.h +++ b/src/google/protobuf/compiler/java/service.h @@ -36,7 +36,7 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ #include -#include +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/shared_code_generator.cc b/src/google/protobuf/compiler/java/shared_code_generator.cc index cfb40867fa..c70b61cd78 100644 --- a/src/google/protobuf/compiler/java/shared_code_generator.cc +++ b/src/google/protobuf/compiler/java/shared_code_generator.cc @@ -30,19 +30,19 @@ // Author: xiaofeng@google.com (Feng Xiao) -#include +#include "google/protobuf/compiler/java/shared_code_generator.h" #include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/descriptor.h" #include "absl/strings/escaping.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/compiler/java/names.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/shared_code_generator.h b/src/google/protobuf/compiler/java/shared_code_generator.h index cb897d84d2..fdb4f0eeca 100644 --- a/src/google/protobuf/compiler/java/shared_code_generator.h +++ b/src/google/protobuf/compiler/java/shared_code_generator.h @@ -39,8 +39,8 @@ #include #include -#include -#include +#include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/string_field.cc b/src/google/protobuf/compiler/java/string_field.cc index db2803d285..d8b5d4ef6f 100644 --- a/src/google/protobuf/compiler/java/string_field.cc +++ b/src/google/protobuf/compiler/java/string_field.cc @@ -33,22 +33,22 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/string_field.h" #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/string_field.h b/src/google/protobuf/compiler/java/string_field.h index 72b4b60203..b8bc921933 100644 --- a/src/google/protobuf/compiler/java/string_field.h +++ b/src/google/protobuf/compiler/java/string_field.h @@ -39,7 +39,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/string_field_lite.cc b/src/google/protobuf/compiler/java/string_field_lite.cc index 61c7e12844..2551d395cc 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.cc +++ b/src/google/protobuf/compiler/java/string_field_lite.cc @@ -33,22 +33,22 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/java/string_field_lite.h" #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include +#include "google/protobuf/compiler/java/context.h" +#include "google/protobuf/compiler/java/doc_comment.h" +#include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/compiler/java/name_resolver.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/string_field_lite.h b/src/google/protobuf/compiler/java/string_field_lite.h index f1cf26bfec..f35da288f9 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.h +++ b/src/google/protobuf/compiler/java/string_field_lite.h @@ -40,7 +40,7 @@ #include #include -#include +#include "google/protobuf/compiler/java/field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index 15b65915e9..ecaf76b981 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc @@ -28,19 +28,19 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/cpp/generator.h" +#include "google/protobuf/compiler/java/generator.h" +#include "google/protobuf/compiler/java/kotlin_generator.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/compiler/csharp/csharp_generator.h" +#include "google/protobuf/compiler/objectivec/objectivec_generator.h" +#include "google/protobuf/compiler/php/php_generator.h" +#include "google/protobuf/compiler/python/generator.h" +#include "google/protobuf/compiler/python/pyi_generator.h" +#include "google/protobuf/compiler/ruby/ruby_generator.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 1c4d7a0ef0..f19cbf5224 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include +#include "google/protobuf/compiler/mock_code_generator.h" #include @@ -39,24 +39,24 @@ #include #include -#include +#include "google/protobuf/stubs/strutil.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/compiler/plugin.pb.h" +#include "google/protobuf/descriptor.pb.h" #include #include "absl/strings/str_join.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/text_format.h" #ifdef major #undef major diff --git a/src/google/protobuf/compiler/mock_code_generator.h b/src/google/protobuf/compiler/mock_code_generator.h index 45d735a30f..f91b7bc5b7 100644 --- a/src/google/protobuf/compiler/mock_code_generator.h +++ b/src/google/protobuf/compiler/mock_code_generator.h @@ -36,7 +36,7 @@ #include #include -#include +#include "google/protobuf/compiler/code_generator.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc index bd8f341cf6..7e1283b841 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc @@ -31,10 +31,14 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_enum.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.h b/src/google/protobuf/compiler/objectivec/objectivec_enum.h index 1d5741a53c..0759ae5dc2 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.h @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc index 6e0d69bcda..049ff475d5 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc @@ -31,9 +31,9 @@ #include #include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_enum_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h index f0d685c3d6..7bd3c32c75 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h @@ -33,7 +33,7 @@ #include #include -#include +#include "google/protobuf/compiler/objectivec/objectivec_field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc index fca84b738f..c70766a6ef 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc @@ -30,15 +30,19 @@ #include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_extension.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_extension.h b/src/google/protobuf/compiler/objectivec/objectivec_extension.h index d412f4a9f2..cfdf718aaa 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_extension.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_extension.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_EXTENSION_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_EXTENSION_H__ -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index 899e62a125..f11cbde086 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -30,14 +30,18 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/compiler/objectivec/objectivec_enum_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_map_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_message_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_primitive_field.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.h b/src/google/protobuf/compiler/objectivec/objectivec_field.h index 759ef808d3..6750b513cd 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.h @@ -33,8 +33,8 @@ #include #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 5c21cd2ab2..a420c2c69b 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -28,16 +28,20 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_file.h" +#include "google/protobuf/compiler/objectivec/objectivec_enum.h" +#include "google/protobuf/compiler/objectivec/objectivec_extension.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/compiler/objectivec/objectivec_message.h" +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/stubs/stl_util.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.h b/src/google/protobuf/compiler/objectivec/objectivec_file.h index f62a4bc979..842ddff154 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.h @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index b08dcaabc2..e2efe29b20 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -32,12 +32,16 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_generator.h" +#include "google/protobuf/compiler/objectivec/objectivec_file.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.h b/src/google/protobuf/compiler/objectivec/objectivec_generator.h index 1dbc666af1..f863fc8686 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.h @@ -34,10 +34,10 @@ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ #include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -74,6 +74,6 @@ class PROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index e3a5c5a585..1dbff83749 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -41,17 +41,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/port.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" @@ -571,8 +571,8 @@ void MaybeUnQuote(absl::string_view* input) { } // namespace // Escape C++ trigraphs by escaping question marks to \? -std::string EscapeTrigraphs(const std::string& to_escape) { - return StringReplace(to_escape, "?", "\\?", true); +std::string EscapeTrigraphs(absl::string_view to_escape) { + return absl::StrReplaceAll(to_escape, {{"?", "\\?"}}); } void TrimWhitespace(absl::string_view* input) { @@ -1217,14 +1217,15 @@ std::string BuildCommentsString(const SourceLocation& location, add_leading_space = true; } - for (int i = 0; i < lines.size(); i++) { - std::string line = StripPrefixString(lines[i], " "); - // HeaderDoc and appledoc use '\' and '@' for markers; escape them. - line = StringReplace(line, "\\", "\\\\", true); - line = StringReplace(line, "@", "\\@", true); - // Decouple / from * to not have inline comments inside comments. - line = StringReplace(line, "/*", "/\\*", true); - line = StringReplace(line, "*/", "*\\/", true); + for (size_t i = 0; i < lines.size(); i++) { + std::string line = absl::StrReplaceAll( + StripPrefixString(lines[i], " "), + {// HeaderDoc and appledoc use '\' and '@' for markers; escape them. + {"\\", "\\\\"}, + {"@", "\\@"}, + // Decouple / from * to not have inline comments inside comments. + {"/*", "/\\*"}, + {"*/", "*\\/"}}); line = prefix + line; StripWhitespace(&line); // If not a one line, need to add the first space before *, as diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 9a5c6e6656..9cee305080 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -36,11 +36,11 @@ #include #include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/zero_copy_stream.h" -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -79,7 +79,7 @@ struct Options { }; // Escape C++ trigraphs by escaping question marks to "\?". -std::string PROTOC_EXPORT EscapeTrigraphs(const std::string& to_escape); +std::string PROTOC_EXPORT EscapeTrigraphs(absl::string_view to_escape); // Remove white space from either end of a absl::string_view. void PROTOC_EXPORT TrimWhitespace(absl::string_view* input); @@ -352,6 +352,6 @@ class PROTOC_EXPORT ImportWriter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc index 89cf7fe351..7ad11f04cb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc @@ -28,8 +28,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include namespace google { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc index 99d7581533..087bd8fb2d 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc @@ -31,9 +31,9 @@ #include #include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_map_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h index d9aa387165..c16e818e2e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h @@ -33,7 +33,7 @@ #include #include -#include +#include "google/protobuf/compiler/objectivec/objectivec_field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 6135fb262f..945d095b7e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -32,20 +32,24 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_message.h" +#include "google/protobuf/compiler/objectivec/objectivec_enum.h" +#include "google/protobuf/compiler/objectivec/objectivec_extension.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/stubs/stl_util.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" #include "absl/strings/str_replace.h" -#include -#include -#include -#include +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 9d14430981..641a518638 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -34,10 +34,10 @@ #include #include #include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_oneof.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc index 2ff0b44a69..e889c6ef5e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc @@ -31,9 +31,9 @@ #include #include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_message_field.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h index 49a84fbd1e..12e191eed2 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h @@ -33,7 +33,7 @@ #include #include -#include +#include "google/protobuf/compiler/objectivec/objectivec_field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc b/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc index 686cedf00e..269cd52660 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc @@ -31,10 +31,14 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_oneof.h" +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h index 034f07fb33..27e9c2a423 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_oneof.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_oneof.h @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index 60d0719fb4..2c30d6bac5 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -31,10 +31,14 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/compiler/objectivec/objectivec_helpers.h" +#include "google/protobuf/compiler/objectivec/objectivec_primitive_field.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_split.h" +#include "absl/strings/str_replace.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h index 06a1528a82..8948b48091 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h @@ -31,7 +31,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_PRIMITIVE_FIELD_H__ -#include +#include "google/protobuf/compiler/objectivec/objectivec_field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index 83dc7f8296..4cae1a1187 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -34,7 +34,7 @@ // // Recursive descent FTW. -#include +#include "google/protobuf/compiler/parser.h" #include @@ -44,18 +44,18 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/base/casts.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/port.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index e40d133251..ccd3e5a5f7 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -42,13 +42,13 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/repeated_field.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -597,6 +597,6 @@ class PROTOBUF_EXPORT SourceLocationTable { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_PARSER_H__ diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 1fee6dd6a2..3b32451916 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/compiler/parser.h" #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/test_util2.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/any.pb.h" +#include "google/protobuf/unittest_custom_options.pb.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/strings/str_join.h" #include "absl/strings/substitute.h" diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 0e6639e0cf..7c1daec42f 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -28,21 +28,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/php/php_generator.h" #include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/plugin.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" -#include -#include -#include +#include "absl/strings/str_replace.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" const std::string kDescriptorFile = "google/protobuf/descriptor.proto"; const std::string kEmptyFile = "google/protobuf/empty.proto"; @@ -1952,17 +1952,13 @@ void GenerateServiceMethodDocComment(io::Printer* printer, } std::string FilenameCName(const FileDescriptor* file) { - std::string c_name = file->name(); - c_name = StringReplace(c_name, ".", "_", true); - c_name = StringReplace(c_name, "/", "_", true); - return c_name; + return absl::StrReplaceAll(file->name(), {{".", "_"}, {"/", "_"}}); } void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) { - std::string c_name = desc->full_name(); - c_name = StringReplace(c_name, ".", "_", true); - std::string php_name = FullClassName(desc, Options()); - php_name = StringReplace(php_name, "\\", "\\\\", true); + std::string c_name = absl::StrReplaceAll(desc->full_name(), {{".", "_"}}); + std::string php_name = + absl::StrReplaceAll(FullClassName(desc, Options()), {{"\\", "\\\\"}}); printer->Print( "/* $c_name$ */\n" "\n" @@ -2045,10 +2041,9 @@ void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) { } void GenerateCMessage(const Descriptor* message, io::Printer* printer) { - std::string c_name = message->full_name(); - c_name = StringReplace(c_name, ".", "_", true); - std::string php_name = FullClassName(message, Options()); - php_name = StringReplace(php_name, "\\", "\\\\", true); + std::string c_name = absl::StrReplaceAll(message->full_name(), {{".", "_"}}); + std::string php_name = + absl::StrReplaceAll(FullClassName(message, Options()), {{"\\", "\\\\"}}); printer->Print( "/* $c_name$ */\n" "\n" @@ -2198,8 +2193,7 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) { } void GenerateEnumCInit(const EnumDescriptor* desc, io::Printer* printer) { - std::string c_name = desc->full_name(); - c_name = StringReplace(c_name, ".", "_", true); + std::string c_name = absl::StrReplaceAll(desc->full_name(), {{".", "_"}}); printer->Print( " $c_name$_ModuleInit();\n", @@ -2207,8 +2201,7 @@ void GenerateEnumCInit(const EnumDescriptor* desc, io::Printer* printer) { } void GenerateCInit(const Descriptor* message, io::Printer* printer) { - std::string c_name = message->full_name(); - c_name = StringReplace(c_name, ".", "_", true); + std::string c_name = absl::StrReplaceAll(message->full_name(), {{".", "_"}}); printer->Print( " $c_name$_ModuleInit();\n", @@ -2250,8 +2243,9 @@ void GenerateCWellKnownTypes(const std::vector& files, std::string metadata_filename = GeneratedMetadataFileName(file, Options()); std::string metadata_classname = FilenameToClassname(metadata_filename); std::string metadata_c_name = - StringReplace(metadata_classname, "\\", "_", true); - metadata_classname = StringReplace(metadata_classname, "\\", "\\\\", true); + absl::StrReplaceAll(metadata_classname, {{"\\", "_"}}); + metadata_classname = + absl::StrReplaceAll(metadata_classname, {{"\\", "\\\\"}}); FileDescriptorProto file_proto; file->CopyTo(&file_proto); std::string serialized; @@ -2332,7 +2326,7 @@ void GenerateCWellKnownTypes(const std::vector& files, std::string metadata_filename = GeneratedMetadataFileName(file, Options()); std::string metadata_classname = FilenameToClassname(metadata_filename); std::string metadata_c_name = - StringReplace(metadata_classname, "\\", "_", true); + absl::StrReplaceAll(metadata_classname, {{"\\", "_"}}); printer.Print( " $metadata_c_name$_ModuleInit();\n", "metadata_c_name", metadata_c_name); diff --git a/src/google/protobuf/compiler/php/php_generator.h b/src/google/protobuf/compiler/php/php_generator.h index 17cb59c08b..5007c71283 100644 --- a/src/google/protobuf/compiler/php/php_generator.h +++ b/src/google/protobuf/compiler/php/php_generator.h @@ -31,12 +31,12 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" #include -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -87,6 +87,6 @@ inline bool IsWrapperType(const FieldDescriptor* descriptor) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index 0a323843db..b7e5c0e6f8 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include +#include "google/protobuf/compiler/plugin.h" #include #include @@ -41,14 +41,14 @@ #include #endif -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/compiler/plugin.pb.h" +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" namespace google { diff --git a/src/google/protobuf/compiler/plugin.h b/src/google/protobuf/compiler/plugin.h index 611713e2c0..388f51a7c1 100644 --- a/src/google/protobuf/compiler/plugin.h +++ b/src/google/protobuf/compiler/plugin.h @@ -65,7 +65,7 @@ #include // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -91,6 +91,6 @@ bool GenerateCode(const CodeGeneratorRequest& request, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index e0b6057242..bcaf8d509d 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -1625,4 +1625,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRespo PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 81ffdc39e7..8e8c111451 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,21 +19,21 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/generated_enum_reflection.h" +#include "google/protobuf/unknown_field_set.h" #include // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fcompiler_2fplugin_2eproto PROTOC_EXPORT #ifdef major #undef major @@ -1202,8 +1202,7 @@ inline void CodeGeneratorRequest::set_file_to_generate(int index, std::string&& // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.file_to_generate_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.file_to_generate_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, size_t size) { @@ -1223,8 +1222,7 @@ inline void CodeGeneratorRequest::add_file_to_generate(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::add_file_to_generate(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.file_to_generate_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.file_to_generate_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::add_file_to_generate(const char* value, size_t size) { @@ -1889,5 +1887,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc index 65c1faa135..3d580adc32 100644 --- a/src/google/protobuf/compiler/python/generator.cc +++ b/src/google/protobuf/compiler/python/generator.cc @@ -42,7 +42,7 @@ // performance-minded Python code leverage the fast C++ implementation // directly. -#include +#include "google/protobuf/compiler/python/generator.h" #include #include @@ -52,20 +52,20 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stringprintf.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/python/helpers.h" +#include "google/protobuf/compiler/python/pyi_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/python/generator.h b/src/google/protobuf/compiler/python/generator.h index 4dd6e2d3af..3fa946d959 100644 --- a/src/google/protobuf/compiler/python/generator.h +++ b/src/google/protobuf/compiler/python/generator.h @@ -38,10 +38,10 @@ #include #include "absl/synchronization/mutex.h" -#include +#include "google/protobuf/compiler/code_generator.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -197,6 +197,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/python/helpers.cc b/src/google/protobuf/compiler/python/helpers.cc index 4502263cc7..711d555249 100644 --- a/src/google/protobuf/compiler/python/helpers.cc +++ b/src/google/protobuf/compiler/python/helpers.cc @@ -28,16 +28,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/python/helpers.h" #include -#include +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/escaping.h" #include "absl/strings/str_split.h" -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/python/helpers.h b/src/google/protobuf/compiler/python/helpers.h index 59fbee1f7b..1fff3c9d79 100644 --- a/src/google/protobuf/compiler/python/helpers.h +++ b/src/google/protobuf/compiler/python/helpers.h @@ -34,8 +34,8 @@ #include #include "absl/strings/str_replace.h" -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/python/plugin_unittest.cc b/src/google/protobuf/compiler/python/plugin_unittest.cc index 8e21594e2f..b8f25cf3e5 100644 --- a/src/google/protobuf/compiler/python/plugin_unittest.cc +++ b/src/google/protobuf/compiler/python/plugin_unittest.cc @@ -33,13 +33,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/compiler/python/generator.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/strings/str_split.h" diff --git a/src/google/protobuf/compiler/python/pyi_generator.cc b/src/google/protobuf/compiler/python/pyi_generator.cc index e19da8518b..7c723ef853 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.cc +++ b/src/google/protobuf/compiler/python/pyi_generator.cc @@ -28,19 +28,19 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/python/pyi_generator.h" #include #include #include "absl/strings/ascii.h" -#include +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_split.h" -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/python/helpers.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { @@ -491,6 +491,7 @@ void PyiGenerator::PrintMessage( } is_first = false; printer_->Print(", $field_name$: ", "field_name", field_name); + Annotate("field_name", field_des); if (field_des->is_repeated() || field_des->cpp_type() != FieldDescriptor::CPPTYPE_BOOL) { printer_->Print("_Optional["); diff --git a/src/google/protobuf/compiler/python/pyi_generator.h b/src/google/protobuf/compiler/python/pyi_generator.h index 655b90a17a..7f1e5d839d 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.h +++ b/src/google/protobuf/compiler/python/pyi_generator.h @@ -40,10 +40,10 @@ #include #include "absl/synchronization/mutex.h" -#include +#include "google/protobuf/compiler/code_generator.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -114,6 +114,6 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_PYI_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h index 21d48cd9a0..bb31797a68 100644 --- a/src/google/protobuf/compiler/python/python_generator.h +++ b/src/google/protobuf/compiler/python/python_generator.h @@ -1,6 +1,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ #define GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ -#include +#include "google/protobuf/compiler/python/generator.h" #endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code.proto b/src/google/protobuf/compiler/ruby/ruby_generated_code.proto index 70ec9f17a0..56173c2774 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_code.proto +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code.proto @@ -1,3 +1,33 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + syntax = "proto3"; package A.B.C; diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto index ea7f783634..cd4955d568 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto @@ -1,3 +1,33 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + syntax = "proto2"; package A.B.C; diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto index 9ec07381be..9fc17191bb 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto @@ -1,3 +1,33 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + syntax = "proto2"; package A.B.C; diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto index 8d7c948a18..153cec62e9 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto +++ b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto @@ -1,3 +1,33 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + syntax = "proto3"; package one.two.a_three; diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto index 7a0d260865..6515634ad9 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto +++ b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto @@ -1,3 +1,33 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + syntax = "proto3"; package one.two.a_three.and; diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto index 544db64d94..23eaa43f0c 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto +++ b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto @@ -1,3 +1,33 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + syntax = "proto3"; package one.two.a_three; diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index 7569a88306..be643d88b6 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -28,17 +28,17 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/compiler/ruby/ruby_generator.h" #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/plugin.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.h b/src/google/protobuf/compiler/ruby/ruby_generator.h index 647bb83606..a6881ff411 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.h +++ b/src/google/protobuf/compiler/ruby/ruby_generator.h @@ -35,9 +35,9 @@ #include -#include +#include "google/protobuf/compiler/code_generator.h" -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -62,6 +62,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc b/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc index c3ce1d3684..31d3770cee 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc @@ -28,17 +28,17 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include +#include "google/protobuf/compiler/ruby/ruby_generator.h" -#include -#include -#include -#include +#include +#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/googletest.h" #include -#include +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/scc.h b/src/google/protobuf/compiler/scc.h index a5d7435169..2408dcd07b 100644 --- a/src/google/protobuf/compiler/scc.h +++ b/src/google/protobuf/compiler/scc.h @@ -33,12 +33,12 @@ #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -159,6 +159,6 @@ class PROTOC_EXPORT SCCAnalyzer { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_SCC_H__ diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index 9a97d1dc00..ae1f5dd049 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include +#include "google/protobuf/compiler/subprocess.h" #include #include @@ -43,12 +43,12 @@ #include #endif -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #include "absl/strings/escaping.h" #include "absl/strings/substitute.h" -#include -#include +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/message.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/subprocess.h b/src/google/protobuf/compiler/subprocess.h index 5cb784d467..b6bf282389 100644 --- a/src/google/protobuf/compiler/subprocess.h +++ b/src/google/protobuf/compiler/subprocess.h @@ -42,12 +42,12 @@ #include #include #endif // !_WIN32 -#include - #include +#include "google/protobuf/port.h" + // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -109,6 +109,6 @@ class PROTOC_EXPORT Subprocess { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ diff --git a/src/google/protobuf/compiler/test_plugin.cc b/src/google/protobuf/compiler/test_plugin.cc index 2556078c85..2ed1e3dd30 100644 --- a/src/google/protobuf/compiler/test_plugin.cc +++ b/src/google/protobuf/compiler/test_plugin.cc @@ -37,8 +37,8 @@ #include -#include -#include +#include "google/protobuf/compiler/mock_code_generator.h" +#include "google/protobuf/compiler/plugin.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/zip_writer.cc b/src/google/protobuf/compiler/zip_writer.cc index 72e1d7114d..73b9ef54b5 100644 --- a/src/google/protobuf/compiler/zip_writer.cc +++ b/src/google/protobuf/compiler/zip_writer.cc @@ -33,11 +33,11 @@ // // Based on http://www.pkware.com/documents/casestudies/APPNOTE.TXT -#include +#include "google/protobuf/compiler/zip_writer.h" #include -#include +#include "google/protobuf/io/coded_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/zip_writer.h b/src/google/protobuf/compiler/zip_writer.h index 5d7f69a407..89717c773c 100644 --- a/src/google/protobuf/compiler/zip_writer.h +++ b/src/google/protobuf/compiler/zip_writer.h @@ -35,8 +35,8 @@ #include #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index ae9c47fa2c..ddebcf6184 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/descriptor.h" #include #include @@ -46,9 +46,9 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/base/dynamic_annotations.h" @@ -58,25 +58,25 @@ #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stringprintf.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" #include "absl/strings/substitute.h" #include "absl/synchronization/mutex.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/any.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor_database.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/io/strtod.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/port.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/unknown_field_set.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -8323,4 +8323,4 @@ Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, bool is_lite) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 7ad2fc486b..dfe8d42cab 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -63,16 +63,17 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/port.h" #include "absl/base/call_once.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #define PROTOBUF_EXPORT @@ -2540,6 +2541,6 @@ PROTOBUF_EXPORT Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, } // namespace google #undef PROTOBUF_INTERNAL_CHECK_CLASS_SIZE -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_DESCRIPTOR_H__ diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 3bd5fe8894..b8a24a9f53 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -11567,4 +11567,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo >(Arena* a PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 34e09e6e6b..a75a31c36e 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,20 +19,20 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/generated_enum_reflection.h" +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fdescriptor_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -8865,8 +8865,7 @@ inline void FileDescriptorProto::set_dependency(int index, std::string&& value) // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::set_dependency(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.dependency_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.dependency_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::set_dependency(int index, const char* value, size_t size) { @@ -8886,8 +8885,7 @@ inline void FileDescriptorProto::add_dependency(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::add_dependency(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.dependency_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.dependency_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::add_dependency(const char* value, size_t size) { @@ -10156,8 +10154,7 @@ inline void DescriptorProto::set_reserved_name(int index, std::string&& value) { // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::set_reserved_name(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.reserved_name_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::set_reserved_name(int index, const char* value, size_t size) { @@ -10177,8 +10174,7 @@ inline void DescriptorProto::add_reserved_name(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::add_reserved_name(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.reserved_name_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::add_reserved_name(const char* value, size_t size) { @@ -11301,8 +11297,7 @@ inline void EnumDescriptorProto::set_reserved_name(int index, std::string&& valu // @@protoc_insertion_point(field_set:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::set_reserved_name(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.reserved_name_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::set_reserved_name(int index, const char* value, size_t size) { @@ -11322,8 +11317,7 @@ inline void EnumDescriptorProto::add_reserved_name(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::add_reserved_name(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.reserved_name_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::add_reserved_name(const char* value, size_t size) { @@ -14538,8 +14532,7 @@ inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, st // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.leading_detached_comments_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.leading_detached_comments_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value, size_t size) { @@ -14559,8 +14552,7 @@ inline void SourceCodeInfo_Location::add_leading_detached_comments(std::string&& // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.leading_detached_comments_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.leading_detached_comments_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value, size_t size) { @@ -14970,5 +14962,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh diff --git a/src/google/protobuf/descriptor_database.cc b/src/google/protobuf/descriptor_database.cc index 209cbe249c..440bf9a97f 100644 --- a/src/google/protobuf/descriptor_database.cc +++ b/src/google/protobuf/descriptor_database.cc @@ -32,17 +32,17 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/descriptor_database.h" #include #include #include #include "absl/strings/ascii.h" -#include +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_replace.h" -#include -#include +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/stubs/stl_util.h" namespace google { diff --git a/src/google/protobuf/descriptor_database.h b/src/google/protobuf/descriptor_database.h index 595b0bf22a..942f975ae3 100644 --- a/src/google/protobuf/descriptor_database.h +++ b/src/google/protobuf/descriptor_database.h @@ -43,11 +43,11 @@ #include #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -399,6 +399,6 @@ class PROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ diff --git a/src/google/protobuf/descriptor_database_unittest.cc b/src/google/protobuf/descriptor_database_unittest.cc index 5948d1b862..d06d0c0501 100644 --- a/src/google/protobuf/descriptor_database_unittest.cc +++ b/src/google/protobuf/descriptor_database_unittest.cc @@ -34,18 +34,18 @@ // // This file makes extensive use of RFC 3092. :) -#include +#include "google/protobuf/descriptor_database.h" #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/text_format.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 48d70a4470..a2900454f6 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -38,33 +38,33 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/any.pb.h" +#include "google/protobuf/compiler/importer.h" +#include "google/protobuf/compiler/parser.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_custom_options.pb.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/stringprintf.h" +#include "google/protobuf/unittest_lazy_dependencies.pb.h" +#include "google/protobuf/unittest_proto3_arena.pb.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor_database.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/stubs/strutil.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include -#include +#include "google/protobuf/stubs/logging.h" #include "absl/strings/substitute.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" using ::testing::AnyOf; @@ -6129,7 +6129,9 @@ static const char* kMapEntryKeyTypeErrorMessage = TEST_F(ValidationErrorTest, MapEntryBase) { FileDescriptorProto file_proto; FillValidMapEntry(&file_proto); - BuildFile(file_proto.DebugString()); + std::string text_proto; + TextFormat::PrintToString(file_proto, &text_proto); + BuildFile(text_proto); } TEST_F(ValidationErrorTest, MapEntryExtensionRange) { @@ -7419,7 +7421,7 @@ class SingletonSourceTree : public compiler::SourceTree { SingletonSourceTree(const SingletonSourceTree&) = delete; SingletonSourceTree& operator=(const SingletonSourceTree&) = delete; - io::ZeroCopyInputStream* Open(const std::string& filename) override { + io::ZeroCopyInputStream* Open(absl::string_view filename) override { return filename == filename_ ? new io::ArrayInputStream(contents_.data(), contents_.size()) : nullptr; @@ -8426,4 +8428,4 @@ TEST_F(LazilyBuildDependenciesTest, Dependency) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/drop_unknown_fields_test.cc b/src/google/protobuf/drop_unknown_fields_test.cc index 55c6b67caf..747cb5b8fe 100644 --- a/src/google/protobuf/drop_unknown_fields_test.cc +++ b/src/google/protobuf/drop_unknown_fields_test.cc @@ -30,9 +30,9 @@ #include -#include -#include -#include +#include "google/protobuf/unittest_drop_unknown_fields.pb.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/message_lite.h" #include using unittest_drop_unknown_fields::Foo; diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 5ca3145244..b0db698485 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -306,4 +306,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Duration >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index e33249099b..a1e62ccdd5 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,19 +19,19 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fduration_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -236,7 +236,7 @@ inline int64_t Duration::seconds() const { return _internal_seconds(); } inline void Duration::_internal_set_seconds(int64_t value) { - + _impl_.seconds_ = value; } inline void Duration::set_seconds(int64_t value) { @@ -256,7 +256,7 @@ inline int32_t Duration::nanos() const { return _internal_nanos(); } inline void Duration::_internal_set_nanos(int32_t value) { - + _impl_.nanos_ = value; } inline void Duration::set_nanos(int32_t value) { @@ -274,5 +274,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc index 144232cdde..16bce6ebbb 100644 --- a/src/google/protobuf/dynamic_message.cc +++ b/src/google/protobuf/dynamic_message.cc @@ -62,7 +62,7 @@ // Item 8 of "More Effective C++" discusses this in more detail, though // I don't have the book on me right now so I'm not sure. -#include +#include "google/protobuf/dynamic_message.h" #include #include @@ -70,23 +70,23 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/map_type_handler.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/wire_format.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -825,4 +825,4 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( } // namespace protobuf } // namespace google -#include // NOLINT +#include "google/protobuf/port_undef.inc" // NOLINT diff --git a/src/google/protobuf/dynamic_message.h b/src/google/protobuf/dynamic_message.h index 9bd262a780..bec0a1e43c 100644 --- a/src/google/protobuf/dynamic_message.h +++ b/src/google/protobuf/dynamic_message.h @@ -44,18 +44,18 @@ #include #include -#include #include "absl/synchronization/mutex.h" -#include -#include -#include +#include "google/protobuf/message.h" +#include "google/protobuf/port.h" +#include "google/protobuf/reflection.h" +#include "google/protobuf/repeated_field.h" #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -225,6 +225,6 @@ class PROTOBUF_EXPORT DynamicMapSorter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ diff --git a/src/google/protobuf/dynamic_message_unittest.cc b/src/google/protobuf/dynamic_message_unittest.cc index 7ac20295cc..6dd1184710 100644 --- a/src/google/protobuf/dynamic_message_unittest.cc +++ b/src/google/protobuf/dynamic_message_unittest.cc @@ -40,19 +40,19 @@ // reflection_ops_unittest, cover the rest of the functionality used by // DynamicMessage. -#include +#include "google/protobuf/dynamic_message.h" #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_no_field_presence.pb.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/testing/googletest.h" #include -#include +#include "google/protobuf/test_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index f562c59397..c3de546339 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -129,4 +129,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Empty >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 8e858d0512..8e65cb6b39 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,20 +19,20 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_bases.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fempty_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -194,5 +194,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh diff --git a/src/google/protobuf/endian.h b/src/google/protobuf/endian.h index e0ee6cdf28..2527b3e7f1 100644 --- a/src/google/protobuf/endian.h +++ b/src/google/protobuf/endian.h @@ -38,7 +38,7 @@ #include // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -193,6 +193,6 @@ inline uint64_t ToHost(uint64_t value) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_ENDIAN_H__ diff --git a/src/google/protobuf/explicitly_constructed.h b/src/google/protobuf/explicitly_constructed.h index 174c59ab4b..c27364459b 100644 --- a/src/google/protobuf/explicitly_constructed.h +++ b/src/google/protobuf/explicitly_constructed.h @@ -35,11 +35,11 @@ #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on namespace google { @@ -92,6 +92,6 @@ using ExplicitlyConstructedArenaString = ExplicitlyConstructed; } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_EXPLICITLY_CONSTRUCTED_H__ diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index c0dc193eaf..791c1e3489 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -32,26 +32,26 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/extension_set.h" #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/arena.h" #include "absl/container/flat_hash_set.h" #include "absl/hash/hash.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/extension_set_inl.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/port.h" +#include "google/protobuf/repeated_field.h" // must be last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1959,4 +1959,4 @@ LazyEagerVerifyFnType FindExtensionLazyEagerVerifyFn( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index 43c56a756b..2ce566aec6 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -46,16 +46,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/port.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/port.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/wire_format_lite.h" // clang-format off -#include // Must be last +#include "google/protobuf/port_def.inc" // Must be last // clang-format on #ifdef SWIG @@ -1560,6 +1561,6 @@ void LinkExtensionReflection( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ diff --git a/src/google/protobuf/extension_set_heavy.cc b/src/google/protobuf/extension_set_heavy.cc index 086ab89f55..0ccce3c373 100644 --- a/src/google/protobuf/extension_set_heavy.cc +++ b/src/google/protobuf/extension_set_heavy.cc @@ -35,25 +35,25 @@ // Contains methods defined in extension_set.h which cannot be part of the // lite library because they use descriptors or reflection. -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" #include "absl/base/casts.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/extension_set_inl.h" +#include "google/protobuf/message.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/port.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -438,4 +438,4 @@ uint8_t* ExtensionSet::SerializeMessageSetWithCachedSizesToArray( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/extension_set_inl.h b/src/google/protobuf/extension_set_inl.h index 95936cc243..f98065c607 100644 --- a/src/google/protobuf/extension_set_inl.h +++ b/src/google/protobuf/extension_set_inl.h @@ -31,9 +31,9 @@ #ifndef GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__ #define GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__ -#include -#include -#include +#include "google/protobuf/extension_set.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/parse_context.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index 065ab4dfdb..8b436bc20c 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -32,31 +32,31 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/extension_set.h" + +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_mset.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/base/casts.h" -#include -#include -#include +#include "google/protobuf/test_util.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/stubs/stl_util.h" -#include +#include "google/protobuf/stubs/strutil.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { diff --git a/src/google/protobuf/field_access_listener.h b/src/google/protobuf/field_access_listener.h index 00436c33cd..fd54f0e63e 100644 --- a/src/google/protobuf/field_access_listener.h +++ b/src/google/protobuf/field_access_listener.h @@ -33,8 +33,8 @@ #include -#include -#include +#include "google/protobuf/message_lite.h" +#include "google/protobuf/port.h" namespace google { diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index 5f710927ea..66af752693 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -283,4 +283,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::FieldMask >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 46723f9921..7d003df4bd 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,19 +19,19 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2ffield_5fmask_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -263,8 +263,7 @@ inline void FieldMask::set_paths(int index, std::string&& value) { // @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths) } inline void FieldMask::set_paths(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.paths_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.paths_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths) } inline void FieldMask::set_paths(int index, const char* value, size_t size) { @@ -284,8 +283,7 @@ inline void FieldMask::add_paths(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths) } inline void FieldMask::add_paths(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.paths_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.paths_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths) } inline void FieldMask::add_paths(const char* value, size_t size) { @@ -313,5 +311,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh diff --git a/src/google/protobuf/generated_enum_reflection.h b/src/google/protobuf/generated_enum_reflection.h index 440a6fc2bb..31ddc12e03 100644 --- a/src/google/protobuf/generated_enum_reflection.h +++ b/src/google/protobuf/generated_enum_reflection.h @@ -42,16 +42,16 @@ #include -#include +#include "google/protobuf/port.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/generated_enum_util.h" #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -95,6 +95,6 @@ PROTOBUF_EXPORT const std::string& NameOfEnum(const EnumDescriptor* descriptor, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ diff --git a/src/google/protobuf/generated_enum_util.cc b/src/google/protobuf/generated_enum_util.cc index f73e82c50a..ab21577fff 100644 --- a/src/google/protobuf/generated_enum_util.cc +++ b/src/google/protobuf/generated_enum_util.cc @@ -28,11 +28,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/generated_enum_util.h" #include -#include +#include "google/protobuf/generated_message_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/generated_enum_util.h b/src/google/protobuf/generated_enum_util.h index de0bd8f216..86e1bb95de 100644 --- a/src/google/protobuf/generated_enum_util.h +++ b/src/google/protobuf/generated_enum_util.h @@ -35,10 +35,10 @@ #include #include "absl/strings/string_view.h" -#include +#include "google/protobuf/message_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -80,6 +80,6 @@ PROTOBUF_EXPORT bool InitializeEnumStrings( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__ diff --git a/src/google/protobuf/generated_message_bases.cc b/src/google/protobuf/generated_message_bases.cc index 306a38eef3..2ccca160d1 100644 --- a/src/google/protobuf/generated_message_bases.cc +++ b/src/google/protobuf/generated_message_bases.cc @@ -28,17 +28,17 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/generated_message_bases.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" // Must be last: -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -121,4 +121,4 @@ void ZeroFieldsBase::InternalSwap(ZeroFieldsBase* other) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/generated_message_bases.h b/src/google/protobuf/generated_message_bases.h index b295218a70..e8310799e4 100644 --- a/src/google/protobuf/generated_message_bases.h +++ b/src/google/protobuf/generated_message_bases.h @@ -35,14 +35,14 @@ #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ -#include -#include -#include -#include -#include +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/message.h" +#include "google/protobuf/parse_context.h" // Must come last: -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -82,6 +82,6 @@ class PROTOBUF_EXPORT ZeroFieldsBase : public Message { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 441a6e2ce9..b1b472cb9d 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/generated_message_reflection.h" #include #include @@ -40,28 +40,28 @@ #include #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #include "absl/base/casts.h" +#include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/generated_message_tctable_gen.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/inlined_string_field.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/unknown_field_set.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on #define GOOGLE_PROTOBUF_HAS_ONEOF @@ -139,7 +139,8 @@ const std::string** MakeDenseEnumCache(const EnumDescriptor* desc, int min_val, return str_ptrs; } -const std::string& NameOfDenseEnumSlow(int v, DenseEnumCacheInfo* deci) { +PROTOBUF_NOINLINE const std::string& NameOfDenseEnumSlow( + int v, DenseEnumCacheInfo* deci) { if (v < deci->min_val || v > deci->max_val) return GetEmptyStringAlreadyInited(); @@ -2977,12 +2978,12 @@ static uint32_t AlignTo(uint32_t v) { } static internal::TailCallParseFunc GetFastParseFunction( - const std::string& name) { + absl::string_view name) { // This list must be synchronized with TcParser. // Missing entries are replaced with MiniParse in opt mode to avoid runtime // failures. It check-fails in debug mode. static const auto* const map = - new std::unordered_map{ + new absl::flat_hash_map{ {"::_pbi::TcParser::FastF32S1", internal::TcParser::FastF32S1}, {"::_pbi::TcParser::FastF32S2", internal::TcParser::FastF32S2}, {"::_pbi::TcParser::FastF32R1", internal::TcParser::FastF32R1}, @@ -3075,6 +3076,8 @@ static internal::TailCallParseFunc GetFastParseFunction( {"::_pbi::TcParser::FastMtR2", internal::TcParser::FastMtR2}, {"::_pbi::TcParser::FastGtR1", internal::TcParser::FastGtR1}, {"::_pbi::TcParser::FastGtR2", internal::TcParser::FastGtR2}, + {"::_pbi::TcParser::FastEndG1", internal::TcParser::FastEndG1}, + {"::_pbi::TcParser::FastEndG2", internal::TcParser::FastEndG2}, }; auto it = map->find(name); if (it == map->end()) { @@ -3109,8 +3112,14 @@ void Reflection::PopulateTcParseFastEntries( TcParseTableBase::FastFieldEntry* fast_entries) const { for (const auto& fast_field : table_info.fast_path_fields) { if (fast_field.field == nullptr) { - // No fast entry here. Use mini parser. - *fast_entries++ = {internal::TcParser::MiniParse, {}}; + if (fast_field.func_name.empty()) { + // No fast entry here. Use mini parser. + *fast_entries++ = {internal::TcParser::MiniParse, {}}; + } else { + // No field, but still a special entry. + *fast_entries++ = {GetFastParseFunction(fast_field.func_name), + {fast_field.coded_tag, fast_field.nonfield_info}}; + } } else if (fast_field.func_name.find("TcParser::FastEv") != fast_field.func_name.npos) { // We can't use fast parsing for these entries because we can't specify @@ -3624,4 +3633,4 @@ bool IsDescendant(Message& root, const Message& message) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index a674135627..3a6e93cb2c 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -40,17 +40,17 @@ #include -#include +#include "google/protobuf/stubs/common.h" #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_enum_reflection.h" +#include "google/protobuf/port.h" +#include "google/protobuf/unknown_field_set.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -402,6 +402,6 @@ const std::string& NameOfDenseEnum(int v) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ diff --git a/src/google/protobuf/generated_message_reflection_unittest.cc b/src/google/protobuf/generated_message_reflection_unittest.cc index 2ef2734162..75ba3f644d 100644 --- a/src/google/protobuf/generated_message_reflection_unittest.cc +++ b/src/google/protobuf/generated_message_reflection_unittest.cc @@ -42,25 +42,25 @@ // compiler/cpp/unittest, except using the reflection interface // rather than generated accessors. -#include +#include "google/protobuf/generated_message_reflection.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_mset.pb.h" +#include "google/protobuf/unittest_mset_wire_format.pb.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/testing/googletest.h" #include -#include -#include +#include "google/protobuf/map_test_util.h" +#include "google/protobuf/test_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/generated_message_tctable_decl.h b/src/google/protobuf/generated_message_tctable_decl.h index 8959acb821..b5963a299f 100644 --- a/src/google/protobuf/generated_message_tctable_decl.h +++ b/src/google/protobuf/generated_message_tctable_decl.h @@ -41,11 +41,11 @@ #include #include -#include -#include +#include "google/protobuf/message_lite.h" +#include "google/protobuf/parse_context.h" // Must come last: -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -86,6 +86,27 @@ struct TcFieldData { uint8_t aux_idx() const { return static_cast(data >> 24); } uint16_t offset() const { return static_cast(data >> 48); } + // Constructor for special entries that do not represent a field. + // - End group: `nonfield_info` is the decoded tag. + constexpr TcFieldData(uint16_t coded_tag, uint16_t nonfield_info) + : data(uint64_t{nonfield_info} << 16 | // + uint64_t{coded_tag}) {} + + // Fields used in non-field entries + // + // Bit: + // +-----------+-------------------+ + // |63 .. 32|31 .. 0| + // +---------------+---------------+ + // : . : . : . 16|=======| [16] coded_tag() + // : . : . 32|=======| . : [16] decoded_tag() + // :---.---:---.---: . : . : [32] (unused) + // +-----------+-------------------+ + // |63 .. 32|31 .. 0| + // +---------------+---------------+ + + uint16_t decoded_tag() const { return static_cast(data >> 16); } + // Fields used in mini table parsing: // // Bit: @@ -365,6 +386,6 @@ static_assert(offsetof(TcParseTable<1>, fast_entries) == } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_DECL_H__ diff --git a/src/google/protobuf/generated_message_tctable_full.cc b/src/google/protobuf/generated_message_tctable_full.cc index 780a13afcb..f224d4c9c8 100644 --- a/src/google/protobuf/generated_message_tctable_full.cc +++ b/src/google/protobuf/generated_message_tctable_full.cc @@ -30,16 +30,16 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/extension_set.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/message.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/port.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format.h" // must be last -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/generated_message_tctable_gen.cc b/src/google/protobuf/generated_message_tctable_gen.cc index ed28bebc3c..9d6a6daae9 100644 --- a/src/google/protobuf/generated_message_tctable_gen.cc +++ b/src/google/protobuf/generated_message_tctable_gen.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/generated_message_tctable_gen.h" #include #include @@ -36,14 +36,14 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/generated_message_tctable_decl.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/wire_format.h" // Must come last: -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -245,28 +245,42 @@ bool IsFieldEligibleForFastParsing( return true; } +absl::optional GetEndGroupTag(const Descriptor* descriptor) { + auto* parent = descriptor->containing_type(); + if (parent == nullptr) return absl::nullopt; + for (int i = 0; i < parent->field_count(); ++i) { + auto* field = parent->field(i); + if (field->type() == field->TYPE_GROUP && + field->message_type() == descriptor) { + return WireFormatLite::MakeTag(field->number(), + WireFormatLite::WIRETYPE_END_GROUP); + } + } + return absl::nullopt; +} + +uint32_t RecodeTagForFastParsing(uint32_t tag) { + GOOGLE_DCHECK_LE(tag, 0x3FFF); + // Construct the varint-coded tag. If it is more than 7 bits, we need to + // shift the high bits and add a continue bit. + if (uint32_t hibits = tag & 0xFFFFFF80) { + // hi = tag & ~0x7F + // lo = tag & 0x7F + // This shifts hi to the left by 1 to the next byte and sets the + // continuation bit. + tag = tag + hibits + 128; + } + return tag; +} + std::vector SplitFastFieldsForSize( + absl::optional end_group_tag, const std::vector& field_entries, int table_size_log2, const TailCallTableInfo::OptionProvider& option_provider) { std::vector result(1 << table_size_log2); const uint32_t idx_mask = static_cast(result.size() - 1); - - for (const auto& entry : field_entries) { - if (!IsFieldEligibleForFastParsing(entry, option_provider)) { - continue; - } - - const auto* field = entry.field; - const auto options = option_provider.GetForField(field); - uint32_t tag = WireFormat::MakeTag(field); - - // Construct the varint-coded tag. If it is more than 7 bits, we need to - // shift the high bits and add a continue bit. - if (uint32_t hibits = tag & 0xFFFFFF80) { - tag = tag + hibits + 128; // tag = lobits + 2*hibits + 128 - } - + const auto tag_to_idx = [&](uint32_t tag) { // The field index is determined by the low bits of the field number, where // the table size determines the width of the mask. The largest table // supported is 32 entries. The parse loop uses these bits directly, so that @@ -277,10 +291,33 @@ std::vector SplitFastFieldsForSize( // idx (table_size_log2=5) // This means that any field number that does not fit in the lower 4 bits // will always have the top bit of its table index asserted. - const uint32_t fast_idx = (tag >> 3) & idx_mask; + return (tag >> 3) & idx_mask; + }; + + if (end_group_tag.has_value() && (*end_group_tag >> 14) == 0) { + // Fits in 1 or 2 varint bytes. + const uint32_t tag = RecodeTagForFastParsing(*end_group_tag); + const uint32_t fast_idx = tag_to_idx(tag); + + TailCallTableInfo::FastFieldInfo& info = result[fast_idx]; + info.func_name = "::_pbi::TcParser::FastEndG"; + info.func_name.append(*end_group_tag < 128 ? "1" : "2"); + info.coded_tag = tag; + info.nonfield_info = *end_group_tag; + } + + for (const auto& entry : field_entries) { + if (!IsFieldEligibleForFastParsing(entry, option_provider)) { + continue; + } + + const auto* field = entry.field; + const auto options = option_provider.GetForField(field); + const uint32_t tag = RecodeTagForFastParsing(WireFormat::MakeTag(field)); + const uint32_t fast_idx = tag_to_idx(tag); TailCallTableInfo::FastFieldInfo& info = result[fast_idx]; - if (info.field != nullptr) { + if (!info.func_name.empty()) { // This field entry is already filled. continue; } @@ -731,10 +768,11 @@ TailCallTableInfo::TailCallTableInfo( table_size_log2 = 0; // fallback value int num_fast_fields = -1; + auto end_group_tag = GetEndGroupTag(descriptor); for (int try_size_log2 : {0, 1, 2, 3, 4, 5}) { size_t try_size = 1 << try_size_log2; - auto split_fields = - SplitFastFieldsForSize(field_entries, try_size_log2, option_provider); + auto split_fields = SplitFastFieldsForSize(end_group_tag, field_entries, + try_size_log2, option_provider); GOOGLE_CHECK_EQ(split_fields.size(), try_size); int try_num_fast_fields = 0; for (const auto& info : split_fields) { @@ -752,8 +790,17 @@ TailCallTableInfo::TailCallTableInfo( // cover more fields in certain cases, but a larger table in that case // would have mostly empty entries; so, we cap the size to avoid // pathologically sparse tables. - if (try_size > ordered_fields.size()) { - break; + if (end_group_tag.has_value()) { + // If this message uses group encoding, the tables are sometimes very + // sparse because the fields in the group avoid using the same field + // numbering as the parent message (even though currently, the proto + // compiler allows the overlap, and there is no possible conflict.) + // As such, this test produces a false negative as far as whether the + // large table will be worth it. So we disable the test in this case. + } else { + if (try_size > ordered_fields.size()) { + break; + } } } @@ -776,4 +823,4 @@ TailCallTableInfo::TailCallTableInfo( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/generated_message_tctable_gen.h b/src/google/protobuf/generated_message_tctable_gen.h index cdb516808b..32e591dcaf 100644 --- a/src/google/protobuf/generated_message_tctable_gen.h +++ b/src/google/protobuf/generated_message_tctable_gen.h @@ -39,12 +39,12 @@ #include #include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/generated_message_tctable_decl.h" // Must come last: -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -81,6 +81,7 @@ struct PROTOBUF_EXPORT TailCallTableInfo { uint16_t coded_tag; uint8_t hasbit_idx; uint8_t aux_idx; + uint16_t nonfield_info; }; std::vector fast_path_fields; @@ -157,6 +158,6 @@ struct PROTOBUF_EXPORT TailCallTableInfo { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_GEN_H__ diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h index b72ea6324d..490bbff743 100644 --- a/src/google/protobuf/generated_message_tctable_impl.h +++ b/src/google/protobuf/generated_message_tctable_impl.h @@ -37,15 +37,15 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/generated_message_tctable_decl.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/wire_format_lite.h" // Must come last: -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -478,6 +478,9 @@ class PROTOBUF_EXPORT TcParser final { // parsing. static const char* MiniParse(PROTOBUF_TC_PARAM_DECL); + static const char* FastEndG1(PROTOBUF_TC_PARAM_DECL); + static const char* FastEndG2(PROTOBUF_TC_PARAM_DECL); + private: friend class GeneratedTcTableLiteTest; static void* MaybeGetSplitBase(MessageLite* msg, const bool is_split, @@ -489,6 +492,9 @@ class PROTOBUF_EXPORT TcParser final { template static inline const char* RepeatedParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL); + template + static const char* FastEndGroupImpl(PROTOBUF_TC_PARAM_DECL); + static inline PROTOBUF_ALWAYS_INLINE void SyncHasbits( MessageLite* msg, uint64_t hasbits, const TcParseTableBase* table) { const uint32_t has_bits_offset = table->has_bits_offset; @@ -752,6 +758,6 @@ inline PROTOBUF_ALWAYS_INLINE const char* TcParser::Error( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_IMPL_H__ diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index 04b4e4a49d..de9984c823 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -32,16 +32,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/extension_set.h" +#include "google/protobuf/generated_message_tctable_decl.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/inlined_string_field.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/wire_format_lite.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on namespace google { @@ -314,6 +314,23 @@ const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { } } +template +const char* TcParser::FastEndGroupImpl(PROTOBUF_TC_PARAM_DECL) { + if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { + PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); + } + ctx->SetLastTag(data.decoded_tag()); + ptr += sizeof(TagType); + PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS); +} + +const char* TcParser::FastEndG1(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return FastEndGroupImpl(PROTOBUF_TC_PARAM_PASS); +} +const char* TcParser::FastEndG2(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return FastEndGroupImpl(PROTOBUF_TC_PARAM_PASS); +} + namespace { // InvertPacked changes tag bits from the given wire type to length diff --git a/src/google/protobuf/generated_message_tctable_lite_test.cc b/src/google/protobuf/generated_message_tctable_lite_test.cc index 7cba5daec1..79b0d461af 100644 --- a/src/google/protobuf/generated_message_tctable_lite_test.cc +++ b/src/google/protobuf/generated_message_tctable_lite_test.cc @@ -30,8 +30,8 @@ #include -#include -#include +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/wire_format_lite.h" #include #include @@ -80,7 +80,7 @@ TEST(IsEntryForFieldNumTest, Matcher) { }}; // clang-format on int table_field_numbers[] = {1, 2, 3}; - table.field_lookup_table = {65535, 65535}; + table.field_lookup_table = {{65535, 65535}}; auto& entries = table.field_entries; EXPECT_THAT(&entries[0], IsEntryForFieldNum(&table, 1, table_field_numbers)); diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index cad12a3511..f9c75c64d0 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/generated_message_util.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/wire_format_lite.h" // Must be included last -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -406,4 +406,4 @@ MessageLite* GetOwnedMessageInternal(Arena* message_arena, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 3a1a6732cd..42c7db790f 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -46,21 +46,21 @@ #include #include -#include +#include "google/protobuf/stubs/common.h" #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/any.h" +#include "google/protobuf/has_bits.h" +#include "google/protobuf/implicit_weak_message.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/port.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/wire_format_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -247,6 +247,6 @@ inline void OnShutdownDestroyString(const std::string* ptr) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ diff --git a/src/google/protobuf/has_bits.h b/src/google/protobuf/has_bits.h index f8a45879f1..b90c450059 100644 --- a/src/google/protobuf/has_bits.h +++ b/src/google/protobuf/has_bits.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_HAS_BITS_H__ #define GOOGLE_PROTOBUF_HAS_BITS_H__ -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -112,6 +112,6 @@ inline bool HasBits::empty() const { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_HAS_BITS_H__ diff --git a/src/google/protobuf/implicit_weak_message.cc b/src/google/protobuf/implicit_weak_message.cc index 27ed6b65d2..5fac836d0a 100644 --- a/src/google/protobuf/implicit_weak_message.cc +++ b/src/google/protobuf/implicit_weak_message.cc @@ -28,14 +28,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/implicit_weak_message.h" -#include -#include -#include +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/wire_format_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -69,4 +69,4 @@ const ImplicitWeakMessage* ImplicitWeakMessage::default_instance() { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 1cdf216948..1915e8cbad 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -33,17 +33,17 @@ #include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/repeated_field.h" #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" // This file is logically internal-only and should only be used by protobuf // generated code. @@ -209,6 +209,6 @@ struct WeakRepeatedPtrField { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__ diff --git a/src/google/protobuf/inlined_string_field.cc b/src/google/protobuf/inlined_string_field.cc index 0c3e4766fd..34b73d2672 100644 --- a/src/google/protobuf/inlined_string_field.cc +++ b/src/google/protobuf/inlined_string_field.cc @@ -28,16 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/inlined_string_field.h" + +#include "google/protobuf/arena.h" +#include "absl/strings/internal/resize_uninitialized.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/parse_context.h" -#include -#include -#include -#include -#include // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on namespace google { diff --git a/src/google/protobuf/inlined_string_field.h b/src/google/protobuf/inlined_string_field.h index 1c391b39a6..fe52a4d43a 100644 --- a/src/google/protobuf/inlined_string_field.h +++ b/src/google/protobuf/inlined_string_field.h @@ -34,15 +34,15 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/port.h" #include "absl/strings/string_view.h" -#include -#include +#include "google/protobuf/arenastring.h" +#include "google/protobuf/message_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -527,6 +527,6 @@ inline std::string* InlinedStringField::MutableNoCopy(std::nullptr_t) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__ diff --git a/src/google/protobuf/inlined_string_field_unittest.cc b/src/google/protobuf/inlined_string_field_unittest.cc index ed5f81a257..53552df1ca 100644 --- a/src/google/protobuf/inlined_string_field_unittest.cc +++ b/src/google/protobuf/inlined_string_field_unittest.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/inlined_string_field.h" #include #include @@ -38,14 +38,14 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/arenastring.h" #include #include "absl/strings/string_view.h" -#include +#include "google/protobuf/message.h" namespace google { diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel index 3c2b659dc3..f53c612918 100644 --- a/src/google/protobuf/io/BUILD.bazel +++ b/src/google/protobuf/io/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") +load("//build_defs:cpp_opts.bzl", "COPTS") package( default_visibility = ["//visibility:public"], @@ -28,6 +28,7 @@ cc_library( ":io_win32", "//src/google/protobuf:arena", "//src/google/protobuf/stubs:lite", + "@com_google_absl//absl/strings:internal", ], ) @@ -39,7 +40,6 @@ cc_library( strip_include_prefix = "/src", deps = [ ":io", - "//src/google/protobuf", "//src/google/protobuf/stubs", ], ) @@ -63,8 +63,17 @@ cc_library( copts = COPTS, include_prefix = "google/protobuf/io", deps = [ - ":io", + ":zero_copy_sink", "//src/google/protobuf/stubs", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/cleanup", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/functional:function_ref", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:optional", + "@com_google_absl//absl/types:span", + "@com_google_absl//absl/types:variant", ], ) @@ -118,6 +127,7 @@ cc_test( name = "io_test", srcs = [ "coded_stream_unittest.cc", + "printer_death_test.cc", "printer_unittest.cc", "tokenizer_unittest.cc", "zero_copy_stream_unittest.cc", @@ -132,6 +142,8 @@ cc_test( "//:protobuf", "//src/google/protobuf:test_util2", "//src/google/protobuf/testing", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc index 487e1b8a37..b29fccf8fc 100644 --- a/src/google/protobuf/io/coded_stream.cc +++ b/src/google/protobuf/io/coded_stream.cc @@ -38,7 +38,7 @@ // will not cross the end of the buffer, since we can avoid a lot // of branching in this case. -#include +#include "google/protobuf/io/coded_stream.h" #include @@ -46,16 +46,18 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "absl/strings/internal/resize_uninitialized.h" +#include "absl/strings/string_view.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -260,7 +262,7 @@ bool CodedInputStream::ReadString(std::string* buffer, int size) { if (size < 0) return false; // security: size is often user-supplied if (BufferSize() >= size) { - STLStringResizeUninitialized(buffer, size); + absl::strings_internal::STLStringResizeUninitialized(buffer, size); std::pair z = as_string_data(buffer); if (z.second) { // Oddly enough, memcpy() requires its first two args to be non-NULL even @@ -964,4 +966,4 @@ uint8_t* CodedOutputStream::WriteVarint32ToArrayOutOfLineHelper(uint32_t value, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 2b1a1da1f1..d849a1be30 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -127,15 +127,15 @@ #endif -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "absl/numeric/bits.h" #include "absl/strings/string_view.h" -#include -#include +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1729,15 +1729,16 @@ inline size_t CodedOutputStream::VarintSize32(uint32_t value) { // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1 // Use an explicit multiplication to implement the divide of // a number in the 1..31 range. - // Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is - // undefined. - uint32_t log2value = Bits::Log2FloorNonZero(value | 0x1); + // + // Explicit OR 0x1 to avoid calling absl::bit_width(0), which is + // requires a branch to check for on many platforms. + uint32_t log2value = absl::bit_width(value | 0x1) - 1; return static_cast((log2value * 9 + 73) / 64); } inline size_t CodedOutputStream::VarintSize32PlusOne(uint32_t value) { // Same as above, but one more. - uint32_t log2value = Bits::Log2FloorNonZero(value | 0x1); + uint32_t log2value = absl::bit_width(value | 0x1) - 1; return static_cast((log2value * 9 + 73 + 64) / 64); } @@ -1745,15 +1746,16 @@ inline size_t CodedOutputStream::VarintSize64(uint64_t value) { // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1 // Use an explicit multiplication to implement the divide of // a number in the 1..63 range. - // Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is - // undefined. - uint32_t log2value = Bits::Log2FloorNonZero64(value | 0x1); + // + // Explicit OR 0x1 to avoid calling absl::bit_width(0), which is + // requires a branch to check for on many platforms. + uint32_t log2value = absl::bit_width(value | 0x1) - 1; return static_cast((log2value * 9 + 73) / 64); } inline size_t CodedOutputStream::VarintSize64PlusOne(uint64_t value) { // Same as above, but one more. - uint32_t log2value = Bits::Log2FloorNonZero64(value | 0x1); + uint32_t log2value = absl::bit_width(value | 0x1) - 1; return static_cast((log2value * 9 + 73 + 64) / 64); } @@ -1794,6 +1796,6 @@ inline uint8_t* CodedOutputStream::WriteStringToArray(const std::string& str, #pragma runtime_checks("c", restore) #endif // _MSC_VER && !defined(__INTEL_COMPILER) -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ diff --git a/src/google/protobuf/io/coded_stream_unittest.cc b/src/google/protobuf/io/coded_stream_unittest.cc index 5838f1b572..1fca15c49c 100644 --- a/src/google/protobuf/io/coded_stream_unittest.cc +++ b/src/google/protobuf/io/coded_stream_unittest.cc @@ -34,7 +34,7 @@ // // This file contains tests and benchmarks. -#include +#include "google/protobuf/io/coded_stream.h" #include @@ -43,19 +43,19 @@ #include #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" #include #include "absl/base/casts.h" -#include +#include "google/protobuf/stubs/logging.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/io/zero_copy_stream_impl.h" -#include +#include "google/protobuf/testing/googletest.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -136,7 +136,7 @@ class CodedStreamTest : public testing::Test { static uint8_t buffer_[kBufferSize]; }; -uint8_t CodedStreamTest::buffer_[CodedStreamTest::kBufferSize]; +uint8_t CodedStreamTest::buffer_[CodedStreamTest::kBufferSize] = {}; // We test each operation over a variety of block sizes to insure that // we test cases where reads or writes cross buffer boundaries, cases @@ -727,7 +727,7 @@ TEST_1D(CodedStreamTest, ReadStringImpossiblyLarge, kBlockSizes) { TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnStack) { // Same test as above, except directly use a buffer. This used to cause // crashes while the above did not. - uint8_t buffer[8]; + uint8_t buffer[8] = {}; CodedInputStream coded_input(buffer, 8); std::string str; EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30)); @@ -1318,7 +1318,7 @@ class ReallyBigInputStream : public ZeroCopyInputStream { int backup_amount_; private: - char buffer_[1024]; + char buffer_[1024] = {}; int64_t buffer_count_; }; @@ -1347,4 +1347,4 @@ TEST_F(CodedStreamTest, InputOver2G) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/io/gzip_stream.cc b/src/google/protobuf/io/gzip_stream.cc index a5284b3e12..d9d44a0adf 100644 --- a/src/google/protobuf/io/gzip_stream.cc +++ b/src/google/protobuf/io/gzip_stream.cc @@ -35,11 +35,11 @@ #if HAVE_ZLIB -#include -#include +#include "google/protobuf/io/gzip_stream.h" +#include "google/protobuf/port.h" -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/io/gzip_stream.h b/src/google/protobuf/io/gzip_stream.h index 8c121109c3..c7ef1327a2 100644 --- a/src/google/protobuf/io/gzip_stream.h +++ b/src/google/protobuf/io/gzip_stream.h @@ -43,13 +43,13 @@ #ifndef GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ #define GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/port.h" #include "zlib.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -199,6 +199,6 @@ class PROTOBUF_EXPORT GzipOutputStream PROTOBUF_FUTURE_FINAL } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ diff --git a/src/google/protobuf/io/io_win32.cc b/src/google/protobuf/io/io_win32.cc index 4e81908809..684c56743c 100644 --- a/src/google/protobuf/io/io_win32.cc +++ b/src/google/protobuf/io/io_win32.cc @@ -49,7 +49,7 @@ // debug failing tests if that's caused by the long path support. #define SUPPORT_LONGPATHS -#include +#include "google/protobuf/io/io_win32.h" #include #include diff --git a/src/google/protobuf/io/io_win32.h b/src/google/protobuf/io/io_win32.h index a72b4ea3cf..370bcaaee4 100644 --- a/src/google/protobuf/io/io_win32.h +++ b/src/google/protobuf/io/io_win32.h @@ -52,10 +52,10 @@ #include #include -#include +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" // Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the // following functions already, except for mkdir. @@ -134,7 +134,7 @@ PROTOBUF_EXPORT bool wcs_to_utf8(const wchar_t* input, std::string* out); #define STDOUT_FILENO 1 #endif -#include +#include "google/protobuf/port_undef.inc" #endif // defined(_WIN32) diff --git a/src/google/protobuf/io/io_win32_unittest.cc b/src/google/protobuf/io/io_win32_unittest.cc index e8f378fcac..d4e50b83a4 100644 --- a/src/google/protobuf/io/io_win32_unittest.cc +++ b/src/google/protobuf/io/io_win32_unittest.cc @@ -40,7 +40,7 @@ #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN -#include +#include "google/protobuf/io/io_win32.h" #include #include diff --git a/src/google/protobuf/io/printer.cc b/src/google/protobuf/io/printer.cc index 47bd00b50a..0b8e053ea2 100644 --- a/src/google/protobuf/io/printer.cc +++ b/src/google/protobuf/io/printer.cc @@ -32,195 +32,229 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include - -#include - -#include -#include -#include +#include "google/protobuf/io/printer.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "absl/strings/ascii.h" +#include "absl/strings/escaping.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/strings/str_cat.h" +#include "google/protobuf/stubs/stringprintf.h" +#include "absl/strings/string_view.h" +#include "absl/strings/strip.h" +#include "absl/types/optional.h" +#include "absl/types/span.h" +#include "absl/types/variant.h" namespace google { namespace protobuf { namespace io { +namespace { +// Returns the number of spaces stripped. +size_t ConsumeInitialRawStringIndent(absl::string_view& format) { + size_t len = 0; + // We are processing a call that looks like + // + // p->Emit(R"cc( + // class Foo { + // int x, y, z; + // }; + // )cc"); + // + // We need to discard all leading newlines, then consume all spaces until + // we reach a non-space; this run of spaces is stripped off at the start of + // each line. + + while (absl::ConsumePrefix(&format, "\n")) { + } -Printer::Printer(ZeroCopyOutputStream* output, char variable_delimiter) - : variable_delimiter_(variable_delimiter), - output_(output), - buffer_(NULL), - buffer_size_(0), - offset_(0), - at_start_of_line_(true), - failed_(false), - annotation_collector_(NULL) {} - -Printer::Printer(ZeroCopyOutputStream* output, char variable_delimiter, - AnnotationCollector* annotation_collector) - : variable_delimiter_(variable_delimiter), - output_(output), - buffer_(NULL), - buffer_size_(0), - offset_(0), - at_start_of_line_(true), - failed_(false), - annotation_collector_(annotation_collector) {} - -Printer::~Printer() { - // Only BackUp() if we invoked Next() at least once, and we have never failed. - // Note that we always call `Backup`, i.e. we call BackUp(0) as some output - // streams have buffered output, and BackUp() serves as a flush event in such - // implementations. - if (buffer_ != nullptr && !failed_) { - output_->BackUp(buffer_size_); + while (absl::ConsumePrefix(&format, " ")) { + ++len; } + + return len; } -bool Printer::GetSubstitutionRange(const char* varname, - std::pair* range) { - std::map >::const_iterator iter = - substitutions_.find(varname); - if (iter == substitutions_.end()) { - GOOGLE_LOG(DFATAL) << " Undefined variable in annotation: " << varname; - return false; +// Returns the amount of additional indenting past `raw_string_indent_len`. +size_t ConsumeIndentForLine(size_t raw_string_indent_len, + absl::string_view& format) { + size_t total_indent = 0; + while (absl::ConsumePrefix(&format, " ")) { + ++total_indent; } - if (iter->second.first > iter->second.second) { - GOOGLE_LOG(DFATAL) << " Variable used for annotation used multiple times: " - << varname; - return false; + if (total_indent < raw_string_indent_len) { + total_indent = 0; + } else { + total_indent -= raw_string_indent_len; } - *range = iter->second; - return true; + return total_indent; } -void Printer::Annotate(const char* begin_varname, const char* end_varname, - const std::string& file_path, - const std::vector& path) { - if (annotation_collector_ == NULL) { - // Can't generate signatures with this Printer. - return; +template +absl::optional LookupInFrameStack( + absl::string_view var, + absl::Span(absl::string_view)>> frames) { + for (size_t i = frames.size(); i >= 1; --i) { + auto val = frames[i - 1](var); + if (val.has_value()) { + return val; + } } - std::pair begin, end; - if (!GetSubstitutionRange(begin_varname, &begin) || - !GetSubstitutionRange(end_varname, &end)) { - return; + return absl::nullopt; +} +} // namespace + +constexpr absl::string_view Printer::kProtocCodegenTrace; + +Printer::Printer(ZeroCopyOutputStream* output, Options options) + : sink_(output), options_(options) { + if (!options_.enable_codegen_trace.has_value()) { + // Trace-by-default is threaded through via an env var, rather than a + // global, so that child processes can pick it up as well. The flag + // --enable_codegen_trace setenv()'s this in protoc's startup code. + static const bool kEnableCodegenTrace = + ::getenv(kProtocCodegenTrace.data()) != nullptr; + options_.enable_codegen_trace = kEnableCodegenTrace; } - if (begin.first > end.second) { - GOOGLE_LOG(DFATAL) << " Annotation has negative length from " << begin_varname - << " to " << end_varname; - } else { - annotation_collector_->AddAnnotation(begin.first, end.second, file_path, - path); +} + +bool Printer::Validate(bool cond, Printer::PrintOptions opts, + absl::FunctionRef message) { + if (!cond) { + if (opts.checks_are_debug_only) { + GOOGLE_LOG(DFATAL) << message(); + } else { + GOOGLE_LOG(FATAL) << message(); + } } + return cond; } -void Printer::Print(const std::map& variables, - const char* text) { - int size = strlen(text); - int pos = 0; // The number of bytes we've written so far. - substitutions_.clear(); - line_start_variables_.clear(); +bool Printer::Validate(bool cond, Printer::PrintOptions opts, + absl::string_view message) { + return Validate(cond, opts, [=] { return std::string(message); }); +} - for (int i = 0; i < size; i++) { - if (text[i] == '\n') { - // Saw newline. If there is more text, we may need to insert an indent - // here. So, write what we have so far, including the '\n'. - WriteRaw(text + pos, i - pos + 1); - pos = i + 1; +// This function is outlined to isolate the use of +// GOOGLE_CHECK into the .cc file. +void Printer::Outdent() { + PrintOptions opts; + opts.checks_are_debug_only = true; + if (!Validate(indent_ >= options_.spaces_per_indent, opts, + "Outdent() without matching Indent()")) { + return; + } + indent_ -= options_.spaces_per_indent; +} - // Setting this true will cause the next WriteRaw() to insert an indent - // first. - at_start_of_line_ = true; - line_start_variables_.clear(); +void Printer::Emit( + std::initializer_list>>> + vars, + absl::string_view format, SourceLocation loc) { + PrintOptions opts; + opts.strip_raw_string_indentation = true; + opts.loc = loc; + + absl::flat_hash_map>> + map = vars; + + var_lookups_.emplace_back([&map](absl::string_view var) -> LookupResult { + auto it = map.find(var); + if (it == map.end()) { + return absl::nullopt; + } + if (auto* str = absl::get_if(&it->second)) { + return *str; + } - } else if (text[i] == variable_delimiter_) { - // Saw the start of a variable name. + auto* f = absl::get_if>(&it->second); + GOOGLE_CHECK(f != nullptr); + return *f; + }); - // Write what we have so far. - WriteRaw(text + pos, i - pos); - pos = i + 1; + PrintImpl(format, {}, opts); - // Find closing delimiter. - const char* end = strchr(text + pos, variable_delimiter_); - if (end == NULL) { - GOOGLE_LOG(DFATAL) << " Unclosed variable name."; - end = text + pos; - } - int endpos = end - text; + var_lookups_.pop_back(); +} - std::string varname(text + pos, endpos - pos); - if (varname.empty()) { - // Two delimiters in a row reduce to a literal delimiter character. - WriteRaw(&variable_delimiter_, 1); - } else { - // Replace with the variable's value. - std::map::const_iterator iter = - variables.find(varname); - if (iter == variables.end()) { - GOOGLE_LOG(DFATAL) << " Undefined variable: " << varname; - } else { - if (at_start_of_line_ && iter->second.empty()) { - line_start_variables_.push_back(varname); - } - WriteRaw(iter->second.data(), iter->second.size()); - std::pair >::iterator, - bool> - inserted = substitutions_.insert(std::make_pair( - varname, - std::make_pair(offset_ - iter->second.size(), offset_))); - if (!inserted.second) { - // This variable was used multiple times. Make its span have - // negative length so we can detect it if it gets used in an - // annotation. - inserted.first->second = std::make_pair(1, 0); - } - } - } +absl::optional> Printer::GetSubstitutionRange( + absl::string_view varname, PrintOptions opts) { + auto it = substitutions_.find(std::string(varname)); + if (!Validate(it != substitutions_.end(), opts, [varname] { + return absl::StrCat("undefined variable in annotation: ", varname); + })) { + return absl::nullopt; + } - // Advance past this variable. - i = endpos; - pos = endpos + 1; - } + std::pair range = it->second; + if (!Validate(range.first <= range.second, opts, [varname] { + return absl::StrCat( + "variable used for annotation used multiple times: ", varname); + })) { + return absl::nullopt; } - // Write the rest. - WriteRaw(text + pos, size - pos); + return range; } -void Printer::Indent() { indent_ += " "; } - -void Printer::Outdent() { - if (indent_.empty()) { - GOOGLE_LOG(DFATAL) << " Outdent() without matching Indent()."; +void Printer::Annotate(absl::string_view begin_varname, + absl::string_view end_varname, + absl::string_view file_path, + const std::vector& path) { + if (options_.annotation_collector == nullptr) { return; } - indent_.resize(indent_.size() - 2); -} - -void Printer::PrintRaw(const std::string& data) { - WriteRaw(data.data(), data.size()); -} - -void Printer::PrintRaw(const char* data) { - if (failed_) return; - WriteRaw(data, strlen(data)); + PrintOptions opts; + opts.checks_are_debug_only = true; + auto begin = GetSubstitutionRange(begin_varname, opts); + auto end = GetSubstitutionRange(end_varname, opts); + if (!begin.has_value() || !end.has_value()) { + return; + } + if (begin->first > end->second) { + GOOGLE_LOG(DFATAL) << "annotation has negative length from " << begin_varname + << " to " << end_varname; + return; + } + options_.annotation_collector->AddAnnotation(begin->first, end->second, + std::string(file_path), path); } -void Printer::WriteRaw(const char* data, int size) { - if (failed_) return; - if (size == 0) return; +void Printer::WriteRaw(const char* data, size_t size) { + if (failed_ || size == 0) { + return; + } - if (at_start_of_line_ && (size > 0) && (data[0] != '\n')) { + if (at_start_of_line_ && data[0] != '\n') { // Insert an indent. at_start_of_line_ = false; - CopyToBuffer(indent_.data(), indent_.size()); - if (failed_) return; + for (size_t i = 0; i < indent_; ++i) { + sink_.Write(" "); + } + + if (failed_) { + return; + } + // Fix up empty variables (e.g., "{") that should be annotated as // coming after the indent. - for (std::vector::iterator i = line_start_variables_.begin(); - i != line_start_variables_.end(); ++i) { - substitutions_[*i].first += indent_.size(); - substitutions_[*i].second += indent_.size(); + for (const std::string& var : line_start_variables_) { + substitutions_[var].first += indent_; + substitutions_[var].second += indent_; } } @@ -229,175 +263,389 @@ void Printer::WriteRaw(const char* data, int size) { // the current line. line_start_variables_.clear(); - CopyToBuffer(data, size); -} - -bool Printer::Next() { - do { - void* void_buffer; - if (!output_->Next(&void_buffer, &buffer_size_)) { - failed_ = true; - return false; - } - buffer_ = reinterpret_cast(void_buffer); - } while (buffer_size_ == 0); - return true; + sink_.Append(data, size); + failed_ |= sink_.failed(); } -void Printer::CopyToBuffer(const char* data, int size) { - if (failed_) return; - if (size == 0) return; - - while (size > buffer_size_) { - // Data exceeds space in the buffer. Copy what we can and request a - // new buffer. - if (buffer_size_ > 0) { - memcpy(buffer_, data, buffer_size_); - offset_ += buffer_size_; - data += buffer_size_; - size -= buffer_size_; - } - void* void_buffer; - failed_ = !output_->Next(&void_buffer, &buffer_size_); - if (failed_) return; - buffer_ = reinterpret_cast(void_buffer); +void Printer::IndentIfAtStart() { + if (!at_start_of_line_) { + return; } - // Buffer is big enough to receive the data; copy it. - memcpy(buffer_, data, size); - buffer_ += size; - buffer_size_ -= size; - offset_ += size; + for (size_t i = 0; i < indent_; ++i) { + sink_.Write(" "); + } + at_start_of_line_ = false; } -void Printer::IndentIfAtStart() { - if (at_start_of_line_) { - CopyToBuffer(indent_.data(), indent_.size()); - at_start_of_line_ = false; +void Printer::PrintCodegenTrace(absl::optional loc) { + if (!options_.enable_codegen_trace.value_or(false) || !loc.has_value()) { + return; } -} -void Printer::FormatInternal(const std::vector& args, - const std::map& vars, - const char* format) { - auto save = format; - int arg_index = 0; - std::vector annotations; - while (*format) { - char c = *format++; - switch (c) { - case '$': - format = WriteVariable(args, vars, format, &arg_index, &annotations); - continue; - case '\n': - at_start_of_line_ = true; - line_start_variables_.clear(); - break; - default: - IndentIfAtStart(); - break; - } - push_back(c); + if (!at_start_of_line_) { + at_start_of_line_ = true; + line_start_variables_.clear(); + sink_.Write("\n"); } - if (arg_index != static_cast(args.size())) { - GOOGLE_LOG(FATAL) << " Unused arguments. " << save; + + PrintRaw(StringPrintf("%s @%s:%d\n", options_.comment_start, + loc->file_name(), loc->line())); + at_start_of_line_ = true; +} + +bool Printer::ValidateIndexLookupInBounds(size_t index, + size_t current_arg_index, + size_t args_len, PrintOptions opts) { + if (!Validate(index < args_len, opts, [this, index] { + return StringPrintf("annotation %c{%d%c is out of bounds", + options_.variable_delimiter, index + 1, + options_.variable_delimiter); + })) { + return false; } - if (!annotations.empty()) { - GOOGLE_LOG(FATAL) << " Annotation range is not-closed, expect $}$. " << save; + if (!Validate( + index <= current_arg_index, opts, [this, index, current_arg_index] { + return StringPrintf( + "annotation arg must be in correct order as given; expected " + "%c{%d%c but got %c{%d%c", + options_.variable_delimiter, current_arg_index + 1, + options_.variable_delimiter, options_.variable_delimiter, + index + 1, options_.variable_delimiter); + })) { + return false; } + return true; } -const char* Printer::WriteVariable( - const std::vector& args, - const std::map& vars, const char* format, - int* arg_index, std::vector* annotations) { - auto start = format; - auto end = strchr(format, '$'); - if (!end) { - GOOGLE_LOG(FATAL) << " Unclosed variable name."; - } - format = end + 1; - if (end == start) { - // "$$" is an escape for just '$' - IndentIfAtStart(); - push_back('$'); - return format; +void Printer::PrintImpl(absl::string_view format, + absl::Span args, PrintOptions opts) { + // Inside of this function, we set indentation as we print new lines from the + // format string. No matter how we exit this function, we should fix up the + // indent to what it was before we entered; a cleanup makes it easy to avoid + // this mistake. + size_t original_indent = indent_; + auto unindent = + absl::MakeCleanup([this, original_indent] { indent_ = original_indent; }); + + absl::string_view original = format; + + line_start_variables_.clear(); + + if (opts.use_substitution_map) { + substitutions_.clear(); } - if (*start == '{') { - GOOGLE_CHECK(std::isdigit(start[1])); - GOOGLE_CHECK_EQ(end - start, 2); - int idx = start[1] - '1'; - if (idx < 0 || static_cast(idx) >= args.size()) { - GOOGLE_LOG(FATAL) << "Annotation ${" << idx + 1 << "$ is out of bounds."; + + size_t raw_string_indent_len = opts.strip_raw_string_indentation + ? ConsumeInitialRawStringIndent(format) + : 0; + + PrintCodegenTrace(opts.loc); + + size_t arg_index = 0; + std::vector annot_stack; + std::vector> annot_records; + while (!format.empty()) { + // Skip to the next special character. We do this so that we can delay + // printing "normal" text until we know what kind of variable substitution + // we're doing, since that may require trimming whitespace. + size_t next_special = 0; + for (; next_special < format.size(); ++next_special) { + if (format[next_special] == options_.variable_delimiter || + format[next_special] == '\n') { + break; + } } - if (idx > *arg_index) { - GOOGLE_LOG(FATAL) << "Annotation arg must be in correct order as given. Expected" - << " ${" << (*arg_index) + 1 << "$ got ${" << idx + 1 << "$."; - } else if (idx == *arg_index) { - (*arg_index)++; + + absl::string_view next_chunk = format.substr(0, next_special); + format = format.substr(next_special); + + if (format.empty()) { + PrintRaw(next_chunk); + break; } - IndentIfAtStart(); - annotations->push_back({{offset_, 0}, args[idx]}); - return format; - } else if (*start == '}') { - GOOGLE_CHECK(annotations); - if (annotations->empty()) { - GOOGLE_LOG(FATAL) << "Unexpected end of annotation found."; + + char c = format.front(); + format = format.substr(1); + if (c == '\n') { + PrintRaw(next_chunk); + at_start_of_line_ = true; + line_start_variables_.clear(); + sink_.Write("\n"); + indent_ = + original_indent + ConsumeIndentForLine(raw_string_indent_len, format); + continue; + } else if (c != options_.variable_delimiter) { + PrintRaw(next_chunk); + continue; } - auto& a = annotations->back(); - a.first.second = offset_; - if (annotation_collector_) annotation_collector_->AddAnnotationNew(a); - annotations->pop_back(); - return format; - } - auto start_var = start; - while (start_var < end && *start_var == ' ') start_var++; - if (start_var == end) { - GOOGLE_LOG(FATAL) << " Empty variable."; - } - auto end_var = end; - while (start_var < end_var && *(end_var - 1) == ' ') end_var--; - std::string var_name{ - start_var, static_cast(end_var - start_var)}; - std::string sub; - if (std::isdigit(var_name[0])) { - GOOGLE_CHECK_EQ(var_name.size(), 1U); // No need for multi-digits - int idx = var_name[0] - '1'; // Start counting at 1 - GOOGLE_CHECK_GE(idx, 0); - if (static_cast(idx) >= args.size()) { - GOOGLE_LOG(FATAL) << "Argument $" << idx + 1 << "$ is out of bounds."; + + size_t end = format.find(options_.variable_delimiter); + if (!Validate(end != absl::string_view::npos, opts, [format] { + return absl::StrCat("unclosed variable name: \"", + absl::CHexEscape(format), "\""); + })) { + PrintRaw(next_chunk); + WriteRaw(&options_.variable_delimiter, 1); + PrintRaw(format); + break; } - if (idx > *arg_index) { - GOOGLE_LOG(FATAL) << "Arguments must be used in same order as given. Expected $" - << (*arg_index) + 1 << "$ got $" << idx + 1 << "$."; - } else if (idx == *arg_index) { - (*arg_index)++; + + absl::string_view match = format.substr(0, end); + absl::string_view var = match; + format = format.substr(end + 1); + + if (var.empty()) { + // `$$` is an escape for just `$`. + PrintRaw(next_chunk); + WriteRaw(&options_.variable_delimiter, 1); + continue; } - sub = args[idx]; - } else { - auto it = vars.find(var_name); - if (it == vars.end()) { - GOOGLE_LOG(FATAL) << " Unknown variable: " << var_name << "."; + + if (opts.use_curly_brace_substitutions && absl::ConsumePrefix(&var, "{")) { + PrintRaw(next_chunk); + + if (!Validate(var.size() == 1u, opts, "expected single-digit variable")) { + continue; + } + + if (!Validate(absl::ascii_isdigit(var[0]), opts, + "expected digit after {")) { + continue; + } + + size_t idx = var[0] - '1'; + if (!ValidateIndexLookupInBounds(idx, arg_index, args.size(), opts)) { + continue; + } + + if (idx == arg_index) { + ++arg_index; + } + + IndentIfAtStart(); + annot_stack.push_back({{sink_.bytes_written(), 0}, args[idx]}); + continue; + } else if (opts.use_curly_brace_substitutions && + absl::ConsumePrefix(&var, "}")) { + PrintRaw(next_chunk); + + // The rest of var is actually ignored, and this is apparently + // public API now. Oops? + if (!Validate(!annot_stack.empty(), opts, + "unexpected end of annotation")) { + continue; + } + + annot_stack.back().first.second = sink_.bytes_written(); + if (options_.annotation_collector != nullptr) { + options_.annotation_collector->AddAnnotationNew(annot_stack.back()); + } + IndentIfAtStart(); + annot_stack.pop_back(); + continue; } - sub = it->second; - } - // By returning here in case of empty we also skip possible spaces inside - // the $...$, i.e. "void$ dllexpor$ f();" -> "void f();" in the empty case. - if (sub.empty()) return format; + absl::string_view prefix, suffix; + if (opts.strip_spaces_around_vars) { + var = absl::StripLeadingAsciiWhitespace(var); + prefix = match.substr(0, match.size() - var.size()); + var = absl::StripTrailingAsciiWhitespace(var); + suffix = match.substr(prefix.size() + var.size()); + } - // We're going to write something non-empty so we need a possible indent. - IndentIfAtStart(); + if (!Validate(!var.empty(), opts, "unexpected empty variable")) { + PrintRaw(next_chunk); + continue; + } - // Write the possible spaces in front. - CopyToBuffer(start, start_var - start); - // Write a non-empty substituted variable. - CopyToBuffer(sub.c_str(), sub.size()); - // Finish off with writing possible trailing spaces. - CopyToBuffer(end_var, end - end_var); - return format; -} + LookupResult sub; + absl::optional same_name_record; + if (opts.allow_digit_substitions && absl::ascii_isdigit(var[0])) { + PrintRaw(next_chunk); + + if (!Validate(var.size() == 1u, opts, "expected single-digit variable")) { + continue; + } + + size_t idx = var[0] - '1'; + if (!ValidateIndexLookupInBounds(idx, arg_index, args.size(), opts)) { + continue; + } + if (idx == arg_index) { + ++arg_index; + } + sub = args[idx]; + } else if (opts.use_annotation_frames && + (var == "_start" || var == "_end")) { + bool is_start = var == "_start"; + + size_t next_delim = format.find('$'); + if (!Validate(next_delim != absl::string_view::npos, opts, + "$_start$ must be followed by a name and another $")) { + PrintRaw(next_chunk); + continue; + } + + auto var = format.substr(0, next_delim); + format = format.substr(next_delim + 1); + + if (is_start) { + PrintRaw(next_chunk); + IndentIfAtStart(); + annot_records.push_back({var, sink_.bytes_written()}); + // Skip all whitespace immediately after a _start. + while (!format.empty() && absl::ascii_isspace(format.front())) { + format = format.substr(1); + } + } else { + // Skip all whitespace immediately *before* an _end. + while (!next_chunk.empty() && absl::ascii_isspace(next_chunk.back())) { + next_chunk = next_chunk.substr(0, next_chunk.size() - 1); + } + PrintRaw(next_chunk); + + // If a line consisted *only* of an _end, this will likely result in + // a blank line if we do not zap the newline after it, and any + // indentation beyond that. + if (at_start_of_line_) { + absl::ConsumePrefix(&format, "\n"); + indent_ = original_indent + + ConsumeIndentForLine(raw_string_indent_len, format); + } + + auto record_var = annot_records.back(); + annot_records.pop_back(); + + if (!Validate(record_var.first == var, opts, [record_var, var] { + return StringPrintf( + "_start and _end variables must match, but got %s and %s, " + "respectively", + record_var.first, var); + })) { + continue; + } + + absl::optional record = + LookupInFrameStack(var, absl::MakeSpan(annotation_lookups_)); + + if (!Validate(record.has_value(), opts, [var] { + return absl::StrCat("undefined variable: \"", + absl::CHexEscape(var), "\""); + })) { + continue; + } + + if (options_.annotation_collector != nullptr) { + options_.annotation_collector->AddAnnotation( + record_var.second, sink_.bytes_written(), record->file_path, + record->path); + } + } + continue; + } else { + PrintRaw(next_chunk); + sub = LookupInFrameStack(var, absl::MakeSpan(var_lookups_)); + + if (opts.use_annotation_frames) { + same_name_record = + LookupInFrameStack(var, absl::MakeSpan(annotation_lookups_)); + } + } + + // By returning here in case of empty we also skip possible spaces inside + // the $...$, i.e. "void$ dllexpor$ f();" -> "void f();" in the empty case. + if (!Validate(sub.has_value(), opts, [var] { + return absl::StrCat("undefined variable: \"", absl::CHexEscape(var), + "\""); + })) { + continue; + } + + size_t range_start = sink_.bytes_written(); + size_t range_end = sink_.bytes_written(); + + if (auto* str = absl::get_if(&*sub)) { + if (at_start_of_line_ && str->empty()) { + line_start_variables_.emplace_back(var); + } + + if (!str->empty()) { + // If `sub` is empty, we do not print the spaces around it. + PrintRaw(prefix); + PrintRaw(*str); + range_end = sink_.bytes_written(); + range_start = range_end - str->size(); + PrintRaw(suffix); + } + } else { + auto* fnc = absl::get_if>(&*sub); + GOOGLE_CHECK(fnc != nullptr); + + Validate( + prefix.empty() && suffix.empty(), opts, + "substitution that resolves to callback cannot contain whitespace"); + + IndentIfAtStart(); + range_start = sink_.bytes_written(); + (*fnc)(); + range_end = sink_.bytes_written(); + + // If we just evaluated a closure, and we are at the start of a line, that + // means it finished with a newline. If a newline follows immediately + // after, we drop it. This helps callback formatting "work as expected" + // with respect to forms like + // + // class Foo { + // $methods$; + // }; + // + // Without this line, this would turn into something like + // + // class Foo { + // void Bar() {} + // + // }; + // + // in many cases. We *also* do this if a ; follows the substitution, + // because this helps clang-format keep its head on in many cases. + // Users that need to keep the semi can write $foo$/**/; + absl::ConsumePrefix(&format, ";"); + absl::ConsumePrefix(&format, "\n"); + indent_ = + original_indent + ConsumeIndentForLine(raw_string_indent_len, format); + } + + if (same_name_record.has_value() && + options_.annotation_collector != nullptr) { + options_.annotation_collector->AddAnnotation(range_start, range_end, + same_name_record->file_path, + same_name_record->path); + } + + if (opts.use_substitution_map) { + auto insertion = substitutions_.emplace( + std::string(var), std::make_pair(range_start, range_end)); + + if (!insertion.second) { + // This variable was used multiple times. + // Make its span have negative length so + // we can detect it if it gets used in an + // annotation. + insertion.first->second = {1, 0}; + } + } + } + + Validate(arg_index == args.size(), opts, + [original] { return absl::StrCat("unused args: ", original); }); + Validate(annot_stack.empty(), opts, [this, original] { + return StringPrintf( + "annotation range was not closed; expected %c}%c: %s", + options_.variable_delimiter, options_.variable_delimiter, original); + }); +} } // namespace io } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/io/printer.h b/src/google/protobuf/io/printer.h index c48018a956..3c096a48d2 100644 --- a/src/google/protobuf/io/printer.h +++ b/src/google/protobuf/io/printer.h @@ -37,26 +37,40 @@ #ifndef GOOGLE_PROTOBUF_IO_PRINTER_H__ #define GOOGLE_PROTOBUF_IO_PRINTER_H__ +#include +#include +#include #include #include +#include +#include #include -#include +#include "absl/cleanup/cleanup.h" +#include "absl/container/flat_hash_map.h" +#include "absl/functional/function_ref.h" +#include "google/protobuf/stubs/stringprintf.h" +#include "absl/strings/string_view.h" +#include "absl/types/optional.h" +#include "absl/types/variant.h" +#include "google/protobuf/io/zero_copy_sink.h" +#include "google/protobuf/port.h" + // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { namespace io { - -class ZeroCopyOutputStream; // zero_copy_stream.h - // Records annotations about a Printer's output. class PROTOBUF_EXPORT AnnotationCollector { public: - // Annotation is a offset range and a payload pair. - typedef std::pair, std::string> Annotation; + // Annotation is a offset range and a payload pair. This payload's layout is + // specific to derived types of AnnotationCollector. + using Annotation = std::pair, std::string>; + + virtual ~AnnotationCollector() = default; // Records that the bytes in file_path beginning with begin_offset and ending // before end_offset are associated with the SourceCodeInfo-style path. @@ -66,28 +80,29 @@ class PROTOBUF_EXPORT AnnotationCollector { // TODO(gerbens) I don't see why we need virtuals here. Just a vector of // range, payload pairs stored in a context should suffice. - virtual void AddAnnotationNew(Annotation& /* a */) {} - - virtual ~AnnotationCollector() {} + virtual void AddAnnotationNew(Annotation&) {} }; -// Records annotations about a Printer's output to the given protocol buffer, -// assuming that the buffer has an ::Annotation message exposing path, -// source_file, begin and end fields. +// Records annotations about a Printer's output to a Protobuf message, +// assuming that it has a repeated submessage field named `annotation` with +// fields matching +// +// message ??? { +// repeated int32 path = 1; +// optional string source_file = 2; +// optional int32 begin = 3; +// optional int32 end = 4; +// } template class AnnotationProtoCollector : public AnnotationCollector { public: - // annotation_proto is the protocol buffer to which new Annotations should be - // added. It is not owned by the AnnotationProtoCollector. explicit AnnotationProtoCollector(AnnotationProto* annotation_proto) : annotation_proto_(annotation_proto) {} - // Override for AnnotationCollector::AddAnnotation. void AddAnnotation(size_t begin_offset, size_t end_offset, const std::string& file_path, const std::vector& path) override { - typename AnnotationProto::Annotation* annotation = - annotation_proto_->add_annotation(); + auto* annotation = annotation_proto_->add_annotation(); for (int i = 0; i < path.size(); ++i) { annotation->add_path(path[i]); } @@ -95,7 +110,7 @@ class AnnotationProtoCollector : public AnnotationCollector { annotation->set_begin(begin_offset); annotation->set_end(end_offset); } - // Override for AnnotationCollector::AddAnnotation. + void AddAnnotationNew(Annotation& a) override { auto* annotation = annotation_proto_->add_annotation(); annotation->ParseFromString(a.second); @@ -104,10 +119,185 @@ class AnnotationProtoCollector : public AnnotationCollector { } private: - // The protocol buffer to which new annotations should be added. - AnnotationProto* const annotation_proto_; + AnnotationProto* annotation_proto_; }; +// A source code printer for assisting in code generation. +// +// This type implements a simple templating language for substiting variables +// into static, user-provided strings, and also tracks indentation +// automatically. +// +// The main entry-point for this type is the Emit function, which can be used +// thus: +// +// Printer p(output); +// p.Emit({{"class", my_class_name}}, R"cc( +// class $class$ { +// public: +// $class$(int x) : x_(x) {} +// private: +// int x_; +// }; +// )cc"); +// +// Substitutions are of the form $var$, which is looked up in the map passed in +// as the first argument. The variable delimiter character, $, can be chosen to +// be something convenient for the target language. For example, in PHP, which +// makes heavy use of $, it can be made into something like # instead. +// +// A literal $ can be emitted by writing $$. +// +// Substitutions may contain spaces around the name of the variable, which will +// be ignored for the purposes of looking up the variable to substitute in, but +// which will be reproduced in the output: +// +// p.Emit({{"foo", "bar"}}, "$ foo $"); +// +// emits the string " bar ". If the substituted-in variable is the empty string, +// then the surrounding spaces are *not* printed: +// +// p.Emit({{"xzy", xyz}}, "$xyz $Thing"); +// +// If xyz is "Foo", this will become "Foo Thing", but if it is "", this becomes +// "Thing", rather than " Thing". This helps minimize awkward whitespace in the +// output. +// +// If a variable is referenced in the format string that is missing, the program +// will crash. Callers must statically know that every variable reference is +// valid, and MUST NOT pass user-provided strings directly into Emit(). +// +// # Callback Substitution +// +// Instead of passing a string into Emit(), it is possible to pass in a callback +// as a variable mapping. This will take indentation into account, which allows +// factoring out parts of a formatting string while ensuring braces are +// balanced: +// +// p.Emit( +// {{"methods", [&] { +// p.Emit(R"cc( +// int Bar() { +// return 42; +// } +// )cc"); +// }}}, +// R"cc( +// class Foo { +// public: +// $methods$; +// }; +// )cc" +// ); +// +// This emits +// +// class Foo { +// public: +// int Bar() { +// return 42; +// } +// }; +// +// # Lookup Frames +// +// If many calls to Emit() use the same set of variables, they can be stored +// in a *variable lookup frame*, like so: +// +// auto vars = p.WithVars({{"class_name", my_class_name}}); +// p.Emit(R"cc( +// class $class_name$ { +// public: +// $class_name$(int x); +// // Etc. +// }; +// )cc"); +// +// WithVars() returns an RAII object that will "pop" the lookup frame on scope +// exit, ensuring that the variables remain local. There are a few different +// overloads of WithVars(); it accepts a map type, like absl::flat_hash_map, +// either by-value (which will cause the Printer to store a copy), or by +// pointer (which will cause the Printer to store a pointer, potentially +// avoiding a copy.) +// +// p.Emit(vars, "..."); is effectively syntax sugar for +// +// { auto v = p.WithVars(vars); p.Emit("..."); } +// +// NOTE: callbacks are *not* allowed with WithVars; callbacks should be local +// to a specific Emit() call. +// +// # Annotations +// +// If Printer is given an AnnotationCollector, it will use it to record which +// spans of generated code correspond to user-indicated descriptors. There are +// a few different ways of indicating when to emit annotations. +// +// The WithAnnotations() function is like WithVars(), but accepts maps with +// string keys and descriptor values. It adds an annotation variable frame and +// returns an RAII object that pops the frame. +// +// There are two different ways to annotate code. In the first, when +// substituting a variable, if there is an annotation with the same name, then +// the resulting expanded value's span will be annotated with that annotation. +// For example: +// +// auto v = p.WithVars({{"class_name", my_class_name}}); +// auto a = p.WithAnnotations({{"class_name", message_descriptor}}); +// p.Emit(R"cc( +// class $class_name$ { +// public: +// $class_name$(int x); +// // Etc. +// }; +// )cc"); +// +// The span corresponding to whatever $class_name$ expands to will be annotated +// as having come from message_descriptor. +// +// Alternatively, a range may be given explicitly: +// +// auto a = p.WithAnnotations({{"my_desc", message_descriptor}}); +// p.Emit(R"cc( +// $_start$my_desc$ +// class Foo { +// // Etc. +// }; +// $_end$my_desc$ +// )cc"); +// +// The special $_start$ and $_end$ variables indicate the start and end of an +// annotated span, which is annotated with the variable that follows. +// +// Note that whitespace after a $_start$ and before an $_end$ is not printed. +// +// +// # Indentation +// +// Printer tracks an indentation amount to add to each new line, independent +// from indentation in an Emit() call's literal. The amount of indentation to +// add is controlled by the WithIndent() function: +// +// p.Emit("class $class_name$ {"); +// { +// auto indent = p.WithIndent(); +// p.Emit(R"cc( +// public: +// $class_name$(int x); +// )cc"); +// } +// p.Emit("};"); +// +// This will automatically add one level of indentation to all code in scope of +// `indent`, which is an RAII object much like the return value of `WithVars()`. +// +// # Old API +// TODO(b/242326974): Delete this documentation. +// +// Printer supports an older-style API that is in the process of being +// re-written. The old documentation is reproduced here until all use-cases are +// handled. +// // This simple utility class assists in code generation. It basically // allows the caller to define a set of variables and then output some // text with variable substitutions. Example usage: @@ -179,28 +369,249 @@ class AnnotationProtoCollector : public AnnotationCollector { // // This code associates the span covering "call(bar,bar)" in the output with the // call_ descriptor. - class PROTOBUF_EXPORT Printer { + private: + // This type exists to work around an absl type that has not yet been + // released. + struct SourceLocation { + static SourceLocation current() { return {}; } + absl::string_view file_name() { return ""; } + int line() { return 0; } + }; + + struct AnnotationRecord { + std::vector path; + std::string file_path; + + // AnnotationRecord's constructors are *not* marked as explicit, + // specifically so that it is possible to construct a + // map by writing + // + // {{"foo", my_cool_descriptor}, {"bar", "file.proto"}} + + template < + typename String, + std::enable_if_t::value, + int> = 0> + AnnotationRecord( // NOLINT(google-explicit-constructor) + const String& file_path) + : file_path(file_path) {} + + template ::value, int> = 0> + AnnotationRecord(const Desc* desc) // NOLINT(google-explicit-constructor) + : file_path(desc->file()->name()) { + desc->GetLocationPath(&path); + } + }; + public: - // Create a printer that writes text to the given output stream. Use the - // given character as the delimiter for variables. - Printer(ZeroCopyOutputStream* output, char variable_delimiter); - - // Create a printer that writes text to the given output stream. Use the - // given character as the delimiter for variables. If annotation_collector - // is not null, Printer will provide it with annotations about code written - // to the stream. annotation_collector is not owned by Printer. + static constexpr char kDefaultVariableDelimiter = '$'; + static constexpr absl::string_view kProtocCodegenTrace = + "PROTOC_CODEGEN_TRACE"; + + // Options for controlling how the output of a Printer is formatted. + struct Options { + Options() = default; + Options(const Options&) = default; + Options(Options&&) = default; + Options(char variable_delimiter, AnnotationCollector* annotation_collector) + : variable_delimiter(variable_delimiter), + annotation_collector(annotation_collector) {} + + // The delimiter for variable substitutions, e.g. $foo$. + char variable_delimiter = kDefaultVariableDelimiter; + // An optional listener the Printer calls whenever it emits a source + // annotation; may be null. + AnnotationCollector* annotation_collector = nullptr; + // The "comment start" token for the language being generated. This is used + // to allow the Printer to emit debugging annotations in the source code + // output. + absl::string_view comment_start = "//"; + // The number of spaces that a single level of indentation adds by default; + // this is the amount that WithIndent() increases indentation by. + size_t spaces_per_indent = 2; + // Whether to emit a "codegen trace" for calls to Emit(). If true, each call + // to Emit() will print a comment indicating where in the source of the + // compiler the Emit() call occurred. + // + // If disengaged, defaults to whether or not the environment variable + // `PROTOC_CODEGEN_TRACE` is set. + absl::optional enable_codegen_trace = absl::nullopt; + }; + + // Constructs a new Printer with the default options to output to + // `output`. + explicit Printer(ZeroCopyOutputStream* output) : Printer(output, Options{}) {} + + // Constructs a new printer with the given set of options to output to + // `output`. + Printer(ZeroCopyOutputStream* output, Options options); + + // Old-style constructor. Avoid in preference to the two constructors above. + // + // Will eventually be marked as deprecated. Printer(ZeroCopyOutputStream* output, char variable_delimiter, - AnnotationCollector* annotation_collector); + AnnotationCollector* annotation_collector = nullptr) + : Printer(output, Options{variable_delimiter, annotation_collector}) {} Printer(const Printer&) = delete; Printer& operator=(const Printer&) = delete; - ~Printer(); + + // Pushes a new variable lookup frame that stores `vars` by reference. + // + // Returns an RAII object that pops the lookup frame. + template + auto WithVars(const Map* vars) { + var_lookups_.emplace_back([vars](absl::string_view var) -> LookupResult { + auto it = vars->find(std::string(var)); + if (it == vars->end()) { + return absl::nullopt; + } + return absl::string_view(it->second); + }); + return absl::MakeCleanup([this] { var_lookups_.pop_back(); }); + } + + // Pushes a new variable lookup frame that stores `vars` by value. + // + // When writing `WithVars({...})`, this is the overload that will be called, + // and it will synthesize an `absl::flat_hash_map`. + // + // Returns an RAII object that pops the lookup frame. + template , + std::enable_if_t::value, int> = 0> + auto WithVars(Map&& vars) { + var_lookups_.emplace_back([vars = std::forward(vars)]( + absl::string_view var) -> LookupResult { + auto it = vars.find(std::string(var)); + if (it == vars.end()) { + return absl::nullopt; + } + return absl::string_view(it->second); + }); + return absl::MakeCleanup([this] { var_lookups_.pop_back(); }); + } + + // Pushes a new annotation lookup frame that stores `vars` by reference. + // + // Returns an RAII object that pops the lookup frame. + template + auto WithAnnotations(const Map* vars) { + annotation_lookups_.emplace_back( + [vars](absl::string_view var) -> absl::optional { + auto it = vars->find(std::string(var)); + if (it == vars->end()) { + return absl::nullopt; + } + return AnnotationRecord(it->second); + }); + return absl::MakeCleanup([this] { annotation_lookups_.pop_back(); }); + } + + // Pushes a new variable lookup frame that stores `vars` by value. + // + // When writing `WithAnnotations({...})`, this is the overload that will be + // called, and it will synthesize an `absl::flat_hash_map`. + // + // Returns an RAII object that pops the lookup frame. + template > + auto WithAnnotations(Map&& vars) { + annotation_lookups_.emplace_back( + [vars = std::forward(vars)]( + absl::string_view var) -> absl::optional { + auto it = vars.find(std::string(var)); + if (it == vars.end()) { + return absl::nullopt; + } + return AnnotationRecord(it->second); + }); + return absl::MakeCleanup([this] { annotation_lookups_.pop_back(); }); + } + + // Increases the indentation by `indent` spaces; when nullopt, increments + // indentation by the configured default spaces_per_indentation. + // + // Returns an RAII object that removes this indentation. + auto WithIndent(absl::optional indent = absl::nullopt) { + size_t delta = indent.value_or(options_.spaces_per_indent); + indent_ += delta; + return absl::MakeCleanup([this, delta] { indent_ -= delta; }); + } + + // Emits formatted source code to the underlying output. See the class + // documentation for more details. + // + // `format` MUST be a string constant. + void Emit(absl::string_view format, + SourceLocation loc = SourceLocation::current()) { + Emit({}, format, loc); + } + + // Emits formatted source code to the underlying output, injecting + // additional variables as a lookup frame for just this call. See the class + // documentation for more details. + // + // `format` MUST be a string constant. + void Emit( + std::initializer_list< + std::pair>>> + vars, + absl::string_view format, SourceLocation loc = SourceLocation::current()); + + // Write a string directly to the underlying output, performing no formatting + // of any sort. + void PrintRaw(absl::string_view data) { WriteRaw(data.data(), data.size()); } + + // Write a string directly to the underlying output, performing no formatting + // of any sort. + void WriteRaw(const char* data, size_t size); + + // True if any write to the underlying stream failed. (We don't just + // crash in this case because this is an I/O failure, not a programming + // error.) + bool failed() const { return failed_; } + + // -- Old-style API below; to be deprecated and removed. -- + // TODO(b/242326974): Deprecate these APIs. + + template > + void Print(const Map& vars, absl::string_view text) { + PrintOptions opts; + opts.checks_are_debug_only = true; + opts.use_substitution_map = true; + opts.allow_digit_substitions = false; + + auto pop = WithVars(&vars); + PrintImpl(text, {}, opts); + } + + template + void Print(absl::string_view text, const Args&... args) { + static_assert(sizeof...(args) % 2 == 0, ""); + + // Include an extra arg, since a zero-length array is ill-formed, and + // MSVC complains. + absl::string_view vars[] = {args..., ""}; + absl::flat_hash_map map; + map.reserve(sizeof...(args) / 2); + for (size_t i = 0; i < sizeof...(args); i += 2) { + map.emplace(std::string(vars[i]), std::string(vars[i + 1])); + } + + Print(map, text); + } // Link a substitution variable emitted by the last call to Print to the // object described by descriptor. template - void Annotate(const char* varname, const SomeDescriptor* descriptor) { + void Annotate(absl::string_view varname, const SomeDescriptor* descriptor) { Annotate(varname, varname, descriptor); } @@ -209,13 +620,12 @@ class PROTOBUF_EXPORT Printer { // begins at begin_varname's value and ends after the last character of the // value substituted for end_varname. template - void Annotate(const char* begin_varname, const char* end_varname, + void Annotate(absl::string_view begin_varname, absl::string_view end_varname, const SomeDescriptor* descriptor) { - if (annotation_collector_ == NULL) { - // Annotations aren't turned on for this Printer, so don't pay the cost - // of building the location path. + if (options_.annotation_collector == nullptr) { return; } + std::vector path; descriptor->GetLocationPath(&path); Annotate(begin_varname, end_varname, descriptor->file()->name(), path); @@ -223,7 +633,7 @@ class PROTOBUF_EXPORT Printer { // Link a substitution variable emitted by the last call to Print to the file // with path file_name. - void Annotate(const char* varname, const std::string& file_name) { + void Annotate(absl::string_view varname, absl::string_view file_name) { Annotate(varname, varname, file_name); } @@ -231,152 +641,138 @@ class PROTOBUF_EXPORT Printer { // the last call to Print to the file with path file_name. The range begins // at begin_varname's value and ends after the last character of the value // substituted for end_varname. - void Annotate(const char* begin_varname, const char* end_varname, - const std::string& file_name) { - if (annotation_collector_ == NULL) { - // Annotations aren't turned on for this Printer. + void Annotate(absl::string_view begin_varname, absl::string_view end_varname, + absl::string_view file_name) { + if (options_.annotation_collector == nullptr) { return; } - std::vector empty_path; - Annotate(begin_varname, end_varname, file_name, empty_path); - } - // Print some text after applying variable substitutions. If a particular - // variable in the text is not defined, this will crash. Variables to be - // substituted are identified by their names surrounded by delimiter - // characters (as given to the constructor). The variable bindings are - // defined by the given map. - void Print(const std::map& variables, - const char* text); - - // Like the first Print(), except the substitutions are given as parameters. - template - void Print(const char* text, const Args&... args) { - std::map vars; - FillMap(&vars, args...); - Print(vars, text); + Annotate(begin_varname, end_varname, file_name, {}); } - // Indent text by two spaces. After calling Indent(), two spaces will be - // inserted at the beginning of each line of text. Indent() may be called - // multiple times to produce deeper indents. - void Indent(); + // Indent text by `options.spaces_per_indent`; undone by Outdent(). + void Indent() { indent_ += options_.spaces_per_indent; } - // Reduces the current indent level by two spaces, or crashes if the indent - // level is zero. + // Undoes a call to Indent(). void Outdent(); - // Write a string to the output buffer. - // This method does not look for newlines to add indentation. - void PrintRaw(const std::string& data); - - // Write a zero-delimited string to output buffer. - // This method does not look for newlines to add indentation. - void PrintRaw(const char* data); - - // Write some bytes to the output buffer. - // This method does not look for newlines to add indentation. - void WriteRaw(const char* data, int size); - // FormatInternal is a helper function not meant to use directly, use - // compiler::cpp::Formatter instead. This function is meant to support - // formatting text using named variables (eq. "$foo$) from a lookup map (vars) - // and variables directly supplied by arguments (eq "$1$" meaning first - // argument which is the zero index element of args). - void FormatInternal(const std::vector& args, + // compiler::cpp::Formatter instead. + void FormatInternal(absl::Span args, const std::map& vars, - const char* format); - - // True if any write to the underlying stream failed. (We don't just - // crash in this case because this is an I/O failure, not a programming - // error.) - bool failed() const { return failed_; } - - private: - // Link the output range defined by the substitution variables as emitted by - // the last call to Print to the object found at the SourceCodeInfo-style path - // in a file with path file_path. The range begins at the start of - // begin_varname's value and ends after the last character of the value - // substituted for end_varname. Note that begin_varname and end_varname - // may refer to the same variable. - void Annotate(const char* begin_varname, const char* end_varname, - const std::string& file_path, const std::vector& path); - - void FillMap(std::map* vars) {} + absl::string_view format) { + PrintOptions opts; + opts.use_curly_brace_substitutions = true; + opts.strip_spaces_around_vars = true; - template - void FillMap(std::map* vars, const std::string& key, - const std::string& value, const Args&... args) { - (*vars)[key] = value; - FillMap(vars, args...); + auto pop = WithVars(&vars); + PrintImpl(format, args, opts); } - // Copy size worth of bytes from data to buffer_. - void CopyToBuffer(const char* data, int size); - - void push_back(char c) { - if (failed_) return; - if (buffer_size_ == 0) { - if (!Next()) return; - } - *buffer_++ = c; - buffer_size_--; - offset_++; - } - - bool Next(); - - inline void IndentIfAtStart(); - const char* WriteVariable( - const std::vector& args, - const std::map& vars, const char* format, - int* arg_index, - std::vector* annotations); - - const char variable_delimiter_; - - ZeroCopyOutputStream* const output_; - char* buffer_; - int buffer_size_; - // The current position, in bytes, in the output stream. This is equivalent - // to the total number of bytes that have been written so far. This value is - // used to calculate annotation ranges in the substitutions_ map below. - size_t offset_; - - std::string indent_; - bool at_start_of_line_; - bool failed_; + private: + // Options for PrintImpl(). + struct PrintOptions { + // The callsite of the public entry-point. Only Emit() sets this. + absl::optional loc; + // If set, Validate() calls will not crash the program. + bool checks_are_debug_only = false; + // If set, the `substitutions_` map will be populated as variables are + // substituted. + bool use_substitution_map = false; + // If set, the ${1$ and $}$ forms will be substituted. These are used for + // a slightly janky annotation-insertion mechanism in FormatInternal, that + // requires that passed-in substitution variables be serialized protos. + bool use_curly_brace_substitutions = false; + // If set, the $n$ forms will be substituted, pulling from the `args` + // argument to PrintImpl(). + bool allow_digit_substitions = true; + // If set, when a variable substitution with spaces in it, such as $ var$, + // is encountered, the spaces are stripped, so that it is as if it was + // $var$. If $var$ substitutes to a non-empty string, the removed spaces are + // printed around the substituted value. + // + // See the class documentation for more information on this behavior. + bool strip_spaces_around_vars = true; + // If set, leading whitespace will be stripped from the format string to + // determine the "extraneous indentation" that is produced when the format + // string is a C++ raw string. This is used to remove leading spaces from + // a raw string that would otherwise result in erratic indentation in the + // output. + bool strip_raw_string_indentation = false; + // If set, the annotation lookup frames are searched, per the annotation + // semantics of Emit() described in the class documentation. + bool use_annotation_frames = true; + }; + + // Emit an annotation for the range defined by the given substitution + // variables, as set by the most recent call to PrintImpl() that set + // `use_substitution_map` to true. + // + // The range begins at the start of `begin_varname`'s value and ends after the + // last byte of `end_varname`'s value. + // + // `begin_varname` and `end_varname may` refer to the same variable. + void Annotate(absl::string_view begin_varname, absl::string_view end_varname, + absl::string_view file_path, const std::vector& path); + + // The core printing implementation. There are three public entry points, + // which enable different slices of functionality that are controlled by the + // `opts` argument. + void PrintImpl(absl::string_view format, absl::Span args, + PrintOptions opts); + + // This is a private function only so that it can see PrintOptions. + static bool Validate(bool cond, PrintOptions opts, + absl::FunctionRef message); + static bool Validate(bool cond, PrintOptions opts, absl::string_view message); + + // Performs calls to `Validate()` to check that `index < current_arg_index` + // and `index < args_len`, producing appropriate log lines if the checks fail, + // and crashing if necessary. + bool ValidateIndexLookupInBounds(size_t index, size_t current_arg_index, + size_t args_len, PrintOptions opts); + + // Prints indentation if `at_start_of_line_` is true. + void IndentIfAtStart(); + + // Prints a codegen trace, for the given location in the compiler's source. + void PrintCodegenTrace(absl::optional loc); + + // Returns the start and end of the value that was substituted in place of + // the variable `varname` in the last call to PrintImpl() (with + // `use_substitution_map` set), if such a variable was substituted exactly + // once. + absl::optional> GetSubstitutionRange( + absl::string_view varname, PrintOptions opts); + + google::protobuf::io::zc_sink_internal::ZeroCopyStreamByteSink sink_; + Options options_; + size_t indent_ = 0; + bool at_start_of_line_ = true; + bool failed_ = false; + + using LookupResult = + absl::optional>>; + + std::vector> var_lookups_; + + std::vector< + std::function(absl::string_view)>> + annotation_lookups_; // A map from variable name to [start, end) offsets in the output buffer. - // These refer to the offsets used for a variable after the last call to - // Print. If a variable was used more than once, the entry used in - // this map is set to a negative-length span. For singly-used variables, the - // start offset is the beginning of the substitution; the end offset is the - // last byte of the substitution plus one (such that (end - start) is the - // length of the substituted string). - std::map > substitutions_; - - // Keeps track of the keys in substitutions_ that need to be updated when + // + // This stores the data looked up by GetSubstitutionRange(). + std::map> substitutions_; + // Keeps track of the keys in `substitutions_` that need to be updated when // indents are inserted. These are keys that refer to the beginning of the // current line. std::vector line_start_variables_; - - // Returns true and sets range to the substitution range in the output for - // varname if varname was used once in the last call to Print. If varname - // was not used, or if it was used multiple times, returns false (and - // fails a debug assertion). - bool GetSubstitutionRange(const char* varname, - std::pair* range); - - // If non-null, annotation_collector_ is used to store annotations about - // generated code. - AnnotationCollector* const annotation_collector_; }; - } // namespace io } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IO_PRINTER_H__ diff --git a/src/google/protobuf/io/printer_death_test.cc b/src/google/protobuf/io/printer_death_test.cc new file mode 100644 index 0000000000..5497168124 --- /dev/null +++ b/src/google/protobuf/io/printer_death_test.cc @@ -0,0 +1,174 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Author: kenton@google.com (Kenton Varda) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. + +#include "google/protobuf/io/printer.h" + +#include +#include +#include +#include + +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.pb.h" +#include +#include "google/protobuf/testing/googletest.h" +#include +#include "absl/container/flat_hash_map.h" +#include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" + +namespace google { +namespace protobuf { +namespace io { +class PrinterTest : public testing::Test { + protected: + ZeroCopyOutputStream* output() { + GOOGLE_CHECK(stream_.has_value()); + return &*stream_; + } + absl::string_view written() { + stream_.reset(); + return out_; + } + + std::string out_; + absl::optional stream_{&out_}; +}; + +// FakeDescriptorFile defines only those members that Printer uses to write out +// annotations. +struct FakeDescriptorFile { + const std::string& name() const { return filename; } + std::string filename; +}; + +// FakeDescriptor defines only those members that Printer uses to write out +// annotations. +struct FakeDescriptor { + const FakeDescriptorFile* file() const { return &fake_file; } + void GetLocationPath(std::vector* output) const { *output = path; } + + FakeDescriptorFile fake_file; + std::vector path; +}; + +class FakeAnnotationCollector : public AnnotationCollector { + public: + ~FakeAnnotationCollector() override = default; + + void AddAnnotation(size_t begin_offset, size_t end_offset, + const std::string& file_path, + const std::vector& path) override { + } +}; + +#ifdef PROTOBUF_HAS_DEATH_TEST +TEST_F(PrinterTest, Death) { + Printer printer(output(), '$'); + + EXPECT_DEBUG_DEATH(printer.Print("$nosuchvar$"), ""); + EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), ""); + EXPECT_DEBUG_DEATH(printer.Outdent(), ""); +} + +TEST_F(PrinterTest, AnnotateMultipleUsesDeath) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + printer.Print("012$foo$4$foo$\n", "foo", "3"); + + FakeDescriptor descriptor{{"path"}, {33}}; + EXPECT_DEBUG_DEATH(printer.Annotate("foo", "foo", &descriptor), ""); +} + +TEST_F(PrinterTest, AnnotateNegativeLengthDeath) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); + + FakeDescriptor descriptor{{"path"}, {33}}; + EXPECT_DEBUG_DEATH(printer.Annotate("bar", "foo", &descriptor), ""); +} + +TEST_F(PrinterTest, AnnotateUndefinedDeath) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + printer.Print("012$foo$4$foo$\n", "foo", "3"); + + FakeDescriptor descriptor{{"path"}, {33}}; + EXPECT_DEBUG_DEATH(printer.Annotate("bar", "bar", &descriptor), ""); +} + +TEST_F(PrinterTest, FormatInternalUnusedArgs) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + + EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$1$"), ""); +} + +TEST_F(PrinterTest, FormatInternalOutOfOrderArgs) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + + EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$2$ $1$"), ""); +} + +TEST_F(PrinterTest, FormatInternalZeroArg) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + + EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$0$"), ""); +} + +TEST_F(PrinterTest, FormatInternalOutOfBounds) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + + EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$1$ $2$ $3$"), ""); +} + +TEST_F(PrinterTest, FormatInternalUnknownVar) { + FakeAnnotationCollector collector; + Printer printer(output(), '$', &collector); + + EXPECT_DEATH(printer.FormatInternal({}, {}, "$huh$"), ""); + EXPECT_DEATH(printer.FormatInternal({}, {}, "$ $"), ""); +} +#endif // PROTOBUF_HAS_DEATH_TEST +} // namespace io +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/io/printer_unittest.cc b/src/google/protobuf/io/printer_unittest.cc index 82ee5ead29..7e1ebafaef 100644 --- a/src/google/protobuf/io/printer_unittest.cc +++ b/src/google/protobuf/io/printer_unittest.cc @@ -32,530 +32,388 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/io/printer.h" +#include +#include +#include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.pb.h" +#include +#include "google/protobuf/testing/googletest.h" #include -#include +#include "absl/container/flat_hash_map.h" +#include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" namespace google { namespace protobuf { namespace io { +using ::testing::AllOf; +using ::testing::ElementsAre; +using ::testing::ExplainMatchResult; +using ::testing::Field; +using ::testing::IsEmpty; +using ::testing::MatchesRegex; + +class PrinterTest : public testing::Test { + protected: + ZeroCopyOutputStream* output() { + GOOGLE_CHECK(stream_.has_value()); + return &*stream_; + } + absl::string_view written() { + stream_.reset(); + return out_; + } -// Each test repeats over several block sizes in order to test both cases -// where particular writes cross a buffer boundary and cases where they do -// not. + std::string out_; + absl::optional stream_{&out_}; +}; -TEST(Printer, EmptyPrinter) { - char buffer[8192]; - const int block_size = 100; - ArrayOutputStream output(buffer, ABSL_ARRAYSIZE(buffer), block_size); - Printer printer(&output, '\0'); - EXPECT_TRUE(!printer.failed()); +TEST_F(PrinterTest, EmptyPrinter) { + Printer printer(output(), '\0'); + EXPECT_FALSE(printer.failed()); } -TEST(Printer, BasicPrinting) { - char buffer[8192]; - - for (int block_size = 1; block_size < 512; block_size *= 2) { - ArrayOutputStream output(buffer, sizeof(buffer), block_size); - - { - Printer printer(&output, '\0'); - - printer.Print("Hello World!"); - printer.Print(" This is the same line.\n"); - printer.Print("But this is a new one.\nAnd this is another one."); - - EXPECT_FALSE(printer.failed()); - } - - buffer[output.ByteCount()] = '\0'; +TEST_F(PrinterTest, BasicPrinting) { + { + Printer printer(output(), '\0'); - EXPECT_STREQ( - "Hello World! This is the same line.\n" - "But this is a new one.\n" - "And this is another one.", - buffer); + printer.Print("Hello World!"); + printer.Print(" This is the same line.\n"); + printer.Print("But this is a new one.\nAnd this is another one."); + EXPECT_FALSE(printer.failed()); } -} - -TEST(Printer, WriteRaw) { - char buffer[8192]; - - for (int block_size = 1; block_size < 512; block_size *= 2) { - ArrayOutputStream output(buffer, sizeof(buffer), block_size); - - { - std::string string_obj = "From an object\n"; - Printer printer(&output, '$'); - printer.WriteRaw("Hello World!", 12); - printer.PrintRaw(" This is the same line.\n"); - printer.PrintRaw("But this is a new one.\nAnd this is another one."); - printer.WriteRaw("\n", 1); - printer.PrintRaw(string_obj); - EXPECT_FALSE(printer.failed()); - } - buffer[output.ByteCount()] = '\0'; - - EXPECT_STREQ( - "Hello World! This is the same line.\n" - "But this is a new one.\n" - "And this is another one." - "\n" - "From an object\n", - buffer); - } + EXPECT_EQ(written(), + "Hello World! This is the same line.\n" + "But this is a new one.\n" + "And this is another one."); } -TEST(Printer, VariableSubstitution) { - char buffer[8192]; - - for (int block_size = 1; block_size < 512; block_size *= 2) { - ArrayOutputStream output(buffer, sizeof(buffer), block_size); - - { - Printer printer(&output, '$'); - std::map vars; +TEST_F(PrinterTest, WriteRaw) { + { + absl::string_view string_obj = "From an object\n"; + Printer printer(output(), '$'); + printer.WriteRaw("Hello World!", 12); + printer.PrintRaw(" This is the same line.\n"); + printer.PrintRaw("But this is a new one.\nAnd this is another one."); + printer.WriteRaw("\n", 1); + printer.PrintRaw(string_obj); + EXPECT_FALSE(printer.failed()); + } - vars["foo"] = "World"; - vars["bar"] = "$foo$"; - vars["abcdefg"] = "1234"; + EXPECT_EQ(written(), + "Hello World! This is the same line.\n" + "But this is a new one.\n" + "And this is another one." + "\n" + "From an object\n"); +} - printer.Print(vars, "Hello $foo$!\nbar = $bar$\n"); - printer.PrintRaw("RawBit\n"); - printer.Print(vars, "$abcdefg$\nA literal dollar sign: $$"); +TEST_F(PrinterTest, VariableSubstitution) { + { + Printer printer(output(), '$'); - vars["foo"] = "blah"; - printer.Print(vars, "\nNow foo = $foo$."); + absl::flat_hash_map vars{ + {"foo", "World"}, + {"bar", "$foo$"}, + {"abcdefg", "1234"}, + }; - EXPECT_FALSE(printer.failed()); - } + printer.Print(vars, "Hello $foo$!\nbar = $bar$\n"); + printer.PrintRaw("RawBit\n"); + printer.Print(vars, "$abcdefg$\nA literal dollar sign: $$"); - buffer[output.ByteCount()] = '\0'; + vars["foo"] = "blah"; + printer.Print(vars, "\nNow foo = $foo$."); - EXPECT_STREQ( - "Hello World!\n" - "bar = $foo$\n" - "RawBit\n" - "1234\n" - "A literal dollar sign: $\n" - "Now foo = blah.", - buffer); + EXPECT_FALSE(printer.failed()); } -} -TEST(Printer, InlineVariableSubstitution) { - char buffer[8192]; - - ArrayOutputStream output(buffer, sizeof(buffer)); + EXPECT_EQ(written(), + "Hello World!\n" + "bar = $foo$\n" + "RawBit\n" + "1234\n" + "A literal dollar sign: $\n" + "Now foo = blah."); +} +TEST_F(PrinterTest, InlineVariableSubstitution) { { - Printer printer(&output, '$'); + Printer printer(output(), '$'); printer.Print("Hello $foo$!\n", "foo", "World"); printer.PrintRaw("RawBit\n"); printer.Print("$foo$ $bar$\n", "foo", "one", "bar", "two"); EXPECT_FALSE(printer.failed()); } - buffer[output.ByteCount()] = '\0'; - - EXPECT_STREQ( - "Hello World!\n" - "RawBit\n" - "one two\n", - buffer); + EXPECT_EQ(written(), + "Hello World!\n" + "RawBit\n" + "one two\n"); } -// MockDescriptorFile defines only those members that Printer uses to write out +// FakeDescriptorFile defines only those members that Printer uses to write out // annotations. -class MockDescriptorFile { - public: - explicit MockDescriptorFile(const std::string& file) : file_(file) {} +struct FakeDescriptorFile { + const std::string& name() const { return filename; } + std::string filename; +}; - // The mock filename for this file. - const std::string& name() const { return file_; } +// FakeDescriptor defines only those members that Printer uses to write out +// annotations. +struct FakeDescriptor { + const FakeDescriptorFile* file() const { return &fake_file; } + void GetLocationPath(std::vector* output) const { *output = path; } - private: - std::string file_; + FakeDescriptorFile fake_file; + std::vector path; }; -// MockDescriptor defines only those members that Printer uses to write out -// annotations. -class MockDescriptor { +class FakeAnnotationCollector : public AnnotationCollector { public: - MockDescriptor(const std::string& file, const std::vector& path) - : file_(file), path_(path) {} + ~FakeAnnotationCollector() override = default; + + // Records that the bytes in file_path beginning with begin_offset and ending + // before end_offset are associated with the SourceCodeInfo-style path. + void AddAnnotation(size_t begin_offset, size_t end_offset, + const std::string& file_path, + const std::vector& path) override { + annotations_.emplace_back( + Record{begin_offset, end_offset, file_path, path}); + } - // The mock file in which this descriptor was defined. - const MockDescriptorFile* file() const { return &file_; } + void AddAnnotationNew(Annotation& a) override { + GeneratedCodeInfo::Annotation annotation; + annotation.ParseFromString(a.second); - private: - // Allows access to GetLocationPath. - friend class Printer; + Record r{a.first.first, a.first.second, annotation.source_file(), {}}; + for (int i : annotation.path()) { + r.path.push_back(i); + } - // Copies the pre-stored path to output. - void GetLocationPath(std::vector* output) const { *output = path_; } + annotations_.emplace_back(r); + } - MockDescriptorFile file_; - std::vector path_; + struct Record { + size_t start, end; + std::string file_path; + std::vector path; + + friend std::ostream& operator<<(std::ostream& out, const Record& record) { + return out << "Record{" << record.start << ", " << record.end << ", \"" + << record.file_path << "\", [" + << absl::StrJoin(record.path, ", ") << "]}"; + } + }; + + absl::Span Get() const { return annotations_; } + + private: + std::vector annotations_; }; -TEST(Printer, AnnotateMap) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +template +testing::Matcher Annotation(Start start, + End end, + FilePath file_path, + Path path) { + return AllOf(Field("start", &FakeAnnotationCollector::Record::start, start), + Field("end", &FakeAnnotationCollector::Record::end, end), + Field("file_path", &FakeAnnotationCollector::Record::file_path, + file_path), + Field("path", &FakeAnnotationCollector::Record::path, path)); +} + +TEST_F(PrinterTest, AnnotateMap) { + FakeAnnotationCollector collector; { - Printer printer(&output, '$', &info_collector); - std::map vars; - vars["foo"] = "3"; - vars["bar"] = "5"; + Printer printer(output(), '$', &collector); + absl::flat_hash_map vars = {{"foo", "3"}, + {"bar", "5"}}; printer.Print(vars, "012$foo$4$bar$\n"); - std::vector path_1; - path_1.push_back(33); - std::vector path_2; - path_2.push_back(11); - path_2.push_back(22); - MockDescriptor descriptor_1("path_1", path_1); - MockDescriptor descriptor_2("path_2", path_2); + + FakeDescriptor descriptor_1{{"path_1"}, {33}}; + FakeDescriptor descriptor_2{{"path_2"}, {11, 22}}; printer.Annotate("foo", "foo", &descriptor_1); printer.Annotate("bar", "bar", &descriptor_2); } - buffer[output.ByteCount()] = '\0'; - EXPECT_STREQ("012345\n", buffer); - ASSERT_EQ(2, info.annotation_size()); - const GeneratedCodeInfo::Annotation* foo = info.annotation(0).path_size() == 1 - ? &info.annotation(0) - : &info.annotation(1); - const GeneratedCodeInfo::Annotation* bar = info.annotation(0).path_size() == 1 - ? &info.annotation(1) - : &info.annotation(0); - ASSERT_EQ(1, foo->path_size()); - ASSERT_EQ(2, bar->path_size()); - EXPECT_EQ(33, foo->path(0)); - EXPECT_EQ(11, bar->path(0)); - EXPECT_EQ(22, bar->path(1)); - EXPECT_EQ("path_1", foo->source_file()); - EXPECT_EQ("path_2", bar->source_file()); - EXPECT_EQ(3, foo->begin()); - EXPECT_EQ(4, foo->end()); - EXPECT_EQ(5, bar->begin()); - EXPECT_EQ(6, bar->end()); + + EXPECT_EQ(written(), "012345\n"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(3, 4, "path_1", ElementsAre(33)), + Annotation(5, 6, "path_2", ElementsAre(11, 22)))); } -TEST(Printer, AnnotateInline) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +TEST_F(PrinterTest, AnnotateInline) { + FakeAnnotationCollector collector; { - Printer printer(&output, '$', &info_collector); + Printer printer(output(), '$', &collector); printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); - std::vector path_1; - path_1.push_back(33); - std::vector path_2; - path_2.push_back(11); - path_2.push_back(22); - MockDescriptor descriptor_1("path_1", path_1); - MockDescriptor descriptor_2("path_2", path_2); + + FakeDescriptor descriptor_1{{"path_1"}, {33}}; + FakeDescriptor descriptor_2{{"path_2"}, {11, 22}}; printer.Annotate("foo", "foo", &descriptor_1); printer.Annotate("bar", "bar", &descriptor_2); } - buffer[output.ByteCount()] = '\0'; - EXPECT_STREQ("012345\n", buffer); - ASSERT_EQ(2, info.annotation_size()); - const GeneratedCodeInfo::Annotation* foo = info.annotation(0).path_size() == 1 - ? &info.annotation(0) - : &info.annotation(1); - const GeneratedCodeInfo::Annotation* bar = info.annotation(0).path_size() == 1 - ? &info.annotation(1) - : &info.annotation(0); - ASSERT_EQ(1, foo->path_size()); - ASSERT_EQ(2, bar->path_size()); - EXPECT_EQ(33, foo->path(0)); - EXPECT_EQ(11, bar->path(0)); - EXPECT_EQ(22, bar->path(1)); - EXPECT_EQ("path_1", foo->source_file()); - EXPECT_EQ("path_2", bar->source_file()); - EXPECT_EQ(3, foo->begin()); - EXPECT_EQ(4, foo->end()); - EXPECT_EQ(5, bar->begin()); - EXPECT_EQ(6, bar->end()); + + EXPECT_EQ(written(), "012345\n"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(3, 4, "path_1", ElementsAre(33)), + Annotation(5, 6, "path_2", ElementsAre(11, 22)))); } -TEST(Printer, AnnotateRange) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +TEST_F(PrinterTest, AnnotateRange) { + FakeAnnotationCollector collector; { - Printer printer(&output, '$', &info_collector); + Printer printer(output(), '$', &collector); printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); - std::vector path; - path.push_back(33); - MockDescriptor descriptor("path", path); + + FakeDescriptor descriptor{{"path"}, {33}}; printer.Annotate("foo", "bar", &descriptor); } - buffer[output.ByteCount()] = '\0'; - EXPECT_STREQ("012345\n", buffer); - ASSERT_EQ(1, info.annotation_size()); - const GeneratedCodeInfo::Annotation* foobar = &info.annotation(0); - ASSERT_EQ(1, foobar->path_size()); - EXPECT_EQ(33, foobar->path(0)); - EXPECT_EQ("path", foobar->source_file()); - EXPECT_EQ(3, foobar->begin()); - EXPECT_EQ(6, foobar->end()); + + EXPECT_EQ(written(), "012345\n"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(3, 6, "path", ElementsAre(33)))); } -TEST(Printer, AnnotateEmptyRange) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +TEST_F(PrinterTest, AnnotateEmptyRange) { + FakeAnnotationCollector collector; { - Printer printer(&output, '$', &info_collector); + Printer printer(output(), '$', &collector); printer.Print("012$foo$4$baz$$bam$$bar$\n", "foo", "3", "bar", "5", "baz", "", "bam", ""); - std::vector path; - path.push_back(33); - MockDescriptor descriptor("path", path); + + FakeDescriptor descriptor{{"path"}, {33}}; printer.Annotate("baz", "bam", &descriptor); } - buffer[output.ByteCount()] = '\0'; - EXPECT_STREQ("012345\n", buffer); - ASSERT_EQ(1, info.annotation_size()); - const GeneratedCodeInfo::Annotation* bazbam = &info.annotation(0); - ASSERT_EQ(1, bazbam->path_size()); - EXPECT_EQ(33, bazbam->path(0)); - EXPECT_EQ("path", bazbam->source_file()); - EXPECT_EQ(5, bazbam->begin()); - EXPECT_EQ(5, bazbam->end()); + + EXPECT_EQ(written(), "012345\n"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(5, 5, "path", ElementsAre(33)))); } -TEST(Printer, AnnotateDespiteUnrelatedMultipleUses) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +TEST_F(PrinterTest, AnnotateDespiteUnrelatedMultipleUses) { + FakeAnnotationCollector collector; { - Printer printer(&output, '$', &info_collector); + Printer printer(output(), '$', &collector); printer.Print("012$foo$4$foo$$bar$\n", "foo", "3", "bar", "5"); - std::vector path; - path.push_back(33); - MockDescriptor descriptor("path", path); + + FakeDescriptor descriptor{{"path"}, {33}}; printer.Annotate("bar", "bar", &descriptor); } - buffer[output.ByteCount()] = '\0'; - EXPECT_STREQ("0123435\n", buffer); - ASSERT_EQ(1, info.annotation_size()); - const GeneratedCodeInfo::Annotation* bar = &info.annotation(0); - ASSERT_EQ(1, bar->path_size()); - EXPECT_EQ(33, bar->path(0)); - EXPECT_EQ("path", bar->source_file()); - EXPECT_EQ(6, bar->begin()); - EXPECT_EQ(7, bar->end()); + + EXPECT_EQ(written(), "0123435\n"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(6, 7, "path", ElementsAre(33)))); } -TEST(Printer, AnnotateIndent) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +TEST_F(PrinterTest, AnnotateIndent) { + FakeAnnotationCollector collector; { - Printer printer(&output, '$', &info_collector); + Printer printer(output(), '$', &collector); printer.Print("0\n"); printer.Indent(); + printer.Print("$foo$", "foo", "4"); - std::vector path; - path.push_back(44); - MockDescriptor descriptor("path", path); - printer.Annotate("foo", &descriptor); + FakeDescriptor descriptor1{{"path"}, {44}}; + printer.Annotate("foo", &descriptor1); + printer.Print(",\n"); printer.Print("$bar$", "bar", "9"); - path[0] = 99; - MockDescriptor descriptor_two("path", path); - printer.Annotate("bar", &descriptor_two); + FakeDescriptor descriptor2{{"path"}, {99}}; + printer.Annotate("bar", &descriptor2); + printer.Print("\n${$$D$$}$\n", "{", "", "}", "", "D", "d"); - path[0] = 1313; - MockDescriptor descriptor_three("path", path); - printer.Annotate("{", "}", &descriptor_three); + FakeDescriptor descriptor3{{"path"}, {1313}}; + printer.Annotate("{", "}", &descriptor3); + printer.Outdent(); printer.Print("\n"); } - buffer[output.ByteCount()] = '\0'; - EXPECT_STREQ("0\n 4,\n 9\n d\n\n", buffer); - ASSERT_EQ(3, info.annotation_size()); - const GeneratedCodeInfo::Annotation* foo = &info.annotation(0); - ASSERT_EQ(1, foo->path_size()); - EXPECT_EQ(44, foo->path(0)); - EXPECT_EQ("path", foo->source_file()); - EXPECT_EQ(4, foo->begin()); - EXPECT_EQ(5, foo->end()); - const GeneratedCodeInfo::Annotation* bar = &info.annotation(1); - ASSERT_EQ(1, bar->path_size()); - EXPECT_EQ(99, bar->path(0)); - EXPECT_EQ("path", bar->source_file()); - EXPECT_EQ(9, bar->begin()); - EXPECT_EQ(10, bar->end()); - const GeneratedCodeInfo::Annotation* braces = &info.annotation(2); - ASSERT_EQ(1, braces->path_size()); - EXPECT_EQ(1313, braces->path(0)); - EXPECT_EQ("path", braces->source_file()); - EXPECT_EQ(13, braces->begin()); - EXPECT_EQ(14, braces->end()); + + EXPECT_EQ(written(), "0\n 4,\n 9\n d\n\n"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(4, 5, "path", ElementsAre(44)), + Annotation(9, 10, "path", ElementsAre(99)), + Annotation(13, 14, "path", ElementsAre(1313)))); } -TEST(Printer, AnnotateIndentNewline) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +TEST_F(PrinterTest, AnnotateIndentNewline) { + FakeAnnotationCollector collector; { - Printer printer(&output, '$', &info_collector); + Printer printer(output(), '$', &collector); printer.Indent(); + printer.Print("$A$$N$$B$C\n", "A", "", "N", "\nz", "B", ""); - std::vector path; - path.push_back(0); - MockDescriptor descriptor("path", path); + FakeDescriptor descriptor{{"path"}, {0}}; printer.Annotate("A", "B", &descriptor); + printer.Outdent(); printer.Print("\n"); } - buffer[output.ByteCount()] = '\0'; - EXPECT_STREQ("\nz C\n\n", buffer); - ASSERT_EQ(1, info.annotation_size()); - const GeneratedCodeInfo::Annotation* ab = &info.annotation(0); - ASSERT_EQ(1, ab->path_size()); - EXPECT_EQ(0, ab->path(0)); - EXPECT_EQ("path", ab->source_file()); - EXPECT_EQ(0, ab->begin()); - EXPECT_EQ(4, ab->end()); -} - -TEST(Printer, Indenting) { - char buffer[8192]; - - for (int block_size = 1; block_size < 512; block_size *= 2) { - ArrayOutputStream output(buffer, sizeof(buffer), block_size); - - { - Printer printer(&output, '$'); - std::map vars; - - vars["newline"] = "\n"; - - printer.Print("This is not indented.\n"); - printer.Indent(); - printer.Print("This is indented\nAnd so is this\n"); - printer.Outdent(); - printer.Print("But this is not."); - printer.Indent(); - printer.Print( - " And this is still the same line.\n" - "But this is indented.\n"); - printer.PrintRaw("RawBit has indent at start\n"); - printer.PrintRaw("but not after a raw newline\n"); - printer.Print(vars, - "Note that a newline in a variable will break " - "indenting, as we see$newline$here.\n"); - printer.Indent(); - printer.Print("And this"); - printer.Outdent(); - printer.Outdent(); - printer.Print(" is double-indented\nBack to normal."); - - EXPECT_FALSE(printer.failed()); - } - - buffer[output.ByteCount()] = '\0'; - - EXPECT_STREQ( - "This is not indented.\n" - " This is indented\n" - " And so is this\n" - "But this is not. And this is still the same line.\n" - " But this is indented.\n" - " RawBit has indent at start\n" - "but not after a raw newline\n" - "Note that a newline in a variable will break indenting, as we see\n" - "here.\n" - " And this is double-indented\n" - "Back to normal.", - buffer); - } -} - -// Death tests do not work on Windows as of yet. -#ifdef PROTOBUF_HAS_DEATH_TEST -TEST(Printer, Death) { - char buffer[8192]; - - ArrayOutputStream output(buffer, sizeof(buffer)); - Printer printer(&output, '$'); + EXPECT_EQ(written(), "\nz C\n\n"); - EXPECT_DEBUG_DEATH(printer.Print("$nosuchvar$"), "Undefined variable"); - EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), "Unclosed variable name"); - EXPECT_DEBUG_DEATH(printer.Outdent(), "without matching Indent"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(0, 4, "path", ElementsAre(0)))); } -TEST(Printer, AnnotateMultipleUsesDeath) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); +TEST_F(PrinterTest, Indenting) { { - Printer printer(&output, '$', &info_collector); - printer.Print("012$foo$4$foo$\n", "foo", "3"); - std::vector path; - path.push_back(33); - MockDescriptor descriptor("path", path); - EXPECT_DEBUG_DEATH(printer.Annotate("foo", "foo", &descriptor), "multiple"); - } -} + Printer printer(output(), '$'); + absl::flat_hash_map vars = {{"newline", "\n"}}; -TEST(Printer, AnnotateNegativeLengthDeath) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); - { - Printer printer(&output, '$', &info_collector); - printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); - std::vector path; - path.push_back(33); - MockDescriptor descriptor("path", path); - EXPECT_DEBUG_DEATH(printer.Annotate("bar", "foo", &descriptor), "negative"); - } -} + printer.Print("This is not indented.\n"); + printer.Indent(); + printer.Print("This is indented\nAnd so is this\n"); + printer.Outdent(); + printer.Print("But this is not."); + printer.Indent(); + printer.Print( + " And this is still the same line.\n" + "But this is indented.\n"); + printer.PrintRaw("RawBit has indent at start\n"); + printer.PrintRaw("but not after a raw newline\n"); + printer.Print(vars, + "Note that a newline in a variable will break " + "indenting, as we see$newline$here.\n"); + printer.Indent(); + printer.Print("And this"); + printer.Outdent(); + printer.Outdent(); + printer.Print(" is double-indented\nBack to normal."); -TEST(Printer, AnnotateUndefinedDeath) { - char buffer[8192]; - ArrayOutputStream output(buffer, sizeof(buffer)); - GeneratedCodeInfo info; - AnnotationProtoCollector info_collector(&info); - { - Printer printer(&output, '$', &info_collector); - printer.Print("012$foo$4$foo$\n", "foo", "3"); - std::vector path; - path.push_back(33); - MockDescriptor descriptor("path", path); - EXPECT_DEBUG_DEATH(printer.Annotate("bar", "bar", &descriptor), - "Undefined"); + EXPECT_FALSE(printer.failed()); } -} -#endif // PROTOBUF_HAS_DEATH_TEST -TEST(Printer, WriteFailurePartial) { - char buffer[17]; + EXPECT_EQ( + written(), + "This is not indented.\n" + " This is indented\n" + " And so is this\n" + "But this is not. And this is still the same line.\n" + " But this is indented.\n" + " RawBit has indent at start\n" + "but not after a raw newline\n" + "Note that a newline in a variable will break indenting, as we see\n" + "here.\n" + " And this is double-indented\n" + "Back to normal."); +} - ArrayOutputStream output(buffer, sizeof(buffer)); +TEST_F(PrinterTest, WriteFailurePartial) { + std::string buffer(17, '\xaa'); + ArrayOutputStream output(&buffer[0], buffer.size()); Printer printer(&output, '$'); // Print 16 bytes to almost fill the buffer (should not fail). @@ -573,13 +431,12 @@ TEST(Printer, WriteFailurePartial) { EXPECT_TRUE(printer.failed()); // Buffer should contain the first 17 bytes written. - EXPECT_EQ("0123456789abcdef<", std::string(buffer, sizeof(buffer))); + EXPECT_EQ(buffer, "0123456789abcdef<"); } -TEST(Printer, WriteFailureExact) { - char buffer[16]; - - ArrayOutputStream output(buffer, sizeof(buffer)); +TEST_F(PrinterTest, WriteFailureExact) { + std::string buffer(16, '\xaa'); + ArrayOutputStream output(&buffer[0], buffer.size()); Printer printer(&output, '$'); // Print 16 bytes to fill the buffer exactly (should not fail). @@ -595,139 +452,306 @@ TEST(Printer, WriteFailureExact) { EXPECT_TRUE(printer.failed()); // Buffer should contain the first 16 bytes written. - EXPECT_EQ("0123456789abcdef", std::string(buffer, sizeof(buffer))); + EXPECT_EQ(buffer, "0123456789abcdef"); } -TEST(Printer, FormatInternal) { - std::vector args{"arg1", "arg2"}; - std::map vars{ - {"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}; - // Substitution tests +TEST_F(PrinterTest, FormatInternalDirectSub) { { - // Direct arg substitution - std::string s; - { - StringOutputStream output(&s); - Printer printer(&output, '$'); - printer.FormatInternal(args, vars, "$1$ $2$"); - } - EXPECT_EQ("arg1 arg2", s); + Printer printer(output(), '$'); + printer.FormatInternal({"arg1", "arg2"}, {}, "$1$ $2$"); } + EXPECT_EQ(written(), "arg1 arg2"); +} + +TEST_F(PrinterTest, FormatInternalSubWithSpacesLeft) { { - // Variable substitution including spaces left - std::string s; - { - StringOutputStream output(&s); - Printer printer(&output, '$'); - printer.FormatInternal({}, vars, "$foo$$ baz$$ empty$"); - } - EXPECT_EQ("bar bla", s); + Printer printer(output(), '$'); + printer.FormatInternal({}, {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, + "$foo$$ baz$$ empty$"); } + EXPECT_EQ(written(), "bar bla"); +} + +TEST_F(PrinterTest, FormatInternalSubWithSpacesRight) { { - // Variable substitution including spaces right - std::string s; - { - StringOutputStream output(&s); - Printer printer(&output, '$'); - printer.FormatInternal({}, vars, "$empty $$foo $$baz$"); - } - EXPECT_EQ("bar bla", s); + Printer printer(output(), '$'); + printer.FormatInternal({}, {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, + "$empty $$foo $$baz$"); } + EXPECT_EQ(written(), "bar bla"); +} + +TEST_F(PrinterTest, FormatInternalSubMixed) { { - // Mixed variable substitution - std::string s; - { - StringOutputStream output(&s); - Printer printer(&output, '$'); - printer.FormatInternal(args, vars, "$empty $$1$ $foo $$2$ $baz$"); - } - EXPECT_EQ("arg1 bar arg2 bla", s); + Printer printer(output(), '$'); + printer.FormatInternal({"arg1", "arg2"}, + {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, + "$empty $$1$ $foo $$2$ $baz$"); } + EXPECT_EQ(written(), "arg1 bar arg2 bla"); +} - // Indentation tests +TEST_F(PrinterTest, FormatInternalIndent) { { - // Empty lines shouldn't indent. - std::string s; - { - StringOutputStream output(&s); - Printer printer(&output, '$'); - printer.Indent(); - printer.FormatInternal(args, vars, "$empty $\n\n$1$ $foo $$2$\n$baz$"); - printer.Outdent(); - } - EXPECT_EQ("\n\n arg1 bar arg2\n bla", s); + Printer printer(output(), '$'); + printer.Indent(); + printer.FormatInternal({"arg1", "arg2"}, + {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, + "$empty $\n\n$1$ $foo $$2$\n$baz$"); + printer.Outdent(); } + EXPECT_EQ(written(), "\n\n arg1 bar arg2\n bla"); +} + +TEST_F(PrinterTest, FormatInternalAnnotations) { + FakeAnnotationCollector collector; { - // Annotations should respect indentation. - std::string s; - GeneratedCodeInfo info; - { - StringOutputStream output(&s); - AnnotationProtoCollector info_collector(&info); - Printer printer(&output, '$', &info_collector); - printer.Indent(); - GeneratedCodeInfo::Annotation annotation; - annotation.set_source_file("file.proto"); - annotation.add_path(33); - std::vector args{annotation.SerializeAsString(), "arg1", - "arg2"}; - printer.FormatInternal(args, vars, "$empty $\n\n${1$$2$$}$ $3$\n$baz$"); - printer.Outdent(); - } - EXPECT_EQ("\n\n arg1 arg2\n bla", s); - ASSERT_EQ(1, info.annotation_size()); - const GeneratedCodeInfo::Annotation* arg1 = &info.annotation(0); - ASSERT_EQ(1, arg1->path_size()); - EXPECT_EQ(33, arg1->path(0)); - EXPECT_EQ("file.proto", arg1->source_file()); - EXPECT_EQ(4, arg1->begin()); - EXPECT_EQ(8, arg1->end()); + Printer printer(output(), '$', &collector); + + printer.Indent(); + GeneratedCodeInfo::Annotation annotation; + annotation.set_source_file("file.proto"); + annotation.add_path(33); + + printer.FormatInternal({annotation.SerializeAsString(), "arg1", "arg2"}, + {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, + "$empty $\n\n${1$$2$$}$ $3$\n$baz$"); + printer.Outdent(); } -#ifdef PROTOBUF_HAS_DEATH_TEST - // Death tests in case of illegal format strings. + + EXPECT_EQ(written(), "\n\n arg1 arg2\n bla"); + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(4, 8, "file.proto", ElementsAre(33)))); +} + +TEST_F(PrinterTest, Emit) { { - // Unused arguments - std::string s; - StringOutputStream output(&s); - Printer printer(&output, '$'); - EXPECT_DEATH(printer.FormatInternal(args, vars, "$empty $$1$"), "Unused"); + Printer printer(output()); + printer.Emit(R"cc( + class Foo { + int x, y, z; + }; + )cc"); + printer.Emit(R"java( + public final class Bar { + Bar() {} + } + )java"); } + + EXPECT_EQ(written(), + "class Foo {\n" + " int x, y, z;\n" + "};\n" + "public final class Bar {\n" + " Bar() {}\n" + "}\n"); +} + +TEST_F(PrinterTest, EmitWithSubs) { { - // Wrong order arguments - std::string s; - StringOutputStream output(&s); - Printer printer(&output, '$'); - EXPECT_DEATH(printer.FormatInternal(args, vars, "$2$ $1$"), "order"); + Printer printer(output()); + printer.Emit({{"class", "Foo"}, {"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, + R"cc( + class $class$ { + int $f1$, $f2$, $f3$; + }; + )cc"); } + + EXPECT_EQ(written(), + "class Foo {\n" + " int x, y, z;\n" + "};\n"); +} + +TEST_F(PrinterTest, EmitWithVars) { { - // Zero is illegal argument - std::string s; - StringOutputStream output(&s); - Printer printer(&output, '$'); - EXPECT_DEATH(printer.FormatInternal(args, vars, "$0$"), "failed"); + Printer printer(output()); + auto v = printer.WithVars({ + {"class", "Foo"}, + {"f1", "x"}, + {"f2", "y"}, + {"f3", "z"}, + }); + printer.Emit(R"cc( + class $class$ { + int $f1$, $f2$, $f3$; + }; + )cc"); } + + EXPECT_EQ(written(), + "class Foo {\n" + " int x, y, z;\n" + "};\n"); +} + +TEST_F(PrinterTest, EmitWithSpacedVars) { { - // Argument out of bounds - std::string s; - StringOutputStream output(&s); - Printer printer(&output, '$'); - EXPECT_DEATH(printer.FormatInternal(args, vars, "$1$ $2$ $3$"), "bounds"); + Printer printer(output()); + auto v = printer.WithVars({ + {"is_final", "final"}, + {"isnt_final", ""}, + {"class", "Foo"}, + }); + printer.Emit(R"java( + public $is_final $class $class$ { + // Stuff. + } + )java"); + printer.Emit(R"java( + public $isnt_final $class $class$ { + // Stuff. + } + )java"); } + + EXPECT_EQ(written(), + "public final class Foo {\n" + " // Stuff.\n" + "}\n" + "public class Foo {\n" + " // Stuff.\n" + "}\n"); +} + +TEST_F(PrinterTest, EmitWithIndent) { { - // Unknown variable - std::string s; - StringOutputStream output(&s); - Printer printer(&output, '$'); - EXPECT_DEATH(printer.FormatInternal(args, vars, "$huh$ $1$$2$"), "Unknown"); + Printer printer(output()); + auto v = printer.WithIndent(); + printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( + class Foo { + int $f1$, $f2$, $f3$; + }; + )cc"); } + + EXPECT_EQ(written(), + " class Foo {\n" + " int x, y, z;\n" + " };\n"); +} + + +TEST_F(PrinterTest, EmitSameNameAnnotation) { + FakeAnnotationCollector collector; { - // Illegal variable - std::string s; - StringOutputStream output(&s); - Printer printer(&output, '$'); - EXPECT_DEATH(printer.FormatInternal({}, vars, "$ $"), "Empty"); + Printer printer(output(), '$', &collector); + FakeDescriptor descriptor{{"file.proto"}, {33}}; + auto v = printer.WithVars({{"class", "Foo"}}); + auto a = printer.WithAnnotations({{"class", &descriptor}}); + + printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( + class $class$ { + int $f1$, $f2$, $f3$; + }; + )cc"); } -#endif // PROTOBUF_HAS_DEATH_TEST + + EXPECT_EQ(written(), + "class Foo {\n" + " int x, y, z;\n" + "};\n"); + + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(6, 9, "file.proto", ElementsAre(33)))); +} + +TEST_F(PrinterTest, EmitSameNameAnnotationFileNameOnly) { + FakeAnnotationCollector collector; + { + Printer printer(output(), '$', &collector); + auto v = printer.WithVars({{"class", "Foo"}}); + auto a = printer.WithAnnotations({{"class", "file.proto"}}); + + printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( + class $class$ { + int $f1$, $f2$, $f3$; + }; + )cc"); + } + + EXPECT_EQ(written(), + "class Foo {\n" + " int x, y, z;\n" + "};\n"); + + EXPECT_THAT(collector.Get(), + ElementsAre(Annotation(6, 9, "file.proto", IsEmpty()))); +} + +TEST_F(PrinterTest, EmitRangeAnnotation) { + FakeAnnotationCollector collector; + { + Printer printer(output(), '$', &collector); + FakeDescriptor descriptor1{{"file1.proto"}, {33}}; + FakeDescriptor descriptor2{{"file2.proto"}, {11, 22}}; + auto v = printer.WithVars({{"class", "Foo"}}); + auto a = printer.WithAnnotations({ + {"message", &descriptor1}, + {"field", &descriptor2}, + }); + + printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( + $_start$message$ class $class$ { + $_start$field$ int $f1$, $f2$, $f3$; + $_end$field$ + }; + $_end$message$ + )cc"); + } + + EXPECT_EQ(written(), + "class Foo {\n" + " int x, y, z;\n" + "};\n"); + + EXPECT_THAT( + collector.Get(), + ElementsAre(Annotation(14, 27, "file2.proto", ElementsAre(11, 22)), + Annotation(0, 30, "file1.proto", ElementsAre(33)))); +} + +TEST_F(PrinterTest, EmitCallbacks) { + { + Printer printer(output()); + printer.Emit( + { + {"class", "Foo"}, + {"method", "bar"}, + {"methods", + [&] { + printer.Emit(R"cc( + int $method$() { return 42; } + )cc"); + }}, + {"fields", + [&] { + printer.Emit(R"cc( + int $method$_; + )cc"); + }}, + }, + R"cc( + class $class$ { + public: + $methods$; + + private: + $fields$; + }; + )cc"); + } + + EXPECT_EQ(written(), + "class Foo {\n" + " public:\n" + " int bar() { return 42; }\n" + "\n" + " private:\n" + " int bar_;\n" + "};\n"); } } // namespace io diff --git a/src/google/protobuf/io/strtod.cc b/src/google/protobuf/io/strtod.cc index 03acb5b294..61c6c2924e 100644 --- a/src/google/protobuf/io/strtod.cc +++ b/src/google/protobuf/io/strtod.cc @@ -28,17 +28,17 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/io/strtod.h" #include #include #include #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" -#include +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc index f870a752a0..7bc0820dd8 100644 --- a/src/google/protobuf/io/tokenizer.cc +++ b/src/google/protobuf/io/tokenizer.cc @@ -88,18 +88,18 @@ // I'd love to hear about other alternatives, though, as this code isn't // exactly pretty. -#include +#include "google/protobuf/io/tokenizer.h" -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/escaping.h" -#include -#include -#include -#include +#include "google/protobuf/stubs/stringprintf.h" +#include "google/protobuf/io/strtod.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/stubs/stl_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1236,4 +1236,4 @@ bool Tokenizer::IsIdentifier(const std::string& text) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/io/tokenizer.h b/src/google/protobuf/io/tokenizer.h index fcedb226db..cab1faf917 100644 --- a/src/google/protobuf/io/tokenizer.h +++ b/src/google/protobuf/io/tokenizer.h @@ -40,11 +40,12 @@ #include #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -435,6 +436,6 @@ inline void Tokenizer::ParseString(const std::string& text, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IO_TOKENIZER_H__ diff --git a/src/google/protobuf/io/tokenizer_unittest.cc b/src/google/protobuf/io/tokenizer_unittest.cc index d107145c73..40a24c8e9d 100644 --- a/src/google/protobuf/io/tokenizer_unittest.cc +++ b/src/google/protobuf/io/tokenizer_unittest.cc @@ -32,19 +32,19 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/io/tokenizer.h" #include #include #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/escaping.h" #include "absl/strings/substitute.h" -#include -#include +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/testing/googletest.h" #include namespace google { diff --git a/src/google/protobuf/io/zero_copy_sink.cc b/src/google/protobuf/io/zero_copy_sink.cc index e7809bd4ff..70456485c7 100644 --- a/src/google/protobuf/io/zero_copy_sink.cc +++ b/src/google/protobuf/io/zero_copy_sink.cc @@ -28,30 +28,38 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/io/zero_copy_sink.h" + +#include +#include namespace google { namespace protobuf { namespace io { namespace zc_sink_internal { void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) { - while (true) { - if (len <= buffer_size_) { // NOLINT - memcpy(buffer_, bytes, len); - buffer_ = static_cast(buffer_) + len; - buffer_size_ -= len; - return; - } - if (buffer_size_ > 0) { - memcpy(buffer_, bytes, buffer_size_); - bytes += buffer_size_; - len -= buffer_size_; - } - if (!stream_->Next(&buffer_, &buffer_size_)) { - // There isn't a way for ByteSink to report errors. - buffer_size_ = 0; - return; + while (!failed_ && len > 0) { + if (buffer_size_ == 0) { + int size; + if (!stream_->Next(&buffer_, &size)) { + // There isn't a way for ByteSink to report errors. + buffer_size_ = 0; + failed_ = true; + return; + } + buffer_size_ = static_cast(size); } + + auto to_write = std::min(len, buffer_size_); + memcpy(buffer_, bytes, to_write); + + buffer_ = static_cast(buffer_) + to_write; + buffer_size_ -= to_write; + + bytes += to_write; + len -= to_write; + + bytes_written_ += to_write; } } } // namespace zc_sink_internal diff --git a/src/google/protobuf/io/zero_copy_sink.h b/src/google/protobuf/io/zero_copy_sink.h index c097a8936c..4d70d39f6a 100644 --- a/src/google/protobuf/io/zero_copy_sink.h +++ b/src/google/protobuf/io/zero_copy_sink.h @@ -33,12 +33,12 @@ #include -#include -#include -#include +#include "google/protobuf/stubs/bytestream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -59,16 +59,22 @@ class PROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink { } void Append(const char* bytes, size_t len) override; + void Write(absl::string_view str) { Append(str.data(), str.size()); } + + size_t bytes_written() { return bytes_written_; } + bool failed() { return failed_; } private: io::ZeroCopyOutputStream* stream_; void* buffer_ = nullptr; - int buffer_size_ = 0; + size_t buffer_size_ = 0; + size_t bytes_written_ = 0; + bool failed_ = false; }; } // namespace zc_sink_internal } // namespace io } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_ZERO_COPY_SINK_H__ diff --git a/src/google/protobuf/io/zero_copy_sink_test.cc b/src/google/protobuf/io/zero_copy_sink_test.cc index b492ac34ae..7c69eda58d 100644 --- a/src/google/protobuf/io/zero_copy_sink_test.cc +++ b/src/google/protobuf/io/zero_copy_sink_test.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/io/zero_copy_sink.h" #include #include @@ -36,8 +36,8 @@ #include #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #include #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" diff --git a/src/google/protobuf/io/zero_copy_stream.cc b/src/google/protobuf/io/zero_copy_stream.cc index f81555e554..83b72258b8 100644 --- a/src/google/protobuf/io/zero_copy_stream.cc +++ b/src/google/protobuf/io/zero_copy_stream.cc @@ -32,10 +32,10 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/io/zero_copy_stream.h" -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/io/zero_copy_stream.h b/src/google/protobuf/io/zero_copy_stream.h index 3b85efb4a3..ad27345878 100644 --- a/src/google/protobuf/io/zero_copy_stream.h +++ b/src/google/protobuf/io/zero_copy_stream.h @@ -107,11 +107,12 @@ #ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ #define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -252,6 +253,6 @@ class PROTOBUF_EXPORT ZeroCopyOutputStream { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc index c66bc862a7..2955c7bea0 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -43,11 +43,11 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/stubs/stl_util.h" namespace google { diff --git a/src/google/protobuf/io/zero_copy_stream_impl.h b/src/google/protobuf/io/zero_copy_stream_impl.h index 645b41d0af..d5a119c3da 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.h +++ b/src/google/protobuf/io/zero_copy_stream_impl.h @@ -43,12 +43,12 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -332,6 +332,6 @@ class PROTOBUF_EXPORT ConcatenatingInputStream PROTOBUF_FUTURE_FINAL } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc index 43ee26c2fd..9becd2c392 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -32,19 +32,19 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include #include #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" #include "absl/base/casts.h" -#include +#include "absl/strings/internal/resize_uninitialized.h" // Must be included last -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -158,7 +158,7 @@ bool StringOutputStream::Next(void** data, int* size) { // Avoid integer overflow in returned '*size'. new_size = std::min(new_size, old_size + std::numeric_limits::max()); // Increase the size, also make sure that it is at least kMinimumSize. - STLStringResizeUninitialized( + absl::strings_internal::STLStringResizeUninitialized( target_, std::max(new_size, kMinimumSize + 0)); // "+ 0" works around GCC4 weirdness. diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/src/google/protobuf/io/zero_copy_stream_impl_lite.h index 557993907d..28ad9d667b 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.h +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.h @@ -49,14 +49,15 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/port.h" +#include "google/protobuf/stubs/stl_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -420,6 +421,6 @@ inline std::pair as_string_data(std::string* s) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index 181b66b393..d82354e571 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -63,20 +63,20 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #if HAVE_ZLIB -#include +#include "google/protobuf/io/gzip_stream.h" #endif -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/googletest.h" #include namespace google { @@ -1053,7 +1053,7 @@ TEST_F(IoTest, LimitingInputStream) { TEST_F(IoTest, LimitingInputStreamByteCount) { const int kHalfBufferSize = 128; const int kBufferSize = kHalfBufferSize * 2; - uint8 buffer[kBufferSize]; + uint8 buffer[kBufferSize] = {}; // Set up input. Only allow half to be read at once. ArrayInputStream array_input(buffer, kBufferSize, kHalfBufferSize); diff --git a/src/google/protobuf/lite_arena_unittest.cc b/src/google/protobuf/lite_arena_unittest.cc index d68c6c9bbe..927663d531 100644 --- a/src/google/protobuf/lite_arena_unittest.cc +++ b/src/google/protobuf/lite_arena_unittest.cc @@ -28,8 +28,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include +#include "google/protobuf/arena_test_util.h" +#include "google/protobuf/map_lite_test_util.h" #include namespace google { diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index 993f39b1f8..529e7bdc9d 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -34,22 +34,22 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/map_lite_unittest.pb.h" +#include "google/protobuf/unittest_lite.pb.h" #include -#include +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/arena_test_util.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/map_lite_test_util.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/test_util_lite.h" +#include "google/protobuf/wire_format_lite.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/map.cc b/src/google/protobuf/map.cc index d60a9a285c..1d7535d5c2 100644 --- a/src/google/protobuf/map.cc +++ b/src/google/protobuf/map.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/map.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index c78df0c70c..9f7c200cc4 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -55,11 +55,11 @@ #include #endif -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/generated_enum_util.h" +#include "google/protobuf/map_type_handler.h" +#include "google/protobuf/port.h" #ifdef SWIG @@ -67,7 +67,7 @@ #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1492,6 +1492,6 @@ class Map { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MAP_H__ diff --git a/src/google/protobuf/map_entry.h b/src/google/protobuf/map_entry.h index c42cf5050d..d220d90195 100644 --- a/src/google/protobuf/map_entry.h +++ b/src/google/protobuf/map_entry.h @@ -31,16 +31,16 @@ #ifndef GOOGLE_PROTOBUF_MAP_ENTRY_H__ #define GOOGLE_PROTOBUF_MAP_ENTRY_H__ -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/map_entry_lite.h" +#include "google/protobuf/map_type_handler.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -129,6 +129,6 @@ class MapEntry : public MapEntryImpl +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__ diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index dded1b6b27..78ed4f2508 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -37,19 +37,19 @@ #include #include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" #include "absl/base/casts.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/map.h" +#include "google/protobuf/map_type_handler.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/port.h" +#include "google/protobuf/wire_format_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -559,6 +559,6 @@ class MapSorterPtr { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__ diff --git a/src/google/protobuf/map_field.cc b/src/google/protobuf/map_field.cc index 6219d0fa34..b34010491b 100644 --- a/src/google/protobuf/map_field.cc +++ b/src/google/protobuf/map_field.cc @@ -28,15 +28,15 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/map_field.h" #include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/map_field_inl.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -653,4 +653,4 @@ size_t DynamicMapField::SpaceUsedExcludingSelfNoLock() const { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index bf3f67af51..0f1a607f3f 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -34,22 +34,22 @@ #include #include -#include -#include +#include "google/protobuf/arena.h" +#include "google/protobuf/port.h" #include "absl/synchronization/mutex.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/map_entry.h" +#include "google/protobuf/map_field_lite.h" +#include "google/protobuf/map_type_handler.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/unknown_field_set.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -943,6 +943,6 @@ class PROTOBUF_EXPORT MapIterator { #pragma warning(pop) // restore warning C4265 #endif // _MSC_VER -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MAP_FIELD_H__ diff --git a/src/google/protobuf/map_field_inl.h b/src/google/protobuf/map_field_inl.h index 379a817809..9311abdd81 100644 --- a/src/google/protobuf/map_field_inl.h +++ b/src/google/protobuf/map_field_inl.h @@ -34,13 +34,13 @@ #include #include "absl/base/casts.h" -#include -#include -#include -#include +#include "google/protobuf/map.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/map_type_handler.h" +#include "google/protobuf/port.h" // must be last -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -376,6 +376,6 @@ size_t MapField +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MAP_FIELD_INL_H__ diff --git a/src/google/protobuf/map_field_lite.h b/src/google/protobuf/map_field_lite.h index ee028efdd5..d8e539c0d3 100644 --- a/src/google/protobuf/map_field_lite.h +++ b/src/google/protobuf/map_field_lite.h @@ -33,15 +33,15 @@ #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/port.h" +#include "google/protobuf/map.h" +#include "google/protobuf/map_entry_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/wire_format_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -204,6 +204,6 @@ inline PROTOBUF_NOINLINE void MapFieldLiteNotDestructed(void* map_field_lite) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__ diff --git a/src/google/protobuf/map_field_test.cc b/src/google/protobuf/map_field_test.cc index 1659c957fd..d0116bd91b 100644 --- a/src/google/protobuf/map_field_test.cc +++ b/src/google/protobuf/map_field_test.cc @@ -32,21 +32,21 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/map.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" #include -#include -#include +#include "google/protobuf/arena_test_util.h" +#include "google/protobuf/map_test_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/map_lite_test_util.cc b/src/google/protobuf/map_lite_test_util.cc index 121f267d64..d519ba40f1 100644 --- a/src/google/protobuf/map_lite_test_util.cc +++ b/src/google/protobuf/map_lite_test_util.cc @@ -28,10 +28,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/map_lite_test_util.h" -#include -#include +#include "google/protobuf/map_lite_unittest.pb.h" +#include "google/protobuf/map_test_util_impl.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/map_lite_test_util.h b/src/google/protobuf/map_lite_test_util.h index 573de7b285..a4a1e61f16 100644 --- a/src/google/protobuf/map_lite_test_util.h +++ b/src/google/protobuf/map_lite_test_util.h @@ -31,7 +31,7 @@ #ifndef GOOGLE_PROTOBUF_MAP_LITE_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_MAP_LITE_TEST_UTIL_H__ -#include +#include "google/protobuf/map_lite_unittest.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index fd895246b5..4eee747305 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -28,10 +28,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include -#include -#include +#include "google/protobuf/map_proto2_unittest.pb.h" +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/reflection_tester.h" +#include "google/protobuf/test_util2.h" #define BRIDGE_UNITTEST ::google::protobuf::bridge_unittest @@ -41,13 +41,13 @@ // Must include after defining UNITTEST, etc. // clang-format off -#include -#include -#include +#include "google/protobuf/test_util.inc" +#include "google/protobuf/map_test_util.inc" +#include "google/protobuf/map_test.inc" // clang-format on // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -85,4 +85,4 @@ TEST(MapTest, Aligned8OnArena) { MapTest_Aligned(); } } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/map_test.inc b/src/google/protobuf/map_test.inc index 4d61c94686..baf3c82c99 100644 --- a/src/google/protobuf/map_test.inc +++ b/src/google/protobuf/map_test.inc @@ -46,36 +46,36 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/descriptor.pb.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include #include "absl/base/casts.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/arena_test_util.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor_database.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/map.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/message.h" +#include "google/protobuf/reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/util/message_differencer.h" +#include "google/protobuf/util/time_util.h" +#include "google/protobuf/wire_format.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -4161,4 +4161,4 @@ TEST(MoveTest, MoveAssignmentWorks) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/map_test_util.h b/src/google/protobuf/map_test_util.h index f3215db5cd..130e494bef 100644 --- a/src/google/protobuf/map_test_util.h +++ b/src/google/protobuf/map_test_util.h @@ -31,14 +31,14 @@ #ifndef GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__ -#include -#include +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/reflection_tester.h" #define UNITTEST ::protobuf_unittest #define BRIDGE_UNITTEST ::google::protobuf::bridge_unittest // Must be included after defining UNITTEST, etc. -#include +#include "google/protobuf/map_test_util.inc" #undef UNITTEST #undef BRIDGE_UNITTEST diff --git a/src/google/protobuf/map_test_util.inc b/src/google/protobuf/map_test_util.inc index 5b12c76968..14b781a0be 100644 --- a/src/google/protobuf/map_test_util.inc +++ b/src/google/protobuf/map_test_util.inc @@ -28,9 +28,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/map_test_util_impl.h" +#include "google/protobuf/message.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/map_test_util_impl.h b/src/google/protobuf/map_test_util_impl.h index 655aec8384..adbc3fc7e1 100644 --- a/src/google/protobuf/map_test_util_impl.h +++ b/src/google/protobuf/map_test_util_impl.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__ #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__ -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #include diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index c210c63db5..c092792346 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_MAP_TYPE_HANDLER_H__ #define GOOGLE_PROTOBUF_MAP_TYPE_HANDLER_H__ -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/wire_format_lite.h" #ifdef SWIG #error "You cannot SWIG proto headers" diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 6eaf90c278..4cad7af324 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -32,40 +32,40 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/message.h" #include #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "absl/base/casts.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/reflection_internal.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/stubs/stl_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -473,4 +473,4 @@ InternalMetadata::mutable_unknown_fields_slow(); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 3e58f41db9..fd03c6b9b9 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -116,23 +116,23 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/port.h" #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include // TODO(b/211442718): cleanup -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/generated_message_tctable_decl.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/map.h" // TODO(b/211442718): cleanup +#include "google/protobuf/message_lite.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -1568,6 +1568,6 @@ const Type& Reflection::GetRaw(const Message& message, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MESSAGE_H__ diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index f6f8a371d6..7cae7beb55 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -33,32 +33,32 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/message_lite.h" #include #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/arena.h" #include "absl/base/dynamic_annotations.h" +#include "absl/strings/internal/resize_uninitialized.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" -#include -#include -#include -#include +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/repeated_field.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -455,7 +455,8 @@ bool MessageLite::AppendPartialToString(std::string* output) const { return false; } - STLStringResizeUninitializedAmortized(output, old_size + byte_size); + absl::strings_internal::STLStringResizeUninitializedAmortized( + output, old_size + byte_size); uint8_t* start = reinterpret_cast(io::mutable_string_data(output) + old_size); SerializeToArrayImpl(*this, start, byte_size); @@ -603,4 +604,4 @@ void ShutdownProtobufLibrary() { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 87e51af1d0..f4bca9cb27 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -43,19 +43,20 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/port.h" #include "absl/base/call_once.h" #include "absl/strings/string_view.h" -#include -#include +#include "google/protobuf/explicitly_constructed.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/port.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on #ifdef SWIG @@ -586,6 +587,6 @@ T* OnShutdownDelete(T* p) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index f71f60c363..dbf84b6352 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/unittest.pb.h" #define MESSAGE_TEST_NAME MessageTest #define MESSAGE_FACTORY_TEST_NAME MessageFactoryTest @@ -42,7 +42,7 @@ // Must include after the above macros. // clang-format off -#include -#include -#include +#include "google/protobuf/test_util.inc" +#include "google/protobuf/message_unittest.inc" +#include "google/protobuf/arena.h" // clang-format on diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index c3e76c5518..1217c403ea 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -44,29 +44,29 @@ #include #include -#include +#include "google/protobuf/message.h" #ifndef _MSC_VER #include #endif #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.pb.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include -#include +#include "google/protobuf/stubs/logging.h" #include "absl/strings/substitute.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/arena.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/test_util2.h" namespace google { diff --git a/src/google/protobuf/metadata_lite.h b/src/google/protobuf/metadata_lite.h index d015dc2f9d..0700327dcd 100644 --- a/src/google/protobuf/metadata_lite.h +++ b/src/google/protobuf/metadata_lite.h @@ -32,12 +32,13 @@ #define GOOGLE_PROTOBUF_METADATA_LITE_H__ #include -#include -#include -#include + +#include "google/protobuf/arena.h" +#include "google/protobuf/port.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -327,6 +328,6 @@ class PROTOBUF_EXPORT LiteUnknownFieldSetter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_METADATA_LITE_H__ diff --git a/src/google/protobuf/no_field_presence_test.cc b/src/google/protobuf/no_field_presence_test.cc index 2582cfea8e..d28fb14f18 100644 --- a/src/google/protobuf/no_field_presence_test.cc +++ b/src/google/protobuf/no_field_presence_test.cc @@ -30,10 +30,10 @@ #include -#include -#include -#include -#include +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_no_field_presence.pb.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" #include namespace google { diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index 91e1013974..34063195c8 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc @@ -28,19 +28,19 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include - -#include -#include -#include -#include -#include -#include +#include "google/protobuf/parse_context.h" + +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/endian.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/repeated_field.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/wire_format_lite.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -308,7 +308,7 @@ void WriteLengthDelimited(uint32_t num, absl::string_view val, std::string* s) { std::pair VarintParseSlow32(const char* p, uint32_t res) { - for (std::uint32_t i = 2; i < 5; i++) { + for (std::uint32_t i = 1; i < 5; i++) { uint32_t byte = static_cast(p[i]); res += (byte - 1) << (7 * i); if (PROTOBUF_PREDICT_TRUE(byte < 128)) { @@ -328,7 +328,7 @@ std::pair VarintParseSlow32(const char* p, std::pair VarintParseSlow64(const char* p, uint32_t res32) { uint64_t res = res32; - for (std::uint32_t i = 2; i < 10; i++) { + for (std::uint32_t i = 1; i < 10; i++) { uint64_t byte = static_cast(p[i]); res += (byte - 1) << (7 * i); if (PROTOBUF_PREDICT_TRUE(byte < 128)) { @@ -542,8 +542,226 @@ const char* UnknownFieldParse(uint32_t tag, std::string* unknown, return FieldParser(tag, field_parser, ptr, ctx); } +#ifdef __aarch64__ +// Generally, speaking, the ARM-optimized Varint decode algorithm is to extract +// and concatenate all potentially valid data bits, compute the actual length +// of the Varint, and mask off the data bits which are not actually part of the +// result. More detail on the two main parts is shown below. +// +// 1) Extract and concatenate all potentially valid data bits. +// Two ARM-specific features help significantly: +// a) Efficient and non-destructive bit extraction (UBFX) +// b) A single instruction can perform both an OR with a shifted +// second operand in one cycle. E.g., the following two lines do the same +// thing +// ```result = operand_1 | (operand2 << 7);``` +// ```ORR %[result], %[operand_1], %[operand_2], LSL #7``` +// The figure below shows the implementation for handling four chunks. +// +// Bits 32 31-24 23 22-16 15 14-8 7 6-0 +// +----+---------+----+---------+----+---------+----+---------+ +// |CB 3| Chunk 3 |CB 2| Chunk 2 |CB 1| Chunk 1 |CB 0| Chunk 0 | +// +----+---------+----+---------+----+---------+----+---------+ +// | | | | +// UBFX UBFX UBFX UBFX -- cycle 1 +// | | | | +// V V V V +// Combined LSL #7 and ORR Combined LSL #7 and ORR -- cycle 2 +// | | +// V V +// Combined LSL #14 and ORR -- cycle 3 +// | +// V +// Parsed bits 0-27 +// +// +// 2) Calculate the index of the cleared continuation bit in order to determine +// where the encoded Varint ends and the size of the decoded value. The +// easiest way to do this is mask off all data bits, leaving just the +// continuation bits. We actually need to do the masking on an inverted +// copy of the data, which leaves a 1 in all continuation bits which were +// originally clear. The number of trailing zeroes in this value indicates +// the size of the Varint. +// +// AND 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 +// +// Bits 63 55 47 39 31 23 15 7 +// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ +// ~ |CB 7| |CB 6| |CB 5| |CB 4| |CB 3| |CB 2| |CB 1| |CB 0| | +// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ +// | | | | | | | | +// V V V V V V V V +// Bits 63 55 47 39 31 23 15 7 +// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ +// |~CB 7|0|~CB 6|0|~CB 5|0|~CB 4|0|~CB 3|0|~CB 2|0|~CB 1|0|~CB 0|0| +// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ +// | +// CTZ +// V +// Index of first cleared continuation bit +// +// +// While this is implemented in C++ significant care has been taken to ensure +// the compiler emits the best instruction sequence. In some cases we use the +// following two functions to manipulate the compiler's scheduling decisions. +// +// Controls compiler scheduling by telling it that the first value is modified +// by the second value the callsite. This is useful if non-critical path +// instructions are too aggressively scheduled, resulting in a slowdown of the +// actual critical path due to opportunity costs. An example usage is shown +// where a false dependence of num_bits on result is added to prevent checking +// for a very unlikely error until all critical path instructions have been +// fetched. +// +// ``` +// num_bits = +// result = +// num_bits = ValueBarrier(num_bits, result); +// if (num_bits == 63) { +// GOOGLE_LOG(FATAL) << "Invalid num_bits value"; +// } +// ``` +template +PROTOBUF_ALWAYS_INLINE inline V1Type ValueBarrier(V1Type value1, + V2Type value2) { + asm("" : "+r"(value1) : "r"(value2)); + return value1; +} + +// Falsely indicate that the specific value is modified at this location. This +// prevents code which depends on this value from being scheduled earlier. +template +PROTOBUF_ALWAYS_INLINE inline V1Type ValueBarrier(V1Type value1) { + asm("" : "+r"(value1)); + return value1; +} + +PROTOBUF_ALWAYS_INLINE inline uint64_t ExtractAndMergeTwoChunks( + uint64_t data, uint64_t first_byte) { + GOOGLE_DCHECK(first_byte <= 6); + uint64_t first = Ubfx7(data, first_byte * 8); + uint64_t second = Ubfx7(data, (first_byte + 1) * 8); + return ForceToRegister(first | (second << 7)); +} + +struct SlowPathEncodedInfo { + const char* p; + uint64_t last8; + uint64_t valid_bits; + uint64_t valid_chunk_bits; + uint64_t masked_cont_bits; +}; + +// Performs multiple actions which are identical between 32 and 64 bit Varints +// in order to compute the length of the encoded Varint and compute the new +// of p. +PROTOBUF_ALWAYS_INLINE inline SlowPathEncodedInfo ComputeLengthAndUpdateP( + const char* p) { + SlowPathEncodedInfo result; + // Load the last two bytes of the encoded Varint. + std::memcpy(&result.last8, p + 2, sizeof(result.last8)); + uint64_t mask = ForceToRegister(0x8080808080808080); + // Only set continuation bits remain + result.masked_cont_bits = ForceToRegister(mask & (~result.last8)); + // The first cleared continuation bit is the most significant 1 in the + // reversed value. Result is undefined for an input of 0 and we handle that + // case below. + result.valid_bits = absl::countr_zero(result.masked_cont_bits); + // Calculates the number of chunks in the encoded Varint. This value is low + // by three as neither the cleared continuation chunk nor the first two chunks + // are counted. + uint64_t set_continuation_bits = result.valid_bits >> 3; + // Update p to point past the encoded Varint. + result.p = p + set_continuation_bits + 3; + // Calculate number of valid data bits in the decoded value so invalid bits + // can be masked off. Value is too low by 14 but we account for that when + // calculating the mask. + result.valid_chunk_bits = result.valid_bits - set_continuation_bits; + return result; +} + +constexpr uint64_t kResultMaskUnshifted = 0xffffffffffffc000ULL; +constexpr uint64_t kFirstResultBitChunk1 = 1 * 7; +constexpr uint64_t kFirstResultBitChunk2 = 2 * 7; +constexpr uint64_t kFirstResultBitChunk3 = 3 * 7; +constexpr uint64_t kFirstResultBitChunk4 = 4 * 7; +constexpr uint64_t kFirstResultBitChunk6 = 6 * 7; +constexpr uint64_t kFirstResultBitChunk8 = 8 * 7; +constexpr uint64_t kValidBitsForInvalidVarint = 0x60; + +PROTOBUF_NOINLINE const char* VarintParseSlowArm64(const char* p, uint64_t* out, + uint64_t first8) { + SlowPathEncodedInfo info = ComputeLengthAndUpdateP(p); + // Extract data bits from the low six chunks. This includes chunks zero and + // one which we already know are valid. + uint64_t merged_01 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/0); + uint64_t merged_23 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/2); + uint64_t merged_45 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/4); + // Low 42 bits of decoded value. + uint64_t result = merged_01 | merged_23 << kFirstResultBitChunk2 | + merged_45 << kFirstResultBitChunk4; + // This immediate ends in 14 zeroes since valid_chunk_bits is too low by 14. + uint64_t result_mask = kResultMaskUnshifted << info.valid_chunk_bits; + // masked_cont_bits is 0 iff the Varint is invalid. In that case + info.valid_bits = + info.masked_cont_bits ? info.valid_bits : kValidBitsForInvalidVarint; + // Test for early exit if Varint does not exceed 6 chunks. Branching on one + // bit is faster on ARM than via a compare and branch. + if (PROTOBUF_PREDICT_FALSE((info.valid_bits & 0x20) != 0)) { + // Extract data bits from high four chunks. + uint64_t merged_67 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/6); + // Last two chunks come from last two bytes of info.last8. + uint64_t merged_89 = + ExtractAndMergeTwoChunks(info.last8, /*first_chunk=*/6); + result |= merged_67 << kFirstResultBitChunk6; + result |= merged_89 << kFirstResultBitChunk8; + // Handle an invalid Varint with all 10 continuation bits set. + info.masked_cont_bits = ValueBarrier(info.masked_cont_bits); + if (PROTOBUF_PREDICT_FALSE(info.masked_cont_bits == 0)) { + *out = 0; + return nullptr; + } + } + // Mask off invalid data bytes. + result &= ~result_mask; + *out = result; + return info.p; +} + +// See comments in VarintParseSlowArm64 for a description of the algorithm. +// Differences in the 32 bit version are noted below. +PROTOBUF_NOINLINE const char* VarintParseSlowArm32(const char* p, uint32_t* out, + uint64_t first8) { + // This also skips the slop bytes. + SlowPathEncodedInfo info = ComputeLengthAndUpdateP(p); + // Extract data bits from chunks 1-4. Chunk zero is merged in below. + uint64_t merged_12 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/1); + uint64_t merged_34 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/3); + first8 = ValueBarrier(first8, p); + uint64_t result = Ubfx7(first8, /*start=*/0); + result = ForceToRegister(result | merged_12 << kFirstResultBitChunk1); + result = ForceToRegister(result | merged_34 << kFirstResultBitChunk3); + uint64_t result_mask = kResultMaskUnshifted << info.valid_chunk_bits; + result &= ~result_mask; + // It is extremely unlikely that a Varint is invalid so checking that + // condition isn't on the critical path. Here we make sure that we don't do so + // until result has been computed. + info.masked_cont_bits = ValueBarrier(info.masked_cont_bits, result); + if (PROTOBUF_PREDICT_FALSE(info.masked_cont_bits == 0)) { + // Makes the compiler think out was modified here. This ensures it won't + // predicate this extremely predictable branch. + out = ValueBarrier(out); + *out = 0; + return nullptr; + } + *out = result; + return info.p; +} + +#endif // __aarch64__ + } // namespace internal } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 985e157e6e..3dbdf3e4ae 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -36,21 +36,23 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/arena.h" +#include "absl/strings/internal/resize_uninitialized.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/arenastring.h" +#include "google/protobuf/endian.h" +#include "google/protobuf/implicit_weak_message.h" +#include "google/protobuf/inlined_string_field.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/port.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/wire_format_lite.h" + // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { @@ -157,7 +159,13 @@ class PROTOBUF_EXPORT EpsCopyInputStream { PROTOBUF_NODISCARD const char* ReadString(const char* ptr, int size, std::string* s) { if (size <= buffer_end_ + kSlopBytes - ptr) { - s->assign(ptr, size); + // Fundamentally we just want to do assign to the string. + // However micro-benchmarks regress on string reading cases. So we copy + // the same logic from the old CodedInputStream ReadString. Note: as of + // Apr 2021, this is still a significant win over `assign()`. + absl::strings_internal::STLStringResizeUninitialized(s, size); + char* z = &(*s)[0]; + memcpy(z, ptr, size); return ptr + size; } return ReadStringFallback(ptr, size, s); @@ -565,21 +573,64 @@ inline const char* VarintParseSlow(const char* p, uint32_t res, uint64_t* out) { return tmp.first; } +#ifdef __aarch64__ +const char* VarintParseSlowArm64(const char* p, uint64_t* out, uint64_t first8); +const char* VarintParseSlowArm32(const char* p, uint32_t* out, uint64_t first8); + +inline const char* VarintParseSlowArm(const char* p, uint32_t* out, + uint64_t first8) { + return VarintParseSlowArm32(p, out, first8); +} + +inline const char* VarintParseSlowArm(const char* p, uint64_t* out, + uint64_t first8) { + return VarintParseSlowArm64(p, out, first8); +} + +// Moves data into a register and returns data. This impacts the compiler's +// scheduling and instruction selection decisions. +static PROTOBUF_ALWAYS_INLINE inline uint64_t ForceToRegister(uint64_t data) { + asm("" : "+r"(data)); + return data; +} + +// Performs a 7 bit UBFX (Unsigned Bit Extract) starting at the indicated bit. +static PROTOBUF_ALWAYS_INLINE inline uint64_t Ubfx7(uint64_t data, + uint64_t start) { + return ForceToRegister((data >> start) & 0x7f); +} + +#endif // __aarch64__ + template PROTOBUF_NODISCARD const char* VarintParse(const char* p, T* out) { +#if defined(__aarch64__) && defined(PROTOBUF_LITTLE_ENDIAN) + // This optimization is not supported in big endian mode + uint64_t first8; + std::memcpy(&first8, p, sizeof(first8)); + if (PROTOBUF_PREDICT_TRUE((first8 & 0x80) == 0)) { + *out = static_cast(first8); + return p + 1; + } + if (PROTOBUF_PREDICT_TRUE((first8 & 0x8000) == 0)) { + uint64_t chunk1; + uint64_t chunk2; + // Extracting the two chunks this way gives a speedup for this path. + chunk1 = Ubfx7(first8, 0); + chunk2 = Ubfx7(first8, 8); + *out = chunk1 | (chunk2 << 7); + return p + 2; + } + return VarintParseSlowArm(p, out, first8); +#else // __aarch64__ auto ptr = reinterpret_cast(p); uint32_t res = ptr[0]; - if (!(res & 0x80)) { + if ((res & 0x80) == 0) { *out = res; return p + 1; } - uint32_t byte = ptr[1]; - res += (byte - 1) << 7; - if (!(byte & 0x80)) { - *out = res; - return p + 2; - } return VarintParseSlow(p, res, out); +#endif // __aarch64__ } // Used for tags, could read up to 5 bytes which must be available. @@ -1066,6 +1117,6 @@ PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownFieldParse( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_PARSE_CONTEXT_H__ diff --git a/src/google/protobuf/port.h b/src/google/protobuf/port.h index 6dab2af72a..f3c6e66ecd 100644 --- a/src/google/protobuf/port.h +++ b/src/google/protobuf/port.h @@ -36,13 +36,14 @@ #ifndef GOOGLE_PROTOBUF_PORT_H__ #define GOOGLE_PROTOBUF_PORT_H__ +#include #include #include #include // must be last -#include +#include "google/protobuf/port_def.inc" namespace google { @@ -113,6 +114,6 @@ inline ToRef DownCast(From& f) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_PORT_H__ diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index b0aa0331c3..bbfc299d19 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -814,8 +814,8 @@ #endif // Tail call table-driven parsing can be enabled by defining -// PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER at compilation time. Note -// that this macro is for small-scale testing only, and is not supported. +// PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER at compilation time. +// We hope to turn on table-driven parsing by default in Q4 2022. #ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED #error PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED was previously declared #endif @@ -826,9 +826,7 @@ #ifdef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION #error PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION was previously defined #endif -#if !defined(PROTOBUF_TEMPORARY_DISABLE_TABLE_PARSER_ON_REFLECTION) && \ - (defined(PROTOBUF_EXPERIMENTAL_USE_TABLE_PARSER_ON_REFLECTION) || \ - defined(PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED)) +#if !defined(PROTOBUF_TEMPORARY_DISABLE_TABLE_PARSER_ON_REFLECTION) #define PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION 1 #endif // PROTOBUF_ENABLE_FORCE_ALLOCATION_ON_CONSTRUCTION diff --git a/src/google/protobuf/preserve_unknown_enum_test.cc b/src/google/protobuf/preserve_unknown_enum_test.cc index 7e6bbf121a..64d8247252 100644 --- a/src/google/protobuf/preserve_unknown_enum_test.cc +++ b/src/google/protobuf/preserve_unknown_enum_test.cc @@ -28,11 +28,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include -#include -#include -#include -#include +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_preserve_unknown_enum.pb.h" +#include "google/protobuf/unittest_preserve_unknown_enum2.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" #include namespace google { diff --git a/src/google/protobuf/proto3_arena_lite_unittest.cc b/src/google/protobuf/proto3_arena_lite_unittest.cc index a3fdb96415..7c37f3f8ac 100644 --- a/src/google/protobuf/proto3_arena_lite_unittest.cc +++ b/src/google/protobuf/proto3_arena_lite_unittest.cc @@ -32,8 +32,8 @@ #include #include -#include -#include +#include "google/protobuf/unittest_proto3_arena.pb.h" +#include "google/protobuf/arena.h" #include using proto3_arena_unittest::TestAllTypes; diff --git a/src/google/protobuf/proto3_arena_unittest.cc b/src/google/protobuf/proto3_arena_unittest.cc index 9538ab9c6b..175c6e99a2 100644 --- a/src/google/protobuf/proto3_arena_unittest.cc +++ b/src/google/protobuf/proto3_arena_unittest.cc @@ -32,17 +32,17 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_proto3_arena.pb.h" +#include "google/protobuf/unittest_proto3_optional.pb.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/text_format.h" #include -#include -#include +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/test_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" using proto3_arena_unittest::ForeignMessage; using proto3_arena_unittest::TestAllTypes; diff --git a/src/google/protobuf/proto3_lite_unittest.cc b/src/google/protobuf/proto3_lite_unittest.cc index abeeedb15f..e3012dbf96 100644 --- a/src/google/protobuf/proto3_lite_unittest.cc +++ b/src/google/protobuf/proto3_lite_unittest.cc @@ -28,13 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/unittest_proto3.pb.h" #define LITE_TEST_NAME Proto3LiteTest #define UNITTEST ::proto3_unittest // Must include after the above macros. -#include +#include "google/protobuf/proto3_lite_unittest.inc" // Make extract script happy. namespace google { diff --git a/src/google/protobuf/proto3_lite_unittest.inc b/src/google/protobuf/proto3_lite_unittest.inc index eb3fd7adde..a60bb687a5 100644 --- a/src/google/protobuf/proto3_lite_unittest.inc +++ b/src/google/protobuf/proto3_lite_unittest.inc @@ -32,7 +32,7 @@ #include #include -#include +#include "google/protobuf/arena.h" #include using UNITTEST::TestAllTypes; diff --git a/src/google/protobuf/reflection.h b/src/google/protobuf/reflection.h index 7b75a43f22..df9e5a7965 100644 --- a/src/google/protobuf/reflection.h +++ b/src/google/protobuf/reflection.h @@ -36,15 +36,15 @@ #include -#include -#include +#include "google/protobuf/message.h" +#include "google/protobuf/generated_enum_util.h" #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -565,6 +565,6 @@ struct RefTypeTraits< } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_REFLECTION_H__ diff --git a/src/google/protobuf/reflection_internal.h b/src/google/protobuf/reflection_internal.h index f749c3eb11..3fdee895e0 100644 --- a/src/google/protobuf/reflection_internal.h +++ b/src/google/protobuf/reflection_internal.h @@ -31,9 +31,9 @@ #ifndef GOOGLE_PROTOBUF_REFLECTION_INTERNAL_H__ #define GOOGLE_PROTOBUF_REFLECTION_INTERNAL_H__ -#include -#include -#include +#include "google/protobuf/map_field.h" +#include "google/protobuf/reflection.h" +#include "google/protobuf/repeated_field.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/reflection_ops.cc b/src/google/protobuf/reflection_ops.cc index a0c5231188..0ef6c9a929 100644 --- a/src/google/protobuf/reflection_ops.cc +++ b/src/google/protobuf/reflection_ops.cc @@ -31,22 +31,22 @@ // Author: kenton@google.com (Kenton Varda) // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/reflection_ops.h" #include #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/unknown_field_set.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -457,4 +457,4 @@ void GenericSwap(Message* lhs, Message* rhs) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/reflection_ops.h b/src/google/protobuf/reflection_ops.h index 1294ef7ed6..b6f1bd2f47 100644 --- a/src/google/protobuf/reflection_ops.h +++ b/src/google/protobuf/reflection_ops.h @@ -38,15 +38,15 @@ #ifndef GOOGLE_PROTOBUF_REFLECTION_OPS_H__ #define GOOGLE_PROTOBUF_REFLECTION_OPS_H__ -#include -#include +#include "google/protobuf/message.h" +#include "google/protobuf/port.h" #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -85,6 +85,6 @@ class PROTOBUF_EXPORT ReflectionOps { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_REFLECTION_OPS_H__ diff --git a/src/google/protobuf/reflection_ops_unittest.cc b/src/google/protobuf/reflection_ops_unittest.cc index ab04b80063..282e4ae957 100644 --- a/src/google/protobuf/reflection_ops_unittest.cc +++ b/src/google/protobuf/reflection_ops_unittest.cc @@ -32,16 +32,16 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/reflection_ops.h" -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/descriptor.h" #include -#include +#include "google/protobuf/test_util.h" -#include +#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/reflection_tester.cc b/src/google/protobuf/reflection_tester.cc index 4c6db03283..23084dc275 100644 --- a/src/google/protobuf/reflection_tester.cc +++ b/src/google/protobuf/reflection_tester.cc @@ -28,14 +28,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/reflection_tester.h" #include -#include -#include +#include "google/protobuf/map_field.h" +#include "google/protobuf/message.h" // Must include last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1670,4 +1670,4 @@ void MapReflectionTester::ExpectClearViaReflectionIterator(Message* message) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/reflection_tester.h b/src/google/protobuf/reflection_tester.h index 3a2dc8194e..7a124affef 100644 --- a/src/google/protobuf/reflection_tester.h +++ b/src/google/protobuf/reflection_tester.h @@ -31,10 +31,10 @@ #ifndef GOOGLE_PROTOBUF_REFLECTION_TESTER_H__ #define GOOGLE_PROTOBUF_REFLECTION_TESTER_H__ -#include +#include "google/protobuf/message.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -117,6 +117,6 @@ class MapReflectionTester { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_REFLECTION_TESTER_H__ diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc index 7264d0a1e3..f8212e3632 100644 --- a/src/google/protobuf/repeated_field.cc +++ b/src/google/protobuf/repeated_field.cc @@ -32,15 +32,15 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/repeated_field.h" #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -68,4 +68,4 @@ template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator; } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 5f4ea913e9..ccae6bb97a 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -52,16 +52,17 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/port.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/port.h" +#include "google/protobuf/repeated_ptr_field.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -467,7 +468,9 @@ class RepeatedField final { } FastAdderImpl(const FastAdderImpl&) = delete; FastAdderImpl& operator=(const FastAdderImpl&) = delete; - ~FastAdderImpl() { repeated_field_->ExchangeCurrentSize(index_); } + ~FastAdderImpl() { + repeated_field_->current_size_ = index_; + } void Add(Element val) { if (index_ == capacity_) { @@ -1214,6 +1217,6 @@ extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedIterator; } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_REPEATED_FIELD_H__ diff --git a/src/google/protobuf/repeated_field_reflection_unittest.cc b/src/google/protobuf/repeated_field_reflection_unittest.cc index 3512e5f489..ccecdd0494 100644 --- a/src/google/protobuf/repeated_field_reflection_unittest.cc +++ b/src/google/protobuf/repeated_field_reflection_unittest.cc @@ -33,13 +33,13 @@ // Test reflection methods for aggregate access to Repeated[Ptr]Fields. // This test proto2 methods on a proto2 layout. -#include -#include -#include +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/reflection.h" #include #include "absl/base/casts.h" -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/test_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index 8a63339385..eb0b9091cf 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -35,7 +35,7 @@ // TODO(kenton): Improve this unittest to bring it up to the standards of // other proto2 unittests. -#include +#include "google/protobuf/repeated_field.h" #include #include @@ -47,17 +47,18 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/stubs/strutil.h" #include #include +#include "absl/numeric/bits.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stl_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -179,7 +180,7 @@ void CheckAllocationSizes(bool is_ptr) { // Must be `>= 16`, as expected by the Arena. ASSERT_GE(last_alloc, 16); // Must be of a power of two. - size_t log2 = Bits::Log2FloorNonZero64(last_alloc); + size_t log2 = absl::bit_width(last_alloc) - 1; ASSERT_EQ((1 << log2), last_alloc); } @@ -642,14 +643,16 @@ TEST(RepeatedField, AddRange4) { // an input iterator. TEST(RepeatedField, AddRange5) { RepeatedField me; + me.Add(0); std::stringstream ss; ss << 1 << ' ' << 2; me.Add(std::istream_iterator(ss), std::istream_iterator()); - ASSERT_EQ(me.size(), 2); - ASSERT_EQ(me.Get(0), 1); - ASSERT_EQ(me.Get(1), 2); + ASSERT_EQ(me.size(), 3); + ASSERT_EQ(me.Get(0), 0); + ASSERT_EQ(me.Get(1), 1); + ASSERT_EQ(me.Get(2), 2); } TEST(RepeatedField, AddAndAssignRanges) { @@ -2414,4 +2417,4 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, MoveProtos) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index c63643dc17..1661474f27 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -34,14 +34,14 @@ #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/implicit_weak_message.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -150,4 +150,4 @@ MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 4e916c17a3..f58481dff3 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -58,15 +58,16 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/port.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -286,12 +287,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { const int n = current_size_; GOOGLE_DCHECK_GE(n, 0); if (n > 0) { - void* const* elements = rep_->elements; - int i = 0; - do { - TypeHandler::Clear(cast(elements[i++])); - } while (i < n); - ExchangeCurrentSize(0); + ClearNonEmpty(); } } @@ -705,12 +701,26 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return reinterpret_cast(element); } + // Out-of-line helper routine for Clear() once the inlined check has + // determined the container is non-empty + template + PROTOBUF_NOINLINE void ClearNonEmpty() { + const int n = current_size_; + void* const* elements = rep_->elements; + int i = 0; + GOOGLE_DCHECK_GT(n, + 0); // do/while loop to avoid initial test because we know n > 0 + do { + TypeHandler::Clear(cast(elements[i++])); + } while (i < n); + ExchangeCurrentSize(0); + } + // Non-templated inner function to avoid code duplication. Takes a function // pointer to the type-specific (templated) inner allocate/merge loop. - void MergeFromInternal(const RepeatedPtrFieldBase& other, - void (RepeatedPtrFieldBase::*inner_loop)(void**, - void**, int, - int)) { + PROTOBUF_NOINLINE void MergeFromInternal( + const RepeatedPtrFieldBase& other, + void (RepeatedPtrFieldBase::*inner_loop)(void**, void**, int, int)) { // Note: wrapper has already guaranteed that other.rep_ != nullptr here. int other_size = other.current_size_; void** other_elements = other.rep_->elements; @@ -871,10 +881,10 @@ class StringTypeHandler { typedef std::string Type; using Movable = IsMovable; - static inline std::string* New(Arena* arena) { + static PROTOBUF_NOINLINE std::string* New(Arena* arena) { return Arena::Create(arena); } - static inline std::string* New(Arena* arena, std::string&& value) { + static PROTOBUF_NOINLINE std::string* New(Arena* arena, std::string&& value) { return Arena::Create(arena, std::move(value)); } static inline std::string* NewFromPrototype(const std::string*, @@ -1326,7 +1336,7 @@ inline Element* RepeatedPtrField::Mutable(int index) { } template -inline Element* RepeatedPtrField::Add() { +PROTOBUF_NOINLINE Element* RepeatedPtrField::Add() { return RepeatedPtrFieldBase::Add(); } @@ -2021,6 +2031,6 @@ extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_REPEATED_PTR_FIELD_H__ diff --git a/src/google/protobuf/service.cc b/src/google/protobuf/service.cc index 53945684cb..da1ae780e7 100644 --- a/src/google/protobuf/service.cc +++ b/src/google/protobuf/service.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/service.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/service.h b/src/google/protobuf/service.h index 7490f3fb42..a512e71981 100644 --- a/src/google/protobuf/service.h +++ b/src/google/protobuf/service.h @@ -102,15 +102,17 @@ #include -#include -#include + +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/port.h" #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -287,6 +289,6 @@ class PROTOBUF_EXPORT RpcChannel { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_SERVICE_H__ diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 41530f7798..e6934f0187 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -296,4 +296,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::SourceContext >(Arena* arena PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index e9a8f58ff7..0c8c71a48c 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,19 +19,19 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fsource_5fcontext_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -242,11 +242,11 @@ inline const std::string& SourceContext::_internal_file_name() const { return _impl_.file_name_.Get(); } inline void SourceContext::_internal_set_file_name(const std::string& value) { - + _impl_.file_name_.Set(value, GetArenaForAllocation()); } inline std::string* SourceContext::_internal_mutable_file_name() { - + return _impl_.file_name_.Mutable(GetArenaForAllocation()); } inline std::string* SourceContext::release_file_name() { @@ -255,9 +255,9 @@ inline std::string* SourceContext::release_file_name() { } inline void SourceContext::set_allocated_file_name(std::string* file_name) { if (file_name != nullptr) { - + } else { - + } _impl_.file_name_.SetAllocated(file_name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -278,5 +278,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh diff --git a/src/google/protobuf/string_member_robber.h b/src/google/protobuf/string_member_robber.h index 01a90a6fb6..e16069ab46 100644 --- a/src/google/protobuf/string_member_robber.h +++ b/src/google/protobuf/string_member_robber.h @@ -34,8 +34,8 @@ #include #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #endif // GOOGLE_PROTOBUF_STRING_MEMBER_ROBBER_H__ diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index a95b4735e5..42fbd1a2fb 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -1064,4 +1064,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::ListValue >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 27dd45c9cd..768265e203 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,23 +19,23 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -#include -#include -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/map.h" // IWYU pragma: export +#include "google/protobuf/map_entry.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/generated_enum_reflection.h" +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fstruct_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -1177,5 +1177,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh diff --git a/src/google/protobuf/stubs/BUILD.bazel b/src/google/protobuf/stubs/BUILD.bazel index 423f19048f..15db8bf717 100644 --- a/src/google/protobuf/stubs/BUILD.bazel +++ b/src/google/protobuf/stubs/BUILD.bazel @@ -14,7 +14,6 @@ cc_library( srcs = [ "bytestream.cc", "common.cc", - "int128.cc", "stringprintf.cc", "structurally_valid.cc", "strutil.cc", @@ -23,10 +22,7 @@ cc_library( "bytestream.h", "callback.h", "common.h", - "int128.h", "logging.h", - "macros.h", - "map_util.h", "mathutil.h", "platform_macros.h", "port.h", @@ -57,10 +53,7 @@ cc_library( "bytestream.h", "callback.h", "common.h", - "int128.h", "logging.h", - "macros.h", - "map_util.h", "mathutil.h", "platform_macros.h", "port.h", @@ -83,7 +76,6 @@ cc_test( srcs = [ "bytestream_unittest.cc", "common_unittest.cc", - "int128_unittest.cc", "stringprintf_unittest.cc", "structurally_valid_unittest.cc", "strutil_unittest.cc", diff --git a/src/google/protobuf/stubs/bytestream.cc b/src/google/protobuf/stubs/bytestream.cc index c690d19db9..9a516d6e1a 100644 --- a/src/google/protobuf/stubs/bytestream.cc +++ b/src/google/protobuf/stubs/bytestream.cc @@ -28,12 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/stubs/bytestream.h" #include + #include -#include +#include "google/protobuf/stubs/logging.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/stubs/bytestream.h b/src/google/protobuf/stubs/bytestream.h index fa58ec25e5..a11233ef5f 100644 --- a/src/google/protobuf/stubs/bytestream.h +++ b/src/google/protobuf/stubs/bytestream.h @@ -50,15 +50,15 @@ #ifndef GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ #define GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ -#include #include #include #include "absl/strings/string_view.h" +#include "google/protobuf/stubs/common.h" // Must be last. -#include // NOLINT +#include "google/protobuf/port_def.inc" // NOLINT class CordByteSink; @@ -80,6 +80,8 @@ namespace strings { class PROTOBUF_EXPORT ByteSink { public: ByteSink() {} + ByteSink(const ByteSink&) = delete; + ByteSink& operator=(const ByteSink&) = delete; virtual ~ByteSink() {} // Appends the "n" bytes starting at "bytes". @@ -89,9 +91,6 @@ class PROTOBUF_EXPORT ByteSink { // subclasses may use internal buffers that require calling Flush() at the end // of the stream. virtual void Flush(); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ByteSink); }; // An abstract interface for an object that produces a fixed-size sequence of @@ -109,6 +108,8 @@ class PROTOBUF_EXPORT ByteSink { class PROTOBUF_EXPORT ByteSource { public: ByteSource() {} + ByteSource(const ByteSource&) = delete; + ByteSource& operator=(const ByteSource&) = delete; virtual ~ByteSource() {} // Returns the number of bytes left to read from the source. Available() @@ -143,9 +144,6 @@ class PROTOBUF_EXPORT ByteSource { // // REQUIRES: Available() >= n virtual void CopyTo(ByteSink* sink, size_t n); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ByteSource); }; // @@ -165,6 +163,8 @@ class PROTOBUF_EXPORT ByteSource { // class PROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink { public: + UncheckedArrayByteSink(const UncheckedArrayByteSink&) = delete; + UncheckedArrayByteSink& operator=(const UncheckedArrayByteSink&) = delete; explicit UncheckedArrayByteSink(char* dest) : dest_(dest) {} virtual void Append(const char* data, size_t n) override; @@ -176,7 +176,6 @@ class PROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink { private: char* dest_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UncheckedArrayByteSink); }; // Implementation of ByteSink that writes to a sized byte array. This sink will @@ -194,6 +193,8 @@ class PROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink { class PROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { public: CheckedArrayByteSink(char* outbuf, size_t capacity); + CheckedArrayByteSink(const CheckedArrayByteSink&) = delete; + CheckedArrayByteSink& operator=(const CheckedArrayByteSink&) = delete; virtual void Append(const char* bytes, size_t n) override; // Returns the number of bytes actually written to the sink. @@ -208,7 +209,6 @@ class PROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { const size_t capacity_; size_t size_; bool overflowed_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CheckedArrayByteSink); }; // Implementation of ByteSink that allocates an internal buffer (a char array) @@ -230,6 +230,8 @@ class PROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { class PROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink { public: explicit GrowingArrayByteSink(size_t estimated_size); + GrowingArrayByteSink(const GrowingArrayByteSink&) = delete; + GrowingArrayByteSink& operator=(const GrowingArrayByteSink&) = delete; virtual ~GrowingArrayByteSink(); virtual void Append(const char* bytes, size_t n) override; @@ -244,7 +246,6 @@ class PROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink { size_t capacity_; char* buf_; size_t size_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GrowingArrayByteSink); }; // Implementation of ByteSink that appends to the given string. @@ -260,11 +261,12 @@ class PROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink { class PROTOBUF_EXPORT StringByteSink : public ByteSink { public: explicit StringByteSink(std::string* dest) : dest_(dest) {} + StringByteSink(const StringByteSink&) = delete; + StringByteSink& operator=(const StringByteSink&) = delete; virtual void Append(const char* data, size_t n) override; private: std::string* dest_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringByteSink); }; // Implementation of ByteSink that discards all data. @@ -277,10 +279,9 @@ class PROTOBUF_EXPORT StringByteSink : public ByteSink { class PROTOBUF_EXPORT NullByteSink : public ByteSink { public: NullByteSink() {} + NullByteSink(const NullByteSink&) = delete; + NullByteSink& operator=(const NullByteSink&) = delete; void Append(const char* /*data*/, size_t /*n*/) override {} - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(NullByteSink); }; // @@ -299,6 +300,8 @@ class PROTOBUF_EXPORT NullByteSink : public ByteSink { class PROTOBUF_EXPORT ArrayByteSource : public ByteSource { public: explicit ArrayByteSource(absl::string_view s) : input_(s) {} + ArrayByteSource(const ArrayByteSource&) = delete; + ArrayByteSource& operator=(const ArrayByteSource&) = delete; virtual size_t Available() const override; virtual absl::string_view Peek() override; @@ -306,7 +309,6 @@ class PROTOBUF_EXPORT ArrayByteSource : public ByteSource { private: absl::string_view input_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayByteSource); }; // Implementation of ByteSource that wraps another ByteSource, limiting the @@ -349,6 +351,6 @@ class PROTOBUF_EXPORT LimitByteSource : public ByteSource { } // namespace protobuf } // namespace google -#include // NOLINT +#include "google/protobuf/port_undef.inc" // NOLINT #endif // GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ diff --git a/src/google/protobuf/stubs/bytestream_unittest.cc b/src/google/protobuf/stubs/bytestream_unittest.cc index ccc845d9f3..0e5f5a5b64 100644 --- a/src/google/protobuf/stubs/bytestream_unittest.cc +++ b/src/google/protobuf/stubs/bytestream_unittest.cc @@ -28,14 +28,15 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/stubs/bytestream.h" +#include #include #include + #include -#include -#include +#include "google/protobuf/testing/googletest.h" namespace google { namespace protobuf { @@ -121,8 +122,6 @@ class FlushingByteSink : public StringByteSink { public: explicit FlushingByteSink(std::string* dest) : StringByteSink(dest) {} virtual void Flush() { Append("z", 1); } - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FlushingByteSink); }; // Write and Flush via the ByteSink superclass interface. diff --git a/src/google/protobuf/stubs/callback.h b/src/google/protobuf/stubs/callback.h index 43d546d199..691eda4a95 100644 --- a/src/google/protobuf/stubs/callback.h +++ b/src/google/protobuf/stubs/callback.h @@ -3,9 +3,7 @@ #include -#include - -#include +#include "google/protobuf/port_def.inc" // =================================================================== // emulates google3/base/callback.h @@ -73,48 +71,44 @@ namespace protobuf { class PROTOBUF_EXPORT Closure { public: Closure() {} + Closure(const Closure&) = delete; + Closure& operator=(const Closure&) = delete; virtual ~Closure(); virtual void Run() = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Closure); }; template class ResultCallback { public: ResultCallback() {} + ResultCallback(const ResultCallback&) = delete; + ResultCallback& operator=(const ResultCallback&) = delete; virtual ~ResultCallback() {} virtual R Run() = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback); }; template class PROTOBUF_EXPORT ResultCallback1 { public: ResultCallback1() {} + ResultCallback1(const ResultCallback1&) = delete; + ResultCallback1& operator=(const ResultCallback1&) = delete; virtual ~ResultCallback1() {} virtual R Run(A1) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback1); }; template class PROTOBUF_EXPORT ResultCallback2 { public: ResultCallback2() {} + ResultCallback2(const ResultCallback2&) = delete; + ResultCallback2& operator=(const ResultCallback2&) = delete; virtual ~ResultCallback2() {} virtual R Run(A1,A2) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback2); }; namespace internal { @@ -578,6 +572,6 @@ void PROTOBUF_EXPORT DoNothing(); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index 8d7f00738c..d5c80bcc98 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -30,12 +30,13 @@ // Author: kenton@google.com (Kenton Varda) -#include +#include "google/protobuf/stubs/common.h" -#include #include -#include #include + +#include +#include #include #ifdef _WIN32 @@ -49,16 +50,14 @@ #include #endif -#include -#include -#include -#include - #include "absl/status/status.h" #include "absl/strings/string_view.h" +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/strutil.h" // Must be last. -#include // NOLINT +#include "google/protobuf/port_def.inc" // NOLINT namespace google { namespace protobuf { @@ -216,13 +215,6 @@ LogMessage& LogMessage::operator<<(const absl::Status& status) { return *this; } -LogMessage& LogMessage::operator<<(const uint128& value) { - std::ostringstream str; - str << value; - message_ += str.str(); - return *this; -} - LogMessage& LogMessage::operator<<(char value) { return *this << absl::string_view(&value, 1); } @@ -337,4 +329,4 @@ const char* FatalException::what() const throw() { } // namespace protobuf } // namespace google -#include // NOLINT +#include "google/protobuf/port_undef.inc" // NOLINT diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index d729739473..9a6190f6ab 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -35,10 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMMON_H__ #define GOOGLE_PROTOBUF_COMMON_H__ -#include -#include -#include - #include #include #include @@ -48,6 +44,8 @@ #include #include "absl/strings/string_view.h" +#include "google/protobuf/stubs/platform_macros.h" +#include "google/protobuf/stubs/port.h" #ifndef PROTOBUF_USE_EXCEPTIONS #if defined(_MSC_VER) && defined(_CPPUNWIND) @@ -70,7 +68,7 @@ #include #endif -#include +#include "google/protobuf/port_def.inc" namespace std {} @@ -199,6 +197,6 @@ class FatalException : public std::exception { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMMON_H__ diff --git a/src/google/protobuf/stubs/common_unittest.cc b/src/google/protobuf/stubs/common_unittest.cc index 675cf39ab1..eb43fd2229 100644 --- a/src/google/protobuf/stubs/common_unittest.cc +++ b/src/google/protobuf/stubs/common_unittest.cc @@ -30,17 +30,18 @@ // Author: kenton@google.com (Kenton Varda) -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" + #include #include #include "absl/strings/ascii.h" #include "absl/strings/substitute.h" +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/testing/googletest.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/stubs/int128.cc b/src/google/protobuf/stubs/int128.cc deleted file mode 100644 index a151cfb554..0000000000 --- a/src/google/protobuf/stubs/int128.cc +++ /dev/null @@ -1,193 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include - -#include -#include // NOLINT(readability/streams) -#include - -#include - -#include - -namespace google { -namespace protobuf { - -const uint128_pod kuint128max = {uint64_t{0xFFFFFFFFFFFFFFFFu}, - uint64_t{0xFFFFFFFFFFFFFFFFu}}; - -// Returns the 0-based position of the last set bit (i.e., most significant bit) -// in the given uint64. The argument may not be 0. -// -// For example: -// Given: 5 (decimal) == 101 (binary) -// Returns: 2 -#define STEP(T, n, pos, sh) \ - do { \ - if ((n) >= (static_cast(1) << (sh))) { \ - (n) = (n) >> (sh); \ - (pos) |= (sh); \ - } \ - } while (0) -static inline int Fls64(uint64_t n) { - GOOGLE_DCHECK_NE(0, n); - int pos = 0; - STEP(uint64_t, n, pos, 0x20); - uint32_t n32 = n; - STEP(uint32_t, n32, pos, 0x10); - STEP(uint32_t, n32, pos, 0x08); - STEP(uint32_t, n32, pos, 0x04); - return pos + ((uint64_t{0x3333333322221100u} >> (n32 << 2)) & 0x3); -} -#undef STEP - -// Like Fls64() above, but returns the 0-based position of the last set bit -// (i.e., most significant bit) in the given uint128. The argument may not be 0. -static inline int Fls128(uint128 n) { - if (uint64_t hi = Uint128High64(n)) { - return Fls64(hi) + 64; - } - return Fls64(Uint128Low64(n)); -} - -void uint128::DivModImpl(uint128 dividend, uint128 divisor, - uint128* quotient_ret, uint128* remainder_ret) { - if (divisor == 0) { - GOOGLE_LOG(FATAL) << "Division or mod by zero: dividend.hi=" << dividend.hi_ - << ", lo=" << dividend.lo_; - } else if (dividend < divisor) { - *quotient_ret = 0; - *remainder_ret = dividend; - return; - } else { - int dividend_bit_length = Fls128(dividend); - int divisor_bit_length = Fls128(divisor); - int difference = dividend_bit_length - divisor_bit_length; - uint128 quotient = 0; - while (difference >= 0) { - quotient <<= 1; - uint128 shifted_divisor = divisor << difference; - if (shifted_divisor <= dividend) { - dividend -= shifted_divisor; - quotient += 1; - } - difference -= 1; - } - //record the final quotient and remainder - *quotient_ret = quotient; - *remainder_ret = dividend; - } -} - - -uint128& uint128::operator/=(const uint128& divisor) { - uint128 quotient = 0; - uint128 remainder = 0; - DivModImpl(*this, divisor, "ient, &remainder); - *this = quotient; - return *this; -} -uint128& uint128::operator%=(const uint128& divisor) { - uint128 quotient = 0; - uint128 remainder = 0; - DivModImpl(*this, divisor, "ient, &remainder); - *this = remainder; - return *this; -} - -std::ostream& operator<<(std::ostream& o, const uint128& b) { - std::ios_base::fmtflags flags = o.flags(); - - // Select a divisor which is the largest power of the base < 2^64. - uint128 div; - std::streamsize div_base_log; - switch (flags & std::ios::basefield) { - case std::ios::hex: - div = - static_cast(uint64_t{0x1000000000000000u}); // 16^15 - div_base_log = 15; - break; - case std::ios::oct: - div = static_cast( - uint64_t{01000000000000000000000u}); // 8^21 - div_base_log = 21; - break; - default: // std::ios::dec - div = static_cast( - uint64_t{10000000000000000000u}); // 10^19 - div_base_log = 19; - break; - } - - // Now piece together the uint128 representation from three chunks of - // the original value, each less than "div" and therefore representable - // as a uint64. - std::ostringstream os; - std::ios_base::fmtflags copy_mask = - std::ios::basefield | std::ios::showbase | std::ios::uppercase; - os.setf(flags & copy_mask, copy_mask); - uint128 high = b; - uint128 low; - uint128::DivModImpl(high, div, &high, &low); - uint128 mid; - uint128::DivModImpl(high, div, &high, &mid); - if (high.lo_ != 0) { - os << high.lo_; - os << std::noshowbase << std::setfill('0') << std::setw(div_base_log); - os << mid.lo_; - os << std::setw(div_base_log); - } else if (mid.lo_ != 0) { - os << mid.lo_; - os << std::noshowbase << std::setfill('0') << std::setw(div_base_log); - } - os << low.lo_; - std::string rep = os.str(); - - // Add the requisite padding. - std::streamsize width = o.width(0); - auto repSize = static_cast(rep.size()); - if (width > repSize) { - if ((flags & std::ios::adjustfield) == std::ios::left) { - rep.append(width - repSize, o.fill()); - } else { - rep.insert(static_cast(0), width - repSize, - o.fill()); - } - } - - // Stream the final representation in a single "<<" call. - return o << rep; -} - -} // namespace protobuf -} // namespace google - -#include // NOLINT diff --git a/src/google/protobuf/stubs/int128.h b/src/google/protobuf/stubs/int128.h deleted file mode 100644 index 92d7bdffa4..0000000000 --- a/src/google/protobuf/stubs/int128.h +++ /dev/null @@ -1,387 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef GOOGLE_PROTOBUF_STUBS_INT128_H_ -#define GOOGLE_PROTOBUF_STUBS_INT128_H_ - -#include - -#include - -#include - -namespace google { -namespace protobuf { - -struct uint128_pod; - -// TODO(xiaofeng): Define GOOGLE_PROTOBUF_HAS_CONSTEXPR when constexpr is -// available. -#ifdef GOOGLE_PROTOBUF_HAS_CONSTEXPR -# define UINT128_CONSTEXPR constexpr -#else -# define UINT128_CONSTEXPR -#endif - -// An unsigned 128-bit integer type. Thread-compatible. -class PROTOBUF_EXPORT uint128 { - public: - UINT128_CONSTEXPR uint128(); // Sets to 0, but don't trust on this behavior. - UINT128_CONSTEXPR uint128(uint64_t top, uint64_t bottom); -#ifndef SWIG - UINT128_CONSTEXPR uint128(int bottom); - UINT128_CONSTEXPR uint128(uint32_t bottom); // Top 96 bits = 0 -#endif - UINT128_CONSTEXPR uint128(uint64_t bottom); // hi_ = 0 - UINT128_CONSTEXPR uint128(const uint128_pod &val); - - // Trivial copy constructor, assignment operator and destructor. - - void Initialize(uint64_t top, uint64_t bottom); - - // Arithmetic operators. - uint128& operator+=(const uint128& b); - uint128& operator-=(const uint128& b); - uint128& operator*=(const uint128& b); - // Long division/modulo for uint128. - uint128& operator/=(const uint128& b); - uint128& operator%=(const uint128& b); - uint128 operator++(int); - uint128 operator--(int); - uint128& operator<<=(int); - uint128& operator>>=(int); - uint128& operator&=(const uint128& b); - uint128& operator|=(const uint128& b); - uint128& operator^=(const uint128& b); - uint128& operator++(); - uint128& operator--(); - - friend uint64_t Uint128Low64(const uint128& v); - friend uint64_t Uint128High64(const uint128& v); - - // We add "std::" to avoid including all of port.h. - PROTOBUF_EXPORT friend std::ostream& operator<<(std::ostream& o, - const uint128& b); - - private: - static void DivModImpl(uint128 dividend, uint128 divisor, - uint128* quotient_ret, uint128* remainder_ret); - - // Little-endian memory order optimizations can benefit from - // having lo_ first, hi_ last. - // See util/endian/endian.h and Load128/Store128 for storing a uint128. - uint64_t lo_; - uint64_t hi_; - - // Not implemented, just declared for catching automatic type conversions. - uint128(uint8_t); - uint128(uint16_t); - uint128(float v); - uint128(double v); -}; - -// This is a POD form of uint128 which can be used for static variables which -// need to be operated on as uint128. -struct uint128_pod { - // Note: The ordering of fields is different than 'class uint128' but the - // same as its 2-arg constructor. This enables more obvious initialization - // of static instances, which is the primary reason for this struct in the - // first place. This does not seem to defeat any optimizations wrt - // operations involving this struct. - uint64_t hi; - uint64_t lo; -}; - -PROTOBUF_EXPORT extern const uint128_pod kuint128max; - -// allow uint128 to be logged -PROTOBUF_EXPORT extern std::ostream& operator<<(std::ostream& o, - const uint128& b); - -// Methods to access low and high pieces of 128-bit value. -// Defined externally from uint128 to facilitate conversion -// to native 128-bit types when compilers support them. -inline uint64_t Uint128Low64(const uint128& v) { return v.lo_; } -inline uint64_t Uint128High64(const uint128& v) { return v.hi_; } - -// TODO: perhaps it would be nice to have int128, a signed 128-bit type? - -// -------------------------------------------------------------------------- -// Implementation details follow -// -------------------------------------------------------------------------- -inline bool operator==(const uint128& lhs, const uint128& rhs) { - return (Uint128Low64(lhs) == Uint128Low64(rhs) && - Uint128High64(lhs) == Uint128High64(rhs)); -} -inline bool operator!=(const uint128& lhs, const uint128& rhs) { - return !(lhs == rhs); -} - -inline UINT128_CONSTEXPR uint128::uint128() : lo_(0), hi_(0) {} -inline UINT128_CONSTEXPR uint128::uint128(uint64_t top, uint64_t bottom) - : lo_(bottom), hi_(top) {} -inline UINT128_CONSTEXPR uint128::uint128(const uint128_pod& v) - : lo_(v.lo), hi_(v.hi) {} -inline UINT128_CONSTEXPR uint128::uint128(uint64_t bottom) - : lo_(bottom), hi_(0) {} -#ifndef SWIG -inline UINT128_CONSTEXPR uint128::uint128(uint32_t bottom) - : lo_(bottom), hi_(0) {} -inline UINT128_CONSTEXPR uint128::uint128(int bottom) - : lo_(bottom), hi_(static_cast((bottom < 0) ? -1 : 0)) {} -#endif - -#undef UINT128_CONSTEXPR - -inline void uint128::Initialize(uint64_t top, uint64_t bottom) { - hi_ = top; - lo_ = bottom; -} - -// Comparison operators. - -#define CMP128(op) \ -inline bool operator op(const uint128& lhs, const uint128& rhs) { \ - return (Uint128High64(lhs) == Uint128High64(rhs)) ? \ - (Uint128Low64(lhs) op Uint128Low64(rhs)) : \ - (Uint128High64(lhs) op Uint128High64(rhs)); \ -} - -CMP128(<) -CMP128(>) -CMP128(>=) -CMP128(<=) - -#undef CMP128 - -// Unary operators - -inline uint128 operator-(const uint128& val) { - const uint64_t hi_flip = ~Uint128High64(val); - const uint64_t lo_flip = ~Uint128Low64(val); - const uint64_t lo_add = lo_flip + 1; - if (lo_add < lo_flip) { - return uint128(hi_flip + 1, lo_add); - } - return uint128(hi_flip, lo_add); -} - -inline bool operator!(const uint128& val) { - return !Uint128High64(val) && !Uint128Low64(val); -} - -// Logical operators. - -inline uint128 operator~(const uint128& val) { - return uint128(~Uint128High64(val), ~Uint128Low64(val)); -} - -#define LOGIC128(op) \ -inline uint128 operator op(const uint128& lhs, const uint128& rhs) { \ - return uint128(Uint128High64(lhs) op Uint128High64(rhs), \ - Uint128Low64(lhs) op Uint128Low64(rhs)); \ -} - -LOGIC128(|) -LOGIC128(&) -LOGIC128(^) - -#undef LOGIC128 - -#define LOGICASSIGN128(op) \ -inline uint128& uint128::operator op(const uint128& other) { \ - hi_ op other.hi_; \ - lo_ op other.lo_; \ - return *this; \ -} - -LOGICASSIGN128(|=) -LOGICASSIGN128(&=) -LOGICASSIGN128(^=) - -#undef LOGICASSIGN128 - -// Shift operators. - -inline uint128 operator<<(const uint128& val, int amount) { - // uint64 shifts of >= 64 are undefined, so we will need some special-casing. - if (amount < 64) { - if (amount == 0) { - return val; - } - uint64_t new_hi = (Uint128High64(val) << amount) | - (Uint128Low64(val) >> (64 - amount)); - uint64_t new_lo = Uint128Low64(val) << amount; - return uint128(new_hi, new_lo); - } else if (amount < 128) { - return uint128(Uint128Low64(val) << (amount - 64), 0); - } else { - return uint128(0, 0); - } -} - -inline uint128 operator>>(const uint128& val, int amount) { - // uint64 shifts of >= 64 are undefined, so we will need some special-casing. - if (amount < 64) { - if (amount == 0) { - return val; - } - uint64_t new_hi = Uint128High64(val) >> amount; - uint64_t new_lo = (Uint128Low64(val) >> amount) | - (Uint128High64(val) << (64 - amount)); - return uint128(new_hi, new_lo); - } else if (amount < 128) { - return uint128(0, Uint128High64(val) >> (amount - 64)); - } else { - return uint128(0, 0); - } -} - -inline uint128& uint128::operator<<=(int amount) { - // uint64 shifts of >= 64 are undefined, so we will need some special-casing. - if (amount < 64) { - if (amount != 0) { - hi_ = (hi_ << amount) | (lo_ >> (64 - amount)); - lo_ = lo_ << amount; - } - } else if (amount < 128) { - hi_ = lo_ << (amount - 64); - lo_ = 0; - } else { - hi_ = 0; - lo_ = 0; - } - return *this; -} - -inline uint128& uint128::operator>>=(int amount) { - // uint64 shifts of >= 64 are undefined, so we will need some special-casing. - if (amount < 64) { - if (amount != 0) { - lo_ = (lo_ >> amount) | (hi_ << (64 - amount)); - hi_ = hi_ >> amount; - } - } else if (amount < 128) { - lo_ = hi_ >> (amount - 64); - hi_ = 0; - } else { - lo_ = 0; - hi_ = 0; - } - return *this; -} - -inline uint128 operator+(const uint128& lhs, const uint128& rhs) { - return uint128(lhs) += rhs; -} - -inline uint128 operator-(const uint128& lhs, const uint128& rhs) { - return uint128(lhs) -= rhs; -} - -inline uint128 operator*(const uint128& lhs, const uint128& rhs) { - return uint128(lhs) *= rhs; -} - -inline uint128 operator/(const uint128& lhs, const uint128& rhs) { - return uint128(lhs) /= rhs; -} - -inline uint128 operator%(const uint128& lhs, const uint128& rhs) { - return uint128(lhs) %= rhs; -} - -inline uint128& uint128::operator+=(const uint128& b) { - hi_ += b.hi_; - uint64_t lolo = lo_ + b.lo_; - if (lolo < lo_) - ++hi_; - lo_ = lolo; - return *this; -} - -inline uint128& uint128::operator-=(const uint128& b) { - hi_ -= b.hi_; - if (b.lo_ > lo_) - --hi_; - lo_ -= b.lo_; - return *this; -} - -inline uint128& uint128::operator*=(const uint128& b) { - uint64_t a96 = hi_ >> 32; - uint64_t a64 = hi_ & 0xffffffffu; - uint64_t a32 = lo_ >> 32; - uint64_t a00 = lo_ & 0xffffffffu; - uint64_t b96 = b.hi_ >> 32; - uint64_t b64 = b.hi_ & 0xffffffffu; - uint64_t b32 = b.lo_ >> 32; - uint64_t b00 = b.lo_ & 0xffffffffu; - // multiply [a96 .. a00] x [b96 .. b00] - // terms higher than c96 disappear off the high side - // terms c96 and c64 are safe to ignore carry bit - uint64_t c96 = a96 * b00 + a64 * b32 + a32 * b64 + a00 * b96; - uint64_t c64 = a64 * b00 + a32 * b32 + a00 * b64; - this->hi_ = (c96 << 32) + c64; - this->lo_ = 0; - // add terms after this one at a time to capture carry - *this += uint128(a32 * b00) << 32; - *this += uint128(a00 * b32) << 32; - *this += a00 * b00; - return *this; -} - -inline uint128 uint128::operator++(int) { - uint128 tmp(*this); - *this += 1; - return tmp; -} - -inline uint128 uint128::operator--(int) { - uint128 tmp(*this); - *this -= 1; - return tmp; -} - -inline uint128& uint128::operator++() { - *this += 1; - return *this; -} - -inline uint128& uint128::operator--() { - *this -= 1; - return *this; -} - -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_STUBS_INT128_H_ diff --git a/src/google/protobuf/stubs/int128_unittest.cc b/src/google/protobuf/stubs/int128_unittest.cc deleted file mode 100644 index b1634f0c4f..0000000000 --- a/src/google/protobuf/stubs/int128_unittest.cc +++ /dev/null @@ -1,511 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include - -#include -#include -#include - -#include -#include - -#include - -namespace google { -namespace protobuf { - -TEST(Int128, AllTests) { - uint128 zero(0); - uint128 one(1); - uint128 one_2arg(0, 1); - uint128 two(0, 2); - uint128 three(0, 3); - uint128 big(2000, 2); - uint128 big_minus_one(2000, 1); - uint128 bigger(2001, 1); - uint128 biggest(kuint128max); - uint128 high_low(1, 0); - uint128 low_high(0, std::numeric_limits::max()); - EXPECT_LT(one, two); - EXPECT_GT(two, one); - EXPECT_LT(one, big); - EXPECT_LT(one, big); - EXPECT_EQ(one, one_2arg); - EXPECT_NE(one, two); - EXPECT_GT(big, one); - EXPECT_GE(big, two); - EXPECT_GE(big, big_minus_one); - EXPECT_GT(big, big_minus_one); - EXPECT_LT(big_minus_one, big); - EXPECT_LE(big_minus_one, big); - EXPECT_NE(big_minus_one, big); - EXPECT_LT(big, biggest); - EXPECT_LE(big, biggest); - EXPECT_GT(biggest, big); - EXPECT_GE(biggest, big); - EXPECT_EQ(big, ~~big); - EXPECT_EQ(one, one | one); - EXPECT_EQ(big, big | big); - EXPECT_EQ(one, one | zero); - EXPECT_EQ(one, one & one); - EXPECT_EQ(big, big & big); - EXPECT_EQ(zero, one & zero); - EXPECT_EQ(zero, big & ~big); - EXPECT_EQ(zero, one ^ one); - EXPECT_EQ(zero, big ^ big); - EXPECT_EQ(one, one ^ zero); - - // Shift operators. - EXPECT_EQ(big, big << 0); - EXPECT_EQ(big, big >> 0); - EXPECT_GT(big << 1, big); - EXPECT_LT(big >> 1, big); - EXPECT_EQ(big, (big << 10) >> 10); - EXPECT_EQ(big, (big >> 1) << 1); - EXPECT_EQ(one, (one << 80) >> 80); - EXPECT_EQ(zero, (one >> 80) << 80); - EXPECT_EQ(zero, big >> 128); - EXPECT_EQ(zero, big << 128); - - // Shift assignments. - uint128 big_copy = big; - EXPECT_EQ(big << 0, big_copy <<= 0); - big_copy = big; - EXPECT_EQ(big >> 0, big_copy >>= 0); - big_copy = big; - EXPECT_EQ(big << 1, big_copy <<= 1); - big_copy = big; - EXPECT_EQ(big >> 1, big_copy >>= 1); - big_copy = big; - EXPECT_EQ(big << 10, big_copy <<= 10); - big_copy = big; - EXPECT_EQ(big >> 10, big_copy >>= 10); - big_copy = big; - EXPECT_EQ(big << 64, big_copy <<= 64); - big_copy = big; - EXPECT_EQ(big >> 64, big_copy >>= 64); - big_copy = big; - EXPECT_EQ(big << 73, big_copy <<= 73); - big_copy = big; - EXPECT_EQ(big >> 73, big_copy >>= 73); - big_copy = big; - EXPECT_EQ(big << 128, big_copy <<= 128); - big_copy = big; - EXPECT_EQ(big >> 128, big_copy >>= 128); - - EXPECT_EQ(Uint128High64(biggest), std::numeric_limits::max()); - EXPECT_EQ(Uint128Low64(biggest), std::numeric_limits::max()); - EXPECT_EQ(zero + one, one); - EXPECT_EQ(one + one, two); - EXPECT_EQ(big_minus_one + one, big); - EXPECT_EQ(one - one, zero); - EXPECT_EQ(one - zero, one); - EXPECT_EQ(zero - one, biggest); - EXPECT_EQ(big - big, zero); - EXPECT_EQ(big - one, big_minus_one); - EXPECT_EQ(big + std::numeric_limits::max(), bigger); - EXPECT_EQ(biggest + 1, zero); - EXPECT_EQ(zero - 1, biggest); - EXPECT_EQ(high_low - one, low_high); - EXPECT_EQ(low_high + one, high_low); - EXPECT_EQ(Uint128High64((uint128(1) << 64) - 1), 0); - EXPECT_EQ(Uint128Low64((uint128(1) << 64) - 1), std::numeric_limits::max()); - EXPECT_TRUE(!!one); - EXPECT_TRUE(!!high_low); - EXPECT_FALSE(!!zero); - EXPECT_FALSE(!one); - EXPECT_FALSE(!high_low); - EXPECT_TRUE(!zero); - EXPECT_TRUE(zero == 0); - EXPECT_FALSE(zero != 0); - EXPECT_FALSE(one == 0); - EXPECT_TRUE(one != 0); - - uint128 test = zero; - EXPECT_EQ(++test, one); - EXPECT_EQ(test, one); - EXPECT_EQ(test++, one); - EXPECT_EQ(test, two); - EXPECT_EQ(test -= 2, zero); - EXPECT_EQ(test, zero); - EXPECT_EQ(test += 2, two); - EXPECT_EQ(test, two); - EXPECT_EQ(--test, one); - EXPECT_EQ(test, one); - EXPECT_EQ(test--, one); - EXPECT_EQ(test, zero); - EXPECT_EQ(test |= three, three); - EXPECT_EQ(test &= one, one); - EXPECT_EQ(test ^= three, two); - EXPECT_EQ(test >>= 1, one); - EXPECT_EQ(test <<= 1, two); - - EXPECT_EQ(big, -(-big)); - EXPECT_EQ(two, -((-one) - 1)); - EXPECT_EQ(kuint128max, -one); - EXPECT_EQ(zero, -zero); - - GOOGLE_LOG(INFO) << one; - GOOGLE_LOG(INFO) << big_minus_one; -} - -TEST(Int128, PodTests) { - uint128_pod pod = { 12345, 67890 }; - uint128 from_pod(pod); - EXPECT_EQ(12345, Uint128High64(from_pod)); - EXPECT_EQ(67890, Uint128Low64(from_pod)); - - uint128 zero(0); - uint128_pod zero_pod = {0, 0}; - uint128 one(1); - uint128_pod one_pod = {0, 1}; - uint128 two(2); - uint128_pod two_pod = {0, 2}; - uint128 three(3); - uint128_pod three_pod = {0, 3}; - uint128 big(1, 0); - uint128_pod big_pod = {1, 0}; - - EXPECT_EQ(zero, zero_pod); - EXPECT_EQ(zero_pod, zero); - EXPECT_EQ(zero_pod, zero_pod); - EXPECT_EQ(one, one_pod); - EXPECT_EQ(one_pod, one); - EXPECT_EQ(one_pod, one_pod); - EXPECT_EQ(two, two_pod); - EXPECT_EQ(two_pod, two); - EXPECT_EQ(two_pod, two_pod); - - EXPECT_NE(one, two_pod); - EXPECT_NE(one_pod, two); - EXPECT_NE(one_pod, two_pod); - - EXPECT_LT(one, two_pod); - EXPECT_LT(one_pod, two); - EXPECT_LT(one_pod, two_pod); - EXPECT_LE(one, one_pod); - EXPECT_LE(one_pod, one); - EXPECT_LE(one_pod, one_pod); - EXPECT_LE(one, two_pod); - EXPECT_LE(one_pod, two); - EXPECT_LE(one_pod, two_pod); - - EXPECT_GT(two, one_pod); - EXPECT_GT(two_pod, one); - EXPECT_GT(two_pod, one_pod); - EXPECT_GE(two, two_pod); - EXPECT_GE(two_pod, two); - EXPECT_GE(two_pod, two_pod); - EXPECT_GE(two, one_pod); - EXPECT_GE(two_pod, one); - EXPECT_GE(two_pod, one_pod); - - EXPECT_EQ(three, one | two_pod); - EXPECT_EQ(three, one_pod | two); - EXPECT_EQ(three, one_pod | two_pod); - EXPECT_EQ(one, three & one_pod); - EXPECT_EQ(one, three_pod & one); - EXPECT_EQ(one, three_pod & one_pod); - EXPECT_EQ(two, three ^ one_pod); - EXPECT_EQ(two, three_pod ^ one); - EXPECT_EQ(two, three_pod ^ one_pod); - EXPECT_EQ(two, three & (~one)); - EXPECT_EQ(three, ~~three); - - EXPECT_EQ(two, two_pod << 0); - EXPECT_EQ(two, one_pod << 1); - EXPECT_EQ(big, one_pod << 64); - EXPECT_EQ(zero, one_pod << 128); - EXPECT_EQ(two, two_pod >> 0); - EXPECT_EQ(one, two_pod >> 1); - EXPECT_EQ(one, big_pod >> 64); - - EXPECT_EQ(one, zero + one_pod); - EXPECT_EQ(one, zero_pod + one); - EXPECT_EQ(one, zero_pod + one_pod); - EXPECT_EQ(one, two - one_pod); - EXPECT_EQ(one, two_pod - one); - EXPECT_EQ(one, two_pod - one_pod); -} - -TEST(Int128, OperatorAssignReturnRef) { - uint128 v(1); - (v += 4) -= 3; - EXPECT_EQ(2, v); -} - -TEST(Int128, Multiply) { - uint128 a, b, c; - - // Zero test. - a = 0; - b = 0; - c = a * b; - EXPECT_EQ(0, c); - - // Max carries. - a = uint128(0) - 1; - b = uint128(0) - 1; - c = a * b; - EXPECT_EQ(1, c); - - // Self-operation with max carries. - c = uint128(0) - 1; - c *= c; - EXPECT_EQ(1, c); - - // 1-bit x 1-bit. - for (int i = 0; i < 64; ++i) { - for (int j = 0; j < 64; ++j) { - a = uint128(1) << i; - b = uint128(1) << j; - c = a * b; - EXPECT_EQ(uint128(1) << (i+j), c); - } - } - - // Verified with dc. - a = uint128(uint64_t{0xffffeeeeddddccccu}, uint64_t{0xbbbbaaaa99998888u}); - b = uint128(uint64_t{0x7777666655554444u}, uint64_t{0x3333222211110000u}); - c = a * b; - EXPECT_EQ( - uint128(uint64_t{0x530EDA741C71D4C3u}, uint64_t{0xBF25975319080000u}), c); - EXPECT_EQ(0, c - b * a); - EXPECT_EQ(a * a - b * b, (a + b) * (a - b)); - - // Verified with dc. - a = uint128(uint64_t{0x0123456789abcdefu}, uint64_t{0xfedcba9876543210u}); - b = uint128(uint64_t{0x02468ace13579bdfu}, uint64_t{0xfdb97531eca86420u}); - c = a * b; - EXPECT_EQ( - uint128(uint64_t{0x97a87f4f261ba3f2u}, uint64_t{0x342d0bbf48948200u}), c); - EXPECT_EQ(0, c - b * a); - EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); -} - -TEST(Int128, AliasTests) { - uint128 x1(1, 2); - uint128 x2(2, 4); - x1 += x1; - EXPECT_EQ(x2, x1); - - uint128 x3(1, static_cast(1) << 63); - uint128 x4(3, 0); - x3 += x3; - EXPECT_EQ(x4, x3); -} - -#ifdef PROTOBUF_HAS_DEATH_TEST -TEST(Int128, DivideByZeroCheckFails) { - uint128 a = 0; - uint128 b = 0; - EXPECT_DEATH(a / b, "Division or mod by zero:"); - a = 123; - EXPECT_DEATH(a / b, "Division or mod by zero:"); -} - -TEST(Int128, ModByZeroCheckFails) { - uint128 a = 0; - uint128 b = 0; - EXPECT_DEATH(a % b, "Division or mod by zero:"); - a = 123; - EXPECT_DEATH(a % b, "Division or mod by zero:"); -} -#endif // PROTOBUF_HAS_DEATH_TEST - -TEST(Int128, DivideAndMod) { - // a := q * b + r - uint128 a, b, q, r; - - // Zero test. - a = 0; - b = 123; - q = a / b; - r = a % b; - EXPECT_EQ(0, q); - EXPECT_EQ(0, r); - - a = uint128(uint64_t{0x530eda741c71d4c3u}, uint64_t{0xbf25975319080000u}); - q = uint128(uint64_t{0x4de2cab081u}, uint64_t{0x14c34ab4676e4babu}); - b = uint128(0x1110001); - r = uint128(0x3eb455); - ASSERT_EQ(a, q * b + r); // Sanity-check. - - uint128 result_q, result_r; - result_q = a / b; - result_r = a % b; - EXPECT_EQ(q, result_q); - EXPECT_EQ(r, result_r); - - // Try the other way around. - std::swap(q, b); - result_q = a / b; - result_r = a % b; - EXPECT_EQ(q, result_q); - EXPECT_EQ(r, result_r); - // Restore. - std::swap(b, q); - - // Dividend < divisor; result should be q:0 r:. - std::swap(a, b); - result_q = a / b; - result_r = a % b; - EXPECT_EQ(0, result_q); - EXPECT_EQ(a, result_r); - // Try the other way around. - std::swap(a, q); - result_q = a / b; - result_r = a % b; - EXPECT_EQ(0, result_q); - EXPECT_EQ(a, result_r); - // Restore. - std::swap(q, a); - std::swap(b, a); - - // Try a large remainder. - b = a / 2 + 1; - uint128 expected_r(uint64_t{0x29876d3a0e38ea61u}, - uint64_t{0xdf92cba98c83ffffu}); - // Sanity checks. - ASSERT_EQ(a / 2 - 1, expected_r); - ASSERT_EQ(a, b + expected_r); - result_q = a / b; - result_r = a % b; - EXPECT_EQ(1, result_q); - EXPECT_EQ(expected_r, result_r); -} - -static uint64_t RandomUint64() { - uint64_t v1 = rand(); - uint64_t v2 = rand(); - uint64_t v3 = rand(); - return v1 * v2 + v3; -} - -TEST(Int128, DivideAndModRandomInputs) { - const int kNumIters = 1 << 18; - for (int i = 0; i < kNumIters; ++i) { - const uint128 a(RandomUint64(), RandomUint64()); - const uint128 b(RandomUint64(), RandomUint64()); - if (b == 0) { - continue; // Avoid a div-by-zero. - } - const uint128 q = a / b; - const uint128 r = a % b; - ASSERT_EQ(a, b * q + r); - } -} - -#ifdef GOOGLE_PROTOBUF_HAS_CONSTEXPR -TEST(Int128, ConstexprTest) { - constexpr uint128 zero; - constexpr uint128 one = 1; - constexpr uint128_pod pod = {2, 3}; - constexpr uint128 from_pod = pod; - constexpr uint128 minus_two = -2; - EXPECT_EQ(one, uint128(1)); - EXPECT_EQ(from_pod, uint128(2, 3)); - EXPECT_EQ(minus_two, uint128(-1ULL, -2ULL)); -} - -TEST(Int128, Traits) { - EXPECT_TRUE(std::is_trivially_copy_constructible::value); - EXPECT_TRUE(std::is_trivially_copy_assignable::value); - EXPECT_TRUE(std::is_trivially_destructible::value); -} -#endif // GOOGLE_PROTOBUF_HAS_CONSTEXPR - -TEST(Int128, OStream) { - struct { - uint128 val; - std::ios_base::fmtflags flags; - std::streamsize width; - char fill; - const char* rep; - } cases[] = { - // zero with different bases - {uint128(0), std::ios::dec, 0, '_', "0"}, - {uint128(0), std::ios::oct, 0, '_', "0"}, - {uint128(0), std::ios::hex, 0, '_', "0"}, - // crossover between lo_ and hi_ - {uint128(0, -1), std::ios::dec, 0, '_', "18446744073709551615"}, - {uint128(0, -1), std::ios::oct, 0, '_', "1777777777777777777777"}, - {uint128(0, -1), std::ios::hex, 0, '_', "ffffffffffffffff"}, - {uint128(1, 0), std::ios::dec, 0, '_', "18446744073709551616"}, - {uint128(1, 0), std::ios::oct, 0, '_', "2000000000000000000000"}, - {uint128(1, 0), std::ios::hex, 0, '_', "10000000000000000"}, - // just the top bit - {uint128(uint64_t{0x8000000000000000u}, 0), std::ios::dec, 0, '_', - "170141183460469231731687303715884105728"}, - {uint128(uint64_t{0x8000000000000000u}, 0), std::ios::oct, 0, '_', - "2000000000000000000000000000000000000000000"}, - {uint128(uint64_t{0x8000000000000000u}, 0), std::ios::hex, 0, '_', - "80000000000000000000000000000000"}, - // maximum uint128 value - {uint128(-1, -1), std::ios::dec, 0, '_', - "340282366920938463463374607431768211455"}, - {uint128(-1, -1), std::ios::oct, 0, '_', - "3777777777777777777777777777777777777777777"}, - {uint128(-1, -1), std::ios::hex, 0, '_', - "ffffffffffffffffffffffffffffffff"}, - // uppercase - {uint128(-1, -1), std::ios::hex | std::ios::uppercase, 0, '_', - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"}, - // showbase - {uint128(1), std::ios::dec | std::ios::showbase, 0, '_', "1"}, - {uint128(1), std::ios::oct | std::ios::showbase, 0, '_', "01"}, - {uint128(1), std::ios::hex | std::ios::showbase, 0, '_', "0x1"}, - // showbase does nothing on zero - {uint128(0), std::ios::dec | std::ios::showbase, 0, '_', "0"}, - {uint128(0), std::ios::oct | std::ios::showbase, 0, '_', "0"}, - {uint128(0), std::ios::hex | std::ios::showbase, 0, '_', "0"}, - // showpos does nothing on unsigned types - {uint128(1), std::ios::dec | std::ios::showpos, 0, '_', "1"}, - // padding - {uint128(9), std::ios::dec, 6, '_', "_____9"}, - {uint128(12345), std::ios::dec, 6, '_', "_12345"}, - // left adjustment - {uint128(9), std::ios::dec | std::ios::left, 6, '_', "9_____"}, - {uint128(12345), std::ios::dec | std::ios::left, 6, '_', "12345_"}, - }; - for (size_t i = 0; i < GOOGLE_ARRAYSIZE(cases); ++i) { - std::ostringstream os; - os.flags(cases[i].flags); - os.width(cases[i].width); - os.fill(cases[i].fill); - os << cases[i].val; - EXPECT_EQ(cases[i].rep, os.str()); - } -} -} // namespace protobuf -} // namespace google - -#include diff --git a/src/google/protobuf/stubs/logging.h b/src/google/protobuf/stubs/logging.h index a2b71aa49b..004c557b83 100644 --- a/src/google/protobuf/stubs/logging.h +++ b/src/google/protobuf/stubs/logging.h @@ -31,14 +31,12 @@ #ifndef GOOGLE_PROTOBUF_STUBS_LOGGING_H_ #define GOOGLE_PROTOBUF_STUBS_LOGGING_H_ -#include -#include - #include "absl/status/status.h" #include "absl/strings/string_view.h" +#include "google/protobuf/stubs/port.h" // Must be last. -#include // NOLINT +#include "google/protobuf/port_def.inc" // NOLINT // =================================================================== // emulates google3/base/logging.h @@ -236,6 +234,6 @@ class PROTOBUF_EXPORT LogSilencer { } // namespace protobuf } // namespace google -#include // NOLINT +#include "google/protobuf/port_undef.inc" // NOLINT #endif // GOOGLE_PROTOBUF_STUBS_LOGGING_H_ diff --git a/src/google/protobuf/stubs/macros.h b/src/google/protobuf/stubs/macros.h deleted file mode 100644 index ae9a8b987f..0000000000 --- a/src/google/protobuf/stubs/macros.h +++ /dev/null @@ -1,93 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_MACROS_H__ -#define GOOGLE_PROTOBUF_MACROS_H__ - -namespace google { -namespace protobuf { - -#undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS -#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ - TypeName(const TypeName&) = delete; \ - void operator=(const TypeName&) = delete - -#undef GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS -#define GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ - TypeName() = delete; \ - TypeName(const TypeName&) = delete; \ - void operator=(const TypeName&) = delete - -// =================================================================== -// from google3/base/basictypes.h - -// The GOOGLE_ARRAYSIZE(arr) macro returns the # of elements in an array arr. -// The expression is a compile-time constant, and therefore can be -// used in defining new arrays, for example. -// -// GOOGLE_ARRAYSIZE catches a few type errors. If you see a compiler error -// -// "warning: division by zero in ..." -// -// when using GOOGLE_ARRAYSIZE, you are (wrongfully) giving it a pointer. -// You should only use GOOGLE_ARRAYSIZE on statically allocated arrays. -// -// The following comments are on the implementation details, and can -// be ignored by the users. -// -// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in -// the array) and sizeof(*(arr)) (the # of bytes in one array -// element). If the former is divisible by the latter, perhaps arr is -// indeed an array, in which case the division result is the # of -// elements in the array. Otherwise, arr cannot possibly be an array, -// and we generate a compiler error to prevent the code from -// compiling. -// -// Since the size of bool is implementation-defined, we need to cast -// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final -// result has type size_t. -// -// This macro is not perfect as it wrongfully accepts certain -// pointers, namely where the pointer size is divisible by the pointee -// size. Since all our code has to go through a 32-bit compiler, -// where a pointer is 4 bytes, this means all pointers to a type whose -// size is 3 or greater than 4 will be (righteously) rejected. -// -// Kudos to Jorg Brown for this simple and elegant implementation. - -#undef GOOGLE_ARRAYSIZE -#define GOOGLE_ARRAYSIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast(!(sizeof(a) % sizeof(*(a))))) - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_MACROS_H__ diff --git a/src/google/protobuf/stubs/map_util.h b/src/google/protobuf/stubs/map_util.h deleted file mode 100644 index 24e098ad1b..0000000000 --- a/src/google/protobuf/stubs/map_util.h +++ /dev/null @@ -1,769 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// from google3/util/gtl/map_util.h -// Author: Anton Carver - -#ifndef GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ -#define GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ - -#include -#include -#include -#include -#include - -#include - -namespace google { -namespace protobuf { -namespace internal { -// Local implementation of RemoveConst to avoid including base/type_traits.h. -template struct RemoveConst { typedef T type; }; -template struct RemoveConst : RemoveConst {}; -} // namespace internal - -// -// Find*() -// - -// Returns a const reference to the value associated with the given key if it -// exists. Crashes otherwise. -// -// This is intended as a replacement for operator[] as an rvalue (for reading) -// when the key is guaranteed to exist. -// -// operator[] for lookup is discouraged for several reasons: -// * It has a side-effect of inserting missing keys -// * It is not thread-safe (even when it is not inserting, it can still -// choose to resize the underlying storage) -// * It invalidates iterators (when it chooses to resize) -// * It default constructs a value object even if it doesn't need to -// -// This version assumes the key is printable, and includes it in the fatal log -// message. -template -const typename Collection::value_type::second_type& -FindOrDie(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - GOOGLE_CHECK(it != collection.end()) << "Map key not found: " << key; - return it->second; -} - -// Same as above, but returns a non-const reference. -template -typename Collection::value_type::second_type& -FindOrDie(Collection& collection, // NOLINT - const typename Collection::value_type::first_type& key) { - typename Collection::iterator it = collection.find(key); - GOOGLE_CHECK(it != collection.end()) << "Map key not found: " << key; - return it->second; -} - -// Same as FindOrDie above, but doesn't log the key on failure. -template -const typename Collection::value_type::second_type& -FindOrDieNoPrint(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - GOOGLE_CHECK(it != collection.end()) << "Map key not found"; - return it->second; -} - -// Same as above, but returns a non-const reference. -template -typename Collection::value_type::second_type& -FindOrDieNoPrint(Collection& collection, // NOLINT - const typename Collection::value_type::first_type& key) { - typename Collection::iterator it = collection.find(key); - GOOGLE_CHECK(it != collection.end()) << "Map key not found"; - return it->second; -} - -// Returns a const reference to the value associated with the given key if it -// exists, otherwise returns a const reference to the provided default value. -// -// WARNING: If a temporary object is passed as the default "value," -// this function will return a reference to that temporary object, -// which will be destroyed at the end of the statement. A common -// example: if you have a map with string values, and you pass a char* -// as the default "value," either use the returned value immediately -// or store it in a string (not string&). -// Details: http://go/findwithdefault -template -const typename Collection::value_type::second_type& -FindWithDefault(const Collection& collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return value; - } - return it->second; -} - -// Returns a pointer to the const value associated with the given key if it -// exists, or nullptr otherwise. -template -const typename Collection::value_type::second_type* -FindOrNull(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return 0; - } - return &it->second; -} - -// Same as above but returns a pointer to the non-const value. -template -typename Collection::value_type::second_type* -FindOrNull(Collection& collection, // NOLINT - const typename Collection::value_type::first_type& key) { - typename Collection::iterator it = collection.find(key); - if (it == collection.end()) { - return 0; - } - return &it->second; -} - -// Returns the pointer value associated with the given key. If none is found, -// nullptr is returned. The function is designed to be used with a map of keys to -// pointers. -// -// This function does not distinguish between a missing key and a key mapped -// to nullptr. -template -typename Collection::value_type::second_type -FindPtrOrNull(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return typename Collection::value_type::second_type(); - } - return it->second; -} - -// Same as above, except takes non-const reference to collection. -// -// This function is needed for containers that propagate constness to the -// pointee, such as boost::ptr_map. -template -typename Collection::value_type::second_type -FindPtrOrNull(Collection& collection, // NOLINT - const typename Collection::value_type::first_type& key) { - typename Collection::iterator it = collection.find(key); - if (it == collection.end()) { - return typename Collection::value_type::second_type(); - } - return it->second; -} - -// Finds the pointer value associated with the given key in a map whose values -// are linked_ptrs. Returns nullptr if key is not found. -template -typename Collection::value_type::second_type::element_type* -FindLinkedPtrOrNull(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return 0; - } - // Since linked_ptr::get() is a const member returning a non const, - // we do not need a version of this function taking a non const collection. - return it->second.get(); -} - -// Same as above, but dies if the key is not found. -template -typename Collection::value_type::second_type::element_type& -FindLinkedPtrOrDie(const Collection& collection, - const typename Collection::value_type::first_type& key) { - typename Collection::const_iterator it = collection.find(key); - GOOGLE_CHECK(it != collection.end()) << "key not found: " << key; - // Since linked_ptr::operator*() is a const member returning a non const, - // we do not need a version of this function taking a non const collection. - return *it->second; -} - -// Finds the value associated with the given key and copies it to *value (if not -// nullptr). Returns false if the key was not found, true otherwise. -template -bool FindCopy(const Collection& collection, - const Key& key, - Value* const value) { - typename Collection::const_iterator it = collection.find(key); - if (it == collection.end()) { - return false; - } - if (value) { - *value = it->second; - } - return true; -} - -// -// Contains*() -// - -// Returns true if and only if the given collection contains the given key. -template -bool ContainsKey(const Collection& collection, const Key& key) { - return collection.find(key) != collection.end(); -} - -// Returns true if and only if the given collection contains the given key-value -// pair. -template -bool ContainsKeyValuePair(const Collection& collection, - const Key& key, - const Value& value) { - typedef typename Collection::const_iterator const_iterator; - std::pair range = collection.equal_range(key); - for (const_iterator it = range.first; it != range.second; ++it) { - if (it->second == value) { - return true; - } - } - return false; -} - -// -// Insert*() -// - -// Inserts the given key-value pair into the collection. Returns true if and -// only if the key from the given pair didn't previously exist. Otherwise, the -// value in the map is replaced with the value from the given pair. -template -bool InsertOrUpdate(Collection* const collection, - const typename Collection::value_type& vt) { - std::pair ret = collection->insert(vt); - if (!ret.second) { - // update - ret.first->second = vt.second; - return false; - } - return true; -} - -// Same as above, except that the key and value are passed separately. -template -bool InsertOrUpdate(Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { - return InsertOrUpdate( - collection, typename Collection::value_type(key, value)); -} - -// Inserts/updates all the key-value pairs from the range defined by the -// iterators "first" and "last" into the given collection. -template -void InsertOrUpdateMany(Collection* const collection, - InputIterator first, InputIterator last) { - for (; first != last; ++first) { - InsertOrUpdate(collection, *first); - } -} - -// Change the value associated with a particular key in a map or hash_map -// of the form map which owns the objects pointed to by the -// value pointers. If there was an existing value for the key, it is deleted. -// True indicates an insert took place, false indicates an update + delete. -template -bool InsertAndDeleteExisting( - Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { - std::pair ret = - collection->insert(typename Collection::value_type(key, value)); - if (!ret.second) { - delete ret.first->second; - ret.first->second = value; - return false; - } - return true; -} - -// Inserts the given key and value into the given collection if and only if the -// given key did NOT already exist in the collection. If the key previously -// existed in the collection, the value is not changed. Returns true if the -// key-value pair was inserted; returns false if the key was already present. -template -bool InsertIfNotPresent(Collection* const collection, - const typename Collection::value_type& vt) { - return collection->insert(vt).second; -} - -// Same as above except the key and value are passed separately. -template -bool InsertIfNotPresent( - Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { - return InsertIfNotPresent( - collection, typename Collection::value_type(key, value)); -} - -// Same as above except dies if the key already exists in the collection. -template -void InsertOrDie(Collection* const collection, - const typename Collection::value_type& value) { - GOOGLE_CHECK(InsertIfNotPresent(collection, value)) - << "duplicate value: " << value; -} - -// Same as above except doesn't log the value on error. -template -void InsertOrDieNoPrint(Collection* const collection, - const typename Collection::value_type& value) { - GOOGLE_CHECK(InsertIfNotPresent(collection, value)) << "duplicate value."; -} - -// Inserts the key-value pair into the collection. Dies if key was already -// present. -template -void InsertOrDie(Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& data) { - GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) - << "duplicate key: " << key; -} - -// Same as above except doesn't log the key on error. -template -void InsertOrDieNoPrint( - Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& data) { - GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) << "duplicate key."; -} - -// Inserts a new key and default-initialized value. Dies if the key was already -// present. Returns a reference to the value. Example usage: -// -// map m; -// SomeProto& proto = InsertKeyOrDie(&m, 3); -// proto.set_field("foo"); -template -typename Collection::value_type::second_type& InsertKeyOrDie( - Collection* const collection, - const typename Collection::value_type::first_type& key) { - typedef typename Collection::value_type value_type; - std::pair res = - collection->insert(value_type(key, typename value_type::second_type())); - GOOGLE_CHECK(res.second) << "duplicate key: " << key; - return res.first->second; -} - -// -// Lookup*() -// - -// Looks up a given key and value pair in a collection and inserts the key-value -// pair if it's not already present. Returns a reference to the value associated -// with the key. -template -typename Collection::value_type::second_type& -LookupOrInsert(Collection* const collection, - const typename Collection::value_type& vt) { - return collection->insert(vt).first->second; -} - -// Same as above except the key-value are passed separately. -template -typename Collection::value_type::second_type& -LookupOrInsert(Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value) { - return LookupOrInsert( - collection, typename Collection::value_type(key, value)); -} - -// Counts the number of equivalent elements in the given "sequence", and stores -// the results in "count_map" with element as the key and count as the value. -// -// Example: -// vector v = {"a", "b", "c", "a", "b"}; -// map m; -// AddTokenCounts(v, 1, &m); -// assert(m["a"] == 2); -// assert(m["b"] == 2); -// assert(m["c"] == 1); -template -void AddTokenCounts( - const Sequence& sequence, - const typename Collection::value_type::second_type& increment, - Collection* const count_map) { - for (typename Sequence::const_iterator it = sequence.begin(); - it != sequence.end(); ++it) { - typename Collection::value_type::second_type& value = - LookupOrInsert(count_map, *it, - typename Collection::value_type::second_type()); - value += increment; - } -} - -// Returns a reference to the value associated with key. If not found, a value -// is default constructed on the heap and added to the map. -// -// This function is useful for containers of the form map, where -// inserting a new key, value pair involves constructing a new heap-allocated -// Value, and storing a pointer to that in the collection. -template -typename Collection::value_type::second_type& -LookupOrInsertNew(Collection* const collection, - const typename Collection::value_type::first_type& key) { - typedef typename std::iterator_traits< - typename Collection::value_type::second_type>::value_type Element; - std::pair ret = - collection->insert(typename Collection::value_type( - key, - static_cast(nullptr))); - if (ret.second) { - ret.first->second = new Element(); - } - return ret.first->second; -} - -// Same as above but constructs the value using the single-argument constructor -// and the given "arg". -template -typename Collection::value_type::second_type& -LookupOrInsertNew(Collection* const collection, - const typename Collection::value_type::first_type& key, - const Arg& arg) { - typedef typename std::iterator_traits< - typename Collection::value_type::second_type>::value_type Element; - std::pair ret = - collection->insert(typename Collection::value_type( - key, - static_cast(nullptr))); - if (ret.second) { - ret.first->second = new Element(arg); - } - return ret.first->second; -} - -// Lookup of linked/shared pointers is used in two scenarios: -// -// Use LookupOrInsertNewLinkedPtr if the container owns the elements. -// In this case it is fine working with the raw pointer as long as it is -// guaranteed that no other thread can delete/update an accessed element. -// A mutex will need to lock the container operation as well as the use -// of the returned elements. Finding an element may be performed using -// FindLinkedPtr*(). -// -// Use LookupOrInsertNewSharedPtr if the container does not own the elements -// for their whole lifetime. This is typically the case when a reader allows -// parallel updates to the container. In this case a Mutex only needs to lock -// container operations, but all element operations must be performed on the -// shared pointer. Finding an element must be performed using FindPtr*() and -// cannot be done with FindLinkedPtr*() even though it compiles. - -// Lookup a key in a map or hash_map whose values are linked_ptrs. If it is -// missing, set collection[key].reset(new Value::element_type) and return that. -// Value::element_type must be default constructable. -template -typename Collection::value_type::second_type::element_type* -LookupOrInsertNewLinkedPtr( - Collection* const collection, - const typename Collection::value_type::first_type& key) { - typedef typename Collection::value_type::second_type Value; - std::pair ret = - collection->insert(typename Collection::value_type(key, Value())); - if (ret.second) { - ret.first->second.reset(new typename Value::element_type); - } - return ret.first->second.get(); -} - -// A variant of LookupOrInsertNewLinkedPtr where the value is constructed using -// a single-parameter constructor. Note: the constructor argument is computed -// even if it will not be used, so only values cheap to compute should be passed -// here. On the other hand it does not matter how expensive the construction of -// the actual stored value is, as that only occurs if necessary. -template -typename Collection::value_type::second_type::element_type* -LookupOrInsertNewLinkedPtr( - Collection* const collection, - const typename Collection::value_type::first_type& key, - const Arg& arg) { - typedef typename Collection::value_type::second_type Value; - std::pair ret = - collection->insert(typename Collection::value_type(key, Value())); - if (ret.second) { - ret.first->second.reset(new typename Value::element_type(arg)); - } - return ret.first->second.get(); -} - -// Lookup a key in a map or hash_map whose values are shared_ptrs. If it is -// missing, set collection[key].reset(new Value::element_type). Unlike -// LookupOrInsertNewLinkedPtr, this function returns the shared_ptr instead of -// the raw pointer. Value::element_type must be default constructable. -template -typename Collection::value_type::second_type& -LookupOrInsertNewSharedPtr( - Collection* const collection, - const typename Collection::value_type::first_type& key) { - typedef typename Collection::value_type::second_type SharedPtr; - typedef typename Collection::value_type::second_type::element_type Element; - std::pair ret = - collection->insert(typename Collection::value_type(key, SharedPtr())); - if (ret.second) { - ret.first->second.reset(new Element()); - } - return ret.first->second; -} - -// A variant of LookupOrInsertNewSharedPtr where the value is constructed using -// a single-parameter constructor. Note: the constructor argument is computed -// even if it will not be used, so only values cheap to compute should be passed -// here. On the other hand it does not matter how expensive the construction of -// the actual stored value is, as that only occurs if necessary. -template -typename Collection::value_type::second_type& -LookupOrInsertNewSharedPtr( - Collection* const collection, - const typename Collection::value_type::first_type& key, - const Arg& arg) { - typedef typename Collection::value_type::second_type SharedPtr; - typedef typename Collection::value_type::second_type::element_type Element; - std::pair ret = - collection->insert(typename Collection::value_type(key, SharedPtr())); - if (ret.second) { - ret.first->second.reset(new Element(arg)); - } - return ret.first->second; -} - -// -// Misc Utility Functions -// - -// Updates the value associated with the given key. If the key was not already -// present, then the key-value pair are inserted and "previous" is unchanged. If -// the key was already present, the value is updated and "*previous" will -// contain a copy of the old value. -// -// InsertOrReturnExisting has complementary behavior that returns the -// address of an already existing value, rather than updating it. -template -bool UpdateReturnCopy(Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& value, - typename Collection::value_type::second_type* previous) { - std::pair ret = - collection->insert(typename Collection::value_type(key, value)); - if (!ret.second) { - // update - if (previous) { - *previous = ret.first->second; - } - ret.first->second = value; - return true; - } - return false; -} - -// Same as above except that the key and value are passed as a pair. -template -bool UpdateReturnCopy(Collection* const collection, - const typename Collection::value_type& vt, - typename Collection::value_type::second_type* previous) { - std::pair ret = collection->insert(vt); - if (!ret.second) { - // update - if (previous) { - *previous = ret.first->second; - } - ret.first->second = vt.second; - return true; - } - return false; -} - -// Tries to insert the given key-value pair into the collection. Returns nullptr if -// the insert succeeds. Otherwise, returns a pointer to the existing value. -// -// This complements UpdateReturnCopy in that it allows to update only after -// verifying the old value and still insert quickly without having to look up -// twice. Unlike UpdateReturnCopy this also does not come with the issue of an -// undefined previous* in case new data was inserted. -template -typename Collection::value_type::second_type* InsertOrReturnExisting( - Collection* const collection, const typename Collection::value_type& vt) { - std::pair ret = collection->insert(vt); - if (ret.second) { - return nullptr; // Inserted, no existing previous value. - } else { - return &ret.first->second; // Return address of already existing value. - } -} - -// Same as above, except for explicit key and data. -template -typename Collection::value_type::second_type* InsertOrReturnExisting( - Collection* const collection, - const typename Collection::value_type::first_type& key, - const typename Collection::value_type::second_type& data) { - return InsertOrReturnExisting(collection, - typename Collection::value_type(key, data)); -} - -// Erases the collection item identified by the given key, and returns the value -// associated with that key. It is assumed that the value (i.e., the -// mapped_type) is a pointer. Returns nullptr if the key was not found in the -// collection. -// -// Examples: -// map my_map; -// -// One line cleanup: -// delete EraseKeyReturnValuePtr(&my_map, "abc"); -// -// Use returned value: -// std::unique_ptr value_ptr( -// EraseKeyReturnValuePtr(&my_map, "abc")); -// if (value_ptr.get()) -// value_ptr->DoSomething(); -// -template -typename Collection::value_type::second_type EraseKeyReturnValuePtr( - Collection* const collection, - const typename Collection::value_type::first_type& key) { - typename Collection::iterator it = collection->find(key); - if (it == collection->end()) { - return nullptr; - } - typename Collection::value_type::second_type v = it->second; - collection->erase(it); - return v; -} - -// Inserts all the keys from map_container into key_container, which must -// support insert(MapContainer::key_type). -// -// Note: any initial contents of the key_container are not cleared. -template -void InsertKeysFromMap(const MapContainer& map_container, - KeyContainer* key_container) { - GOOGLE_CHECK(key_container != nullptr); - for (typename MapContainer::const_iterator it = map_container.begin(); - it != map_container.end(); ++it) { - key_container->insert(it->first); - } -} - -// Appends all the keys from map_container into key_container, which must -// support push_back(MapContainer::key_type). -// -// Note: any initial contents of the key_container are not cleared. -template -void AppendKeysFromMap(const MapContainer& map_container, - KeyContainer* key_container) { - GOOGLE_CHECK(key_container != nullptr); - for (typename MapContainer::const_iterator it = map_container.begin(); - it != map_container.end(); ++it) { - key_container->push_back(it->first); - } -} - -// A more specialized overload of AppendKeysFromMap to optimize reallocations -// for the common case in which we're appending keys to a vector and hence can -// (and sometimes should) call reserve() first. -// -// (It would be possible to play SFINAE games to call reserve() for any -// container that supports it, but this seems to get us 99% of what we need -// without the complexity of a SFINAE-based solution.) -template -void AppendKeysFromMap(const MapContainer& map_container, - std::vector* key_container) { - GOOGLE_CHECK(key_container != nullptr); - // We now have the opportunity to call reserve(). Calling reserve() every - // time is a bad idea for some use cases: libstdc++'s implementation of - // vector<>::reserve() resizes the vector's backing store to exactly the - // given size (unless it's already at least that big). Because of this, - // the use case that involves appending a lot of small maps (total size - // N) one by one to a vector would be O(N^2). But never calling reserve() - // loses the opportunity to improve the use case of adding from a large - // map to an empty vector (this improves performance by up to 33%). A - // number of heuristics are possible; see the discussion in - // cl/34081696. Here we use the simplest one. - if (key_container->empty()) { - key_container->reserve(map_container.size()); - } - for (typename MapContainer::const_iterator it = map_container.begin(); - it != map_container.end(); ++it) { - key_container->push_back(it->first); - } -} - -// Inserts all the values from map_container into value_container, which must -// support push_back(MapContainer::mapped_type). -// -// Note: any initial contents of the value_container are not cleared. -template -void AppendValuesFromMap(const MapContainer& map_container, - ValueContainer* value_container) { - GOOGLE_CHECK(value_container != nullptr); - for (typename MapContainer::const_iterator it = map_container.begin(); - it != map_container.end(); ++it) { - value_container->push_back(it->second); - } -} - -// A more specialized overload of AppendValuesFromMap to optimize reallocations -// for the common case in which we're appending values to a vector and hence -// can (and sometimes should) call reserve() first. -// -// (It would be possible to play SFINAE games to call reserve() for any -// container that supports it, but this seems to get us 99% of what we need -// without the complexity of a SFINAE-based solution.) -template -void AppendValuesFromMap(const MapContainer& map_container, - std::vector* value_container) { - GOOGLE_CHECK(value_container != nullptr); - // See AppendKeysFromMap for why this is done. - if (value_container->empty()) { - value_container->reserve(map_container.size()); - } - for (typename MapContainer::const_iterator it = map_container.begin(); - it != map_container.end(); ++it) { - value_container->push_back(it->second); - } -} - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ diff --git a/src/google/protobuf/stubs/mathutil.h b/src/google/protobuf/stubs/mathutil.h index 1d16bcedb2..908b2450d2 100644 --- a/src/google/protobuf/stubs/mathutil.h +++ b/src/google/protobuf/stubs/mathutil.h @@ -30,12 +30,13 @@ #ifndef GOOGLE_PROTOBUF_STUBS_MATHUTIL_H_ #define GOOGLE_PROTOBUF_STUBS_MATHUTIL_H_ -#include #include + +#include #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index e0d3ef776e..d459a94446 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -32,15 +32,17 @@ #define GOOGLE_PROTOBUF_STUBS_PORT_H_ #include -#include #include +#include + #include +#include #include -#include -#include +#include "google/protobuf/stubs/platform_macros.h" -#include +// Must be last. +#include "google/protobuf/port_def.inc" // NOLINT #undef PROTOBUF_LITTLE_ENDIAN #ifdef _WIN32 @@ -228,69 +230,6 @@ static inline uint64_t bswap_64(uint64_t x) { #endif -// =================================================================== -// from google3/util/bits/bits.h - -class Bits { - public: - static uint32_t Log2FloorNonZero(uint32_t n) { -#if defined(__GNUC__) - return 31 ^ static_cast(__builtin_clz(n)); -#elif defined(_MSC_VER) - unsigned long where; - _BitScanReverse(&where, n); - return where; -#else - return Log2FloorNonZero_Portable(n); -#endif - } - - static uint32_t Log2FloorNonZero64(uint64_t n) { - // Older versions of clang run into an instruction-selection failure when - // it encounters __builtin_clzll: - // https://bugs.chromium.org/p/nativeclient/issues/detail?id=4395 - // This includes arm-nacl-clang and clang in older Android NDK versions. - // To work around this, when we build with those we use the portable - // implementation instead. -#if defined(__GNUC__) && !defined(GOOGLE_PROTOBUF_USE_PORTABLE_LOG2) - return 63 ^ static_cast(__builtin_clzll(n)); -#elif defined(_MSC_VER) && defined(_M_X64) - unsigned long where; - _BitScanReverse64(&where, n); - return where; -#else - return Log2FloorNonZero64_Portable(n); -#endif - } - private: - static int Log2FloorNonZero_Portable(uint32_t n) { - if (n == 0) - return -1; - int log = 0; - uint32_t value = n; - for (int i = 4; i >= 0; --i) { - int shift = (1 << i); - uint32_t x = value >> shift; - if (x != 0) { - value = x; - log += shift; - } - } - assert(value == 1); - return log; - } - - static int Log2FloorNonZero64_Portable(uint64_t n) { - const uint32_t topbits = static_cast(n >> 32); - if (topbits == 0) { - // Top bits are zero, so scan in bottom bits - return static_cast(Log2FloorNonZero(static_cast(n))); - } else { - return 32 + static_cast(Log2FloorNonZero(topbits)); - } - } -}; - // =================================================================== // from google3/util/endian/endian.h PROTOBUF_EXPORT uint32_t ghtonl(uint32_t x); @@ -354,6 +293,6 @@ class BigEndian { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_STUBS_PORT_H_ diff --git a/src/google/protobuf/stubs/status_macros.h b/src/google/protobuf/stubs/status_macros.h index 2e7c0f54e9..fc2267e1b4 100644 --- a/src/google/protobuf/stubs/status_macros.h +++ b/src/google/protobuf/stubs/status_macros.h @@ -33,13 +33,12 @@ #ifndef GOOGLE_PROTOBUF_STUBS_STATUS_MACROS_H_ #define GOOGLE_PROTOBUF_STUBS_STATUS_MACROS_H_ -#include - #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "google/protobuf/stubs/common.h" // Needs to be last. -#include // NOLINT +#include "google/protobuf/port_def.inc" // NOLINT namespace google { namespace protobuf { @@ -90,6 +89,6 @@ absl::Status DoAssignOrReturn(T& lhs, absl::StatusOr result) { } // namespace protobuf } // namespace google -#include // NOLINT +#include "google/protobuf/port_undef.inc" // NOLINT #endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_ diff --git a/src/google/protobuf/stubs/stl_util.h b/src/google/protobuf/stubs/stl_util.h index e6260d0760..cd10c4b2ef 100644 --- a/src/google/protobuf/stubs/stl_util.h +++ b/src/google/protobuf/stubs/stl_util.h @@ -33,38 +33,16 @@ #ifndef GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ #define GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ -#include - #include +#include "google/protobuf/stubs/common.h" + // Must be last. -#include // NOLINT +#include "google/protobuf/port_def.inc" // NOLINT namespace google { namespace protobuf { -// Inside Google, this function implements a horrible, disgusting hack in which -// we reach into the string's private implementation and resize it without -// initializing the new bytes. In some cases doing this can significantly -// improve performance. However, since it's totally non-portable it has no -// place in open source code. Feel free to fill this function in with your -// own disgusting hack if you want the perf boost. -inline void STLStringResizeUninitialized(std::string* s, size_t new_size) { - s->resize(new_size); -} - -// As above, but we make sure to follow amortized growth in which we always -// increase the capacity by at least a constant factor >1. -inline void STLStringResizeUninitializedAmortized(std::string* s, - size_t new_size) { - const size_t cap = s->capacity(); - if (new_size > cap) { - // Make sure to always grow by at least a factor of 2x. - s->reserve(std::max(new_size, 2 * cap)); - } - STLStringResizeUninitialized(s, new_size); -} - // Return a mutable char* pointing to a string's internal buffer, // which may not be null-terminated. Writing through this pointer will // modify the string. @@ -85,6 +63,6 @@ inline char* string_as_array(std::string* str) { } // namespace protobuf } // namespace google -#include // NOLINT +#include "google/protobuf/port_undef.inc" // NOLINT #endif // GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ diff --git a/src/google/protobuf/stubs/stringprintf.cc b/src/google/protobuf/stubs/stringprintf.cc index a6ad4c0da4..2e6613ebb3 100644 --- a/src/google/protobuf/stubs/stringprintf.cc +++ b/src/google/protobuf/stubs/stringprintf.cc @@ -30,15 +30,16 @@ // from google3/base/stringprintf.cc -#include +#include "google/protobuf/stubs/stringprintf.h" #include -#include // For va_list and related operations -#include // MSVC requires this for _vsnprintf +#include // For va_list and related operations +#include // MSVC requires this for _vsnprintf + #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" namespace google { namespace protobuf { @@ -152,7 +153,7 @@ std::string StringPrintfVector(const char* format, for (int i = 0; i < v.size(); ++i) { cstr[i] = v[i].c_str(); } - for (int i = v.size(); i < GOOGLE_ARRAYSIZE(cstr); ++i) { + for (int i = v.size(); i < kStringPrintfVectorMaxArgs; ++i) { cstr[i] = &string_printf_empty_block[0]; } diff --git a/src/google/protobuf/stubs/stringprintf.h b/src/google/protobuf/stubs/stringprintf.h index e3858be130..e1c0561dcd 100644 --- a/src/google/protobuf/stubs/stringprintf.h +++ b/src/google/protobuf/stubs/stringprintf.h @@ -41,12 +41,14 @@ #define GOOGLE_PROTOBUF_STUBS_STRINGPRINTF_H #include + #include #include -#include +#include "google/protobuf/stubs/common.h" -#include +// Must be last. +#include "google/protobuf/port_def.inc" // NOLINT namespace google { namespace protobuf { @@ -80,6 +82,6 @@ PROTOBUF_EXPORT extern std::string StringPrintfVector( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_STUBS_STRINGPRINTF_H diff --git a/src/google/protobuf/stubs/stringprintf_unittest.cc b/src/google/protobuf/stubs/stringprintf_unittest.cc index dbecd2b33c..c53e190f50 100644 --- a/src/google/protobuf/stubs/stringprintf_unittest.cc +++ b/src/google/protobuf/stubs/stringprintf_unittest.cc @@ -30,14 +30,16 @@ // from google3/base/stringprintf_unittest.cc -#include -#include +#include "google/protobuf/stubs/stringprintf.h" + #include #include #include #include +#include "google/protobuf/testing/googletest.h" + namespace google { namespace protobuf { namespace { diff --git a/src/google/protobuf/stubs/structurally_valid.cc b/src/google/protobuf/stubs/structurally_valid.cc index 136bb0c787..418b40b9b5 100644 --- a/src/google/protobuf/stubs/structurally_valid.cc +++ b/src/google/protobuf/stubs/structurally_valid.cc @@ -30,9 +30,8 @@ // Author: jrm@google.com (Jim Meehan) -#include - #include "absl/strings/string_view.h" +#include "google/protobuf/stubs/common.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/stubs/structurally_valid_unittest.cc b/src/google/protobuf/stubs/structurally_valid_unittest.cc index ebd9c42306..bb56a68085 100644 --- a/src/google/protobuf/stubs/structurally_valid_unittest.cc +++ b/src/google/protobuf/stubs/structurally_valid_unittest.cc @@ -31,9 +31,10 @@ // Copyright 2008 Google Inc. All Rights Reserved. // Author: xpeng@google.com (Peter Peng) -#include #include +#include "google/protobuf/stubs/common.h" + namespace google { namespace protobuf { namespace internal { diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index 0c4826b23e..b6d2049a34 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc @@ -30,11 +30,10 @@ // from google3/strings/strutil.cc +#include "google/protobuf/stubs/strutil.h" + #include #include // FLT_DIG and DBL_DIG -#include -#include -#include #include #include @@ -44,6 +43,8 @@ #include "absl/strings/ascii.h" #include "absl/strings/string_view.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/stl_util.h" #ifdef _WIN32 // MSVC has only _snprintf, not snprintf. diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 2766536ee9..2aa522db04 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -33,16 +33,18 @@ #ifndef GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ #define GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ -#include #include #include -#include #include #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" +#include "google/protobuf/stubs/common.h" + +// Must be last. +#include "google/protobuf/port_def.inc" // NOLINT namespace google { namespace protobuf { @@ -470,6 +472,6 @@ double NoLocaleStrtod(const char* str, char** endptr); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ diff --git a/src/google/protobuf/stubs/strutil_unittest.cc b/src/google/protobuf/stubs/strutil_unittest.cc index 482609a0c4..d657579ad5 100644 --- a/src/google/protobuf/stubs/strutil_unittest.cc +++ b/src/google/protobuf/stubs/strutil_unittest.cc @@ -30,13 +30,13 @@ // Author: kenton@google.com (Kenton Varda) -#include +#include "google/protobuf/stubs/strutil.h" +#include #include -#include -#include -#include +#include "google/protobuf/stubs/stl_util.h" +#include "google/protobuf/testing/googletest.h" #ifdef _WIN32 #define snprintf _snprintf diff --git a/src/google/protobuf/test_util.cc b/src/google/protobuf/test_util.cc index 795cb6ae17..5fee8ff4bd 100644 --- a/src/google/protobuf/test_util.cc +++ b/src/google/protobuf/test_util.cc @@ -38,7 +38,7 @@ #include #endif -#include +#include "google/protobuf/test_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/test_util.h b/src/google/protobuf/test_util.h index 10ae12a439..5449ed67ef 100644 --- a/src/google/protobuf/test_util.h +++ b/src/google/protobuf/test_util.h @@ -35,17 +35,17 @@ #ifndef GOOGLE_PROTOBUF_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_TEST_UTIL_H__ -#include +#include "google/protobuf/unittest.pb.h" #define UNITTEST ::protobuf_unittest #define UNITTEST_IMPORT ::protobuf_unittest_import // Must be included when the preprocessor symbols above are defined. -#include +#include "google/protobuf/test_util.inc" #undef UNITTEST #undef UNITTEST_IMPORT // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1272,6 +1272,6 @@ inline void ExpectAllFieldsAndExtensionsInOrder(const std::string& serialized) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_TEST_UTIL_H__ diff --git a/src/google/protobuf/test_util.inc b/src/google/protobuf/test_util.inc index 95f97f90a2..4512db2611 100644 --- a/src/google/protobuf/test_util.inc +++ b/src/google/protobuf/test_util.inc @@ -37,11 +37,11 @@ // within an enclosing namespace and requires header files to be included // out of this file. -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/message.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/test_util2.h b/src/google/protobuf/test_util2.h index e4958b4ca0..1f51ec878b 100644 --- a/src/google/protobuf/test_util2.h +++ b/src/google/protobuf/test_util2.h @@ -31,13 +31,13 @@ #ifndef GOOGLE_PROTOBUF_TEST_UTIL2_H__ #define GOOGLE_PROTOBUF_TEST_UTIL2_H__ -#include +#include "google/protobuf/stubs/strutil.h" -#include +#include "google/protobuf/testing/googletest.h" #include "absl/strings/str_replace.h" -#include -#include -#include +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/util/message_differencer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/test_util_lite.cc b/src/google/protobuf/test_util_lite.cc index 0f078f8366..f09a218e2b 100644 --- a/src/google/protobuf/test_util_lite.cc +++ b/src/google/protobuf/test_util_lite.cc @@ -32,10 +32,10 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/test_util_lite.h" -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" #include #include "absl/strings/string_view.h" diff --git a/src/google/protobuf/test_util_lite.h b/src/google/protobuf/test_util_lite.h index b8cbed9cb3..7ed6029840 100644 --- a/src/google/protobuf/test_util_lite.h +++ b/src/google/protobuf/test_util_lite.h @@ -35,7 +35,7 @@ #ifndef GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ #define GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ -#include +#include "google/protobuf/unittest_lite.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/testing/BUILD.bazel b/src/google/protobuf/testing/BUILD.bazel index 3b87fe9c4e..20e37b6061 100644 --- a/src/google/protobuf/testing/BUILD.bazel +++ b/src/google/protobuf/testing/BUILD.bazel @@ -25,6 +25,7 @@ cc_library( "//:protobuf_lite", # for ShutdownProtobufLibrary "//src/google/protobuf/io", "//src/google/protobuf/stubs:lite", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", ], ) diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index 7b628879c6..c4acd4be4c 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -31,7 +31,8 @@ // Author: kenton@google.com (Kenton Varda) // emulates google3/file/base/file.cc -#include +#include "google/protobuf/testing/file.h" + #include #include #include @@ -45,8 +46,8 @@ #endif #include -#include -#include +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/stubs/logging.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/testing/file.h b/src/google/protobuf/testing/file.h index f18f685865..18348a6f99 100644 --- a/src/google/protobuf/testing/file.h +++ b/src/google/protobuf/testing/file.h @@ -34,7 +34,7 @@ #ifndef GOOGLE_PROTOBUF_TESTING_FILE_H__ #define GOOGLE_PROTOBUF_TESTING_FILE_H__ -#include +#include "google/protobuf/stubs/common.h" namespace google { namespace protobuf { @@ -45,6 +45,9 @@ const int DEFAULT_FILE_MODE = 0777; // in tests. class File { public: + File(const File&) = delete; + File& operator=(const File&) = delete; + // Check if the file exists. static bool Exists(const std::string& name); @@ -96,9 +99,6 @@ class File { bool /*is_default*/) { return WriteStringToFile(contents, name); } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(File); }; } // namespace protobuf diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index 88343f9347..350f9a9808 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -31,14 +31,17 @@ // Author: kenton@google.com (Kenton Varda) // emulates google3/testing/base/public/googletest.cc -#include -#include -#include -#include -#include -#include +#include "google/protobuf/testing/googletest.h" + #include #include +#include +#include + +#include "absl/strings/str_replace.h" +#include "google/protobuf/io/io_win32.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/testing/file.h" #ifdef _MSC_VER // #include #else @@ -150,7 +153,7 @@ std::string GetTemporaryDirectoryName() { // The Win32 API accepts forward slashes as a path delimiter as long as the // path doesn't use the "\\?\" prefix. // Let's avoid confusion and use only forward slashes. - result = StringReplace(result, "\\", "/", true); + result = absl::StrReplaceAll(result, {{"\\", "/"}}); #endif // _WIN32 return result; } diff --git a/src/google/protobuf/testing/googletest.h b/src/google/protobuf/testing/googletest.h index 6a0c694e71..87c8a4183f 100644 --- a/src/google/protobuf/testing/googletest.h +++ b/src/google/protobuf/testing/googletest.h @@ -34,11 +34,14 @@ #ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__ #define GOOGLE_PROTOBUF_GOOGLETEST_H__ +#include + #include #include -#include -#include -#include + +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" + // Disable death tests if we use exceptions in CHECK(). #if !PROTOBUF_USE_EXCEPTIONS && defined(GTEST_HAS_DEATH_TEST) && \ !GTEST_OS_WINDOWS @@ -81,6 +84,8 @@ static const LogLevel WARNING = LOGLEVEL_WARNING; class ScopedMemoryLog { public: ScopedMemoryLog(); + ScopedMemoryLog(const ScopedMemoryLog&) = delete; + ScopedMemoryLog& operator=(const ScopedMemoryLog&) = delete; virtual ~ScopedMemoryLog(); // Fetches all messages with the given severity level. @@ -94,8 +99,6 @@ class ScopedMemoryLog { const std::string& message); static ScopedMemoryLog* active_log_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog); }; } // namespace protobuf diff --git a/src/google/protobuf/testing/zcgunzip.cc b/src/google/protobuf/testing/zcgunzip.cc index 68f8172f61..facb1cabea 100644 --- a/src/google/protobuf/testing/zcgunzip.cc +++ b/src/google/protobuf/testing/zcgunzip.cc @@ -53,8 +53,8 @@ #endif #endif -#include -#include +#include "google/protobuf/io/gzip_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" using google::protobuf::io::FileInputStream; using google::protobuf::io::GzipInputStream; diff --git a/src/google/protobuf/testing/zcgzip.cc b/src/google/protobuf/testing/zcgzip.cc index 808d058a1e..3ac2cf2c30 100644 --- a/src/google/protobuf/testing/zcgzip.cc +++ b/src/google/protobuf/testing/zcgzip.cc @@ -52,8 +52,8 @@ #endif #endif -#include -#include +#include "google/protobuf/io/gzip_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" using google::protobuf::io::FileOutputStream; using google::protobuf::io::GzipOutputStream; diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index cbf621cdd8..8633e88699 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/text_format.h" #include #include @@ -46,30 +46,30 @@ #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/any.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/strtod.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/stubs/stl_util.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -2750,4 +2750,4 @@ void TextFormat::Printer::PrintUnknownFields( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/text_format.h b/src/google/protobuf/text_format.h index c339bfbb33..bfae7e6de8 100644 --- a/src/google/protobuf/text_format.h +++ b/src/google/protobuf/text_format.h @@ -44,15 +44,16 @@ #include #include -#include -#include +#include "google/protobuf/port.h" #include "absl/strings/string_view.h" -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/message.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/port.h" + // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -689,6 +690,6 @@ inline TextFormat::ParseInfoTree* TextFormat::CreateNested( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__ diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index c66a686f1e..e11533da34 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/text_format.h" #include #include @@ -40,34 +40,35 @@ #include #include #include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" +#include "google/protobuf/any.pb.h" +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_mset.pb.h" +#include "google/protobuf/unittest_mset_wire_format.pb.h" +#include "google/protobuf/unittest_proto3.pb.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/stubs/strutil.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include -#include +#include "google/protobuf/stubs/logging.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" #include "absl/strings/substitute.h" -#include -#include +#include "google/protobuf/test_util.h" +#include "google/protobuf/test_util2.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1083,10 +1084,8 @@ TEST_F(TextFormatTest, OptionalColon) { // Some platforms (e.g. Windows) insist on padding the exponent to three // digits when one or two would be just fine. -static std::string RemoveRedundantZeros(std::string text) { - text = StringReplace(text, "e+0", "e+", true); - text = StringReplace(text, "e-0", "e-", true); - return text; +static std::string RemoveRedundantZeros(absl::string_view text) { + return absl::StrReplaceAll(text, {{"e+0", "e+"}, {"e-0", "e-"}}); } TEST_F(TextFormatTest, PrintExotic) { @@ -2291,4 +2290,4 @@ TEST(TextFormatFloatingPointTest, PreservesNegative0) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 84a04a54cc..47ecf7250c 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -306,4 +306,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Timestamp >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index a53224fc3b..1bee3c79e2 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,19 +19,19 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2ftimestamp_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -236,7 +236,7 @@ inline int64_t Timestamp::seconds() const { return _internal_seconds(); } inline void Timestamp::_internal_set_seconds(int64_t value) { - + _impl_.seconds_ = value; } inline void Timestamp::set_seconds(int64_t value) { @@ -256,7 +256,7 @@ inline int32_t Timestamp::nanos() const { return _internal_nanos(); } inline void Timestamp::_internal_set_nanos(int32_t value) { - + _impl_.nanos_ = value; } inline void Timestamp::set_nanos(int32_t value) { @@ -274,5 +274,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index abf51746af..760823fed8 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -2164,4 +2164,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Option >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 218a0e5cb1..a8354863fe 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,22 +19,22 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/generated_enum_reflection.h" +#include "google/protobuf/unknown_field_set.h" #include #include // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2ftype_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -1419,11 +1419,11 @@ inline const std::string& Type::_internal_name() const { return _impl_.name_.Get(); } inline void Type::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Type::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Type::release_name() { @@ -1432,9 +1432,9 @@ inline std::string* Type::release_name() { } inline void Type::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1520,8 +1520,7 @@ inline void Type::set_oneofs(int index, std::string&& value) { // @@protoc_insertion_point(field_set:google.protobuf.Type.oneofs) } inline void Type::set_oneofs(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.oneofs_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.oneofs_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.Type.oneofs) } inline void Type::set_oneofs(int index, const char* value, size_t size) { @@ -1541,8 +1540,7 @@ inline void Type::add_oneofs(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs) } inline void Type::add_oneofs(const char* value) { - GOOGLE_DCHECK(value != nullptr); - _impl_.oneofs_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); _impl_.oneofs_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.Type.oneofs) } inline void Type::add_oneofs(const char* value, size_t size) { @@ -1623,9 +1621,9 @@ inline void Type::unsafe_arena_set_allocated_source_context( } _impl_.source_context_ = source_context; if (source_context) { - + } else { - + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Type.source_context) } @@ -1677,9 +1675,9 @@ inline void Type::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCo source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, source_context, submessage_arena); } - + } else { - + } _impl_.source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.source_context) @@ -1761,7 +1759,7 @@ inline int32_t Field::number() const { return _internal_number(); } inline void Field::_internal_set_number(int32_t value) { - + _impl_.number_ = value; } inline void Field::set_number(int32_t value) { @@ -1793,11 +1791,11 @@ inline const std::string& Field::_internal_name() const { return _impl_.name_.Get(); } inline void Field::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_name() { @@ -1806,9 +1804,9 @@ inline std::string* Field::release_name() { } inline void Field::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1843,11 +1841,11 @@ inline const std::string& Field::_internal_type_url() const { return _impl_.type_url_.Get(); } inline void Field::_internal_set_type_url(const std::string& value) { - + _impl_.type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_type_url() { - + return _impl_.type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_type_url() { @@ -1856,9 +1854,9 @@ inline std::string* Field::release_type_url() { } inline void Field::set_allocated_type_url(std::string* type_url) { if (type_url != nullptr) { - + } else { - + } _impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1881,7 +1879,7 @@ inline int32_t Field::oneof_index() const { return _internal_oneof_index(); } inline void Field::_internal_set_oneof_index(int32_t value) { - + _impl_.oneof_index_ = value; } inline void Field::set_oneof_index(int32_t value) { @@ -1901,7 +1899,7 @@ inline bool Field::packed() const { return _internal_packed(); } inline void Field::_internal_set_packed(bool value) { - + _impl_.packed_ = value; } inline void Field::set_packed(bool value) { @@ -1973,11 +1971,11 @@ inline const std::string& Field::_internal_json_name() const { return _impl_.json_name_.Get(); } inline void Field::_internal_set_json_name(const std::string& value) { - + _impl_.json_name_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_json_name() { - + return _impl_.json_name_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_json_name() { @@ -1986,9 +1984,9 @@ inline std::string* Field::release_json_name() { } inline void Field::set_allocated_json_name(std::string* json_name) { if (json_name != nullptr) { - + } else { - + } _impl_.json_name_.SetAllocated(json_name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -2023,11 +2021,11 @@ inline const std::string& Field::_internal_default_value() const { return _impl_.default_value_.Get(); } inline void Field::_internal_set_default_value(const std::string& value) { - + _impl_.default_value_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_default_value() { - + return _impl_.default_value_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_default_value() { @@ -2036,9 +2034,9 @@ inline std::string* Field::release_default_value() { } inline void Field::set_allocated_default_value(std::string* default_value) { if (default_value != nullptr) { - + } else { - + } _impl_.default_value_.SetAllocated(default_value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -2077,11 +2075,11 @@ inline const std::string& Enum::_internal_name() const { return _impl_.name_.Get(); } inline void Enum::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Enum::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Enum::release_name() { @@ -2090,9 +2088,9 @@ inline std::string* Enum::release_name() { } inline void Enum::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -2206,9 +2204,9 @@ inline void Enum::unsafe_arena_set_allocated_source_context( } _impl_.source_context_ = source_context; if (source_context) { - + } else { - + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Enum.source_context) } @@ -2260,9 +2258,9 @@ inline void Enum::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCo source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, source_context, submessage_arena); } - + } else { - + } _impl_.source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.source_context) @@ -2316,11 +2314,11 @@ inline const std::string& EnumValue::_internal_name() const { return _impl_.name_.Get(); } inline void EnumValue::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* EnumValue::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* EnumValue::release_name() { @@ -2329,9 +2327,9 @@ inline std::string* EnumValue::release_name() { } inline void EnumValue::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -2354,7 +2352,7 @@ inline int32_t EnumValue::number() const { return _internal_number(); } inline void EnumValue::_internal_set_number(int32_t value) { - + _impl_.number_ = value; } inline void EnumValue::set_number(int32_t value) { @@ -2430,11 +2428,11 @@ inline const std::string& Option::_internal_name() const { return _impl_.name_.Get(); } inline void Option::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Option::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Option::release_name() { @@ -2443,9 +2441,9 @@ inline std::string* Option::release_name() { } inline void Option::set_allocated_name(std::string* name) { if (name != nullptr) { - + } else { - + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -2479,9 +2477,9 @@ inline void Option::unsafe_arena_set_allocated_value( } _impl_.value_ = value; if (value) { - + } else { - + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Option.value) } @@ -2533,9 +2531,9 @@ inline void Option::set_allocated_value(::PROTOBUF_NAMESPACE_ID::Any* value) { value = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, value, submessage_arena); } - + } else { - + } _impl_.value_ = value; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Option.value) @@ -2579,5 +2577,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index 74c358e9a2..3a6d8d70b3 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -32,24 +32,25 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/unknown_field_set.h" + +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "absl/strings/internal/resize_uninitialized.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/generated_message_tctable_decl.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" + // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -243,7 +244,7 @@ bool UnknownFieldSet::ParseFromArray(const void* data, int size) { bool UnknownFieldSet::SerializeToString(std::string* output) const { const size_t size = google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(*this); - STLStringResizeUninitializedAmortized(output, size); + absl::strings_internal::STLStringResizeUninitializedAmortized(output, size); google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( *this, reinterpret_cast(const_cast(output->data()))); return true; @@ -347,4 +348,4 @@ const char* UnknownFieldParse(uint64_t tag, UnknownFieldSet* unknown, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h index 354a02c3a9..04b630ebbd 100644 --- a/src/google/protobuf/unknown_field_set.h +++ b/src/google/protobuf/unknown_field_set.h @@ -44,16 +44,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/port.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" #ifdef SWIG #error "You cannot SWIG proto headers" @@ -404,5 +405,5 @@ inline void UnknownField::SetType(Type type) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ diff --git a/src/google/protobuf/unknown_field_set_unittest.cc b/src/google/protobuf/unknown_field_set_unittest.cc index 8791ee047d..92fff73135 100644 --- a/src/google/protobuf/unknown_field_set_unittest.cc +++ b/src/google/protobuf/unknown_field_set_unittest.cc @@ -35,30 +35,30 @@ // This test is testing a lot more than just the UnknownFieldSet class. It // tests handling of unknown fields throughout the system. -#include +#include "google/protobuf/unknown_field_set.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_lite.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/wire_format.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include #include "absl/synchronization/mutex.h" #include "absl/time/clock.h" #include "absl/time/time.h" -#include -#include +#include "google/protobuf/test_util.h" +#include "google/protobuf/stubs/stl_util.h" namespace google { diff --git a/src/google/protobuf/util/delimited_message_util.cc b/src/google/protobuf/util/delimited_message_util.cc index fdc633f49a..36b51e9576 100644 --- a/src/google/protobuf/util/delimited_message_util.cc +++ b/src/google/protobuf/util/delimited_message_util.cc @@ -31,8 +31,8 @@ // Adapted from the patch of kenton@google.com (Kenton Varda) // See https://github.com/protocolbuffers/protobuf/pull/710 for details. -#include -#include +#include "google/protobuf/util/delimited_message_util.h" +#include "google/protobuf/io/coded_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/delimited_message_util.h b/src/google/protobuf/util/delimited_message_util.h index 78625cf2f1..9a4e066767 100644 --- a/src/google/protobuf/util/delimited_message_util.h +++ b/src/google/protobuf/util/delimited_message_util.h @@ -37,12 +37,12 @@ #include -#include -#include -#include +#include "google/protobuf/message_lite.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -104,6 +104,6 @@ bool PROTOBUF_EXPORT SerializeDelimitedToCodedStream( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__ diff --git a/src/google/protobuf/util/delimited_message_util_test.cc b/src/google/protobuf/util/delimited_message_util_test.cc index 9483a646e7..954afb2f5e 100644 --- a/src/google/protobuf/util/delimited_message_util_test.cc +++ b/src/google/protobuf/util/delimited_message_util_test.cc @@ -31,13 +31,13 @@ // Adapted from the patch of kenton@google.com (Kenton Varda) // See https://github.com/protocolbuffers/protobuf/pull/710 for details. -#include +#include "google/protobuf/util/delimited_message_util.h" #include -#include -#include -#include +#include "google/protobuf/test_util.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/testing/googletest.h" #include namespace google { diff --git a/src/google/protobuf/util/field_comparator.cc b/src/google/protobuf/util/field_comparator.cc index e3dc0059d2..9161d53072 100644 --- a/src/google/protobuf/util/field_comparator.cc +++ b/src/google/protobuf/util/field_comparator.cc @@ -30,15 +30,15 @@ // Author: ksroka@google.com (Krzysztof Sroka) -#include +#include "google/protobuf/util/field_comparator.h" #include #include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/message.h" +#include "google/protobuf/util/message_differencer.h" +#include "google/protobuf/stubs/mathutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/field_comparator.h b/src/google/protobuf/util/field_comparator.h index c5a92dec1b..1988b9ed10 100644 --- a/src/google/protobuf/util/field_comparator.h +++ b/src/google/protobuf/util/field_comparator.h @@ -39,10 +39,11 @@ #include #include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -277,6 +278,6 @@ class PROTOBUF_EXPORT DefaultFieldComparator PROTOBUF_FUTURE_FINAL } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__ diff --git a/src/google/protobuf/util/field_comparator_test.cc b/src/google/protobuf/util/field_comparator_test.cc index b6802774b3..a6de21c6fe 100644 --- a/src/google/protobuf/util/field_comparator_test.cc +++ b/src/google/protobuf/util/field_comparator_test.cc @@ -30,14 +30,14 @@ // Author: ksroka@google.com (Krzysztof Sroka) -#include +#include "google/protobuf/util/field_comparator.h" #include -#include -#include +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/descriptor.h" #include -#include +#include "google/protobuf/stubs/mathutil.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc index e297ecb709..ef47730683 100644 --- a/src/google/protobuf/util/field_mask_util.cc +++ b/src/google/protobuf/util/field_mask_util.cc @@ -28,16 +28,19 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/field_mask_util.h" #include +#include +#include +#include #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include +#include "google/protobuf/message.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -51,7 +54,7 @@ std::string FieldMaskUtil::ToString(const FieldMask& mask) { void FieldMaskUtil::FromString(absl::string_view str, FieldMask* out) { out->Clear(); - std::vector paths = absl::StrSplit(str, ","); + std::vector paths = absl::StrSplit(str, ','); for (const std::string& path : paths) { if (path.empty()) continue; out->add_paths(path); @@ -124,7 +127,7 @@ bool FieldMaskUtil::ToJsonString(const FieldMask& mask, std::string* out) { bool FieldMaskUtil::FromJsonString(absl::string_view str, FieldMask* out) { out->Clear(); - std::vector paths = absl::StrSplit(str, ","); + std::vector paths = absl::StrSplit(str, ','); for (const std::string& path : paths) { if (path.empty()) continue; std::string snakecase_path; @@ -142,7 +145,7 @@ bool FieldMaskUtil::GetFieldDescriptors( if (field_descriptors != nullptr) { field_descriptors->clear(); } - std::vector parts = absl::StrSplit(path, "."); + std::vector parts = absl::StrSplit(path, '.'); for (const std::string& field_name : parts) { if (descriptor == nullptr) { return false; @@ -323,7 +326,7 @@ void FieldMaskTree::MergeToFieldMask(const std::string& prefix, } void FieldMaskTree::AddPath(const std::string& path) { - std::vector parts = absl::StrSplit(path, "."); + std::vector parts = absl::StrSplit(path, '.'); if (parts.empty()) { return; } @@ -356,7 +359,7 @@ void FieldMaskTree::RemovePath(const std::string& path, // code below. return; } - std::vector parts = absl::StrSplit(path, "."); + std::vector parts = absl::StrSplit(path, '.'); if (parts.empty()) { return; } @@ -405,7 +408,7 @@ void FieldMaskTree::RemovePath(const std::string& path, } void FieldMaskTree::IntersectPath(const std::string& path, FieldMaskTree* out) { - std::vector parts = absl::StrSplit(path, "."); + std::vector parts = absl::StrSplit(path, '.'); if (parts.empty()) { return; } diff --git a/src/google/protobuf/util/field_mask_util.h b/src/google/protobuf/util/field_mask_util.h index eef39836fc..03fb6a1660 100644 --- a/src/google/protobuf/util/field_mask_util.h +++ b/src/google/protobuf/util/field_mask_util.h @@ -35,13 +35,14 @@ #include #include +#include -#include +#include "google/protobuf/field_mask.pb.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/descriptor.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -258,6 +259,6 @@ class PROTOBUF_EXPORT FieldMaskUtil::TrimOptions { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ diff --git a/src/google/protobuf/util/field_mask_util_test.cc b/src/google/protobuf/util/field_mask_util_test.cc index bcad739fc1..a67a0254f9 100644 --- a/src/google/protobuf/util/field_mask_util_test.cc +++ b/src/google/protobuf/util/field_mask_util_test.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/field_mask_util.h" #include #include #include -#include -#include -#include +#include "google/protobuf/field_mask.pb.h" +#include "google/protobuf/test_util.h" +#include "google/protobuf/unittest.pb.h" #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/constants.h b/src/google/protobuf/util/internal/constants.h index 8bded86998..7c81c47ddd 100644 --- a/src/google/protobuf/util/internal/constants.h +++ b/src/google/protobuf/util/internal/constants.h @@ -33,7 +33,7 @@ #include -#include +#include "google/protobuf/stubs/common.h" // This file contains constants used by //net/proto2/util/converter. diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index 4428b2d8b0..514832971f 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -28,22 +28,22 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/datapiece.h" #include #include #include -#include -#include -#include +#include "google/protobuf/struct.pb.h" +#include "google/protobuf/type.pb.h" +#include "google/protobuf/descriptor.h" #include "absl/status/status.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include -#include -#include +#include "google/protobuf/util/internal/utility.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/stubs/mathutil.h" namespace google { namespace protobuf { @@ -222,6 +222,8 @@ absl::StatusOr DataPiece::ToBool() const { case TYPE_BOOL: return bool_; case TYPE_STRING: + // Calls out to absl::SimpleAtob, which supports "true"/"false", + // "yes"/"no", "y"/"n", "t"/"f", and "1"/"0". return StringToNumber(safe_strtob); default: break; diff --git a/src/google/protobuf/util/internal/datapiece.h b/src/google/protobuf/util/internal/datapiece.h index 8dd36a7ba3..a69e8f00aa 100644 --- a/src/google/protobuf/util/internal/datapiece.h +++ b/src/google/protobuf/util/internal/datapiece.h @@ -34,14 +34,15 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/type.pb.h" +#include "google/protobuf/port.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -216,6 +217,6 @@ class PROTOBUF_EXPORT DataPiece { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_DATAPIECE_H__ diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.cc b/src/google/protobuf/util/internal/default_value_objectwriter.cc index 2efaa97e66..05eccdf8d0 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.cc +++ b/src/google/protobuf/util/internal/default_value_objectwriter.cc @@ -28,13 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/default_value_objectwriter.h" #include #include "absl/container/flat_hash_map.h" -#include -#include +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/utility.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h index 3a0a062cbc..2745159a0f 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.h +++ b/src/google/protobuf/util/internal/default_value_objectwriter.h @@ -37,16 +37,16 @@ #include #include -#include #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/datapiece.h" +#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/internal/utility.h" +#include "google/protobuf/util/type_resolver.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -326,6 +326,6 @@ class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_DEFAULT_VALUE_OBJECTWRITER_H__ diff --git a/src/google/protobuf/util/internal/default_value_objectwriter_test.cc b/src/google/protobuf/util/internal/default_value_objectwriter_test.cc index dc35e51ea2..a8851b58bd 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/default_value_objectwriter_test.cc @@ -28,12 +28,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/default_value_objectwriter.h" -#include -#include -#include -#include +#include "google/protobuf/util/internal/expecting_objectwriter.h" +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/testdata/default_value_test.pb.h" +#include "google/protobuf/util/internal/type_info_test_helper.h" #include namespace google { diff --git a/src/google/protobuf/util/internal/error_listener.cc b/src/google/protobuf/util/internal/error_listener.cc index 538307bae2..a6641fda36 100644 --- a/src/google/protobuf/util/internal/error_listener.cc +++ b/src/google/protobuf/util/internal/error_listener.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/error_listener.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/error_listener.h b/src/google/protobuf/util/internal/error_listener.h index 2c3d9d56f7..27fb65cfe8 100644 --- a/src/google/protobuf/util/internal/error_listener.h +++ b/src/google/protobuf/util/internal/error_listener.h @@ -36,14 +36,15 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/location_tracker.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -101,6 +102,6 @@ class PROTOBUF_EXPORT NoopErrorListener : public ErrorListener { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_ERROR_LISTENER_H__ diff --git a/src/google/protobuf/util/internal/expecting_objectwriter.h b/src/google/protobuf/util/internal/expecting_objectwriter.h index c14b87bec3..8f200d55be 100644 --- a/src/google/protobuf/util/internal/expecting_objectwriter.h +++ b/src/google/protobuf/util/internal/expecting_objectwriter.h @@ -52,10 +52,10 @@ #include -#include #include #include "absl/strings/string_view.h" -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/object_writer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/field_mask_utility.cc b/src/google/protobuf/util/internal/field_mask_utility.cc index 8800a18935..e0ffe1324e 100644 --- a/src/google/protobuf/util/internal/field_mask_utility.cc +++ b/src/google/protobuf/util/internal/field_mask_utility.cc @@ -28,16 +28,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/field_mask_utility.h" #include "absl/status/status.h" -#include +#include "google/protobuf/stubs/strutil.h" #include "absl/strings/str_cat.h" -#include -#include +#include "google/protobuf/util/internal/utility.h" +#include "google/protobuf/stubs/status_macros.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/field_mask_utility.h b/src/google/protobuf/util/internal/field_mask_utility.h index d18b8d3981..0db911a923 100644 --- a/src/google/protobuf/util/internal/field_mask_utility.h +++ b/src/google/protobuf/util/internal/field_mask_utility.h @@ -36,10 +36,10 @@ #include #include -#include -#include +#include "google/protobuf/stubs/callback.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" +#include "google/protobuf/port.h" namespace google { diff --git a/src/google/protobuf/util/internal/json_escaping.cc b/src/google/protobuf/util/internal/json_escaping.cc index ac6a0447b5..3cda95418e 100644 --- a/src/google/protobuf/util/internal/json_escaping.cc +++ b/src/google/protobuf/util/internal/json_escaping.cc @@ -28,12 +28,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/json_escaping.h" #include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/json_escaping.h b/src/google/protobuf/util/internal/json_escaping.h index b27f1da367..98b0e5be68 100644 --- a/src/google/protobuf/util/internal/json_escaping.h +++ b/src/google/protobuf/util/internal/json_escaping.h @@ -33,8 +33,9 @@ #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/bytestream.h" +#include "google/protobuf/port.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/json_objectwriter.cc b/src/google/protobuf/util/internal/json_objectwriter.cc index 376cc4deb9..ad9f5a12aa 100644 --- a/src/google/protobuf/util/internal/json_objectwriter.cc +++ b/src/google/protobuf/util/internal/json_objectwriter.cc @@ -28,20 +28,20 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/json_objectwriter.h" #include #include #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/base/casts.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include -#include +#include "google/protobuf/util/internal/json_escaping.h" +#include "google/protobuf/util/internal/utility.h" namespace google { diff --git a/src/google/protobuf/util/internal/json_objectwriter.h b/src/google/protobuf/util/internal/json_objectwriter.h index 23d36e4673..443cdb491f 100644 --- a/src/google/protobuf/util/internal/json_objectwriter.h +++ b/src/google/protobuf/util/internal/json_objectwriter.h @@ -35,12 +35,12 @@ #include #include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/stubs/bytestream.h" +#include "google/protobuf/util/internal/structured_objectwriter.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on namespace google { @@ -274,6 +274,6 @@ class PROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_OBJECTWRITER_H__ diff --git a/src/google/protobuf/util/internal/json_objectwriter_test.cc b/src/google/protobuf/util/internal/json_objectwriter_test.cc index 8acf2c59fd..33b24de2ca 100644 --- a/src/google/protobuf/util/internal/json_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/json_objectwriter_test.cc @@ -28,13 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/json_objectwriter.h" #include -#include +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include -#include +#include "google/protobuf/util/internal/utility.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/json_stream_parser.cc b/src/google/protobuf/util/internal/json_stream_parser.cc index e7990bbb67..eccedb9d84 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.cc +++ b/src/google/protobuf/util/internal/json_stream_parser.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/json_stream_parser.h" #include #include @@ -37,16 +37,16 @@ #include #include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/status/status.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include -#include +#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/internal/json_escaping.h" namespace google { diff --git a/src/google/protobuf/util/internal/json_stream_parser.h b/src/google/protobuf/util/internal/json_stream_parser.h index 0e3d9ff3bb..9f30a057aa 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.h +++ b/src/google/protobuf/util/internal/json_stream_parser.h @@ -35,13 +35,14 @@ #include #include -#include +#include "google/protobuf/stubs/common.h" #include "absl/status/status.h" +#include "google/protobuf/port.h" #include "absl/strings/string_view.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -346,6 +347,6 @@ class PROTOBUF_EXPORT JsonStreamParser { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_STREAM_PARSER_H__ diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index 06636b8458..9d3fd4c958 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -28,18 +28,18 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/json_stream_parser.h" #include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/util/internal/expecting_objectwriter.h" #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/time/time.h" -#include +#include "google/protobuf/util/internal/object_writer.h" namespace google { diff --git a/src/google/protobuf/util/internal/location_tracker.h b/src/google/protobuf/util/internal/location_tracker.h index a0c4bad397..4cec03ec82 100644 --- a/src/google/protobuf/util/internal/location_tracker.h +++ b/src/google/protobuf/util/internal/location_tracker.h @@ -33,10 +33,10 @@ #include -#include +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -66,6 +66,6 @@ class PROTOBUF_EXPORT LocationTrackerInterface { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_LOCATION_TRACKER_H__ diff --git a/src/google/protobuf/util/internal/mock_error_listener.h b/src/google/protobuf/util/internal/mock_error_listener.h index b90b7a0f5c..b04de6ff09 100644 --- a/src/google/protobuf/util/internal/mock_error_listener.h +++ b/src/google/protobuf/util/internal/mock_error_listener.h @@ -33,8 +33,8 @@ #include #include "absl/strings/string_view.h" -#include -#include +#include "google/protobuf/util/internal/error_listener.h" +#include "google/protobuf/util/internal/location_tracker.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/object_location_tracker.h b/src/google/protobuf/util/internal/object_location_tracker.h index 05abc56626..c5a8f27b75 100644 --- a/src/google/protobuf/util/internal/object_location_tracker.h +++ b/src/google/protobuf/util/internal/object_location_tracker.h @@ -33,8 +33,8 @@ #include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/location_tracker.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/object_source.h b/src/google/protobuf/util/internal/object_source.h index 229e8d9748..2538314859 100644 --- a/src/google/protobuf/util/internal/object_source.h +++ b/src/google/protobuf/util/internal/object_source.h @@ -31,13 +31,13 @@ #ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_SOURCE_H__ #define GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_SOURCE_H__ -#include #include "absl/status/status.h" #include "absl/strings/string_view.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -78,6 +78,6 @@ class PROTOBUF_EXPORT ObjectSource { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_SOURCE_H__ diff --git a/src/google/protobuf/util/internal/object_writer.cc b/src/google/protobuf/util/internal/object_writer.cc index 680b8944aa..c03c19593e 100644 --- a/src/google/protobuf/util/internal/object_writer.cc +++ b/src/google/protobuf/util/internal/object_writer.cc @@ -28,9 +28,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/object_writer.h" -#include +#include "google/protobuf/util/internal/datapiece.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/object_writer.h b/src/google/protobuf/util/internal/object_writer.h index 090f55392e..a91c628f10 100644 --- a/src/google/protobuf/util/internal/object_writer.h +++ b/src/google/protobuf/util/internal/object_writer.h @@ -33,11 +33,12 @@ #include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/port.h" #include "absl/strings/string_view.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -146,6 +147,6 @@ class PROTOBUF_EXPORT ObjectWriter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_WRITER_H__ diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc index 57d6e41210..792443701f 100644 --- a/src/google/protobuf/util/internal/proto_writer.cc +++ b/src/google/protobuf/util/internal/proto_writer.cc @@ -28,14 +28,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/proto_writer.h" #include #include #include #include -#include +#include "google/protobuf/wire_format_lite.h" #include "absl/base/call_once.h" #include "absl/status/statusor.h" #include "absl/strings/ascii.h" @@ -43,14 +43,14 @@ #include "absl/strings/str_cat.h" #include "absl/time/clock.h" #include "absl/time/time.h" -#include -#include -#include -#include +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/field_mask_utility.h" +#include "google/protobuf/util/internal/object_location_tracker.h" +#include "google/protobuf/util/internal/utility.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h index 6f49c6db3f..f19b191cca 100644 --- a/src/google/protobuf/util/internal/proto_writer.h +++ b/src/google/protobuf/util/internal/proto_writer.h @@ -37,22 +37,22 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/type.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/bytestream.h" #include "absl/status/status.h" -#include -#include -#include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/datapiece.h" +#include "google/protobuf/util/internal/error_listener.h" +#include "google/protobuf/util/internal/structured_objectwriter.h" +#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/type_resolver.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -386,6 +386,6 @@ class PROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTO_WRITER_H__ diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 84c602c8b0..63a9dc1836 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -28,36 +28,36 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/protostream_objectsource.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/unknown_field_set.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stringprintf.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" -#include -#include -#include -#include +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/field_mask_utility.h" +#include "google/protobuf/util/internal/utility.h" +#include "google/protobuf/stubs/status_macros.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h index 377c6bdeaa..350966b5ec 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/src/google/protobuf/util/internal/protostream_objectsource.h @@ -37,19 +37,20 @@ #include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/type.pb.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/object_source.h" +#include "google/protobuf/util/internal/object_writer.h" +#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/type_resolver.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -319,6 +320,6 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTOSTREAM_OBJECTSOURCE_H__ diff --git a/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/src/google/protobuf/util/internal/protostream_objectsource_test.cc index e36785ff25..4fde30b19f 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource_test.cc @@ -28,30 +28,30 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/protostream_objectsource.h" #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/any.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/util/internal/expecting_objectwriter.h" #include #include "absl/base/casts.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/testdata/anys.pb.h" +#include "google/protobuf/util/internal/testdata/books.pb.h" +#include "google/protobuf/util/internal/testdata/field_mask.pb.h" +#include "google/protobuf/util/internal/testdata/maps.pb.h" +#include "google/protobuf/util/internal/testdata/proto3.pb.h" +#include "google/protobuf/util/internal/testdata/struct.pb.h" +#include "google/protobuf/util/internal/testdata/timestamp_duration.pb.h" +#include "google/protobuf/util/internal/type_info_test_helper.h" namespace google { diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc index 476d6f4cd1..677647e5ec 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/protostream_objectwriter.h" #include #include @@ -36,22 +36,22 @@ #include #include -#include -#include +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/base/call_once.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/strip.h" #include "absl/time/time.h" -#include -#include -#include -#include +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/field_mask_utility.h" +#include "google/protobuf/util/internal/object_location_tracker.h" +#include "google/protobuf/util/internal/utility.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.h b/src/google/protobuf/util/internal/protostream_objectwriter.h index eef475e191..95fedf891d 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.h +++ b/src/google/protobuf/util/internal/protostream_objectwriter.h @@ -36,25 +36,25 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/type.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/bytestream.h" #include "absl/container/flat_hash_set.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/datapiece.h" +#include "google/protobuf/util/internal/error_listener.h" +#include "google/protobuf/util/internal/proto_writer.h" +#include "google/protobuf/util/internal/structured_objectwriter.h" +#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/type_resolver.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -452,6 +452,6 @@ class PROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTOSTREAM_OBJECTWRITER_H__ diff --git a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc index 672bf8b720..640085ff79 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc @@ -28,36 +28,36 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/protostream_objectwriter.h" #include // For size_t -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/field_mask.pb.h" +#include "google/protobuf/timestamp.pb.h" +#include "google/protobuf/type.pb.h" +#include "google/protobuf/wrappers.pb.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/message.h" +#include "google/protobuf/util/internal/mock_error_listener.h" +#include "google/protobuf/stubs/bytestream.h" #include #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/testdata/anys.pb.h" +#include "google/protobuf/util/internal/testdata/books.pb.h" +#include "google/protobuf/util/internal/testdata/field_mask.pb.h" +#include "google/protobuf/util/internal/testdata/maps.pb.h" +#include "google/protobuf/util/internal/testdata/oneofs.pb.h" +#include "google/protobuf/util/internal/testdata/proto3.pb.h" +#include "google/protobuf/util/internal/testdata/struct.pb.h" +#include "google/protobuf/util/internal/testdata/timestamp_duration.pb.h" +#include "google/protobuf/util/internal/testdata/wrappers.pb.h" +#include "google/protobuf/util/internal/type_info_test_helper.h" +#include "google/protobuf/util/message_differencer.h" +#include "google/protobuf/util/type_resolver_util.h" namespace google { diff --git a/src/google/protobuf/util/internal/structured_objectwriter.h b/src/google/protobuf/util/internal/structured_objectwriter.h index c9129e5dcc..9fe59e3a3f 100644 --- a/src/google/protobuf/util/internal/structured_objectwriter.h +++ b/src/google/protobuf/util/internal/structured_objectwriter.h @@ -33,13 +33,12 @@ #include -#include #include "absl/base/casts.h" -#include -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/internal/object_writer.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -119,6 +118,6 @@ class PROTOBUF_EXPORT StructuredObjectWriter : public ObjectWriter { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_STRUCTURED_OBJECTWRITER_H__ diff --git a/src/google/protobuf/util/internal/type_info.cc b/src/google/protobuf/util/internal/type_info.cc index bb11d76fc0..927fb939ed 100644 --- a/src/google/protobuf/util/internal/type_info.cc +++ b/src/google/protobuf/util/internal/type_info.cc @@ -28,17 +28,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/type_info.h" #include #include -#include -#include +#include "google/protobuf/type.pb.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/util/internal/utility.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/type_info.h b/src/google/protobuf/util/internal/type_info.h index d224071081..801bfba1fc 100644 --- a/src/google/protobuf/util/internal/type_info.h +++ b/src/google/protobuf/util/internal/type_info.h @@ -31,16 +31,16 @@ #ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_TYPE_INFO_H__ #define GOOGLE_PROTOBUF_UTIL_INTERNAL_TYPE_INFO_H__ -#include -#include +#include "google/protobuf/type.pb.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/port.h" +#include "google/protobuf/util/type_resolver.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -92,6 +92,6 @@ class PROTOBUF_EXPORT TypeInfo { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_TYPE_INFO_H__ diff --git a/src/google/protobuf/util/internal/type_info_test_helper.cc b/src/google/protobuf/util/internal/type_info_test_helper.cc index 088f4127c7..e73efaea9b 100644 --- a/src/google/protobuf/util/internal/type_info_test_helper.cc +++ b/src/google/protobuf/util/internal/type_info_test_helper.cc @@ -28,21 +28,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/type_info_test_helper.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/util/internal/constants.h" +#include "google/protobuf/util/internal/default_value_objectwriter.h" +#include "google/protobuf/util/internal/protostream_objectsource.h" +#include "google/protobuf/util/internal/protostream_objectwriter.h" +#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/type_resolver.h" +#include "google/protobuf/util/type_resolver_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/type_info_test_helper.h b/src/google/protobuf/util/internal/type_info_test_helper.h index 1110a34ec2..9999c2c8b8 100644 --- a/src/google/protobuf/util/internal/type_info_test_helper.h +++ b/src/google/protobuf/util/internal/type_info_test_helper.h @@ -34,13 +34,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/util/internal/default_value_objectwriter.h" +#include "google/protobuf/util/internal/protostream_objectsource.h" +#include "google/protobuf/util/internal/protostream_objectwriter.h" +#include "google/protobuf/util/internal/type_info.h" +#include "google/protobuf/util/type_resolver.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc index bbb96f1512..f8054ca728 100644 --- a/src/google/protobuf/util/internal/utility.cc +++ b/src/google/protobuf/util/internal/utility.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/internal/utility.h" #include #include @@ -36,21 +36,21 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/callback.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/wrappers.pb.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include +#include "google/protobuf/util/internal/constants.h" // must be last -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/internal/utility.h b/src/google/protobuf/util/internal/utility.h index fe429ac178..552873d6ea 100644 --- a/src/google/protobuf/util/internal/utility.h +++ b/src/google/protobuf/util/internal/utility.h @@ -36,12 +36,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/any.pb.h" +#include "google/protobuf/type.pb.h" +#include "google/protobuf/repeated_field.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -49,7 +49,7 @@ // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -202,6 +202,6 @@ PROTOBUF_EXPORT bool SafeStrToFloat(absl::string_view str, float* value); } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_UTILITY_H__ diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc index 92277285d1..8df47333ee 100644 --- a/src/google/protobuf/util/json_util.cc +++ b/src/google/protobuf/util/json_util.cc @@ -28,30 +28,29 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/json_util.h" -#include #include "absl/base/call_once.h" #include "absl/status/status.h" -#include +#include "google/protobuf/stubs/bytestream.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_sink.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/util/internal/default_value_objectwriter.h" +#include "google/protobuf/util/internal/error_listener.h" +#include "google/protobuf/util/internal/json_objectwriter.h" +#include "google/protobuf/util/internal/json_stream_parser.h" +#include "google/protobuf/util/internal/protostream_objectsource.h" +#include "google/protobuf/util/internal/protostream_objectwriter.h" +#include "google/protobuf/util/type_resolver.h" +#include "google/protobuf/util/type_resolver_util.h" +#include "google/protobuf/stubs/status_macros.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h index 8387120825..5ee4f83ed0 100644 --- a/src/google/protobuf/util/json_util.h +++ b/src/google/protobuf/util/json_util.h @@ -34,14 +34,14 @@ #define GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__ -#include +#include "google/protobuf/stubs/bytestream.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" -#include -#include +#include "google/protobuf/message.h" +#include "google/protobuf/util/type_resolver.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -192,6 +192,6 @@ inline absl::Status JsonToBinaryString(TypeResolver* resolver, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__ diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 714d4f1337..3f18431fee 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/json_util.h" #include #include @@ -37,33 +37,33 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/duration.pb.h" +#include "google/protobuf/field_mask.pb.h" +#include "google/protobuf/struct.pb.h" +#include "google/protobuf/timestamp.pb.h" +#include "google/protobuf/wrappers.pb.h" +#include "google/protobuf/unittest.pb.h" #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor_database.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/util/internal/testdata/maps.pb.h" +#include "google/protobuf/util/json_format.pb.h" +#include "google/protobuf/util/json_format.pb.h" +#include "google/protobuf/util/json_format_proto3.pb.h" +#include "google/protobuf/util/json_format_proto3.pb.h" +#include "google/protobuf/util/type_resolver.h" +#include "google/protobuf/util/type_resolver_util.h" +#include "google/protobuf/stubs/status_macros.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" bool IsJson2() { // Pay no attention to the person behind the curtain. diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index dd19ce104d..51b2bea3be 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/util/message_differencer.h" #include #include @@ -42,26 +42,27 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/generated_enum_reflection.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/message.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/stubs/strutil.h" +#include "absl/container/fixed_array.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include -#include +#include "google/protobuf/stubs/stringprintf.h" +#include "google/protobuf/util/field_comparator.h" // Always include as last one, otherwise it can break compilation -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index 65bde8d427..7d1e6acbde 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -51,13 +51,14 @@ #include #include -#include // FieldDescriptor -#include // Message -#include -#include +#include "google/protobuf/descriptor.h" // FieldDescriptor +#include "google/protobuf/message.h" // Message +#include "google/protobuf/unknown_field_set.h" +#include "absl/container/fixed_array.h" +#include "google/protobuf/util/field_comparator.h" // Always include as last one, otherwise it can break compilation -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -79,7 +80,7 @@ class FieldContext; // declared below MessageDifferencer // In case of internal google codebase we are using absl::FixedArray instead // of vector. It significantly speeds up proto comparison (by ~30%) by // reducing the number of malloc/free operations -typedef std::vector FieldDescriptorArray; +typedef absl::FixedArray FieldDescriptorArray; // A basic differencer that can be used to determine // the differences between two specified Protocol Messages. If any differences @@ -975,6 +976,6 @@ class PROTOBUF_EXPORT FieldContext { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_MESSAGE_DIFFERENCER_H__ diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index af638f6f9e..93a4553538 100644 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -39,25 +39,25 @@ #include #include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" + +#include "google/protobuf/stubs/strutil.h" + +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/any_test.pb.h" +#include "google/protobuf/map_test_util.h" +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/test_util.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/util/field_comparator.h" +#include "google/protobuf/util/message_differencer.h" +#include "google/protobuf/testing/googletest.h" #include #include "absl/functional/bind_front.h" #include "absl/strings/str_split.h" -#include +#include "google/protobuf/util/message_differencer_unittest.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/time_util.cc b/src/google/protobuf/util/time_util.cc index 9b14eca474..94154a0e3c 100644 --- a/src/google/protobuf/util/time_util.cc +++ b/src/google/protobuf/util/time_util.cc @@ -28,21 +28,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/time_util.h" #include -#include -#include -#include -#include +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/duration.pb.h" +#include "google/protobuf/timestamp.pb.h" +#include "absl/numeric/int128.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stringprintf.h" #include "absl/time/clock.h" #include "absl/time/time.h" // Must go after other includes. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -443,7 +443,7 @@ using ::PROTOBUF_NAMESPACE_ID::util::CreateNormalized; using ::PROTOBUF_NAMESPACE_ID::util::kNanosPerSecond; // Convert a Duration to uint128. -void ToUint128(const Duration& value, uint128* result, bool* negative) { +void ToUint128(const Duration& value, absl::uint128* result, bool* negative) { if (value.seconds() < 0 || value.nanos() < 0) { *negative = true; *result = static_cast(-value.seconds()); @@ -455,11 +455,11 @@ void ToUint128(const Duration& value, uint128* result, bool* negative) { } } -void ToDuration(const uint128& value, bool negative, Duration* duration) { +void ToDuration(const absl::uint128& value, bool negative, Duration* duration) { int64_t seconds = - static_cast(Uint128Low64(value / kNanosPerSecond)); + static_cast(absl::Uint128Low64(value / kNanosPerSecond)); int32_t nanos = - static_cast(Uint128Low64(value % kNanosPerSecond)); + static_cast(absl::Uint128Low64(value % kNanosPerSecond)); if (negative) { seconds = -seconds; nanos = -nanos; @@ -483,7 +483,7 @@ Duration& operator-=(Duration& d1, const Duration& d2) { // NOLINT Duration& operator*=(Duration& d, int64_t r) { // NOLINT bool negative; - uint128 value; + absl::uint128 value; ToUint128(d, &value, &negative); if (r > 0) { value *= static_cast(r); @@ -512,7 +512,7 @@ Duration& operator*=(Duration& d, double r) { // NOLINT Duration& operator/=(Duration& d, int64_t r) { // NOLINT bool negative; - uint128 value; + absl::uint128 value; ToUint128(d, &value, &negative); if (r > 0) { value /= static_cast(r); @@ -530,10 +530,10 @@ Duration& operator/=(Duration& d, double r) { // NOLINT Duration& operator%=(Duration& d1, const Duration& d2) { // NOLINT bool negative1, negative2; - uint128 value1, value2; + absl::uint128 value1, value2; ToUint128(d1, &value1, &negative1); ToUint128(d2, &value2, &negative2); - uint128 result = value1 % value2; + absl::uint128 result = value1 % value2; // When negative values are involved in division, we round the division // result towards zero. With this semantics, sign of the remainder is the // same as the dividend. For example: @@ -546,10 +546,10 @@ Duration& operator%=(Duration& d1, const Duration& d2) { // NOLINT int64_t operator/(const Duration& d1, const Duration& d2) { bool negative1, negative2; - uint128 value1, value2; + absl::uint128 value1, value2; ToUint128(d1, &value1, &negative1); ToUint128(d2, &value2, &negative2); - int64_t result = Uint128Low64(value1 / value2); + int64_t result = absl::Uint128Low64(value1 / value2); if (negative1 != negative2) { result = -result; } diff --git a/src/google/protobuf/util/time_util.h b/src/google/protobuf/util/time_util.h index c4d3e3001a..c272199918 100644 --- a/src/google/protobuf/util/time_util.h +++ b/src/google/protobuf/util/time_util.h @@ -50,11 +50,11 @@ struct timeval { #include #endif -#include -#include +#include "google/protobuf/duration.pb.h" +#include "google/protobuf/timestamp.pb.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -326,6 +326,6 @@ inline std::ostream& operator<<(std::ostream& out, const Timestamp& t) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__ diff --git a/src/google/protobuf/util/time_util_test.cc b/src/google/protobuf/util/time_util_test.cc index f4add50d8f..464e57b4ee 100644 --- a/src/google/protobuf/util/time_util_test.cc +++ b/src/google/protobuf/util/time_util_test.cc @@ -28,14 +28,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/time_util.h" #include #include -#include -#include -#include +#include "google/protobuf/duration.pb.h" +#include "google/protobuf/timestamp.pb.h" +#include "google/protobuf/testing/googletest.h" #include namespace google { diff --git a/src/google/protobuf/util/type_resolver.h b/src/google/protobuf/util/type_resolver.h index 77de2340dd..f5c3338a45 100644 --- a/src/google/protobuf/util/type_resolver.h +++ b/src/google/protobuf/util/type_resolver.h @@ -35,13 +35,13 @@ #include -#include -#include +#include "google/protobuf/type.pb.h" #include "absl/status/status.h" +#include "google/protobuf/port.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -71,6 +71,6 @@ class PROTOBUF_EXPORT TypeResolver { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_H__ diff --git a/src/google/protobuf/util/type_resolver_util.cc b/src/google/protobuf/util/type_resolver_util.cc index 8de463789a..49ae2d31c4 100644 --- a/src/google/protobuf/util/type_resolver_util.cc +++ b/src/google/protobuf/util/type_resolver_util.cc @@ -28,21 +28,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/type_resolver_util.h" -#include -#include -#include -#include -#include +#include "google/protobuf/type.pb.h" +#include "google/protobuf/wrappers.pb.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/stubs/strutil.h" #include "absl/status/status.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include -#include +#include "google/protobuf/util/internal/utility.h" +#include "google/protobuf/util/type_resolver.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on namespace google { diff --git a/src/google/protobuf/util/type_resolver_util.h b/src/google/protobuf/util/type_resolver_util.h index 7f6a4b9b11..f8e9c194cc 100644 --- a/src/google/protobuf/util/type_resolver_util.h +++ b/src/google/protobuf/util/type_resolver_util.h @@ -42,7 +42,7 @@ namespace util { class TypeResolver; // Must be included last. -#include +#include "google/protobuf/port_def.inc" // Creates a TypeResolver that serves type information in the given descriptor // pool. Caller takes ownership of the returned TypeResolver. @@ -53,6 +53,6 @@ PROTOBUF_EXPORT TypeResolver* NewTypeResolverForDescriptorPool( } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_UTIL_H__ diff --git a/src/google/protobuf/util/type_resolver_util_test.cc b/src/google/protobuf/util/type_resolver_util_test.cc index f7b29889b5..d926541980 100644 --- a/src/google/protobuf/util/type_resolver_util_test.cc +++ b/src/google/protobuf/util/type_resolver_util_test.cc @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "google/protobuf/util/type_resolver_util.h" #include #include @@ -36,16 +36,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/type.pb.h" +#include "google/protobuf/wrappers.pb.h" +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/test_util.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_custom_options.pb.h" +#include "google/protobuf/util/type_resolver.h" +#include "google/protobuf/testing/googletest.h" #include -#include +#include "google/protobuf/util/json_format_proto3.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/well_known_types_unittest.cc b/src/google/protobuf/well_known_types_unittest.cc index c9a9aa10ec..2cc25b5b54 100644 --- a/src/google/protobuf/well_known_types_unittest.cc +++ b/src/google/protobuf/well_known_types_unittest.cc @@ -27,12 +27,12 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include - -#include -#include #include -#include + +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/stl_util.h" +#include "google/protobuf/testing/googletest.h" +#include "google/protobuf/unittest_well_known_types.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/wire_format.cc b/src/google/protobuf/wire_format.cc index e44c6ebeee..e42d44a9f7 100644 --- a/src/google/protobuf/wire_format.cc +++ b/src/google/protobuf/wire_format.cc @@ -32,30 +32,30 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/wire_format.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/map_field.h" +#include "google/protobuf/map_field_inl.h" +#include "google/protobuf/message.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/unknown_field_set.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" const size_t kMapEntryTagByteSize = 2; @@ -1755,4 +1755,4 @@ size_t ComputeUnknownFieldsSize(const InternalMetadata& metadata, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h index 2227521df0..027fcb35de 100644 --- a/src/google/protobuf/wire_format.h +++ b/src/google/protobuf/wire_format.h @@ -40,22 +40,23 @@ #define GOOGLE_PROTOBUF_WIRE_FORMAT_H__ -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" #include "absl/base/casts.h" -#include -#include -#include -#include -#include -#include +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/message.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/parse_context.h" +#include "google/protobuf/port.h" +#include "google/protobuf/wire_format_lite.h" #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -410,6 +411,6 @@ uint8_t* SerializeMapKeyWithCachedSizes(const FieldDescriptor* field, } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_H__ diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index ce78639e47..612ae40c69 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -32,24 +32,24 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/wire_format_lite.h" #include #include #include #include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "absl/strings/str_cat.h" -#include +#include "google/protobuf/stubs/stringprintf.h" // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -816,4 +816,4 @@ size_t WireFormatLite::SInt64Size(const RepeatedField& value) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index f52cc3f449..5f5dd80f8a 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -44,14 +44,15 @@ #include #include -#include -#include -#include -#include +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/port.h" #include "absl/base/casts.h" -#include -#include -#include +#include "google/protobuf/arenastring.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/port.h" +#include "google/protobuf/repeated_field.h" #ifndef NDEBUG #define GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED @@ -69,7 +70,7 @@ // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -1896,6 +1897,6 @@ bool ParseMessageSetItemImpl(io::CodedInputStream* input, MS ms) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ diff --git a/src/google/protobuf/wire_format_unittest.cc b/src/google/protobuf/wire_format_unittest.cc index f1ed951c79..f51cf53e14 100644 --- a/src/google/protobuf/wire_format_unittest.cc +++ b/src/google/protobuf/wire_format_unittest.cc @@ -32,12 +32,12 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include +#include "google/protobuf/wire_format.h" -#include -#include -#include -#include +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_mset.pb.h" +#include "google/protobuf/unittest_mset_wire_format.pb.h" +#include "google/protobuf/unittest_proto3_arena.pb.h" #include #include @@ -49,12 +49,12 @@ // Must include after defining UNITTEST, etc. // clang-format off -#include -#include +#include "google/protobuf/test_util.inc" +#include "google/protobuf/wire_format_unittest.inc" // clang-format on // Must be included last. -#include +#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { @@ -67,4 +67,4 @@ namespace { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/wire_format_unittest.inc b/src/google/protobuf/wire_format_unittest.inc index 871a7035c2..c2d2a00afd 100644 --- a/src/google/protobuf/wire_format_unittest.inc +++ b/src/google/protobuf/wire_format_unittest.inc @@ -32,26 +32,26 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/common.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" #include -#include +#include "google/protobuf/testing/googletest.h" #include #include "absl/base/casts.h" -#include -#include -#include -#include -#include +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/stubs/stl_util.h" // clang-format off -#include +#include "google/protobuf/port_def.inc" // clang-format on namespace google { @@ -1620,4 +1620,4 @@ TEST(RepeatedVarint, Enum) { } // namespace protobuf } // namespace google -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index e68627fb41..cc9048b047 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -5,15 +5,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" PROTOBUF_PRAGMA_INIT_SEG @@ -1994,4 +1994,4 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::BytesValue >(Arena* arena) { PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include +#include "google/protobuf/port_undef.inc" diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 53d1c294ff..3fbb1a666a 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -1,13 +1,13 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh #include #include -#include +#include "google/protobuf/port_def.inc" #if PROTOBUF_VERSION < 3021000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update @@ -19,19 +19,19 @@ #error regenerate this file with a newer version of protoc. #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" // @@protoc_insertion_point(includes) -#include +#include "google/protobuf/port_def.inc" #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fwrappers_2eproto PROTOBUF_EXPORT PROTOBUF_NAMESPACE_OPEN namespace internal { @@ -1451,7 +1451,7 @@ inline double DoubleValue::value() const { return _internal_value(); } inline void DoubleValue::_internal_set_value(double value) { - + _impl_.value_ = value; } inline void DoubleValue::set_value(double value) { @@ -1475,7 +1475,7 @@ inline float FloatValue::value() const { return _internal_value(); } inline void FloatValue::_internal_set_value(float value) { - + _impl_.value_ = value; } inline void FloatValue::set_value(float value) { @@ -1499,7 +1499,7 @@ inline int64_t Int64Value::value() const { return _internal_value(); } inline void Int64Value::_internal_set_value(int64_t value) { - + _impl_.value_ = value; } inline void Int64Value::set_value(int64_t value) { @@ -1523,7 +1523,7 @@ inline uint64_t UInt64Value::value() const { return _internal_value(); } inline void UInt64Value::_internal_set_value(uint64_t value) { - + _impl_.value_ = value; } inline void UInt64Value::set_value(uint64_t value) { @@ -1547,7 +1547,7 @@ inline int32_t Int32Value::value() const { return _internal_value(); } inline void Int32Value::_internal_set_value(int32_t value) { - + _impl_.value_ = value; } inline void Int32Value::set_value(int32_t value) { @@ -1571,7 +1571,7 @@ inline uint32_t UInt32Value::value() const { return _internal_value(); } inline void UInt32Value::_internal_set_value(uint32_t value) { - + _impl_.value_ = value; } inline void UInt32Value::set_value(uint32_t value) { @@ -1595,7 +1595,7 @@ inline bool BoolValue::value() const { return _internal_value(); } inline void BoolValue::_internal_set_value(bool value) { - + _impl_.value_ = value; } inline void BoolValue::set_value(bool value) { @@ -1631,11 +1631,11 @@ inline const std::string& StringValue::_internal_value() const { return _impl_.value_.Get(); } inline void StringValue::_internal_set_value(const std::string& value) { - + _impl_.value_.Set(value, GetArenaForAllocation()); } inline std::string* StringValue::_internal_mutable_value() { - + return _impl_.value_.Mutable(GetArenaForAllocation()); } inline std::string* StringValue::release_value() { @@ -1644,9 +1644,9 @@ inline std::string* StringValue::release_value() { } inline void StringValue::set_allocated_value(std::string* value) { if (value != nullptr) { - + } else { - + } _impl_.value_.SetAllocated(value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1685,11 +1685,11 @@ inline const std::string& BytesValue::_internal_value() const { return _impl_.value_.Get(); } inline void BytesValue::_internal_set_value(const std::string& value) { - + _impl_.value_.Set(value, GetArenaForAllocation()); } inline std::string* BytesValue::_internal_mutable_value() { - + return _impl_.value_.Mutable(GetArenaForAllocation()); } inline std::string* BytesValue::release_value() { @@ -1698,9 +1698,9 @@ inline std::string* BytesValue::release_value() { } inline void BytesValue::set_allocated_value(std::string* value) { if (value != nullptr) { - + } else { - + } _impl_.value_.SetAllocated(value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -1737,5 +1737,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto +#include "google/protobuf/port_undef.inc" +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh