mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Simplified constant alias handling (#1845)
This commit is contained in:
parent
df42194eec
commit
11121e142a
@ -4897,14 +4897,7 @@ std::string VulkanHppGenerator::generateConstexprDefines() const
|
|||||||
{
|
{
|
||||||
if ( !listedConstants.contains( constant ) )
|
if ( !listedConstants.contains( constant ) )
|
||||||
{
|
{
|
||||||
auto constIt = m_constants.find( constant );
|
auto constIt = findByNameOrAlias( m_constants, constant );
|
||||||
if ( constIt == m_constants.end() )
|
|
||||||
{
|
|
||||||
auto aliasIt = m_constantAliases.find( constant );
|
|
||||||
assert( aliasIt != m_constantAliases.end() );
|
|
||||||
constIt = m_constants.find( aliasIt->second.name );
|
|
||||||
assert( constIt != m_constants.end() );
|
|
||||||
}
|
|
||||||
std::string tag = findTag( constant );
|
std::string tag = findTag( constant );
|
||||||
constants += replaceWithMap( constexprValueTemplate,
|
constants += replaceWithMap( constexprValueTemplate,
|
||||||
{ { "type", constIt->second.type },
|
{ { "type", constIt->second.type },
|
||||||
@ -5126,14 +5119,7 @@ std::string VulkanHppGenerator::generateConstexprUsings() const
|
|||||||
{
|
{
|
||||||
if ( !listedConstants.contains( constant ) )
|
if ( !listedConstants.contains( constant ) )
|
||||||
{
|
{
|
||||||
auto constIt = m_constants.find( constant );
|
assert( findByNameOrAlias( m_constants, constant ) != m_constants.end() );
|
||||||
if ( constIt == m_constants.end() )
|
|
||||||
{
|
|
||||||
auto aliasIt = m_constantAliases.find( constant );
|
|
||||||
assert( aliasIt != m_constantAliases.end() );
|
|
||||||
constIt = m_constants.find( aliasIt->second.name );
|
|
||||||
assert( constIt != m_constants.end() );
|
|
||||||
}
|
|
||||||
std::string tag = findTag( constant );
|
std::string tag = findTag( constant );
|
||||||
constants += replaceWithMap( constexprUsingTemplate, { { "constName", stripPrefix( toCamelCase( stripPostfix( constant, tag ) ), "Vk" ) + tag } } );
|
constants += replaceWithMap( constexprUsingTemplate, { { "constName", stripPrefix( toCamelCase( stripPostfix( constant, tag ) ), "Vk" ) + tag } } );
|
||||||
listedConstants.insert( constant );
|
listedConstants.insert( constant );
|
||||||
@ -13024,10 +13010,10 @@ void VulkanHppGenerator::readEnumsConstants( tinyxml2::XMLElement const * elemen
|
|||||||
std::string alias = aliasIt->second;
|
std::string alias = aliasIt->second;
|
||||||
std::string name = attributes.find( "name" )->second;
|
std::string name = attributes.find( "name" )->second;
|
||||||
|
|
||||||
checkForError( m_constants.contains( alias ), line, "enum <" + name + "> is an alias of an unknown enum <" + alias + ">." );
|
auto constIt = m_constants.find( alias );
|
||||||
|
checkForError( constIt != m_constants.end(), line, "constant alias <" + name + "> is an alias of an unknown constant <" + alias + ">." );
|
||||||
|
checkForError( constIt->second.aliases.insert( { name, line } ).second, line, "constant alias <" + name + "> already listed for constant <" + alias + ">" );
|
||||||
checkForError( m_types.insert( { name, TypeData{ TypeCategory::Constant, {}, line } } ).second, line, "enum <" + name + "> already specified" );
|
checkForError( m_types.insert( { name, TypeData{ TypeCategory::Constant, {}, line } } ).second, line, "enum <" + name + "> already specified" );
|
||||||
assert( !m_constantAliases.contains( name ) );
|
|
||||||
m_constantAliases[name] = { alias, line };
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -13054,7 +13040,7 @@ void VulkanHppGenerator::readEnumsConstants( tinyxml2::XMLElement const * elemen
|
|||||||
|
|
||||||
checkForError( m_types.insert( { name, TypeData{ TypeCategory::Constant, {}, line } } ).second, line, "enum <" + name + "> already specified" );
|
checkForError( m_types.insert( { name, TypeData{ TypeCategory::Constant, {}, line } } ).second, line, "enum <" + name + "> already specified" );
|
||||||
assert( !m_constants.contains( name ) );
|
assert( !m_constants.contains( name ) );
|
||||||
m_constants[name] = { type, value, line };
|
m_constants[name] = { {}, type, value, line };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13882,10 +13868,20 @@ void VulkanHppGenerator::readRequireEnum(
|
|||||||
|
|
||||||
if ( extends.empty() )
|
if ( extends.empty() )
|
||||||
{
|
{
|
||||||
|
// enum aliases that don't extend something are listed as constants
|
||||||
|
auto typeIt = m_types.find( alias );
|
||||||
|
checkForError( typeIt != m_types.end(), line, "enum alias <" + name + "> is an alias of an unknown enum <" + alias + ">" );
|
||||||
|
checkForError(
|
||||||
|
typeIt->second.category == TypeCategory::Constant, line, "enum alias <" + name + "> is an alias of a non-constant type <" + alias + ">" );
|
||||||
checkForError(
|
checkForError(
|
||||||
m_types.insert( { name, TypeData{ TypeCategory::Constant, { requiredBy }, line } } ).second, line, "required enum <" + name + "> already specified" );
|
m_types.insert( { name, TypeData{ TypeCategory::Constant, { requiredBy }, line } } ).second, line, "required enum <" + name + "> already specified" );
|
||||||
assert( !m_constantAliases.contains( name ) );
|
|
||||||
m_constantAliases[name] = { alias, line };
|
// if that constant is a uint32_t, it's stored in m_constants (I think, this doesn't happen at all!!)
|
||||||
|
auto constIt = m_constants.find( alias );
|
||||||
|
if ( constIt != m_constants.end() )
|
||||||
|
{
|
||||||
|
checkForError( constIt->second.aliases.insert( { name, line } ).second, line, "enum alias <" + name + "> already listed for enum <" + alias + ">" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -13971,7 +13967,7 @@ void VulkanHppGenerator::readRequireEnum(
|
|||||||
if ( type == "uint32_t" )
|
if ( type == "uint32_t" )
|
||||||
{
|
{
|
||||||
assert( !m_constants.contains( name ) );
|
assert( !m_constants.contains( name ) );
|
||||||
m_constants[name] = { type, value, line };
|
m_constants[name] = { {}, type, value, line };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +199,7 @@ private:
|
|||||||
|
|
||||||
struct ConstantData
|
struct ConstantData
|
||||||
{
|
{
|
||||||
|
std::map<std::string, int> aliases = {};
|
||||||
std::string type = {};
|
std::string type = {};
|
||||||
std::string value = {};
|
std::string value = {};
|
||||||
int xmlLine = {};
|
int xmlLine = {};
|
||||||
@ -1033,7 +1034,6 @@ private:
|
|||||||
std::map<std::string, BaseTypeData> m_baseTypes;
|
std::map<std::string, BaseTypeData> m_baseTypes;
|
||||||
std::map<std::string, BitmaskData> m_bitmasks;
|
std::map<std::string, BitmaskData> m_bitmasks;
|
||||||
std::map<std::string, CommandData> m_commands;
|
std::map<std::string, CommandData> m_commands;
|
||||||
std::map<std::string, AliasData> m_constantAliases;
|
|
||||||
std::map<std::string, ConstantData> m_constants;
|
std::map<std::string, ConstantData> m_constants;
|
||||||
std::map<std::string, DefineData> m_defines;
|
std::map<std::string, DefineData> m_defines;
|
||||||
DefinesPartition m_definesPartition; // partition defined macros into mutually-exclusive sets of callees, callers, and values
|
DefinesPartition m_definesPartition; // partition defined macros into mutually-exclusive sets of callees, callers, and values
|
||||||
|
Loading…
Reference in New Issue
Block a user