Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Nov 30, 2024
1 parent ff3c31b commit d8c0fa9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion include/NZSL/SpirV/SpirvConstantCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#ifndef NZSL_SPIRV_SPIRVCONSTANTCACHE_HPP
#define NZSL_SPIRV_SPIRVCONSTANTCACHE_HPP

#include <NazaraUtils/PrivateImpl.hpp>
#include <NZSL/Config.hpp>
#include <NZSL/Enums.hpp>
#include <NZSL/Ast/ConstantValue.hpp>
#include <NZSL/Ast/Enums.hpp>
#include <NZSL/Ast/ExpressionType.hpp>
#include <NZSL/SpirV/SpirvData.hpp>
#include <NazaraUtils/PrivateImpl.hpp>
#include <memory>
#include <optional>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/NZSL/SpirV/SpirvVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define NZSL_SPIRV_SPIRVVARIABLE_HPP

#include <NZSL/Config.hpp>
#include <NZSL/SpirV/SpirvData.hpp>
#include <NZSL/SpirV/SpirvConstantCache.hpp>
#include <NZSL/SpirV/SpirvData.hpp>

namespace nzsl
{
Expand Down
30 changes: 13 additions & 17 deletions src/NZSL/Ast/SanitizeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ namespace nzsl::Ast
currentContext.currentModule = clone;

m_context = &currentContext;
Nz::CallOnExit resetContext([&] { m_context = nullptr; });
NAZARA_DEFER({ m_context = nullptr; });

PreregisterIndices(module);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<MultiStatement>();
multi->sourceLocation = node.sourceLocation;
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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<MultiStatement>();
multi->sourceLocation = node.sourceLocation;
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 2 additions & 5 deletions src/NZSL/GlslWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/NZSL/SpirV/SpirvConstantCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include <NZSL/SpirV/SpirvConstantCache.hpp>
#include <NazaraUtils/Assert.hpp>
#include <NZSL/SpirvWriter.hpp>
#include <NZSL/Ast/Nodes.hpp>
#include <NZSL/Math/FieldOffsets.hpp>
#include <NZSL/SpirvWriter.hpp>
#include <NZSL/SpirV/SpirvSection.hpp>
#include <tsl/ordered_map.h>
#include <cassert>
Expand Down

0 comments on commit d8c0fa9

Please sign in to comment.