|
|
|
@ -233,6 +233,9 @@ std::string MapValueSize(upb::FieldDefPtr map_field, absl::string_view expr) { |
|
|
|
|
|
|
|
|
|
std::string FieldInitializer(const DefPoolPair& pools, upb::FieldDefPtr field, |
|
|
|
|
const Options& options); |
|
|
|
|
std::string FieldInitializerStrong(const DefPoolPair& pools, |
|
|
|
|
upb::FieldDefPtr field, |
|
|
|
|
const Options& options); |
|
|
|
|
|
|
|
|
|
void DumpEnumValues(upb::EnumDefPtr desc, Output& output) { |
|
|
|
|
std::vector<upb::EnumValDefPtr> values; |
|
|
|
@ -466,7 +469,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, resolved_name, MapKeyCType(field), MapValueCType(field), |
|
|
|
|
FieldInitializer(pools, field, options), MapKeySize(field, "key"), |
|
|
|
|
FieldInitializerStrong(pools, field, options), MapKeySize(field, "key"), |
|
|
|
|
MapValueSize(field, "*val")); |
|
|
|
|
output( |
|
|
|
|
R"cc( |
|
|
|
@ -478,7 +481,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), msg_name, resolved_name, |
|
|
|
|
FieldInitializer(pools, field, options)); |
|
|
|
|
FieldInitializerStrong(pools, field, options)); |
|
|
|
|
// Generate private getter returning a upb_Map or NULL for immutable and
|
|
|
|
|
// a upb_Map for mutable.
|
|
|
|
|
//
|
|
|
|
@ -497,7 +500,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, resolved_name, kMapGetterPostfix, kMutableMapGetterPostfix, |
|
|
|
|
FieldInitializer(pools, field, options), |
|
|
|
|
FieldInitializerStrong(pools, field, options), |
|
|
|
|
MapKeySize(field, MapKeyCType(field)), |
|
|
|
|
MapValueSize(field, MapValueCType(field))); |
|
|
|
|
} |
|
|
|
@ -538,10 +541,10 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), // $0
|
|
|
|
|
msg_name, // $1
|
|
|
|
|
ResolveFieldName(field, field_names), // $2
|
|
|
|
|
FieldInitializer(pools, field, options) // #3
|
|
|
|
|
CTypeConst(field), // $0
|
|
|
|
|
msg_name, // $1
|
|
|
|
|
ResolveFieldName(field, field_names), // $2
|
|
|
|
|
FieldInitializerStrong(pools, field, options) // #3
|
|
|
|
|
); |
|
|
|
|
// Generate private getter returning array or NULL for immutable and upb_Array
|
|
|
|
|
// for mutable.
|
|
|
|
@ -569,12 +572,12 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
return arr; |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), // $0
|
|
|
|
|
msg_name, // $1
|
|
|
|
|
ResolveFieldName(field, field_names), // $2
|
|
|
|
|
FieldInitializer(pools, field, options), // $3
|
|
|
|
|
kRepeatedFieldArrayGetterPostfix, // $4
|
|
|
|
|
kRepeatedFieldMutableArrayGetterPostfix // $5
|
|
|
|
|
CTypeConst(field), // $0
|
|
|
|
|
msg_name, // $1
|
|
|
|
|
ResolveFieldName(field, field_names), // $2
|
|
|
|
|
FieldInitializerStrong(pools, field, options), // $3
|
|
|
|
|
kRepeatedFieldArrayGetterPostfix, // $4
|
|
|
|
|
kRepeatedFieldMutableArrayGetterPostfix // $5
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -595,7 +598,7 @@ void GenerateScalarGetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CTypeConst(field), msg_name, field_name, FieldDefault(field), |
|
|
|
|
FieldInitializer(pools, field, Options)); |
|
|
|
|
FieldInitializerStrong(pools, field, Options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GenerateGetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
@ -640,7 +643,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, resolved_name, MapKeyCType(field), MapValueCType(field), |
|
|
|
|
FieldInitializer(pools, field, options), MapKeySize(field, "key"), |
|
|
|
|
FieldInitializerStrong(pools, field, options), MapKeySize(field, "key"), |
|
|
|
|
MapValueSize(field, "val")); |
|
|
|
|
output( |
|
|
|
|
R"cc( |
|
|
|
@ -663,7 +666,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CType(field), msg_name, resolved_name, |
|
|
|
|
FieldInitializer(pools, field, options)); |
|
|
|
|
FieldInitializerStrong(pools, field, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
@ -686,7 +689,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CType(field), msg_name, resolved_name, |
|
|
|
|
FieldInitializer(pools, field, options)); |
|
|
|
|
FieldInitializerStrong(pools, field, options)); |
|
|
|
|
output( |
|
|
|
|
R"cc( |
|
|
|
|
UPB_INLINE $0* $1_resize_$2($1* msg, size_t size, upb_Arena* arena) { |
|
|
|
@ -717,7 +720,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
)cc", |
|
|
|
|
MessageName(field.message_type()), msg_name, resolved_name, |
|
|
|
|
MessageMiniTableRef(field.message_type(), options), |
|
|
|
|
FieldInitializer(pools, field, options)); |
|
|
|
|
FieldInitializerStrong(pools, field, options)); |
|
|
|
|
} else { |
|
|
|
|
output( |
|
|
|
|
R"cc( |
|
|
|
@ -735,7 +738,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
CType(field), msg_name, resolved_name, |
|
|
|
|
FieldInitializer(pools, field, options)); |
|
|
|
|
FieldInitializerStrong(pools, field, options)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -768,7 +771,7 @@ void GenerateNonRepeatedSetters(upb::FieldDefPtr field, |
|
|
|
|
} |
|
|
|
|
)cc", |
|
|
|
|
msg_name, field_name, CType(field), |
|
|
|
|
FieldInitializer(pools, field, options)); |
|
|
|
|
FieldInitializerStrong(pools, field, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Message fields also have a Msg_mutable_foo() accessor that will create
|
|
|
|
@ -1007,6 +1010,31 @@ std::string FieldInitializer(upb::FieldDefPtr field, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string StrongReferenceSingle(upb::FieldDefPtr field) { |
|
|
|
|
if (!field.message_type()) return ""; |
|
|
|
|
return absl::Substitute(" UPB_PRIVATE(_upb_MiniTable_StrongReference)(&$0)", |
|
|
|
|
MessageInitName(field.message_type())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string StrongReference(upb::FieldDefPtr field) { |
|
|
|
|
if (field.IsMap() && |
|
|
|
|
field.message_type().FindFieldByNumber(2).IsSubMessage()) { |
|
|
|
|
return StrongReferenceSingle(field) + ";\n" + |
|
|
|
|
StrongReferenceSingle(field.message_type().FindFieldByNumber(2)); |
|
|
|
|
} else { |
|
|
|
|
return StrongReferenceSingle(field); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::string FieldInitializerStrong(const DefPoolPair& pools, |
|
|
|
|
upb::FieldDefPtr field, |
|
|
|
|
const Options& options) { |
|
|
|
|
std::string ret = FieldInitializer(pools, field, options); |
|
|
|
|
if (!options.bootstrap && field.IsSubMessage()) { |
|
|
|
|
ret += ";\n" + StrongReference(field); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string FieldInitializer(const DefPoolPair& pools, upb::FieldDefPtr field, |
|
|
|
|
const Options& options) { |
|
|
|
|
return FieldInitializer(field, pools.GetField64(field), |
|
|
|
|