Shader: Add SourceLocation members
TODO: Fill from Parser and use them for error throwing in SanitizeVisitor
This commit is contained in:
committed by
Jérôme Leclercq
parent
b8bf19f8cd
commit
960ab64d98
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||
#include <Nazara/Shader/Ast/Module.hpp>
|
||||
#include <vector>
|
||||
@@ -23,12 +24,15 @@ namespace Nz::ShaderAst
|
||||
|
||||
template<typename T> bool Compare(const T& lhs, const T& rhs);
|
||||
template<typename T, std::size_t S> bool Compare(const std::array<T, S>& lhs, const std::array<T, S>& rhs);
|
||||
template<typename T> bool Compare(const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs);
|
||||
template<typename T> bool Compare(const std::vector<T>& lhs, const std::vector<T>& rhs);
|
||||
template<typename T> bool Compare(const std::unique_ptr<T>& lhs, const std::unique_ptr<T>& rhs);
|
||||
template<typename T> bool Compare(const ExpressionValue<T>& lhs, const ExpressionValue<T>& rhs);
|
||||
inline bool Compare(const AccessIdentifierExpression::Identifier& lhs, const AccessIdentifierExpression::Identifier& rhs);
|
||||
inline bool Compare(const BranchStatement::ConditionalStatement& lhs, const BranchStatement::ConditionalStatement& rhs);
|
||||
inline bool Compare(const DeclareExternalStatement::ExternalVar& lhs, const DeclareExternalStatement::ExternalVar& rhs);
|
||||
inline bool Compare(const DeclareFunctionStatement::Parameter& lhs, const DeclareFunctionStatement::Parameter& rhs);
|
||||
inline bool Compare(const ShaderLang::SourceLocation& lhs, const ShaderLang::SourceLocation& rhs);
|
||||
inline bool Compare(const StructDescription& lhs, const StructDescription& rhs);
|
||||
inline bool Compare(const StructDescription::StructMember& lhs, const StructDescription::StructMember& rhs);
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace Nz::ShaderAst
|
||||
if (lhs.GetType() != rhs.GetType())
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||
return false;
|
||||
|
||||
switch (lhs.GetType())
|
||||
{
|
||||
case NodeType::None: break;
|
||||
@@ -70,6 +73,9 @@ namespace Nz::ShaderAst
|
||||
if (lhs.GetType() != rhs.GetType())
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||
return false;
|
||||
|
||||
switch (lhs.GetType())
|
||||
{
|
||||
case NodeType::None: break;
|
||||
@@ -101,6 +107,17 @@ namespace Nz::ShaderAst
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Compare(const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs)
|
||||
{
|
||||
if (lhs == nullptr)
|
||||
return rhs == nullptr;
|
||||
else if (rhs == nullptr)
|
||||
return false;
|
||||
|
||||
return Compare(*lhs, *rhs);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Compare(const std::vector<T>& lhs, const std::vector<T>& rhs)
|
||||
{
|
||||
@@ -153,6 +170,17 @@ namespace Nz::ShaderAst
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Compare(const AccessIdentifierExpression::Identifier& lhs, const AccessIdentifierExpression::Identifier& rhs)
|
||||
{
|
||||
if (!Compare(lhs.identifier, rhs.identifier))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Compare(const BranchStatement::ConditionalStatement& lhs, const BranchStatement::ConditionalStatement& rhs)
|
||||
{
|
||||
if (!Compare(lhs.condition, rhs.condition))
|
||||
@@ -178,6 +206,9 @@ namespace Nz::ShaderAst
|
||||
if (!Compare(lhs.type, rhs.type))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -189,6 +220,29 @@ namespace Nz::ShaderAst
|
||||
if (!Compare(lhs.type, rhs.type))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Compare(const ShaderLang::SourceLocation& lhs, const ShaderLang::SourceLocation& rhs)
|
||||
{
|
||||
if (!Compare(lhs.endColumn, rhs.endColumn))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.endLine, rhs.endLine))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.startColumn, rhs.startColumn))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.startLine, rhs.startLine))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.file, rhs.file))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -223,6 +277,9 @@ namespace Nz::ShaderAst
|
||||
if (!Compare(lhs.type, rhs.type))
|
||||
return false;
|
||||
|
||||
if (!Compare(lhs.sourceLocation, rhs.sourceLocation))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/ByteStream.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||
#include <Nazara/Shader/Ast/Module.hpp>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
@@ -43,7 +44,6 @@ namespace Nz::ShaderAst
|
||||
void Serialize(TypeExpression& node);
|
||||
void Serialize(VariableValueExpression& node);
|
||||
void Serialize(UnaryExpression& node);
|
||||
void SerializeExpressionCommon(Expression& expr);
|
||||
|
||||
void Serialize(BranchStatement& node);
|
||||
void Serialize(ConditionalStatement& node);
|
||||
@@ -65,6 +65,9 @@ namespace Nz::ShaderAst
|
||||
void Serialize(ScopedStatement& node);
|
||||
void Serialize(WhileStatement& node);
|
||||
|
||||
void SerializeExpressionCommon(Expression& expr);
|
||||
void SerializeNodeCommon(ShaderAst::Node& node);
|
||||
|
||||
protected:
|
||||
template<typename T> void Container(T& container);
|
||||
template<typename T> void Enum(T& enumVal);
|
||||
@@ -75,11 +78,14 @@ namespace Nz::ShaderAst
|
||||
|
||||
virtual bool IsWriting() const = 0;
|
||||
|
||||
virtual void SerializeModule(ModulePtr& module) = 0;
|
||||
|
||||
virtual void Node(ExpressionPtr& node) = 0;
|
||||
virtual void Node(StatementPtr& node) = 0;
|
||||
|
||||
virtual void SerializeModule(ModulePtr& module) = 0;
|
||||
virtual void SharedString(std::shared_ptr<const std::string>& val) = 0;
|
||||
|
||||
inline void SourceLoc(ShaderLang::SourceLocation& sourceLoc);
|
||||
|
||||
virtual void Type(ExpressionType& type) = 0;
|
||||
|
||||
virtual void Value(bool& val) = 0;
|
||||
@@ -110,11 +116,11 @@ namespace Nz::ShaderAst
|
||||
private:
|
||||
using AstSerializerBase::Serialize;
|
||||
|
||||
void SerializeModule(ModulePtr& module) override;
|
||||
|
||||
bool IsWriting() const override;
|
||||
void Node(ExpressionPtr& node) override;
|
||||
void Node(StatementPtr& node) override;
|
||||
void SerializeModule(ModulePtr& module) override;
|
||||
void SharedString(std::shared_ptr<const std::string>& val) override;
|
||||
void Type(ExpressionType& type) override;
|
||||
void Value(bool& val) override;
|
||||
void Value(float& val) override;
|
||||
@@ -131,6 +137,7 @@ namespace Nz::ShaderAst
|
||||
void Value(UInt32& val) override;
|
||||
void Value(UInt64& val) override;
|
||||
|
||||
std::unordered_map<std::string, UInt32> m_stringIndices;
|
||||
ByteStream& m_stream;
|
||||
};
|
||||
|
||||
@@ -145,11 +152,11 @@ namespace Nz::ShaderAst
|
||||
private:
|
||||
using AstSerializerBase::Serialize;
|
||||
|
||||
void SerializeModule(ModulePtr& module) override;
|
||||
|
||||
bool IsWriting() const override;
|
||||
void Node(ExpressionPtr& node) override;
|
||||
void Node(StatementPtr& node) override;
|
||||
void SerializeModule(ModulePtr& module) override;
|
||||
void SharedString(std::shared_ptr<const std::string>& val) override;
|
||||
void Type(ExpressionType& type) override;
|
||||
void Value(bool& val) override;
|
||||
void Value(float& val) override;
|
||||
@@ -166,6 +173,7 @@ namespace Nz::ShaderAst
|
||||
void Value(UInt32& val) override;
|
||||
void Value(UInt64& val) override;
|
||||
|
||||
std::vector<std::shared_ptr<const std::string>> m_strings;
|
||||
ByteStream& m_stream;
|
||||
};
|
||||
|
||||
|
||||
@@ -166,6 +166,15 @@ namespace Nz::ShaderAst
|
||||
}
|
||||
}
|
||||
|
||||
inline void AstSerializerBase::SourceLoc(ShaderLang::SourceLocation& sourceLoc)
|
||||
{
|
||||
SharedString(sourceLoc.file);
|
||||
Value(sourceLoc.endColumn);
|
||||
Value(sourceLoc.endLine);
|
||||
Value(sourceLoc.startColumn);
|
||||
Value(sourceLoc.startLine);
|
||||
}
|
||||
|
||||
inline void AstSerializerBase::SizeT(std::size_t& val)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_SHADER_AST_EXPRESSIONTYPE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
@@ -166,6 +167,7 @@ namespace Nz::ShaderAst
|
||||
ExpressionValue<UInt32> locationIndex;
|
||||
ExpressionValue<ExpressionType> type;
|
||||
std::string name;
|
||||
ShaderLang::SourceLocation sourceLocation;
|
||||
};
|
||||
|
||||
ExpressionValue<StructLayout> layout;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
|
||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||
#include <Nazara/Shader/Ast/ConstantValue.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
@@ -41,6 +42,8 @@ namespace Nz::ShaderAst
|
||||
|
||||
Node& operator=(const Node&) = delete;
|
||||
Node& operator=(Node&&) noexcept = default;
|
||||
|
||||
ShaderLang::SourceLocation sourceLocation;
|
||||
};
|
||||
|
||||
// Expressions
|
||||
@@ -69,7 +72,13 @@ namespace Nz::ShaderAst
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
std::vector<std::string> identifiers;
|
||||
struct Identifier
|
||||
{
|
||||
std::string identifier;
|
||||
ShaderLang::SourceLocation sourceLocation;
|
||||
};
|
||||
|
||||
std::vector<Identifier> identifiers;
|
||||
ExpressionPtr expr;
|
||||
};
|
||||
|
||||
@@ -317,6 +326,7 @@ namespace Nz::ShaderAst
|
||||
ExpressionValue<UInt32> bindingIndex;
|
||||
ExpressionValue<UInt32> bindingSet;
|
||||
ExpressionValue<ExpressionType> type;
|
||||
ShaderLang::SourceLocation sourceLocation;
|
||||
};
|
||||
|
||||
std::vector<ExternalVar> externalVars;
|
||||
@@ -330,9 +340,10 @@ namespace Nz::ShaderAst
|
||||
|
||||
struct Parameter
|
||||
{
|
||||
ExpressionValue<ExpressionType> type;
|
||||
std::optional<std::size_t> varIndex;
|
||||
std::string name;
|
||||
ExpressionValue<ExpressionType> type;
|
||||
ShaderLang::SourceLocation sourceLocation;
|
||||
};
|
||||
|
||||
std::optional<std::size_t> funcIndex;
|
||||
|
||||
Reference in New Issue
Block a user