Index: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc |
diff --git a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc |
index 8c21ed2396082433f771ae4e7fafaf36d2fc4eb0..6e1620d4d2e3c6d72ef211518fef462557f8fbe8 100644 |
--- a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc |
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// https://developers.google.com/protocol-buffers/ |
+// http://code.google.com/p/protobuf/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -51,8 +51,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, |
SetCommonFieldVariables(descriptor, variables, options); |
const EnumValueDescriptor* default_value = descriptor->default_value_enum(); |
(*variables)["type"] = ClassName(descriptor->enum_type(), true); |
- (*variables)["default"] = Int32ToString(default_value->number()); |
- (*variables)["full_name"] = descriptor->full_name(); |
+ (*variables)["default"] = SimpleItoa(default_value->number()); |
} |
} // namespace |
@@ -76,29 +75,20 @@ GeneratePrivateMembers(io::Printer* printer) const { |
void EnumFieldGenerator:: |
GenerateAccessorDeclarations(io::Printer* printer) const { |
printer->Print(variables_, |
- "$type$ $name$() const$deprecation$;\n" |
- "void set_$name$($type$ value)$deprecation$;\n"); |
+ "inline $type$ $name$() const$deprecation$;\n" |
+ "inline void set_$name$($type$ value)$deprecation$;\n"); |
} |
void EnumFieldGenerator:: |
-GenerateInlineAccessorDefinitions(io::Printer* printer, |
- bool is_inline) const { |
- map<string, string> variables(variables_); |
- variables["inline"] = is_inline ? "inline" : ""; |
- printer->Print(variables, |
- "$inline$ $type$ $classname$::$name$() const {\n" |
- " // @@protoc_insertion_point(field_get:$full_name$)\n" |
+GenerateInlineAccessorDefinitions(io::Printer* printer) const { |
+ printer->Print(variables_, |
+ "inline $type$ $classname$::$name$() const {\n" |
" return static_cast< $type$ >($name$_);\n" |
"}\n" |
- "$inline$ void $classname$::set_$name$($type$ value) {\n"); |
- if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
- printer->Print(variables, |
- " assert($type$_IsValid(value));\n"); |
- } |
- printer->Print(variables, |
- " $set_hasbit$\n" |
+ "inline void $classname$::set_$name$($type$ value) {\n" |
+ " assert($type$_IsValid(value));\n" |
+ " set_has_$name$();\n" |
" $name$_ = value;\n" |
- " // @@protoc_insertion_point(field_set:$full_name$)\n" |
"}\n"); |
} |
@@ -128,27 +118,16 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { |
"int value;\n" |
"DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" |
" int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(\n" |
- " input, &value)));\n"); |
- if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
- printer->Print(variables_, |
- "set_$name$(static_cast< $type$ >(value));\n"); |
- } else { |
- printer->Print(variables_, |
- "if ($type$_IsValid(value)) {\n" |
- " set_$name$(static_cast< $type$ >(value));\n"); |
- if (UseUnknownFieldSet(descriptor_->file())) { |
- printer->Print(variables_, |
- "} else {\n" |
- " mutable_unknown_fields()->AddVarint($number$, value);\n"); |
- } else { |
- printer->Print( |
- "} else {\n" |
- " unknown_fields_stream.WriteVarint32(tag);\n" |
- " unknown_fields_stream.WriteVarint32(value);\n"); |
- } |
+ " input, &value)));\n" |
+ "if ($type$_IsValid(value)) {\n" |
+ " set_$name$(static_cast< $type$ >(value));\n"); |
+ if (HasUnknownFields(descriptor_->file())) { |
printer->Print(variables_, |
- "}\n"); |
+ "} else {\n" |
+ " mutable_unknown_fields()->AddVarint($number$, value);\n"); |
} |
+ printer->Print(variables_, |
+ "}\n"); |
} |
void EnumFieldGenerator:: |
@@ -174,61 +153,6 @@ GenerateByteSize(io::Printer* printer) const { |
// =================================================================== |
-EnumOneofFieldGenerator:: |
-EnumOneofFieldGenerator(const FieldDescriptor* descriptor, |
- const Options& options) |
- : EnumFieldGenerator(descriptor, options) { |
- SetCommonOneofFieldVariables(descriptor, &variables_); |
-} |
- |
-EnumOneofFieldGenerator::~EnumOneofFieldGenerator() {} |
- |
-void EnumOneofFieldGenerator:: |
-GenerateInlineAccessorDefinitions(io::Printer* printer, |
- bool is_inline) const { |
- map<string, string> variables(variables_); |
- variables["inline"] = is_inline ? "inline" : ""; |
- printer->Print(variables, |
- "$inline$ $type$ $classname$::$name$() const {\n" |
- " // @@protoc_insertion_point(field_get:$full_name$)\n" |
- " if (has_$name$()) {\n" |
- " return static_cast< $type$ >($oneof_prefix$$name$_);\n" |
- " }\n" |
- " return static_cast< $type$ >($default$);\n" |
- "}\n" |
- "$inline$ void $classname$::set_$name$($type$ value) {\n"); |
- if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
- printer->Print(variables, |
- " assert($type$_IsValid(value));\n"); |
- } |
- printer->Print(variables, |
- " if (!has_$name$()) {\n" |
- " clear_$oneof_name$();\n" |
- " set_has_$name$();\n" |
- " }\n" |
- " $oneof_prefix$$name$_ = value;\n" |
- " // @@protoc_insertion_point(field_set:$full_name$)\n" |
- "}\n"); |
-} |
- |
-void EnumOneofFieldGenerator:: |
-GenerateClearingCode(io::Printer* printer) const { |
- printer->Print(variables_, "$oneof_prefix$$name$_ = $default$;\n"); |
-} |
- |
-void EnumOneofFieldGenerator:: |
-GenerateSwappingCode(io::Printer* printer) const { |
- // Don't print any swapping code. Swapping the union will swap this field. |
-} |
- |
-void EnumOneofFieldGenerator:: |
-GenerateConstructorCode(io::Printer* printer) const { |
- printer->Print(variables_, |
- " $classname$_default_oneof_instance_->$name$_ = $default$;\n"); |
-} |
- |
-// =================================================================== |
- |
RepeatedEnumFieldGenerator:: |
RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, |
const Options& options) |
@@ -242,8 +166,7 @@ void RepeatedEnumFieldGenerator:: |
GeneratePrivateMembers(io::Printer* printer) const { |
printer->Print(variables_, |
"::google::protobuf::RepeatedField<int> $name$_;\n"); |
- if (descriptor_->is_packed() |
- && HasGeneratedMethods(descriptor_->file())) { |
+ if (descriptor_->options().packed() && HasGeneratedMethods(descriptor_->file())) { |
printer->Print(variables_, |
"mutable int _$name$_cached_byte_size_;\n"); |
} |
@@ -252,51 +175,35 @@ GeneratePrivateMembers(io::Printer* printer) const { |
void RepeatedEnumFieldGenerator:: |
GenerateAccessorDeclarations(io::Printer* printer) const { |
printer->Print(variables_, |
- "$type$ $name$(int index) const$deprecation$;\n" |
- "void set_$name$(int index, $type$ value)$deprecation$;\n" |
- "void add_$name$($type$ value)$deprecation$;\n"); |
+ "inline $type$ $name$(int index) const$deprecation$;\n" |
+ "inline void set_$name$(int index, $type$ value)$deprecation$;\n" |
+ "inline void add_$name$($type$ value)$deprecation$;\n"); |
printer->Print(variables_, |
- "const ::google::protobuf::RepeatedField<int>& $name$() const$deprecation$;\n" |
- "::google::protobuf::RepeatedField<int>* mutable_$name$()$deprecation$;\n"); |
+ "inline const ::google::protobuf::RepeatedField<int>& $name$() const$deprecation$;\n" |
+ "inline ::google::protobuf::RepeatedField<int>* mutable_$name$()$deprecation$;\n"); |
} |
void RepeatedEnumFieldGenerator:: |
-GenerateInlineAccessorDefinitions(io::Printer* printer, |
- bool is_inline) const { |
- map<string, string> variables(variables_); |
- variables["inline"] = is_inline ? "inline" : ""; |
- printer->Print(variables, |
- "$inline$ $type$ $classname$::$name$(int index) const {\n" |
- " // @@protoc_insertion_point(field_get:$full_name$)\n" |
+GenerateInlineAccessorDefinitions(io::Printer* printer) const { |
+ printer->Print(variables_, |
+ "inline $type$ $classname$::$name$(int index) const {\n" |
" return static_cast< $type$ >($name$_.Get(index));\n" |
"}\n" |
- "$inline$ void $classname$::set_$name$(int index, $type$ value) {\n"); |
- if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
- printer->Print(variables, |
- " assert($type$_IsValid(value));\n"); |
- } |
- printer->Print(variables, |
+ "inline void $classname$::set_$name$(int index, $type$ value) {\n" |
+ " assert($type$_IsValid(value));\n" |
" $name$_.Set(index, value);\n" |
- " // @@protoc_insertion_point(field_set:$full_name$)\n" |
"}\n" |
- "$inline$ void $classname$::add_$name$($type$ value) {\n"); |
- if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
- printer->Print(variables, |
- " assert($type$_IsValid(value));\n"); |
- } |
- printer->Print(variables, |
+ "inline void $classname$::add_$name$($type$ value) {\n" |
+ " assert($type$_IsValid(value));\n" |
" $name$_.Add(value);\n" |
- " // @@protoc_insertion_point(field_add:$full_name$)\n" |
"}\n"); |
- printer->Print(variables, |
- "$inline$ const ::google::protobuf::RepeatedField<int>&\n" |
+ printer->Print(variables_, |
+ "inline const ::google::protobuf::RepeatedField<int>&\n" |
"$classname$::$name$() const {\n" |
- " // @@protoc_insertion_point(field_list:$full_name$)\n" |
" return $name$_;\n" |
"}\n" |
- "$inline$ ::google::protobuf::RepeatedField<int>*\n" |
+ "inline ::google::protobuf::RepeatedField<int>*\n" |
"$classname$::mutable_$name$() {\n" |
- " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" |
" return &$name$_;\n" |
"}\n"); |
} |
@@ -313,7 +220,7 @@ GenerateMergingCode(io::Printer* printer) const { |
void RepeatedEnumFieldGenerator:: |
GenerateSwappingCode(io::Printer* printer) const { |
- printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); |
+ printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n"); |
} |
void RepeatedEnumFieldGenerator:: |
@@ -328,59 +235,27 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { |
"int value;\n" |
"DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" |
" int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(\n" |
- " input, &value)));\n"); |
- if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
+ " input, &value)));\n" |
+ "if ($type$_IsValid(value)) {\n" |
+ " add_$name$(static_cast< $type$ >(value));\n"); |
+ if (HasUnknownFields(descriptor_->file())) { |
printer->Print(variables_, |
- "add_$name$(static_cast< $type$ >(value));\n"); |
- } else { |
- printer->Print(variables_, |
- "if ($type$_IsValid(value)) {\n" |
- " add_$name$(static_cast< $type$ >(value));\n"); |
- if (UseUnknownFieldSet(descriptor_->file())) { |
- printer->Print(variables_, |
- "} else {\n" |
- " mutable_unknown_fields()->AddVarint($number$, value);\n"); |
- } else { |
- printer->Print( |
- "} else {\n" |
- " unknown_fields_stream.WriteVarint32(tag);\n" |
- " unknown_fields_stream.WriteVarint32(value);\n"); |
- } |
- printer->Print("}\n"); |
+ "} else {\n" |
+ " mutable_unknown_fields()->AddVarint($number$, value);\n"); |
} |
+ printer->Print("}\n"); |
} |
void RepeatedEnumFieldGenerator:: |
GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { |
- if (!descriptor_->is_packed()) { |
- // This path is rarely executed, so we use a non-inlined implementation. |
- if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
- printer->Print(variables_, |
- "DO_((::google::protobuf::internal::" |
- "WireFormatLite::ReadPackedEnumPreserveUnknowns(\n" |
- " input,\n" |
- " $number$,\n" |
- " NULL,\n" |
- " NULL,\n" |
- " this->mutable_$name$())));\n"); |
- } else if (UseUnknownFieldSet(descriptor_->file())) { |
- printer->Print(variables_, |
- "DO_((::google::protobuf::internal::WireFormatLite::ReadPackedEnumPreserveUnknowns(\n" |
- " input,\n" |
- " $number$,\n" |
- " $type$_IsValid,\n" |
- " mutable_unknown_fields(),\n" |
- " this->mutable_$name$())));\n"); |
- } else { |
- printer->Print(variables_, |
- "DO_((::google::protobuf::internal::" |
- "WireFormatLite::ReadPackedEnumPreserveUnknowns(\n" |
- " input,\n" |
- " $number$,\n" |
- " $type$_IsValid,\n" |
- " &unknown_fields_stream,\n" |
- " this->mutable_$name$())));\n"); |
- } |
+ if (!descriptor_->options().packed()) { |
+ // We use a non-inlined implementation in this case, since this path will |
+ // rarely be executed. |
+ printer->Print(variables_, |
+ "DO_((::google::protobuf::internal::WireFormatLite::ReadPackedEnumNoInline(\n" |
+ " input,\n" |
+ " &$type$_IsValid,\n" |
+ " this->mutable_$name$())));\n"); |
} else { |
printer->Print(variables_, |
"::google::protobuf::uint32 length;\n" |
@@ -391,27 +266,10 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { |
" int value;\n" |
" DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" |
" int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(\n" |
- " input, &value)));\n"); |
- if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
- printer->Print(variables_, |
- " add_$name$(static_cast< $type$ >(value));\n"); |
- } else { |
- printer->Print(variables_, |
+ " input, &value)));\n" |
" if ($type$_IsValid(value)) {\n" |
" add_$name$(static_cast< $type$ >(value));\n" |
- " } else {\n"); |
- if (UseUnknownFieldSet(descriptor_->file())) { |
- printer->Print(variables_, |
- " mutable_unknown_fields()->AddVarint($number$, value);\n"); |
- } else { |
- printer->Print(variables_, |
- " unknown_fields_stream.WriteVarint32(tag);\n" |
- " unknown_fields_stream.WriteVarint32(value);\n"); |
- } |
- printer->Print( |
- " }\n"); |
- } |
- printer->Print(variables_, |
+ " }\n" |
"}\n" |
"input->PopLimit(limit);\n"); |
} |
@@ -419,7 +277,7 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { |
void RepeatedEnumFieldGenerator:: |
GenerateSerializeWithCachedSizes(io::Printer* printer) const { |
- if (descriptor_->is_packed()) { |
+ if (descriptor_->options().packed()) { |
// Write the tag and the size. |
printer->Print(variables_, |
"if (this->$name$_size() > 0) {\n" |
@@ -432,7 +290,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const { |
} |
printer->Print(variables_, |
"for (int i = 0; i < this->$name$_size(); i++) {\n"); |
- if (descriptor_->is_packed()) { |
+ if (descriptor_->options().packed()) { |
printer->Print(variables_, |
" ::google::protobuf::internal::WireFormatLite::WriteEnumNoTag(\n" |
" this->$name$(i), output);\n"); |
@@ -446,7 +304,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const { |
void RepeatedEnumFieldGenerator:: |
GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { |
- if (descriptor_->is_packed()) { |
+ if (descriptor_->options().packed()) { |
// Write the tag and the size. |
printer->Print(variables_, |
"if (this->$name$_size() > 0) {\n" |
@@ -460,7 +318,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { |
} |
printer->Print(variables_, |
"for (int i = 0; i < this->$name$_size(); i++) {\n"); |
- if (descriptor_->is_packed()) { |
+ if (descriptor_->options().packed()) { |
printer->Print(variables_, |
" target = ::google::protobuf::internal::WireFormatLite::WriteEnumNoTagToArray(\n" |
" this->$name$(i), target);\n"); |
@@ -484,7 +342,7 @@ GenerateByteSize(io::Printer* printer) const { |
" this->$name$(i));\n" |
"}\n"); |
- if (descriptor_->is_packed()) { |
+ if (descriptor_->options().packed()) { |
printer->Print(variables_, |
"if (data_size > 0) {\n" |
" total_size += $tag_size$ +\n" |