PROTOBUF_SYNC_PIPER
pull/10797/head
Mike Kruskal 2 years ago
parent 407aa2d931
commit 86594306aa
  1. 4
      src/google/protobuf/compiler/command_line_interface.cc
  2. 6
      src/google/protobuf/compiler/command_line_interface.h
  3. 3
      src/google/protobuf/compiler/cpp/enum_field.cc
  4. 3
      src/google/protobuf/compiler/cpp/extension.h
  5. 32
      src/google/protobuf/compiler/cpp/field.cc
  6. 12
      src/google/protobuf/compiler/cpp/field.h
  7. 3
      src/google/protobuf/compiler/cpp/file.h
  8. 8
      src/google/protobuf/compiler/cpp/helpers.cc
  9. 16
      src/google/protobuf/compiler/cpp/helpers.h
  10. 10
      src/google/protobuf/compiler/cpp/map_field.cc
  11. 22
      src/google/protobuf/compiler/cpp/message.cc
  12. 4
      src/google/protobuf/compiler/cpp/message.h
  13. 10
      src/google/protobuf/compiler/cpp/message_field.cc
  14. 3
      src/google/protobuf/compiler/cpp/parse_function_generator.cc
  15. 15
      src/google/protobuf/compiler/cpp/parse_function_generator.h
  16. 8
      src/google/protobuf/compiler/cpp/primitive_field.cc
  17. 5
      src/google/protobuf/compiler/cpp/service.h
  18. 8
      src/google/protobuf/compiler/cpp/string_field.cc
  19. 4
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  20. 8
      src/google/protobuf/compiler/csharp/csharp_field_base.h
  21. 59
      src/google/protobuf/compiler/csharp/csharp_message.cc
  22. 7
      src/google/protobuf/compiler/java/enum.cc
  23. 3
      src/google/protobuf/compiler/java/enum_field.cc
  24. 5
      src/google/protobuf/compiler/java/enum_field.h
  25. 26
      src/google/protobuf/compiler/java/enum_field_lite.cc
  26. 5
      src/google/protobuf/compiler/java/enum_field_lite.h
  27. 7
      src/google/protobuf/compiler/java/enum_lite.cc
  28. 8
      src/google/protobuf/compiler/java/extension.cc
  29. 11
      src/google/protobuf/compiler/java/extension.h
  30. 3
      src/google/protobuf/compiler/java/extension_lite.cc
  31. 25
      src/google/protobuf/compiler/java/field.cc
  32. 18
      src/google/protobuf/compiler/java/field.h
  33. 9
      src/google/protobuf/compiler/java/helpers.cc
  34. 9
      src/google/protobuf/compiler/java/helpers.h
  35. 52
      src/google/protobuf/compiler/java/map_field.cc
  36. 2
      src/google/protobuf/compiler/java/map_field.h
  37. 8
      src/google/protobuf/compiler/java/map_field_lite.cc
  38. 2
      src/google/protobuf/compiler/java/map_field_lite.h
  39. 10
      src/google/protobuf/compiler/java/message.cc
  40. 2
      src/google/protobuf/compiler/java/message_builder.cc
  41. 2
      src/google/protobuf/compiler/java/message_builder_lite.cc
  42. 26
      src/google/protobuf/compiler/java/message_field.cc
  43. 4
      src/google/protobuf/compiler/java/message_field.h
  44. 23
      src/google/protobuf/compiler/java/message_field_lite.cc
  45. 4
      src/google/protobuf/compiler/java/message_field_lite.h
  46. 7
      src/google/protobuf/compiler/java/message_lite.cc
  47. 72
      src/google/protobuf/compiler/java/primitive_field.cc
  48. 4
      src/google/protobuf/compiler/java/primitive_field.h
  49. 71
      src/google/protobuf/compiler/java/primitive_field_lite.cc
  50. 4
      src/google/protobuf/compiler/java/primitive_field_lite.h
  51. 14
      src/google/protobuf/compiler/java/service.cc
  52. 11
      src/google/protobuf/compiler/java/string_field.cc
  53. 4
      src/google/protobuf/compiler/java/string_field.h
  54. 11
      src/google/protobuf/compiler/java/string_field_lite.cc
  55. 4
      src/google/protobuf/compiler/java/string_field_lite.h
  56. 6
      src/google/protobuf/compiler/objectivec/enum_field.cc
  57. 5
      src/google/protobuf/compiler/objectivec/extension.cc
  58. 6
      src/google/protobuf/compiler/objectivec/field.cc
  59. 3
      src/google/protobuf/compiler/objectivec/field.h
  60. 2
      src/google/protobuf/compiler/objectivec/file.cc
  61. 10
      src/google/protobuf/compiler/objectivec/import_writer.cc
  62. 3
      src/google/protobuf/compiler/objectivec/import_writer.h
  63. 3
      src/google/protobuf/compiler/objectivec/message.cc
  64. 6
      src/google/protobuf/compiler/objectivec/message_field.cc
  65. 29
      src/google/protobuf/compiler/objectivec/names.cc
  66. 3
      src/google/protobuf/compiler/objectivec/oneof.h
  67. 6
      src/google/protobuf/compiler/objectivec/primitive_field.cc
  68. 29
      src/google/protobuf/compiler/python/generator.cc
  69. 3
      src/google/protobuf/compiler/python/pyi_generator.h
  70. 33
      src/google/protobuf/io/printer.h
  71. 2
      third_party/utf8_range

@ -425,7 +425,7 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext {
// The files_ field maps from path keys to file content values. It's a map // The files_ field maps from path keys to file content values. It's a map
// instead of an unordered_map so that files are written in order (good when // instead of an unordered_map so that files are written in order (good when
// writing zips). // writing zips).
absl::flat_hash_map<std::string, std::string> files_; std::map<std::string, std::string> files_;
const std::vector<const FileDescriptor*>& parsed_files_; const std::vector<const FileDescriptor*>& parsed_files_;
bool had_error_; bool had_error_;
}; };
@ -1493,7 +1493,7 @@ CommandLineInterface::ParseArgumentStatus CommandLineInterface::ParseArguments(
// Make sure each plugin option has a matching plugin output. // Make sure each plugin option has a matching plugin output.
bool foundUnknownPluginOption = false; bool foundUnknownPluginOption = false;
for (absl::flat_hash_map<std::string, std::string>::const_iterator i = for (std::map<std::string, std::string>::const_iterator i =
plugin_parameters_.begin(); plugin_parameters_.begin();
i != plugin_parameters_.end(); ++i) { i != plugin_parameters_.end(); ++i) {
if (plugins_.find(i->first) != plugins_.end()) { if (plugins_.find(i->first) != plugins_.end()) {

@ -367,9 +367,9 @@ class PROTOC_EXPORT CommandLineInterface {
// flag. For example, if the user invokes the compiler with: // flag. For example, if the user invokes the compiler with:
// protoc --foo_out=outputdir --foo_opt=enable_bar ... // protoc --foo_out=outputdir --foo_opt=enable_bar ...
// Then there will be an entry ("--foo_out", "enable_bar") in this map. // Then there will be an entry ("--foo_out", "enable_bar") in this map.
absl::flat_hash_map<std::string, std::string> generator_parameters_; std::map<std::string, std::string> generator_parameters_;
// Similar to generator_parameters_, but stores the parameters for plugins. // Similar to generator_parameters_, but stores the parameters for plugins.
absl::flat_hash_map<std::string, std::string> plugin_parameters_; std::map<std::string, std::string> plugin_parameters_;
// See AllowPlugins(). If this is empty, plugins aren't allowed. // See AllowPlugins(). If this is empty, plugins aren't allowed.
std::string plugin_prefix_; std::string plugin_prefix_;
@ -377,7 +377,7 @@ class PROTOC_EXPORT CommandLineInterface {
// Maps specific plugin names to files. When executing a plugin, this map // Maps specific plugin names to files. When executing a plugin, this map
// is searched first to find the plugin executable. If not found here, the // is searched first to find the plugin executable. If not found here, the
// PATH (or other OS-specific search strategy) is searched. // PATH (or other OS-specific search strategy) is searched.
absl::flat_hash_map<std::string, std::string> plugins_; std::map<std::string, std::string> plugins_;
// Stuff parsed from command line. // Stuff parsed from command line.
enum Mode { enum Mode {

@ -36,7 +36,6 @@
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/field.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
@ -48,7 +47,7 @@ namespace cpp {
namespace { namespace {
void SetEnumVariables(const FieldDescriptor* descriptor, void SetEnumVariables(const FieldDescriptor* descriptor,
absl::flat_hash_map<std::string, std::string>* variables, std::map<std::string, std::string>* variables,
const Options& options) { const Options& options) {
SetCommonFieldVariables(descriptor, variables, options); SetCommonFieldVariables(descriptor, variables, options);
const EnumValueDescriptor* default_value = descriptor->default_value_enum(); const EnumValueDescriptor* default_value = descriptor->default_value_enum();

@ -38,7 +38,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/compiler/cpp/options.h"
#include "google/protobuf/port.h" #include "google/protobuf/port.h"
@ -85,7 +84,7 @@ class ExtensionGenerator {
Options options_; Options options_;
MessageSCCAnalyzer* scc_analyzer_; MessageSCCAnalyzer* scc_analyzer_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };
} // namespace cpp } // namespace cpp

@ -38,7 +38,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/strings/substitute.h" #include "absl/strings/substitute.h"
@ -63,12 +62,12 @@ using internal::WireFormat;
namespace { namespace {
void MaySetAnnotationVariable( void MaySetAnnotationVariable(const Options& options,
const Options& options, absl::string_view annotation_name, absl::string_view annotation_name,
absl::string_view substitute_template_prefix, absl::string_view substitute_template_prefix,
absl::string_view prepared_template, int field_index, absl::string_view prepared_template,
absl::string_view access_type, int field_index, absl::string_view access_type,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
if (options.field_listener_options.forbidden_field_listener_events.count( if (options.field_listener_options.forbidden_field_listener_events.count(
std::string(annotation_name))) std::string(annotation_name)))
return; return;
@ -125,9 +124,9 @@ std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor,
} // namespace } // namespace
void AddAccessorAnnotations( void AddAccessorAnnotations(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, const Options& options, const Options& options,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
// Can be expanded to include more specific calls, for example, for arena or // Can be expanded to include more specific calls, for example, for arena or
// clear calls. // clear calls.
static constexpr const char* kAccessorsAnnotations[] = { static constexpr const char* kAccessorsAnnotations[] = {
@ -262,7 +261,7 @@ absl::flat_hash_map<std::string, std::string> FieldVars(
// TODO(b/245791219): Refactor AddAccessorAnnotations to avoid this // TODO(b/245791219): Refactor AddAccessorAnnotations to avoid this
// workaround. // workaround.
absl::flat_hash_map<std::string, std::string> workaround = { std::map<std::string, std::string> workaround = {
{"field", vars["field"]}, {"field", vars["field"]},
{"tracker", "Impl_::_tracker_"}, {"tracker", "Impl_::_tracker_"},
}; };
@ -274,10 +273,9 @@ absl::flat_hash_map<std::string, std::string> FieldVars(
return vars; return vars;
} }
void SetCommonFieldVariables( void SetCommonFieldVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables,
absl::flat_hash_map<std::string, std::string>* variables, const Options& options) {
const Options& options) {
SetCommonMessageDataVariables(descriptor->containing_type(), variables); SetCommonMessageDataVariables(descriptor->containing_type(), variables);
for (auto& pair : FieldVars(descriptor, options)) { for (auto& pair : FieldVars(descriptor, options)) {
@ -296,14 +294,14 @@ absl::flat_hash_map<std::string, std::string> OneofFieldVars(
void SetCommonOneofFieldVariables( void SetCommonOneofFieldVariables(
const FieldDescriptor* descriptor, const FieldDescriptor* descriptor,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
for (auto& pair : OneofFieldVars(descriptor)) { for (auto& pair : OneofFieldVars(descriptor)) {
variables->emplace(pair); variables->emplace(pair);
} }
} }
void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) { void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) {
if (!internal::cpp::HasHasbit(descriptor_) || has_bit_index < 0) { if (!internal::cpp::HasHasbit(descriptor_)) {
GOOGLE_CHECK_EQ(has_bit_index, -1); GOOGLE_CHECK_EQ(has_bit_index, -1);
return; return;
} }

@ -41,7 +41,6 @@
#include <string> #include <string>
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/compiler/cpp/options.h"
@ -68,14 +67,13 @@ absl::flat_hash_map<std::string, std::string> OneofFieldVars(
// field code generators. // field code generators.
// ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size',
// 'deprecation']. // 'deprecation'].
void SetCommonFieldVariables( void SetCommonFieldVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables,
absl::flat_hash_map<std::string, std::string>* variables, const Options& options);
const Options& options);
void SetCommonOneofFieldVariables( void SetCommonOneofFieldVariables(
const FieldDescriptor* descriptor, const FieldDescriptor* descriptor,
absl::flat_hash_map<std::string, std::string>* variables); std::map<std::string, std::string>* variables);
class FieldGenerator { class FieldGenerator {
public: public:
@ -228,7 +226,7 @@ class FieldGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
const Options& options_; const Options& options_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };
// Convenience class which constructs FieldGenerators for a Descriptor. // Convenience class which constructs FieldGenerators for a Descriptor.

@ -44,7 +44,6 @@
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/compiler/scc.h" #include "google/protobuf/compiler/scc.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
#include "google/protobuf/compiler/cpp/enum.h" #include "google/protobuf/compiler/cpp/enum.h"
#include "google/protobuf/compiler/cpp/extension.h" #include "google/protobuf/compiler/cpp/extension.h"
@ -196,7 +195,7 @@ class FileGenerator {
// This member is unused and should be deleted once all old-style variable // This member is unused and should be deleted once all old-style variable
// maps are gone. // maps are gone.
// TODO(b/245791219) // TODO(b/245791219)
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
// Contains the post-order walk of all the messages (and child messages) in // Contains the post-order walk of all the messages (and child messages) in
// this file. If you need a pre-order walk just reverse iterate. // this file. If you need a pre-order walk just reverse iterate.

@ -252,7 +252,7 @@ absl::flat_hash_map<std::string, std::string> MessageVars(
void SetCommonMessageDataVariables( void SetCommonMessageDataVariables(
const Descriptor* descriptor, const Descriptor* descriptor,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
for (auto& pair : MessageVars(descriptor)) { for (auto& pair : MessageVars(descriptor)) {
variables->emplace(pair); variables->emplace(pair);
} }
@ -286,9 +286,9 @@ absl::flat_hash_map<std::string, std::string> UnknownFieldsVars(
}; };
} }
void SetUnknownFieldsVariable( void SetUnknownFieldsVariable(const Descriptor* descriptor,
const Descriptor* descriptor, const Options& options, const Options& options,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
for (auto& pair : UnknownFieldsVars(descriptor, options)) { for (auto& pair : UnknownFieldsVars(descriptor, options)) {
variables->emplace(pair); variables->emplace(pair);
} }

@ -94,14 +94,14 @@ absl::flat_hash_map<std::string, std::string> MessageVars(
// Variables to access message data from the message scope. // Variables to access message data from the message scope.
void SetCommonMessageDataVariables( void SetCommonMessageDataVariables(
const Descriptor* descriptor, const Descriptor* descriptor,
absl::flat_hash_map<std::string, std::string>* variables); std::map<std::string, std::string>* variables);
absl::flat_hash_map<std::string, std::string> UnknownFieldsVars( absl::flat_hash_map<std::string, std::string> UnknownFieldsVars(
const Descriptor* desc, const Options& opts); const Descriptor* desc, const Options& opts);
void SetUnknownFieldsVariable( void SetUnknownFieldsVariable(const Descriptor* descriptor,
const Descriptor* descriptor, const Options& options, const Options& options,
absl::flat_hash_map<std::string, std::string>* variables); std::map<std::string, std::string>* variables);
bool GetBootstrapBasename(const Options& options, const std::string& basename, bool GetBootstrapBasename(const Options& options, const std::string& basename,
std::string* bootstrap_basename); std::string* bootstrap_basename);
@ -794,7 +794,7 @@ class PROTOC_EXPORT Formatter {
public: public:
explicit Formatter(io::Printer* printer) : printer_(printer) {} explicit Formatter(io::Printer* printer) : printer_(printer) {}
Formatter(io::Printer* printer, Formatter(io::Printer* printer,
const absl::flat_hash_map<std::string, std::string>& vars) const std::map<std::string, std::string>& vars)
: printer_(printer), vars_(vars) {} : printer_(printer), vars_(vars) {}
template <typename T> template <typename T>
@ -802,7 +802,7 @@ class PROTOC_EXPORT Formatter {
vars_[key] = ToString(value); vars_[key] = ToString(value);
} }
void AddMap(const absl::flat_hash_map<std::string, std::string>& vars) { void AddMap(const std::map<std::string, std::string>& vars) {
for (const auto& keyval : vars) vars_[keyval.first] = keyval.second; for (const auto& keyval : vars) vars_[keyval.first] = keyval.second;
} }
@ -844,12 +844,12 @@ class PROTOC_EXPORT Formatter {
private: private:
Formatter* format_; Formatter* format_;
absl::flat_hash_map<std::string, std::string> vars_; std::map<std::string, std::string> vars_;
}; };
private: private:
io::Printer* printer_; io::Printer* printer_;
absl::flat_hash_map<std::string, std::string> vars_; std::map<std::string, std::string> vars_;
// Convenience overloads to accept different types as arguments. // Convenience overloads to accept different types as arguments.
static std::string ToString(const std::string& s) { return s; } static std::string ToString(const std::string& s) { return s; }

@ -31,19 +31,17 @@
#include "google/protobuf/compiler/cpp/map_field.h" #include "google/protobuf/compiler/cpp/map_field.h"
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
#include "absl/strings/str_cat.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace compiler { namespace compiler {
namespace cpp { namespace cpp {
void SetMessageVariables( void SetMessageVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables,
absl::flat_hash_map<std::string, std::string>* variables, const Options& options) {
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options); SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = ClassName(descriptor->message_type(), false); (*variables)["type"] = ClassName(descriptor->message_type(), false);
(*variables)["full_name"] = descriptor->full_name(); (*variables)["full_name"] = descriptor->full_name();

@ -278,9 +278,9 @@ bool HasHasMethod(const FieldDescriptor* field) {
// Collects map entry message type information. // Collects map entry message type information.
void CollectMapInfo(const Options& options, const Descriptor* descriptor, void CollectMapInfo(const Options& options, const Descriptor* descriptor,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
GOOGLE_CHECK(IsMapEntryMessage(descriptor)); GOOGLE_CHECK(IsMapEntryMessage(descriptor));
absl::flat_hash_map<std::string, std::string>& vars = *variables; std::map<std::string, std::string>& vars = *variables;
const FieldDescriptor* key = descriptor->map_key(); const FieldDescriptor* key = descriptor->map_key();
const FieldDescriptor* val = descriptor->map_value(); const FieldDescriptor* val = descriptor->map_value();
vars["key_cpp"] = PrimitiveTypeName(options, key->cpp_type()); vars["key_cpp"] = PrimitiveTypeName(options, key->cpp_type());
@ -429,7 +429,7 @@ class ColdChunkSkipper {
const std::vector<int>& has_bit_indices_; const std::vector<int>& has_bit_indices_;
const AccessInfoMap* access_info_map_; const AccessInfoMap* access_info_map_;
const double cold_threshold_; const double cold_threshold_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
int limit_chunk_ = -1; int limit_chunk_ = -1;
}; };
@ -640,11 +640,11 @@ absl::flat_hash_map<std::string, std::string> ClassVars(const Descriptor* desc,
// =================================================================== // ===================================================================
MessageGenerator::MessageGenerator( MessageGenerator::MessageGenerator(const Descriptor* descriptor,
const Descriptor* descriptor, const std::map<std::string, std::string>&,
const absl::flat_hash_map<std::string, std::string>&, int index_in_file_messages,
int index_in_file_messages, const Options& options, const Options& options,
MessageSCCAnalyzer* scc_analyzer) MessageSCCAnalyzer* scc_analyzer)
: descriptor_(descriptor), : descriptor_(descriptor),
index_in_file_messages_(index_in_file_messages), index_in_file_messages_(index_in_file_messages),
options_(options), options_(options),
@ -779,7 +779,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) {
for (auto field : ordered_fields) { for (auto field : ordered_fields) {
Formatter::SaveState save(&format); Formatter::SaveState save(&format);
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
SetCommonFieldVariables(field, &vars, options_); SetCommonFieldVariables(field, &vars, options_);
auto v = p->WithVars(std::move(vars)); auto v = p->WithVars(std::move(vars));
format(" ${1$$2$$}$ = $number$,\n", field, FieldConstantName(field)); format(" ${1$$2$$}$ = $number$,\n", field, FieldConstantName(field));
@ -1290,7 +1290,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
Formatter format(p); Formatter format(p);
if (IsMapEntryMessage(descriptor_)) { if (IsMapEntryMessage(descriptor_)) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
CollectMapInfo(options_, descriptor_, &vars); CollectMapInfo(options_, descriptor_, &vars);
vars["lite"] = vars["lite"] =
HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite"; HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite";
@ -3749,7 +3749,7 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* p,
void MessageGenerator::GenerateSerializeOneExtensionRange( void MessageGenerator::GenerateSerializeOneExtensionRange(
io::Printer* p, const Descriptor::ExtensionRange* range) { io::Printer* p, const Descriptor::ExtensionRange* range) {
absl::flat_hash_map<std::string, std::string> vars = variables_; std::map<std::string, std::string> vars = variables_;
vars["start"] = absl::StrCat(range->start); vars["start"] = absl::StrCat(range->start);
vars["end"] = absl::StrCat(range->end); vars["end"] = absl::StrCat(range->end);
Formatter format(p, vars); Formatter format(p, vars);

@ -61,7 +61,7 @@ namespace cpp {
class MessageGenerator { class MessageGenerator {
public: public:
MessageGenerator(const Descriptor* descriptor, MessageGenerator(const Descriptor* descriptor,
const absl::flat_hash_map<std::string, std::string>& ignored, const std::map<std::string, std::string>& ignored,
int index_in_file_messages, const Options& options, int index_in_file_messages, const Options& options,
MessageSCCAnalyzer* scc_analyzer); MessageSCCAnalyzer* scc_analyzer);
@ -214,7 +214,7 @@ class MessageGenerator {
MessageSCCAnalyzer* scc_analyzer_; MessageSCCAnalyzer* scc_analyzer_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };

@ -35,10 +35,9 @@
#include "google/protobuf/compiler/cpp/message_field.h" #include "google/protobuf/compiler/cpp/message_field.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/field.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
#include "absl/strings/str_cat.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {
@ -56,10 +55,9 @@ std::string ReinterpretCast(const std::string& type,
} }
} }
void SetMessageVariables( void SetMessageVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, const Options& options, const Options& options, bool implicit_weak,
bool implicit_weak, std::map<std::string, std::string>* variables) {
absl::flat_hash_map<std::string, std::string>* variables) {
SetCommonFieldVariables(descriptor, variables, options); SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = FieldMessageTypeName(descriptor, options); (*variables)["type"] = FieldMessageTypeName(descriptor, options);
(*variables)["casted_member"] = ReinterpretCast( (*variables)["casted_member"] = ReinterpretCast(

@ -38,7 +38,6 @@
#include <vector> #include <vector>
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/generated_message_tctable_gen.h" #include "google/protobuf/generated_message_tctable_gen.h"
@ -110,7 +109,7 @@ ParseFunctionGenerator::ParseFunctionGenerator(
const std::vector<int>& has_bit_indices, const std::vector<int>& has_bit_indices,
const std::vector<int>& inlined_string_indices, const Options& options, const std::vector<int>& inlined_string_indices, const Options& options,
MessageSCCAnalyzer* scc_analyzer, MessageSCCAnalyzer* scc_analyzer,
const absl::flat_hash_map<std::string, std::string>& vars) const std::map<std::string, std::string>& vars)
: descriptor_(descriptor), : descriptor_(descriptor),
scc_analyzer_(scc_analyzer), scc_analyzer_(scc_analyzer),
options_(options), options_(options),

@ -38,7 +38,6 @@
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/wire_format_lite.h" #include "google/protobuf/wire_format_lite.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/compiler/cpp/options.h"
#include "google/protobuf/generated_message_tctable_gen.h" #include "google/protobuf/generated_message_tctable_gen.h"
@ -52,12 +51,12 @@ namespace cpp {
// (and any associated supporting members). // (and any associated supporting members).
class ParseFunctionGenerator { class ParseFunctionGenerator {
public: public:
ParseFunctionGenerator( ParseFunctionGenerator(const Descriptor* descriptor, int max_has_bit_index,
const Descriptor* descriptor, int max_has_bit_index, const std::vector<int>& has_bit_indices,
const std::vector<int>& has_bit_indices, const std::vector<int>& inlined_string_indices,
const std::vector<int>& inlined_string_indices, const Options& options, const Options& options,
MessageSCCAnalyzer* scc_analyzer, MessageSCCAnalyzer* scc_analyzer,
const absl::flat_hash_map<std::string, std::string>& vars); const std::map<std::string, std::string>& vars);
// Emits class-level method declarations to `printer`: // Emits class-level method declarations to `printer`:
void GenerateMethodDecls(io::Printer* printer); void GenerateMethodDecls(io::Printer* printer);
@ -127,7 +126,7 @@ class ParseFunctionGenerator {
const Descriptor* descriptor_; const Descriptor* descriptor_;
MessageSCCAnalyzer* scc_analyzer_; MessageSCCAnalyzer* scc_analyzer_;
const Options& options_; const Options& options_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
std::unique_ptr<internal::TailCallTableInfo> tc_table_info_; std::unique_ptr<internal::TailCallTableInfo> tc_table_info_;
std::vector<int> inlined_string_indices_; std::vector<int> inlined_string_indices_;
const std::vector<const FieldDescriptor*> ordered_fields_; const std::vector<const FieldDescriptor*> ordered_fields_;

@ -36,7 +36,6 @@
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
@ -99,10 +98,9 @@ int FixedSize(FieldDescriptor::Type type) {
return -1; return -1;
} }
void SetPrimitiveVariables( void SetPrimitiveVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables,
absl::flat_hash_map<std::string, std::string>* variables, const Options& options) {
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options); SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = PrimitiveTypeName(options, descriptor->cpp_type()); (*variables)["type"] = PrimitiveTypeName(options, descriptor->cpp_type());
(*variables)["default"] = DefaultValue(options, descriptor); (*variables)["default"] = DefaultValue(options, descriptor);

@ -39,7 +39,6 @@
#include <string> #include <string>
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/compiler/cpp/options.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
@ -51,7 +50,7 @@ class ServiceGenerator {
public: public:
// See generator.cc for the meaning of dllexport_decl. // See generator.cc for the meaning of dllexport_decl.
ServiceGenerator(const ServiceDescriptor* descriptor, ServiceGenerator(const ServiceDescriptor* descriptor,
const absl::flat_hash_map<std::string, std::string>& vars, const std::map<std::string, std::string>& vars,
const Options& options) const Options& options)
: descriptor_(descriptor), options_(&options), vars_(vars) { : descriptor_(descriptor), options_(&options), vars_(vars) {
vars_["classname"] = descriptor_->name(); vars_["classname"] = descriptor_->name();
@ -99,7 +98,7 @@ class ServiceGenerator {
const ServiceDescriptor* descriptor_; const ServiceDescriptor* descriptor_;
const Options* options_; const Options* options_;
absl::flat_hash_map<std::string, std::string> vars_; std::map<std::string, std::string> vars_;
int index_in_metadata_; int index_in_metadata_;

@ -34,7 +34,6 @@
#include "google/protobuf/compiler/cpp/string_field.h" #include "google/protobuf/compiler/cpp/string_field.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
@ -46,10 +45,9 @@ namespace cpp {
namespace { namespace {
void SetStringVariables( void SetStringVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables,
absl::flat_hash_map<std::string, std::string>* variables, const Options& options) {
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options); SetCommonFieldVariables(descriptor, variables, options);
const std::string kNS = "::" + ProtobufNamespace(options) + "::internal::"; const std::string kNS = "::" + ProtobufNamespace(options) + "::internal::";

@ -52,7 +52,7 @@ namespace compiler {
namespace csharp { namespace csharp {
void FieldGeneratorBase::SetCommonFieldVariables( void FieldGeneratorBase::SetCommonFieldVariables(
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
// Note: this will be valid even though the tag emitted for packed and unpacked versions of // Note: this will be valid even though the tag emitted for packed and unpacked versions of
// repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which // repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which
// never effects the tag size. // never effects the tag size.
@ -124,7 +124,7 @@ void FieldGeneratorBase::SetCommonFieldVariables(
} }
void FieldGeneratorBase::SetCommonOneofFieldVariables( void FieldGeneratorBase::SetCommonOneofFieldVariables(
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["oneof_name"] = oneof_name(); (*variables)["oneof_name"] = oneof_name();
if (SupportsPresenceApi(descriptor_)) { if (SupportsPresenceApi(descriptor_)) {
(*variables)["has_property_check"] = "Has" + property_name(); (*variables)["has_property_check"] = "Has" + property_name();

@ -34,7 +34,6 @@
#include <string> #include <string>
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
@ -78,7 +77,7 @@ class FieldGeneratorBase : public SourceGeneratorBase {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
const int presenceIndex_; const int presenceIndex_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
void AddDeprecatedFlag(io::Printer* printer); void AddDeprecatedFlag(io::Printer* printer);
void AddNullCheck(io::Printer* printer); void AddNullCheck(io::Printer* printer);
@ -86,7 +85,7 @@ class FieldGeneratorBase : public SourceGeneratorBase {
void AddPublicMemberAttributes(io::Printer* printer); void AddPublicMemberAttributes(io::Printer* printer);
void SetCommonOneofFieldVariables( void SetCommonOneofFieldVariables(
absl::flat_hash_map<std::string, std::string>* variables); std::map<std::string, std::string>* variables);
std::string oneof_property_name(); std::string oneof_property_name();
std::string oneof_case_name(); std::string oneof_case_name();
@ -102,8 +101,7 @@ class FieldGeneratorBase : public SourceGeneratorBase {
std::string capitalized_type_name(); std::string capitalized_type_name();
private: private:
void SetCommonFieldVariables( void SetCommonFieldVariables(std::map<std::string, std::string>* variables);
absl::flat_hash_map<std::string, std::string>* variables);
std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor); std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor);
std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor); std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor);
}; };

@ -35,14 +35,13 @@
#include <sstream> #include <sstream>
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h"
#include "google/protobuf/compiler/csharp/csharp_enum.h" #include "google/protobuf/compiler/csharp/csharp_enum.h"
#include "google/protobuf/compiler/csharp/csharp_field_base.h" #include "google/protobuf/compiler/csharp/csharp_field_base.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/compiler/csharp/names.h" #include "google/protobuf/compiler/csharp/names.h"
#include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
@ -115,7 +114,7 @@ void MessageGenerator::AddSerializableAttribute(io::Printer* printer) {
} }
void MessageGenerator::Generate(io::Printer* printer) { void MessageGenerator::Generate(io::Printer* printer) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["class_name"] = class_name(); vars["class_name"] = class_name();
vars["access_level"] = class_access_level(); vars["access_level"] = class_access_level();
@ -377,7 +376,7 @@ bool MessageGenerator::HasNestedGeneratedTypes()
} }
void MessageGenerator::GenerateCloningCode(io::Printer* printer) { void MessageGenerator::GenerateCloningCode(io::Printer* printer) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
WriteGeneratedCodeAttributes(printer); WriteGeneratedCodeAttributes(printer);
vars["class_name"] = class_name(); vars["class_name"] = class_name();
printer->Print( printer->Print(
@ -441,30 +440,32 @@ void MessageGenerator::GenerateFreezingCode(io::Printer* printer) {
} }
void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["class_name"] = class_name(); vars["class_name"] = class_name();
// Equality // Equality
WriteGeneratedCodeAttributes(printer); WriteGeneratedCodeAttributes(printer);
printer->Print(vars, printer->Print(
"public override bool Equals(object other) {\n" vars,
" return Equals(other as $class_name$);\n" "public override bool Equals(object other) {\n"
"}\n\n"); " return Equals(other as $class_name$);\n"
WriteGeneratedCodeAttributes(printer); "}\n\n");
printer->Print(vars, WriteGeneratedCodeAttributes(printer);
"public bool Equals($class_name$ other) {\n" printer->Print(
" if (ReferenceEquals(other, null)) {\n" vars,
" return false;\n" "public bool Equals($class_name$ other) {\n"
" }\n" " if (ReferenceEquals(other, null)) {\n"
" if (ReferenceEquals(other, this)) {\n" " return false;\n"
" return true;\n" " }\n"
" }\n"); " if (ReferenceEquals(other, this)) {\n"
printer->Indent(); " return true;\n"
for (int i = 0; i < descriptor_->field_count(); i++) { " }\n");
std::unique_ptr<FieldGeneratorBase> generator( printer->Indent();
CreateFieldGeneratorInternal(descriptor_->field(i))); for (int i = 0; i < descriptor_->field_count(); i++) {
generator->WriteEquals(printer); std::unique_ptr<FieldGeneratorBase> generator(
} CreateFieldGeneratorInternal(descriptor_->field(i)));
generator->WriteEquals(printer);
}
for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) { for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
printer->Print("if ($property_name$Case != other.$property_name$Case) return false;\n", printer->Print("if ($property_name$Case != other.$property_name$Case) return false;\n",
"property_name", UnderscoresToCamelCase(descriptor_->oneof_decl(i)->name(), true)); "property_name", UnderscoresToCamelCase(descriptor_->oneof_decl(i)->name(), true));
@ -606,7 +607,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
// Note: These are separate from GenerateMessageSerializationMethods() // Note: These are separate from GenerateMessageSerializationMethods()
// because they need to be generated even for messages that are optimized // because they need to be generated even for messages that are optimized
// for code size. // for code size.
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["class_name"] = class_name(); vars["class_name"] = class_name();
WriteGeneratedCodeAttributes(printer); WriteGeneratedCodeAttributes(printer);
@ -686,7 +687,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
} }
void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_parse_context) { void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_parse_context) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["maybe_ref_input"] = use_parse_context ? "ref input" : "input"; vars["maybe_ref_input"] = use_parse_context ? "ref input" : "input";
printer->Print( printer->Print(

@ -38,7 +38,6 @@
#include <string> #include <string>
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
@ -104,7 +103,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
} }
for (int i = 0; i < canonical_values_.size(); i++) { for (int i = 0; i < canonical_values_.size(); i++) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["name"] = canonical_values_[i]->name(); vars["name"] = canonical_values_[i]->name();
vars["index"] = absl::StrCat(canonical_values_[i]->index()); vars["index"] = absl::StrCat(canonical_values_[i]->index());
vars["number"] = absl::StrCat(canonical_values_[i]->number()); vars["number"] = absl::StrCat(canonical_values_[i]->number());
@ -136,7 +135,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
for (int i = 0; i < aliases_.size(); i++) { for (int i = 0; i < aliases_.size(); i++) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["classname"] = descriptor_->name(); vars["classname"] = descriptor_->name();
vars["name"] = aliases_[i].value->name(); vars["name"] = aliases_[i].value->name();
vars["canonical_name"] = aliases_[i].canonical_value->name(); vars["canonical_name"] = aliases_[i].canonical_value->name();
@ -147,7 +146,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
} }
for (int i = 0; i < descriptor_->value_count(); i++) { for (int i = 0; i < descriptor_->value_count(); i++) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["name"] = descriptor_->value(i)->name(); vars["name"] = descriptor_->value(i)->name();
vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["number"] = absl::StrCat(descriptor_->value(i)->number());
vars["{"] = ""; vars["{"] = "";

@ -42,7 +42,6 @@
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
@ -62,7 +61,7 @@ namespace {
void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info, int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver, ClassNameResolver* name_resolver,
absl::flat_hash_map<std::string, std::string>* variables, std::map<std::string, std::string>* variables,
Context* context) { Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);

@ -38,7 +38,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/java/field.h" #include "google/protobuf/compiler/java/field.h"
namespace google { namespace google {
@ -91,7 +90,7 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };
@ -154,7 +153,7 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };

@ -42,9 +42,7 @@
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
#include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/helpers.h"
@ -70,13 +68,13 @@ bool EnableExperimentalRuntimeForLite() {
void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info, int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver, ClassNameResolver* name_resolver,
absl::flat_hash_map<std::string, std::string>* variables, std::map<std::string, std::string>* variables,
Context* context) { Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] = (*variables)["type"] =
name_resolver->GetImmutableClassName(descriptor->enum_type()); name_resolver->GetImmutableClassName(descriptor->enum_type());
variables->emplace("kt_type", EscapeKotlinKeywords((*variables)["type"])); (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]);
(*variables)["mutable_type"] = (*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->enum_type()); name_resolver->GetMutableClassName(descriptor->enum_type());
(*variables)["default"] = (*variables)["default"] =
@ -91,12 +89,11 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
// by the proto compiler // by the proto compiler
(*variables)["deprecation"] = (*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
variables->emplace( (*variables)["kt_deprecation"] =
"kt_deprecation",
descriptor->options().deprecated() descriptor->options().deprecated()
? absl::StrCat("@kotlin.Deprecated(message = \"Field ", ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
(*variables)["name"], " is deprecated\") ") " is deprecated\") "
: ""); : "";
(*variables)["required"] = descriptor->is_required() ? "true" : "false"; (*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (HasHasbit(descriptor)) { if (HasHasbit(descriptor)) {
@ -120,9 +117,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["set_has_field_bit_message"] = ""; (*variables)["set_has_field_bit_message"] = "";
(*variables)["clear_has_field_bit_message"] = ""; (*variables)["clear_has_field_bit_message"] = "";
variables->emplace("is_field_present_message", (*variables)["is_field_present_message"] =
absl::StrCat((*variables)["name"], "_ != ", (*variables)["name"] + "_ != " + (*variables)["default"] +
(*variables)["default"], ".getNumber()")); ".getNumber()";
} }
(*variables)["get_has_field_bit_from_local"] = (*variables)["get_has_field_bit_from_local"] =
@ -131,10 +128,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
GenerateSetBitToLocal(messageBitIndex); GenerateSetBitToLocal(messageBitIndex);
if (SupportUnknownEnumValue(descriptor->file())) { if (SupportUnknownEnumValue(descriptor->file())) {
variables->emplace("unknown", (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED";
absl::StrCat((*variables)["type"], ".UNRECOGNIZED"));
} else { } else {
variables->emplace("unknown", (*variables)["default"]); (*variables)["unknown"] = (*variables)["default"];
} }
// We use `x.getClass()` as a null check because it generates less bytecode // We use `x.getClass()` as a null check because it generates less bytecode

@ -39,7 +39,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/java/field.h" #include "google/protobuf/compiler/java/field.h"
namespace google { namespace google {
@ -84,7 +83,7 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
const int messageBitIndex_; const int messageBitIndex_;
Context* context_; Context* context_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
@ -132,7 +131,7 @@ class RepeatedImmutableEnumFieldLiteGenerator
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
Context* context_; Context* context_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };

@ -38,7 +38,6 @@
#include <string> #include <string>
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
@ -87,7 +86,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Indent(); printer->Indent();
for (int i = 0; i < canonical_values_.size(); i++) { for (int i = 0; i < canonical_values_.size(); i++) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["name"] = canonical_values_[i]->name(); vars["name"] = canonical_values_[i]->name();
vars["number"] = absl::StrCat(canonical_values_[i]->number()); vars["number"] = absl::StrCat(canonical_values_[i]->number());
WriteEnumValueDocComment(printer, canonical_values_[i]); WriteEnumValueDocComment(printer, canonical_values_[i]);
@ -110,7 +109,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
for (int i = 0; i < aliases_.size(); i++) { for (int i = 0; i < aliases_.size(); i++) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["classname"] = descriptor_->name(); vars["classname"] = descriptor_->name();
vars["name"] = aliases_[i].value->name(); vars["name"] = aliases_[i].value->name();
vars["canonical_name"] = aliases_[i].canonical_value->name(); vars["canonical_name"] = aliases_[i].canonical_value->name();
@ -121,7 +120,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
} }
for (int i = 0; i < descriptor_->value_count(); i++) { for (int i = 0; i < descriptor_->value_count(); i++) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["name"] = descriptor_->value(i)->name(); vars["name"] = descriptor_->value(i)->name();
vars["number"] = absl::StrCat(descriptor_->value(i)->number()); vars["number"] = absl::StrCat(descriptor_->value(i)->number());
vars["{"] = ""; vars["{"] = "";

@ -35,7 +35,6 @@
#include "google/protobuf/compiler/java/extension.h" #include "google/protobuf/compiler/java/extension.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
@ -69,9 +68,8 @@ ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {}
void ExtensionGenerator::InitTemplateVars( void ExtensionGenerator::InitTemplateVars(
const FieldDescriptor* descriptor, const std::string& scope, bool immutable, const FieldDescriptor* descriptor, const std::string& scope, bool immutable,
ClassNameResolver* name_resolver, ClassNameResolver* name_resolver,
absl::flat_hash_map<std::string, std::string>* vars_pointer, std::map<std::string, std::string>* vars_pointer, Context* context) {
Context* context) { std::map<std::string, std::string>& vars = *vars_pointer;
absl::flat_hash_map<std::string, std::string>& vars = *vars_pointer;
vars["scope"] = scope; vars["scope"] = scope;
vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor); vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor);
vars["containing_type"] = vars["containing_type"] =
@ -118,7 +116,7 @@ void ExtensionGenerator::InitTemplateVars(
} }
void ImmutableExtensionGenerator::Generate(io::Printer* printer) { void ImmutableExtensionGenerator::Generate(io::Printer* printer) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
const bool kUseImmutableNames = true; const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars, context_); &vars, context_);

@ -38,7 +38,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/port.h" #include "google/protobuf/port.h"
namespace google { namespace google {
@ -82,11 +81,11 @@ class ExtensionGenerator {
virtual int GenerateRegistrationCode(io::Printer* printer) = 0; virtual int GenerateRegistrationCode(io::Printer* printer) = 0;
protected: protected:
static void InitTemplateVars( static void InitTemplateVars(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, const std::string& scope, const std::string& scope, bool immutable,
bool immutable, ClassNameResolver* name_resolver, ClassNameResolver* name_resolver,
absl::flat_hash_map<std::string, std::string>* vars_pointer, std::map<std::string, std::string>* vars_pointer,
Context* context); Context* context);
}; };
class ImmutableExtensionGenerator : public ExtensionGenerator { class ImmutableExtensionGenerator : public ExtensionGenerator {

@ -31,7 +31,6 @@
#include "google/protobuf/compiler/java/extension_lite.h" #include "google/protobuf/compiler/java/extension_lite.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
#include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/helpers.h"
@ -61,7 +60,7 @@ ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator(
ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {} ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {}
void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) { void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
const bool kUseImmutableNames = true; const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars, context_); &vars, context_);

@ -39,7 +39,6 @@
#include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/substitute.h" #include "absl/strings/substitute.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
@ -242,9 +241,9 @@ template <>
FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap() {} FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap() {}
void SetCommonFieldVariables( void SetCommonFieldVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, const FieldGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["field_name"] = descriptor->name(); (*variables)["field_name"] = descriptor->name();
(*variables)["name"] = info->name; (*variables)["name"] = info->name;
(*variables)["classname"] = descriptor->containing_type()->name(); (*variables)["classname"] = descriptor->containing_type()->name();
@ -274,16 +273,15 @@ void SetCommonFieldVariables(
(*variables)["annotation_field_type"] = (*variables)["annotation_field_type"] =
std::string(FieldTypeName(descriptor->type())) + "_LIST"; std::string(FieldTypeName(descriptor->type())) + "_LIST";
if (descriptor->is_packed()) { if (descriptor->is_packed()) {
variables->emplace( (*variables)["annotation_field_type"] =
"annotation_field_type", (*variables)["annotation_field_type"] + "_PACKED";
absl::StrCat((*variables)["annotation_field_type"], "_PACKED"));
} }
} }
} }
void SetCommonOneofVariables( void SetCommonOneofVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, const OneofGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
(*variables)["oneof_name"] = info->name; (*variables)["oneof_name"] = info->name;
(*variables)["oneof_capitalized_name"] = info->capitalized_name; (*variables)["oneof_capitalized_name"] = info->capitalized_name;
(*variables)["oneof_index"] = (*variables)["oneof_index"] =
@ -296,10 +294,9 @@ void SetCommonOneofVariables(
info->name + "Case_ == " + absl::StrCat(descriptor->number()); info->name + "Case_ == " + absl::StrCat(descriptor->number());
} }
void PrintExtraFieldInfo( void PrintExtraFieldInfo(const std::map<std::string, std::string>& variables,
const absl::flat_hash_map<std::string, std::string>& variables, io::Printer* printer) {
io::Printer* printer) { const std::map<std::string, std::string>::const_iterator it =
const absl::flat_hash_map<std::string, std::string>::const_iterator it =
variables.find("disambiguated_reason"); variables.find("disambiguated_reason");
if (it != variables.end() && !it->second.empty()) { if (it != variables.end() && !it->second.empty()) {
printer->Print( printer->Print(

@ -43,7 +43,6 @@
#include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/port.h" #include "google/protobuf/port.h"
namespace google { namespace google {
@ -170,19 +169,18 @@ struct OneofGeneratorInfo {
}; };
// Set some common variables used in variable FieldGenerators. // Set some common variables used in variable FieldGenerators.
void SetCommonFieldVariables( void SetCommonFieldVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, const FieldGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables); std::map<std::string, std::string>* variables);
// Set some common oneof variables used in OneofFieldGenerators. // Set some common oneof variables used in OneofFieldGenerators.
void SetCommonOneofVariables( void SetCommonOneofVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, const OneofGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables); std::map<std::string, std::string>* variables);
// Print useful comments before a field's accessors. // Print useful comments before a field's accessors.
void PrintExtraFieldInfo( void PrintExtraFieldInfo(const std::map<std::string, std::string>& variables,
const absl::flat_hash_map<std::string, std::string>& variables, io::Printer* printer);
io::Printer* printer);
} // namespace java } // namespace java
} // namespace compiler } // namespace compiler

@ -84,10 +84,11 @@ void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,
printer->Print(ptemplate.c_str(), "annotation_file", annotation_file); printer->Print(ptemplate.c_str(), "annotation_file", annotation_file);
} }
void PrintEnumVerifierLogic( void PrintEnumVerifierLogic(io::Printer* printer,
io::Printer* printer, const FieldDescriptor* descriptor, const FieldDescriptor* descriptor,
const absl::flat_hash_map<std::string, std::string>& variables, const std::map<std::string, std::string>& variables,
const char* var_name, const char* terminating_string, bool enforce_lite) { const char* var_name,
const char* terminating_string, bool enforce_lite) {
std::string enum_verifier_string = std::string enum_verifier_string =
enforce_lite ? absl::StrCat(var_name, ".internalGetVerifier()") enforce_lite ? absl::StrCat(var_name, ".internalGetVerifier()")
: absl::StrCat( : absl::StrCat(

@ -74,10 +74,11 @@ void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$',
// If a GeneratedMessageLite contains non-lite enums, then its verifier // If a GeneratedMessageLite contains non-lite enums, then its verifier
// must be instantiated inline, rather than retrieved from the enum class. // must be instantiated inline, rather than retrieved from the enum class.
void PrintEnumVerifierLogic( void PrintEnumVerifierLogic(io::Printer* printer,
io::Printer* printer, const FieldDescriptor* descriptor, const FieldDescriptor* descriptor,
const absl::flat_hash_map<std::string, std::string>& variables, const std::map<std::string, std::string>& variables,
const char* var_name, const char* terminating_string, bool enforce_lite); const char* var_name,
const char* terminating_string, bool enforce_lite);
// Converts a name to camel-case. If cap_first_letter is true, capitalize the // Converts a name to camel-case. If cap_first_letter is true, capitalize the
// first letter. // first letter.

@ -31,7 +31,6 @@
#include "google/protobuf/compiler/java/map_field.h" #include "google/protobuf/compiler/java/map_field.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
#include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/helpers.h"
@ -89,10 +88,10 @@ std::string WireType(const FieldDescriptor* field) {
std::string(FieldTypeName(field->type())); std::string(FieldTypeName(field->type()));
} }
void SetMessageVariables( void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int builderBitIndex, const FieldGeneratorInfo* info,
const FieldGeneratorInfo* info, Context* context, Context* context,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
ClassNameResolver* name_resolver = context->GetNameResolver(); ClassNameResolver* name_resolver = context->GetNameResolver();
@ -134,8 +133,8 @@ void SetMessageVariables(
if (valueJavaType == JAVATYPE_ENUM) { if (valueJavaType == JAVATYPE_ENUM) {
// We store enums as Integers internally. // We store enums as Integers internally.
(*variables)["value_type"] = "int"; (*variables)["value_type"] = "int";
variables->emplace("value_type_pass_through_nullness", (*variables)["value_type_pass_through_nullness"] =
(*variables)["value_type"]); (*variables)["value_type"];
(*variables)["boxed_value_type"] = "java.lang.Integer"; (*variables)["boxed_value_type"] = "java.lang.Integer";
(*variables)["value_wire_type"] = WireType(value); (*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] = (*variables)["value_default_value"] =
@ -144,15 +143,13 @@ void SetMessageVariables(
(*variables)["value_enum_type"] = TypeName(value, name_resolver, false); (*variables)["value_enum_type"] = TypeName(value, name_resolver, false);
variables->emplace( (*variables)["value_enum_type_pass_through_nullness"] =
"value_enum_type_pass_through_nullness", pass_through_nullness + (*variables)["value_enum_type"];
absl::StrCat(pass_through_nullness, (*variables)["value_enum_type"]));
if (SupportUnknownEnumValue(descriptor->file())) { if (SupportUnknownEnumValue(descriptor->file())) {
// Map unknown values to a special UNRECOGNIZED value if supported. // Map unknown values to a special UNRECOGNIZED value if supported.
variables->emplace( (*variables)["unrecognized_value"] =
"unrecognized_value", (*variables)["value_enum_type"] + ".UNRECOGNIZED";
absl::StrCat((*variables)["value_enum_type"], ".UNRECOGNIZED"));
} else { } else {
// Map unknown values to the default value if we don't have UNRECOGNIZED. // Map unknown values to the default value if we don't have UNRECOGNIZED.
(*variables)["unrecognized_value"] = (*variables)["unrecognized_value"] =
@ -161,36 +158,31 @@ void SetMessageVariables(
} else { } else {
(*variables)["value_type"] = TypeName(value, name_resolver, false); (*variables)["value_type"] = TypeName(value, name_resolver, false);
variables->emplace( (*variables)["value_type_pass_through_nullness"] =
"value_type_pass_through_nullness", (IsReferenceType(valueJavaType) ? pass_through_nullness : "") +
absl::StrCat( (*variables)["value_type"];
(IsReferenceType(valueJavaType) ? pass_through_nullness : ""),
(*variables)["value_type"]));
(*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true);
(*variables)["value_wire_type"] = WireType(value); (*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] = (*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver, context->options()); DefaultValue(value, true, name_resolver, context->options());
} }
variables->emplace("type_parameters", (*variables)["type_parameters"] =
absl::StrCat((*variables)["boxed_key_type"], ", ", (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"];
(*variables)["boxed_value_type"]));
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler // by the proto compiler
(*variables)["deprecation"] = (*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
variables->emplace( (*variables)["kt_deprecation"] =
"kt_deprecation",
descriptor->options().deprecated() descriptor->options().deprecated()
? absl::StrCat("@kotlin.Deprecated(message = \"Field ", ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
(*variables)["name"], " is deprecated\") ") " is deprecated\") "
: ""); : "";
(*variables)["on_changed"] = "onChanged();"; (*variables)["on_changed"] = "onChanged();";
variables->emplace("default_entry", (*variables)["default_entry"] =
absl::StrCat((*variables)["capitalized_name"], (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry";
"DefaultEntryHolder.defaultEntry")); (*variables)["map_field_parameter"] = (*variables)["default_entry"];
variables->emplace("map_field_parameter", (*variables)["default_entry"]);
(*variables)["descriptor"] = (*variables)["descriptor"] =
name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" + name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" +
UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, "; UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, ";

@ -68,7 +68,7 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator {
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
Context* context_; Context* context_;
void GenerateMapGetters(io::Printer* printer) const; void GenerateMapGetters(io::Printer* printer) const;

@ -90,10 +90,10 @@ std::string WireType(const FieldDescriptor* field) {
std::string(FieldTypeName(field->type())); std::string(FieldTypeName(field->type()));
} }
void SetMessageVariables( void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int builderBitIndex, const FieldGeneratorInfo* info,
const FieldGeneratorInfo* info, Context* context, Context* context,
absl::flat_hash_map<std::string, std::string>* variables) { std::map<std::string, std::string>* variables) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
ClassNameResolver* name_resolver = context->GetNameResolver(); ClassNameResolver* name_resolver = context->GetNameResolver();

@ -61,7 +61,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator {
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
Context* context_; Context* context_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };

@ -115,7 +115,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables(
// the outermost class in the file. This way, they will be initialized in // the outermost class in the file. This way, they will be initialized in
// a deterministic order. // a deterministic order.
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
vars["index"] = absl::StrCat(descriptor_->index()); vars["index"] = absl::StrCat(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
@ -159,7 +159,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables(
int ImmutableMessageGenerator::GenerateStaticVariableInitializers( int ImmutableMessageGenerator::GenerateStaticVariableInitializers(
io::Printer* printer) { io::Printer* printer) {
int bytecode_estimate = 0; int bytecode_estimate = 0;
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
vars["index"] = absl::StrCat(descriptor_->index()); vars["index"] = absl::StrCat(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
@ -196,7 +196,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers(
void ImmutableMessageGenerator::GenerateFieldAccessorTable( void ImmutableMessageGenerator::GenerateFieldAccessorTable(
io::Printer* printer, int* bytecode_estimate) { io::Printer* printer, int* bytecode_estimate) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) { if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) {
// We can only make these package-private since the classes that use them // We can only make these package-private since the classes that use them
@ -314,7 +314,7 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
void ImmutableMessageGenerator::Generate(io::Printer* printer) { void ImmutableMessageGenerator::Generate(io::Printer* printer) {
bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
absl::flat_hash_map<std::string, std::string> variables; std::map<std::string, std::string> variables;
variables["static"] = is_own_file ? "" : "static "; variables["static"] = is_own_file ? "" : "static ";
variables["classname"] = descriptor_->name(); variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
@ -426,7 +426,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
} }
// oneof // oneof
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
for (auto oneof : oneofs_) { for (auto oneof : oneofs_) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] = vars["oneof_capitalized_name"] =

@ -126,7 +126,7 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
} }
// oneof // oneof
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
for (auto oneof : oneofs_) { for (auto oneof : oneofs_) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] = vars["oneof_capitalized_name"] =

@ -82,7 +82,7 @@ MessageBuilderLiteGenerator::~MessageBuilderLiteGenerator() {}
void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { void MessageBuilderLiteGenerator::Generate(io::Printer* printer) {
WriteMessageDocComment(printer, descriptor_); WriteMessageDocComment(printer, descriptor_);
absl::flat_hash_map<std::string, std::string> vars = { std::map<std::string, std::string> vars = {
{"{", ""}, {"{", ""},
{"}", ""}, {"}", ""},
{"classname", name_resolver_->GetImmutableClassName(descriptor_)}, {"classname", name_resolver_->GetImmutableClassName(descriptor_)},

@ -39,7 +39,6 @@
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/context.h"
#include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/doc_comment.h"
#include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/helpers.h"
@ -56,16 +55,16 @@ namespace java {
namespace { namespace {
void SetMessageVariables( void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int builderBitIndex, const FieldGeneratorInfo* info,
const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, ClassNameResolver* name_resolver,
absl::flat_hash_map<std::string, std::string>* variables, std::map<std::string, std::string>* variables,
Context* context) { Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] = (*variables)["type"] =
name_resolver->GetImmutableClassName(descriptor->message_type()); name_resolver->GetImmutableClassName(descriptor->message_type());
variables->emplace("kt_type", EscapeKotlinKeywords((*variables)["type"])); (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]);
(*variables)["mutable_type"] = (*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->message_type()); name_resolver->GetMutableClassName(descriptor->message_type());
(*variables)["group_or_message"] = (*variables)["group_or_message"] =
@ -75,12 +74,11 @@ void SetMessageVariables(
// by the proto compiler // by the proto compiler
(*variables)["deprecation"] = (*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
variables->emplace( (*variables)["kt_deprecation"] =
"kt_deprecation",
descriptor->options().deprecated() descriptor->options().deprecated()
? absl::StrCat("@kotlin.Deprecated(message = \"Field ", ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
(*variables)["name"], " is deprecated\") ") " is deprecated\") "
: ""); : "";
(*variables)["on_changed"] = "onChanged();"; (*variables)["on_changed"] = "onChanged();";
(*variables)["ver"] = GeneratedCodeVersionSuffix(); (*variables)["ver"] = GeneratedCodeVersionSuffix();
(*variables)["get_parser"] = (*variables)["get_parser"] =
@ -108,8 +106,8 @@ void SetMessageVariables(
(*variables)["set_has_field_bit_builder"] = ""; (*variables)["set_has_field_bit_builder"] = "";
(*variables)["clear_has_field_bit_builder"] = ""; (*variables)["clear_has_field_bit_builder"] = "";
variables->emplace("is_field_present_message", (*variables)["is_field_present_message"] =
absl::StrCat((*variables)["name"], "_ != null")); (*variables)["name"] + "_ != null";
} }
// For repeated builders, one bit is used for whether the array is immutable. // For repeated builders, one bit is used for whether the array is immutable.

@ -92,7 +92,7 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
Context* context_; Context* context_;
@ -165,7 +165,7 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
void PrintNestedBuilderCondition(io::Printer* printer, void PrintNestedBuilderCondition(io::Printer* printer,

@ -56,16 +56,16 @@ namespace java {
namespace { namespace {
void SetMessageVariables( void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int builderBitIndex, const FieldGeneratorInfo* info,
const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, ClassNameResolver* name_resolver,
absl::flat_hash_map<std::string, std::string>* variables, std::map<std::string, std::string>* variables,
Context* context) { Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] = (*variables)["type"] =
name_resolver->GetImmutableClassName(descriptor->message_type()); name_resolver->GetImmutableClassName(descriptor->message_type());
variables->emplace("kt_type", EscapeKotlinKeywords((*variables)["type"])); (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]);
(*variables)["mutable_type"] = (*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->message_type()); name_resolver->GetMutableClassName(descriptor->message_type());
(*variables)["group_or_message"] = (*variables)["group_or_message"] =
@ -75,12 +75,11 @@ void SetMessageVariables(
// by the proto compiler // by the proto compiler
(*variables)["deprecation"] = (*variables)["deprecation"] =
descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
variables->emplace( (*variables)["kt_deprecation"] =
"kt_deprecation",
descriptor->options().deprecated() descriptor->options().deprecated()
? absl::StrCat("@kotlin.Deprecated(message = \"Field ", ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
(*variables)["name"], " is deprecated\") ") " is deprecated\") "
: ""); : "";
(*variables)["required"] = descriptor->is_required() ? "true" : "false"; (*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (HasHasbit(descriptor)) { if (HasHasbit(descriptor)) {
@ -99,7 +98,7 @@ void SetMessageVariables(
(*variables)["clear_has_field_bit_message"] = ""; (*variables)["clear_has_field_bit_message"] = "";
(*variables)["is_field_present_message"] = (*variables)["is_field_present_message"] =
absl::StrCat((*variables)["name"], "_ != null"); (*variables)["name"] + "_ != null";
} }
(*variables)["get_has_field_bit_from_local"] = (*variables)["get_has_field_bit_from_local"] =

@ -83,7 +83,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
const int messageBitIndex_; const int messageBitIndex_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
Context* context_; Context* context_;
@ -136,7 +136,7 @@ class RepeatedImmutableMessageFieldLiteGenerator
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
Context* context_; Context* context_;
}; };

@ -117,7 +117,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
MaybePrintGeneratedAnnotation(context_, printer, descriptor_, MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true, "OrBuilder"); /* immutable = */ true, "OrBuilder");
absl::flat_hash_map<std::string, std::string> variables = { std::map<std::string, std::string> variables = {
{"{", ""}, {"{", ""},
{"}", ""}, {"}", ""},
{"deprecation", {"deprecation",
@ -173,8 +173,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
absl::flat_hash_map<std::string, std::string> variables = {{"{", ""}, std::map<std::string, std::string> variables = {{"{", ""}, {"}", ""}};
{"}", ""}};
variables["static"] = is_own_file ? " " : " static "; variables["static"] = is_own_file ? " " : " static ";
variables["classname"] = descriptor_->name(); variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
@ -243,7 +242,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
} }
// oneof // oneof
absl::flat_hash_map<std::string, std::string> vars = {{"{", ""}, {"}", ""}}; std::map<std::string, std::string> vars = {{"{", ""}, {"}", ""}};
for (auto oneof : oneofs_) { for (auto oneof : oneofs_) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] = vars["oneof_capitalized_name"] =

@ -57,55 +57,54 @@ using internal::WireFormat;
namespace { namespace {
void SetPrimitiveVariables( void SetPrimitiveVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, const FieldGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables, ClassNameResolver* name_resolver,
Context* context) { std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
JavaType javaType = GetJavaType(descriptor); JavaType javaType = GetJavaType(descriptor);
(*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["type"] = PrimitiveTypeName(javaType);
(*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType);
(*variables)["kt_type"] = KotlinTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType);
variables->emplace("field_type", (*variables)["type"]); (*variables)["field_type"] = (*variables)["type"];
std::string name = (*variables)["name"];
if (javaType == JAVATYPE_BOOLEAN || javaType == JAVATYPE_DOUBLE || if (javaType == JAVATYPE_BOOLEAN || javaType == JAVATYPE_DOUBLE ||
javaType == JAVATYPE_FLOAT || javaType == JAVATYPE_INT || javaType == JAVATYPE_FLOAT || javaType == JAVATYPE_INT ||
javaType == JAVATYPE_LONG) { javaType == JAVATYPE_LONG) {
std::string capitalized_type = UnderscoresToCamelCase( std::string capitalized_type = UnderscoresToCamelCase(
PrimitiveTypeName(javaType), /*cap_first_letter=*/true); PrimitiveTypeName(javaType), /*cap_first_letter=*/true);
(*variables)["field_list_type"] = (*variables)["field_list_type"] =
absl::StrCat("com.google.protobuf.Internal.", capitalized_type, "List"); "com.google.protobuf.Internal." + capitalized_type + "List";
(*variables)["empty_list"] = (*variables)["empty_list"] = "empty" + capitalized_type + "List()";
absl::StrCat("empty", capitalized_type, "List()"); (*variables)["create_list"] = "new" + capitalized_type + "List()";
(*variables)["create_list"] =
absl::StrCat("new", capitalized_type, "List()");
(*variables)["mutable_copy_list"] = (*variables)["mutable_copy_list"] =
absl::StrCat("mutableCopy(", name, "_)"); "mutableCopy(" + (*variables)["name"] + "_)";
(*variables)["name_make_immutable"] = (*variables)["name_make_immutable"] =
absl::StrCat(name, "_.makeImmutable()"); (*variables)["name"] + "_.makeImmutable()";
(*variables)["repeated_get"] = (*variables)["repeated_get"] =
absl::StrCat(name, "_.get", capitalized_type); (*variables)["name"] + "_.get" + capitalized_type;
(*variables)["repeated_add"] = (*variables)["repeated_add"] =
absl::StrCat(name, "_.add", capitalized_type); (*variables)["name"] + "_.add" + capitalized_type;
(*variables)["repeated_set"] = (*variables)["repeated_set"] =
absl::StrCat(name, "_.set", capitalized_type); (*variables)["name"] + "_.set" + capitalized_type;
} else { } else {
std::string boxed_type = (*variables)["boxed_type"];
(*variables)["field_list_type"] = (*variables)["field_list_type"] =
absl::StrCat("java.util.List<", boxed_type, ">"); "java.util.List<" + (*variables)["boxed_type"] + ">";
(*variables)["create_list"] = (*variables)["create_list"] =
absl::StrCat("new java.util.ArrayList<", boxed_type, ">()"); "new java.util.ArrayList<" + (*variables)["boxed_type"] + ">()";
(*variables)["mutable_copy_list"] = (*variables)["mutable_copy_list"] = "new java.util.ArrayList<" +
absl::StrCat("new java.util.ArrayList<", boxed_type, ">(", name, "_)"); (*variables)["boxed_type"] + ">(" +
(*variables)["name"] + "_)";
(*variables)["empty_list"] = "java.util.Collections.emptyList()"; (*variables)["empty_list"] = "java.util.Collections.emptyList()";
(*variables)["name_make_immutable"] = absl::StrCat( (*variables)["name_make_immutable"] =
name, "_ = java.util.Collections.unmodifiableList(", name, "_)"); (*variables)["name"] + "_ = java.util.Collections.unmodifiableList(" +
(*variables)["repeated_get"] = absl::StrCat(name, "_.get"); (*variables)["name"] + "_)";
(*variables)["repeated_add"] = absl::StrCat(name, "_.add"); (*variables)["repeated_get"] = (*variables)["name"] + "_.get";
(*variables)["repeated_set"] = absl::StrCat(name, "_.set"); (*variables)["repeated_add"] = (*variables)["name"] + "_.add";
(*variables)["repeated_set"] = (*variables)["name"] + "_.set";
} }
(*variables)["default"] = (*variables)["default"] =
@ -135,8 +134,8 @@ void SetPrimitiveVariables(
descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
(*variables)["kt_deprecation"] = (*variables)["kt_deprecation"] =
descriptor->options().deprecated() descriptor->options().deprecated()
? absl::StrCat("@kotlin.Deprecated(message = \"Field ", name, ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
" is deprecated\") ") " is deprecated\") "
: ""; : "";
int fixed_size = FixedSize(GetType(descriptor)); int fixed_size = FixedSize(GetType(descriptor));
if (fixed_size != -1) { if (fixed_size != -1) {
@ -166,20 +165,21 @@ void SetPrimitiveVariables(
switch (descriptor->type()) { switch (descriptor->type()) {
case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_BYTES:
(*variables)["is_field_present_message"] = (*variables)["is_field_present_message"] =
absl::StrCat("!", name, "_.isEmpty()"); "!" + (*variables)["name"] + "_.isEmpty()";
break; break;
case FieldDescriptor::TYPE_FLOAT: case FieldDescriptor::TYPE_FLOAT:
(*variables)["is_field_present_message"] = (*variables)["is_field_present_message"] =
absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0"); "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] +
"_) != 0";
break; break;
case FieldDescriptor::TYPE_DOUBLE: case FieldDescriptor::TYPE_DOUBLE:
(*variables)["is_field_present_message"] = absl::StrCat( (*variables)["is_field_present_message"] =
"java.lang.Double.doubleToRawLongBits(", name, "_) != 0"); "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] +
"_) != 0";
break; break;
default: default:
variables->emplace( (*variables)["is_field_present_message"] =
"is_field_present_message", (*variables)["name"] + "_ != " + (*variables)["default"];
absl::StrCat(name, "_ != ", (*variables)["default"]));
break; break;
} }
} }

@ -92,7 +92,7 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };
@ -155,7 +155,7 @@ class RepeatedImmutablePrimitiveFieldGenerator
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };

@ -66,17 +66,18 @@ bool EnableExperimentalRuntimeForLite() {
#endif // !PROTOBUF_EXPERIMENT #endif // !PROTOBUF_EXPERIMENT
} }
void SetPrimitiveVariables( void SetPrimitiveVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, const FieldGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables, ClassNameResolver* name_resolver,
Context* context) { std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
JavaType javaType = GetJavaType(descriptor); JavaType javaType = GetJavaType(descriptor);
(*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["type"] = PrimitiveTypeName(javaType);
(*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType);
(*variables)["kt_type"] = KotlinTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType);
variables->emplace("field_type", (*variables)["type"]); (*variables)["field_type"] = (*variables)["type"];
(*variables)["default"] = (*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options()); ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["capitalized_type"] = GetCapitalizedType( (*variables)["capitalized_type"] = GetCapitalizedType(
@ -89,47 +90,43 @@ void SetPrimitiveVariables(
std::string capitalized_type = UnderscoresToCamelCase( std::string capitalized_type = UnderscoresToCamelCase(
PrimitiveTypeName(javaType), true /* cap_next_letter */); PrimitiveTypeName(javaType), true /* cap_next_letter */);
std::string name = (*variables)["name"];
switch (javaType) { switch (javaType) {
case JAVATYPE_INT: case JAVATYPE_INT:
case JAVATYPE_LONG: case JAVATYPE_LONG:
case JAVATYPE_FLOAT: case JAVATYPE_FLOAT:
case JAVATYPE_DOUBLE: case JAVATYPE_DOUBLE:
case JAVATYPE_BOOLEAN: case JAVATYPE_BOOLEAN:
(*variables)["field_list_type"] = absl::StrCat( (*variables)["field_list_type"] =
"com.google.protobuf.Internal.", capitalized_type, "List"); "com.google.protobuf.Internal." + capitalized_type + "List";
(*variables)["empty_list"] = (*variables)["empty_list"] = "empty" + capitalized_type + "List()";
absl::StrCat("empty", capitalized_type, "List()");
(*variables)["make_name_unmodifiable"] = (*variables)["make_name_unmodifiable"] =
absl::StrCat(name, "_.makeImmutable()"); (*variables)["name"] + "_.makeImmutable()";
(*variables)["repeated_get"] = (*variables)["repeated_get"] =
absl::StrCat(name, "_.get", capitalized_type); (*variables)["name"] + "_.get" + capitalized_type;
(*variables)["repeated_add"] = (*variables)["repeated_add"] =
absl::StrCat(name, "_.add", capitalized_type); (*variables)["name"] + "_.add" + capitalized_type;
(*variables)["repeated_set"] = (*variables)["repeated_set"] =
absl::StrCat(name, "_.set", capitalized_type); (*variables)["name"] + "_.set" + capitalized_type;
(*variables)["visit_type"] = capitalized_type; (*variables)["visit_type"] = capitalized_type;
(*variables)["visit_type_list"] = (*variables)["visit_type_list"] = "visit" + capitalized_type + "List";
absl::StrCat("visit", capitalized_type, "List");
break; break;
default: default:
variables->emplace( (*variables)["field_list_type"] =
"field_list_type", "com.google.protobuf.Internal.ProtobufList<" +
absl::StrCat("com.google.protobuf.Internal.ProtobufList<", (*variables)["boxed_type"] + ">";
(*variables)["boxed_type"], ">"));
(*variables)["empty_list"] = "emptyProtobufList()"; (*variables)["empty_list"] = "emptyProtobufList()";
(*variables)["make_name_unmodifiable"] = (*variables)["make_name_unmodifiable"] =
absl::StrCat(name, "_.makeImmutable()"); (*variables)["name"] + "_.makeImmutable()";
(*variables)["repeated_get"] = absl::StrCat(name, "_.get"); (*variables)["repeated_get"] = (*variables)["name"] + "_.get";
(*variables)["repeated_add"] = absl::StrCat(name, "_.add"); (*variables)["repeated_add"] = (*variables)["name"] + "_.add";
(*variables)["repeated_set"] = absl::StrCat(name, "_.set"); (*variables)["repeated_set"] = (*variables)["name"] + "_.set";
(*variables)["visit_type"] = "ByteString"; (*variables)["visit_type"] = "ByteString";
(*variables)["visit_type_list"] = "visitList"; (*variables)["visit_type_list"] = "visitList";
} }
if (javaType == JAVATYPE_BYTES) { if (javaType == JAVATYPE_BYTES) {
(*variables)["bytes_default"] = (*variables)["bytes_default"] =
absl::AsciiStrToUpper(name) + "_DEFAULT_VALUE"; absl::AsciiStrToUpper((*variables)["name"]) + "_DEFAULT_VALUE";
} }
if (IsReferenceType(javaType)) { if (IsReferenceType(javaType)) {
@ -146,8 +143,8 @@ void SetPrimitiveVariables(
descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
(*variables)["kt_deprecation"] = (*variables)["kt_deprecation"] =
descriptor->options().deprecated() descriptor->options().deprecated()
? absl::StrCat("@kotlin.Deprecated(message = \"Field ", name, ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] +
" is deprecated\") ") " is deprecated\") "
: ""; : "";
int fixed_size = FixedSize(GetType(descriptor)); int fixed_size = FixedSize(GetType(descriptor));
if (fixed_size != -1) { if (fixed_size != -1) {
@ -172,20 +169,21 @@ void SetPrimitiveVariables(
switch (descriptor->type()) { switch (descriptor->type()) {
case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_BYTES:
(*variables)["is_field_present_message"] = (*variables)["is_field_present_message"] =
absl::StrCat("!", name, "_.isEmpty()"); "!" + (*variables)["name"] + "_.isEmpty()";
break; break;
case FieldDescriptor::TYPE_FLOAT: case FieldDescriptor::TYPE_FLOAT:
(*variables)["is_field_present_message"] = (*variables)["is_field_present_message"] =
absl::StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0"); "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] +
"_) != 0";
break; break;
case FieldDescriptor::TYPE_DOUBLE: case FieldDescriptor::TYPE_DOUBLE:
(*variables)["is_field_present_message"] = absl::StrCat( (*variables)["is_field_present_message"] =
"java.lang.Double.doubleToRawLongBits(", name, "_) != 0"); "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] +
"_) != 0";
break; break;
default: default:
variables->emplace( (*variables)["is_field_present_message"] =
"is_field_present_message", (*variables)["name"] + "_ != " + (*variables)["default"];
absl::StrCat(name, "_ != " + (*variables)["default"]));
break; break;
} }
} }
@ -195,8 +193,7 @@ void SetPrimitiveVariables(
(*variables)["set_has_field_bit_to_local"] = (*variables)["set_has_field_bit_to_local"] =
GenerateSetBitToLocal(messageBitIndex); GenerateSetBitToLocal(messageBitIndex);
// Annotations often use { and } variables to denote ranges. // Annotations often use { and } variables to denote ranges.
(*variables)["{"] = ""; (*variables)["{"] = (*variables)["}"] = "";
(*variables)["}"] = "";
} }
} // namespace } // namespace

@ -83,7 +83,7 @@ class ImmutablePrimitiveFieldLiteGenerator
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
const int messageBitIndex_; const int messageBitIndex_;
Context* context_; Context* context_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
@ -133,7 +133,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
Context* context_; Context* context_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };

@ -215,7 +215,7 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) { for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i); const MethodDescriptor* method = descriptor_->method(i);
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["index"] = absl::StrCat(i); vars["index"] = absl::StrCat(i);
vars["method"] = UnderscoresToCamelCase(method); vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
@ -262,7 +262,7 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod(
for (int i = 0; i < descriptor_->method_count(); i++) { for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i); const MethodDescriptor* method = descriptor_->method(i);
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["index"] = absl::StrCat(i); vars["index"] = absl::StrCat(i);
vars["method"] = UnderscoresToCamelCase(method); vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
@ -307,7 +307,7 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
for (int i = 0; i < descriptor_->method_count(); i++) { for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i); const MethodDescriptor* method = descriptor_->method(i);
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["index"] = absl::StrCat(i); vars["index"] = absl::StrCat(i);
vars["type"] = vars["type"] =
(which == REQUEST) (which == REQUEST)
@ -362,7 +362,7 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
printer->Print(" {\n"); printer->Print(" {\n");
printer->Indent(); printer->Indent();
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["index"] = absl::StrCat(i); vars["index"] = absl::StrCat(i);
vars["output"] = GetOutput(method); vars["output"] = GetOutput(method);
printer->Print(vars, printer->Print(vars,
@ -426,7 +426,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
printer->Print(" {\n"); printer->Print(" {\n");
printer->Indent(); printer->Indent();
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["index"] = absl::StrCat(i); vars["index"] = absl::StrCat(i);
vars["output"] = GetOutput(method); vars["output"] = GetOutput(method);
printer->Print(vars, printer->Print(vars,
@ -449,7 +449,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
void ImmutableServiceGenerator::GenerateMethodSignature( void ImmutableServiceGenerator::GenerateMethodSignature(
io::Printer* printer, const MethodDescriptor* method, io::Printer* printer, const MethodDescriptor* method,
IsAbstract is_abstract) { IsAbstract is_abstract) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["name"] = UnderscoresToCamelCase(method); vars["name"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method); vars["output"] = GetOutput(method);
@ -463,7 +463,7 @@ void ImmutableServiceGenerator::GenerateMethodSignature(
void ImmutableServiceGenerator::GenerateBlockingMethodSignature( void ImmutableServiceGenerator::GenerateBlockingMethodSignature(
io::Printer* printer, const MethodDescriptor* method) { io::Printer* printer, const MethodDescriptor* method) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["method"] = UnderscoresToCamelCase(method); vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method); vars["output"] = GetOutput(method);

@ -59,11 +59,12 @@ using internal::WireFormatLite;
namespace { namespace {
void SetPrimitiveVariables( void SetPrimitiveVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, const FieldGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables, ClassNameResolver* name_resolver,
Context* context) { std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
(*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY";

@ -91,7 +91,7 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };
@ -152,7 +152,7 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator {
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
}; };

@ -59,11 +59,12 @@ using internal::WireFormatLite;
namespace { namespace {
void SetPrimitiveVariables( void SetPrimitiveVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, const FieldGeneratorInfo* info,
absl::flat_hash_map<std::string, std::string>* variables, ClassNameResolver* name_resolver,
Context* context) { std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables); SetCommonFieldVariables(descriptor, info, variables);
(*variables)["empty_list"] = (*variables)["empty_list"] =

@ -84,7 +84,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected: protected:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
const int messageBitIndex_; const int messageBitIndex_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
Context* context_; Context* context_;
@ -133,7 +133,7 @@ class RepeatedImmutableStringFieldLiteGenerator
private: private:
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_; ClassNameResolver* name_resolver_;
Context* context_; Context* context_;
}; };

@ -34,7 +34,6 @@
#include <set> #include <set>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/helpers.h"
#include "google/protobuf/compiler/objectivec/names.h" #include "google/protobuf/compiler/objectivec/names.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
@ -46,9 +45,8 @@ namespace objectivec {
namespace { namespace {
void SetEnumVariables( void SetEnumVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables) {
absl::flat_hash_map<std::string, std::string>* variables) {
std::string type = EnumName(descriptor->enum_type()); std::string type = EnumName(descriptor->enum_type());
(*variables)["storage_type"] = type; (*variables)["storage_type"] = type;
// For non repeated fields, if it was defined in a different file, the // For non repeated fields, if it was defined in a different file, the

@ -37,7 +37,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/helpers.h"
#include "google/protobuf/compiler/objectivec/names.h" #include "google/protobuf/compiler/objectivec/names.h"
@ -65,7 +64,7 @@ ExtensionGenerator::ExtensionGenerator(const std::string& root_class_name,
} }
void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["method_name"] = method_name_; vars["method_name"] = method_name_;
if (IsRetainedName(method_name_)) { if (IsRetainedName(method_name_)) {
vars["storage_attribute"] = " NS_RETURNS_NOT_RETAINED"; vars["storage_attribute"] = " NS_RETURNS_NOT_RETAINED";
@ -92,7 +91,7 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) {
void ExtensionGenerator::GenerateStaticVariablesInitialization( void ExtensionGenerator::GenerateStaticVariablesInitialization(
io::Printer* printer) { io::Printer* printer) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["root_class_and_method_name"] = root_class_and_method_name_; vars["root_class_and_method_name"] = root_class_and_method_name_;
const std::string containing_type = ClassName(descriptor_->containing_type()); const std::string containing_type = ClassName(descriptor_->containing_type());
vars["extended_type"] = ObjCClass(containing_type); vars["extended_type"] = ObjCClass(containing_type);

@ -37,7 +37,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/objectivec/enum_field.h" #include "google/protobuf/compiler/objectivec/enum_field.h"
#include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/helpers.h"
@ -54,9 +53,8 @@ namespace objectivec {
namespace { namespace {
void SetCommonFieldVariables( void SetCommonFieldVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables) {
absl::flat_hash_map<std::string, std::string>* variables) {
std::string camel_case_name = FieldName(descriptor); std::string camel_case_name = FieldName(descriptor);
std::string raw_field_name; std::string raw_field_name;
if (descriptor->type() == FieldDescriptor::TYPE_GROUP) { if (descriptor->type() == FieldDescriptor::TYPE_GROUP) {

@ -37,7 +37,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
@ -105,7 +104,7 @@ class FieldGenerator {
bool WantsHasProperty() const; bool WantsHasProperty() const;
const FieldDescriptor* descriptor_; const FieldDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };
class SingleFieldGenerator : public FieldGenerator { class SingleFieldGenerator : public FieldGenerator {

@ -626,7 +626,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
// File descriptor only needed if there are messages to use it. // File descriptor only needed if there are messages to use it.
if (!message_generators_.empty()) { if (!message_generators_.empty()) {
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["root_class_name"] = root_class_name_; vars["root_class_name"] = root_class_name_;
vars["package"] = file_->package(); vars["package"] = file_->package();
vars["objc_prefix"] = FileClassPrefix(file_); vars["objc_prefix"] = FileClassPrefix(file_);

@ -36,7 +36,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "google/protobuf/compiler/objectivec/line_consumer.h" #include "google/protobuf/compiler/objectivec/line_consumer.h"
@ -56,14 +55,13 @@ namespace {
class ProtoFrameworkCollector : public LineConsumer { class ProtoFrameworkCollector : public LineConsumer {
public: public:
explicit ProtoFrameworkCollector( explicit ProtoFrameworkCollector(
absl::flat_hash_map<std::string, std::string>* std::map<std::string, std::string>* inout_proto_file_to_framework_name)
inout_proto_file_to_framework_name)
: map_(inout_proto_file_to_framework_name) {} : map_(inout_proto_file_to_framework_name) {}
bool ConsumeLine(absl::string_view line, std::string* out_error) override; bool ConsumeLine(absl::string_view line, std::string* out_error) override;
private: private:
absl::flat_hash_map<std::string, std::string>* map_; std::map<std::string, std::string>* map_;
}; };
bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line, bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line,
@ -90,7 +88,7 @@ bool ProtoFrameworkCollector::ConsumeLine(absl::string_view line,
absl::string_view proto_file = absl::StripAsciiWhitespace( absl::string_view proto_file = absl::StripAsciiWhitespace(
proto_file_list.substr(start, offset - start)); proto_file_list.substr(start, offset - start));
if (!proto_file.empty()) { if (!proto_file.empty()) {
absl::flat_hash_map<std::string, std::string>::iterator existing_entry = std::map<std::string, std::string>::iterator existing_entry =
map_->find(std::string(proto_file)); map_->find(std::string(proto_file));
if (existing_entry != map_->end()) { if (existing_entry != map_->end()) {
std::cerr << "warning: duplicate proto file reference, replacing " std::cerr << "warning: duplicate proto file reference, replacing "
@ -149,7 +147,7 @@ void ImportWriter::AddFile(const FileDescriptor* file,
ParseFrameworkMappings(); ParseFrameworkMappings();
} }
absl::flat_hash_map<std::string, std::string>::iterator proto_lookup = std::map<std::string, std::string>::iterator proto_lookup =
proto_file_to_framework_name_.find(file->name()); proto_file_to_framework_name_.find(file->name());
if (proto_lookup != proto_file_to_framework_name_.end()) { if (proto_lookup != proto_file_to_framework_name_.end()) {
other_framework_imports_.push_back( other_framework_imports_.push_back(

@ -35,7 +35,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
@ -69,7 +68,7 @@ class ImportWriter {
const std::string named_framework_to_proto_path_mappings_path_; const std::string named_framework_to_proto_path_mappings_path_;
const std::string runtime_import_prefix_; const std::string runtime_import_prefix_;
const bool include_wkt_imports_; const bool include_wkt_imports_;
absl::flat_hash_map<std::string, std::string> proto_file_to_framework_name_; std::map<std::string, std::string> proto_file_to_framework_name_;
bool need_to_parse_mapping_file_; bool need_to_parse_mapping_file_;
std::vector<std::string> protobuf_imports_; std::vector<std::string> protobuf_imports_;

@ -39,7 +39,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/objectivec/enum.h" #include "google/protobuf/compiler/objectivec/enum.h"
@ -518,7 +517,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
printer->Outdent(); printer->Outdent();
} }
absl::flat_hash_map<std::string, std::string> vars; std::map<std::string, std::string> vars;
vars["classname"] = class_name_; vars["classname"] = class_name_;
vars["rootclassname"] = root_classname_; vars["rootclassname"] = root_classname_;
vars["fields"] = has_fields ? "fields" : "NULL"; vars["fields"] = has_fields ? "fields" : "NULL";

@ -34,7 +34,6 @@
#include <set> #include <set>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/helpers.h"
#include "google/protobuf/compiler/objectivec/names.h" #include "google/protobuf/compiler/objectivec/names.h"
@ -45,9 +44,8 @@ namespace objectivec {
namespace { namespace {
void SetMessageVariables( void SetMessageVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables) {
absl::flat_hash_map<std::string, std::string>* variables) {
const std::string& message_type = ClassName(descriptor->message_type()); const std::string& message_type = ClassName(descriptor->message_type());
const std::string& containing_class = const std::string& containing_class =
ClassName(descriptor->containing_type()); ClassName(descriptor->containing_type());

@ -41,7 +41,6 @@
#include <vector> #include <vector>
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
@ -84,16 +83,16 @@ class SimpleLineCollector : public LineConsumer {
class PackageToPrefixesCollector : public LineConsumer { class PackageToPrefixesCollector : public LineConsumer {
public: public:
PackageToPrefixesCollector(const std::string& usage, PackageToPrefixesCollector(
absl::flat_hash_map<std::string, std::string>* const std::string& usage,
inout_package_to_prefix_map) std::map<std::string, std::string>* inout_package_to_prefix_map)
: usage_(usage), prefix_map_(inout_package_to_prefix_map) {} : usage_(usage), prefix_map_(inout_package_to_prefix_map) {}
bool ConsumeLine(absl::string_view line, std::string* out_error) override; bool ConsumeLine(absl::string_view line, std::string* out_error) override;
private: private:
const std::string usage_; const std::string usage_;
absl::flat_hash_map<std::string, std::string>* prefix_map_; std::map<std::string, std::string>* prefix_map_;
}; };
class PrefixModeStorage { class PrefixModeStorage {
@ -130,7 +129,7 @@ class PrefixModeStorage {
private: private:
bool use_package_name_; bool use_package_name_;
absl::flat_hash_map<std::string, std::string> package_to_prefix_map_; std::map<std::string, std::string> package_to_prefix_map_;
std::string package_to_prefix_mappings_path_; std::string package_to_prefix_mappings_path_;
std::string exception_path_; std::string exception_path_;
std::string forced_prefix_; std::string forced_prefix_;
@ -188,7 +187,7 @@ std::string PrefixModeStorage::prefix_from_proto_package_mappings(
const std::string lookup_key = const std::string lookup_key =
package.empty() ? no_package_prefix + file->name() : package; package.empty() ? no_package_prefix + file->name() : package;
absl::flat_hash_map<std::string, std::string>::const_iterator prefix_lookup = std::map<std::string, std::string>::const_iterator prefix_lookup =
package_to_prefix_map_.find(lookup_key); package_to_prefix_map_.find(lookup_key);
if (prefix_lookup != package_to_prefix_map_.end()) { if (prefix_lookup != package_to_prefix_map_.end()) {
@ -1022,10 +1021,9 @@ bool PackageToPrefixesCollector::ConsumeLine(absl::string_view line,
return true; return true;
} }
bool LoadExpectedPackagePrefixes( bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path,
const std::string& expected_prefixes_path, std::map<std::string, std::string>* prefix_map,
absl::flat_hash_map<std::string, std::string>* prefix_map, std::string* out_error) {
std::string* out_error) {
if (expected_prefixes_path.empty()) { if (expected_prefixes_path.empty()) {
return true; return true;
} }
@ -1036,8 +1034,7 @@ bool LoadExpectedPackagePrefixes(
bool ValidateObjCClassPrefix( bool ValidateObjCClassPrefix(
const FileDescriptor* file, const std::string& expected_prefixes_path, const FileDescriptor* file, const std::string& expected_prefixes_path,
const absl::flat_hash_map<std::string, std::string>& const std::map<std::string, std::string>& expected_package_prefixes,
expected_package_prefixes,
bool prefixes_must_be_registered, bool require_prefixes, bool prefixes_must_be_registered, bool require_prefixes,
std::string* out_error) { std::string* out_error) {
// Reminder: An explicit prefix option of "" is valid in case the default // Reminder: An explicit prefix option of "" is valid in case the default
@ -1060,7 +1057,7 @@ bool ValidateObjCClassPrefix(
// Check: Error - See if there was an expected prefix for the package and // Check: Error - See if there was an expected prefix for the package and
// report if it doesn't match (wrong or missing). // report if it doesn't match (wrong or missing).
absl::flat_hash_map<std::string, std::string>::const_iterator package_match = std::map<std::string, std::string>::const_iterator package_match =
expected_package_prefixes.find(lookup_key); expected_package_prefixes.find(lookup_key);
if (package_match != expected_package_prefixes.end()) { if (package_match != expected_package_prefixes.end()) {
// There was an entry, and... // There was an entry, and...
@ -1098,7 +1095,7 @@ bool ValidateObjCClassPrefix(
if (!prefix.empty() && have_expected_prefix_file) { if (!prefix.empty() && have_expected_prefix_file) {
// For a non empty prefix, look for any other package that uses the prefix. // For a non empty prefix, look for any other package that uses the prefix.
std::string other_package_for_prefix; std::string other_package_for_prefix;
for (absl::flat_hash_map<std::string, std::string>::const_iterator i = for (std::map<std::string, std::string>::const_iterator i =
expected_package_prefixes.begin(); expected_package_prefixes.begin();
i != expected_package_prefixes.end(); ++i) { i != expected_package_prefixes.end(); ++i) {
if (i->second == prefix) { if (i->second == prefix) {
@ -1216,7 +1213,7 @@ bool ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files,
} }
// Load the expected package prefixes, if available, to validate against. // Load the expected package prefixes, if available, to validate against.
absl::flat_hash_map<std::string, std::string> expected_package_prefixes; std::map<std::string, std::string> expected_package_prefixes;
if (!LoadExpectedPackagePrefixes(validation_options.expected_prefixes_path, if (!LoadExpectedPackagePrefixes(validation_options.expected_prefixes_path,
&expected_package_prefixes, out_error)) { &expected_package_prefixes, out_error)) {
return false; return false;

@ -36,7 +36,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
@ -68,7 +67,7 @@ class OneofGenerator {
private: private:
const OneofDescriptor* descriptor_; const OneofDescriptor* descriptor_;
absl::flat_hash_map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
}; };
} // namespace objectivec } // namespace objectivec

@ -33,7 +33,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/helpers.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
@ -112,9 +111,8 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) {
return nullptr; return nullptr;
} }
void SetPrimitiveVariables( void SetPrimitiveVariables(const FieldDescriptor* descriptor,
const FieldDescriptor* descriptor, std::map<std::string, std::string>* variables) {
absl::flat_hash_map<std::string, std::string>* variables) {
std::string primitive_name = PrimitiveTypeName(descriptor); std::string primitive_name = PrimitiveTypeName(descriptor);
(*variables)["type"] = primitive_name; (*variables)["type"] = primitive_name;
(*variables)["storage_type"] = primitive_name; (*variables)["storage_type"] = primitive_name;

@ -54,7 +54,6 @@
#include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
@ -434,7 +433,7 @@ void Generator::PrintImports() const {
// Prints the single file descriptor for this file. // Prints the single file descriptor for this file.
void Generator::PrintFileDescriptor() const { void Generator::PrintFileDescriptor() const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["name"] = file_->name(); m["name"] = file_->name();
m["package"] = file_->package(); m["package"] = file_->package();
@ -509,7 +508,7 @@ void Generator::PrintAllNestedEnumsInFile() const {
// enum name to a Python EnumDescriptor object equivalent to // enum name to a Python EnumDescriptor object equivalent to
// enum_descriptor. // enum_descriptor.
void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
std::string module_level_descriptor_name = std::string module_level_descriptor_name =
ModuleLevelDescriptorName(enum_descriptor); ModuleLevelDescriptorName(enum_descriptor);
m["descriptor_name"] = module_level_descriptor_name; m["descriptor_name"] = module_level_descriptor_name;
@ -584,7 +583,7 @@ void Generator::PrintServices() const {
void Generator::PrintServiceDescriptor( void Generator::PrintServiceDescriptor(
const ServiceDescriptor& descriptor) const { const ServiceDescriptor& descriptor) const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["service_name"] = ModuleLevelServiceDescriptorName(descriptor); m["service_name"] = ModuleLevelServiceDescriptorName(descriptor);
m["name"] = descriptor.name(); m["name"] = descriptor.name();
m["file"] = kDescriptorKey; m["file"] = kDescriptorKey;
@ -634,7 +633,7 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const {
// //
// Mutually recursive with PrintNestedDescriptors(). // Mutually recursive with PrintNestedDescriptors().
void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { void Generator::PrintDescriptor(const Descriptor& message_descriptor) const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["name"] = message_descriptor.name(); m["name"] = message_descriptor.name();
m["full_name"] = message_descriptor.full_name(); m["full_name"] = message_descriptor.full_name();
m["file"] = kDescriptorKey; m["file"] = kDescriptorKey;
@ -785,7 +784,7 @@ void Generator::PrintMessage(const Descriptor& message_descriptor,
to_register->push_back(qualified_name); to_register->push_back(qualified_name);
PrintNestedMessages(message_descriptor, qualified_name, to_register); PrintNestedMessages(message_descriptor, qualified_name, to_register);
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["descriptor_key"] = kDescriptorKey; m["descriptor_key"] = kDescriptorKey;
m["descriptor_name"] = ModuleLevelDescriptorName(message_descriptor); m["descriptor_name"] = ModuleLevelDescriptorName(message_descriptor);
printer_->Print(m, "'$descriptor_key$' : $descriptor_name$,\n"); printer_->Print(m, "'$descriptor_key$' : $descriptor_name$,\n");
@ -840,7 +839,7 @@ void Generator::FixForeignFieldsInDescriptor(
FixContainingTypeInDescriptor(enum_descriptor, &descriptor); FixContainingTypeInDescriptor(enum_descriptor, &descriptor);
} }
for (int i = 0; i < descriptor.oneof_decl_count(); ++i) { for (int i = 0; i < descriptor.oneof_decl_count(); ++i) {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
const OneofDescriptor* oneof = descriptor.oneof_decl(i); const OneofDescriptor* oneof = descriptor.oneof_decl(i);
m["descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["descriptor_name"] = ModuleLevelDescriptorName(descriptor);
m["oneof_name"] = oneof->name(); m["oneof_name"] = oneof->name();
@ -859,7 +858,7 @@ void Generator::FixForeignFieldsInDescriptor(
} }
void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const { void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["message_name"] = descriptor.name(); m["message_name"] = descriptor.name();
m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor);
@ -871,7 +870,7 @@ void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const {
void Generator::AddServiceToFileDescriptor( void Generator::AddServiceToFileDescriptor(
const ServiceDescriptor& descriptor) const { const ServiceDescriptor& descriptor) const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["service_name"] = descriptor.name(); m["service_name"] = descriptor.name();
m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor); m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor);
@ -883,7 +882,7 @@ void Generator::AddServiceToFileDescriptor(
void Generator::AddEnumToFileDescriptor( void Generator::AddEnumToFileDescriptor(
const EnumDescriptor& descriptor) const { const EnumDescriptor& descriptor) const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["enum_name"] = descriptor.name(); m["enum_name"] = descriptor.name();
m["enum_descriptor_name"] = ModuleLevelDescriptorName(descriptor); m["enum_descriptor_name"] = ModuleLevelDescriptorName(descriptor);
@ -895,7 +894,7 @@ void Generator::AddEnumToFileDescriptor(
void Generator::AddExtensionToFileDescriptor( void Generator::AddExtensionToFileDescriptor(
const FieldDescriptor& descriptor) const { const FieldDescriptor& descriptor) const {
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["descriptor_name"] = kDescriptorKey; m["descriptor_name"] = kDescriptorKey;
m["field_name"] = descriptor.name(); m["field_name"] = descriptor.name();
m["resolved_name"] = ResolveKeyword(descriptor.name()); m["resolved_name"] = ResolveKeyword(descriptor.name());
@ -919,7 +918,7 @@ void Generator::FixForeignFieldsInField(
const std::string& python_dict_name) const { const std::string& python_dict_name) const {
const std::string field_referencing_expression = const std::string field_referencing_expression =
FieldReferencingExpression(containing_type, field, python_dict_name); FieldReferencingExpression(containing_type, field, python_dict_name);
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["field_ref"] = field_referencing_expression; m["field_ref"] = field_referencing_expression;
const Descriptor* foreign_message_type = field.message_type(); const Descriptor* foreign_message_type = field.message_type();
if (foreign_message_type) { if (foreign_message_type) {
@ -1015,7 +1014,7 @@ void Generator::FixForeignFieldsInExtension(
const FieldDescriptor& extension_field) const { const FieldDescriptor& extension_field) const {
GOOGLE_CHECK(extension_field.is_extension()); GOOGLE_CHECK(extension_field.is_extension());
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
// Confusingly, for FieldDescriptors that happen to be extensions, // Confusingly, for FieldDescriptors that happen to be extensions,
// containing_type() means "extended type." // containing_type() means "extended type."
// On the other hand, extension_scope() will give us what we normally // On the other hand, extension_scope() will give us what we normally
@ -1047,7 +1046,7 @@ void Generator::PrintEnumValueDescriptor(
// More circular references. ::sigh:: // More circular references. ::sigh::
std::string options_string; std::string options_string;
descriptor.options().SerializeToString(&options_string); descriptor.options().SerializeToString(&options_string);
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["name"] = descriptor.name(); m["name"] = descriptor.name();
m["index"] = absl::StrCat(descriptor.index()); m["index"] = absl::StrCat(descriptor.index());
m["number"] = absl::StrCat(descriptor.number()); m["number"] = absl::StrCat(descriptor.number());
@ -1075,7 +1074,7 @@ void Generator::PrintFieldDescriptor(const FieldDescriptor& field,
bool is_extension) const { bool is_extension) const {
std::string options_string; std::string options_string;
field.options().SerializeToString(&options_string); field.options().SerializeToString(&options_string);
absl::flat_hash_map<std::string, std::string> m; std::map<std::string, std::string> m;
m["name"] = field.name(); m["name"] = field.name();
m["full_name"] = field.full_name(); m["full_name"] = field.full_name();
m["index"] = absl::StrCat(field.index()); m["index"] = absl::StrCat(field.index());

@ -39,7 +39,6 @@
#include <set> #include <set>
#include <string> #include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/synchronization/mutex.h" #include "absl/synchronization/mutex.h"
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
@ -107,7 +106,7 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera
mutable io::Printer* printer_; // Set in Generate(). Under mutex_. mutable io::Printer* printer_; // Set in Generate(). Under mutex_.
// import_map will be a mapping from filename to module alias, e.g. // import_map will be a mapping from filename to module alias, e.g.
// "google3/foo/bar.py" -> "_bar" // "google3/foo/bar.py" -> "_bar"
mutable absl::flat_hash_map<std::string, std::string> import_map_; mutable std::map<std::string, std::string> import_map_;
}; };
} // namespace python } // namespace python

@ -40,6 +40,7 @@
#include <cstddef> #include <cstddef>
#include <functional> #include <functional>
#include <initializer_list> #include <initializer_list>
#include <map>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -534,10 +535,10 @@ class PROTOBUF_EXPORT Printer {
// Pushes a new variable lookup frame that stores `vars` by reference. // Pushes a new variable lookup frame that stores `vars` by reference.
// //
// Returns an RAII object that pops the lookup frame. // Returns an RAII object that pops the lookup frame.
template <typename Map, typename StringType = absl::string_view> template <typename Map>
auto WithVars(const Map* vars) { auto WithVars(const Map* vars) {
var_lookups_.emplace_back([vars](absl::string_view var) -> LookupResult { var_lookups_.emplace_back([vars](absl::string_view var) -> LookupResult {
auto it = vars->find(StringType(var)); auto it = vars->find(std::string(var));
if (it == vars->end()) { if (it == vars->end()) {
return absl::nullopt; return absl::nullopt;
} }
@ -553,12 +554,11 @@ class PROTOBUF_EXPORT Printer {
// //
// Returns an RAII object that pops the lookup frame. // Returns an RAII object that pops the lookup frame.
template <typename Map = absl::flat_hash_map<std::string, std::string>, template <typename Map = absl::flat_hash_map<std::string, std::string>,
typename StringType = absl::string_view,
std::enable_if_t<!std::is_pointer<Map>::value, int> = 0> std::enable_if_t<!std::is_pointer<Map>::value, int> = 0>
auto WithVars(Map&& vars) { auto WithVars(Map&& vars) {
var_lookups_.emplace_back([vars = std::forward<Map>(vars)]( var_lookups_.emplace_back([vars = std::forward<Map>(vars)](
absl::string_view var) -> LookupResult { absl::string_view var) -> LookupResult {
auto it = vars.find(StringType(var)); auto it = vars.find(std::string(var));
if (it == vars.end()) { if (it == vars.end()) {
return absl::nullopt; return absl::nullopt;
} }
@ -581,11 +581,11 @@ class PROTOBUF_EXPORT Printer {
// Pushes a new annotation lookup frame that stores `vars` by reference. // Pushes a new annotation lookup frame that stores `vars` by reference.
// //
// Returns an RAII object that pops the lookup frame. // Returns an RAII object that pops the lookup frame.
template <typename Map, typename StringType = absl::string_view> template <typename Map>
auto WithAnnotations(const Map* vars) { auto WithAnnotations(const Map* vars) {
annotation_lookups_.emplace_back( annotation_lookups_.emplace_back(
[vars](absl::string_view var) -> absl::optional<AnnotationRecord> { [vars](absl::string_view var) -> absl::optional<AnnotationRecord> {
auto it = vars->find(StringType(var)); auto it = vars->find(std::string(var));
if (it == vars->end()) { if (it == vars->end()) {
return absl::nullopt; return absl::nullopt;
} }
@ -605,7 +605,7 @@ class PROTOBUF_EXPORT Printer {
annotation_lookups_.emplace_back( annotation_lookups_.emplace_back(
[vars = std::forward<Map>(vars)]( [vars = std::forward<Map>(vars)](
absl::string_view var) -> absl::optional<AnnotationRecord> { absl::string_view var) -> absl::optional<AnnotationRecord> {
auto it = vars.find(var); auto it = vars.find(std::string(var));
if (it == vars.end()) { if (it == vars.end()) {
return absl::nullopt; return absl::nullopt;
} }
@ -671,19 +671,6 @@ class PROTOBUF_EXPORT Printer {
PrintImpl(text, {}, opts); PrintImpl(text, {}, opts);
} }
// TODO(b/243140651) Delete this once migrating callers to containers with
// heterogeneous lookup.
void Print(const std::map<std::string, std::string>& vars,
absl::string_view text) {
PrintOptions opts;
opts.checks_are_debug_only = true;
opts.use_substitution_map = true;
opts.allow_digit_substitions = false;
auto pop = WithVars<std::map<std::string, std::string>, std::string>(&vars);
PrintImpl(text, {}, opts);
}
template <typename... Args> template <typename... Args>
void Print(absl::string_view text, const Args&... args) { void Print(absl::string_view text, const Args&... args) {
static_assert(sizeof...(args) % 2 == 0, ""); static_assert(sizeof...(args) % 2 == 0, "");
@ -691,10 +678,10 @@ class PROTOBUF_EXPORT Printer {
// Include an extra arg, since a zero-length array is ill-formed, and // Include an extra arg, since a zero-length array is ill-formed, and
// MSVC complains. // MSVC complains.
absl::string_view vars[] = {args..., ""}; absl::string_view vars[] = {args..., ""};
absl::flat_hash_map<absl::string_view, absl::string_view> map; absl::flat_hash_map<std::string, std::string> map;
map.reserve(sizeof...(args) / 2); map.reserve(sizeof...(args) / 2);
for (size_t i = 0; i < sizeof...(args); i += 2) { for (size_t i = 0; i < sizeof...(args); i += 2) {
map.emplace(vars[i], vars[i + 1]); map.emplace(std::string(vars[i]), std::string(vars[i + 1]));
} }
Print(map, text); Print(map, text);
@ -751,7 +738,7 @@ class PROTOBUF_EXPORT Printer {
// FormatInternal is a helper function not meant to use directly, use // FormatInternal is a helper function not meant to use directly, use
// compiler::cpp::Formatter instead. // compiler::cpp::Formatter instead.
void FormatInternal(absl::Span<const std::string> args, void FormatInternal(absl::Span<const std::string> args,
const absl::flat_hash_map<std::string, std::string>& vars, const std::map<std::string, std::string>& vars,
absl::string_view format) { absl::string_view format) {
PrintOptions opts; PrintOptions opts;
opts.use_curly_brace_substitutions = true; opts.use_curly_brace_substitutions = true;

@ -1 +1 @@
Subproject commit 45fbf543fec00020a08650791a37575319a3ea1d Subproject commit a67b76f9f40107f2c78a5aa860bb6ce37ed83d85
Loading…
Cancel
Save