2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gbx_subr_test_temp.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-03-21 01:04:10 +01:00
|
|
|
(c) 2000-2011 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +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
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-03 02:51:09 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef STT_INEQUALITY
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
void STT_NAME(ushort code)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
static void *jump[17] = {
|
|
|
|
&&__VARIANT, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR,
|
|
|
|
&&__NULL,
|
|
|
|
&&__OBJECT
|
|
|
|
};
|
|
|
|
|
|
|
|
TYPE type;
|
|
|
|
VALUE *P1, *P2;
|
2009-07-08 21:57:50 +02:00
|
|
|
bool result, variant;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
P1 = SP - 2;
|
|
|
|
P2 = P1 + 1;
|
|
|
|
|
|
|
|
variant = FALSE;
|
2010-06-05 01:48:53 +02:00
|
|
|
type = code & 0x1F;
|
2007-12-30 17:41:49 +01:00
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
|
|
|
type = Max(P1->type, P2->type);
|
|
|
|
|
|
|
|
if (TYPE_is_variant(P1->type))
|
|
|
|
{
|
|
|
|
#ifdef STT_CASE
|
|
|
|
TEMP = *P1;
|
|
|
|
P1 = &TEMP;
|
|
|
|
#endif
|
|
|
|
VARIANT_undo(P1);
|
|
|
|
variant = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TYPE_is_variant(P2->type))
|
|
|
|
{
|
|
|
|
VARIANT_undo(P2);
|
|
|
|
variant = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variant)
|
|
|
|
type = Max(P1->type, P2->type);
|
|
|
|
|
|
|
|
if (TYPE_is_object_null(P1->type) && TYPE_is_object_null(P2->type))
|
|
|
|
type = T_OBJECT;
|
|
|
|
else if (TYPE_is_object(type))
|
|
|
|
THROW(E_TYPE, "Object", TYPE_get_name(Min(P1->type, P2->type)));
|
|
|
|
|
|
|
|
if (!variant)
|
|
|
|
*PC |= type;
|
|
|
|
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
__BYTE:
|
|
|
|
__SHORT:
|
|
|
|
__INTEGER:
|
|
|
|
|
|
|
|
result = P1->_integer.value STT_TEST P2->_integer.value;
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
|
|
|
VALUE_conv(P1, T_LONG);
|
|
|
|
VALUE_conv(P2, T_LONG);
|
|
|
|
|
|
|
|
result = P1->_long.value STT_TEST P2->_long.value;
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
|
|
|
VALUE_conv(P1, T_DATE);
|
|
|
|
VALUE_conv(P2, T_DATE);
|
|
|
|
|
|
|
|
#ifdef STT_NEAR
|
|
|
|
result = P1->_date.date STT_TEST P2->_date.date;
|
|
|
|
#else
|
|
|
|
result = (DATE_comp_value(P1, P2) STT_TEST 0);
|
|
|
|
#endif
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_string(P1);
|
|
|
|
VALUE_conv_string(P2);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
if (P1->_string.len != P2->_string.len)
|
|
|
|
result = 0 STT_TEST 1;
|
|
|
|
else
|
2007-12-30 17:41:49 +01:00
|
|
|
#ifdef STT_NEAR
|
2008-01-27 15:00:04 +01:00
|
|
|
result = (STRING_equal_ignore_case(P1->_string.addr + P1->_string.start, P1->_string.len, P2->_string.addr + P2->_string.start, P2->_string.len) STT_TEST 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
#else
|
2008-01-27 15:00:04 +01:00
|
|
|
result = (STRING_equal_same(P1->_string.addr + P1->_string.start, P2->_string.addr + P2->_string.start, P1->_string.len) STT_TEST 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
goto __END_RELEASE;
|
|
|
|
|
|
|
|
#ifdef STT_NEAR
|
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_float(P1);
|
|
|
|
VALUE_conv_float(P2);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
result = fabs(P1->_float.value - P2->_float.value) <= 1E-6 * fabs(P1->_float.value + P2->_float.value);
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__FLOAT:
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_float(P1);
|
|
|
|
VALUE_conv_float(P2);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
result = fabs(P1->_float.value - P2->_float.value) <= 1E-12 * fabs(P1->_float.value + P2->_float.value);
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
__FLOAT:
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_float(P1);
|
|
|
|
VALUE_conv_float(P2);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
result = P1->_float.value STT_TEST P2->_float.value;
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
|
|
|
result = OBJECT_comp_value(P1, P2) STT_TEST TRUE;
|
|
|
|
goto __END_RELEASE;
|
|
|
|
|
|
|
|
__NULL:
|
|
|
|
|
|
|
|
result = VALUE_is_null(P1->type == T_NULL ? P2 : P1) STT_TEST TRUE;
|
|
|
|
goto __END_RELEASE;
|
|
|
|
|
|
|
|
__ERROR:
|
|
|
|
|
|
|
|
THROW(E_TYPE, "Number or Date", TYPE_get_name(type));
|
|
|
|
|
|
|
|
__END_RELEASE:
|
|
|
|
|
|
|
|
#ifdef STT_CASE
|
|
|
|
RELEASE(P2);
|
|
|
|
#else
|
|
|
|
RELEASE(P1);
|
|
|
|
RELEASE(P2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__END:
|
|
|
|
|
|
|
|
#ifdef STT_CASE
|
|
|
|
|
|
|
|
P2->type = T_BOOLEAN;
|
|
|
|
P2->_boolean.value = result ? -1 : 0;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
P1->type = T_BOOLEAN;
|
|
|
|
P1->_boolean.value = result ? -1 : 0;
|
|
|
|
|
|
|
|
SP--;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* inequality tests */
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
void STT_NAME(ushort code)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
static void *jump[17] = {
|
|
|
|
&&__VARIANT, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, &&__DATE,
|
|
|
|
&&__STRING, &&__STRING, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR,
|
|
|
|
&&__NULL, &&__ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
TYPE type, typem;
|
|
|
|
VALUE *P1, *P2;
|
2009-07-08 21:57:50 +02:00
|
|
|
bool result, variant;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
P1 = SP - 2;
|
|
|
|
P2 = P1 + 1;
|
|
|
|
|
|
|
|
variant = FALSE;
|
2010-06-05 01:48:53 +02:00
|
|
|
type = code & 0x1F;
|
2007-12-30 17:41:49 +01:00
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
|
|
|
if (TYPE_is_variant(P1->type))
|
|
|
|
{
|
|
|
|
VARIANT_undo(P1);
|
|
|
|
variant = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TYPE_is_variant(P2->type))
|
|
|
|
{
|
|
|
|
VARIANT_undo(P2);
|
|
|
|
variant = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = Max(P1->type, P2->type);
|
|
|
|
|
|
|
|
if (type == T_NULL || TYPE_is_string(type))
|
|
|
|
{
|
|
|
|
typem = Min(P1->type, P2->type);
|
|
|
|
if (!TYPE_is_string(typem))
|
|
|
|
THROW(E_TYPE, TYPE_get_name(typem), TYPE_get_name(type));
|
|
|
|
}
|
|
|
|
else if (TYPE_is_object(type))
|
|
|
|
goto __ERROR;
|
|
|
|
|
|
|
|
if (!variant)
|
|
|
|
*PC |= type;
|
|
|
|
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
__BOOLEAN:
|
|
|
|
__BYTE:
|
|
|
|
__SHORT:
|
|
|
|
__INTEGER:
|
|
|
|
|
|
|
|
result = P1->_integer.value STT_TEST P2->_integer.value;
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__LONG:
|
|
|
|
|
|
|
|
VALUE_conv(P1, T_LONG);
|
|
|
|
VALUE_conv(P2, T_LONG);
|
|
|
|
|
|
|
|
result = P1->_long.value STT_TEST P2->_long.value;
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__DATE:
|
|
|
|
|
|
|
|
VALUE_conv(P1, T_DATE);
|
|
|
|
VALUE_conv(P2, T_DATE);
|
|
|
|
|
|
|
|
result = (DATE_comp_value(P1, P2) STT_TEST 0);
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__NULL:
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_string(P1);
|
|
|
|
VALUE_conv_string(P2);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
result = (STRING_compare(P1->_string.addr + P1->_string.start, P1->_string.len, P2->_string.addr + P2->_string.start, P2->_string.len) STT_TEST 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
goto __END_RELEASE;
|
|
|
|
|
|
|
|
__SINGLE:
|
|
|
|
__FLOAT:
|
|
|
|
|
2010-06-03 01:23:50 +02:00
|
|
|
VALUE_conv_float(P1);
|
|
|
|
VALUE_conv_float(P2);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
result = P1->_float.value STT_TEST P2->_float.value;
|
|
|
|
goto __END;
|
|
|
|
|
|
|
|
__ERROR:
|
|
|
|
|
|
|
|
THROW(E_TYPE, "Number, Date or String", TYPE_get_name(type));
|
|
|
|
|
|
|
|
__END_RELEASE:
|
|
|
|
|
|
|
|
RELEASE(P1);
|
|
|
|
RELEASE(P2);
|
|
|
|
|
|
|
|
__END:
|
|
|
|
|
|
|
|
P1->type = T_BOOLEAN;
|
|
|
|
P1->_boolean.value = result ? -1 : 0;
|
|
|
|
|
|
|
|
SP--;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef STT_INEQUALITY
|
|
|
|
#undef STT_INEQUALITY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef STT_NAME
|
|
|
|
#undef STT_TEST
|
|
|
|
|
|
|
|
#ifdef STT_NO_OBJECT
|
|
|
|
#undef STT_NO_OBJECT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef STT_CASE
|
|
|
|
#undef STT_CASE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef STT_NULL
|
|
|
|
#undef STT_NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef STT_NEAR
|
|
|
|
#undef STT_NEAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|