From: Hymans, C. <Cha...@ea...> - 2005-07-28 07:54:09
|
=20 Hi, =20 By default, the following code: ------------- int a; f((a=3D=3D1) || (a=3D=3D2)); ------------- is transformed by CIL to: ------------- int a ; int tmp ; =20 { #line 3 if (a =3D=3D 1) { #line 3 tmp =3D 1; } else { #line 3 if (a =3D=3D 2) { #line 3 tmp =3D 1; } else { #line 3 tmp =3D 0; } } #line 3 f(tmp); ------------- I would like to keep the original shape of the code. After reading cabs2cil.ml, I found out setting useLogicalOperators to true yields the following result: ------------- int a ; =20 { #line 3 f((a =3D=3D 1 || a =3D=3D 2) !=3D 0); ------------- =20 I noticed afterwards that useLogicalOperators is documented as: ------------- val useLogicalOperators : bool Pervasives.ref Whether to use the logical operands LAnd and LOr. By default, do not use them because they are unlike other expressions and do not evaluate both of their operands ------------- =20 However, I find the explanation hard to understand. Maybe it should read something like: ------------- Set useLogicalOperators to true if you want to keep boolean expressions without side-effects as close as possible to the original code. ------------- =20 Still, it would be nice to get rid of the !=3D 0 in the expression ((a = =3D=3D 1 || a =3D=3D 2) !=3D 0).=20 I understand that this transformation is sometimes necessary. For instance the following code: ------------------ int a; f(0||a); ------------------ is transformed to=20 ------------------ int a; f(a !=3D 0); ------------------=20 =20 So in order to do that, maybe it's ok to add the following code at line 3465 of file cabs2cil.ml: ------------------ | CEExp (se, (BinOp((LAnd|LOr), _, _, _)|UnOp(LNot, _, _) as e)) -> finishExp se e intType ------------------=20 =20 Is this modification correct ? =20 Thanks,=20 Charles |