Add support of attribute "protect" for enum values.

This commit is contained in:
asuessenbach 2021-06-30 09:58:58 +02:00
parent 5002a06691
commit 7e37cfb5d7
2 changed files with 37 additions and 13 deletions

View File

@ -1023,7 +1023,16 @@ void VulkanHppGenerator::appendEnum( std::string & str, std::pair<std::string, E
for ( auto const & value : enumData.second.values ) for ( auto const & value : enumData.second.values )
{ {
std::string enter, leave; std::string enter, leave;
if ( !value.extension.empty() )
{
assert( value.protect.empty() );
std::tie( enter, leave ) = generateProtection( value.extension ); std::tie( enter, leave ) = generateProtection( value.extension );
}
else if ( !value.protect.empty() )
{
enter = "#if defined( " + value.protect + " )\n";
leave = "#endif /*" + value.protect + "*/\n";
}
if ( previousEnter != enter ) if ( previousEnter != enter )
{ {
enumList += previousLeave + enter; enumList += previousLeave + enter;
@ -9580,16 +9589,14 @@ void VulkanHppGenerator::EnumData::addEnumAlias( int line, std::string const & n
aliases.insert( std::make_pair( name, EnumAliasData( aliasName, line ) ) ); aliases.insert( std::make_pair( name, EnumAliasData( aliasName, line ) ) );
} }
void VulkanHppGenerator::EnumData::addEnumValue( int line, void VulkanHppGenerator::EnumData::addEnumValue(
std::string const & valueName, int line, std::string const & valueName, std::string const & protect, bool bitpos, std::string const & extension )
bool bitpos,
std::string const & extension )
{ {
auto valueIt = std::find_if( auto valueIt = std::find_if(
values.begin(), values.end(), [&valueName]( EnumValueData const & evd ) { return evd.name == valueName; } ); values.begin(), values.end(), [&valueName]( EnumValueData const & evd ) { return evd.name == valueName; } );
if ( valueIt == values.end() ) if ( valueIt == values.end() )
{ {
values.emplace_back( line, valueName, extension, bitpos ); values.emplace_back( line, valueName, protect, extension, bitpos );
} }
} }
@ -12715,10 +12722,14 @@ void VulkanHppGenerator::readEnum( tinyxml2::XMLElement const * el
std::map<std::string, EnumData>::iterator enumIt ) std::map<std::string, EnumData>::iterator enumIt )
{ {
int line = element->GetLineNum(); int line = element->GetLineNum();
checkAttributes( line, attributes, { { "name", {} } }, { { "bitpos", {} }, { "comment", {} }, { "value", {} } } ); checkAttributes(
line,
attributes,
{ { "name", {} } },
{ { "bitpos", {} }, { "comment", {} }, { "protect", { "VK_ENABLE_BETA_EXTENSIONS" } }, { "value", {} } } );
checkElements( line, getChildElements( element ), {} ); checkElements( line, getChildElements( element ), {} );
std::string alias, bitpos, name, value; std::string alias, bitpos, name, protect, value;
for ( auto const & attribute : attributes ) for ( auto const & attribute : attributes )
{ {
if ( attribute.first == "bitpos" ) if ( attribute.first == "bitpos" )
@ -12729,6 +12740,10 @@ void VulkanHppGenerator::readEnum( tinyxml2::XMLElement const * el
{ {
name = attribute.second; name = attribute.second;
} }
else if ( attribute.first == "protect" )
{
protect = attribute.second;
}
else if ( attribute.first == "value" ) else if ( attribute.first == "value" )
{ {
value = attribute.second; value = attribute.second;
@ -12741,7 +12756,7 @@ void VulkanHppGenerator::readEnum( tinyxml2::XMLElement const * el
"encountered enum value <" + name + "> that does not begin with expected prefix <" + prefix + ">" ); "encountered enum value <" + name + "> that does not begin with expected prefix <" + prefix + ">" );
check( bitpos.empty() ^ value.empty(), line, "invalid set of attributes for enum <" + name + ">" ); check( bitpos.empty() ^ value.empty(), line, "invalid set of attributes for enum <" + name + ">" );
enumIt->second.addEnumValue( line, name, !bitpos.empty(), "" ); enumIt->second.addEnumValue( line, name, protect, !bitpos.empty(), "" );
} }
void VulkanHppGenerator::readEnumAlias( tinyxml2::XMLElement const * element, void VulkanHppGenerator::readEnumAlias( tinyxml2::XMLElement const * element,
@ -13685,7 +13700,7 @@ void VulkanHppGenerator::readRequireEnum( tinyxml2::XMLElement const *
line, line,
"exactly one out of bitpos = <" + bitpos + ">, offset = <" + offset + ">, and value = <" + value + "exactly one out of bitpos = <" + bitpos + ">, offset = <" + offset + ">, and value = <" + value +
"> are supposed to be empty" ); "> are supposed to be empty" );
enumIt->second.addEnumValue( element->GetLineNum(), name, !bitpos.empty(), extension ); enumIt->second.addEnumValue( element->GetLineNum(), name, "", !bitpos.empty(), extension );
} }
else if ( value.empty() ) else if ( value.empty() )
{ {

View File

@ -138,12 +138,17 @@ private:
struct EnumValueData struct EnumValueData
{ {
EnumValueData( int line, std::string const & name_, std::string const & extension_, bool singleBit_ ) EnumValueData( int line,
: name( name_ ), extension( extension_ ), singleBit( singleBit_ ), xmlLine( line ) std::string const & name_,
std::string const & protect_,
std::string const & extension_,
bool singleBit_ )
: name( name_ ), extension( extension_ ), protect( protect_ ), singleBit( singleBit_ ), xmlLine( line )
{} {}
std::string name; std::string name;
std::string extension; std::string extension;
std::string protect;
bool singleBit; bool singleBit;
int xmlLine; int xmlLine;
}; };
@ -152,7 +157,11 @@ private:
{ {
EnumData( int line ) : xmlLine( line ) {} EnumData( int line ) : xmlLine( line ) {}
void addEnumAlias( int line, std::string const & name, std::string const & alias ); void addEnumAlias( int line, std::string const & name, std::string const & alias );
void addEnumValue( int line, std::string const & valueName, bool bitpos, std::string const & extension ); void addEnumValue( int line,
std::string const & valueName,
std::string const & protect,
bool bitpos,
std::string const & extension );
std::string alias; // alias for this enum std::string alias; // alias for this enum
std::map<std::string, EnumAliasData> aliases; // aliases for the values std::map<std::string, EnumAliasData> aliases; // aliases for the values