From: Mikko Rasa Date: Tue, 20 Apr 2021 15:18:25 +0000 (+0300) Subject: Refactor handling of %, << and >> in ConstantFolder X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3c2397dbb6e45fe72214f71048c4edfe4f11ac73;p=libs%2Fgl.git Refactor handling of %, << and >> in ConstantFolder This is in line with the other operators and makes adding unsigned types easier. --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 044dd4e5..06ea0f49 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -592,6 +592,18 @@ T ConstantFolder::evaluate_arithmetic(char oper, T left, T right) } } +template +T ConstantFolder::evaluate_int_special_op(char oper, T left, T right) +{ + switch(oper) + { + case '%': return left%right; + case '<': return left<': return left>>right; + default: return T(); + } +} + void ConstantFolder::set_result(const Variant &value, bool literal) { r_constant_value = value; @@ -745,15 +757,8 @@ void ConstantFolder::visit(BinaryExpression &binary) } else if(oper=='%' || ((oper=='<' || oper=='>') && oper2==oper)) { - if(!left_value.check_type()) - return; - - if(oper=='%') - set_result(left_value.value()%r_constant_value.value()); - else if(oper=='<') - set_result(left_value.value()<()); - else if(oper=='>') - set_result(left_value.value()>>r_constant_value.value()); + if(left_value.check_type()) + set_result(evaluate_int_special_op(oper, left_value.value(), r_constant_value.value())); } } diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index a714a97a..ed9f9134 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -181,6 +181,8 @@ private: static bool evaluate_relation(const char *, T, T); template static T evaluate_arithmetic(char, T, T); + template + static T evaluate_int_special_op(char, T, T); void set_result(const Variant &, bool = false); virtual void visit(RefPtr &);