aboutsummaryrefslogtreecommitdiffstats
path: root/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_enum_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum_field.cc100
1 files changed, 15 insertions, 85 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
index 20b18ad..91ce493 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+++ b/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
@@ -46,13 +46,11 @@ namespace cpp {
namespace {
void SetEnumVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
- const Options& options) {
- SetCommonFieldVariables(descriptor, variables, options);
+ map<string, string>* variables) {
+ SetCommonFieldVariables(descriptor, variables);
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
@@ -60,10 +58,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
// ===================================================================
EnumFieldGenerator::
-EnumFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
+EnumFieldGenerator(const FieldDescriptor* descriptor)
: descriptor_(descriptor) {
- SetEnumVariables(descriptor, &variables_, options);
+ SetEnumVariables(descriptor, &variables_);
}
EnumFieldGenerator::~EnumFieldGenerator() {}
@@ -84,14 +81,12 @@ void EnumFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer) const {
printer->Print(variables_,
"inline $type$ $classname$::$name$() const {\n"
- " // @@protoc_insertion_point(field_get:$full_name$)\n"
" return static_cast< $type$ >($name$_);\n"
"}\n"
"inline void $classname$::set_$name$($type$ value) {\n"
- " assert($type$_IsValid(value));\n"
- " set_has_$name$();\n"
+ " GOOGLE_DCHECK($type$_IsValid(value));\n"
+ " _set_bit($index$);\n"
" $name$_ = value;\n"
- " // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n");
}
@@ -124,15 +119,10 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
" input, &value)));\n"
"if ($type$_IsValid(value)) {\n"
" set_$name$(static_cast< $type$ >(value));\n");
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (HasUnknownFields(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(variables_,
"}\n");
@@ -161,57 +151,10 @@ 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) const {
- printer->Print(variables_,
- "inline $type$ $classname$::$name$() const {\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"
- " assert($type$_IsValid(value));\n"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " }\n"
- " $oneof_prefix$$name$_ = value;\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)
+RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor)
: descriptor_(descriptor) {
- SetEnumVariables(descriptor, &variables_, options);
+ SetEnumVariables(descriptor, &variables_);
}
RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {}
@@ -220,8 +163,7 @@ void RepeatedEnumFieldGenerator::
GeneratePrivateMembers(io::Printer* printer) const {
printer->Print(variables_,
"::google::protobuf::RepeatedField<int> $name$_;\n");
- if (descriptor_->options().packed()
- && HasGeneratedMethods(descriptor_->file())) {
+ if (descriptor_->options().packed() && HasGeneratedMethods(descriptor_->file())) {
printer->Print(variables_,
"mutable int _$name$_cached_byte_size_;\n");
}
@@ -242,28 +184,23 @@ void RepeatedEnumFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer) const {
printer->Print(variables_,
"inline $type$ $classname$::$name$(int index) const {\n"
- " // @@protoc_insertion_point(field_get:$full_name$)\n"
" return static_cast< $type$ >($name$_.Get(index));\n"
"}\n"
"inline void $classname$::set_$name$(int index, $type$ value) {\n"
- " assert($type$_IsValid(value));\n"
+ " GOOGLE_DCHECK($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"
- " assert($type$_IsValid(value));\n"
+ " GOOGLE_DCHECK($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"
"$classname$::$name$() const {\n"
- " // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $name$_;\n"
"}\n"
"inline ::google::protobuf::RepeatedField<int>*\n"
"$classname$::mutable_$name$() {\n"
- " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
" return &$name$_;\n"
"}\n");
}
@@ -298,15 +235,10 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
" input, &value)));\n"
"if ($type$_IsValid(value)) {\n"
" add_$name$(static_cast< $type$ >(value));\n");
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (HasUnknownFields(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");
}
@@ -413,9 +345,7 @@ GenerateByteSize(io::Printer* printer) const {
" total_size += $tag_size$ +\n"
" ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n"
"}\n"
- "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n"
"_$name$_cached_byte_size_ = data_size;\n"
- "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n"
"total_size += data_size;\n");
} else {
printer->Print(variables_,