|
|
|
@ -226,7 +226,7 @@ bool EmitFieldNonDefaultCondition(io::Printer* printer, |
|
|
|
|
} |
|
|
|
|
format.Indent(); |
|
|
|
|
return true; |
|
|
|
|
} else if (InRealOneof(field)) { |
|
|
|
|
} else if (field->real_containing_oneof()) { |
|
|
|
|
format("if (_internal_has_$name$()) {\n"); |
|
|
|
|
format.Indent(); |
|
|
|
|
return true; |
|
|
|
@ -282,7 +282,7 @@ void CollectMapInfo(const Options& options, const Descriptor* descriptor, |
|
|
|
|
bool HasPrivateHasMethod(const FieldDescriptor* field) { |
|
|
|
|
// Only for oneofs in message types with no field presence. has_$name$(),
|
|
|
|
|
// based on the oneof case, is still useful internally for generated code.
|
|
|
|
|
return (!HasFieldPresence(field->file()) && InRealOneof(field)); |
|
|
|
|
return (!HasFieldPresence(field->file()) && field->real_containing_oneof()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO(ckennelly): Cull these exclusions if/when these protos do not have
|
|
|
|
@ -597,7 +597,7 @@ MessageGenerator::MessageGenerator( |
|
|
|
|
|
|
|
|
|
if (IsWeak(field, options_)) { |
|
|
|
|
num_weak_fields_++; |
|
|
|
|
} else if (!InRealOneof(field)) { |
|
|
|
|
} else if (!field->real_containing_oneof()) { |
|
|
|
|
optimized_order_.push_back(field); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -677,7 +677,7 @@ void MessageGenerator::AddGenerators( |
|
|
|
|
void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) { |
|
|
|
|
Formatter format(printer, variables_); |
|
|
|
|
// optimized_fields_ does not contain fields where
|
|
|
|
|
// InRealOneof(field) == true
|
|
|
|
|
// field->real_containing_oneof()
|
|
|
|
|
// so we need to iterate over those as well.
|
|
|
|
|
//
|
|
|
|
|
// We place the non-oneof fields in optimized_order_, as that controls the
|
|
|
|
@ -689,7 +689,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) { |
|
|
|
|
ordered_fields.insert(ordered_fields.begin(), optimized_order_.begin(), |
|
|
|
|
optimized_order_.end()); |
|
|
|
|
for (auto field : FieldRange(descriptor_)) { |
|
|
|
|
if (!InRealOneof(field) && !field->options().weak() && |
|
|
|
|
if (!field->real_containing_oneof() && !field->options().weak() && |
|
|
|
|
IsFieldUsed(field, options_)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -922,7 +922,7 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field, |
|
|
|
|
|
|
|
|
|
format.Indent(); |
|
|
|
|
|
|
|
|
|
if (InRealOneof(field)) { |
|
|
|
|
if (field->real_containing_oneof()) { |
|
|
|
|
// Clear this field only if it is the active field in this oneof,
|
|
|
|
|
// otherwise ignore
|
|
|
|
|
format("if (_internal_has_$name$()) {\n"); |
|
|
|
@ -983,7 +983,7 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) { |
|
|
|
|
? ".weak" |
|
|
|
|
: ""); |
|
|
|
|
} |
|
|
|
|
} else if (InRealOneof(field)) { |
|
|
|
|
} else if (field->real_containing_oneof()) { |
|
|
|
|
format.Set("field_name", UnderscoresToCamelCase(field->name(), true)); |
|
|
|
|
format.Set("oneof_name", field->containing_oneof()->name()); |
|
|
|
|
format.Set("oneof_index", |
|
|
|
@ -1485,7 +1485,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { |
|
|
|
|
for (auto field : FieldRange(descriptor_)) { |
|
|
|
|
// set_has_***() generated in all oneofs.
|
|
|
|
|
if (!field->is_repeated() && !field->options().weak() && |
|
|
|
|
InRealOneof(field)) { |
|
|
|
|
field->real_containing_oneof()) { |
|
|
|
|
format("void set_has_$1$();\n", FieldName(field)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1594,12 +1594,11 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Generate _oneof_case_.
|
|
|
|
|
int count = RealOneofCount(descriptor_); |
|
|
|
|
if (count > 0) { |
|
|
|
|
if (descriptor_->real_oneof_decl_count() > 0) { |
|
|
|
|
format( |
|
|
|
|
"$uint32$ _oneof_case_[$1$];\n" |
|
|
|
|
"\n", |
|
|
|
|
count); |
|
|
|
|
descriptor_->real_oneof_decl_count()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (num_weak_fields_) { |
|
|
|
@ -1695,7 +1694,7 @@ bool MessageGenerator::GenerateParseTable(io::Printer* printer, size_t offset, |
|
|
|
|
format("PROTOBUF_FIELD_OFFSET($classtype$, _has_bits_),\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (RealOneofCount(descriptor_) > 0) { |
|
|
|
|
if (descriptor_->real_oneof_decl_count() > 0) { |
|
|
|
|
format("PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_),\n"); |
|
|
|
|
} else { |
|
|
|
|
format("-1, // no _oneof_case_\n"); |
|
|
|
@ -1755,7 +1754,7 @@ uint32 CalcFieldNum(const FieldGenerator& generator, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (InRealOneof(field)) { |
|
|
|
|
if (field->real_containing_oneof()) { |
|
|
|
|
return internal::FieldMetadata::CalculateType( |
|
|
|
|
type, internal::FieldMetadata::kOneOf); |
|
|
|
|
} else if (field->is_packed()) { |
|
|
|
@ -1764,7 +1763,7 @@ uint32 CalcFieldNum(const FieldGenerator& generator, |
|
|
|
|
} else if (field->is_repeated()) { |
|
|
|
|
return internal::FieldMetadata::CalculateType( |
|
|
|
|
type, internal::FieldMetadata::kRepeated); |
|
|
|
|
} else if (HasHasbit(field) || InRealOneof(field) || is_a_map) { |
|
|
|
|
} else if (HasHasbit(field) || field->real_containing_oneof() || is_a_map) { |
|
|
|
|
return internal::FieldMetadata::CalculateType( |
|
|
|
|
type, internal::FieldMetadata::kPresence); |
|
|
|
|
} else { |
|
|
|
@ -1859,7 +1858,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string classfieldname = FieldName(field); |
|
|
|
|
if (InRealOneof(field)) { |
|
|
|
|
if (field->real_containing_oneof()) { |
|
|
|
|
classfieldname = field->containing_oneof()->name(); |
|
|
|
|
} |
|
|
|
|
format.Set("field_name", classfieldname); |
|
|
|
@ -1895,7 +1894,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { |
|
|
|
|
type = internal::FieldMetadata::kSpecial; |
|
|
|
|
ptr = "reinterpret_cast<const void*>(::" + variables_["proto_ns"] + |
|
|
|
|
"::internal::LazyFieldSerializer"; |
|
|
|
|
if (InRealOneof(field)) { |
|
|
|
|
if (field->real_containing_oneof()) { |
|
|
|
|
ptr += "OneOf"; |
|
|
|
|
} else if (!HasHasbit(field)) { |
|
|
|
|
ptr += "NoPresence"; |
|
|
|
@ -1912,7 +1911,7 @@ int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { |
|
|
|
|
"reinterpret_cast<const " |
|
|
|
|
"void*>(::$proto_ns$::internal::WeakFieldSerializer)},\n", |
|
|
|
|
tag); |
|
|
|
|
} else if (InRealOneof(field)) { |
|
|
|
|
} else if (field->real_containing_oneof()) { |
|
|
|
|
format.Set("oneofoffset", |
|
|
|
|
sizeof(uint32) * field->containing_oneof()->index()); |
|
|
|
|
format( |
|
|
|
@ -1972,10 +1971,10 @@ void MessageGenerator::GenerateDefaultInstanceInitializer( |
|
|
|
|
|
|
|
|
|
if (!field->is_repeated() && !IsLazy(field, options_) && |
|
|
|
|
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
|
(!InRealOneof(field) || |
|
|
|
|
(!field->real_containing_oneof() || |
|
|
|
|
HasDescriptorMethods(descriptor_->file(), options_))) { |
|
|
|
|
std::string name; |
|
|
|
|
if (InRealOneof(field) || field->options().weak()) { |
|
|
|
|
if (field->real_containing_oneof() || field->options().weak()) { |
|
|
|
|
name = "_" + classname_ + "_default_instance_."; |
|
|
|
|
} else { |
|
|
|
|
name = |
|
|
|
@ -2007,7 +2006,7 @@ void MessageGenerator::GenerateDefaultInstanceInitializer( |
|
|
|
|
" $1$::internal_default_instance());\n", |
|
|
|
|
FieldMessageTypeName(field, options_)); |
|
|
|
|
} |
|
|
|
|
} else if (InRealOneof(field) && |
|
|
|
|
} else if (field->real_containing_oneof() && |
|
|
|
|
HasDescriptorMethods(descriptor_->file(), options_)) { |
|
|
|
|
field_generators_.get(field).GenerateConstructorCode(printer); |
|
|
|
|
} |
|
|
|
@ -2118,7 +2117,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { |
|
|
|
|
Formatter::SaveState saver(&format); |
|
|
|
|
std::map<std::string, std::string> vars; |
|
|
|
|
SetCommonFieldVariables(field, &vars, options_); |
|
|
|
|
if (InRealOneof(field)) { |
|
|
|
|
if (field->real_containing_oneof()) { |
|
|
|
|
SetCommonOneofFieldVariables(field, &vars); |
|
|
|
|
} |
|
|
|
|
format.AddMap(vars); |
|
|
|
@ -2129,7 +2128,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) { |
|
|
|
|
GenerateStructors(printer); |
|
|
|
|
format("\n"); |
|
|
|
|
|
|
|
|
|
if (RealOneofCount(descriptor_) > 0) { |
|
|
|
|
if (descriptor_->real_oneof_decl_count() > 0) { |
|
|
|
|
GenerateOneofClear(printer); |
|
|
|
|
format("\n"); |
|
|
|
|
} |
|
|
|
@ -2258,8 +2257,8 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) { |
|
|
|
|
|
|
|
|
|
processing_type |= static_cast<unsigned>( |
|
|
|
|
field->is_repeated() ? internal::kRepeatedMask : 0); |
|
|
|
|
processing_type |= |
|
|
|
|
static_cast<unsigned>(InRealOneof(field) ? internal::kOneofMask : 0); |
|
|
|
|
processing_type |= static_cast<unsigned>( |
|
|
|
|
field->real_containing_oneof() ? internal::kOneofMask : 0); |
|
|
|
|
|
|
|
|
|
if (field->is_map()) { |
|
|
|
|
processing_type = internal::TYPE_MAP; |
|
|
|
@ -2269,7 +2268,7 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) { |
|
|
|
|
WireFormat::TagSize(field->number(), field->type()); |
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> vars; |
|
|
|
|
if (InRealOneof(field)) { |
|
|
|
|
if (field->real_containing_oneof()) { |
|
|
|
|
vars["name"] = field->containing_oneof()->name(); |
|
|
|
|
vars["presence"] = StrCat(field->containing_oneof()->index()); |
|
|
|
|
} else { |
|
|
|
@ -2400,7 +2399,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets( |
|
|
|
|
} else { |
|
|
|
|
format("~0u, // no _extensions_\n"); |
|
|
|
|
} |
|
|
|
|
if (RealOneofCount(descriptor_) > 0) { |
|
|
|
|
if (descriptor_->real_oneof_decl_count() > 0) { |
|
|
|
|
format("PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_[0]),\n"); |
|
|
|
|
} else { |
|
|
|
|
format("~0u, // no _oneof_case_\n"); |
|
|
|
@ -2418,13 +2417,13 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets( |
|
|
|
|
} |
|
|
|
|
const int kNumGenericOffsets = 5; // the number of fixed offsets above
|
|
|
|
|
const size_t offsets = kNumGenericOffsets + descriptor_->field_count() + |
|
|
|
|
RealOneofCount(descriptor_) - num_stripped; |
|
|
|
|
descriptor_->real_oneof_decl_count() - num_stripped; |
|
|
|
|
size_t entries = offsets; |
|
|
|
|
for (auto field : FieldRange(descriptor_)) { |
|
|
|
|
if (!IsFieldUsed(field, options_)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (InRealOneof(field) || field->options().weak()) { |
|
|
|
|
if (field->real_containing_oneof() || field->options().weak()) { |
|
|
|
|
format("offsetof($classtype$DefaultTypeInternal, $1$_)", |
|
|
|
|
FieldName(field)); |
|
|
|
|
} else { |
|
|
|
@ -2444,7 +2443,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets( |
|
|
|
|
format("PROTOBUF_FIELD_OFFSET($classtype$, $1$_),\n", oneof->name()); |
|
|
|
|
count++; |
|
|
|
|
} |
|
|
|
|
GOOGLE_CHECK_EQ(count, RealOneofCount(descriptor_)); |
|
|
|
|
GOOGLE_CHECK_EQ(count, descriptor_->real_oneof_decl_count()); |
|
|
|
|
|
|
|
|
|
if (IsMapEntryMessage(descriptor_)) { |
|
|
|
|
entries += 2; |
|
|
|
@ -2656,7 +2655,7 @@ void MessageGenerator::GenerateStructors(io::Printer* printer) { |
|
|
|
|
for (auto field : optimized_order_) { |
|
|
|
|
GOOGLE_DCHECK(IsFieldUsed(field, options_)); |
|
|
|
|
bool has_arena_constructor = field->is_repeated(); |
|
|
|
|
if (!InRealOneof(field) && |
|
|
|
|
if (!field->real_containing_oneof() && |
|
|
|
|
(IsLazy(field, options_) || IsStringPiece(field, options_))) { |
|
|
|
|
has_arena_constructor = true; |
|
|
|
|
} |
|
|
|
@ -3122,8 +3121,7 @@ void MessageGenerator::GenerateSwap(io::Printer* printer) { |
|
|
|
|
format("swap($1$_, other->$1$_);\n", oneof->name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int count = RealOneofCount(descriptor_); |
|
|
|
|
for (int i = 0; i < count; i++) { |
|
|
|
|
for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) { |
|
|
|
|
format("swap(_oneof_case_[$1$], other->_oneof_case_[$1$]);\n", i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3572,7 +3570,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody( |
|
|
|
|
if (eager_ || MustFlush(field)) { |
|
|
|
|
Flush(); |
|
|
|
|
} |
|
|
|
|
if (!InRealOneof(field)) { |
|
|
|
|
if (!field->real_containing_oneof()) { |
|
|
|
|
// TODO(ckennelly): Defer non-oneof fields similarly to oneof fields.
|
|
|
|
|
|
|
|
|
|
if (!field->options().weak() && !field->is_repeated() && !eager_) { |
|
|
|
@ -4014,7 +4012,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* printer) { |
|
|
|
|
} else if (field->options().weak()) { |
|
|
|
|
continue; |
|
|
|
|
} else { |
|
|
|
|
GOOGLE_CHECK(!InRealOneof(field)); |
|
|
|
|
GOOGLE_CHECK(!field->real_containing_oneof()); |
|
|
|
|
format( |
|
|
|
|
"if (_internal_has_$1$()) {\n" |
|
|
|
|
" if (!$1$_->IsInitialized()) return false;\n" |
|
|
|
@ -4054,7 +4052,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* printer) { |
|
|
|
|
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && |
|
|
|
|
!ShouldIgnoreRequiredFieldCheck(field, options_) && |
|
|
|
|
scc_analyzer_->HasRequiredFields(field->message_type())) { |
|
|
|
|
GOOGLE_CHECK(!(field->options().weak() || !InRealOneof(field))); |
|
|
|
|
GOOGLE_CHECK(!(field->options().weak() || !field->real_containing_oneof())); |
|
|
|
|
if (field->options().weak()) { |
|
|
|
|
// Just skip.
|
|
|
|
|
} else { |
|
|
|
|