attempting to upgrade to proto 3.5

This commit is contained in:
Kevin Darby committed 2018-12-28 16:02:52 +00:00
1 parent eb1b42a5e8
commit cc3510c6c2
368 files changed
+35764 -24867

No files matched your search

@@ -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;
@@ -1117,7 +1151,7 @@ void Generator::PrintFieldDescriptor(
" has_default_value=$has_default_value$, default_value=$default_value$,\n"
" message_type=None, enum_type=None, containing_type=None,\n"
" is_extension=$is_extension$, extension_scope=None,\n"
" options=$options$$json_name$)";
" options=$options$$json_name$, file=DESCRIPTOR)";
printer_->Print(m, field_descriptor_decl);
}