Example #1
0
/** <!--******************************************************************-->
 *
 * @fn COPYbool
 *
 * @brief Copies the node and its sons/attributes
 *
 * @param arg_node Bool node to process
 * @param arg_info pointer to info structure
 *
 * @return processed node
 *
 ***************************************************************************/
node *
COPYbool (node * arg_node, info * arg_info)
{
  node *result = TBmakeBool (FALSE);
  DBUG_ENTER ("COPYbool");
  LUTinsertIntoLutP (INFO_LUT (arg_info), arg_node, result);
  /* Copy attributes */
  BOOL_VALUE (result) = BOOL_VALUE (arg_node);
  /* Return value */
  DBUG_RETURN (result);
}
Example #2
0
void valueCopy(dplVal *to, dplVal *from) {
	if(from->isArray == TRUE) {
		arrayValueCopy(to, from);
	}
	else {
		to->type = from->type;

		switch(from->type) {
			case IS_INT:
				to->value.ival = INT_VALUE(from);
			break;
			case IS_DOUBLE:
				to->value.dval = DOUBLE_VALUE(from);
			break;
			case IS_BOOL:
				to->value.boolval = BOOL_VALUE(from);
			break;
			case IS_STRING:
				to->value.str.val = strdup(STR_VALUE(from));
				to->value.str.len = STR_LEN(from);
			break;
			case IS_FILE:
				FILE_PATH(to) = strdup(FILE_PATH(from));
				FILE_HANDLE(to) = FILE_HANDLE(from);
				FILE_SIZE(to) = FILE_SIZE(from);
				FILE_DATA(to) = FILE_DATA(from);
			break;
		}
	}
}
Example #3
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);
  }

}
Example #4
0
node *
PRTbool (node * arg_node, info * arg_info)
{
  DBUG_ENTER ("PRTbool");

  if (BOOL_VALUE( arg_node)) {
    printf( "true");
  }
  else {
    printf( "false");
  }
  
  DBUG_RETURN (arg_node);
}
Example #5
0
static rc
testConstant (void)
{
    Constant *c;
    char *str;

    c = createConstInt(1);
    ASSERT_EQUALS_INT(1, INT_VALUE(c), "constant int 1");

    c = createConstFloat(2.0);
    ASSERT_EQUALS_FLOAT(2.0, FLOAT_VALUE(c), "constant float 2.0");

    c = createConstBool(TRUE);
    ASSERT_EQUALS_INT(TRUE, BOOL_VALUE(c), "constant boolean TRUE");

    str = strdup("test");
    c = createConstString(str);
    ASSERT_EQUALS_STRING("test", STRING_VALUE(c), "constant string \"test\"");

    return PASS;
}
Example #6
0
/* temp for printing values with print */
void valuePrint(dplVal *value) {
	if(value->isNull == TRUE) {
		printf("<null>\n");
	}
	else if(value->isArray == TRUE) {
		arrayValuePrint(value,NULL);
	}
	else {
		switch(value->type) {
			case IS_INT:
				printf("%d\n",INT_VALUE(value));
			break;
			case IS_DOUBLE:
				printf("%f\n",DOUBLE_VALUE(value));
			break;
			case IS_BOOL:
				if(BOOL_VALUE(value) == TRUE) {
					printf("<bool:true>\n");
				}
				else {
					printf("<bool:false>\n");
				}
			break;
			case IS_STRING:
				printf("%s\n",STR_VALUE(value));
			break;
			case IS_FILE:
				if(value->value.file.print_context == TRUE) {
					printf("%s",FILE_DATA(value));
				}
				else {
					printf("%s\n",FILE_PATH(value));
				}
			break;
		}
	}
}
Example #7
0
node* CALCCONSTbinop(node *arg_node, info *arg_info){
  DBUG_ENTER ("CALCCONSTbinop");
  node * ret;
  BINOP_LEFT( arg_node) = TRAVopt( BINOP_LEFT( arg_node), NULL);
  BINOP_RIGHT( arg_node) = TRAVopt( BINOP_RIGHT( arg_node), NULL);
  nodetype ntr = NODE_TYPE(BINOP_RIGHT( arg_node));
  nodetype ntl = NODE_TYPE(BINOP_LEFT( arg_node));
  if(ntr!= ntl || !(ntl==N_int || ntl==N_bool || ntl==N_float ))
    DBUG_RETURN (arg_node);

  if(ntl == N_bool){
    bool l = BOOL_VALUE(BINOP_LEFT( arg_node));
    bool r = BOOL_VALUE(BINOP_RIGHT( arg_node));

    switch(BINOP_OP(arg_node)){
    case BO_and:
      DBISNS(TBmakeBool(r&&l));
      break;
    case BO_or:
      DBISNS(TBmakeBool(r||l));
      break;
    case BO_ne:
      DBISNS(TBmakeBool(r != l));
      break;
    case BO_eq:
      DBISNS(TBmakeBool(r==l));
      break;
    case BO_add:
      DBISNS(TBmakeBool(r | l));
      break;
    case BO_mul:
      DBISNS(TBmakeBool(r & l));
      break;
    default:
      DBUG_RETURN(arg_node);
      break;

    }
  }else if(ntl == N_int){
    int l = INT_VALUE(BINOP_LEFT( arg_node));
    int r = INT_VALUE(BINOP_RIGHT( arg_node));

    switch(BINOP_OP(arg_node)){
    case BO_add:
      DBISNS(TBmakeInt(r+l));
      break;
    case BO_sub:
      DBISNS(TBmakeInt(r-l));
      break;
    case BO_mul:
      DBISNS(TBmakeInt(r*l));
      break;
    case BO_div:
      if (r != 0)
      {
        DBISNS(TBmakeInt(l/r));
      }
      break;
    case BO_mod:
      DBISNS(TBmakeInt(l % r));
      break;
    case BO_lt:
      DBISNS(TBmakeBool(l < r));
      break;
    case BO_le:
      DBISNS(TBmakeBool(l<=r));
      break;
    case BO_gt:
      DBISNS(TBmakeBool(l>r));
      break;
    case BO_ge:
      DBISNS(TBmakeBool(l>=r));
      break;
    case BO_eq:
      DBISNS(TBmakeBool(l==r));
      break;
    case BO_ne:
      DBISNS(TBmakeBool(l != r));
      break;
    default:
      DBUG_RETURN (arg_node);
      break;

    }
  }else if(ntl == N_float){
    float l = FLOAT_VALUE(BINOP_LEFT( arg_node));
    float r = FLOAT_VALUE(BINOP_RIGHT( arg_node));

    switch(BINOP_OP(arg_node)){
    case BO_add:
      DBISNS(TBmakeFloat(r+l));
      break;
    case BO_sub:
      DBISNS(TBmakeFloat(r-l));
      break;
    case BO_mul:
      DBISNS(TBmakeFloat(r*l));
      break;
    case BO_div:
      if (r != 0.0f)
      {
        DBISNS(TBmakeFloat(l/r));
      }
      break;
    case BO_lt:
      DBISNS(TBmakeBool(l < r));
      break;
    case BO_le:
      DBISNS(TBmakeBool(l<=r));
      break;
    case BO_gt:
      DBISNS(TBmakeBool(l>r));
      break;
    case BO_ge:
      DBISNS(TBmakeBool(l>=r));
      break;
    case BO_eq:
      DBISNS(TBmakeBool(l==r));
      break;
    case BO_ne:
      DBISNS(TBmakeBool(l != r));
      break;
    default:
      DBUG_RETURN (arg_node);
      break;

    }
  }






  DBUG_RETURN (arg_node);


}
Example #8
0
node* CALCCONSTcast(node *arg_node, info *arg_info){
  DBUG_ENTER ("CALCCONSTcast");

  CAST_EXPR( arg_node) = TRAVopt( CAST_EXPR( arg_node), NULL);
  node * ret;
  switch(NODE_TYPE(CAST_EXPR( arg_node))){
  case N_bool:
    switch(CAST_TYPE(arg_node)){
    case VT_bool:
      //no cast needed
      ret = CAST_EXPR( arg_node);
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );
      break;
    case VT_int:
      //FREEcast(arg_node);
      ret = TBmakeInt((int)BOOL_VALUE(CAST_EXPR( arg_node)));
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );

      break;
    case VT_float:
      //FREEcast(arg_node);
      ret = TBmakeFloat((float)BOOL_VALUE(CAST_EXPR( arg_node)));
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );
      break;
    default:
      DBUG_RETURN(arg_node);

    }

    break;
  case N_int:
    switch(CAST_TYPE(arg_node)){
    case VT_bool:
      ret =TBmakeBool(INT_VALUE(CAST_EXPR( arg_node)));
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );
      break;
    case VT_int:
      //no cast needed

      ret = CAST_EXPR( arg_node);
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );


      break;
    case VT_float:

      ret =TBmakeFloat((float)INT_VALUE(CAST_EXPR( arg_node) ));
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );

      break;
    default:
      DBUG_RETURN(arg_node);

    }

    break;
  case N_float:
    switch(CAST_TYPE(arg_node)){
    case VT_bool:
      ret =TBmakeBool(FLOAT_VALUE(CAST_EXPR( arg_node)));
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );


      break;
    case VT_int:
      ret =TBmakeInt(FLOAT_VALUE(CAST_EXPR( arg_node)));
      FREEdoFreeNode(arg_node);
      DBUG_RETURN(ret );

      break;
    case VT_float:
      //no cast needed
      ret = CAST_EXPR( arg_node);
      FREEdoFreeNode(arg_node);

      DBUG_RETURN(ret );


      break;
    default:
      DBUG_RETURN(arg_node);

    }

    break;
  default:
    DBUG_RETURN(arg_node);

  }


}