Selaa lähdekoodia

fixed issue where bool_op phase would not traverse properly in nested expressions

Taddeus Kroes 12 vuotta sitten
vanhempi
sitoutus
efd38ab9df
2 muutettua tiedostoa jossa 6 lisäystä ja 6 poistoa
  1. 5 5
      phases/bool_op.ml
  2. 1 1
      stringify.ml

+ 5 - 5
phases/bool_op.ml

@@ -27,19 +27,19 @@ let floatconst value = Const (FloatVal value, [Type Float])
 
 let rec trav_binop = function
     | ((Eq | Ne) as op, left, right, loc) ->
-        Binop (op, cast Int left, cast Int right, loc)
+        Binop (op, cast Int (bool_op left), cast Int (bool_op right), loc)
 
     | (And, left, right, loc) ->
-        Cond (left, right, boolconst false, loc)
+        Cond (bool_op left, bool_op right, boolconst false, loc)
 
     | (Or, left, right, loc) ->
-        Cond (left, boolconst true, right, loc)
+        Cond (bool_op left, boolconst true, bool_op right, loc)
 
     | ((Add | Mul) as op, left, right, loc) ->
-        cast Bool (Binop (op, cast Int left, cast Int right, loc))
+        cast Bool (Binop (op, cast Int (bool_op left), cast Int (bool_op right), loc))
 
     | (op, left, right, loc) ->
-        Binop (op, left, right, loc)
+        Binop (op, bool_op left, bool_op right, loc)
 
 and bool_op = function
     | Binop (op, left, right, loc) when typeof left = Bool && typeof right = Bool ->

+ 1 - 1
stringify.ml

@@ -133,7 +133,7 @@ and node2str node =
         "(" ^ str left ^ " " ^ op2str op ^ " " ^ str right ^ ")"
     | TypeCast (ctype, value, _) -> "(" ^ type2str ctype ^ ")" ^ str value
     | FunCall (name, args, _) -> name ^ "(" ^ (concat ", " args) ^ ")"
-    | Cond (cond, t, f, _) -> (str cond) ^ " ? " ^ str t ^ " : " ^ str f
+    | Cond (cond, t, f, _) -> "(" ^ (str cond) ^ " ? " ^ str t ^ " : " ^ str f ^ ")"
 
     (* Annotation nodes print more information at higher verbosity, for
      * debugging purposes *)