|
|
|
@ -39,6 +39,7 @@ |
|
|
|
|
#include "google/protobuf/compiler/plugin.h" |
|
|
|
|
#include "google/protobuf/descriptor.h" |
|
|
|
|
#include "google/protobuf/descriptor.pb.h" |
|
|
|
|
#include "google/protobuf/descriptor_legacy.h" |
|
|
|
|
#include "google/protobuf/io/printer.h" |
|
|
|
|
#include "google/protobuf/io/zero_copy_stream.h" |
|
|
|
|
|
|
|
|
@ -79,7 +80,8 @@ std::string GetOutputFilename(absl::string_view proto_file) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string LabelForField(const FieldDescriptor* field) { |
|
|
|
|
if (field->has_optional_keyword() && field->containing_oneof() != nullptr) { |
|
|
|
|
if (FieldDescriptorLegacy(field).has_optional_keyword() && |
|
|
|
|
field->containing_oneof() != nullptr) { |
|
|
|
|
return "proto3_optional"; |
|
|
|
|
} |
|
|
|
|
switch (field->label()) { |
|
|
|
@ -114,13 +116,13 @@ std::string TypeName(const FieldDescriptor* field) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string StringifySyntax(FileDescriptor::Syntax syntax) { |
|
|
|
|
std::string StringifySyntax(FileDescriptorLegacy::Syntax syntax) { |
|
|
|
|
switch (syntax) { |
|
|
|
|
case FileDescriptor::SYNTAX_PROTO2: |
|
|
|
|
case FileDescriptorLegacy::Syntax::SYNTAX_PROTO2: |
|
|
|
|
return "proto2"; |
|
|
|
|
case FileDescriptor::SYNTAX_PROTO3: |
|
|
|
|
case FileDescriptorLegacy::Syntax::SYNTAX_PROTO3: |
|
|
|
|
return "proto3"; |
|
|
|
|
case FileDescriptor::SYNTAX_UNKNOWN: |
|
|
|
|
case FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN: |
|
|
|
|
default: |
|
|
|
|
ABSL_LOG(FATAL) << "Unsupported syntax; this generator only supports " |
|
|
|
|
"proto2 and proto3 syntax."; |
|
|
|
@ -474,7 +476,7 @@ bool GenerateDslDescriptor(const FileDescriptor* file, io::Printer* printer, |
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Print("add_file(\"$filename$\", :syntax => :$syntax$) do\n", |
|
|
|
|
"filename", file->name(), "syntax", |
|
|
|
|
StringifySyntax(file->syntax())); |
|
|
|
|
StringifySyntax(FileDescriptorLegacy(file).syntax())); |
|
|
|
|
printer->Indent(); |
|
|
|
|
for (int i = 0; i < file->message_type_count(); i++) { |
|
|
|
|
if (!GenerateMessage(file->message_type(i), printer, error)) { |
|
|
|
@ -557,7 +559,8 @@ bool Generator::Generate( |
|
|
|
|
const std::string& parameter, |
|
|
|
|
GeneratorContext* generator_context, |
|
|
|
|
std::string* error) const { |
|
|
|
|
if (file->syntax() == FileDescriptor::SYNTAX_UNKNOWN) { |
|
|
|
|
if (FileDescriptorLegacy(file).syntax() == |
|
|
|
|
FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN) { |
|
|
|
|
*error = "Invalid or unsupported proto syntax"; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|