2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbx_value.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
(c) 2000-2012 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
#define __GBX_VALUE_C
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_common_case.h"
|
|
|
|
|
|
|
|
#include "gbx_math.h"
|
|
|
|
#include "gbx_type.h"
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
#include "gbx_c_array.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_string.h"
|
|
|
|
#include "gbx_number.h"
|
|
|
|
#include "gbx_object.h"
|
|
|
|
#include "gbx_variant.h"
|
|
|
|
#include "gbx_date.h"
|
2010-05-27 00:01:28 +02:00
|
|
|
#include "gbx_struct.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_local.h"
|
|
|
|
#include "gb_common_buffer.h"
|
2010-07-14 03:50:18 +02:00
|
|
|
#include "gbx_extern.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#include "gbx_value.h"
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
#if 0
|
2009-08-05 18:14:08 +02:00
|
|
|
static bool unknown_function(VALUE *value)
|
|
|
|
{
|
|
|
|
if (value->_function.kind == FUNCTION_UNKNOWN)
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
EXEC_unknown_property = TRUE;
|
|
|
|
EXEC_unknown_name = CP->load->unknown[value->_function.index];
|
2009-08-05 18:14:08 +02:00
|
|
|
|
|
|
|
EXEC_special(SPEC_UNKNOWN, value->_function.class, value->_function.object, 0, FALSE);
|
|
|
|
|
|
|
|
//object = value->_function.object;
|
|
|
|
OBJECT_UNREF(value->_function.object, "VALUE_conv");
|
|
|
|
|
|
|
|
SP--;
|
|
|
|
//*val = *SP;
|
|
|
|
COPY_VALUE(value, SP);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-03 04:46:15 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
void THROW_TYPE_INTEGER(TYPE type)
|
|
|
|
{
|
|
|
|
THROW(E_TYPE, TYPE_get_name(T_INTEGER), TYPE_get_name(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
void THROW_TYPE_FLOAT(TYPE type)
|
|
|
|
{
|
|
|
|
THROW(E_TYPE, TYPE_get_name(T_FLOAT), TYPE_get_name(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
void THROW_TYPE_STRING(TYPE type)
|
|
|
|
{
|
|
|
|
THROW(E_TYPE, TYPE_get_name(T_STRING), TYPE_get_name(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
static void VALUE_put(VALUE *value, void *addr, TYPE type)
|
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
static void *jump[16] = {
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL
|
|
|
|
};
|
2008-01-17 22:39:26 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
VALUE_conv(value, type);
|
2008-01-17 22:39:26 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (TYPE_is_object(type))
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[type];
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((unsigned char *)addr) = (value->_boolean.value != 0 ? 255 : 0);
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__BYTE:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((unsigned char *)addr) = (unsigned char)(value->_byte.value);
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__SHORT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((short *)addr) = (short)(value->_short.value);
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__INTEGER:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((int *)addr) = value->_integer.value;
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((int64_t *)addr) = value->_long.value;
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
*((float *)addr) = value->_single.value;
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__FLOAT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((double *)addr) = value->_float.value;
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
/* Inverted, if value ~= addr */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
((int *)addr)[1] = value->_date.time;
|
|
|
|
((int *)addr)[0] = value->_date.date;
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
/*__STRING:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
((int *)addr)[0] = (int)(value->_string.addr + value->_string.start);
|
|
|
|
((int *)addr)[1] = value->_string.len;
|
|
|
|
return;*/
|
|
|
|
|
|
|
|
__POINTER:
|
|
|
|
|
|
|
|
*((void **)addr) = value->_pointer.value;
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((void **)addr) = value->_object.object;
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((VARIANT *)addr) = *((VARIANT *)&value->_variant.vtype);
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*((void **)addr) = value->_class.class;
|
|
|
|
return;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
|
|
|
__VOID:
|
|
|
|
__FUNCTION:
|
|
|
|
__NULL:
|
|
|
|
__STRING:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
ERROR_panic("Bad type (%d) for VALUE_put", type);
|
2008-01-17 22:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
/* This function must keep the datatype, as it is used for initializing local variables */
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_default(VALUE *value, TYPE type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
static void *jump[16] = {
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL
|
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->type = type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (TYPE_is_object(type))
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
__BYTE:
|
|
|
|
__SHORT:
|
|
|
|
__INTEGER:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = 0;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_long.value = 0;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SINGLE:
|
2010-11-16 02:49:18 +01:00
|
|
|
value->_single.value = 0;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__FLOAT:
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_float.value = 0;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__STRING:
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_string.addr = NULL;
|
|
|
|
value->_string.start = 0;
|
|
|
|
value->_string.len = 0;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__VARIANT:
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_variant.vtype = T_NULL;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
__POINTER:
|
|
|
|
value->_pointer.value = NULL;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__DATE:
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_date.date = 0;
|
|
|
|
value->_date.time = 0;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__VOID:
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__OBJECT:
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_object.class = (CLASS *)type;
|
|
|
|
value->_object.object = NULL;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__FUNCTION:
|
|
|
|
__CLASS:
|
|
|
|
__NULL:
|
2010-05-19 14:43:57 +02:00
|
|
|
ERROR_panic("VALUE_default: Unknown default type");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_convert(VALUE *value, TYPE type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
static const void *jump[16][16] =
|
|
|
|
{
|
|
|
|
/* ,-------> void b c h i l g f d cs s p v func class n */
|
|
|
|
// |
|
|
|
|
/* void */ { &&__OK, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, &&__NR, },
|
2010-06-13 14:03:29 +02:00
|
|
|
/* b */ { &&__N, &&__OK, &&__b2c, &&__b2h, &&__TYPE, &&__b2l, &&__b2g, &&__b2f, &&__N, &&__b2s, &&__b2s, &&__N, &&__2v, &&__N, &&__N, &&__N, },
|
|
|
|
/* c */ { &&__N, &&__c2b, &&__OK, &&__c2h, &&__TYPE, &&__c2l, &&__c2g, &&__c2f, &&__c2d, &&__c2s, &&__c2s, &&__N, &&__2v, &&__N, &&__N, &&__N, },
|
|
|
|
/* h */ { &&__N, &&__h2b, &&__h2c, &&__OK, &&__TYPE, &&__h2l, &&__h2g, &&__h2f, &&__h2d, &&__h2s, &&__h2s, &&__N, &&__2v, &&__N, &&__N, &&__N, },
|
2010-07-14 13:55:32 +02:00
|
|
|
/* i */ { &&__N, &&__i2b, &&__i2c, &&__i2h, &&__OK, &&__i2l, &&__i2g, &&__i2f, &&__i2d, &&__i2s, &&__i2s, &&__i2p, &&__2v, &&__N, &&__N, &&__N, },
|
|
|
|
/* l */ { &&__N, &&__l2b, &&__l2c, &&__l2h, &&__l2i, &&__OK, &&__l2g, &&__l2f, &&__l2d, &&__l2s, &&__l2s, &&__l2p, &&__2v, &&__N, &&__N, &&__N, },
|
2010-11-16 02:49:18 +01:00
|
|
|
/* g */ { &&__N, &&__g2b, &&__g2c, &&__g2h, &&__g2i, &&__g2l, &&__OK, &&__g2f, &&__g2d, &&__g2s, &&__g2s, &&__N, &&__2v, &&__N, &&__N, &&__N, },
|
2010-05-19 14:43:57 +02:00
|
|
|
/* f */ { &&__N, &&__f2b, &&__f2c, &&__f2h, &&__f2i, &&__f2l, &&__f2g, &&__OK, &&__f2d, &&__f2s, &&__f2s, &&__N, &&__2v, &&__N, &&__N, &&__N, },
|
2010-06-13 14:03:29 +02:00
|
|
|
/* d */ { &&__N, &&__d2b, &&__d2c, &&__d2h, &&__d2i, &&__d2l, &&__d2g, &&__d2f, &&__OK, &&__d2s, &&__d2s, &&__N, &&__2v, &&__N, &&__N, &&__N, },
|
|
|
|
/* cs */ { &&__N, &&__s2b, &&__s2c, &&__s2h, &&__s2i, &&__s2l, &&__s2g, &&__s2f, &&__s2d, &&__OK, &&__OK, &&__N, &&__s2v, &&__N, &&__N, &&__N, },
|
|
|
|
/* s */ { &&__N, &&__s2b, &&__s2c, &&__s2h, &&__s2i, &&__s2l, &&__s2g, &&__s2f, &&__s2d, &&__OK, &&__OK, &&__N, &&__s2v, &&__N, &&__N, &&__N, },
|
2010-07-14 13:55:32 +02:00
|
|
|
/* p */ { &&__N, &&__N, &&__N, &&__N, &&__p2i, &&__p2l, &&__N, &&__N, &&__N, &&__N, &&__N, &&__OK, &&__2v, &&__N, &&__N, &&__N, },
|
2010-05-19 14:43:57 +02:00
|
|
|
/* v */ { &&__N, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__v2, &&__OK, &&__N, &&__v2, &&__v2, },
|
2010-11-16 02:49:18 +01:00
|
|
|
/* func */ { &&__N, &&__func, &&__func, &&__func, &&__func, &&__func, &&__func, &&__func, &&__func, &&__func, &&__func, &&__F2p, &&__func, &&__OK, &&__N, &&__func, },
|
2010-05-19 14:43:57 +02:00
|
|
|
/* class */ { &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__2v, &&__N, &&__OK, &&__N, },
|
|
|
|
/* null */ { &&__N, &&__n2b, &&__N, &&__N, &&__N, &&__N, &&__N, &&__N, &&__n2d, &&__n2s, &&__n2s, &&__N, &&__2v, &&__N, &&__N, &&__OK, },
|
|
|
|
};
|
|
|
|
|
|
|
|
int len;
|
|
|
|
char *addr;
|
|
|
|
CLASS *class;
|
|
|
|
bool test;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if ((type | value->type) >> 4)
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[value->type][type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__c2b:
|
|
|
|
__h2b:
|
|
|
|
__i2b:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
value->_integer.value = -(value->_integer.value != 0);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2b:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
value->_integer.value = -(value->_long.value != 0);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__g2b:
|
|
|
|
|
|
|
|
value->_integer.value = -(value->_single.value != 0);
|
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__f2b:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
value->_integer.value = -(value->_float.value != 0);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__d2b:
|
2010-06-05 01:48:53 +02:00
|
|
|
value->_integer.value = -(value->_date.date != 0 || value->_date.time != 0);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__b2c:
|
|
|
|
__h2c:
|
|
|
|
__i2c:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (unsigned char)value->_integer.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BYTE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2c:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (unsigned char)value->_long.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BYTE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__g2c:
|
|
|
|
|
|
|
|
value->_integer.value = (unsigned char)value->_single.value;
|
|
|
|
value->type = T_BYTE;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__f2c:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (unsigned char)value->_float.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BYTE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__b2h:
|
|
|
|
__c2h:
|
|
|
|
__i2h:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (short)value->_integer.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_SHORT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2h:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (short)value->_long.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_SHORT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__g2h:
|
|
|
|
|
|
|
|
value->_integer.value = (short)value->_single.value;
|
|
|
|
value->type = T_SHORT;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__f2h:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (short)value->_float.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_SHORT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2i:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (int)value->_long.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_INTEGER;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__g2i:
|
|
|
|
|
|
|
|
value->_integer.value = (int)value->_single.value;
|
|
|
|
value->type = T_INTEGER;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__f2i:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = (int)value->_float.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_INTEGER;
|
|
|
|
return;
|
2010-07-14 13:55:32 +02:00
|
|
|
|
|
|
|
__p2i:
|
|
|
|
|
|
|
|
value->_integer.value = (int)(intptr_t)value->_pointer.value;
|
|
|
|
value->type = T_INTEGER;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__b2l:
|
|
|
|
__c2l:
|
|
|
|
__h2l:
|
|
|
|
__i2l:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_long.value = (int64_t)value->_integer.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_LONG;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__g2l:
|
|
|
|
|
|
|
|
value->_long.value = (int64_t)value->_single.value;
|
|
|
|
value->type = T_LONG;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__f2l:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_long.value = (int64_t)value->_float.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_LONG;
|
|
|
|
return;
|
|
|
|
|
2010-07-14 13:55:32 +02:00
|
|
|
__p2l:
|
|
|
|
|
|
|
|
value->_long.value = (int64_t)(intptr_t)value->_pointer.value;
|
|
|
|
value->type = T_LONG;
|
|
|
|
return;
|
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
__b2g:
|
|
|
|
__c2g:
|
|
|
|
__h2g:
|
|
|
|
__i2g:
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
value->_single.value = value->_integer.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_SINGLE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2g:
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
value->_single.value = (float)value->_long.value;
|
2010-12-05 12:33:22 +01:00
|
|
|
if (!isfinite(value->_single.value))
|
2010-05-19 14:43:57 +02:00
|
|
|
THROW(E_OVERFLOW);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_SINGLE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__f2g:
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
value->_single.value = (float)value->_float.value;
|
2010-12-05 12:33:22 +01:00
|
|
|
if (!isfinite(value->_single.value))
|
2010-05-19 14:43:57 +02:00
|
|
|
THROW(E_OVERFLOW);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_SINGLE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__b2f:
|
|
|
|
__c2f:
|
|
|
|
__h2f:
|
|
|
|
__i2f:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_float.value = value->_integer.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2f:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_float.value = value->_long.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__g2f:
|
|
|
|
|
|
|
|
value->_float.value = value->_single.value;
|
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__c2d:
|
|
|
|
__h2d:
|
|
|
|
__i2d:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_date.date = Max(0, value->_integer.value);
|
|
|
|
value->_date.time = 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_DATE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2d:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->_long.value < 0)
|
|
|
|
value->_date.date = 0;
|
|
|
|
else if (value->_long.value > INT_MAX)
|
|
|
|
value->_date.date = INT_MAX;
|
|
|
|
else
|
|
|
|
value->_date.date = (int)value->_long.value;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_date.time = 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_DATE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__g2d:
|
|
|
|
{
|
2011-06-28 12:34:19 +02:00
|
|
|
float val = value->_single.value;
|
|
|
|
float ival = floorf(val);
|
|
|
|
value->_date.time = (int)((val - ival) * 86400000.0 + 0.5);
|
|
|
|
value->_date.date = (int)ival;
|
|
|
|
value->type = T_DATE;
|
|
|
|
return;
|
2010-11-16 02:49:18 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__f2d:
|
2010-06-05 01:48:53 +02:00
|
|
|
{
|
2011-06-28 12:34:19 +02:00
|
|
|
double val = value->_float.value;
|
|
|
|
double ival = floor(val);
|
|
|
|
value->_date.time = (int)((val - ival) * 86400000.0 + 0.5);
|
|
|
|
value->_date.date = (int)ival;
|
|
|
|
value->type = T_DATE;
|
|
|
|
return;
|
2010-06-05 01:48:53 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__d2c:
|
|
|
|
__d2h:
|
|
|
|
__d2i:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = value->_date.date;
|
|
|
|
value->type = T_INTEGER;
|
|
|
|
goto *jump[T_INTEGER][type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__d2l:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_long.value = value->_date.date;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_LONG;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__d2g:
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
value->_single.value = (float)value->_date.date + (float)value->_date.time / 86400000.0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_SINGLE;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__d2f:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_float.value = (double)value->_date.date + (double)value->_date.time / 86400000.0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__b2s:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->_boolean.value)
|
|
|
|
STRING_char_value(value, 'T');
|
|
|
|
else
|
|
|
|
STRING_void_value(value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__c2s:
|
|
|
|
__h2s:
|
|
|
|
__i2s:
|
|
|
|
|
2008-08-08 16:41:57 +02:00
|
|
|
/*len = sprintf(COMMON_buffer, "%d", value->_integer.value);
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_new_temp_value(value, COMMON_buffer, len);*/
|
|
|
|
NUMBER_int_to_string(value->_integer.value, 0, 10, value);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__l2s:
|
|
|
|
|
2008-08-08 16:41:57 +02:00
|
|
|
/*len = sprintf(COMMON_buffer, "%" PRId64, value->_long.value);
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_new_temp_value(value, COMMON_buffer, len);*/
|
|
|
|
NUMBER_int_to_string(value->_long.value, 0, 10, value);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__g2s:
|
2010-11-16 02:49:18 +01:00
|
|
|
|
|
|
|
LOCAL_format_number(value->_single.value, LF_GENERAL_NUMBER, NULL, 0, &addr, &len, FALSE);
|
|
|
|
STRING_new_temp_value(value, addr, len);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__f2s:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
LOCAL_format_number(value->_float.value, LF_GENERAL_NUMBER, NULL, 0, &addr, &len, FALSE);
|
|
|
|
STRING_new_temp_value(value, addr, len);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__d2s:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
len = DATE_to_string(COMMON_buffer, value);
|
|
|
|
STRING_new_temp_value(value, COMMON_buffer, len);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__s2b:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
addr = value->_string.addr;
|
2010-06-05 01:48:53 +02:00
|
|
|
value->_integer.value = -(addr != NULL && value->_string.len != 0);
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->type == T_STRING)
|
|
|
|
STRING_unref(&addr);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__s2c:
|
|
|
|
__s2h:
|
|
|
|
__s2i:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
addr = value->type == T_STRING ? value->_string.addr : NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (NUMBER_from_string(NB_READ_INTEGER, value->_string.addr + value->_string.start, value->_string.len, value))
|
|
|
|
goto __N;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_unref(&addr);
|
|
|
|
goto *jump[T_INTEGER][type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__s2l:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
addr = value->type == T_STRING ? value->_string.addr : NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (NUMBER_from_string(NB_READ_LONG, value->_string.addr + value->_string.start, value->_string.len, value))
|
|
|
|
goto __N;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_unref(&addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
__s2g:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
addr = value->type == T_STRING ? value->_string.addr : NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
if (NUMBER_from_string(NB_READ_FLOAT, value->_string.addr + value->_string.start, value->_string.len, value))
|
|
|
|
goto __N;
|
|
|
|
|
|
|
|
value->_single.value = value->_float.value;
|
|
|
|
|
|
|
|
STRING_unref(&addr);
|
|
|
|
value->type = type;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__s2f:
|
|
|
|
|
|
|
|
addr = value->type == T_STRING ? value->_string.addr : NULL;
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (NUMBER_from_string(NB_READ_FLOAT, value->_string.addr + value->_string.start, value->_string.len, value))
|
|
|
|
goto __N;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_unref(&addr);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = type;
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__s2d:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
addr = value->type == T_STRING ? value->_string.addr : NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (DATE_from_string(value->_string.addr + value->_string.start, value->_string.len, value, FALSE))
|
|
|
|
goto __N;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_unref(&addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__n2b:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__n2d:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
DATE_void_value(value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__n2s:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_void_value(value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__v2:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_undo_variant(value);
|
2010-05-19 14:43:57 +02:00
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__s2v:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
addr = STRING_copy_from_value_temp(value);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (addr != value->_string.addr)
|
|
|
|
{
|
|
|
|
STRING_ref(addr);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->type == T_STRING)
|
|
|
|
STRING_unref(&value->_string.addr);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-10-31 17:21:24 +01:00
|
|
|
value->_variant.vtype = T_STRING; //value->type;
|
2009-11-28 02:22:00 +01:00
|
|
|
value->_variant.value._string = addr;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_VARIANT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__2v:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
/* VALUE_put ne fonctionne pas avec T_STRING ! */
|
|
|
|
if (value->type != T_NULL)
|
|
|
|
VALUE_put(value, &value->_variant.value, value->type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_variant.vtype = value->type;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_VARIANT;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-05 18:14:08 +02:00
|
|
|
__func:
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
|
|
|
//else
|
|
|
|
goto __N;
|
2009-08-05 18:14:08 +02:00
|
|
|
|
2010-07-14 13:55:32 +02:00
|
|
|
__i2p:
|
|
|
|
value->_pointer.value = (void *)(intptr_t)value->_integer.value;
|
|
|
|
value->type = T_POINTER;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__l2p:
|
|
|
|
value->_pointer.value = (void *)(intptr_t)value->_long.value;
|
|
|
|
value->type = T_POINTER;
|
|
|
|
return;
|
|
|
|
|
2010-11-16 02:49:18 +01:00
|
|
|
__F2p:
|
2010-07-14 03:50:18 +02:00
|
|
|
|
|
|
|
value->_pointer.value = EXTERN_make_callback(&value->_function);
|
|
|
|
value->type = T_POINTER;
|
|
|
|
return;
|
2009-08-05 18:14:08 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__OBJECT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (!TYPE_is_object(type))
|
|
|
|
{
|
|
|
|
if (type == T_BOOLEAN)
|
|
|
|
{
|
|
|
|
test = (value->_object.object != NULL);
|
|
|
|
OBJECT_UNREF(value->_object.object, "VALUE_convert");
|
2010-06-13 14:03:29 +02:00
|
|
|
value->_boolean.value = -test;
|
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type == T_VARIANT)
|
|
|
|
goto __2v;
|
2009-08-05 18:14:08 +02:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
goto __N;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (!TYPE_is_object(value->type))
|
|
|
|
{
|
|
|
|
if (value->type == T_NULL)
|
|
|
|
{
|
|
|
|
OBJECT_null(value, (CLASS *)type); /* marche aussi pour type = T_OBJECT */
|
|
|
|
goto __TYPE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->type == T_VARIANT)
|
|
|
|
goto __v2;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-05 18:14:08 +02:00
|
|
|
if (value->type == T_FUNCTION)
|
|
|
|
goto __func;
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->type == T_CLASS)
|
|
|
|
{
|
|
|
|
class = value->_class.class;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
if (CLASS_is_virtual(class))
|
|
|
|
THROW(E_VIRTUAL);
|
2010-05-19 14:43:57 +02:00
|
|
|
|
|
|
|
CLASS_load(class);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (class->auto_create)
|
|
|
|
value->_object.object = CLASS_auto_create(class, 0);
|
|
|
|
else
|
|
|
|
value->_object.object = class;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
OBJECT_REF(value->_object.object, "VALUE_convert");
|
|
|
|
value->type = T_OBJECT;
|
|
|
|
/* on continue... */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto __N;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (value->_object.object == NULL)
|
|
|
|
goto __TYPE;
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->type == T_OBJECT)
|
|
|
|
{
|
|
|
|
/*if (value->_object.object == NULL)
|
|
|
|
goto __TYPE;*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
class = OBJECT_class(value->_object.object);
|
|
|
|
/* on continue */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
class = value->_object.class;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (CLASS_is_virtual(class))
|
|
|
|
THROW(E_VIRTUAL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (type == T_OBJECT)
|
|
|
|
goto __TYPE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__RETRY:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if ((class == (CLASS *)type) || CLASS_inherits(class, (CLASS *)type))
|
|
|
|
goto __TYPE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->type != T_OBJECT && value->_object.object)
|
|
|
|
{
|
|
|
|
class = OBJECT_class(value->_object.object);
|
|
|
|
value->type = T_OBJECT;
|
|
|
|
goto __RETRY;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-27 02:27:23 +01:00
|
|
|
if (class->special[SPEC_CONVERT] != NO_SYMBOL)
|
|
|
|
{
|
|
|
|
void *conv = ((void *(*)())(CLASS_get_desc(class, class->special[SPEC_CONVERT])->constant.value._pointer))(value->_object.object, type);
|
|
|
|
if (conv)
|
|
|
|
{
|
|
|
|
OBJECT_REF(conv, "VALUE_conv");
|
|
|
|
OBJECT_UNREF(value->_object.object, "VALUE_conv");
|
|
|
|
value->_object.object = conv;
|
|
|
|
goto __TYPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
THROW(E_TYPE, TYPE_get_name(type), TYPE_get_name((TYPE)class));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__TYPE:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->type = type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__OK:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__N:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
THROW(E_TYPE, TYPE_get_name(type), TYPE_get_name(value->type));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__NR:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
THROW(E_NRETURN);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_write(VALUE *value, void *addr, TYPE type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
static void *jump[16] = {
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL
|
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
char *str;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (TYPE_is_object(type))
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv_boolean(value);
|
2010-05-19 14:43:57 +02:00
|
|
|
*((unsigned char *)addr) = (value->_boolean.value != 0 ? 255 : 0);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BYTE:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv(value, T_BYTE);
|
2010-05-19 14:43:57 +02:00
|
|
|
*((unsigned char *)addr) = (unsigned char)(value->_byte.value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SHORT:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv(value, T_SHORT);
|
2010-05-19 14:43:57 +02:00
|
|
|
*((short *)addr) = (short)(value->_short.value);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__INTEGER:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv_integer(value);
|
2010-05-19 14:43:57 +02:00
|
|
|
*((int *)addr) = value->_integer.value;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv(value, T_LONG);
|
2010-05-19 14:43:57 +02:00
|
|
|
*((int64_t *)addr) = value->_long.value;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv(value, T_SINGLE);
|
2010-11-16 02:49:18 +01:00
|
|
|
*((float *)addr) = value->_single.value;
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__FLOAT:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv_float(value);
|
2010-05-19 14:43:57 +02:00
|
|
|
*((double *)addr) = value->_float.value;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv(value, T_DATE);
|
2010-05-19 14:43:57 +02:00
|
|
|
((int *)addr)[0] = value->_date.date;
|
|
|
|
((int *)addr)[1] = value->_date.time;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
/* Il faut faire l'affectation en deux temps au cas o
|
|
|
|
value->_string.addr == *addr ! */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv_string(value);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
str = STRING_copy_from_value_temp(value);
|
2010-05-19 14:43:57 +02:00
|
|
|
STRING_ref(str);
|
|
|
|
STRING_unref((char **)addr);
|
|
|
|
*((char **)addr) = str;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
VALUE_conv(value, type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
OBJECT_REF(value->_object.object, "VALUE_write");
|
|
|
|
OBJECT_UNREF(*((void **)addr), "VALUE_write");
|
|
|
|
*((void **)addr) = value->_object.object;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
VALUE_conv(value, type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
OBJECT_REF(value->_class.class, "VALUE_write");
|
|
|
|
OBJECT_UNREF(*((void **)addr), "VALUE_write");
|
|
|
|
*((void **)addr) = value->_class.class;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__POINTER:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_conv(value, T_POINTER);
|
2010-05-19 14:43:57 +02:00
|
|
|
*((void **)addr) = value->_pointer.value;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
VARIANT_undo(value);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
type = value->type;
|
|
|
|
if (type == T_CSTRING)
|
|
|
|
type = T_STRING;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
VARIANT_clear((VARIANT *)addr);
|
|
|
|
((VARIANT *)addr)->type = type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
/* Et si type ne fait pas partie des types valides pour cette fonction ?? */
|
|
|
|
if (type == T_NULL)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
addr = &((VARIANT *)addr)->value.data;
|
|
|
|
/*goto *jump[Min(T_OBJECT, type)];*/
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__VOID:
|
|
|
|
__FUNCTION:
|
|
|
|
__NULL:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
ERROR_panic("Bad type (%d) for VALUE_write", type);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_read(VALUE *value, void *addr, TYPE type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
static void *jump[16] = {
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__CSTRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL
|
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->type = type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (TYPE_is_object(type))
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_boolean.value = (*((unsigned char *)addr) != 0) ? (-1) : 0;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BYTE:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_byte.value = *((unsigned char *)addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SHORT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_short.value = *((short *)addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__INTEGER:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_integer.value = *((int *)addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_long.value = *((int64_t *)addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_single.value = *((float *)addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__FLOAT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_float.value = *((double *)addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_date.date = ((int *)addr)[0];
|
|
|
|
value->_date.time = ((int *)addr)[1];
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
{
|
|
|
|
char *str = *((char **)addr);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
value->type = T_STRING;
|
|
|
|
value->_string.addr = str;
|
|
|
|
value->_string.start = 0;
|
|
|
|
value->_string.len = STRING_length(str);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CSTRING:
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
{
|
|
|
|
char *str = *((char **)addr);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
value->type = T_CSTRING;
|
|
|
|
value->_string.addr = str;
|
|
|
|
value->_string.start = 0;
|
|
|
|
value->_string.len = (str == NULL) ? 0 : strlen(str);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_object.object = *((void **)addr);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__POINTER:
|
|
|
|
|
|
|
|
value->_pointer.value = *((void **)addr);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
value->_variant.type = T_VARIANT;
|
|
|
|
value->_variant.vtype = ((VARIANT *)addr)->type;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->_variant.vtype == T_VOID)
|
|
|
|
value->_variant.vtype = T_NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
VARIANT_copy_value(&value->_variant, ((VARIANT *)addr));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
|
|
|
value->_class.class = *((void **)addr);
|
|
|
|
value->_class.super = NULL;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__VOID:
|
|
|
|
__FUNCTION:
|
|
|
|
__NULL:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
ERROR_panic("Bad type (%d) for VALUE_read", type);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_free(void *addr, TYPE type)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
if (type == T_STRING)
|
|
|
|
{
|
|
|
|
STRING_unref((char **)addr);
|
|
|
|
*((char **)addr) = NULL;
|
|
|
|
}
|
|
|
|
else if (TYPE_is_object(type))
|
|
|
|
{
|
2008-08-14 21:42:27 +02:00
|
|
|
OBJECT_UNREF(*((void **)addr), "VALUE_free");
|
2010-05-19 14:43:57 +02:00
|
|
|
*((void **)addr) = NULL;
|
|
|
|
}
|
|
|
|
else if (type == T_VARIANT)
|
|
|
|
{
|
|
|
|
VARIANT_free((VARIANT *)addr);
|
|
|
|
((VARIANT *)addr)->type = T_NULL;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_to_string(VALUE *value, char **addr, int *len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
static void *jump[16] = {
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL
|
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (TYPE_is_object(value->type))
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[value->type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__NULL:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*addr = ""; // To be coherent with Print "", as Null == "" */
|
|
|
|
*len = 0;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (value->_boolean.value)
|
|
|
|
{
|
2011-05-05 10:54:21 +02:00
|
|
|
*addr = (char *)LOCAL_gettext("True");
|
|
|
|
*len = strlen(*addr);
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-05 10:54:21 +02:00
|
|
|
*addr = (char *)LOCAL_gettext("False");
|
|
|
|
*len = strlen(*addr);
|
|
|
|
//*addr = LOCAL_local.false_str;
|
|
|
|
//*len = LOCAL_local.len_false_str;
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__BYTE:
|
|
|
|
__SHORT:
|
|
|
|
__INTEGER:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*len = sprintf(COMMON_buffer, "%d", value->_integer.value);
|
|
|
|
*addr = COMMON_buffer;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*len = sprintf(COMMON_buffer, "%" PRId64, value->_long.value);
|
|
|
|
*addr = COMMON_buffer;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
LOCAL_format_date(DATE_split(value), LF_STANDARD, NULL, 0, addr, len);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__SINGLE:
|
2010-11-16 02:49:18 +01:00
|
|
|
|
2010-12-30 04:17:37 +01:00
|
|
|
LOCAL_format_number(value->_single.value, LF_SHORT_NUMBER, NULL, 0, addr, len, TRUE);
|
2010-11-16 02:49:18 +01:00
|
|
|
return;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
__FLOAT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
LOCAL_format_number(value->_float.value, LF_STANDARD, NULL, 0, addr, len, TRUE);
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*len = value->_string.len;
|
|
|
|
*addr = value->_string.addr + value->_string.start;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (VALUE_is_null(value))
|
|
|
|
goto __NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*len = sprintf(COMMON_buffer, "(%s %p)", OBJECT_class(value->_object.object)->name, value->_object.object);
|
|
|
|
*addr = COMMON_buffer;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__POINTER:
|
|
|
|
|
|
|
|
if (VALUE_is_null(value))
|
|
|
|
goto __NULL;
|
|
|
|
|
|
|
|
*len = sprintf(COMMON_buffer, "(Pointer %p)", value->_pointer.value);
|
|
|
|
*addr = COMMON_buffer;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
VARIANT_undo(value);
|
|
|
|
goto __CONV;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__VOID:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
THROW(E_NRETURN);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*len = sprintf(COMMON_buffer, "(Class %s)", value->_class.class->name);
|
|
|
|
*addr = COMMON_buffer;
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__FUNCTION:
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
2009-08-05 18:14:08 +02:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
*len = sprintf(COMMON_buffer, "(Function %s:%d)", value->_function.class->name, value->_function.index);
|
|
|
|
*addr = COMMON_buffer;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_from_string(VALUE *value, const char *addr, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
value->type = T_NULL;
|
|
|
|
|
2010-12-20 04:26:00 +01:00
|
|
|
while (len > 0 && isspace(*addr))
|
|
|
|
addr++, len--;
|
|
|
|
|
|
|
|
while (len > 0 && isspace(addr[len - 1]))
|
|
|
|
len--;
|
|
|
|
|
|
|
|
if (len <= 0)
|
2007-12-30 17:41:49 +01:00
|
|
|
return;
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (!DATE_from_string(addr, len, value, TRUE))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (!NUMBER_from_string(NB_READ_ALL | NB_READ_HEX_BIN | NB_LOCAL, addr, len, value))
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-11-28 00:00:08 +01:00
|
|
|
if (len == LOCAL_local.len_true_str && strncasecmp(addr, LOCAL_local.true_str, len) == 0)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
value->_boolean.value = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-28 00:00:08 +01:00
|
|
|
if (len == LOCAL_local.len_false_str && strncasecmp(addr, LOCAL_local.false_str, len) == 0)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
value->_boolean.value = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
void VALUE_class_read(CLASS *class, VALUE *value, char *addr, CTYPE ctype, void *ref)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_class_read_inline(class, value, addr, ctype, ref);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_class_write(CLASS *class, VALUE *value, char *addr, CTYPE ctype)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
if (ctype.id == T_OBJECT)
|
|
|
|
{
|
2010-05-22 20:02:34 +02:00
|
|
|
TYPE type = (ctype.value >= 0) ? (TYPE)class->load->class_ref[ctype.value] : T_OBJECT;
|
|
|
|
|
|
|
|
VALUE_conv(value, type);
|
|
|
|
|
|
|
|
OBJECT_REF(value->_object.object, "VALUE_class_write");
|
|
|
|
OBJECT_UNREF(*((void **)addr), "VALUE_class_write");
|
|
|
|
*((void **)addr) = value->_object.object;
|
|
|
|
//VALUE_write(value, addr, (ctype.value >= 0) ? (TYPE)class->load->class_ref[ctype.value] : T_OBJECT);
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
2010-11-26 21:30:58 +01:00
|
|
|
else if (ctype.id == TC_STRUCT)
|
|
|
|
{
|
|
|
|
TYPE type = (TYPE)class->load->class_ref[ctype.value];
|
|
|
|
VALUE_conv(value, type);
|
|
|
|
THROW_ILLEGAL();
|
|
|
|
}
|
|
|
|
else if (ctype.id == TC_ARRAY)
|
2010-05-19 14:43:57 +02:00
|
|
|
{
|
2010-05-27 00:01:28 +02:00
|
|
|
THROW_ILLEGAL();
|
2010-05-19 14:43:57 +02:00
|
|
|
}
|
|
|
|
else
|
2010-06-05 01:48:53 +02:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
VALUE_write(value, addr, (TYPE)ctype.id);
|
2010-06-05 01:48:53 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_class_constant(CLASS *class, VALUE *value, int ind)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
VALUE_class_constant_inline(class, value, ind);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool VALUE_is_null(VALUE *val)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 14:43:57 +02:00
|
|
|
static void *jump[16] = {
|
|
|
|
&&__FALSE, &&__FALSE, &&__FALSE, &&__FALSE, &&__FALSE, &&__FALSE, &&__FALSE, &&__FALSE, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FALSE, &&__FALSE, &&__NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
TYPE type = val->type;
|
|
|
|
|
|
|
|
if (TYPE_is_object(type))
|
|
|
|
return val->_object.object == NULL;
|
|
|
|
else
|
|
|
|
goto *jump[type];
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
__NULL:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
return val->_string.addr == 0 || val->_string.len == 0;
|
|
|
|
|
|
|
|
__DATE:
|
|
|
|
return val->_date.date == 0 && val->_date.time == 0;
|
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
__POINTER:
|
|
|
|
return val->_pointer.value == NULL;
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
__VARIANT:
|
2010-05-19 14:43:57 +02:00
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
if (val->_variant.vtype == T_NULL)
|
|
|
|
return TRUE;
|
2009-11-28 02:22:00 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (val->_variant.vtype == T_STRING)
|
|
|
|
return val->_variant.value._string == NULL;
|
2009-11-28 02:22:00 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (val->_variant.vtype == T_DATE)
|
|
|
|
return val->_variant.value.data == 0;
|
|
|
|
|
|
|
|
if (val->_variant.vtype == T_POINTER)
|
|
|
|
return val->_variant.value._pointer == NULL;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
2010-05-19 14:43:57 +02:00
|
|
|
if (TYPE_is_object(val->_variant.vtype))
|
|
|
|
return val->_variant.value._object == NULL;
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
__FALSE:
|
2010-05-19 14:43:57 +02:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
void VALUE_convert_boolean(VALUE *value)
|
|
|
|
{
|
|
|
|
static const void *jump[16] =
|
|
|
|
{
|
2011-01-16 23:04:17 +01:00
|
|
|
&&__NR, &&__OK, &&__c2b, &&__h2b, &&__i2b, &&__l2b, &&__g2b, &&__f2b,
|
2010-06-03 01:23:50 +02:00
|
|
|
&&__d2b, &&__s2b, &&__s2b, &&__N, &&__v2, &&__func, &&__N, &&__n2b
|
|
|
|
};
|
|
|
|
|
|
|
|
char *addr;
|
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
|
|
|
if (TYPE_is_object(value->type))
|
2010-06-05 01:48:53 +02:00
|
|
|
{
|
|
|
|
if (value->_object.object)
|
|
|
|
{
|
|
|
|
OBJECT_just_unref(value->_object.object);
|
|
|
|
value->_boolean.value = -1;
|
|
|
|
}
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-06-05 01:48:53 +02:00
|
|
|
}
|
2010-06-03 01:23:50 +02:00
|
|
|
else
|
|
|
|
goto *jump[value->type];
|
|
|
|
|
|
|
|
__c2b:
|
|
|
|
__h2b:
|
|
|
|
__i2b:
|
|
|
|
|
|
|
|
value->_integer.value = (value->_integer.value != 0) ? -1 : 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__l2b:
|
|
|
|
|
|
|
|
value->_integer.value = (value->_long.value != 0) ? -1 : 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
2011-01-16 23:04:17 +01:00
|
|
|
__g2b:
|
|
|
|
|
|
|
|
value->_integer.value = (value->_single.value != 0) ? -1 : 0;
|
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
__f2b:
|
|
|
|
|
|
|
|
value->_integer.value = (value->_float.value != 0) ? -1 : 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__d2b:
|
|
|
|
|
|
|
|
value->_integer.value = (value->_date.date != 0 || value->_date.time != 0) ? -1 : 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__s2b:
|
|
|
|
|
|
|
|
addr = value->_string.addr;
|
|
|
|
value->_integer.value = ((addr != NULL) && (value->_string.len != 0)) ? -1 : 0;
|
|
|
|
if (value->type == T_STRING)
|
|
|
|
STRING_unref(&addr);
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__n2b:
|
|
|
|
|
|
|
|
value->_integer.value = 0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_BOOLEAN;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__v2:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_undo_variant(value);
|
2010-06-03 01:23:50 +02:00
|
|
|
goto __CONV;
|
|
|
|
|
|
|
|
__func:
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
|
|
|
//else
|
2010-06-03 01:23:50 +02:00
|
|
|
goto __N;
|
|
|
|
|
|
|
|
__N:
|
|
|
|
|
|
|
|
THROW(E_TYPE, "Boolean", TYPE_get_name(value->type));
|
|
|
|
|
|
|
|
__NR:
|
|
|
|
|
|
|
|
THROW(E_NRETURN);
|
2010-06-13 14:03:29 +02:00
|
|
|
|
|
|
|
__OK:
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VALUE_convert_integer(VALUE *value)
|
|
|
|
{
|
|
|
|
static const void *jump[16] =
|
|
|
|
{
|
2011-01-16 23:04:17 +01:00
|
|
|
&&__NR, &&__TYPE, &&__TYPE, &&__TYPE, &&__OK, &&__l2i, &&__g2i, &&__f2i,
|
2010-06-03 01:23:50 +02:00
|
|
|
&&__d2i, &&__s2i, &&__s2i, &&__N, &&__v2, &&__func, &&__N, &&__N
|
|
|
|
};
|
|
|
|
|
|
|
|
char *addr;
|
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
goto *jump[value->type];
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__l2i:
|
|
|
|
|
|
|
|
value->_integer.value = (int)value->_long.value;
|
|
|
|
goto __TYPE;
|
|
|
|
|
2011-01-16 23:04:17 +01:00
|
|
|
__g2i:
|
|
|
|
|
|
|
|
value->_integer.value = (int)value->_single.value;
|
|
|
|
goto __TYPE;
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
__f2i:
|
|
|
|
|
|
|
|
value->_integer.value = (int)value->_float.value;
|
|
|
|
goto __TYPE;
|
|
|
|
|
|
|
|
__d2i:
|
|
|
|
|
|
|
|
value->_integer.value = value->_date.date;
|
|
|
|
goto __TYPE;
|
|
|
|
|
|
|
|
__s2i:
|
|
|
|
|
|
|
|
addr = value->type == T_STRING ? value->_string.addr : NULL;
|
|
|
|
|
|
|
|
if (NUMBER_from_string(NB_READ_INTEGER, value->_string.addr + value->_string.start, value->_string.len, value))
|
|
|
|
goto __N;
|
|
|
|
|
|
|
|
STRING_unref(&addr);
|
|
|
|
goto __TYPE;
|
|
|
|
|
|
|
|
__v2:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_undo_variant(value);
|
|
|
|
if (TYPE_is_object(value->type))
|
|
|
|
goto __N;
|
|
|
|
else
|
|
|
|
goto __CONV;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__func:
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
|
|
|
//else
|
2010-06-03 01:23:50 +02:00
|
|
|
goto __N;
|
|
|
|
|
|
|
|
__TYPE:
|
|
|
|
|
|
|
|
value->type = T_INTEGER;
|
|
|
|
|
|
|
|
__OK:
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
__N:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
THROW_TYPE_INTEGER(value->type);
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__NR:
|
|
|
|
|
|
|
|
THROW(E_NRETURN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VALUE_convert_float(VALUE *value)
|
|
|
|
{
|
|
|
|
static const void *jump[16] =
|
|
|
|
{
|
2010-06-13 14:03:29 +02:00
|
|
|
&&__NR, &&__b2f, &&__c2f, &&__h2f, &&__i2f, &&__l2f, &&__g2f, &&__OK,
|
2010-06-03 01:23:50 +02:00
|
|
|
&&__d2f, &&__s2f, &&__s2f, &&__N, &&__v2, &&__func, &&__N, &&__N
|
|
|
|
};
|
|
|
|
|
|
|
|
char *addr;
|
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
if (TYPE_is_object(value->type))
|
|
|
|
goto __N;
|
|
|
|
else
|
|
|
|
goto *jump[value->type];
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__b2f:
|
|
|
|
__c2f:
|
|
|
|
__h2f:
|
|
|
|
__i2f:
|
|
|
|
|
|
|
|
value->_float.value = value->_integer.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__l2f:
|
|
|
|
|
|
|
|
value->_float.value = value->_long.value;
|
2011-01-16 23:04:17 +01:00
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
2010-06-13 14:03:29 +02:00
|
|
|
|
|
|
|
__g2f:
|
|
|
|
|
2011-01-16 23:04:17 +01:00
|
|
|
value->_float.value = value->_single.value;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__d2f:
|
|
|
|
|
|
|
|
value->_float.value = (double)value->_date.date + (double)value->_date.time / 86400000.0;
|
2010-06-13 14:03:29 +02:00
|
|
|
value->type = T_FLOAT;
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__s2f:
|
|
|
|
|
|
|
|
addr = value->type == T_STRING ? value->_string.addr : NULL;
|
|
|
|
|
|
|
|
if (NUMBER_from_string(NB_READ_FLOAT, value->_string.addr + value->_string.start, value->_string.len, value))
|
|
|
|
goto __N;
|
|
|
|
|
|
|
|
STRING_unref(&addr);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__v2:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_undo_variant(value);
|
|
|
|
if (TYPE_is_object(value->type))
|
|
|
|
goto __N;
|
|
|
|
else
|
|
|
|
goto __CONV;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__func:
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
|
|
|
//else
|
2010-06-03 01:23:50 +02:00
|
|
|
goto __N;
|
|
|
|
|
|
|
|
__N:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
THROW_TYPE_FLOAT(value->type);
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__NR:
|
|
|
|
|
|
|
|
THROW(E_NRETURN);
|
2010-06-13 14:03:29 +02:00
|
|
|
|
|
|
|
__OK:
|
|
|
|
|
|
|
|
return;
|
2010-06-03 01:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VALUE_convert_string(VALUE *value)
|
|
|
|
{
|
|
|
|
static const void *jump[16] =
|
|
|
|
{
|
|
|
|
&&__NR, &&__b2s, &&__c2s, &&__h2s, &&__i2s, &&__l2s, &&__g2s, &&__f2s,
|
|
|
|
&&__d2s, &&__OK, &&__OK, &&__N, &&__v2, &&__func, &&__N, &&__n2s
|
|
|
|
};
|
|
|
|
|
|
|
|
int len;
|
|
|
|
char *addr;
|
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
goto *jump[value->type];
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__b2s:
|
|
|
|
|
|
|
|
if (value->_boolean.value)
|
|
|
|
STRING_char_value(value, 'T');
|
|
|
|
else
|
|
|
|
STRING_void_value(value);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__c2s:
|
|
|
|
__h2s:
|
|
|
|
__i2s:
|
|
|
|
|
|
|
|
NUMBER_int_to_string(value->_integer.value, 0, 10, value);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__l2s:
|
|
|
|
|
|
|
|
NUMBER_int_to_string(value->_long.value, 0, 10, value);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__g2s:
|
2011-01-16 23:04:17 +01:00
|
|
|
|
|
|
|
LOCAL_format_number(value->_single.value, LF_GENERAL_NUMBER, NULL, 0, &addr, &len, FALSE);
|
|
|
|
STRING_new_temp_value(value, addr, len);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
__f2s:
|
|
|
|
|
|
|
|
LOCAL_format_number(value->_float.value, LF_GENERAL_NUMBER, NULL, 0, &addr, &len, FALSE);
|
|
|
|
STRING_new_temp_value(value, addr, len);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__d2s:
|
|
|
|
|
|
|
|
len = DATE_to_string(COMMON_buffer, value);
|
|
|
|
STRING_new_temp_value(value, COMMON_buffer, len);
|
|
|
|
BORROW(value);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__n2s:
|
|
|
|
|
|
|
|
STRING_void_value(value);
|
|
|
|
return;
|
|
|
|
|
|
|
|
__v2:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
VALUE_undo_variant(value);
|
|
|
|
if (TYPE_is_object(value->type))
|
|
|
|
goto __N;
|
|
|
|
else
|
|
|
|
goto __CONV;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
__func:
|
2010-06-03 01:23:50 +02:00
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
|
|
|
//else
|
2010-06-05 01:48:53 +02:00
|
|
|
goto __N;
|
|
|
|
|
|
|
|
__OK:
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
__N:
|
|
|
|
|
|
|
|
THROW_TYPE_STRING(value->type);
|
|
|
|
|
|
|
|
__NR:
|
|
|
|
|
|
|
|
THROW(E_NRETURN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VALUE_convert_variant(VALUE *value)
|
|
|
|
{
|
|
|
|
static const void *jump[16] =
|
|
|
|
{
|
|
|
|
&&__NR, &&__2v, &&__2v, &&__2v, &&__2v, &&__2v, &&__2v, &&__2v,
|
|
|
|
&&__2v, &&__s2v, &&__s2v, &&__2v, &&__OK, &&__func, &&__2v, &&__2v
|
|
|
|
};
|
|
|
|
|
|
|
|
char *addr;
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//__CONV:
|
2010-06-05 01:48:53 +02:00
|
|
|
|
|
|
|
if (TYPE_is_object(value->type))
|
|
|
|
goto __2v;
|
|
|
|
else
|
|
|
|
goto *jump[value->type];
|
|
|
|
|
|
|
|
__s2v:
|
|
|
|
|
|
|
|
addr = STRING_copy_from_value_temp(value);
|
|
|
|
|
|
|
|
if (addr != value->_string.addr)
|
|
|
|
{
|
|
|
|
STRING_ref(addr);
|
|
|
|
|
|
|
|
if (value->type == T_STRING)
|
|
|
|
STRING_unref(&value->_string.addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
value->_variant.value._string = addr;
|
|
|
|
value->_variant.vtype = T_STRING;
|
|
|
|
|
|
|
|
goto __TYPE;
|
|
|
|
|
|
|
|
__2v:
|
|
|
|
|
|
|
|
/* VALUE_put ne fonctionne pas avec T_STRING ! */
|
|
|
|
if (value->type != T_NULL)
|
|
|
|
VALUE_put(value, &value->_variant.value, value->type);
|
|
|
|
|
|
|
|
value->_variant.vtype = value->type;
|
|
|
|
goto __TYPE;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__func:
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
|
|
|
//else
|
2010-06-03 01:23:50 +02:00
|
|
|
goto __N;
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
__TYPE:
|
|
|
|
|
|
|
|
value->type = T_VARIANT;
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__OK:
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
__N:
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
THROW(E_TYPE, "Variant", TYPE_get_name(value->type));
|
2010-06-03 01:23:50 +02:00
|
|
|
|
|
|
|
__NR:
|
|
|
|
|
|
|
|
THROW(E_NRETURN);
|
|
|
|
}
|
2010-06-05 01:48:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
void VALUE_convert_object(VALUE *value, TYPE type)
|
|
|
|
{
|
|
|
|
CLASS *class;
|
|
|
|
|
|
|
|
__CONV:
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (!TYPE_is_object(type))
|
|
|
|
{
|
|
|
|
if (type == T_BOOLEAN)
|
|
|
|
{
|
|
|
|
test = (value->_object.object != NULL);
|
|
|
|
OBJECT_UNREF(value->_object.object, "VALUE_convert");
|
|
|
|
value->_boolean.value = test ? -1 : 0;
|
|
|
|
goto __TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == T_VARIANT)
|
|
|
|
goto __2v;
|
|
|
|
|
|
|
|
goto __N;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!TYPE_is_object(value->type))
|
|
|
|
{
|
|
|
|
if (value->type == T_NULL)
|
|
|
|
{
|
|
|
|
OBJECT_null(value, (CLASS *)type); /* marche aussi pour type = T_OBJECT */
|
|
|
|
goto __TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value->type == T_VARIANT)
|
|
|
|
goto __v2;
|
|
|
|
|
|
|
|
if (value->type == T_FUNCTION)
|
|
|
|
goto __func;
|
|
|
|
|
|
|
|
if (value->type == T_CLASS)
|
|
|
|
{
|
|
|
|
class = value->_class.class;
|
|
|
|
|
|
|
|
if (CLASS_is_virtual(class))
|
|
|
|
THROW(E_VIRTUAL);
|
|
|
|
|
|
|
|
CLASS_load(class);
|
|
|
|
|
|
|
|
if (class->auto_create)
|
|
|
|
value->_object.object = CLASS_auto_create(class, 0);
|
|
|
|
else
|
|
|
|
value->_object.object = class;
|
|
|
|
|
|
|
|
OBJECT_REF(value->_object.object, "VALUE_convert");
|
|
|
|
value->type = T_OBJECT;
|
|
|
|
/* on continue... */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto __N;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value->_object.object == NULL)
|
|
|
|
goto __TYPE;
|
|
|
|
|
|
|
|
if (value->type == T_OBJECT)
|
|
|
|
{
|
|
|
|
/*if (value->_object.object == NULL)
|
|
|
|
goto __TYPE;*/
|
|
|
|
|
|
|
|
class = OBJECT_class(value->_object.object);
|
|
|
|
/* on continue */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
class = value->_object.class;
|
|
|
|
|
|
|
|
if (CLASS_is_virtual(class))
|
|
|
|
THROW(E_VIRTUAL);
|
|
|
|
|
|
|
|
if (type == T_OBJECT)
|
|
|
|
goto __TYPE;
|
|
|
|
|
|
|
|
__RETRY:
|
|
|
|
|
|
|
|
if ((class == (CLASS *)type) || CLASS_inherits(class, (CLASS *)type))
|
|
|
|
goto __TYPE;
|
|
|
|
|
|
|
|
if (value->type != T_OBJECT && value->_object.object)
|
|
|
|
{
|
|
|
|
class = OBJECT_class(value->_object.object);
|
|
|
|
value->type = T_OBJECT;
|
|
|
|
goto __RETRY;
|
|
|
|
}
|
|
|
|
|
2010-12-30 04:17:37 +01:00
|
|
|
if (class->special[SPEC_CONVERT] != NO_SYMBOL)
|
|
|
|
{
|
|
|
|
void *conv = ((void *(*)())(CLASS_get_desc(class, class->special[SPEC_CONVERT])->constant.value._pointer))(value->_object.object, type);
|
|
|
|
if (conv)
|
|
|
|
{
|
|
|
|
OBJECT_REF(conv, "VALUE_conv");
|
|
|
|
OBJECT_UNREF(value->_object.object, "VALUE_conv");
|
|
|
|
value->_object.object = conv;
|
|
|
|
goto __TYPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
THROW(E_TYPE, TYPE_get_name(type), TYPE_get_name((TYPE)class));
|
|
|
|
|
|
|
|
__v2:
|
|
|
|
|
|
|
|
VALUE_undo_variant(value);
|
|
|
|
goto __CONV;
|
|
|
|
|
|
|
|
__func:
|
|
|
|
|
2011-07-03 04:46:15 +02:00
|
|
|
//if (unknown_function(value))
|
|
|
|
// goto __CONV;
|
|
|
|
//else
|
2010-06-05 01:48:53 +02:00
|
|
|
goto __N;
|
|
|
|
|
|
|
|
__TYPE:
|
|
|
|
|
|
|
|
value->type = type;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__N:
|
|
|
|
|
|
|
|
THROW(E_TYPE, TYPE_get_name(type), TYPE_get_name(value->type));
|
|
|
|
}
|
|
|
|
|
2010-12-30 04:17:37 +01:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
void VALUE_undo_variant(VALUE *value)
|
|
|
|
{
|
|
|
|
static void *jump[16] = {
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
2010-06-09 01:08:04 +02:00
|
|
|
&&__STRING, &&__CSTRING, &&__POINTER, &&__VOID, &&__FUNCTION, &&__CLASS, &&__NULL
|
2010-06-05 01:48:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TYPE type = value->_variant.vtype;
|
|
|
|
|
|
|
|
//if (index != T_NULL)
|
|
|
|
// VALUE_read(value, &value->_variant.value, value->_variant.vtype);
|
|
|
|
|
|
|
|
value->type = type;
|
|
|
|
|
|
|
|
if (TYPE_is_object(type))
|
|
|
|
goto __OBJECT;
|
|
|
|
else
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
|
|
|
|
value->_boolean.value = value->_variant.value._boolean ? -1 : 0;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__BYTE:
|
|
|
|
|
|
|
|
value->_byte.value = value->_variant.value._byte;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__SHORT:
|
|
|
|
|
|
|
|
value->_short.value = value->_variant.value._short;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__INTEGER:
|
|
|
|
|
|
|
|
value->_integer.value = value->_variant.value._integer;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
|
|
|
value->_long.value = value->_variant.value._long;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
|
|
|
|
value->_single.value = value->_variant.value._single;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__FLOAT:
|
|
|
|
|
|
|
|
value->_float.value = value->_variant.value._float;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
|
|
|
// It works, as the normal date field is before the variant date field!
|
|
|
|
value->_date.date = value->_variant.value._date.date;
|
|
|
|
value->_date.time = value->_variant.value._date.time;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
|
|
|
{
|
|
|
|
char *str = value->_variant.value._string;
|
|
|
|
|
|
|
|
value->type = T_STRING;
|
|
|
|
value->_string.addr = str;
|
|
|
|
value->_string.start = 0;
|
|
|
|
value->_string.len = STRING_length(str);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__CSTRING:
|
|
|
|
|
|
|
|
{
|
|
|
|
char *str = value->_variant.value._string;
|
|
|
|
|
2010-10-31 17:21:24 +01:00
|
|
|
value->type = T_CSTRING;
|
2010-06-09 01:08:04 +02:00
|
|
|
value->_string.addr = str;
|
|
|
|
value->_string.start = 0;
|
|
|
|
value->_string.len = strlen(str);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
__OBJECT:
|
|
|
|
|
|
|
|
value->_object.object = value->_variant.value._object;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__POINTER:
|
|
|
|
|
|
|
|
value->_pointer.value = value->_variant.value._pointer;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__CLASS: // Is it useful for variants ?
|
|
|
|
|
|
|
|
value->_class.class = value->_variant.value._object;
|
|
|
|
value->_class.super = NULL;
|
|
|
|
return;
|
|
|
|
|
|
|
|
__NULL:
|
|
|
|
return;
|
|
|
|
|
|
|
|
__VOID:
|
|
|
|
__FUNCTION:
|
|
|
|
|
|
|
|
ERROR_panic("Bad type (%d) for VALUE_undo_variant", type);
|
|
|
|
}
|