//rewrite cast and set info_type to cast type node *CTcast(node *arg_node, info *arg_info){ DBUG_ENTER("CTcast"); extern node *CTbinop( node *arg_node, info *arg_info); extern node *CTfunbody( node *arg_node, info *arg_info); CAST_EXPRESSION(arg_node) = TRAVdo(CAST_EXPRESSION(arg_node), arg_info); type exprType = INFO_TYPE(arg_info); type castType = CAST_TYPE(arg_node); //set info type to cast type INFO_TYPE(arg_info) = CAST_TYPE(arg_node); //rewrite cast if(exprType == T_boolean && castType == T_int){ node *expr = CAST_EXPRESSION(arg_node); node *then = TBmakeNum(1); node *other = TBmakeNum(0); node *condexpr = TBmakeConditionexpr(expr, other, then); arg_node = condexpr; } else if(exprType == T_boolean && castType == T_float){ node *expr = CAST_EXPRESSION(arg_node); node *then = TBmakeFloat(1.0); node *other = TBmakeFloat(0.0); node *condexpr = TBmakeConditionexpr(expr, then, other); arg_node = condexpr; } else if(exprType == T_int && castType == T_boolean){ node *expr = TBmakeBinop(BO_gt, CAST_EXPRESSION(arg_node), TBmakeNum(0)); BINOP_OPTYPE(expr) = T_int; node *then = TBmakeBool(true); node *other = TBmakeBool(false); node *condexpr = TBmakeConditionexpr(expr, other, then); arg_node = condexpr; } else if(exprType == T_float && castType == T_boolean){ node *expr = TBmakeBinop(BO_gt, CAST_EXPRESSION(arg_node), TBmakeFloat(0.0)); BINOP_OPTYPE(expr) = T_float; node *then = TBmakeBool(true); node *other = TBmakeBool(false); node *condexpr = TBmakeConditionexpr(expr, other, then); arg_node = condexpr; } DBUG_RETURN(arg_node); }
/** <!--******************************************************************--> * * @fn COPYbinop * * @brief Copies the node and its sons/attributes * * @param arg_node BinOp node to process * @param arg_info pointer to info structure * * @return processed node * ***************************************************************************/ node * COPYbinop (node * arg_node, info * arg_info) { node *result = TBmakeBinop (BO_unknown, NULL, NULL); DBUG_ENTER ("COPYbinop"); LUTinsertIntoLutP (INFO_LUT (arg_info), arg_node, result); /* Copy attributes */ BINOP_OP (result) = BINOP_OP (arg_node); /* Copy sons */ BINOP_LEFT (result) = COPYTRAV (BINOP_LEFT (arg_node), arg_info); BINOP_RIGHT (result) = COPYTRAV (BINOP_RIGHT (arg_node), arg_info); /* Return value */ DBUG_RETURN (result); }