From d8c0fa91ade786dd879e142b7540be3656d00c58 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 30 Nov 2024 01:42:16 +0100 Subject: [PATCH] Cleanup code --- include/NZSL/SpirV/SpirvConstantCache.hpp | 2 +- include/NZSL/SpirV/SpirvVariable.hpp | 2 +- src/NZSL/Ast/SanitizeVisitor.cpp | 30 ++++++++++------------- src/NZSL/GlslWriter.cpp | 7 ++---- src/NZSL/SpirV/SpirvConstantCache.cpp | 2 +- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/include/NZSL/SpirV/SpirvConstantCache.hpp b/include/NZSL/SpirV/SpirvConstantCache.hpp index 61bcda6e..9ce19097 100644 --- a/include/NZSL/SpirV/SpirvConstantCache.hpp +++ b/include/NZSL/SpirV/SpirvConstantCache.hpp @@ -7,13 +7,13 @@ #ifndef NZSL_SPIRV_SPIRVCONSTANTCACHE_HPP #define NZSL_SPIRV_SPIRVCONSTANTCACHE_HPP +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/include/NZSL/SpirV/SpirvVariable.hpp b/include/NZSL/SpirV/SpirvVariable.hpp index 5949b102..8035fb26 100644 --- a/include/NZSL/SpirV/SpirvVariable.hpp +++ b/include/NZSL/SpirV/SpirvVariable.hpp @@ -8,8 +8,8 @@ #define NZSL_SPIRV_SPIRVVARIABLE_HPP #include -#include #include +#include namespace nzsl { diff --git a/src/NZSL/Ast/SanitizeVisitor.cpp b/src/NZSL/Ast/SanitizeVisitor.cpp index 3ebd3d79..4120d45e 100644 --- a/src/NZSL/Ast/SanitizeVisitor.cpp +++ b/src/NZSL/Ast/SanitizeVisitor.cpp @@ -226,7 +226,7 @@ namespace nzsl::Ast currentContext.currentModule = clone; m_context = ¤tContext; - Nz::CallOnExit resetContext([&] { m_context = nullptr; }); + NAZARA_DEFER({ m_context = nullptr; }); PreregisterIndices(module); @@ -1300,7 +1300,7 @@ namespace nzsl::Ast auto& cond = node.condStatements[condIndex]; PushScope(); - Nz::CallOnExit unscoper([&] { PopScope(); }); + NAZARA_DEFER({ PopScope(); }); auto BuildCondStatement = [&](BranchStatement::ConditionalStatement& condStatement) { @@ -1365,7 +1365,7 @@ namespace nzsl::Ast { unsigned int prevCondStatementIndex = m_context->currentConditionalIndex; m_context->currentConditionalIndex = m_context->nextConditionalIndex++; - Nz::CallOnExit restoreCond([=] { m_context->currentConditionalIndex = prevCondStatementIndex; }); + NAZARA_DEFER({ m_context->currentConditionalIndex = prevCondStatementIndex; }); // Unresolvable condition auto condStatement = ShaderBuilder::ConditionalStatement(std::move(cloneCondition), Cloner::Clone(*node.statement)); @@ -1415,10 +1415,8 @@ namespace nzsl::Ast return clone; } -#ifdef NAZARA_COMPILER_GCC - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif +NAZARA_WARNING_PUSH() +NAZARA_WARNING_GCC_DISABLE("-Wmaybe-uninitialized") StatementPtr SanitizeVisitor::Clone(DeclareExternalStatement& node) { @@ -1605,9 +1603,7 @@ namespace nzsl::Ast return clone; } -#ifdef NAZARA_COMPILER_GCC - #pragma GCC diagnostic pop -#endif +NAZARA_WARNING_POP() StatementPtr SanitizeVisitor::Clone(DeclareFunctionStatement& node) { @@ -2043,7 +2039,7 @@ namespace nzsl::Ast bool wasInLoop = m_context->inLoop; m_context->inLoop = true; - Nz::CallOnExit restoreLoop([=] { m_context->inLoop = wasInLoop; }); + NAZARA_DEFER({ m_context->inLoop = wasInLoop; }); clone->statement = CloneStatement(node.statement); } @@ -2162,7 +2158,7 @@ namespace nzsl::Ast if (m_context->options.reduceLoopsToWhile) { PushScope(); - Nz::CallOnExit unscoper([&] { PopScope(); }); + NAZARA_DEFER({ PopScope(); }); auto multi = std::make_unique(); multi->sourceLocation = node.sourceLocation; @@ -2218,7 +2214,7 @@ namespace nzsl::Ast { bool wasInLoop = m_context->inLoop; m_context->inLoop = true; - Nz::CallOnExit restoreLoop([=] { m_context->inLoop = wasInLoop; }); + NAZARA_DEFER({ m_context->inLoop = wasInLoop; }); body->statements.emplace_back(Unscope(CloneStatement(node.statement))); } @@ -2332,7 +2328,7 @@ namespace nzsl::Ast if (m_context->options.reduceLoopsToWhile) { PushScope(); - Nz::CallOnExit unscoper([&] { PopScope(); }); + NAZARA_DEFER({ PopScope(); }); auto multi = std::make_unique(); multi->sourceLocation = node.sourceLocation; @@ -2376,7 +2372,7 @@ namespace nzsl::Ast { bool wasInLoop = m_context->inLoop; m_context->inLoop = true; - Nz::CallOnExit restoreLoop([=] { m_context->inLoop = wasInLoop; }); + NAZARA_DEFER({ m_context->inLoop = wasInLoop; }); body->statements.emplace_back(Unscope(CloneStatement(node.statement))); } @@ -2408,7 +2404,7 @@ namespace nzsl::Ast bool wasInLoop = m_context->inLoop; m_context->inLoop = true; - Nz::CallOnExit restoreLoop([=] { m_context->inLoop = wasInLoop; }); + NAZARA_DEFER({ m_context->inLoop = wasInLoop; }); clone->statement = CloneStatement(node.statement); } @@ -2769,7 +2765,7 @@ namespace nzsl::Ast { bool wasInLoop = m_context->inLoop; m_context->inLoop = true; - Nz::CallOnExit restoreLoop([=] { m_context->inLoop = wasInLoop; }); + NAZARA_DEFER({ m_context->inLoop = wasInLoop; }); clone->body = CloneStatement(node.body); } diff --git a/src/NZSL/GlslWriter.cpp b/src/NZSL/GlslWriter.cpp index 493e5f21..b39b7dd7 100644 --- a/src/NZSL/GlslWriter.cpp +++ b/src/NZSL/GlslWriter.cpp @@ -367,10 +367,7 @@ namespace nzsl state.states = &states; m_currentState = &state; - Nz::CallOnExit onExit([this]() - { - m_currentState = nullptr; - }); + NAZARA_DEFER({ m_currentState = nullptr; }); Ast::ModulePtr sanitizedModule; const Ast::Module* targetModule; @@ -549,7 +546,7 @@ namespace nzsl std::size_t startPos = 0; while ((startPos = identifier.find("__"sv, startPos)) != std::string::npos) { - std::size_t endPos = identifier.find_first_not_of("_", startPos); + std::size_t endPos = identifier.find_first_not_of('_', startPos); identifier.replace(startPos, endPos - startPos, fmt::format("{}{}_", (startPos == 0) ? "_" : "", endPos - startPos)); startPos = endPos; diff --git a/src/NZSL/SpirV/SpirvConstantCache.cpp b/src/NZSL/SpirV/SpirvConstantCache.cpp index 74c4dcad..131fda08 100644 --- a/src/NZSL/SpirV/SpirvConstantCache.cpp +++ b/src/NZSL/SpirV/SpirvConstantCache.cpp @@ -4,9 +4,9 @@ #include #include +#include #include #include -#include #include #include #include