@ -227,6 +227,9 @@ std::string CTypeConst(const protobuf::FieldDescriptor* field) {
return CTypeInternal ( field , true ) ;
return CTypeInternal ( field , true ) ;
}
}
std : : string FieldInitializer ( const FileLayout & layout ,
const protobuf : : FieldDescriptor * field ) ;
void DumpEnumValues ( const protobuf : : EnumDescriptor * desc , Output & output ) {
void DumpEnumValues ( const protobuf : : EnumDescriptor * desc , Output & output ) {
std : : vector < const protobuf : : EnumValueDescriptor * > values ;
std : : vector < const protobuf : : EnumValueDescriptor * > values ;
for ( int i = 0 ; i < desc - > value_count ( ) ; i + + ) {
for ( int i = 0 ; i < desc - > value_count ( ) ; i + + ) {
@ -256,7 +259,7 @@ void GenerateExtensionInHeader(const protobuf::FieldDescriptor* ext,
output (
output (
R " cc(
R " cc(
UPB_INLINE bool $ 0 _has_ $ 1 ( const struct $ 2 * msg ) {
UPB_INLINE bool $ 0 _has_ $ 1 ( const struct $ 2 * msg ) {
return _upb_Message_Getext ( msg , & $ 3 ) ! = NULL ;
return _upb_MiniTable_HasExtensionField ( msg , & $ 3 ) ;
}
}
) cc " ,
) cc " ,
ExtensionIdentBase ( ext ) , ext - > name ( ) , MessageName ( ext - > containing_type ( ) ) ,
ExtensionIdentBase ( ext ) , ext - > name ( ) , MessageName ( ext - > containing_type ( ) ) ,
@ -375,32 +378,35 @@ void GenerateHazzer(const protobuf::FieldDescriptor* field,
const NameToFieldDescriptorMap & field_names ,
const NameToFieldDescriptorMap & field_names ,
Output & output ) {
Output & output ) {
std : : string resolved_name = ResolveFieldName ( field , field_names ) ;
std : : string resolved_name = ResolveFieldName ( field , field_names ) ;
if ( layout . HasHasbit ( field ) ) {
if ( field - > has_presence ( ) ) {
output (
output (
R " cc(
R " cc(
UPB_INLINE bool $ 0 _has_ $ 1 ( const $ 0 * msg ) {
UPB_INLINE bool $ 0 _has_ $ 1 ( const $ 0 * msg ) {
return _upb_hasbit ( msg , $ 2 ) ;
const upb_MiniTableField field = $ 2 ;
return _upb_MiniTable_HasNonExtensionField ( msg , & field ) ;
}
}
) cc " ,
) cc " ,
msg_name , resolved_name , layout . GetHasbitIndex ( field ) ) ;
msg_name , resolved_name , FieldInitializer ( layout , field ) ) ;
} else if ( field - > real_containing_oneof ( ) ) {
} else if ( field - > is_map ( ) ) {
// TODO(b/259616267): remove.
output (
output (
R " cc(
R " cc(
UPB_INLINE bool $ 0 _has_ $ 1 ( const $ 0 * msg ) {
UPB_INLINE bool $ 0 _has_ $ 1 ( const $ 0 * msg ) {
return _upb_getoneofcase ( msg , $ 2 ) = = $ 3 ;
return $ 0 _ $ 1 _size ( msg ) ! = 0 ;
}
}
) cc " ,
) cc " ,
msg_name , resolved_name ,
msg_name , resolved_name ) ;
layout . GetOneofCaseOffset ( field - > real_containing_oneof ( ) ) ,
} else if ( field - > is_repeated ( ) ) {
field - > number ( ) ) ;
// TODO(b/259616267): remove.
} else if ( field - > message_type ( ) ) {
output (
output (
R " cc(
R " cc(
UPB_INLINE bool $ 0 _has_ $ 1 ( const $ 0 * msg ) {
UPB_INLINE bool $ 0 _has_ $ 1 ( const $ 0 * msg ) {
return _upb_has_submsg_nohasbit ( msg , $ 2 ) ;
size_t size ;
$ 0 _ $ 1 ( msg , & size ) ;
return size ! = 0 ;
}
}
) cc " ,
) cc " ,
msg_name , resolved_name , layout . GetFieldOffset ( field ) ) ;
msg_name , resolved_name ) ;
}
}
}
}
@ -592,9 +598,6 @@ void GenerateRepeatedGetters(const protobuf::FieldDescriptor* field,
layout . GetFieldOffset ( field ) ) ;
layout . GetFieldOffset ( field ) ) ;
}
}
std : : string FieldInitializer ( const FileLayout & layout ,
const protobuf : : FieldDescriptor * field ) ;
void GenerateScalarGetters ( const protobuf : : FieldDescriptor * field ,
void GenerateScalarGetters ( const protobuf : : FieldDescriptor * field ,
const FileLayout & layout , absl : : string_view msg_name ,
const FileLayout & layout , absl : : string_view msg_name ,
const NameToFieldDescriptorMap & field_names ,
const NameToFieldDescriptorMap & field_names ,
@ -798,13 +801,13 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message,
auto field_names = CreateFieldNameMap ( message ) ;
auto field_names = CreateFieldNameMap ( message ) ;
for ( auto field : FieldNumberOrder ( message ) ) {
for ( auto field : FieldNumberOrder ( message ) ) {
GenerateHazzer ( field , layout , msg_name , field_names , output ) ;
if ( field - > is_repeated ( ) ) {
if ( field - > is_repeated ( ) ) {
GenerateRepeatedClear ( field , layout , msg_name , field_names , output ) ;
GenerateRepeatedClear ( field , layout , msg_name , field_names , output ) ;
} else {
} else {
GenerateClear ( field , layout , msg_name , field_names , output ) ;
GenerateClear ( field , layout , msg_name , field_names , output ) ;
}
}
GenerateGetters ( field , layout , msg_name , field_names , output ) ;
GenerateGetters ( field , layout , msg_name , field_names , output ) ;
GenerateHazzer ( field , layout , msg_name , field_names , output ) ;
}
}
output ( " \n " ) ;
output ( " \n " ) ;