]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.cpp
Refactor handling of %, << and >> in ConstantFolder
[libs/gl.git] / source / glsl / optimize.cpp
index 044dd4e5a29ef1eefde6985b5c4798b93cf239fd..06ea0f49c98a03b4c8186449eaac823d922a4719 100644 (file)
@@ -592,6 +592,18 @@ T ConstantFolder::evaluate_arithmetic(char oper, T left, T right)
        }
 }
 
+template<typename T>
+T ConstantFolder::evaluate_int_special_op(char oper, T left, T right)
+{
+       switch(oper)
+       {
+       case '%': return left%right;
+       case '<': return left<<right;
+       case '>': 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<int>())
-                       return;
-
-               if(oper=='%')
-                       set_result(left_value.value<int>()%r_constant_value.value<int>());
-               else if(oper=='<')
-                       set_result(left_value.value<int>()<<r_constant_value.value<int>());
-               else if(oper=='>')
-                       set_result(left_value.value<int>()>>r_constant_value.value<int>());
+               if(left_value.check_type<int>())
+                       set_result(evaluate_int_special_op(oper, left_value.value<int>(), r_constant_value.value<int>()));
        }
 }