Shader: Add AstExportVisitor

This commit is contained in:
Jérôme Leclercq
2022-03-04 18:32:31 +01:00
parent 073f1dc434
commit 7dab1d735f
3 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_AST_ASTEXPORTVISITOR_HPP
#define NAZARA_SHADER_AST_ASTEXPORTVISITOR_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Shader/Config.hpp>
#include <Nazara/Shader/Ast/AstRecursiveVisitor.hpp>
#include <vector>
namespace Nz::ShaderAst
{
class NAZARA_SHADER_API AstExportVisitor : public AstRecursiveVisitor
{
public:
struct Callbacks;
AstExportVisitor() = default;
AstExportVisitor(const AstExportVisitor&) = delete;
AstExportVisitor(AstExportVisitor&&) = delete;
~AstExportVisitor() = default;
void Visit(Statement& statement, const Callbacks& callbacks);
AstExportVisitor& operator=(const AstExportVisitor&) = delete;
AstExportVisitor& operator=(AstExportVisitor&&) = delete;
struct Callbacks
{
std::function<void(DeclareStructStatement& structNode)> onExportedStruct;
};
private:
void Visit(DeclareStructStatement& node) override;
const Callbacks* m_callbacks;
};
}
#include <Nazara/Shader/Ast/AstExportVisitor.inl>
#endif // NAZARA_SHADER_AST_ASTEXPORTVISITOR_HPP

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstExportVisitor.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
}
#include <Nazara/Shader/DebugOff.hpp>

View File

@@ -0,0 +1,25 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Shader module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/Ast/AstExportVisitor.hpp>
#include <stdexcept>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderAst
{
void AstExportVisitor::Visit(Statement& statement, const Callbacks& callbacks)
{
m_callbacks = &callbacks;
statement.Visit(*this);
}
void AstExportVisitor::Visit(DeclareStructStatement& node)
{
if (!node.isExported.HasValue() || !node.isExported.GetResultingValue())
return;
if (m_callbacks->onExportedStruct)
m_callbacks->onExportedStruct(node);
}
}