diff options
Diffstat (limited to 'src/google/protobuf/compiler')
62 files changed, 1105 insertions, 930 deletions
diff --git a/src/google/protobuf/compiler/annotation_test_util.h b/src/google/protobuf/compiler/annotation_test_util.h index 34c3f6a9..fbd3dec5 100644 --- a/src/google/protobuf/compiler/annotation_test_util.h +++ b/src/google/protobuf/compiler/annotation_test_util.h @@ -49,15 +49,15 @@ namespace annotation_test_util { // file_content = content of Foo.java // file_info = parsed content of Foo.java.pb.meta struct ExpectedOutput { - string file_path; - string file_content; + std::string file_path; + std::string file_content; GeneratedCodeInfo file_info; - explicit ExpectedOutput(const string& file_path) : file_path(file_path) {} + explicit ExpectedOutput(const std::string& file_path) : file_path(file_path) {} }; // Creates a file with name `filename` and content `data` in temp test // directory. -void AddFile(const string& filename, const string& data); +void AddFile(const std::string& filename, const std::string& data); // Runs proto compiler. Captures proto file structrue in FileDescriptorProto. // Files will be generated in TestTempDir() folder. Callers of this @@ -70,17 +70,17 @@ void AddFile(const string& filename, const string& data); // annotation_unittest.cc for an example of how to initialize it. // file: output parameter, will be set to the descriptor of the proto file // specified in filename. -bool RunProtoCompiler(const string& filename, - const string& plugin_specific_args, +bool RunProtoCompiler(const std::string& filename, + const std::string& plugin_specific_args, CommandLineInterface* cli, FileDescriptorProto* file); -bool DecodeMetadata(const string& path, GeneratedCodeInfo* info); +bool DecodeMetadata(const std::string& path, GeneratedCodeInfo* info); // Finds all of the Annotations for a given source file and path. // See Location.path in http://google3/net/proto2/proto/descriptor.proto for // explanation of what path vector is. void FindAnnotationsOnPath( - const GeneratedCodeInfo& info, const string& source_file, + const GeneratedCodeInfo& info, const std::string& source_file, const std::vector<int>& path, std::vector<const GeneratedCodeInfo::Annotation*>* annotations); @@ -90,21 +90,21 @@ void FindAnnotationsOnPath( // http://google3/net/proto2/proto/descriptor.proto for explanation of what path // vector is. const GeneratedCodeInfo::Annotation* FindAnnotationOnPath( - const GeneratedCodeInfo& info, const string& source_file, + const GeneratedCodeInfo& info, const std::string& source_file, const std::vector<int>& path); // Returns true if at least one of the provided annotations covers a given // substring in file_content. bool AtLeastOneAnnotationMatchesSubstring( - const string& file_content, + const std::string& file_content, const std::vector<const GeneratedCodeInfo::Annotation*>& annotations, - const string& expected_text); + const std::string& expected_text); // Returns true if the provided annotation covers a given substring in // file_content. -bool AnnotationMatchesSubstring(const string& file_content, +bool AnnotationMatchesSubstring(const std::string& file_content, const GeneratedCodeInfo::Annotation* annotation, - const string& expected_text); + const std::string& expected_text); } // namespace annotation_test_util } // namespace compiler diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h index a1cd6113..b1eb61ac 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -43,6 +43,8 @@ #include <vector> #include <utility> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -61,7 +63,7 @@ class GeneratorContext; // The abstract interface to a class which generates code implementing a // particular proto file in a particular language. A number of these may // be registered with CommandLineInterface to support various languages. -class LIBPROTOC_EXPORT CodeGenerator { +class PROTOC_EXPORT CodeGenerator { public: inline CodeGenerator() {} virtual ~CodeGenerator(); @@ -78,9 +80,9 @@ class LIBPROTOC_EXPORT CodeGenerator { // Returns true if successful. Otherwise, sets *error to a description of // the problem (e.g. "invalid parameter") and returns false. virtual bool Generate(const FileDescriptor* file, - const string& parameter, + const std::string& parameter, GeneratorContext* generator_context, - string* error) const = 0; + std::string* error) const = 0; // Generates code for all given proto files. // @@ -94,9 +96,9 @@ class LIBPROTOC_EXPORT CodeGenerator { // Returns true if successful. Otherwise, sets *error to a description of // the problem (e.g. "invalid parameter") and returns false. virtual bool GenerateAll(const std::vector<const FileDescriptor*>& files, - const string& parameter, + const std::string& parameter, GeneratorContext* generator_context, - string* error) const; + std::string* error) const; // This is no longer used, but this class is part of the opensource protobuf // library, so it has to remain to keep vtables the same for the current @@ -112,7 +114,7 @@ class LIBPROTOC_EXPORT CodeGenerator { // abstract interface represents the directory to which the CodeGenerator is // to write and other information about the context in which the Generator // runs. -class LIBPROTOC_EXPORT GeneratorContext { +class PROTOC_EXPORT GeneratorContext { public: inline GeneratorContext() { } @@ -128,10 +130,10 @@ class LIBPROTOC_EXPORT GeneratorContext { // generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that // "foo/" is included in these filenames. The filename is not allowed to // contain "." or ".." components. - virtual io::ZeroCopyOutputStream* Open(const string& filename) = 0; + virtual io::ZeroCopyOutputStream* Open(const std::string& filename) = 0; // Similar to Open() but the output will be appended to the file if exists - virtual io::ZeroCopyOutputStream* OpenForAppend(const string& filename); + virtual io::ZeroCopyOutputStream* OpenForAppend(const std::string& filename); // Creates a ZeroCopyOutputStream which will insert code into the given file // at the given insertion point. See plugin.proto (plugin.pb.h) for more @@ -140,7 +142,7 @@ class LIBPROTOC_EXPORT GeneratorContext { // // WARNING: This feature is currently EXPERIMENTAL and is subject to change. virtual io::ZeroCopyOutputStream* OpenForInsert( - const string& filename, const string& insertion_point); + const std::string& filename, const std::string& insertion_point); // Returns a vector of FileDescriptors for all the files being compiled // in this run. Useful for languages, such as Go, that treat files @@ -166,11 +168,13 @@ typedef GeneratorContext OutputDirectory; // "foo=bar,baz,qux=corge" // parses to the pairs: // ("foo", "bar"), ("baz", ""), ("qux", "corge") -LIBPROTOC_EXPORT void ParseGeneratorParameter( - const string&, std::vector<std::pair<string, string> >*); +PROTOC_EXPORT void ParseGeneratorParameter( + const std::string&, std::vector<std::pair<std::string, std::string> >*); } // namespace compiler } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 80056774..4d1ef09b 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -84,6 +84,8 @@ #include <google/protobuf/stubs/io_win32.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -169,7 +171,8 @@ bool VerifyDirectoryExists(const string& path) { bool TryCreateParentDirectory(const string& prefix, const string& filename) { // Recursively create parent directories to the output file. // On Windows, both '/' and '\' are valid path separators. - std::vector<string> parts = Split(filename, "/\\", true); + std::vector<string> parts = + Split(filename, "/\\", true); string path_so_far = prefix; for (int i = 0; i < parts.size() - 1; i++) { path_so_far += parts[i]; @@ -1546,7 +1549,7 @@ CommandLineInterface::InterpretArgument(const string& name, std::cout << version_info_ << std::endl; } std::cout << "libprotoc " - << protobuf::internal::VersionString(GOOGLE_PROTOBUF_VERSION) + << protobuf::internal::VersionString(PROTOBUF_VERSION) << std::endl; return PARSE_ARGUMENT_DONE_AND_EXIT; // Exit without running compiler. @@ -1932,10 +1935,10 @@ bool CommandLineInterface::GeneratePluginOutput( google::protobuf::compiler::Version* version = request.mutable_compiler_version(); - version->set_major(GOOGLE_PROTOBUF_VERSION / 1000000); - version->set_minor(GOOGLE_PROTOBUF_VERSION / 1000 % 1000); - version->set_patch(GOOGLE_PROTOBUF_VERSION % 1000); - version->set_suffix(GOOGLE_PROTOBUF_VERSION_SUFFIX); + version->set_major(PROTOBUF_VERSION / 1000000); + version->set_minor(PROTOBUF_VERSION / 1000 % 1000); + version->set_patch(PROTOBUF_VERSION % 1000); + version->set_suffix(PROTOBUF_VERSION_SUFFIX); // Invoke the plugin. Subprocess subprocess; diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 8dba9949..cef29ffe 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -47,6 +47,8 @@ #include <google/protobuf/stubs/common.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -102,7 +104,7 @@ class DiskSourceTree; // importer.h // relative virtual path, the physical file path takes precendence. // // For a full description of the command-line syntax, invoke it with --help. -class LIBPROTOC_EXPORT CommandLineInterface { +class PROTOC_EXPORT CommandLineInterface { public: static const char* const kPathSeparator; @@ -125,9 +127,9 @@ class LIBPROTOC_EXPORT CommandLineInterface { // protoc --foo_out=enable_bar:outdir // The text before the colon is passed to CodeGenerator::Generate() as the // "parameter". - void RegisterGenerator(const string& flag_name, + void RegisterGenerator(const std::string& flag_name, CodeGenerator* generator, - const string& help_text); + const std::string& help_text); // Register a code generator for a language. // Besides flag_name you can specify another option_flag_name that could be @@ -137,10 +139,10 @@ class LIBPROTOC_EXPORT CommandLineInterface { // Then you could invoke the compiler with a command like: // protoc --foo_out=enable_bar:outdir --foo_opt=enable_baz // This will pass "enable_bar,enable_baz" as the parameter to the generator. - void RegisterGenerator(const string& flag_name, - const string& option_flag_name, + void RegisterGenerator(const std::string& flag_name, + const std::string& option_flag_name, CodeGenerator* generator, - const string& help_text); + const std::string& help_text); // Enables "plugins". In this mode, if a command-line flag ends with "_out" // but does not match any registered generator, the compiler will attempt to @@ -178,7 +180,7 @@ class LIBPROTOC_EXPORT CommandLineInterface { // protoc --plug_out=enable_bar:outdir --plug_opt=enable_baz // This will pass "enable_bar,enable_baz" as the parameter to the plugin. // - void AllowPlugins(const string& exe_name_prefix); + void AllowPlugins(const std::string& exe_name_prefix); // Run the Protocol Compiler with the given command-line parameters. // Returns the error code which should be returned by main(). @@ -196,7 +198,7 @@ class LIBPROTOC_EXPORT CommandLineInterface { // Provides some text which will be printed when the --version flag is // used. The version of libprotoc will also be printed on the next line // after this text. - void SetVersionInfo(const string& text) { + void SetVersionInfo(const std::string& text) { version_info_ = text; } @@ -207,14 +209,14 @@ class LIBPROTOC_EXPORT CommandLineInterface { class ErrorPrinter; class GeneratorContextImpl; class MemoryOutputStream; - typedef std::unordered_map<string, GeneratorContextImpl*> GeneratorContextMap; + typedef std::unordered_map<std::string, GeneratorContextImpl*> GeneratorContextMap; // Clear state from previous Run(). void Clear(); // Remaps the proto file so that it is relative to one of the ddirectories // in proto_path_. Returns false if an error occurred. - bool MakeProtoProtoPathRelative(DiskSourceTree* source_tree, string* proto); + bool MakeProtoProtoPathRelative(DiskSourceTree* source_tree, std::string* proto); // Remaps each file in input_files_ so that it is relative to one of the // directories in proto_path_. Returns false if an error occurred. @@ -234,7 +236,7 @@ class LIBPROTOC_EXPORT CommandLineInterface { // Read an argument file and append the file's content to the list of // arguments. Return false if the file cannot be read. - bool ExpandArgumentFile(const string& file, std::vector<string>* arguments); + bool ExpandArgumentFile(const std::string& file, std::vector<std::string>* arguments); // Parses a command-line argument into a name/value pair. Returns // true if the next argument in the argv should be used as the value, @@ -247,11 +249,11 @@ class LIBPROTOC_EXPORT CommandLineInterface { // name = "--cpp_out", value = "src/foo.pb2.cc" // "foo.proto" -> // name = "", value = "foo.proto" - bool ParseArgument(const char* arg, string* name, string* value); + bool ParseArgument(const char* arg, std::string* name, std::string* value); // Interprets arguments parsed with ParseArgument. - ParseArgumentStatus InterpretArgument(const string& name, - const string& value); + ParseArgumentStatus InterpretArgument(const std::string& name, + const std::string& value); // Print the --help text to stderr. void PrintHelpText(); @@ -273,8 +275,8 @@ class LIBPROTOC_EXPORT CommandLineInterface { GeneratorContext* generator_context); bool GeneratePluginOutput( const std::vector<const FileDescriptor*>& parsed_files, - const string& plugin_name, const string& parameter, - GeneratorContext* generator_context, string* error); + const std::string& plugin_name, const std::string& parameter, + GeneratorContext* generator_context, std::string* error); // Implements --encode and --decode. bool EncodeOrDecode(const DescriptorPool* pool); @@ -324,36 +326,36 @@ class LIBPROTOC_EXPORT CommandLineInterface { // ----------------------------------------------------------------- // The name of the executable as invoked (i.e. argv[0]). - string executable_name_; + std::string executable_name_; // Version info set with SetVersionInfo(). - string version_info_; + std::string version_info_; // Registered generators. struct GeneratorInfo { - string flag_name; - string option_flag_name; + std::string flag_name; + std::string option_flag_name; CodeGenerator* generator; - string help_text; + std::string help_text; }; - typedef std::map<string, GeneratorInfo> GeneratorMap; + typedef std::map<std::string, GeneratorInfo> GeneratorMap; GeneratorMap generators_by_flag_name_; GeneratorMap generators_by_option_name_; // A map from generator names to the parameters specified using the option // flag. For example, if the user invokes the compiler with: // protoc --foo_out=outputdir --foo_opt=enable_bar ... // Then there will be an entry ("--foo_out", "enable_bar") in this map. - std::map<string, string> generator_parameters_; + std::map<std::string, std::string> generator_parameters_; // Similar to generator_parameters_, but stores the parameters for plugins. - std::map<string, string> plugin_parameters_; + std::map<std::string, std::string> plugin_parameters_; // See AllowPlugins(). If this is empty, plugins aren't allowed. - string plugin_prefix_; + std::string plugin_prefix_; // 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 // PATH (or other OS-specific search strategy) is searched. - std::map<string, string> plugins_; + std::map<std::string, std::string> plugins_; // Stuff parsed from command line. enum Mode { @@ -379,44 +381,44 @@ class LIBPROTOC_EXPORT CommandLineInterface { ErrorFormat error_format_; - std::vector<std::pair<string, string> > + std::vector<std::pair<std::string, std::string> > proto_path_; // Search path for proto files. - std::vector<string> input_files_; // Names of the input proto files. + std::vector<std::string> input_files_; // Names of the input proto files. // Names of proto files which are allowed to be imported. Used by build // systems to enforce depend-on-what-you-import. - std::set<string> direct_dependencies_; + std::set<std::string> direct_dependencies_; bool direct_dependencies_explicitly_set_; // If there's a violation of depend-on-what-you-import, this string will be // presented to the user. "%s" will be replaced with the violating import. - string direct_dependencies_violation_msg_; + std::string direct_dependencies_violation_msg_; // output_directives_ lists all the files we are supposed to output and what // generator to use for each. struct OutputDirective { - string name; // E.g. "--foo_out" + std::string name; // E.g. "--foo_out" CodeGenerator* generator; // NULL for plugins - string parameter; - string output_location; + std::string parameter; + std::string output_location; }; std::vector<OutputDirective> output_directives_; // When using --encode or --decode, this names the type we are encoding or // decoding. (Empty string indicates --decode_raw.) - string codec_type_; + std::string codec_type_; // If --descriptor_set_in was given, these are filenames containing // parsed FileDescriptorSets to be used for loading protos. Otherwise, empty. - std::vector<string> descriptor_set_in_names_; + std::vector<std::string> descriptor_set_in_names_; // If --descriptor_set_out was given, this is the filename to which the // FileDescriptorSet should be written. Otherwise, empty. - string descriptor_set_out_name_; + std::string descriptor_set_out_name_; // If --dependency_out was given, this is the path to the file where the // dependency file will be written. Otherwise, empty. - string dependency_out_name_; + std::string dependency_out_name_; // True if --include_imports was given, meaning that we should // write all transitive dependencies to the DescriptorSet. Otherwise, only @@ -437,4 +439,6 @@ class LIBPROTOC_EXPORT CommandLineInterface { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ diff --git a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc index 4c135649..a19ad595 100644 --- a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc @@ -50,6 +50,7 @@ #include <google/protobuf/test_util2.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/descriptor.h> +#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> #include <google/protobuf/stubs/map_util.h> #include <google/protobuf/stubs/stl_util.h> @@ -98,6 +99,13 @@ class MockGeneratorContext : public GeneratorContext { &actual_contents, true)) << physical_filename; CleanStringLineEndings(&actual_contents, false); + +#ifdef WRITE_FILES // Define to debug mismatched files. + GOOGLE_CHECK_OK( + File::SetContents("/tmp/1.cc", *expected_contents, true)); + GOOGLE_CHECK_OK(File::SetContents("/tmp/2.cc", actual_contents, true)); +#endif + EXPECT_EQ(*expected_contents, actual_contents) << physical_filename << " needs to be regenerated. Please run " @@ -119,8 +127,8 @@ class MockGeneratorContext : public GeneratorContext { std::map<string, string*> files_; }; -const char kDescriptorParameter[] = "dllexport_decl=LIBPROTOBUF_EXPORT"; -const char kPluginParameter[] = "dllexport_decl=LIBPROTOC_EXPORT"; +const char kDescriptorParameter[] = "dllexport_decl=PROTOBUF_EXPORT"; +const char kPluginParameter[] = "dllexport_decl=PROTOC_EXPORT"; const char kNormalParameter[] = ""; const char* test_protos[][2] = { diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.h b/src/google/protobuf/compiler/cpp/cpp_enum.h index 55e6b835..6b9700ae 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.h +++ b/src/google/protobuf/compiler/cpp/cpp_enum.h @@ -58,7 +58,7 @@ class EnumGenerator { public: // See generator.cc for the meaning of dllexport_decl. EnumGenerator(const EnumDescriptor* descriptor, - const std::map<string, string>& vars, const Options& options); + const std::map<std::string, std::string>& vars, const Options& options); ~EnumGenerator(); // Generate header code defining the enum. This code should be placed @@ -85,12 +85,12 @@ class EnumGenerator { private: const EnumDescriptor* descriptor_; - const string classname_; + const std::string classname_; const Options& options_; // whether to generate the *_ARRAYSIZE constant. const bool generate_array_size_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; friend class FileGenerator; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc index 25bcc333..f866eb6e 100644 --- a/src/google/protobuf/compiler/cpp/cpp_extension.cc +++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc @@ -137,6 +137,16 @@ void ExtensionGenerator::GenerateDeclaration(io::Printer* printer) const { } void ExtensionGenerator::GenerateDefinition(io::Printer* printer) { + // If we are building for lite with implicit weak fields, we want to skip over + // any custom options (i.e. extensions of messages from descriptor.proto). + // This prevents the creation of any unnecessary linker references to the + // descriptor messages. + if (options_.lite_implicit_weak_fields && + descriptor_->containing_type()->file()->name() == + "net/proto2/proto/descriptor.proto") { + return; + } + Formatter format(printer, variables_); string default_str; // If this is a class member, it needs to be declared in its class scope. diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.h b/src/google/protobuf/compiler/cpp/cpp_extension.h index c316f5da..72413f6b 100644 --- a/src/google/protobuf/compiler/cpp/cpp_extension.h +++ b/src/google/protobuf/compiler/cpp/cpp_extension.h @@ -75,10 +75,10 @@ class ExtensionGenerator { private: const FieldDescriptor* descriptor_; - string type_traits_; + std::string type_traits_; Options options_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); }; diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h index 4561b33e..43a3e367 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_field.h @@ -61,11 +61,11 @@ namespace cpp { // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', // 'deprecation']. void SetCommonFieldVariables(const FieldDescriptor* descriptor, - std::map<string, string>* variables, + std::map<std::string, std::string>* variables, const Options& options); void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor, - std::map<string, string>* variables); + std::map<std::string, std::string>* variables); class FieldGenerator { public: @@ -203,7 +203,7 @@ class FieldGenerator { protected: const FieldDescriptor* descriptor_; const Options& options_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index 414da2f8..1e80715d 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -256,6 +256,8 @@ void FileGenerator::GenerateProtoHeader(io::Printer* printer, GenerateHeader(printer); + IncludeFile("net/proto2/public/port_undef.inc", printer); + GenerateBottomHeaderGuard(printer, filename_identifier); } @@ -425,20 +427,6 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* printer) { } } - // TODO(gerbens) Remove this when all code in google is using the same - // proto library. This is a temporary hack to force build errors if - // the proto library is compiled with GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS - // and is also linking internal proto2. This is to prevent regressions while - // we work cleaning up the code base. After this is completed and we have - // one proto lib all code uses this should be removed. - if (options_.opensource_runtime) { - format( - "// This is a temporary google only hack\n" - "#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS\n" - "#include \"third_party/protobuf/version.h\"\n" - "#endif\n"); - } - format("// @@protoc_insertion_point(includes)\n"); IncludeFile("net/proto2/public/port_def.inc", printer); } @@ -702,6 +690,8 @@ void FileGenerator::GenerateSource(io::Printer* printer) { format( "\n" "// @@protoc_insertion_point(global_scope)\n"); + + IncludeFile("net/proto2/public/port_undef.inc", printer); } void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) { @@ -751,7 +741,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) { format( "\n" "const $uint32$ $tablename$::offsets[] " - "$GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); + "PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {\n"); format.Indent(); std::vector<std::pair<size_t, size_t> > pairs; pairs.reserve(message_generators_.size()); @@ -762,7 +752,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) { format( "};\n" "static const ::$proto_ns$::internal::MigrationSchema schemas[] " - "$GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); + "PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {\n"); format.Indent(); { int offset = 0; @@ -958,7 +948,7 @@ void FileGenerator::GenerateTables(io::Printer* printer) { format( "PROTOBUF_CONSTEXPR_VAR ::$proto_ns$::internal::ParseTableField\n" " const $tablename$::entries[] " - "$GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); + "PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {\n"); format.Indent(); std::vector<size_t> entries; @@ -981,7 +971,7 @@ void FileGenerator::GenerateTables(io::Printer* printer) { "PROTOBUF_CONSTEXPR_VAR " "::$proto_ns$::internal::AuxillaryParseTableField\n" " const $tablename$::aux[] " - "$GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); + "PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {\n"); format.Indent(); std::vector<size_t> aux_entries; @@ -1001,7 +991,7 @@ void FileGenerator::GenerateTables(io::Printer* printer) { "};\n" "PROTOBUF_CONSTEXPR_VAR ::$proto_ns$::internal::ParseTable const\n" " $tablename$::schema[] " - "$GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); + "PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {\n"); format.Indent(); size_t offset = 0; @@ -1199,25 +1189,25 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) { } if (options_.opensource_runtime) { - DoIncludeFile("net/proto2/public/stubs/common.h", false, printer); - // Verify the protobuf library header version is compatible with the protoc // version before going any further. + IncludeFile("net/proto2/public/port_def.inc", printer); format( - "#if GOOGLE_PROTOBUF_VERSION < $1$\n" + "#if PROTOBUF_VERSION < $1$\n" "#error This file was generated by a newer version of protoc which is\n" "#error incompatible with your Protocol Buffer headers. Please update\n" "#error your headers.\n" "#endif\n" - "#if $2$ < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION\n" + "#if $2$ < PROTOBUF_MIN_PROTOC_VERSION\n" "#error This file was generated by an older version of protoc which " "is\n" "#error incompatible with your Protocol Buffer headers. Please\n" "#error regenerate this file with a newer version of protoc.\n" "#endif\n" "\n", - GOOGLE_PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC, // 1 - GOOGLE_PROTOBUF_VERSION); // 2 + PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC, // 1 + PROTOBUF_VERSION); // 2 + IncludeFile("net/proto2/public/port_undef.inc", printer); } // OK, it's now safe to #include other files. @@ -1341,11 +1331,11 @@ void FileGenerator::GenerateGlobalStateFunctionDeclarations( // These tables describe how to serialize and parse messages. Used // for table driven code. " static const ::$proto_ns$::internal::ParseTableField entries[]\n" - " $GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold);\n" + " PROTOBUF_SECTION_VARIABLE(protodesc_cold);\n" " static const ::$proto_ns$::internal::AuxillaryParseTableField aux[]\n" - " $GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold);\n" + " PROTOBUF_SECTION_VARIABLE(protodesc_cold);\n" " static const ::$proto_ns$::internal::ParseTable schema[$1$]\n" - " $GOOGLE_PROTOBUF$_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold);\n" + " PROTOBUF_SECTION_VARIABLE(protodesc_cold);\n" " static const ::$proto_ns$::internal::FieldMetadata field_metadata[];\n" " static const ::$proto_ns$::internal::SerializationTable " "serialization_table[];\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_file.h b/src/google/protobuf/compiler/cpp/cpp_file.h index 9dfdf50f..315cf139 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.h +++ b/src/google/protobuf/compiler/cpp/cpp_file.h @@ -76,10 +76,10 @@ class FileGenerator { // info_path, if non-empty, should be the path (relative to printer's // output) to the metadata file describing this proto header. - void GenerateProtoHeader(io::Printer* printer, const string& info_path); + void GenerateProtoHeader(io::Printer* printer, const std::string& info_path); // info_path, if non-empty, should be the path (relative to printer's // output) to the metadata file describing this PB header. - void GeneratePBHeader(io::Printer* printer, const string& info_path); + void GeneratePBHeader(io::Printer* printer, const std::string& info_path); void GenerateSource(io::Printer* printer); int NumMessages() const { return message_generators_.size(); } @@ -91,16 +91,16 @@ class FileGenerator { // Internal type used by GenerateForwardDeclarations (defined in file.cc). class ForwardDeclarations; - void IncludeFile(const string& google3_name, io::Printer* printer) { + void IncludeFile(const std::string& google3_name, io::Printer* printer) { DoIncludeFile(google3_name, false, printer); } - void IncludeFileAndExport(const string& google3_name, io::Printer* printer) { + void IncludeFileAndExport(const std::string& google3_name, io::Printer* printer) { DoIncludeFile(google3_name, true, printer); } - void DoIncludeFile(const string& google3_name, bool do_export, + void DoIncludeFile(const std::string& google3_name, bool do_export, io::Printer* printer); - string CreateHeaderInclude(const string& basename, + std::string CreateHeaderInclude(const std::string& basename, const FileDescriptor* file); void GenerateInternalForwardDeclarations( const std::vector<const FieldDescriptor*>& fields, const Options& options, @@ -117,9 +117,9 @@ class FileGenerator { // Generates top or bottom of a header file. void GenerateTopHeaderGuard(io::Printer* printer, - const string& filename_identifier); + const std::string& filename_identifier); void GenerateBottomHeaderGuard(io::Printer* printer, - const string& filename_identifier); + const std::string& filename_identifier); // Generates #include directives. void GenerateLibraryIncludes(io::Printer* printer); @@ -127,7 +127,7 @@ class FileGenerator { // Generate a pragma to pull in metadata using the given info_path (if // non-empty). info_path should be relative to printer's output. - void GenerateMetadataPragma(io::Printer* printer, const string& info_path); + void GenerateMetadataPragma(io::Printer* printer, const std::string& info_path); // Generates a couple of different pieces before definitions: void GenerateGlobalStateFunctionDeclarations(io::Printer* printer); @@ -182,7 +182,7 @@ class FileGenerator { MessageSCCAnalyzer scc_analyzer_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; // 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. diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc index 79f773ee..0e7e4dfd 100644 --- a/src/google/protobuf/compiler/cpp/cpp_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc @@ -182,32 +182,41 @@ bool CppGenerator::Generate(const FileDescriptor* file, // Generate cc file(s). if (UsingImplicitWeakFields(file, file_options)) { - { - // This is the global .cc file, containing enum/services/tables/reflection + if (file->name() == "net/proto2/proto/descriptor.proto") { + // If we are building with implicit weak fields then we do not want to + // produce any symbols for descriptor.proto, so we just create an empty + // pb.cc file. std::unique_ptr<io::ZeroCopyOutputStream> output( generator_context->Open(basename + ".pb.cc")); - io::Printer printer(output.get(), '$'); - file_generator.GenerateGlobalSource(&printer); - } + } else { + { + // This is the global .cc file, containing + // enum/services/tables/reflection + std::unique_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(basename + ".pb.cc")); + io::Printer printer(output.get(), '$'); + file_generator.GenerateGlobalSource(&printer); + } - int num_cc_files = file_generator.NumMessages(); + int num_cc_files = file_generator.NumMessages(); - // If we're using implicit weak fields then we allow the user to optionally - // specify how many files to generate, not counting the global pb.cc file. - // If we have more files than messages, then some files will be generated as - // empty placeholders. - if (file_options.num_cc_files > 0) { - GOOGLE_CHECK_LE(file_generator.NumMessages(), file_options.num_cc_files) - << "There must be at least as many numbered .cc files as messages."; - num_cc_files = file_options.num_cc_files; - } - for (int i = 0; i < num_cc_files; i++) { - // TODO(gerbens) Agree on naming scheme. - std::unique_ptr<io::ZeroCopyOutputStream> output(generator_context->Open( - basename + ".out/" + SimpleItoa(i) + ".cc")); - io::Printer printer(output.get(), '$'); - if (i < file_generator.NumMessages()) { - file_generator.GenerateSourceForMessage(i, &printer); + // If we're using implicit weak fields then we allow the user to + // optionally specify how many files to generate, not counting the global + // pb.cc file. If we have more files than messages, then some files will + // be generated as empty placeholders. + if (file_options.num_cc_files > 0) { + GOOGLE_CHECK_LE(file_generator.NumMessages(), file_options.num_cc_files) + << "There must be at least as many numbered .cc files as messages."; + num_cc_files = file_options.num_cc_files; + } + for (int i = 0; i < num_cc_files; i++) { + std::unique_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(basename + ".out/" + + SimpleItoa(i) + ".cc")); + io::Printer printer(output.get(), '$'); + if (i < file_generator.NumMessages()) { + file_generator.GenerateSourceForMessage(i, &printer); + } } } } else { diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.h b/src/google/protobuf/compiler/cpp/cpp_generator.h index 06d3c36f..30363e73 100644 --- a/src/google/protobuf/compiler/cpp/cpp_generator.h +++ b/src/google/protobuf/compiler/cpp/cpp_generator.h @@ -40,6 +40,8 @@ #include <string> #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -49,12 +51,12 @@ namespace cpp { // header. If you create your own protocol compiler binary and you want // it to support C++ output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT CppGenerator : public CodeGenerator { +class PROTOC_EXPORT CppGenerator : public CodeGenerator { public: CppGenerator(); ~CppGenerator(); - enum class LIBPROTOC_EXPORT Runtime { + enum class Runtime { kGoogle3, // Use the internal google3 runtime. kOpensource, // Use the open-source runtime. @@ -70,9 +72,9 @@ class LIBPROTOC_EXPORT CppGenerator : public CodeGenerator { // implements CodeGenerator ---------------------------------------- bool Generate(const FileDescriptor* file, - const string& parameter, + const std::string& parameter, GeneratorContext* generator_context, - string* error) const; + std::string* error) const; private: Runtime runtime_ = Runtime::kOpensource; @@ -84,4 +86,6 @@ class LIBPROTOC_EXPORT CppGenerator : public CodeGenerator { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index bc0a9264..472c55f4 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -53,6 +53,8 @@ #include <google/protobuf/stubs/hash.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -487,10 +489,9 @@ string DefaultValue(const Options& options, const FieldDescriptor* field) { case FieldDescriptor::CPPTYPE_UINT32: return SimpleItoa(field->default_value_uint32()) + "u"; case FieldDescriptor::CPPTYPE_INT64: - return Int64ToString(MacroPrefix(options), field->default_value_int64()); + return Int64ToString("PROTOBUF", field->default_value_int64()); case FieldDescriptor::CPPTYPE_UINT64: - return UInt64ToString(MacroPrefix(options), - field->default_value_uint64()); + return UInt64ToString("PROTOBUF", field->default_value_uint64()); case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field->default_value_double(); if (value == std::numeric_limits<double>::infinity()) { @@ -1058,7 +1059,7 @@ void ListAllTypesForServices(const FileDescriptor* fd, bool GetBootstrapBasename(const Options& options, const string& basename, string* bootstrap_basename) { - if (options.opensource_runtime) { + if (options.opensource_runtime || options.lite_implicit_weak_fields) { return false; } @@ -1169,6 +1170,193 @@ bool ShouldRepeat(const FieldDescriptor* descriptor, wiretype != internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED); } +void GenerateLengthDelim( + const FieldDescriptor* field, const Options& options, + MessageSCCAnalyzer* scc_analyzer, + const Formatter& format) { + format( + "ptr = Varint::Parse32Inline(ptr, &size);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); + if (!IsProto1(field->file(), options) && field->is_packable()) { + if (!HasPreservingUnknownEnumSemantics(field->file()) && + field->type() == FieldDescriptor::TYPE_ENUM) { + format( + "ctx->extra_parse_data().SetEnumValidator($1$_IsValid, " + "msg->mutable_unknown_fields(), $2$);\n" + "parser_till_end = " + "::$proto_ns$::internal::PackedValidEnumParser$3$;\n" + "object = msg->mutable_$4$();\n", + QualifiedClassName(field->enum_type()), field->number(), + UseUnknownFieldSet(field->file(), options) ? "" : "Lite", + FieldName(field)); + } else { + format( + "parser_till_end = ::$proto_ns$::internal::Packed$1$Parser;\n" + "object = msg->mutable_$2$();\n", + DeclaredTypeMethodName(field->type()), FieldName(field)); + } + format( + "if (size > end - ptr) goto len_delim_till_end;\n" + "auto newend = ptr + size;\n" + "if (size) ptr = parser_till_end(ptr, newend, object, ctx);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr == newend);\n"); + } else { + auto field_type = field->type(); + if (IsProto1(field->file(), options)) { + if (field->is_packable()) { + // Sigh ... packed fields endup as a string in proto1 + field_type = FieldDescriptor::TYPE_BYTES; + } + if (field_type == FieldDescriptor::TYPE_STRING) { + // In proto1 strings are treated as bytes + field_type = FieldDescriptor::TYPE_BYTES; + } + } + string utf8 = ""; + switch (field_type) { + case FieldDescriptor::TYPE_STRING: + utf8 = GetUtf8Suffix(field, options); + if (!utf8.empty()) { + string name = "nullptr"; + if (HasDescriptorMethods(field->file(), options)) { + name = "\"" + field->full_name() + "\""; + } + format("ctx->extra_parse_data().SetFieldName($1$);\n", name); + } + PROTOBUF_FALLTHROUGH_INTENDED; + case FieldDescriptor::TYPE_BYTES: { + if (field->options().ctype() == FieldOptions::STRING || + (IsProto1(field->file(), options) && + field->options().ctype() == FieldOptions::STRING_PIECE)) { + format( + "parser_till_end = ::$proto_ns$::internal::StringParser$1$;\n" + "$string$* str = msg->$2$_$3$();\n" + "str->clear();\n", + utf8, + field->is_repeated() && !field->is_map() && + !field->is_packable() + ? "add" + : "mutable", + FieldName(field)); + if (utf8.empty()) { + // special case if there is no utf8 verification. + format( + "object = str;\n" + "if (size > end - ptr) goto len_delim_till_end;\n" + "str->append(ptr, size);\n" + "ptr += size;\n"); + return; + } + } else if (field->options().ctype() == FieldOptions::CORD) { + string cord_parser = "CordParser" + utf8; + format( + "parser_till_end = ::$proto_ns$::internal::$1$;\n" + "auto* str = msg->$2$_$3$();\n" + "str->Clear();\n", + cord_parser, + field->is_repeated() && !field->is_map() ? "add" : "mutable", + FieldName(field)); + } else if (field->options().ctype() == FieldOptions::STRING_PIECE) { + format( + "parser_till_end = " + "::$proto_ns$::internal::StringPieceParser$1$;\n" + "::$proto_ns$::internal::StringPieceField* str = " + "msg->$2$_$3$();\n" + "str->Clear();\n", + utf8, + field->is_repeated() && !field->is_map() ? "add" : "mutable", + FieldName(field)); + } + format( + "object = str;\n" + "if (size > end - ptr) goto len_delim_till_end;\n" + "auto newend = ptr + size;\n" + "if (size) ptr = parser_till_end(ptr, newend, object, ctx);\n"); + if (!utf8.empty()) { + // If utf8 verification is on this can fail. + format("$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr == newend);\n"); + } + break; + } + case FieldDescriptor::TYPE_MESSAGE: { + GOOGLE_CHECK(field->message_type()); + if (!IsProto1(field->file(), options) && field->is_map()) { + const FieldDescriptor* val = + field->message_type()->FindFieldByName("value"); + GOOGLE_CHECK(val); + if (HasFieldPresence(field->file()) && + val->type() == FieldDescriptor::TYPE_ENUM) { + format( + "ctx->extra_parse_data().field_number = $1$;\n" + "ctx->extra_parse_data().unknown_fields = " + "&msg->_internal_metadata_;\n", + field->number()); + } + format( + "parser_till_end = ::$proto_ns$::internal::SlowMapEntryParser;\n" + "auto parse_map = $1$::_ParseMap;\n" + "ctx->extra_parse_data().payload.clear();\n" + "ctx->extra_parse_data().parse_map = parse_map;\n" + "object = &msg->$2$_;\n" + "if (size > end - ptr) goto len_delim_till_end;\n" + "auto newend = ptr + size;\n" + "GOOGLE_PROTOBUF_PARSER_ASSERT(parse_map(ptr, newend, " + "object, ctx));\n" + "ptr = newend;\n", + QualifiedClassName(field->message_type()), FieldName(field)); + break; + } + if (IsImplicitWeakField(field, options, scc_analyzer)) { + if (!field->is_repeated()) { + format("object = HasBitSetters::mutable_$1$(msg);\n", + FieldName(field)); + } else { + format( + "object = " + "CastToBase(&msg->$1$_)->AddWeak(reinterpret_cast<const " + "::google::protobuf::MessageLite*>(&$2$::_$3$_default_instance_));\n", + FieldName(field), Namespace(field->message_type()), + ClassName(field->message_type())); + } + format( + "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" + "object)->_ParseFunc();\n"); + } else if (IsWeak(field, options)) { + if (IsProto1(field->file(), options)) { + format("object = msg->internal_mutable_$1$();\n", + FieldName(field)); + } else { + format( + "object = msg->_weak_field_map_.MutableMessage($1$, " + "_$classname$_default_instance_.$2$_);\n", + field->number(), FieldName(field)); + } + format( + "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" + "object)->_ParseFunc();\n"); + } else { + format( + "parser_till_end = $1$::_InternalParse;\n" + "object = msg->$2$_$3$();\n", + QualifiedClassName(field->message_type()), + field->is_repeated() ? "add" : "mutable", FieldName(field)); + } + format( + "if (size > end - ptr) goto len_delim_till_end;\n" + "auto newend = ptr + size;\n" + "bool ok = ctx->ParseExactRange({parser_till_end, object},\n" + " ptr, newend);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ok);\n" + "ptr = newend;\n"); + break; + } + default: + GOOGLE_LOG(FATAL) << "Illegal combination for length delimited wiretype " + << " filed type is " << field->type(); + } + } +} + void GenerateCaseBody(internal::WireFormatLite::WireType wiretype, const FieldDescriptor* field, const Options& options, MessageSCCAnalyzer* scc_analyzer, @@ -1185,10 +1373,11 @@ void GenerateCaseBody(internal::WireFormatLite::WireType wiretype, format( "$uint64$ val;\n" "ptr = Varint::Parse64(ptr, &val);\n" - "if (!ptr) goto error;\n"); + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n"); string type = PrimitiveTypeName(options, field->cpp_type()); - if (field->type() == FieldDescriptor::TYPE_SINT32 || - field->type() == FieldDescriptor::TYPE_SINT64) { + if ((field->type() == FieldDescriptor::TYPE_SINT32 || + field->type() == FieldDescriptor::TYPE_SINT64) && + !IsProto1(field->file(), options)) { int size = EstimateAlignmentSize(field) * 8; format( "$1$ value = " @@ -1232,149 +1421,17 @@ void GenerateCaseBody(internal::WireFormatLite::WireType wiretype, break; } case WireFormatLite::WIRETYPE_LENGTH_DELIMITED: { - format( - "ptr = Varint::Parse32Inline(ptr, &size);\n" - "if (!ptr) goto error;\n"); - if (!IsProto1(field->file(), options) && field->is_packable()) { - if (!HasPreservingUnknownEnumSemantics(field->file()) && - field->type() == FieldDescriptor::TYPE_ENUM) { - format( - "ctx->extra_parse_data().SetEnumValidator($1$_IsValid, " - "msg->mutable_unknown_fields(), $2$);\n" - "parser_till_end = " - "::$proto_ns$::internal::PackedValidEnumParser$3$;\n" - "object = msg->mutable_$4$();\n", - QualifiedClassName(field->enum_type()), field->number(), - UseUnknownFieldSet(field->file(), options) ? "" : "Lite", - FieldName(field)); - } else { - format( - "parser_till_end = ::$proto_ns$::internal::Packed$1$Parser;\n" - "object = msg->mutable_$2$();\n", - DeclaredTypeMethodName(field->type()), FieldName(field)); - } - } else { - auto field_type = field->type(); - if (IsProto1(field->file(), options)) { - if (field->is_packable()) { - // Sigh ... packed fields endup as a string in proto1 - field_type = FieldDescriptor::TYPE_BYTES; - } - if (field_type == FieldDescriptor::TYPE_STRING) { - // In proto1 strings are treated as bytes - field_type = FieldDescriptor::TYPE_BYTES; - } - } - string utf8 = ""; - switch (field_type) { - case FieldDescriptor::TYPE_STRING: - utf8 = GetUtf8Suffix(field, options); - if (!utf8.empty()) { - string name = "nullptr"; - if (HasDescriptorMethods(field->file(), options)) { - name = field->full_name(); - } - format("ctx->extra_parse_data().SetFieldName(\"$1$\");\n", name); - } - [[clang::fallthrough]]; - case FieldDescriptor::TYPE_BYTES: { - if (field->options().ctype() == FieldOptions::STRING || - (IsProto1(field->file(), options) && - field->options().ctype() == FieldOptions::STRING_PIECE)) { - format( - "parser_till_end = ::$proto_ns$::internal::StringParser$1$;\n" - "$string$* str = msg->$2$_$3$();\n" - "str->clear();\n", - utf8, - field->is_repeated() && !field->is_map() && - !field->is_packable() - ? "add" - : "mutable", - FieldName(field)); - } else if (field->options().ctype() == FieldOptions::CORD) { - string cord_parser = "CordParser" + utf8; - format( - "parser_till_end = ::$proto_ns$::internal::$1$;\n" - "auto* str = msg->$2$_$3$();\n" - "str->Clear();\n", - cord_parser, - field->is_repeated() && !field->is_map() ? "add" : "mutable", - FieldName(field)); - } else if (field->options().ctype() == FieldOptions::STRING_PIECE) { - format( - "parser_till_end = " - "::$proto_ns$::internal::StringPieceParser$1$;\n" - "::$proto_ns$::internal::StringPieceField* str = " - "msg->$2$_$3$();\n" - "str->Clear();\n", - utf8, - field->is_repeated() && !field->is_map() ? "add" : "mutable", - FieldName(field)); - } - format("object = str;\n"); - break; - } - case FieldDescriptor::TYPE_MESSAGE: { - GOOGLE_CHECK(field->message_type()); - if (IsImplicitWeakField(field, options, scc_analyzer)) { - if (!field->is_repeated()) { - format("object = HasBitSetters::mutable_$1$(msg);\n", - FieldName(field)); - } else { - format( - "object = " - "CastToBase(&msg->$1$_)->AddWeak(reinterpret_cast<const " - "::google::protobuf::MessageLite*>(&$2$::_$3$_default_instance_));\n", - FieldName(field), Namespace(field->message_type()), - ClassName(field->message_type())); - } - format( - "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" - "object)->_ParseFunc();\n"); - break; - } else if (IsWeak(field, options)) { - if (IsProto1(field->file(), options)) { - format("object = msg->internal_mutable_$1$();\n", - FieldName(field)); - } else { - format( - "object = msg->_weak_field_map_.MutableMessage($1$, " - "_$classname$_default_instance_.$2$_);\n", - field->number(), FieldName(field)); - } - format( - "parser_till_end = static_cast<::$proto_ns$::MessageLite*>(" - "object)->_ParseFunc();\n"); - break; - } - format( - "parser_till_end = $1$::_InternalParse;\n" - "object = msg->$2$_$3$();\n", - QualifiedClassName(field->message_type()), - field->is_repeated() && !field->is_map() ? "add" : "mutable", - FieldName(field)); - break; - } - default: - GOOGLE_LOG(FATAL) << "Illegal combination for length delimited wiretype " - << " filed type is " << field->type(); - } - } - format( - "if (size > end - ptr) goto len_delim_till_end;\n" - "auto newend = ptr + size;\n" - "if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) " - "goto error;\n" - "ptr = newend;\n"); + GenerateLengthDelim(field, options, scc_analyzer, format); break; } case WireFormatLite::WIRETYPE_START_GROUP: { format( "parser_till_end = $1$::_InternalParse;\n" "object = msg->$2$_$3$();\n" - "if (!ctx->PrepareGroup(tag, &depth)) goto error;\n" + "bool ok = ctx->PrepareGroup(tag, &depth);\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ok);\n" "ptr = parser_till_end(ptr, end, object, ctx);\n" - "if (!ptr) goto error;\n" + "$GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n" "if (ctx->GroupContinues(depth)) goto group_continues;\n", QualifiedClassName(field->message_type()), field->is_repeated() ? "add" : "mutable", FieldName(field)); @@ -1413,8 +1470,8 @@ void GenerateCaseBody(internal::WireFormatLite::WireType wiretype, uint64 mask = (1ull << (cnt * 8)) - 1; format.Outdent(); format( - "} while((*reinterpret_cast<const $uint64$*>(ptr) & $1$) == $2$ && " - "(ptr += $3$));\n", + "} while ((::$proto_ns$::io::UnalignedLoad<$uint64$>(ptr) & $1$) == " + "$2$ && (ptr += $3$));\n", mask, y, cnt); } format("break;\n"); @@ -1491,9 +1548,8 @@ void GenerateParserLoop(const Descriptor* descriptor, const Options& options, " while (ptr < end) {\n" " $uint32$ tag;\n" " ptr = Varint::Parse32Inline(ptr, &tag);\n" - " if (!ptr) goto error;\n" - " switch (tag >> 3) {\n" - " case 0: goto error;\n"); + " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ptr);\n" + " switch (tag >> 3) {\n"); format.Indent(); format.Indent(); @@ -1526,8 +1582,9 @@ void GenerateParserLoop(const Descriptor* descriptor, const Options& options, format( "default: {\n" "handle_unusual: (void)&&handle_unusual;\n" - " if ((tag & 7) == 4) {\n" - " if (!ctx->ValidEndGroup(tag)) goto error;\n" + " if ((tag & 7) == 4 || tag == 0) {\n" + " bool ok = ctx->ValidEndGroup(tag);\n" + " $GOOGLE_PROTOBUF$_PARSER_ASSERT(ok);\n" " return ptr;\n" " }\n"); if (IsMapEntryMessage(descriptor)) { @@ -1579,8 +1636,6 @@ void GenerateParserLoop(const Descriptor* descriptor, const Options& options, " } // switch\n" " } // while\n" " return ptr;\n" - "error:\n" - " return nullptr;\n" "len_delim_till_end: (void)&&len_delim_till_end;\n" " return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg},\n" " {parser_till_end, object}, size);\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index c01329fa..b8431aed 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -55,19 +55,16 @@ namespace protobuf { namespace compiler { namespace cpp { -inline string ProtobufNamespace(const Options& options) { +inline std::string ProtobufNamespace(const Options& options) { return options.opensource_runtime ? "google::protobuf" : "proto2"; } -inline string MacroPrefix(const Options& options) { +inline std::string MacroPrefix(const Options& options) { return options.opensource_runtime ? "GOOGLE_PROTOBUF" : "GOOGLE_PROTOBUF"; } -inline string DeprecatedAttribute(const Options& options, bool deprecated) { - if (!deprecated) { - return ""; - } - return MacroPrefix(options) + "_DEPRECATED "; +inline std::string DeprecatedAttribute(const Options& options, bool deprecated) { + return deprecated ? "PROTOBUF_DEPRECATED " : ""; } // Commonly-used separator comments. Thick is a line of '=', thin is a line @@ -79,35 +76,35 @@ inline bool IsProto1(const FileDescriptor* file, const Options& options) { return false; } -void SetCommonVars(const Options& options, std::map<string, string>* variables); +void SetCommonVars(const Options& options, std::map<std::string, std::string>* variables); -bool GetBootstrapBasename(const Options& options, const string& basename, - string* bootstrap_basename); +bool GetBootstrapBasename(const Options& options, const std::string& basename, + std::string* bootstrap_basename); bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context, - bool bootstrap_flag, string* basename); + bool bootstrap_flag, std::string* basename); bool IsBootstrapProto(const Options& options, const FileDescriptor* file); // Name space of the proto file. This namespace is such that the string // "<namespace>::some_name" is the correct fully qualified namespace. // This means if the package is empty the namespace is "", and otherwise // the namespace is "::foo::bar::...::baz" without trailing semi-colons. -string Namespace(const string& package); -inline string Namespace(const FileDescriptor* d) { +std::string Namespace(const std::string& package); +inline std::string Namespace(const FileDescriptor* d) { return Namespace(d->package()); } -string Namespace(const Descriptor* d); -string Namespace(const FieldDescriptor* d); -string Namespace(const EnumDescriptor* d); +std::string Namespace(const Descriptor* d); +std::string Namespace(const FieldDescriptor* d); +std::string Namespace(const EnumDescriptor* d); // Returns true if it's safe to reset "field" to zero. bool CanInitializeByZeroing(const FieldDescriptor* field); -string ClassName(const Descriptor* descriptor); -string ClassName(const EnumDescriptor* enum_descriptor); +std::string ClassName(const Descriptor* descriptor); +std::string ClassName(const EnumDescriptor* enum_descriptor); -string QualifiedClassName(const Descriptor* d); -string QualifiedClassName(const EnumDescriptor* d); +std::string QualifiedClassName(const Descriptor* d); +std::string QualifiedClassName(const EnumDescriptor* d); // DEPRECATED just use ClassName or QualifiedClassName, a boolean is very // unreadable at the callsite. @@ -119,33 +116,33 @@ string QualifiedClassName(const EnumDescriptor* d); // ::foo::bar::Baz_Qux // While the non-qualified version would be: // Baz_Qux -inline string ClassName(const Descriptor* descriptor, bool qualified) { +inline std::string ClassName(const Descriptor* descriptor, bool qualified) { return qualified ? QualifiedClassName(descriptor) : ClassName(descriptor); } -inline string ClassName(const EnumDescriptor* descriptor, bool qualified) { +inline std::string ClassName(const EnumDescriptor* descriptor, bool qualified) { return qualified ? QualifiedClassName(descriptor) : ClassName(descriptor); } // Fully qualified name of the default_instance of this message. -string DefaultInstanceName(const Descriptor* descriptor); +std::string DefaultInstanceName(const Descriptor* descriptor); // Returns the name of a no-op function that we can call to introduce a linker // dependency on the given message type. This is used to implement implicit weak // fields. -string ReferenceFunctionName(const Descriptor* descriptor); +std::string ReferenceFunctionName(const Descriptor* descriptor); // Name of the base class: google::protobuf::Message or google::protobuf::MessageLite. -string SuperClassName(const Descriptor* descriptor, const Options& options); +std::string SuperClassName(const Descriptor* descriptor, const Options& options); // Get the (unqualified) name that should be used for this field in C++ code. // The name is coerced to lower-case to emulate proto1 behavior. People // should be using lowercase-with-underscores style for proto field names // anyway, so normally this just returns field->name(). -string FieldName(const FieldDescriptor* field); +std::string FieldName(const FieldDescriptor* field); // Get the sanitized name that should be used for the given enum in C++ code. -string EnumValueName(const EnumValueDescriptor* enum_value); +std::string EnumValueName(const EnumValueDescriptor* enum_value); // Returns an estimate of the compiler's alignment for the field. This // can't guarantee to be correct because the generated code could be compiled on @@ -155,7 +152,7 @@ int EstimateAlignmentSize(const FieldDescriptor* field); // Get the unqualified name that should be used for a field's field // number constant. -string FieldConstantName(const FieldDescriptor *field); +std::string FieldConstantName(const FieldDescriptor *field); // Returns the scope where the field was defined (for extensions, this is // different from the message type to which the field applies). @@ -166,51 +163,51 @@ inline const Descriptor* FieldScope(const FieldDescriptor* field) { // Returns the fully-qualified type name field->message_type(). Usually this // is just ClassName(field->message_type(), true); -string FieldMessageTypeName(const FieldDescriptor* field); +std::string FieldMessageTypeName(const FieldDescriptor* field); // Strips ".proto" or ".protodevel" from the end of a filename. -LIBPROTOC_EXPORT string StripProto(const string& filename); +PROTOC_EXPORT std::string StripProto(const std::string& filename); // Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.). const char* PrimitiveTypeName(FieldDescriptor::CppType type); -string PrimitiveTypeName(const Options& options, FieldDescriptor::CppType type); +std::string PrimitiveTypeName(const Options& options, FieldDescriptor::CppType type); // Get the declared type name in CamelCase format, as is used e.g. for the // methods of WireFormat. For example, TYPE_INT32 becomes "Int32". const char* DeclaredTypeMethodName(FieldDescriptor::Type type); // Return the code that evaluates to the number when compiled. -string Int32ToString(int number); +std::string Int32ToString(int number); // Return the code that evaluates to the number when compiled. -string Int64ToString(const Options& options, int64 number); +std::string Int64ToString(const Options& options, int64 number); // Get code that evaluates to the field's default value. -string DefaultValue(const Options& options, const FieldDescriptor* field); +std::string DefaultValue(const Options& options, const FieldDescriptor* field); // Compatibility function for callers outside proto2. -string DefaultValue(const FieldDescriptor* field); +std::string DefaultValue(const FieldDescriptor* field); // Convert a file name into a valid identifier. -string FilenameIdentifier(const string& filename); +std::string FilenameIdentifier(const std::string& filename); // For each .proto file generates a unique name. To prevent collisions of // symbols in the global namespace -string UniqueName(const string& name, const string& filename, +std::string UniqueName(const std::string& name, const std::string& filename, const Options& options); -inline string UniqueName(const string& name, const FileDescriptor* d, +inline std::string UniqueName(const std::string& name, const FileDescriptor* d, const Options& options) { return UniqueName(name, d->name(), options); } -inline string UniqueName(const string& name, const Descriptor* d, +inline std::string UniqueName(const std::string& name, const Descriptor* d, const Options& options) { return UniqueName(name, d->file(), options); } -inline string UniqueName(const string& name, const EnumDescriptor* d, +inline std::string UniqueName(const std::string& name, const EnumDescriptor* d, const Options& options) { return UniqueName(name, d->file(), options); } -inline string UniqueName(const string& name, const ServiceDescriptor* d, +inline std::string UniqueName(const std::string& name, const ServiceDescriptor* d, const Options& options) { return UniqueName(name, d->file(), options); } @@ -222,32 +219,32 @@ inline Options InternalRuntimeOptions() { options.opensource_runtime = false; return options; } -inline string UniqueName(const string& name, const string& filename) { +inline std::string UniqueName(const std::string& name, const std::string& filename) { return UniqueName(name, filename, InternalRuntimeOptions()); } -inline string UniqueName(const string& name, const FileDescriptor* d) { +inline std::string UniqueName(const std::string& name, const FileDescriptor* d) { return UniqueName(name, d->name(), InternalRuntimeOptions()); } -inline string UniqueName(const string& name, const Descriptor* d) { +inline std::string UniqueName(const std::string& name, const Descriptor* d) { return UniqueName(name, d->file(), InternalRuntimeOptions()); } -inline string UniqueName(const string& name, const EnumDescriptor* d) { +inline std::string UniqueName(const std::string& name, const EnumDescriptor* d) { return UniqueName(name, d->file(), InternalRuntimeOptions()); } -inline string UniqueName(const string& name, const ServiceDescriptor* d) { +inline std::string UniqueName(const std::string& name, const ServiceDescriptor* d) { return UniqueName(name, d->file(), InternalRuntimeOptions()); } // Return the qualified C++ name for a file level symbol. -string QualifiedFileLevelSymbol(const string& package, const string& name); +std::string QualifiedFileLevelSymbol(const std::string& package, const std::string& name); // Escape C++ trigraphs by escaping question marks to \? -string EscapeTrigraphs(const string& to_escape); +std::string EscapeTrigraphs(const std::string& to_escape); // Escaped function name to eliminate naming conflict. -string SafeFunctionName(const Descriptor* descriptor, +std::string SafeFunctionName(const Descriptor* descriptor, const FieldDescriptor* field, - const string& prefix); + const std::string& prefix); // Returns true if generated messages have public unknown fields accessors inline bool PublicUnknownFieldsAccessors(const Descriptor* message) { @@ -355,6 +352,8 @@ inline bool HasFastArraySerialization(const FileDescriptor* file, inline bool IsProto2MessageSet(const Descriptor* descriptor, const Options& options) { return !options.opensource_runtime && + !options.enforce_lite && + !options.lite_implicit_weak_fields && descriptor->options().message_set_wire_format() && descriptor->full_name() == "google.protobuf.bridge.MessageSet"; } @@ -362,6 +361,8 @@ inline bool IsProto2MessageSet(const Descriptor* descriptor, inline bool IsProto2MessageSetFile(const FileDescriptor* file, const Options& options) { return !options.opensource_runtime && + !options.enforce_lite && + !options.lite_implicit_weak_fields && file->name() == "net/proto2/bridge/proto/message_set.proto"; } @@ -372,7 +373,7 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) { // Returns true if the field's CPPTYPE is string or message. bool IsStringOrMessage(const FieldDescriptor* field); -string UnderscoresToCamelCase(const string& input, bool cap_next_letter); +std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter); inline bool HasFieldPresence(const FileDescriptor* file) { return file->syntax() != FileDescriptor::SYNTAX_PROTO3; @@ -401,11 +402,11 @@ inline bool IsCrossFileMessage(const FieldDescriptor* field) { field->message_type()->file() != field->file(); } -inline string MessageCreateFunction(const Descriptor* d) { +inline std::string MessageCreateFunction(const Descriptor* d) { return SupportsArenas(d) ? "CreateMessage" : "Create"; } -inline string MakeDefaultName(const FieldDescriptor* field) { +inline std::string MakeDefaultName(const FieldDescriptor* field) { return "_i_give_permission_to_break_this_code_default_" + FieldName(field) + "_"; } @@ -455,7 +456,7 @@ struct MessageAnalysis { // quadratic performance, if we do this per message we would get O(V*(V+E)). // Logically this is just only used in message.cc, but in the header for // FileGenerator to help share it. -class LIBPROTOC_EXPORT MessageSCCAnalyzer { +class PROTOC_EXPORT MessageSCCAnalyzer { public: explicit MessageSCCAnalyzer(const Options& options) : options_(options) {} @@ -528,18 +529,18 @@ bool IsImplicitWeakField(const FieldDescriptor* field, const Options& options, // "__declspec(export) void fun();" // // which is convenient to prevent double, leading or trailing spaces. -class LIBPROTOC_EXPORT Formatter { +class PROTOC_EXPORT Formatter { public: explicit Formatter(io::Printer* printer) : printer_(printer) {} - Formatter(io::Printer* printer, const std::map<string, string>& vars) + Formatter(io::Printer* printer, const std::map<std::string, std::string>& vars) : printer_(printer), vars_(vars) {} template <typename T> - void Set(const string& key, const T& value) { + void Set(const std::string& key, const T& value) { vars_[key] = ToString(value); } - void AddMap(const std::map<string, string>& vars) { + void AddMap(const std::map<std::string, std::string>& vars) { for (const auto& keyval : vars) vars_[keyval.first] = keyval.second; } @@ -552,7 +553,7 @@ class LIBPROTOC_EXPORT Formatter { void Outdent() const { printer_->Outdent(); } io::Printer* printer() const { return printer_; } - class LIBPROTOC_EXPORT SaveState { + class PROTOC_EXPORT SaveState { public: explicit SaveState(Formatter* format) : format_(format), vars_(format->vars_) {} @@ -560,28 +561,28 @@ class LIBPROTOC_EXPORT Formatter { private: Formatter* format_; - std::map<string, string> vars_; + std::map<std::string, std::string> vars_; }; private: io::Printer* printer_; - std::map<string, string> vars_; + std::map<std::string, std::string> vars_; // Convenience overloads to accept different types as arguments. - static string ToString(const string& s) { return s; } + static std::string ToString(const std::string& s) { return s; } template <typename I, typename = typename std::enable_if< std::is_integral<I>::value>::type> - static string ToString(I x) { + static std::string ToString(I x) { return SimpleItoa(x); } - static string ToString(strings::Hex x) { return StrCat(x); } - static string ToString(const FieldDescriptor* d) { return Payload(d); } - static string ToString(const Descriptor* d) { return Payload(d); } - static string ToString(const EnumDescriptor* d) { return Payload(d); } - static string ToString(const EnumValueDescriptor* d) { return Payload(d); } + static std::string ToString(strings::Hex x) { return StrCat(x); } + static std::string ToString(const FieldDescriptor* d) { return Payload(d); } + static std::string ToString(const Descriptor* d) { return Payload(d); } + static std::string ToString(const EnumDescriptor* d) { return Payload(d); } + static std::string ToString(const EnumValueDescriptor* d) { return Payload(d); } template <typename Descriptor> - static string Payload(const Descriptor* descriptor) { + static std::string Payload(const Descriptor* descriptor) { std::vector<int> path; descriptor->GetLocationPath(&path); GeneratedCodeInfo::Annotation annotation; @@ -593,18 +594,18 @@ class LIBPROTOC_EXPORT Formatter { } }; -class LIBPROTOC_EXPORT NamespaceOpener { +class PROTOC_EXPORT NamespaceOpener { public: explicit NamespaceOpener(const Formatter& format) : printer_(format.printer()) {} - NamespaceOpener(const string& name, const Formatter& format) + NamespaceOpener(const std::string& name, const Formatter& format) : NamespaceOpener(format) { ChangeTo(name); } ~NamespaceOpener() { ChangeTo(""); } - void ChangeTo(const string& name) { - std::vector<string> new_stack_ = + void ChangeTo(const std::string& name) { + std::vector<std::string> new_stack_ = Split(name, "::", true); int len = std::min(name_stack_.size(), new_stack_.size()); int common_idx = 0; @@ -623,10 +624,10 @@ class LIBPROTOC_EXPORT NamespaceOpener { private: io::Printer* printer_; - std::vector<string> name_stack_; + std::vector<std::string> name_stack_; }; -string GetUtf8Suffix(const FieldDescriptor* field, const Options& options); +std::string GetUtf8Suffix(const FieldDescriptor* field, const Options& options); void GenerateUtf8CheckCodeForString(const FieldDescriptor* field, const Options& options, bool for_parse, const char* parameters, diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc index 4ab407d2..3114bbf7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -177,54 +177,49 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { descriptor_->message_type()->FindFieldByName("key"); const FieldDescriptor* value_field = descriptor_->message_type()->FindFieldByName("value"); - bool using_entry = false; string key; string value; + format( + "$map_classname$::Parser< ::$proto_ns$::internal::MapField$lite$<\n" + " $map_classname$,\n" + " $key_cpp$, $val_cpp$,\n" + " ::$proto_ns$::internal::WireFormatLite::$key_wire_type$,\n" + " ::$proto_ns$::internal::WireFormatLite::$val_wire_type$,\n" + " $default_enum_value$ >,\n" + " ::$proto_ns$::Map< $key_cpp$, $val_cpp$ > >" + " parser(&$name$_);\n"); if (IsProto3Field(descriptor_) || value_field->type() != FieldDescriptor::TYPE_ENUM) { format( - "$map_classname$::Parser< ::$proto_ns$::internal::MapField$lite$<\n" - " $map_classname$,\n" - " $key_cpp$, $val_cpp$,\n" - " ::$proto_ns$::internal::WireFormatLite::$key_wire_type$,\n" - " ::$proto_ns$::internal::WireFormatLite::$val_wire_type$,\n" - " $default_enum_value$ >,\n" - " ::$proto_ns$::Map< $key_cpp$, $val_cpp$ > >" - " parser(&$name$_);\n" "DO_(::$proto_ns$::internal::WireFormatLite::ReadMessageNoVirtual(\n" " input, &parser));\n"); key = "parser.key()"; value = "parser.value()"; } else { - using_entry = true; key = "entry->key()"; value = "entry->value()"; - format("::std::unique_ptr<$map_classname$> entry($name$_.NewEntry());\n"); + format("auto entry = parser.NewEntry();\n"); format( - "{\n" - " ::std::string data;\n" - " DO_(::$proto_ns$::internal::WireFormatLite::ReadString(input, " + "::std::string data;\n" + "DO_(::$proto_ns$::internal::WireFormatLite::ReadString(input, " "&data));\n" - " DO_(entry->ParseFromString(data));\n" - " if ($val_cpp$_IsValid(*entry->mutable_value())) {\n" - " (*mutable_$name$())[entry->key()] =\n" - " static_cast< $val_cpp$ >(*entry->mutable_value());\n" - " } else {\n"); + "DO_(entry->ParseFromString(data));\n" + "if ($val_cpp$_IsValid(*entry->mutable_value())) {\n" + " (*mutable_$name$())[entry->key()] =\n" + " static_cast< $val_cpp$ >(*entry->mutable_value());\n" + "} else {\n"); if (HasDescriptorMethods(descriptor_->file(), options_)) { format( - " mutable_unknown_fields()" + " mutable_unknown_fields()" "->AddLengthDelimited($number$, data);\n"); } else { format( - " unknown_fields_stream.WriteVarint32($tag$u);\n" - " unknown_fields_stream.WriteVarint32(\n" - " static_cast< ::google::protobuf::uint32>(data.size()));\n" - " unknown_fields_stream.WriteString(data);\n"); + " unknown_fields_stream.WriteVarint32($tag$u);\n" + " unknown_fields_stream.WriteVarint32(\n" + " static_cast< ::google::protobuf::uint32>(data.size()));\n" + " unknown_fields_stream.WriteString(data);\n"); } - - format( - " }\n" - "}\n"); + format("}\n"); } if (key_field->type() == FieldDescriptor::TYPE_STRING) { @@ -242,11 +237,6 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { .data(), format); } - - // If entry is allocated by arena, its desctructor should be avoided. - if (using_entry && SupportsArenas(descriptor_)) { - format("if (entry->GetArena() != NULL) entry.release();\n"); - } } static void GenerateSerializationLoop(const Formatter& format, diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index e219d784..4af54032 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -554,7 +554,7 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_bit_index, } // Emit has_bit check for each has_bit_dword index. - format("if ($GOOGLE_PROTOBUF$_PREDICT_FALSE("); + format("if (PROTOBUF_PREDICT_FALSE("); int first_word = HasbitWord(chunk, 0); while (chunk < limit_chunk_) { uint32 mask = 0; @@ -940,8 +940,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { " $default_enum_value$ > {\n" "public:\n" "#if $GOOGLE_PROTOBUF$_ENABLE_EXPERIMENTAL_PARSER\n" - " static const char* _InternalParse(const char* begin, const char* " - "end, void* object, ::$proto_ns$::internal::ParseContext* ctx);\n" + "static bool _ParseMap(const char* begin, const " + "char* end, void* object, ::google::protobuf::internal::ParseContext* ctx);\n" "#endif // $GOOGLE_PROTOBUF$_ENABLE_EXPERIMENTAL_PARSER\n" " typedef ::$proto_ns$::internal::MapEntry$lite$<$classname$, \n" " $key_cpp$, $val_cpp$,\n" @@ -1514,23 +1514,17 @@ bool MessageGenerator::GenerateParseTable(io::Printer* printer, size_t offset, // If we don't have field presence, then _has_bits_ does not exist. format("-1,\n"); } else { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(\n" - " $classtype$, _has_bits_),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _has_bits_),\n"); } if (descriptor_->oneof_decl_count() > 0) { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(\n" - " $classtype$, _oneof_case_),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_),\n"); } else { format("-1, // no _oneof_case_\n"); } if (descriptor_->extension_range_count() > 0) { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_extensions_),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _extensions_),\n"); } else { format("-1, // no _extensions_\n"); } @@ -1538,8 +1532,7 @@ bool MessageGenerator::GenerateParseTable(io::Printer* printer, size_t offset, // TODO(ckennelly): Consolidate this with the calculation for // AuxillaryParseTableField. format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(\n" - " $classtype$, _internal_metadata_),\n" + "PROTOBUF_FIELD_OFFSET($classtype$, _internal_metadata_),\n" "&$package_ns$::_$classname$_default_instance_,\n"); if (UseUnknownFieldSet(descriptor_->file(), options_)) { @@ -1650,10 +1643,10 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { Formatter::SaveState saver(&format); format.AddMap(vars); format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(" + "{PROTOBUF_FIELD_OFFSET(" "::$proto_ns$::internal::MapEntryHelper<$classtype$::" "SuperType>, $field_name$_), $tag$," - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(" + "PROTOBUF_FIELD_OFFSET(" "::$proto_ns$::internal::MapEntryHelper<$classtype$::" "SuperType>, _has_bits_) * 8 + $hasbit$, $type$, " "$ptr$},\n"); @@ -1661,8 +1654,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { return 2; } format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_cached_size_), 0, 0, 0, NULL},\n"); + "{PROTOBUF_FIELD_OFFSET($classtype$, _cached_size_), 0, 0, 0, NULL},\n"); std::vector<const Descriptor::ExtensionRange*> sorted_extensions; for (int i = 0; i < descriptor_->extension_range_count(); ++i) { sorted_extensions.push_back(descriptor_->extension_range(i)); @@ -1677,8 +1669,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { const Descriptor::ExtensionRange* range = sorted_extensions[extension_idx]; format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_extensions_), " + "{PROTOBUF_FIELD_OFFSET($classtype$, _extensions_), " "$1$, $2$, ::$proto_ns$::internal::FieldMetadata::kSpecial, " "reinterpret_cast<const " "void*>(::$proto_ns$::internal::ExtensionSerializer)},\n", @@ -1703,8 +1694,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { if (IsMapEntryMessage(field->message_type())) { format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($" - "classtype$, $field_name$_), $1$, $2$, " + "{PROTOBUF_FIELD_OFFSET($classtype$, $field_name$_), $1$, $2$, " "::$proto_ns$::internal::FieldMetadata::kSpecial, " "reinterpret_cast<const void*>(static_cast< " "::$proto_ns$::internal::SpecialSerializer>(" @@ -1745,7 +1735,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { if (field->options().weak()) { // TODO(gerbens) merge weak fields into ranges format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(" + "{PROTOBUF_FIELD_OFFSET(" "$classtype$, _weak_field_map_), $1$, $1$, " "::$proto_ns$::internal::FieldMetadata::kSpecial, " "reinterpret_cast<const " @@ -1755,24 +1745,21 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { format.Set("oneofoffset", sizeof(uint32) * field->containing_oneof()->index()); format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "$field_name$_), " - "$1$, $GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_oneof_case_) + $oneofoffset$, $2$, $3$},\n", + "{PROTOBUF_FIELD_OFFSET($classtype$, $field_name$_), $1$," + " PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_) + " + "$oneofoffset$, $2$, $3$},\n", tag, type, ptr); } else if (HasFieldPresence(descriptor_->file()) && has_bit_indices_[field->index()] != -1) { format.Set("hasbitsoffset", has_bit_indices_[field->index()]); format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "$field_name$_), " - "$1$, $GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_has_bits_) * 8 + $hasbitsoffset$, $2$, $3$},\n", + "{PROTOBUF_FIELD_OFFSET($classtype$, $field_name$_), " + "$1$, PROTOBUF_FIELD_OFFSET($classtype$, _has_bits_) * 8 + " + "$hasbitsoffset$, $2$, $3$},\n", tag, type, ptr); } else { format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "$field_name$_), " + "{PROTOBUF_FIELD_OFFSET($classtype$, $field_name$_), " "$1$, ~0u, $2$, $3$},\n", tag, type, ptr); } @@ -1783,8 +1770,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { ? "UnknownFieldSetSerializer" : "UnknownFieldSerializerLite"; format( - "{$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_internal_metadata_), 0, ~0u, " + "{PROTOBUF_FIELD_OFFSET($classtype$, _internal_metadata_), 0, ~0u, " "::$proto_ns$::internal::FieldMetadata::kSpecial, reinterpret_cast<const " "void*>(::$proto_ns$::internal::$1$)},\n", serializer); @@ -1876,12 +1862,62 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { "}\n" "\n"); } - // TODO(gerbens) make maps parse :( format( "#if $GOOGLE_PROTOBUF$_ENABLE_EXPERIMENTAL_PARSER\n" - "const char* $classname$::_InternalParse(const char* begin, const " - "char* end, void* object, ::$proto_ns$::internal::ParseContext* ctx) { " - "return end; }\n" + "bool $classname$::_ParseMap(const char* begin, const " + "char* end, void* object, ::google::protobuf::internal::ParseContext* ctx) {\n" + " using MF = ::$proto_ns$::internal::MapField$1$<\n" + " $classname$, EntryKeyType, EntryValueType,\n" + " kEntryKeyFieldType, kEntryValueFieldType,\n" + " kEntryDefaultEnumValue>;\n" + " auto mf = static_cast<MF*>(object);\n" + " Parser<MF, ::$proto_ns$::Map<EntryKeyType, EntryValueType>> " + "parser(mf);\n" + "#define DO_(x) if (!(x)) return false\n", + HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite"); + const FieldDescriptor* key = descriptor_->FindFieldByName("key"); + const FieldDescriptor* val = descriptor_->FindFieldByName("value"); + GOOGLE_CHECK(val); + string key_string; + string value_string; + if (HasFieldPresence(descriptor_->file()) && + val->type() == FieldDescriptor::TYPE_ENUM) { + format( + " DO_(parser.ParseMapEnumValidation(\n" + " begin, end, ctx->extra_parse_data().field_number,\n" + " static_cast<::google::protobuf::internal::InternalMetadataWithArena$1$*>(" + "ctx->extra_parse_data().unknown_fields), $2$_IsValid));\n", + HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite", + QualifiedClassName(val->enum_type())); + key_string = "parser.entry_key()"; + value_string = "parser.entry_value()"; + } else { + format(" DO_(parser.ParseMap(begin, end));\n"); + key_string = "parser.key()"; + value_string = "parser.value()"; + } + format.Indent(); + if (key->type() == FieldDescriptor::TYPE_STRING) { + GenerateUtf8CheckCodeForString( + key, options_, true, + StrCat(key_string, ".data(), static_cast<int>(", key_string, + ".length()),\n") + .data(), + format); + } + if (val->type() == FieldDescriptor::TYPE_STRING) { + GenerateUtf8CheckCodeForString( + val, options_, true, + StrCat(value_string, ".data(), static_cast<int>(", value_string, + ".length()),\n") + .data(), + format); + } + format.Outdent(); + format( + "#undef DO_\n" + " return true;\n" + "}\n" "#endif // $GOOGLE_PROTOBUF$_ENABLE_EXPERIMENTAL_PARSER\n"); format("\n"); return; @@ -2138,8 +2174,7 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) { format( "{\n" - " $GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(\n" - " $classtype$, $name$_),\n" + " PROTOBUF_FIELD_OFFSET($classtype$, $name$_),\n" " static_cast<$uint32$>($presence$),\n" " $nwtype$, $pwtype$, $ptype$, $tag_size$\n" "},\n"); @@ -2236,33 +2271,23 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets( Formatter format(printer, variables_); if (HasFieldPresence(descriptor_->file()) || IsMapEntryMessage(descriptor_)) { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_has_bits_),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _has_bits_),\n"); } else { format("~0u, // no _has_bits_\n"); } - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_internal_metadata_),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _internal_metadata_),\n"); if (descriptor_->extension_range_count() > 0) { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, " - "_extensions_),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _extensions_),\n"); } else { format("~0u, // no _extensions_\n"); } if (descriptor_->oneof_decl_count() > 0) { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET(" - "$classtype$, _oneof_case_[0]),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_[0]),\n"); } else { format("~0u, // no _oneof_case_\n"); } if (num_weak_fields_ > 0) { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$," - " _weak_field_map_),\n"); + format("PROTOBUF_FIELD_OFFSET($classtype$, _weak_field_map_),\n"); } else { format("~0u, // no _weak_field_map_\n"); } @@ -2275,9 +2300,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets( format("offsetof($classtype$DefaultTypeInternal, $1$_)", FieldName(field)); } else { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, $1$_)", - FieldName(field)); + format("PROTOBUF_FIELD_OFFSET($classtype$, $1$_)", FieldName(field)); } uint32 tag = field_generators_.get(field).CalculateFieldTag(); @@ -2289,9 +2312,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets( } for (auto oneof : OneOfRange(descriptor_)) { - format( - "$GOOGLE_PROTOBUF$_GENERATED_MESSAGE_FIELD_OFFSET($classtype$, $1$_),\n", - oneof->name()); + format("PROTOBUF_FIELD_OFFSET($classtype$, $1$_),\n", oneof->name()); } if (IsMapEntryMessage(descriptor_)) { @@ -2687,7 +2708,7 @@ void MessageGenerator::GenerateSourceInProto2Namespace(io::Printer* printer) { Formatter format(printer, variables_); format( "template<> " - "$GOOGLE_PROTOBUF$_ATTRIBUTE_NOINLINE " + "PROTOBUF_NOINLINE " "$classtype$* Arena::CreateMaybeMessage< $classtype$ >(Arena* arena) {\n" " return Arena::$1$Internal< $classtype$ >(arena);\n" "}\n", @@ -3334,8 +3355,9 @@ void MessageGenerator::GenerateMergeFromCodedStream(io::Printer* printer) { "const char* $classname$::_InternalParse(const char* begin, const " "char* end, void* object,\n" " ::$proto_ns$::internal::ParseContext* ctx) {\n" + " auto msg = static_cast<$classname$*>(object);\n" " return ::$proto_ns$::internal::ParseMessageSet(begin, end, " - "static_cast<$classname$*>(object), ctx);\n" + "msg, &msg->_extensions_, &msg->_internal_metadata_, ctx);\n" "}\n" "const char* $classname$::InternalParseMessageSetItem(const char* " "begin, const char* end, void* object,\n" @@ -3396,7 +3418,7 @@ void MessageGenerator::GenerateMergeFromCodedStream(io::Printer* printer) { format( "#define DO_(EXPRESSION) if " - "(!$GOOGLE_PROTOBUF$_PREDICT_TRUE(EXPRESSION)) goto failure\n" + "(!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure\n" " $uint32$ tag;\n"); if (!UseUnknownFieldSet(descriptor_->file(), options_)) { @@ -3801,11 +3823,12 @@ void MessageGenerator::GenerateSerializeWithCachedSizesToArray( " target = _extensions_." "InternalSerializeMessageSetWithCachedSizesToArray(\n" " deterministic, target);\n"); + GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_)); std::map<string, string> vars; SetUnknkownFieldsVariable(descriptor_, options_, &vars); format.AddMap(vars); format( - " target = ::$proto_ns$::internal::\n" + " target = ::$proto_ns$::internal::WireFormat::\n" " SerializeUnknownMessageSetItemsToArray(\n" " $unknown_fields$, target);\n"); format( diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h index 170a70cd..6bef8d56 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/src/google/protobuf/compiler/cpp/cpp_message.h @@ -63,7 +63,7 @@ class MessageGenerator { public: // See generator.cc for the meaning of dllexport_decl. MessageGenerator(const Descriptor* descriptor, - const std::map<string, string>& vars, + const std::map<std::string, std::string>& vars, int index_in_file_messages, const Options& options, MessageSCCAnalyzer* scc_analyzer); ~MessageGenerator(); @@ -194,7 +194,7 @@ class MessageGenerator { const Descriptor* descriptor_; int index_in_file_messages_; - string classname_; + std::string classname_; Options options_; FieldGeneratorMap field_generators_; // optimized_order_ is the order we layout the message's fields in the @@ -216,7 +216,7 @@ class MessageGenerator { MessageSCCAnalyzer* scc_analyzer_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; friend class FileGenerator; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); diff --git a/src/google/protobuf/compiler/cpp/cpp_options.h b/src/google/protobuf/compiler/cpp/cpp_options.h index 6a364deb..84c18622 100644 --- a/src/google/protobuf/compiler/cpp/cpp_options.h +++ b/src/google/protobuf/compiler/cpp/cpp_options.h @@ -35,7 +35,6 @@ #include <string> -#include <google/protobuf/stubs/common.h> namespace google { namespace protobuf { namespace compiler { @@ -45,7 +44,7 @@ namespace cpp { // Generator options (see generator.cc for a description of each): struct Options { - string dllexport_decl; + std::string dllexport_decl; bool safe_boundary_check = false; bool proto_h = false; bool transitive_pb_h = true; @@ -58,8 +57,8 @@ struct Options { bool opensource_runtime = false; bool opensource_include_paths = false; int num_cc_files = 0; - string annotation_pragma_name; - string annotation_guard_name; + std::string annotation_pragma_name; + std::string annotation_guard_name; const AccessInfoMap* access_info_map = nullptr; }; diff --git a/src/google/protobuf/compiler/cpp/cpp_service.h b/src/google/protobuf/compiler/cpp/cpp_service.h index 3acbe637..2952e413 100644 --- a/src/google/protobuf/compiler/cpp/cpp_service.h +++ b/src/google/protobuf/compiler/cpp/cpp_service.h @@ -57,7 +57,7 @@ class ServiceGenerator { public: // See generator.cc for the meaning of dllexport_decl. explicit ServiceGenerator(const ServiceDescriptor* descriptor, - const std::map<string, string>& vars, + const std::map<std::string, std::string>& vars, const Options& options); ~ServiceGenerator(); @@ -109,7 +109,7 @@ class ServiceGenerator { void GenerateStubMethods(io::Printer* printer); const ServiceDescriptor* descriptor_; - std::map<string, string> vars_; + std::map<std::string, std::string> vars_; int index_in_metadata_; diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.inc b/src/google/protobuf/compiler/cpp/cpp_unittest.inc index 0604731f..898b1fbb 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.inc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.inc @@ -78,6 +78,8 @@ #include <google/protobuf/stubs/casts.h> #include <google/protobuf/stubs/stl_util.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -203,7 +205,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, ExtremeSmallIntegerDefault) { const UNITTEST::TestExtremeDefaultValues& extreme_default = UNITTEST::TestExtremeDefaultValues::default_instance(); EXPECT_EQ(~0x7fffffff, kint32min); - EXPECT_EQ(GOOGLE_LONGLONG(~0x7fffffffffffffff), kint64min); + EXPECT_EQ(PROTOBUF_LONGLONG(~0x7fffffffffffffff), kint64min); EXPECT_EQ(kint32min, extreme_default.really_small_int32()); EXPECT_EQ(kint64min, extreme_default.really_small_int64()); } @@ -656,7 +658,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, CopyAssignmentOperator) { TestUtil::ExpectAllFieldsSet(message2); } -#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || GOOGLE_PROTOBUF_RTTI +#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || PROTOBUF_RTTI TEST(GENERATED_MESSAGE_TEST_NAME, UpcastCopyFrom) { // Test the CopyFrom method that takes in the generic const Message& // parameter. @@ -2267,3 +2269,5 @@ TEST(DESCRIPTOR_INIT_TEST_NAME, Initialized) { } // namespace compiler } // namespace protobuf } // namespace google + +#include <google/protobuf/port_undef.inc> diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.h b/src/google/protobuf/compiler/csharp/csharp_generator.h index c8b19529..dc7319b1 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator.h +++ b/src/google/protobuf/compiler/csharp/csharp_generator.h @@ -37,6 +37,8 @@ #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -46,9 +48,9 @@ namespace csharp { // header. If you create your own protocol compiler binary and you want // it to support C# output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator +class PROTOC_EXPORT Generator : public google::protobuf::compiler::CodeGenerator { -public: + public: virtual bool Generate( const FileDescriptor* file, const string& parameter, @@ -61,4 +63,6 @@ public: } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index 8dd265bc..ec0b1c77 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -42,6 +42,8 @@ #include <google/protobuf/compiler/code_generator.h> #include <google/protobuf/io/printer.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -96,7 +98,8 @@ std::string UnderscoresToPascalCase(const std::string& input); // Note that we wouldn't normally want to export this (we're not expecting // it to be used outside libprotoc itself) but this exposes it for testing. -std::string LIBPROTOC_EXPORT GetEnumValueName(const std::string& enum_name, const std::string& enum_value_name); +std::string PROTOC_EXPORT GetEnumValueName(const std::string& enum_name, + const std::string& enum_value_name); // TODO(jtattermusch): perhaps we could move this to strutil std::string StringToBase64(const std::string& input); @@ -145,4 +148,7 @@ inline bool IsWrapperType(const FieldDescriptor* descriptor) { } // namespace compiler } // namespace protobuf } // namespace google + +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__ diff --git a/src/google/protobuf/compiler/csharp/csharp_names.h b/src/google/protobuf/compiler/csharp/csharp_names.h index 21758f28..87a16515 100644 --- a/src/google/protobuf/compiler/csharp/csharp_names.h +++ b/src/google/protobuf/compiler/csharp/csharp_names.h @@ -41,6 +41,8 @@ #include <string> #include <google/protobuf/stubs/port.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -57,14 +59,14 @@ namespace csharp { // // Returns: // The namespace to use for given file descriptor. -string LIBPROTOC_EXPORT GetFileNamespace(const FileDescriptor* descriptor); +string PROTOC_EXPORT GetFileNamespace(const FileDescriptor* descriptor); // Requires: // descriptor != NULL // // Returns: // The fully-qualified C# class name. -string LIBPROTOC_EXPORT GetClassName(const Descriptor* descriptor); +string PROTOC_EXPORT GetClassName(const Descriptor* descriptor); // Requires: // descriptor != NULL @@ -73,7 +75,7 @@ string LIBPROTOC_EXPORT GetClassName(const Descriptor* descriptor); // The fully-qualified name of the C# class that provides // access to the file descriptor. Proto compiler generates // such class for each .proto file processed. -string LIBPROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor); +string PROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor); // Generates output file name for given file descriptor. If generate_directories // is true, the output file will be put under directory corresponding to file's @@ -89,16 +91,16 @@ string LIBPROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor) // The file name to use as output file for given file descriptor. In case // of failure, this function will return empty string and error parameter // will contain the error message. -string LIBPROTOC_EXPORT GetOutputFile( - const google::protobuf::FileDescriptor* descriptor, - const string file_extension, - const bool generate_directories, - const string base_namespace, - string* error); +string PROTOC_EXPORT +GetOutputFile(const google::protobuf::FileDescriptor* descriptor, + const string file_extension, const bool generate_directories, + const string base_namespace, string* error); } // namespace csharp } // namespace compiler } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ diff --git a/src/google/protobuf/compiler/importer.h b/src/google/protobuf/compiler/importer.h index 5f279078..cf6b0123 100644 --- a/src/google/protobuf/compiler/importer.h +++ b/src/google/protobuf/compiler/importer.h @@ -45,6 +45,8 @@ #include <google/protobuf/descriptor_database.h> #include <google/protobuf/compiler/parser.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -73,7 +75,7 @@ class DiskSourceTree; // // Note: This class does not implement FindFileContainingSymbol() or // FindFileContainingExtension(); these will always return false. -class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase { +class PROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase { public: SourceTreeDescriptorDatabase(SourceTree* source_tree); ~SourceTreeDescriptorDatabase(); @@ -96,11 +98,11 @@ class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabas } // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, + bool FindFileByName(const std::string& filename, FileDescriptorProto* output) override; - bool FindFileContainingSymbol(const string& symbol_name, + bool FindFileContainingSymbol(const std::string& symbol_name, FileDescriptorProto* output) override; - bool FindFileContainingExtension(const string& containing_type, + bool FindFileContainingExtension(const std::string& containing_type, int field_number, FileDescriptorProto* output) override; @@ -110,19 +112,20 @@ class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabas SourceTree* source_tree_; MultiFileErrorCollector* error_collector_; - class LIBPROTOBUF_EXPORT ValidationErrorCollector : public DescriptorPool::ErrorCollector { + class PROTOBUF_EXPORT ValidationErrorCollector + : public DescriptorPool::ErrorCollector { public: ValidationErrorCollector(SourceTreeDescriptorDatabase* owner); ~ValidationErrorCollector(); // implements ErrorCollector --------------------------------------- - void AddError(const string& filename, const string& element_name, + void AddError(const std::string& filename, const std::string& element_name, const Message* descriptor, ErrorLocation location, - const string& message) override; + const std::string& message) override; - void AddWarning(const string& filename, const string& element_name, + void AddWarning(const std::string& filename, const std::string& element_name, const Message* descriptor, ErrorLocation location, - const string& message) override; + const std::string& message) override; private: SourceTreeDescriptorDatabase* owner_; @@ -142,7 +145,7 @@ class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabas // You may find that SourceTreeDescriptorDatabase is more flexible. // // TODO(kenton): I feel like this class is not well-named. -class LIBPROTOBUF_EXPORT Importer { +class PROTOBUF_EXPORT Importer { public: Importer(SourceTree* source_tree, MultiFileErrorCollector* error_collector); @@ -161,7 +164,7 @@ class LIBPROTOBUF_EXPORT Importer { // you want to see errors for the same files repeatedly, you can use a // separate Importer object to import each one (but use the same // DescriptorPool so that they can be cross-linked). - const FileDescriptor* Import(const string& filename); + const FileDescriptor* Import(const std::string& filename); // The DescriptorPool in which all imported FileDescriptors and their // contents are stored. @@ -169,7 +172,7 @@ class LIBPROTOBUF_EXPORT Importer { return &pool_; } - void AddUnusedImportTrackFile(const string& file_name); + void AddUnusedImportTrackFile(const std::string& file_name); void ClearUnusedImportTrackFiles(); @@ -182,18 +185,18 @@ class LIBPROTOBUF_EXPORT Importer { // If the importer encounters problems while trying to import the proto files, // it reports them to a MultiFileErrorCollector. -class LIBPROTOBUF_EXPORT MultiFileErrorCollector { +class PROTOBUF_EXPORT MultiFileErrorCollector { public: inline MultiFileErrorCollector() {} virtual ~MultiFileErrorCollector(); // Line and column numbers are zero-based. A line number of -1 indicates // an error with the entire file (e.g. "not found"). - virtual void AddError(const string& filename, int line, int column, - const string& message) = 0; + virtual void AddError(const std::string& filename, int line, int column, + const std::string& message) = 0; - virtual void AddWarning(const string& filename, int line, int column, - const string& message) {} + virtual void AddWarning(const std::string& filename, int line, int column, + const std::string& message) {} private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); @@ -203,7 +206,7 @@ class LIBPROTOBUF_EXPORT MultiFileErrorCollector { // Used by the default implementation of Importer to resolve import statements // Most users will probably want to use the DiskSourceTree implementation, // below. -class LIBPROTOBUF_EXPORT SourceTree { +class PROTOBUF_EXPORT SourceTree { public: inline SourceTree() {} virtual ~SourceTree(); @@ -212,14 +215,14 @@ class LIBPROTOBUF_EXPORT SourceTree { // found. The caller takes ownership of the returned object. The filename // must be a path relative to the root of the source tree and must not // contain "." or ".." components. - virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; + virtual io::ZeroCopyInputStream* Open(const std::string& filename) = 0; // If Open() returns NULL, calling this method immediately will return an // description of the error. // Subclasses should implement this method and return a meaningful value for // better error reporting. // TODO(xiaofeng): change this to a pure virtual function. - virtual string GetLastErrorMessage(); + virtual std::string GetLastErrorMessage(); private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); @@ -228,7 +231,7 @@ class LIBPROTOBUF_EXPORT SourceTree { // An implementation of SourceTree which loads files from locations on disk. // Multiple mappings can be set up to map locations in the DiskSourceTree to // locations in the physical filesystem. -class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { +class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { public: DiskSourceTree(); ~DiskSourceTree(); @@ -249,7 +252,7 @@ class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { // // disk_path may be an absolute path or relative to the current directory, // just like a path you'd pass to open(). - void MapPath(const string& virtual_path, const string& disk_path); + void MapPath(const std::string& virtual_path, const std::string& disk_path); // Return type for DiskFileToVirtualFile(). enum DiskFileToVirtualFileResult { @@ -280,39 +283,39 @@ class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { // * NO_MAPPING: Indicates that no mapping was found which contains this // file. DiskFileToVirtualFileResult - DiskFileToVirtualFile(const string& disk_file, - string* virtual_file, - string* shadowing_disk_file); + DiskFileToVirtualFile(const std::string& disk_file, + std::string* virtual_file, + std::string* shadowing_disk_file); // Given a virtual path, find the path to the file on disk. // Return true and update disk_file with the on-disk path if the file exists. // Return false and leave disk_file untouched if the file doesn't exist. - bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); + bool VirtualFileToDiskFile(const std::string& virtual_file, std::string* disk_file); // implements SourceTree ------------------------------------------- - io::ZeroCopyInputStream* Open(const string& filename) override; + io::ZeroCopyInputStream* Open(const std::string& filename) override; - string GetLastErrorMessage() override; + std::string GetLastErrorMessage() override; private: struct Mapping { - string virtual_path; - string disk_path; + std::string virtual_path; + std::string disk_path; - inline Mapping(const string& virtual_path_param, - const string& disk_path_param) + inline Mapping(const std::string& virtual_path_param, + const std::string& disk_path_param) : virtual_path(virtual_path_param), disk_path(disk_path_param) {} }; std::vector<Mapping> mappings_; - string last_error_message_; + std::string last_error_message_; // Like Open(), but returns the on-disk path in disk_file if disk_file is // non-NULL and the file could be successfully opened. - io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, - string* disk_file); + io::ZeroCopyInputStream* OpenVirtualFile(const std::string& virtual_file, + std::string* disk_file); // Like Open() but given the actual on-disk path. - io::ZeroCopyInputStream* OpenDiskFile(const string& filename); + io::ZeroCopyInputStream* OpenDiskFile(const std::string& filename); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); }; @@ -321,4 +324,6 @@ class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ diff --git a/src/google/protobuf/compiler/java/java_doc_comment.h b/src/google/protobuf/compiler/java/java_doc_comment.h index 112c3bc3..ef9b3a90 100644 --- a/src/google/protobuf/compiler/java/java_doc_comment.h +++ b/src/google/protobuf/compiler/java/java_doc_comment.h @@ -37,6 +37,8 @@ #include <google/protobuf/descriptor.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace io { @@ -61,11 +63,13 @@ void WriteMethodDocComment(io::Printer* printer, const MethodDescriptor* method); // Exposed for testing only. -LIBPROTOC_EXPORT string EscapeJavadoc(const string& input); +PROTOC_EXPORT std::string EscapeJavadoc(const std::string& input); } // namespace java } // namespace compiler } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ diff --git a/src/google/protobuf/compiler/java/java_enum_field.h b/src/google/protobuf/compiler/java/java_enum_field.h index 842da592..723102d8 100644 --- a/src/google/protobuf/compiler/java/java_enum_field.h +++ b/src/google/protobuf/compiler/java/java_enum_field.h @@ -81,11 +81,11 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; @@ -142,11 +142,11 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.h b/src/google/protobuf/compiler/java/java_enum_field_lite.h index 6bda426f..bf25ffaa 100644 --- a/src/google/protobuf/compiler/java/java_enum_field_lite.h +++ b/src/google/protobuf/compiler/java/java_enum_field_lite.h @@ -79,11 +79,11 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -136,11 +136,11 @@ class RepeatedImmutableEnumFieldLiteGenerator void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; diff --git a/src/google/protobuf/compiler/java/java_extension.h b/src/google/protobuf/compiler/java/java_extension.h index 7a58373f..1f11324c 100644 --- a/src/google/protobuf/compiler/java/java_extension.h +++ b/src/google/protobuf/compiler/java/java_extension.h @@ -80,9 +80,9 @@ class ExtensionGenerator { protected: static void InitTemplateVars(const FieldDescriptor* descriptor, - const string& scope, bool immutable, + const std::string& scope, bool immutable, ClassNameResolver* name_resolver, - std::map<string, string>* vars_pointer); + std::map<std::string, std::string>* vars_pointer); private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); @@ -102,7 +102,7 @@ class ImmutableExtensionGenerator : public ExtensionGenerator { const FieldDescriptor* descriptor_; Context* context_; ClassNameResolver* name_resolver_; - string scope_; + std::string scope_; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionGenerator); diff --git a/src/google/protobuf/compiler/java/java_extension_lite.h b/src/google/protobuf/compiler/java/java_extension_lite.h index 34716f9d..eaa90a4b 100644 --- a/src/google/protobuf/compiler/java/java_extension_lite.h +++ b/src/google/protobuf/compiler/java/java_extension_lite.h @@ -63,7 +63,7 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator { const FieldDescriptor* descriptor_; Context* context_; ClassNameResolver* name_resolver_; - string scope_; + std::string scope_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionLiteGenerator); }; diff --git a/src/google/protobuf/compiler/java/java_field.h b/src/google/protobuf/compiler/java/java_field.h index 881427d7..abefc589 100644 --- a/src/google/protobuf/compiler/java/java_field.h +++ b/src/google/protobuf/compiler/java/java_field.h @@ -87,7 +87,7 @@ class ImmutableFieldGenerator { virtual void GenerateEqualsCode(io::Printer* printer) const = 0; virtual void GenerateHashCode(io::Printer* printer) const = 0; - virtual string GetBoxedType() const = 0; + virtual std::string GetBoxedType() const = 0; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator); @@ -118,7 +118,7 @@ class ImmutableFieldLiteGenerator { virtual void GenerateHashCode(io::Printer* printer) const = 0; - virtual string GetBoxedType() const = 0; + virtual std::string GetBoxedType() const = 0; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldLiteGenerator); @@ -171,29 +171,29 @@ FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap(); // Field information used in FieldGeneartors. struct FieldGeneratorInfo { - string name; - string capitalized_name; - string disambiguated_reason; + std::string name; + std::string capitalized_name; + std::string disambiguated_reason; }; // Oneof information used in OneofFieldGenerators. struct OneofGeneratorInfo { - string name; - string capitalized_name; + std::string name; + std::string capitalized_name; }; // Set some common variables used in variable FieldGenerators. void SetCommonFieldVariables(const FieldDescriptor* descriptor, const FieldGeneratorInfo* info, - std::map<string, string>* variables); + std::map<std::string, std::string>* variables); // Set some common oneof variables used in OneofFieldGenerators. void SetCommonOneofVariables(const FieldDescriptor* descriptor, const OneofGeneratorInfo* info, - std::map<string, string>* variables); + std::map<std::string, std::string>* variables); // Print useful comments before a field's accessors. -void PrintExtraFieldInfo(const std::map<string, string>& variables, +void PrintExtraFieldInfo(const std::map<std::string, std::string>& variables, io::Printer* printer); } // namespace java diff --git a/src/google/protobuf/compiler/java/java_file.cc b/src/google/protobuf/compiler/java/java_file.cc index 5dc2dff8..5356512c 100644 --- a/src/google/protobuf/compiler/java/java_file.cc +++ b/src/google/protobuf/compiler/java/java_file.cc @@ -232,7 +232,9 @@ bool FileGenerator::Validate(string* error) { << "will be ignored by protoc in the future and protoc will always " << "generate full runtime code for Java. To use Java Lite runtime, " << "users should use the Java Lite plugin instead. See:\n" - << " https://github.com/protocolbuffers/protobuf/blob/master/java/lite.md"; + << " " + "https://github.com/protocolbuffers/protobuf/blob/master/java/" + "lite.md"; } return true; } diff --git a/src/google/protobuf/compiler/java/java_file.h b/src/google/protobuf/compiler/java/java_file.h index 4158d48b..9dca82bb 100644 --- a/src/google/protobuf/compiler/java/java_file.h +++ b/src/google/protobuf/compiler/java/java_file.h @@ -74,20 +74,20 @@ class FileGenerator { // Checks for problems that would otherwise lead to cryptic compile errors. // Returns true if there are no problems, or writes an error description to // the given string and returns false otherwise. - bool Validate(string* error); + bool Validate(std::string* error); void Generate(io::Printer* printer); // If we aren't putting everything into one file, this will write all the // files other than the outer file (i.e. one for each message, enum, and // service type). - void GenerateSiblings(const string& package_dir, + void GenerateSiblings(const std::string& package_dir, GeneratorContext* generator_context, - std::vector<string>* file_list, - std::vector<string>* annotation_list); + std::vector<std::string>* file_list, + std::vector<std::string>* annotation_list); - const string& java_package() { return java_package_; } - const string& classname() { return classname_; } + const std::string& java_package() { return java_package_; } + const std::string& classname() { return classname_; } private: void GenerateDescriptorInitializationCodeForImmutable(io::Printer* printer); @@ -97,8 +97,8 @@ class FileGenerator { bool immutable_api_); const FileDescriptor* file_; - string java_package_; - string classname_; + std::string java_package_; + std::string classname_; std::vector<std::unique_ptr<MessageGenerator>> message_generators_; std::vector<std::unique_ptr<ExtensionGenerator>> extension_generators_; diff --git a/src/google/protobuf/compiler/java/java_generator.h b/src/google/protobuf/compiler/java/java_generator.h index 6eefdd84..21873581 100644 --- a/src/google/protobuf/compiler/java/java_generator.h +++ b/src/google/protobuf/compiler/java/java_generator.h @@ -40,6 +40,8 @@ #include <string> #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -49,16 +51,16 @@ namespace java { // own protocol compiler binary and you want it to support Java output, you // can do so by registering an instance of this CodeGenerator with the // CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT JavaGenerator : public CodeGenerator { +class PROTOC_EXPORT JavaGenerator : public CodeGenerator { public: JavaGenerator(); ~JavaGenerator(); // implements CodeGenerator ---------------------------------------- bool Generate(const FileDescriptor* file, - const string& parameter, + const std::string& parameter, GeneratorContext* context, - string* error) const; + std::string* error) const; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator); @@ -69,4 +71,6 @@ class LIBPROTOC_EXPORT JavaGenerator : public CodeGenerator { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/java/java_helpers.h b/src/google/protobuf/compiler/java/java_helpers.h index 375bd67d..93caa3dc 100644 --- a/src/google/protobuf/compiler/java/java_helpers.h +++ b/src/google/protobuf/compiler/java/java_helpers.h @@ -60,89 +60,89 @@ extern const char kThinSeparator[]; // annotation_file should be generated from the filename of the source file // being annotated (which in turn must be a Java identifier plus ".java"). void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$', - const string& annotation_file = ""); + const std::string& annotation_file = ""); // If a GeneratedMessageLite contains non-lite enums, then its verifier // must be instantiated inline, rather than retrieved from the enum class. void PrintEnumVerifierLogic(io::Printer* printer, const FieldDescriptor* descriptor, - const std::map<string, string>& variables, + const std::map<std::string, std::string>& variables, 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 // first letter. -string UnderscoresToCamelCase(const string& name, bool cap_first_letter); +std::string UnderscoresToCamelCase(const std::string& name, bool cap_first_letter); // Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes // "fooBarBaz" or "FooBarBaz", respectively. -string UnderscoresToCamelCase(const FieldDescriptor* field); -string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field); +std::string UnderscoresToCamelCase(const FieldDescriptor* field); +std::string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field); // Similar, but for method names. (Typically, this merely has the effect // of lower-casing the first letter of the name.) -string UnderscoresToCamelCase(const MethodDescriptor* method); +std::string UnderscoresToCamelCase(const MethodDescriptor* method); // Similar to UnderscoresToCamelCase, but guarentees that the result is a // complete Java identifier by adding a _ if needed. -string CamelCaseFieldName(const FieldDescriptor* field); +std::string CamelCaseFieldName(const FieldDescriptor* field); // Get an identifier that uniquely identifies this type within the file. // This is used to declare static variables related to this type at the // outermost file scope. -string UniqueFileScopeIdentifier(const Descriptor* descriptor); +std::string UniqueFileScopeIdentifier(const Descriptor* descriptor); // Strips ".proto" or ".protodevel" from the end of a filename. -string StripProto(const string& filename); +std::string StripProto(const std::string& filename); // Gets the unqualified class name for the file. For each .proto file, there // will be one Java class containing all the immutable messages and another // Java class containing all the mutable messages. // TODO(xiaofeng): remove the default value after updating client code. -string FileClassName(const FileDescriptor* file, bool immutable = true); +std::string FileClassName(const FileDescriptor* file, bool immutable = true); // Returns the file's Java package name. -string FileJavaPackage(const FileDescriptor* file); -string FileJavaPackage(const FileDescriptor* file, bool immutable); +std::string FileJavaPackage(const FileDescriptor* file); +std::string FileJavaPackage(const FileDescriptor* file, bool immutable); // Returns output directory for the given package name. -string JavaPackageToDir(string package_name); +std::string JavaPackageToDir(std::string package_name); // Converts the given fully-qualified name in the proto namespace to its // fully-qualified name in the Java namespace, given that it is in the given // file. // TODO(xiaofeng): this method is deprecated and should be removed in the // future. -string ToJavaName(const string& full_name, +std::string ToJavaName(const std::string& full_name, const FileDescriptor* file); // TODO(xiaofeng): the following methods are kept for they are exposed // publicly in //net/proto2/compiler/java/public/names.h. They return // immutable names only and should be removed after mutable API is // integrated into google3. -string ClassName(const Descriptor* descriptor); -string ClassName(const EnumDescriptor* descriptor); -string ClassName(const ServiceDescriptor* descriptor); -string ClassName(const FileDescriptor* descriptor); +std::string ClassName(const Descriptor* descriptor); +std::string ClassName(const EnumDescriptor* descriptor); +std::string ClassName(const ServiceDescriptor* descriptor); +std::string ClassName(const FileDescriptor* descriptor); // Comma-separate list of option-specified interfaces implemented by the // Message, to follow the "implements" declaration of the Message definition. -string ExtraMessageInterfaces(const Descriptor* descriptor); +std::string ExtraMessageInterfaces(const Descriptor* descriptor); // Comma-separate list of option-specified interfaces implemented by the // MutableMessage, to follow the "implements" declaration of the MutableMessage // definition. -string ExtraMutableMessageInterfaces(const Descriptor* descriptor); +std::string ExtraMutableMessageInterfaces(const Descriptor* descriptor); // Comma-separate list of option-specified interfaces implemented by the // Builder, to follow the "implements" declaration of the Builder definition. -string ExtraBuilderInterfaces(const Descriptor* descriptor); +std::string ExtraBuilderInterfaces(const Descriptor* descriptor); // Comma-separate list of option-specified interfaces extended by the // MessageOrBuilder, to follow the "extends" declaration of the // MessageOrBuilder definition. -string ExtraMessageOrBuilderInterfaces(const Descriptor* descriptor); +std::string ExtraMessageOrBuilderInterfaces(const Descriptor* descriptor); // Get the unqualified Java class name for mutable messages. i.e. without // package or outer classnames. -inline string ShortMutableJavaClassName(const Descriptor* descriptor) { +inline std::string ShortMutableJavaClassName(const Descriptor* descriptor) { return descriptor->name(); } @@ -179,14 +179,14 @@ inline bool IsOwnFile(const ServiceDescriptor* descriptor, bool immutable) { // annotation data for that descriptor. `suffix` is usually empty, but may // (e.g.) be "OrBuilder" for some generated interfaces. template <typename Descriptor> -string AnnotationFileName(const Descriptor* descriptor, const string& suffix) { +std::string AnnotationFileName(const Descriptor* descriptor, const std::string& suffix) { return descriptor->name() + suffix + ".java.pb.meta"; } template <typename Descriptor> void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer, Descriptor* descriptor, bool immutable, - const string& suffix = "") { + const std::string& suffix = "") { if (context->options().annotate_code && IsOwnFile(descriptor, immutable)) { PrintGeneratedAnnotation(printer, '$', AnnotationFileName(descriptor, suffix)); @@ -195,7 +195,7 @@ void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer, // Get the unqualified name that should be used for a field's field // number constant. -string FieldConstantName(const FieldDescriptor *field); +std::string FieldConstantName(const FieldDescriptor *field); // Returns the type of the FieldDescriptor. // This does nothing interesting for the open source release, but is used for @@ -229,9 +229,9 @@ const char* BoxedPrimitiveTypeName(JavaType type); const char* FieldTypeName(const FieldDescriptor::Type field_type); class ClassNameResolver; -string DefaultValue(const FieldDescriptor* field, bool immutable, +std::string DefaultValue(const FieldDescriptor* field, bool immutable, ClassNameResolver* name_resolver); -inline string ImmutableDefaultValue(const FieldDescriptor* field, +inline std::string ImmutableDefaultValue(const FieldDescriptor* field, ClassNameResolver* name_resolver) { return DefaultValue(field, true, name_resolver); } @@ -267,50 +267,50 @@ inline bool HasGenericServices(const FileDescriptor *file, bool enforce_lite) { // Methods for shared bitfields. // Gets the name of the shared bitfield for the given index. -string GetBitFieldName(int index); +std::string GetBitFieldName(int index); // Gets the name of the shared bitfield for the given bit index. // Effectively, GetBitFieldName(bitIndex / 32) -string GetBitFieldNameForBit(int bitIndex); +std::string GetBitFieldNameForBit(int bitIndex); // Generates the java code for the expression that returns the boolean value // of the bit of the shared bitfields for the given bit index. // Example: "((bitField1_ & 0x04) == 0x04)" -string GenerateGetBit(int bitIndex); +std::string GenerateGetBit(int bitIndex); // Generates the java code for the expression that sets the bit of the shared // bitfields for the given bit index. // Example: "bitField1_ = (bitField1_ | 0x04)" -string GenerateSetBit(int bitIndex); +std::string GenerateSetBit(int bitIndex); // Generates the java code for the expression that clears the bit of the shared // bitfields for the given bit index. // Example: "bitField1_ = (bitField1_ & ~0x04)" -string GenerateClearBit(int bitIndex); +std::string GenerateClearBit(int bitIndex); // Does the same as GenerateGetBit but operates on the bit field on a local // variable. This is used by the builder to copy the value in the builder to // the message. // Example: "((from_bitField1_ & 0x04) == 0x04)" -string GenerateGetBitFromLocal(int bitIndex); +std::string GenerateGetBitFromLocal(int bitIndex); // Does the same as GenerateSetBit but operates on the bit field on a local // variable. This is used by the builder to copy the value in the builder to // the message. // Example: "to_bitField1_ = (to_bitField1_ | 0x04)" -string GenerateSetBitToLocal(int bitIndex); +std::string GenerateSetBitToLocal(int bitIndex); // Does the same as GenerateGetBit but operates on the bit field on a local // variable. This is used by the parsing constructor to record if a repeated // field is mutable. // Example: "((mutable_bitField1_ & 0x04) == 0x04)" -string GenerateGetBitMutableLocal(int bitIndex); +std::string GenerateGetBitMutableLocal(int bitIndex); // Does the same as GenerateSetBit but operates on the bit field on a local // variable. This is used by the parsing constructor to record if a repeated // field is mutable. // Example: "mutable_bitField1_ = (mutable_bitField1_ | 0x04)" -string GenerateSetBitMutableLocal(int bitIndex); +std::string GenerateSetBitMutableLocal(int bitIndex); // Returns whether the JavaType is a reference type. bool IsReferenceType(JavaType type); @@ -398,7 +398,7 @@ inline bool CheckUtf8(const FieldDescriptor* descriptor) { descriptor->file()->options().java_string_check_utf8(); } -inline string GeneratedCodeVersionSuffix() { +inline std::string GeneratedCodeVersionSuffix() { return "V3"; } @@ -410,7 +410,7 @@ inline void WriteIntToUtf16CharSequence(int value, } // Escape a UTF-16 character so it can be embedded in a Java string literal. -void EscapeUtf16ToString(uint16 code, string* output); +void EscapeUtf16ToString(uint16 code, std::string* output); // Only the lowest two bytes of the return value are used. The lowest byte // is the integer value of a j/c/g/protobuf/FieldType enum. For the other diff --git a/src/google/protobuf/compiler/java/java_map_field.h b/src/google/protobuf/compiler/java/java_map_field.h index 90c90eb2..b123b041 100644 --- a/src/google/protobuf/compiler/java/java_map_field.h +++ b/src/google/protobuf/compiler/java/java_map_field.h @@ -63,11 +63,11 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; ClassNameResolver* name_resolver_; void GenerateMapGetters(io::Printer* printer) const; }; diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.h b/src/google/protobuf/compiler/java/java_map_field_lite.h index 710617ae..df5fe64d 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.h +++ b/src/google/protobuf/compiler/java/java_map_field_lite.h @@ -62,11 +62,11 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/java_message_field.h b/src/google/protobuf/compiler/java/java_message_field.h index d70d8270..58344e55 100644 --- a/src/google/protobuf/compiler/java/java_message_field.h +++ b/src/google/protobuf/compiler/java/java_message_field.h @@ -82,11 +82,11 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; @@ -150,11 +150,11 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.h b/src/google/protobuf/compiler/java/java_message_field_lite.h index c9eb30b8..7e78ca4f 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.h +++ b/src/google/protobuf/compiler/java/java_message_field_lite.h @@ -79,11 +79,11 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -136,11 +136,11 @@ class RepeatedImmutableMessageFieldLiteGenerator void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index 85a7453d..a131e8cc 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -736,14 +736,14 @@ void ImmutableMessageLiteGenerator::GenerateSerializeOneExtensionRange( void ImmutableMessageLiteGenerator::GenerateBuilder(io::Printer* printer) { printer->Print( - "public static Builder newBuilder() {\n" - " return (Builder) DEFAULT_INSTANCE.createBuilder();\n" - "}\n" - "public static Builder newBuilder($classname$ prototype) {\n" - " return (Builder) DEFAULT_INSTANCE.createBuilder(prototype);\n" - "}\n" - "\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); + "public static Builder newBuilder() {\n" + " return (Builder) DEFAULT_INSTANCE.createBuilder();\n" + "}\n" + "public static Builder newBuilder($classname$ prototype) {\n" + " return (Builder) DEFAULT_INSTANCE.createBuilder(prototype);\n" + "}\n" + "\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); MessageBuilderLiteGenerator builderGenerator(descriptor_, context_); builderGenerator.Generate(printer); diff --git a/src/google/protobuf/compiler/java/java_name_resolver.h b/src/google/protobuf/compiler/java/java_name_resolver.h index 90684da2..aa19f007 100644 --- a/src/google/protobuf/compiler/java/java_name_resolver.h +++ b/src/google/protobuf/compiler/java/java_name_resolver.h @@ -56,63 +56,63 @@ class ClassNameResolver { ~ClassNameResolver(); // Gets the unqualified outer class name for the file. - string GetFileClassName(const FileDescriptor* file, bool immutable); + std::string GetFileClassName(const FileDescriptor* file, bool immutable); // Gets the unqualified immutable outer class name of a file. - string GetFileImmutableClassName(const FileDescriptor* file); + std::string GetFileImmutableClassName(const FileDescriptor* file); // Gets the unqualified default immutable outer class name of a file // (converted from the proto file's name). - string GetFileDefaultImmutableClassName(const FileDescriptor* file); + std::string GetFileDefaultImmutableClassName(const FileDescriptor* file); // Check whether there is any type defined in the proto file that has // the given class name. bool HasConflictingClassName(const FileDescriptor* file, - const string& classname); + const std::string& classname); // Gets the name of the outer class that holds descriptor information. // Descriptors are shared between immutable messages and mutable messages. // Since both of them are generated optionally, the descriptors need to be // put in another common place. - string GetDescriptorClassName(const FileDescriptor* file); + std::string GetDescriptorClassName(const FileDescriptor* file); // Gets the fully-qualified class name corresponding to the given descriptor. - string GetClassName(const Descriptor* descriptor, bool immutable); - string GetClassName(const EnumDescriptor* descriptor, bool immutable); - string GetClassName(const ServiceDescriptor* descriptor, bool immutable); - string GetClassName(const FileDescriptor* descriptor, bool immutable); + std::string GetClassName(const Descriptor* descriptor, bool immutable); + std::string GetClassName(const EnumDescriptor* descriptor, bool immutable); + std::string GetClassName(const ServiceDescriptor* descriptor, bool immutable); + std::string GetClassName(const FileDescriptor* descriptor, bool immutable); template<class DescriptorType> - string GetImmutableClassName(const DescriptorType* descriptor) { + std::string GetImmutableClassName(const DescriptorType* descriptor) { return GetClassName(descriptor, true); } template<class DescriptorType> - string GetMutableClassName(const DescriptorType* descriptor) { + std::string GetMutableClassName(const DescriptorType* descriptor) { return GetClassName(descriptor, false); } // Gets the fully qualified name of an extension identifier. - string GetExtensionIdentifierName(const FieldDescriptor* descriptor, + std::string GetExtensionIdentifierName(const FieldDescriptor* descriptor, bool immutable); // Gets the fully qualified name for generated classes in Java convention. // Nested classes will be separated using '$' instead of '.' // For example: // com.package.OuterClass$OuterMessage$InnerMessage - string GetJavaImmutableClassName(const Descriptor* descriptor); - string GetJavaImmutableClassName(const EnumDescriptor* descriptor); + std::string GetJavaImmutableClassName(const Descriptor* descriptor); + std::string GetJavaImmutableClassName(const EnumDescriptor* descriptor); private: // Get the full name of a Java class by prepending the Java package name // or outer class name. - string GetClassFullName(const string& name_without_package, + std::string GetClassFullName(const std::string& name_without_package, const FileDescriptor* file, bool immutable, bool multiple_files); // Get the Java Class style full name of a message. - string GetJavaClassFullName( - const string& name_without_package, + std::string GetJavaClassFullName( + const std::string& name_without_package, const FileDescriptor* file, bool immutable); // Caches the result to provide better performance. - std::map<const FileDescriptor*, string> file_immutable_outer_class_names_; + std::map<const FileDescriptor*, std::string> file_immutable_outer_class_names_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver); }; diff --git a/src/google/protobuf/compiler/java/java_names.h b/src/google/protobuf/compiler/java/java_names.h index 39e8c51f..a8efbb49 100644 --- a/src/google/protobuf/compiler/java/java_names.h +++ b/src/google/protobuf/compiler/java/java_names.h @@ -57,41 +57,41 @@ namespace java { // // Returns: // The fully-qualified Java class name. -string ClassName(const Descriptor* descriptor); +std::string ClassName(const Descriptor* descriptor); // Requires: // descriptor != NULL // // Returns: // The fully-qualified Java class name. -string ClassName(const EnumDescriptor* descriptor); +std::string ClassName(const EnumDescriptor* descriptor); // Requires: // descriptor != NULL // // Returns: // The fully-qualified Java class name. -string ClassName(const FileDescriptor* descriptor); +std::string ClassName(const FileDescriptor* descriptor); // Requires: // descriptor != NULL // // Returns: // The fully-qualified Java class name. -string ClassName(const ServiceDescriptor* descriptor); +std::string ClassName(const ServiceDescriptor* descriptor); // Requires: // descriptor != NULL // // Returns: // Java package name. -string FileJavaPackage(const FileDescriptor* descriptor); +std::string FileJavaPackage(const FileDescriptor* descriptor); // Requires: // descriptor != NULL // Returns: // Captialized camel case name field name. -string CapitalizedFieldName(const FieldDescriptor* descriptor); +std::string CapitalizedFieldName(const FieldDescriptor* descriptor); // Requires: // descriptor != NULL diff --git a/src/google/protobuf/compiler/java/java_primitive_field.h b/src/google/protobuf/compiler/java/java_primitive_field.h index a1368057..185a268e 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field.h +++ b/src/google/protobuf/compiler/java/java_primitive_field.h @@ -82,11 +82,11 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; @@ -143,11 +143,11 @@ class RepeatedImmutablePrimitiveFieldGenerator void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.h b/src/google/protobuf/compiler/java/java_primitive_field_lite.h index c12e458c..6c05521f 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field_lite.h +++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.h @@ -82,11 +82,11 @@ class ImmutablePrimitiveFieldLiteGenerator void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -143,11 +143,11 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; diff --git a/src/google/protobuf/compiler/java/java_service.h b/src/google/protobuf/compiler/java/java_service.h index f34cd798..24b0ccaa 100644 --- a/src/google/protobuf/compiler/java/java_service.h +++ b/src/google/protobuf/compiler/java/java_service.h @@ -125,7 +125,7 @@ class ImmutableServiceGenerator : public ServiceGenerator { const MethodDescriptor* method); // Return the output type of the method. - string GetOutput(const MethodDescriptor* method); + std::string GetOutput(const MethodDescriptor* method); Context* context_; ClassNameResolver* name_resolver_; diff --git a/src/google/protobuf/compiler/java/java_shared_code_generator.h b/src/google/protobuf/compiler/java/java_shared_code_generator.h index 1eb6feaf..2f09c3a9 100644 --- a/src/google/protobuf/compiler/java/java_shared_code_generator.h +++ b/src/google/protobuf/compiler/java/java_shared_code_generator.h @@ -70,8 +70,8 @@ class SharedCodeGenerator { ~SharedCodeGenerator(); void Generate(GeneratorContext* generator_context, - std::vector<string>* file_list, - std::vector<string>* annotation_file_list); + std::vector<std::string>* file_list, + std::vector<std::string>* annotation_file_list); void GenerateDescriptors(io::Printer* printer); diff --git a/src/google/protobuf/compiler/java/java_string_field.h b/src/google/protobuf/compiler/java/java_string_field.h index 7f9fa0ed..38fb8365 100644 --- a/src/google/protobuf/compiler/java/java_string_field.h +++ b/src/google/protobuf/compiler/java/java_string_field.h @@ -82,11 +82,11 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; @@ -141,11 +141,11 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; const int builderBitIndex_; Context* context_; diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.h b/src/google/protobuf/compiler/java/java_string_field_lite.h index 684d3b00..89d5c1ae 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.h +++ b/src/google/protobuf/compiler/java/java_string_field_lite.h @@ -81,11 +81,11 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; protected: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; @@ -137,11 +137,11 @@ class RepeatedImmutableStringFieldLiteGenerator void GenerateHashCode(io::Printer* printer) const; - string GetBoxedType() const; + std::string GetBoxedType() const; private: const FieldDescriptor* descriptor_; - std::map<string, string> variables_; + std::map<std::string, std::string> variables_; const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; diff --git a/src/google/protobuf/compiler/js/js_generator.h b/src/google/protobuf/compiler/js/js_generator.h index 21e03bc1..4567b07a 100644 --- a/src/google/protobuf/compiler/js/js_generator.h +++ b/src/google/protobuf/compiler/js/js_generator.h @@ -40,6 +40,8 @@ #include <google/protobuf/stubs/common.h> #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -56,9 +58,9 @@ namespace js { struct GeneratorOptions { // Output path. - string output_dir; + std::string output_dir; // Namespace prefix. - string namespace_prefix; + std::string namespace_prefix; // Enable binary-format support? bool binary; // What style of imports should be used. @@ -84,11 +86,11 @@ struct GeneratorOptions { annotate_code(false) {} bool ParseFromOptions( - const std::vector< std::pair< string, string > >& options, - string* error); + const std::vector< std::pair< std::string, std::string > >& options, + std::string* error); // Returns the file name extension to use for generated code. - string GetFileNameExtension() const { + std::string GetFileNameExtension() const { return import_style == kImportClosure ? extension : "_pb.js"; } @@ -113,11 +115,11 @@ struct GeneratorOptions { bool testonly; // Create a library with name <name>_lib.js rather than a separate .js file // per type? - string library; + std::string library; // Error if there are two types that would generate the same output file? bool error_on_name_conflict; // The extension to use for output file names. - string extension; + std::string extension; // Create a separate output file for each input file? bool one_output_file_per_input_file; // If true, we should build .meta files that contain annotations for @@ -129,15 +131,15 @@ struct GeneratorOptions { // header. If you create your own protocol compiler binary and you want it to // support JavaScript output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator : public CodeGenerator { +class PROTOC_EXPORT Generator : public CodeGenerator { public: Generator() {} virtual ~Generator() {} virtual bool Generate(const FileDescriptor* file, - const string& parameter, + const std::string& parameter, GeneratorContext* context, - string* error) const { + std::string* error) const { *error = "Unimplemented Generate() method. Call GenerateAll() instead."; return false; } @@ -145,9 +147,9 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { virtual bool HasGenerateAll() const { return true; } virtual bool GenerateAll(const std::vector<const FileDescriptor*>& files, - const string& parameter, + const std::string& parameter, GeneratorContext* context, - string* error) const; + std::string* error) const; private: void GenerateHeader(const GeneratorOptions& options, @@ -157,28 +159,28 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void FindProvides(const GeneratorOptions& options, io::Printer* printer, const std::vector<const FileDescriptor*>& file, - std::set<string>* provided) const; + std::set<std::string>* provided) const; void FindProvidesForFile(const GeneratorOptions& options, io::Printer* printer, const FileDescriptor* file, - std::set<string>* provided) const; + std::set<std::string>* provided) const; void FindProvidesForMessage(const GeneratorOptions& options, io::Printer* printer, const Descriptor* desc, - std::set<string>* provided) const; + std::set<std::string>* provided) const; void FindProvidesForEnum(const GeneratorOptions& options, io::Printer* printer, const EnumDescriptor* enumdesc, - std::set<string>* provided) const; + std::set<std::string>* provided) const; // For extension fields at file scope. void FindProvidesForFields(const GeneratorOptions& options, io::Printer* printer, const std::vector<const FieldDescriptor*>& fields, - std::set<string>* provided) const; + std::set<std::string>* provided) const; // Print the goog.provides() found by the methods above. void GenerateProvides(const GeneratorOptions& options, io::Printer* printer, - std::set<string>* provided) const; + std::set<std::string>* provided) const; // Generate goog.setTestOnly() if indicated. void GenerateTestOnly(const GeneratorOptions& options, @@ -188,34 +190,34 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void GenerateRequiresForLibrary( const GeneratorOptions& options, io::Printer* printer, const std::vector<const FileDescriptor*>& files, - std::set<string>* provided) const; + std::set<std::string>* provided) const; void GenerateRequiresForMessage(const GeneratorOptions& options, io::Printer* printer, const Descriptor* desc, - std::set<string>* provided) const; + std::set<std::string>* provided) const; // For extension fields at file scope. void GenerateRequiresForExtensions( const GeneratorOptions& options, io::Printer* printer, const std::vector<const FieldDescriptor*>& fields, - std::set<string>* provided) const; + std::set<std::string>* provided) const; void GenerateRequiresImpl(const GeneratorOptions& options, - io::Printer* printer, std::set<string>* required, - std::set<string>* forwards, - std::set<string>* provided, bool require_jspb, + io::Printer* printer, std::set<std::string>* required, + std::set<std::string>* forwards, + std::set<std::string>* provided, bool require_jspb, bool require_extension, bool require_map) const; void FindRequiresForMessage(const GeneratorOptions& options, const Descriptor* desc, - std::set<string>* required, - std::set<string>* forwards, + std::set<std::string>* required, + std::set<std::string>* forwards, bool* have_message) const; void FindRequiresForField(const GeneratorOptions& options, const FieldDescriptor* field, - std::set<string>* required, - std::set<string>* forwards) const; + std::set<std::string>* required, + std::set<std::string>* forwards) const; void FindRequiresForExtension(const GeneratorOptions& options, const FieldDescriptor* field, - std::set<string>* required, - std::set<string>* forwards) const; + std::set<std::string>* required, + std::set<std::string>* forwards) const; void GenerateFile(const GeneratorOptions& options, io::Printer* printer, @@ -331,4 +333,6 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/mock_code_generator.h b/src/google/protobuf/compiler/mock_code_generator.h index 3b59bc4b..e6370b34 100644 --- a/src/google/protobuf/compiler/mock_code_generator.h +++ b/src/google/protobuf/compiler/mock_code_generator.h @@ -74,7 +74,7 @@ namespace compiler { // that can later be verified with CheckGeneratedAnnotations. class MockCodeGenerator : public CodeGenerator { public: - MockCodeGenerator(const string& name); + MockCodeGenerator(const std::string& name); virtual ~MockCodeGenerator(); // Expect (via gTest) that a MockCodeGenerator with the given name was called @@ -84,45 +84,45 @@ class MockCodeGenerator : public CodeGenerator { // should have inserted lines into this file. // |parsed_file_list| is a comma-separated list of names of the files // that are being compiled together in this run. - static void ExpectGenerated(const string& name, - const string& parameter, - const string& insertions, - const string& file, - const string& first_message_name, - const string& parsed_file_list, - const string& output_directory); + static void ExpectGenerated(const std::string& name, + const std::string& parameter, + const std::string& insertions, + const std::string& file, + const std::string& first_message_name, + const std::string& parsed_file_list, + const std::string& output_directory); // Checks that the correct text ranges were annotated by the // MockCodeGenerator_Annotate directive. - static void CheckGeneratedAnnotations(const string& name, - const string& file, - const string& output_directory); + static void CheckGeneratedAnnotations(const std::string& name, + const std::string& file, + const std::string& output_directory); // Get the name of the file which would be written by the given generator. - static string GetOutputFileName(const string& generator_name, + static std::string GetOutputFileName(const std::string& generator_name, const FileDescriptor* file); - static string GetOutputFileName(const string& generator_name, - const string& file); + static std::string GetOutputFileName(const std::string& generator_name, + const std::string& file); // implements CodeGenerator ---------------------------------------- virtual bool Generate(const FileDescriptor* file, - const string& parameter, + const std::string& parameter, GeneratorContext* context, - string* error) const; + std::string* error) const; private: - string name_; + std::string name_; - static string GetOutputFileContent(const string& generator_name, - const string& parameter, + static std::string GetOutputFileContent(const std::string& generator_name, + const std::string& parameter, const FileDescriptor* file, GeneratorContext *context); - static string GetOutputFileContent(const string& generator_name, - const string& parameter, - const string& file, - const string& parsed_file_list, - const string& first_message_name); + static std::string GetOutputFileContent(const std::string& generator_name, + const std::string& parameter, + const std::string& file, + const std::string& parsed_file_list, + const std::string& first_message_name); }; } // namespace compiler diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.h b/src/google/protobuf/compiler/objectivec/objectivec_generator.h index 3e43f732..ac20cfdb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.h @@ -36,6 +36,8 @@ #include <string> #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -45,7 +47,7 @@ namespace objectivec { // header. If you create your own protocol compiler binary and you want it to // support ObjectiveC output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator { +class PROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator { public: ObjectiveCGenerator(); ~ObjectiveCGenerator(); @@ -69,4 +71,7 @@ class LIBPROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator { } // namespace compiler } // namespace protobuf } // namespace google + +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 8999aa59..e7f21f28 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -39,6 +39,8 @@ #include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.pb.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -53,66 +55,67 @@ struct Options { }; // Escape C++ trigraphs by escaping question marks to "\?". -string LIBPROTOC_EXPORT EscapeTrigraphs(const string& to_escape); +string PROTOC_EXPORT EscapeTrigraphs(const string& to_escape); // Strips ".proto" or ".protodevel" from the end of a filename. -string LIBPROTOC_EXPORT StripProto(const string& filename); +string PROTOC_EXPORT StripProto(const string& filename); // Remove white space from either end of a StringPiece. -void LIBPROTOC_EXPORT StringPieceTrimWhitespace(StringPiece* input); +void PROTOC_EXPORT StringPieceTrimWhitespace(StringPiece* input); // Returns true if the name requires a ns_returns_not_retained attribute applied // to it. -bool LIBPROTOC_EXPORT IsRetainedName(const string& name); +bool PROTOC_EXPORT IsRetainedName(const string& name); // Returns true if the name starts with "init" and will need to have special // handling under ARC. -bool LIBPROTOC_EXPORT IsInitName(const string& name); +bool PROTOC_EXPORT IsInitName(const string& name); // Gets the objc_class_prefix. -string LIBPROTOC_EXPORT FileClassPrefix(const FileDescriptor* file); +string PROTOC_EXPORT FileClassPrefix(const FileDescriptor* file); // Gets the path of the file we're going to generate (sans the .pb.h // extension). The path will be dependent on the objectivec package // declared in the proto package. -string LIBPROTOC_EXPORT FilePath(const FileDescriptor* file); +string PROTOC_EXPORT FilePath(const FileDescriptor* file); // Just like FilePath(), but without the directory part. -string LIBPROTOC_EXPORT FilePathBasename(const FileDescriptor* file); +string PROTOC_EXPORT FilePathBasename(const FileDescriptor* file); // Gets the name of the root class we'll generate in the file. This class // is not meant for external consumption, but instead contains helpers that // the rest of the classes need -string LIBPROTOC_EXPORT FileClassName(const FileDescriptor* file); +string PROTOC_EXPORT FileClassName(const FileDescriptor* file); // These return the fully-qualified class name corresponding to the given // descriptor. -string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor); -string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor, string* out_suffix_added); -string LIBPROTOC_EXPORT EnumName(const EnumDescriptor* descriptor); +string PROTOC_EXPORT ClassName(const Descriptor* descriptor); +string PROTOC_EXPORT ClassName(const Descriptor* descriptor, + string* out_suffix_added); +string PROTOC_EXPORT EnumName(const EnumDescriptor* descriptor); // Returns the fully-qualified name of the enum value corresponding to the // the descriptor. -string LIBPROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor); +string PROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor); // Returns the name of the enum value corresponding to the descriptor. -string LIBPROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor); +string PROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor); // Reverse what an enum does. -string LIBPROTOC_EXPORT UnCamelCaseEnumShortName(const string& name); +string PROTOC_EXPORT UnCamelCaseEnumShortName(const string& name); // Returns the name to use for the extension (used as the method off the file's // Root class). -string LIBPROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor); +string PROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor); // Returns the transformed field name. -string LIBPROTOC_EXPORT FieldName(const FieldDescriptor* field); -string LIBPROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field); +string PROTOC_EXPORT FieldName(const FieldDescriptor* field); +string PROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field); // Returns the transformed oneof name. -string LIBPROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor); -string LIBPROTOC_EXPORT OneofName(const OneofDescriptor* descriptor); -string LIBPROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor); +string PROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor); +string PROTOC_EXPORT OneofName(const OneofDescriptor* descriptor); +string PROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor); inline bool HasFieldPresence(const FileDescriptor* file) { return file->syntax() != FileDescriptor::SYNTAX_PROTO3; @@ -127,7 +130,8 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) { } // Reverse of the above. -string LIBPROTOC_EXPORT UnCamelCaseFieldName(const string& name, const FieldDescriptor* field); +string PROTOC_EXPORT UnCamelCaseFieldName(const string& name, + const FieldDescriptor* field); enum ObjectiveCType { OBJECTIVECTYPE_INT32, @@ -175,48 +179,52 @@ string GetOptionalDeprecatedAttribute( } } -string LIBPROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field); +string PROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field); -ObjectiveCType LIBPROTOC_EXPORT GetObjectiveCType(FieldDescriptor::Type field_type); +ObjectiveCType PROTOC_EXPORT +GetObjectiveCType(FieldDescriptor::Type field_type); inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) { return GetObjectiveCType(field->type()); } -bool LIBPROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field); -bool LIBPROTOC_EXPORT IsReferenceType(const FieldDescriptor* field); +bool PROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field); +bool PROTOC_EXPORT IsReferenceType(const FieldDescriptor* field); -string LIBPROTOC_EXPORT GPBGenericValueFieldName(const FieldDescriptor* field); -string LIBPROTOC_EXPORT DefaultValue(const FieldDescriptor* field); -bool LIBPROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field); +string PROTOC_EXPORT GPBGenericValueFieldName(const FieldDescriptor* field); +string PROTOC_EXPORT DefaultValue(const FieldDescriptor* field); +bool PROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field); -string LIBPROTOC_EXPORT BuildFlagsString(const FlagType type, const std::vector<string>& strings); +string PROTOC_EXPORT BuildFlagsString(const FlagType type, + const std::vector<string>& strings); // Builds HeaderDoc/appledoc style comments out of the comments in the .proto // file. -string LIBPROTOC_EXPORT BuildCommentsString(const SourceLocation& location, - bool prefer_single_line); +string PROTOC_EXPORT BuildCommentsString(const SourceLocation& location, + bool prefer_single_line); // The name the commonly used by the library when built as a framework. // This lines up to the name used in the CocoaPod. -extern LIBPROTOC_EXPORT const char* const ProtobufLibraryFrameworkName; +extern PROTOC_EXPORT const char* const ProtobufLibraryFrameworkName; // Returns the CPP symbol name to use as the gate for framework style imports // for the given framework name to use. -string LIBPROTOC_EXPORT ProtobufFrameworkImportSymbol(const string& framework_name); +string PROTOC_EXPORT +ProtobufFrameworkImportSymbol(const string& framework_name); // Checks if the file is one of the proto's bundled with the library. -bool LIBPROTOC_EXPORT IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); +bool PROTOC_EXPORT +IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); // Checks the prefix for the given files and outputs any warnings as needed. If // there are flat out errors, then out_error is filled in with the first error // and the result is false. -bool LIBPROTOC_EXPORT ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files, - const Options& generation_options, - string* out_error); +bool PROTOC_EXPORT +ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files, + const Options& generation_options, string* out_error); // Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform // the input into the expected output. -class LIBPROTOC_EXPORT TextFormatDecodeData { +class PROTOC_EXPORT TextFormatDecodeData { public: TextFormatDecodeData(); ~TextFormatDecodeData(); @@ -237,20 +245,20 @@ class LIBPROTOC_EXPORT TextFormatDecodeData { }; // Helper for parsing simple files. -class LIBPROTOC_EXPORT LineConsumer { +class PROTOC_EXPORT LineConsumer { public: LineConsumer(); virtual ~LineConsumer(); virtual bool ConsumeLine(const StringPiece& line, string* out_error) = 0; }; -bool LIBPROTOC_EXPORT ParseSimpleFile( - const string& path, LineConsumer* line_consumer, string* out_error); - +bool PROTOC_EXPORT ParseSimpleFile(const string& path, + LineConsumer* line_consumer, + string* out_error); // Helper class for parsing framework import mappings and generating // import statements. -class LIBPROTOC_EXPORT ImportWriter { +class PROTOC_EXPORT ImportWriter { public: ImportWriter(const string& generate_for_named_framework, const string& named_framework_to_proto_path_mappings_path, @@ -290,4 +298,7 @@ class LIBPROTOC_EXPORT ImportWriter { } // namespace compiler } // namespace protobuf } // namespace google + +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index b55750ca..9ae6c6da 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -45,6 +45,8 @@ #include <google/protobuf/descriptor.h> #include <google/protobuf/repeated_field.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -63,7 +65,7 @@ class SourceLocationTable; // to a FileDescriptorProto. It does not resolve import directives or perform // many other kinds of validation needed to construct a complete // FileDescriptor. -class LIBPROTOBUF_EXPORT Parser { +class PROTOBUF_EXPORT Parser { public: Parser(); ~Parser(); @@ -93,7 +95,7 @@ class LIBPROTOBUF_EXPORT Parser { // Returns the identifier used in the "syntax = " declaration, if one was // seen during the last call to Parse(), or the empty string otherwise. - const string& GetSyntaxIdentifier() { return syntax_identifier_; } + const std::string& GetSyntaxIdentifier() { return syntax_identifier_; } // If set true, input files will be required to begin with a syntax // identifier. Otherwise, files may omit this. If a syntax identifier @@ -163,7 +165,7 @@ class LIBPROTOBUF_EXPORT Parser { // where "text" is the expected token text. bool Consume(const char* text); // Consume a token of type IDENTIFIER and store its text in "output". - bool ConsumeIdentifier(string* output, const char* error); + bool ConsumeIdentifier(std::string* output, const char* error); // Consume an integer and store its value in "output". bool ConsumeInteger(int* output, const char* error); // Consume a signed integer and store its value in "output". @@ -175,7 +177,7 @@ class LIBPROTOBUF_EXPORT Parser { // tokens of either INTEGER or FLOAT type. bool ConsumeNumber(double* output, const char* error); // Consume a string literal and store its (unescaped) value in "output". - bool ConsumeString(string* output, const char* error); + bool ConsumeString(std::string* output, const char* error); // Consume a token representing the end of the statement. Comments between // this token and the next will be harvested for documentation. The given @@ -198,18 +200,18 @@ class LIBPROTOBUF_EXPORT Parser { // Error logging helpers // Invokes error_collector_->AddError(), if error_collector_ is not NULL. - void AddError(int line, int column, const string& error); + void AddError(int line, int column, const std::string& error); // Invokes error_collector_->AddError() with the line and column number // of the current token. - void AddError(const string& error); + void AddError(const std::string& error); // Records a location in the SourceCodeInfo.location table (see // descriptor.proto). We use RAII to ensure that the start and end locations // are recorded -- the constructor records the start location and the // destructor records the end location. Since the parser is // recursive-descent, this works out beautifully. - class LIBPROTOBUF_EXPORT LocationRecorder { + class PROTOBUF_EXPORT LocationRecorder { public: // Construct the file's "root" location. LocationRecorder(Parser* parser); @@ -264,8 +266,8 @@ class LIBPROTOBUF_EXPORT Parser { // // TODO(kenton): See comment on TryConsumeEndOfDeclaration(), above, for // why this is const. - void AttachComments(string* leading, string* trailing, - std::vector<string>* detached_comments) const; + void AttachComments(std::string* leading, std::string* trailing, + std::vector<std::string>* detached_comments) const; private: // Indexes of parent and current location in the parent @@ -313,7 +315,7 @@ class LIBPROTOBUF_EXPORT Parser { bool ParsePackage(FileDescriptorProto* file, const LocationRecorder& root_location, const FileDescriptorProto* containing_file); - bool ParseImport(RepeatedPtrField<string>* dependency, + bool ParseImport(RepeatedPtrField<std::string>* dependency, RepeatedField<int32>* public_dependency, RepeatedField<int32>* weak_dependency, const LocationRecorder& root_location, @@ -437,10 +439,10 @@ class LIBPROTOBUF_EXPORT Parser { // Parse a type name and fill in "type" (if it is a primitive) or // "type_name" (if it is not) with the type parsed. bool ParseType(FieldDescriptorProto::Type* type, - string* type_name); + std::string* type_name); // Parse a user-defined type and fill in "type_name" with the name. // If a primitive type is named, it is treated as an error. - bool ParseUserDefinedType(string* type_name); + bool ParseUserDefinedType(std::string* type_name); // Parses field options, i.e. the stuff in square brackets at the end // of a field definition. Also parses default value. @@ -489,7 +491,7 @@ class LIBPROTOBUF_EXPORT Parser { // REQUIRES: LookingAt("{") // When finished successfully, we are looking at the first token past // the ending brace. - bool ParseUninterpretedBlock(string* value); + bool ParseUninterpretedBlock(std::string* value); struct MapField { // Whether the field is a map field. @@ -498,8 +500,8 @@ class LIBPROTOBUF_EXPORT Parser { FieldDescriptorProto::Type key_type; FieldDescriptorProto::Type value_type; // Or the type names string if the types are customized types. - string key_type_name; - string value_type_name; + std::string key_type_name; + std::string value_type_name; MapField() : is_map_field(false) {} }; @@ -524,18 +526,18 @@ class LIBPROTOBUF_EXPORT Parser { bool had_errors_; bool require_syntax_identifier_; bool stop_after_syntax_identifier_; - string syntax_identifier_; + std::string syntax_identifier_; // Leading doc comments for the next declaration. These are not complete // yet; use ConsumeEndOfDeclaration() to get the complete comments. - string upcoming_doc_comments_; + std::string upcoming_doc_comments_; // Detached comments are not connected to any syntax entities. Elements in // this vector are paragraphs of comments separated by empty lines. The // detached comments will be put into the leading_detached_comments field for // the next element (See SourceCodeInfo.Location in descriptor.proto), when // ConsumeEndOfDeclaration() is called. - std::vector<string> upcoming_detached_comments_; + std::vector<std::string> upcoming_detached_comments_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser); }; @@ -548,7 +550,7 @@ class LIBPROTOBUF_EXPORT Parser { // far more complete information about source locations. However, as of this // writing you still need to use SourceLocationTable when integrating with // DescriptorPool. -class LIBPROTOBUF_EXPORT SourceLocationTable { +class PROTOBUF_EXPORT SourceLocationTable { public: SourceLocationTable(); ~SourceLocationTable(); @@ -581,4 +583,6 @@ class LIBPROTOBUF_EXPORT SourceLocationTable { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_PARSER_H__ diff --git a/src/google/protobuf/compiler/php/php_generator.h b/src/google/protobuf/compiler/php/php_generator.h index b851d9b4..283767ec 100644 --- a/src/google/protobuf/compiler/php/php_generator.h +++ b/src/google/protobuf/compiler/php/php_generator.h @@ -36,12 +36,14 @@ #include <string> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { namespace php { -class LIBPROTOC_EXPORT Generator +class PROTOC_EXPORT Generator : public google::protobuf::compiler::CodeGenerator { virtual bool Generate( const FileDescriptor* file, @@ -53,11 +55,11 @@ class LIBPROTOC_EXPORT Generator // To skip reserved keywords in php, some generated classname are prefixed. // Other code generators may need following API to figure out the actual // classname. -LIBPROTOC_EXPORT std::string GeneratedClassName( +PROTOC_EXPORT std::string GeneratedClassName( const google::protobuf::Descriptor* desc); -LIBPROTOC_EXPORT std::string GeneratedClassName( +PROTOC_EXPORT std::string GeneratedClassName( const google::protobuf::EnumDescriptor* desc); -LIBPROTOC_EXPORT std::string GeneratedClassName( +PROTOC_EXPORT std::string GeneratedClassName( const google::protobuf::ServiceDescriptor* desc); } // namespace php @@ -65,4 +67,6 @@ LIBPROTOC_EXPORT std::string GeneratedClassName( } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/plugin.h b/src/google/protobuf/compiler/plugin.h index c6649173..48db3c1c 100644 --- a/src/google/protobuf/compiler/plugin.h +++ b/src/google/protobuf/compiler/plugin.h @@ -64,7 +64,8 @@ #include <string> -#include <google/protobuf/stubs/common.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -74,17 +75,20 @@ class CodeGeneratorRequest; class CodeGeneratorResponse; // Implements main() for a protoc plugin exposing the given code generator. -LIBPROTOC_EXPORT int PluginMain(int argc, char* argv[], const CodeGenerator* generator); +PROTOC_EXPORT int PluginMain(int argc, char* argv[], + const CodeGenerator* generator); // Generates code using the given code generator. Returns true if the code // generation is successful. If the code geneartion fails, error_msg may be // populated to describe the failure cause. bool GenerateCode(const CodeGeneratorRequest& request, const CodeGenerator& generator, CodeGeneratorResponse* response, - string* error_msg); + std::string* error_msg); } // namespace compiler } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 7569f27f..234be0dd 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -13,10 +13,6 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> -// This is a temporary google only hack -#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS -#include "third_party/protobuf/version.h" -#endif // @@protoc_insertion_point(includes) #include <google/protobuf/port_def.inc> @@ -56,7 +52,7 @@ static void InitDefaultsVersion_google_2fprotobuf_2fcompiler_2fplugin_2eproto() ::google::protobuf::compiler::Version::InitAsDefaultInstance(); } -LIBPROTOC_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_Version_google_2fprotobuf_2fcompiler_2fplugin_2eproto = +PROTOC_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_Version_google_2fprotobuf_2fcompiler_2fplugin_2eproto = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsVersion_google_2fprotobuf_2fcompiler_2fplugin_2eproto}, {}}; static void InitDefaultsCodeGeneratorRequest_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { @@ -70,7 +66,7 @@ static void InitDefaultsCodeGeneratorRequest_google_2fprotobuf_2fcompiler_2fplug ::google::protobuf::compiler::CodeGeneratorRequest::InitAsDefaultInstance(); } -LIBPROTOC_EXPORT ::google::protobuf::internal::SCCInfo<2> scc_info_CodeGeneratorRequest_google_2fprotobuf_2fcompiler_2fplugin_2eproto = +PROTOC_EXPORT ::google::protobuf::internal::SCCInfo<2> scc_info_CodeGeneratorRequest_google_2fprotobuf_2fcompiler_2fplugin_2eproto = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 2, InitDefaultsCodeGeneratorRequest_google_2fprotobuf_2fcompiler_2fplugin_2eproto}, { &scc_info_FileDescriptorProto_google_2fprotobuf_2fdescriptor_2eproto.base, &scc_info_Version_google_2fprotobuf_2fcompiler_2fplugin_2eproto.base,}}; @@ -86,7 +82,7 @@ static void InitDefaultsCodeGeneratorResponse_File_google_2fprotobuf_2fcompiler_ ::google::protobuf::compiler::CodeGeneratorResponse_File::InitAsDefaultInstance(); } -LIBPROTOC_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_CodeGeneratorResponse_File_google_2fprotobuf_2fcompiler_2fplugin_2eproto = +PROTOC_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_CodeGeneratorResponse_File_google_2fprotobuf_2fcompiler_2fplugin_2eproto = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsCodeGeneratorResponse_File_google_2fprotobuf_2fcompiler_2fplugin_2eproto}, {}}; static void InitDefaultsCodeGeneratorResponse_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { @@ -100,7 +96,7 @@ static void InitDefaultsCodeGeneratorResponse_google_2fprotobuf_2fcompiler_2fplu ::google::protobuf::compiler::CodeGeneratorResponse::InitAsDefaultInstance(); } -LIBPROTOC_EXPORT ::google::protobuf::internal::SCCInfo<1> scc_info_CodeGeneratorResponse_google_2fprotobuf_2fcompiler_2fplugin_2eproto = +PROTOC_EXPORT ::google::protobuf::internal::SCCInfo<1> scc_info_CodeGeneratorResponse_google_2fprotobuf_2fcompiler_2fplugin_2eproto = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsCodeGeneratorResponse_google_2fprotobuf_2fcompiler_2fplugin_2eproto}, { &scc_info_CodeGeneratorResponse_File_google_2fprotobuf_2fcompiler_2fplugin_2eproto.base,}}; @@ -115,55 +111,55 @@ void InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { constexpr ::google::protobuf::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto = nullptr; constexpr ::google::protobuf::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto = nullptr; -const ::google::protobuf::uint32 TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::Version, _has_bits_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::Version, _internal_metadata_), +const ::google::protobuf::uint32 TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::Version, _has_bits_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::Version, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ ~0u, // no _weak_field_map_ - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::Version, major_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::Version, minor_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::Version, patch_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::Version, suffix_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::Version, major_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::Version, minor_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::Version, patch_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::Version, suffix_), 1, 2, 3, 0, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _has_bits_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _has_bits_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ ~0u, // no _weak_field_map_ - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, file_to_generate_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, parameter_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, proto_file_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, compiler_version_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, file_to_generate_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, parameter_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, proto_file_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorRequest, compiler_version_), ~0u, 0, ~0u, 1, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, _has_bits_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, _has_bits_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ ~0u, // no _weak_field_map_ - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, name_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, insertion_point_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, content_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, name_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, insertion_point_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse_File, content_), 0, 1, 2, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, _has_bits_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, _has_bits_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ ~0u, // no _weak_field_map_ - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, error_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, file_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, error_), + PROTOBUF_FIELD_OFFSET(::google::protobuf::compiler::CodeGeneratorResponse, file_), 0, ~0u, }; -static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { +static const ::google::protobuf::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { { 0, 9, sizeof(::google::protobuf::compiler::Version)}, { 13, 22, sizeof(::google::protobuf::compiler::CodeGeneratorRequest)}, { 26, 34, sizeof(::google::protobuf::compiler::CodeGeneratorResponse_File)}, @@ -323,15 +319,14 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob while (ptr < end) { ::google::protobuf::uint32 tag; ptr = Varint::Parse32Inline(ptr, &tag); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { - case 0: goto error; // optional int32 major = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 8) goto handle_unusual; ::google::protobuf::uint64 val; ptr = Varint::Parse64(ptr, &val); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_major(value); break; @@ -341,7 +336,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob if (static_cast<::google::protobuf::uint8>(tag) != 16) goto handle_unusual; ::google::protobuf::uint64 val; ptr = Varint::Parse64(ptr, &val); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_minor(value); break; @@ -351,7 +346,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob if (static_cast<::google::protobuf::uint8>(tag) != 24) goto handle_unusual; ::google::protobuf::uint64 val; ptr = Varint::Parse64(ptr, &val); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ::google::protobuf::int32 value = val; msg->set_patch(value); break; @@ -360,7 +355,7 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob case 4: { if (static_cast<::google::protobuf::uint8>(tag) != 34) goto handle_unusual; ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.Version.suffix"); parser_till_end = ::google::protobuf::internal::StringParserUTF8Verify; ::std::string* str = msg->mutable_suffix(); @@ -368,14 +363,15 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob object = str; if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; - ptr = newend; + if (size) ptr = parser_till_end(ptr, newend, object, ctx); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr == newend); break; } default: { handle_unusual: (void)&&handle_unusual; - if ((tag & 7) == 4) { - if (!ctx->ValidEndGroup(tag)) goto error; + if ((tag & 7) == 4 || tag == 0) { + bool ok = ctx->ValidEndGroup(tag); + GOOGLE_PROTOBUF_PARSER_ASSERT(ok); return ptr; } auto res = UnknownFieldParse(tag, {_InternalParse, msg}, @@ -386,8 +382,6 @@ const char* Version::_InternalParse(const char* begin, const char* end, void* ob } // switch } // while return ptr; -error: - return nullptr; len_delim_till_end: (void)&&len_delim_till_end; return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -399,7 +393,7 @@ group_continues: (void)&&group_continues; #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool Version::MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!GOOGLE_PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure +#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure ::google::protobuf::uint32 tag; // @@protoc_insertion_point(parse_start:google.protobuf.compiler.Version) for (;;) { @@ -806,15 +800,14 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* while (ptr < end) { ::google::protobuf::uint32 tag; ptr = Varint::Parse32Inline(ptr, &tag); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { - case 0: goto error; // repeated string file_to_generate = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; do { ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.file_to_generate"); parser_till_end = ::google::protobuf::internal::StringParserUTF8Verify; ::std::string* str = msg->add_file_to_generate(); @@ -822,17 +815,17 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* object = str; if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; - ptr = newend; + if (size) ptr = parser_till_end(ptr, newend, object, ctx); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr == newend); if (ptr >= end) break; - } while((*reinterpret_cast<const ::google::protobuf::uint64*>(ptr) & 255) == 10 && (ptr += 1)); + } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 10 && (ptr += 1)); break; } // optional string parameter = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorRequest.parameter"); parser_till_end = ::google::protobuf::internal::StringParserUTF8Verify; ::std::string* str = msg->mutable_parameter(); @@ -840,20 +833,22 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* object = str; if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; - ptr = newend; + if (size) ptr = parser_till_end(ptr, newend, object, ctx); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr == newend); break; } // optional .google.protobuf.compiler.Version compiler_version = 3; case 3: { if (static_cast<::google::protobuf::uint8>(tag) != 26) goto handle_unusual; ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::compiler::Version::_InternalParse; object = msg->mutable_compiler_version(); if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; + bool ok = ctx->ParseExactRange({parser_till_end, object}, + ptr, newend); + GOOGLE_PROTOBUF_PARSER_ASSERT(ok); ptr = newend; break; } @@ -862,21 +857,24 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; do { ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::FileDescriptorProto::_InternalParse; object = msg->add_proto_file(); if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; + bool ok = ctx->ParseExactRange({parser_till_end, object}, + ptr, newend); + GOOGLE_PROTOBUF_PARSER_ASSERT(ok); ptr = newend; if (ptr >= end) break; - } while((*reinterpret_cast<const ::google::protobuf::uint64*>(ptr) & 255) == 122 && (ptr += 1)); + } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 122 && (ptr += 1)); break; } default: { handle_unusual: (void)&&handle_unusual; - if ((tag & 7) == 4) { - if (!ctx->ValidEndGroup(tag)) goto error; + if ((tag & 7) == 4 || tag == 0) { + bool ok = ctx->ValidEndGroup(tag); + GOOGLE_PROTOBUF_PARSER_ASSERT(ok); return ptr; } auto res = UnknownFieldParse(tag, {_InternalParse, msg}, @@ -887,8 +885,6 @@ const char* CodeGeneratorRequest::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -error: - return nullptr; len_delim_till_end: (void)&&len_delim_till_end; return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -900,7 +896,7 @@ group_continues: (void)&&group_continues; #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool CodeGeneratorRequest::MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!GOOGLE_PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure +#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure ::google::protobuf::uint32 tag; // @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorRequest) for (;;) { @@ -1322,14 +1318,13 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const while (ptr < end) { ::google::protobuf::uint32 tag; ptr = Varint::Parse32Inline(ptr, &tag); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { - case 0: goto error; // optional string name = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.name"); parser_till_end = ::google::protobuf::internal::StringParserUTF8Verify; ::std::string* str = msg->mutable_name(); @@ -1337,15 +1332,15 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const object = str; if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; - ptr = newend; + if (size) ptr = parser_till_end(ptr, newend, object, ctx); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr == newend); break; } // optional string insertion_point = 2; case 2: { if (static_cast<::google::protobuf::uint8>(tag) != 18) goto handle_unusual; ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point"); parser_till_end = ::google::protobuf::internal::StringParserUTF8Verify; ::std::string* str = msg->mutable_insertion_point(); @@ -1353,15 +1348,15 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const object = str; if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; - ptr = newend; + if (size) ptr = parser_till_end(ptr, newend, object, ctx); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr == newend); break; } // optional string content = 15; case 15: { if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.File.content"); parser_till_end = ::google::protobuf::internal::StringParserUTF8Verify; ::std::string* str = msg->mutable_content(); @@ -1369,14 +1364,15 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const object = str; if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; - ptr = newend; + if (size) ptr = parser_till_end(ptr, newend, object, ctx); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr == newend); break; } default: { handle_unusual: (void)&&handle_unusual; - if ((tag & 7) == 4) { - if (!ctx->ValidEndGroup(tag)) goto error; + if ((tag & 7) == 4 || tag == 0) { + bool ok = ctx->ValidEndGroup(tag); + GOOGLE_PROTOBUF_PARSER_ASSERT(ok); return ptr; } auto res = UnknownFieldParse(tag, {_InternalParse, msg}, @@ -1387,8 +1383,6 @@ const char* CodeGeneratorResponse_File::_InternalParse(const char* begin, const } // switch } // while return ptr; -error: - return nullptr; len_delim_till_end: (void)&&len_delim_till_end; return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -1400,7 +1394,7 @@ group_continues: (void)&&group_continues; #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool CodeGeneratorResponse_File::MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!GOOGLE_PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure +#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure ::google::protobuf::uint32 tag; // @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorResponse.File) for (;;) { @@ -1772,14 +1766,13 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* while (ptr < end) { ::google::protobuf::uint32 tag; ptr = Varint::Parse32Inline(ptr, &tag); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); switch (tag >> 3) { - case 0: goto error; // optional string error = 1; case 1: { if (static_cast<::google::protobuf::uint8>(tag) != 10) goto handle_unusual; ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); ctx->extra_parse_data().SetFieldName("google.protobuf.compiler.CodeGeneratorResponse.error"); parser_till_end = ::google::protobuf::internal::StringParserUTF8Verify; ::std::string* str = msg->mutable_error(); @@ -1787,8 +1780,8 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* object = str; if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; - ptr = newend; + if (size) ptr = parser_till_end(ptr, newend, object, ctx); + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr == newend); break; } // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; @@ -1796,21 +1789,24 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* if (static_cast<::google::protobuf::uint8>(tag) != 122) goto handle_unusual; do { ptr = Varint::Parse32Inline(ptr, &size); - if (!ptr) goto error; + GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); parser_till_end = ::google::protobuf::compiler::CodeGeneratorResponse_File::_InternalParse; object = msg->add_file(); if (size > end - ptr) goto len_delim_till_end; auto newend = ptr + size; - if (!ctx->ParseExactRange({parser_till_end, object}, ptr, newend)) goto error; + bool ok = ctx->ParseExactRange({parser_till_end, object}, + ptr, newend); + GOOGLE_PROTOBUF_PARSER_ASSERT(ok); ptr = newend; if (ptr >= end) break; - } while((*reinterpret_cast<const ::google::protobuf::uint64*>(ptr) & 255) == 122 && (ptr += 1)); + } while ((::google::protobuf::io::UnalignedLoad<::google::protobuf::uint64>(ptr) & 255) == 122 && (ptr += 1)); break; } default: { handle_unusual: (void)&&handle_unusual; - if ((tag & 7) == 4) { - if (!ctx->ValidEndGroup(tag)) goto error; + if ((tag & 7) == 4 || tag == 0) { + bool ok = ctx->ValidEndGroup(tag); + GOOGLE_PROTOBUF_PARSER_ASSERT(ok); return ptr; } auto res = UnknownFieldParse(tag, {_InternalParse, msg}, @@ -1821,8 +1817,6 @@ const char* CodeGeneratorResponse::_InternalParse(const char* begin, const char* } // switch } // while return ptr; -error: - return nullptr; len_delim_till_end: (void)&&len_delim_till_end; return ctx->StoreAndTailCall(ptr, end, {_InternalParse, msg}, {parser_till_end, object}, size); @@ -1834,7 +1828,7 @@ group_continues: (void)&&group_continues; #else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER bool CodeGeneratorResponse::MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!GOOGLE_PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure +#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure ::google::protobuf::uint32 tag; // @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorResponse) for (;;) { @@ -2066,19 +2060,20 @@ void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) { } // namespace google namespace google { namespace protobuf { -template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::google::protobuf::compiler::Version* Arena::CreateMaybeMessage< ::google::protobuf::compiler::Version >(Arena* arena) { +template<> PROTOBUF_NOINLINE ::google::protobuf::compiler::Version* Arena::CreateMaybeMessage< ::google::protobuf::compiler::Version >(Arena* arena) { return Arena::CreateInternal< ::google::protobuf::compiler::Version >(arena); } -template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::google::protobuf::compiler::CodeGeneratorRequest* Arena::CreateMaybeMessage< ::google::protobuf::compiler::CodeGeneratorRequest >(Arena* arena) { +template<> PROTOBUF_NOINLINE ::google::protobuf::compiler::CodeGeneratorRequest* Arena::CreateMaybeMessage< ::google::protobuf::compiler::CodeGeneratorRequest >(Arena* arena) { return Arena::CreateInternal< ::google::protobuf::compiler::CodeGeneratorRequest >(arena); } -template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::google::protobuf::compiler::CodeGeneratorResponse_File* Arena::CreateMaybeMessage< ::google::protobuf::compiler::CodeGeneratorResponse_File >(Arena* arena) { +template<> PROTOBUF_NOINLINE ::google::protobuf::compiler::CodeGeneratorResponse_File* Arena::CreateMaybeMessage< ::google::protobuf::compiler::CodeGeneratorResponse_File >(Arena* arena) { return Arena::CreateInternal< ::google::protobuf::compiler::CodeGeneratorResponse_File >(arena); } -template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::google::protobuf::compiler::CodeGeneratorResponse* Arena::CreateMaybeMessage< ::google::protobuf::compiler::CodeGeneratorResponse >(Arena* arena) { +template<> PROTOBUF_NOINLINE ::google::protobuf::compiler::CodeGeneratorResponse* Arena::CreateMaybeMessage< ::google::protobuf::compiler::CodeGeneratorResponse >(Arena* arena) { return Arena::CreateInternal< ::google::protobuf::compiler::CodeGeneratorResponse >(arena); } } // namespace protobuf } // namespace google // @@protoc_insertion_point(global_scope) +#include <google/protobuf/port_undef.inc> diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 4b7527e5..187587ca 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -7,18 +7,19 @@ #include <limits> #include <string> -#include <google/protobuf/stubs/common.h> -#if GOOGLE_PROTOBUF_VERSION < 3006000 +#include <google/protobuf/port_def.inc> +#if PROTOBUF_VERSION < 3006001 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3006001 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. #endif +#include <google/protobuf/port_undef.inc> #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/arena.h> #include <google/protobuf/arenastring.h> @@ -33,7 +34,7 @@ #include <google/protobuf/descriptor.pb.h> // @@protoc_insertion_point(includes) #include <google/protobuf/port_def.inc> -#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fcompiler_2fplugin_2eproto LIBPROTOC_EXPORT +#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fcompiler_2fplugin_2eproto PROTOC_EXPORT #ifdef major #undef major #endif @@ -42,38 +43,38 @@ #endif // Internal implementation detail -- do not use these members. -struct LIBPROTOC_EXPORT TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto { +struct PROTOC_EXPORT TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto { static const ::google::protobuf::internal::ParseTableField entries[] - GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold); + PROTOBUF_SECTION_VARIABLE(protodesc_cold); static const ::google::protobuf::internal::AuxillaryParseTableField aux[] - GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold); + PROTOBUF_SECTION_VARIABLE(protodesc_cold); static const ::google::protobuf::internal::ParseTable schema[4] - GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold); + PROTOBUF_SECTION_VARIABLE(protodesc_cold); static const ::google::protobuf::internal::FieldMetadata field_metadata[]; static const ::google::protobuf::internal::SerializationTable serialization_table[]; static const ::google::protobuf::uint32 offsets[]; }; -void LIBPROTOC_EXPORT AddDescriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); +void PROTOC_EXPORT AddDescriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); namespace google { namespace protobuf { namespace compiler { class CodeGeneratorRequest; class CodeGeneratorRequestDefaultTypeInternal; -LIBPROTOC_EXPORT extern CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; +PROTOC_EXPORT extern CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; class CodeGeneratorResponse; class CodeGeneratorResponseDefaultTypeInternal; -LIBPROTOC_EXPORT extern CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; +PROTOC_EXPORT extern CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; class CodeGeneratorResponse_File; class CodeGeneratorResponse_FileDefaultTypeInternal; -LIBPROTOC_EXPORT extern CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; +PROTOC_EXPORT extern CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; class Version; class VersionDefaultTypeInternal; -LIBPROTOC_EXPORT extern VersionDefaultTypeInternal _Version_default_instance_; +PROTOC_EXPORT extern VersionDefaultTypeInternal _Version_default_instance_; } // namespace compiler -template<> LIBPROTOC_EXPORT ::google::protobuf::compiler::CodeGeneratorRequest* Arena::CreateMaybeMessage<::google::protobuf::compiler::CodeGeneratorRequest>(Arena*); -template<> LIBPROTOC_EXPORT ::google::protobuf::compiler::CodeGeneratorResponse* Arena::CreateMaybeMessage<::google::protobuf::compiler::CodeGeneratorResponse>(Arena*); -template<> LIBPROTOC_EXPORT ::google::protobuf::compiler::CodeGeneratorResponse_File* Arena::CreateMaybeMessage<::google::protobuf::compiler::CodeGeneratorResponse_File>(Arena*); -template<> LIBPROTOC_EXPORT ::google::protobuf::compiler::Version* Arena::CreateMaybeMessage<::google::protobuf::compiler::Version>(Arena*); +template<> PROTOC_EXPORT ::google::protobuf::compiler::CodeGeneratorRequest* Arena::CreateMaybeMessage<::google::protobuf::compiler::CodeGeneratorRequest>(Arena*); +template<> PROTOC_EXPORT ::google::protobuf::compiler::CodeGeneratorResponse* Arena::CreateMaybeMessage<::google::protobuf::compiler::CodeGeneratorResponse>(Arena*); +template<> PROTOC_EXPORT ::google::protobuf::compiler::CodeGeneratorResponse_File* Arena::CreateMaybeMessage<::google::protobuf::compiler::CodeGeneratorResponse_File>(Arena*); +template<> PROTOC_EXPORT ::google::protobuf::compiler::Version* Arena::CreateMaybeMessage<::google::protobuf::compiler::Version>(Arena*); } // namespace protobuf } // namespace google namespace google { @@ -82,7 +83,7 @@ namespace compiler { // =================================================================== -class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ { +class PROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ { public: Version(); virtual ~Version(); @@ -234,7 +235,7 @@ class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_ }; // ------------------------------------------------------------------- -class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { +class PROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { public: CodeGeneratorRequest(); virtual ~CodeGeneratorRequest(); @@ -408,7 +409,7 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message }; // ------------------------------------------------------------------- -class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse.File) */ { +class PROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse.File) */ { public: CodeGeneratorResponse_File(); virtual ~CodeGeneratorResponse_File(); @@ -568,7 +569,7 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M }; // ------------------------------------------------------------------- -class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse) */ { +class PROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse) */ { public: CodeGeneratorResponse(); virtual ~CodeGeneratorResponse(); diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h index 99a73832..c21c36da 100644 --- a/src/google/protobuf/compiler/python/python_generator.h +++ b/src/google/protobuf/compiler/python/python_generator.h @@ -39,6 +39,8 @@ #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -58,16 +60,16 @@ namespace python { // If you create your own protocol compiler binary and you want it to support // Python output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator : public CodeGenerator { +class PROTOC_EXPORT Generator : public CodeGenerator { public: Generator(); virtual ~Generator(); // CodeGenerator methods. virtual bool Generate(const FileDescriptor* file, - const string& parameter, + const std::string& parameter, GeneratorContext* generator_context, - string* error) const; + std::string* error) const; private: void PrintImports() const; @@ -84,7 +86,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void PrintFieldDescriptorsInDescriptor( const Descriptor& message_descriptor, bool is_extension, - const string& list_variable_name, + const std::string& list_variable_name, int (Descriptor::*CountFn)() const, const FieldDescriptor* (Descriptor::*GetterFn)(int) const) const; void PrintFieldsInDescriptor(const Descriptor& message_descriptor) const; @@ -94,11 +96,11 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void PrintNestedDescriptors(const Descriptor& containing_descriptor) const; void PrintMessages() const; - void PrintMessage(const Descriptor& message_descriptor, const string& prefix, - std::vector<string>* to_register) const; + void PrintMessage(const Descriptor& message_descriptor, const std::string& prefix, + std::vector<std::string>* to_register) const; void PrintNestedMessages(const Descriptor& containing_descriptor, - const string& prefix, - std::vector<string>* to_register) const; + const std::string& prefix, + std::vector<std::string>* to_register) const; void FixForeignFieldsInDescriptors() const; void FixForeignFieldsInDescriptor( @@ -106,14 +108,14 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { const Descriptor* containing_descriptor) const; void FixForeignFieldsInField(const Descriptor* containing_type, const FieldDescriptor& field, - const string& python_dict_name) const; + const std::string& python_dict_name) const; void AddMessageToFileDescriptor(const Descriptor& descriptor) const; void AddEnumToFileDescriptor(const EnumDescriptor& descriptor) const; void AddExtensionToFileDescriptor(const FieldDescriptor& descriptor) const; void AddServiceToFileDescriptor(const ServiceDescriptor& descriptor) const; - string FieldReferencingExpression(const Descriptor* containing_type, + std::string FieldReferencingExpression(const Descriptor* containing_type, const FieldDescriptor& field, - const string& python_dict_name) const; + const std::string& python_dict_name) const; template <typename DescriptorT> void FixContainingTypeInDescriptor( const DescriptorT& descriptor, @@ -133,13 +135,13 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { const ServiceDescriptor& descriptor) const; void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; - string OptionsValue(const string& serialized_options) const; + std::string OptionsValue(const std::string& serialized_options) const; bool GeneratingDescriptorProto() const; template <typename DescriptorT> - string ModuleLevelDescriptorName(const DescriptorT& descriptor) const; - string ModuleLevelMessageName(const Descriptor& descriptor) const; - string ModuleLevelServiceDescriptorName( + std::string ModuleLevelDescriptorName(const DescriptorT& descriptor) const; + std::string ModuleLevelMessageName(const Descriptor& descriptor) const; + std::string ModuleLevelServiceDescriptorName( const ServiceDescriptor& descriptor) const; template <typename DescriptorT, typename DescriptorProtoT> @@ -153,13 +155,13 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void FixOptionsForMessage(const Descriptor& descriptor) const; void CopyPublicDependenciesAliases( - const string& copy_from, const FileDescriptor* file) const; + const std::string& copy_from, const FileDescriptor* file) const; // Very coarse-grained lock to ensure that Generate() is reentrant. // Guards file_, printer_ and file_descriptor_serialized_. mutable Mutex mutex_; mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. - mutable string file_descriptor_serialized_; + mutable std::string file_descriptor_serialized_; mutable io::Printer* printer_; // Set in Generate(). Under mutex_. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator); @@ -170,4 +172,6 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.h b/src/google/protobuf/compiler/ruby/ruby_generator.h index 8c1dfa26..521697fb 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.h +++ b/src/google/protobuf/compiler/ruby/ruby_generator.h @@ -37,6 +37,8 @@ #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -46,7 +48,7 @@ namespace ruby { // If you create your own protocol compiler binary and you want it to support // Ruby output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator +class PROTOC_EXPORT Generator : public google::protobuf::compiler::CodeGenerator { virtual bool Generate( const FileDescriptor* file, @@ -60,5 +62,7 @@ class LIBPROTOC_EXPORT Generator } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__ diff --git a/src/google/protobuf/compiler/scc.h b/src/google/protobuf/compiler/scc.h index 69a47f1b..c8cf77d6 100644 --- a/src/google/protobuf/compiler/scc.h +++ b/src/google/protobuf/compiler/scc.h @@ -35,6 +35,8 @@ #include <google/protobuf/descriptor.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace compiler { @@ -52,7 +54,7 @@ struct SCC { // This class is used for analyzing the SCC for each message, to ensure linear // instead of quadratic performance, if we do this per message we would get // O(V*(V+E)). -class LIBPROTOC_EXPORT SCCAnalyzer { +class PROTOC_EXPORT SCCAnalyzer { public: explicit SCCAnalyzer() : index_(0) {} @@ -92,4 +94,6 @@ class LIBPROTOC_EXPORT SCCAnalyzer { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_SCC_H__ diff --git a/src/google/protobuf/compiler/subprocess.h b/src/google/protobuf/compiler/subprocess.h index dad5daba..977abff7 100644 --- a/src/google/protobuf/compiler/subprocess.h +++ b/src/google/protobuf/compiler/subprocess.h @@ -44,6 +44,8 @@ #include <string> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -52,7 +54,7 @@ class Message; namespace compiler { // Utility class for launching sub-processes. -class LIBPROTOC_EXPORT Subprocess { +class PROTOC_EXPORT Subprocess { public: Subprocess(); ~Subprocess(); @@ -64,19 +66,19 @@ class LIBPROTOC_EXPORT Subprocess { // Start the subprocess. Currently we don't provide a way to specify // arguments as protoc plugins don't have any. - void Start(const string& program, SearchMode search_mode); + void Start(const std::string& program, SearchMode search_mode); // Serialize the input message and pipe it to the subprocess's stdin, then // close the pipe. Meanwhile, read from the subprocess's stdout and parse // the data into *output. All this is done carefully to avoid deadlocks. // Returns true if successful. On any sort of error, returns false and sets // *error to a description of the problem. - bool Communicate(const Message& input, Message* output, string* error); + bool Communicate(const Message& input, Message* output, std::string* error); #ifdef _WIN32 // Given an error code, returns a human-readable error message. This is // defined here so that CommandLineInterface can share it. - static string Win32ErrorMessage(DWORD error_code); + static std::string Win32ErrorMessage(DWORD error_code); #endif private: @@ -104,4 +106,6 @@ class LIBPROTOC_EXPORT Subprocess { } // namespace protobuf } // namespace google +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ diff --git a/src/google/protobuf/compiler/zip_writer.h b/src/google/protobuf/compiler/zip_writer.h index 03db4d57..a99bb78c 100644 --- a/src/google/protobuf/compiler/zip_writer.h +++ b/src/google/protobuf/compiler/zip_writer.h @@ -73,12 +73,12 @@ class ZipWriter { ZipWriter(io::ZeroCopyOutputStream* raw_output); ~ZipWriter(); - bool Write(const string& filename, const string& contents); + bool Write(const std::string& filename, const std::string& contents); bool WriteDirectory(); private: struct FileInfo { - string name; + std::string name; uint32 offset; uint32 size; uint32 crc32; |