]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Handle "modulo" operation on floating-types in CCodeAssignmentModule
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 26 Mar 2019 12:00:01 +0000 (13:00 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 26 Mar 2019 12:08:37 +0000 (13:08 +0100)
Duplication with CCodeBaseModule.visit_binary_expression()

See https://gitlab.gnome.org/GNOME/vala/issues/755

codegen/valaccodeassignmentmodule.vala
codegen/valaccodebasemodule.vala

index 96a47524eb9358277e1ef35f98d7620bc8c0c697..617293b0a67e81382f3293492e38898507e3a6fa 100644 (file)
@@ -49,7 +49,28 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
                        case AssignmentOperator.SUB: cop = CCodeAssignmentOperator.SUB; break;
                        case AssignmentOperator.MUL: cop = CCodeAssignmentOperator.MUL; break;
                        case AssignmentOperator.DIV: cop = CCodeAssignmentOperator.DIV; break;
-                       case AssignmentOperator.PERCENT: cop = CCodeAssignmentOperator.PERCENT; break;
+                       case AssignmentOperator.PERCENT:
+                               // FIXME Code duplication with CCodeBaseModule.visit_binary_expression()
+                               var cleft = get_cvalue (assignment.left);
+                               var cright = get_cvalue (assignment.right);
+                               if (assignment.value_type.equals (double_type)) {
+                                       cfile.add_include ("math.h");
+                                       var ccall = new CCodeFunctionCall (new CCodeIdentifier ("fmod"));
+                                       ccall.add_argument (cleft);
+                                       ccall.add_argument (cright);
+                                       set_cvalue (assignment.right, ccall);
+                                       cop = CCodeAssignmentOperator.SIMPLE;
+                               } else if (assignment.value_type.equals (float_type)) {
+                                       cfile.add_include ("math.h");
+                                       var ccall = new CCodeFunctionCall (new CCodeIdentifier ("fmodf"));
+                                       ccall.add_argument (cleft);
+                                       ccall.add_argument (cright);
+                                       set_cvalue (assignment.right, ccall);
+                                       cop = CCodeAssignmentOperator.SIMPLE;
+                               } else {
+                                       cop = CCodeAssignmentOperator.PERCENT;
+                               }
+                               break;
                        case AssignmentOperator.SHIFT_LEFT: cop = CCodeAssignmentOperator.SHIFT_LEFT; break;
                        case AssignmentOperator.SHIFT_RIGHT: cop = CCodeAssignmentOperator.SHIFT_RIGHT; break;
                        default: assert_not_reached ();
index 8e9863aedc367050aa3982395d04a6cbe3ea9dce..62fd6655440fb1cc5249099786a6911482e37342 100644 (file)
@@ -5471,6 +5471,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        op = CCodeBinaryOperator.DIV;
                        break;
                case BinaryOperator.MOD:
+                       // FIXME Code duplication with CCodeAssignmentModule.emit_simple_assignment()
                        if (expr.value_type.equals (double_type)) {
                                cfile.add_include ("math.h");
                                var ccall = new CCodeFunctionCall (new CCodeIdentifier ("fmod"));