From 13f9f7d7068475d589d6004eade856d94ea40d2a Mon Sep 17 00:00:00 2001 From: DHrpcs3 Date: Mon, 21 Dec 2015 22:45:58 +0200 Subject: [PATCH] Fixed clang compilation errors --- rsx_decompiler/rsx_decompiler.cpp | 5 +- rsx_decompiler/rsx_decompiler_base.h | 12 +- rsx_decompiler/rsx_fp_decompiler.cpp | 48 +++--- rsx_decompiler/rsx_vp_decompiler.cpp | 16 +- shader_code/clike_builder.h | 154 +++++++++---------- shader_code/clike_language.h | 214 ++++++++++++++++----------- shader_code/glsl_language.h | 13 +- 7 files changed, 258 insertions(+), 204 deletions(-) diff --git a/rsx_decompiler/rsx_decompiler.cpp b/rsx_decompiler/rsx_decompiler.cpp index 97e2ecf..6678c66 100644 --- a/rsx_decompiler/rsx_decompiler.cpp +++ b/rsx_decompiler/rsx_decompiler.cpp @@ -1,6 +1,7 @@ #include "rsx_decompiler.h" #include #include +#include namespace rsx { @@ -50,7 +51,7 @@ namespace rsx switch (program.type) { case program_type::fragment: - for (std::size_t index = 0; index < std::size(rsx::fragment_program::input_attrib_map); ++index) + for (std::size_t index = 0; index < 16; ++index) { if (program.input_attributes & (1 << index)) { @@ -60,7 +61,7 @@ namespace rsx break; case program_type::vertex: - for (std::size_t index = 0; index < std::size(rsx::vertex_program::input_registers_table); ++index) + for (std::size_t index = 0; index < 16; ++index) { if (program.input_attributes & (1 << index)) { diff --git a/rsx_decompiler/rsx_decompiler_base.h b/rsx_decompiler/rsx_decompiler_base.h index c508548..78aae73 100644 --- a/rsx_decompiler/rsx_decompiler_base.h +++ b/rsx_decompiler/rsx_decompiler_base.h @@ -25,8 +25,8 @@ namespace rsx }; template - static typename base::boolean_expr single_compare_function(compare_function function, - typename base::expression_t a, typename base::expression_t b) + static typename base::template boolean_expr single_compare_function(compare_function function, + typename base::template expression_t a, typename base::template expression_t b) { std::string operator_string; @@ -47,8 +47,8 @@ namespace rsx } template - static typename base::boolean_expr vector_compare_function(compare_function function, - typename base::expression_t a, typename base::expression_t b) + static typename base::template boolean_expr vector_compare_function(compare_function function, + typename base::template expression_t a, typename base::template expression_t b) { switch (function) { @@ -64,8 +64,8 @@ namespace rsx } template - static typename base::boolean_expr custom_compare(compare_function function, int channel_count, - typename base::expression_t a, typename base::expression_t b) + static typename base::template boolean_expr custom_compare(compare_function function, int channel_count, + typename base::template expression_t a, typename base::template expression_t b) { if (channel_count == 1) { diff --git a/rsx_decompiler/rsx_fp_decompiler.cpp b/rsx_decompiler/rsx_fp_decompiler.cpp index a833354..9a3f392 100644 --- a/rsx_decompiler/rsx_fp_decompiler.cpp +++ b/rsx_decompiler/rsx_fp_decompiler.cpp @@ -13,16 +13,16 @@ namespace rsx using base = decompiler_base; template - using boolean_expr = typename base::boolean_expr; + using boolean_expr = typename base::template boolean_expr; template - using float_point_expr = typename base::float_point_expr; + using float_point_expr = typename base::template float_point_expr; template - using float_point_t = typename base::float_point_t; + using float_point_t = typename base::template float_point_t; template - using boolean_t = typename base::boolean_t; + using boolean_t = typename base::template boolean_t; struct context_t { @@ -30,7 +30,7 @@ namespace rsx bool is_next_is_constant; u32 offset; - typename base::float_point_expr<4> constant() + float_point_expr<4> constant() { constant_info info; info.id = offset + sizeof(instruction_t); @@ -41,7 +41,7 @@ namespace rsx return info.name; } - typename base::float_point_expr<4> temporary(bool is_fp16, int index) + float_point_expr<4> temporary(bool is_fp16, int index) { register_info info; info.id = index; @@ -51,7 +51,7 @@ namespace rsx return info.name; } - typename base::float_point_expr<4> condition(int index) + float_point_expr<4> condition(int index) { register_info info; info.id = index; @@ -62,7 +62,7 @@ namespace rsx return info.name; } - typename base::float_point_expr<4> input(int index) + float_point_expr<4> input(int index) { program.input_attributes |= (1 << index); return input_attrib_map[index]; @@ -121,7 +121,7 @@ namespace rsx return result; } - typename base::float_point_expr<4> swizzle_as_dst(typename base::float_point_expr<4> arg) const + float_point_expr<4> swizzle_as_dst(float_point_expr<4> arg) const { std::string arg_mask; @@ -133,7 +133,7 @@ namespace rsx return float_point_expr<4>(arg.text, arg_mask, arg.is_single, arg.base_count); } - typename base::float_point_expr<4> src(context_t& context, int index, bool is_swizzle_as_dst = false) const + float_point_expr<4> src(context_t& context, int index, bool is_swizzle_as_dst = false) const { src_t src; @@ -156,7 +156,7 @@ namespace rsx throw; }; - typename base::float_point_expr<4> result = get_variable(src); + float_point_expr<4> result = get_variable(src); result.assign(result.swizzle(src.swizzle_x, src.swizzle_y, src.swizzle_z, src.swizzle_w)); @@ -190,7 +190,7 @@ namespace rsx return swizzle; } - typename base::float_point_expr<4> destination(context_t& context) const + float_point_expr<4> destination(context_t& context) const { if (data.dst.no_dest) { @@ -206,22 +206,22 @@ namespace rsx instruction_t instruction; context_t context; - typename base::float_point_expr<4> src(int index, bool is_swizzle_as_dst = false) + float_point_expr<4> src(int index, bool is_swizzle_as_dst = false) { return instruction.src(context, index, is_swizzle_as_dst); } - typename base::float_point_expr<4> src_swizzled_as_dst(int index) + float_point_expr<4> src_swizzled_as_dst(int index) { return src(index, instruction.data.dst.set_cond || !instruction.data.dst.no_dest); } - typename base::float_point_expr<4> modify_condition_register() + float_point_expr<4> modify_condition_register() { return context.condition(instruction.data.src0.cond_mod_reg_index); } - typename base::float_point_expr<4> execution_condition_register() + float_point_expr<4> execution_condition_register() { std::string swizzle; @@ -270,7 +270,7 @@ namespace rsx throw; } - typename base::boolean_expr<1> execution_condition(condition_operation operation) + boolean_expr<1> execution_condition(condition_operation operation) { if (instruction.data.src0.exec_if_gr && instruction.data.src0.exec_if_eq && instruction.data.src0.exec_if_gr) { @@ -302,12 +302,12 @@ namespace rsx throw; } - typename boolean_expr<4> compare(typename base::compare_function function, float_point_expr<4> a, float_point_expr<4> b) + boolean_expr<4> compare(typename base::compare_function function, float_point_expr<4> a, float_point_expr<4> b) { return base::custom_compare(function, (int)instruction.destination_swizzle().size(), a, b); } - typename base::expression_from tex() + typename base::template expression_from tex() { return{ "unk_tex" }; } @@ -381,7 +381,7 @@ namespace rsx return arg; } - builder::writer_t set_dst(const typename base::float_point_expr<4>& arg, u32 flags = none) + builder::writer_t set_dst(const float_point_expr<4>& arg, u32 flags = none) { builder::writer_t result; @@ -427,7 +427,7 @@ namespace rsx } else { - static const typename base::float_point_expr<1> zero(0.0f); + static const float_point_expr<1> zero(0.0f); std::map>> condition_map; @@ -458,7 +458,7 @@ namespace rsx dst_swizzle += dest.swizzle(channels.second).mask[0]; } - typename base::float_point_expr<4> expression{ src.with_mask(src_swizzle) }; + float_point_expr<4> expression{ src.with_mask(src_swizzle) }; if (!instruction.data.dst.no_dest) { @@ -470,7 +470,7 @@ namespace rsx expression.assign(cond.with_mask(dst_swizzle) = expression); } - result += base::if_(cond.swizzle(channel_to_index.at(entry.first)).call_operator>(operation, zero), expression); + result += base::if_(cond.swizzle(channel_to_index.at(entry.first)).template call_operator>(operation, zero), expression); } } } @@ -504,7 +504,7 @@ namespace rsx return result; } - builder::writer_t set_dst(const typename base::float_point_expr<1>& arg, u32 flags = none) + builder::writer_t set_dst(const float_point_expr<1>& arg, u32 flags = none) { if (instruction.destination_swizzle().size() != 1) { diff --git a/rsx_decompiler/rsx_vp_decompiler.cpp b/rsx_decompiler/rsx_vp_decompiler.cpp index 6659273..b13f2cf 100644 --- a/rsx_decompiler/rsx_vp_decompiler.cpp +++ b/rsx_decompiler/rsx_vp_decompiler.cpp @@ -13,22 +13,22 @@ namespace rsx using base = decompiler_base; template - using boolean_expr = typename base::boolean_expr; + using boolean_expr = typename base::template boolean_expr; template - using float_point_expr = typename base::float_point_expr; + using float_point_expr = typename base::template float_point_expr; template - using integer_expr = typename base::integer_expr; + using integer_expr = typename base::template integer_expr; template - using float_point_t = typename base::float_point_t; + using float_point_t = typename base::template float_point_t; template - using boolean_t = typename base::boolean_t; + using boolean_t = typename base::template boolean_t; template - using integer_t = typename base::integer_t; + using integer_t = typename base::template integer_t; struct context_t { @@ -402,7 +402,7 @@ namespace rsx expression.assign(cond.with_mask(dst_swizzle) = expression); } - result += base::if_(cond.swizzle(channel_to_index.at(entry.first)).call_operator>(operation, zero), expression); + result += base::if_(cond.swizzle(channel_to_index.at(entry.first)).template call_operator>(operation, zero), expression); } } } @@ -462,7 +462,7 @@ namespace rsx any }; - typename base::compare_function execution_condition_function(u32 condition = instruction.data.d0.cond) const + typename base::compare_function execution_condition_function(u32 condition) const { switch (condition) { diff --git a/shader_code/clike_builder.h b/shader_code/clike_builder.h index c23c411..b193c51 100644 --- a/shader_code/clike_builder.h +++ b/shader_code/clike_builder.h @@ -24,7 +24,7 @@ namespace shader_code return invoke(); } - static expression_t<> ctor(typename native_type_t::type value) + static expression_t<> ctor(typename clike_language::native_type_t::type value) { return invoke(expression_t(native_type_t::to_string(value))); } @@ -37,7 +37,7 @@ namespace shader_code static constexpr const char* name() { - using type_name_t = typename language::type_name_t; + using type_name_t = typename language::template type_name_t; return type_name_t::name; } @@ -45,7 +45,7 @@ namespace shader_code template static expression_t<> invoke(T... exprs) { - return function_t, typename language::type_name_t>::invoke(exprs...); + return function_t, typename language::template type_name_t>::invoke(exprs...); } }; @@ -65,14 +65,14 @@ namespace shader_code using base::ctor; template - static typename base::expression_t<> ctor(typename base::expression_t expr) + static typename base::template expression_t<> ctor(typename base::template expression_t expr) { - return this->invoke(expr); + return base::invoke(expr); } - static typename base::expression_t<> ctor(typename base::expression_t a, typename base::expression_t b) + static typename base::template expression_t<> ctor(typename base::template expression_t a, typename base::template expression_t b) { - return this->invoke(a, b); + return base::invoke(a, b); } }; @@ -83,25 +83,25 @@ namespace shader_code using base::ctor; template - static typename base::expression_t<> ctor(typename base::expression_t expr) + static typename base::template expression_t<> ctor(typename base::template expression_t expr) { - return this->invoke(expr); + return base::invoke(expr); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b) { - return this->invoke(a, b); + return base::invoke(a, b); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b) { - return this->invoke(a, b); + return base::invoke(a, b); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b, - typename base::expression_t c) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b, + typename base::template expression_t c) { - return this->invoke(a, b, c); + return base::invoke(a, b, c); } }; @@ -112,57 +112,57 @@ namespace shader_code using base::ctor; template - static typename base::expression_t ctor(typename base::expression_t expr) + static typename base::template expression_t ctor(typename base::template expression_t expr) { - return base::invoke(expr); + return base::template invoke(expr); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b) { - return base::invoke(a, b); + return base::template invoke(a, b); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b) { - return base::invoke(a, b); + return base::template invoke(a, b); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b) { - return base::invoke(a, b); + return base::template invoke(a, b); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b, - typename base::expression_t c, typename base::expression_t d) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b, + typename base::template expression_t c, typename base::template expression_t d) { - return base::invoke(a, b, c, d); + return base::template invoke(a, b, c, d); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b, - typename base::expression_t c) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b, + typename base::template expression_t c) { - return base::invoke(a, b, c); + return base::template invoke(a, b, c); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b, - typename base::expression_t c) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b, + typename base::template expression_t c) { - return base::invoke(a, b, c); + return base::template invoke(a, b, c); } - static typename base::expression_t ctor(typename base::expression_t a, typename base::expression_t b, - typename base::expression_t c) + static typename base::template expression_t ctor(typename base::template expression_t a, typename base::template expression_t b, + typename base::template expression_t c) { - return base::invoke(a, b, c); + return base::template invoke(a, b, c); } }; - using sampler1D_t = typename type_t; - using sampler2D_t = typename type_t; - using sampler3D_t = typename type_t; + using sampler1D_t = type_t; + using sampler2D_t = type_t; + using sampler3D_t = type_t; template - using boolean_t = typename type_t; + using boolean_t = type_t; template - using integer_t = typename type_t; + using integer_t = type_t; template - using float_point_t = typename type_t; + using float_point_t = type_t; using void_expr = expression_from; template using float_point_expr = expression_from>; @@ -171,187 +171,187 @@ namespace shader_code static expression_from> texture(const expression_from& texture, const expression_from>& coord) { - return function_t, typename language::function_name_t>::invoke(texture, coord); + return function_t, typename language::template function_name_t>::invoke(texture, coord); } static expression_from> texture(const expression_from& texture, const expression_from>& coord) { - return function_t, typename language::function_name_t>::invoke(texture, coord); + return function_t, typename language::template function_name_t>::invoke(texture, coord); } static expression_from> texture_lod(const expression_from& texture, const expression_from>& coord, const expression_from>& lod) { - return function_t, typename language::function_name_t>::invoke(texture, coord, lod); + return function_t, typename language::template function_name_t>::invoke(texture, coord, lod); } static expression_from> texture_bias(const expression_from& texture, const expression_from>& coord, const expression_from>& bias) { - return function_t, typename language::function_name_t>::invoke(texture, coord, bias); + return function_t, typename language::template function_name_t>::invoke(texture, coord, bias); } static expression_from> texture_grad(const expression_from& texture, const expression_from>& coord, const expression_from>& ddx, const expression_from>& ddy) { - return function_t, typename language::function_name_t>::invoke(texture, coord, ddx, ddy); + return function_t, typename language::template function_name_t>::invoke(texture, coord, ddx, ddy); } static expression_from> texture(const expression_from& texture, const expression_from>& coord) { - return function_t, typename language::function_name_t>::invoke(texture, coord); + return function_t, typename language::template function_name_t>::invoke(texture, coord); } template static expression_from> normalize(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> abs(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> abs(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> any(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template 1)>> static expression_from> all(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template 1)>> static expression_from> dot(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_t min(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_t max(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> greater(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> less(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> equal(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> greater_equal(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> less_equal(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> not_equal(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> fract(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> floor(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> sin(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> cos(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> clamp(const expression_t& a, const expression_t& b, const expression_t& c) { - return function_t, typename language::function_name_t>::invoke(a, b, c); + return function_t, typename language::template function_name_t>::invoke(a, b, c); } template static expression_from> sqrt(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> rsqrt(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> pow(const expression_t& a, const expression_t& b) { - return function_t, typename language::function_name_t>::invoke(a, b); + return function_t, typename language::template function_name_t>::invoke(a, b); } template static expression_from> exp(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> log(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> exp2(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> log2(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> ddx(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } template static expression_from> ddy(const expression_t& arg) { - return function_t, typename language::function_name_t>::invoke(arg); + return function_t, typename language::template function_name_t>::invoke(arg); } }; -} \ No newline at end of file +} diff --git a/shader_code/clike_language.h b/shader_code/clike_language.h index 9ddadb9..4850719 100644 --- a/shader_code/clike_language.h +++ b/shader_code/clike_language.h @@ -4,7 +4,7 @@ namespace shader_code { - struct clike_language + namespace clike_language_impl { enum class type_class_t { @@ -17,6 +17,27 @@ namespace shader_code type_sampler3D }; + template + using type_t = builder::type_t; + + template + using boolean_t = type_t; + + template + using integer_t = type_t; + + template + using float_point_t = type_t; + + + using sampler1D_t = type_t; + using sampler2D_t = type_t; + using sampler3D_t = type_t; + using void_t = type_t; + + template + struct native_type_t; + template struct native_type_base_t { @@ -28,9 +49,6 @@ namespace shader_code } }; - template - struct native_type_t; - template<> struct native_type_t { @@ -80,64 +98,9 @@ namespace shader_code { }; - template - using type_t = builder::type_t; - - template - using boolean_t = typename type_t; - - template - using integer_t = typename type_t; - - template - using float_point_t = typename type_t; - - using sampler1D_t = type_t; - using sampler2D_t = type_t; - using sampler3D_t = type_t; - using void_t = type_t; - - enum function_class_t - { - function_abs, - function_fract, - function_floor, - function_exp, - function_log, - function_exp2, - function_log2, - function_pow, - function_texture, - function_texture_lod, - function_texture_bias, - function_texture_grad, - function_normalize, - function_any, - function_all, - function_dot, - function_min, - function_max, - function_greater, - function_less, - function_equal, - function_greater_equal, - function_less_equal, - function_not_equal, - function_sin, - function_cos, - function_clamp, - function_sqrt, - function_rsqrt, - function_ddx, - function_ddy - }; - template struct expression_t; - template - using expression_from = expression_t; - template struct expression_helper_t : public builder::expression_base_t { @@ -151,22 +114,22 @@ namespace shader_code expression_helper_t(const std::string& text, bool is_single = true, int base_count = Count) : expression_base_t{ text } - , is_single(is_single) , mask{ std::string("xyzw").substr(0, base_count) } + , is_single(is_single) , base_count(base_count) { } expression_helper_t(const std::string& text, const std::string& mask, bool is_single = true, int base_count = Count) : expression_base_t{ text } - , is_single(is_single) , mask(mask) + , is_single(is_single) , base_count(base_count) { } template - expression_helper_t(const std::string& text, const char (&mask)[N], bool is_single = true, int base_count = Count) + expression_helper_t(const std::string& text, const char(&mask)[N], bool is_single = true, int base_count = Count) : expression_helper_t{ text, std::string(mask), is_single, base_count } { static_assert(N == Count + 1, "Bad swizzle!"); @@ -180,8 +143,8 @@ namespace shader_code base_count = rhs.base_count; } - template - expression_t as() const + template + expression_t as() const { return{ text, mask, is_single, base_count }; } @@ -199,7 +162,7 @@ namespace shader_code std::string new_mask; using sw = std::string[]; sw{ (new_mask += mask.substr(channels, 1))... }; - + return{ !is_single ? "(" + text + ")" : text, new_mask, is_single, base_count }; } @@ -243,7 +206,7 @@ namespace shader_code return{ text, mask, true, base_count }; } - //protected: + //protected: template expression_t call_operator(const std::string& opname, const ArgType& rhs) const { @@ -257,6 +220,9 @@ namespace shader_code } }; + template + using expression_from = expression_t; + template struct expression_ctors_t : public expression_helper_t { @@ -459,7 +425,7 @@ namespace shader_code template struct expression_t : public expression_swizzle_t { - using base = typename expression_swizzle_t; + using base = expression_swizzle_t; using base::base; const expression_t operator -() @@ -513,9 +479,18 @@ namespace shader_code expression_t operator=(const expression_t& rhs) { return this->call_operator("=", rhs); } - const expression_from> operator!() const { return this->call_operator>("!"); } - const expression_from> operator==(const expression_t& rhs) const { return this->call_operator>("==", rhs); } - const expression_from> operator!=(const expression_t& rhs) const { return this->call_operator>("!=", rhs); } + const expression_t operator!() const + { + return this->call_operator>("!"); + } + const expression_t operator==(const expression_t& rhs) const + { + return this->call_operator>("==", rhs); + } + const expression_t operator!=(const expression_t& rhs) const + { + return this->call_operator>("!=", rhs); + } }; template @@ -536,7 +511,7 @@ namespace shader_code const expression_t operator -() { if (this->is_single && this->text[0] == '-') - return expression_t{ this->text.substr(1), mask }; + return expression_t{ this->text.substr(1), base::mask }; return this->call_operator("-"); } @@ -555,8 +530,8 @@ namespace shader_code return this->call_operator("+", rhs); } - template const expression_t operator/(const expression_t& rhs) const { return this->call_operator>("/", rhs); } - template const expression_t operator*(const expression_t& rhs) const { return this->call_operator>("*", rhs); } + template const expression_t operator/(const expression_t& rhs) const { return this->template call_operator>("/", rhs); } + template const expression_t operator*(const expression_t& rhs) const { return this->template call_operator>("*", rhs); } expression_t operator=(const expression_t& rhs) { return this->call_operator("=", rhs); } @@ -565,20 +540,14 @@ namespace shader_code expression_t operator/=(const expression_t& rhs) { return this->call_operator("/=", rhs); } expression_t operator*=(const expression_t& rhs) { return this->call_operator("*=", rhs); } - const expression_from> operator >(const expression_t& rhs) const { return this->call_operator>(">", rhs); } - const expression_from> operator >=(const expression_t& rhs) const { return this->call_operator>(">=", rhs); } - const expression_from> operator <(const expression_t& rhs) const { return this->call_operator>("<", rhs); } - const expression_from> operator <=(const expression_t& rhs) const { return this->call_operator>("<=", rhs); } - const expression_from> operator==(const expression_t& rhs) const { return this->call_operator>("==", rhs); } - const expression_from> operator!=(const expression_t& rhs) const { return this->call_operator>("!=", rhs); } + const expression_from> operator >(const expression_t& rhs) const { return this->template call_operator>(">", rhs); } + const expression_from> operator >=(const expression_t& rhs) const { return this->template call_operator>(">=", rhs); } + const expression_from> operator <(const expression_t& rhs) const { return this->template call_operator>("<", rhs); } + const expression_from> operator <=(const expression_t& rhs) const { return this->template call_operator>("<=", rhs); } + const expression_from> operator==(const expression_t& rhs) const { return this->template call_operator>("==", rhs); } + const expression_from> operator!=(const expression_t& rhs) const { return this->template call_operator>("!=", rhs); } }; - template - static expression_t<(type_class_t)Type::type, Type::count> expression(const std::string& text, bool is_single = true) - { - return{ text, is_single }; - } - template struct function_t { @@ -609,6 +578,81 @@ namespace shader_code return{ result + ")" }; } }; + } + + struct clike_language + { + using type_class_t = clike_language_impl::type_class_t; + + template + using type_t = clike_language_impl::type_t; + + template + using expression_t = clike_language_impl::expression_t; + + template + using boolean_t = clike_language_impl::boolean_t; + + template + using integer_t = clike_language_impl::integer_t; + + template + using float_point_t = clike_language_impl::float_point_t; + + using sampler1D_t = type_t; + using sampler2D_t = type_t; + using sampler3D_t = type_t; + using void_t = type_t; + + template + using expression_from = expression_t; + + template + using function_t = clike_language_impl::function_t; + + template + using native_type_t = clike_language_impl::native_type_t; + + enum function_class_t + { + function_abs, + function_fract, + function_floor, + function_exp, + function_log, + function_exp2, + function_log2, + function_pow, + function_texture, + function_texture_lod, + function_texture_bias, + function_texture_grad, + function_normalize, + function_any, + function_all, + function_dot, + function_min, + function_max, + function_greater, + function_less, + function_equal, + function_greater_equal, + function_less_equal, + function_not_equal, + function_sin, + function_cos, + function_clamp, + function_sqrt, + function_rsqrt, + function_ddx, + function_ddy + }; + + template + static expression_t<(type_class_t)Type::type, Type::count> expression(const std::string& text, bool is_single = true) + { + return{ text, is_single }; + } template static expression_from if_(expression_from> condition, expression_t then) diff --git a/shader_code/glsl_language.h b/shader_code/glsl_language.h index c75aa70..e803dde 100644 --- a/shader_code/glsl_language.h +++ b/shader_code/glsl_language.h @@ -3,7 +3,7 @@ namespace shader_code { - struct glsl_language + namespace glsl_language_impl { template struct type_name_t; @@ -288,5 +288,14 @@ namespace shader_code { static constexpr char *name = "dFdy"; }; + } + + struct glsl_language + { + template + using type_name_t = glsl_language_impl::type_name_t; + + template + using function_name_t = glsl_language_impl::function_name_t; }; -} \ No newline at end of file +}