// Copyright (C) 2020 Jérôme Leclercq // This file is part of the "Nazara Engine - Shader generator" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_SHADER_SCOPED_VISITOR_HPP #define NAZARA_SHADER_SCOPED_VISITOR_HPP #include #include #include namespace Nz::ShaderAst { class NAZARA_SHADER_API AstScopedVisitor : public AstRecursiveVisitor { public: struct Identifier; AstScopedVisitor() = default; ~AstScopedVisitor() = default; inline const Identifier* FindIdentifier(const std::string_view& identifierName) const; void ScopedVisit(StatementPtr& nodePtr); using AstRecursiveVisitor::Visit; void Visit(BranchStatement& node) override; void Visit(ConditionalStatement& node) override; void Visit(DeclareExternalStatement& node) override; void Visit(DeclareFunctionStatement& node) override; void Visit(DeclareStructStatement& node) override; void Visit(DeclareVariableStatement& node) override; void Visit(MultiStatement& node) override; struct Alias { std::variant value; }; struct Variable { ExpressionType type; }; struct Identifier { std::string name; std::variant value; }; protected: void PushScope(); void PopScope(); inline void RegisterStruct(StructDescription structDesc); inline void RegisterVariable(std::string name, ExpressionType type); private: std::vector m_identifiersInScope; std::vector m_scopeSizes; }; } #include #endif