Esempio n. 1
0
node *OSbinop (node *arg_node, info *arg_info)
{
  DBUG_ENTER("OSbinop");

  /*
   * Extremely important:
   *  we must continue to traverse the abstract syntax tree !!
   */
  BINOP_LEFT( arg_node) = TRAVdo( BINOP_LEFT( arg_node), arg_info);
  BINOP_RIGHT( arg_node) = TRAVdo( BINOP_RIGHT( arg_node), arg_info);

  if (BINOP_OP( arg_node) == BO_sub) {
    if ((NODE_TYPE( BINOP_LEFT( arg_node)) == N_var)
	&& (NODE_TYPE( BINOP_RIGHT( arg_node)) == N_var)
	&& STReq( VAR_NAME( BINOP_LEFT( arg_node)), VAR_NAME( BINOP_RIGHT( arg_node)))) {
      arg_node = FREEdoFreeTree( arg_node);
      arg_node = TBmakeNum( 0);
    }
    else if  ((NODE_TYPE( BINOP_LEFT( arg_node)) == N_num)
	      && (NODE_TYPE( BINOP_RIGHT( arg_node)) == N_num)
	      && (NUM_VALUE( BINOP_LEFT( arg_node)) == NUM_VALUE( BINOP_RIGHT( arg_node)))) {
      arg_node = FREEdoFreeTree( arg_node);
      arg_node = TBmakeNum( 0);
    }
  }

  DBUG_RETURN( arg_node);
}
Esempio n. 2
0
//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);
	}
Esempio n. 3
0
/** <!--******************************************************************-->
 *
 * @fn COPYnum
 *
 * @brief Copies the node and its sons/attributes
 *
 * @param arg_node Num node to process
 * @param arg_info pointer to info structure
 *
 * @return processed node
 *
 ***************************************************************************/
node *
COPYnum (node * arg_node, info * arg_info)
{
  node *result = TBmakeNum (0);
  DBUG_ENTER ("COPYnum");
  LUTinsertIntoLutP (INFO_LUT (arg_info), arg_node, result);
  /* Copy attributes */
  NUM_VALUE (result) = NUM_VALUE (arg_node);
  /* Return value */
  DBUG_RETURN (result);
}