summaryrefslogtreecommitdiffstats
path: root/contrib/libs/protoc/src/google/protobuf/compiler/php
diff options
context:
space:
mode:
authornechda <[email protected]>2024-08-29 23:50:27 +0300
committernechda <[email protected]>2024-08-30 00:05:25 +0300
commite10d6638f07a82edae3ea8197b9f5c0affcc07ea (patch)
tree571c38cec05813766a1ad290c9d51ce7ace52919 /contrib/libs/protoc/src/google/protobuf/compiler/php
parente79b38f2bbbf78d295d1901d2a79f898022d5224 (diff)
Update cpp-protobuf to 22.5
Привет!\ Этот PR переключат cpp & python библиотеки protobuf на версию 22.5 Если у вас возникли проблемы после влития этого PR: 1. Если начали падать канон тесты, то проведите их переканонизацию 2. Прочитайте <https://wiki.yandex-team.ru/users/nechda/obnovlenie-cpp-protobuf-22.5/> страничку с основными изменениями 3. Если страничка в вики не помогла, то пишите в [DEVTOOLSSUPPORT](https://st.yandex-team.ru/DEVTOOLSSUPPORT) 7fecade616c20a841b9e9af7b7998bdfc8d2807d
Diffstat (limited to 'contrib/libs/protoc/src/google/protobuf/compiler/php')
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/php/names.cc144
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/php/names.h73
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.cc462
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.h16
4 files changed, 420 insertions, 275 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/php/names.cc b/contrib/libs/protoc/src/google/protobuf/compiler/php/names.cc
new file mode 100644
index 00000000000..e6fc0145f03
--- /dev/null
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/php/names.cc
@@ -0,0 +1,144 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "google/protobuf/compiler/php/names.h"
+
+#include <string>
+
+#include "google/protobuf/compiler/code_generator.h"
+#include "google/protobuf/compiler/plugin.h"
+#include "google/protobuf/descriptor.h"
+#include "google/protobuf/descriptor.pb.h"
+
+const char* const kReservedNames[] = {
+ "abstract", "and", "array", "as", "break",
+ "callable", "case", "catch", "class", "clone",
+ "const", "continue", "declare", "default", "die",
+ "do", "echo", "else", "elseif", "empty",
+ "enddeclare", "endfor", "endforeach", "endif", "endswitch",
+ "endwhile", "eval", "exit", "extends", "final",
+ "finally", "fn", "for", "foreach", "function",
+ "global", "goto", "if", "implements", "include",
+ "include_once", "instanceof", "insteadof", "interface", "isset",
+ "list", "match", "namespace", "new", "or",
+ "parent", "print", "private", "protected", "public",
+ "readonly", "require", "require_once", "return", "self",
+ "static", "switch", "throw", "trait", "try",
+ "unset", "use", "var", "while", "xor",
+ "yield", "int", "float", "bool", "string",
+ "true", "false", "null", "void", "iterable"};
+const int kReservedNamesSize = 80;
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace php {
+
+bool IsReservedName(y_absl::string_view name) {
+ TProtoStringType lower(name);
+ lower.to_lower();
+ for (int i = 0; i < kReservedNamesSize; i++) {
+ if (lower == kReservedNames[i]) {
+ return true;
+ }
+ }
+ return false;
+}
+
+TProtoStringType ReservedNamePrefix(const TProtoStringType& classname,
+ const FileDescriptor* file) {
+ if (IsReservedName(classname)) {
+ if (file->package() == "google.protobuf") {
+ return "GPB";
+ } else {
+ return "PB";
+ }
+ }
+
+ return "";
+}
+
+namespace {
+
+template <typename DescriptorType>
+TProtoStringType ClassNamePrefixImpl(const TProtoStringType& classname,
+ const DescriptorType* desc) {
+ const TProtoStringType& prefix = (desc->file()->options()).php_class_prefix();
+ if (!prefix.empty()) {
+ return prefix;
+ }
+
+ return ReservedNamePrefix(classname, desc->file());
+}
+
+template <typename DescriptorType>
+TProtoStringType GeneratedClassNameImpl(const DescriptorType* desc) {
+ TProtoStringType classname = ClassNamePrefixImpl(desc->name(), desc) + desc->name();
+ const Descriptor* containing = desc->containing_type();
+ while (containing != NULL) {
+ classname = ClassNamePrefixImpl(containing->name(), desc) + containing->name()
+ + '\\' + classname;
+ containing = containing->containing_type();
+ }
+ return classname;
+}
+
+TProtoStringType GeneratedClassNameImpl(const ServiceDescriptor* desc) {
+ TProtoStringType classname = desc->name();
+ return ClassNamePrefixImpl(classname, desc) + classname;
+}
+
+} // namespace
+
+TProtoStringType ClassNamePrefix(const TProtoStringType& classname,
+ const Descriptor* desc) {
+ return ClassNamePrefixImpl(classname, desc);
+}
+TProtoStringType ClassNamePrefix(const TProtoStringType& classname,
+ const EnumDescriptor* desc) {
+ return ClassNamePrefixImpl(classname, desc);
+}
+
+TProtoStringType GeneratedClassName(const Descriptor* desc) {
+ return GeneratedClassNameImpl(desc);
+}
+
+TProtoStringType GeneratedClassName(const EnumDescriptor* desc) {
+ return GeneratedClassNameImpl(desc);
+}
+
+TProtoStringType GeneratedClassName(const ServiceDescriptor* desc) {
+ return GeneratedClassNameImpl(desc);
+}
+
+} // namespace php
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/php/names.h b/contrib/libs/protoc/src/google/protobuf/compiler/php/names.h
new file mode 100644
index 00000000000..62d7bc5e6c3
--- /dev/null
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/php/names.h
@@ -0,0 +1,73 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__
+#define GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__
+
+#include "google/protobuf/descriptor.h"
+
+#include <string>
+
+#include "y_absl/strings/string_view.h"
+#include "google/protobuf/port_def.inc"
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace php {
+
+// Whether or not a name is reserved.
+PROTOC_EXPORT bool IsReservedName(y_absl::string_view name);
+
+// A prefix to stick in front of reserved names to avoid clashes.
+PROTOC_EXPORT TProtoStringType ReservedNamePrefix(const TProtoStringType& classname,
+ const FileDescriptor* file);
+
+// A prefix to stick in front of all class names.
+PROTOC_EXPORT TProtoStringType ClassNamePrefix(const TProtoStringType& classname,
+ const Descriptor* desc);
+PROTOC_EXPORT TProtoStringType ClassNamePrefix(const TProtoStringType& classname,
+ const EnumDescriptor* desc);
+
+// To skip reserved keywords in php, some generated classname are prefixed.
+// Other code generators may need following API to figure out the actual
+// classname.
+PROTOC_EXPORT TProtoStringType GeneratedClassName(const Descriptor* desc);
+PROTOC_EXPORT TProtoStringType GeneratedClassName(const EnumDescriptor* desc);
+PROTOC_EXPORT TProtoStringType GeneratedClassName(const ServiceDescriptor* desc);
+
+} // namespace php
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
+
+#include "google/protobuf/port_undef.inc"
+
+#endif // GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.cc b/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.cc
index ecaccec3391..a39a9c5c0ee 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.cc
@@ -28,50 +28,43 @@
// (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/php/php_generator.h>
-
-#include <google/protobuf/compiler/code_generator.h>
-#include <google/protobuf/compiler/plugin.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/io/zero_copy_stream.h>
-#include <google/protobuf/stubs/port.h>
-#include <google/protobuf/stubs/strutil.h>
+#include "google/protobuf/compiler/php/php_generator.h"
+#include <algorithm>
#include <sstream>
+#include <string>
+#include <vector>
+
+#include "google/protobuf/compiler/code_generator.h"
+#include "y_absl/container/flat_hash_map.h"
+#include "y_absl/container/flat_hash_set.h"
+#include "y_absl/log/absl_log.h"
+#include "y_absl/strings/ascii.h"
+#include "y_absl/strings/escaping.h"
+#include "y_absl/strings/str_cat.h"
+#include "y_absl/strings/str_replace.h"
+#include "y_absl/strings/str_split.h"
+#include "y_absl/strings/string_view.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/port.h>
+
#include <util/string/cast.h>
-const TProtoStringType kDescriptorFile = "google/protobuf/descriptor.proto";
-const TProtoStringType kEmptyFile = "google/protobuf/empty.proto";
-const TProtoStringType kEmptyMetadataFile = "GPBMetadata/Google/Protobuf/GPBEmpty.php";
-const TProtoStringType kDescriptorMetadataFile =
+constexpr y_absl::string_view kDescriptorFile =
+ "google/protobuf/descriptor.proto";
+constexpr y_absl::string_view kEmptyFile = "google/protobuf/empty.proto";
+constexpr y_absl::string_view kEmptyMetadataFile =
+ "GPBMetadata/Google/Protobuf/GPBEmpty.php";
+constexpr y_absl::string_view kDescriptorMetadataFile =
"GPBMetadata/Google/Protobuf/Internal/Descriptor.php";
-const TProtoStringType kDescriptorDirName = "Google/Protobuf/Internal";
-const TProtoStringType kDescriptorPackageName = "Google\\Protobuf\\Internal";
-const char* const kReservedNames[] = {
- "abstract", "and", "array", "as", "break",
- "callable", "case", "catch", "class", "clone",
- "const", "continue", "declare", "default", "die",
- "do", "echo", "else", "elseif", "empty",
- "enddeclare", "endfor", "endforeach", "endif", "endswitch",
- "endwhile", "eval", "exit", "extends", "final",
- "finally", "fn", "for", "foreach", "function",
- "global", "goto", "if", "implements", "include",
- "include_once", "instanceof", "insteadof", "interface", "isset",
- "list", "match", "namespace", "new", "or",
- "parent", "print", "private", "protected", "public",
- "readonly", "require", "require_once", "return", "self",
- "static", "switch", "throw", "trait", "try",
- "unset", "use", "var", "while", "xor",
- "yield", "int", "float", "bool", "string",
- "true", "false", "null", "void", "iterable"};
-const char* const kValidConstantNames[] = {
- "int", "float", "bool", "string", "true",
- "false", "null", "void", "iterable", "parent",
- "self", "readonly"
-};
-const int kReservedNamesSize = 80;
+constexpr y_absl::string_view kDescriptorPackageName =
+ "Google\\Protobuf\\Internal";
+constexpr y_absl::string_view kValidConstantNames[] = {
+ "int", "float", "bool", "string", "true", "false",
+ "null", "void", "iterable", "parent", "self", "readonly"};
const int kValidConstantNamesSize = 12;
const int kFieldSetter = 1;
const int kFieldGetter = 2;
@@ -86,18 +79,18 @@ struct Options {
bool is_descriptor = false;
bool aggregate_metadata = false;
bool gen_c_wkt = false;
- std::set<TProtoStringType> aggregate_metadata_prefixes;
+ y_absl::flat_hash_set<TProtoStringType> aggregate_metadata_prefixes;
};
namespace {
// Forward decls.
-TProtoStringType PhpName(const TProtoStringType& full_name, const Options& options);
+TProtoStringType PhpName(y_absl::string_view full_name, const Options& options);
TProtoStringType IntToString(arc_i32 value);
-TProtoStringType FilenameToClassname(const TProtoStringType& filename);
+TProtoStringType FilenameToClassname(y_absl::string_view filename);
TProtoStringType GeneratedMetadataFileName(const FileDescriptor* file,
const Options& options);
-TProtoStringType UnderscoresToCamelCase(const TProtoStringType& name,
+TProtoStringType UnderscoresToCamelCase(y_absl::string_view name,
bool cap_first_letter);
void Indent(io::Printer* printer);
void Outdent(io::Printer* printer);
@@ -123,68 +116,19 @@ void GenerateServiceDocComment(io::Printer* printer,
void GenerateServiceMethodDocComment(io::Printer* printer,
const MethodDescriptor* method);
-TProtoStringType ReservedNamePrefix(const TProtoStringType& classname,
- const FileDescriptor* file) {
- bool is_reserved = false;
-
- TProtoStringType lower = classname;
- lower.to_lower();
-
- for (int i = 0; i < kReservedNamesSize; i++) {
- if (lower == kReservedNames[i]) {
- is_reserved = true;
- break;
- }
- }
-
- if (is_reserved) {
- if (file->package() == "google.protobuf") {
- return "GPB";
- } else {
- return "PB";
- }
- }
-
- return "";
-}
-
template <typename DescriptorType>
TProtoStringType DescriptorFullName(const DescriptorType* desc, bool is_internal) {
+ y_absl::string_view full_name = desc->full_name();
if (is_internal) {
- return StringReplace(desc->full_name(),
- "google.protobuf",
- "google.protobuf.internal", false);
- } else {
- return desc->full_name();
- }
-}
-
-template <typename DescriptorType>
-TProtoStringType ClassNamePrefix(const TProtoStringType& classname,
- const DescriptorType* desc) {
- const TProtoStringType& prefix = (desc->file()->options()).php_class_prefix();
- if (!prefix.empty()) {
- return prefix;
- }
-
- return ReservedNamePrefix(classname, desc->file());
-}
-
-template <typename DescriptorType>
-TProtoStringType GeneratedClassNameImpl(const DescriptorType* desc) {
- TProtoStringType classname = ClassNamePrefix(desc->name(), desc) + desc->name();
- const Descriptor* containing = desc->containing_type();
- while (containing != NULL) {
- classname = ClassNamePrefix(containing->name(), desc) + containing->name()
- + '\\' + classname;
- containing = containing->containing_type();
+ constexpr y_absl::string_view replace = "google.protobuf";
+ size_t index = full_name.find(replace);
+ if (index != TProtoStringType::npos) {
+ return y_absl::StrCat(full_name.substr(0, index),
+ "google.protobuf.internal",
+ full_name.substr(index + replace.size()));
+ }
}
- return classname;
-}
-
-TProtoStringType GeneratedClassNameImpl(const ServiceDescriptor* desc) {
- TProtoStringType classname = desc->name();
- return ClassNamePrefix(classname, desc) + classname;
+ return TProtoStringType(full_name);
}
template <typename DescriptorType>
@@ -198,31 +142,13 @@ TProtoStringType LegacyGeneratedClassName(const DescriptorType* desc) {
return ClassNamePrefix(classname, desc) + classname;
}
-TProtoStringType ClassNamePrefix(const TProtoStringType& classname) {
- TProtoStringType lower = classname;
- lower.to_lower();
-
- for (int i = 0; i < kReservedNamesSize; i++) {
- if (lower == kReservedNames[i]) {
- return "PB";
- }
- }
-
- return "";
-}
-
-TProtoStringType ConstantNamePrefix(const TProtoStringType& classname) {
+TProtoStringType ConstantNamePrefix(y_absl::string_view classname) {
bool is_reserved = false;
- TProtoStringType lower = classname;
+ TProtoStringType lower(classname);
lower.to_lower();
- for (int i = 0; i < kReservedNamesSize; i++) {
- if (lower == kReservedNames[i]) {
- is_reserved = true;
- break;
- }
- }
+ is_reserved = IsReservedName(lower);
for (int i = 0; i < kValidConstantNamesSize; i++) {
if (lower == kValidConstantNames[i]) {
@@ -242,9 +168,9 @@ template <typename DescriptorType>
TProtoStringType RootPhpNamespace(const DescriptorType* desc,
const Options& options) {
if (desc->file()->options().has_php_namespace()) {
- const TProtoStringType& php_namespace = desc->file()->options().php_namespace();
+ y_absl::string_view php_namespace = desc->file()->options().php_namespace();
if (!php_namespace.empty()) {
- return php_namespace;
+ return TProtoStringType(php_namespace);
}
return "";
}
@@ -257,10 +183,10 @@ TProtoStringType RootPhpNamespace(const DescriptorType* desc,
template <typename DescriptorType>
TProtoStringType FullClassName(const DescriptorType* desc, const Options& options) {
- TProtoStringType classname = GeneratedClassNameImpl(desc);
+ TProtoStringType classname = GeneratedClassName(desc);
TProtoStringType php_namespace = RootPhpNamespace(desc, options);
if (!php_namespace.empty()) {
- return php_namespace + "\\" + classname;
+ return y_absl::StrCat(php_namespace, "\\", classname);
}
return classname;
}
@@ -278,14 +204,19 @@ TProtoStringType LegacyFullClassName(const DescriptorType* desc,
TProtoStringType classname = LegacyGeneratedClassName(desc);
TProtoStringType php_namespace = RootPhpNamespace(desc, options);
if (!php_namespace.empty()) {
- return php_namespace + "\\" + classname;
+ return y_absl::StrCat(php_namespace, "\\", classname);
}
return classname;
}
-TProtoStringType PhpName(const TProtoStringType& full_name, const Options& options) {
+TProtoStringType PhpNamePrefix(y_absl::string_view classname) {
+ if (IsReservedName(classname)) return "PB";
+ return "";
+}
+
+TProtoStringType PhpName(y_absl::string_view full_name, const Options& options) {
if (options.is_descriptor) {
- return kDescriptorPackageName;
+ return TProtoStringType(kDescriptorPackageName);
}
TProtoStringType segment;
@@ -296,7 +227,7 @@ TProtoStringType PhpName(const TProtoStringType& full_name, const Options& optio
segment += full_name[i] + ('A' - 'a');
cap_next_letter = false;
} else if (full_name[i] == '.') {
- result += ClassNamePrefix(segment) + segment + '\\';
+ result += PhpNamePrefix(segment) + segment + '\\';
segment = "";
cap_next_letter = true;
} else {
@@ -304,7 +235,7 @@ TProtoStringType PhpName(const TProtoStringType& full_name, const Options& optio
cap_next_letter = false;
}
}
- result += ClassNamePrefix(segment) + segment;
+ result += PhpNamePrefix(segment) + segment;
return result;
}
@@ -334,51 +265,51 @@ TProtoStringType DefaultForField(const FieldDescriptor* field) {
TProtoStringType GeneratedMetadataFileName(const FileDescriptor* file,
const Options& options) {
- const TProtoStringType& proto_file = file->name();
+ y_absl::string_view proto_file = file->name();
int start_index = 0;
- int first_index = proto_file.find_first_of("/", start_index);
+ int first_index = proto_file.find_first_of('/', start_index);
TProtoStringType result = "";
TProtoStringType segment = "";
if (proto_file == kEmptyFile) {
- return kEmptyMetadataFile;
+ return TProtoStringType(kEmptyMetadataFile);
}
if (options.is_descriptor) {
- return kDescriptorMetadataFile;
+ return TProtoStringType(kDescriptorMetadataFile);
}
// Append directory name.
- TProtoStringType file_no_suffix;
- int lastindex = proto_file.find_last_of(".");
+ y_absl::string_view file_no_suffix;
+ int lastindex = proto_file.find_last_of('.');
if (proto_file == kEmptyFile) {
- return kEmptyMetadataFile;
+ return TProtoStringType(kEmptyMetadataFile);
} else {
file_no_suffix = proto_file.substr(0, lastindex);
}
if (file->options().has_php_metadata_namespace()) {
- const TProtoStringType& php_metadata_namespace =
+ y_absl::string_view php_metadata_namespace =
file->options().php_metadata_namespace();
if (!php_metadata_namespace.empty() && php_metadata_namespace != "\\") {
- result += php_metadata_namespace;
+ y_absl::StrAppend(&result, php_metadata_namespace);
std::replace(result.begin(), result.vend(), '\\', '/');
if (result.at(result.size() - 1) != '/') {
- result += "/";
+ y_absl::StrAppend(&result, "/");
}
}
} else {
- result += "GPBMetadata/";
+ y_absl::StrAppend(&result, "GPBMetadata/");
while (first_index != TProtoStringType::npos) {
segment = UnderscoresToCamelCase(
file_no_suffix.substr(start_index, first_index - start_index), true);
- result += ReservedNamePrefix(segment, file) + segment + "/";
+ y_absl::StrAppend(&result, ReservedNamePrefix(segment, file), segment, "/");
start_index = first_index + 1;
- first_index = file_no_suffix.find_first_of("/", start_index);
+ first_index = file_no_suffix.find_first_of('/', start_index);
}
}
// Append file name.
- int file_name_start = file_no_suffix.find_last_of("/");
+ int file_name_start = file_no_suffix.find_last_of('/');
if (file_name_start == TProtoStringType::npos) {
file_name_start = 0;
} else {
@@ -387,7 +318,8 @@ TProtoStringType GeneratedMetadataFileName(const FileDescriptor* file,
segment = UnderscoresToCamelCase(
file_no_suffix.substr(file_name_start, first_index - file_name_start), true);
- return result + ReservedNamePrefix(segment, file) + segment + ".php";
+ return y_absl::StrCat(result, ReservedNamePrefix(segment, file), segment,
+ ".php");
}
TProtoStringType GeneratedMetadataFileName(const FileDescriptor* file,
@@ -406,7 +338,7 @@ TProtoStringType GeneratedClassFileName(const DescriptorType* desc,
result[i] = '/';
}
}
- return result + ".php";
+ return y_absl::StrCat(result, ".php");
}
template <typename DescriptorType>
@@ -419,28 +351,33 @@ TProtoStringType LegacyGeneratedClassFileName(const DescriptorType* desc,
result[i] = '/';
}
}
- return result + ".php";
+ return y_absl::StrCat(result, ".php");
}
template <typename DescriptorType>
-TProtoStringType LegacyReadOnlyGeneratedClassFileName(const DescriptorType* desc,
- const Options& options) {
- TProtoStringType php_namespace = RootPhpNamespace(desc, options);
+TProtoStringType LegacyReadOnlyGeneratedClassFileName(TProtoStringType php_namespace,
+ const DescriptorType* desc) {
if (!php_namespace.empty()) {
- return php_namespace + "/" + desc->name() + ".php";
+ for (int i = 0; i < php_namespace.size(); i++) {
+ if (php_namespace[i] == '\\') {
+ php_namespace[i] = '/';
+ }
+ }
+ return y_absl::StrCat(php_namespace, "/", desc->name(), ".php");
}
- return desc->name() + ".php";
+
+ return y_absl::StrCat(desc->name(), ".php");
}
TProtoStringType GeneratedServiceFileName(const ServiceDescriptor* service,
const Options& options) {
- TProtoStringType result = FullClassName(service, options) + "Interface";
+ TProtoStringType result = FullClassName(service, options);
for (int i = 0; i < result.size(); i++) {
if (result[i] == '\\') {
result[i] = '/';
}
}
- return result + ".php";
+ return y_absl::StrCat(result, "Interface", ".php");
}
TProtoStringType IntToString(arc_i32 value) {
@@ -492,7 +429,7 @@ TProtoStringType PhpSetterTypeName(const FieldDescriptor* field,
type = "string";
break;
case FieldDescriptor::TYPE_MESSAGE:
- type = "\\" + FullClassName(field->message_type(), options);
+ type = y_absl::StrCat("\\", FullClassName(field->message_type(), options));
break;
case FieldDescriptor::TYPE_GROUP:
return "null";
@@ -500,11 +437,12 @@ TProtoStringType PhpSetterTypeName(const FieldDescriptor* field,
}
if (field->is_repeated()) {
// accommodate for edge case with multiple types.
- size_t start_pos = type.find("|");
+ size_t start_pos = type.find('|');
if (start_pos != TProtoStringType::npos) {
type.replace(start_pos, 1, ">|array<");
}
- type = "array<" + type + ">|\\Google\\Protobuf\\Internal\\RepeatedField";
+ type = y_absl::StrCat("array<", type,
+ ">|\\Google\\Protobuf\\Internal\\RepeatedField");
}
return type;
}
@@ -542,7 +480,7 @@ TProtoStringType PhpGetterTypeName(const FieldDescriptor* field,
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_BYTES: return "string";
case FieldDescriptor::TYPE_MESSAGE:
- return "\\" + FullClassName(field->message_type(), options);
+ return y_absl::StrCat("\\", FullClassName(field->message_type(), options));
case FieldDescriptor::TYPE_GROUP: return "null";
default: assert(false); return "";
}
@@ -558,13 +496,14 @@ TProtoStringType PhpGetterTypeName(const FieldDescriptor* field,
TProtoStringType EnumOrMessageSuffix(const FieldDescriptor* field,
const Options& options) {
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- return ", '" +
- DescriptorFullName(field->message_type(), options.is_descriptor) +
- "'";
+ return y_absl::StrCat(
+ ", '", DescriptorFullName(field->message_type(), options.is_descriptor),
+ "'");
}
if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
- return ", '" +
- DescriptorFullName(field->enum_type(), options.is_descriptor) + "'";
+ return y_absl::StrCat(
+ ", '", DescriptorFullName(field->enum_type(), options.is_descriptor),
+ "'");
}
return "";
}
@@ -578,7 +517,7 @@ TProtoStringType EnumOrMessageSuffix(const FieldDescriptor* field,
// Converts a name to camel-case. If cap_first_letter is true, capitalize the
// first letter.
-TProtoStringType UnderscoresToCamelCase(const TProtoStringType& name,
+TProtoStringType UnderscoresToCamelCase(y_absl::string_view name,
bool cap_first_letter) {
TProtoStringType result;
for (int i = 0; i < name.size(); i++) {
@@ -659,8 +598,11 @@ void GenerateFieldAccessor(const FieldDescriptor* field, const Options& options,
GenerateFieldDocComment(printer, field, options, kFieldGetter);
// deprecation
- TProtoStringType deprecation_trigger = (field->options().deprecated()) ? "@trigger_error('" +
- field->name() + " is deprecated.', E_USER_DEPRECATED);\n " : "";
+ TProtoStringType deprecation_trigger =
+ (field->options().deprecated())
+ ? y_absl::StrCat("@trigger_error('", field->name(),
+ " is deprecated.', E_USER_DEPRECATED);\n ")
+ : "";
// Emit getter.
if (oneof != NULL) {
@@ -760,18 +702,16 @@ 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", y_absl::AsciiStrToUpper(key->type_name()),
+ "value_type", y_absl::AsciiStrToUpper(value->type_name()));
if (value->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- printer->Print(
- ", \\^class_name^);\n",
- "class_name",
- FullClassName(value->message_type(), options) + "::class");
+ printer->Print(", \\^class_name^);\n", "class_name",
+ y_absl::StrCat(FullClassName(value->message_type(), options),
+ "::class"));
} else if (value->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
printer->Print(
- ", \\^class_name^);\n",
- "class_name",
- FullClassName(value->enum_type(), options) + "::class");
+ ", \\^class_name^);\n", "class_name",
+ y_absl::StrCat(FullClassName(value->enum_type(), options), "::class"));
} else {
printer->Print(");\n");
}
@@ -779,17 +719,15 @@ 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", y_absl::AsciiStrToUpper(field->type_name()));
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- printer->Print(
- ", \\^class_name^);\n",
- "class_name",
- FullClassName(field->message_type(), options) + "::class");
+ printer->Print(", \\^class_name^);\n", "class_name",
+ y_absl::StrCat(FullClassName(field->message_type(), options),
+ "::class"));
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
printer->Print(
- ", \\^class_name^);\n",
- "class_name",
- FullClassName(field->enum_type(), options) + "::class");
+ ", \\^class_name^);\n", "class_name",
+ y_absl::StrCat(FullClassName(field->enum_type(), options), "::class"));
} else {
printer->Print(");\n");
}
@@ -879,16 +817,16 @@ void GenerateServiceMethod(const MethodDescriptor* method,
);
}
-void GenerateMessageToPool(const TProtoStringType& name_prefix,
+void GenerateMessageToPool(y_absl::string_view name_prefix,
const Descriptor* message, io::Printer* printer) {
// Don't generate MapEntry messages -- we use the PHP extension's native
// support for map fields instead.
if (message->options().map_entry()) {
return;
}
- TProtoStringType class_name =
- (name_prefix.empty() ? "" : name_prefix + "\\") +
- ReservedNamePrefix(message->name(), message->file()) + message->name();
+ TProtoStringType class_name = y_absl::StrCat(
+ name_prefix.empty() ? "" : y_absl::StrCat(name_prefix, "\\"),
+ ReservedNamePrefix(message->name(), message->file()), message->name());
printer->Print(
"$pool->addMessage('^message^', "
@@ -909,9 +847,9 @@ void GenerateMessageToPool(const TProtoStringType& 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()),
- "number", StrCat(field->number()),
+ "key", y_absl::AsciiStrToUpper(key->type_name()),
+ "value", y_absl::AsciiStrToUpper(val->type_name()),
+ "number", y_absl::StrCat(field->number()),
"other", EnumOrMessageSuffix(val, true));
} else if (!field->real_containing_oneof()) {
printer->Print(
@@ -919,8 +857,8 @@ void GenerateMessageToPool(const TProtoStringType& name_prefix,
"\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n",
"field", field->name(),
"label", LabelForField(field),
- "type", ToUpper(field->type_name()),
- "number", StrCat(field->number()),
+ "type", y_absl::AsciiStrToUpper(field->type_name()),
+ "number", y_absl::StrCat(field->number()),
"other", EnumOrMessageSuffix(field, true));
}
}
@@ -937,8 +875,8 @@ void GenerateMessageToPool(const TProtoStringType& name_prefix,
"->value('^field^', "
"\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n",
"field", field->name(),
- "type", ToUpper(field->type_name()),
- "number", StrCat(field->number()),
+ "type", y_absl::AsciiStrToUpper(field->type_name()),
+ "number", y_absl::StrCat(field->number()),
"other", EnumOrMessageSuffix(field, true));
}
printer->Print("->finish()\n");
@@ -990,7 +928,7 @@ void GenerateAddFileToPool(const FileDescriptor* file, const Options& options,
"$pool->finish();\n");
} else {
for (int i = 0; i < file->dependency_count(); i++) {
- const TProtoStringType& name = file->dependency(i)->name();
+ y_absl::string_view name = file->dependency(i)->name();
// Currently, descriptor.proto is not ready for external usage. Skip to
// import it for now, so that its dependencies can still work as long as
// they don't use protos defined in descriptor.proto.
@@ -1065,9 +1003,10 @@ void GenerateAddFileToPool(const FileDescriptor* file, const Options& options,
static void AnalyzeDependencyForFile(
const FileDescriptor* file,
- std::set<const FileDescriptor*>* nodes_without_dependency,
- std::map<const FileDescriptor*, std::set<const FileDescriptor*>>* deps,
- std::map<const FileDescriptor*, int>* dependency_count) {
+ y_absl::flat_hash_set<const FileDescriptor*>* nodes_without_dependency,
+ y_absl::flat_hash_map<const FileDescriptor*,
+ y_absl::flat_hash_set<const FileDescriptor*>>* deps,
+ y_absl::flat_hash_map<const FileDescriptor*, int>* dependency_count) {
int count = file->dependency_count();
for (int i = 0; i < file->dependency_count(); i++) {
const FileDescriptor* dependency = file->dependency(i);
@@ -1087,7 +1026,7 @@ static void AnalyzeDependencyForFile(
continue;
}
if (deps->find(dependency) == deps->end()) {
- (*deps)[dependency] = std::set<const FileDescriptor*>();
+ (*deps)[dependency] = {};
}
(*deps)[dependency].insert(file);
AnalyzeDependencyForFile(
@@ -1103,7 +1042,7 @@ static bool NeedsUnwrapping(const FileDescriptor* file,
has_aggregate_metadata_prefix = true;
} else {
for (const auto& prefix : options.aggregate_metadata_prefixes) {
- if (HasPrefixString(file->package(), prefix)) {
+ if (y_absl::StartsWith(file->package(), prefix)) {
has_aggregate_metadata_prefix = true;
break;
}
@@ -1123,9 +1062,11 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
"}\n");
// Sort files according to dependency
- std::map<const FileDescriptor*, std::set<const FileDescriptor*>> deps;
- std::map<const FileDescriptor*, int> dependency_count;
- std::set<const FileDescriptor*> nodes_without_dependency;
+ y_absl::flat_hash_map<const FileDescriptor*,
+ y_absl::flat_hash_set<const FileDescriptor*>>
+ deps;
+ y_absl::flat_hash_map<const FileDescriptor*, int> dependency_count;
+ y_absl::flat_hash_set<const FileDescriptor*> nodes_without_dependency;
FileDescriptorSet sorted_file_set;
AnalyzeDependencyForFile(
@@ -1231,10 +1172,10 @@ void GenerateHead(const FileDescriptor* file, io::Printer* printer) {
"filename", file->name());
}
-TProtoStringType FilenameToClassname(const TProtoStringType& filename) {
- int lastindex = filename.find_last_of(".");
- TProtoStringType result = filename.substr(0, lastindex);
- for (int i = 0; i < result.size(); i++) {
+TProtoStringType FilenameToClassname(y_absl::string_view filename) {
+ size_t lastindex = filename.find_last_of('.');
+ TProtoStringType result(filename.substr(0, lastindex));
+ for (size_t i = 0; i < result.size(); i++) {
if (result[i] == '/') {
result[i] = '\\';
}
@@ -1252,7 +1193,7 @@ void GenerateMetadataFile(const FileDescriptor* file, const Options& options,
GenerateHead(file, &printer);
TProtoStringType fullname = FilenameToClassname(filename);
- int lastindex = fullname.find_last_of("\\");
+ int lastindex = fullname.find_last_of('\\');
if (lastindex != TProtoStringType::npos) {
printer.Print(
@@ -1307,7 +1248,7 @@ void LegacyGenerateClassFile(const FileDescriptor* file,
Outdent(&printer);
printer.Print("}\n");
printer.Print("class_exists(^new^::class);\n",
- "new", GeneratedClassNameImpl(desc));
+ "new", GeneratedClassName(desc));
printer.Print("@trigger_error('^old^ is deprecated and will be removed in "
"the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n",
"old", LegacyFullClassName(desc, options),
@@ -1318,27 +1259,39 @@ template <typename DescriptorType>
void LegacyReadOnlyGenerateClassFile(const FileDescriptor* file,
const DescriptorType* desc, const Options& options,
GeneratorContext* generator_context) {
- TProtoStringType filename = LegacyReadOnlyGeneratedClassFileName(desc, options);
+ TProtoStringType fullname = FullClassName(desc, options);
+ TProtoStringType php_namespace;
+ TProtoStringType classname;
+ int lastindex = fullname.find_last_of("\\");
+
+ if (lastindex != TProtoStringType::npos) {
+ php_namespace = fullname.substr(0, lastindex);
+ classname = fullname.substr(lastindex + 1);
+ } else {
+ php_namespace = "";
+ classname = fullname;
+ }
+
+ TProtoStringType filename = LegacyReadOnlyGeneratedClassFileName(php_namespace, desc);
std::unique_ptr<io::ZeroCopyOutputStream> output(
generator_context->Open(filename));
io::Printer printer(output.get(), '^');
GenerateHead(file, &printer);
- TProtoStringType php_namespace = RootPhpNamespace(desc, options);
if (!php_namespace.empty()) {
printer.Print(
"namespace ^name^;\n\n",
"name", php_namespace);
}
- TProtoStringType newname = FullClassName(desc, options);
+
printer.Print("class_exists(^new^::class); // autoload the new class, which "
"will also create an alias to the deprecated class\n",
- "new", GeneratedClassNameImpl(desc));
+ "new", classname);
printer.Print("@trigger_error(__NAMESPACE__ . '\\^old^ is deprecated and will be removed in "
"the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n",
"old", desc->name(),
- "fullname", newname);
+ "fullname", classname);
}
void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
@@ -1352,7 +1305,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
GenerateHead(file, &printer);
TProtoStringType fullname = FilenameToClassname(filename);
- int lastindex = fullname.find_last_of("\\");
+ int lastindex = fullname.find_last_of('\\');
if (lastindex != TProtoStringType::npos) {
printer.Print(
@@ -1452,7 +1405,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
Outdent(&printer);
printer.Print("}\n\n");
- // write legacy file for backwards compatibility with nested messages and enums
+ // write legacy alias for backwards compatibility with nested messages and enums
if (en->containing_type() != NULL) {
printer.Print(
"// Adding a class alias for backwards compatibility with the previous class name.\n");
@@ -1460,7 +1413,6 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
"class_alias(^new^::class, \\^old^::class);\n\n",
"new", fullname,
"old", LegacyFullClassName(en, options));
- LegacyGenerateClassFile(file, en, options, generator_context);
}
// Write legacy file for backwards compatibility with "readonly" keywword
@@ -1494,7 +1446,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
GenerateHead(file, &printer);
TProtoStringType fullname = FilenameToClassname(filename);
- int lastindex = fullname.find_last_of("\\");
+ int lastindex = fullname.find_last_of('\\');
if (lastindex != TProtoStringType::npos) {
printer.Print(
@@ -1580,7 +1532,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
Outdent(&printer);
printer.Print("}\n\n");
- // write legacy file for backwards compatibility with nested messages and enums
+ // write legacy alias for backwards compatibility with nested messages and enums
if (message->containing_type() != NULL) {
printer.Print(
"// Adding a class alias for backwards compatibility with the previous class name.\n");
@@ -1588,7 +1540,6 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
"class_alias(^new^::class, \\^old^::class);\n\n",
"new", fullname,
"old", LegacyFullClassName(message, options));
- LegacyGenerateClassFile(file, message, options, generator_context);
}
// Write legacy file for backwards compatibility with "readonly" keywword
@@ -1625,7 +1576,7 @@ void GenerateServiceFile(
GenerateHead(file, &printer);
TProtoStringType fullname = FilenameToClassname(filename);
- int lastindex = fullname.find_last_of("\\");
+ int lastindex = fullname.find_last_of('\\');
if (!file->options().php_namespace().empty() ||
(!file->options().has_php_namespace() && !file->package().empty()) ||
@@ -1679,7 +1630,7 @@ void GenerateFile(const FileDescriptor* file, const Options& options,
}
}
-static TProtoStringType EscapePhpdoc(const TProtoStringType& input) {
+static TProtoStringType EscapePhpdoc(y_absl::string_view input) {
TProtoStringType result;
result.reserve(input.size() * 2);
@@ -1736,7 +1687,8 @@ static void GenerateDocCommentBodyForLocation(
// HTML-escape them so that they don't accidentally close the doc comment.
comments = EscapePhpdoc(comments);
- std::vector<TProtoStringType> lines = Split(comments, "\n", true);
+ std::vector<y_absl::string_view> lines =
+ y_absl::StrSplit(comments, '\n', y_absl::SkipEmpty());
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
@@ -1767,8 +1719,8 @@ static void GenerateDocCommentBody(
}
}
-static TProtoStringType FirstLineOf(const TProtoStringType& value) {
- TProtoStringType result = value;
+static TProtoStringType FirstLineOf(y_absl::string_view value) {
+ TProtoStringType result(value);
TProtoStringType::size_type pos = result.find_first_of('\n');
if (pos != TProtoStringType::npos) {
@@ -1935,17 +1887,13 @@ void GenerateServiceMethodDocComment(io::Printer* printer,
}
TProtoStringType FilenameCName(const FileDescriptor* file) {
- TProtoStringType c_name = file->name();
- c_name = StringReplace(c_name, ".", "_", true);
- c_name = StringReplace(c_name, "/", "_", true);
- return c_name;
+ return y_absl::StrReplaceAll(file->name(), {{".", "_"}, {"/", "_"}});
}
void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) {
- TProtoStringType c_name = desc->full_name();
- c_name = StringReplace(c_name, ".", "_", true);
- TProtoStringType php_name = FullClassName(desc, Options());
- php_name = StringReplace(php_name, "\\", "\\\\", true);
+ TProtoStringType c_name = y_absl::StrReplaceAll(desc->full_name(), {{".", "_"}});
+ TProtoStringType php_name =
+ y_absl::StrReplaceAll(FullClassName(desc, Options()), {{"\\", "\\\\"}});
printer->Print(
"/* $c_name$ */\n"
"\n"
@@ -2028,10 +1976,9 @@ void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) {
}
void GenerateCMessage(const Descriptor* message, io::Printer* printer) {
- TProtoStringType c_name = message->full_name();
- c_name = StringReplace(c_name, ".", "_", true);
- TProtoStringType php_name = FullClassName(message, Options());
- php_name = StringReplace(php_name, "\\", "\\\\", true);
+ TProtoStringType c_name = y_absl::StrReplaceAll(message->full_name(), {{".", "_"}});
+ TProtoStringType php_name =
+ y_absl::StrReplaceAll(FullClassName(message, Options()), {{"\\", "\\\\"}});
printer->Print(
"/* $c_name$ */\n"
"\n"
@@ -2181,8 +2128,7 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) {
}
void GenerateEnumCInit(const EnumDescriptor* desc, io::Printer* printer) {
- TProtoStringType c_name = desc->full_name();
- c_name = StringReplace(c_name, ".", "_", true);
+ TProtoStringType c_name = y_absl::StrReplaceAll(desc->full_name(), {{".", "_"}});
printer->Print(
" $c_name$_ModuleInit();\n",
@@ -2190,8 +2136,7 @@ void GenerateEnumCInit(const EnumDescriptor* desc, io::Printer* printer) {
}
void GenerateCInit(const Descriptor* message, io::Printer* printer) {
- TProtoStringType c_name = message->full_name();
- c_name = StringReplace(c_name, ".", "_", true);
+ TProtoStringType c_name = y_absl::StrReplaceAll(message->full_name(), {{".", "_"}});
printer->Print(
" $c_name$_ModuleInit();\n",
@@ -2233,8 +2178,9 @@ void GenerateCWellKnownTypes(const std::vector<const FileDescriptor*>& files,
TProtoStringType metadata_filename = GeneratedMetadataFileName(file, Options());
TProtoStringType metadata_classname = FilenameToClassname(metadata_filename);
TProtoStringType metadata_c_name =
- StringReplace(metadata_classname, "\\", "_", true);
- metadata_classname = StringReplace(metadata_classname, "\\", "\\\\", true);
+ y_absl::StrReplaceAll(metadata_classname, {{"\\", "_"}});
+ metadata_classname =
+ y_absl::StrReplaceAll(metadata_classname, {{"\\", "\\\\"}});
FileDescriptorProto file_proto;
file->CopyTo(&file_proto);
TProtoStringType serialized;
@@ -2252,7 +2198,7 @@ void GenerateCWellKnownTypes(const std::vector<const FileDescriptor*>& files,
for (size_t i = 0; i < serialized.size();) {
for (size_t j = 0; j < 25 && i < serialized.size(); ++i, ++j) {
- printer.Print("'$ch$', ", "ch", CEscape(serialized.substr(i, 1)));
+ printer.Print("'$ch$', ", "ch", y_absl::CEscape(serialized.substr(i, 1)));
}
printer.Print("\n");
}
@@ -2315,7 +2261,7 @@ void GenerateCWellKnownTypes(const std::vector<const FileDescriptor*>& files,
TProtoStringType metadata_filename = GeneratedMetadataFileName(file, Options());
TProtoStringType metadata_classname = FilenameToClassname(metadata_filename);
TProtoStringType metadata_c_name =
- StringReplace(metadata_classname, "\\", "_", true);
+ y_absl::StrReplaceAll(metadata_classname, {{"\\", "_"}});
printer.Print(
" $metadata_c_name$_ModuleInit();\n",
"metadata_c_name", metadata_c_name);
@@ -2333,18 +2279,6 @@ void GenerateCWellKnownTypes(const std::vector<const FileDescriptor*>& files,
} // namespace
-TProtoStringType GeneratedClassName(const Descriptor* desc) {
- return GeneratedClassNameImpl(desc);
-}
-
-TProtoStringType GeneratedClassName(const EnumDescriptor* desc) {
- return GeneratedClassNameImpl(desc);
-}
-
-TProtoStringType GeneratedClassName(const ServiceDescriptor* desc) {
- return GeneratedClassNameImpl(desc);
-}
-
bool Generator::Generate(const FileDescriptor* file,
const TProtoStringType& parameter,
GeneratorContext* generator_context,
@@ -2379,20 +2313,20 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
TProtoStringType* error) const {
Options options;
- for (const auto& option : Split(parameter, ",", true)) {
- const std::vector<TProtoStringType> option_pair = Split(option, "=", true);
- if (HasPrefixString(option_pair[0], "aggregate_metadata")) {
+ for (const auto& option : y_absl::StrSplit(parameter, ",", y_absl::SkipEmpty())) {
+ const std::vector<TProtoStringType> option_pair = y_absl::StrSplit(option, "=", y_absl::SkipEmpty());
+ if (y_absl::StartsWith(option_pair[0], "aggregate_metadata")) {
options.aggregate_metadata = true;
- for (const auto& prefix : Split(option_pair[1], "#", false)) {
+ for (const auto& prefix : y_absl::StrSplit(option_pair[1], "#", y_absl::AllowEmpty())) {
options.aggregate_metadata_prefixes.emplace(prefix);
- GOOGLE_LOG(INFO) << prefix;
+ Y_ABSL_LOG(INFO) << prefix;
}
} else if (option_pair[0] == "internal") {
options.is_descriptor = true;
} else if (option_pair[0] == "internal_generate_c_wkt") {
GenerateCWellKnownTypes(files, generator_context);
} else {
- GOOGLE_LOG(FATAL) << "Unknown codegen option: " << option_pair[0];
+ Y_ABSL_LOG(FATAL) << "Unknown codegen option: " << option_pair[0];
}
}
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.h b/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.h
index 0247afaa560..66fa0034f58 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/php/php_generator.h
@@ -31,12 +31,13 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
-#include <google/protobuf/compiler/code_generator.h>
-#include <google/protobuf/descriptor.h>
+#include "google/protobuf/compiler/code_generator.h"
+#include "google/protobuf/compiler/php/names.h"
+#include "google/protobuf/descriptor.h"
#include <string>
-#include <google/protobuf/port_def.inc>
+#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
@@ -70,13 +71,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator {
TProtoStringType* error) const;
};
-// To skip reserved keywords in php, some generated classname are prefixed.
-// Other code generators may need following API to figure out the actual
-// classname.
-PROTOC_EXPORT TProtoStringType GeneratedClassName(const Descriptor* desc);
-PROTOC_EXPORT TProtoStringType GeneratedClassName(const EnumDescriptor* desc);
-PROTOC_EXPORT TProtoStringType GeneratedClassName(const ServiceDescriptor* desc);
-
inline bool IsWrapperType(const FieldDescriptor* descriptor) {
return descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
descriptor->message_type()->file()->name() == "google/protobuf/wrappers.proto";
@@ -87,6 +81,6 @@ inline bool IsWrapperType(const FieldDescriptor* descriptor) {
} // namespace protobuf
} // namespace google
-#include <google/protobuf/port_undef.inc>
+#include "google/protobuf/port_undef.inc"
#endif // GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__