Merge pull request #10462 from mkruskal-google/sync-stage

Integrate from Piper for C++, Java, and Python
pull/10464/head
Mike Kruskal 3 years ago committed by GitHub
commit 3322c0b92a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      cmake/tests.cmake
  2. 6
      python/google/protobuf/pyext/scoped_pyobject_ptr.h
  3. 9
      python/setup.py
  4. 2
      src/file_lists.cmake
  5. 4
      src/google/protobuf/any.h
  6. 2
      src/google/protobuf/arena.h
  7. 22
      src/google/protobuf/arena_impl.h
  8. 17
      src/google/protobuf/arena_unittest.cc
  9. 7
      src/google/protobuf/compiler/BUILD.bazel
  10. 3
      src/google/protobuf/compiler/code_generator.cc
  11. 14
      src/google/protobuf/compiler/code_generator.h
  12. 26
      src/google/protobuf/compiler/command_line_interface.cc
  13. 4
      src/google/protobuf/compiler/command_line_interface.h
  14. 19
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  15. 1
      src/google/protobuf/compiler/cpp/BUILD.bazel
  16. 4
      src/google/protobuf/compiler/cpp/bootstrap_unittest.cc
  17. 1
      src/google/protobuf/compiler/cpp/extension.cc
  18. 16
      src/google/protobuf/compiler/cpp/field.cc
  19. 4
      src/google/protobuf/compiler/cpp/file.cc
  20. 1
      src/google/protobuf/compiler/cpp/generator.cc
  21. 9
      src/google/protobuf/compiler/cpp/helpers.cc
  22. 3
      src/google/protobuf/compiler/cpp/helpers.h
  23. 4
      src/google/protobuf/compiler/cpp/map_field.cc
  24. 36
      src/google/protobuf/compiler/cpp/message.cc
  25. 4
      src/google/protobuf/compiler/cpp/unittest.inc
  26. 24
      src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
  27. 6
      src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
  28. 14
      src/google/protobuf/compiler/csharp/csharp_enum.cc
  29. 10
      src/google/protobuf/compiler/csharp/csharp_enum_field.cc
  30. 19
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  31. 4
      src/google/protobuf/compiler/csharp/csharp_field_base.h
  32. 14
      src/google/protobuf/compiler/csharp/csharp_generator.cc
  33. 5
      src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
  34. 27
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  35. 8
      src/google/protobuf/compiler/csharp/csharp_helpers.h
  36. 14
      src/google/protobuf/compiler/csharp/csharp_map_field.cc
  37. 26
      src/google/protobuf/compiler/csharp/csharp_message.cc
  38. 16
      src/google/protobuf/compiler/csharp/csharp_message_field.cc
  39. 2
      src/google/protobuf/compiler/csharp/csharp_names.h
  40. 14
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
  41. 22
      src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
  42. 10
      src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
  43. 10
      src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
  44. 10
      src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
  45. 10
      src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
  46. 10
      src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
  47. 33
      src/google/protobuf/compiler/importer.cc
  48. 22
      src/google/protobuf/compiler/importer.h
  49. 6
      src/google/protobuf/compiler/importer_unittest.cc
  50. 3
      src/google/protobuf/compiler/java/BUILD.bazel
  51. 3
      src/google/protobuf/compiler/java/doc_comment.cc
  52. 2
      src/google/protobuf/compiler/java/field.cc
  53. 123
      src/google/protobuf/compiler/java/helpers.cc
  54. 3
      src/google/protobuf/compiler/java/helpers.h
  55. 14
      src/google/protobuf/compiler/java/message.cc
  56. 6
      src/google/protobuf/compiler/java/message_builder.cc
  57. 2
      src/google/protobuf/compiler/java/message_builder_lite.cc
  58. 12
      src/google/protobuf/compiler/java/message_lite.cc
  59. 5
      src/google/protobuf/compiler/java/message_serialization_unittest.cc
  60. 9
      src/google/protobuf/compiler/java/name_resolver.cc
  61. 4
      src/google/protobuf/compiler/java/plugin_unittest.cc
  62. 2
      src/google/protobuf/compiler/java/primitive_field_lite.cc
  63. 15
      src/google/protobuf/compiler/mock_code_generator.cc
  64. 7
      src/google/protobuf/compiler/objectivec/objectivec_enum.cc
  65. 4
      src/google/protobuf/compiler/objectivec/objectivec_extension.cc
  66. 4
      src/google/protobuf/compiler/objectivec/objectivec_field.cc
  67. 4
      src/google/protobuf/compiler/objectivec/objectivec_file.cc
  68. 10
      src/google/protobuf/compiler/objectivec/objectivec_generator.cc
  69. 29
      src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
  70. 2
      src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
  71. 6
      src/google/protobuf/compiler/objectivec/objectivec_message.cc
  72. 4
      src/google/protobuf/compiler/objectivec/objectivec_oneof.cc
  73. 4
      src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
  74. 2
      src/google/protobuf/compiler/parser.cc
  75. 4
      src/google/protobuf/compiler/parser.h
  76. 8
      src/google/protobuf/compiler/parser_unittest.cc
  77. 34
      src/google/protobuf/compiler/php/php_generator.cc
  78. 2
      src/google/protobuf/compiler/python/BUILD.bazel
  79. 10
      src/google/protobuf/compiler/python/generator.cc
  80. 4
      src/google/protobuf/compiler/python/generator.h
  81. 3
      src/google/protobuf/compiler/python/helpers.cc
  82. 1
      src/google/protobuf/compiler/python/helpers.h
  83. 4
      src/google/protobuf/compiler/python/plugin_unittest.cc
  84. 8
      src/google/protobuf/compiler/python/pyi_generator.cc
  85. 3
      src/google/protobuf/compiler/python/pyi_generator.h
  86. 4
      src/google/protobuf/compiler/ruby/ruby_generator.cc
  87. 5
      src/google/protobuf/compiler/scc.h
  88. 8
      src/google/protobuf/compiler/subprocess.cc
  89. 131
      src/google/protobuf/descriptor.cc
  90. 60
      src/google/protobuf/descriptor.h
  91. 1
      src/google/protobuf/descriptor_database.cc
  92. 20
      src/google/protobuf/descriptor_database.h
  93. 31
      src/google/protobuf/descriptor_unittest.cc
  94. 3
      src/google/protobuf/dynamic_message.cc
  95. 4
      src/google/protobuf/dynamic_message.h
  96. 8
      src/google/protobuf/extension_set.h
  97. 6
      src/google/protobuf/generated_message_tctable_impl.h
  98. 115
      src/google/protobuf/generated_message_tctable_lite.cc
  99. 3
      src/google/protobuf/implicit_weak_message.h
  100. 7
      src/google/protobuf/io/coded_stream.h
  101. Some files were not shown because too many files have changed in this diff Show More

@ -144,7 +144,12 @@ set(test_plugin_files
add_executable(test_plugin ${test_plugin_files})
target_include_directories(test_plugin PRIVATE ${ABSL_ROOT_DIR})
target_link_libraries(test_plugin ${protobuf_LIB_PROTOC} ${protobuf_LIB_PROTOBUF} GTest::gmock)
target_link_libraries(test_plugin
${protobuf_LIB_PROTOC}
${protobuf_LIB_PROTOBUF}
${protobuf_ABSL_USED_TARGETS}
GTest::gmock
)
add_executable(lite-test ${protobuf_lite_test_files})
target_link_libraries(lite-test protobuf-lite-test-common ${protobuf_LIB_PROTOBUF_LITE} GTest::gmock_main)

@ -33,8 +33,6 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__
#include <google/protobuf/stubs/common.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
namespace google {
@ -50,6 +48,8 @@ class ScopedPythonPtr {
// The reference count of the specified py_object is not incremented.
explicit ScopedPythonPtr(PyObjectStruct* py_object = nullptr)
: ptr_(py_object) {}
ScopedPythonPtr(const ScopedPythonPtr&) = delete;
ScopedPythonPtr& operator=(const ScopedPythonPtr&) = delete;
// If a PyObject is owned, decrement its reference count.
~ScopedPythonPtr() { Py_XDECREF(ptr_); }
@ -89,8 +89,6 @@ class ScopedPythonPtr {
private:
PyObjectStruct* ptr_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedPythonPtr);
};
typedef ScopedPythonPtr<PyObject> ScopedPyObjectPtr;

@ -298,9 +298,12 @@ if __name__ == '__main__':
else:
extra_objects = ['../libprotobuf.a']
# Repeat all of these enough times to eliminate order-dependence.
extra_objects += list(glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
extra_objects += list(glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
extra_objects += list(glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
extra_objects += list(
glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
extra_objects += list(
glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
extra_objects += list(
glob.iglob('../third_party/abseil-cpp/absl/**/*.a'))
else:
libraries = ['protobuf']
if HasLibraryDirsOpt():

@ -65,7 +65,6 @@ set(libprotobuf_srcs
${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
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/substitute.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.cc
@ -174,7 +173,6 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stl_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/substitute.h
${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.h
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.h

@ -63,6 +63,8 @@ class PROTOBUF_EXPORT AnyMetadata {
// AnyMetadata does not take ownership of "type_url" and "value".
constexpr AnyMetadata(UrlType* type_url, ValueType* value)
: type_url_(type_url), value_(value) {}
AnyMetadata(const AnyMetadata&) = delete;
AnyMetadata& operator=(const AnyMetadata&) = delete;
// Packs a message using the default type URL prefix: "type.googleapis.com".
// The resulted type URL will be "type.googleapis.com/<message_full_name>".
@ -121,8 +123,6 @@ class PROTOBUF_EXPORT AnyMetadata {
UrlType* type_url_;
ValueType* value_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AnyMetadata);
};
// Get the proto type name from Any::type_url value. For example, passing

@ -86,6 +86,7 @@ class InternalMetadata; // defined in metadata_lite.h
class LazyField; // defined in lazy_field.h
class EpsCopyInputStream; // defined in parse_context.h
class RepeatedPtrFieldBase; // defined in repeated_ptr_field.h
class TcParser; // defined in generated_message_tctable_impl.h
template <typename Type>
class GenericTypeHandler; // defined in repeated_field.h
@ -756,6 +757,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
friend class internal::InternalMetadata; // For user_arena().
friend class internal::LazyField; // For CreateMaybeMessage.
friend class internal::EpsCopyInputStream; // For parser performance
friend class internal::TcParser; // For parser performance
friend class MessageLite;
template <typename Key, typename T>
friend class Map;

@ -462,6 +462,27 @@ class PROTOBUF_EXPORT SerialArena {
return true;
}
// If there is enough space in the current block, allocate space for one `T`
// object and register for destruction. The object has not been constructed
// and the memory returned is uninitialized.
template <typename T>
PROTOBUF_ALWAYS_INLINE void* MaybeAllocateWithCleanup() {
GOOGLE_DCHECK_GE(limit_, ptr());
static_assert(!std::is_trivially_destructible<T>::value,
"This function is only for non-trivial types.");
constexpr int aligned_size = AlignUpTo8(sizeof(T));
constexpr auto destructor = cleanup::arena_destruct_object<T>;
size_t required = aligned_size + cleanup::Size(destructor);
if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) {
return nullptr;
}
void* ptr = AllocateFromExistingWithCleanupFallback(aligned_size,
alignof(T), destructor);
PROTOBUF_ASSUME(ptr != nullptr);
return ptr;
}
PROTOBUF_ALWAYS_INLINE
void* AllocateAlignedWithCleanup(size_t n, size_t align,
void (*destructor)(void*),
@ -697,6 +718,7 @@ class PROTOBUF_EXPORT ThreadSafeArena {
}
private:
friend class TcParser;
static uint64_t GetNextLifeCycleId();
// Unique for each arena. Changes on Reset().

@ -102,12 +102,13 @@ class SimpleDataType {
class PleaseDontCopyMe {
public:
explicit PleaseDontCopyMe(int value) : value_(value) {}
PleaseDontCopyMe(const PleaseDontCopyMe&) = delete;
PleaseDontCopyMe& operator=(const PleaseDontCopyMe&) = delete;
int value() const { return value_; }
private:
int value_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PleaseDontCopyMe);
};
// A class that takes four different types as constructor arguments.
@ -117,14 +118,15 @@ class MustBeConstructedWithOneThroughFour {
const std::string& three,
const PleaseDontCopyMe* four)
: one_(one), two_(two), three_(three), four_(four) {}
MustBeConstructedWithOneThroughFour(
const MustBeConstructedWithOneThroughFour&) = delete;
MustBeConstructedWithOneThroughFour& operator=(
const MustBeConstructedWithOneThroughFour&) = delete;
int one_;
const char* const two_;
std::string three_;
const PleaseDontCopyMe* four_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MustBeConstructedWithOneThroughFour);
};
// A class that takes eight different types as constructor arguments.
@ -144,6 +146,10 @@ class MustBeConstructedWithOneThroughEight {
six_(six),
seven_(seven),
eight_(eight) {}
MustBeConstructedWithOneThroughEight(
const MustBeConstructedWithOneThroughEight&) = delete;
MustBeConstructedWithOneThroughEight& operator=(
const MustBeConstructedWithOneThroughEight&) = delete;
int one_;
const char* const two_;
@ -153,9 +159,6 @@ class MustBeConstructedWithOneThroughEight {
const char* const six_;
std::string seven_;
std::string eight_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MustBeConstructedWithOneThroughEight);
};
TEST(ArenaTest, ArenaConstructable) {

@ -36,7 +36,10 @@ cc_library(
copts = COPTS,
include_prefix = "google/protobuf/compiler",
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf"],
deps = [
"//src/google/protobuf",
"@com_google_absl//absl/strings",
],
)
cc_library(
@ -57,6 +60,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//:protobuf",
"@com_google_absl//absl/strings",
],
)
@ -79,6 +83,7 @@ cc_library(
":code_generator",
":importer",
"//:protobuf",
"@com_google_absl//absl/strings",
],
)

@ -39,6 +39,7 @@
#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 {
namespace protobuf {
@ -107,7 +108,7 @@ void GeneratorContext::GetCompilerVersion(Version* version) const {
void ParseGeneratorParameter(
const std::string& text,
std::vector<std::pair<std::string, std::string> >* output) {
std::vector<std::string> parts = Split(text, ",", true);
std::vector<std::string> parts = absl::StrSplit(text, ",", absl::SkipEmpty());
for (int i = 0; i < parts.size(); i++) {
std::string::size_type equals_pos = parts[i].find_first_of('=');

@ -69,7 +69,9 @@ class GeneratorContext;
// be registered with CommandLineInterface to support various languages.
class PROTOC_EXPORT CodeGenerator {
public:
inline CodeGenerator() {}
CodeGenerator() {}
CodeGenerator(const CodeGenerator&) = delete;
CodeGenerator& operator=(const CodeGenerator&) = delete;
virtual ~CodeGenerator();
// Generates code for the given proto file, generating one or more files in
@ -120,9 +122,6 @@ class PROTOC_EXPORT CodeGenerator {
// version of the library. When protobufs does a api breaking change, the
// method can be removed.
virtual bool HasGenerateAll() const { return true; }
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator);
};
// CodeGenerators generate one or more files in a given directory. This
@ -131,8 +130,10 @@ class PROTOC_EXPORT CodeGenerator {
// runs.
class PROTOC_EXPORT GeneratorContext {
public:
inline GeneratorContext() {
GeneratorContext() {
}
GeneratorContext(const GeneratorContext&) = delete;
GeneratorContext& operator=(const GeneratorContext&) = delete;
virtual ~GeneratorContext();
// Opens the given file, truncating it if it exists, and returns a
@ -177,9 +178,6 @@ class PROTOC_EXPORT GeneratorContext {
// this GeneratorContext.
virtual void GetCompilerVersion(Version* version) const;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext);
};
// The type GeneratorContext was once called OutputDirectory. This typedef

@ -71,7 +71,9 @@
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/compiler/zip_writer.h>
@ -173,7 +175,7 @@ bool TryCreateParentDirectory(const std::string& prefix,
// Recursively create parent directories to the output file.
// On Windows, both '/' and '\' are valid path separators.
std::vector<std::string> parts =
Split(filename, "/\\", true);
absl::StrSplit(filename, absl::ByAnyChar("/\\"), absl::SkipEmpty());
std::string path_so_far = prefix;
for (int i = 0; i < parts.size() - 1; i++) {
path_so_far += parts[i];
@ -816,7 +818,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// Find the insertion point.
std::string magic_string =
strings::Substitute("@@protoc_insertion_point($0)", insertion_point_);
absl::Substitute("@@protoc_insertion_point($0)", insertion_point_);
std::string::size_type pos = target->find(magic_string);
if (pos == std::string::npos) {
@ -1701,9 +1703,9 @@ CommandLineInterface::InterpretArgument(const std::string& name,
// Java's -classpath (and some other languages) delimits path components
// with colons. Let's accept that syntax too just to make things more
// intuitive.
std::vector<std::string> parts = Split(
value, CommandLineInterface::kPathSeparator,
true);
std::vector<std::string> parts = absl::StrSplit(
value, absl::ByAnyChar(CommandLineInterface::kPathSeparator),
absl::SkipEmpty());
for (int i = 0; i < parts.size(); i++) {
std::string virtual_path;
@ -1757,7 +1759,7 @@ CommandLineInterface::InterpretArgument(const std::string& name,
direct_dependencies_explicitly_set_ = true;
std::vector<std::string> direct =
Split(value, ":", true);
absl::StrSplit(value, ":", absl::SkipEmpty());
GOOGLE_DCHECK(direct_dependencies_.empty());
direct_dependencies_.insert(direct.begin(), direct.end());
@ -1783,9 +1785,9 @@ CommandLineInterface::InterpretArgument(const std::string& name,
return PARSE_ARGUMENT_FAIL;
}
descriptor_set_in_names_ = Split(
value, CommandLineInterface::kPathSeparator,
true);
descriptor_set_in_names_ = absl::StrSplit(
value, absl::ByAnyChar(CommandLineInterface::kPathSeparator),
absl::SkipEmpty());
} else if (name == "-o" || name == "--descriptor_set_out") {
if (!descriptor_set_out_name_.empty()) {
@ -2295,7 +2297,7 @@ bool CommandLineInterface::GeneratePluginOutput(
std::string communicate_error;
if (!subprocess.Communicate(request, &response, &communicate_error)) {
*error = strings::Substitute("$0: $1", plugin_name, communicate_error);
*error = absl::Substitute("$0: $1", plugin_name, communicate_error);
return false;
}
@ -2322,7 +2324,7 @@ bool CommandLineInterface::GeneratePluginOutput(
current_output.reset();
current_output.reset(generator_context->Open(output_file.name()));
} else if (current_output == nullptr) {
*error = strings::Substitute(
*error = absl::Substitute(
"$0: First file chunk returned by plugin did not specify a file "
"name.",
plugin_name);

@ -117,6 +117,8 @@ class PROTOC_EXPORT CommandLineInterface {
static const char* const kPathSeparator;
CommandLineInterface();
CommandLineInterface(const CommandLineInterface&) = delete;
CommandLineInterface& operator=(const CommandLineInterface&) = delete;
~CommandLineInterface();
// Register a code generator for a language.
@ -457,8 +459,6 @@ class PROTOC_EXPORT CommandLineInterface {
// When using --encode, this will be passed to SetSerializationDeterministic.
bool deterministic_output_ = false;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface);
};
} // namespace compiler

@ -56,8 +56,11 @@
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/status/status.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/compiler/mock_code_generator.h>
@ -320,7 +323,7 @@ void CommandLineInterfaceTest::TearDown() {
}
void CommandLineInterfaceTest::Run(const std::string& command) {
RunWithArgs(Split(command, " ", true));
RunWithArgs(absl::StrSplit(command, " ", absl::SkipEmpty()));
}
void CommandLineInterfaceTest::RunWithArgs(std::vector<std::string> args) {
@ -350,7 +353,7 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector<std::string> args) {
"test_plugin.exe", // Other Win32 (MSVC)
"test_plugin", // Unix
};
for (int i = 0; i < GOOGLE_ARRAYSIZE(possible_paths); i++) {
for (int i = 0; i < ABSL_ARRAYSIZE(possible_paths); i++) {
if (access(possible_paths[i], F_OK) == 0) {
plugin_path = possible_paths[i];
break;
@ -827,7 +830,7 @@ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) {
field->set_number(1);
WriteDescriptorSet("baz_and_bat.bin", &file_descriptor_set);
Run(strings::Substitute(
Run(absl::Substitute(
"protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir "
"--descriptor_set_in=$0 foo.proto bar.proto",
std::string("$tmpdir/foo_and_bar.bin") +
@ -843,7 +846,7 @@ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) {
ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
"bar.proto", "Bar");
Run(strings::Substitute(
Run(absl::Substitute(
"protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir "
"--descriptor_set_in=$0 baz.proto bat.proto",
std::string("$tmpdir/foo_and_bar.bin") +
@ -901,7 +904,7 @@ TEST_F(CommandLineInterfaceTest,
field->set_number(1);
WriteDescriptorSet("foo_and_baz.bin", &file_descriptor_set);
Run(strings::Substitute(
Run(absl::Substitute(
"protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir "
"--descriptor_set_in=$0 bar.proto",
std::string("$tmpdir/foo_and_bar.bin") +
@ -1307,7 +1310,7 @@ TEST_F(CommandLineInterfaceTest, ColonDelimitedPath) {
"}\n");
CreateTempFile("b/foo.proto", "this should not be parsed\n");
Run(strings::Substitute(
Run(absl::Substitute(
"protocol_compiler --test_out=$$tmpdir --proto_path=$0 foo.proto",
std::string("$tmpdir/a") + CommandLineInterface::kPathSeparator +
"$tmpdir/b"));
@ -2589,7 +2592,7 @@ class EncodeDecodeTest : public testing::TestWithParam<EncodeDecodeTestMode> {
std::vector<std::string> args;
args.push_back("protoc");
for (absl::string_view split_piece :
Split(command, " ", true)) {
absl::StrSplit(command, " ", absl::SkipEmpty())) {
args.push_back(std::string(split_piece));
}
if (specify_proto_files) {

@ -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/strings",
"@com_google_absl//absl/synchronization",
],
)

@ -54,7 +54,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/container/flat_hash_map.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/stubs/stl_util.h>
@ -81,7 +81,7 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) override {
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
message);
}
};

@ -39,6 +39,7 @@
#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 <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/descriptor.pb.h>

@ -40,7 +40,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/compiler/cpp/primitive_field.h>
#include <google/protobuf/compiler/cpp/string_field.h>
@ -72,7 +72,7 @@ void MaySetAnnotationVariable(const Options& options,
if (options.field_listener_options.forbidden_field_listener_events.count(
std::string(annotation_name)))
return;
(*variables)[absl::StrCat("annotate_", annotation_name)] = strings::Substitute(
(*variables)[absl::StrCat("annotate_", annotation_name)] = absl::Substitute(
absl::StrCat(substitute_template_prefix, prepared_template, ");\n"),
field_index, access_type);
}
@ -87,13 +87,13 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor,
: "$0";
if (descriptor->default_value_string().empty()) {
return strings::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ",
return absl::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ",
field_pointer, ": nullptr"),
field_member);
}
if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING_PIECE) {
return strings::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ",
return absl::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ",
field_pointer, ": nullptr"),
field_member);
}
@ -102,7 +102,7 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor,
descriptor->options().ctype() == google::protobuf::FieldOptions::STRING
? "&$1.get()"
: "&$1";
return strings::Substitute(
return absl::Substitute(
absl::StrCat("_internal_has_", field_name, "() ? ", field_pointer, " : ",
default_value_pointer),
field_member, MakeDefaultFieldName(descriptor));
@ -115,7 +115,7 @@ std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor,
}
if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING) {
return strings::Substitute(
return absl::Substitute(
"$0.IsDefault() ? &$1.get() : $0.UnsafeGetPointer()", field_member,
MakeDefaultFieldName(descriptor));
}
@ -168,9 +168,9 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor,
if (descriptor->is_repeated() && !descriptor->is_map()) {
if (descriptor->type() != FieldDescriptor::TYPE_MESSAGE &&
descriptor->type() != FieldDescriptor::TYPE_GROUP) {
prepared_template = strings::Substitute("&$0.Get(index)", field_member);
prepared_template = absl::Substitute("&$0.Get(index)", field_member);
prepared_add_template =
strings::Substitute("&$0.Get($0.size() - 1)", field_member);
absl::Substitute("&$0.Get($0.size() - 1)", field_member);
} else {
prepared_template = "nullptr";
prepared_add_template = "nullptr";

@ -43,13 +43,11 @@
#include <vector>
#include <google/protobuf/compiler/scc.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#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/message.h>
#include <google/protobuf/compiler/cpp/service.h>

@ -43,6 +43,7 @@
#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 <google/protobuf/compiler/cpp/file.h>
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/descriptor.pb.h>

@ -58,8 +58,9 @@
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include "absl/synchronization/mutex.h"
#include <google/protobuf/compiler/cpp/names.h>
#include <google/protobuf/compiler/cpp/options.h>
@ -525,7 +526,7 @@ std::string ResolveKeyword(const std::string& name) {
std::string FieldName(const FieldDescriptor* field) {
std::string result = field->name();
LowerString(&result);
absl::AsciiStrToLower(&result);
if (Keywords().count(result) > 0) {
result.append("_");
}
@ -805,7 +806,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
case FieldDescriptor::CPPTYPE_ENUM:
// Lazy: Generate a static_cast because we don't have a helper function
// that constructs the full name of an enum value.
return strings::Substitute(
return absl::Substitute(
"static_cast< $0 >($1)", ClassName(field->enum_type(), true),
Int32ToString(field->default_value_enum()->number()));
case FieldDescriptor::CPPTYPE_STRING:
@ -865,7 +866,7 @@ std::string SafeFunctionName(const Descriptor* descriptor,
const std::string& prefix) {
// Do not use FieldName() since it will escape keywords.
std::string name = field->name();
LowerString(&name);
absl::AsciiStrToLower(&name);
std::string function_name = prefix + name;
if (descriptor->FindFieldByName(function_name)) {
// Single underscore will also make it conflicting with the private data

@ -43,6 +43,7 @@
#include <google/protobuf/compiler/scc.h>
#include <google/protobuf/compiler/code_generator.h>
#include "absl/strings/str_split.h"
#include <google/protobuf/compiler/cpp/names.h>
#include <google/protobuf/compiler/cpp/options.h>
#include <google/protobuf/descriptor.pb.h>
@ -884,7 +885,7 @@ class PROTOC_EXPORT NamespaceOpener {
void ChangeTo(const std::string& name) {
std::vector<std::string> new_stack_ =
Split(name, "::", true);
absl::StrSplit(name, "::", absl::SkipEmpty());
size_t len = std::min(name_stack_.size(), new_stack_.size());
size_t common_idx = 0;
while (common_idx < len) {

@ -62,9 +62,9 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
(*variables)["val_cpp"] = PrimitiveTypeName(options, val->cpp_type());
}
(*variables)["key_wire_type"] =
"TYPE_" + ToUpper(DeclaredTypeMethodName(key->type()));
"TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(key->type()));
(*variables)["val_wire_type"] =
"TYPE_" + ToUpper(DeclaredTypeMethodName(val->type()));
"TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(val->type()));
(*variables)["map_classname"] = ClassName(descriptor->message_type(), false);
(*variables)["number"] = absl::StrCat(descriptor->number());
(*variables)["tag"] = absl::StrCat(internal::WireFormat::MakeTag(descriptor));

@ -58,7 +58,7 @@
#include <google/protobuf/stubs/stringprintf.h>
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/cpp/enum.h>
#include <google/protobuf/compiler/cpp/extension.h>
#include <google/protobuf/compiler/cpp/field.h>
@ -297,9 +297,9 @@ void CollectMapInfo(const Options& options, const Descriptor* descriptor,
vars["val_cpp"] = PrimitiveTypeName(options, val->cpp_type());
}
vars["key_wire_type"] =
"TYPE_" + ToUpper(DeclaredTypeMethodName(key->type()));
"TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(key->type()));
vars["val_wire_type"] =
"TYPE_" + ToUpper(DeclaredTypeMethodName(val->type()));
"TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(val->type()));
}
// Does the given field have a private (internal helper only) has_$name$()
@ -310,14 +310,6 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) {
return IsProto3(field->file()) && field->real_containing_oneof();
}
// TODO(ckennelly): Cull these exclusions if/when these protos do not have
// their methods overridden by subclasses.
bool ShouldMarkClassAsFinal(const Descriptor* descriptor,
const Options& options) {
return true;
}
// Returns true to make the message serialize in order, decided by the following
// factors in the order of precedence.
@ -528,7 +520,7 @@ void MaySetAnnotationVariable(const Options& options,
if (options.field_listener_options.forbidden_field_listener_events.count(
std::string(annotation_name)))
return;
(*variables)[absl::StrCat("annotate_", annotation_name)] = strings::Substitute(
(*variables)[absl::StrCat("annotate_", annotation_name)] = absl::Substitute(
absl::StrCat(injector_template_prefix, injector_template_suffix),
(*variables)["classtype"]);
}
@ -1130,7 +1122,7 @@ void MessageGenerator::GenerateOneofHasBits(io::Printer* printer) {
for (auto oneof : OneOfRange(descriptor_)) {
format.Set("oneof_name", oneof->name());
format.Set("oneof_index", oneof->index());
format.Set("cap_oneof_name", ToUpper(oneof->name()));
format.Set("cap_oneof_name", absl::AsciiStrToUpper(oneof->name()));
format(
"inline bool $classname$::has_$oneof_name$() const {\n"
" return $oneof_name$_case() != $cap_oneof_name$_NOT_SET;\n"
@ -1293,8 +1285,6 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) {
void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
Formatter format(printer, variables_);
format.Set("class_final",
ShouldMarkClassAsFinal(descriptor_, options_) ? "final" : "");
if (IsMapEntryMessage(descriptor_)) {
std::map<std::string, std::string> vars;
@ -1396,7 +1386,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
}
format(
"class $dllexport_decl $${1$$classname$$}$$ class_final$ :\n"
"class $dllexport_decl $${1$$classname$$}$ final :\n"
" public $superclass$ /* @@protoc_insertion_point("
"class_definition:$full_name$) */ {\n",
descriptor_);
@ -1499,7 +1489,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
format("$1$ = $2$,\n", OneofCaseConstantName(field), // 1
field->number()); // 2
}
format("$1$_NOT_SET = 0,\n", ToUpper(oneof->name()));
format("$1$_NOT_SET = 0,\n", absl::AsciiStrToUpper(oneof->name()));
format.Outdent();
format(
"};\n"
@ -2943,7 +2933,7 @@ void MessageGenerator::GenerateStructors(io::Printer* printer) {
"case $1$_NOT_SET: {\n"
" break;\n"
"}\n",
ToUpper(oneof->name()));
absl::AsciiStrToUpper(oneof->name()));
format.Outdent();
format("}\n");
}
@ -3240,12 +3230,12 @@ void MessageGenerator::GenerateOneofClear(io::Printer* printer) {
"case $1$_NOT_SET: {\n"
" break;\n"
"}\n",
ToUpper(oneof->name()));
absl::AsciiStrToUpper(oneof->name()));
format.Outdent();
format(
"}\n"
"$oneof_case$[$1$] = $2$_NOT_SET;\n",
i, ToUpper(oneof->name()));
i, absl::AsciiStrToUpper(oneof->name()));
format.Outdent();
format(
"}\n"
@ -3572,7 +3562,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* printer) {
"case $1$_NOT_SET: {\n"
" break;\n"
"}\n",
ToUpper(oneof->name()));
absl::AsciiStrToUpper(oneof->name()));
format.Outdent();
format("}\n");
}
@ -4345,7 +4335,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* printer) {
"case $1$_NOT_SET: {\n"
" break;\n"
"}\n",
ToUpper(oneof->name()));
absl::AsciiStrToUpper(oneof->name()));
format.Outdent();
format("}\n");
}
@ -4444,7 +4434,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* printer) {
"case $1$_NOT_SET: {\n"
" break;\n"
"}\n",
ToUpper(oneof->name()));
absl::AsciiStrToUpper(oneof->name()));
format.Outdent();
format("}\n");
}

@ -65,7 +65,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/base/casts.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/arena.h>
#include <google/protobuf/compiler/cpp/test_bad_identifiers.pb.h>
#include <google/protobuf/compiler/importer.h>
@ -101,7 +101,7 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) override {
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
message);
}
};

@ -37,21 +37,23 @@
// "generate_descriptor_proto.sh" and add the changed files under
// csharp/src/ to your changelist.
#include <google/protobuf/testing/googletest.h>
#include <map>
#include <google/protobuf/compiler/csharp/csharp_generator.h>
#include <google/protobuf/testing/file.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/map_util.h>
#include <google/protobuf/stubs/stl_util.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.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/substitute.h"
#include <google/protobuf/compiler/csharp/csharp_generator.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/stl_util.h>
namespace google {
namespace protobuf {
@ -70,8 +72,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) {
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n",
filename, line, column, message);
absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
message);
}
};

@ -35,6 +35,10 @@
#include <google/protobuf/descriptor.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"
namespace google {
namespace protobuf {
@ -57,7 +61,7 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) {
comments = StringReplace(comments, "&", "&amp;", true);
comments = StringReplace(comments, "<", "&lt;", true);
std::vector<std::string> lines;
lines = Split(comments, "\n", false);
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...
// but that needs to be part of a bigger effort to understand the markdown better anyway.
printer->Print("/// <summary>\n");

@ -28,19 +28,23 @@
// (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/compiler/csharp/csharp_enum.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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 <google/protobuf/compiler/csharp/csharp_doc_comment.h>
#include <google/protobuf/compiler/csharp/csharp_enum.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 {

@ -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 <google/protobuf/compiler/csharp/csharp_enum_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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/compiler/csharp/csharp_enum_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 {

@ -28,22 +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 <google/protobuf/compiler/csharp/csharp_field_base.h>
#include <cmath>
#include <limits>
#include <sstream>
#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_replace.h"
#include "absl/strings/str_split.h"
#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>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/wire_format.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>
// Must be last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
@ -462,3 +469,5 @@ std::string FieldGeneratorBase::capitalized_type_name() {
} // namespace compiler
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>

@ -33,6 +33,10 @@
#include <string>
#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 <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/csharp/csharp_source_generator_base.h>

@ -28,20 +28,24 @@
// (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/compiler/csharp/csharp_generator.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/compiler/csharp/csharp_generator.h>
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.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/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 {

@ -32,12 +32,11 @@
#include <google/protobuf/any.pb.h>
#include <google/protobuf/compiler/command_line_interface.h>
#include <gtest/gtest.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/printer.h>
#include <gtest/gtest.h>
#include <google/protobuf/io/zero_copy_stream.h>
namespace google {
namespace protobuf {

@ -32,32 +32,37 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <algorithm>
#include <limits>
#include <vector>
#include <sstream>
#include <vector>
#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/printer.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h>
#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 <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 "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"
#include "absl/strings/ascii.h"
// Must be last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
@ -634,3 +639,5 @@ bool IsNullable(const FieldDescriptor* descriptor) {
} // namespace compiler
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>

@ -36,14 +36,14 @@
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__
#include <string>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/port.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/port_def.inc>
#include <google/protobuf/stubs/common.h>
namespace google {
namespace protobuf {

@ -28,18 +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 <google/protobuf/compiler/csharp/csharp_map_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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 <google/protobuf/compiler/csharp/csharp_doc_comment.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/compiler/csharp/csharp_map_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 {

@ -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 <sstream>
#include <google/protobuf/compiler/csharp/csharp_message.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/compiler/csharp/csharp_options.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 <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_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>
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
// Must be last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
@ -780,3 +784,5 @@ FieldGeneratorBase* MessageGenerator::CreateFieldGeneratorInternal(
} // namespace compiler
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>

@ -28,21 +28,25 @@
// (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/compiler/csharp/csharp_message_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#include <google/protobuf/stubs/strutil.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_replace.h"
#include "absl/strings/str_split.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_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 {

@ -39,8 +39,8 @@
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__
#include <string>
#include <google/protobuf/port.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/port.h>
#include <google/protobuf/port_def.inc>

@ -28,19 +28,23 @@
// (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/compiler/csharp/csharp_primitive_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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 <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/compiler/csharp/csharp_primitive_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 {

@ -28,23 +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 <google/protobuf/compiler/csharp/csharp_reflection_class.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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 <google/protobuf/compiler/csharp/csharp_enum.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.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/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>
// Must be last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
@ -328,3 +334,5 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript
} // namespace compiler
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>

@ -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 <google/protobuf/compiler/csharp/csharp_repeated_enum_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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/compiler/csharp/csharp_repeated_enum_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 {

@ -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 <google/protobuf/compiler/csharp/csharp_repeated_message_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/compiler/csharp/csharp_repeated_message_field.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 {

@ -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 <google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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/compiler/csharp/csharp_repeated_primitive_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 {

@ -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 <google/protobuf/compiler/csharp/csharp_source_generator_base.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#include <google/protobuf/compiler/csharp/csharp_source_generator_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>
namespace google {
namespace protobuf {

@ -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 <google/protobuf/compiler/csharp/csharp_wrapper_field.h>
#include <sstream>
#include <google/protobuf/compiler/code_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>
#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/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 {

@ -32,6 +32,8 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#include <google/protobuf/compiler/importer.h>
#ifdef _MSC_VER
#include <direct.h>
#else
@ -44,14 +46,16 @@
#include <algorithm>
#include <memory>
#include <vector>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/compiler/parser.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#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 <ctype.h>
@ -288,27 +292,18 @@ static std::string CanonicalizePath(std::string path) {
}
#endif
std::vector<std::string> canonical_parts;
std::vector<std::string> parts = Split(
path, "/", true); // Note: Removes empty parts.
for (const std::string& part : parts) {
std::vector<absl::string_view> canonical_parts;
if (!path.empty() && path.front() == '/') canonical_parts.push_back("");
for (absl::string_view part : absl::StrSplit(path, '/', absl::SkipEmpty())) {
if (part == ".") {
// Ignore.
} else {
canonical_parts.push_back(part);
}
}
std::string result = absl::StrJoin(canonical_parts, "/");
if (!path.empty() && path[0] == '/') {
// Restore leading slash.
result = '/' + result;
}
if (!path.empty() && LastChar(path) == '/' && !result.empty() &&
LastChar(result) != '/') {
// Restore trailing slash.
result += '/';
}
return result;
if (!path.empty() && path.back() == '/') canonical_parts.push_back("");
return absl::StrJoin(canonical_parts, "/");
}
static inline bool ContainsParentReference(const std::string& path) {

@ -159,6 +159,8 @@ class PROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase {
class PROTOBUF_EXPORT Importer {
public:
Importer(SourceTree* source_tree, MultiFileErrorCollector* error_collector);
Importer(const Importer&) = delete;
Importer& operator=(const Importer&) = delete;
~Importer();
// Import the given file and build a FileDescriptor representing it. If
@ -188,15 +190,15 @@ class PROTOBUF_EXPORT Importer {
private:
SourceTreeDescriptorDatabase database_;
DescriptorPool pool_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer);
};
// If the importer encounters problems while trying to import the proto files,
// it reports them to a MultiFileErrorCollector.
class PROTOBUF_EXPORT MultiFileErrorCollector {
public:
inline MultiFileErrorCollector() {}
MultiFileErrorCollector() {}
MultiFileErrorCollector(const MultiFileErrorCollector&) = delete;
MultiFileErrorCollector& operator=(const MultiFileErrorCollector&) = delete;
virtual ~MultiFileErrorCollector();
// Line and column numbers are zero-based. A line number of -1 indicates
@ -206,9 +208,6 @@ class PROTOBUF_EXPORT MultiFileErrorCollector {
virtual void AddWarning(const std::string& /* filename */, int /* line */,
int /* column */, const std::string& /* message */) {}
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector);
};
// Abstract interface which represents a directory tree containing proto files.
@ -217,7 +216,9 @@ class PROTOBUF_EXPORT MultiFileErrorCollector {
// below.
class PROTOBUF_EXPORT SourceTree {
public:
inline SourceTree() {}
SourceTree() {}
SourceTree(const SourceTree&) = delete;
SourceTree& operator=(const SourceTree&) = delete;
virtual ~SourceTree();
// Open the given file and return a stream that reads it, or NULL if not
@ -232,9 +233,6 @@ class PROTOBUF_EXPORT SourceTree {
// better error reporting.
// TODO(xiaofeng): change this to a pure virtual function.
virtual std::string GetLastErrorMessage();
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree);
};
// An implementation of SourceTree which loads files from locations on disk.
@ -243,6 +241,8 @@ class PROTOBUF_EXPORT SourceTree {
class PROTOBUF_EXPORT DiskSourceTree : public SourceTree {
public:
DiskSourceTree();
DiskSourceTree(const DiskSourceTree&) = delete;
DiskSourceTree& operator=(const DiskSourceTree&) = delete;
~DiskSourceTree() override;
// Map a path on disk to a location in the SourceTree. The path may be
@ -325,8 +325,6 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree {
// Like Open() but given the actual on-disk path.
io::ZeroCopyInputStream* OpenDiskFile(const std::string& filename);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree);
};
} // namespace compiler

@ -46,7 +46,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/container/flat_hash_map.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/stubs/strutil.h>
@ -74,13 +74,13 @@ class MockErrorCollector : public MultiFileErrorCollector {
// implements ErrorCollector ---------------------------------------
void AddError(const std::string& filename, int line, int column,
const std::string& message) override {
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
message);
}
void AddWarning(const std::string& filename, int line, int column,
const std::string& message) override {
strings::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename, line,
absl::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename, line,
column, message);
}
};

@ -83,6 +83,8 @@ cc_library(
deps = [
"//:protobuf",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/strings",
],
)
@ -111,6 +113,7 @@ cc_test(
"//src/google/protobuf/io",
"//src/google/protobuf/stubs:lite",
"//src/google/protobuf/testing",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],

@ -39,6 +39,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_split.h"
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
@ -153,7 +154,7 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer,
comments = EscapeJavadoc(comments);
}
std::vector<std::string> lines = Split(comments, "\n");
std::vector<std::string> lines = absl::StrSplit(comments, "\n");
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}

@ -41,7 +41,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/enum_field.h>
#include <google/protobuf/compiler/java/enum_field_lite.h>

@ -37,16 +37,19 @@
#include <algorithm>
#include <cstdint>
#include <limits>
#include <unordered_set>
#include <vector>
#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 <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.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 <google/protobuf/compiler/java/name_resolver.h>
#include <google/protobuf/compiler/java/names.h>
#include <google/protobuf/descriptor.pb.h>
@ -72,49 +75,47 @@ const char* DefaultPackage(Options options) {
return options.opensource_runtime ? "" : "com.google.protos";
}
// Names that should be avoided (in UpperCamelCase format).
// Using them will cause the compiler to generate accessors whose names
// collide with methods defined in base classes.
// Keep this list in sync with specialFieldNames in
// java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
const char* kForbiddenWordList[] = {
// java.lang.Object:
"Class",
// com.google.protobuf.MessageLiteOrBuilder:
"DefaultInstanceForType",
// com.google.protobuf.MessageLite:
"ParserForType",
"SerializedSize",
// com.google.protobuf.MessageOrBuilder:
"AllFields",
"DescriptorForType",
"InitializationErrorString",
"UnknownFields",
// obsolete. kept for backwards compatibility of generated code
"CachedSize",
};
const std::unordered_set<std::string>* kReservedNames =
new std::unordered_set<std::string>({
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "final", "finally", "float",
"for", "goto", "if", "implements", "import",
"instanceof", "int", "interface", "long", "native",
"new", "package", "private", "protected", "public",
"return", "short", "static", "strictfp", "super",
"switch", "synchronized", "this", "throw", "throws",
"transient", "try", "void", "volatile", "while",
});
bool IsReservedName(absl::string_view name) {
static const auto& kReservedNames =
*new absl::flat_hash_set<absl::string_view>({
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "final", "finally", "float",
"for", "goto", "if", "implements", "import",
"instanceof", "int", "interface", "long", "native",
"new", "package", "private", "protected", "public",
"return", "short", "static", "strictfp", "super",
"switch", "synchronized", "this", "throw", "throws",
"transient", "try", "void", "volatile", "while",
});
return kReservedNames.contains(name);
}
bool IsForbidden(const std::string& field_name) {
for (size_t i = 0; i < ABSL_ARRAYSIZE(kForbiddenWordList); ++i) {
if (UnderscoresToCamelCase(field_name, true) == kForbiddenWordList[i]) {
return true;
}
}
return false;
// Names that should be avoided (in UpperCamelCase format).
// Using them will cause the compiler to generate accessors whose names
// collide with methods defined in base classes.
// Keep this list in sync with specialFieldNames in
// java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
static const auto& kForbiddenNames =
*new absl::flat_hash_set<absl::string_view>({
// java.lang.Object:
"Class",
// com.google.protobuf.MessageLiteOrBuilder:
"DefaultInstanceForType",
// com.google.protobuf.MessageLite:
"ParserForType",
"SerializedSize",
// com.google.protobuf.MessageOrBuilder:
"AllFields",
"DescriptorForType",
"InitializationErrorString",
"UnknownFields",
// obsolete. kept for backwards compatibility of generated code
"CachedSize",
});
return kForbiddenNames.contains(UnderscoresToCamelCase(field_name, true));
}
std::string FieldName(const FieldDescriptor* field) {
@ -261,7 +262,7 @@ std::string UnderscoresToCamelCase(const MethodDescriptor* method) {
std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) {
std::string name = UnderscoresToCamelCase(field);
if (kReservedNames->find(name) != kReservedNames->end()) {
if (IsReservedName(name)) {
return name + "_";
}
return name;
@ -269,23 +270,23 @@ std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) {
// Names that should be avoided as field names in Kotlin.
// All Kotlin hard keywords are in this list.
const std::unordered_set<std::string>* kKotlinForbiddenNames =
new std::unordered_set<std::string>({
"as", "as?", "break", "class", "continue", "do", "else",
"false", "for", "fun", "if", "in", "!in", "interface",
"is", "!is", "null", "object", "package", "return", "super",
"this", "throw", "true", "try", "typealias", "typeof", "val",
"var", "when", "while",
});
bool IsForbiddenKotlin(absl::string_view field_name) {
static const auto& kKotlinForbiddenNames =
*new absl::flat_hash_set<absl::string_view>({
"as", "as?", "break", "class", "continue", "do",
"else", "false", "for", "fun", "if", "in",
"!in", "interface", "is", "!is", "null", "object",
"package", "return", "super", "this", "throw", "true",
"try", "typealias", "typeof", "val", "var", "when",
"while",
});
bool IsForbiddenKotlin(const std::string& field_name) {
return kKotlinForbiddenNames->find(field_name) !=
kKotlinForbiddenNames->end();
return kKotlinForbiddenNames.contains(field_name);
}
std::string EscapeKotlinKeywords(std::string name) {
std::vector<std::string> escaped_packages;
std::vector<std::string> packages = Split(name, "."); // NOLINT
std::vector<std::string> packages = absl::StrSplit(name, "."); // NOLINT
for (const std::string& package : packages) {
if (IsForbiddenKotlin(package)) {
escaped_packages.push_back("`" + package + "`");
@ -381,7 +382,7 @@ std::string ExtraMessageOrBuilderInterfaces(const Descriptor* descriptor) {
std::string FieldConstantName(const FieldDescriptor* field) {
std::string name = field->name() + "_FIELD_NUMBER";
ToUpper(&name);
absl::AsciiStrToUpper(&name);
return name;
}
@ -643,7 +644,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
if (GetType(field) == FieldDescriptor::TYPE_BYTES) {
if (field->has_default_value()) {
// See comments in Internal.java for gory details.
return strings::Substitute(
return absl::Substitute(
"com.google.protobuf.Internal.bytesDefaultValue(\"$0\")",
absl::CEscape(field->default_value_string()));
} else {
@ -655,7 +656,7 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable,
return "\"" + absl::CEscape(field->default_value_string()) + "\"";
} else {
// See comments in Internal.java for gory details.
return strings::Substitute(
return absl::Substitute(
"com.google.protobuf.Internal.stringDefaultValue(\"$0\")",
absl::CEscape(field->default_value_string()));
}
@ -941,7 +942,7 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) {
// already_seen is used to avoid checking the same type multiple times
// (and also to protect against recursion).
bool HasRequiredFields(const Descriptor* type,
std::unordered_set<const Descriptor*>* already_seen) {
absl::flat_hash_set<const Descriptor*>* already_seen) {
if (already_seen->count(type) > 0) {
// The type is already in cache. This means that either:
// a. The type has no required fields.
@ -976,7 +977,7 @@ bool HasRequiredFields(const Descriptor* type,
}
bool HasRequiredFields(const Descriptor* type) {
std::unordered_set<const Descriptor*> already_seen;
absl::flat_hash_set<const Descriptor*> already_seen;
return HasRequiredFields(type, &already_seen);
}

@ -40,6 +40,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.h>
#include "absl/strings/string_view.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/options.h>
#include <google/protobuf/descriptor.pb.h>
@ -57,7 +58,7 @@ namespace java {
extern const char kThickSeparator[];
extern const char kThinSeparator[];
bool IsForbiddenKotlin(const std::string& field_name);
bool IsForbiddenKotlin(absl::string_view field_name);
// If annotation_file is non-empty, prints a javax.annotation.Generated
// annotation to the given Printer. annotation_file will be referenced in the

@ -46,7 +46,7 @@
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/enum.h>
@ -342,7 +342,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
" $classname$> implements\n"
" $extra_interfaces$\n"
" $classname$OrBuilder {\n");
builder_type = strings::Substitute(
builder_type = absl::Substitute(
"com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>",
name_resolver_->GetImmutableClassName(descriptor_),
GeneratedCodeVersionSuffix());
@ -356,7 +356,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
" $extra_interfaces$\n"
" $classname$OrBuilder {\n");
builder_type =
strings::Substitute("com.google.protobuf.GeneratedMessage$0.Builder<?>",
absl::Substitute("com.google.protobuf.GeneratedMessage$0.Builder<?>",
GeneratedCodeVersionSuffix());
}
printer->Print("private static final long serialVersionUID = 0L;\n");
@ -456,12 +456,12 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
printer->Print(
"$deprecation$$field_name$($field_number$),\n", "deprecation",
field->options().deprecated() ? "@java.lang.Deprecated " : "",
"field_name", ToUpper(field->name()), "field_number",
"field_name", absl::AsciiStrToUpper(field->name()), "field_number",
absl::StrCat(field->number()));
printer->Annotate("field_name", field);
}
printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name",
ToUpper(vars["oneof_name"]));
absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Print(vars,
"private final int value;\n"
"private $oneof_capitalized_name$Case(int value) {\n"
@ -489,7 +489,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print(" case $field_number$: return $field_name$;\n",
"field_number", absl::StrCat(field->number()),
"field_name", ToUpper(field->name()));
"field_name", absl::AsciiStrToUpper(field->name()));
}
printer->Print(
" case 0: return $cap_oneof_name$_NOT_SET;\n"
@ -499,7 +499,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"public int getNumber() {\n"
" return this.value;\n"
"}\n",
"cap_oneof_name", ToUpper(vars["oneof_name"]));
"cap_oneof_name", absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Outdent();
printer->Print("};\n\n");
// oneofCase()

@ -45,7 +45,7 @@
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/enum.h>
@ -560,7 +560,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
for (int j = 0; j < oneof->field_count(); j++) {
const FieldDescriptor* field = oneof->field(j);
printer->Print("case $field_name$: {\n", "field_name",
ToUpper(field->name()));
absl::AsciiStrToUpper(field->name()));
printer->Indent();
field_generators_.get(field).GenerateMergingCode(printer);
printer->Print("break;\n");
@ -572,7 +572,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
" break;\n"
"}\n",
"cap_oneof_name",
ToUpper(context_->GetOneofGeneratorInfo(oneof)->name));
absl::AsciiStrToUpper(context_->GetOneofGeneratorInfo(oneof)->name));
printer->Outdent();
printer->Print("}\n");
}

@ -44,7 +44,7 @@
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/enum.h>

@ -46,7 +46,7 @@
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/doc_comment.h>
#include <google/protobuf/compiler/java/enum_lite.h>
@ -190,7 +190,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
" $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n"
" $classname$OrBuilder {\n");
builder_type = strings::Substitute(
builder_type = absl::Substitute(
"com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>",
name_resolver_->GetImmutableClassName(descriptor_));
} else {
@ -254,11 +254,11 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
for (int j = 0; j < (oneof)->field_count(); j++) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print("$field_name$($field_number$),\n", "field_name",
ToUpper(field->name()), "field_number",
absl::AsciiStrToUpper(field->name()), "field_number",
absl::StrCat(field->number()));
}
printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name",
ToUpper(vars["oneof_name"]));
absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Print(vars,
"private final int value;\n"
"private $oneof_capitalized_name$Case(int value) {\n"
@ -284,7 +284,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
const FieldDescriptor* field = (oneof)->field(j);
printer->Print(" case $field_number$: return $field_name$;\n",
"field_number", absl::StrCat(field->number()),
"field_name", ToUpper(field->name()));
"field_name", absl::AsciiStrToUpper(field->name()));
}
printer->Print(
" case 0: return $cap_oneof_name$_NOT_SET;\n"
@ -296,7 +296,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
"public int getNumber() {\n"
" return this.value;\n"
"}\n",
"cap_oneof_name", ToUpper(vars["oneof_name"]));
"cap_oneof_name", absl::AsciiStrToUpper(vars["oneof_name"]));
printer->Outdent();
printer->Print("};\n\n");
// oneofCase()

@ -41,6 +41,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/compiler/java/generator.h>
#include <google/protobuf/test_util2.h>
@ -92,11 +93,11 @@ TEST(MessageSerializationTest, CollapseAdjacentExtensionRanges) {
std::vector<std::string> range_ends;
// Open-source codebase does not have Split overload taking a single
// Open-source codebase does not have absl::StrSplit overload taking a single
// char delimiter.
//
// NOLINTNEXTLINE(abseil-faster-strsplit-delimiter)
for (const auto& line : Split(java_source, "\n")) {
for (const auto& line : absl::StrSplit(java_source, "\n")) {
// Extract end position from writeUntil call. (Open-source codebase does not
// support RE2.)
std::size_t write_until_pos = line.find(kWriteUntilCall);

@ -34,10 +34,13 @@
#include <string>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/ascii.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/java/helpers.h>
#include <google/protobuf/compiler/java/names.h>
// Must be last.
#include <google/protobuf/port_def.inc>
@ -108,7 +111,7 @@ std::string ClassNameWithoutPackage(const ServiceDescriptor* descriptor,
// Return true if a and b are equals (case insensitive).
NameEquality CheckNameEquality(const std::string& a, const std::string& b) {
if (ToUpper(a) == ToUpper(b)) {
if (absl::AsciiStrToUpper(a) == absl::AsciiStrToUpper(b)) {
if (a == b) {
return NameEquality::EXACT_EQUAL;
}
@ -314,7 +317,7 @@ std::string ClassNameResolver::GetJavaClassFullName(
result = GetClassName(file, immutable, kotlin);
if (!result.empty()) result += '$';
}
result += StringReplace(name_without_package, ".", "$", true);
result += absl::StrReplaceAll(name_without_package, {{".", "$"}});
return result;
}

@ -39,9 +39,9 @@
#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/stubs/strutil.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/strings/str_split.h"
namespace google {
namespace protobuf {
@ -114,7 +114,7 @@ TEST(JavaPluginTest, PluginTest) {
std::string output;
GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/Test.java", &output,
true));
std::vector<std::string> lines = Split(output, "\n");
std::vector<std::string> lines = absl::StrSplit(output, "\n");
bool found_generated_annotation = false;
bool found_do_not_edit = false;
for (const auto& line : lines) {

@ -127,7 +127,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
if (javaType == JAVATYPE_BYTES) {
(*variables)["bytes_default"] =
ToUpper((*variables)["name"]) + "_DEFAULT_VALUE";
absl::AsciiStrToUpper((*variables)["name"]) + "_DEFAULT_VALUE";
}
if (IsReferenceType(javaType)) {

@ -49,7 +49,10 @@
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/descriptor.pb.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/str_join.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "absl/strings/substitute.h"
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
@ -109,7 +112,7 @@ void MockCodeGenerator::ExpectGenerated(
&content, true));
std::vector<std::string> lines =
Split(content, "\n", true);
absl::StrSplit(content, "\n", absl::SkipEmpty());
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
@ -120,7 +123,7 @@ void MockCodeGenerator::ExpectGenerated(
std::vector<std::string> insertion_list;
if (!insertions.empty()) {
insertion_list = Split(insertions, ",", true);
insertion_list = absl::StrSplit(insertions, ",", absl::SkipEmpty());
}
EXPECT_EQ(lines.size(), 3 + insertion_list.size() * 2);
@ -251,10 +254,10 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file,
bool insert_endlines = HasPrefixString(parameter, "insert_endlines=");
if (insert_endlines || HasPrefixString(parameter, "insert=")) {
std::vector<std::string> insert_into = Split(
std::vector<std::string> insert_into = absl::StrSplit(
StripPrefixString(
parameter, insert_endlines ? "insert_endlines=" : "insert="),
",", true);
",", absl::SkipEmpty());
for (size_t i = 0; i < insert_into.size(); i++) {
{
@ -375,7 +378,7 @@ std::string MockCodeGenerator::GetOutputFileContent(
const std::string& generator_name, const std::string& parameter,
const std::string& file, const std::string& parsed_file_list,
const std::string& first_message_name) {
return strings::Substitute("$0: $1, $2, $3, $4\n", generator_name, parameter,
return absl::Substitute("$0: $1, $2, $3, $4\n", generator_name, parameter,
file, first_message_name, parsed_file_list);
}

@ -28,8 +28,6 @@
// (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 <algorithm>
#include <limits>
#include <map>
#include <string>
@ -37,8 +35,11 @@
#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 <algorithm> // std::find()
namespace google {
namespace protobuf {

@ -34,6 +34,10 @@
#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 <google/protobuf/io/printer.h>
namespace google {

@ -38,6 +38,10 @@
#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"
namespace google {
namespace protobuf {

@ -38,6 +38,10 @@
#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 <algorithm> // std::find()
#include <iostream>
#include <sstream>

@ -38,6 +38,10 @@
#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"
namespace google {
namespace protobuf {
@ -51,7 +55,7 @@ namespace {
// invalid, `result` is unchanged.
bool StringToBool(const std::string& value, bool* result) {
std::string upper_value(value);
ToUpper(&upper_value);
absl::AsciiStrToUpper(&upper_value);
if (upper_value == "NO") {
*result = false;
return true;
@ -122,8 +126,8 @@ bool ObjectiveCGenerator::GenerateAll(
// A semicolon delimited string that lists the paths of .proto files to
// exclude from the package prefix validations (expected_prefixes_path).
// This is provided as an "out", to skip some files being checked.
for (absl::string_view split_piece : Split(
options[i].second, ";", true)) {
for (absl::string_view split_piece : absl::StrSplit(
options[i].second, ";", absl::SkipEmpty())) {
validation_options.expected_prefixes_suppressions.push_back(
std::string(split_piece));
}

@ -49,12 +49,13 @@
#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/port.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"
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
@ -68,18 +69,18 @@ namespace objectivec {
// in this port namespace to avoid ambiguous definition.
namespace posix {
#ifdef _WIN32
using ::google::protobuf::io::win32::open;
#else
using google::protobuf::io::win32::open;
#else // !_WIN32
using ::open;
#endif
} // namespace port
#endif // _WIN32
} // namespace posix
namespace {
bool BoolFromEnvVar(const char* env_var, bool default_value) {
const char* value = getenv(env_var);
if (value) {
return std::string("YES") == ToUpper(value);
return std::string("YES") == absl::AsciiStrToUpper(value);
}
return default_value;
}
@ -275,7 +276,7 @@ Options::Options() {
const char* suppressions = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES_SUPPRESSIONS");
if (suppressions) {
expected_prefixes_suppressions =
Split(suppressions, ";", true);
absl::StrSplit(suppressions, ";", absl::SkipEmpty());
}
prefixes_must_be_registered =
BoolFromEnvVar("GPB_OBJC_PREFIXES_MUST_BE_REGISTERED", false);
@ -296,7 +297,7 @@ std::unordered_set<std::string> MakeWordsMap(const char* const words[],
const char* const kUpperSegmentsList[] = {"url", "http", "https"};
std::unordered_set<std::string> kUpperSegments =
MakeWordsMap(kUpperSegmentsList, GOOGLE_ARRAYSIZE(kUpperSegmentsList));
MakeWordsMap(kUpperSegmentsList, ABSL_ARRAYSIZE(kUpperSegmentsList));
bool ascii_isnewline(char c) {
return c == '\n' || c == '\r';
@ -456,9 +457,9 @@ std::string SanitizeNameForObjC(const std::string& prefix,
const std::string& extension,
std::string* out_suffix_added) {
static const std::unordered_set<std::string> kReservedWords =
MakeWordsMap(kReservedWordList, GOOGLE_ARRAYSIZE(kReservedWordList));
MakeWordsMap(kReservedWordList, ABSL_ARRAYSIZE(kReservedWordList));
static const std::unordered_set<std::string> kNSObjectMethods =
MakeWordsMap(kNSObjectMethodsList, GOOGLE_ARRAYSIZE(kNSObjectMethodsList));
MakeWordsMap(kNSObjectMethodsList, ABSL_ARRAYSIZE(kNSObjectMethodsList));
std::string sanitized;
// We add the prefix in the cases where the string is missing a prefix.
// We define "missing a prefix" as where 'input':
@ -630,7 +631,7 @@ std::string FileClassPrefix(const FileDescriptor* file) {
// camelcase each one and then join them with underscores, and add an
// underscore at the end.
std::string result;
const std::vector<std::string> segments = Split(file->package(), ".", true);
const std::vector<std::string> segments = absl::StrSplit(file->package(), ".", absl::SkipEmpty());
for (const auto& segment : segments) {
const std::string part = UnderscoresToCamelCase(segment, true);
if (part.empty()) {
@ -1189,7 +1190,7 @@ std::string BuildCommentsString(const SourceLocation& location,
? location.trailing_comments
: location.leading_comments;
std::vector<std::string> lines;
lines = Split(comments, "\n", false);
lines = absl::StrSplit(comments, "\n", absl::AllowEmpty());
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
@ -1244,7 +1245,7 @@ const char* const ProtobufLibraryFrameworkName = "Protobuf";
std::string ProtobufFrameworkImportSymbol(const std::string& framework_name) {
// GPB_USE_[framework_name]_FRAMEWORK_IMPORTS
std::string result = std::string("GPB_USE_");
result += ToUpper(framework_name);
result += absl::AsciiStrToUpper(framework_name);
result += "_FRAMEWORK_IMPORTS";
return result;
}

@ -269,7 +269,7 @@ class TestLineCollector : public LineConsumer {
};
const int kBlockSizes[] = {-1, 1, 2, 5, 64};
const int kBlockSizeCount = GOOGLE_ARRAYSIZE(kBlockSizes);
const int kBlockSizeCount = ABSL_ARRAYSIZE(kBlockSizes);
TEST(ObjCHelper, ParseSimple_BasicsSuccess) {
const std::vector<std::pair<std::string, std::vector<std::string>>> tests = {

@ -38,13 +38,15 @@
#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 <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>
#include "absl/strings/escaping.h"
namespace google {
namespace protobuf {
namespace compiler {

@ -35,6 +35,10 @@
#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"
namespace google {
namespace protobuf {

@ -35,6 +35,10 @@
#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"
namespace google {
namespace protobuf {

@ -1089,7 +1089,7 @@ bool Parser::ParseMessageFieldNoLabel(
AddError(name_token.line, name_token.column,
"Group names must start with a capital letter.");
}
LowerString(field->mutable_name());
absl::AsciiStrToLower(field->mutable_name());
field->set_type_name(group->name());
if (LookingAt("{")) {

@ -71,6 +71,8 @@ class SourceLocationTable;
class PROTOBUF_EXPORT Parser {
public:
Parser();
Parser(const Parser&) = delete;
Parser& operator=(const Parser&) = delete;
~Parser();
// Parse the entire input and construct a FileDescriptorProto representing
@ -545,8 +547,6 @@ class PROTOBUF_EXPORT Parser {
// the next element (See SourceCodeInfo.Location in descriptor.proto), when
// ConsumeEndOfDeclaration() is called.
std::vector<std::string> upcoming_detached_comments_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser);
};
// A table mapping (descriptor, ErrorLocation) pairs -- as reported by

@ -51,7 +51,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/strings/str_join.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
namespace google {
namespace protobuf {
@ -69,11 +69,11 @@ class MockErrorCollector : public io::ErrorCollector {
// implements ErrorCollector ---------------------------------------
void AddWarning(int line, int column, const std::string& message) override {
strings::SubstituteAndAppend(&warning_, "$0:$1: $2\n", line, column, message);
absl::SubstituteAndAppend(&warning_, "$0:$1: $2\n", line, column, message);
}
void AddError(int line, int column, const std::string& message) override {
strings::SubstituteAndAppend(&text_, "$0:$1: $2\n", line, column, message);
absl::SubstituteAndAppend(&text_, "$0:$1: $2\n", line, column, message);
}
};
@ -2402,7 +2402,7 @@ TEST_F(ParseDescriptorDebugTest, TestCommentsInDebugString) {
const std::string debug_string =
descriptor->DebugStringWithOptions(debug_string_options);
for (int i = 0; i < GOOGLE_ARRAYSIZE(expected_comments); ++i) {
for (int i = 0; i < ABSL_ARRAYSIZE(expected_comments); ++i) {
std::string::size_type found_pos =
debug_string.find(expected_comments[i]);
EXPECT_TRUE(found_pos != std::string::npos)

@ -30,17 +30,19 @@
#include <google/protobuf/compiler/php/php_generator.h>
#include <sstream>
#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 <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/escaping.h"
#include <sstream>
const std::string kDescriptorFile = "google/protobuf/descriptor.proto";
const std::string kEmptyFile = "google/protobuf/empty.proto";
@ -765,8 +767,8 @@ void GenerateFieldAccessor(const FieldDescriptor* field, const Options& options,
"$arr = GPBUtil::checkMapField($var, "
"\\Google\\Protobuf\\Internal\\GPBType::^key_type^, "
"\\Google\\Protobuf\\Internal\\GPBType::^value_type^",
"key_type", ToUpper(key->type_name()),
"value_type", ToUpper(value->type_name()));
"key_type", absl::AsciiStrToUpper(key->type_name()),
"value_type", absl::AsciiStrToUpper(value->type_name()));
if (value->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
printer->Print(
", \\^class_name^);\n",
@ -784,7 +786,7 @@ void GenerateFieldAccessor(const FieldDescriptor* field, const Options& options,
printer->Print(
"$arr = GPBUtil::checkRepeatedField($var, "
"\\Google\\Protobuf\\Internal\\GPBType::^type^",
"type", ToUpper(field->type_name()));
"type", absl::AsciiStrToUpper(field->type_name()));
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
printer->Print(
", \\^class_name^);\n",
@ -914,8 +916,8 @@ void GenerateMessageToPool(const std::string& name_prefix,
"->map('^field^', \\Google\\Protobuf\\Internal\\GPBType::^key^, "
"\\Google\\Protobuf\\Internal\\GPBType::^value^, ^number^^other^)\n",
"field", field->name(),
"key", ToUpper(key->type_name()),
"value", ToUpper(val->type_name()),
"key", absl::AsciiStrToUpper(key->type_name()),
"value", absl::AsciiStrToUpper(val->type_name()),
"number", absl::StrCat(field->number()),
"other", EnumOrMessageSuffix(val, true));
} else if (!field->real_containing_oneof()) {
@ -924,7 +926,7 @@ void GenerateMessageToPool(const std::string& name_prefix,
"\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n",
"field", field->name(),
"label", LabelForField(field),
"type", ToUpper(field->type_name()),
"type", absl::AsciiStrToUpper(field->type_name()),
"number", absl::StrCat(field->number()),
"other", EnumOrMessageSuffix(field, true));
}
@ -942,7 +944,7 @@ void GenerateMessageToPool(const std::string& name_prefix,
"->value('^field^', "
"\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n",
"field", field->name(),
"type", ToUpper(field->type_name()),
"type", absl::AsciiStrToUpper(field->type_name()),
"number", absl::StrCat(field->number()),
"other", EnumOrMessageSuffix(field, true));
}
@ -1751,7 +1753,7 @@ static void GenerateDocCommentBodyForLocation(
// HTML-escape them so that they don't accidentally close the doc comment.
comments = EscapePhpdoc(comments);
std::vector<std::string> lines = Split(comments, "\n", true);
std::vector<std::string> lines = absl::StrSplit(comments, "\n", absl::SkipEmpty());
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
@ -2394,11 +2396,11 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
std::string* error) const {
Options options;
for (const auto& option : Split(parameter, ",", true)) {
const std::vector<std::string> option_pair = Split(option, "=", true);
for (const auto& option : absl::StrSplit(parameter, ",", absl::SkipEmpty())) {
const std::vector<std::string> option_pair = absl::StrSplit(option, "=", absl::SkipEmpty());
if (HasPrefixString(option_pair[0], "aggregate_metadata")) {
options.aggregate_metadata = true;
for (const auto& prefix : Split(option_pair[1], "#", false)) {
for (const auto& prefix : absl::StrSplit(option_pair[1], "#", absl::AllowEmpty())) {
options.aggregate_metadata_prefixes.emplace(prefix);
GOOGLE_LOG(INFO) << prefix;
}

@ -27,6 +27,7 @@ cc_library(
deps = [
"//:protobuf",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
],
)
@ -40,6 +41,7 @@ cc_test(
"//src/google/protobuf/compiler:command_line_interface",
"//src/google/protobuf/io",
"//src/google/protobuf/testing",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],

@ -59,7 +59,7 @@
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/compiler/python/helpers.h>
#include <google/protobuf/compiler/python/pyi_generator.h>
#include <google/protobuf/descriptor.h>
@ -944,7 +944,7 @@ std::string Generator::FieldReferencingExpression(
if (!containing_type) {
return ResolveKeyword(field.name());
}
return strings::Substitute("$0.$1['$2']",
return absl::Substitute("$0.$1['$2']",
ModuleLevelDescriptorName(*containing_type),
python_dict_name, field.name());
}
@ -1156,7 +1156,7 @@ std::string Generator::ModuleLevelDescriptorName(
// The C++ implementation doesn't guard against this either. Leaving
// it for now...
std::string name = NamePrefixedWithNestedTypes(descriptor, "_");
ToUpper(&name);
absl::AsciiStrToUpper(&name);
// Module-private for now. Easy to make public later; almost impossible
// to make private later.
name = "_" + name;
@ -1186,7 +1186,7 @@ std::string Generator::ModuleLevelMessageName(
std::string Generator::ModuleLevelServiceDescriptorName(
const ServiceDescriptor& descriptor) const {
std::string name = descriptor.name();
ToUpper(&name);
absl::AsciiStrToUpper(&name);
name = "_" + name;
if (descriptor.file() != file_) {
name = ModuleAlias(descriptor.file()->name()) + "." + name;
@ -1316,7 +1316,7 @@ void Generator::FixAllDescriptorOptions() const {
void Generator::FixOptionsForOneof(const OneofDescriptor& oneof) const {
std::string oneof_options = OptionsValue(oneof.options().SerializeAsString());
if (oneof_options != "None") {
std::string oneof_name = strings::Substitute(
std::string oneof_name = absl::Substitute(
"$0.$1['$2']", ModuleLevelDescriptorName(*oneof.containing_type()),
"oneofs_by_name", oneof.name());
PrintDescriptorOptionsFixingCode(oneof_name, oneof_options, printer_);

@ -74,6 +74,8 @@ struct GeneratorOptions {
class PROTOC_EXPORT Generator : public CodeGenerator {
public:
Generator();
Generator(const Generator&) = delete;
Generator& operator=(const Generator&) = delete;
~Generator() override;
// CodeGenerator methods.
@ -188,8 +190,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator {
mutable io::Printer* printer_; // Set in Generate(). Under mutex_.
bool opensource_runtime_ = true;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator);
};
} // namespace python

@ -34,6 +34,7 @@
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
@ -69,7 +70,7 @@ const char* const* kKeywordsEnd =
kKeywords + (sizeof(kKeywords) / sizeof(kKeywords[0]));
bool ContainsPythonKeyword(const std::string& module_name) {
std::vector<std::string> tokens = Split(module_name, ".");
std::vector<std::string> tokens = absl::StrSplit(module_name, ".");
for (int i = 0; i < static_cast<int>(tokens.size()); ++i) {
if (std::find(kKeywords, kKeywordsEnd, tokens[i]) != kKeywordsEnd) {
return true;

@ -33,6 +33,7 @@
#include <string>
#include "absl/strings/str_replace.h"
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>

@ -39,9 +39,9 @@
#include <google/protobuf/compiler/python/generator.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include "absl/strings/str_split.h"
namespace google {
namespace protobuf {
@ -107,7 +107,7 @@ TEST(PythonPluginTest, ImportTest) {
std::string output;
GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/test1_pb2.py", &output,
true));
std::vector<std::string> lines = Split(output, "\n");
std::vector<std::string> lines = absl::StrSplit(output, "\n");
std::string expected_import = "import test2_pb2";
bool found_expected_import = false;
for (int i = 0; i < lines.size(); ++i) {

@ -33,7 +33,9 @@
#include <string>
#include <utility>
#include "absl/strings/ascii.h"
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_split.h"
#include <google/protobuf/compiler/python/helpers.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
@ -57,7 +59,7 @@ std::string PyiGenerator::ModuleLevelName(const DescriptorT& descriptor) const {
std::string filename = descriptor.file()->name();
if (import_map_.find(filename) == import_map_.end()) {
std::string module_name = ModuleName(descriptor.file()->name());
std::vector<std::string> tokens = Split(module_name, ".");
std::vector<std::string> tokens = absl::StrSplit(module_name, ".");
module_alias = "_" + tokens.back();
} else {
module_alias = import_map_.at(filename);
@ -326,7 +328,7 @@ void PyiGenerator::PrintExtensions(const DescriptorT& descriptor) const {
for (int i = 0; i < descriptor.extension_count(); ++i) {
const FieldDescriptor* extension_field = descriptor.extension(i);
std::string constant_name = extension_field->name() + "_FIELD_NUMBER";
ToUpper(&constant_name);
absl::AsciiStrToUpper(&constant_name);
printer_->Print("$constant_name$: _ClassVar[int]\n",
"constant_name", constant_name);
printer_->Print("$name$: _descriptor.FieldDescriptor\n",
@ -435,7 +437,7 @@ void PyiGenerator::PrintMessage(
const FieldDescriptor& field_des = *message_descriptor.field(i);
printer_->Print(
"$field_number_name$: _ClassVar[int]\n", "field_number_name",
ToUpper(field_des.name()) + "_FIELD_NUMBER");
absl::AsciiStrToUpper(field_des.name()) + "_FIELD_NUMBER");
}
// Prints field name and type
for (int i = 0; i < message_descriptor.field_count(); ++i) {

@ -63,6 +63,8 @@ namespace python {
class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenerator {
public:
PyiGenerator();
PyiGenerator(const PyiGenerator&) = delete;
PyiGenerator& operator=(const PyiGenerator&) = delete;
~PyiGenerator() override;
// CodeGenerator methods.
@ -105,7 +107,6 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera
// import_map will be a mapping from filename to module alias, e.g.
// "google3/foo/bar.py" -> "_bar"
mutable std::map<std::string, std::string> import_map_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PyiGenerator);
};
} // namespace python

@ -28,6 +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 <google/protobuf/compiler/ruby/ruby_generator.h>
#include <iomanip>
#include <sstream>
@ -38,8 +40,6 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/compiler/ruby/ruby_generator.h>
namespace google {
namespace protobuf {
namespace compiler {

@ -64,6 +64,8 @@ template <class DepsGenerator>
class PROTOC_EXPORT SCCAnalyzer {
public:
explicit SCCAnalyzer() : index_(0) {}
SCCAnalyzer(const SCCAnalyzer&) = delete;
SCCAnalyzer& operator=(const SCCAnalyzer&) = delete;
const SCC* GetSCC(const Descriptor* descriptor) {
if (cache_.count(descriptor)) return cache_[descriptor].scc;
@ -151,9 +153,6 @@ class PROTOC_EXPORT SCCAnalyzer {
}
}
}
// This is necessary for compiler bug in msvc2015.
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SCCAnalyzer);
};
} // namespace compiler

@ -46,7 +46,7 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include "absl/strings/escaping.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/message.h>
@ -274,7 +274,7 @@ bool Subprocess::Communicate(const Message& input, Message* output,
child_handle_ = nullptr;
if (exit_code != 0) {
*error = strings::Substitute("Plugin failed with status code $0.", exit_code);
*error = absl::Substitute("Plugin failed with status code $0.", exit_code);
return false;
}
@ -472,12 +472,12 @@ bool Subprocess::Communicate(const Message& input, Message* output,
if (WEXITSTATUS(status) != 0) {
int error_code = WEXITSTATUS(status);
*error =
strings::Substitute("Plugin failed with status code $0.", error_code);
absl::Substitute("Plugin failed with status code $0.", error_code);
return false;
}
} else if (WIFSIGNALED(status)) {
int signal = WTERMSIG(status);
*error = strings::Substitute("Plugin killed by signal $0.", signal);
*error = absl::Substitute("Plugin killed by signal $0.", signal);
return false;
} else {
*error = "Neither WEXITSTATUS nor WTERMSIG is true?";

@ -60,7 +60,8 @@
#include "absl/strings/str_cat.h"
#include <google/protobuf/stubs/stringprintf.h>
#include "absl/strings/str_join.h"
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/str_split.h"
#include "absl/strings/substitute.h"
#include "absl/synchronization/mutex.h"
#include <google/protobuf/any.h>
#include <google/protobuf/descriptor.pb.h>
@ -423,7 +424,7 @@ class FlatAllocatorImpl {
}
std::string lowercase_name = name;
LowerString(&lowercase_name);
absl::AsciiStrToLower(&lowercase_name);
std::string camelcase_name = ToCamelCase(name, /* lower_first = */ true);
std::string json_name =
@ -487,7 +488,7 @@ class FlatAllocatorImpl {
FieldNamesResult result{nullptr, 0, 0, 0};
std::string lowercase_name = name;
LowerString(&lowercase_name);
absl::AsciiStrToLower(&lowercase_name);
result.lowercase_index = push_name(std::move(lowercase_name));
result.camelcase_index =
push_name(ToCamelCase(name, /* lower_first = */ true));
@ -2848,7 +2849,7 @@ bool FormatLineOptions(int depth, const Message& options,
std::vector<std::string> all_options;
if (RetrieveOptions(depth, options, pool, &all_options)) {
for (const std::string& option : all_options) {
strings::SubstituteAndAppend(output, "$0option $1;\n", prefix, option);
absl::SubstituteAndAppend(output, "$0option $1;\n", prefix, option);
}
}
return !all_options.empty();
@ -2900,10 +2901,10 @@ class SourceLocationCommentPrinter {
std::string FormatComment(const std::string& comment_text) {
std::string stripped_comment = comment_text;
StripWhitespace(&stripped_comment);
std::vector<std::string> lines = Split(stripped_comment, "\n");
std::vector<std::string> lines = absl::StrSplit(stripped_comment, "\n");
std::string output;
for (const std::string& line : lines) {
strings::SubstituteAndAppend(&output, "$0// $1\n", prefix_, line);
absl::SubstituteAndAppend(&output, "$0// $1\n", prefix_, line);
}
return output;
}
@ -2932,7 +2933,7 @@ std::string FileDescriptor::DebugStringWithOptions(
SourceLocationCommentPrinter syntax_comment(this, path, "",
debug_string_options);
syntax_comment.AddPreComment(&contents);
strings::SubstituteAndAppend(&contents, "syntax = \"$0\";\n\n",
absl::SubstituteAndAppend(&contents, "syntax = \"$0\";\n\n",
SyntaxName(syntax()));
syntax_comment.AddPostComment(&contents);
}
@ -2947,13 +2948,13 @@ std::string FileDescriptor::DebugStringWithOptions(
for (int i = 0; i < dependency_count(); i++) {
if (public_dependencies.contains(i)) {
strings::SubstituteAndAppend(&contents, "import public \"$0\";\n",
absl::SubstituteAndAppend(&contents, "import public \"$0\";\n",
dependency(i)->name());
} else if (weak_dependencies.contains(i)) {
strings::SubstituteAndAppend(&contents, "import weak \"$0\";\n",
absl::SubstituteAndAppend(&contents, "import weak \"$0\";\n",
dependency(i)->name());
} else {
strings::SubstituteAndAppend(&contents, "import \"$0\";\n",
absl::SubstituteAndAppend(&contents, "import \"$0\";\n",
dependency(i)->name());
}
}
@ -2964,7 +2965,7 @@ std::string FileDescriptor::DebugStringWithOptions(
SourceLocationCommentPrinter package_comment(this, path, "",
debug_string_options);
package_comment.AddPreComment(&contents);
strings::SubstituteAndAppend(&contents, "package $0;\n\n", package());
absl::SubstituteAndAppend(&contents, "package $0;\n\n", package());
package_comment.AddPostComment(&contents);
}
@ -3004,7 +3005,7 @@ std::string FileDescriptor::DebugStringWithOptions(
if (extension(i)->containing_type() != containing_type) {
if (i > 0) contents.append("}\n\n");
containing_type = extension(i)->containing_type();
strings::SubstituteAndAppend(&contents, "extend .$0 {\n",
absl::SubstituteAndAppend(&contents, "extend .$0 {\n",
containing_type->full_name());
}
extension(i)->DebugString(1, &contents, debug_string_options);
@ -3043,7 +3044,7 @@ void Descriptor::DebugString(int depth, std::string* contents,
comment_printer.AddPreComment(contents);
if (include_opening_clause) {
strings::SubstituteAndAppend(contents, "$0message $1", prefix, name());
absl::SubstituteAndAppend(contents, "$0message $1", prefix, name());
}
contents->append(" {\n");
@ -3084,7 +3085,7 @@ void Descriptor::DebugString(int depth, std::string* contents,
}
for (int i = 0; i < extension_range_count(); i++) {
strings::SubstituteAndAppend(contents, "$0 extensions $1 to $2;\n", prefix,
absl::SubstituteAndAppend(contents, "$0 extensions $1 to $2;\n", prefix,
extension_range(i)->start,
extension_range(i)->end - 1);
}
@ -3093,26 +3094,26 @@ void Descriptor::DebugString(int depth, std::string* contents,
const Descriptor* containing_type = nullptr;
for (int i = 0; i < extension_count(); i++) {
if (extension(i)->containing_type() != containing_type) {
if (i > 0) strings::SubstituteAndAppend(contents, "$0 }\n", prefix);
if (i > 0) absl::SubstituteAndAppend(contents, "$0 }\n", prefix);
containing_type = extension(i)->containing_type();
strings::SubstituteAndAppend(contents, "$0 extend .$1 {\n", prefix,
absl::SubstituteAndAppend(contents, "$0 extend .$1 {\n", prefix,
containing_type->full_name());
}
extension(i)->DebugString(depth + 1, contents, debug_string_options);
}
if (extension_count() > 0)
strings::SubstituteAndAppend(contents, "$0 }\n", prefix);
absl::SubstituteAndAppend(contents, "$0 }\n", prefix);
if (reserved_range_count() > 0) {
strings::SubstituteAndAppend(contents, "$0 reserved ", prefix);
absl::SubstituteAndAppend(contents, "$0 reserved ", prefix);
for (int i = 0; i < reserved_range_count(); i++) {
const Descriptor::ReservedRange* range = reserved_range(i);
if (range->end == range->start + 1) {
strings::SubstituteAndAppend(contents, "$0, ", range->start);
absl::SubstituteAndAppend(contents, "$0, ", range->start);
} else if (range->end > FieldDescriptor::kMaxNumber) {
strings::SubstituteAndAppend(contents, "$0 to max, ", range->start);
absl::SubstituteAndAppend(contents, "$0 to max, ", range->start);
} else {
strings::SubstituteAndAppend(contents, "$0 to $1, ", range->start,
absl::SubstituteAndAppend(contents, "$0 to $1, ", range->start,
range->end - 1);
}
}
@ -3120,15 +3121,15 @@ void Descriptor::DebugString(int depth, std::string* contents,
}
if (reserved_name_count() > 0) {
strings::SubstituteAndAppend(contents, "$0 reserved ", prefix);
absl::SubstituteAndAppend(contents, "$0 reserved ", prefix);
for (int i = 0; i < reserved_name_count(); i++) {
strings::SubstituteAndAppend(contents, "\"$0\", ",
absl::SubstituteAndAppend(contents, "\"$0\", ",
absl::CEscape(reserved_name(i)));
}
contents->replace(contents->size() - 2, 2, ";\n");
}
strings::SubstituteAndAppend(contents, "$0}\n", prefix);
absl::SubstituteAndAppend(contents, "$0}\n", prefix);
comment_printer.AddPostComment(contents);
}
@ -3142,7 +3143,7 @@ std::string FieldDescriptor::DebugStringWithOptions(
std::string contents;
int depth = 0;
if (is_extension()) {
strings::SubstituteAndAppend(&contents, "extend .$0 {\n",
absl::SubstituteAndAppend(&contents, "extend .$0 {\n",
containing_type()->full_name());
depth = 1;
}
@ -3173,7 +3174,7 @@ void FieldDescriptor::DebugString(
// Special case map fields.
if (is_map()) {
strings::SubstituteAndAppend(
absl::SubstituteAndAppend(
&field_type, "map<$0, $1>",
message_type()->field(0)->FieldTypeNameDebugString(),
message_type()->field(1)->FieldTypeNameDebugString());
@ -3193,14 +3194,14 @@ void FieldDescriptor::DebugString(
debug_string_options);
comment_printer.AddPreComment(contents);
strings::SubstituteAndAppend(
absl::SubstituteAndAppend(
contents, "$0$1$2 $3 = $4", prefix, label, field_type,
type() == TYPE_GROUP ? message_type()->name() : name(), number());
bool bracketed = false;
if (has_default_value()) {
bracketed = true;
strings::SubstituteAndAppend(contents, " [default = $0",
absl::SubstituteAndAppend(contents, " [default = $0",
DefaultValueAsString(true));
}
if (has_json_name_) {
@ -3261,7 +3262,7 @@ void OneofDescriptor::DebugString(
SourceLocationCommentPrinter comment_printer(this, prefix,
debug_string_options);
comment_printer.AddPreComment(contents);
strings::SubstituteAndAppend(contents, "$0oneof $1 {", prefix, name());
absl::SubstituteAndAppend(contents, "$0oneof $1 {", prefix, name());
FormatLineOptions(depth, options(), containing_type()->file()->pool(),
contents);
@ -3273,7 +3274,7 @@ void OneofDescriptor::DebugString(
for (int i = 0; i < field_count(); i++) {
field(i)->DebugString(depth, contents, debug_string_options);
}
strings::SubstituteAndAppend(contents, "$0}\n", prefix);
absl::SubstituteAndAppend(contents, "$0}\n", prefix);
}
comment_printer.AddPostComment(contents);
}
@ -3300,7 +3301,7 @@ void EnumDescriptor::DebugString(
debug_string_options);
comment_printer.AddPreComment(contents);
strings::SubstituteAndAppend(contents, "$0enum $1 {\n", prefix, name());
absl::SubstituteAndAppend(contents, "$0enum $1 {\n", prefix, name());
FormatLineOptions(depth, options(), file()->pool(), contents);
@ -3309,15 +3310,15 @@ void EnumDescriptor::DebugString(
}
if (reserved_range_count() > 0) {
strings::SubstituteAndAppend(contents, "$0 reserved ", prefix);
absl::SubstituteAndAppend(contents, "$0 reserved ", prefix);
for (int i = 0; i < reserved_range_count(); i++) {
const EnumDescriptor::ReservedRange* range = reserved_range(i);
if (range->end == range->start) {
strings::SubstituteAndAppend(contents, "$0, ", range->start);
absl::SubstituteAndAppend(contents, "$0, ", range->start);
} else if (range->end == INT_MAX) {
strings::SubstituteAndAppend(contents, "$0 to max, ", range->start);
absl::SubstituteAndAppend(contents, "$0 to max, ", range->start);
} else {
strings::SubstituteAndAppend(contents, "$0 to $1, ", range->start,
absl::SubstituteAndAppend(contents, "$0 to $1, ", range->start,
range->end);
}
}
@ -3325,15 +3326,15 @@ void EnumDescriptor::DebugString(
}
if (reserved_name_count() > 0) {
strings::SubstituteAndAppend(contents, "$0 reserved ", prefix);
absl::SubstituteAndAppend(contents, "$0 reserved ", prefix);
for (int i = 0; i < reserved_name_count(); i++) {
strings::SubstituteAndAppend(contents, "\"$0\", ",
absl::SubstituteAndAppend(contents, "\"$0\", ",
absl::CEscape(reserved_name(i)));
}
contents->replace(contents->size() - 2, 2, ";\n");
}
strings::SubstituteAndAppend(contents, "$0}\n", prefix);
absl::SubstituteAndAppend(contents, "$0}\n", prefix);
comment_printer.AddPostComment(contents);
}
@ -3359,12 +3360,12 @@ void EnumValueDescriptor::DebugString(
debug_string_options);
comment_printer.AddPreComment(contents);
strings::SubstituteAndAppend(contents, "$0$1 = $2", prefix, name(), number());
absl::SubstituteAndAppend(contents, "$0$1 = $2", prefix, name(), number());
std::string formatted_options;
if (FormatBracketedOptions(depth, options(), type()->file()->pool(),
&formatted_options)) {
strings::SubstituteAndAppend(contents, " [$0]", formatted_options);
absl::SubstituteAndAppend(contents, " [$0]", formatted_options);
}
contents->append(";\n");
@ -3390,7 +3391,7 @@ void ServiceDescriptor::DebugString(
debug_string_options);
comment_printer.AddPreComment(contents);
strings::SubstituteAndAppend(contents, "service $0 {\n", name());
absl::SubstituteAndAppend(contents, "service $0 {\n", name());
FormatLineOptions(1, options(), file()->pool(), contents);
@ -3425,7 +3426,7 @@ void MethodDescriptor::DebugString(
debug_string_options);
comment_printer.AddPreComment(contents);
strings::SubstituteAndAppend(
absl::SubstituteAndAppend(
contents, "$0rpc $1($4.$2) returns ($5.$3)", prefix, name(),
input_type()->full_name(), output_type()->full_name(),
client_streaming() ? "stream " : "", server_streaming() ? "stream " : "");
@ -3433,7 +3434,7 @@ void MethodDescriptor::DebugString(
std::string formatted_options;
if (FormatLineOptions(depth, options(), service()->file()->pool(),
&formatted_options)) {
strings::SubstituteAndAppend(contents, " {\n$0$1}\n", formatted_options,
absl::SubstituteAndAppend(contents, " {\n$0$1}\n", formatted_options,
prefix);
} else {
contents->append(";\n");
@ -3894,6 +3895,8 @@ class DescriptorBuilder {
// specified builder, which must not be nullptr. We don't take ownership of
// the builder.
explicit OptionInterpreter(DescriptorBuilder* builder);
OptionInterpreter(const OptionInterpreter&) = delete;
OptionInterpreter& operator=(const OptionInterpreter&) = delete;
~OptionInterpreter();
@ -4010,8 +4013,6 @@ class DescriptorBuilder {
// Factory used to create the dynamic messages we need to parse
// any aggregate option values we encounter.
DynamicMessageFactory dynamic_factory_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OptionInterpreter);
};
// Work-around for broken compilers: According to the C++ standard,
@ -5396,7 +5397,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
if (range1.end() > range2.start() && range2.end() > range1.start()) {
AddError(result->full_name(), proto.reserved_range(i),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Reserved range $0 to $1 overlaps with "
absl::Substitute("Reserved range $0 to $1 overlaps with "
"already-defined range $2 to $3.",
range2.start(), range2.end() - 1,
range1.start(), range1.end() - 1));
@ -5409,7 +5410,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
const std::string& name = proto.reserved_name(i);
if (!reserved_name_set.insert(name).second) {
AddError(name, proto, DescriptorPool::ErrorCollector::NAME,
strings::Substitute("Field name \"$0\" is reserved multiple times.",
absl::Substitute("Field name \"$0\" is reserved multiple times.",
name));
}
}
@ -5425,7 +5426,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
AddError(
field->full_name(), proto.extension_range(j),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute(
absl::Substitute(
"Extension range $0 to $1 includes field \"$2\" ($3).",
range->start, range->end - 1, field->name(), field->number()));
}
@ -5437,7 +5438,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
proto.reserved_range(j), DescriptorPool::ErrorCollector::NUMBER);
AddError(field->full_name(), proto.reserved_range(j),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Field \"$0\" uses reserved number $1.",
absl::Substitute("Field \"$0\" uses reserved number $1.",
field->name(), field->number()));
}
}
@ -5445,7 +5446,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
AddError(
field->full_name(), proto.field(i),
DescriptorPool::ErrorCollector::NAME,
strings::Substitute("Field name \"$0\" is reserved.", field->name()));
absl::Substitute("Field name \"$0\" is reserved.", field->name()));
}
}
@ -5459,7 +5460,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
if (range1->end > range2->start && range2->end > range1->start) {
AddError(result->full_name(), proto.extension_range(i),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Extension range $0 to $1 overlaps with "
absl::Substitute("Extension range $0 to $1 overlaps with "
"reserved range $2 to $3.",
range1->start, range1->end - 1, range2->start,
range2->end - 1));
@ -5470,7 +5471,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
if (range1->end > range2->start && range2->end > range1->start) {
AddError(result->full_name(), proto.extension_range(i),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Extension range $0 to $1 overlaps with "
absl::Substitute("Extension range $0 to $1 overlaps with "
"already-defined range $2 to $3.",
range2->start, range2->end - 1, range1->start,
range1->end - 1));
@ -5698,14 +5699,14 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
message_hints_[parent].RequestHintOnFieldNumbers(
proto, DescriptorPool::ErrorCollector::NUMBER);
AddError(result->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Field numbers cannot be greater than $0.",
absl::Substitute("Field numbers cannot be greater than $0.",
FieldDescriptor::kMaxNumber));
} else if (result->number() >= FieldDescriptor::kFirstReservedNumber &&
result->number() <= FieldDescriptor::kLastReservedNumber) {
message_hints_[parent].RequestHintOnFieldNumbers(
proto, DescriptorPool::ErrorCollector::NUMBER);
AddError(result->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute(
absl::Substitute(
"Field numbers $0 through $1 are reserved for the protocol "
"buffer library implementation.",
FieldDescriptor::kFirstReservedNumber,
@ -5740,7 +5741,7 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
proto.oneof_index() >= parent->oneof_decl_count()) {
AddError(result->full_name(), proto,
DescriptorPool::ErrorCollector::TYPE,
strings::Substitute("FieldDescriptorProto.oneof_index $0 is "
absl::Substitute("FieldDescriptorProto.oneof_index $0 is "
"out of range for type \"$1\".",
proto.oneof_index(), parent->name()));
} else {
@ -5989,7 +5990,7 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto,
if (range1.end() >= range2.start() && range2.end() >= range1.start()) {
AddError(result->full_name(), proto.reserved_range(i),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Reserved range $0 to $1 overlaps with "
absl::Substitute("Reserved range $0 to $1 overlaps with "
"already-defined range $2 to $3.",
range2.start(), range2.end(), range1.start(),
range1.end()));
@ -6004,7 +6005,7 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto,
reserved_name_set.insert(name);
} else {
AddError(name, proto, DescriptorPool::ErrorCollector::NAME,
strings::Substitute("Enum value \"$0\" is reserved multiple times.",
absl::Substitute("Enum value \"$0\" is reserved multiple times.",
name));
}
}
@ -6016,7 +6017,7 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto,
if (range->start <= value->number() && value->number() <= range->end) {
AddError(value->full_name(), proto.reserved_range(j),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Enum value \"$0\" uses reserved number $1.",
absl::Substitute("Enum value \"$0\" uses reserved number $1.",
value->name(), value->number()));
}
}
@ -6024,7 +6025,7 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto,
AddError(
value->full_name(), proto.value(i),
DescriptorPool::ErrorCollector::NAME,
strings::Substitute("Enum value \"$0\" is reserved.", value->name()));
absl::Substitute("Enum value \"$0\" is reserved.", value->name()));
}
}
}
@ -6222,7 +6223,7 @@ void DescriptorBuilder::CrossLinkMessage(Descriptor* message,
message->field(i - 1)->containing_oneof() != oneof_decl) {
AddError(message->full_name() + "." + message->field(i - 1)->name(),
proto.field(i - 1), DescriptorPool::ErrorCollector::TYPE,
strings::Substitute(
absl::Substitute(
"Fields in the same oneof must be defined consecutively. "
"\"$0\" cannot be defined before the completion of the "
"\"$1\" oneof definition.",
@ -6342,7 +6343,7 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field,
if (!skip_check) {
AddError(field->full_name(), proto,
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("\"$0\" does not declare $1 as an "
absl::Substitute("\"$0\" does not declare $1 as an "
"extension number.",
field->containing_type()->full_name(),
field->number()));
@ -6533,14 +6534,14 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field,
if (field->is_extension()) {
AddError(field->full_name(), proto,
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Extension number $0 has already been used "
absl::Substitute("Extension number $0 has already been used "
"in \"$1\" by extension \"$2\".",
field->number(), containing_type_name,
conflicting_field->full_name()));
} else {
AddError(field->full_name(), proto,
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Field number $0 has already been used in "
absl::Substitute("Field number $0 has already been used in "
"\"$1\" by field \"$2\".",
field->number(), containing_type_name,
conflicting_field->name()));
@ -6554,7 +6555,7 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field,
field->containing_type() == nullptr
? "unknown"
: field->containing_type()->full_name();
std::string error_msg = strings::Substitute(
std::string error_msg = absl::Substitute(
"Extension number $0 has already been used in \"$1\" by extension "
"\"$2\" defined in $3.",
field->number(), containing_type_name,
@ -6896,7 +6897,7 @@ void DescriptorBuilder::ValidateMessageOptions(Descriptor* message,
if (message->extension_range(i)->end > max_extension_range + 1) {
AddError(message->full_name(), proto.extension_range(i),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Extension numbers cannot be greater than $0.",
absl::Substitute("Extension numbers cannot be greater than $0.",
max_extension_range));
}

@ -259,6 +259,10 @@ class PROTOBUF_EXPORT SymbolBaseN : public SymbolBase {};
class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase {
public:
typedef DescriptorProto Proto;
#ifndef SWIG
Descriptor(const Descriptor&) = delete;
Descriptor& operator=(const Descriptor&) = delete;
#endif
// The name of the message type, not including its scope.
const std::string& name() const;
@ -607,7 +611,6 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase {
friend class OneofDescriptor;
friend class MethodDescriptor;
friend class FileDescriptor;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(Descriptor, 136);
@ -626,6 +629,11 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
public:
typedef FieldDescriptorProto Proto;
#ifndef SWIG
FieldDescriptor(const FieldDescriptor&) = delete;
FieldDescriptor& operator=(const FieldDescriptor&) = delete;
#endif
// Identifies a field type. 0 is reserved for errors. The order is weird
// for historical reasons. Types 12 and up are new in proto2.
enum Type {
@ -984,7 +992,6 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
friend class FileDescriptor;
friend class Descriptor;
friend class OneofDescriptor;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FieldDescriptor, 72);
@ -994,6 +1001,11 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase {
public:
typedef OneofDescriptorProto Proto;
#ifndef SWIG
OneofDescriptor(const OneofDescriptor&) = delete;
OneofDescriptor& operator=(const OneofDescriptor&) = delete;
#endif
const std::string& name() const; // Name of this oneof.
const std::string& full_name() const; // Fully-qualified name of the oneof.
@ -1065,7 +1077,6 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase {
OneofDescriptor() {}
friend class DescriptorBuilder;
friend class Descriptor;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofDescriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(OneofDescriptor, 40);
@ -1077,6 +1088,11 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase {
public:
typedef EnumDescriptorProto Proto;
#ifndef SWIG
EnumDescriptor(const EnumDescriptor&) = delete;
EnumDescriptor& operator=(const EnumDescriptor&) = delete;
#endif
// The name of this enum type in the containing scope.
const std::string& name() const;
@ -1236,7 +1252,6 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase {
friend class FileDescriptor;
friend class DescriptorPool;
friend class Reflection;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumDescriptor, 72);
@ -1251,6 +1266,11 @@ class PROTOBUF_EXPORT EnumValueDescriptor : private internal::SymbolBaseN<0>,
public:
typedef EnumValueDescriptorProto Proto;
#ifndef SWIG
EnumValueDescriptor(const EnumValueDescriptor&) = delete;
EnumValueDescriptor& operator=(const EnumValueDescriptor&) = delete;
#endif
const std::string& name() const; // Name of this enum constant.
int index() const; // Index within the enums's Descriptor.
int number() const; // Numeric value of this enum constant.
@ -1321,7 +1341,6 @@ class PROTOBUF_EXPORT EnumValueDescriptor : private internal::SymbolBaseN<0>,
friend class DescriptorPool;
friend class FileDescriptorTables;
friend class Reflection;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumValueDescriptor, 32);
@ -1332,6 +1351,11 @@ class PROTOBUF_EXPORT ServiceDescriptor : private internal::SymbolBase {
public:
typedef ServiceDescriptorProto Proto;
#ifndef SWIG
ServiceDescriptor(const ServiceDescriptor&) = delete;
ServiceDescriptor& operator=(const ServiceDescriptor&) = delete;
#endif
// The name of the service, not including its containing scope.
const std::string& name() const;
// The fully-qualified name of the service, scope delimited by periods.
@ -1404,7 +1428,6 @@ class PROTOBUF_EXPORT ServiceDescriptor : private internal::SymbolBase {
friend class DescriptorBuilder;
friend class FileDescriptor;
friend class MethodDescriptor;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(ServiceDescriptor, 48);
@ -1417,6 +1440,11 @@ class PROTOBUF_EXPORT MethodDescriptor : private internal::SymbolBase {
public:
typedef MethodDescriptorProto Proto;
#ifndef SWIG
MethodDescriptor(const MethodDescriptor&) = delete;
MethodDescriptor& operator=(const MethodDescriptor&) = delete;
#endif
// Name of this method, not including containing scope.
const std::string& name() const;
// The fully-qualified name of the method, scope delimited by periods.
@ -1493,7 +1521,6 @@ class PROTOBUF_EXPORT MethodDescriptor : private internal::SymbolBase {
MethodDescriptor() {}
friend class DescriptorBuilder;
friend class ServiceDescriptor;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MethodDescriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(MethodDescriptor, 64);
@ -1505,6 +1532,11 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
public:
typedef FileDescriptorProto Proto;
#ifndef SWIG
FileDescriptor(const FileDescriptor&) = delete;
FileDescriptor& operator=(const FileDescriptor&) = delete;
#endif
// The filename, relative to the source tree.
// e.g. "foo/bar/baz.proto"
const std::string& name() const;
@ -1701,7 +1733,6 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
friend class EnumValueDescriptor;
friend class MethodDescriptor;
friend class ServiceDescriptor;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor);
};
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FileDescriptor, 152);
@ -1764,6 +1795,10 @@ class PROTOBUF_EXPORT DescriptorPool {
explicit DescriptorPool(DescriptorDatabase* fallback_database,
ErrorCollector* error_collector = nullptr);
#ifndef SWIG
DescriptorPool(const DescriptorPool&) = delete;
DescriptorPool& operator=(const DescriptorPool&) = delete;
#endif
~DescriptorPool();
// Get a pointer to the generated pool. Generated protocol message classes
@ -1826,6 +1861,10 @@ class PROTOBUF_EXPORT DescriptorPool {
class PROTOBUF_EXPORT ErrorCollector {
public:
inline ErrorCollector() {}
#ifndef SWIG
ErrorCollector(const ErrorCollector&) = delete;
ErrorCollector& operator=(const ErrorCollector&) = delete;
#endif
virtual ~ErrorCollector();
// These constants specify what exact part of the construct is broken.
@ -1866,9 +1905,6 @@ class PROTOBUF_EXPORT DescriptorPool {
ErrorLocation /*location*/, // One of the location constants, above.
const std::string& /*message*/ // Human-readable error message.
) {}
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector);
};
// Convert the FileDescriptorProto to real descriptors and place them in
@ -2073,8 +2109,6 @@ class PROTOBUF_EXPORT DescriptorPool {
// Set of files to track for unused imports. The bool value when true means
// unused imports are treated as errors (and as warnings when false).
std::map<std::string, bool> unused_import_track_files_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool);
};

@ -40,6 +40,7 @@
#include "absl/strings/ascii.h"
#include <google/protobuf/stubs/strutil.h>
#include "absl/strings/str_replace.h"
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/stl_util.h>

@ -74,6 +74,8 @@ class MergedDescriptorDatabase;
class PROTOBUF_EXPORT DescriptorDatabase {
public:
inline DescriptorDatabase() {}
DescriptorDatabase(const DescriptorDatabase&) = delete;
DescriptorDatabase& operator=(const DescriptorDatabase&) = delete;
virtual ~DescriptorDatabase();
// Find a file by file name. Fills in in *output and returns true if found.
@ -136,9 +138,6 @@ class PROTOBUF_EXPORT DescriptorDatabase {
// searching all message names, otherwise returns false and leaves output
// unchanged.
bool FindAllMessageNames(std::vector<std::string>* output);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase);
};
// A DescriptorDatabase into which you can insert files manually.
@ -165,6 +164,8 @@ class PROTOBUF_EXPORT DescriptorDatabase {
class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
public:
SimpleDescriptorDatabase();
SimpleDescriptorDatabase(const SimpleDescriptorDatabase&) = delete;
SimpleDescriptorDatabase& operator=(const SimpleDescriptorDatabase&) = delete;
~SimpleDescriptorDatabase() override;
// Adds the FileDescriptorProto to the database, making a copy. The object
@ -278,8 +279,6 @@ class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
// If file is non-nullptr, copy it into *output and return true, otherwise
// return false.
bool MaybeCopy(const FileDescriptorProto* file, FileDescriptorProto* output);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase);
};
// Very similar to SimpleDescriptorDatabase, but stores all the descriptors
@ -290,6 +289,9 @@ class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
class PROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase {
public:
EncodedDescriptorDatabase();
EncodedDescriptorDatabase(const EncodedDescriptorDatabase&) = delete;
EncodedDescriptorDatabase& operator=(const EncodedDescriptorDatabase&) =
delete;
~EncodedDescriptorDatabase() override;
// Adds the FileDescriptorProto to the database. The descriptor is provided
@ -331,14 +333,14 @@ class PROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase {
// return true, otherwise return false.
bool MaybeParse(std::pair<const void*, int> encoded_file,
FileDescriptorProto* output);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase);
};
// A DescriptorDatabase that fetches files from a given pool.
class PROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase {
public:
explicit DescriptorPoolDatabase(const DescriptorPool& pool);
DescriptorPoolDatabase(const DescriptorPoolDatabase&) = delete;
DescriptorPoolDatabase& operator=(const DescriptorPoolDatabase&) = delete;
~DescriptorPoolDatabase() override;
// implements DescriptorDatabase -----------------------------------
@ -354,7 +356,6 @@ class PROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase {
private:
const DescriptorPool& pool_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase);
};
// A DescriptorDatabase that wraps two or more others. It first searches the
@ -369,6 +370,8 @@ class PROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
// DescriptorDatabases need to stick around.
explicit MergedDescriptorDatabase(
const std::vector<DescriptorDatabase*>& sources);
MergedDescriptorDatabase(const MergedDescriptorDatabase&) = delete;
MergedDescriptorDatabase& operator=(const MergedDescriptorDatabase&) = delete;
~MergedDescriptorDatabase() override;
// implements DescriptorDatabase -----------------------------------
@ -391,7 +394,6 @@ class PROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
private:
std::vector<DescriptorDatabase*> sources_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase);
};
} // namespace protobuf

@ -60,7 +60,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/substitute.h>
#include "absl/strings/substitute.h"
// Must be included last.
@ -247,7 +247,7 @@ class MockErrorCollector : public DescriptorPool::ErrorCollector {
break;
}
strings::SubstituteAndAppend(&text_, "$0: $1: $2: $3\n", filename,
absl::SubstituteAndAppend(&text_, "$0: $1: $2: $3\n", filename,
element_name, location_name, message);
}
@ -292,7 +292,7 @@ class MockErrorCollector : public DescriptorPool::ErrorCollector {
break;
}
strings::SubstituteAndAppend(&warning_text_, "$0: $1: $2: $3\n", filename,
absl::SubstituteAndAppend(&warning_text_, "$0: $1: $2: $3\n", filename,
element_name, location_name, message);
}
};
@ -4244,7 +4244,7 @@ TEST_F(ValidationErrorTest, ReservedFieldsDebugString) {
}
TEST_F(ValidationErrorTest, DebugStringReservedRangeMax) {
const FileDescriptor* file = BuildFile(strings::Substitute(
const FileDescriptor* file = BuildFile(absl::Substitute(
"name: \"foo.proto\" "
"enum_type { "
" name: \"Bar\""
@ -5844,7 +5844,7 @@ TEST_F(ValidationErrorTest, DuplicateExtensionFieldNumber) {
// errors. The "value" argument is embedded inside the
// "uninterpreted_option" portion of the result.
static std::string EmbedAggregateValue(const char* value) {
return strings::Substitute(
return absl::Substitute(
"name: \"foo.proto\" "
"dependency: \"google/protobuf/descriptor.proto\" "
"message_type { name: \"Foo\" } "
@ -7338,19 +7338,19 @@ class ExponentialErrorDatabase : public DescriptorDatabase {
bool PopulateFile(int file_num, FileDescriptorProto* output) {
GOOGLE_CHECK_GE(file_num, 0);
output->Clear();
output->set_name(strings::Substitute("file$0.proto", file_num));
output->set_name(absl::Substitute("file$0.proto", file_num));
// file0.proto doesn't define Message0
if (file_num > 0) {
DescriptorProto* message = output->add_message_type();
message->set_name(strings::Substitute("Message$0", file_num));
message->set_name(absl::Substitute("Message$0", file_num));
for (int i = 0; i < file_num; ++i) {
output->add_dependency(strings::Substitute("file$0.proto", i));
output->add_dependency(absl::Substitute("file$0.proto", i));
FieldDescriptorProto* field = message->add_field();
field->set_name(strings::Substitute("field$0", i));
field->set_name(absl::Substitute("field$0", i));
field->set_number(i);
field->set_label(FieldDescriptorProto::LABEL_OPTIONAL);
field->set_type(FieldDescriptorProto::TYPE_MESSAGE);
field->set_type_name(strings::Substitute("Message$0", i));
field->set_type_name(absl::Substitute("Message$0", i));
}
}
return true;
@ -7400,6 +7400,8 @@ TEST_F(DatabaseBackedPoolTest, DoesntFallbackOnWrongType) {
class AbortingErrorCollector : public DescriptorPool::ErrorCollector {
public:
AbortingErrorCollector() {}
AbortingErrorCollector(const AbortingErrorCollector&) = delete;
AbortingErrorCollector& operator=(const AbortingErrorCollector&) = delete;
void AddError(const std::string& filename, const std::string& element_name,
const Message* message, ErrorLocation location,
@ -7407,9 +7409,6 @@ class AbortingErrorCollector : public DescriptorPool::ErrorCollector {
GOOGLE_LOG(FATAL) << "AddError() called unexpectedly: " << filename << " ["
<< element_name << "]: " << error_message;
}
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AbortingErrorCollector);
};
// A source tree containing only one file.
@ -7417,6 +7416,8 @@ class SingletonSourceTree : public compiler::SourceTree {
public:
SingletonSourceTree(const std::string& filename, const std::string& contents)
: filename_(filename), contents_(contents) {}
SingletonSourceTree(const SingletonSourceTree&) = delete;
SingletonSourceTree& operator=(const SingletonSourceTree&) = delete;
io::ZeroCopyInputStream* Open(const std::string& filename) override {
return filename == filename_
@ -7427,8 +7428,6 @@ class SingletonSourceTree : public compiler::SourceTree {
private:
const std::string filename_;
const std::string contents_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SingletonSourceTree);
};
const char* const kSourceLocationTestInput =
@ -7523,7 +7522,7 @@ class SourceLocationTest : public testing::Test {
}
static std::string PrintSourceLocation(const SourceLocation& loc) {
return strings::Substitute("$0:$1-$2:$3", 1 + loc.start_line,
return absl::Substitute("$0:$1-$2:$3", 1 + loc.start_line,
1 + loc.start_column, 1 + loc.end_line,
1 + loc.end_column);
}

@ -208,6 +208,8 @@ class DynamicMessage : public Message {
// This should only be used by GetPrototypeNoLock() to avoid dead lock.
DynamicMessage(DynamicMessageFactory::TypeInfo* type_info, bool lock_factory);
DynamicMessage(const DynamicMessage&) = delete;
DynamicMessage& operator=(const DynamicMessage&) = delete;
~DynamicMessage() override;
@ -269,7 +271,6 @@ class DynamicMessage : public Message {
const DynamicMessageFactory::TypeInfo* type_info_;
mutable std::atomic<int> cached_byte_size_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessage);
};
struct DynamicMessageFactory::TypeInfo {

@ -98,6 +98,8 @@ class PROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory {
// this is almost never what you want to do. Almost all users should use
// the zero-arg constructor.
DynamicMessageFactory(const DescriptorPool* pool);
DynamicMessageFactory(const DynamicMessageFactory&) = delete;
DynamicMessageFactory& operator=(const DynamicMessageFactory&) = delete;
~DynamicMessageFactory() override;
@ -140,8 +142,6 @@ class PROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory {
friend class DynamicMessage;
const Message* GetPrototypeNoLock(const Descriptor* type);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory);
};
// Helper for computing a sorted list of map entries via reflection.

@ -185,6 +185,8 @@ class PROTOBUF_EXPORT ExtensionSet {
constexpr ExtensionSet();
explicit ExtensionSet(Arena* arena);
ExtensionSet(ArenaInitialized, Arena* arena) : ExtensionSet(arena) {}
ExtensionSet(const ExtensionSet&) = delete;
ExtensionSet& operator=(const ExtensionSet&) = delete;
~ExtensionSet();
// These are called at startup by protocol-compiler-generated code to
@ -538,6 +540,8 @@ class PROTOBUF_EXPORT ExtensionSet {
class PROTOBUF_EXPORT LazyMessageExtension {
public:
LazyMessageExtension() {}
LazyMessageExtension(const LazyMessageExtension&) = delete;
LazyMessageExtension& operator=(const LazyMessageExtension&) = delete;
virtual ~LazyMessageExtension() {}
virtual LazyMessageExtension* New(Arena* arena) const = 0;
@ -574,8 +578,6 @@ class PROTOBUF_EXPORT ExtensionSet {
private:
virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable.
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyMessageExtension);
};
// Give access to function defined below to see LazyMessageExtension.
friend LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena);
@ -908,8 +910,6 @@ class PROTOBUF_EXPORT ExtensionSet {
} map_;
static void DeleteFlatMap(const KeyValue* flat, uint16_t flat_capacity);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionSet);
};
constexpr ExtensionSet::ExtensionSet()

@ -33,7 +33,9 @@
#include <cstdint>
#include <cstdlib>
#include <string>
#include <type_traits>
#include <utility>
#include <google/protobuf/port.h>
#include <google/protobuf/extension_set.h>
@ -572,6 +574,10 @@ class PROTOBUF_EXPORT TcParser final {
template <typename TagType, Utf8Type utf8>
static inline const char* RepeatedString(PROTOBUF_TC_PARAM_DECL);
static inline const char* ParseRepeatedStringOnce(
const char* ptr, Arena* arena, SerialArena* serial_arena,
ParseContext* ctx, RepeatedPtrField<std::string>& field);
// Mini field lookup:
static const TcParseTableBase::FieldEntry* FindFieldEntry(
const TcParseTableBase* table, uint32_t field_num);

@ -537,7 +537,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedFixed(
auto elem = field.Add();
int space = field.Capacity() - idx;
idx = 0;
auto expected_tag = UnalignedLoad<TagType>(ptr);
const auto expected_tag = UnalignedLoad<TagType>(ptr);
do {
ptr += sizeof(TagType);
elem[idx++] = UnalignedLoad<LayoutType>(ptr);
@ -910,7 +910,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedVarint(
}
}
auto& field = RefAt<RepeatedField<FieldType>>(msg, data.offset());
auto expected_tag = UnalignedLoad<TagType>(ptr);
const auto expected_tag = UnalignedLoad<TagType>(ptr);
do {
ptr += sizeof(TagType);
uint64_t tmp;
@ -1111,7 +1111,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedEnum(
}
}
auto& field = RefAt<RepeatedField<int32_t>>(msg, data.offset());
auto expected_tag = UnalignedLoad<TagType>(ptr);
const auto expected_tag = UnalignedLoad<TagType>(ptr);
const TcParseTableBase::FieldAux aux = *table->field_aux(data.aux_idx());
do {
const char* ptr2 = ptr; // save for unknown enum case
@ -1352,31 +1352,52 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedString(
if (PROTOBUF_PREDICT_FALSE(data.coded_tag<TagType>() != 0)) {
PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS);
}
auto expected_tag = UnalignedLoad<TagType>(ptr);
const auto expected_tag = UnalignedLoad<TagType>(ptr);
auto& field = RefAt<RepeatedPtrField<std::string>>(msg, data.offset());
do {
ptr += sizeof(TagType);
std::string* str = field.Add();
ptr = InlineGreedyStringParser(str, ptr, ctx);
if (ptr == nullptr) {
return Error(PROTOBUF_TC_PARAM_PASS);
}
const auto validate_last_string = [expected_tag, table, &field] {
switch (utf8) {
case kNoUtf8:
#ifdef NDEBUG
case kUtf8ValidateOnly:
#endif
break;
return true;
default:
if (PROTOBUF_PREDICT_TRUE(IsStructurallyValidUTF8(*str))) {
break;
if (PROTOBUF_PREDICT_TRUE(
IsStructurallyValidUTF8(field[field.size() - 1]))) {
return true;
}
ReportFastUtf8Error(FastDecodeTag(expected_tag), table);
if (utf8 == kUtf8) return Error(PROTOBUF_TC_PARAM_PASS);
break;
if (utf8 == kUtf8) return false;
return true;
}
if (!ctx->DataAvailable(ptr)) break;
} while (UnalignedLoad<TagType>(ptr) == expected_tag);
};
auto* arena = field.GetOwningArena();
SerialArena* serial_arena;
if (PROTOBUF_PREDICT_TRUE(arena != nullptr &&
arena->impl_.GetSerialArenaFast(&serial_arena) &&
field.PrepareForParse())) {
do {
ptr += sizeof(TagType);
ptr = ParseRepeatedStringOnce(ptr, arena, serial_arena, ctx, field);
if (PROTOBUF_PREDICT_FALSE(ptr == nullptr || !validate_last_string())) {
return Error(PROTOBUF_TC_PARAM_PASS);
}
if (!ctx->DataAvailable(ptr)) break;
} while (UnalignedLoad<TagType>(ptr) == expected_tag);
} else {
do {
ptr += sizeof(TagType);
std::string* str = field.Add();
ptr = InlineGreedyStringParser(str, ptr, ctx);
if (PROTOBUF_PREDICT_FALSE(ptr == nullptr || !validate_last_string())) {
return Error(PROTOBUF_TC_PARAM_PASS);
}
if (!ctx->DataAvailable(ptr)) break;
} while (UnalignedLoad<TagType>(ptr) == expected_tag);
}
return ToParseLoop(PROTOBUF_TC_PARAM_PASS);
}
@ -1887,6 +1908,19 @@ const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) {
return ToParseLoop(PROTOBUF_TC_PARAM_PASS);
}
PROTOBUF_ALWAYS_INLINE const char* TcParser::ParseRepeatedStringOnce(
const char* ptr, Arena* arena, SerialArena* serial_arena, ParseContext* ctx,
RepeatedPtrField<std::string>& field) {
int size = ReadSize(&ptr);
if (PROTOBUF_PREDICT_FALSE(!ptr)) return {};
auto* str = Arena::Create<std::string>(arena);
field.AddAllocatedForParse(str);
ptr = ctx->ReadString(ptr, size, str);
if (PROTOBUF_PREDICT_FALSE(!ptr)) return {};
PROTOBUF_ASSUME(ptr != nullptr);
return ptr;
}
const char* TcParser::MpRepeatedString(PROTOBUF_TC_PARAM_DECL) {
const auto& entry = RefAt<FieldEntry>(table, data.entry_offset());
const uint16_t type_card = entry.type_card;
@ -1904,18 +1938,39 @@ const char* TcParser::MpRepeatedString(PROTOBUF_TC_PARAM_DECL) {
auto& field = RefAt<RepeatedPtrField<std::string>>(msg, entry.offset);
const char* ptr2 = ptr;
uint32_t next_tag;
do {
ptr = ptr2;
std::string* str = field.Add();
ptr = InlineGreedyStringParser(str, ptr, ctx);
if (PROTOBUF_PREDICT_FALSE(
ptr == nullptr ||
!MpVerifyUtf8(*str, table, entry, xform_val))) {
return Error(PROTOBUF_TC_PARAM_PASS);
}
if (!ctx->DataAvailable(ptr)) break;
ptr2 = ReadTag(ptr, &next_tag);
} while (next_tag == decoded_tag);
auto* arena = field.GetOwningArena();
SerialArena* serial_arena;
if (PROTOBUF_PREDICT_TRUE(
arena != nullptr &&
arena->impl_.GetSerialArenaFast(&serial_arena) &&
field.PrepareForParse())) {
do {
ptr = ptr2;
ptr = ParseRepeatedStringOnce(ptr, arena, serial_arena, ctx, field);
if (PROTOBUF_PREDICT_FALSE(ptr == nullptr ||
!MpVerifyUtf8(field[field.size() - 1],
table, entry, xform_val))) {
return Error(PROTOBUF_TC_PARAM_PASS);
}
if (!ctx->DataAvailable(ptr)) break;
ptr2 = ReadTag(ptr, &next_tag);
} while (next_tag == decoded_tag);
} else {
do {
ptr = ptr2;
std::string* str = field.Add();
ptr = InlineGreedyStringParser(str, ptr, ctx);
if (PROTOBUF_PREDICT_FALSE(
ptr == nullptr ||
!MpVerifyUtf8(*str, table, entry, xform_val))) {
return Error(PROTOBUF_TC_PARAM_PASS);
}
if (!ctx->DataAvailable(ptr)) break;
ptr2 = ReadTag(ptr, &next_tag);
} while (next_tag == decoded_tag);
}
break;
}

@ -62,6 +62,8 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
: data_(nullptr) {}
explicit ImplicitWeakMessage(Arena* arena)
: MessageLite(arena), data_(new std::string) {}
ImplicitWeakMessage(const ImplicitWeakMessage&) = delete;
ImplicitWeakMessage& operator=(const ImplicitWeakMessage&) = delete;
~ImplicitWeakMessage() override {
// data_ will be null in the default instance, but we can safely call delete
@ -115,7 +117,6 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
// the default instance can be constant-initialized. In the const methods, we
// have to handle the possibility of data_ being null.
std::string* data_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImplicitWeakMessage);
};
struct ImplicitWeakMessageDefaultType;

@ -177,6 +177,8 @@ class PROTOBUF_EXPORT CodedInputStream {
// faster than using an ArrayInputStream. PushLimit(size) is implied by
// this constructor.
explicit CodedInputStream(const uint8_t* buffer, int size);
CodedInputStream(const CodedInputStream&) = delete;
CodedInputStream& operator=(const CodedInputStream&) = delete;
// Destroy the CodedInputStream and position the underlying
// ZeroCopyInputStream at the first unread byte. If an error occurred while
@ -517,8 +519,6 @@ class PROTOBUF_EXPORT CodedInputStream {
MessageFactory* GetExtensionFactory();
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream);
const uint8_t* buffer_;
const uint8_t* buffer_end_; // pointer to the end of the buffer.
ZeroCopyInputStream* input_;
@ -1060,6 +1060,8 @@ class PROTOBUF_EXPORT CodedOutputStream {
template <class Stream, class = typename std::enable_if<std::is_base_of<
ZeroCopyOutputStream, Stream>::value>::type>
CodedOutputStream(Stream* stream, bool eager_init);
CodedOutputStream(const CodedOutputStream&) = delete;
CodedOutputStream& operator=(const CodedOutputStream&) = delete;
// Destroy the CodedOutputStream and position the underlying
// ZeroCopyOutputStream immediately after the last byte written.
@ -1287,7 +1289,6 @@ class PROTOBUF_EXPORT CodedOutputStream {
// REQUIRES: value >= 0x80, and that (value & 7f) has been written to *target.
static uint8_t* WriteVarint32ToArrayOutOfLineHelper(uint32_t value,
uint8_t* target);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream);
};
// inline methods ====================================================

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save