From 9fd4249a87ffe909a42116eb48ecb1a6ba5c7438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Thu, 15 Apr 2021 14:01:36 +0200 Subject: [PATCH] Shader: compilation fixes --- include/Nazara/Shader/ShaderLangParser.hpp | 8 +++---- src/Nazara/Shader/Ast/AstOptimizer.cpp | 20 ++++++++-------- src/Nazara/Shader/ShaderLangLexer.cpp | 2 +- src/Nazara/Shader/ShaderLangParser.cpp | 27 ++++++++++++---------- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/include/Nazara/Shader/ShaderLangParser.hpp b/include/Nazara/Shader/ShaderLangParser.hpp index 6cea99202..4780a022c 100644 --- a/include/Nazara/Shader/ShaderLangParser.hpp +++ b/include/Nazara/Shader/ShaderLangParser.hpp @@ -14,10 +14,10 @@ namespace Nz::ShaderLang { - class AttributeError : public std::exception + class AttributeError : public std::runtime_error { public: - using exception::exception; + using runtime_error::runtime_error; }; class ExpectedToken : public std::exception @@ -26,10 +26,10 @@ namespace Nz::ShaderLang using exception::exception; }; - class DuplicateIdentifier : public std::exception + class DuplicateIdentifier : public std::runtime_error { public: - using exception::exception; + using runtime_error::runtime_error; }; class ReservedKeyword : public std::exception diff --git a/src/Nazara/Shader/Ast/AstOptimizer.cpp b/src/Nazara/Shader/Ast/AstOptimizer.cpp index 8f948778d..3c00fbd2b 100644 --- a/src/Nazara/Shader/Ast/AstOptimizer.cpp +++ b/src/Nazara/Shader/Ast/AstOptimizer.cpp @@ -53,7 +53,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename CompEq; + using Op = CompEq; }; // CompGe @@ -72,7 +72,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename CompGe; + using Op = CompGe; }; // CompGt @@ -91,7 +91,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename CompGt; + using Op = CompGt; }; // CompLe @@ -110,7 +110,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename CompLe; + using Op = CompLe; }; // CompLt @@ -129,7 +129,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename CompLe; + using Op = CompLe; }; // CompNe @@ -148,7 +148,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename CompNe; + using Op = CompNe; }; // Addition @@ -167,7 +167,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename Addition; + using Op = Addition; }; // Division @@ -186,7 +186,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename Division; + using Op = Division; }; // Multiplication @@ -205,7 +205,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename Multiplication; + using Op = Multiplication; }; // Subtraction @@ -224,7 +224,7 @@ namespace Nz::ShaderAst template struct PropagateConstantType { - using Op = typename Subtraction; + using Op = Subtraction; }; #define EnableOptimisation(Op, T1, T2) template<> struct Op : Op##Base {} diff --git a/src/Nazara/Shader/ShaderLangLexer.cpp b/src/Nazara/Shader/ShaderLangLexer.cpp index 0b084a014..b25c56877 100644 --- a/src/Nazara/Shader/ShaderLangLexer.cpp +++ b/src/Nazara/Shader/ShaderLangLexer.cpp @@ -73,7 +73,7 @@ namespace Nz::ShaderLang char c = Peek(0); Token token; - token.column = currentPos - lastLineFeed; + token.column = static_cast(currentPos - lastLineFeed); token.line = lineNumber; if (c == -1) diff --git a/src/Nazara/Shader/ShaderLangParser.cpp b/src/Nazara/Shader/ShaderLangParser.cpp index 8a28249ac..74d5aefd7 100644 --- a/src/Nazara/Shader/ShaderLangParser.cpp +++ b/src/Nazara/Shader/ShaderLangParser.cpp @@ -11,19 +11,19 @@ namespace Nz::ShaderLang { namespace { - std::unordered_map identifierToBasicType = { + std::unordered_map s_identifierToBasicType = { { "bool", ShaderAst::PrimitiveType::Boolean }, { "i32", ShaderAst::PrimitiveType::Int32 }, { "f32", ShaderAst::PrimitiveType::Float32 }, { "u32", ShaderAst::PrimitiveType::UInt32 } }; - std::unordered_map identifierToIntrinsic = { + std::unordered_map s_identifierToIntrinsic = { { "cross", ShaderAst::IntrinsicType::CrossProduct }, { "dot", ShaderAst::IntrinsicType::DotProduct }, }; - std::unordered_map identifierToAttributeType = { + std::unordered_map s_identifierToAttributeType = { { "binding", ShaderAst::AttributeType::Binding }, { "builtin", ShaderAst::AttributeType::Builtin }, { "entry", ShaderAst::AttributeType::Entry }, @@ -127,7 +127,7 @@ namespace Nz::ShaderLang ShaderAst::ExpressionType Parser::DecodeType(const std::string& identifier) { - if (auto it = identifierToBasicType.find(identifier); it != identifierToBasicType.end()) + if (auto it = s_identifierToBasicType.find(identifier); it != s_identifierToBasicType.end()) return it->second; //FIXME: Handle this better @@ -576,7 +576,10 @@ namespace Nz::ShaderLang throw AttributeError{ "invalid location index" }; break; - } + } + + default: + throw AttributeError{ "unexpected attribute" }; } } @@ -809,7 +812,7 @@ namespace Nz::ShaderLang { const std::string& identifier = std::get(token.data); - if (auto it = identifierToIntrinsic.find(identifier); it != identifierToIntrinsic.end()) + if (auto it = s_identifierToIntrinsic.find(identifier); it != s_identifierToIntrinsic.end()) { if (Peek(1).type == TokenType::OpenParenthesis) { @@ -879,8 +882,8 @@ namespace Nz::ShaderLang const Token& identifierToken = Expect(Advance(), TokenType::Identifier); const std::string& identifier = std::get(identifierToken.data); - auto it = identifierToAttributeType.find(identifier); - if (it == identifierToAttributeType.end()) + auto it = s_identifierToAttributeType.find(identifier); + if (it == s_identifierToAttributeType.end()) throw UnknownAttribute{}; return it->second; @@ -891,8 +894,8 @@ namespace Nz::ShaderLang const Token& identifierToken = Expect(Advance(), TokenType::Identifier); const std::string& identifier = std::get(identifierToken.data); - auto it = identifierToBasicType.find(identifier); - if (it != identifierToBasicType.end()) + auto it = s_identifierToBasicType.find(identifier); + if (it != s_identifierToBasicType.end()) throw ReservedKeyword{}; return identifier; @@ -903,8 +906,8 @@ namespace Nz::ShaderLang const Token& identifierToken = Expect(Advance(), TokenType::Identifier); const std::string& identifier = std::get(identifierToken.data); - auto it = identifierToBasicType.find(identifier); - if (it == identifierToBasicType.end()) + auto it = s_identifierToBasicType.find(identifier); + if (it == s_identifierToBasicType.end()) throw UnknownType{}; return it->second;