Shader: Add AstExportVisitor
This commit is contained in:
46
include/Nazara/Shader/Ast/AstExportVisitor.hpp
Normal file
46
include/Nazara/Shader/Ast/AstExportVisitor.hpp
Normal 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
|
||||||
12
include/Nazara/Shader/Ast/AstExportVisitor.inl
Normal file
12
include/Nazara/Shader/Ast/AstExportVisitor.inl
Normal 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>
|
||||||
25
src/Nazara/Shader/Ast/AstExportVisitor.cpp
Normal file
25
src/Nazara/Shader/Ast/AstExportVisitor.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user