Exemplo n.º 1
0
node* CALCCONSTmonop(node *arg_node, info *arg_info){
  DBUG_ENTER ("CALCCONSTmonop");
  node * ret;
  MONOP_EXPR( arg_node) = TRAVopt( MONOP_EXPR( arg_node), NULL);
  nodetype nt = NODE_TYPE(MONOP_EXPR( arg_node));
  if(MONOP_OP(arg_node) == MO_not && nt == N_bool){
    ret = TBmakeBool(! BOOL_VALUE(MONOP_EXPR( arg_node)));
    FREEdoFreeNode(arg_node);
    DBUG_RETURN(ret);
  }else if(MONOP_OP(arg_node) == MO_neg){
    if(nt == N_int){
      ret = TBmakeInt(-INT_VALUE(MONOP_EXPR( arg_node)));
    FREEdoFreeNode(arg_node);
    DBUG_RETURN(ret);

    }else if(nt == N_float){
      ret = TBmakeFloat(-FLOAT_VALUE(MONOP_EXPR( arg_node)));
    FREEdoFreeNode(arg_node);
    DBUG_RETURN(ret);

    }else{
      DBUG_RETURN (arg_node);
    }
  }else{
    DBUG_RETURN (arg_node);
  }

}
Exemplo n.º 2
0
//check type of monop with operand
node *CTmonop(node *arg_node, info *arg_info){
	DBUG_ENTER("CTmonop");

	//get type of operand in info_type
	MONOP_OPERAND(arg_node) = TRAVdo(MONOP_OPERAND(arg_node), arg_info);
	

	//check if type is boolean.

	if(MONOP_OP(arg_node) == MO_not && INFO_TYPE(arg_info) != T_boolean){
		CTIerrorLine(NODE_LINE(arg_node), "!(not) can only be used with a boolean operand");
	}
	else{
		MONOP_OPTYPE(arg_node) = T_boolean;
	}
	if(MONOP_OP(arg_node) == MO_neg && INFO_TYPE(arg_info) == T_boolean){
		CTIerrorLine(NODE_LINE(arg_node), "-(neg) can only be used with a boolean operand");
	}
	else if(INFO_TYPE(arg_info) == T_int){
		MONOP_OPTYPE(arg_node) = T_int;
	}
	else{
		MONOP_OPTYPE(arg_node) = T_float;
	}

	DBUG_RETURN(arg_node);
}
Exemplo n.º 3
0
/** <!--******************************************************************-->
 *
 * @fn COPYmonop
 *
 * @brief Copies the node and its sons/attributes
 *
 * @param arg_node MonOp node to process
 * @param arg_info pointer to info structure
 *
 * @return processed node
 *
 ***************************************************************************/
node *
COPYmonop (node * arg_node, info * arg_info)
{
  node *result = TBmakeMonop (MO_unknown, NULL);
  DBUG_ENTER ("COPYmonop");
  LUTinsertIntoLutP (INFO_LUT (arg_info), arg_node, result);
  /* Copy attributes */
  MONOP_OP (result) = MONOP_OP (arg_node);
  /* Copy sons */
  MONOP_RIGHT (result) = COPYTRAV (MONOP_RIGHT (arg_node), arg_info);
  /* Return value */
  DBUG_RETURN (result);
}