Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified constant alias handling #1845

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4897,15 +4897,8 @@ std::string VulkanHppGenerator::generateConstexprDefines() const
{
if ( !listedConstants.contains( constant ) )
{
auto constIt = m_constants.find( 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 );
auto constIt = findByNameOrAlias( m_constants, constant );
std::string tag = findTag( constant );
constants += replaceWithMap( constexprValueTemplate,
{ { "type", constIt->second.type },
{ "constName", stripPrefix( toCamelCase( stripPostfix( constant, tag ) ), "Vk" ) + tag },
Expand Down Expand Up @@ -5126,14 +5119,7 @@ std::string VulkanHppGenerator::generateConstexprUsings() const
{
if ( !listedConstants.contains( constant ) )
{
auto constIt = m_constants.find( 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() );
}
assert( findByNameOrAlias( m_constants, constant ) != m_constants.end() );
std::string tag = findTag( constant );
constants += replaceWithMap( constexprUsingTemplate, { { "constName", stripPrefix( toCamelCase( stripPostfix( constant, tag ) ), "Vk" ) + tag } } );
listedConstants.insert( constant );
Expand Down Expand Up @@ -13024,10 +13010,10 @@ void VulkanHppGenerator::readEnumsConstants( tinyxml2::XMLElement const * elemen
std::string alias = aliasIt->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" );
assert( !m_constantAliases.contains( name ) );
m_constantAliases[name] = { alias, line };
}
else
{
Expand All @@ -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" );
assert( !m_constants.contains( name ) );
m_constants[name] = { type, value, line };
m_constants[name] = { {}, type, value, line };
}
}

Expand Down Expand Up @@ -13882,10 +13868,20 @@ void VulkanHppGenerator::readRequireEnum(

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(
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
{
Expand Down Expand Up @@ -13971,7 +13967,7 @@ void VulkanHppGenerator::readRequireEnum(
if ( type == "uint32_t" )
{
assert( !m_constants.contains( name ) );
m_constants[name] = { type, value, line };
m_constants[name] = { {}, type, value, line };
}
}

Expand Down
8 changes: 4 additions & 4 deletions VulkanHppGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ class VulkanHppGenerator

struct ConstantData
{
std::string type = {};
std::string value = {};
int xmlLine = {};
std::map<std::string, int> aliases = {};
std::string type = {};
std::string value = {};
int xmlLine = {};
};

struct DefineData
Expand Down Expand Up @@ -1033,7 +1034,6 @@ class VulkanHppGenerator
std::map<std::string, BaseTypeData> m_baseTypes;
std::map<std::string, BitmaskData> m_bitmasks;
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, DefineData> m_defines;
DefinesPartition m_definesPartition; // partition defined macros into mutually-exclusive sets of callees, callers, and values
Expand Down
Loading