aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/protoc/src/google/protobuf/compiler/objectivec
diff options
context:
space:
mode:
authorheretic <heretic@yandex-team.ru>2022-06-14 13:29:31 +0300
committerheretic <heretic@yandex-team.ru>2022-06-14 13:29:31 +0300
commit16f8be4f481c275c34795233c18f8d078382fcb3 (patch)
tree2363f1306ce2e17e72c0a48614256acd046990e6 /contrib/libs/protoc/src/google/protobuf/compiler/objectivec
parent647dc68b78e469e5ab416e9b62885c9846fd511d (diff)
downloadydb-16f8be4f481c275c34795233c18f8d078382fcb3.tar.gz
Update protobuf to 3.18.1
ref:4846abb21711ea0dc148d4c5df7b5edd3d1bdc69
Diffstat (limited to 'contrib/libs/protoc/src/google/protobuf/compiler/objectivec')
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h10
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_field.h22
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_file.h2
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_generator.cc51
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc277
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.h19
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_map_field.h6
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_message_field.h8
-rw-r--r--contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h6
9 files changed, 308 insertions, 93 deletions
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
index 7016c8022c..89d3e6907c 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
@@ -48,10 +48,12 @@ class EnumFieldGenerator : public SingleFieldGenerator {
EnumFieldGenerator& operator=(const EnumFieldGenerator&) = delete;
public:
- virtual void GenerateCFunctionDeclarations(io::Printer* printer) const;
- virtual void GenerateCFunctionImplementations(io::Printer* printer) const;
+ virtual void GenerateCFunctionDeclarations(
+ io::Printer* printer) const override;
+ virtual void GenerateCFunctionImplementations(
+ io::Printer* printer) const override;
virtual void DetermineForwardDeclarations(
- std::set<TProtoStringType>* fwd_decls) const;
+ std::set<TProtoStringType>* fwd_decls) const override;
protected:
EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options);
@@ -63,7 +65,7 @@ class RepeatedEnumFieldGenerator : public RepeatedFieldGenerator {
const Options& options);
public:
- virtual void FinishInitialization();
+ virtual void FinishInitialization() override;
protected:
RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_field.h
index 24c64dbc05..b2d2e676b1 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_field.h
@@ -112,12 +112,12 @@ class SingleFieldGenerator : public FieldGenerator {
SingleFieldGenerator(const SingleFieldGenerator&) = delete;
SingleFieldGenerator& operator=(const SingleFieldGenerator&) = delete;
- virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const;
- virtual void GeneratePropertyDeclaration(io::Printer* printer) const;
+ virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override;
+ virtual void GeneratePropertyDeclaration(io::Printer* printer) const override;
- virtual void GeneratePropertyImplementation(io::Printer* printer) const;
+ virtual void GeneratePropertyImplementation(io::Printer* printer) const override;
- virtual bool RuntimeUsesHasBit(void) const;
+ virtual bool RuntimeUsesHasBit(void) const override;
protected:
SingleFieldGenerator(const FieldDescriptor* descriptor,
@@ -132,8 +132,8 @@ class ObjCObjFieldGenerator : public SingleFieldGenerator {
ObjCObjFieldGenerator(const ObjCObjFieldGenerator&) = delete;
ObjCObjFieldGenerator& operator=(const ObjCObjFieldGenerator&) = delete;
- virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const;
- virtual void GeneratePropertyDeclaration(io::Printer* printer) const;
+ virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override;
+ virtual void GeneratePropertyDeclaration(io::Printer* printer) const override;
protected:
ObjCObjFieldGenerator(const FieldDescriptor* descriptor,
@@ -147,17 +147,17 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator {
RepeatedFieldGenerator(const RepeatedFieldGenerator&) = delete;
RepeatedFieldGenerator& operator=(const RepeatedFieldGenerator&) = delete;
- virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const;
- virtual void GeneratePropertyDeclaration(io::Printer* printer) const;
+ virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override;
+ virtual void GeneratePropertyDeclaration(io::Printer* printer) const override;
- virtual void GeneratePropertyImplementation(io::Printer* printer) const;
+ virtual void GeneratePropertyImplementation(io::Printer* printer) const override;
- virtual bool RuntimeUsesHasBit(void) const;
+ virtual bool RuntimeUsesHasBit(void) const override;
protected:
RepeatedFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
- virtual void FinishInitialization(void);
+ virtual void FinishInitialization(void) override;
};
// Convenience class which constructs FieldGenerators for a Descriptor.
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_file.h b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_file.h
index c1f6cb19de..6bd747ac5e 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_file.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_file.h
@@ -58,8 +58,6 @@ class FileGenerator {
void GenerateSource(io::Printer* printer);
void GenerateHeader(io::Printer* printer);
- const TProtoStringType& RootClassName() const { return root_class_name_; }
-
private:
const FileDescriptor* file_;
TProtoStringType root_class_name_;
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
index 2157896253..371234aafe 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
@@ -28,8 +28,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include <fstream>
#include <iostream>
#include <string>
+#include <unordered_set>
#include <google/protobuf/compiler/objectivec/objectivec_generator.h>
#include <google/protobuf/compiler/objectivec/objectivec_file.h>
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
@@ -138,6 +140,34 @@ bool ObjectiveCGenerator::GenerateAll(
// header search path since the generate #import will be more complete.
generation_options.runtime_import_prefix =
StripSuffixString(options[i].second, "/");
+ } else if (options[i].first == "use_package_as_prefix") {
+ // Controls how the symbols should be prefixed to avoid symbols
+ // collisions. The objc_class_prefix file option is always honored, this
+ // is just what to do if that isn't set. The available options are:
+ // "no": Not prefixed (the existing mode).
+ // "yes": Make a prefix out of the proto package.
+ TProtoStringType upper_value(options[i].second);
+ UpperString(&upper_value);
+ if (upper_value == "NO") {
+ SetUseProtoPackageAsDefaultPrefix(false);
+ } else if (upper_value == "YES") {
+ SetUseProtoPackageAsDefaultPrefix(true);
+ } else {
+ *error = "error: Unknown use_package_as_prefix: " + options[i].second;
+ return false;
+ }
+ } else if (options[i].first == "proto_package_prefix_exceptions_path") {
+ // Path to find a file containing the list of proto package names that are
+ // exceptions when use_package_as_prefix is enabled. This can be used to
+ // migrate packages one at a time to use_package_as_prefix since there
+ // are likely code updates needed with each one.
+ //
+ // The format of the file is:
+ // - An entry is a line of "proto.package.name".
+ // - Comments start with "#".
+ // - A comment can go on a line after a expected package/prefix pair.
+ // (i.e. - "some.proto.package # comment")
+ SetProtoPackagePrefixExceptionList(options[i].second);
} else {
*error = "error: Unknown generator option: " + options[i].first;
return false;
@@ -146,6 +176,25 @@ bool ObjectiveCGenerator::GenerateAll(
// -----------------------------------------------------------------
+ // These are not official generation options and could be removed/changed in
+ // the future and doing that won't count as a breaking change.
+ bool headers_only = getenv("GPB_OBJC_HEADERS_ONLY") != NULL;
+ std::unordered_set<TProtoStringType> skip_impls;
+ if (getenv("GPB_OBJC_SKIP_IMPLS_FILE") != NULL) {
+ std::ifstream skip_file(getenv("GPB_OBJC_SKIP_IMPLS_FILE"));
+ if (skip_file.is_open()) {
+ std::string line;
+ while (std::getline(skip_file, line)) {
+ skip_impls.insert(line.c_str());
+ }
+ } else {
+ *error = "error: Failed to open GPB_OBJC_SKIP_IMPLS_FILE file";
+ return false;
+ }
+ }
+
+ // -----------------------------------------------------------------
+
// Validate the objc prefix/package pairings.
if (!ValidateObjCClassPrefixes(files, generation_options, error)) {
// *error will have been filled in.
@@ -166,7 +215,7 @@ bool ObjectiveCGenerator::GenerateAll(
}
// Generate m file.
- {
+ if (!headers_only && skip_impls.count(file->name()) == 0) {
std::unique_ptr<io::ZeroCopyOutputStream> output(
context->Open(filepath + ".pbobjc.m"));
io::Printer printer(output.get(), '$');
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
index dbcc4ce110..bbcfbdd2bc 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
@@ -72,6 +72,102 @@ using ::open;
#endif
} // namespace port
+namespace {
+
+class SimpleLineCollector : public LineConsumer {
+ public:
+ SimpleLineCollector(std::unordered_set<TProtoStringType>* inout_set)
+ : set_(inout_set) {}
+
+ virtual bool ConsumeLine(const StringPiece& line, TProtoStringType* out_error) override {
+ set_->insert(TProtoStringType(line));
+ return true;
+ }
+
+ private:
+ std::unordered_set<TProtoStringType>* set_;
+};
+
+class PrefixModeStorage {
+ public:
+ PrefixModeStorage();
+
+ bool use_package_name() const { return use_package_name_; }
+ void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; }
+
+ const TProtoStringType exception_path() const { return exception_path_; }
+ void set_exception_path(const TProtoStringType& path) {
+ exception_path_ = path;
+ exceptions_.clear();
+ }
+
+ bool is_package_exempted(const TProtoStringType& package);
+
+ private:
+ bool use_package_name_;
+ TProtoStringType exception_path_;
+ std::unordered_set<TProtoStringType> exceptions_;
+};
+
+PrefixModeStorage::PrefixModeStorage() {
+ // Even thought there are generation options, have an env back door since some
+ // of these helpers could be used in other plugins.
+
+ const char* use_package_cstr = getenv("GPB_OBJC_USE_PACKAGE_AS_PREFIX");
+ use_package_name_ =
+ (use_package_cstr && (TProtoStringType("YES") == ToUpper(use_package_cstr)));
+
+ const char* exception_path = getenv("GPB_OBJC_PACKAGE_PREFIX_EXCEPTIONS_PATH");
+ if (exception_path) {
+ exception_path_ = exception_path;
+ }
+}
+
+bool PrefixModeStorage::is_package_exempted(const TProtoStringType& package) {
+ if (exceptions_.empty() && !exception_path_.empty()) {
+ TProtoStringType error_str;
+ SimpleLineCollector collector(&exceptions_);
+ if (!ParseSimpleFile(exception_path_, &collector, &error_str)) {
+ if (error_str.empty()) {
+ error_str = TProtoStringType("protoc:0: warning: Failed to parse")
+ + TProtoStringType(" package prefix exceptions file: ")
+ + exception_path_;
+ }
+ std::cerr << error_str << std::endl;
+ std::cerr.flush();
+ exceptions_.clear();
+ }
+
+ // If the file was empty put something in it so it doesn't get reloaded over
+ // and over.
+ if (exceptions_.empty()) {
+ exceptions_.insert("<not a real package>");
+ }
+ }
+
+ return exceptions_.count(package) != 0;
+}
+
+PrefixModeStorage g_prefix_mode;
+
+} // namespace
+
+bool UseProtoPackageAsDefaultPrefix() {
+ return g_prefix_mode.use_package_name();
+}
+
+void SetUseProtoPackageAsDefaultPrefix(bool on_or_off) {
+ g_prefix_mode.set_use_package_name(on_or_off);
+}
+
+TProtoStringType GetProtoPackagePrefixExceptionList() {
+ return g_prefix_mode.exception_path();
+}
+
+void SetProtoPackagePrefixExceptionList(const TProtoStringType& file_path) {
+ g_prefix_mode.set_exception_path(file_path);
+}
+
Options::Options() {
// Default is the value of the env for the package prefixes.
const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES");
@@ -361,6 +457,15 @@ TProtoStringType GetEnumNameForFlagType(const FlagType flag_type) {
}
}
+void MaybeUnQuote(StringPiece* input) {
+ if ((input->length() >= 2) &&
+ ((*input->data() == '\'' || *input->data() == '"')) &&
+ ((*input)[input->length() - 1] == *input->data())) {
+ input->remove_prefix(1);
+ input->remove_suffix(1);
+ }
+}
+
} // namespace
// Escape C++ trigraphs by escaping question marks to \?
@@ -399,8 +504,39 @@ TProtoStringType BaseFileName(const FileDescriptor* file) {
}
TProtoStringType FileClassPrefix(const FileDescriptor* file) {
- // Default is empty string, no need to check has_objc_class_prefix.
- TProtoStringType result = file->options().objc_class_prefix();
+ // Always honor the file option.
+ if (file->options().has_objc_class_prefix()) {
+ return file->options().objc_class_prefix();
+ }
+
+ // If package prefix isn't enabled or no package, done.
+ if (!g_prefix_mode.use_package_name() || file->package().empty()) {
+ return "";
+ }
+
+ // If the package is in the exceptions list, done.
+ if (g_prefix_mode.is_package_exempted(file->package())) {
+ return "";
+ }
+
+ // Transform the package into a prefix: use the dot segments as part,
+ // camelcase each one and then join them with underscores, and add an
+ // underscore at the end.
+ TProtoStringType result;
+ const std::vector<TProtoStringType> segments = Split(file->package(), ".", true);
+ for (const auto& segment : segments) {
+ const TProtoStringType part = UnderscoresToCamelCase(segment, true);
+ if (part.empty()) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.append("_");
+ }
+ result.append(part);
+ }
+ if (!result.empty()) {
+ result.append("_");
+ }
return result;
}
@@ -1052,7 +1188,7 @@ class ExpectedPrefixesCollector : public LineConsumer {
ExpectedPrefixesCollector(std::map<TProtoStringType, TProtoStringType>* inout_package_to_prefix_map)
: prefix_map_(inout_package_to_prefix_map) {}
- virtual bool ConsumeLine(const StringPiece& line, TProtoStringType* out_error);
+ virtual bool ConsumeLine(const StringPiece& line, TProtoStringType* out_error) override;
private:
std::map<TProtoStringType, TProtoStringType>* prefix_map_;
@@ -1070,6 +1206,7 @@ bool ExpectedPrefixesCollector::ConsumeLine(
StringPiece prefix = line.substr(offset + 1);
TrimWhitespace(&package);
TrimWhitespace(&prefix);
+ MaybeUnQuote(&prefix);
// Don't really worry about error checking the package/prefix for
// being valid. Assume the file is validated when it is created/edited.
(*prefix_map_)[TProtoStringType(package)] = TProtoStringType(prefix);
@@ -1092,6 +1229,13 @@ bool ValidateObjCClassPrefix(
const FileDescriptor* file, const TProtoStringType& expected_prefixes_path,
const std::map<TProtoStringType, TProtoStringType>& expected_package_prefixes,
TProtoStringType* out_error) {
+ // Reminder: An explicit prefix option of "" is valid in case the default
+ // prefixing is set to use the proto package and a file needs to be generated
+ // without any prefix at all (for legacy reasons).
+
+ bool has_prefix = file->options().has_objc_class_prefix();
+ bool have_expected_prefix_file = !expected_prefixes_path.empty();
+
const TProtoStringType prefix = file->options().objc_class_prefix();
const TProtoStringType package = file->package();
@@ -1104,7 +1248,7 @@ bool ValidateObjCClassPrefix(
expected_package_prefixes.find(package);
if (package_match != expected_package_prefixes.end()) {
// There was an entry, and...
- if (package_match->second == prefix) {
+ if (has_prefix && package_match->second == prefix) {
// ...it matches. All good, out of here!
return true;
} else {
@@ -1112,7 +1256,7 @@ bool ValidateObjCClassPrefix(
*out_error = "error: Expected 'option objc_class_prefix = \"" +
package_match->second + "\";' for package '" + package +
"' in '" + file->name() + "'";
- if (prefix.length()) {
+ if (has_prefix) {
*out_error += "; but found '" + prefix + "' instead";
}
*out_error += ".";
@@ -1121,22 +1265,76 @@ bool ValidateObjCClassPrefix(
}
// If there was no prefix option, we're done at this point.
- if (prefix.empty()) {
- // No prefix, nothing left to check.
+ if (!has_prefix) {
return true;
}
+ // When the prefix is non empty, check it against the expected entries.
+ if (!prefix.empty() && have_expected_prefix_file) {
+ // For a non empty prefix, look for any other package that uses the prefix.
+ TProtoStringType other_package_for_prefix;
+ for (std::map<TProtoStringType, TProtoStringType>::const_iterator i =
+ expected_package_prefixes.begin();
+ i != expected_package_prefixes.end(); ++i) {
+ if (i->second == prefix) {
+ other_package_for_prefix = i->first;
+ break;
+ }
+ }
+
+ // Check: Warning - If the file does not have a package, check whether the
+ // prefix was declared is being used by another package or not. This is
+ // a special case for empty packages.
+ if (package.empty()) {
+ // The file does not have a package and ...
+ if (other_package_for_prefix.empty()) {
+ // ... no other package has declared that prefix.
+ std::cerr
+ << "protoc:0: warning: File '" << file->name() << "' has no "
+ << "package. Consider adding a new package to the proto and adding '"
+ << "new.package = " << prefix << "' to the expected prefixes file ("
+ << expected_prefixes_path << ")." << std::endl;
+ std::cerr.flush();
+ } else {
+ // ... another package has declared the same prefix.
+ std::cerr
+ << "protoc:0: warning: File '" << file->name() << "' has no package "
+ << "and package '" << other_package_for_prefix << "' already uses '"
+ << prefix << "' as its prefix. Consider either adding a new package "
+ << "to the proto, or reusing one of the packages already using this "
+ << "prefix in the expected prefixes file ("
+ << expected_prefixes_path << ")." << std::endl;
+ std::cerr.flush();
+ }
+ return true;
+ }
+
+ // Check: Error - Make sure the prefix wasn't expected for a different
+ // package (overlap is allowed, but it has to be listed as an expected
+ // overlap).
+ if (!other_package_for_prefix.empty()) {
+ *out_error =
+ "error: Found 'option objc_class_prefix = \"" + prefix +
+ "\";' in '" + file->name() +
+ "'; that prefix is already used for 'package " +
+ other_package_for_prefix + ";'. It can only be reused by listing " +
+ "it in the expected file (" +
+ expected_prefixes_path + ").";
+ return false; // Only report first usage of the prefix.
+ }
+ } // !prefix.empty()
+
// Check: Warning - Make sure the prefix is is a reasonable value according
// to Apple's rules (the checks above implicitly whitelist anything that
// doesn't meet these rules).
- if (!ascii_isupper(prefix[0])) {
+ if (!prefix.empty() && !ascii_isupper(prefix[0])) {
std::cerr
<< "protoc:0: warning: Invalid 'option objc_class_prefix = \""
<< prefix << "\";' in '" << file->name() << "';"
<< " it should start with a capital letter." << std::endl;
std::cerr.flush();
}
- if (prefix.length() < 3) {
+ if (!prefix.empty() && prefix.length() < 3) {
// Apple reserves 2 character prefixes for themselves. They do use some
// 3 character prefixes, but they haven't updated the rules/docs.
std::cerr
@@ -1147,60 +1345,9 @@ bool ValidateObjCClassPrefix(
std::cerr.flush();
}
- // Look for any other package that uses the same prefix.
- TProtoStringType other_package_for_prefix;
- for (std::map<TProtoStringType, TProtoStringType>::const_iterator i =
- expected_package_prefixes.begin();
- i != expected_package_prefixes.end(); ++i) {
- if (i->second == prefix) {
- other_package_for_prefix = i->first;
- break;
- }
- }
-
- // Check: Warning - If the file does not have a package, check whether
- // the prefix declared is being used by another package or not.
- if (package.empty()) {
- // The file does not have a package and ...
- if (other_package_for_prefix.empty()) {
- // ... no other package has declared that prefix.
- std::cerr
- << "protoc:0: warning: File '" << file->name() << "' has no "
- << "package. Consider adding a new package to the proto and adding '"
- << "new.package = " << prefix << "' to the expected prefixes file ("
- << expected_prefixes_path << ")." << std::endl;
- std::cerr.flush();
- } else {
- // ... another package has declared the same prefix.
- std::cerr
- << "protoc:0: warning: File '" << file->name() << "' has no package "
- << "and package '" << other_package_for_prefix << "' already uses '"
- << prefix << "' as its prefix. Consider either adding a new package "
- << "to the proto, or reusing one of the packages already using this "
- << "prefix in the expected prefixes file ("
- << expected_prefixes_path << ")." << std::endl;
- std::cerr.flush();
- }
- return true;
- }
-
- // Check: Error - Make sure the prefix wasn't expected for a different
- // package (overlap is allowed, but it has to be listed as an expected
- // overlap).
- if (!other_package_for_prefix.empty()) {
- *out_error =
- "error: Found 'option objc_class_prefix = \"" + prefix +
- "\";' in '" + file->name() +
- "'; that prefix is already used for 'package " +
- other_package_for_prefix + ";'. It can only be reused by listing " +
- "it in the expected file (" +
- expected_prefixes_path + ").";
- return false; // Only report first usage of the prefix.
- }
-
// Check: Warning - If the given package/prefix pair wasn't expected, issue a
- // warning issue a warning suggesting it gets added to the file.
- if (!expected_package_prefixes.empty()) {
+ // warning suggesting it gets added to the file.
+ if (have_expected_prefix_file) {
std::cerr
<< "protoc:0: warning: Found unexpected 'option objc_class_prefix = \""
<< prefix << "\";' in '" << file->name() << "';"
@@ -1217,6 +1364,12 @@ bool ValidateObjCClassPrefix(
bool ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files,
const Options& generation_options,
TProtoStringType* out_error) {
+ // Allow a '-' as the path for the expected prefixes to completely disable
+ // even the most basic of checks.
+ if (generation_options.expected_prefixes_path == "-") {
+ return true;
+ }
+
// Load the expected package prefixes, if available, to validate against.
std::map<TProtoStringType, TProtoStringType> expected_package_prefixes;
if (!LoadExpectedPackagePrefixes(generation_options,
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
index 9fb24936c2..2e291dbd6b 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
@@ -46,6 +46,19 @@ namespace protobuf {
namespace compiler {
namespace objectivec {
+// Get/Set if the proto package should be used to make the default prefix for
+// symbols. This will then impact most of the type naming apis below. It is done
+// as a global to not break any other generator reusing the methods since they
+// are exported.
+bool PROTOC_EXPORT UseProtoPackageAsDefaultPrefix();
+void PROTOC_EXPORT SetUseProtoPackageAsDefaultPrefix(bool on_or_off);
+// Get/Set the path to a file to load as exceptions when
+// `UseProtoPackageAsDefaultPrefixUseProtoPackageAsDefaultPrefix()` is `true`.
+// And empty string means there should be no exceptions loaded.
+TProtoStringType PROTOC_EXPORT GetProtoPackagePrefixExceptionList();
+void PROTOC_EXPORT SetProtoPackagePrefixExceptionList(
+ const TProtoStringType& file_path);
+
// Generator options (see objectivec_generator.cc for a description of each):
struct Options {
Options();
@@ -70,7 +83,7 @@ bool PROTOC_EXPORT IsRetainedName(const TProtoStringType& name);
// handling under ARC.
bool PROTOC_EXPORT IsInitName(const TProtoStringType& name);
-// Gets the objc_class_prefix.
+// Gets the objc_class_prefix or the prefix made from the proto package.
TProtoStringType PROTOC_EXPORT FileClassPrefix(const FileDescriptor* file);
// Gets the path of the file we're going to generate (sans the .pb.h
@@ -90,7 +103,7 @@ TProtoStringType PROTOC_EXPORT FileClassName(const FileDescriptor* file);
// descriptor.
TProtoStringType PROTOC_EXPORT ClassName(const Descriptor* descriptor);
TProtoStringType PROTOC_EXPORT ClassName(const Descriptor* descriptor,
- TProtoStringType* out_suffix_added);
+ TProtoStringType* out_suffix_added);
TProtoStringType PROTOC_EXPORT EnumName(const EnumDescriptor* descriptor);
// Returns the fully-qualified name of the enum value corresponding to the
@@ -296,7 +309,7 @@ class PROTOC_EXPORT ImportWriter {
ProtoFrameworkCollector(std::map<TProtoStringType, TProtoStringType>* inout_proto_file_to_framework_name)
: map_(inout_proto_file_to_framework_name) {}
- virtual bool ConsumeLine(const StringPiece& line, TProtoStringType* out_error);
+ virtual bool ConsumeLine(const StringPiece& line, TProtoStringType* out_error) override;
private:
std::map<TProtoStringType, TProtoStringType>* map_;
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_map_field.h
index 48ff7e9162..fd2b466dcc 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_map_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_map_field.h
@@ -45,7 +45,7 @@ class MapFieldGenerator : public RepeatedFieldGenerator {
const Options& options);
public:
- virtual void FinishInitialization(void);
+ virtual void FinishInitialization(void) override;
MapFieldGenerator(const MapFieldGenerator&) = delete;
MapFieldGenerator& operator=(const MapFieldGenerator&) = delete;
@@ -55,9 +55,9 @@ class MapFieldGenerator : public RepeatedFieldGenerator {
virtual ~MapFieldGenerator();
virtual void DetermineObjectiveCClassDefinitions(
- std::set<TProtoStringType>* fwd_decls) const;
+ std::set<TProtoStringType>* fwd_decls) const override;
virtual void DetermineForwardDeclarations(
- std::set<TProtoStringType>* fwd_decls) const;
+ std::set<TProtoStringType>* fwd_decls) const override;
private:
std::unique_ptr<FieldGenerator> value_field_generator_;
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
index ff89f66299..8897c9b7b6 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
@@ -55,9 +55,9 @@ class MessageFieldGenerator : public ObjCObjFieldGenerator {
public:
virtual void DetermineForwardDeclarations(
- std::set<TProtoStringType>* fwd_decls) const;
+ std::set<TProtoStringType>* fwd_decls) const override;
virtual void DetermineObjectiveCClassDefinitions(
- std::set<TProtoStringType>* fwd_decls) const;
+ std::set<TProtoStringType>* fwd_decls) const override;
};
class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator {
@@ -74,9 +74,9 @@ class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator {
public:
virtual void DetermineForwardDeclarations(
- std::set<TProtoStringType>* fwd_decls) const;
+ std::set<TProtoStringType>* fwd_decls) const override;
virtual void DetermineObjectiveCClassDefinitions(
- std::set<TProtoStringType>* fwd_decls) const;
+ std::set<TProtoStringType>* fwd_decls) const override;
};
} // namespace objectivec
diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
index 642f2d6323..a9f30f6419 100644
--- a/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
+++ b/contrib/libs/protoc/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
@@ -52,10 +52,10 @@ class PrimitiveFieldGenerator : public SingleFieldGenerator {
PrimitiveFieldGenerator(const PrimitiveFieldGenerator&) = delete;
PrimitiveFieldGenerator& operator=(const PrimitiveFieldGenerator&) = delete;
- virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const;
+ virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override;
- virtual int ExtraRuntimeHasBitsNeeded(void) const;
- virtual void SetExtraRuntimeHasBitsBase(int index_base);
+ virtual int ExtraRuntimeHasBitsNeeded(void) const override;
+ virtual void SetExtraRuntimeHasBitsBase(int index_base) override;
};
class PrimitiveObjFieldGenerator : public ObjCObjFieldGenerator {