aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler')
-rw-r--r--src/google/protobuf/compiler/code_generator.h5
-rw-r--r--src/google/protobuf/compiler/command_line_interface.cc403
-rw-r--r--src/google/protobuf/compiler/command_line_interface.h58
-rw-r--r--src/google/protobuf/compiler/command_line_interface_unittest.cc433
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc9
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum.cc33
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum_field.cc32
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_extension.cc3
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_field.cc8
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_field.h5
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_file.cc140
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_generator.cc2
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_helpers.cc31
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_helpers.h27
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_map_field.cc13
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc823
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.h15
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message_field.cc81
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_move_unittest.cc169
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_options.h4
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_primitive_field.cc34
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.cc165
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.h1
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_unittest.cc69
-rw-r--r--src/google/protobuf/compiler/importer.cc13
-rw-r--r--src/google/protobuf/compiler/java/java_context.cc4
-rw-r--r--src/google/protobuf/compiler/java/java_context.h2
-rw-r--r--src/google/protobuf/compiler/java/java_enum.cc12
-rw-r--r--src/google/protobuf/compiler/java/java_enum_field.cc134
-rw-r--r--src/google/protobuf/compiler/java/java_enum_field_lite.cc134
-rw-r--r--src/google/protobuf/compiler/java/java_enum_lite.cc10
-rw-r--r--src/google/protobuf/compiler/java/java_extension.cc2
-rw-r--r--src/google/protobuf/compiler/java/java_field.cc63
-rw-r--r--src/google/protobuf/compiler/java/java_file.cc64
-rw-r--r--src/google/protobuf/compiler/java/java_generator.cc1
-rw-r--r--src/google/protobuf/compiler/java/java_helpers.cc10
-rw-r--r--src/google/protobuf/compiler/java/java_helpers.h17
-rw-r--r--src/google/protobuf/compiler/java/java_map_field.cc198
-rw-r--r--src/google/protobuf/compiler/java/java_map_field_lite.cc154
-rw-r--r--src/google/protobuf/compiler/java/java_message.cc103
-rw-r--r--src/google/protobuf/compiler/java/java_message_builder.cc48
-rw-r--r--src/google/protobuf/compiler/java/java_message_field.cc171
-rw-r--r--src/google/protobuf/compiler/java/java_message_field_lite.cc145
-rw-r--r--src/google/protobuf/compiler/java/java_message_lite.cc107
-rw-r--r--src/google/protobuf/compiler/java/java_name_resolver.cc1
-rw-r--r--src/google/protobuf/compiler/java/java_primitive_field.cc66
-rw-r--r--src/google/protobuf/compiler/java/java_primitive_field_lite.cc74
-rw-r--r--src/google/protobuf/compiler/java/java_string_field.cc95
-rw-r--r--src/google/protobuf/compiler/java/java_string_field_lite.cc130
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc77
-rw-r--r--src/google/protobuf/compiler/js/well_known_types/any.js2
-rw-r--r--src/google/protobuf/compiler/mock_code_generator.cc71
-rw-r--r--src/google/protobuf/compiler/mock_code_generator.h8
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_helpers.cc2
-rw-r--r--src/google/protobuf/compiler/parser.cc63
-rw-r--r--src/google/protobuf/compiler/parser_unittest.cc131
-rw-r--r--src/google/protobuf/compiler/plugin.cc3
-rw-r--r--src/google/protobuf/compiler/plugin.pb.cc214
-rw-r--r--src/google/protobuf/compiler/plugin.pb.h91
-rw-r--r--src/google/protobuf/compiler/plugin.proto1
-rw-r--r--src/google/protobuf/compiler/profile.pb.cc1453
-rw-r--r--src/google/protobuf/compiler/profile.pb.h728
-rw-r--r--src/google/protobuf/compiler/profile.proto68
-rw-r--r--src/google/protobuf/compiler/python/python_generator.cc44
-rw-r--r--src/google/protobuf/compiler/python/python_generator.h4
-rw-r--r--src/google/protobuf/compiler/subprocess.cc17
-rw-r--r--src/google/protobuf/compiler/subprocess.h1
-rwxr-xr-xsrc/google/protobuf/compiler/zip_output_unittest.sh17
-rw-r--r--src/google/protobuf/compiler/zip_writer.cc8
69 files changed, 3583 insertions, 3741 deletions
diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h
index 6ea5f18d..dd6a59d8 100644
--- a/src/google/protobuf/compiler/code_generator.h
+++ b/src/google/protobuf/compiler/code_generator.h
@@ -50,6 +50,7 @@ namespace io { class ZeroCopyOutputStream; }
class FileDescriptor;
namespace compiler {
+class AccessInfoMap;
class Version;
// Defined in this file.
@@ -112,7 +113,8 @@ class LIBPROTOC_EXPORT CodeGenerator {
// runs.
class LIBPROTOC_EXPORT GeneratorContext {
public:
- inline GeneratorContext() {}
+ inline GeneratorContext() {
+ }
virtual ~GeneratorContext();
// Opens the given file, truncating it if it exists, and returns a
@@ -148,6 +150,7 @@ class LIBPROTOC_EXPORT GeneratorContext {
// this GeneratorContext.
virtual void GetCompilerVersion(Version* version) const;
+
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext);
};
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index 4d894c82..5f864041 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -33,6 +33,8 @@
// Sanjay Ghemawat, Jeff Dean, and others.
#include <google/protobuf/compiler/command_line_interface.h>
+
+
#include <google/protobuf/stubs/platform_macros.h>
#include <stdio.h>
@@ -65,13 +67,21 @@
#endif
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/compiler/subprocess.h>
#include <google/protobuf/compiler/zip_writer.h>
+#include <google/protobuf/compiler/plugin.pb.h>
+#include <google/protobuf/compiler/code_generator.h>
+#include <google/protobuf/compiler/importer.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/printer.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/io/coded_stream.h>
@@ -98,8 +108,7 @@ namespace compiler {
#endif
namespace {
-#if defined(_WIN32) && !defined(__CYGWIN__)
-static const char* kPathSeparator = ";";
+#if defined(_MSC_VER)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::access;
@@ -108,8 +117,6 @@ using google::protobuf::internal::win32::mkdir;
using google::protobuf::internal::win32::open;
using google::protobuf::internal::win32::setmode;
using google::protobuf::internal::win32::write;
-#else
-static const char* kPathSeparator = ":";
#endif
static const char* kDefaultDirectDependenciesViolationMsg =
@@ -268,11 +275,14 @@ string PluginName(const string& plugin_prefix, const string& directive) {
// strip the "--" and "_out/_opt" and add the plugin prefix.
return plugin_prefix + "gen-" + directive.substr(2, directive.size() - 6);
}
+
} // namespace
// A MultiFileErrorCollector that prints errors to stderr.
-class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
- public io::ErrorCollector {
+class CommandLineInterface::ErrorPrinter
+ : public MultiFileErrorCollector,
+ public io::ErrorCollector,
+ public DescriptorPool::ErrorCollector {
public:
ErrorPrinter(ErrorFormat format, DiskSourceTree *tree = NULL)
: format_(format), tree_(tree), found_errors_(false) {}
@@ -299,6 +309,25 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
AddErrorOrWarning("input", line, column, message, "warning", std::clog);
}
+ // implements DescriptorPool::ErrorCollector-------------------------
+ void AddError(
+ const string& filename,
+ const string& element_name,
+ const Message* descriptor,
+ ErrorLocation location,
+ const string& message) {
+ AddErrorOrWarning(filename, -1, -1, message, "error", std::cerr);
+ }
+
+ void AddWarning(
+ const string& filename,
+ const string& element_name,
+ const Message* descriptor,
+ ErrorLocation location,
+ const string& message) {
+ AddErrorOrWarning(filename, -1, -1, message, "warning", std::clog);
+ }
+
bool FoundErrors() const { return found_errors_; }
private:
@@ -400,6 +429,13 @@ class CommandLineInterface::MemoryOutputStream
virtual int64 ByteCount() const { return inner_->ByteCount(); }
private:
+ // Checks to see if "filename_.meta" exists in directory_; if so, fixes the
+ // offsets in that GeneratedCodeInfo record to reflect bytes inserted in
+ // filename_ at original offset insertion_offset with length insertion_length.
+ // We assume that insertions will not occur within any given annotated span
+ // of text.
+ void UpdateMetadata(size_t insertion_offset, size_t insertion_length);
+
// Where to insert the string when it's done.
GeneratorContextImpl* directory_;
string filename_;
@@ -420,8 +456,7 @@ class CommandLineInterface::MemoryOutputStream
CommandLineInterface::GeneratorContextImpl::GeneratorContextImpl(
const std::vector<const FileDescriptor*>& parsed_files)
: parsed_files_(parsed_files),
- had_error_(false) {
-}
+ had_error_(false) {}
CommandLineInterface::GeneratorContextImpl::~GeneratorContextImpl() {
STLDeleteValues(&files_);
@@ -597,6 +632,44 @@ CommandLineInterface::MemoryOutputStream::MemoryOutputStream(
inner_(new io::StringOutputStream(&data_)) {
}
+void CommandLineInterface::MemoryOutputStream::UpdateMetadata(
+ size_t insertion_offset, size_t insertion_length) {
+ std::map<string, string*>::iterator meta_file =
+ directory_->files_.find(filename_ + ".meta");
+ if (meta_file == directory_->files_.end() || !meta_file->second) {
+ // No metadata was recorded for this file.
+ return;
+ }
+ string* encoded_data = meta_file->second;
+ GeneratedCodeInfo metadata;
+ bool is_text_format = false;
+ if (!metadata.ParseFromString(*encoded_data)) {
+ if (!TextFormat::ParseFromString(*encoded_data, &metadata)) {
+ // The metadata is invalid.
+ std::cerr << filename_
+ << ".meta: Could not parse metadata as wire or text format."
+ << std::endl;
+ return;
+ }
+ // Generators that use the public plugin interface emit text-format
+ // metadata (because in the public plugin protocol, file content must be
+ // UTF8-encoded strings).
+ is_text_format = true;
+ }
+ for (int i = 0; i < metadata.annotation_size(); ++i) {
+ GeneratedCodeInfo::Annotation* annotation = metadata.mutable_annotation(i);
+ if (annotation->begin() >= insertion_offset) {
+ annotation->set_begin(annotation->begin() + insertion_length);
+ annotation->set_end(annotation->end() + insertion_length);
+ }
+ }
+ if (is_text_format) {
+ TextFormat::PrintToString(metadata, encoded_data);
+ } else {
+ metadata.SerializeToString(encoded_data);
+ }
+}
+
CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// Make sure all data has been written.
inner_.reset();
@@ -674,6 +747,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
if (indent_.empty()) {
// No indent. This makes things easier.
target->insert(pos, data_);
+ UpdateMetadata(pos, data_.size());
} else {
// Calculate how much space we need.
int indent_size = 0;
@@ -683,6 +757,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// Make a hole for it.
target->insert(pos, data_.size() + indent_size, '\0');
+ UpdateMetadata(pos, data_.size() + indent_size);
// Now copy in the data.
string::size_type data_pos = 0;
@@ -710,6 +785,12 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// ===================================================================
+#if defined(_WIN32) && !defined(__CYGWIN__)
+const char* const CommandLineInterface::kPathSeparator = ";";
+#else
+const char* const CommandLineInterface::kPathSeparator = ":";
+#endif
+
CommandLineInterface::CommandLineInterface()
: mode_(MODE_COMPILE),
print_mode_(PRINT_NONE),
@@ -719,9 +800,7 @@ CommandLineInterface::CommandLineInterface()
kDefaultDirectDependenciesViolationMsg),
imports_in_descriptor_set_(false),
source_info_in_descriptor_set_(false),
- disallow_services_(false),
- inputs_are_proto_path_relative_(false) {
-}
+ disallow_services_(false) {}
CommandLineInterface::~CommandLineInterface() {}
void CommandLineInterface::RegisterGenerator(const string& flag_name,
@@ -762,61 +841,39 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
break;
}
- AddDefaultProtoPaths(&proto_path_);
-
- // Set up the source tree.
- DiskSourceTree source_tree;
- for (int i = 0; i < proto_path_.size(); i++) {
- source_tree.MapPath(proto_path_[i].first, proto_path_[i].second);
- }
-
- // Map input files to virtual paths if necessary.
- if (!inputs_are_proto_path_relative_) {
- if (!MakeInputsBeProtoPathRelative(&source_tree)) {
+ std::vector<const FileDescriptor*> parsed_files;
+ // null unless descriptor_set_in_names_.empty()
+ google::protobuf::scoped_ptr<DiskSourceTree> disk_source_tree;
+ google::protobuf::scoped_ptr<ErrorPrinter> error_collector;
+ google::protobuf::scoped_ptr<DescriptorPool> descriptor_pool;
+ google::protobuf::scoped_ptr<DescriptorDatabase> descriptor_database;
+ if (descriptor_set_in_names_.empty()) {
+ disk_source_tree.reset(new DiskSourceTree());
+ if (!InitializeDiskSourceTree(disk_source_tree.get())) {
return 1;
}
- }
+ error_collector.reset(
+ new ErrorPrinter(error_format_, disk_source_tree.get()));
- // Allocate the Importer.
- ErrorPrinter error_collector(error_format_, &source_tree);
- Importer importer(&source_tree, &error_collector);
-
- std::vector<const FileDescriptor*> parsed_files;
-
- // Parse each file.
- for (int i = 0; i < input_files_.size(); i++) {
- // Import the file.
- importer.AddUnusedImportTrackFile(input_files_[i]);
- const FileDescriptor* parsed_file = importer.Import(input_files_[i]);
- importer.ClearUnusedImportTrackFiles();
- if (parsed_file == NULL) return 1;
- parsed_files.push_back(parsed_file);
+ SourceTreeDescriptorDatabase* database =
+ new SourceTreeDescriptorDatabase(disk_source_tree.get());
+ database->RecordErrorsTo(error_collector.get());
+ descriptor_database.reset(database);
+ descriptor_pool.reset(new DescriptorPool(
+ descriptor_database.get(), database->GetValidationErrorCollector()));
+ } else {
+ error_collector.reset(new ErrorPrinter(error_format_));
- // Enforce --disallow_services.
- if (disallow_services_ && parsed_file->service_count() > 0) {
- std::cerr << parsed_file->name() << ": This file contains services, but "
- "--disallow_services was used." << std::endl;
+ SimpleDescriptorDatabase* database = new SimpleDescriptorDatabase();
+ descriptor_database.reset(database);
+ if (!PopulateSimpleDescriptorDatabase(database)) {
return 1;
}
-
- // Enforce --direct_dependencies
- if (direct_dependencies_explicitly_set_) {
- bool indirect_imports = false;
- for (int i = 0; i < parsed_file->dependency_count(); i++) {
- if (direct_dependencies_.find(parsed_file->dependency(i)->name()) ==
- direct_dependencies_.end()) {
- indirect_imports = true;
- std::cerr << parsed_file->name() << ": "
- << StringReplace(direct_dependencies_violation_msg_, "%s",
- parsed_file->dependency(i)->name(),
- true /* replace_all */)
- << std::endl;
- }
- }
- if (indirect_imports) {
- return 1;
- }
- }
+ descriptor_pool.reset(new DescriptorPool(database, error_collector.get()));
+ }
+ descriptor_pool->EnforceWeakDependencies(true);
+ if (!ParseInputFiles(descriptor_pool.get(), &parsed_files)) {
+ return 1;
}
// We construct a separate GeneratorContext for each output location. Note
@@ -869,15 +926,16 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
}
if (!dependency_out_name_.empty()) {
+ GOOGLE_DCHECK(disk_source_tree.get());
if (!GenerateDependencyManifestFile(parsed_files, output_directories,
- &source_tree)) {
+ disk_source_tree.get())) {
return 1;
}
}
STLDeleteValues(&output_directories);
- if (!descriptor_set_name_.empty()) {
+ if (!descriptor_set_out_name_.empty()) {
if (!WriteDescriptorSet(parsed_files)) {
return 1;
}
@@ -896,13 +954,13 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
return 1;
}
} else {
- if (!EncodeOrDecode(importer.pool())) {
+ if (!EncodeOrDecode(descriptor_pool.get())) {
return 1;
}
}
}
- if (error_collector.FoundErrors()) {
+ if (error_collector->FoundErrors()) {
return 1;
}
@@ -918,7 +976,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
break;
case PRINT_NONE:
GOOGLE_LOG(ERROR) << "If the code reaches here, it usually means a bug of "
- "flag parsing in the CommonadLineInterface.";
+ "flag parsing in the CommandLineInterface.";
return 1;
// Do not add a default case.
@@ -928,6 +986,112 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
return 0;
}
+bool CommandLineInterface::InitializeDiskSourceTree(
+ DiskSourceTree* source_tree) {
+ AddDefaultProtoPaths(&proto_path_);
+
+ // Set up the source tree.
+ for (int i = 0; i < proto_path_.size(); i++) {
+ source_tree->MapPath(proto_path_[i].first, proto_path_[i].second);
+ }
+
+ // Map input files to virtual paths if possible.
+ if (!MakeInputsBeProtoPathRelative(source_tree)) {
+ return false;
+ }
+ return true;
+}
+
+bool CommandLineInterface::PopulateSimpleDescriptorDatabase(
+ SimpleDescriptorDatabase* database) {
+ for (int i = 0; i < descriptor_set_in_names_.size(); i++) {
+ int fd;
+ do {
+ fd = open(descriptor_set_in_names_[i].c_str(), O_RDONLY | O_BINARY);
+ } while (fd < 0 && errno == EINTR);
+ if (fd < 0) {
+ std::cerr << descriptor_set_in_names_[i] << ": "
+ << strerror(ENOENT) << std::endl;
+ return false;
+ }
+
+ FileDescriptorSet file_descriptor_set;
+ bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd);
+ if (close(fd) != 0) {
+ std::cerr << descriptor_set_in_names_[i] << ": close: "
+ << strerror(errno);
+ return false;
+ }
+
+ if (!parsed) {
+ std::cerr << descriptor_set_in_names_[i] << ": Unable to parse."
+ << std::endl;
+ return false;
+ }
+
+ for (int j = 0; j < file_descriptor_set.file_size(); j++) {
+ FileDescriptorProto previously_added_file_descriptor_proto;
+ if (database->FindFileByName(file_descriptor_set.file(j).name(),
+ &previously_added_file_descriptor_proto)) {
+ // already present - skip
+ continue;
+ }
+ if (!database->Add(file_descriptor_set.file(j))) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool CommandLineInterface::ParseInputFiles(
+ DescriptorPool* descriptor_pool,
+ std::vector<const FileDescriptor*>* parsed_files) {
+
+ // Parse each file.
+ for (int i = 0; i < input_files_.size(); i++) {
+ // Import the file.
+ descriptor_pool->AddUnusedImportTrackFile(input_files_[i]);
+ const FileDescriptor* parsed_file =
+ descriptor_pool->FindFileByName(input_files_[i]);
+ descriptor_pool->ClearUnusedImportTrackFiles();
+ if (parsed_file == NULL) {
+ if (!descriptor_set_in_names_.empty()) {
+ std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl;
+ }
+ return false;
+ }
+ parsed_files->push_back(parsed_file);
+
+ // Enforce --disallow_services.
+ if (disallow_services_ && parsed_file->service_count() > 0) {
+ std::cerr << parsed_file->name() << ": This file contains services, but "
+ "--disallow_services was used." << std::endl;
+ return false;
+ }
+
+ // Enforce --direct_dependencies
+ if (direct_dependencies_explicitly_set_) {
+ bool indirect_imports = false;
+ for (int i = 0; i < parsed_file->dependency_count(); i++) {
+ if (direct_dependencies_.find(parsed_file->dependency(i)->name()) ==
+ direct_dependencies_.end()) {
+ indirect_imports = true;
+ std::cerr << parsed_file->name() << ": "
+ << StringReplace(direct_dependencies_violation_msg_, "%s",
+ parsed_file->dependency(i)->name(),
+ true /* replace_all */)
+ << std::endl;
+ }
+ }
+ if (indirect_imports) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
void CommandLineInterface::Clear() {
// Clear all members that are set by Run(). Note that we must not clear
// members which are set by other methods before Run() is called.
@@ -938,7 +1102,8 @@ void CommandLineInterface::Clear() {
direct_dependencies_violation_msg_ = kDefaultDirectDependenciesViolationMsg;
output_directives_.clear();
codec_type_.clear();
- descriptor_set_name_.clear();
+ descriptor_set_in_names_.clear();
+ descriptor_set_out_name_.clear();
dependency_out_name_.clear();
mode_ = MODE_COMPILE;
@@ -952,6 +1117,17 @@ void CommandLineInterface::Clear() {
bool CommandLineInterface::MakeInputsBeProtoPathRelative(
DiskSourceTree* source_tree) {
for (int i = 0; i < input_files_.size(); i++) {
+ // If the input file path is not a physical file path, it must be a virtual
+ // path.
+ if (access(input_files_[i].c_str(), F_OK) < 0) {
+ string disk_file;
+ if (source_tree->VirtualFileToDiskFile(input_files_[i], &disk_file)) {
+ return true;
+ } else {
+ std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl;
+ return false;
+ }
+ }
string virtual_file, shadowing_disk_file;
switch (source_tree->DiskFileToVirtualFile(
input_files_[i], &virtual_file, &shadowing_disk_file)) {
@@ -969,12 +1145,14 @@ bool CommandLineInterface::MakeInputsBeProtoPathRelative(
case DiskSourceTree::CANNOT_OPEN:
std::cerr << input_files_[i] << ": " << strerror(errno) << std::endl;
return false;
- case DiskSourceTree::NO_MAPPING:
- // First check if the file exists at all.
- if (access(input_files_[i].c_str(), F_OK) < 0) {
- // File does not even exist.
- std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl;
+ case DiskSourceTree::NO_MAPPING: {
+ // Try to interpret the path as a virtual path.
+ string disk_file;
+ if (source_tree->VirtualFileToDiskFile(input_files_[i], &disk_file)) {
+ return true;
} else {
+ // The input file path can't be mapped to any --proto_path and it also
+ // can't be interpreted as a virtual path.
std::cerr
<< input_files_[i]
<< ": File does not reside within any path "
@@ -983,9 +1161,11 @@ bool CommandLineInterface::MakeInputsBeProtoPathRelative(
"proto_path must be an exact prefix of the .proto file "
"names -- protoc is too dumb to figure out when two paths "
"(e.g. absolute and relative) are equivalent (it's harder "
- "than you think)." << std::endl;
+ "than you think)."
+ << std::endl;
+ return false;
}
- return false;
+ }
}
}
@@ -1081,7 +1261,7 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) {
return PARSE_ARGUMENT_FAIL;
}
if (mode_ == MODE_COMPILE && output_directives_.empty() &&
- descriptor_set_name_.empty()) {
+ descriptor_set_out_name_.empty()) {
std::cerr << "Missing output directives." << std::endl;
return PARSE_ARGUMENT_FAIL;
}
@@ -1096,11 +1276,11 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) {
<< std::endl;
return PARSE_ARGUMENT_FAIL;
}
- if (imports_in_descriptor_set_ && descriptor_set_name_.empty()) {
+ if (imports_in_descriptor_set_ && descriptor_set_out_name_.empty()) {
std::cerr << "--include_imports only makes sense when combined with "
"--descriptor_set_out." << std::endl;
}
- if (source_info_in_descriptor_set_ && descriptor_set_name_.empty()) {
+ if (source_info_in_descriptor_set_ && descriptor_set_out_name_.empty()) {
std::cerr << "--include_source_info only makes sense when combined with "
"--descriptor_set_out." << std::endl;
}
@@ -1187,11 +1367,20 @@ CommandLineInterface::InterpretArgument(const string& name,
input_files_.push_back(value);
} else if (name == "-I" || name == "--proto_path") {
+ if (!descriptor_set_in_names_.empty()) {
+ std::cerr << "Only one of " << name
+ << " and --descriptor_set_in can be specified."
+ << std::endl;
+ return PARSE_ARGUMENT_FAIL;
+ }
+
// Java's -classpath (and some other languages) delimits path components
// with colons. Let's accept that syntax too just to make things more
// intuitive.
std::vector<string> parts = Split(
- value, kPathSeparator, true);
+ value,
+ CommandLineInterface::kPathSeparator,
+ true);
for (int i = 0; i < parts.size(); i++) {
string virtual_path;
@@ -1249,8 +1438,38 @@ CommandLineInterface::InterpretArgument(const string& name,
} else if (name == "--direct_dependencies_violation_msg") {
direct_dependencies_violation_msg_ = value;
+ } else if (name == "--descriptor_set_in") {
+ if (!descriptor_set_in_names_.empty()) {
+ std::cerr << name << " may only be passed once. To specify multiple "
+ "descriptor sets, pass them all as a single "
+ "parameter separated by '"
+ << CommandLineInterface::kPathSeparator << "'."
+ << std::endl;
+ return PARSE_ARGUMENT_FAIL;
+ }
+ if (value.empty()) {
+ std::cerr << name << " requires a non-empty value." << std::endl;
+ return PARSE_ARGUMENT_FAIL;
+ }
+ if (!proto_path_.empty()) {
+ std::cerr << "Only one of " << name
+ << " and --proto_path can be specified."
+ << std::endl;
+ return PARSE_ARGUMENT_FAIL;
+ }
+ if (!dependency_out_name_.empty()) {
+ std::cerr << name << " cannot be used with --dependency_out."
+ << std::endl;
+ return PARSE_ARGUMENT_FAIL;
+ }
+
+ descriptor_set_in_names_ = Split(
+ value,
+ CommandLineInterface::kPathSeparator,
+ true);
+
} else if (name == "-o" || name == "--descriptor_set_out") {
- if (!descriptor_set_name_.empty()) {
+ if (!descriptor_set_out_name_.empty()) {
std::cerr << name << " may only be passed once." << std::endl;
return PARSE_ARGUMENT_FAIL;
}
@@ -1264,7 +1483,7 @@ CommandLineInterface::InterpretArgument(const string& name,
"same time." << std::endl;
return PARSE_ARGUMENT_FAIL;
}
- descriptor_set_name_ = value;
+ descriptor_set_out_name_ = value;
} else if (name == "--dependency_out") {
if (!dependency_out_name_.empty()) {
@@ -1275,6 +1494,11 @@ CommandLineInterface::InterpretArgument(const string& name,
std::cerr << name << " requires a non-empty value." << std::endl;
return PARSE_ARGUMENT_FAIL;
}
+ if (!descriptor_set_in_names_.empty()) {
+ std::cerr << name << " cannot be used with --descriptor_set_in."
+ << std::endl;
+ return PARSE_ARGUMENT_FAIL;
+ }
dependency_out_name_ = value;
} else if (name == "--include_imports") {
@@ -1314,7 +1538,7 @@ CommandLineInterface::InterpretArgument(const string& name,
<< std::endl;
return PARSE_ARGUMENT_FAIL;
}
- if (!output_directives_.empty() || !descriptor_set_name_.empty()) {
+ if (!output_directives_.empty() || !descriptor_set_out_name_.empty()) {
std::cerr << "Cannot use " << name
<< " and generate code or descriptors at the same time."
<< std::endl;
@@ -1380,7 +1604,7 @@ CommandLineInterface::InterpretArgument(const string& name,
<< "other info at the same time." << std::endl;
return PARSE_ARGUMENT_FAIL;
}
- if (!output_directives_.empty() || !descriptor_set_name_.empty()) {
+ if (!output_directives_.empty() || !descriptor_set_out_name_.empty()) {
std::cerr << "Cannot use " << name
<< " and generate code or descriptors at the same time."
<< std::endl;
@@ -1472,6 +1696,14 @@ void CommandLineInterface::PrintHelpText() {
" pairs in text format to standard output. No\n"
" PROTO_FILES should be given when using this\n"
" flag.\n"
+" --descriptor_set_in=FILES Specifies a delimited list of FILES\n"
+" each containing a FileDescriptorSet (a\n"
+" protocol buffer defined in descriptor.proto).\n"
+" The FileDescriptor for each of the PROTO_FILES\n"
+" provided will be loaded from these\n"
+" FileDescriptorSets. If a FileDescriptor\n"
+" appears multiple times, the first occurrence\n"
+" will be used.\n"
" -oFILE, Writes a FileDescriptorSet (a protocol buffer,\n"
" --descriptor_set_out=FILE defined in descriptor.proto) containing all of\n"
" the input files to FILE.\n"
@@ -1651,6 +1883,7 @@ bool CommandLineInterface::GeneratePluginOutput(
request.set_parameter(parameter);
}
+
std::set<const FileDescriptor*> already_seen;
for (int i = 0; i < parsed_files.size(); i++) {
request.add_file_to_generate(parsed_files[i]->name());
@@ -1819,24 +2052,24 @@ bool CommandLineInterface::WriteDescriptorSet(
int fd;
do {
- fd = open(descriptor_set_name_.c_str(),
+ fd = open(descriptor_set_out_name_.c_str(),
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
} while (fd < 0 && errno == EINTR);
if (fd < 0) {
- perror(descriptor_set_name_.c_str());
+ perror(descriptor_set_out_name_.c_str());
return false;
}
io::FileOutputStream out(fd);
if (!file_set.SerializeToZeroCopyStream(&out)) {
- std::cerr << descriptor_set_name_ << ": " << strerror(out.GetErrno())
+ std::cerr << descriptor_set_out_name_ << ": " << strerror(out.GetErrno())
<< std::endl;
out.Close();
return false;
}
if (!out.Close()) {
- std::cerr << descriptor_set_name_ << ": " << strerror(out.GetErrno())
+ std::cerr << descriptor_set_out_name_ << ": " << strerror(out.GetErrno())
<< std::endl;
return false;
}
diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h
index 997c1748..e6596575 100644
--- a/src/google/protobuf/compiler/command_line_interface.h
+++ b/src/google/protobuf/compiler/command_line_interface.h
@@ -52,17 +52,16 @@ namespace protobuf {
class Descriptor; // descriptor.h
class DescriptorPool; // descriptor.h
class FileDescriptor; // descriptor.h
+class FileDescriptorSet; // descriptor.h
class FileDescriptorProto; // descriptor.pb.h
template<typename T> class RepeatedPtrField; // repeated_field.h
+class SimpleDescriptorDatabase; // descriptor_database.h
-} // namespace protobuf
-
-namespace protobuf {
namespace compiler {
-class CodeGenerator; // code_generator.h
-class GeneratorContext; // code_generator.h
-class DiskSourceTree; // importer.h
+class CodeGenerator; // code_generator.h
+class GeneratorContext; // code_generator.h
+class DiskSourceTree; // importer.h
// This class implements the command-line interface to the protocol compiler.
// It is designed to make it very easy to create a custom protocol compiler
@@ -91,9 +90,21 @@ class DiskSourceTree; // importer.h
// The compiler is invoked with syntax like:
// protoc --cpp_out=outdir --foo_out=outdir --proto_path=src src/foo.proto
//
+// The .proto file to compile can be specified on the command line using either
+// its physical file path, or a virtual path relative to a diretory specified
+// in --proto_path. For example, for src/foo.proto, the following two protoc
+// invocations work the same way:
+// 1. protoc --proto_path=src src/foo.proto (physical file path)
+// 2. protoc --proto_path=src foo.proto (virtual path relative to src)
+//
+// If a file path can be interpreted both as a physical file path and as a
+// 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 {
public:
+ static const char* const kPathSeparator;
+
CommandLineInterface();
~CommandLineInterface();
@@ -175,17 +186,11 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// it calls strerror(). I'm not sure why you'd want to do this anyway.
int Run(int argc, const char* const argv[]);
- // Call SetInputsAreCwdRelative(true) if the input files given on the command
- // line should be interpreted relative to the proto import path specified
- // using --proto_path or -I flags. Otherwise, input file names will be
- // interpreted relative to the current working directory (or as absolute
- // paths if they start with '/'), though they must still reside inside
- // a directory given by --proto_path or the compiler will fail. The latter
- // mode is generally more intuitive and easier to use, especially e.g. when
- // defining implicit rules in Makefiles.
- void SetInputsAreProtoPathRelative(bool enable) {
- inputs_are_proto_path_relative_ = enable;
- }
+ // DEPRECATED. Calling this method has no effect. Protocol compiler now
+ // always try to find the .proto file relative to the current directory
+ // first and if the file is not found, it will then treat the input path
+ // as a virutal path.
+ void SetInputsAreProtoPathRelative(bool /* enable */) {}
// 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
@@ -243,6 +248,16 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// Print the --help text to stderr.
void PrintHelpText();
+ // Loads proto_path_ into the provided source_tree.
+ bool InitializeDiskSourceTree(DiskSourceTree* source_tree);
+
+ // Loads descriptor_set_in into the provided database
+ bool PopulateSimpleDescriptorDatabase(SimpleDescriptorDatabase* database);
+
+ // Parses input_files_ into parsed_files
+ bool ParseInputFiles(DescriptorPool* descriptor_pool,
+ std::vector<const FileDescriptor*>* parsed_files);
+
// Generate the given output file from the given input.
struct OutputDirective; // see below
bool GenerateOutput(const std::vector<const FileDescriptor*>& parsed_files,
@@ -383,9 +398,13 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// decoding. (Empty string indicates --decode_raw.)
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_;
+
// If --descriptor_set_out was given, this is the filename to which the
// FileDescriptorSet should be written. Otherwise, empty.
- string descriptor_set_name_;
+ 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.
@@ -408,9 +427,6 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// Was the --disallow_services flag used?
bool disallow_services_;
- // See SetInputsAreProtoPathRelative().
- bool inputs_are_proto_path_relative_;
-
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface);
};
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index 5fbb37a4..73d3e4c9 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -69,7 +69,7 @@ namespace google {
namespace protobuf {
namespace compiler {
-#if defined(_WIN32)
+#if defined(_MSC_VER)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::access;
@@ -127,10 +127,6 @@ class CommandLineInterfaceTest : public testing::Test {
// google3.
#endif // !PROTOBUF_OPENSOURCE
- void SetInputsAreProtoPathRelative(bool enable) {
- cli_.SetInputsAreProtoPathRelative(enable);
- }
-
// -----------------------------------------------------------------
// Methods to check the test results (called after Run()).
@@ -190,12 +186,17 @@ class CommandLineInterfaceTest : public testing::Test {
const string& insertions,
const string& proto_name,
const string& message_name);
+ void CheckGeneratedAnnotations(const string& name, const string& file);
void ExpectNullCodeGeneratorCalled(const string& parameter);
+
void ReadDescriptorSet(const string& filename,
FileDescriptorSet* descriptor_set);
+ void WriteDescriptorSet(const string& filename,
+ const FileDescriptorSet* descriptor_set);
+
void ExpectFileContent(const string& filename,
const string& content);
@@ -249,11 +250,6 @@ class CommandLineInterfaceTest::NullCodeGenerator : public CodeGenerator {
// ===================================================================
void CommandLineInterfaceTest::SetUp() {
- // Most of these tests were written before this option was added, so we
- // run with the option on (which used to be the only way) except in certain
- // tests where we turn it off.
- cli_.SetInputsAreProtoPathRelative(true);
-
temp_directory_ = TestTempDir() + "/proto2_cli_test_temp";
// If the temp directory already exists, it must be left over from a
@@ -279,6 +275,7 @@ void CommandLineInterfaceTest::SetUp() {
mock_generators_to_delete_.push_back(generator);
cli_.RegisterGenerator("--null_out", generator, "Null output.");
+
disallow_plugins_ = false;
}
@@ -469,12 +466,18 @@ void CommandLineInterfaceTest::ExpectGeneratedWithInsertions(
proto_name, temp_directory_);
}
+void CommandLineInterfaceTest::CheckGeneratedAnnotations(const string& name,
+ const string& file) {
+ MockCodeGenerator::CheckGeneratedAnnotations(name, file, temp_directory_);
+}
+
void CommandLineInterfaceTest::ExpectNullCodeGeneratorCalled(
const string& parameter) {
EXPECT_TRUE(null_generator_->called_);
EXPECT_EQ(parameter, null_generator_->parameter_);
}
+
void CommandLineInterfaceTest::ReadDescriptorSet(
const string& filename, FileDescriptorSet* descriptor_set) {
string path = temp_directory_ + "/" + filename;
@@ -486,6 +489,13 @@ void CommandLineInterfaceTest::ReadDescriptorSet(
}
}
+void CommandLineInterfaceTest::WriteDescriptorSet(
+ const string& filename, const FileDescriptorSet* descriptor_set) {
+ string binary_proto;
+ GOOGLE_CHECK(descriptor_set->SerializeToString(&binary_proto));
+ CreateTempFile(filename, binary_proto);
+}
+
void CommandLineInterfaceTest::ExpectCapturedStdout(
const string& expected_text) {
EXPECT_EQ(expected_text, captured_stdout_);
@@ -494,7 +504,8 @@ void CommandLineInterfaceTest::ExpectCapturedStdout(
void CommandLineInterfaceTest::ExpectCapturedStdoutSubstringWithZeroReturnCode(
const string& expected_substring) {
EXPECT_EQ(0, return_code_);
- EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, captured_stdout_);
+ EXPECT_PRED_FORMAT2(
+ testing::IsSubstring, expected_substring, captured_stdout_);
}
void CommandLineInterfaceTest::ExpectFileContent(
@@ -523,6 +534,22 @@ TEST_F(CommandLineInterfaceTest, BasicOutput) {
ExpectGenerated("test_generator", "", "foo.proto", "Foo");
}
+TEST_F(CommandLineInterfaceTest, BasicOutput_DescriptorSetIn) {
+ // Test that the common case works.
+ FileDescriptorSet file_descriptor_set;
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("foo.proto");
+ file_descriptor_proto->add_message_type()->set_name("Foo");
+
+ WriteDescriptorSet("foo.bin", &file_descriptor_set);
+
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin foo.proto");
+
+ ExpectNoErrors();
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
+}
+
TEST_F(CommandLineInterfaceTest, BasicPlugin) {
// Test that basic plugins work.
@@ -537,6 +564,23 @@ TEST_F(CommandLineInterfaceTest, BasicPlugin) {
ExpectGenerated("test_plugin", "", "foo.proto", "Foo");
}
+TEST_F(CommandLineInterfaceTest, BasicPlugin_DescriptorSetIn) {
+ // Test that basic plugins work.
+
+ FileDescriptorSet file_descriptor_set;
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("foo.proto");
+ file_descriptor_proto->add_message_type()->set_name("Foo");
+
+ WriteDescriptorSet("foo.bin", &file_descriptor_set);
+
+ Run("protocol_compiler --plug_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin foo.proto");
+
+ ExpectNoErrors();
+ ExpectGenerated("test_plugin", "", "foo.proto", "Foo");
+}
+
TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin) {
// Invoke a generator and a plugin at the same time.
@@ -552,6 +596,24 @@ TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin) {
ExpectGenerated("test_plugin", "", "foo.proto", "Foo");
}
+TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin_DescriptorSetIn) {
+ // Invoke a generator and a plugin at the same time.
+
+ FileDescriptorSet file_descriptor_set;
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("foo.proto");
+ file_descriptor_proto->add_message_type()->set_name("Foo");
+
+ WriteDescriptorSet("foo.bin", &file_descriptor_set);
+
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin foo.proto");
+
+ ExpectNoErrors();
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
+ ExpectGenerated("test_plugin", "", "foo.proto", "Foo");
+}
+
TEST_F(CommandLineInterfaceTest, MultipleInputs) {
// Test parsing multiple input files.
@@ -576,6 +638,34 @@ TEST_F(CommandLineInterfaceTest, MultipleInputs) {
"bar.proto", "Bar");
}
+TEST_F(CommandLineInterfaceTest, MultipleInputs_DescriptorSetIn) {
+ // Test parsing multiple input files.
+ FileDescriptorSet file_descriptor_set;
+
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("foo.proto");
+ file_descriptor_proto->add_message_type()->set_name("Foo");
+
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("bar.proto");
+ file_descriptor_proto->add_message_type()->set_name("Bar");
+
+ WriteDescriptorSet("foo.bin", &file_descriptor_set);
+
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin foo.proto bar.proto");
+
+ ExpectNoErrors();
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
+ "foo.proto", "Foo");
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
+ "bar.proto", "Bar");
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
+ "foo.proto", "Foo");
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
+ "bar.proto", "Bar");
+}
+
TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport) {
// Test parsing multiple input files with an import of a separate file.
@@ -606,6 +696,165 @@ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport) {
"bar.proto", "Bar");
}
+TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) {
+ // Test parsing multiple input files with an import of a separate file.
+ FileDescriptorSet file_descriptor_set;
+
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("foo.proto");
+ file_descriptor_proto->add_message_type()->set_name("Foo");
+
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("bar.proto");
+ file_descriptor_proto->add_dependency("baz.proto");
+ DescriptorProto* message = file_descriptor_proto->add_message_type();
+ message->set_name("Bar");
+ FieldDescriptorProto* field = message->add_field();
+ field->set_type_name("Baz");
+ field->set_name("a");
+ field->set_number(1);
+
+ WriteDescriptorSet("foo_and_bar.bin", &file_descriptor_set);
+
+ file_descriptor_set.clear_file();
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("baz.proto");
+ file_descriptor_proto->add_message_type()->set_name("Baz");
+
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("bat.proto");
+ file_descriptor_proto->add_dependency("baz.proto");
+ message = file_descriptor_proto->add_message_type();
+ message->set_name("Bat");
+ field = message->add_field();
+ field->set_type_name("Baz");
+ field->set_name("a");
+ field->set_number(1);
+
+ WriteDescriptorSet("baz_and_bat.bin", &file_descriptor_set);
+ Run(strings::Substitute(
+ "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir "
+ "--descriptor_set_in=$0 foo.proto bar.proto",
+ string("$tmpdir/foo_and_bar.bin") +
+ CommandLineInterface::kPathSeparator +
+ "$tmpdir/baz_and_bat.bin"));
+
+ ExpectNoErrors();
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
+ "foo.proto", "Foo");
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
+ "bar.proto", "Bar");
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
+ "foo.proto", "Foo");
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
+ "bar.proto", "Bar");
+
+ Run(strings::Substitute(
+ "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir "
+ "--descriptor_set_in=$0 baz.proto bat.proto",
+ string("$tmpdir/foo_and_bar.bin") +
+ CommandLineInterface::kPathSeparator +
+ "$tmpdir/baz_and_bat.bin"));
+
+ ExpectNoErrors();
+ ExpectGeneratedWithMultipleInputs("test_generator", "baz.proto,bat.proto",
+ "baz.proto", "Baz");
+ ExpectGeneratedWithMultipleInputs("test_generator", "baz.proto,bat.proto",
+ "bat.proto", "Bat");
+ ExpectGeneratedWithMultipleInputs("test_plugin", "baz.proto,bat.proto",
+ "baz.proto", "Baz");
+ ExpectGeneratedWithMultipleInputs("test_plugin", "baz.proto,bat.proto",
+ "bat.proto", "Bat");
+}
+
+TEST_F(CommandLineInterfaceTest,
+ MultipleInputsWithImport_DescriptorSetIn_DuplicateFileDescriptor) {
+ // Test parsing multiple input files with an import of a separate file.
+ FileDescriptorSet file_descriptor_set;
+
+ FileDescriptorProto foo_file_descriptor_proto;
+ foo_file_descriptor_proto.set_name("foo.proto");
+ foo_file_descriptor_proto.add_message_type()->set_name("Foo");
+
+ file_descriptor_set.add_file()->CopyFrom(foo_file_descriptor_proto);
+
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("bar.proto");
+ file_descriptor_proto->add_dependency("baz.proto");
+ file_descriptor_proto->add_dependency("foo.proto");
+ DescriptorProto* message = file_descriptor_proto->add_message_type();
+ message->set_name("Bar");
+ FieldDescriptorProto* field = message->add_field();
+ field->set_type_name("Baz");
+ field->set_name("a");
+ field->set_number(1);
+ field = message->add_field();
+ field->set_type_name("Foo");
+ field->set_name("f");
+ field->set_number(2);
+ WriteDescriptorSet("foo_and_bar.bin", &file_descriptor_set);
+
+ file_descriptor_set.clear_file();
+ file_descriptor_set.add_file()->CopyFrom(foo_file_descriptor_proto);
+
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("baz.proto");
+ file_descriptor_proto->add_dependency("foo.proto");
+ message = file_descriptor_proto->add_message_type();
+ message->set_name("Baz");
+ field = message->add_field();
+ field->set_type_name("Foo");
+ field->set_name("f");
+ field->set_number(1);
+ WriteDescriptorSet("foo_and_baz.bin", &file_descriptor_set);
+
+ Run(strings::Substitute(
+ "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir "
+ "--descriptor_set_in=$0 bar.proto",
+ string("$tmpdir/foo_and_bar.bin") +
+ CommandLineInterface::kPathSeparator +
+ "$tmpdir/foo_and_baz.bin"));
+
+ ExpectNoErrors();
+ ExpectGenerated("test_generator", "", "bar.proto", "Bar");
+ ExpectGenerated("test_plugin", "", "bar.proto", "Bar");
+}
+
+TEST_F(CommandLineInterfaceTest,
+ MultipleInputsWithImport_DescriptorSetIn_MissingImport) {
+ // Test parsing multiple input files with an import of a separate file.
+ FileDescriptorSet file_descriptor_set;
+
+ FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("foo.proto");
+ file_descriptor_proto->add_message_type()->set_name("Foo");
+
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("bar.proto");
+ file_descriptor_proto->add_dependency("baz.proto");
+ DescriptorProto* message = file_descriptor_proto->add_message_type();
+ message->set_name("Bar");
+ FieldDescriptorProto* field = message->add_field();
+ field->set_type_name("Baz");
+ field->set_name("a");
+ field->set_number(1);
+
+ WriteDescriptorSet("foo_and_bar.bin", &file_descriptor_set);
+
+ file_descriptor_set.clear_file();
+ file_descriptor_proto = file_descriptor_set.add_file();
+ file_descriptor_proto->set_name("baz.proto");
+ file_descriptor_proto->add_message_type()->set_name("Baz");
+
+ WriteDescriptorSet("baz.bin", &file_descriptor_set);
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo_and_bar.bin "
+ "foo.proto bar.proto");
+ ExpectErrorSubstring(
+ "bar.proto: Import \"baz.proto\" was not found or had errors.");
+ ExpectErrorSubstring("bar.proto: \"Baz\" is not defined.");
+}
+
TEST_F(CommandLineInterfaceTest, CreateDirectory) {
// Test that when we output to a sub-directory, it is created.
@@ -752,6 +1001,25 @@ TEST_F(CommandLineInterfaceTest, Insert) {
"foo.proto", "Foo");
}
+TEST_F(CommandLineInterfaceTest, InsertWithAnnotationFixup) {
+ // Check that annotation spans are updated after insertions.
+
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message MockCodeGenerator_Annotate {}\n");
+
+ Run("protocol_compiler "
+ "--test_out=TestParameter:$tmpdir "
+ "--plug_out=TestPluginParameter:$tmpdir "
+ "--test_out=insert=test_generator,test_plugin:$tmpdir "
+ "--plug_out=insert=test_generator,test_plugin:$tmpdir "
+ "--proto_path=$tmpdir foo.proto");
+
+ ExpectNoErrors();
+ CheckGeneratedAnnotations("test_generator", "foo.proto");
+ CheckGeneratedAnnotations("test_plugin", "foo.proto");
+}
+
#if defined(_WIN32)
TEST_F(CommandLineInterfaceTest, WindowsOutputPath) {
@@ -837,17 +1105,11 @@ TEST_F(CommandLineInterfaceTest, ColonDelimitedPath) {
"}\n");
CreateTempFile("b/foo.proto", "this should not be parsed\n");
-#undef PATH_SEPARATOR
-#if defined(_WIN32)
-#define PATH_SEPARATOR ";"
-#else
-#define PATH_SEPARATOR ":"
-#endif
-
- Run("protocol_compiler --test_out=$tmpdir "
- "--proto_path=$tmpdir/a" PATH_SEPARATOR "$tmpdir/b foo.proto");
-
-#undef PATH_SEPARATOR
+ Run(strings::Substitute(
+ "protocol_compiler --test_out=$$tmpdir --proto_path=$0 foo.proto",
+ string("$tmpdir/a") +
+ CommandLineInterface::kPathSeparator +
+ "$tmpdir/b"));
ExpectNoErrors();
ExpectGenerated("test_generator", "", "foo.proto", "Foo");
@@ -1057,8 +1319,6 @@ TEST_F(CommandLineInterfaceTest, DirectDependencies_CustomErrorMessage) {
TEST_F(CommandLineInterfaceTest, CwdRelativeInputs) {
// Test that we can accept working-directory-relative input files.
- SetInputsAreProtoPathRelative(false);
-
CreateTempFile("foo.proto",
"syntax = \"proto2\";\n"
"message Foo {}\n");
@@ -1316,6 +1576,17 @@ TEST_F(CommandLineInterfaceTest, ParseErrors) {
"foo.proto:2:1: Expected top-level statement (e.g. \"message\").\n");
}
+TEST_F(CommandLineInterfaceTest, ParseErrors_DescriptorSetIn) {
+ // Test that parse errors are reported.
+ CreateTempFile("foo.bin", "not a FileDescriptorSet");
+
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin foo.proto");
+
+ ExpectErrorText(
+ "$tmpdir/foo.bin: Unable to parse.\n");
+}
+
TEST_F(CommandLineInterfaceTest, ParseErrorsMultipleFiles) {
// Test that parse errors are reported from multiple files.
@@ -1362,16 +1633,23 @@ TEST_F(CommandLineInterfaceTest, InputNotFoundError) {
Run("protocol_compiler --test_out=$tmpdir "
"--proto_path=$tmpdir foo.proto");
+ ExpectErrorText("foo.proto: No such file or directory\n");
+}
+
+TEST_F(CommandLineInterfaceTest, InputNotFoundError_DescriptorSetIn) {
+ // Test what happens if the input file is not found.
+
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin foo.proto");
+
ExpectErrorText(
- "foo.proto: File not found.\n");
+ "$tmpdir/foo.bin: No such file or directory\n");
}
TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotFoundError) {
// Test what happens when a working-directory-relative input file is not
// found.
- SetInputsAreProtoPathRelative(false);
-
Run("protocol_compiler --test_out=$tmpdir "
"--proto_path=$tmpdir $tmpdir/foo.proto");
@@ -1383,8 +1661,6 @@ TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotMappedError) {
// Test what happens when a working-directory-relative input file is not
// mapped to a virtual path.
- SetInputsAreProtoPathRelative(false);
-
CreateTempFile("foo.proto",
"syntax = \"proto2\";\n"
"message Foo {}\n");
@@ -1409,8 +1685,6 @@ TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotFoundAndNotMappedError) {
// Check what happens if the input file is not found *and* is not mapped
// in the proto_path.
- SetInputsAreProtoPathRelative(false);
-
// Create a directory called "bar" so that we can point --proto_path at it.
CreateTempFile("bar/dummy", "");
@@ -1425,8 +1699,6 @@ TEST_F(CommandLineInterfaceTest, CwdRelativeInputShadowedError) {
// Test what happens when a working-directory-relative input file is shadowed
// by another file in the virtual path.
- SetInputsAreProtoPathRelative(false);
-
CreateTempFile("foo/foo.proto",
"syntax = \"proto2\";\n"
"message Foo {}\n");
@@ -1452,8 +1724,34 @@ TEST_F(CommandLineInterfaceTest, ProtoPathNotFoundError) {
"--proto_path=$tmpdir/foo foo.proto");
ExpectErrorText(
- "$tmpdir/foo: warning: directory does not exist.\n"
- "foo.proto: File not found.\n");
+ "$tmpdir/foo: warning: directory does not exist.\n"
+ "foo.proto: No such file or directory\n");
+}
+
+TEST_F(CommandLineInterfaceTest, ProtoPathAndDescriptorSetIn) {
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--proto_path=$tmpdir --descriptor_set_in=$tmpdir/foo.bin foo.proto");
+ ExpectErrorText(
+ "Only one of --descriptor_set_in and --proto_path can be specified.\n");
+
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin --proto_path=$tmpdir foo.proto");
+ ExpectErrorText(
+ "Only one of --proto_path and --descriptor_set_in can be specified.\n");
+}
+
+TEST_F(CommandLineInterfaceTest, ProtoPathAndDependencyOut) {
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--dependency_out=$tmpdir/manifest "
+ "--descriptor_set_in=$tmpdir/foo.bin foo.proto");
+ ExpectErrorText(
+ "--descriptor_set_in cannot be used with --dependency_out.\n");
+
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--descriptor_set_in=$tmpdir/foo.bin "
+ "--dependency_out=$tmpdir/manifest foo.proto");
+ ExpectErrorText(
+ "--dependency_out cannot be used with --descriptor_set_in.\n");
}
TEST_F(CommandLineInterfaceTest, MissingInputError) {
@@ -1903,9 +2201,16 @@ TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) {
// test as a shell script, but we'd like to be able to run the test on
// platforms that don't have a Bourne-compatible shell available (especially
// Windows/MSVC).
-class EncodeDecodeTest : public testing::Test {
+
+enum EncodeDecodeTestMode {
+ PROTO_PATH,
+ DESCRIPTOR_SET_IN
+};
+
+class EncodeDecodeTest : public testing::TestWithParam<EncodeDecodeTestMode> {
protected:
virtual void SetUp() {
+ WriteUnittestProtoDescriptorSet();
duped_stdin_ = dup(STDIN_FILENO);
}
@@ -1948,7 +2253,18 @@ class EncodeDecodeTest : public testing::Test {
std::vector<string> args;
args.push_back("protoc");
SplitStringUsing(command, " ", &args);
- args.push_back("--proto_path=" + TestSourceDir());
+ switch (GetParam()) {
+ case PROTO_PATH:
+ args.push_back("--proto_path=" + TestSourceDir());
+ break;
+ case DESCRIPTOR_SET_IN:
+ args.push_back(StrCat(
+ "--descriptor_set_in=",
+ unittest_proto_descriptor_set_filename_));
+ break;
+ default:
+ ADD_FAILURE() << "unexpected EncodeDecodeTestMode: " << GetParam();
+ }
google::protobuf::scoped_array<const char * > argv(new const char* [args.size()]);
for (int i = 0; i < args.size(); i++) {
@@ -1956,7 +2272,6 @@ class EncodeDecodeTest : public testing::Test {
}
CommandLineInterface cli;
- cli.SetInputsAreProtoPathRelative(true);
CaptureTestStdout();
CaptureTestStderr();
@@ -1994,12 +2309,37 @@ class EncodeDecodeTest : public testing::Test {
}
private:
+ void WriteUnittestProtoDescriptorSet() {
+ unittest_proto_descriptor_set_filename_ =
+ TestTempDir() + "/unittest_proto_descriptor_set.bin";
+ FileDescriptorSet file_descriptor_set;
+ protobuf_unittest::TestAllTypes test_all_types;
+ test_all_types.descriptor()->file()->CopyTo(file_descriptor_set.add_file());
+
+ protobuf_unittest_import::ImportMessage import_message;
+ import_message.descriptor()->file()->CopyTo(file_descriptor_set.add_file());
+
+
+ protobuf_unittest_import::PublicImportMessage public_import_message;
+ public_import_message.descriptor()->file()->CopyTo(
+ file_descriptor_set.add_file());
+ GOOGLE_DCHECK(file_descriptor_set.IsInitialized());
+
+ string binary_proto;
+ GOOGLE_CHECK(file_descriptor_set.SerializeToString(&binary_proto));
+ GOOGLE_CHECK_OK(File::SetContents(
+ unittest_proto_descriptor_set_filename_,
+ binary_proto,
+ true));
+ }
+
int duped_stdin_;
string captured_stdout_;
string captured_stderr_;
+ string unittest_proto_descriptor_set_filename_;
};
-TEST_F(EncodeDecodeTest, Encode) {
+TEST_P(EncodeDecodeTest, Encode) {
RedirectStdinFromFile(TestSourceDir() + "/google/protobuf/"
"testdata/text_format_unittest_data_oneof_implemented.txt");
EXPECT_TRUE(Run("google/protobuf/unittest.proto "
@@ -2009,7 +2349,7 @@ TEST_F(EncodeDecodeTest, Encode) {
ExpectStderrMatchesText("");
}
-TEST_F(EncodeDecodeTest, Decode) {
+TEST_P(EncodeDecodeTest, Decode) {
RedirectStdinFromFile(TestSourceDir() +
"/google/protobuf/testdata/golden_message_oneof_implemented");
EXPECT_TRUE(Run("google/protobuf/unittest.proto "
@@ -2020,7 +2360,7 @@ TEST_F(EncodeDecodeTest, Decode) {
ExpectStderrMatchesText("");
}
-TEST_F(EncodeDecodeTest, Partial) {
+TEST_P(EncodeDecodeTest, Partial) {
RedirectStdinFromText("");
EXPECT_TRUE(Run("google/protobuf/unittest.proto "
"--encode=protobuf_unittest.TestRequired"));
@@ -2029,7 +2369,7 @@ TEST_F(EncodeDecodeTest, Partial) {
"warning: Input message is missing required fields: a, b, c\n");
}
-TEST_F(EncodeDecodeTest, DecodeRaw) {
+TEST_P(EncodeDecodeTest, DecodeRaw) {
protobuf_unittest::TestAllTypes message;
message.set_optional_int32(123);
message.set_optional_string("foo");
@@ -2043,21 +2383,24 @@ TEST_F(EncodeDecodeTest, DecodeRaw) {
ExpectStderrMatchesText("");
}
-TEST_F(EncodeDecodeTest, UnknownType) {
+TEST_P(EncodeDecodeTest, UnknownType) {
EXPECT_FALSE(Run("google/protobuf/unittest.proto "
"--encode=NoSuchType"));
ExpectStdoutMatchesText("");
ExpectStderrMatchesText("Type not defined: NoSuchType\n");
}
-TEST_F(EncodeDecodeTest, ProtoParseError) {
+TEST_P(EncodeDecodeTest, ProtoParseError) {
EXPECT_FALSE(Run("google/protobuf/no_such_file.proto "
"--encode=NoSuchType"));
ExpectStdoutMatchesText("");
ExpectStderrMatchesText(
- "google/protobuf/no_such_file.proto: File not found.\n");
+ "google/protobuf/no_such_file.proto: No such file or directory\n");
}
+INSTANTIATE_TEST_CASE_P(FileDescriptorSetSource,
+ EncodeDecodeTest,
+ testing::Values(PROTO_PATH, DESCRIPTOR_SET_IN));
} // anonymous namespace
#endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
diff --git a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
index fce58c02..f99159f5 100644
--- a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
@@ -125,12 +125,9 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) {
importer.Import("google/protobuf/descriptor.proto");
const FileDescriptor* plugin_proto_file =
importer.Import("google/protobuf/compiler/plugin.proto");
- const FileDescriptor* profile_proto_file =
- importer.Import("google/protobuf/compiler/profile.proto");
EXPECT_EQ("", error_collector.text_);
ASSERT_TRUE(proto_file != NULL);
ASSERT_TRUE(plugin_proto_file != NULL);
- ASSERT_TRUE(profile_proto_file != NULL);
CppGenerator generator;
MockGeneratorContext context;
@@ -141,8 +138,6 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) {
parameter = "dllexport_decl=LIBPROTOC_EXPORT";
ASSERT_TRUE(generator.Generate(plugin_proto_file, parameter,
&context, &error));
- ASSERT_TRUE(generator.Generate(profile_proto_file, parameter,
- &context, &error));
context.ExpectFileMatches("google/protobuf/descriptor.pb.h",
"google/protobuf/descriptor.pb.h");
@@ -152,10 +147,6 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) {
"google/protobuf/compiler/plugin.pb.h");
context.ExpectFileMatches("google/protobuf/compiler/plugin.pb.cc",
"google/protobuf/compiler/plugin.pb.cc");
- context.ExpectFileMatches("google/protobuf/compiler/profile.pb.h",
- "google/protobuf/compiler/profile.pb.h");
- context.ExpectFileMatches("google/protobuf/compiler/profile.pb.cc",
- "google/protobuf/compiler/profile.pb.cc");
}
} // namespace
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc
index 6a8a83d1..3b4b97e6 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc
@@ -81,10 +81,16 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
std::map<string, string> vars;
vars["classname"] = classname_;
vars["short_name"] = descriptor_->name();
- vars["enumbase"] = classname_ + (options_.proto_h ? " : int" : "");
-
- printer->Print(vars, "enum $enumbase$ {\n");
- printer->Annotate("enumbase", descriptor_);
+ vars["enumbase"] = options_.proto_h ? " : int" : "";
+ // These variables are placeholders to pick out the beginning and ends of
+ // identifiers for annotations (when doing so with existing variables would
+ // be ambiguous or impossible). They should never be set to anything but the
+ // empty string.
+ vars["{"] = "";
+ vars["}"] = "";
+
+ printer->Print(vars, "enum $classname$$enumbase$ {\n");
+ printer->Annotate("classname", descriptor_);
printer->Indent();
const EnumValueDescriptor* min_value = descriptor_->value(0);
@@ -102,7 +108,8 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
" PROTOBUF_DEPRECATED" : "";
if (i > 0) printer->Print(",\n");
- printer->Print(vars, "$prefix$$name$$deprecation$ = $number$");
+ printer->Print(vars, "${$$prefix$$name$$}$$deprecation$ = $number$");
+ printer->Annotate("{", "}", descriptor_->value(i));
if (descriptor_->value(i)->number() < min_value->number()) {
min_value = descriptor_->value(i);
@@ -134,14 +141,20 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
}
printer->Print(vars,
- "$dllexport$bool $classname$_IsValid(int value);\n"
- "const $classname$ $prefix$$short_name$_MIN = $prefix$$min_name$;\n"
- "const $classname$ $prefix$$short_name$_MAX = $prefix$$max_name$;\n");
+ "$dllexport$bool $classname$_IsValid(int value);\n"
+ "const $classname$ ${$$prefix$$short_name$_MIN$}$ = "
+ "$prefix$$min_name$;\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(vars,
+ "const $classname$ ${$$prefix$$short_name$_MAX$}$ = "
+ "$prefix$$max_name$;\n");
+ printer->Annotate("{", "}", descriptor_);
if (generate_array_size_) {
printer->Print(vars,
- "const int $prefix$$short_name$_ARRAYSIZE = "
- "$prefix$$short_name$_MAX + 1;\n\n");
+ "const int ${$$prefix$$short_name$_ARRAYSIZE$}$ = "
+ "$prefix$$short_name$_MAX + 1;\n\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (HasDescriptorMethods(descriptor_->file(), options_)) {
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
index 960730ca..08a635fa 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
@@ -74,9 +74,11 @@ GeneratePrivateMembers(io::Printer* printer) const {
void EnumFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
+ printer->Print(variables_, "$deprecated_attr$$type$ $name$() const;\n");
+ printer->Annotate("name", descriptor_);
printer->Print(variables_,
- "$deprecated_attr$$type$ $name$() const;\n"
- "$deprecated_attr$void set_$name$($type$ value);\n");
+ "$deprecated_attr$void ${$set_$name$$}$($type$ value);\n");
+ printer->Annotate("{", "}", descriptor_);
}
void EnumFieldGenerator::
@@ -113,7 +115,7 @@ GenerateMergingCode(io::Printer* printer) const {
void EnumFieldGenerator::
GenerateSwappingCode(io::Printer* printer) const {
- printer->Print(variables_, "std::swap($name$_, other->$name$_);\n");
+ printer->Print(variables_, "swap($name$_, other->$name$_);\n");
}
void EnumFieldGenerator::
@@ -259,12 +261,23 @@ GeneratePrivateMembers(io::Printer* printer) const {
void RepeatedEnumFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$deprecated_attr$$type$ $name$(int index) const;\n"
- "$deprecated_attr$void set_$name$(int index, $type$ value);\n"
- "$deprecated_attr$void add_$name$($type$ value);\n");
+ "$deprecated_attr$$type$ $name$(int index) const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(int index, $type$ value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$add_$name$$}$($type$ value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$const ::google::protobuf::RepeatedField<int>& $name$() const;\n");
+ printer->Annotate("name", descriptor_);
printer->Print(variables_,
- "$deprecated_attr$const ::google::protobuf::RepeatedField<int>& $name$() const;\n"
- "$deprecated_attr$::google::protobuf::RepeatedField<int>* mutable_$name$();\n");
+ "$deprecated_attr$::google::protobuf::RepeatedField<int>* "
+ "${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedEnumFieldGenerator::
@@ -294,8 +307,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
printer->Print(variables,
" $name$_.Add(value);\n"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
- "}\n");
- printer->Print(variables,
+ "}\n"
"$inline$const ::google::protobuf::RepeatedField<int>&\n"
"$classname$::$name$() const {\n"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc
index e4fce461..6b1673b2 100644
--- a/src/google/protobuf/compiler/cpp/cpp_extension.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc
@@ -35,9 +35,10 @@
#include <google/protobuf/compiler/cpp/cpp_extension.h>
#include <map>
#include <google/protobuf/compiler/cpp/cpp_helpers.h>
-#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/stubs/strutil.h>
+
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc
index 4480a9d2..dce9617c 100644
--- a/src/google/protobuf/compiler/cpp/cpp_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_field.cc
@@ -95,6 +95,13 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
// By default, empty string, so that generic code used for both oneofs and
// singular fields can be written.
(*variables)["oneof_prefix"] = "";
+
+ // These variables are placeholders to pick out the beginning and ends of
+ // identifiers for annotations (when doing so with existing variables would
+ // be ambiguous or impossible). They should never be set to anything but the
+ // empty string.
+ (*variables)["{"] = "";
+ (*variables)["}"] = "";
}
void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor,
@@ -194,7 +201,6 @@ const FieldGenerator& FieldGeneratorMap::get(
return *field_generators_[field->index()];
}
-
} // namespace cpp
} // namespace compiler
} // namespace protobuf
diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h
index 00dc25d4..d9dd3850 100644
--- a/src/google/protobuf/compiler/cpp/cpp_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_field.h
@@ -180,10 +180,6 @@ class FieldGenerator {
virtual void GenerateDefaultInstanceAllocator(io::Printer* /*printer*/)
const {}
- // Generate code that should be run when ShutdownProtobufLibrary() is called,
- // to delete all dynamically-allocated objects.
- virtual void GenerateShutdownCode(io::Printer* /*printer*/) const {}
-
// Generate lines to decode this field, which will be placed inside the
// message's MergeFromCodedStream() method.
virtual void GenerateMergeFromCodedStream(io::Printer* printer) const = 0;
@@ -233,7 +229,6 @@ class FieldGeneratorMap {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
};
-
} // namespace cpp
} // namespace compiler
} // namespace protobuf
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index feb8ba65..a066a6a7 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -126,12 +126,20 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
new EnumGenerator(file->enum_type(i), options));
enum_generators_.push_back(enum_generators_owner_[i].get());
}
+ for (int i = 0; i < enum_generators_.size(); i++) {
+ enum_generators_[i]->index_in_metadata_ = i;
+ }
for (int i = 0; i < file->service_count(); i++) {
service_generators_owner_[i].reset(
new ServiceGenerator(file->service(i), options));
service_generators_.push_back(service_generators_owner_[i].get());
}
+ if (HasGenericServices(file_, options_)) {
+ for (int i = 0; i < service_generators_.size(); i++) {
+ service_generators_[i]->index_in_metadata_ = i;
+ }
+ }
for (int i = 0; i < file->extension_count(); i++) {
extension_generators_owner_[i].reset(
@@ -343,9 +351,10 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
"::";
}
printer->Print(
- "class $classname$DefaultTypeInternal : "
- "public ::google::protobuf::internal::ExplicitlyConstructed<$parent$$classname$> "
- "{\n",
+ "class $classname$DefaultTypeInternal {\n"
+ "public:\n"
+ " ::google::protobuf::internal::ExplicitlyConstructed<$parent$$classname$>\n"
+ " _instance;\n",
"parent", parent, "classname", message_generators_[i]->classname_);
printer->Indent();
message_generators_[i]->GenerateExtraDefaultFields(printer);
@@ -545,7 +554,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// table-driven parsing.
printer->Print("PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField\n"
- " const TableStruct::entries[] = {\n");
+ " const TableStruct::entries[] "
+ "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n");
printer->Indent();
std::vector<size_t> entries;
@@ -566,7 +576,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
"};\n"
"\n"
"PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField\n"
- " const TableStruct::aux[] = {\n");
+ " const TableStruct::aux[] "
+ "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n");
printer->Indent();
std::vector<size_t> aux_entries;
@@ -585,7 +596,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
printer->Print(
"};\n"
"PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const\n"
- " TableStruct::schema[] = {\n");
+ " TableStruct::schema[] "
+ "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n");
printer->Indent();
size_t offset = 0;
@@ -597,7 +609,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
}
if (message_generators_.empty()) {
- printer->Print("{ NULL, NULL, 0, -1, -1, false },\n");
+ printer->Print("{ NULL, NULL, 0, -1, -1, -1, -1, NULL, false },\n");
}
printer->Outdent();
@@ -605,9 +617,47 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
"};\n"
"\n");
+ if (!message_generators_.empty() && options_.table_driven_serialization) {
+ printer->Print(
+ "const ::google::protobuf::internal::FieldMetadata TableStruct::field_metadata[] "
+ "= {\n");
+ printer->Indent();
+ std::vector<int> field_metadata_offsets;
+ int idx = 0;
+ for (int i = 0; i < message_generators_.size(); i++) {
+ field_metadata_offsets.push_back(idx);
+ idx += message_generators_[i]->GenerateFieldMetadata(printer);
+ }
+ field_metadata_offsets.push_back(idx);
+ printer->Outdent();
+ printer->Print(
+ "};\n"
+ "const ::google::protobuf::internal::SerializationTable "
+ "TableStruct::serialization_table[] = {\n");
+ printer->Indent();
+ // We rely on the order we layout the tables to match the order we
+ // calculate them with FlattenMessagesInFile, so we check here that
+ // these match exactly.
+ std::vector<const Descriptor*> calculated_order =
+ FlattenMessagesInFile(file_);
+ GOOGLE_CHECK_EQ(calculated_order.size(), message_generators_.size());
+ for (int i = 0; i < message_generators_.size(); i++) {
+ GOOGLE_CHECK_EQ(calculated_order[i], message_generators_[i]->descriptor_);
+ printer->Print(
+ "{$num_fields$, TableStruct::field_metadata + $index$},\n",
+ "classname", message_generators_[i]->classname_, "num_fields",
+ SimpleItoa(field_metadata_offsets[i + 1] - field_metadata_offsets[i]),
+ "index", SimpleItoa(field_metadata_offsets[i]));
+ }
+ printer->Outdent();
+ printer->Print(
+ "};\n"
+ "\n");
+ }
if (HasDescriptorMethods(file_, options_)) {
if (!message_generators_.empty()) {
- printer->Print("const ::google::protobuf::uint32 TableStruct::offsets[] = {\n");
+ printer->Print("const ::google::protobuf::uint32 TableStruct::offsets[] "
+ "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n");
printer->Indent();
std::vector<std::pair<size_t, size_t> > pairs;
for (int i = 0; i < message_generators_.size(); i++) {
@@ -616,8 +666,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
printer->Outdent();
printer->Print(
"};\n"
- "\n"
- "static const ::google::protobuf::internal::MigrationSchema schemas[] = {\n");
+ "static const ::google::protobuf::internal::MigrationSchema schemas[] "
+ "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n");
printer->Indent();
{
int offset = 0;
@@ -648,7 +698,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// we still need these symbols to exist
printer->Print(
// MSVC doesn't like empty arrays, so we add a dummy.
- "const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u };\n"
+ "const ::google::protobuf::uint32 TableStruct::offsets[1] = {};\n"
"static const ::google::protobuf::internal::MigrationSchema* schemas = NULL;\n"
"static const ::google::protobuf::Message* const* "
"file_default_instances = NULL;\n");
@@ -691,7 +741,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
printer->Print(
"file_level_metadata[$index$].reflection = "
"$parent$::$classname$::CreateReflection(file_level_metadata[$index$]"
- ".descriptor, _$classname$_default_instance_.get_mutable());\n",
+ ".descriptor, _$classname$_default_instance_._instance.get_mutable());\n",
"index", SimpleItoa(i), "parent",
ClassName(message_generators_[i]->descriptor_->containing_type(),
false),
@@ -738,33 +788,6 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
"} // namespace\n");
}
- // -----------------------------------------------------------------
-
- // ShutdownFile(): Deletes descriptors, default instances, etc. on shutdown.
- printer->Print(
- "\n"
- "void TableStruct::Shutdown() {\n");
- printer->Indent();
-
- for (int i = 0; i < message_generators_.size(); i++) {
- message_generators_[i]->GenerateShutdownCode(printer);
- }
-
- if (HasDescriptorMethods(file_, options_)) {
- for (int i = 0; i < message_generators_.size(); i++) {
- if (!IsMapEntryMessage(message_generators_[i]->descriptor_)) continue;
- printer->Print(
- "delete file_level_metadata[$index$].reflection;\n",
- "index", SimpleItoa(i));
- }
- }
-
- printer->Outdent();
- printer->Print(
- "}\n\n");
-
- // -----------------------------------------------------------------
-
// Now generate the InitDefaultsImpl() function.
printer->Print(
"void TableStruct::InitDefaultsImpl() {\n"
@@ -826,7 +849,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
string file_data;
file_proto.SerializeToString(&file_data);
- printer->Print("static const char descriptor[] = {\n");
+ printer->Print("static const char descriptor[] "
+ "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n");
printer->Indent();
if (file_data.size() > 66535) {
@@ -877,9 +901,6 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
file_namespace);
}
- printer->Print(
- "::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);\n");
-
printer->Outdent();
printer->Print(
"}\n"
@@ -1022,11 +1043,11 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
"#include <google/protobuf/map.h>"
" // IWYU pragma: export\n");
if (HasDescriptorMethods(file_, options_)) {
- printer->Print(
- "#include <google/protobuf/map_field_inl.h>\n");
+ printer->Print("#include <google/protobuf/map_entry.h>\n");
+ printer->Print("#include <google/protobuf/map_field_inl.h>\n");
} else {
- printer->Print(
- "#include <google/protobuf/map_field_lite.h>\n");
+ printer->Print("#include <google/protobuf/map_entry_lite.h>\n");
+ printer->Print("#include <google/protobuf/map_field_lite.h>\n");
}
}
@@ -1093,7 +1114,7 @@ void FileGenerator::GenerateDependencyIncludes(io::Printer* printer) {
void FileGenerator::GenerateGlobalStateFunctionDeclarations(
io::Printer* printer) {
- // Forward-declare the AddDescriptors, AssignDescriptors, and ShutdownFile
+ // Forward-declare the AddDescriptors, AssignDescriptors
// functions, so that we can declare them to be friends of each class.
printer->Print(
"\n"
@@ -1104,12 +1125,14 @@ void FileGenerator::GenerateGlobalStateFunctionDeclarations(
" static const ::google::protobuf::internal::AuxillaryParseTableField aux[];\n"
" static const ::google::protobuf::internal::ParseTable schema[];\n"
" static const ::google::protobuf::uint32 offsets[];\n"
+ " static const ::google::protobuf::internal::FieldMetadata field_metadata[];\n"
+ " static const ::google::protobuf::internal::SerializationTable "
+ "serialization_table[];\n"
// The following function(s) need to be able to access private members of
// the messages defined in the file. So we make them static members.
// This is the internal implementation of InitDefaults. It should only
// be called by InitDefaults which makes sure it will be called only once.
" static void InitDefaultsImpl();\n"
- " static void Shutdown();\n"
"};\n"
"void $dllexport_decl$AddDescriptors();\n"
"void $dllexport_decl$InitDefaults();\n"
@@ -1199,6 +1222,13 @@ void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) {
// dependent.
printer->Print("#if !PROTOBUF_INLINE_NOT_IN_HEADERS\n");
+ // TODO(gerbens) remove pragmas when gcc is no longer used. Current version
+ // of gcc fires a bogus error when compiled with strict-aliasing.
+ printer->Print(
+ "#ifdef __GNUC__\n"
+ " #pragma GCC diagnostic push\n"
+ " #pragma GCC diagnostic ignored \"-Wstrict-aliasing\"\n"
+ "#endif // __GNUC__\n");
// Generate class inline methods.
for (int i = 0; i < message_generators_.size(); i++) {
if (i > 0) {
@@ -1208,6 +1238,10 @@ void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) {
message_generators_[i]->GenerateInlineMethods(printer,
/* is_inline = */ true);
}
+ printer->Print(
+ "#ifdef __GNUC__\n"
+ " #pragma GCC diagnostic pop\n"
+ "#endif // __GNUC__\n");
printer->Print("#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS\n");
for (int i = 0; i < message_generators_.size(); i++) {
@@ -1224,13 +1258,8 @@ void FileGenerator::GenerateProto2NamespaceEnumSpecializations(
io::Printer* printer) {
// Emit GetEnumDescriptor specializations into google::protobuf namespace:
if (HasEnumDefinitions(file_)) {
- // The SWIG conditional is to avoid a null-pointer dereference
- // (bug 1984964) in swig-1.3.21 resulting from the following syntax:
- // namespace X { void Y<Z::W>(); }
- // which appears in GetEnumDescriptor() specializations.
printer->Print(
"\n"
- "#ifndef SWIG\n"
"namespace google {\nnamespace protobuf {\n"
"\n");
for (int i = 0; i < enum_generators_.size(); i++) {
@@ -1238,8 +1267,7 @@ void FileGenerator::GenerateProto2NamespaceEnumSpecializations(
}
printer->Print(
"\n"
- "} // namespace protobuf\n} // namespace google\n"
- "#endif // SWIG\n");
+ "} // namespace protobuf\n} // namespace google\n");
}
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc
index cee31224..68abd0ef 100644
--- a/src/google/protobuf/compiler/cpp/cpp_generator.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc
@@ -100,6 +100,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.enforce_lite = true;
} else if (options[i].first == "table_driven_parsing") {
file_options.table_driven_parsing = true;
+ } else if (options[i].first == "table_driven_serialization") {
+ file_options.table_driven_serialization = true;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
index 9cddba5c..00959796 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
@@ -37,14 +37,16 @@
#include <vector>
#include <google/protobuf/stubs/hash.h>
-#include <google/protobuf/compiler/cpp/cpp_helpers.h>
-#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/compiler/cpp/cpp_helpers.h>
+#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+
+
namespace google {
namespace protobuf {
namespace compiler {
@@ -167,6 +169,11 @@ string ClassName(const EnumDescriptor* enum_descriptor, bool qualified) {
}
}
+string DefaultInstanceName(const Descriptor* descriptor) {
+ string prefix = descriptor->file()->package().empty() ? "" : "::";
+ return prefix + DotsToColons(descriptor->file()->package()) + "::_" +
+ ClassName(descriptor, false) + "_default_instance_";
+}
string DependentBaseClassTemplateName(const Descriptor* descriptor) {
return ClassName(descriptor, false) + "_InternalBase";
@@ -654,6 +661,26 @@ void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field,
"VerifyUtf8Cord", "VerifyUTF8CordNamedField", printer);
}
+namespace {
+
+void Flatten(const Descriptor* descriptor,
+ std::vector<const Descriptor*>* flatten) {
+ for (int i = 0; i < descriptor->nested_type_count(); i++)
+ Flatten(descriptor->nested_type(i), flatten);
+ flatten->push_back(descriptor);
+}
+
+} // namespace
+
+std::vector<const Descriptor*> FlattenMessagesInFile(
+ const FileDescriptor* file) {
+ std::vector<const Descriptor*> result;
+ for (int i = 0; i < file->message_type_count(); i++) {
+ Flatten(file->message_type(i), &result);
+ }
+ return result;
+}
+
bool HasWeakFields(const Descriptor* descriptor) {
return false;
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h
index a744a865..6ae68591 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.h
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -67,6 +67,9 @@ extern const char kThinSeparator[];
string ClassName(const Descriptor* descriptor, bool qualified);
string ClassName(const EnumDescriptor* enum_descriptor, bool qualified);
+// Fully qualified name of the default_instance of this message.
+string DefaultInstanceName(const Descriptor* descriptor);
+
// Name of the CRTP class template (for use with proto_h).
// This is a class name, like "ProtoName_InternalBase".
string DependentBaseClassTemplateName(const Descriptor* descriptor);
@@ -159,8 +162,18 @@ string SafeFunctionName(const Descriptor* descriptor,
const FieldDescriptor* field,
const string& prefix);
-// Returns true if unknown fields are preseved after parsing.
-inline bool PreserveUnknownFields(const Descriptor* message) {
+// Returns true if unknown fields are always preserved after parsing.
+inline bool AlwaysPreserveUnknownFields(const FileDescriptor* file) {
+ return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
+}
+
+// Returns true if unknown fields are preserved after parsing.
+inline bool AlwaysPreserveUnknownFields(const Descriptor* message) {
+ return AlwaysPreserveUnknownFields(message->file());
+}
+
+// Returns true if generated messages have public unknown fields accessors
+inline bool PublicUnknownFieldsAccessors(const Descriptor* message) {
return message->file()->syntax() != FileDescriptor::SYNTAX_PROTO3;
}
@@ -168,10 +181,8 @@ inline bool PreserveUnknownFields(const Descriptor* message) {
::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor(
const FileDescriptor* file, const Options& options);
-// If PreserveUnknownFields() is true, determines whether unknown
-// fields will be stored in an UnknownFieldSet or a string.
-// If PreserveUnknownFields() is false, this method will not be
-// used.
+// Determines whether unknown fields will be stored in an UnknownFieldSet or
+// a string.
inline bool UseUnknownFieldSet(const FileDescriptor* file,
const Options& options) {
return GetOptimizeFor(file, options) != FileOptions::LITE_RUNTIME;
@@ -277,6 +288,10 @@ inline ::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor(
: file->options().optimize_for();
}
+// This orders the messages in a .pb.cc as it's outputted by file.cc
+std::vector<const Descriptor*> FlattenMessagesInFile(
+ const FileDescriptor* file);
+
bool HasWeakFields(const Descriptor* desc);
bool HasWeakFields(const FileDescriptor* desc);
diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc
index d76db169..da33d29b 100644
--- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc
@@ -150,6 +150,7 @@ GeneratePrivateMembers(io::Printer* printer) const {
" $map_classname$;\n");
}
printer->Print(variables_,
+ "private:\n"
"::google::protobuf::internal::MapField$lite$<\n"
" $map_classname$,\n"
" $key_cpp$, $val_cpp$,\n"
@@ -161,11 +162,15 @@ GeneratePrivateMembers(io::Printer* printer) const {
void MapFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
- printer->Print(variables_,
+ printer->Print(
+ variables_,
"$deprecated_attr$const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n"
- " $name$() const;\n"
- "$deprecated_attr$::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n"
- " mutable_$name$();\n");
+ " $name$() const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n"
+ " ${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void MapFieldGenerator::
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index 33231ae3..63ebb3c5 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -52,6 +52,8 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/generated_message_table_driven.h>
+#include <google/protobuf/generated_message_util.h>
+#include <google/protobuf/map_entry_lite.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
@@ -280,7 +282,7 @@ void OptimizePadding(std::vector<const FieldDescriptor*>* fields,
enum Family {
REPEATED = 0,
STRING = 1,
- MESSAGE = 2,
+ MESSAGE = 3,
ZERO_INITIALIZABLE = 4,
OTHER = 5,
kMaxFamily
@@ -452,22 +454,13 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) {
}
-bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) {
+bool TableDrivenParsingEnabled(
+ const Descriptor* descriptor, const Options& options) {
if (!options.table_driven_parsing) {
return false;
}
// Consider table-driven parsing. We only do this if:
- // - There are no extensions
- if (descriptor->extension_range_count() != 0) {
- return false;
- }
-
- // - We are not using UnknownFieldSet (part of the non-lite library).
- if (UseUnknownFieldSet(descriptor->file(), options)) {
- return false;
- }
-
// - We have has_bits for fields. This avoids a check on every field we set
// when are present (the common case).
if (!HasFieldPresence(descriptor->file())) {
@@ -482,16 +475,6 @@ bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) {
max_field_number = field->number();
}
- // - There are no map fields.
- if (field->is_map()) {
- return false;
- }
-
- // - There are no oneof fields.
- if (field->containing_oneof()) {
- return false;
- }
-
// - There are no weak fields.
if (field->options().weak()) {
return false;
@@ -503,8 +486,10 @@ bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) {
return false;
}
- // - Field numbers are relatively dense within the actual number of fields
- if (max_field_number * table_sparseness >= descriptor->field_count()) {
+ // - Field numbers are relatively dense within the actual number of fields.
+ // We check for strictly greater than in the case where there are no fields
+ // (only extensions) so max_field_number == descriptor->field_count() == 0.
+ if (max_field_number * table_sparseness > descriptor->field_count()) {
return false;
}
@@ -516,6 +501,31 @@ bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) {
return true;
}
+void SetUnknkownFieldsVariable(const Descriptor* descriptor,
+ const Options& options,
+ std::map<string, string>* variables) {
+ if (UseUnknownFieldSet(descriptor->file(), options)) {
+ (*variables)["unknown_fields_type"] = "::google::protobuf::UnknownFieldSet";
+ } else {
+ (*variables)["unknown_fields_type"] = "::std::string";
+ }
+ if (AlwaysPreserveUnknownFields(descriptor)) {
+ (*variables)["have_unknown_fields"] =
+ "_internal_metadata_.have_unknown_fields()";
+ (*variables)["unknown_fields"] = "_internal_metadata_.unknown_fields()";
+ } else {
+ (*variables)["have_unknown_fields"] =
+ "(_internal_metadata_.have_unknown_fields() && "
+ " ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())";
+ (*variables)["unknown_fields"] =
+ "(::google::protobuf::internal::GetProto3PreserveUnknownsDefault()"
+ " ? _internal_metadata_.unknown_fields()"
+ " : _internal_metadata_.default_instance())";
+ }
+ (*variables)["mutable_unknown_fields"] =
+ "_internal_metadata_.mutable_unknown_fields()";
+}
+
} // anonymous namespace
// ===================================================================
@@ -592,7 +602,7 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor,
use_dependent_base_ = true;
}
- table_driven_ = TableDrivenEnabled(descriptor_, options_);
+ table_driven_ = TableDrivenParsingEnabled(descriptor_, options_);
}
MessageGenerator::~MessageGenerator() {}
@@ -703,24 +713,29 @@ GenerateFieldAccessorDeclarations(io::Printer* printer) {
}
if (field->is_repeated()) {
- printer->Print(vars, "$deprecated_attr$int $name$_size() const;\n");
+ printer->Print(vars, "$deprecated_attr$int ${$$name$_size$}$() const;\n");
+ printer->Annotate("{", "}", field);
} else if (HasHasMethod(field)) {
- printer->Print(vars, "$deprecated_attr$bool has_$name$() const;\n");
+ printer->Print(vars, "$deprecated_attr$bool ${$has_$name$$}$() const;\n");
+ printer->Annotate("{", "}", field);
} else if (HasPrivateHasMethod(field)) {
printer->Print(vars,
- "private:\n"
- "bool has_$name$() const;\n"
- "public:\n");
+ "private:\n"
+ "bool ${$has_$name$$}$() const;\n"
+ "public:\n");
+ printer->Annotate("{", "}", field);
}
if (!dependent_field) {
// If this field is dependent, then its clear_() method is in the
// depenent base class. (See also GenerateDependentAccessorDeclarations.)
- printer->Print(vars, "$deprecated_attr$void clear_$name$();\n");
+ printer->Print(vars, "$deprecated_attr$void ${$clear_$name$$}$();\n");
+ printer->Annotate("{", "}", field);
}
printer->Print(vars,
"$deprecated_attr$static const int $constant_name$ = "
"$number$;\n");
+ printer->Annotate("constant_name", field);
// Generate type-specific accessor declarations.
field_generators_.get(field).GenerateAccessorDeclarations(printer);
@@ -1074,32 +1089,39 @@ GenerateClassDefinition(io::Printer* printer) {
printer->Print(" public:\n");
printer->Indent();
- printer->Print(vars,
- "$classname$();\n"
- "virtual ~$classname$();\n"
- "\n"
- "$classname$(const $classname$& from);\n"
- "\n"
- "inline $classname$& operator=(const $classname$& from) {\n"
- " CopyFrom(from);\n"
- " return *this;\n"
- "}\n"
- "\n");
+ printer->Print(
+ vars,
+ "$classname$();\n"
+ "virtual ~$classname$();\n"
+ "\n"
+ "$classname$(const $classname$& from);\n"
+ "\n"
+ "inline $classname$& operator=(const $classname$& from) {\n"
+ " CopyFrom(from);\n"
+ " return *this;\n"
+ "}\n");
+
+ if (options_.table_driven_serialization) {
+ printer->Print(
+ "private:\n"
+ "const void* InternalGetTable() const;\n"
+ "public:\n"
+ "\n");
+ }
// Generate move constructor and move assignment operator for types other than
// Any.
- #ifdef PROTO_EXPERIMENTAL_ENABLE_MOVE
if (!IsAnyMessage(descriptor_)) {
printer->Print(vars,
"#if LANG_CXX11\n"
- "$classname$($classname$&& from)\n"
+ "$classname$($classname$&& from) noexcept\n"
" : $classname$() {\n"
" *this = ::std::move(from);\n"
"}\n"
"\n"
- "inline $classname$& operator=($classname$&& from) {\n"
+ "inline $classname$& operator=($classname$&& from) noexcept {\n"
" if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {\n"
- " InternalSwap(&from);\n"
+ " if (this != &from) InternalSwap(&from);\n"
" } else {\n"
" CopyFrom(from);\n"
" }\n"
@@ -1107,22 +1129,17 @@ GenerateClassDefinition(io::Printer* printer) {
"}\n"
"#endif\n");
}
- #endif
- if (PreserveUnknownFields(descriptor_)) {
- string type = UseUnknownFieldSet(descriptor_->file(), options_)
- ? "::google::protobuf::UnknownFieldSet"
- : "::std::string";
- printer->Print(
- "inline const $type$& unknown_fields() const {\n"
- " return _internal_metadata_.unknown_fields();\n"
- "}\n"
- "\n"
- "inline $type$* mutable_unknown_fields() {\n"
- " return _internal_metadata_.mutable_unknown_fields();\n"
- "}\n"
- "\n",
- "type", type );
+ SetUnknkownFieldsVariable(descriptor_, options_, &vars);
+ if (PublicUnknownFieldsAccessors(descriptor_)) {
+ printer->Print(vars,
+ "inline const $unknown_fields_type$& unknown_fields() const {\n"
+ " return $unknown_fields$;\n"
+ "}\n"
+ "inline $unknown_fields_type$* mutable_unknown_fields() {\n"
+ " return $mutable_unknown_fields$;\n"
+ "}\n"
+ "\n");
}
// N.B.: We exclude GetArena() when arena support is disabled, falling back on
@@ -1190,7 +1207,6 @@ GenerateClassDefinition(io::Printer* printer) {
" $message_index$;\n"
"\n");
-
if (SupportsArenas(descriptor_)) {
printer->Print(vars,
"void UnsafeArenaSwap($classname$* other);\n");
@@ -1214,6 +1230,9 @@ GenerateClassDefinition(io::Printer* printer) {
printer->Print(vars,
"void Swap($classname$* other);\n"
+ "friend void swap($classname$& a, $classname$& b) {\n"
+ " a.Swap(&b);\n"
+ "}\n"
"\n"
"// implements Message ----------------------------------------------\n"
"\n"
@@ -1250,9 +1269,14 @@ GenerateClassDefinition(io::Printer* printer) {
"\n"
"size_t ByteSizeLong() const PROTOBUF_FINAL;\n"
"bool MergePartialFromCodedStream(\n"
- " ::google::protobuf::io::CodedInputStream* input)$merge_partial_final$;\n"
- "void SerializeWithCachedSizes(\n"
- " ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;\n");
+ " ::google::protobuf::io::CodedInputStream* input)$merge_partial_final$;\n");
+ if (!options_.table_driven_serialization ||
+ descriptor_->options().message_set_wire_format()) {
+ printer->Print(
+ "void SerializeWithCachedSizes(\n"
+ " ::google::protobuf::io::CodedOutputStream* output) const "
+ "PROTOBUF_FINAL;\n");
+ }
// DiscardUnknownFields() is implemented in message.cc using reflections. We
// need to implement this function in generated code for messages.
if (!UseUnknownFieldSet(descriptor_->file(), options_)) {
@@ -1278,6 +1302,9 @@ GenerateClassDefinition(io::Printer* printer) {
"final", use_final);
if (SupportsArenas(descriptor_)) {
printer->Print(
+ // TODO(gerbens) Make this private! Currently people are deriving from
+ // protos to give access to this constructor, breaking the invariants
+ // we rely on.
"protected:\n"
"explicit $classname$(::google::protobuf::Arena* arena);\n"
"private:\n"
@@ -1443,7 +1470,7 @@ GenerateClassDefinition(io::Printer* printer) {
if (SupportsArenas(descriptor_)) {
printer->Print(
- "friend class ::google::protobuf::Arena;\n"
+ "template <typename T> friend class ::google::protobuf::Arena::InternalHelper;\n"
"typedef void InternalArenaConstructable_;\n"
"typedef void DestructorSkippable_;\n");
}
@@ -1577,7 +1604,6 @@ GenerateExtraDefaultFields(io::Printer* printer) {
// Generate oneof default instance and weak field instances for reflection
// usage.
if (descriptor_->oneof_decl_count() > 0 || num_weak_fields_ > 0) {
- printer->Print("public:\n");
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
@@ -1602,7 +1628,7 @@ GenerateExtraDefaultFields(io::Printer* printer) {
bool MessageGenerator::GenerateParseTable(io::Printer* printer, size_t offset,
size_t aux_offset) {
if (!table_driven_) {
- printer->Print("{ NULL, NULL, 0, -1, -1, false },\n");
+ printer->Print("{ NULL, NULL, 0, -1, -1, -1, -1, NULL, false },\n");
return false;
}
@@ -1639,9 +1665,44 @@ bool MessageGenerator::GenerateParseTable(io::Printer* printer, size_t offset,
" $classname$, _has_bits_),\n");
}
+ if (descriptor_->oneof_decl_count() > 0) {
+ printer->Print(vars,
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n"
+ " $classname$, _oneof_case_),\n");
+ } else {
+ printer->Print("-1, // no _oneof_case_\n");
+ }
+
+ if (descriptor_->extension_range_count() > 0) {
+ printer->Print(vars,
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
+ "_extensions_),\n");
+ } else {
+ printer->Print("-1, // no _extensions_\n");
+ }
+
+ // TODO(ckennelly): Consolidate this with the calculation for
+ // AuxillaryParseTableField.
+ std::vector<string> package_parts;
+
+ const Descriptor* outer = descriptor_;
+ while (outer->containing_type() != NULL) {
+ outer = outer->containing_type();
+ }
+
+ package_parts = Split(
+ outer->full_name(), ".", true);
+ // outer->full_name() contains the class itself. Remove it as it is
+ // used in the name of the default instance variable.
+ GOOGLE_DCHECK_NE(package_parts.size(), 0);
+ package_parts.back().clear();
+
+ vars["ns"] = Join(package_parts, "::");
+
printer->Print(vars,
"GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n"
- " $classname$, _internal_metadata_),\n");
+ " $classname$, _internal_metadata_),\n"
+ "&::$ns$_$classname$_default_instance_,\n");
if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(vars, "true,\n");
@@ -1670,6 +1731,239 @@ void MessageGenerator::GenerateSchema(io::Printer* printer, int offset,
"{ $offset$, $has_bits_offsets$, sizeof($classname$)},\n");
}
+namespace {
+
+// TODO(gerbens) remove this after the next sync with GitHub code base.
+// Then the opensource testing has gained the functionality to compile
+// the CalcFieldNum given the symbols defined in generated-message-util.
+#ifdef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP
+// We need a clean version of CalcFieldNum that doesn't use new functionality
+// in the runtime, because this functionality is not yet in the opensource
+// runtime
+
+uint32 CalculateType(uint32 type, uint32 type_class) {
+ return (type - 1) + type_class * 20;
+}
+
+uint32 CalcFieldNum(const FieldDescriptor* field, const Options& options) {
+ bool is_a_map = IsMapEntryMessage(field->containing_type());
+ int type = field->type();
+ if (field->containing_oneof()) {
+ return CalculateType(type, 4);
+ }
+ if (field->is_packed()) {
+ return CalculateType(type, 3);
+ } else if (field->is_repeated()) {
+ return CalculateType(type, 2);
+ } else if (!HasFieldPresence(field->file()) &&
+ field->containing_oneof() == NULL && !is_a_map) {
+ return CalculateType(type, 1);
+ } else {
+ return CalculateType(type, 0);
+ }
+}
+
+#else
+// We need to calculate for each field what function the table driven code
+// should use to serialize it. This returns the index in a lookup table.
+uint32 CalcFieldNum(const FieldDescriptor* field, const Options& options) {
+ bool is_a_map = IsMapEntryMessage(field->containing_type());
+ int type = field->type();
+ if (field->containing_oneof()) {
+ return internal::FieldMetadata::CalculateType(
+ type, internal::FieldMetadata::kOneOf);
+ }
+ if (field->is_packed()) {
+ return internal::FieldMetadata::CalculateType(
+ type, internal::FieldMetadata::kPacked);
+ } else if (field->is_repeated()) {
+ return internal::FieldMetadata::CalculateType(
+ type, internal::FieldMetadata::kRepeated);
+ } else if (!HasFieldPresence(field->file()) &&
+ field->containing_oneof() == NULL && !is_a_map) {
+ return internal::FieldMetadata::CalculateType(
+ type, internal::FieldMetadata::kNoPresence);
+ } else {
+ return internal::FieldMetadata::CalculateType(
+ type, internal::FieldMetadata::kPresence);
+ }
+}
+#endif
+
+int FindMessageIndexInFile(const Descriptor* descriptor) {
+ std::vector<const Descriptor*> flatten =
+ FlattenMessagesInFile(descriptor->file());
+ return std::find(flatten.begin(), flatten.end(), descriptor) -
+ flatten.begin();
+}
+
+} // namespace
+
+int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) {
+ if (!options_.table_driven_serialization) {
+ return 0;
+ }
+
+ std::vector<const FieldDescriptor*> sorted = SortFieldsByNumber(descriptor_);
+ if (IsMapEntryMessage(descriptor_)) {
+ for (int i = 0; i < 2; i++) {
+ const FieldDescriptor* field = sorted[i];
+ uint32 tag = internal::WireFormatLite::MakeTag(
+ field->number(), WireFormat::WireTypeForFieldType(field->type()));
+
+ std::map<string, string> vars;
+ vars["classname"] = classname_;
+ vars["parent_classname"] =
+ ClassName(descriptor_->containing_type(), false);
+ vars["field_name"] = FieldName(field);
+ vars["tag"] = SimpleItoa(tag);
+ vars["hasbit"] = SimpleItoa(i);
+ vars["type"] = SimpleItoa(CalcFieldNum(field, options_));
+ vars["ptr"] = "NULL";
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ GOOGLE_CHECK(!IsMapEntryMessage(field->message_type()));
+ {
+ vars["ptr"] =
+ QualifiedFileLevelSymbol(
+ field->message_type()->file()->package(),
+ FileLevelNamespace(field->message_type()->file()->name())) +
+ "::TableStruct::serialization_table + " +
+ SimpleItoa(FindMessageIndexInFile(field->message_type()));
+ }
+ }
+ vars["extra"] = HasDescriptorMethods(descriptor_->file(), options_)
+ ? "::SuperType"
+ : "";
+ printer->Print(vars,
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET("
+ "::google::protobuf::internal::MapEntryHelper<$parent_classname$::$"
+ "classname$$extra$>, $field_name$_), $tag$,"
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET("
+ "::google::protobuf::internal::MapEntryHelper<$parent_classname$::$"
+ "classname$$extra$>, _has_bits_) * 8 + $hasbit$, $type$, "
+ "$ptr$},\n");
+ }
+ return 2;
+ }
+ printer->Print(
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
+ "_cached_size_), 0, 0, 0, NULL},\n",
+ "classname", classname_);
+ 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));
+ }
+ std::sort(sorted_extensions.begin(), sorted_extensions.end(),
+ ExtensionRangeSorter());
+ for (int i = 0, extension_idx = 0; /* no range */; i++) {
+ for (; extension_idx < sorted_extensions.size() &&
+ (i == sorted.size() ||
+ sorted_extensions[extension_idx]->start < sorted[i]->number());
+ extension_idx++) {
+ const Descriptor::ExtensionRange* range =
+ sorted_extensions[extension_idx];
+ printer->Print(
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
+ "_extensions_), $start$, $end$, "
+ "::google::protobuf::internal::FieldMetadata::kSpecial, "
+ "reinterpret_cast<const "
+ "void*>(::google::protobuf::internal::ExtensionSerializer)},\n",
+ "classname", classname_, "start", SimpleItoa(range->start), "end",
+ SimpleItoa(range->end));
+ }
+ if (i == sorted.size()) break;
+ const FieldDescriptor* field = sorted[i];
+
+ uint32 tag = internal::WireFormatLite::MakeTag(
+ field->number(), WireFormat::WireTypeForFieldType(field->type()));
+ if (field->is_packed()) {
+ tag = internal::WireFormatLite::MakeTag(
+ field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
+ }
+
+ string classfieldname = FieldName(field);
+ if (field->containing_oneof()) {
+ classfieldname = field->containing_oneof()->name();
+ }
+ std::map<string, string> vars;
+ vars["classname"] = classname_;
+ vars["field_name"] = classfieldname;
+ vars["tag"] = SimpleItoa(tag);
+ vars["ptr"] = "NULL";
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ if (IsMapEntryMessage(field->message_type())) {
+ vars["idx"] = SimpleItoa(FindMessageIndexInFile(field->message_type()));
+ vars["fieldclassname"] = ClassName(field->message_type(), false);
+ printer->Print(vars,
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($"
+ "classname$, $field_name$_), $tag$, $idx$, "
+ "::google::protobuf::internal::FieldMetadata::kSpecial, "
+ "reinterpret_cast<const void*>(static_cast< "
+ "::google::protobuf::internal::SpecialSerializer>("
+ "::google::protobuf::internal::MapFieldSerializer< "
+ "::google::protobuf::internal::MapEntryToMapField<$classname$::$"
+ "fieldclassname$>::MapFieldType, "
+ "TableStruct::serialization_table>))},\n");
+ continue;
+ } else {
+ vars["ptr"] =
+ QualifiedFileLevelSymbol(
+ field->message_type()->file()->package(),
+ FileLevelNamespace(field->message_type()->file()->name())) +
+ "::TableStruct::serialization_table + " +
+ SimpleItoa(FindMessageIndexInFile(field->message_type()));
+ }
+ }
+ vars["type"] = SimpleItoa(CalcFieldNum(field, options_));
+
+
+ if (field->options().weak()) {
+ // TODO(gerbens) merge weak fields into ranges
+ printer->Print(vars,
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($"
+ "classname$, _weak_field_map_), $tag$, $tag$, "
+ "::google::protobuf::internal::FieldMetadata::kSpecial, "
+ "reinterpret_cast<const "
+ "void*>(::google::protobuf::internal::WeakFieldSerializer)},\n");
+ } else if (field->containing_oneof()) {
+ vars["oneofoffset"] =
+ SimpleItoa(sizeof(uint32) * field->containing_oneof()->index());
+ printer->Print(vars,
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($"
+ "classname$, $field_name$_), $tag$, "
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($"
+ "classname$, _oneof_case_) + $oneofoffset$, "
+ "$type$, $ptr$},\n");
+ } else if (HasFieldPresence(descriptor_->file()) &&
+ has_bit_indices_[field->index()] != -1) {
+ vars["hasbitsoffset"] = SimpleItoa(has_bit_indices_[field->index()]);
+ printer->Print(vars,
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($"
+ "classname$, $field_name$_), $tag$, "
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($"
+ "classname$, _has_bits_) * 8 + $hasbitsoffset$, $type$, "
+ "$ptr$},\n");
+ } else {
+ printer->Print(vars,
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($"
+ "classname$, $field_name$_), $tag$, ~0u, $type$, "
+ "$ptr$},\n");
+ }
+ }
+ int num_field_metadata = 1 + sorted.size() + sorted_extensions.size();
+ num_field_metadata++;
+ string serializer = UseUnknownFieldSet(descriptor_->file(), options_)
+ ? "::google::protobuf::internal::UnknownFieldSetSerializer"
+ : "::google::protobuf::internal::UnknownFieldSerializerLite";
+ printer->Print(
+ "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
+ "_internal_metadata_), 0, ~0u, "
+ "::google::protobuf::internal::FieldMetadata::kSpecial, reinterpret_cast<const "
+ "void*>($serializer$)},\n",
+ "classname", classname_, "serializer", serializer);
+ return num_field_metadata;
+}
+
void MessageGenerator::
GenerateDefaultInstanceAllocator(io::Printer* printer) {
// Construct the default instances of all fields, as they will be used
@@ -1682,7 +1976,9 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) {
// Construct the default instance. We can't call InitAsDefaultInstance() yet
// because we need to make sure all default instances that this one might
// depend on are constructed first.
- printer->Print("_$classname$_default_instance_.DefaultConstruct();\n",
+ printer->Print("_$classname$_default_instance_._instance.DefaultConstruct();\n"
+ "::google::protobuf::internal::OnShutdownDestroyMessage(\n"
+ " &_$classname$_default_instance_);",
"classname", classname_);
}
@@ -1690,9 +1986,9 @@ void MessageGenerator::
GenerateDefaultInstanceInitializer(io::Printer* printer) {
if (IsMapEntryMessage(descriptor_)) {
printer->Print(
- "_$classname$_default_instance_.get_mutable()->set_default_instance(_$"
- "classname$_default_instance_.get_mutable());\n"
- "_$classname$_default_instance_.get_mutable()->InitAsDefaultInstance();"
+ "_$classname$_default_instance_._instance.get_mutable()->set_default_instance(_$"
+ "classname$_default_instance_._instance.get_mutable());\n"
+ "_$classname$_default_instance_._instance.get_mutable()->InitAsDefaultInstance();"
"\n",
"classname", classname_);
return;
@@ -1715,7 +2011,8 @@ GenerateDefaultInstanceInitializer(io::Printer* printer) {
if (field->containing_oneof() || field->options().weak()) {
name = "_" + classname_ + "_default_instance_.";
} else {
- name = "_" + classname_ + "_default_instance_.get_mutable()->";
+ name =
+ "_" + classname_ + "_default_instance_._instance.get_mutable()->";
}
name += FieldName(field);
printer->Print(
@@ -1732,25 +2029,6 @@ GenerateDefaultInstanceInitializer(io::Printer* printer) {
}
void MessageGenerator::
-GenerateShutdownCode(io::Printer* printer) {
- if (IsMapEntryMessage(descriptor_)) return;
-
- printer->Print("_$classname$_default_instance_.Shutdown();\n", "classname",
- classname_);
-
- if (HasDescriptorMethods(descriptor_->file(), options_)) {
- printer->Print("delete file_level_metadata[$index$].reflection;\n", "index",
- SimpleItoa(index_in_file_messages_));
- }
-
- // Handle default instances of fields.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- field_generators_.get(descriptor_->field(i))
- .GenerateShutdownCode(printer);
- }
-}
-
-void MessageGenerator::
GenerateClassMethods(io::Printer* printer) {
if (IsMapEntryMessage(descriptor_)) {
if (HasDescriptorMethods(descriptor_->file(), options_)) {
@@ -1854,6 +2132,15 @@ GenerateClassMethods(io::Printer* printer) {
GenerateSwap(printer);
printer->Print("\n");
+ if (options_.table_driven_serialization) {
+ printer->Print(
+ "const void* $classname$::InternalGetTable() const {\n"
+ " return $file_namespace$::TableStruct::serialization_table + $index$;\n"
+ "}\n"
+ "\n",
+ "classname", classname_, "index", SimpleItoa(index_in_file_messages_),
+ "file_namespace", FileLevelNamespace(descriptor_->file()->name()));
+ }
if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(
"::google::protobuf::Metadata $classname$::GetMetadata() const {\n"
@@ -1926,13 +2213,25 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) {
processing_type |= static_cast<unsigned>(
field->is_repeated() ? internal::kRepeatedMask : 0);
+ processing_type |= static_cast<unsigned>(
+ field->containing_oneof() ? internal::kOneofMask : 0);
+
+ if (field->is_map()) {
+ processing_type = internal::TYPE_MAP;
+ }
+
const unsigned char tag_size =
WireFormat::TagSize(field->number(), field->type());
std::map<string, string> vars;
vars["classname"] = classname_;
- vars["name"] = FieldName(field);
- vars["has"] = SimpleItoa(has_bit_indices_[field->index()]);
+ if (field->containing_oneof() != NULL) {
+ vars["name"] = field->containing_oneof()->name();
+ vars["presence"] = SimpleItoa(field->containing_oneof()->index());
+ } else {
+ vars["name"] = FieldName(field);
+ vars["presence"] = SimpleItoa(has_bit_indices_[field->index()]);
+ }
vars["nwtype"] = SimpleItoa(normal_wiretype);
vars["pwtype"] = SimpleItoa(packed_wiretype);
vars["ptype"] = SimpleItoa(processing_type);
@@ -1942,7 +2241,7 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) {
"{\n"
" GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n"
" $classname$, $name$_),\n"
- " static_cast< ::google::protobuf::uint32>($has$),\n"
+ " static_cast< ::google::protobuf::uint32>($presence$),\n"
" $nwtype$, $pwtype$, $ptype$, $tag_size$\n"
"},\n");
}
@@ -1977,7 +2276,7 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) {
printer->Print(
vars,
"{::google::protobuf::internal::AuxillaryParseTableField::enum_aux{"
- "$type$_IsValid, \"$type$\" }},\n");
+ "$type$_IsValid}},\n");
last_field_number++;
break;
case FieldDescriptor::CPPTYPE_MESSAGE: {
@@ -1995,7 +2294,17 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) {
GOOGLE_DCHECK_NE(package_parts.size(), 0);
package_parts.back().clear();
- vars["classname"] = ClassName(field->message_type(), false);
+ if (field->is_map()) {
+ vars["classname"] = ClassName(field->containing_type(), false) +
+ "::" + ClassName(field->message_type(), false);
+ printer->Print(vars,
+ "{::google::protobuf::internal::AuxillaryParseTableField::map_"
+ "aux{&::google::protobuf::internal::ParseMap<$classname$>}},\n");
+ last_field_number++;
+ break;
+ } else {
+ vars["classname"] = ClassName(field->message_type(), false);
+ }
vars["ns"] = Join(package_parts, "::");
vars["type"] = FieldMessageTypeName(field);
vars["file_namespace"] = FileLevelNamespace(outer->file()->name());
@@ -2005,7 +2314,7 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) {
" &::$ns$_$classname$_default_instance_,\n");
bool dont_emit_table =
- !TableDrivenEnabled(field->message_type(), options_);
+ !TableDrivenParsingEnabled(field->message_type(), options_);
if (dont_emit_table) {
printer->Print(" NULL,\n");
@@ -2034,16 +2343,10 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) {
break;
}
vars["full_name"] = field->full_name();
- vars["strict"] =
- field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3
- ? "true" : "false";
- vars["type"] = field->full_name();
printer->Print(vars,
"{::google::protobuf::internal::AuxillaryParseTableField::string_aux{\n"
" $default$,\n"
- " \"$full_name$\",\n"
- " $strict$,\n"
- " \"$type$\"\n"
+ " \"$full_name$\"\n"
"}},\n");
last_field_number++;
break;
@@ -2103,8 +2406,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(
const FieldDescriptor* field = descriptor_->field(i);
if (field->containing_oneof() || field->options().weak()) {
printer->Print(
- "GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET("
- "(&_$classname$_default_instance_), $name$_),\n",
+ "offsetof($classname$DefaultTypeInternal, $name$_),\n",
"classname", classname_, "name", FieldName(field));
} else {
printer->Print(
@@ -2178,6 +2480,7 @@ GenerateSharedDestructorCode(io::Printer* printer) {
// Do nothing when the message is allocated in an arena.
printer->Print(
"::google::protobuf::Arena* arena = GetArenaNoVirtual();\n"
+ "GOOGLE_DCHECK(arena == NULL);\n"
"if (arena != NULL) {\n"
" return;\n"
"}\n"
@@ -2385,8 +2688,7 @@ GenerateStructors(io::Printer* printer) {
initializer_with_arena += ", _weak_field_map_(arena)";
}
- string initializer_null;
- initializer_null = ", _internal_metadata_(NULL)";
+ string initializer_null = superclass + "(), _internal_metadata_(NULL)";
if (IsAnyMessage(descriptor_)) {
initializer_null += ", _any_metadata_(&type_url_, &value_)";
}
@@ -2396,16 +2698,16 @@ GenerateStructors(io::Printer* printer) {
printer->Print(
"$classname$::$classname$()\n"
- " : $superclass$()$initializer$ {\n"
+ " : $initializer$ {\n"
" if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {\n"
" $file_namespace$::InitDefaults();\n"
" }\n"
" SharedCtor();\n"
" // @@protoc_insertion_point(constructor:$full_name$)\n"
"}\n",
- "classname", classname_, "superclass", superclass, "full_name",
- descriptor_->full_name(), "initializer", initializer_null,
- "file_namespace", FileLevelNamespace(descriptor_->file()->name()));
+ "classname", classname_, "full_name", descriptor_->full_name(),
+ "initializer", initializer_null, "file_namespace",
+ FileLevelNamespace(descriptor_->file()->name()));
if (SupportsArenas(descriptor_)) {
printer->Print(
@@ -2598,7 +2900,6 @@ GenerateStructors(io::Printer* printer) {
"}\n",
"classname", classname_);
}
-
}
// Return the number of bits set in n, a non-negative integer.
@@ -2611,6 +2912,22 @@ static int popcnt(uint32 n) {
return result;
}
+bool MessageGenerator::MaybeGenerateOptionalFieldCondition(
+ io::Printer* printer, const FieldDescriptor* field,
+ int expected_has_bits_index) {
+ int has_bit_index = has_bit_indices_[field->index()];
+ if (!field->options().weak() &&
+ expected_has_bits_index == has_bit_index / 32) {
+ const string mask =
+ StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8));
+ printer->Print(
+ "if (cached_has_bits & 0x$mask$u) {\n",
+ "mask", mask);
+ return true;
+ }
+ return false;
+}
+
void MessageGenerator::
GenerateClear(io::Printer* printer) {
printer->Print(
@@ -2619,6 +2936,15 @@ GenerateClear(io::Printer* printer) {
"classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
+ printer->Print(
+ // TODO(jwb): It would be better to avoid emitting this if it is not used,
+ // rather than emitting a workaround for the resulting warning.
+ "::google::protobuf::uint32 cached_has_bits = 0;\n"
+ "// Prevent compiler warnings about cached_has_bits being unused\n"
+ "(void) cached_has_bits;\n\n");
+
+ int cached_has_bit_index = -1;
+
// Step 1: Extensions
if (descriptor_->extension_range_count() > 0) {
printer->Print("_extensions_.Clear();\n");
@@ -2727,9 +3053,14 @@ GenerateClear(io::Printer* printer) {
GOOGLE_DCHECK_LE(2, count);
GOOGLE_DCHECK_GE(8, count);
+ if (cached_has_bit_index != last_chunk / 4) {
+ cached_has_bit_index = last_chunk / 4;
+ printer->Print(
+ "cached_has_bits = _has_bits_[$idx$];\n",
+ "idx", SimpleItoa(cached_has_bit_index));
+ }
printer->Print(
- "if (_has_bits_[$index$ / 32] & $mask$u) {\n",
- "index", SimpleItoa(last_chunk * 8),
+ "if (cached_has_bits & $mask$u) {\n",
"mask", SimpleItoa(last_chunk_mask));
printer->Indent();
}
@@ -2776,7 +3107,12 @@ GenerateClear(io::Printer* printer) {
if (should_check_bit &&
// If no field presence, then always clear strings/messages as well.
HasFieldPresence(descriptor_->file())) {
- printer->Print("if (has_$name$()) {\n", "name", fieldname);
+ if (!MaybeGenerateOptionalFieldCondition(printer, field,
+ cached_has_bit_index)) {
+ printer->Print(
+ "if (has_$name$()) {\n",
+ "name", fieldname);
+ }
printer->Indent();
have_enclosing_if = true;
}
@@ -2812,9 +3148,7 @@ GenerateClear(io::Printer* printer) {
printer->Print("_has_bits_.Clear();\n");
}
- if (PreserveUnknownFields(descriptor_)) {
- printer->Print("_internal_metadata_.Clear();\n");
- }
+ printer->Print("_internal_metadata_.Clear();\n");
printer->Outdent();
printer->Print("}\n");
@@ -2918,6 +3252,7 @@ GenerateSwap(io::Printer* printer) {
printer->Print("void $classname$::InternalSwap($classname$* other) {\n",
"classname", classname_);
printer->Indent();
+ printer->Print("using std::swap;\n");
if (HasGeneratedMethods(descriptor_->file(), options_)) {
for (int i = 0; i < optimized_order_.size(); i++) {
@@ -2929,24 +3264,22 @@ GenerateSwap(io::Printer* printer) {
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
printer->Print(
- "std::swap($oneof_name$_, other->$oneof_name$_);\n"
- "std::swap(_oneof_case_[$i$], other->_oneof_case_[$i$]);\n",
+ "swap($oneof_name$_, other->$oneof_name$_);\n"
+ "swap(_oneof_case_[$i$], other->_oneof_case_[$i$]);\n",
"oneof_name", descriptor_->oneof_decl(i)->name(),
"i", SimpleItoa(i));
}
if (HasFieldPresence(descriptor_->file())) {
for (int i = 0; i < HasBitsSize() / 4; ++i) {
- printer->Print("std::swap(_has_bits_[$i$], other->_has_bits_[$i$]);\n",
+ printer->Print("swap(_has_bits_[$i$], other->_has_bits_[$i$]);\n",
"i", SimpleItoa(i));
}
}
- if (PreserveUnknownFields(descriptor_)) {
- printer->Print("_internal_metadata_.Swap(&other->_internal_metadata_);\n");
- }
+ printer->Print("_internal_metadata_.Swap(&other->_internal_metadata_);\n");
- printer->Print("std::swap(_cached_size_, other->_cached_size_);\n");
+ printer->Print("swap(_cached_size_, other->_cached_size_);\n");
if (descriptor_->extension_range_count() > 0) {
printer->Print("_extensions_.Swap(&other->_extensions_);\n");
}
@@ -3249,21 +3582,16 @@ GenerateCopyFrom(io::Printer* printer) {
void MessageGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) {
+ std::map<string, string> vars;
+ SetUnknkownFieldsVariable(descriptor_, options_, &vars);
if (descriptor_->options().message_set_wire_format()) {
// Special-case MessageSet.
- printer->Print(
+ vars["classname"] = classname_;
+ printer->Print(vars,
"bool $classname$::MergePartialFromCodedStream(\n"
- " ::google::protobuf::io::CodedInputStream* input) {\n",
- "classname", classname_);
-
- printer->Print(
- " return _extensions_.ParseMessageSet(input, "
- "internal_default_instance(),\n"
- " mutable_unknown_fields());\n",
- // Vars.
- "classname", classname_);
-
- printer->Print(
+ " ::google::protobuf::io::CodedInputStream* input) {\n"
+ " return _extensions_.ParseMessageSet(input,\n"
+ " internal_default_instance(), $mutable_unknown_fields$);\n"
"}\n");
return;
}
@@ -3279,14 +3607,18 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
if (table_driven_) {
printer->Indent();
+ const string lite = UseUnknownFieldSet(descriptor_->file(), options_) ?
+ "" : "Lite";
+
printer->Print(
- "return ::google::protobuf::internal::MergePartialFromCodedStream(\n"
+ "return ::google::protobuf::internal::MergePartialFromCodedStream$lite$(\n"
" this,\n"
" $file_namespace$::TableStruct::schema[\n"
" $classname$::kIndexInFileMessages],\n"
" input);\n",
"classname", classname_,
- "file_namespace", FileLevelNamespace(descriptor_->file()->name()));
+ "file_namespace", FileLevelNamespace(descriptor_->file()->name()),
+ "lite", lite);
printer->Outdent();
@@ -3298,8 +3630,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
"#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure\n"
" ::google::protobuf::uint32 tag;\n");
- if (PreserveUnknownFields(descriptor_) &&
- !UseUnknownFieldSet(descriptor_->file(), options_)) {
+ if (!UseUnknownFieldSet(descriptor_->file(), options_)) {
// Use LazyStringOutputString to avoid initializing unknown fields string
// unless it is actually needed. For the same reason, disable eager refresh
// on the CodedOutputStream.
@@ -3352,13 +3683,12 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
}
printer->Print("::std::pair< ::google::protobuf::uint32, bool> p = "
- "input->ReadTagWithCutoff$lasttag$($max$u);\n"
+ "input->ReadTagWithCutoffNoLastTag($max$u);\n"
"tag = p.first;\n"
"if (!p.second) goto handle_unusual;\n",
"max", SimpleItoa(maxtag <= kCutoff0 ? kCutoff0 :
(maxtag <= kCutoff1 ? kCutoff1 :
- maxtag)),
- "lasttag", !capture_last_tag ? "NoLastTag" : "");
+ maxtag)));
if (descriptor_->field_count() > 0) {
// We don't even want to print the switch() if we have no fields because
@@ -3393,9 +3723,11 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
const FieldGenerator& field_generator = field_generators_.get(field);
// Emit code to parse the common, expected case.
- printer->Print("if (static_cast< ::google::protobuf::uint8>(tag) ==\n"
- " static_cast< ::google::protobuf::uint8>($commontag$u)) {\n",
- "commontag", SimpleItoa(WireFormat::MakeTag(field)));
+ printer->Print(
+ "if (static_cast< ::google::protobuf::uint8>(tag) ==\n"
+ " static_cast< ::google::protobuf::uint8>($truncated$u /* $full$ & 0xFF */)) {\n",
+ "truncated", SimpleItoa(WireFormat::MakeTag(field) & 0xFF),
+ "full", SimpleItoa(WireFormat::MakeTag(field)));
printer->Indent();
if (field->is_packed()) {
@@ -3409,22 +3741,30 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
if (field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
WireFormat::WireTypeForFieldType(field->type());
- printer->Print("} else if (static_cast< ::google::protobuf::uint8>(tag) ==\n"
- " static_cast< ::google::protobuf::uint8>($uncommontag$u)) {\n",
- "uncommontag", SimpleItoa(
- internal::WireFormatLite::MakeTag(
- field->number(), wiretype)));
+ const uint32 tag = internal::WireFormatLite::MakeTag(
+ field->number(), wiretype);
+ printer->Print(
+ "} else if (\n"
+ " static_cast< ::google::protobuf::uint8>(tag) ==\n"
+ " static_cast< ::google::protobuf::uint8>($truncated$u /* $full$ & 0xFF */)) {\n",
+ "truncated", SimpleItoa(tag & 0xFF),
+ "full", SimpleItoa(tag));
+
printer->Indent();
field_generator.GenerateMergeFromCodedStream(printer);
printer->Outdent();
} else if (field->is_packable() && !field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
- printer->Print("} else if (static_cast< ::google::protobuf::uint8>(tag) ==\n"
- " static_cast< ::google::protobuf::uint8>($uncommontag$u)) {\n",
- "uncommontag", SimpleItoa(
- internal::WireFormatLite::MakeTag(
- field->number(), wiretype)));
+ const uint32 tag = internal::WireFormatLite::MakeTag(
+ field->number(), wiretype);
+
+ printer->Print(
+ "} else if (\n"
+ " static_cast< ::google::protobuf::uint8>(tag) ==\n"
+ " static_cast< ::google::protobuf::uint8>($truncated$u /* $full$ & 0xFF */)) {\n",
+ "truncated", SimpleItoa(tag & 0xFF),
+ "full", SimpleItoa(tag));
printer->Indent();
field_generator.GenerateMergeFromCodedStreamWithPacking(printer);
printer->Outdent();
@@ -3450,12 +3790,20 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
printer->Print("handle_unusual:\n");
printer->Indent();
// If tag is 0 or an end-group tag then this must be the end of the message.
- printer->Print(
- "if (tag == 0 ||\n"
- " ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==\n"
- " ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {\n"
- " goto success;\n"
- "}\n");
+ if (capture_last_tag) {
+ printer->Print(
+ "if (tag == 0 ||\n"
+ " ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==\n"
+ " ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {\n"
+ " input->SetLastTag(tag);\n"
+ " goto success;\n"
+ "}\n");
+ } else {
+ printer->Print(
+ "if (tag == 0) {\n"
+ " goto success;\n"
+ "}\n");
+ }
// Handle extension ranges.
if (descriptor_->extension_range_count() > 0) {
@@ -3483,23 +3831,16 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
}
}
printer->Print(") {\n");
- if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- " DO_(_extensions_.ParseField(tag, input, "
- "internal_default_instance(),\n"
- " mutable_unknown_fields()));\n");
- } else {
- printer->Print(
- " DO_(_extensions_.ParseField(tag, input, "
- "internal_default_instance(),\n"
- " &unknown_fields_stream));\n");
- }
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
+ printer->Print(vars,
+ " DO_(_extensions_.ParseField(tag, input,\n"
+ " internal_default_instance(),\n"
+ " $mutable_unknown_fields$));\n");
} else {
printer->Print(
- // With static initializers.
- " DO_(_extensions_.ParseField(tag, input, "
- "internal_default_instance());\n");
+ " DO_(_extensions_.ParseField(tag, input,\n"
+ " internal_default_instance(),\n"
+ " &unknown_fields_stream));\n");
}
printer->Print(
" continue;\n"
@@ -3507,19 +3848,14 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
}
// We really don't recognize this tag. Skip it.
- if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
+ printer->Print(vars,
"DO_(::google::protobuf::internal::WireFormat::SkipField(\n"
- " input, tag, mutable_unknown_fields()));\n");
- } else {
- printer->Print(
- "DO_(::google::protobuf::internal::WireFormatLite::SkipField(\n"
- " input, tag, &unknown_fields_stream));\n");
- }
+ " input, tag, $mutable_unknown_fields$));\n");
} else {
printer->Print(
- "DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));\n");
+ "DO_(::google::protobuf::internal::WireFormatLite::SkipField(\n"
+ " input, tag, &unknown_fields_stream));\n");
}
if (descriptor_->field_count() > 0) {
@@ -3656,13 +3992,16 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) {
" _extensions_.SerializeMessageSetWithCachedSizes(output);\n",
"classname", classname_);
GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_));
- printer->Print(
+ std::map<string, string> vars;
+ SetUnknkownFieldsVariable(descriptor_, options_, &vars);
+ printer->Print(vars,
" ::google::protobuf::internal::WireFormat::SerializeUnknownMessageSetItems(\n"
- " unknown_fields(), output);\n");
+ " $unknown_fields$, output);\n");
printer->Print(
"}\n");
return;
}
+ if (options_.table_driven_serialization) return;
printer->Print(
"void $classname$::SerializeWithCachedSizes(\n"
@@ -3697,10 +4036,12 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) {
" deterministic, target);\n",
"classname", classname_);
GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_));
- printer->Print(
+ std::map<string, string> vars;
+ SetUnknkownFieldsVariable(descriptor_, options_, &vars);
+ printer->Print(vars,
" target = ::google::protobuf::internal::WireFormat::\n"
" SerializeUnknownMessageSetItemsToArray(\n"
- " unknown_fields(), target);\n");
+ " $unknown_fields$, target);\n");
printer->Print(
" return target;\n"
"}\n");
@@ -3865,29 +4206,29 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) {
}
}
- if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print("if (_internal_metadata_.have_unknown_fields()) {\n");
- printer->Indent();
- if (to_array) {
- printer->Print(
- "target = "
- "::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(\n"
- " unknown_fields(), target);\n");
- } else {
- printer->Print(
- "::google::protobuf::internal::WireFormat::SerializeUnknownFields(\n"
- " unknown_fields(), output);\n");
- }
- printer->Outdent();
-
- printer->Print(
- "}\n");
+ std::map<string, string> vars;
+ SetUnknkownFieldsVariable(descriptor_, options_, &vars);
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
+ printer->Print(vars,
+ "if ($have_unknown_fields$) {\n");
+ printer->Indent();
+ if (to_array) {
+ printer->Print(vars,
+ "target = "
+ "::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(\n"
+ " $unknown_fields$, target);\n");
} else {
- printer->Print(
- "output->WriteRaw(unknown_fields().data(),\n"
- " static_cast<int>(unknown_fields().size()));\n");
+ printer->Print(vars,
+ "::google::protobuf::internal::WireFormat::SerializeUnknownFields(\n"
+ " $unknown_fields$, output);\n");
}
+ printer->Outdent();
+
+ printer->Print("}\n");
+ } else {
+ printer->Print(vars,
+ "output->WriteRaw($unknown_fields$.data(),\n"
+ " static_cast<int>($unknown_fields$.size()));\n");
}
}
@@ -3931,18 +4272,19 @@ void MessageGenerator::
GenerateByteSize(io::Printer* printer) {
if (descriptor_->options().message_set_wire_format()) {
// Special-case MessageSet.
- printer->Print(
- "size_t $classname$::ByteSizeLong() const {\n"
- "// @@protoc_insertion_point(message_set_byte_size_start:$full_name$)\n"
- " size_t total_size = _extensions_.MessageSetByteSize();\n",
- "classname", classname_, "full_name", descriptor_->full_name());
GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_));
- printer->Print(
- "if (_internal_metadata_.have_unknown_fields()) {\n"
- " total_size += ::google::protobuf::internal::WireFormat::\n"
- " ComputeUnknownMessageSetItemsSize(unknown_fields());\n"
- "}\n");
- printer->Print(
+ std::map<string, string> vars;
+ SetUnknkownFieldsVariable(descriptor_, options_, &vars);
+ vars["classname"] = classname_;
+ vars["full_name"] = descriptor_->full_name();
+ printer->Print(vars,
+ "size_t $classname$::ByteSizeLong() const {\n"
+ "// @@protoc_insertion_point(message_set_byte_size_start:$full_name$)\n"
+ " size_t total_size = _extensions_.MessageSetByteSize();\n"
+ " if ($have_unknown_fields$) {\n"
+ " total_size += ::google::protobuf::internal::WireFormat::\n"
+ " ComputeUnknownMessageSetItemsSize($unknown_fields$);\n"
+ " }\n"
" int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);\n"
" GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n"
" _cached_size_ = cached_size;\n"
@@ -3996,19 +4338,19 @@ GenerateByteSize(io::Printer* printer) {
"\n");
}
- if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- "if (_internal_metadata_.have_unknown_fields()) {\n"
- " total_size +=\n"
- " ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(\n"
- " unknown_fields());\n"
- "}\n");
- } else {
- printer->Print(
- "total_size += unknown_fields().size();\n"
- "\n");
- }
+ std::map<string, string> vars;
+ SetUnknkownFieldsVariable(descriptor_, options_, &vars);
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
+ printer->Print(vars,
+ "if ($have_unknown_fields$) {\n"
+ " total_size +=\n"
+ " ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(\n"
+ " $unknown_fields$);\n"
+ "}\n");
+ } else {
+ printer->Print(vars,
+ "total_size += $unknown_fields$.size();\n"
+ "\n");
}
// Handle required fields (if any). We expect all of them to be
@@ -4357,7 +4699,6 @@ GenerateIsInitialized(io::Printer* printer) {
"}\n");
}
-
} // namespace cpp
} // namespace compiler
} // namespace protobuf
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h
index 23aaeeb0..352069eb 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.h
+++ b/src/google/protobuf/compiler/cpp/cpp_message.h
@@ -104,10 +104,6 @@ class MessageGenerator {
// allocated before any can be initialized.
void GenerateDefaultInstanceInitializer(io::Printer* printer);
- // Generates code that should be run when ShutdownProtobufLibrary() is called,
- // to delete all dynamically-allocated objects.
- void GenerateShutdownCode(io::Printer* printer);
-
// Generate all non-inline methods for this class.
void GenerateClassMethods(io::Printer* printer);
@@ -132,6 +128,9 @@ class MessageGenerator {
// of entries generated and the index of the first has_bit entry.
std::pair<size_t, size_t> GenerateOffsets(io::Printer* printer);
void GenerateSchema(io::Printer* printer, int offset, int has_offset);
+ // For each field generates a table entry describing the field for the
+ // table driven serializer.
+ int GenerateFieldMetadata(io::Printer* printer);
// Generate constructors and destructor.
void GenerateStructors(io::Printer* printer);
@@ -147,6 +146,13 @@ class MessageGenerator {
// Generate the arena-specific destructor code.
void GenerateArenaDestructorCode(io::Printer* printer);
+ // Helper for GenerateClear and others. Optionally emits a condition that
+ // assumes the existence of the cached_has_bits variable, and returns true if
+ // the condition was printed.
+ bool MaybeGenerateOptionalFieldCondition(io::Printer* printer,
+ const FieldDescriptor* field,
+ int expected_has_bits_index);
+
// Generate standard Message methods.
void GenerateClear(io::Printer* printer);
void GenerateOneofClear(io::Printer* printer);
@@ -179,7 +185,6 @@ class MessageGenerator {
io::Printer* printer, const Descriptor::ExtensionRange* range,
bool unbounded);
-
// Generates has_foo() functions and variables for singular field has-bits.
void GenerateSingularFieldHasBits(const FieldDescriptor* field,
std::map<string, string> vars,
diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
index ed1719cc..da4c3950 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
@@ -50,6 +50,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = FieldMessageTypeName(descriptor);
+ (*variables)["type_default_instance"] =
+ DefaultInstanceName(descriptor->message_type());
if (descriptor->options().weak() || !descriptor->containing_oneof()) {
(*variables)["non_null_ptr_to_name"] =
StrCat("this->", (*variables)["name"], "_");
@@ -98,6 +100,7 @@ void MessageFieldGenerator::
GenerateGetterDeclaration(io::Printer* printer) const {
printer->Print(variables_,
"$deprecated_attr$const $type$& $name$() const;\n");
+ printer->Annotate("name", descriptor_);
}
void MessageFieldGenerator::
@@ -107,9 +110,14 @@ GenerateDependentAccessorDeclarations(io::Printer* printer) const {
}
// Arena manipulation code is out-of-line in the derived message class.
printer->Print(variables_,
- "$deprecated_attr$$type$* mutable_$name$();\n"
- "$deprecated_attr$$type$* $release_name$();\n"
- "$deprecated_attr$void set_allocated_$name$($type$* $name$);\n");
+ "$deprecated_attr$$type$* ${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_, "$deprecated_attr$$type$* $release_name$();\n");
+ printer->Annotate("release_name", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_allocated_$name$$}$"
+ "($type$* $name$);\n");
+ printer->Annotate("{", "}", descriptor_);
}
void MessageFieldGenerator::
@@ -130,15 +138,25 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
GenerateGetterDeclaration(printer);
if (!dependent_field_) {
printer->Print(variables_,
- "$deprecated_attr$$type$* mutable_$name$();\n"
- "$deprecated_attr$$type$* $release_name$();\n"
- "$deprecated_attr$void set_allocated_$name$($type$* $name$);\n");
+ "$deprecated_attr$$type$* ${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_, "$deprecated_attr$$type$* $release_name$();\n");
+ printer->Annotate("release_name", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_allocated_$name$$}$"
+ "($type$* $name$);\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportsArenas(descriptor_)) {
+ printer->Print(
+ variables_,
+ "$deprecated_attr$$type$* ${$unsafe_arena_release_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
printer->Print(variables_,
- "$deprecated_attr$$type$* unsafe_arena_release_$name$();\n"
- "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n"
- " $type$* $name$);\n");
+ "$deprecated_attr$void "
+ "${$unsafe_arena_set_allocated_$name$$}$(\n"
+ " $type$* $name$);\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
@@ -346,30 +364,18 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
void MessageFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- if (dependent_field_) {
- // for dependent fields we cannot access its internal_default_instance,
- // because the type is incomplete.
- // TODO(gerbens) deprecate dependent base class.
- std::map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline " : "";
- printer->Print(variables,
- "$inline$const $type$& $classname$::$name$() const {\n"
- " // @@protoc_insertion_point(field_get:$full_name$)\n"
- " return $name$_ != NULL ? *$name$_\n"
- " : *internal_default_instance()->$name$_;\n"
- "}\n");
- return;
- }
-
std::map<string, string> variables(variables_);
variables["inline"] = is_inline ? "inline " : "";
printer->Print(variables,
"$inline$const $type$& $classname$::$name$() const {\n"
+ " const $type$* p = $name$_;\n"
" // @@protoc_insertion_point(field_get:$full_name$)\n"
- " return $name$_ != NULL ? *$name$_\n"
- " : *$type$::internal_default_instance();\n"
+ " return p != NULL ? *p : *reinterpret_cast<const $type$*>(\n"
+ " &$type_default_instance$);\n"
"}\n");
+ if (dependent_field_) return;
+
if (SupportsArenas(descriptor_)) {
printer->Print(variables,
"$inline$"
@@ -511,18 +517,18 @@ GenerateMergingCode(io::Printer* printer) const {
void MessageFieldGenerator::
GenerateSwappingCode(io::Printer* printer) const {
- printer->Print(variables_, "std::swap($name$_, other->$name$_);\n");
+ printer->Print(variables_, "swap($name$_, other->$name$_);\n");
}
void MessageFieldGenerator::
GenerateDestructorCode(io::Printer* printer) const {
+ // TODO(gerbens) Remove this when we don't need to destruct default instances.
// In google3 a default instance will never get deleted so we don't need to
// worry about that but in opensource protobuf default instances are deleted
// in shutdown process and we need to take special care when handling them.
printer->Print(variables_,
- "if (this != internal_default_instance()) {\n"
- " delete $name$_;\n"
- "}\n");
+ "if (this != internal_default_instance()) ");
+ printer->Print(variables_, "delete $name$_;\n");
}
void MessageFieldGenerator::
@@ -899,16 +905,20 @@ GeneratePrivateMembers(io::Printer* printer) const {
void RepeatedMessageFieldGenerator::
InternalGenerateTypeDependentAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$deprecated_attr$$type$* mutable_$name$(int index);\n"
- "$deprecated_attr$$type$* add_$name$();\n");
+ "$deprecated_attr$$type$* ${$mutable_$name$$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_, "$deprecated_attr$$type$* ${$add_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
if (dependent_getter_) {
printer->Print(variables_,
"$deprecated_attr$const ::google::protobuf::RepeatedPtrField< $type$ >&\n"
" $name$() const;\n");
+ printer->Annotate("name", descriptor_);
}
printer->Print(variables_,
- "$deprecated_attr$::google::protobuf::RepeatedPtrField< $type$ >*\n"
- " mutable_$name$();\n");
+ "$deprecated_attr$::google::protobuf::RepeatedPtrField< $type$ >*\n"
+ " ${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedMessageFieldGenerator::
@@ -916,6 +926,7 @@ GenerateDependentAccessorDeclarations(io::Printer* printer) const {
if (dependent_getter_) {
printer->Print(variables_,
"$deprecated_attr$const $type$& $name$(int index) const;\n");
+ printer->Annotate("name", descriptor_);
}
if (dependent_field_) {
InternalGenerateTypeDependentAccessorDeclarations(printer);
@@ -927,6 +938,7 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
if (!dependent_getter_) {
printer->Print(variables_,
"$deprecated_attr$const $type$& $name$(int index) const;\n");
+ printer->Annotate("name", descriptor_);
}
if (!dependent_field_) {
InternalGenerateTypeDependentAccessorDeclarations(printer);
@@ -935,6 +947,7 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
"$deprecated_attr$const ::google::protobuf::RepeatedPtrField< $type$ >&\n"
" $name$() const;\n");
+ printer->Annotate("name", descriptor_);
}
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc
new file mode 100644
index 00000000..f72a7d60
--- /dev/null
+++ b/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc
@@ -0,0 +1,169 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/test_util.h>
+#include <google/protobuf/unittest.pb.h>
+#include <gtest/gtest.h>
+
+#if LANG_CXX11
+#include <google/protobuf/stubs/type_traits.h>
+#endif
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace cpp {
+
+// Can't use an anonymous namespace here due to brokenness of Tru64 compiler.
+namespace cpp_unittest {
+
+// Moves are enabled only when compiling with a C++11 compiler or newer.
+#if LANG_CXX11
+
+TEST(MovableMessageTest, MoveConstructor) {
+ protobuf_unittest::TestAllTypes message1;
+ TestUtil::SetAllFields(&message1);
+ const auto* nested = &message1.optional_nested_message();
+
+ protobuf_unittest::TestAllTypes message2(std::move(message1));
+ TestUtil::ExpectAllFieldsSet(message2);
+
+ // Check if the optional_nested_message was actually moved (and not just
+ // copied).
+ EXPECT_EQ(nested, &message2.optional_nested_message());
+ EXPECT_NE(nested, &message1.optional_nested_message());
+}
+
+TEST(MovableMessageTest, MoveAssignmentOperator) {
+ protobuf_unittest::TestAllTypes message1;
+ TestUtil::SetAllFields(&message1);
+ const auto* nested = &message1.optional_nested_message();
+
+ protobuf_unittest::TestAllTypes message2;
+ message2 = std::move(message1);
+ TestUtil::ExpectAllFieldsSet(message2);
+
+ // Check if the optional_nested_message was actually moved (and not just
+ // copied).
+ EXPECT_EQ(nested, &message2.optional_nested_message());
+ EXPECT_NE(nested, &message1.optional_nested_message());
+}
+
+TEST(MovableMessageTest, SelfMoveAssignment) {
+ // The `self` reference is necessary to defeat -Wself-move.
+ protobuf_unittest::TestAllTypes message, &self = message;
+ TestUtil::SetAllFields(&message);
+ message = std::move(self);
+ TestUtil::ExpectAllFieldsSet(message);
+}
+
+TEST(MovableMessageTest, MoveSameArena) {
+ Arena arena;
+
+ auto* message1_on_arena =
+ Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena);
+ TestUtil::SetAllFields(message1_on_arena);
+ const auto* nested = &message1_on_arena->optional_nested_message();
+
+ auto* message2_on_arena =
+ Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena);
+
+ // Moving messages on the same arena should lead to swapped pointers.
+ *message2_on_arena = std::move(*message1_on_arena);
+ EXPECT_EQ(nested, &message2_on_arena->optional_nested_message());
+}
+
+TEST(MovableMessageTest, MoveDifferentArenas) {
+ Arena arena1, arena2;
+
+ auto* message1_on_arena =
+ Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena1);
+ TestUtil::SetAllFields(message1_on_arena);
+ const auto* nested = &message1_on_arena->optional_nested_message();
+
+ auto* message2_on_arena =
+ Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena2);
+
+ // Moving messages on two different arenas should lead to a copy.
+ *message2_on_arena = std::move(*message1_on_arena);
+ EXPECT_NE(nested, &message2_on_arena->optional_nested_message());
+ TestUtil::ExpectAllFieldsSet(*message1_on_arena);
+ TestUtil::ExpectAllFieldsSet(*message2_on_arena);
+}
+
+TEST(MovableMessageTest, MoveFromArena) {
+ Arena arena;
+
+ auto* message1_on_arena =
+ Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena);
+ TestUtil::SetAllFields(message1_on_arena);
+ const auto* nested = &message1_on_arena->optional_nested_message();
+
+ protobuf_unittest::TestAllTypes message2;
+
+ // Moving from a message on the arena should lead to a copy.
+ message2 = std::move(*message1_on_arena);
+ EXPECT_NE(nested, &message2.optional_nested_message());
+ TestUtil::ExpectAllFieldsSet(*message1_on_arena);
+ TestUtil::ExpectAllFieldsSet(message2);
+}
+
+TEST(MovableMessageTest, MoveToArena) {
+ Arena arena;
+
+ protobuf_unittest::TestAllTypes message1;
+ TestUtil::SetAllFields(&message1);
+ const auto* nested = &message1.optional_nested_message();
+
+ auto* message2_on_arena =
+ Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena);
+
+ // Moving to a message on the arena should lead to a copy.
+ *message2_on_arena = std::move(message1);
+ EXPECT_NE(nested, &message2_on_arena->optional_nested_message());
+ TestUtil::ExpectAllFieldsSet(message1);
+ TestUtil::ExpectAllFieldsSet(*message2_on_arena);
+}
+
+TEST(MovableMessageTest, Noexcept) {
+ EXPECT_TRUE(
+ std::is_nothrow_move_constructible<protobuf_unittest::TestAllTypes>());
+ EXPECT_TRUE(std::is_nothrow_move_assignable<protobuf_unittest::TestAllTypes>());
+}
+
+#endif // LANG_CXX11
+
+} // namespace cpp_unittest
+
+} // namespace cpp
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
diff --git a/src/google/protobuf/compiler/cpp/cpp_options.h b/src/google/protobuf/compiler/cpp/cpp_options.h
index bdaa12a5..04338083 100644
--- a/src/google/protobuf/compiler/cpp/cpp_options.h
+++ b/src/google/protobuf/compiler/cpp/cpp_options.h
@@ -49,7 +49,8 @@ struct Options {
transitive_pb_h(true),
annotate_headers(false),
enforce_lite(false),
- table_driven_parsing(false) {}
+ table_driven_parsing(false),
+ table_driven_serialization(false) {}
string dllexport_decl;
bool safe_boundary_check;
@@ -58,6 +59,7 @@ struct Options {
bool annotate_headers;
bool enforce_lite;
bool table_driven_parsing;
+ bool table_driven_serialization;
string annotation_pragma_name;
string annotation_guard_name;
};
diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
index e45f35b3..b05fcc4e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
@@ -115,9 +115,11 @@ GeneratePrivateMembers(io::Printer* printer) const {
void PrimitiveFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
+ printer->Print(variables_, "$deprecated_attr$$type$ $name$() const;\n");
+ printer->Annotate("name", descriptor_);
printer->Print(variables_,
- "$deprecated_attr$$type$ $name$() const;\n"
- "$deprecated_attr$void set_$name$($type$ value);\n");
+ "$deprecated_attr$void ${$set_$name$$}$($type$ value);\n");
+ printer->Annotate("{", "}", descriptor_);
}
void PrimitiveFieldGenerator::
@@ -148,7 +150,7 @@ GenerateMergingCode(io::Printer* printer) const {
void PrimitiveFieldGenerator::
GenerateSwappingCode(io::Printer* printer) const {
- printer->Print(variables_, "std::swap($name$_, other->$name$_);\n");
+ printer->Print(variables_, "swap($name$_, other->$name$_);\n");
}
void PrimitiveFieldGenerator::
@@ -290,14 +292,23 @@ GeneratePrivateMembers(io::Printer* printer) const {
void RepeatedPrimitiveFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$deprecated_attr$$type$ $name$(int index) const;\n"
- "$deprecated_attr$void set_$name$(int index, $type$ value);\n"
- "$deprecated_attr$void add_$name$($type$ value);\n");
+ "$deprecated_attr$$type$ $name$(int index) const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(int index, $type$ value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$add_$name$$}$($type$ value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n"
+ " $name$() const;\n");
+ printer->Annotate("name", descriptor_);
printer->Print(variables_,
- "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n"
- " $name$() const;\n"
- "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n"
- " mutable_$name$();\n");
+ "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n"
+ " ${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedPrimitiveFieldGenerator::
@@ -316,8 +327,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
"$inline$void $classname$::add_$name$($type$ value) {\n"
" $name$_.Add(value);\n"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
- "}\n");
- printer->Print(variables,
+ "}\n"
"$inline$const ::google::protobuf::RepeatedField< $type$ >&\n"
"$classname$::$name$() const {\n"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 6a710888..fec13b6d 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -142,28 +142,47 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
}
printer->Print(variables_,
- "$deprecated_attr$const ::std::string& $name$() const;\n"
- "$deprecated_attr$void set_$name$(const ::std::string& value);\n");
+ "$deprecated_attr$const ::std::string& $name$() const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(const ::std::string& value);\n");
+ printer->Annotate("{", "}", descriptor_);
- if (!SupportsArenas(descriptor_)) {
- printer->Print(variables_,
- "#if LANG_CXX11\n"
- "$deprecated_attr$void set_$name$(::std::string&& value);\n"
- "#endif\n");
- }
+ printer->Print(variables_,
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void ${$set_$name$$}$(::std::string&& value);\n"
+ "#endif\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(const char* value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(const $pointer_type$* "
+ "value, size_t size)"
+ ";\n");
+ printer->Annotate("{", "}", descriptor_);
printer->Print(variables_,
- "$deprecated_attr$void set_$name$(const char* value);\n"
- "$deprecated_attr$void set_$name$(const $pointer_type$* value, size_t size)"
- ";\n"
- "$deprecated_attr$::std::string* mutable_$name$();\n"
- "$deprecated_attr$::std::string* $release_name$();\n"
- "$deprecated_attr$void set_allocated_$name$(::std::string* $name$);\n");
+ "$deprecated_attr$::std::string* ${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_, "$deprecated_attr$::std::string* $release_name$();\n");
+ printer->Annotate("release_name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_allocated_$name$$}$(::std::string* $name$);\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportsArenas(descriptor_)) {
- printer->Print(variables_,
- "$deprecated_attr$::std::string* unsafe_arena_release_$name$();\n"
- "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n"
- " ::std::string* $name$);\n");
+ printer->Print(
+ variables_,
+ "$deprecated_attr$::std::string* ${$unsafe_arena_release_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$unsafe_arena_set_allocated_$name$$}$(\n"
+ " ::std::string* $name$);\n");
+ printer->Annotate("{", "}", descriptor_);
}
@@ -191,6 +210,14 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" $name$_.Set($default_variable$, value, GetArenaNoVirtual());\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(::std::string&& value) {\n"
+ " $set_hasbit$\n"
+ " $name$_.Set(\n"
+ " $default_variable$, ::std::move(value), GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
+ "}\n"
+ "#endif\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
" $null_check$"
" $set_hasbit$\n"
@@ -456,15 +483,10 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) const {
printer->Print(variables_,
"$classname$::$default_variable_name$.DefaultConstruct();\n"
"*$classname$::$default_variable_name$.get_mutable() = "
- "::std::string($default$, $default_length$);\n");
- }
-}
-
-void StringFieldGenerator::
-GenerateShutdownCode(io::Printer* printer) const {
- if (!descriptor_->default_value_string().empty()) {
- printer->Print(variables_,
- "$classname$::$default_variable_name$.Shutdown();\n");
+ "::std::string($default$, $default_length$);\n"
+ "::google::protobuf::internal::OnShutdownDestroyString(\n"
+ " $classname$::$default_variable_name$.get_mutable());\n"
+ );
}
}
@@ -554,6 +576,19 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" GetArenaNoVirtual());\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(::std::string&& value) {\n"
+ " // @@protoc_insertion_point(field_set:$full_name$)\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.Set(\n"
+ " $default_variable$, ::std::move(value), GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
+ "}\n"
+ "#endif\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
" $null_check$"
" if (!has_$name$()) {\n"
@@ -837,28 +872,62 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
}
printer->Print(variables_,
- "$deprecated_attr$const ::std::string& $name$(int index) const;\n"
- "$deprecated_attr$::std::string* mutable_$name$(int index);\n"
- "$deprecated_attr$void set_$name$(int index, const ::std::string& value);\n"
- "#if LANG_CXX11\n"
- "$deprecated_attr$void set_$name$(int index, ::std::string&& value);\n"
- "#endif\n"
- "$deprecated_attr$void set_$name$(int index, const char* value);\n"
- ""
- "$deprecated_attr$void set_$name$("
- "int index, const $pointer_type$* value, size_t size);\n"
- "$deprecated_attr$::std::string* add_$name$();\n"
- "$deprecated_attr$void add_$name$(const ::std::string& value);\n"
- "#if LANG_CXX11\n"
- "$deprecated_attr$void add_$name$(::std::string&& value);\n"
- "#endif\n"
- "$deprecated_attr$void add_$name$(const char* value);\n"
- "$deprecated_attr$void add_$name$(const $pointer_type$* value, size_t size)"
- ";\n"
- "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() "
- "const;\n"
- "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* mutable_$name$()"
+ "$deprecated_attr$const ::std::string& $name$(int index) const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$::std::string* ${$mutable_$name$$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(int index, const "
+ "::std::string& value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void ${$set_$name$$}$(int index, ::std::string&& value);\n"
+ "#endif\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(int index, const "
+ "char* value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ ""
+ "$deprecated_attr$void ${$set_$name$$}$("
+ "int index, const $pointer_type$* value, size_t size);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$::std::string* ${$add_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$add_$name$$}$(const ::std::string& value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void ${$add_$name$$}$(::std::string&& value);\n"
+ "#endif\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$add_$name$$}$(const char* value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$add_$name$$}$(const $pointer_type$* "
+ "value, size_t size)"
+ ";\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() "
+ "const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* "
+ "${$mutable_$name$$}$()"
";\n");
+ printer->Annotate("{", "}", descriptor_);
if (unknown_ctype) {
printer->Outdent();
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.h b/src/google/protobuf/compiler/cpp/cpp_string_field.h
index af263c1a..531252b0 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.h
@@ -65,7 +65,6 @@ class StringFieldGenerator : public FieldGenerator {
void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateDestructorCode(io::Printer* printer) const;
void GenerateDefaultInstanceAllocator(io::Printer* printer) const;
- void GenerateShutdownCode(io::Printer* printer) const;
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
index e56964c7..fdde771b 100644
--- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
@@ -576,12 +576,73 @@ TEST(GeneratedMessageTest, SwapWithOther) {
EXPECT_EQ(unittest::TestAllTypes::BAR, message2.repeated_nested_enum(1));
}
-TEST(GeneratedMessageTest, CopyConstructor) {
- unittest::TestAllTypes message1;
+TEST(GeneratedMessageTest, ADLSwap) {
+ unittest::TestAllTypes message1, message2;
TestUtil::SetAllFields(&message1);
- unittest::TestAllTypes message2(message1);
+ // Note the address of one of the repeated fields, to verify it was swapped
+ // rather than copied.
+ const int32* addr = &message1.repeated_int32().Get(0);
+
+ using std::swap;
+ swap(message1, message2);
+
TestUtil::ExpectAllFieldsSet(message2);
+ TestUtil::ExpectClear(message1);
+
+ EXPECT_EQ(addr, &message2.repeated_int32().Get(0));
+}
+
+TEST(GeneratedMessageTest, CopyConstructor) {
+ // All set.
+ {
+ unittest::TestAllTypes message1;
+ TestUtil::SetAllFields(&message1);
+
+ unittest::TestAllTypes message2(message1);
+ TestUtil::ExpectAllFieldsSet(message2);
+ }
+
+ // None set.
+ {
+ unittest::TestAllTypes message1;
+ unittest::TestAllTypes message2(message1);
+
+ EXPECT_FALSE(message1.has_optional_string());
+ EXPECT_FALSE(message2.has_optional_string());
+ EXPECT_EQ(&message1.optional_string(),
+ &message2.optional_string());
+
+ EXPECT_FALSE(message1.has_optional_bytes());
+ EXPECT_FALSE(message2.has_optional_bytes());
+ EXPECT_EQ(&message1.optional_bytes(),
+ &message2.optional_bytes());
+
+ EXPECT_FALSE(message1.has_optional_nested_message());
+ EXPECT_FALSE(message2.has_optional_nested_message());
+ EXPECT_EQ(&message1.optional_nested_message(),
+ &message2.optional_nested_message());
+
+ EXPECT_FALSE(message1.has_optional_foreign_message());
+ EXPECT_FALSE(message2.has_optional_foreign_message());
+ EXPECT_EQ(&message1.optional_foreign_message(),
+ &message2.optional_foreign_message());
+
+ EXPECT_FALSE(message1.has_optional_import_message());
+ EXPECT_FALSE(message2.has_optional_import_message());
+ EXPECT_EQ(&message1.optional_import_message(),
+ &message2.optional_import_message());
+
+ EXPECT_FALSE(message1.has_optional_public_import_message());
+ EXPECT_FALSE(message2.has_optional_public_import_message());
+ EXPECT_EQ(&message1.optional_public_import_message(),
+ &message2.optional_public_import_message());
+
+ EXPECT_FALSE(message1.has_optional_lazy_message());
+ EXPECT_FALSE(message2.has_optional_lazy_message());
+ EXPECT_EQ(&message1.optional_lazy_message(),
+ &message2.optional_lazy_message());
+ }
}
TEST(GeneratedMessageTest, CopyConstructorWithArenas) {
@@ -1340,7 +1401,7 @@ class GeneratedServiceTest : public testing::Test {
foo_(descriptor_->FindMethodByName("Foo")),
bar_(descriptor_->FindMethodByName("Bar")),
stub_(&mock_channel_),
- done_(NewPermanentCallback(&DoNothing)) {}
+ done_(::google::protobuf::NewPermanentCallback(&DoNothing)) {}
virtual void SetUp() {
ASSERT_TRUE(foo_ != NULL);
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index 71e3c6de..4c357aa0 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -32,6 +32,7 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
+
#ifdef _MSC_VER
#include <direct.h>
#else
@@ -58,6 +59,9 @@
#ifdef _WIN32
#include <ctype.h>
+#endif
+
+#ifdef _MSC_VER
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::access;
@@ -297,10 +301,8 @@ static string CanonicalizePath(string path) {
}
static inline bool ContainsParentReference(const string& path) {
- return path == ".." ||
- HasPrefixString(path, "../") ||
- HasSuffixString(path, "/..") ||
- path.find("/../") != string::npos;
+ return path == ".." || HasPrefixString(path, "../") ||
+ HasSuffixString(path, "/..") || path.find("/../") != string::npos;
}
// Maps a file from an old location to a new one. Typically, old_prefix is
@@ -330,8 +332,7 @@ static bool ApplyMapping(const string& filename,
// We do not allow the file name to use "..".
return false;
}
- if (HasPrefixString(filename, "/") ||
- IsWindowsAbsolutePath(filename)) {
+ if (HasPrefixString(filename, "/") || IsWindowsAbsolutePath(filename)) {
// This is an absolute path, so it isn't matched by the empty string.
return false;
}
diff --git a/src/google/protobuf/compiler/java/java_context.cc b/src/google/protobuf/compiler/java/java_context.cc
index b82fb3dd..0771d5e1 100644
--- a/src/google/protobuf/compiler/java/java_context.cc
+++ b/src/google/protobuf/compiler/java/java_context.cc
@@ -50,7 +50,7 @@ Context::Context(const FileDescriptor* file, const Options& options)
Context::~Context() {
}
-ClassNameResolver* Context::GetNameResolver() {
+ClassNameResolver* Context::GetNameResolver() const {
return name_resolver_.get();
}
@@ -154,7 +154,7 @@ void Context::InitializeFieldGeneratorInfoForFields(
for (int i = 0; i < fields.size(); ++i) {
const FieldDescriptor* field = fields[i];
FieldGeneratorInfo info;
- info.name = UnderscoresToCamelCase(field);
+ info.name = CamelCaseFieldName(field);
info.capitalized_name = UnderscoresToCapitalizedCamelCase(field);
// For fields conflicting with some other fields, we append the field
// number to their field names in generated code to avoid conflicts.
diff --git a/src/google/protobuf/compiler/java/java_context.h b/src/google/protobuf/compiler/java/java_context.h
index b22e7e3a..9a74c430 100644
--- a/src/google/protobuf/compiler/java/java_context.h
+++ b/src/google/protobuf/compiler/java/java_context.h
@@ -70,7 +70,7 @@ class Context {
// Get the name resolver associated with this context. The resolver
// can be used to map descriptors to Java class names.
- ClassNameResolver* GetNameResolver();
+ ClassNameResolver* GetNameResolver() const;
// Get the FieldGeneratorInfo for a given field.
const FieldGeneratorInfo* GetFieldGeneratorInfo(
diff --git a/src/google/protobuf/compiler/java/java_enum.cc b/src/google/protobuf/compiler/java/java_enum.cc
index b9ee00ff..d125ebe5 100644
--- a/src/google/protobuf/compiler/java/java_enum.cc
+++ b/src/google/protobuf/compiler/java/java_enum.cc
@@ -109,14 +109,16 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print(vars,
"$name$($index$, $number$),\n");
}
+ printer->Annotate("name", canonical_values_[i]);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
if (ordinal_is_index) {
- printer->Print("UNRECOGNIZED(-1),\n");
+ printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", "");
} else {
- printer->Print("UNRECOGNIZED(-1, -1),\n");
+ printer->Print("${$UNRECOGNIZED$}$(-1, -1),\n", "{", "", "}", "");
}
+ printer->Annotate("{", "}", descriptor_);
}
printer->Print(
@@ -133,15 +135,19 @@ void EnumGenerator::Generate(io::Printer* printer) {
WriteEnumValueDocComment(printer, aliases_[i].value);
printer->Print(vars,
"public static final $classname$ $name$ = $canonical_name$;\n");
+ printer->Annotate("name", aliases_[i].value);
}
for (int i = 0; i < descriptor_->value_count(); i++) {
std::map<string, string> vars;
vars["name"] = descriptor_->value(i)->name();
vars["number"] = SimpleItoa(descriptor_->value(i)->number());
+ vars["{"] = "";
+ vars["}"] = "";
WriteEnumValueDocComment(printer, descriptor_->value(i));
printer->Print(vars,
- "public static final int $name$_VALUE = $number$;\n");
+ "public static final int ${$$name$_VALUE$}$ = $number$;\n");
+ printer->Annotate("{", "}", descriptor_->value(i));
}
printer->Print("\n");
diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc
index 279b9da4..9f7bb349 100644
--- a/src/google/protobuf/compiler/java/java_enum_field.cc
+++ b/src/google/protobuf/compiler/java/java_enum_field.cc
@@ -183,23 +183,26 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" $type$ result = $type$.$for_number$($name$_);\n"
" return result == null ? $unknown$ : result;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableEnumFieldGenerator::
@@ -209,33 +212,38 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_builder$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Value(int value) {\n"
+ "$deprecation$public Builder "
+ "${$set$capitalized_name$Value$}$(int value) {\n"
" $name$_ = value;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" $type$ result = $type$.$for_number$($name$_);\n"
" return result == null ? $unknown$ : result;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" if (value == null) {\n"
" throw new NullPointerException();\n"
" }\n"
@@ -244,14 +252,16 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $clear_has_field_bit_builder$\n"
" $name$_ = $default_number$;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableEnumFieldGenerator::
@@ -311,12 +321,8 @@ GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
"$type$ value = $type$.$for_number$(rawValue);\n"
- "if (value == null) {\n");
- if (PreserveUnknownFields(descriptor_->containing_type())) {
- printer->Print(variables_,
- " unknownFields.mergeVarintField($number$, rawValue);\n");
- }
- printer->Print(variables_,
+ "if (value == null) {\n"
+ " unknownFields.mergeVarintField($number$, rawValue);\n"
"} else {\n"
" $set_has_field_bit_message$\n"
" $name$_ = rawValue;\n"
@@ -386,23 +392,25 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return (java.lang.Integer) $oneof_name$_;\n"
" }\n"
" return $default_number$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" $type$ result = $type$.$for_number$(\n"
" (java.lang.Integer) $oneof_name$_);\n"
@@ -410,6 +418,7 @@ GenerateMembers(io::Printer* printer) const {
" }\n"
" return $default$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableEnumOneofFieldGenerator::
@@ -417,31 +426,35 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return ((java.lang.Integer) $oneof_name$_).intValue();\n"
" }\n"
" return $default_number$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Value(int value) {\n"
+ "$deprecation$public Builder "
+ "${$set$capitalized_name$Value$}$(int value) {\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = value;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" $type$ result = $type$.$for_number$(\n"
" (java.lang.Integer) $oneof_name$_);\n"
@@ -449,9 +462,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return $default$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" if (value == null) {\n"
" throw new NullPointerException();\n"
" }\n"
@@ -460,9 +474,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" $clear_oneof_case_message$;\n"
" $oneof_name$_ = null;\n"
@@ -470,6 +485,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableEnumOneofFieldGenerator::
@@ -502,12 +518,8 @@ GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
"$type$ value = $type$.$for_number$(rawValue);\n"
- "if (value == null) {\n");
- if (PreserveUnknownFields(descriptor_->containing_type())) {
- printer->Print(variables_,
- " unknownFields.mergeVarintField($number$, rawValue);\n");
- }
- printer->Print(variables_,
+ "if (value == null) {\n"
+ " unknownFields.mergeVarintField($number$, rawValue);\n"
"} else {\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = rawValue;\n"
@@ -621,32 +633,38 @@ GenerateMembers(io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$() {\n"
" return new com.google.protobuf.Internal.ListAdapter<\n"
" java.lang.Integer, $type$>($name$_, $name$_converter_);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_converter_.convert($name$_.get(index));\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<java.lang.Integer>\n"
- "get$capitalized_name$ValueList() {\n"
+ "${$get$capitalized_name$ValueList$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value(int index) {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (descriptor_->is_packed() &&
@@ -684,23 +702,27 @@ GenerateBuilderMembers(io::Printer* printer) const {
// could hold on to the returned list and modify it after the message
// has been built, thus mutating the message which is supposed to be
// immutable.
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$() {\n"
" return new com.google.protobuf.Internal.ListAdapter<\n"
" java.lang.Integer, $type$>($name$_, $name$_converter_);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_converter_.convert($name$_.get(index));\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$ value) {\n"
" if (value == null) {\n"
" throw new NullPointerException();\n"
@@ -710,9 +732,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n"
" if (value == null) {\n"
" throw new NullPointerException();\n"
" }\n"
@@ -721,9 +744,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<? extends $type$> values) {\n"
" ensure$capitalized_name$IsMutable();\n"
" for ($type$ value : values) {\n"
@@ -732,47 +756,54 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $name$_ = java.util.Collections.emptyList();\n"
" $clear_mutable_bit_builder$;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<java.lang.Integer>\n"
- "get$capitalized_name$ValueList() {\n"
+ "${$get$capitalized_name$ValueList$}$() {\n"
" return java.util.Collections.unmodifiableList($name$_);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value(int index) {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$Value$}$(\n"
" int index, int value) {\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.set(index, value);\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$Value(int value) {\n"
+ "$deprecation$public Builder "
+ "${$add$capitalized_name$Value$}$(int value) {\n"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.add(value);\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$Value$}$(\n"
" java.lang.Iterable<java.lang.Integer> values) {\n"
" ensure$capitalized_name$IsMutable();\n"
" for (int value : values) {\n"
@@ -781,6 +812,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
@@ -848,12 +880,8 @@ GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
"$type$ value = $type$.$for_number$(rawValue);\n"
- "if (value == null) {\n");
- if (PreserveUnknownFields(descriptor_->containing_type())) {
- printer->Print(variables_,
- " unknownFields.mergeVarintField($number$, rawValue);\n");
- }
- printer->Print(variables_,
+ "if (value == null) {\n"
+ " unknownFields.mergeVarintField($number$, rawValue);\n"
"} else {\n"
" if (!$get_mutable_bit_parser$) {\n"
" $name$_ = new java.util.ArrayList<java.lang.Integer>();\n"
diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/src/google/protobuf/compiler/java/java_enum_field_lite.cc
index 1eefdcfc..a4de1e23 100644
--- a/src/google/protobuf/compiler/java/java_enum_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_enum_field_lite.cc
@@ -165,23 +165,26 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" $type$ result = $type$.forNumber($name$_);\n"
" return result == null ? $unknown$ : result;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Generate private setters for the builder to proxy into.
if (SupportUnknownEnumValue(descriptor_->file())) {
@@ -214,43 +217,50 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return instance.has$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" return instance.get$capitalized_name$Value();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Value(int value) {\n"
+ "$deprecation$public Builder "
+ "${$set$capitalized_name$Value$}$(int value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$Value(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableEnumFieldLiteGenerator::
@@ -296,12 +306,8 @@ GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
"$type$ value = $type$.forNumber(rawValue);\n"
- "if (value == null) {\n");
- if (PreserveUnknownFields(descriptor_->containing_type())) {
- printer->Print(variables_,
- " super.mergeVarintField($number$, rawValue);\n");
- }
- printer->Print(variables_,
+ "if (value == null) {\n"
+ " super.mergeVarintField($number$, rawValue);\n"
"} else {\n"
" $set_has_field_bit_message$\n"
" $name$_ = rawValue;\n"
@@ -372,29 +378,32 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return (java.lang.Integer) $oneof_name$_;\n"
" }\n"
" return $default_number$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" $type$ result = $type$.forNumber((java.lang.Integer) $oneof_name$_);\n"
" return result == null ? $unknown$ : result;\n"
" }\n"
" return $default$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Generate private setters for the builder to proxy into.
if (SupportUnknownEnumValue(descriptor_->file())) {
@@ -430,43 +439,50 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return instance.has$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
" return instance.get$capitalized_name$Value();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Value(int value) {\n"
+ "$deprecation$public Builder "
+ "${$set$capitalized_name$Value$}$(int value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$Value(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableEnumOneofFieldLiteGenerator::
@@ -487,12 +503,8 @@ GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
"$type$ value = $type$.forNumber(rawValue);\n"
- "if (value == null) {\n");
- if (PreserveUnknownFields(descriptor_->containing_type())) {
- printer->Print(variables_,
- " super.mergeVarintField($number$, rawValue);\n");
- }
- printer->Print(variables_,
+ "if (value == null) {\n"
+ " super.mergeVarintField($number$, rawValue);\n"
"} else {\n"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = rawValue;\n"
@@ -607,35 +619,41 @@ GenerateMembers(io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$() {\n"
" return new com.google.protobuf.Internal.ListAdapter<\n"
" java.lang.Integer, $type$>($name$_, $name$_converter_);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_converter_.convert($name$_.getInt(index));\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<java.lang.Integer>\n"
- "get$capitalized_name$ValueList() {\n"
+ "${$get$capitalized_name$ValueList$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value(int index) {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n"
" return $name$_.getInt(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
- if (descriptor_->options().packed() &&
+ if (descriptor_->is_packed() &&
context_->HasGeneratedMethods(descriptor_->containing_type())) {
printer->Print(variables_,
"private int $name$MemoizedSerializedSize;\n");
@@ -714,85 +732,99 @@ void RepeatedImmutableEnumFieldLiteGenerator::
GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$() {\n"
" return instance.get$capitalized_name$List();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return instance.get$capitalized_name$Count();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return instance.get$capitalized_name$(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(index, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<? extends $type$> values) {\n"
" copyOnWrite();\n"
" instance.addAll$capitalized_name$(values);"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<java.lang.Integer>\n"
- "get$capitalized_name$ValueList() {\n"
+ "${$get$capitalized_name$ValueList$}$() {\n"
" return java.util.Collections.unmodifiableList(\n"
" instance.get$capitalized_name$ValueList());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Value(int index) {\n"
+ "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n"
" return instance.get$capitalized_name$Value(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$Value$}$(\n"
" int index, int value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$Value(index, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$Value(int value) {\n"
+ "$deprecation$public Builder "
+ "${$add$capitalized_name$Value$}$(int value) {\n"
" instance.add$capitalized_name$Value(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$Value$}$(\n"
" java.lang.Iterable<java.lang.Integer> values) {\n"
" copyOnWrite();\n"
" instance.addAll$capitalized_name$Value(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
@@ -889,7 +921,7 @@ GenerateParsingDoneCode(io::Printer* printer) const {
void RepeatedImmutableEnumFieldLiteGenerator::
GenerateSerializationCode(io::Printer* printer) const {
- if (descriptor_->options().packed()) {
+ if (descriptor_->is_packed()) {
printer->Print(variables_,
"if (get$capitalized_name$List().size() > 0) {\n"
" output.writeUInt32NoTag($tag$);\n"
@@ -920,7 +952,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
"}\n");
printer->Print(
"size += dataSize;\n");
- if (descriptor_->options().packed()) {
+ if (descriptor_->is_packed()) {
printer->Print(variables_,
"if (!get$capitalized_name$List().isEmpty()) {"
" size += $tag_size$;\n"
@@ -933,7 +965,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
}
// cache the data size for packed fields.
- if (descriptor_->options().packed()) {
+ if (descriptor_->is_packed()) {
printer->Print(variables_,
"$name$MemoizedSerializedSize = dataSize;\n");
}
diff --git a/src/google/protobuf/compiler/java/java_enum_lite.cc b/src/google/protobuf/compiler/java/java_enum_lite.cc
index 38b054e7..ab3b3323 100644
--- a/src/google/protobuf/compiler/java/java_enum_lite.cc
+++ b/src/google/protobuf/compiler/java/java_enum_lite.cc
@@ -93,10 +93,12 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
}
printer->Print(vars,
"$name$($number$),\n");
+ printer->Annotate("name", canonical_values_[i]);
}
if (SupportUnknownEnumValue(descriptor_->file())) {
- printer->Print("UNRECOGNIZED(-1),\n");
+ printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", "");
+ printer->Annotate("{", "}", descriptor_);
}
printer->Print(
@@ -113,15 +115,19 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
WriteEnumValueDocComment(printer, aliases_[i].value);
printer->Print(vars,
"public static final $classname$ $name$ = $canonical_name$;\n");
+ printer->Annotate("name", aliases_[i].value);
}
for (int i = 0; i < descriptor_->value_count(); i++) {
std::map<string, string> vars;
vars["name"] = descriptor_->value(i)->name();
vars["number"] = SimpleItoa(descriptor_->value(i)->number());
+ vars["{"] = "";
+ vars["}"] = "";
WriteEnumValueDocComment(printer, descriptor_->value(i));
printer->Print(vars,
- "public static final int $name$_VALUE = $number$;\n");
+ "public static final int ${$$name$_VALUE$}$ = $number$;\n");
+ printer->Annotate("{", "}", descriptor_->value(i));
}
printer->Print("\n");
diff --git a/src/google/protobuf/compiler/java/java_extension.cc b/src/google/protobuf/compiler/java/java_extension.cc
index cb237bf6..9b9be55b 100644
--- a/src/google/protobuf/compiler/java/java_extension.cc
+++ b/src/google/protobuf/compiler/java/java_extension.cc
@@ -75,7 +75,7 @@ void ExtensionGenerator::InitTemplateVars(
vars["default"] = descriptor->is_repeated() ?
"" : DefaultValue(descriptor, immutable, name_resolver);
vars["type_constant"] = FieldTypeName(GetType(descriptor));
- vars["packed"] = descriptor->options().packed() ? "true" : "false";
+ vars["packed"] = descriptor->is_packed() ? "true" : "false";
vars["enum_map"] = "null";
vars["prototype"] = "null";
diff --git a/src/google/protobuf/compiler/java/java_field.cc b/src/google/protobuf/compiler/java/java_field.cc
index 04917296..1ab18629 100644
--- a/src/google/protobuf/compiler/java/java_field.cc
+++ b/src/google/protobuf/compiler/java/java_field.cc
@@ -45,8 +45,6 @@
#include <google/protobuf/compiler/java/java_enum_field.h>
#include <google/protobuf/compiler/java/java_enum_field_lite.h>
#include <google/protobuf/compiler/java/java_helpers.h>
-#include <google/protobuf/compiler/java/java_lazy_message_field.h>
-#include <google/protobuf/compiler/java/java_lazy_message_field_lite.h>
#include <google/protobuf/compiler/java/java_map_field.h>
#include <google/protobuf/compiler/java/java_map_field_lite.h>
#include <google/protobuf/compiler/java/java_message_field.h>
@@ -77,13 +75,8 @@ ImmutableFieldGenerator* MakeImmutableGenerator(
return new ImmutableMapFieldGenerator(
field, messageBitIndex, builderBitIndex, context);
} else {
- if (IsLazy(field, context->EnforceLite())) {
- return new RepeatedImmutableLazyMessageFieldGenerator(
- field, messageBitIndex, builderBitIndex, context);
- } else {
- return new RepeatedImmutableMessageFieldGenerator(
- field, messageBitIndex, builderBitIndex, context);
- }
+ return new RepeatedImmutableMessageFieldGenerator(
+ field, messageBitIndex, builderBitIndex, context);
}
case JAVATYPE_ENUM:
return new RepeatedImmutableEnumFieldGenerator(
@@ -99,13 +92,8 @@ ImmutableFieldGenerator* MakeImmutableGenerator(
if (field->containing_oneof()) {
switch (GetJavaType(field)) {
case JAVATYPE_MESSAGE:
- if (IsLazy(field, context->EnforceLite())) {
- return new ImmutableLazyMessageOneofFieldGenerator(
- field, messageBitIndex, builderBitIndex, context);
- } else {
- return new ImmutableMessageOneofFieldGenerator(
- field, messageBitIndex, builderBitIndex, context);
- }
+ return new ImmutableMessageOneofFieldGenerator(
+ field, messageBitIndex, builderBitIndex, context);
case JAVATYPE_ENUM:
return new ImmutableEnumOneofFieldGenerator(
field, messageBitIndex, builderBitIndex, context);
@@ -119,13 +107,8 @@ ImmutableFieldGenerator* MakeImmutableGenerator(
} else {
switch (GetJavaType(field)) {
case JAVATYPE_MESSAGE:
- if (IsLazy(field, context->EnforceLite())) {
- return new ImmutableLazyMessageFieldGenerator(
- field, messageBitIndex, builderBitIndex, context);
- } else {
- return new ImmutableMessageFieldGenerator(
- field, messageBitIndex, builderBitIndex, context);
- }
+ return new ImmutableMessageFieldGenerator(
+ field, messageBitIndex, builderBitIndex, context);
case JAVATYPE_ENUM:
return new ImmutableEnumFieldGenerator(
field, messageBitIndex, builderBitIndex, context);
@@ -150,13 +133,8 @@ ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator(
return new ImmutableMapFieldLiteGenerator(
field, messageBitIndex, builderBitIndex, context);
} else {
- if (IsLazy(field, context->EnforceLite())) {
- return new RepeatedImmutableLazyMessageFieldLiteGenerator(
- field, messageBitIndex, builderBitIndex, context);
- } else {
- return new RepeatedImmutableMessageFieldLiteGenerator(
- field, messageBitIndex, builderBitIndex, context);
- }
+ return new RepeatedImmutableMessageFieldLiteGenerator(
+ field, messageBitIndex, builderBitIndex, context);
}
case JAVATYPE_ENUM:
return new RepeatedImmutableEnumFieldLiteGenerator(
@@ -172,13 +150,8 @@ ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator(
if (field->containing_oneof()) {
switch (GetJavaType(field)) {
case JAVATYPE_MESSAGE:
- if (IsLazy(field, context->EnforceLite())) {
- return new ImmutableLazyMessageOneofFieldLiteGenerator(
- field, messageBitIndex, builderBitIndex, context);
- } else {
- return new ImmutableMessageOneofFieldLiteGenerator(
- field, messageBitIndex, builderBitIndex, context);
- }
+ return new ImmutableMessageOneofFieldLiteGenerator(
+ field, messageBitIndex, builderBitIndex, context);
case JAVATYPE_ENUM:
return new ImmutableEnumOneofFieldLiteGenerator(
field, messageBitIndex, builderBitIndex, context);
@@ -192,13 +165,8 @@ ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator(
} else {
switch (GetJavaType(field)) {
case JAVATYPE_MESSAGE:
- if (IsLazy(field, context->EnforceLite())) {
- return new ImmutableLazyMessageFieldLiteGenerator(
- field, messageBitIndex, builderBitIndex, context);
- } else {
- return new ImmutableMessageFieldLiteGenerator(
- field, messageBitIndex, builderBitIndex, context);
- }
+ return new ImmutableMessageFieldLiteGenerator(
+ field, messageBitIndex, builderBitIndex, context);
case JAVATYPE_ENUM:
return new ImmutableEnumFieldLiteGenerator(
field, messageBitIndex, builderBitIndex, context);
@@ -293,10 +261,17 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
std::map<string, string>* variables) {
(*variables)["field_name"] = descriptor->name();
(*variables)["name"] = info->name;
+ (*variables)["classname"] = descriptor->containing_type()->name();
(*variables)["capitalized_name"] = info->capitalized_name;
(*variables)["disambiguated_reason"] = info->disambiguated_reason;
(*variables)["constant_name"] = FieldConstantName(descriptor);
(*variables)["number"] = SimpleItoa(descriptor->number());
+ // These variables are placeholders to pick out the beginning and ends of
+ // identifiers for annotations (when doing so with existing variables would
+ // be ambiguous or impossible). They should never be set to anything but the
+ // empty string.
+ (*variables)["{"] = "";
+ (*variables)["}"] = "";
}
void SetCommonOneofVariables(const FieldDescriptor* descriptor,
diff --git a/src/google/protobuf/compiler/java/java_file.cc b/src/google/protobuf/compiler/java/java_file.cc
index 0fda166d..2d5465ba 100644
--- a/src/google/protobuf/compiler/java/java_file.cc
+++ b/src/google/protobuf/compiler/java/java_file.cc
@@ -499,19 +499,57 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(io::Printer*
// Try to load immutable messages' outer class. Its initialization code
// will take care of interpreting custom options.
printer->Print(
- "try {\n"
- // Note that we have to load the immutable class dynamically here as
- // we want the mutable code to be independent from the immutable code
- // at compile time. It is required to implement dual-compile for
- // mutable and immutable API in blaze.
- " java.lang.Class immutableClass = java.lang.Class.forName(\n"
- " \"$immutable_classname$\");\n"
- "} catch (java.lang.ClassNotFoundException e) {\n"
- // The immutable class can not be found. Custom options are left
- // as unknown fields.
- // TODO(xiaofeng): inform the user with a warning?
- "}\n",
- "immutable_classname", name_resolver_->GetImmutableClassName(file_));
+ "try {\n"
+ // Note that we have to load the immutable class dynamically here as
+ // we want the mutable code to be independent from the immutable code
+ // at compile time. It is required to implement dual-compile for
+ // mutable and immutable API in blaze.
+ " java.lang.Class immutableClass = java.lang.Class.forName(\n"
+ " \"$immutable_classname$\");\n"
+ "} catch (java.lang.ClassNotFoundException e) {\n",
+ "immutable_classname", name_resolver_->GetImmutableClassName(file_));
+ printer->Indent();
+
+ // The immutable class can not be found. We try our best to collect all
+ // custom option extensions to interpret the custom options.
+ printer->Print(
+ "com.google.protobuf.ExtensionRegistry registry =\n"
+ " com.google.protobuf.ExtensionRegistry.newInstance();\n"
+ "com.google.protobuf.MessageLite defaultExtensionInstance = null;\n");
+ FieldDescriptorSet::iterator it;
+ for (it = extensions.begin(); it != extensions.end(); it++) {
+ const FieldDescriptor* field = *it;
+ string scope;
+ if (field->extension_scope() != NULL) {
+ scope = name_resolver_->GetMutableClassName(field->extension_scope()) +
+ ".getDescriptor()";
+ } else {
+ scope = FileJavaPackage(field->file(), true) + "." +
+ name_resolver_->GetDescriptorClassName(field->file()) +
+ ".descriptor";
+ }
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ printer->Print(
+ "defaultExtensionInstance = com.google.protobuf.Internal\n"
+ " .getDefaultInstance(\"$class$\");\n"
+ "if (defaultExtensionInstance != null) {\n"
+ " registry.add(\n"
+ " $scope$.getExtensions().get($index$),\n"
+ " (com.google.protobuf.Message) defaultExtensionInstance);\n"
+ "}\n",
+ "scope", scope, "index", SimpleItoa(field->index()), "class",
+ name_resolver_->GetImmutableClassName(field->message_type()));
+ } else {
+ printer->Print("registry.add($scope$.getExtensions().get($index$));\n",
+ "scope", scope, "index", SimpleItoa(field->index()));
+ }
+ }
+ printer->Print(
+ "com.google.protobuf.Descriptors.FileDescriptor\n"
+ " .internalUpdateFileDescriptor(descriptor, registry);\n");
+
+ printer->Outdent();
+ printer->Print("}\n");
}
// Force descriptor initialization of all dependencies.
diff --git a/src/google/protobuf/compiler/java/java_generator.cc b/src/google/protobuf/compiler/java/java_generator.cc
index 02141210..84a3b90d 100644
--- a/src/google/protobuf/compiler/java/java_generator.cc
+++ b/src/google/protobuf/compiler/java/java_generator.cc
@@ -42,6 +42,7 @@
#include <google/protobuf/compiler/java/java_file.h>
#include <google/protobuf/compiler/java/java_generator_factory.h>
#include <google/protobuf/compiler/java/java_helpers.h>
+#include <google/protobuf/compiler/java/java_name_resolver.h>
#include <google/protobuf/compiler/java/java_options.h>
#include <google/protobuf/compiler/java/java_shared_code_generator.h>
#include <google/protobuf/io/printer.h>
diff --git a/src/google/protobuf/compiler/java/java_helpers.cc b/src/google/protobuf/compiler/java/java_helpers.cc
index 8469740f..d8ac2db3 100644
--- a/src/google/protobuf/compiler/java/java_helpers.cc
+++ b/src/google/protobuf/compiler/java/java_helpers.cc
@@ -43,6 +43,8 @@
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+
+
#include <google/protobuf/stubs/hash.h> // for hash<T *>
namespace google {
@@ -167,6 +169,14 @@ string UniqueFileScopeIdentifier(const Descriptor* descriptor) {
return "static_" + StringReplace(descriptor->full_name(), ".", "_", true);
}
+string CamelCaseFieldName(const FieldDescriptor* field) {
+ string fieldName = UnderscoresToCamelCase(field);
+ if ('0' <= fieldName[0] && fieldName[0] <= '9') {
+ return '_' + fieldName;
+ }
+ return fieldName;
+}
+
string StripProto(const string& filename) {
if (HasSuffixString(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel");
diff --git a/src/google/protobuf/compiler/java/java_helpers.h b/src/google/protobuf/compiler/java/java_helpers.h
index 829ec3d7..bd565ced 100644
--- a/src/google/protobuf/compiler/java/java_helpers.h
+++ b/src/google/protobuf/compiler/java/java_helpers.h
@@ -74,6 +74,10 @@ string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field);
// of lower-casing the first letter of the name.)
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);
+
// 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.
@@ -242,15 +246,6 @@ inline bool HasGenericServices(const FileDescriptor *file, bool enforce_lite) {
file->options().java_generic_services();
}
-inline bool IsLazy(const FieldDescriptor* descriptor, bool enforce_lite) {
- // Currently, the proto-lite version supports lazy field.
- // TODO(niwasaki): Support lazy fields also for other proto runtimes.
- if (HasDescriptorMethods(descriptor->file(), enforce_lite)) {
- return false;
- }
- return descriptor->options().lazy();
-}
-
// Methods for shared bitfields.
// Gets the name of the shared bitfield for the given index.
@@ -372,10 +367,6 @@ inline bool IsMapField(const FieldDescriptor* descriptor) {
return descriptor->is_map();
}
-inline bool PreserveUnknownFields(const Descriptor* descriptor) {
- return descriptor->file()->syntax() != FileDescriptor::SYNTAX_PROTO3;
-}
-
inline bool IsAnyMessage(const Descriptor* descriptor) {
return descriptor->full_name() == "google.protobuf.Any";
}
diff --git a/src/google/protobuf/compiler/java/java_map_field.cc b/src/google/protobuf/compiler/java/java_map_field.cc
index 608b5378..b22a2199 100644
--- a/src/google/protobuf/compiler/java/java_map_field.cc
+++ b/src/google/protobuf/compiler/java/java_map_field.cc
@@ -183,12 +183,14 @@ GenerateInterfaceMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$int get$capitalized_name$Count();\n");
+ "$deprecation$int ${$get$capitalized_name$Count$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$boolean contains$capitalized_name$(\n"
+ "$deprecation$boolean ${$contains$capitalized_name$$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
@@ -197,23 +199,27 @@ GenerateInterfaceMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$();\n");
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$Map();\n");
+ "${$get$capitalized_name$Map$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$$value_enum_type$ get$capitalized_name$OrDefault(\n"
+ "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_enum_type$ defaultValue);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$$value_enum_type$ get$capitalized_name$OrThrow(\n"
+ "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
@@ -222,25 +228,29 @@ GenerateInterfaceMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$Value();\n");
+ "${$get$capitalized_name$Value$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$ValueMap();\n");
+ "${$get$capitalized_name$ValueMap$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$ValueOrDefault(\n"
+ "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$ValueOrThrow(\n"
+ "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(
@@ -250,25 +260,29 @@ GenerateInterfaceMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$();\n");
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$Map();\n");
+ "${$get$capitalized_name$Map$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$OrDefault(\n"
+ "$value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$OrThrow(\n"
+ "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
@@ -349,23 +363,27 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return $name$_;\n"
"}\n");
GenerateMapGetters(printer);
- printer->Print(variables_,
- "$deprecation$\n"
- "public Builder clear$capitalized_name$() {\n"
- " internalGetMutable$capitalized_name$().getMutableMap()\n"
- " .clear();\n"
- " return this;\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$\n"
+ "public Builder ${$clear$capitalized_name$$}$() {\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .clear();\n"
+ " return this;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$\n"
- "public Builder remove$capitalized_name$(\n"
- " $key_type$ key) {\n"
- " $key_null_check$\n"
- " internalGetMutable$capitalized_name$().getMutableMap()\n"
- " .remove(key);\n"
- " return this;\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$\n"
+ "public Builder ${$remove$capitalized_name$$}$(\n"
+ " $key_type$ key) {\n"
+ " $key_null_check$\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .remove(key);\n"
+ " return this;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
@@ -374,13 +392,14 @@ GenerateBuilderMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "getMutable$capitalized_name$() {\n"
+ "${$getMutable$capitalized_name$$}$() {\n"
" return internalGetAdapted$capitalized_name$Map(\n"
" internalGetMutable$capitalized_name$().getMutableMap());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder put$capitalized_name$(\n"
+ "$deprecation$public Builder ${$put$capitalized_name$$}$(\n"
" $key_type$ key,\n"
" $value_enum_type$ value) {\n"
" $key_null_check$\n"
@@ -389,16 +408,18 @@ GenerateBuilderMembers(io::Printer* printer) const {
" .put(key, $name$ValueConverter.doBackward(value));\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$public Builder putAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n"
" java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n"
" internalGetAdapted$capitalized_name$Map(\n"
" internalGetMutable$capitalized_name$().getMutableMap())\n"
" .putAll(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
@@ -407,13 +428,14 @@ GenerateBuilderMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "getMutable$capitalized_name$Value() {\n"
+ "${$getMutable$capitalized_name$Value$}$() {\n"
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$public Builder put$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$put$capitalized_name$Value$}$(\n"
" $key_type$ key,\n"
" $value_type$ value) {\n"
" $key_null_check$\n"
@@ -421,15 +443,17 @@ GenerateBuilderMembers(io::Printer* printer) const {
" .put(key, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$public Builder putAll$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$putAll$capitalized_name$Value$}$(\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n"
" internalGetMutable$capitalized_name$().getMutableMap()\n"
" .putAll(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(
@@ -439,30 +463,35 @@ GenerateBuilderMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$>\n"
- "getMutable$capitalized_name$() {\n"
+ "${$getMutable$capitalized_name$$}$() {\n"
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$"
- "public Builder put$capitalized_name$(\n"
- " $key_type$ key,\n"
- " $value_type$ value) {\n"
- " $key_null_check$\n"
- " $value_null_check$\n"
- " internalGetMutable$capitalized_name$().getMutableMap()\n"
- " .put(key, value);\n"
- " return this;\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$"
+ "public Builder ${$put$capitalized_name$$}$(\n"
+ " $key_type$ key,\n"
+ " $value_type$ value) {\n"
+ " $key_null_check$\n"
+ " $value_null_check$\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .put(key, value);\n"
+ " return this;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$\n"
- "public Builder putAll$capitalized_name$(\n"
- " java.util.Map<$type_parameters$> values) {\n"
- " internalGetMutable$capitalized_name$().getMutableMap()\n"
- " .putAll(values);\n"
- " return this;\n"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$\n"
+ "public Builder ${$putAll$capitalized_name$$}$(\n"
+ " java.util.Map<$type_parameters$> values) {\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .putAll(values);\n"
+ " return this;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
@@ -471,18 +500,20 @@ GenerateMapGetters(io::Printer* printer) const {
printer->Print(
variables_,
"$deprecation$\n"
- "public int get$capitalized_name$Count() {\n"
+ "public int ${$get$capitalized_name$Count$}$() {\n"
" return internalGet$capitalized_name$().getMap().size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public boolean contains$capitalized_name$(\n"
+ "public boolean ${$contains$capitalized_name$$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" return internalGet$capitalized_name$().getMap().containsKey(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
@@ -491,22 +522,25 @@ GenerateMapGetters(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$() {\n"
+ "${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$\n"
- "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$Map() {\n"
- " return internalGetAdapted$capitalized_name$Map(\n"
- " internalGet$capitalized_name$().getMap());"
- "}\n");
+ printer->Print(
+ variables_,
+ "$deprecation$\n"
+ "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "${$get$capitalized_name$Map$}$() {\n"
+ " return internalGetAdapted$capitalized_name$Map(\n"
+ " internalGet$capitalized_name$().getMap());"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_enum_type$ get$capitalized_name$OrDefault(\n"
+ "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_enum_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -516,11 +550,12 @@ GenerateMapGetters(io::Printer* printer) const {
" ? $name$ValueConverter.doForward(map.get(key))\n"
" : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_enum_type$ get$capitalized_name$OrThrow(\n"
+ "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
@@ -530,6 +565,7 @@ GenerateMapGetters(io::Printer* printer) const {
" }\n"
" return $name$ValueConverter.doForward(map.get(key));\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
@@ -538,22 +574,24 @@ GenerateMapGetters(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "get$capitalized_name$Value() {\n"
+ "${$get$capitalized_name$Value$}$() {\n"
" return get$capitalized_name$ValueMap();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "get$capitalized_name$ValueMap() {\n"
+ "${$get$capitalized_name$ValueMap$}$() {\n"
" return internalGet$capitalized_name$().getMap();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$ValueOrDefault(\n"
+ "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -561,11 +599,12 @@ GenerateMapGetters(io::Printer* printer) const {
" internalGet$capitalized_name$().getMap();\n"
" return map.containsKey(key) ? map.get(key) : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$ValueOrThrow(\n"
+ "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
@@ -575,6 +614,7 @@ GenerateMapGetters(io::Printer* printer) const {
" }\n"
" return map.get(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(
@@ -583,21 +623,25 @@ GenerateMapGetters(io::Printer* printer) const {
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
- "public java.util.Map<$type_parameters$> get$capitalized_name$() {\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public java.util.Map<$type_parameters$> get$capitalized_name$Map() {\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$Map$}$() {\n"
" return internalGet$capitalized_name$().getMap();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$OrDefault(\n"
+ "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -605,11 +649,12 @@ GenerateMapGetters(io::Printer* printer) const {
" internalGet$capitalized_name$().getMap();\n"
" return map.containsKey(key) ? map.get(key) : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$OrThrow(\n"
+ "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$type_parameters$> map =\n"
@@ -619,6 +664,7 @@ GenerateMapGetters(io::Printer* printer) const {
" }\n"
" return map.get(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.cc b/src/google/protobuf/compiler/java/java_map_field_lite.cc
index 073d1cfc..f19ec271 100644
--- a/src/google/protobuf/compiler/java/java_map_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_map_field_lite.cc
@@ -166,12 +166,14 @@ GenerateInterfaceMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$int get$capitalized_name$Count();\n");
+ "$deprecation$int ${$get$capitalized_name$Count$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$boolean contains$capitalized_name$(\n"
+ "$deprecation$boolean ${$contains$capitalized_name$$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
@@ -180,23 +182,27 @@ GenerateInterfaceMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$();\n");
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$Map();\n");
+ "${$get$capitalized_name$Map$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$$value_enum_type$ get$capitalized_name$OrDefault(\n"
+ "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_enum_type$ defaultValue);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$$value_enum_type$ get$capitalized_name$OrThrow(\n"
+ "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
@@ -205,25 +211,29 @@ GenerateInterfaceMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$Value();\n");
+ "${$get$capitalized_name$Value$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$ValueMap();\n");
+ "${$get$capitalized_name$ValueMap$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$ValueOrDefault(\n"
+ "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$ValueOrThrow(\n"
+ "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(
@@ -233,25 +243,29 @@ GenerateInterfaceMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$();\n");
+ "${$get$capitalized_name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
- "get$capitalized_name$Map();\n");
+ "${$get$capitalized_name$Map$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$OrDefault(\n"
+ "$value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue);\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "$value_type$ get$capitalized_name$OrThrow(\n"
+ "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key);\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
@@ -288,18 +302,20 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(
variables_,
"$deprecation$\n"
- "public int get$capitalized_name$Count() {\n"
+ "public int ${$get$capitalized_name$Count$}$() {\n"
" return internalGet$capitalized_name$().size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public boolean contains$capitalized_name$(\n"
+ "public boolean ${$contains$capitalized_name$$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" return internalGet$capitalized_name$().containsKey(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
@@ -316,26 +332,28 @@ GenerateMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$() {\n"
+ "${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$Map() {\n"
+ "${$get$capitalized_name$Map$}$() {\n"
" return java.util.Collections.unmodifiableMap(\n"
" new com.google.protobuf.Internal.MapAdapter<\n"
" $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n"
" internalGet$capitalized_name$(),\n"
" $name$ValueConverter));\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_enum_type$ get$capitalized_name$OrDefault(\n"
+ "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_enum_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -345,11 +363,12 @@ GenerateMembers(io::Printer* printer) const {
" ? $name$ValueConverter.doForward(map.get(key))\n"
" : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_enum_type$ get$capitalized_name$OrThrow(\n"
+ "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
@@ -359,6 +378,7 @@ GenerateMembers(io::Printer* printer) const {
" }\n"
" return $name$ValueConverter.doForward(map.get(key));\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
@@ -367,23 +387,25 @@ GenerateMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "get$capitalized_name$Value() {\n"
+ "${$get$capitalized_name$Value$}$() {\n"
" return get$capitalized_name$ValueMap();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "get$capitalized_name$ValueMap() {\n"
+ "${$get$capitalized_name$ValueMap$}$() {\n"
" return java.util.Collections.unmodifiableMap(\n"
" internalGet$capitalized_name$());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$ValueOrDefault(\n"
+ "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -391,11 +413,12 @@ GenerateMembers(io::Printer* printer) const {
" internalGet$capitalized_name$();\n"
" return map.containsKey(key) ? map.get(key) : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$ValueOrThrow(\n"
+ "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
@@ -405,6 +428,7 @@ GenerateMembers(io::Printer* printer) const {
" }\n"
" return map.get(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(
@@ -413,22 +437,26 @@ GenerateMembers(io::Printer* printer) const {
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
- "public java.util.Map<$type_parameters$> get$capitalized_name$() {\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public java.util.Map<$type_parameters$> get$capitalized_name$Map() {\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$Map$}$() {\n"
" return java.util.Collections.unmodifiableMap(\n"
" internalGet$capitalized_name$());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$OrDefault(\n"
+ "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -436,11 +464,12 @@ GenerateMembers(io::Printer* printer) const {
" internalGet$capitalized_name$();\n"
" return map.containsKey(key) ? map.get(key) : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$OrThrow(\n"
+ "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$type_parameters$> map =\n"
@@ -450,6 +479,7 @@ GenerateMembers(io::Printer* printer) const {
" }\n"
" return map.get(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
// Generate private setters for the builder to proxy into.
@@ -490,37 +520,41 @@ GenerateBuilderMembers(io::Printer* printer) const {
printer->Print(
variables_,
"$deprecation$\n"
- "public int get$capitalized_name$Count() {\n"
+ "public int ${$get$capitalized_name$Count$}$() {\n"
" return instance.get$capitalized_name$Map().size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public boolean contains$capitalized_name$(\n"
+ "public boolean ${$contains$capitalized_name$$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" return instance.get$capitalized_name$Map().containsKey(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public Builder clear$capitalized_name$() {\n"
+ "public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.getMutable$capitalized_name$Map().clear();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public Builder remove$capitalized_name$(\n"
+ "public Builder ${$remove$capitalized_name$$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" copyOnWrite();\n"
" instance.getMutable$capitalized_name$Map().remove(key);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
@@ -529,23 +563,25 @@ GenerateBuilderMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$() {\n"
+ "${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$Map() {\n"
+ "${$get$capitalized_name$Map$}$() {\n"
" return java.util.Collections.unmodifiableMap(\n"
" instance.get$capitalized_name$Map());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_enum_type$ get$capitalized_name$OrDefault(\n"
+ "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_enum_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -555,11 +591,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
" ? map.get(key)\n"
" : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_enum_type$ get$capitalized_name$OrThrow(\n"
+ "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $value_enum_type$> map =\n"
@@ -569,10 +606,11 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return map.get(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$public Builder put$capitalized_name$(\n"
+ "$deprecation$public Builder ${$put$capitalized_name$$}$(\n"
" $key_type$ key,\n"
" $value_enum_type$ value) {\n"
" $key_null_check$\n"
@@ -581,15 +619,17 @@ GenerateBuilderMembers(io::Printer* printer) const {
" instance.getMutable$capitalized_name$Map().put(key, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$public Builder putAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n"
" java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n"
" copyOnWrite();\n"
" instance.getMutable$capitalized_name$Map().putAll(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
@@ -598,23 +638,25 @@ GenerateBuilderMembers(io::Printer* printer) const {
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "get$capitalized_name$Value() {\n"
+ "${$get$capitalized_name$Value$}$() {\n"
" return get$capitalized_name$ValueMap();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
- "get$capitalized_name$ValueMap() {\n"
+ "${$get$capitalized_name$ValueMap$}$() {\n"
" return java.util.Collections.unmodifiableMap(\n"
" instance.get$capitalized_name$ValueMap());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$ValueOrDefault(\n"
+ "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -622,11 +664,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
" instance.get$capitalized_name$ValueMap();\n"
" return map.containsKey(key) ? map.get(key) : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$ValueOrThrow(\n"
+ "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n"
@@ -636,10 +679,11 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return map.get(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$public Builder put$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$put$capitalized_name$Value$}$(\n"
" $key_type$ key,\n"
" $value_type$ value) {\n"
" $key_null_check$\n"
@@ -647,15 +691,17 @@ GenerateBuilderMembers(io::Printer* printer) const {
" instance.getMutable$capitalized_name$ValueMap().put(key, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- "$deprecation$public Builder putAll$capitalized_name$Value(\n"
+ "$deprecation$public Builder ${$putAll$capitalized_name$Value$}$(\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n"
" copyOnWrite();\n"
" instance.getMutable$capitalized_name$ValueMap().putAll(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(
@@ -664,22 +710,26 @@ GenerateBuilderMembers(io::Printer* printer) const {
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
- "public java.util.Map<$type_parameters$> get$capitalized_name$() {\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$"
- "public java.util.Map<$type_parameters$> get$capitalized_name$Map() {\n"
+ "public java.util.Map<$type_parameters$> "
+ "${$get$capitalized_name$Map$}$() {\n"
" return java.util.Collections.unmodifiableMap(\n"
" instance.get$capitalized_name$Map());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$OrDefault(\n"
+ "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n"
" $key_type$ key,\n"
" $value_type$ defaultValue) {\n"
" $key_null_check$\n"
@@ -687,11 +737,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
" instance.get$capitalized_name$Map();\n"
" return map.containsKey(key) ? map.get(key) : defaultValue;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$\n"
- "public $value_type$ get$capitalized_name$OrThrow(\n"
+ "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n"
" $key_type$ key) {\n"
" $key_null_check$\n"
" java.util.Map<$type_parameters$> map =\n"
@@ -701,11 +752,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return map.get(key);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$"
- "public Builder put$capitalized_name$(\n"
+ "public Builder ${$put$capitalized_name$$}$(\n"
" $key_type$ key,\n"
" $value_type$ value) {\n"
" $key_null_check$\n"
@@ -714,16 +766,18 @@ GenerateBuilderMembers(io::Printer* printer) const {
" instance.getMutable$capitalized_name$Map().put(key, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$"
- "public Builder putAll$capitalized_name$(\n"
+ "public Builder ${$putAll$capitalized_name$$}$(\n"
" java.util.Map<$type_parameters$> values) {\n"
" copyOnWrite();\n"
" instance.getMutable$capitalized_name$Map().putAll(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc
index 6e3b4a75..ecc67575 100644
--- a/src/google/protobuf/compiler/java/java_message.cc
+++ b/src/google/protobuf/compiler/java/java_message.cc
@@ -56,8 +56,9 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/wire_format.h>
-#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+#include <google/protobuf/stubs/strutil.h>
+
namespace google {
namespace protobuf {
@@ -253,7 +254,7 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
- "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessage$ver$.\n"
" ExtendableMessageOrBuilder<$classname$> {\n",
@@ -261,19 +262,19 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
- "idend", "", "ver", GeneratedCodeVersionSuffix());
+ "{", "", "}", "", "ver", GeneratedCodeVersionSuffix());
} else {
printer->Print(
- "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.MessageOrBuilder {\n",
"deprecation", descriptor_->options().deprecated() ?
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
- "idend", "");
+ "{", "", "}", "");
}
- printer->Annotate("classname", "idend", descriptor_);
+ printer->Annotate("{", "}", descriptor_);
printer->Indent();
for (int i = 0; i < descriptor_->field_count(); i++) {
@@ -345,6 +346,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"com.google.protobuf.GeneratedMessage$0.Builder<?>",
GeneratedCodeVersionSuffix());
}
+ printer->Print(
+ "private static final long serialVersionUID = 0L;\n");
+
printer->Indent();
// Using builder_type, instead of Builder, prevents the Builder class from
// being loaded into PermGen space when the default instance is created.
@@ -370,15 +374,8 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
printer->Print(
"@java.lang.Override\n"
"public final com.google.protobuf.UnknownFieldSet\n"
- "getUnknownFields() {\n");
- if (PreserveUnknownFields(descriptor_)) {
- printer->Print(
- " return this.unknownFields;\n");
- } else {
- printer->Print(
- " return com.google.protobuf.UnknownFieldSet.getDefaultInstance();\n");
- }
- printer->Print(
+ "getUnknownFields() {\n"
+ " return this.unknownFields;\n"
"}\n");
if (context_->HasGeneratedMethods(descriptor_)) {
@@ -623,14 +620,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
}
}
- if (PreserveUnknownFields(descriptor_)) {
- if (descriptor_->options().message_set_wire_format()) {
- printer->Print(
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
"unknownFields.writeAsMessageSetTo(output);\n");
- } else {
- printer->Print(
+ } else {
+ printer->Print(
"unknownFields.writeTo(output);\n");
- }
}
printer->Outdent();
@@ -658,14 +653,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
}
}
- if (PreserveUnknownFields(descriptor_)) {
- if (descriptor_->options().message_set_wire_format()) {
- printer->Print(
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
"size += unknownFields.getSerializedSizeAsMessageSet();\n");
- } else {
- printer->Print(
+ } else {
+ printer->Print(
"size += unknownFields.getSerializedSize();\n");
- }
}
printer->Outdent();
@@ -674,9 +667,6 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
" return size;\n"
"}\n"
"\n");
-
- printer->Print(
- "private static final long serialVersionUID = 0L;\n");
}
void ImmutableMessageGenerator::
@@ -1078,13 +1068,11 @@ GenerateEqualsAndHashCode(io::Printer* printer) {
printer->Print("}\n");
}
- if (PreserveUnknownFields(descriptor_)) {
- // Always consider unknown fields for equality. This will sometimes return
- // false for non-canonical ordering when running in LITE_RUNTIME but it's
- // the best we can do.
- printer->Print(
+ // Always consider unknown fields for equality. This will sometimes return
+ // false for non-canonical ordering when running in LITE_RUNTIME but it's
+ // the best we can do.
+ printer->Print(
"result = result && unknownFields.equals(other.unknownFields);\n");
- }
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"result = result &&\n"
@@ -1226,11 +1214,9 @@ GenerateParsingConstructor(io::Printer* printer) {
"bit_field_name", GetBitFieldName(i));
}
- if (PreserveUnknownFields(descriptor_)) {
- printer->Print(
+ printer->Print(
"com.google.protobuf.UnknownFieldSet.Builder unknownFields =\n"
" com.google.protobuf.UnknownFieldSet.newBuilder();\n");
- }
printer->Print(
"try {\n");
@@ -1247,28 +1233,19 @@ GenerateParsingConstructor(io::Printer* printer) {
printer->Indent();
printer->Print(
- "case 0:\n" // zero signals EOF / limit reached
+ "case 0:\n" // zero signals EOF / limit reached
" done = true;\n"
- " break;\n");
-
- if (PreserveUnknownFields(descriptor_)) {
- printer->Print(
- "default: {\n"
- " if (!parseUnknownField(input, unknownFields,\n"
- " extensionRegistry, tag)) {\n"
- " done = true;\n" // it's an endgroup tag
- " }\n"
- " break;\n"
- "}\n");
- } else {
- printer->Print(
- "default: {\n"
- " if (!input.skipField(tag)) {\n"
- " done = true;\n" // it's an endgroup tag
- " }\n"
- " break;\n"
- "}\n");
- }
+ " break;\n"
+ "default: {\n"
+ " if (!parseUnknownField$suffix$(\n"
+ " input, unknownFields, extensionRegistry, tag)) {\n"
+ " done = true;\n" // it's an endgroup tag
+ " }\n"
+ " break;\n"
+ "}\n",
+ "suffix",
+ descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? "Proto3"
+ : "");
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = sorted_fields[i];
@@ -1328,10 +1305,8 @@ GenerateParsingConstructor(io::Printer* printer) {
field_generators_.get(field).GenerateParsingDoneCode(printer);
}
- if (PreserveUnknownFields(descriptor_)) {
- // Make unknown fields immutable.
- printer->Print("this.unknownFields = unknownFields.build();\n");
- }
+ // Make unknown fields immutable.
+ printer->Print("this.unknownFields = unknownFields.build();\n");
// Make extensions immutable.
printer->Print(
diff --git a/src/google/protobuf/compiler/java/java_message_builder.cc b/src/google/protobuf/compiler/java/java_message_builder.cc
index 56017171..f9bbfbf4 100644
--- a/src/google/protobuf/compiler/java/java_message_builder.cc
+++ b/src/google/protobuf/compiler/java/java_message_builder.cc
@@ -54,8 +54,9 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/wire_format.h>
-#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+#include <google/protobuf/stubs/strutil.h>
+
namespace google {
namespace protobuf {
@@ -171,36 +172,25 @@ Generate(io::Printer* printer) {
.GenerateBuilderMembers(printer);
}
- if (!PreserveUnknownFields(descriptor_)) {
- printer->Print(
- "public final Builder setUnknownFields(\n"
- " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
- " return this;\n"
- "}\n"
- "\n"
- "public final Builder mergeUnknownFields(\n"
- " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
- " return this;\n"
- "}\n"
- "\n");
- } else {
+ bool is_proto3 =
+ descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
- printer->Print(
- "public final Builder setUnknownFields(\n"
- " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
- " return super.setUnknownFields(unknownFields);\n"
- "}\n"
- "\n"
- "public final Builder mergeUnknownFields(\n"
- " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
- " return super.mergeUnknownFields(unknownFields);\n"
- "}\n"
- "\n");
- }
+ printer->Print(
+ "public final Builder setUnknownFields(\n"
+ " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
+ " return super.setUnknownFields$suffix$(unknownFields);\n"
+ "}\n"
+ "\n"
+ "public final Builder mergeUnknownFields(\n"
+ " final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
+ " return super.mergeUnknownFields(unknownFields);\n"
+ "}\n"
+ "\n",
+ "suffix", is_proto3 ? "Proto3" : "");
printer->Print(
"\n"
@@ -594,10 +584,8 @@ GenerateCommonBuilderMethods(io::Printer* printer) {
" this.mergeExtensionFields(other);\n");
}
- if (PreserveUnknownFields(descriptor_)) {
- printer->Print(
- " this.mergeUnknownFields(other.unknownFields);\n");
- }
+ printer->Print(
+ " this.mergeUnknownFields(other.unknownFields);\n");
printer->Print(
" onChanged();\n");
diff --git a/src/google/protobuf/compiler/java/java_message_field.cc b/src/google/protobuf/compiler/java/java_message_field.cc
index ae84db1c..baa7f872 100644
--- a/src/google/protobuf/compiler/java/java_message_field.cc
+++ b/src/google/protobuf/compiler/java/java_message_field.cc
@@ -150,12 +150,9 @@ GenerateInterfaceMembers(io::Printer* printer) const {
// interface so that builders can choose dynamically to either return a
// message or a nested builder, so that asking for the interface doesn't
// cause a message to ever be built.
- if (SupportFieldPresence(descriptor_->file()) ||
- descriptor_->containing_oneof() == NULL) {
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$boolean has$capitalized_name$();\n");
- }
+ WriteFieldDocComment(printer, descriptor_);
+ printer->Print(variables_,
+ "$deprecation$boolean has$capitalized_name$();\n");
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$$type$ get$capitalized_name$();\n");
@@ -174,39 +171,45 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public $type$OrBuilder "
- "get$capitalized_name$OrBuilder() {\n"
+ "${$get$capitalized_name$OrBuilder$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
} else {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $name$_ != null;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public $type$OrBuilder "
- "get$capitalized_name$OrBuilder() {\n"
+ "${$get$capitalized_name$OrBuilder$}$() {\n"
" return get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
}
@@ -232,6 +235,7 @@ void ImmutableMessageFieldGenerator::PrintNestedBuilderFunction(
const char* nested_builder_case,
const char* trailing_code) const {
printer->Print(variables_, method_prototype);
+ printer->Annotate("{", "}", descriptor_);
printer->Print(" {\n");
printer->Indent();
PrintNestedBuilderCondition(printer, regular_case, nested_builder_case);
@@ -267,20 +271,22 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
if (support_field_presence) {
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_builder$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
} else {
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $name$Builder_ != null || $name$_ != null;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
// Field getField()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public $type$ get$capitalized_name$()",
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$()",
"return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n",
"return $name$Builder_.getMessage();\n",
NULL);
@@ -288,7 +294,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder setField(Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder set$capitalized_name$($type$ value)",
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value)",
"if (value == null) {\n"
" throw new NullPointerException();\n"
@@ -304,7 +310,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder setField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" $type$.Builder builderForValue)",
"$name$_ = builderForValue.build();\n"
@@ -318,7 +324,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder mergeField(Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder merge$capitalized_name$($type$ value)",
+ "$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)",
support_field_presence
? "if ($get_has_field_bit_builder$ &&\n"
@@ -346,7 +352,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder clearField()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder clear$capitalized_name$()",
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$()",
"$name$_ = null;\n"
"$on_changed$\n",
@@ -361,14 +367,17 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$.Builder get$capitalized_name$Builder() {\n"
+ "$deprecation$public $type$.Builder "
+ "${$get$capitalized_name$Builder$}$() {\n"
" $set_has_field_bit_builder$\n"
" $on_changed$\n"
" return get$capitalized_name$FieldBuilder().getBuilder();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder() {\n"
+ "$deprecation$public $type$OrBuilder "
+ "${$get$capitalized_name$OrBuilder$}$() {\n"
" if ($name$Builder_ != null) {\n"
" return $name$Builder_.getMessageOrBuilder();\n"
" } else {\n"
@@ -376,6 +385,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $type$.getDefaultInstance() : $name$_;\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"private com.google.protobuf.SingleFieldBuilder$ver$<\n"
@@ -530,30 +540,32 @@ ImmutableMessageOneofFieldGenerator::
void ImmutableMessageOneofFieldGenerator::
GenerateMembers(io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- if (SupportFieldPresence(descriptor_->file())) {
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
- " return $has_oneof_case_message$;\n"
- "}\n");
- }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
+ " return $has_oneof_case_message$;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ WriteFieldDocComment(printer, descriptor_);
+ printer->Print(variables_,
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return ($type$) $oneof_name$_;\n"
" }\n"
" return $type$.getDefaultInstance();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder() {\n"
+ "$deprecation$public $type$OrBuilder "
+ "${$get$capitalized_name$OrBuilder$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return ($type$) $oneof_name$_;\n"
" }\n"
" return $type$.getDefaultInstance();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableMessageOneofFieldGenerator::
@@ -571,19 +583,18 @@ GenerateBuilderMembers(io::Printer* printer) const {
// The comments above the methods below are based on a hypothetical
// field of type "Field" called "Field".
- if (SupportFieldPresence(descriptor_->file())) {
- // boolean hasField()
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
- " return $has_oneof_case_message$;\n"
- "}\n");
- }
+ // boolean hasField()
+ WriteFieldDocComment(printer, descriptor_);
+ printer->Print(variables_,
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
+ " return $has_oneof_case_message$;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field getField()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public $type$ get$capitalized_name$()",
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$()",
"if ($has_oneof_case_message$) {\n"
" return ($type$) $oneof_name$_;\n"
@@ -600,7 +611,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder setField(Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder set$capitalized_name$($type$ value)",
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value)",
"if (value == null) {\n"
" throw new NullPointerException();\n"
@@ -616,7 +627,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder setField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" $type$.Builder builderForValue)",
"$oneof_name$_ = builderForValue.build();\n"
@@ -630,7 +641,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder mergeField(Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder merge$capitalized_name$($type$ value)",
+ "$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)",
"if ($has_oneof_case_message$ &&\n"
" $oneof_name$_ != $type$.getDefaultInstance()) {\n"
@@ -652,7 +663,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field.Builder clearField()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder clear$capitalized_name$()",
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$()",
"if ($has_oneof_case_message$) {\n"
" $clear_oneof_case_message$;\n"
@@ -670,12 +681,15 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$.Builder get$capitalized_name$Builder() {\n"
+ "$deprecation$public $type$.Builder "
+ "${$get$capitalized_name$Builder$}$() {\n"
" return get$capitalized_name$FieldBuilder().getBuilder();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder() {\n"
+ "$deprecation$public $type$OrBuilder "
+ "${$get$capitalized_name$OrBuilder$}$() {\n"
" if (($has_oneof_case_message$) && ($name$Builder_ != null)) {\n"
" return $name$Builder_.getMessageOrBuilder();\n"
" } else {\n"
@@ -685,11 +699,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return $type$.getDefaultInstance();\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"private com.google.protobuf.SingleFieldBuilder$ver$<\n"
" $type$, $type$.Builder, $type$OrBuilder> \n"
- " get$capitalized_name$FieldBuilder() {\n"
+ " ${$get$capitalized_name$FieldBuilder$}$() {\n"
" if ($name$Builder_ == null) {\n"
" if (!($has_oneof_case_message$)) {\n"
" $oneof_name$_ = $type$.getDefaultInstance();\n"
@@ -705,6 +720,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$;\n"
" return $name$Builder_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableMessageOneofFieldGenerator::
@@ -833,31 +849,38 @@ GenerateMembers(io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$() {\n"
" return $name$_;\n" // note: unmodifiable list
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<? extends $type$OrBuilder> \n"
- " get$capitalized_name$OrBuilderList() {\n"
+ " ${$get$capitalized_name$OrBuilderList$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder(\n"
+ "$deprecation$public $type$OrBuilder "
+ "${$get$capitalized_name$OrBuilder$}$(\n"
" int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
@@ -883,6 +906,7 @@ void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderFunction(
const char* nested_builder_case,
const char* trailing_code) const {
printer->Print(variables_, method_prototype);
+ printer->Annotate("{", "}", descriptor_);
printer->Print(" {\n");
printer->Indent();
PrintNestedBuilderCondition(printer, regular_case, nested_builder_case);
@@ -934,7 +958,8 @@ GenerateBuilderMembers(io::Printer* printer) const {
// List<Field> getRepeatedFieldList()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List()",
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$()",
"return java.util.Collections.unmodifiableList($name$_);\n",
"return $name$Builder_.getMessageList();\n",
@@ -944,7 +969,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// int getRepeatedFieldCount()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public int get$capitalized_name$Count()",
+ "$deprecation$public int ${$get$capitalized_name$Count$}$()",
"return $name$_.size();\n",
"return $name$Builder_.getCount();\n",
@@ -954,7 +979,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Field getRepeatedField(int index)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public $type$ get$capitalized_name$(int index)",
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index)",
"return $name$_.get(index);\n",
@@ -965,7 +990,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder setRepeatedField(int index, Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$ value)",
"if (value == null) {\n"
" throw new NullPointerException();\n"
@@ -979,7 +1004,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder setRepeatedField(int index, Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$.Builder builderForValue)",
"ensure$capitalized_name$IsMutable();\n"
@@ -993,7 +1018,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder addRepeatedField(Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder add$capitalized_name$($type$ value)",
+ "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value)",
"if (value == null) {\n"
" throw new NullPointerException();\n"
@@ -1010,7 +1035,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder addRepeatedField(int index, Field value)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" int index, $type$ value)",
"if (value == null) {\n"
@@ -1027,7 +1052,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder addRepeatedField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" $type$.Builder builderForValue)",
"ensure$capitalized_name$IsMutable();\n"
@@ -1041,7 +1066,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder addRepeatedField(int index, Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" int index, $type$.Builder builderForValue)",
"ensure$capitalized_name$IsMutable();\n"
@@ -1055,7 +1080,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder addAllRepeatedField(Iterable<Field> values)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<? extends $type$> values)",
"ensure$capitalized_name$IsMutable();\n"
@@ -1070,7 +1095,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder clearAllRepeatedField()
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder clear$capitalized_name$()",
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$()",
"$name$_ = java.util.Collections.emptyList();\n"
"$clear_mutable_bit_builder$;\n"
@@ -1083,7 +1108,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
// Builder removeRepeatedField(int index)
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(printer,
- "$deprecation$public Builder remove$capitalized_name$(int index)",
+ "$deprecation$public Builder ${$remove$capitalized_name$$}$(int index)",
"ensure$capitalized_name$IsMutable();\n"
"$name$_.remove(index);\n"
@@ -1095,14 +1120,16 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$.Builder get$capitalized_name$Builder(\n"
+ "$deprecation$public $type$.Builder ${$get$capitalized_name$Builder$}$(\n"
" int index) {\n"
" return get$capitalized_name$FieldBuilder().getBuilder(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder(\n"
+ "$deprecation$public $type$OrBuilder "
+ "${$get$capitalized_name$OrBuilder$}$(\n"
" int index) {\n"
" if ($name$Builder_ == null) {\n"
" return $name$_.get(index);"
@@ -1110,35 +1137,40 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return $name$Builder_.getMessageOrBuilder(index);\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<? extends $type$OrBuilder> \n"
- " get$capitalized_name$OrBuilderList() {\n"
+ " ${$get$capitalized_name$OrBuilderList$}$() {\n"
" if ($name$Builder_ != null) {\n"
" return $name$Builder_.getMessageOrBuilderList();\n"
" } else {\n"
" return java.util.Collections.unmodifiableList($name$_);\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$.Builder add$capitalized_name$Builder() {\n"
+ "$deprecation$public $type$.Builder "
+ "${$add$capitalized_name$Builder$}$() {\n"
" return get$capitalized_name$FieldBuilder().addBuilder(\n"
" $type$.getDefaultInstance());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$.Builder add$capitalized_name$Builder(\n"
+ "$deprecation$public $type$.Builder ${$add$capitalized_name$Builder$}$(\n"
" int index) {\n"
" return get$capitalized_name$FieldBuilder().addBuilder(\n"
" index, $type$.getDefaultInstance());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<$type$.Builder> \n"
- " get$capitalized_name$BuilderList() {\n"
+ " ${$get$capitalized_name$BuilderList$}$() {\n"
" return get$capitalized_name$FieldBuilder().getBuilderList();\n"
"}\n"
"private com.google.protobuf.RepeatedFieldBuilder$ver$<\n"
@@ -1155,6 +1187,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return $name$Builder_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutableMessageFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.cc b/src/google/protobuf/compiler/java/java_message_field_lite.cc
index c71e9101..df3e80d4 100644
--- a/src/google/protobuf/compiler/java/java_message_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_message_field_lite.cc
@@ -129,16 +129,9 @@ int ImmutableMessageFieldLiteGenerator::GetNumBitsForBuilder() const {
void ImmutableMessageFieldLiteGenerator::
GenerateInterfaceMembers(io::Printer* printer) const {
- // TODO(jonp): In the future, consider having a method specific to the
- // interface so that builders can choose dynamically to either return a
- // message or a nested builder, so that asking for the interface doesn't
- // cause a message to ever be built.
- if (SupportFieldPresence(descriptor_->file()) ||
- descriptor_->containing_oneof() == NULL) {
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$boolean has$capitalized_name$();\n");
- }
+ WriteFieldDocComment(printer, descriptor_);
+ printer->Print(variables_,
+ "$deprecation$boolean has$capitalized_name$();\n");
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$$type$ get$capitalized_name$();\n");
@@ -154,25 +147,29 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
} else {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $name$_ != null;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
// Field.Builder setField(Field value)
@@ -226,53 +223,60 @@ GenerateBuilderMembers(io::Printer* printer) const {
// boolean hasField()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return instance.has$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field getField()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder setField(Field value)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
" }\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder setField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" $type$.Builder builderForValue) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(builderForValue);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder mergeField(Field value)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder merge$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder "
+ "${$merge$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.merge$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder clearField()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableMessageFieldLiteGenerator::
@@ -390,21 +394,21 @@ ImmutableMessageOneofFieldLiteGenerator::
void ImmutableMessageOneofFieldLiteGenerator::
GenerateMembers(io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
- if (SupportFieldPresence(descriptor_->file())) {
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
- " return $has_oneof_case_message$;\n"
- "}\n");
- }
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
+ " return $has_oneof_case_message$;\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
+ WriteFieldDocComment(printer, descriptor_);
+ printer->Print(variables_,
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return ($type$) $oneof_name$_;\n"
" }\n"
" return $type$.getDefaultInstance();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder setField(Field value)
WriteFieldDocComment(printer, descriptor_);
@@ -457,58 +461,63 @@ GenerateBuilderMembers(io::Printer* printer) const {
// The comments above the methods below are based on a hypothetical
// field of type "Field" called "Field".
- if (SupportFieldPresence(descriptor_->file())) {
- // boolean hasField()
- WriteFieldDocComment(printer, descriptor_);
- printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
- " return instance.has$capitalized_name$();\n"
- "}\n");
- }
+ // boolean hasField()
+ WriteFieldDocComment(printer, descriptor_);
+ printer->Print(variables_,
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
+ " return instance.has$capitalized_name$();\n"
+ "}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field getField()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder setField(Field value)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder setField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" $type$.Builder builderForValue) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(builderForValue);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder mergeField(Field value)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder merge$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder "
+ "${$merge$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.merge$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Field.Builder clearField()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableMessageOneofFieldLiteGenerator::
@@ -615,31 +624,38 @@ GenerateMembers(io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$() {\n"
" return $name$_;\n" // note: unmodifiable list
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<? extends $type$OrBuilder> \n"
- " get$capitalized_name$OrBuilderList() {\n"
+ " ${$get$capitalized_name$OrBuilderList$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder(\n"
+ "$deprecation$public $type$OrBuilder "
+ "${$get$capitalized_name$OrBuilder$}$(\n"
" int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
printer->Print(variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
@@ -745,110 +761,123 @@ GenerateBuilderMembers(io::Printer* printer) const {
// List<Field> getRepeatedFieldList()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<$type$> "
+ "${$get$capitalized_name$List$}$() {\n"
" return java.util.Collections.unmodifiableList(\n"
" instance.get$capitalized_name$List());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// int getRepeatedFieldCount()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return instance.get$capitalized_name$Count();\n"
"}");
+ printer->Annotate("{", "}", descriptor_);
// Field getRepeatedField(int index)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return instance.get$capitalized_name$(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder setRepeatedField(int index, Field value)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(index, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder setRepeatedField(int index, Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$.Builder builderForValue) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(index, builderForValue);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder addRepeatedField(Field value)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder addRepeatedField(int index, Field value)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" int index, $type$ value) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$(index, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder addRepeatedField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" $type$.Builder builderForValue) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$(builderForValue);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder addRepeatedField(int index, Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" int index, $type$.Builder builderForValue) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$(index, builderForValue);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder addAllRepeatedField(Iterable<Field> values)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<? extends $type$> values) {\n"
" copyOnWrite();\n"
" instance.addAll$capitalized_name$(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder clearAllRepeatedField()
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
// Builder removeRepeatedField(int index)
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder remove$capitalized_name$(int index) {\n"
+ "$deprecation$public Builder ${$remove$capitalized_name$$}$(int index) {\n"
" copyOnWrite();\n"
" instance.remove$capitalized_name$(index);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutableMessageFieldLiteGenerator::
diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc
index aad10bb1..26f16439 100644
--- a/src/google/protobuf/compiler/java/java_message_lite.cc
+++ b/src/google/protobuf/compiler/java/java_message_lite.cc
@@ -56,8 +56,9 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/wire_format.h>
-#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+#include <google/protobuf/stubs/strutil.h>
+
namespace google {
namespace protobuf {
@@ -124,7 +125,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
- "$deprecation$public interface $classname$OrBuilder$idend$ extends \n"
+ "$deprecation$public interface ${$$classname$OrBuilder$}$ extends \n"
" $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessageLite.\n"
" ExtendableMessageOrBuilder<\n"
@@ -133,19 +134,19 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
- "idend", "");
+ "{", "", "}", "");
} else {
printer->Print(
- "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.MessageLiteOrBuilder {\n",
"deprecation", descriptor_->options().deprecated() ?
"@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
- "idend", "");
+ "{", "", "}", "");
}
- printer->Annotate("classname", "idend", descriptor_);
+ printer->Annotate("{", "}", descriptor_);
printer->Indent();
for (int i = 0; i < descriptor_->field_count(); i++) {
@@ -345,15 +346,15 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
}
printer->Print(
- "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n"
- "protected final java.lang.Object dynamicMethod(\n"
- " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n"
- " java.lang.Object arg0, java.lang.Object arg1) {\n"
- " switch (method) {\n"
- " case NEW_MUTABLE_INSTANCE: {\n"
- " return new $classname$();\n"
- " }\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
+ "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n"
+ "protected final java.lang.Object dynamicMethod(\n"
+ " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n"
+ " java.lang.Object arg0, java.lang.Object arg1) {\n"
+ " switch (method) {\n"
+ " case NEW_MUTABLE_INSTANCE: {\n"
+ " return new $classname$();\n"
+ " }\n",
+ "classname", name_resolver_->GetImmutableClassName(descriptor_));
printer->Indent();
printer->Indent();
@@ -530,14 +531,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
}
}
- if (PreserveUnknownFields(descriptor_)) {
- if (descriptor_->options().message_set_wire_format()) {
- printer->Print(
- "unknownFields.writeAsMessageSetTo(output);\n");
- } else {
- printer->Print(
- "unknownFields.writeTo(output);\n");
- }
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
+ "unknownFields.writeAsMessageSetTo(output);\n");
+ } else {
+ printer->Print(
+ "unknownFields.writeTo(output);\n");
}
printer->Outdent();
@@ -565,14 +564,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
}
}
- if (PreserveUnknownFields(descriptor_)) {
- if (descriptor_->options().message_set_wire_format()) {
- printer->Print(
- "size += unknownFields.getSerializedSizeAsMessageSet();\n");
- } else {
- printer->Print(
- "size += unknownFields.getSerializedSize();\n");
- }
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
+ "size += unknownFields.getSerializedSizeAsMessageSet();\n");
+ } else {
+ printer->Print(
+ "size += unknownFields.getSerializedSize();\n");
}
printer->Outdent();
@@ -968,41 +965,31 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream(
" done = true;\n"
" break;\n");
- if (PreserveUnknownFields(descriptor_)) {
- if (descriptor_->extension_range_count() > 0) {
- if (descriptor_->options().message_set_wire_format()) {
- printer->Print(
- "default: {\n"
- " if (!parseUnknownFieldAsMessageSet(\n"
- " getDefaultInstanceForType(), input, extensionRegistry,\n"
- " tag)) {\n"
- " done = true;\n" // it's an endgroup tag
- " }\n"
- " break;\n"
- "}\n");
- } else {
- printer->Print(
- "default: {\n"
- " if (!parseUnknownField(getDefaultInstanceForType(),\n"
- " input, extensionRegistry, tag)) {\n"
- " done = true;\n" // it's an endgroup tag
- " }\n"
- " break;\n"
- "}\n");
- }
+ if (descriptor_->extension_range_count() > 0) {
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
+ "default: {\n"
+ " if (!parseUnknownFieldAsMessageSet(\n"
+ " getDefaultInstanceForType(), input, extensionRegistry,\n"
+ " tag)) {\n"
+ " done = true;\n" // it's an endgroup tag
+ " }\n"
+ " break;\n"
+ "}\n");
} else {
printer->Print(
- "default: {\n"
- " if (!parseUnknownField(tag, input)) {\n"
- " done = true;\n" // it's an endgroup tag
- " }\n"
- " break;\n"
- "}\n");
+ "default: {\n"
+ " if (!parseUnknownField(getDefaultInstanceForType(),\n"
+ " input, extensionRegistry, tag)) {\n"
+ " done = true;\n" // it's an endgroup tag
+ " }\n"
+ " break;\n"
+ "}\n");
}
} else {
printer->Print(
"default: {\n"
- " if (!input.skipField(tag)) {\n"
+ " if (!parseUnknownField(tag, input)) {\n"
" done = true;\n" // it's an endgroup tag
" }\n"
" break;\n"
diff --git a/src/google/protobuf/compiler/java/java_name_resolver.cc b/src/google/protobuf/compiler/java/java_name_resolver.cc
index bffe4f16..1673b4ee 100644
--- a/src/google/protobuf/compiler/java/java_name_resolver.cc
+++ b/src/google/protobuf/compiler/java/java_name_resolver.cc
@@ -33,6 +33,7 @@
#include <map>
#include <string>
+
#include <google/protobuf/compiler/java/java_helpers.h>
#include <google/protobuf/stubs/substitute.h>
diff --git a/src/google/protobuf/compiler/java/java_primitive_field.cc b/src/google/protobuf/compiler/java/java_primitive_field.cc
index 840252e7..074a6be8 100644
--- a/src/google/protobuf/compiler/java/java_primitive_field.cc
+++ b/src/google/protobuf/compiler/java/java_primitive_field.cc
@@ -190,16 +190,18 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutablePrimitiveFieldGenerator::
@@ -210,31 +212,35 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_builder$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
"$null_check$"
" $set_has_field_bit_builder$\n"
" $name$_ = value;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $clear_has_field_bit_builder$\n");
+ printer->Annotate("{", "}", descriptor_);
JavaType type = GetJavaType(descriptor_);
if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) {
// The default value is not a simple literal so we want to avoid executing
@@ -441,19 +447,21 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return ($boxed_type$) $oneof_name$_;\n"
" }\n"
" return $default$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
@@ -462,33 +470,36 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return ($boxed_type$) $oneof_name$_;\n"
" }\n"
" return $default$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
"$null_check$"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = value;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" $clear_oneof_case_message$;\n"
" $oneof_name$_ = null;\n"
@@ -496,6 +507,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutablePrimitiveOneofFieldGenerator::
@@ -604,19 +616,22 @@ GenerateMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<$boxed_type$>\n"
- " get$capitalized_name$List() {\n"
+ " ${$get$capitalized_name$List$}$() {\n"
" return $name$_;\n" // note: unmodifiable list
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
if (descriptor_->is_packed() &&
context_->HasGeneratedMethods(descriptor_->containing_type())) {
@@ -654,22 +669,25 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<$boxed_type$>\n"
- " get$capitalized_name$List() {\n"
+ " ${$get$capitalized_name$List$}$() {\n"
" return java.util.Collections.unmodifiableList($name$_);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$ value) {\n"
"$null_check$"
" ensure$capitalized_name$IsMutable();\n"
@@ -677,18 +695,20 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n"
"$null_check$"
" ensure$capitalized_name$IsMutable();\n"
" $name$_.add(value);\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<? extends $boxed_type$> values) {\n"
" ensure$capitalized_name$IsMutable();\n"
" com.google.protobuf.AbstractMessageLite.Builder.addAll(\n"
@@ -696,14 +716,16 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $name$_ = $empty_list$;\n"
" $clear_mutable_bit_builder$;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutablePrimitiveFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
index 0e8e492f..f9293171 100644
--- a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
@@ -222,16 +222,18 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@@ -264,32 +266,36 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return instance.has$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutablePrimitiveFieldLiteGenerator::
@@ -482,19 +488,21 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" return ($boxed_type$) $oneof_name$_;\n"
" }\n"
" return $default$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@@ -520,32 +528,36 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return instance.has$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$() {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutablePrimitiveOneofFieldLiteGenerator::
@@ -634,21 +646,24 @@ GenerateMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<$boxed_type$>\n"
- " get$capitalized_name$List() {\n"
+ " ${$get$capitalized_name$List$}$() {\n"
" return $name$_;\n" // note: unmodifiable list
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return $repeated_get$(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
- if (descriptor_->options().packed() &&
+ if (descriptor_->is_packed() &&
context_->HasGeneratedMethods(descriptor_->containing_type())) {
printer->Print(variables_,
"private int $name$MemoizedSerializedSize = -1;\n");
@@ -697,50 +712,57 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public java.util.List<$boxed_type$>\n"
- " get$capitalized_name$List() {\n"
+ " ${$get$capitalized_name$List$}$() {\n"
" return java.util.Collections.unmodifiableList(\n"
" instance.get$capitalized_name$List());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return instance.get$capitalized_name$Count();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public $type$ get$capitalized_name$(int index) {\n"
+ "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
" return instance.get$capitalized_name$(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, $type$ value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(index, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$($type$ value) {\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<? extends $boxed_type$> values) {\n"
" copyOnWrite();\n"
" instance.addAll$capitalized_name$(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutablePrimitiveFieldLiteGenerator::
@@ -829,7 +851,7 @@ GenerateParsingDoneCode(io::Printer* printer) const {
void RepeatedImmutablePrimitiveFieldLiteGenerator::
GenerateSerializationCode(io::Printer* printer) const {
- if (descriptor_->options().packed()) {
+ if (descriptor_->is_packed()) {
// We invoke getSerializedSize in writeTo for messages that have packed
// fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods.
// That makes it safe to rely on the memoized size here.
@@ -870,7 +892,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
printer->Print(
"size += dataSize;\n");
- if (descriptor_->options().packed()) {
+ if (descriptor_->is_packed()) {
printer->Print(variables_,
"if (!get$capitalized_name$List().isEmpty()) {\n"
" size += $tag_size$;\n"
@@ -883,7 +905,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
}
// cache the data size for packed fields.
- if (descriptor_->options().packed()) {
+ if (descriptor_->is_packed()) {
printer->Print(variables_,
"$name$MemoizedSerializedSize = dataSize;\n");
}
diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc
index 5c2900ce..2b6e9381 100644
--- a/src/google/protobuf/compiler/java/java_string_field.cc
+++ b/src/google/protobuf/compiler/java/java_string_field.cc
@@ -217,14 +217,15 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" java.lang.Object ref = $name$_;\n"
" if (ref instanceof java.lang.String) {\n"
" return (java.lang.String) ref;\n"
@@ -232,6 +233,7 @@ GenerateMembers(io::Printer* printer) const {
" com.google.protobuf.ByteString bs = \n"
" (com.google.protobuf.ByteString) ref;\n"
" java.lang.String s = bs.toStringUtf8();\n");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" $name$_ = s;\n");
@@ -248,7 +250,7 @@ GenerateMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" java.lang.Object ref = $name$_;\n"
" if (ref instanceof java.lang.String) {\n"
" com.google.protobuf.ByteString b = \n"
@@ -260,6 +262,7 @@ GenerateMembers(io::Printer* printer) const {
" return (com.google.protobuf.ByteString) ref;\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableStringFieldGenerator::
@@ -269,19 +272,21 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_builder$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" java.lang.Object ref = $name$_;\n"
" if (!(ref instanceof java.lang.String)) {\n"
" com.google.protobuf.ByteString bs =\n"
" (com.google.protobuf.ByteString) ref;\n"
" java.lang.String s = bs.toStringUtf8();\n");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" $name$_ = s;\n");
@@ -301,7 +306,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" java.lang.Object ref = $name$_;\n"
" if (ref instanceof String) {\n"
" com.google.protobuf.ByteString b = \n"
@@ -313,10 +318,11 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return (com.google.protobuf.ByteString) ref;\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
"$null_check$"
" $set_has_field_bit_builder$\n"
@@ -324,10 +330,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $clear_has_field_bit_builder$\n");
+ printer->Annotate("{", "}", descriptor_);
// The default value is not a simple literal so we want to avoid executing
// it multiple times. Instead, get the default out of the default instance.
printer->Print(variables_,
@@ -339,9 +347,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Bytes(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
"$null_check$");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" checkByteStringIsUtf8(value);\n");
@@ -482,14 +491,15 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" java.lang.Object ref $default_init$;\n"
" if ($has_oneof_case_message$) {\n"
" ref = $oneof_name$_;\n"
@@ -500,6 +510,7 @@ GenerateMembers(io::Printer* printer) const {
" com.google.protobuf.ByteString bs = \n"
" (com.google.protobuf.ByteString) ref;\n"
" java.lang.String s = bs.toStringUtf8();\n");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" if ($has_oneof_case_message$) {\n"
@@ -519,7 +530,7 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" java.lang.Object ref $default_init$;\n"
" if ($has_oneof_case_message$) {\n"
" ref = $oneof_name$_;\n"
@@ -536,6 +547,7 @@ GenerateMembers(io::Printer* printer) const {
" return (com.google.protobuf.ByteString) ref;\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableStringOneofFieldGenerator::
@@ -543,14 +555,15 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" java.lang.Object ref $default_init$;\n"
" if ($has_oneof_case_message$) {\n"
" ref = $oneof_name$_;\n"
@@ -560,6 +573,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" (com.google.protobuf.ByteString) ref;\n"
" java.lang.String s = bs.toStringUtf8();\n"
" if ($has_oneof_case_message$) {\n");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" $oneof_name$_ = s;\n");
@@ -580,7 +594,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" java.lang.Object ref $default_init$;\n"
" if ($has_oneof_case_message$) {\n"
" ref = $oneof_name$_;\n"
@@ -597,10 +611,11 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return (com.google.protobuf.ByteString) ref;\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
"$null_check$"
" $set_oneof_case_message$;\n"
@@ -608,9 +623,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" $clear_oneof_case_message$;\n"
" $oneof_name$_ = null;\n"
@@ -618,12 +634,14 @@ GenerateBuilderMembers(io::Printer* printer) const {
" }\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Bytes(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
"$null_check$");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" checkByteStringIsUtf8(value);\n");
@@ -744,25 +762,30 @@ GenerateMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ProtocolStringList\n"
- " get$capitalized_name$List() {\n"
+ " ${$get$capitalized_name$List$}$() {\n"
" return $name$_;\n" // note: unmodifiable list
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n"
+ "$deprecation$public java.lang.String "
+ "${$get$capitalized_name$$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes(int index) {\n"
+ " ${$get$capitalized_name$Bytes$}$(int index) {\n"
" return $name$_.getByteString(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutableStringFieldGenerator::
@@ -794,28 +817,33 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ProtocolStringList\n"
- " get$capitalized_name$List() {\n"
+ " ${$get$capitalized_name$List$}$() {\n"
" return $name$_.getUnmodifiableView();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n"
+ "$deprecation$public java.lang.String "
+ "${$get$capitalized_name$$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes(int index) {\n"
+ " ${$get$capitalized_name$Bytes$}$(int index) {\n"
" return $name$_.getByteString(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, java.lang.String value) {\n"
"$null_check$"
" ensure$capitalized_name$IsMutable();\n"
@@ -823,9 +851,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
"$null_check$"
" ensure$capitalized_name$IsMutable();\n"
@@ -833,9 +862,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<java.lang.String> values) {\n"
" ensure$capitalized_name$IsMutable();\n"
" com.google.protobuf.AbstractMessageLite.Builder.addAll(\n"
@@ -843,20 +873,23 @@ GenerateBuilderMembers(io::Printer* printer) const {
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $name$_ = $empty_list$;\n"
" $clear_mutable_bit_builder$;\n"
" $on_changed$\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$Bytes(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
"$null_check$");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" checkByteStringIsUtf8(value);\n");
diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc
index 7e3ad1d0..adda307c 100644
--- a/src/google/protobuf/compiler/java/java_string_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc
@@ -71,7 +71,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default_init"] =
"= " + ImmutableDefaultValue(descriptor, name_resolver);
- (*variables)["capitalized_type"] = "String";
+ (*variables)["capitalized_type"] = "java.lang.String";
(*variables)["tag"] =
SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
@@ -192,22 +192,25 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" return $name$_;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" return com.google.protobuf.ByteString.copyFromUtf8($name$_);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@@ -246,48 +249,54 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return instance.has$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" return instance.get$capitalized_name$Bytes();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Bytes(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$Bytes(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableStringFieldLiteGenerator::
@@ -324,7 +333,7 @@ void ImmutableStringFieldLiteGenerator::
GenerateParsingCode(io::Printer* printer) const {
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
- "String s = input.readStringRequireUtf8();\n"
+ "java.lang.String s = input.readStringRequireUtf8();\n"
"$set_has_field_bit_message$\n"
"$name$_ = s;\n");
} else {
@@ -333,7 +342,7 @@ GenerateParsingCode(io::Printer* printer) const {
// spurious intermediary ByteString allocations, cutting overall allocations
// in half.
printer->Print(variables_,
- "String s = input.readString();\n"
+ "java.lang.String s = input.readString();\n"
"$set_has_field_bit_message$\n"
"$name$_ = s;\n");
}
@@ -410,54 +419,60 @@ GenerateMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" java.lang.String ref $default_init$;\n"
" if ($has_oneof_case_message$) {\n"
" ref = (java.lang.String) $oneof_name$_;\n"
" }\n"
" return ref;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" java.lang.String ref $default_init$;\n"
" if ($has_oneof_case_message$) {\n"
" ref = (java.lang.String) $oneof_name$_;\n"
" }\n"
" return com.google.protobuf.ByteString.copyFromUtf8(ref);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "private void set$capitalized_name$(\n"
+ "private void ${$set$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
"$null_check$"
" $set_oneof_case_message$;\n"
" $oneof_name$_ = value;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "private void clear$capitalized_name$() {\n"
+ "private void ${$clear$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
" $clear_oneof_case_message$;\n"
" $oneof_name$_ = null;\n"
" }\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "private void set$capitalized_name$Bytes(\n"
+ "private void ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
"$null_check$");
+ printer->Annotate("{", "}", descriptor_);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
" checkByteStringIsUtf8(value);\n");
@@ -474,48 +489,54 @@ GenerateBuilderMembers(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public boolean has$capitalized_name$() {\n"
+ "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return instance.has$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$() {\n"
+ "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n"
" return instance.get$capitalized_name$();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes() {\n"
+ " ${$get$capitalized_name$Bytes$}$() {\n"
" return instance.get$capitalized_name$Bytes();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$Bytes(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$Bytes(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void ImmutableStringOneofFieldLiteGenerator::
@@ -529,7 +550,7 @@ void ImmutableStringOneofFieldLiteGenerator::
GenerateParsingCode(io::Printer* printer) const {
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
- "String s = input.readStringRequireUtf8();\n"
+ "java.lang.String s = input.readStringRequireUtf8();\n"
"$set_oneof_case_message$;\n"
"$oneof_name$_ = s;\n");
} else {
@@ -538,7 +559,7 @@ GenerateParsingCode(io::Printer* printer) const {
// spurious intermediary ByteString allocations, cutting overall allocations
// in half.
printer->Print(variables_,
- "String s = input.readString();\n"
+ "java.lang.String s = input.readString();\n"
"$set_oneof_case_message$;\n"
"$oneof_name$_ = s;\n");
}
@@ -597,7 +618,7 @@ void RepeatedImmutableStringFieldLiteGenerator::
GenerateInterfaceMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$java.util.List<String>\n"
+ "$deprecation$java.util.List<java.lang.String>\n"
" get$capitalized_name$List();\n");
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@@ -615,30 +636,37 @@ GenerateInterfaceMembers(io::Printer* printer) const {
void RepeatedImmutableStringFieldLiteGenerator::
GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
- "private com.google.protobuf.Internal.ProtobufList<String> $name$_;\n");
+ "private com.google.protobuf.Internal.ProtobufList<java.lang.String> "
+ "$name$_;\n");
PrintExtraFieldInfo(variables_, printer);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<String> get$capitalized_name$List() {\n"
- " return $name$_;\n" // note: unmodifiable list
+ "$deprecation$public java.util.List<java.lang.String> "
+ "${$get$capitalized_name$List$}$() {\n"
+ " return $name$_;\n" // note: unmodifiable list
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return $name$_.size();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n"
+ "$deprecation$public java.lang.String "
+ "${$get$capitalized_name$$}$(int index) {\n"
" return $name$_.get(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes(int index) {\n"
+ " ${$get$capitalized_name$Bytes$}$(int index) {\n"
" return com.google.protobuf.ByteString.copyFromUtf8(\n"
" $name$_.get(index));\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
printer->Print(variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
@@ -697,67 +725,77 @@ void RepeatedImmutableStringFieldLiteGenerator::
GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.util.List<String>\n"
- " get$capitalized_name$List() {\n"
+ "$deprecation$public java.util.List<java.lang.String>\n"
+ " ${$get$capitalized_name$List$}$() {\n"
" return java.util.Collections.unmodifiableList(\n"
" instance.get$capitalized_name$List());\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public int get$capitalized_name$Count() {\n"
+ "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
" return instance.get$capitalized_name$Count();\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n"
+ "$deprecation$public java.lang.String "
+ "${$get$capitalized_name$$}$(int index) {\n"
" return instance.get$capitalized_name$(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public com.google.protobuf.ByteString\n"
- " get$capitalized_name$Bytes(int index) {\n"
+ " ${$get$capitalized_name$Bytes$}$(int index) {\n"
" return instance.get$capitalized_name$Bytes(index);\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder set$capitalized_name$(\n"
+ "$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
" int index, java.lang.String value) {\n"
" copyOnWrite();\n"
" instance.set$capitalized_name$(index, value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$$}$(\n"
" java.lang.String value) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder addAll$capitalized_name$(\n"
+ "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n"
" java.lang.Iterable<java.lang.String> values) {\n"
" copyOnWrite();\n"
" instance.addAll$capitalized_name$(values);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder clear$capitalized_name$() {\n"
+ "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" copyOnWrite();\n"
" instance.clear$capitalized_name$();\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
- "$deprecation$public Builder add$capitalized_name$Bytes(\n"
+ "$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
" copyOnWrite();\n"
" instance.add$capitalized_name$Bytes(value);\n"
" return this;\n"
"}\n");
+ printer->Annotate("{", "}", descriptor_);
}
void RepeatedImmutableStringFieldLiteGenerator::
@@ -787,14 +825,14 @@ void RepeatedImmutableStringFieldLiteGenerator::
GenerateParsingCode(io::Printer* printer) const {
if (CheckUtf8(descriptor_)) {
printer->Print(variables_,
- "String s = input.readStringRequireUtf8();\n");
+ "java.lang.String s = input.readStringRequireUtf8();\n");
} else {
// Lite runtime should attempt to reduce allocations by attempting to
// construct the string directly from the input stream buffer. This avoids
// spurious intermediary ByteString allocations, cutting overall allocations
// in half.
printer->Print(variables_,
- "String s = input.readString();\n");
+ "java.lang.String s = input.readString();\n");
}
printer->Print(variables_,
"if (!$is_mutable$) {\n"
@@ -868,7 +906,7 @@ GenerateHashCode(io::Printer* printer) const {
}
string RepeatedImmutableStringFieldLiteGenerator::GetBoxedType() const {
- return "String";
+ return "java.lang.String";
}
} // namespace java
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index 2d86d1c8..73d32762 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -143,12 +143,16 @@ bool IsReserved(const string& ident) {
return false;
}
+bool StrEndsWith(StringPiece sp, StringPiece x) {
+ return sp.size() >= x.size() && sp.substr(sp.size() - x.size()) == x;
+}
+
// Returns a copy of |filename| with any trailing ".protodevel" or ".proto
// suffix stripped.
// TODO(haberman): Unify with copy in compiler/cpp/internal/helpers.cc.
string StripProto(const string& filename) {
- const char* suffix = HasSuffixString(filename, ".protodevel")
- ? ".protodevel" : ".proto";
+ const char* suffix =
+ StrEndsWith(filename, ".protodevel") ? ".protodevel" : ".proto";
return StripSuffixString(filename, suffix);
}
@@ -757,8 +761,22 @@ string DoubleToString(double value) {
return PostProcessFloat(result);
}
+// Return true if this is an integral field that should be represented as string
+// in JS.
+bool IsIntegralFieldWithStringJSType(const FieldDescriptor* field) {
+ switch (field->cpp_type()) {
+ case FieldDescriptor::CPPTYPE_INT64:
+ case FieldDescriptor::CPPTYPE_UINT64:
+ // The default value of JSType is JS_NORMAL, which behaves the same as
+ // JS_NUMBER.
+ return field->options().jstype() == google::protobuf::FieldOptions::JS_STRING;
+ default:
+ return false;
+ }
+}
+
string MaybeNumberString(const FieldDescriptor* field, const string& orig) {
- return orig;
+ return IsIntegralFieldWithStringJSType(field) ? ("\"" + orig + "\"") : orig;
}
string JSFieldDefault(const FieldDescriptor* field) {
@@ -857,7 +875,7 @@ string ProtoTypeName(const GeneratorOptions& options,
}
string JSIntegerTypeName(const FieldDescriptor* field) {
- return "number";
+ return IsIntegralFieldWithStringJSType(field) ? "string" : "number";
}
string JSStringTypeName(const GeneratorOptions& options,
@@ -1034,8 +1052,7 @@ string JSBinaryReaderMethodType(const FieldDescriptor* field) {
if (name[0] >= 'a' && name[0] <= 'z') {
name[0] = (name[0] - 'a') + 'A';
}
-
- return name;
+ return IsIntegralFieldWithStringJSType(field) ? (name + "String") : name;
}
string JSBinaryReadWriteMethodName(const FieldDescriptor* field,
@@ -1245,13 +1262,6 @@ string FieldComments(const FieldDescriptor* field, BytesMode bytes_mode) {
" * You should avoid comparisons like {@code val === true/false} in "
"those cases.\n";
}
- if (field->is_repeated()) {
- comments +=
- " * If you change this array by adding, removing or replacing "
- "elements, or if you\n"
- " * replace the array itself, then you must call the setter to "
- "update it.\n";
- }
if (field->type() == FieldDescriptor::TYPE_BYTES && bytes_mode == BYTES_U8) {
comments +=
" * Note that Uint8Array is not supported on all browsers.\n"
@@ -1324,7 +1334,7 @@ bool IsExtendable(const Descriptor* desc) {
// Returns the max index in the underlying data storage array beyond which the
// extension object is used.
string GetPivot(const Descriptor* desc) {
- static const int kDefaultPivot = (1 << 29); // max field number (29 bits)
+ static const int kDefaultPivot = 500;
// Find the max field number
int max_field_number = 0;
@@ -1336,7 +1346,7 @@ string GetPivot(const Descriptor* desc) {
}
int pivot = -1;
- if (IsExtendable(desc)) {
+ if (IsExtendable(desc) || (max_field_number >= kDefaultPivot)) {
pivot = ((max_field_number + 1) < kDefaultPivot) ?
(max_field_number + 1) : kDefaultPivot;
}
@@ -1508,6 +1518,10 @@ void Generator::GenerateHeader(const GeneratorOptions& options,
printer->Print("/**\n"
" * @fileoverview\n"
" * @enhanceable\n"
+ " * @suppress {messageConventions} JS Compiler reports an "
+ "error if a variable or\n"
+ " * field starts with 'MSG_' and isn't a translatable "
+ "message.\n"
" * @public\n"
" */\n"
"// GENERATED CODE -- DO NOT EDIT!\n"
@@ -1699,18 +1713,16 @@ void Generator::GenerateRequiresImpl(const GeneratorOptions& options,
bool require_jspb, bool require_extension,
bool require_map) const {
if (require_jspb) {
- printer->Print(
- "goog.require('jspb.Message');\n"
- "goog.require('jspb.BinaryReader');\n"
- "goog.require('jspb.BinaryWriter');\n");
+ required->insert("jspb.Message");
+ required->insert("jspb.BinaryReader");
+ required->insert("jspb.BinaryWriter");
}
if (require_extension) {
- printer->Print("goog.require('jspb.ExtensionFieldBinaryInfo');\n");
- printer->Print(
- "goog.require('jspb.ExtensionFieldInfo');\n");
+ required->insert("jspb.ExtensionFieldBinaryInfo");
+ required->insert("jspb.ExtensionFieldInfo");
}
if (require_map) {
- printer->Print("goog.require('jspb.Map');\n");
+ required->insert("jspb.Map");
}
std::set<string>::iterator it;
@@ -2038,6 +2050,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options,
" * http://goto/soy-param-migration\n"
" * @param {!$classname$} msg The msg instance to transform.\n"
" * @return {!Object}\n"
+ " * @suppress {unusedLocalVariables} f is only used for nested messages\n"
" */\n"
"$classname$.toObject = function(includeInstance, msg) {\n"
" var f, obj = {",
@@ -2126,7 +2139,8 @@ void Generator::GenerateFieldValueExpression(io::Printer* printer,
"obj", obj_reference);
}
} else {
- printer->Print("jspb.Message.getField($obj$, $index$)",
+ printer->Print("jspb.Message.get$cardinality$Field($obj$, $index$)",
+ "cardinality", field->is_repeated() ? "Repeated" : "",
"index", JSFieldIndex(field),
"obj", obj_reference);
}
@@ -2334,7 +2348,6 @@ void GenerateBytesWrapper(const GeneratorOptions& options,
"defname", JSGetterName(options, field, BYTES_DEFAULT));
}
-
void Generator::GenerateClassField(const GeneratorOptions& options,
io::Printer* printer,
const FieldDescriptor* field) const {
@@ -2464,7 +2477,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
// Simple (primitive) field, either singular or repeated.
// TODO(b/26173701): Always use BYTES_DEFAULT for the getter return type;
- // at this point we "lie" to non-binary users and tell the the return
+ // at this point we "lie" to non-binary users and tell the return
// type is always base64 string, pending a LSC to migrate to typed getters.
BytesMode bytes_mode =
field->type() == FieldDescriptor::TYPE_BYTES && !options.binary ?
@@ -2911,6 +2924,7 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options,
" * format), writing to the given BinaryWriter.\n"
" * @param {!$class$} message\n"
" * @param {!jspb.BinaryWriter} writer\n"
+ " * @suppress {unusedLocalVariables} f is only used for nested messages\n"
" */\n"
"$class$.serializeBinaryToWriter = function(message, "
"writer) {\n"
@@ -2983,7 +2997,13 @@ void Generator::GenerateClassSerializeBinaryField(
case FieldDescriptor::CPPTYPE_INT64:
case FieldDescriptor::CPPTYPE_UINT32:
case FieldDescriptor::CPPTYPE_UINT64: {
- {
+ if (IsIntegralFieldWithStringJSType(field)) {
+ // We can use `parseInt` here even though it will not be precise for
+ // 64-bit quantities because we are only testing for zero/nonzero,
+ // and JS numbers (64-bit floating point values, i.e., doubles) are
+ // integer-precise in the range that includes zero.
+ printer->Print(" if (parseInt(f, 10) !== 0) {\n");
+ } else {
printer->Print(" if (f !== 0) {\n");
}
break;
@@ -3307,7 +3327,8 @@ void Generator::GenerateFile(const GeneratorOptions& options,
printer->Print(
"var $alias$ = require('$file$');\n",
"alias", ModuleAlias(name),
- "file", GetRootPath(file->name(), name) + GetJSFilename(options, name));
+ "file",
+ GetRootPath(file->name(), name) + GetJSFilename(options, name));
}
}
diff --git a/src/google/protobuf/compiler/js/well_known_types/any.js b/src/google/protobuf/compiler/js/well_known_types/any.js
index 22f18919..d7ca6e3a 100644
--- a/src/google/protobuf/compiler/js/well_known_types/any.js
+++ b/src/google/protobuf/compiler/js/well_known_types/any.js
@@ -69,7 +69,7 @@ proto.google.protobuf.Any.prototype.pack = function(serialized, name,
* the binary data properly.
* @param {string} name The expected type name of this message object.
* @return {?T} If the name matched the expected name, returns the deserialized
- * object, otherwise returns undefined.
+ * object, otherwise returns null.
*/
proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) {
if (this.getTypeName() == name) {
diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc
index 8b7a6146..cc660f4a 100644
--- a/src/google/protobuf/compiler/mock_code_generator.cc
+++ b/src/google/protobuf/compiler/mock_code_generator.cc
@@ -40,6 +40,7 @@
#endif
#include <vector>
+
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/logging.h>
@@ -52,6 +53,7 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
+#include <google/protobuf/text_format.h>
#include <google/protobuf/stubs/substitute.h>
#include <gtest/gtest.h>
@@ -136,11 +138,48 @@ void MockCodeGenerator::ExpectGenerated(
}
}
+namespace {
+void CheckSingleAnnotation(const string& expected_file,
+ const string& expected_text,
+ const string& file_content,
+ const GeneratedCodeInfo::Annotation& annotation) {
+ EXPECT_EQ(expected_file, annotation.source_file());
+ ASSERT_GE(file_content.size(), annotation.begin());
+ ASSERT_GE(file_content.size(), annotation.end());
+ ASSERT_LE(annotation.begin(), annotation.end());
+ EXPECT_EQ(expected_text.size(), annotation.end() - annotation.begin());
+ EXPECT_EQ(expected_text,
+ file_content.substr(annotation.begin(), expected_text.size()));
+}
+} // anonymous namespace
+
+void MockCodeGenerator::CheckGeneratedAnnotations(
+ const string& name, const string& file, const string& output_directory) {
+ string file_content;
+ GOOGLE_CHECK_OK(
+ File::GetContents(output_directory + "/" + GetOutputFileName(name, file),
+ &file_content, true));
+ string meta_content;
+ GOOGLE_CHECK_OK(File::GetContents(
+ output_directory + "/" + GetOutputFileName(name, file) + ".meta",
+ &meta_content, true));
+ GeneratedCodeInfo annotations;
+ GOOGLE_CHECK(TextFormat::ParseFromString(meta_content, &annotations));
+ ASSERT_EQ(3, annotations.annotation_size());
+ CheckSingleAnnotation("first_annotation", "first", file_content,
+ annotations.annotation(0));
+ CheckSingleAnnotation("second_annotation", "second", file_content,
+ annotations.annotation(1));
+ CheckSingleAnnotation("third_annotation", "third", file_content,
+ annotations.annotation(2));
+}
+
bool MockCodeGenerator::Generate(
const FileDescriptor* file,
const string& parameter,
GeneratorContext* context,
string* error) const {
+ bool annotate = false;
for (int i = 0; i < file->message_type_count(); i++) {
if (HasPrefixString(file->message_type(i)->name(), "MockCodeGenerator_")) {
string command = StripPrefixString(file->message_type(i)->name(),
@@ -169,6 +208,8 @@ bool MockCodeGenerator::Generate(
std::cerr << "Saw json_name: "
<< field_descriptor_proto.has_json_name() << std::endl;
abort();
+ } else if (command == "Annotate") {
+ annotate = true;
} else if (command == "ShowVersionNumber") {
Version compiler_version;
context->GetCompilerVersion(&compiler_version);
@@ -219,16 +260,40 @@ bool MockCodeGenerator::Generate(
google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output(
context->Open(GetOutputFileName(name_, file)));
- io::Printer printer(output.get(), '$');
- printer.PrintRaw(GetOutputFileContent(name_, parameter,
- file, context));
+ GeneratedCodeInfo annotations;
+ io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector(
+ &annotations);
+ io::Printer printer(output.get(), '$',
+ annotate ? &annotation_collector : NULL);
+ printer.PrintRaw(GetOutputFileContent(name_, parameter, file, context));
+ string annotate_suffix = "_annotation";
+ if (annotate) {
+ printer.Print("$p$", "p", "first");
+ printer.Annotate("p", "first" + annotate_suffix);
+ }
printer.PrintRaw(kFirstInsertionPoint);
+ if (annotate) {
+ printer.Print("$p$", "p", "second");
+ printer.Annotate("p", "second" + annotate_suffix);
+ }
printer.PrintRaw(kSecondInsertionPoint);
+ if (annotate) {
+ printer.Print("$p$", "p", "third");
+ printer.Annotate("p", "third" + annotate_suffix);
+ }
if (printer.failed()) {
*error = "MockCodeGenerator detected write error.";
return false;
}
+ if (annotate) {
+ google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> meta_output(
+ context->Open(GetOutputFileName(name_, file) + ".meta"));
+ if (!TextFormat::Print(annotations, meta_output.get())) {
+ *error = "MockCodeGenerator couldn't write .meta";
+ return false;
+ }
+ }
}
return true;
diff --git a/src/google/protobuf/compiler/mock_code_generator.h b/src/google/protobuf/compiler/mock_code_generator.h
index e1665f88..cdd9138c 100644
--- a/src/google/protobuf/compiler/mock_code_generator.h
+++ b/src/google/protobuf/compiler/mock_code_generator.h
@@ -68,6 +68,8 @@ namespace compiler {
// printing "Saw message type MockCodeGenerator_HasSourceCodeInfo: FOO." to
// stderr, where FOO is "1" if the supplied FileDescriptorProto has source
// code info, and "0" otherwise.
+// MockCodeGenerator_Annotate: Generate() will add annotations to its output
+// that can later be verified with CheckGeneratedAnnotations.
class MockCodeGenerator : public CodeGenerator {
public:
MockCodeGenerator(const string& name);
@@ -88,6 +90,12 @@ class MockCodeGenerator : public CodeGenerator {
const string& parsed_file_list,
const 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);
+
// Get the name of the file which would be written by the given generator.
static string GetOutputFileName(const string& generator_name,
const FileDescriptor* file);
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
index 72b5d5f5..54dc7455 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
@@ -50,7 +50,7 @@
#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/strutil.h>
-#if defined(_WIN32)
+#if defined(_MSC_VER)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::open;
diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc
index 1a409566..bb4a44c3 100644
--- a/src/google/protobuf/compiler/parser.cc
+++ b/src/google/protobuf/compiler/parser.cc
@@ -664,7 +664,7 @@ bool Parser::ParseMessageDefinition(
namespace {
-const int kMaxExtensionRangeSentinel = -1;
+const int kMaxRangeSentinel = -1;
bool IsMessageSetWireFormatMessage(const DescriptorProto& message) {
const MessageOptions& options = message.options();
@@ -688,12 +688,27 @@ void AdjustExtensionRangesWithMaxEndNumber(DescriptorProto* message) {
kint32max :
FieldDescriptor::kMaxNumber + 1;
for (int i = 0; i < message->extension_range_size(); ++i) {
- if (message->extension_range(i).end() == kMaxExtensionRangeSentinel) {
+ if (message->extension_range(i).end() == kMaxRangeSentinel) {
message->mutable_extension_range(i)->set_end(max_extension_number);
}
}
}
+// Modifies any reserved ranges that specified 'max' as the end of the
+// reserved range, and sets them to the type-specific maximum. The actual max
+// tag number can only be determined after all options have been parsed.
+void AdjustReservedRangesWithMaxEndNumber(DescriptorProto* message) {
+ const bool is_message_set = IsMessageSetWireFormatMessage(*message);
+ const int max_field_number = is_message_set ?
+ kint32max :
+ FieldDescriptor::kMaxNumber + 1;
+ for (int i = 0; i < message->reserved_range_size(); ++i) {
+ if (message->reserved_range(i).end() == kMaxRangeSentinel) {
+ message->mutable_reserved_range(i)->set_end(max_field_number);
+ }
+ }
+}
+
} // namespace
bool Parser::ParseMessageBlock(DescriptorProto* message,
@@ -717,6 +732,9 @@ bool Parser::ParseMessageBlock(DescriptorProto* message,
if (message->extension_range_size() > 0) {
AdjustExtensionRangesWithMaxEndNumber(message);
}
+ if (message->reserved_range_size() > 0) {
+ AdjustReservedRangesWithMaxEndNumber(message);
+ }
return true;
}
@@ -1429,6 +1447,8 @@ bool Parser::ParseExtensions(DescriptorProto* message,
// Parse the declaration.
DO(Consume("extensions"));
+ int old_range_size = message->extension_range_size();
+
do {
// Note that kExtensionRangeFieldNumber was already pushed by the parent.
LocationRecorder location(extensions_location,
@@ -1455,7 +1475,7 @@ bool Parser::ParseExtensions(DescriptorProto* message,
// Set to the sentinel value - 1 since we increment the value below.
// The actual value of the end of the range should be set with
// AdjustExtensionRangesWithMaxEndNumber.
- end = kMaxExtensionRangeSentinel - 1;
+ end = kMaxRangeSentinel - 1;
} else {
DO(ConsumeInteger(&end, "Expected integer."));
}
@@ -1475,12 +1495,36 @@ bool Parser::ParseExtensions(DescriptorProto* message,
range->set_end(end);
} while (TryConsume(","));
+ if (LookingAt("[")) {
+ LocationRecorder location(
+ extensions_location,
+ DescriptorProto::ExtensionRange::kOptionsFieldNumber);
+
+ DO(Consume("["));
+
+ // Parse extension range options in the first range.
+ ExtensionRangeOptions* options =
+ message->mutable_extension_range(old_range_size)->mutable_options();
+ do {
+ DO(ParseOption(options, location, containing_file, OPTION_ASSIGNMENT));
+ } while (TryConsume(","));
+
+ DO(Consume("]"));
+
+ // Then copy the extension range options to all of the other ranges we've
+ // parsed.
+ for (int i = old_range_size + 1; i < message->extension_range_size(); i++) {
+ message->mutable_extension_range(i)->mutable_options()
+ ->CopyFrom(*options);
+ }
+ }
+
DO(ConsumeEndOfDeclaration(";", &extensions_location));
return true;
}
-// This is similar to extension range parsing, except that "max" is not
-// supported, and accepts field name literals.
+// This is similar to extension range parsing, except that it accepts field
+// name literals.
bool Parser::ParseReserved(DescriptorProto* message,
const LocationRecorder& message_location) {
// Parse the declaration.
@@ -1528,7 +1572,14 @@ bool Parser::ParseReservedNumbers(DescriptorProto* message,
if (TryConsume("to")) {
LocationRecorder end_location(
location, DescriptorProto::ReservedRange::kEndFieldNumber);
- DO(ConsumeInteger(&end, "Expected integer."));
+ if (TryConsume("max")) {
+ // Set to the sentinel value - 1 since we increment the value below.
+ // The actual value of the end of the range should be set with
+ // AdjustExtensionRangesWithMaxEndNumber.
+ end = kMaxRangeSentinel - 1;
+ } else {
+ DO(ConsumeInteger(&end, "Expected integer."));
+ }
} else {
LocationRecorder end_location(
location, DescriptorProto::ReservedRange::kEndFieldNumber);
diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc
index d5e31325..97831f71 100644
--- a/src/google/protobuf/compiler/parser_unittest.cc
+++ b/src/google/protobuf/compiler/parser_unittest.cc
@@ -663,7 +663,7 @@ TEST_F(ParseMessageTest, ReservedRange) {
ExpectParsesTo(
"message TestMessage {\n"
" required int32 foo = 1;\n"
- " reserved 2, 15, 9 to 11, 3;\n"
+ " reserved 2, 15, 9 to 11, 3, 20 to max;\n"
"}\n",
"message_type {"
@@ -673,6 +673,29 @@ TEST_F(ParseMessageTest, ReservedRange) {
" reserved_range { start:15 end:16 }"
" reserved_range { start:9 end:12 }"
" reserved_range { start:3 end:4 }"
+ " reserved_range { start:20 end:536870912 }"
+ "}");
+}
+
+TEST_F(ParseMessageTest, ReservedRangeOnMessageSet) {
+ ExpectParsesTo(
+ "message TestMessage {\n"
+ " option message_set_wire_format = true;\n"
+ " reserved 20 to max;\n"
+ "}\n",
+
+ "message_type {"
+ " name: \"TestMessage\""
+ " options {"
+ " uninterpreted_option {"
+ " name {"
+ " name_part: \"message_set_wire_format\""
+ " is_extension: false"
+ " }"
+ " identifier_value: \"true\""
+ " }"
+ " }"
+ " reserved_range { start:20 end:2147483647 }"
"}");
}
@@ -703,6 +726,30 @@ TEST_F(ParseMessageTest, ExtensionRange) {
"}");
}
+TEST_F(ParseMessageTest, ExtensionRangeWithOptions) {
+ ExpectParsesTo(
+ "message TestMessage {\n"
+ " extensions 10 to 19 [(i) = 5];\n"
+ "}\n",
+
+ "message_type {"
+ " name: \"TestMessage\""
+ " extension_range {"
+ " start:10"
+ " end:20"
+ " options {"
+ " uninterpreted_option {"
+ " name {"
+ " name_part: \"i\""
+ " is_extension: true"
+ " }"
+ " positive_int_value: 5"
+ " }"
+ " }"
+ " }"
+ "}");
+}
+
TEST_F(ParseMessageTest, CompoundExtensionRange) {
ExpectParsesTo(
"message TestMessage {\n"
@@ -719,6 +766,82 @@ TEST_F(ParseMessageTest, CompoundExtensionRange) {
"}");
}
+TEST_F(ParseMessageTest, CompoundExtensionRangeWithOptions) {
+ ExpectParsesTo(
+ "message TestMessage {\n"
+ " extensions 2, 15, 9 to 11, 100 to max, 3 [(i) = 5];\n"
+ "}\n",
+
+ "message_type {"
+ " name: \"TestMessage\""
+ " extension_range {"
+ " start:2"
+ " end:3"
+ " options {"
+ " uninterpreted_option {"
+ " name {"
+ " name_part: \"i\""
+ " is_extension: true"
+ " }"
+ " positive_int_value: 5"
+ " }"
+ " }"
+ " }"
+ " extension_range {"
+ " start:15"
+ " end:16"
+ " options {"
+ " uninterpreted_option {"
+ " name {"
+ " name_part: \"i\""
+ " is_extension: true"
+ " }"
+ " positive_int_value: 5"
+ " }"
+ " }"
+ " }"
+ " extension_range {"
+ " start:9"
+ " end:12"
+ " options {"
+ " uninterpreted_option {"
+ " name {"
+ " name_part: \"i\""
+ " is_extension: true"
+ " }"
+ " positive_int_value: 5"
+ " }"
+ " }"
+ " }"
+ " extension_range {"
+ " start:100"
+ " end:536870912"
+ " options {"
+ " uninterpreted_option {"
+ " name {"
+ " name_part: \"i\""
+ " is_extension: true"
+ " }"
+ " positive_int_value: 5"
+ " }"
+ " }"
+ " }"
+ " extension_range {"
+ " start:3"
+ " end:4"
+ " options {"
+ " uninterpreted_option {"
+ " name {"
+ " name_part: \"i\""
+ " is_extension: true"
+ " }"
+ " positive_int_value: 5"
+ " }"
+ " }"
+ " }"
+ "}");
+}
+
TEST_F(ParseMessageTest, LargerMaxForMessageSetWireFormatMessages) {
// Messages using the message_set_wire_format option can accept larger
// extension numbers, as the numbers are not encoded as int32 field values
@@ -1368,12 +1491,12 @@ TEST_F(ParseErrorTest, EnumValueMissingNumber) {
// -------------------------------------------------------------------
// Reserved field number errors
-TEST_F(ParseErrorTest, ReservedMaxNotAllowed) {
+TEST_F(ParseErrorTest, ReservedStandaloneMaxNotAllowed) {
ExpectHasErrors(
"message Foo {\n"
- " reserved 10 to max;\n"
+ " reserved max;\n"
"}\n",
- "1:17: Expected integer.\n");
+ "1:11: Expected field name or number range.\n");
}
TEST_F(ParseErrorTest, ReservedMixNameAndNumber) {
diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc
index e8ffbb51..cb5e37bb 100644
--- a/src/google/protobuf/compiler/plugin.cc
+++ b/src/google/protobuf/compiler/plugin.cc
@@ -49,7 +49,7 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
-#if defined(_WIN32)
+#if defined(_MSC_VER)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::setmode;
@@ -126,6 +126,7 @@ bool GenerateCode(const CodeGeneratorRequest& request,
GeneratorResponseContext context(
request.compiler_version(), response, parsed_files);
+
string error;
bool succeeded = generator.GenerateAll(
parsed_files, request.parameter(), &context, &error);
diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc
index 516a5878..07883a37 100644
--- a/src/google/protobuf/compiler/plugin.pb.cc
+++ b/src/google/protobuf/compiler/plugin.pb.cc
@@ -20,13 +20,25 @@
namespace google {
namespace protobuf {
namespace compiler {
-class VersionDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Version> {
+class VersionDefaultTypeInternal {
+public:
+ ::google::protobuf::internal::ExplicitlyConstructed<Version>
+ _instance;
} _Version_default_instance_;
-class CodeGeneratorRequestDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorRequest> {
+class CodeGeneratorRequestDefaultTypeInternal {
+public:
+ ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorRequest>
+ _instance;
} _CodeGeneratorRequest_default_instance_;
-class CodeGeneratorResponse_FileDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorResponse_File> {
+class CodeGeneratorResponse_FileDefaultTypeInternal {
+public:
+ ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorResponse_File>
+ _instance;
} _CodeGeneratorResponse_File_default_instance_;
-class CodeGeneratorResponseDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorResponse> {
+class CodeGeneratorResponseDefaultTypeInternal {
+public:
+ ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorResponse>
+ _instance;
} _CodeGeneratorResponse_default_instance_;
namespace protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto {
@@ -39,23 +51,23 @@ namespace {
} // namespace
PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField
- const TableStruct::entries[] = {
+ const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0},
};
PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField
- const TableStruct::aux[] = {
+ const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
::google::protobuf::internal::AuxillaryParseTableField(),
};
PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const
- TableStruct::schema[] = {
- { NULL, NULL, 0, -1, -1, false },
- { NULL, NULL, 0, -1, -1, false },
- { NULL, NULL, 0, -1, -1, false },
- { NULL, NULL, 0, -1, -1, false },
+ TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
+ { NULL, NULL, 0, -1, -1, -1, -1, NULL, false },
+ { NULL, NULL, 0, -1, -1, -1, -1, NULL, false },
+ { NULL, NULL, 0, -1, -1, -1, -1, NULL, false },
+ { NULL, NULL, 0, -1, -1, -1, -1, NULL, false },
};
-const ::google::protobuf::uint32 TableStruct::offsets[] = {
+const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _has_bits_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _internal_metadata_),
~0u, // no _extensions_
@@ -103,8 +115,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = {
0,
~0u,
};
-
-static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{ 0, 9, sizeof(Version)},
{ 13, 22, sizeof(CodeGeneratorRequest)},
{ 26, 34, sizeof(CodeGeneratorResponse_File)},
@@ -140,28 +151,20 @@ void protobuf_RegisterTypes(const ::std::string&) {
}
} // namespace
-
-void TableStruct::Shutdown() {
- _Version_default_instance_.Shutdown();
- delete file_level_metadata[0].reflection;
- _CodeGeneratorRequest_default_instance_.Shutdown();
- delete file_level_metadata[1].reflection;
- _CodeGeneratorResponse_File_default_instance_.Shutdown();
- delete file_level_metadata[2].reflection;
- _CodeGeneratorResponse_default_instance_.Shutdown();
- delete file_level_metadata[3].reflection;
-}
-
void TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::internal::InitProtobufDefaults();
::google::protobuf::protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
- _Version_default_instance_.DefaultConstruct();
- _CodeGeneratorRequest_default_instance_.DefaultConstruct();
- _CodeGeneratorResponse_File_default_instance_.DefaultConstruct();
- _CodeGeneratorResponse_default_instance_.DefaultConstruct();
- _CodeGeneratorRequest_default_instance_.get_mutable()->compiler_version_ = const_cast< ::google::protobuf::compiler::Version*>(
+ _Version_default_instance_._instance.DefaultConstruct();
+ ::google::protobuf::internal::OnShutdownDestroyMessage(
+ &_Version_default_instance_);_CodeGeneratorRequest_default_instance_._instance.DefaultConstruct();
+ ::google::protobuf::internal::OnShutdownDestroyMessage(
+ &_CodeGeneratorRequest_default_instance_);_CodeGeneratorResponse_File_default_instance_._instance.DefaultConstruct();
+ ::google::protobuf::internal::OnShutdownDestroyMessage(
+ &_CodeGeneratorResponse_File_default_instance_);_CodeGeneratorResponse_default_instance_._instance.DefaultConstruct();
+ ::google::protobuf::internal::OnShutdownDestroyMessage(
+ &_CodeGeneratorResponse_default_instance_);_CodeGeneratorRequest_default_instance_._instance.get_mutable()->compiler_version_ = const_cast< ::google::protobuf::compiler::Version*>(
::google::protobuf::compiler::Version::internal_default_instance());
}
@@ -172,7 +175,7 @@ void InitDefaults() {
namespace {
void AddDescriptorsImpl() {
InitDefaults();
- static const char descriptor[] = {
+ static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n%google/protobuf/compiler/plugin.proto\022"
"\030google.protobuf.compiler\032 google/protob"
"uf/descriptor.proto\"F\n\007Version\022\r\n\005major\030"
@@ -195,7 +198,6 @@ void AddDescriptorsImpl() {
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/compiler/plugin.proto", &protobuf_RegisterTypes);
::google::protobuf::protobuf_google_2fprotobuf_2fdescriptor_2eproto::AddDescriptors();
- ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);
}
} // anonymous namespace
@@ -288,11 +290,16 @@ Version* Version::New(::google::protobuf::Arena* arena) const {
void Version::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.Version)
+ ::google::protobuf::uint32 cached_has_bits = 0;
+ // Prevent compiler warnings about cached_has_bits being unused
+ (void) cached_has_bits;
+
if (has_suffix()) {
GOOGLE_DCHECK(!suffix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
(*suffix_.UnsafeRawStringPointer())->clear();
}
- if (_has_bits_[0 / 32] & 14u) {
+ cached_has_bits = _has_bits_[0];
+ if (cached_has_bits & 14u) {
::memset(&major_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&patch_) -
reinterpret_cast<char*>(&major_)) + sizeof(patch_));
@@ -314,7 +321,7 @@ bool Version::MergePartialFromCodedStream(
// optional int32 major = 1;
case 1: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(8u)) {
+ static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) {
set_has_major();
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
@@ -328,7 +335,7 @@ bool Version::MergePartialFromCodedStream(
// optional int32 minor = 2;
case 2: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(16u)) {
+ static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) {
set_has_minor();
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
@@ -342,7 +349,7 @@ bool Version::MergePartialFromCodedStream(
// optional int32 patch = 3;
case 3: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(24u)) {
+ static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) {
set_has_patch();
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
@@ -356,7 +363,7 @@ bool Version::MergePartialFromCodedStream(
// optional string suffix = 4;
case 4: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(34u)) {
+ static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_suffix()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -371,13 +378,11 @@ bool Version::MergePartialFromCodedStream(
default: {
handle_unusual:
- if (tag == 0 ||
- ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
- ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+ if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
- input, tag, mutable_unknown_fields()));
+ input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -425,7 +430,7 @@ void Version::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
- unknown_fields(), output);
+ _internal_metadata_.unknown_fields(), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.compiler.Version)
}
@@ -466,7 +471,7 @@ void Version::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
- unknown_fields(), target);
+ _internal_metadata_.unknown_fields(), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.Version)
return target;
@@ -479,7 +484,7 @@ size_t Version::ByteSizeLong() const {
if (_internal_metadata_.have_unknown_fields()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ _internal_metadata_.unknown_fields());
}
if (_has_bits_[0 / 32] & 15u) {
// optional string suffix = 4;
@@ -582,13 +587,14 @@ void Version::Swap(Version* other) {
InternalSwap(other);
}
void Version::InternalSwap(Version* other) {
+ using std::swap;
suffix_.Swap(&other->suffix_);
- std::swap(major_, other->major_);
- std::swap(minor_, other->minor_);
- std::swap(patch_, other->patch_);
- std::swap(_has_bits_[0], other->_has_bits_[0]);
+ swap(major_, other->major_);
+ swap(minor_, other->minor_);
+ swap(patch_, other->patch_);
+ swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
- std::swap(_cached_size_, other->_cached_size_);
+ swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Version::GetMetadata() const {
@@ -786,9 +792,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() {
void CodeGeneratorRequest::SharedDtor() {
parameter_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != internal_default_instance()) {
- delete compiler_version_;
- }
+ if (this != internal_default_instance()) delete compiler_version_;
}
void CodeGeneratorRequest::SetCachedSize(int size) const {
@@ -816,14 +820,19 @@ CodeGeneratorRequest* CodeGeneratorRequest::New(::google::protobuf::Arena* arena
void CodeGeneratorRequest::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorRequest)
+ ::google::protobuf::uint32 cached_has_bits = 0;
+ // Prevent compiler warnings about cached_has_bits being unused
+ (void) cached_has_bits;
+
file_to_generate_.Clear();
proto_file_.Clear();
- if (_has_bits_[0 / 32] & 3u) {
- if (has_parameter()) {
+ cached_has_bits = _has_bits_[0];
+ if (cached_has_bits & 3u) {
+ if (cached_has_bits & 0x00000001u) {
GOOGLE_DCHECK(!parameter_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
(*parameter_.UnsafeRawStringPointer())->clear();
}
- if (has_compiler_version()) {
+ if (cached_has_bits & 0x00000002u) {
GOOGLE_DCHECK(compiler_version_ != NULL);
compiler_version_->::google::protobuf::compiler::Version::Clear();
}
@@ -845,7 +854,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
// repeated string file_to_generate = 1;
case 1: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(10u)) {
+ static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_file_to_generate()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -862,7 +871,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
// optional string parameter = 2;
case 2: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(18u)) {
+ static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_parameter()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -878,7 +887,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
// optional .google.protobuf.compiler.Version compiler_version = 3;
case 3: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(26u)) {
+ static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_compiler_version()));
} else {
@@ -890,7 +899,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
// repeated .google.protobuf.FileDescriptorProto proto_file = 15;
case 15: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(122u)) {
+ static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, add_proto_file()));
} else {
@@ -901,13 +910,11 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
default: {
handle_unusual:
- if (tag == 0 ||
- ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
- ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+ if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
- input, tag, mutable_unknown_fields()));
+ input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -963,7 +970,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
- unknown_fields(), output);
+ _internal_metadata_.unknown_fields(), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.compiler.CodeGeneratorRequest)
}
@@ -1014,7 +1021,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
- unknown_fields(), target);
+ _internal_metadata_.unknown_fields(), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.CodeGeneratorRequest)
return target;
@@ -1027,7 +1034,7 @@ size_t CodeGeneratorRequest::ByteSizeLong() const {
if (_internal_metadata_.have_unknown_fields()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ _internal_metadata_.unknown_fields());
}
// repeated string file_to_generate = 1;
total_size += 1 *
@@ -1131,13 +1138,14 @@ void CodeGeneratorRequest::Swap(CodeGeneratorRequest* other) {
InternalSwap(other);
}
void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) {
+ using std::swap;
file_to_generate_.InternalSwap(&other->file_to_generate_);
proto_file_.InternalSwap(&other->proto_file_);
parameter_.Swap(&other->parameter_);
- std::swap(compiler_version_, other->compiler_version_);
- std::swap(_has_bits_[0], other->_has_bits_[0]);
+ swap(compiler_version_, other->compiler_version_);
+ swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
- std::swap(_cached_size_, other->_cached_size_);
+ swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata CodeGeneratorRequest::GetMetadata() const {
@@ -1325,9 +1333,10 @@ void CodeGeneratorRequest::clear_compiler_version() {
clear_has_compiler_version();
}
const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const {
+ const ::google::protobuf::compiler::Version* p = compiler_version_;
// @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
- return compiler_version_ != NULL ? *compiler_version_
- : *::google::protobuf::compiler::Version::internal_default_instance();
+ return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::compiler::Version*>(
+ &::google::protobuf::compiler::_Version_default_instance_);
}
::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() {
set_has_compiler_version();
@@ -1437,16 +1446,21 @@ CodeGeneratorResponse_File* CodeGeneratorResponse_File::New(::google::protobuf::
void CodeGeneratorResponse_File::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse.File)
- if (_has_bits_[0 / 32] & 7u) {
- if (has_name()) {
+ ::google::protobuf::uint32 cached_has_bits = 0;
+ // Prevent compiler warnings about cached_has_bits being unused
+ (void) cached_has_bits;
+
+ cached_has_bits = _has_bits_[0];
+ if (cached_has_bits & 7u) {
+ if (cached_has_bits & 0x00000001u) {
GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
(*name_.UnsafeRawStringPointer())->clear();
}
- if (has_insertion_point()) {
+ if (cached_has_bits & 0x00000002u) {
GOOGLE_DCHECK(!insertion_point_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
(*insertion_point_.UnsafeRawStringPointer())->clear();
}
- if (has_content()) {
+ if (cached_has_bits & 0x00000004u) {
GOOGLE_DCHECK(!content_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
(*content_.UnsafeRawStringPointer())->clear();
}
@@ -1468,7 +1482,7 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
// optional string name = 1;
case 1: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(10u)) {
+ static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1484,7 +1498,7 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
// optional string insertion_point = 2;
case 2: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(18u)) {
+ static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_insertion_point()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1500,7 +1514,7 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
// optional string content = 15;
case 15: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(122u)) {
+ static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_content()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1515,13 +1529,11 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
default: {
handle_unusual:
- if (tag == 0 ||
- ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
- ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+ if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
- input, tag, mutable_unknown_fields()));
+ input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -1574,7 +1586,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
- unknown_fields(), output);
+ _internal_metadata_.unknown_fields(), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.compiler.CodeGeneratorResponse.File)
}
@@ -1622,7 +1634,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
- unknown_fields(), target);
+ _internal_metadata_.unknown_fields(), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.CodeGeneratorResponse.File)
return target;
@@ -1635,7 +1647,7 @@ size_t CodeGeneratorResponse_File::ByteSizeLong() const {
if (_internal_metadata_.have_unknown_fields()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ _internal_metadata_.unknown_fields());
}
if (_has_bits_[0 / 32] & 7u) {
// optional string name = 1;
@@ -1729,12 +1741,13 @@ void CodeGeneratorResponse_File::Swap(CodeGeneratorResponse_File* other) {
InternalSwap(other);
}
void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other) {
+ using std::swap;
name_.Swap(&other->name_);
insertion_point_.Swap(&other->insertion_point_);
content_.Swap(&other->content_);
- std::swap(_has_bits_[0], other->_has_bits_[0]);
+ swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
- std::swap(_cached_size_, other->_cached_size_);
+ swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata CodeGeneratorResponse_File::GetMetadata() const {
@@ -2004,6 +2017,10 @@ CodeGeneratorResponse* CodeGeneratorResponse::New(::google::protobuf::Arena* are
void CodeGeneratorResponse::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse)
+ ::google::protobuf::uint32 cached_has_bits = 0;
+ // Prevent compiler warnings about cached_has_bits being unused
+ (void) cached_has_bits;
+
file_.Clear();
if (has_error()) {
GOOGLE_DCHECK(!error_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
@@ -2026,7 +2043,7 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream(
// optional string error = 1;
case 1: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(10u)) {
+ static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_error()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -2042,7 +2059,7 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream(
// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15;
case 15: {
if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(122u)) {
+ static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, add_file()));
} else {
@@ -2053,13 +2070,11 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream(
default: {
handle_unusual:
- if (tag == 0 ||
- ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
- ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+ if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormat::SkipField(
- input, tag, mutable_unknown_fields()));
+ input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -2099,7 +2114,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
- unknown_fields(), output);
+ _internal_metadata_.unknown_fields(), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.compiler.CodeGeneratorResponse)
}
@@ -2133,7 +2148,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes(
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
- unknown_fields(), target);
+ _internal_metadata_.unknown_fields(), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.CodeGeneratorResponse)
return target;
@@ -2146,7 +2161,7 @@ size_t CodeGeneratorResponse::ByteSizeLong() const {
if (_internal_metadata_.have_unknown_fields()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ _internal_metadata_.unknown_fields());
}
// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15;
{
@@ -2225,11 +2240,12 @@ void CodeGeneratorResponse::Swap(CodeGeneratorResponse* other) {
InternalSwap(other);
}
void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) {
+ using std::swap;
file_.InternalSwap(&other->file_);
error_.Swap(&other->error_);
- std::swap(_has_bits_[0], other->_has_bits_[0]);
+ swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
- std::swap(_cached_size_, other->_cached_size_);
+ swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata CodeGeneratorResponse::GetMetadata() const {
diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h
index 57e1f77b..2d66f035 100644
--- a/src/google/protobuf/compiler/plugin.pb.h
+++ b/src/google/protobuf/compiler/plugin.pb.h
@@ -8,12 +8,12 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3003000
+#if GOOGLE_PROTOBUF_VERSION < 3004000
#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 3003002 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3004000 < GOOGLE_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.
@@ -67,8 +67,9 @@ struct LIBPROTOC_EXPORT TableStruct {
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[];
static const ::google::protobuf::uint32 offsets[];
+ static const ::google::protobuf::internal::FieldMetadata field_metadata[];
+ static const ::google::protobuf::internal::SerializationTable serialization_table[];
static void InitDefaultsImpl();
- static void Shutdown();
};
void LIBPROTOC_EXPORT AddDescriptors();
void LIBPROTOC_EXPORT InitDefaults();
@@ -87,11 +88,24 @@ class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_
CopyFrom(from);
return *this;
}
+ #if LANG_CXX11
+ Version(Version&& from) noexcept
+ : Version() {
+ *this = ::std::move(from);
+ }
+ inline Version& operator=(Version&& from) noexcept {
+ if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (this != &from) InternalSwap(&from);
+ } else {
+ CopyFrom(from);
+ }
+ return *this;
+ }
+ #endif
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _internal_metadata_.unknown_fields();
}
-
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return _internal_metadata_.mutable_unknown_fields();
}
@@ -107,6 +121,9 @@ class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_
0;
void Swap(Version* other);
+ friend void swap(Version& a, Version& b) {
+ a.Swap(&b);
+ }
// implements Message ----------------------------------------------
@@ -217,11 +234,24 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message
CopyFrom(from);
return *this;
}
+ #if LANG_CXX11
+ CodeGeneratorRequest(CodeGeneratorRequest&& from) noexcept
+ : CodeGeneratorRequest() {
+ *this = ::std::move(from);
+ }
+ inline CodeGeneratorRequest& operator=(CodeGeneratorRequest&& from) noexcept {
+ if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (this != &from) InternalSwap(&from);
+ } else {
+ CopyFrom(from);
+ }
+ return *this;
+ }
+ #endif
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _internal_metadata_.unknown_fields();
}
-
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return _internal_metadata_.mutable_unknown_fields();
}
@@ -237,6 +267,9 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message
1;
void Swap(CodeGeneratorRequest* other);
+ friend void swap(CodeGeneratorRequest& a, CodeGeneratorRequest& b) {
+ a.Swap(&b);
+ }
// implements Message ----------------------------------------------
@@ -365,11 +398,24 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M
CopyFrom(from);
return *this;
}
+ #if LANG_CXX11
+ CodeGeneratorResponse_File(CodeGeneratorResponse_File&& from) noexcept
+ : CodeGeneratorResponse_File() {
+ *this = ::std::move(from);
+ }
+ inline CodeGeneratorResponse_File& operator=(CodeGeneratorResponse_File&& from) noexcept {
+ if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (this != &from) InternalSwap(&from);
+ } else {
+ CopyFrom(from);
+ }
+ return *this;
+ }
+ #endif
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _internal_metadata_.unknown_fields();
}
-
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return _internal_metadata_.mutable_unknown_fields();
}
@@ -385,6 +431,9 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M
2;
void Swap(CodeGeneratorResponse_File* other);
+ friend void swap(CodeGeneratorResponse_File& a, CodeGeneratorResponse_File& b) {
+ a.Swap(&b);
+ }
// implements Message ----------------------------------------------
@@ -501,11 +550,24 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag
CopyFrom(from);
return *this;
}
+ #if LANG_CXX11
+ CodeGeneratorResponse(CodeGeneratorResponse&& from) noexcept
+ : CodeGeneratorResponse() {
+ *this = ::std::move(from);
+ }
+ inline CodeGeneratorResponse& operator=(CodeGeneratorResponse&& from) noexcept {
+ if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+ if (this != &from) InternalSwap(&from);
+ } else {
+ CopyFrom(from);
+ }
+ return *this;
+ }
+ #endif
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _internal_metadata_.unknown_fields();
}
-
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return _internal_metadata_.mutable_unknown_fields();
}
@@ -521,6 +583,9 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag
3;
void Swap(CodeGeneratorResponse* other);
+ friend void swap(CodeGeneratorResponse& a, CodeGeneratorResponse& b) {
+ a.Swap(&b);
+ }
// implements Message ----------------------------------------------
@@ -609,6 +674,10 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
+#ifdef __GNUC__
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif // __GNUC__
// Version
// optional int32 major = 1;
@@ -927,9 +996,10 @@ inline void CodeGeneratorRequest::clear_compiler_version() {
clear_has_compiler_version();
}
inline const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const {
+ const ::google::protobuf::compiler::Version* p = compiler_version_;
// @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
- return compiler_version_ != NULL ? *compiler_version_
- : *::google::protobuf::compiler::Version::internal_default_instance();
+ return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::compiler::Version*>(
+ &::google::protobuf::compiler::_Version_default_instance_);
}
inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() {
set_has_compiler_version();
@@ -1247,6 +1317,9 @@ CodeGeneratorResponse::file() const {
return file_;
}
+#ifdef __GNUC__
+ #pragma GCC diagnostic pop
+#endif // __GNUC__
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
// -------------------------------------------------------------------
diff --git a/src/google/protobuf/compiler/plugin.proto b/src/google/protobuf/compiler/plugin.proto
index f04dc73c..5b557452 100644
--- a/src/google/protobuf/compiler/plugin.proto
+++ b/src/google/protobuf/compiler/plugin.proto
@@ -91,6 +91,7 @@ message CodeGeneratorRequest {
// The version number of protocol compiler.
optional Version compiler_version = 3;
+
}
// The plugin writes an encoded CodeGeneratorResponse to stdout.
diff --git a/src/google/protobuf/compiler/profile.pb.cc b/src/google/protobuf/compiler/profile.pb.cc
deleted file mode 100644
index 4616b514..00000000
--- a/src/google/protobuf/compiler/profile.pb.cc
+++ /dev/null
@@ -1,1453 +0,0 @@
-// Generated by the protocol buffer compiler. DO NOT EDIT!
-// source: google/protobuf/compiler/profile.proto
-
-#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
-#include <google/protobuf/compiler/profile.pb.h>
-
-#include <algorithm>
-
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/port.h>
-#include <google/protobuf/stubs/once.h>
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/wire_format_lite_inl.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/generated_message_reflection.h>
-#include <google/protobuf/reflection_ops.h>
-#include <google/protobuf/wire_format.h>
-// @@protoc_insertion_point(includes)
-
-namespace google {
-namespace protobuf {
-namespace compiler {
-class FieldAccessInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FieldAccessInfo> {
-} _FieldAccessInfo_default_instance_;
-class MessageAccessInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<MessageAccessInfo> {
-} _MessageAccessInfo_default_instance_;
-class AccessInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<AccessInfo> {
-} _AccessInfo_default_instance_;
-
-namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto {
-
-
-namespace {
-
-::google::protobuf::Metadata file_level_metadata[3];
-
-} // namespace
-
-PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField
- const TableStruct::entries[] = {
- {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0},
-};
-
-PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField
- const TableStruct::aux[] = {
- ::google::protobuf::internal::AuxillaryParseTableField(),
-};
-PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const
- TableStruct::schema[] = {
- { NULL, NULL, 0, -1, -1, false },
- { NULL, NULL, 0, -1, -1, false },
- { NULL, NULL, 0, -1, -1, false },
-};
-
-const ::google::protobuf::uint32 TableStruct::offsets[] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, _has_bits_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, _internal_metadata_),
- ~0u, // no _extensions_
- ~0u, // no _oneof_case_
- ~0u, // no _weak_field_map_
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, getters_count_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, setters_count_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, configs_count_),
- 0,
- 1,
- 2,
- 3,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, _has_bits_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, _internal_metadata_),
- ~0u, // no _extensions_
- ~0u, // no _oneof_case_
- ~0u, // no _weak_field_map_
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, count_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, field_),
- 0,
- 1,
- ~0u,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AccessInfo, _has_bits_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AccessInfo, _internal_metadata_),
- ~0u, // no _extensions_
- ~0u, // no _oneof_case_
- ~0u, // no _weak_field_map_
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AccessInfo, message_),
- ~0u,
-};
-
-static const ::google::protobuf::internal::MigrationSchema schemas[] = {
- { 0, 9, sizeof(FieldAccessInfo)},
- { 13, 21, sizeof(MessageAccessInfo)},
- { 24, 30, sizeof(AccessInfo)},
-};
-
-static ::google::protobuf::Message const * const file_default_instances[] = {
- reinterpret_cast<const ::google::protobuf::Message*>(&_FieldAccessInfo_default_instance_),
- reinterpret_cast<const ::google::protobuf::Message*>(&_MessageAccessInfo_default_instance_),
- reinterpret_cast<const ::google::protobuf::Message*>(&_AccessInfo_default_instance_),
-};
-
-namespace {
-
-void protobuf_AssignDescriptors() {
- AddDescriptors();
- ::google::protobuf::MessageFactory* factory = NULL;
- AssignDescriptors(
- "google/protobuf/compiler/profile.proto", schemas, file_default_instances, TableStruct::offsets, factory,
- file_level_metadata, NULL, NULL);
-}
-
-void protobuf_AssignDescriptorsOnce() {
- static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
- ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
-}
-
-void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
-void protobuf_RegisterTypes(const ::std::string&) {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 3);
-}
-
-} // namespace
-
-void TableStruct::Shutdown() {
- _FieldAccessInfo_default_instance_.Shutdown();
- delete file_level_metadata[0].reflection;
- _MessageAccessInfo_default_instance_.Shutdown();
- delete file_level_metadata[1].reflection;
- _AccessInfo_default_instance_.Shutdown();
- delete file_level_metadata[2].reflection;
-}
-
-void TableStruct::InitDefaultsImpl() {
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- ::google::protobuf::internal::InitProtobufDefaults();
- _FieldAccessInfo_default_instance_.DefaultConstruct();
- _MessageAccessInfo_default_instance_.DefaultConstruct();
- _AccessInfo_default_instance_.DefaultConstruct();
-}
-
-void InitDefaults() {
- static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
- ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
-}
-namespace {
-void AddDescriptorsImpl() {
- InitDefaults();
- static const char descriptor[] = {
- "\n&google/protobuf/compiler/profile.proto"
- "\022\030google.protobuf.compiler\"d\n\017FieldAcces"
- "sInfo\022\014\n\004name\030\001 \001(\t\022\025\n\rgetters_count\030\002 \001"
- "(\004\022\025\n\rsetters_count\030\003 \001(\004\022\025\n\rconfigs_cou"
- "nt\030\004 \001(\004\"j\n\021MessageAccessInfo\022\014\n\004name\030\001 "
- "\001(\t\022\r\n\005count\030\002 \001(\004\0228\n\005field\030\003 \003(\0132).goog"
- "le.protobuf.compiler.FieldAccessInfo\"J\n\n"
- "AccessInfo\022<\n\007message\030\001 \003(\0132+.google.pro"
- "tobuf.compiler.MessageAccessInfo"
- };
- ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
- descriptor, 352);
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
- "google/protobuf/compiler/profile.proto", &protobuf_RegisterTypes);
- ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);
-}
-} // anonymous namespace
-
-void AddDescriptors() {
- static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
- ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
-}
-// Force AddDescriptors() to be called at dynamic initialization time.
-struct StaticDescriptorInitializer {
- StaticDescriptorInitializer() {
- AddDescriptors();
- }
-} static_descriptor_initializer;
-
-} // namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto
-
-
-// ===================================================================
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const int FieldAccessInfo::kNameFieldNumber;
-const int FieldAccessInfo::kGettersCountFieldNumber;
-const int FieldAccessInfo::kSettersCountFieldNumber;
-const int FieldAccessInfo::kConfigsCountFieldNumber;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
-
-FieldAccessInfo::FieldAccessInfo()
- : ::google::protobuf::Message(), _internal_metadata_(NULL) {
- if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults();
- }
- SharedCtor();
- // @@protoc_insertion_point(constructor:google.protobuf.compiler.FieldAccessInfo)
-}
-FieldAccessInfo::FieldAccessInfo(const FieldAccessInfo& from)
- : ::google::protobuf::Message(),
- _internal_metadata_(NULL),
- _has_bits_(from._has_bits_),
- _cached_size_(0) {
- _internal_metadata_.MergeFrom(from._internal_metadata_);
- name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (from.has_name()) {
- name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
- }
- ::memcpy(&getters_count_, &from.getters_count_,
- static_cast<size_t>(reinterpret_cast<char*>(&configs_count_) -
- reinterpret_cast<char*>(&getters_count_)) + sizeof(configs_count_));
- // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.FieldAccessInfo)
-}
-
-void FieldAccessInfo::SharedCtor() {
- _cached_size_ = 0;
- name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- ::memset(&getters_count_, 0, static_cast<size_t>(
- reinterpret_cast<char*>(&configs_count_) -
- reinterpret_cast<char*>(&getters_count_)) + sizeof(configs_count_));
-}
-
-FieldAccessInfo::~FieldAccessInfo() {
- // @@protoc_insertion_point(destructor:google.protobuf.compiler.FieldAccessInfo)
- SharedDtor();
-}
-
-void FieldAccessInfo::SharedDtor() {
- name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-
-void FieldAccessInfo::SetCachedSize(int size) const {
- GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
- _cached_size_ = size;
- GOOGLE_SAFE_CONCURRENT_WRITES_END();
-}
-const ::google::protobuf::Descriptor* FieldAccessInfo::descriptor() {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce();
- return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
-}
-
-const FieldAccessInfo& FieldAccessInfo::default_instance() {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults();
- return *internal_default_instance();
-}
-
-FieldAccessInfo* FieldAccessInfo::New(::google::protobuf::Arena* arena) const {
- FieldAccessInfo* n = new FieldAccessInfo;
- if (arena != NULL) {
- arena->Own(n);
- }
- return n;
-}
-
-void FieldAccessInfo::Clear() {
-// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.FieldAccessInfo)
- if (has_name()) {
- GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
- (*name_.UnsafeRawStringPointer())->clear();
- }
- if (_has_bits_[0 / 32] & 14u) {
- ::memset(&getters_count_, 0, static_cast<size_t>(
- reinterpret_cast<char*>(&configs_count_) -
- reinterpret_cast<char*>(&getters_count_)) + sizeof(configs_count_));
- }
- _has_bits_.Clear();
- _internal_metadata_.Clear();
-}
-
-bool FieldAccessInfo::MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
- ::google::protobuf::uint32 tag;
- // @@protoc_insertion_point(parse_start:google.protobuf.compiler.FieldAccessInfo)
- for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
- tag = p.first;
- if (!p.second) goto handle_unusual;
- switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
- case 1: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(10u)) {
- DO_(::google::protobuf::internal::WireFormatLite::ReadString(
- input, this->mutable_name()));
- ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
- this->name().data(), static_cast<int>(this->name().length()),
- ::google::protobuf::internal::WireFormat::PARSE,
- "google.protobuf.compiler.FieldAccessInfo.name");
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- // optional uint64 getters_count = 2;
- case 2: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(16u)) {
- set_has_getters_count();
- DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
- ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
- input, &getters_count_)));
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- // optional uint64 setters_count = 3;
- case 3: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(24u)) {
- set_has_setters_count();
- DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
- ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
- input, &setters_count_)));
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- // optional uint64 configs_count = 4;
- case 4: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(32u)) {
- set_has_configs_count();
- DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
- ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
- input, &configs_count_)));
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- default: {
- handle_unusual:
- if (tag == 0 ||
- ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
- ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
- goto success;
- }
- DO_(::google::protobuf::internal::WireFormat::SkipField(
- input, tag, mutable_unknown_fields()));
- break;
- }
- }
- }
-success:
- // @@protoc_insertion_point(parse_success:google.protobuf.compiler.FieldAccessInfo)
- return true;
-failure:
- // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.FieldAccessInfo)
- return false;
-#undef DO_
-}
-
-void FieldAccessInfo::SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const {
- // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.FieldAccessInfo)
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- cached_has_bits = _has_bits_[0];
- // optional string name = 1;
- if (cached_has_bits & 0x00000001u) {
- ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
- this->name().data(), static_cast<int>(this->name().length()),
- ::google::protobuf::internal::WireFormat::SERIALIZE,
- "google.protobuf.compiler.FieldAccessInfo.name");
- ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
- 1, this->name(), output);
- }
-
- // optional uint64 getters_count = 2;
- if (cached_has_bits & 0x00000002u) {
- ::google::protobuf::internal::WireFormatLite::WriteUInt64(2, this->getters_count(), output);
- }
-
- // optional uint64 setters_count = 3;
- if (cached_has_bits & 0x00000004u) {
- ::google::protobuf::internal::WireFormatLite::WriteUInt64(3, this->setters_count(), output);
- }
-
- // optional uint64 configs_count = 4;
- if (cached_has_bits & 0x00000008u) {
- ::google::protobuf::internal::WireFormatLite::WriteUInt64(4, this->configs_count(), output);
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
- unknown_fields(), output);
- }
- // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.FieldAccessInfo)
-}
-
-::google::protobuf::uint8* FieldAccessInfo::InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* target) const {
- (void)deterministic; // Unused
- // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.FieldAccessInfo)
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- cached_has_bits = _has_bits_[0];
- // optional string name = 1;
- if (cached_has_bits & 0x00000001u) {
- ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
- this->name().data(), static_cast<int>(this->name().length()),
- ::google::protobuf::internal::WireFormat::SERIALIZE,
- "google.protobuf.compiler.FieldAccessInfo.name");
- target =
- ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
- 1, this->name(), target);
- }
-
- // optional uint64 getters_count = 2;
- if (cached_has_bits & 0x00000002u) {
- target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(2, this->getters_count(), target);
- }
-
- // optional uint64 setters_count = 3;
- if (cached_has_bits & 0x00000004u) {
- target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(3, this->setters_count(), target);
- }
-
- // optional uint64 configs_count = 4;
- if (cached_has_bits & 0x00000008u) {
- target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(4, this->configs_count(), target);
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
- unknown_fields(), target);
- }
- // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.FieldAccessInfo)
- return target;
-}
-
-size_t FieldAccessInfo::ByteSizeLong() const {
-// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.FieldAccessInfo)
- size_t total_size = 0;
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
- }
- if (_has_bits_[0 / 32] & 15u) {
- // optional string name = 1;
- if (has_name()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->name());
- }
-
- // optional uint64 getters_count = 2;
- if (has_getters_count()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::UInt64Size(
- this->getters_count());
- }
-
- // optional uint64 setters_count = 3;
- if (has_setters_count()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::UInt64Size(
- this->setters_count());
- }
-
- // optional uint64 configs_count = 4;
- if (has_configs_count()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::UInt64Size(
- this->configs_count());
- }
-
- }
- int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
- GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
- _cached_size_ = cached_size;
- GOOGLE_SAFE_CONCURRENT_WRITES_END();
- return total_size;
-}
-
-void FieldAccessInfo::MergeFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.FieldAccessInfo)
- GOOGLE_DCHECK_NE(&from, this);
- const FieldAccessInfo* source =
- ::google::protobuf::internal::DynamicCastToGenerated<const FieldAccessInfo>(
- &from);
- if (source == NULL) {
- // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.FieldAccessInfo)
- ::google::protobuf::internal::ReflectionOps::Merge(from, this);
- } else {
- // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.FieldAccessInfo)
- MergeFrom(*source);
- }
-}
-
-void FieldAccessInfo::MergeFrom(const FieldAccessInfo& from) {
-// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.FieldAccessInfo)
- GOOGLE_DCHECK_NE(&from, this);
- _internal_metadata_.MergeFrom(from._internal_metadata_);
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- cached_has_bits = from._has_bits_[0];
- if (cached_has_bits & 15u) {
- if (cached_has_bits & 0x00000001u) {
- set_has_name();
- name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
- }
- if (cached_has_bits & 0x00000002u) {
- getters_count_ = from.getters_count_;
- }
- if (cached_has_bits & 0x00000004u) {
- setters_count_ = from.setters_count_;
- }
- if (cached_has_bits & 0x00000008u) {
- configs_count_ = from.configs_count_;
- }
- _has_bits_[0] |= cached_has_bits;
- }
-}
-
-void FieldAccessInfo::CopyFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.FieldAccessInfo)
- if (&from == this) return;
- Clear();
- MergeFrom(from);
-}
-
-void FieldAccessInfo::CopyFrom(const FieldAccessInfo& from) {
-// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.FieldAccessInfo)
- if (&from == this) return;
- Clear();
- MergeFrom(from);
-}
-
-bool FieldAccessInfo::IsInitialized() const {
- return true;
-}
-
-void FieldAccessInfo::Swap(FieldAccessInfo* other) {
- if (other == this) return;
- InternalSwap(other);
-}
-void FieldAccessInfo::InternalSwap(FieldAccessInfo* other) {
- name_.Swap(&other->name_);
- std::swap(getters_count_, other->getters_count_);
- std::swap(setters_count_, other->setters_count_);
- std::swap(configs_count_, other->configs_count_);
- std::swap(_has_bits_[0], other->_has_bits_[0]);
- _internal_metadata_.Swap(&other->_internal_metadata_);
- std::swap(_cached_size_, other->_cached_size_);
-}
-
-::google::protobuf::Metadata FieldAccessInfo::GetMetadata() const {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce();
- return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages];
-}
-
-#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// FieldAccessInfo
-
-// optional string name = 1;
-bool FieldAccessInfo::has_name() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-void FieldAccessInfo::set_has_name() {
- _has_bits_[0] |= 0x00000001u;
-}
-void FieldAccessInfo::clear_has_name() {
- _has_bits_[0] &= ~0x00000001u;
-}
-void FieldAccessInfo::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- clear_has_name();
-}
-const ::std::string& FieldAccessInfo::name() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.name)
- return name_.GetNoArena();
-}
-void FieldAccessInfo::set_name(const ::std::string& value) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.name)
-}
-#if LANG_CXX11
-void FieldAccessInfo::set_name(::std::string&& value) {
- set_has_name();
- name_.SetNoArena(
- &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
- // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.FieldAccessInfo.name)
-}
-#endif
-void FieldAccessInfo::set_name(const char* value) {
- GOOGLE_DCHECK(value != NULL);
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
- // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.FieldAccessInfo.name)
-}
-void FieldAccessInfo::set_name(const char* value, size_t size) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.FieldAccessInfo.name)
-}
-::std::string* FieldAccessInfo::mutable_name() {
- set_has_name();
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.FieldAccessInfo.name)
- return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-::std::string* FieldAccessInfo::release_name() {
- // @@protoc_insertion_point(field_release:google.protobuf.compiler.FieldAccessInfo.name)
- clear_has_name();
- return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-void FieldAccessInfo::set_allocated_name(::std::string* name) {
- if (name != NULL) {
- set_has_name();
- } else {
- clear_has_name();
- }
- name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.FieldAccessInfo.name)
-}
-
-// optional uint64 getters_count = 2;
-bool FieldAccessInfo::has_getters_count() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-void FieldAccessInfo::set_has_getters_count() {
- _has_bits_[0] |= 0x00000002u;
-}
-void FieldAccessInfo::clear_has_getters_count() {
- _has_bits_[0] &= ~0x00000002u;
-}
-void FieldAccessInfo::clear_getters_count() {
- getters_count_ = GOOGLE_ULONGLONG(0);
- clear_has_getters_count();
-}
-::google::protobuf::uint64 FieldAccessInfo::getters_count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.getters_count)
- return getters_count_;
-}
-void FieldAccessInfo::set_getters_count(::google::protobuf::uint64 value) {
- set_has_getters_count();
- getters_count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.getters_count)
-}
-
-// optional uint64 setters_count = 3;
-bool FieldAccessInfo::has_setters_count() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
-}
-void FieldAccessInfo::set_has_setters_count() {
- _has_bits_[0] |= 0x00000004u;
-}
-void FieldAccessInfo::clear_has_setters_count() {
- _has_bits_[0] &= ~0x00000004u;
-}
-void FieldAccessInfo::clear_setters_count() {
- setters_count_ = GOOGLE_ULONGLONG(0);
- clear_has_setters_count();
-}
-::google::protobuf::uint64 FieldAccessInfo::setters_count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.setters_count)
- return setters_count_;
-}
-void FieldAccessInfo::set_setters_count(::google::protobuf::uint64 value) {
- set_has_setters_count();
- setters_count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.setters_count)
-}
-
-// optional uint64 configs_count = 4;
-bool FieldAccessInfo::has_configs_count() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
-}
-void FieldAccessInfo::set_has_configs_count() {
- _has_bits_[0] |= 0x00000008u;
-}
-void FieldAccessInfo::clear_has_configs_count() {
- _has_bits_[0] &= ~0x00000008u;
-}
-void FieldAccessInfo::clear_configs_count() {
- configs_count_ = GOOGLE_ULONGLONG(0);
- clear_has_configs_count();
-}
-::google::protobuf::uint64 FieldAccessInfo::configs_count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.configs_count)
- return configs_count_;
-}
-void FieldAccessInfo::set_configs_count(::google::protobuf::uint64 value) {
- set_has_configs_count();
- configs_count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.configs_count)
-}
-
-#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
-
-// ===================================================================
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const int MessageAccessInfo::kNameFieldNumber;
-const int MessageAccessInfo::kCountFieldNumber;
-const int MessageAccessInfo::kFieldFieldNumber;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
-
-MessageAccessInfo::MessageAccessInfo()
- : ::google::protobuf::Message(), _internal_metadata_(NULL) {
- if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults();
- }
- SharedCtor();
- // @@protoc_insertion_point(constructor:google.protobuf.compiler.MessageAccessInfo)
-}
-MessageAccessInfo::MessageAccessInfo(const MessageAccessInfo& from)
- : ::google::protobuf::Message(),
- _internal_metadata_(NULL),
- _has_bits_(from._has_bits_),
- _cached_size_(0),
- field_(from.field_) {
- _internal_metadata_.MergeFrom(from._internal_metadata_);
- name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (from.has_name()) {
- name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
- }
- count_ = from.count_;
- // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.MessageAccessInfo)
-}
-
-void MessageAccessInfo::SharedCtor() {
- _cached_size_ = 0;
- name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- count_ = GOOGLE_ULONGLONG(0);
-}
-
-MessageAccessInfo::~MessageAccessInfo() {
- // @@protoc_insertion_point(destructor:google.protobuf.compiler.MessageAccessInfo)
- SharedDtor();
-}
-
-void MessageAccessInfo::SharedDtor() {
- name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-
-void MessageAccessInfo::SetCachedSize(int size) const {
- GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
- _cached_size_ = size;
- GOOGLE_SAFE_CONCURRENT_WRITES_END();
-}
-const ::google::protobuf::Descriptor* MessageAccessInfo::descriptor() {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce();
- return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
-}
-
-const MessageAccessInfo& MessageAccessInfo::default_instance() {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults();
- return *internal_default_instance();
-}
-
-MessageAccessInfo* MessageAccessInfo::New(::google::protobuf::Arena* arena) const {
- MessageAccessInfo* n = new MessageAccessInfo;
- if (arena != NULL) {
- arena->Own(n);
- }
- return n;
-}
-
-void MessageAccessInfo::Clear() {
-// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.MessageAccessInfo)
- field_.Clear();
- if (has_name()) {
- GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
- (*name_.UnsafeRawStringPointer())->clear();
- }
- count_ = GOOGLE_ULONGLONG(0);
- _has_bits_.Clear();
- _internal_metadata_.Clear();
-}
-
-bool MessageAccessInfo::MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
- ::google::protobuf::uint32 tag;
- // @@protoc_insertion_point(parse_start:google.protobuf.compiler.MessageAccessInfo)
- for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
- tag = p.first;
- if (!p.second) goto handle_unusual;
- switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
- case 1: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(10u)) {
- DO_(::google::protobuf::internal::WireFormatLite::ReadString(
- input, this->mutable_name()));
- ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
- this->name().data(), static_cast<int>(this->name().length()),
- ::google::protobuf::internal::WireFormat::PARSE,
- "google.protobuf.compiler.MessageAccessInfo.name");
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- // optional uint64 count = 2;
- case 2: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(16u)) {
- set_has_count();
- DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
- ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
- input, &count_)));
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- // repeated .google.protobuf.compiler.FieldAccessInfo field = 3;
- case 3: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(26u)) {
- DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
- input, add_field()));
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- default: {
- handle_unusual:
- if (tag == 0 ||
- ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
- ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
- goto success;
- }
- DO_(::google::protobuf::internal::WireFormat::SkipField(
- input, tag, mutable_unknown_fields()));
- break;
- }
- }
- }
-success:
- // @@protoc_insertion_point(parse_success:google.protobuf.compiler.MessageAccessInfo)
- return true;
-failure:
- // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.MessageAccessInfo)
- return false;
-#undef DO_
-}
-
-void MessageAccessInfo::SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const {
- // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.MessageAccessInfo)
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- cached_has_bits = _has_bits_[0];
- // optional string name = 1;
- if (cached_has_bits & 0x00000001u) {
- ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
- this->name().data(), static_cast<int>(this->name().length()),
- ::google::protobuf::internal::WireFormat::SERIALIZE,
- "google.protobuf.compiler.MessageAccessInfo.name");
- ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
- 1, this->name(), output);
- }
-
- // optional uint64 count = 2;
- if (cached_has_bits & 0x00000002u) {
- ::google::protobuf::internal::WireFormatLite::WriteUInt64(2, this->count(), output);
- }
-
- // repeated .google.protobuf.compiler.FieldAccessInfo field = 3;
- for (unsigned int i = 0,
- n = static_cast<unsigned int>(this->field_size()); i < n; i++) {
- ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
- 3, this->field(static_cast<int>(i)), output);
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
- unknown_fields(), output);
- }
- // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.MessageAccessInfo)
-}
-
-::google::protobuf::uint8* MessageAccessInfo::InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* target) const {
- (void)deterministic; // Unused
- // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.MessageAccessInfo)
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- cached_has_bits = _has_bits_[0];
- // optional string name = 1;
- if (cached_has_bits & 0x00000001u) {
- ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
- this->name().data(), static_cast<int>(this->name().length()),
- ::google::protobuf::internal::WireFormat::SERIALIZE,
- "google.protobuf.compiler.MessageAccessInfo.name");
- target =
- ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
- 1, this->name(), target);
- }
-
- // optional uint64 count = 2;
- if (cached_has_bits & 0x00000002u) {
- target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(2, this->count(), target);
- }
-
- // repeated .google.protobuf.compiler.FieldAccessInfo field = 3;
- for (unsigned int i = 0,
- n = static_cast<unsigned int>(this->field_size()); i < n; i++) {
- target = ::google::protobuf::internal::WireFormatLite::
- InternalWriteMessageNoVirtualToArray(
- 3, this->field(static_cast<int>(i)), deterministic, target);
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
- unknown_fields(), target);
- }
- // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.MessageAccessInfo)
- return target;
-}
-
-size_t MessageAccessInfo::ByteSizeLong() const {
-// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.MessageAccessInfo)
- size_t total_size = 0;
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
- }
- // repeated .google.protobuf.compiler.FieldAccessInfo field = 3;
- {
- unsigned int count = static_cast<unsigned int>(this->field_size());
- total_size += 1UL * count;
- for (unsigned int i = 0; i < count; i++) {
- total_size +=
- ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
- this->field(static_cast<int>(i)));
- }
- }
-
- if (_has_bits_[0 / 32] & 3u) {
- // optional string name = 1;
- if (has_name()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->name());
- }
-
- // optional uint64 count = 2;
- if (has_count()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::UInt64Size(
- this->count());
- }
-
- }
- int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
- GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
- _cached_size_ = cached_size;
- GOOGLE_SAFE_CONCURRENT_WRITES_END();
- return total_size;
-}
-
-void MessageAccessInfo::MergeFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.MessageAccessInfo)
- GOOGLE_DCHECK_NE(&from, this);
- const MessageAccessInfo* source =
- ::google::protobuf::internal::DynamicCastToGenerated<const MessageAccessInfo>(
- &from);
- if (source == NULL) {
- // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.MessageAccessInfo)
- ::google::protobuf::internal::ReflectionOps::Merge(from, this);
- } else {
- // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.MessageAccessInfo)
- MergeFrom(*source);
- }
-}
-
-void MessageAccessInfo::MergeFrom(const MessageAccessInfo& from) {
-// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.MessageAccessInfo)
- GOOGLE_DCHECK_NE(&from, this);
- _internal_metadata_.MergeFrom(from._internal_metadata_);
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- field_.MergeFrom(from.field_);
- cached_has_bits = from._has_bits_[0];
- if (cached_has_bits & 3u) {
- if (cached_has_bits & 0x00000001u) {
- set_has_name();
- name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
- }
- if (cached_has_bits & 0x00000002u) {
- count_ = from.count_;
- }
- _has_bits_[0] |= cached_has_bits;
- }
-}
-
-void MessageAccessInfo::CopyFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.MessageAccessInfo)
- if (&from == this) return;
- Clear();
- MergeFrom(from);
-}
-
-void MessageAccessInfo::CopyFrom(const MessageAccessInfo& from) {
-// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.MessageAccessInfo)
- if (&from == this) return;
- Clear();
- MergeFrom(from);
-}
-
-bool MessageAccessInfo::IsInitialized() const {
- return true;
-}
-
-void MessageAccessInfo::Swap(MessageAccessInfo* other) {
- if (other == this) return;
- InternalSwap(other);
-}
-void MessageAccessInfo::InternalSwap(MessageAccessInfo* other) {
- field_.InternalSwap(&other->field_);
- name_.Swap(&other->name_);
- std::swap(count_, other->count_);
- std::swap(_has_bits_[0], other->_has_bits_[0]);
- _internal_metadata_.Swap(&other->_internal_metadata_);
- std::swap(_cached_size_, other->_cached_size_);
-}
-
-::google::protobuf::Metadata MessageAccessInfo::GetMetadata() const {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce();
- return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages];
-}
-
-#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// MessageAccessInfo
-
-// optional string name = 1;
-bool MessageAccessInfo::has_name() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-void MessageAccessInfo::set_has_name() {
- _has_bits_[0] |= 0x00000001u;
-}
-void MessageAccessInfo::clear_has_name() {
- _has_bits_[0] &= ~0x00000001u;
-}
-void MessageAccessInfo::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- clear_has_name();
-}
-const ::std::string& MessageAccessInfo::name() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.name)
- return name_.GetNoArena();
-}
-void MessageAccessInfo::set_name(const ::std::string& value) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.name)
-}
-#if LANG_CXX11
-void MessageAccessInfo::set_name(::std::string&& value) {
- set_has_name();
- name_.SetNoArena(
- &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
- // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.MessageAccessInfo.name)
-}
-#endif
-void MessageAccessInfo::set_name(const char* value) {
- GOOGLE_DCHECK(value != NULL);
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
- // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.MessageAccessInfo.name)
-}
-void MessageAccessInfo::set_name(const char* value, size_t size) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.MessageAccessInfo.name)
-}
-::std::string* MessageAccessInfo::mutable_name() {
- set_has_name();
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.name)
- return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-::std::string* MessageAccessInfo::release_name() {
- // @@protoc_insertion_point(field_release:google.protobuf.compiler.MessageAccessInfo.name)
- clear_has_name();
- return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-void MessageAccessInfo::set_allocated_name(::std::string* name) {
- if (name != NULL) {
- set_has_name();
- } else {
- clear_has_name();
- }
- name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.MessageAccessInfo.name)
-}
-
-// optional uint64 count = 2;
-bool MessageAccessInfo::has_count() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-void MessageAccessInfo::set_has_count() {
- _has_bits_[0] |= 0x00000002u;
-}
-void MessageAccessInfo::clear_has_count() {
- _has_bits_[0] &= ~0x00000002u;
-}
-void MessageAccessInfo::clear_count() {
- count_ = GOOGLE_ULONGLONG(0);
- clear_has_count();
-}
-::google::protobuf::uint64 MessageAccessInfo::count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.count)
- return count_;
-}
-void MessageAccessInfo::set_count(::google::protobuf::uint64 value) {
- set_has_count();
- count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.count)
-}
-
-// repeated .google.protobuf.compiler.FieldAccessInfo field = 3;
-int MessageAccessInfo::field_size() const {
- return field_.size();
-}
-void MessageAccessInfo::clear_field() {
- field_.Clear();
-}
-const ::google::protobuf::compiler::FieldAccessInfo& MessageAccessInfo::field(int index) const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.field)
- return field_.Get(index);
-}
-::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::mutable_field(int index) {
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.field)
- return field_.Mutable(index);
-}
-::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::add_field() {
- // @@protoc_insertion_point(field_add:google.protobuf.compiler.MessageAccessInfo.field)
- return field_.Add();
-}
-::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >*
-MessageAccessInfo::mutable_field() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.MessageAccessInfo.field)
- return &field_;
-}
-const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >&
-MessageAccessInfo::field() const {
- // @@protoc_insertion_point(field_list:google.protobuf.compiler.MessageAccessInfo.field)
- return field_;
-}
-
-#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
-
-// ===================================================================
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const int AccessInfo::kMessageFieldNumber;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
-
-AccessInfo::AccessInfo()
- : ::google::protobuf::Message(), _internal_metadata_(NULL) {
- if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults();
- }
- SharedCtor();
- // @@protoc_insertion_point(constructor:google.protobuf.compiler.AccessInfo)
-}
-AccessInfo::AccessInfo(const AccessInfo& from)
- : ::google::protobuf::Message(),
- _internal_metadata_(NULL),
- _has_bits_(from._has_bits_),
- _cached_size_(0),
- message_(from.message_) {
- _internal_metadata_.MergeFrom(from._internal_metadata_);
- // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.AccessInfo)
-}
-
-void AccessInfo::SharedCtor() {
- _cached_size_ = 0;
-}
-
-AccessInfo::~AccessInfo() {
- // @@protoc_insertion_point(destructor:google.protobuf.compiler.AccessInfo)
- SharedDtor();
-}
-
-void AccessInfo::SharedDtor() {
-}
-
-void AccessInfo::SetCachedSize(int size) const {
- GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
- _cached_size_ = size;
- GOOGLE_SAFE_CONCURRENT_WRITES_END();
-}
-const ::google::protobuf::Descriptor* AccessInfo::descriptor() {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce();
- return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
-}
-
-const AccessInfo& AccessInfo::default_instance() {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults();
- return *internal_default_instance();
-}
-
-AccessInfo* AccessInfo::New(::google::protobuf::Arena* arena) const {
- AccessInfo* n = new AccessInfo;
- if (arena != NULL) {
- arena->Own(n);
- }
- return n;
-}
-
-void AccessInfo::Clear() {
-// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.AccessInfo)
- message_.Clear();
- _has_bits_.Clear();
- _internal_metadata_.Clear();
-}
-
-bool AccessInfo::MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
- ::google::protobuf::uint32 tag;
- // @@protoc_insertion_point(parse_start:google.protobuf.compiler.AccessInfo)
- for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
- tag = p.first;
- if (!p.second) goto handle_unusual;
- switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // repeated .google.protobuf.compiler.MessageAccessInfo message = 1;
- case 1: {
- if (static_cast< ::google::protobuf::uint8>(tag) ==
- static_cast< ::google::protobuf::uint8>(10u)) {
- DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
- input, add_message()));
- } else {
- goto handle_unusual;
- }
- break;
- }
-
- default: {
- handle_unusual:
- if (tag == 0 ||
- ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
- ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
- goto success;
- }
- DO_(::google::protobuf::internal::WireFormat::SkipField(
- input, tag, mutable_unknown_fields()));
- break;
- }
- }
- }
-success:
- // @@protoc_insertion_point(parse_success:google.protobuf.compiler.AccessInfo)
- return true;
-failure:
- // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.AccessInfo)
- return false;
-#undef DO_
-}
-
-void AccessInfo::SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const {
- // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.AccessInfo)
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- // repeated .google.protobuf.compiler.MessageAccessInfo message = 1;
- for (unsigned int i = 0,
- n = static_cast<unsigned int>(this->message_size()); i < n; i++) {
- ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
- 1, this->message(static_cast<int>(i)), output);
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
- unknown_fields(), output);
- }
- // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.AccessInfo)
-}
-
-::google::protobuf::uint8* AccessInfo::InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* target) const {
- (void)deterministic; // Unused
- // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.AccessInfo)
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- // repeated .google.protobuf.compiler.MessageAccessInfo message = 1;
- for (unsigned int i = 0,
- n = static_cast<unsigned int>(this->message_size()); i < n; i++) {
- target = ::google::protobuf::internal::WireFormatLite::
- InternalWriteMessageNoVirtualToArray(
- 1, this->message(static_cast<int>(i)), deterministic, target);
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
- unknown_fields(), target);
- }
- // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.AccessInfo)
- return target;
-}
-
-size_t AccessInfo::ByteSizeLong() const {
-// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.AccessInfo)
- size_t total_size = 0;
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
- }
- // repeated .google.protobuf.compiler.MessageAccessInfo message = 1;
- {
- unsigned int count = static_cast<unsigned int>(this->message_size());
- total_size += 1UL * count;
- for (unsigned int i = 0; i < count; i++) {
- total_size +=
- ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
- this->message(static_cast<int>(i)));
- }
- }
-
- int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
- GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
- _cached_size_ = cached_size;
- GOOGLE_SAFE_CONCURRENT_WRITES_END();
- return total_size;
-}
-
-void AccessInfo::MergeFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.AccessInfo)
- GOOGLE_DCHECK_NE(&from, this);
- const AccessInfo* source =
- ::google::protobuf::internal::DynamicCastToGenerated<const AccessInfo>(
- &from);
- if (source == NULL) {
- // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.AccessInfo)
- ::google::protobuf::internal::ReflectionOps::Merge(from, this);
- } else {
- // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.AccessInfo)
- MergeFrom(*source);
- }
-}
-
-void AccessInfo::MergeFrom(const AccessInfo& from) {
-// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.AccessInfo)
- GOOGLE_DCHECK_NE(&from, this);
- _internal_metadata_.MergeFrom(from._internal_metadata_);
- ::google::protobuf::uint32 cached_has_bits = 0;
- (void) cached_has_bits;
-
- message_.MergeFrom(from.message_);
-}
-
-void AccessInfo::CopyFrom(const ::google::protobuf::Message& from) {
-// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.AccessInfo)
- if (&from == this) return;
- Clear();
- MergeFrom(from);
-}
-
-void AccessInfo::CopyFrom(const AccessInfo& from) {
-// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.AccessInfo)
- if (&from == this) return;
- Clear();
- MergeFrom(from);
-}
-
-bool AccessInfo::IsInitialized() const {
- return true;
-}
-
-void AccessInfo::Swap(AccessInfo* other) {
- if (other == this) return;
- InternalSwap(other);
-}
-void AccessInfo::InternalSwap(AccessInfo* other) {
- message_.InternalSwap(&other->message_);
- std::swap(_has_bits_[0], other->_has_bits_[0]);
- _internal_metadata_.Swap(&other->_internal_metadata_);
- std::swap(_cached_size_, other->_cached_size_);
-}
-
-::google::protobuf::Metadata AccessInfo::GetMetadata() const {
- protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce();
- return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages];
-}
-
-#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// AccessInfo
-
-// repeated .google.protobuf.compiler.MessageAccessInfo message = 1;
-int AccessInfo::message_size() const {
- return message_.size();
-}
-void AccessInfo::clear_message() {
- message_.Clear();
-}
-const ::google::protobuf::compiler::MessageAccessInfo& AccessInfo::message(int index) const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.AccessInfo.message)
- return message_.Get(index);
-}
-::google::protobuf::compiler::MessageAccessInfo* AccessInfo::mutable_message(int index) {
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.AccessInfo.message)
- return message_.Mutable(index);
-}
-::google::protobuf::compiler::MessageAccessInfo* AccessInfo::add_message() {
- // @@protoc_insertion_point(field_add:google.protobuf.compiler.AccessInfo.message)
- return message_.Add();
-}
-::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >*
-AccessInfo::mutable_message() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.AccessInfo.message)
- return &message_;
-}
-const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >&
-AccessInfo::message() const {
- // @@protoc_insertion_point(field_list:google.protobuf.compiler.AccessInfo.message)
- return message_;
-}
-
-#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
-
-// @@protoc_insertion_point(namespace_scope)
-
-} // namespace compiler
-} // namespace protobuf
-} // namespace google
-
-// @@protoc_insertion_point(global_scope)
diff --git a/src/google/protobuf/compiler/profile.pb.h b/src/google/protobuf/compiler/profile.pb.h
deleted file mode 100644
index b4931cf1..00000000
--- a/src/google/protobuf/compiler/profile.pb.h
+++ /dev/null
@@ -1,728 +0,0 @@
-// Generated by the protocol buffer compiler. DO NOT EDIT!
-// source: google/protobuf/compiler/profile.proto
-
-#ifndef PROTOBUF_google_2fprotobuf_2fcompiler_2fprofile_2eproto__INCLUDED
-#define PROTOBUF_google_2fprotobuf_2fcompiler_2fprofile_2eproto__INCLUDED
-
-#include <string>
-
-#include <google/protobuf/stubs/common.h>
-
-#if GOOGLE_PROTOBUF_VERSION < 3003000
-#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 3003002 < GOOGLE_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/io/coded_stream.h>
-#include <google/protobuf/arena.h>
-#include <google/protobuf/arenastring.h>
-#include <google/protobuf/generated_message_table_driven.h>
-#include <google/protobuf/generated_message_util.h>
-#include <google/protobuf/metadata.h>
-#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h> // IWYU pragma: export
-#include <google/protobuf/extension_set.h> // IWYU pragma: export
-#include <google/protobuf/unknown_field_set.h>
-// @@protoc_insertion_point(includes)
-namespace google {
-namespace protobuf {
-namespace compiler {
-class AccessInfo;
-class AccessInfoDefaultTypeInternal;
-LIBPROTOC_EXPORT extern AccessInfoDefaultTypeInternal _AccessInfo_default_instance_;
-class FieldAccessInfo;
-class FieldAccessInfoDefaultTypeInternal;
-LIBPROTOC_EXPORT extern FieldAccessInfoDefaultTypeInternal _FieldAccessInfo_default_instance_;
-class MessageAccessInfo;
-class MessageAccessInfoDefaultTypeInternal;
-LIBPROTOC_EXPORT extern MessageAccessInfoDefaultTypeInternal _MessageAccessInfo_default_instance_;
-} // namespace compiler
-} // namespace protobuf
-} // namespace google
-
-namespace google {
-namespace protobuf {
-namespace compiler {
-
-namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto {
-// Internal implementation detail -- do not call these.
-struct LIBPROTOC_EXPORT TableStruct {
- static const ::google::protobuf::internal::ParseTableField entries[];
- static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
- static const ::google::protobuf::internal::ParseTable schema[];
- static const ::google::protobuf::uint32 offsets[];
- static void InitDefaultsImpl();
- static void Shutdown();
-};
-void LIBPROTOC_EXPORT AddDescriptors();
-void LIBPROTOC_EXPORT InitDefaults();
-} // namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto
-
-// ===================================================================
-
-class LIBPROTOC_EXPORT FieldAccessInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.FieldAccessInfo) */ {
- public:
- FieldAccessInfo();
- virtual ~FieldAccessInfo();
-
- FieldAccessInfo(const FieldAccessInfo& from);
-
- inline FieldAccessInfo& operator=(const FieldAccessInfo& from) {
- CopyFrom(from);
- return *this;
- }
-
- inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
- return _internal_metadata_.unknown_fields();
- }
-
- inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
- return _internal_metadata_.mutable_unknown_fields();
- }
-
- static const ::google::protobuf::Descriptor* descriptor();
- static const FieldAccessInfo& default_instance();
-
- static inline const FieldAccessInfo* internal_default_instance() {
- return reinterpret_cast<const FieldAccessInfo*>(
- &_FieldAccessInfo_default_instance_);
- }
- static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
- 0;
-
- void Swap(FieldAccessInfo* other);
-
- // implements Message ----------------------------------------------
-
- inline FieldAccessInfo* New() const PROTOBUF_FINAL { return New(NULL); }
-
- FieldAccessInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
- void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
- void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
- void CopyFrom(const FieldAccessInfo& from);
- void MergeFrom(const FieldAccessInfo& from);
- void Clear() PROTOBUF_FINAL;
- bool IsInitialized() const PROTOBUF_FINAL;
-
- size_t ByteSizeLong() const PROTOBUF_FINAL;
- bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
- void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
- ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
- int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
- private:
- void SharedCtor();
- void SharedDtor();
- void SetCachedSize(int size) const PROTOBUF_FINAL;
- void InternalSwap(FieldAccessInfo* other);
- private:
- inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return NULL;
- }
- inline void* MaybeArenaPtr() const {
- return NULL;
- }
- public:
-
- ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
-
- // nested types ----------------------------------------------------
-
- // accessors -------------------------------------------------------
-
- // optional string name = 1;
- bool has_name() const;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- #if LANG_CXX11
- void set_name(::std::string&& value);
- #endif
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
- // optional uint64 getters_count = 2;
- bool has_getters_count() const;
- void clear_getters_count();
- static const int kGettersCountFieldNumber = 2;
- ::google::protobuf::uint64 getters_count() const;
- void set_getters_count(::google::protobuf::uint64 value);
-
- // optional uint64 setters_count = 3;
- bool has_setters_count() const;
- void clear_setters_count();
- static const int kSettersCountFieldNumber = 3;
- ::google::protobuf::uint64 setters_count() const;
- void set_setters_count(::google::protobuf::uint64 value);
-
- // optional uint64 configs_count = 4;
- bool has_configs_count() const;
- void clear_configs_count();
- static const int kConfigsCountFieldNumber = 4;
- ::google::protobuf::uint64 configs_count() const;
- void set_configs_count(::google::protobuf::uint64 value);
-
- // @@protoc_insertion_point(class_scope:google.protobuf.compiler.FieldAccessInfo)
- private:
- void set_has_name();
- void clear_has_name();
- void set_has_getters_count();
- void clear_has_getters_count();
- void set_has_setters_count();
- void clear_has_setters_count();
- void set_has_configs_count();
- void clear_has_configs_count();
-
- ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- ::google::protobuf::internal::HasBits<1> _has_bits_;
- mutable int _cached_size_;
- ::google::protobuf::internal::ArenaStringPtr name_;
- ::google::protobuf::uint64 getters_count_;
- ::google::protobuf::uint64 setters_count_;
- ::google::protobuf::uint64 configs_count_;
- friend struct protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::TableStruct;
-};
-// -------------------------------------------------------------------
-
-class LIBPROTOC_EXPORT MessageAccessInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.MessageAccessInfo) */ {
- public:
- MessageAccessInfo();
- virtual ~MessageAccessInfo();
-
- MessageAccessInfo(const MessageAccessInfo& from);
-
- inline MessageAccessInfo& operator=(const MessageAccessInfo& from) {
- CopyFrom(from);
- return *this;
- }
-
- inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
- return _internal_metadata_.unknown_fields();
- }
-
- inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
- return _internal_metadata_.mutable_unknown_fields();
- }
-
- static const ::google::protobuf::Descriptor* descriptor();
- static const MessageAccessInfo& default_instance();
-
- static inline const MessageAccessInfo* internal_default_instance() {
- return reinterpret_cast<const MessageAccessInfo*>(
- &_MessageAccessInfo_default_instance_);
- }
- static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
- 1;
-
- void Swap(MessageAccessInfo* other);
-
- // implements Message ----------------------------------------------
-
- inline MessageAccessInfo* New() const PROTOBUF_FINAL { return New(NULL); }
-
- MessageAccessInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
- void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
- void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
- void CopyFrom(const MessageAccessInfo& from);
- void MergeFrom(const MessageAccessInfo& from);
- void Clear() PROTOBUF_FINAL;
- bool IsInitialized() const PROTOBUF_FINAL;
-
- size_t ByteSizeLong() const PROTOBUF_FINAL;
- bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
- void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
- ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
- int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
- private:
- void SharedCtor();
- void SharedDtor();
- void SetCachedSize(int size) const PROTOBUF_FINAL;
- void InternalSwap(MessageAccessInfo* other);
- private:
- inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return NULL;
- }
- inline void* MaybeArenaPtr() const {
- return NULL;
- }
- public:
-
- ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
-
- // nested types ----------------------------------------------------
-
- // accessors -------------------------------------------------------
-
- // repeated .google.protobuf.compiler.FieldAccessInfo field = 3;
- int field_size() const;
- void clear_field();
- static const int kFieldFieldNumber = 3;
- const ::google::protobuf::compiler::FieldAccessInfo& field(int index) const;
- ::google::protobuf::compiler::FieldAccessInfo* mutable_field(int index);
- ::google::protobuf::compiler::FieldAccessInfo* add_field();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >*
- mutable_field();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >&
- field() const;
-
- // optional string name = 1;
- bool has_name() const;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- #if LANG_CXX11
- void set_name(::std::string&& value);
- #endif
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
- // optional uint64 count = 2;
- bool has_count() const;
- void clear_count();
- static const int kCountFieldNumber = 2;
- ::google::protobuf::uint64 count() const;
- void set_count(::google::protobuf::uint64 value);
-
- // @@protoc_insertion_point(class_scope:google.protobuf.compiler.MessageAccessInfo)
- private:
- void set_has_name();
- void clear_has_name();
- void set_has_count();
- void clear_has_count();
-
- ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- ::google::protobuf::internal::HasBits<1> _has_bits_;
- mutable int _cached_size_;
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo > field_;
- ::google::protobuf::internal::ArenaStringPtr name_;
- ::google::protobuf::uint64 count_;
- friend struct protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::TableStruct;
-};
-// -------------------------------------------------------------------
-
-class LIBPROTOC_EXPORT AccessInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.AccessInfo) */ {
- public:
- AccessInfo();
- virtual ~AccessInfo();
-
- AccessInfo(const AccessInfo& from);
-
- inline AccessInfo& operator=(const AccessInfo& from) {
- CopyFrom(from);
- return *this;
- }
-
- inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
- return _internal_metadata_.unknown_fields();
- }
-
- inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
- return _internal_metadata_.mutable_unknown_fields();
- }
-
- static const ::google::protobuf::Descriptor* descriptor();
- static const AccessInfo& default_instance();
-
- static inline const AccessInfo* internal_default_instance() {
- return reinterpret_cast<const AccessInfo*>(
- &_AccessInfo_default_instance_);
- }
- static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
- 2;
-
- void Swap(AccessInfo* other);
-
- // implements Message ----------------------------------------------
-
- inline AccessInfo* New() const PROTOBUF_FINAL { return New(NULL); }
-
- AccessInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
- void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
- void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
- void CopyFrom(const AccessInfo& from);
- void MergeFrom(const AccessInfo& from);
- void Clear() PROTOBUF_FINAL;
- bool IsInitialized() const PROTOBUF_FINAL;
-
- size_t ByteSizeLong() const PROTOBUF_FINAL;
- bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
- void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
- ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
- int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
- private:
- void SharedCtor();
- void SharedDtor();
- void SetCachedSize(int size) const PROTOBUF_FINAL;
- void InternalSwap(AccessInfo* other);
- private:
- inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return NULL;
- }
- inline void* MaybeArenaPtr() const {
- return NULL;
- }
- public:
-
- ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
-
- // nested types ----------------------------------------------------
-
- // accessors -------------------------------------------------------
-
- // repeated .google.protobuf.compiler.MessageAccessInfo message = 1;
- int message_size() const;
- void clear_message();
- static const int kMessageFieldNumber = 1;
- const ::google::protobuf::compiler::MessageAccessInfo& message(int index) const;
- ::google::protobuf::compiler::MessageAccessInfo* mutable_message(int index);
- ::google::protobuf::compiler::MessageAccessInfo* add_message();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >*
- mutable_message();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >&
- message() const;
-
- // @@protoc_insertion_point(class_scope:google.protobuf.compiler.AccessInfo)
- private:
-
- ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- ::google::protobuf::internal::HasBits<1> _has_bits_;
- mutable int _cached_size_;
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo > message_;
- friend struct protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::TableStruct;
-};
-// ===================================================================
-
-
-// ===================================================================
-
-#if !PROTOBUF_INLINE_NOT_IN_HEADERS
-// FieldAccessInfo
-
-// optional string name = 1;
-inline bool FieldAccessInfo::has_name() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-inline void FieldAccessInfo::set_has_name() {
- _has_bits_[0] |= 0x00000001u;
-}
-inline void FieldAccessInfo::clear_has_name() {
- _has_bits_[0] &= ~0x00000001u;
-}
-inline void FieldAccessInfo::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- clear_has_name();
-}
-inline const ::std::string& FieldAccessInfo::name() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.name)
- return name_.GetNoArena();
-}
-inline void FieldAccessInfo::set_name(const ::std::string& value) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.name)
-}
-#if LANG_CXX11
-inline void FieldAccessInfo::set_name(::std::string&& value) {
- set_has_name();
- name_.SetNoArena(
- &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
- // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.FieldAccessInfo.name)
-}
-#endif
-inline void FieldAccessInfo::set_name(const char* value) {
- GOOGLE_DCHECK(value != NULL);
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
- // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.FieldAccessInfo.name)
-}
-inline void FieldAccessInfo::set_name(const char* value, size_t size) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.FieldAccessInfo.name)
-}
-inline ::std::string* FieldAccessInfo::mutable_name() {
- set_has_name();
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.FieldAccessInfo.name)
- return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-inline ::std::string* FieldAccessInfo::release_name() {
- // @@protoc_insertion_point(field_release:google.protobuf.compiler.FieldAccessInfo.name)
- clear_has_name();
- return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-inline void FieldAccessInfo::set_allocated_name(::std::string* name) {
- if (name != NULL) {
- set_has_name();
- } else {
- clear_has_name();
- }
- name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.FieldAccessInfo.name)
-}
-
-// optional uint64 getters_count = 2;
-inline bool FieldAccessInfo::has_getters_count() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-inline void FieldAccessInfo::set_has_getters_count() {
- _has_bits_[0] |= 0x00000002u;
-}
-inline void FieldAccessInfo::clear_has_getters_count() {
- _has_bits_[0] &= ~0x00000002u;
-}
-inline void FieldAccessInfo::clear_getters_count() {
- getters_count_ = GOOGLE_ULONGLONG(0);
- clear_has_getters_count();
-}
-inline ::google::protobuf::uint64 FieldAccessInfo::getters_count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.getters_count)
- return getters_count_;
-}
-inline void FieldAccessInfo::set_getters_count(::google::protobuf::uint64 value) {
- set_has_getters_count();
- getters_count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.getters_count)
-}
-
-// optional uint64 setters_count = 3;
-inline bool FieldAccessInfo::has_setters_count() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
-}
-inline void FieldAccessInfo::set_has_setters_count() {
- _has_bits_[0] |= 0x00000004u;
-}
-inline void FieldAccessInfo::clear_has_setters_count() {
- _has_bits_[0] &= ~0x00000004u;
-}
-inline void FieldAccessInfo::clear_setters_count() {
- setters_count_ = GOOGLE_ULONGLONG(0);
- clear_has_setters_count();
-}
-inline ::google::protobuf::uint64 FieldAccessInfo::setters_count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.setters_count)
- return setters_count_;
-}
-inline void FieldAccessInfo::set_setters_count(::google::protobuf::uint64 value) {
- set_has_setters_count();
- setters_count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.setters_count)
-}
-
-// optional uint64 configs_count = 4;
-inline bool FieldAccessInfo::has_configs_count() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
-}
-inline void FieldAccessInfo::set_has_configs_count() {
- _has_bits_[0] |= 0x00000008u;
-}
-inline void FieldAccessInfo::clear_has_configs_count() {
- _has_bits_[0] &= ~0x00000008u;
-}
-inline void FieldAccessInfo::clear_configs_count() {
- configs_count_ = GOOGLE_ULONGLONG(0);
- clear_has_configs_count();
-}
-inline ::google::protobuf::uint64 FieldAccessInfo::configs_count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.configs_count)
- return configs_count_;
-}
-inline void FieldAccessInfo::set_configs_count(::google::protobuf::uint64 value) {
- set_has_configs_count();
- configs_count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.configs_count)
-}
-
-// -------------------------------------------------------------------
-
-// MessageAccessInfo
-
-// optional string name = 1;
-inline bool MessageAccessInfo::has_name() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-inline void MessageAccessInfo::set_has_name() {
- _has_bits_[0] |= 0x00000001u;
-}
-inline void MessageAccessInfo::clear_has_name() {
- _has_bits_[0] &= ~0x00000001u;
-}
-inline void MessageAccessInfo::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- clear_has_name();
-}
-inline const ::std::string& MessageAccessInfo::name() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.name)
- return name_.GetNoArena();
-}
-inline void MessageAccessInfo::set_name(const ::std::string& value) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.name)
-}
-#if LANG_CXX11
-inline void MessageAccessInfo::set_name(::std::string&& value) {
- set_has_name();
- name_.SetNoArena(
- &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
- // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.MessageAccessInfo.name)
-}
-#endif
-inline void MessageAccessInfo::set_name(const char* value) {
- GOOGLE_DCHECK(value != NULL);
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
- // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.MessageAccessInfo.name)
-}
-inline void MessageAccessInfo::set_name(const char* value, size_t size) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.MessageAccessInfo.name)
-}
-inline ::std::string* MessageAccessInfo::mutable_name() {
- set_has_name();
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.name)
- return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-inline ::std::string* MessageAccessInfo::release_name() {
- // @@protoc_insertion_point(field_release:google.protobuf.compiler.MessageAccessInfo.name)
- clear_has_name();
- return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-}
-inline void MessageAccessInfo::set_allocated_name(::std::string* name) {
- if (name != NULL) {
- set_has_name();
- } else {
- clear_has_name();
- }
- name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.MessageAccessInfo.name)
-}
-
-// optional uint64 count = 2;
-inline bool MessageAccessInfo::has_count() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-inline void MessageAccessInfo::set_has_count() {
- _has_bits_[0] |= 0x00000002u;
-}
-inline void MessageAccessInfo::clear_has_count() {
- _has_bits_[0] &= ~0x00000002u;
-}
-inline void MessageAccessInfo::clear_count() {
- count_ = GOOGLE_ULONGLONG(0);
- clear_has_count();
-}
-inline ::google::protobuf::uint64 MessageAccessInfo::count() const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.count)
- return count_;
-}
-inline void MessageAccessInfo::set_count(::google::protobuf::uint64 value) {
- set_has_count();
- count_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.count)
-}
-
-// repeated .google.protobuf.compiler.FieldAccessInfo field = 3;
-inline int MessageAccessInfo::field_size() const {
- return field_.size();
-}
-inline void MessageAccessInfo::clear_field() {
- field_.Clear();
-}
-inline const ::google::protobuf::compiler::FieldAccessInfo& MessageAccessInfo::field(int index) const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.field)
- return field_.Get(index);
-}
-inline ::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::mutable_field(int index) {
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.field)
- return field_.Mutable(index);
-}
-inline ::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::add_field() {
- // @@protoc_insertion_point(field_add:google.protobuf.compiler.MessageAccessInfo.field)
- return field_.Add();
-}
-inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >*
-MessageAccessInfo::mutable_field() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.MessageAccessInfo.field)
- return &field_;
-}
-inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >&
-MessageAccessInfo::field() const {
- // @@protoc_insertion_point(field_list:google.protobuf.compiler.MessageAccessInfo.field)
- return field_;
-}
-
-// -------------------------------------------------------------------
-
-// AccessInfo
-
-// repeated .google.protobuf.compiler.MessageAccessInfo message = 1;
-inline int AccessInfo::message_size() const {
- return message_.size();
-}
-inline void AccessInfo::clear_message() {
- message_.Clear();
-}
-inline const ::google::protobuf::compiler::MessageAccessInfo& AccessInfo::message(int index) const {
- // @@protoc_insertion_point(field_get:google.protobuf.compiler.AccessInfo.message)
- return message_.Get(index);
-}
-inline ::google::protobuf::compiler::MessageAccessInfo* AccessInfo::mutable_message(int index) {
- // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.AccessInfo.message)
- return message_.Mutable(index);
-}
-inline ::google::protobuf::compiler::MessageAccessInfo* AccessInfo::add_message() {
- // @@protoc_insertion_point(field_add:google.protobuf.compiler.AccessInfo.message)
- return message_.Add();
-}
-inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >*
-AccessInfo::mutable_message() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.AccessInfo.message)
- return &message_;
-}
-inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >&
-AccessInfo::message() const {
- // @@protoc_insertion_point(field_list:google.protobuf.compiler.AccessInfo.message)
- return message_;
-}
-
-#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
-// -------------------------------------------------------------------
-
-// -------------------------------------------------------------------
-
-
-// @@protoc_insertion_point(namespace_scope)
-
-
-} // namespace compiler
-} // namespace protobuf
-} // namespace google
-
-// @@protoc_insertion_point(global_scope)
-
-#endif // PROTOBUF_google_2fprotobuf_2fcompiler_2fprofile_2eproto__INCLUDED
diff --git a/src/google/protobuf/compiler/profile.proto b/src/google/protobuf/compiler/profile.proto
deleted file mode 100644
index 09ebe091..00000000
--- a/src/google/protobuf/compiler/profile.proto
+++ /dev/null
@@ -1,68 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// Author: seongkim@google.com (Seong Beom Kim)
-//
-// protoc (Protocol Compiler) can generate more efficient code
-// if it knows how a workload accesses fields of a message;
-// e.g. some much more frequently than others.
-//
-// Protos defined here describe the access information per message
-// and per field. Note that one can use any methods to collect
-// the access patterns like CPU profiling, instrumented build, etc.
-
-syntax = "proto2";
-
-package google.protobuf.compiler;
-
-// To convey the access pattern of a field, it classifies
-// the type of the accessor methods into getters, setters and
-// configs. Getters and setters read and write the field
-// respectively and other operations like checking if the field
-// exists are considered as configs.
-message FieldAccessInfo {
- optional string name = 1;
- optional uint64 getters_count = 2;
- optional uint64 setters_count = 3;
- optional uint64 configs_count = 4;
-}
-
-// "count" correlates with how many samples an access info has
-// for a message. High "count" means more confident optimization
-// based on the info.
-message MessageAccessInfo {
- optional string name = 1;
- optional uint64 count = 2;
- repeated FieldAccessInfo field = 3;
-}
-
-message AccessInfo {
- repeated MessageAccessInfo message = 1;
-}
diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc
index 21a7e158..97769835 100644
--- a/src/google/protobuf/compiler/python/python_generator.cc
+++ b/src/google/protobuf/compiler/python/python_generator.cc
@@ -63,11 +63,12 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/io/printer.h>
-#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/zero_copy_stream.h>
+#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+
namespace google {
namespace protobuf {
namespace compiler {
@@ -75,12 +76,21 @@ namespace python {
namespace {
+// Reimplemented here because we can't bring in
+// absl/strings/string_view_utils.h because it needs C++11.
+bool StrStartsWith(StringPiece sp, StringPiece x) {
+ return sp.size() >= x.size() && sp.substr(0, x.size()) == x;
+}
+bool StrEndsWith(StringPiece sp, StringPiece x) {
+ return sp.size() >= x.size() && sp.substr(sp.size() - x.size()) == x;
+}
+
// Returns a copy of |filename| with any trailing ".protodevel" or ".proto
// suffix stripped.
// TODO(robinson): Unify with copy in compiler/cpp/internal/helpers.cc.
string StripProto(const string& filename) {
- const char* suffix = HasSuffixString(filename, ".protodevel")
- ? ".protodevel" : ".proto";
+ const char* suffix =
+ StrEndsWith(filename, ".protodevel") ? ".protodevel" : ".proto";
return StripSuffixString(filename, suffix);
}
@@ -350,7 +360,9 @@ bool Generator::Generate(const FileDescriptor* file,
// can only be successfully parsed after we register corresponding
// extensions. Therefore we parse all options again here to recognize
// custom options that may be unknown when we define the descriptors.
+ // This does not apply to services because they are not used by extensions.
FixAllDescriptorOptions();
+ PrintServiceDescriptors();
if (HasGenericServices(file)) {
PrintServices();
}
@@ -562,9 +574,16 @@ void Generator::PrintMessageDescriptors() const {
}
}
-void Generator::PrintServices() const {
+void Generator::PrintServiceDescriptors() const {
for (int i = 0; i < file_->service_count(); ++i) {
PrintServiceDescriptor(*file_->service(i));
+ AddServiceToFileDescriptor(*file_->service(i));
+ printer_->Print("\n");
+ }
+}
+
+void Generator::PrintServices() const {
+ for (int i = 0; i < file_->service_count(); ++i) {
PrintServiceClass(*file_->service(i));
PrintServiceStub(*file_->service(i));
printer_->Print("\n");
@@ -628,7 +647,10 @@ void Generator::PrintServiceDescriptor(
}
printer_->Outdent();
- printer_->Print("])\n\n");
+ printer_->Print("])\n");
+ printer_->Print("_sym_db.RegisterServiceDescriptor($name$)\n", "name",
+ service_name);
+ printer_->Print("\n");
}
@@ -887,6 +909,18 @@ void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const {
printer_->Print(m, file_descriptor_template);
}
+void Generator::AddServiceToFileDescriptor(
+ const ServiceDescriptor& descriptor) const {
+ std::map<string, string> m;
+ m["descriptor_name"] = kDescriptorKey;
+ m["service_name"] = descriptor.name();
+ m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor);
+ const char file_descriptor_template[] =
+ "$descriptor_name$.services_by_name['$service_name$'] = "
+ "$service_descriptor_name$\n";
+ printer_->Print(m, file_descriptor_template);
+}
+
void Generator::AddEnumToFileDescriptor(
const EnumDescriptor& descriptor) const {
std::map<string, string> m;
diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h
index 594260af..2b5a028b 100644
--- a/src/google/protobuf/compiler/python/python_generator.h
+++ b/src/google/protobuf/compiler/python/python_generator.h
@@ -112,6 +112,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
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,
const FieldDescriptor& field,
const string& python_dict_name) const;
@@ -126,11 +127,12 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
void FixForeignFieldsInNestedExtensions(const Descriptor& descriptor) const;
void PrintServices() const;
+ void PrintServiceDescriptors() const;
void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const;
void PrintServiceClass(const ServiceDescriptor& descriptor) const;
void PrintServiceStub(const ServiceDescriptor& descriptor) const;
void PrintDescriptorKeyAndModuleName(
- const ServiceDescriptor& descriptor) const ;
+ const ServiceDescriptor& descriptor) const;
void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const;
string OptionsValue(const string& class_name,
diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc
index 933450fa..2e5a89ac 100644
--- a/src/google/protobuf/compiler/subprocess.cc
+++ b/src/google/protobuf/compiler/subprocess.cc
@@ -33,6 +33,7 @@
#include <google/protobuf/compiler/subprocess.h>
#include <algorithm>
+#include <cstring>
#include <iostream>
#ifndef _WIN32
@@ -47,11 +48,20 @@
#include <google/protobuf/message.h>
#include <google/protobuf/stubs/substitute.h>
-
namespace google {
namespace protobuf {
namespace compiler {
+namespace {
+char* portable_strdup(const char* s) {
+ char* ns = (char*) malloc(strlen(s) + 1);
+ if (ns != NULL) {
+ strcpy(ns, s);
+ }
+ return ns;
+}
+} // namespace
+
#ifdef _WIN32
static void CloseHandleOrDie(HANDLE handle) {
@@ -115,7 +125,7 @@ void Subprocess::Start(const string& program, SearchMode search_mode) {
}
// CreateProcess() mutates its second parameter. WTF?
- char* name_copy = strdup(program.c_str());
+ char* name_copy = portable_strdup(program.c_str());
// Create the process.
PROCESS_INFORMATION process_info;
@@ -299,7 +309,7 @@ void Subprocess::Start(const string& program, SearchMode search_mode) {
GOOGLE_CHECK(pipe(stdin_pipe) != -1);
GOOGLE_CHECK(pipe(stdout_pipe) != -1);
- char* argv[2] = { strdup(program.c_str()), NULL };
+ char* argv[2] = { portable_strdup(program.c_str()), NULL };
child_pid_ = fork();
if (child_pid_ == -1) {
@@ -347,7 +357,6 @@ void Subprocess::Start(const string& program, SearchMode search_mode) {
bool Subprocess::Communicate(const Message& input, Message* output,
string* error) {
-
GOOGLE_CHECK_NE(child_stdin_, -1) << "Must call Start() first.";
// The "sighandler_t" typedef is GNU-specific, so define our own.
diff --git a/src/google/protobuf/compiler/subprocess.h b/src/google/protobuf/compiler/subprocess.h
index 25138631..9d980b06 100644
--- a/src/google/protobuf/compiler/subprocess.h
+++ b/src/google/protobuf/compiler/subprocess.h
@@ -44,7 +44,6 @@
#include <string>
-
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/zip_output_unittest.sh b/src/google/protobuf/compiler/zip_output_unittest.sh
index 6fc7136d..f8597912 100755
--- a/src/google/protobuf/compiler/zip_output_unittest.sh
+++ b/src/google/protobuf/compiler/zip_output_unittest.sh
@@ -41,6 +41,8 @@ fail() {
TEST_TMPDIR=.
PROTOC=./protoc
+JAR=jar
+UNZIP=unzip
echo '
syntax = "proto2";
@@ -57,8 +59,9 @@ $PROTOC \
|| fail 'protoc failed.'
echo "Testing output to zip..."
-if unzip -h > /dev/null; then
- unzip -t $TEST_TMPDIR/testzip.zip > $TEST_TMPDIR/testzip.list || fail 'unzip failed.'
+if $UNZIP -h > /dev/null; then
+ $UNZIP -t $TEST_TMPDIR/testzip.zip > $TEST_TMPDIR/testzip.list \
+ || fail 'unzip failed.'
grep 'testing: testzip\.pb\.cc *OK$' $TEST_TMPDIR/testzip.list > /dev/null \
|| fail 'testzip.pb.cc not found in output zip.'
@@ -73,8 +76,14 @@ else
fi
echo "Testing output to jar..."
-if jar c $TEST_TMPDIR/testzip.proto > /dev/null; then
- jar tf $TEST_TMPDIR/testzip.jar > $TEST_TMPDIR/testzip.list || fail 'jar failed.'
+if $JAR c $TEST_TMPDIR/testzip.proto > /dev/null; then
+ $JAR tf $TEST_TMPDIR/testzip.jar > $TEST_TMPDIR/testzip.list \
+ || fail 'jar failed.'
+
+ # Check that -interface.jar timestamps are normalized:
+ if [[ "$(TZ=UTC $JAR tvf $TEST_TMPDIR/testzip.jar)" != *'Tue Jan 01 00:00:00 UTC 1980'* ]]; then
+ fail 'Zip did not contain normalized timestamps'
+ fi
grep '^test/jar/Foo\.java$' $TEST_TMPDIR/testzip.list > /dev/null \
|| fail 'Foo.java not found in output jar.'
diff --git a/src/google/protobuf/compiler/zip_writer.cc b/src/google/protobuf/compiler/zip_writer.cc
index 458cced2..1799af6a 100644
--- a/src/google/protobuf/compiler/zip_writer.cc
+++ b/src/google/protobuf/compiler/zip_writer.cc
@@ -70,6 +70,10 @@ namespace google {
namespace protobuf {
namespace compiler {
+// January 1, 1980 as a DOS date.
+// see https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
+static const uint16 kDosEpoch = 1 << 5 | 1;
+
static const uint32 kCRC32Table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -154,7 +158,7 @@ bool ZipWriter::Write(const string& filename, const string& contents) {
WriteShort(&output, 0); // flags
WriteShort(&output, 0); // compression method: stored
WriteShort(&output, 0); // last modified time
- WriteShort(&output, 0); // last modified date
+ WriteShort(&output, kDosEpoch); // last modified date
output.WriteLittleEndian32(info.crc32); // crc-32
output.WriteLittleEndian32(info.size); // compressed size
output.WriteLittleEndian32(info.size); // uncompressed size
@@ -185,7 +189,7 @@ bool ZipWriter::WriteDirectory() {
WriteShort(&output, 0); // flags
WriteShort(&output, 0); // compression method: stored
WriteShort(&output, 0); // last modified time
- WriteShort(&output, 0); // last modified date
+ WriteShort(&output, kDosEpoch); // last modified date
output.WriteLittleEndian32(crc32); // crc-32
output.WriteLittleEndian32(size); // compressed size
output.WriteLittleEndian32(size); // uncompressed size