Commit f68b251f authored by Josh Humphries's avatar Josh Humphries Committed by Adam Cozzette

don't emit location for label unless label is present

parent 2849a799
...@@ -902,10 +902,8 @@ bool Parser::ParseMessageField(FieldDescriptorProto* field, ...@@ -902,10 +902,8 @@ bool Parser::ParseMessageField(FieldDescriptorProto* field,
const LocationRecorder& field_location, const LocationRecorder& field_location,
const FileDescriptorProto* containing_file) { const FileDescriptorProto* containing_file) {
{ {
LocationRecorder location(field_location,
FieldDescriptorProto::kLabelFieldNumber);
FieldDescriptorProto::Label label; FieldDescriptorProto::Label label;
if (ParseLabel(&label, containing_file)) { if (ParseLabel(&label, field_location, containing_file)) {
field->set_label(label); field->set_label(label);
if (label == FieldDescriptorProto::LABEL_OPTIONAL && if (label == FieldDescriptorProto::LABEL_OPTIONAL &&
syntax_identifier_ == "proto3") { syntax_identifier_ == "proto3") {
...@@ -2206,18 +2204,22 @@ bool Parser::ParseMethodOptions(const LocationRecorder& parent_location, ...@@ -2206,18 +2204,22 @@ bool Parser::ParseMethodOptions(const LocationRecorder& parent_location,
// ------------------------------------------------------------------- // -------------------------------------------------------------------
bool Parser::ParseLabel(FieldDescriptorProto::Label* label, bool Parser::ParseLabel(FieldDescriptorProto::Label* label,
const LocationRecorder& field_location,
const FileDescriptorProto* containing_file) { const FileDescriptorProto* containing_file) {
if (!LookingAt("optional") && !LookingAt("repeated") && !LookingAt("required")) {
return false;
}
LocationRecorder location(field_location,
FieldDescriptorProto::kLabelFieldNumber);
if (TryConsume("optional")) { if (TryConsume("optional")) {
*label = FieldDescriptorProto::LABEL_OPTIONAL; *label = FieldDescriptorProto::LABEL_OPTIONAL;
return true;
} else if (TryConsume("repeated")) { } else if (TryConsume("repeated")) {
*label = FieldDescriptorProto::LABEL_REPEATED; *label = FieldDescriptorProto::LABEL_REPEATED;
return true; } else {
} else if (TryConsume("required")) { Consume("required");
*label = FieldDescriptorProto::LABEL_REQUIRED; *label = FieldDescriptorProto::LABEL_REQUIRED;
return true;
} }
return false; return true;
} }
bool Parser::ParseType(FieldDescriptorProto::Type* type, bool Parser::ParseType(FieldDescriptorProto::Type* type,
......
...@@ -440,6 +440,7 @@ class PROTOBUF_EXPORT Parser { ...@@ -440,6 +440,7 @@ class PROTOBUF_EXPORT Parser {
// Parse "required", "optional", or "repeated" and fill in "label" // Parse "required", "optional", or "repeated" and fill in "label"
// with the value. Returns true if such a label is consumed. // with the value. Returns true if such a label is consumed.
bool ParseLabel(FieldDescriptorProto::Label* label, bool ParseLabel(FieldDescriptorProto::Label* label,
const LocationRecorder& field_location,
const FileDescriptorProto* containing_file); const FileDescriptorProto* containing_file);
// Parse a type name and fill in "type" (if it is a primitive) or // Parse a type name and fill in "type" (if it is a primitive) or
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment