diff options
-rw-r--r-- | basic/inc/basic/sbx.hxx | 5 | ||||
-rw-r--r-- | basic/inc/basic/sbxdef.hxx | 402 | ||||
-rw-r--r-- | basic/inc/basic/sbxvar.hxx | 316 | ||||
-rw-r--r-- | basic/source/classes/sbunoobj.cxx | 26 | ||||
-rw-r--r-- | basic/source/runtime/methods1.cxx | 30 | ||||
-rw-r--r-- | basic/source/sbx/makefile.mk | 1 | ||||
-rw-r--r-- | basic/source/sbx/sbxbool.cxx | 34 | ||||
-rw-r--r-- | basic/source/sbx/sbxbyte.cxx | 41 | ||||
-rw-r--r-- | basic/source/sbx/sbxchar.cxx | 43 | ||||
-rw-r--r-- | basic/source/sbx/sbxconv.hxx | 45 | ||||
-rw-r--r-- | basic/source/sbx/sbxcurr.cxx | 506 | ||||
-rw-r--r-- | basic/source/sbx/sbxdate.cxx | 18 | ||||
-rw-r--r-- | basic/source/sbx/sbxdbl.cxx | 19 | ||||
-rw-r--r-- | basic/source/sbx/sbxdec.cxx | 73 | ||||
-rw-r--r-- | basic/source/sbx/sbxint.cxx | 165 | ||||
-rw-r--r-- | basic/source/sbx/sbxlng.cxx | 60 | ||||
-rw-r--r-- | basic/source/sbx/sbxsng.cxx | 39 | ||||
-rw-r--r-- | basic/source/sbx/sbxstr.cxx | 20 | ||||
-rw-r--r-- | basic/source/sbx/sbxuint.cxx | 43 | ||||
-rw-r--r-- | basic/source/sbx/sbxulng.cxx | 35 | ||||
-rw-r--r-- | basic/source/sbx/sbxvalue.cxx | 389 |
21 files changed, 998 insertions, 1312 deletions
diff --git a/basic/inc/basic/sbx.hxx b/basic/inc/basic/sbx.hxx index a4fa718c8467..b3c28ada8989 100644 --- a/basic/inc/basic/sbx.hxx +++ b/basic/inc/basic/sbx.hxx @@ -33,14 +33,13 @@ #include "svl/svarray.hxx" #include "svl/smplhint.hxx" #include "svl/lstner.hxx" + #include <basic/sbxdef.hxx> #include <basic/sbxform.hxx> - #include <basic/sbxobj.hxx> #include <basic/sbxprop.hxx> #include <basic/sbxmeth.hxx> -class BigInt; class String; class UniString; class SvStream; @@ -52,8 +51,6 @@ class SbxObject; class SbxArray; class SbxDimArray; class SbxFactory; -struct SbxINT64; -struct SbxUINT64; class SfxBroadcaster; class SvDispatch; diff --git a/basic/inc/basic/sbxdef.hxx b/basic/inc/basic/sbxdef.hxx index ca707168687b..0b6ea77c70a2 100644 --- a/basic/inc/basic/sbxdef.hxx +++ b/basic/inc/basic/sbxdef.hxx @@ -54,90 +54,99 @@ enum SbxClassType { // SBX-class-IDs (order is important!) #define _SBX_DATA_TYPE enum SbxDataType { - SbxEMPTY = 0, // * Uninitialized - SbxNULL = 1, // * Contains no valid data - SbxINTEGER = 2, // * Integer (INT16) - SbxLONG = 3, // * Long integer (INT32) - SbxSINGLE = 4, // * Single-precision floating point number (float) - SbxDOUBLE = 5, // * Double-precision floating point number (double) - SbxCURRENCY = 6, // Currency (INT64) - SbxDATE = 7, // * Date (double) - SbxSTRING = 8, // * String (StarView) - SbxOBJECT = 9, // * SbxBase object pointer - SbxERROR = 10, // * Error (UINT16) - SbxBOOL = 11, // * Boolean (0 or -1) - SbxVARIANT = 12, // * Display for variant datatype - SbxDATAOBJECT = 13, // * Common data object w/o ref count - - SbxCHAR = 16, // * signed char - SbxBYTE = 17, // * unsigned char - SbxUSHORT = 18, // * unsigned short (UINT16) - SbxULONG = 19, // * unsigned long (UINT32) - SbxLONG64 = 20, // signed 64-bit int - SbxULONG64 = 21, // unsigned 64-bit int - SbxINT = 22, // * signed machine-dependent int - SbxUINT = 23, // * unsigned machine-dependent int - SbxVOID = 24, // * no value (= SbxEMPTY) - SbxHRESULT = 25, // HRESULT - SbxPOINTER = 26, // generic pointer - SbxDIMARRAY = 27, // dimensioned array - SbxCARRAY = 28, // C style array - SbxUSERDEF = 29, // user defined - SbxLPSTR = 30, // * null terminated string - SbxLPWSTR = 31, // wide null terminated string - SbxCoreSTRING = 32, // from 1997-4-10 for GetCoreString(), only for converting - SbxWSTRING = 33, // from 2000-10-4 Reimplemented for backwards compatibility (#78919) - SbxWCHAR = 34, // from 2000-10-4 Reimplemented for backwards compatibility (#78919) - SbxSALINT64 = 35, // for UNO hyper - SbxSALUINT64 = 36, // for UNO unsigned hyper - SbxDECIMAL = 37, // for UNO/automation Decimal - - SbxVECTOR = 0x1000, // simple counted array - SbxARRAY = 0x2000, // array - SbxBYREF = 0x4000, // access by reference - - SbxSV1 = 128, // first defined data type for StarView - SbxMEMORYSTREAM, // SvMemoryStream - SbxSTORAGE, // SvStorage - - SbxUSER1 = 256, // first user defined data type - SbxUSERn = 2047 // last user defined data type + SbxEMPTY = 0, // * Uninitialized + SbxNULL = 1, // * Contains no valid data + SbxINTEGER = 2, // * Integer (INT16) + SbxLONG = 3, // * Long integer (INT32) + SbxSINGLE = 4, // * Single-precision floating point number (float) + SbxDOUBLE = 5, // * Double-precision floating point number (double) + SbxCURRENCY = 6, // Currency (INT64) + SbxDATE = 7, // * Date (double) + SbxSTRING = 8, // * String (StarView) + SbxOBJECT = 9, // * SbxBase object pointer + SbxERROR = 10, // * Error (UINT16) + SbxBOOL = 11, // * Boolean (0 or -1) + + SbxVARIANT = 12, // * Display for variant datatype + SbxDATAOBJECT = 13, // * Common data object w/o ref count + + SbxCHAR = 16, // * signed char + SbxBYTE = 17, // * unsigned char + SbxUSHORT = 18, // * unsigned short (UINT16) + SbxULONG = 19, // * unsigned long (UINT32) + +//deprecated: // old 64bit types kept for backward compatibility in file I/O + SbxLONG64 = 20, // moved to SbxSALINT64 as 64bit int + SbxULONG64 = 21, // moved to SbxSALUINT64 as 64bit int + + SbxINT = 22, // * signed machine-dependent int + SbxUINT = 23, // * unsigned machine-dependent int + + SbxVOID = 24, // * no value (= SbxEMPTY) + SbxHRESULT = 25, // HRESULT + SbxPOINTER = 26, // generic pointer + SbxDIMARRAY = 27, // dimensioned array + SbxCARRAY = 28, // C style array + SbxUSERDEF = 29, // user defined + SbxLPSTR = 30, // * null terminated string + + SbxLPWSTR = 31, // wide null terminated string + SbxCoreSTRING = 32, // from 1997-4-10 for GetCoreString(), only for converting< + + SbxWSTRING = 33, // from 2000-10-4 Reimplemented for backwards compatibility (#78919) + SbxWCHAR = 34, // from 2000-10-4 Reimplemented for backwards compatibility (#78919) + SbxSALINT64 = 35, // for currency internal, signed 64-bit int and UNO hyper + SbxSALUINT64= 36, // for currency internal, unsigned 64-bit int and UNO unsigned hyper + SbxDECIMAL = 37, // for UNO/automation Decimal + + SbxVECTOR = 0x1000, // simple counted array + SbxARRAY = 0x2000, // array + SbxBYREF = 0x4000, // access by reference + + SbxSV1 = 128, // first defined data type for StarView + SbxMEMORYSTREAM, // SvMemoryStream + SbxSTORAGE, // SvStorage + + SbxUSER1 = 256, // first user defined data type + SbxUSERn = 2047 // last user defined data type }; const UINT32 SBX_TYPE_WITH_EVENTS_FLAG = 0x10000; -const UINT32 SBX_FIXED_LEN_STRING_FLAG = 0x10000; // same value as above as no conflict possible - +const UINT32 SBX_FIXED_LEN_STRING_FLAG = 0x10000; // same value as above as no conflict possible #endif #ifndef _SBX_OPERATOR #define _SBX_OPERATOR enum SbxOperator { - // Arithmetical: - SbxEXP, // this ^ var - SbxMUL, // this * var - SbxDIV, // this / var - SbxMOD, // this MOD var - SbxPLUS, // this + var - SbxMINUS, // this - var - SbxNEG, // -this (var is ignored) - SbxIDIV, // this / var (both operands max. INT32!) - // Boolean operators (max INT32!): - SbxAND, // this & var - SbxOR, // this | var - SbxXOR, // this ^ var - SbxEQV, // ~this ^ var - SbxIMP, // ~this | var - SbxNOT, // ~this (var is ignored) - // String-concat: - SbxCAT, // this & var - // Comparisons: - SbxEQ, // this = var - SbxNE, // this <> var - SbxLT, // this < var - SbxGT, // this > var - SbxLE, // this <= var - SbxGE // this >= var + // Arithmetical: + SbxEXP, // this ^ var + SbxMUL, // this * var + SbxDIV, // this / var + SbxMOD, // this MOD var (max INT32!) + SbxPLUS, // this + var + SbxMINUS, // this - var + SbxNEG, // -this (var is ignored) + SbxIDIV, // this / var (max INT32!) + + // Boolean operators (TODO deprecate this limit: max INT32!) + SbxAND, // this & var + SbxOR, // this | var + SbxXOR, // this ^ var + SbxEQV, // ~this ^ var + SbxIMP, // ~this | var + SbxNOT, // ~this (var is ignored) + + // String concatenation: + SbxCAT, // this & var (VBA: this + var) + + // Comparisons: + SbxEQ, // this = var + SbxNE, // this <> var + SbxLT, // this < var + SbxGT, // this > var + SbxLE, // this <= var + SbxGE // this >= var }; #endif @@ -145,131 +154,100 @@ enum SbxOperator { #ifndef _SBX_NAME_TYPE #define _SBX_NAME_TYPE -enum SbxNameType { // Type of the questioned name of a variable - SbxNAME_NONE, // plain name - SbxNAME_SHORT, // Name(A,B) - SbxNAME_SHORT_TYPES, // Name%(A%,B$) - SbxNAME_LONG_TYPES // Name(A As Integer, B As String) As Integer +enum SbxNameType { // Type of the questioned name of a variable + SbxNAME_NONE, // plain name + SbxNAME_SHORT, // Name(A,B) + SbxNAME_SHORT_TYPES, // Name%(A%,B$) + SbxNAME_LONG_TYPES // Name(A As Integer, B As String) As Integer }; #endif // from 1996/3/20: New error messages -typedef ULONG SbxError; // Preserve old type +typedef ULONG SbxError; // Preserve old type #endif -// von #ifndef __RSC // New error codes per define -#define ERRCODE_SBX_OK ERRCODE_NONE // processed -#define ERRCODE_SBX_SYNTAX (1UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_COMPILER) // Syntaxerror in parser (where else could syntax errors happen? ;-) -#define ERRCODE_SBX_NOTIMP (2UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_NOTSUPPORTED) // not possible -#define ERRCODE_SBX_OVERFLOW (3UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_SBX) // overflow -#define ERRCODE_SBX_BOUNDS (4UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_SBX) // Invalid array index -#define ERRCODE_SBX_ZERODIV (5UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_SBX) // Division by zero -#define ERRCODE_SBX_CONVERSION (6UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_SBX) // wrong data type -#define ERRCODE_SBX_BAD_PARAMETER (7UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // invalid Parameter -#define ERRCODE_SBX_PROC_UNDEFINED (8UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // BASIC-Sub or Function undefined -#define ERRCODE_SBX_ERROR (9UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_UNKNOWN) // other object-related error -#define ERRCODE_SBX_NO_OBJECT (10UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // Object variable unassigned -#define ERRCODE_SBX_CANNOT_LOAD (11UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_CREATE) // Object cannot be loaded or initialized -#define ERRCODE_SBX_BAD_INDEX (12UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_SBX) // Invalid object index -#define ERRCODE_SBX_NO_ACTIVE_OBJECT (13UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_ACCESS) // Object is not activated -#define ERRCODE_SBX_BAD_PROP_VALUE (14UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // Bad property value -#define ERRCODE_SBX_PROP_READONLY (15UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_READ) // Property is read only -#define ERRCODE_SBX_PROP_WRITEONLY (16UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_WRITE) // Property is write only -#define ERRCODE_SBX_INVALID_OBJECT (17UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_ACCESS) // Invalid object reference -#define ERRCODE_SBX_NO_METHOD (18UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // Property oder Methode unbekannt -#define ERRCODE_SBX_INVALID_USAGE_OBJECT (19UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_ACCESS) // Invalid object usage -#define ERRCODE_SBX_NO_OLE (20UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_ACCESS) // No OLE-Object -#define ERRCODE_SBX_BAD_METHOD (21UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // Method not supported -#define ERRCODE_SBX_OLE_ERROR (22UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // OLE Automation Error -#define ERRCODE_SBX_BAD_ACTION (23UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_NOTSUPPORTED) // Action not supported -#define ERRCODE_SBX_NO_NAMED_ARGS (24UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // No named arguments -#define ERRCODE_SBX_BAD_LOCALE (25UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_NOTSUPPORTED) // Locale settings not supported -#define ERRCODE_SBX_NAMED_NOT_FOUND (26UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // Unknown named argument -#define ERRCODE_SBX_NOT_OPTIONAL (27UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // Argument not optional -#define ERRCODE_SBX_WRONG_ARGS (28UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_SBX) // Invalid number of arguments -#define ERRCODE_SBX_NOT_A_COLL (29UL | ERRCODE_AREA_SBX | \ - ERRCODE_CLASS_RUNTIME) // Object contains no elements -#define LAST_SBX_ERROR_ID 29UL - - -// Less important for resources +#define ERRCODE_SBX_OK ERRCODE_NONE // processed + +#define ERRCODE_SBX_SYNTAX (1UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_COMPILER) +#define ERRCODE_SBX_NOTIMP (2UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_NOTSUPPORTED) +#define ERRCODE_SBX_OVERFLOW (3UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_SBX) // overflow +#define ERRCODE_SBX_BOUNDS (4UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_SBX) // Invalid array index +#define ERRCODE_SBX_ZERODIV (5UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_SBX) // Division by zero +#define ERRCODE_SBX_CONVERSION (6UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_SBX) // wrong data type +#define ERRCODE_SBX_BAD_PARAMETER (7UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // invalid Parameter +#define ERRCODE_SBX_PROC_UNDEFINED (8UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Sub or Func not def +#define ERRCODE_SBX_ERROR (9UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_UNKNOWN) // generic object error +#define ERRCODE_SBX_NO_OBJECT (10UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Object var not object +#define ERRCODE_SBX_CANNOT_LOAD (11UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_CREATE) // Object init/load fail +#define ERRCODE_SBX_BAD_INDEX (12UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_SBX) // Invalid object index +#define ERRCODE_SBX_NO_ACTIVE_OBJECT (13UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_ACCESS) // Object not active +#define ERRCODE_SBX_BAD_PROP_VALUE (14UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Bad property value +#define ERRCODE_SBX_PROP_READONLY (15UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_READ) // Property is read only +#define ERRCODE_SBX_PROP_WRITEONLY (16UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_WRITE) // Property is write only +#define ERRCODE_SBX_INVALID_OBJECT (17UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_ACCESS) // Invalid object reference +#define ERRCODE_SBX_NO_METHOD (18UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Property oder Methode unbekannt +#define ERRCODE_SBX_INVALID_USAGE_OBJECT (19UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_ACCESS) // Invalid object usage +#define ERRCODE_SBX_NO_OLE (20UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_ACCESS) // No OLE-Object +#define ERRCODE_SBX_BAD_METHOD (21UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Method not supported +#define ERRCODE_SBX_OLE_ERROR (22UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // OLE Automation Error +#define ERRCODE_SBX_BAD_ACTION (23UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_NOTSUPPORTED) // Action not supported +#define ERRCODE_SBX_NO_NAMED_ARGS (24UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // No named arguments +#define ERRCODE_SBX_BAD_LOCALE (25UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_NOTSUPPORTED) // Locale not supported +#define ERRCODE_SBX_NAMED_NOT_FOUND (26UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Unknown named argument +#define ERRCODE_SBX_NOT_OPTIONAL (27UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Argument not optional +#define ERRCODE_SBX_WRONG_ARGS (28UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_SBX) // Invalid number of arguments +#define ERRCODE_SBX_NOT_A_COLL (29UL | ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME) // Object contains no elements +#define LAST_SBX_ERROR_ID 29UL + #ifndef __RSC // Map old codes to new ones -#define SbxERR_OK ERRCODE_SBX_OK -#define SbxERR_SYNTAX ERRCODE_SBX_SYNTAX -#define SbxERR_NOTIMP ERRCODE_SBX_NOTIMP -#define SbxERR_OVERFLOW ERRCODE_SBX_OVERFLOW -#define SbxERR_BOUNDS ERRCODE_SBX_BOUNDS -#define SbxERR_ZERODIV ERRCODE_SBX_ZERODIV -#define SbxERR_CONVERSION ERRCODE_SBX_CONVERSION -#define SbxERR_BAD_PARAMETER ERRCODE_SBX_BAD_PARAMETER -#define SbxERR_PROC_UNDEFINED ERRCODE_SBX_PROC_UNDEFINED -#define SbxERR_ERROR ERRCODE_SBX_ERROR -#define SbxERR_NO_OBJECT ERRCODE_SBX_NO_OBJECT -#define SbxERR_CANNOT_LOAD ERRCODE_SBX_CANNOT_LOAD -#define SbxERR_BAD_INDEX ERRCODE_SBX_BAD_INDEX -#define SbxERR_NO_ACTIVE_OBJECT ERRCODE_SBX_NO_ACTIVE_OBJECT -#define SbxERR_BAD_PROP_VALUE ERRCODE_SBX_BAD_PROP_VALUE -#define SbxERR_PROP_READONLY ERRCODE_SBX_PROP_READONLY -#define SbxERR_PROP_WRITEONLY ERRCODE_SBX_PROP_WRITEONLY -#define SbxERR_INVALID_OBJECT ERRCODE_SBX_INVALID_OBJECT -#define SbxERR_NO_METHOD ERRCODE_SBX_NO_METHOD -#define SbxERR_INVALID_USAGE_OBJECT ERRCODE_SBX_INVALID_USAGE_OBJECT -#define SbxERR_NO_OLE ERRCODE_SBX_NO_OLE -#define SbxERR_BAD_METHOD ERRCODE_SBX_BAD_METHOD -#define SbxERR_OLE_ERROR ERRCODE_SBX_OLE_ERROR -#define SbxERR_BAD_ACTION ERRCODE_SBX_BAD_ACTION -#define SbxERR_NO_NAMED_ARGS ERRCODE_SBX_NO_NAMED_ARGS -#define SbxERR_BAD_LOCALE ERRCODE_SBX_BAD_LOCALE -#define SbxERR_NAMED_NOT_FOUND ERRCODE_SBX_NAMED_NOT_FOUND -#define SbxERR_NOT_OPTIONAL ERRCODE_SBX_NOT_OPTIONAL -#define SbxERR_WRONG_ARGS ERRCODE_SBX_WRONG_ARGS -#define SbxERR_NOT_A_COLL ERRCODE_SBX_NOT_A_COLL +#define SbxERR_OK ERRCODE_SBX_OK +#define SbxERR_SYNTAX ERRCODE_SBX_SYNTAX +#define SbxERR_NOTIMP ERRCODE_SBX_NOTIMP +#define SbxERR_OVERFLOW ERRCODE_SBX_OVERFLOW +#define SbxERR_BOUNDS ERRCODE_SBX_BOUNDS +#define SbxERR_ZERODIV ERRCODE_SBX_ZERODIV +#define SbxERR_CONVERSION ERRCODE_SBX_CONVERSION +#define SbxERR_BAD_PARAMETER ERRCODE_SBX_BAD_PARAMETER +#define SbxERR_PROC_UNDEFINED ERRCODE_SBX_PROC_UNDEFINED +#define SbxERR_ERROR ERRCODE_SBX_ERROR +#define SbxERR_NO_OBJECT ERRCODE_SBX_NO_OBJECT +#define SbxERR_CANNOT_LOAD ERRCODE_SBX_CANNOT_LOAD +#define SbxERR_BAD_INDEX ERRCODE_SBX_BAD_INDEX +#define SbxERR_NO_ACTIVE_OBJECT ERRCODE_SBX_NO_ACTIVE_OBJECT +#define SbxERR_BAD_PROP_VALUE ERRCODE_SBX_BAD_PROP_VALUE +#define SbxERR_PROP_READONLY ERRCODE_SBX_PROP_READONLY +#define SbxERR_PROP_WRITEONLY ERRCODE_SBX_PROP_WRITEONLY +#define SbxERR_INVALID_OBJECT ERRCODE_SBX_INVALID_OBJECT +#define SbxERR_NO_METHOD ERRCODE_SBX_NO_METHOD +#define SbxERR_INVALID_USAGE_OBJECT ERRCODE_SBX_INVALID_USAGE_OBJECT +#define SbxERR_NO_OLE ERRCODE_SBX_NO_OLE +#define SbxERR_BAD_METHOD ERRCODE_SBX_BAD_METHOD +#define SbxERR_OLE_ERROR ERRCODE_SBX_OLE_ERROR +#define SbxERR_BAD_ACTION ERRCODE_SBX_BAD_ACTION +#define SbxERR_NO_NAMED_ARGS ERRCODE_SBX_NO_NAMED_ARGS +#define SbxERR_BAD_LOCALE ERRCODE_SBX_BAD_LOCALE +#define SbxERR_NAMED_NOT_FOUND ERRCODE_SBX_NAMED_NOT_FOUND +#define SbxERR_NOT_OPTIONAL ERRCODE_SBX_NOT_OPTIONAL +#define SbxERR_WRONG_ARGS ERRCODE_SBX_WRONG_ARGS +#define SbxERR_NOT_A_COLL ERRCODE_SBX_NOT_A_COLL // Flag-Bits: -#define SBX_READ 0x0001 // Read permission -#define SBX_WRITE 0x0002 // Write permission -#define SBX_READWRITE 0x0003 // Read/Write permission -#define SBX_DONTSTORE 0x0004 // Don't store object -#define SBX_MODIFIED 0x0008 // Object was changed -#define SBX_FIXED 0x0010 // Fixed data type (SbxVariable) -#define SBX_CONST 0x0020 // Definition of const value -#define SBX_OPTIONAL 0x0040 // Parameter is optional -#define SBX_HIDDEN 0x0080 // Element is invisible +#define SBX_READ 0x0001 // Read permission +#define SBX_WRITE 0x0002 // Write permission +#define SBX_READWRITE 0x0003 // Read/Write permission +#define SBX_DONTSTORE 0x0004 // Don't store object +#define SBX_MODIFIED 0x0008 // Object was changed +#define SBX_FIXED 0x0010 // Fixed data type (SbxVariable) +#define SBX_CONST 0x0020 // Definition of const value +#define SBX_OPTIONAL 0x0040 // Parameter is optional +#define SBX_HIDDEN 0x0080 // Element is invisible #define SBX_INVISIBLE 0x0100 // Element is not found by Find() #define SBX_EXTSEARCH 0x0200 // Object is searched completely #define SBX_EXTFOUND 0x0400 // Variable was found through extended search @@ -291,7 +269,7 @@ typedef ULONG SbxError; // Preserve old type // List of all creators for Load/Store -#define SBXCR_SBX 0x20584253 // SBX(blank) +#define SBXCR_SBX 0x20584253 // SBX(blank) // List of predefined SBX-IDs. New SBX-IDs must be precisly defined so that // they are unique within the Stream and appropriate Factory. @@ -307,42 +285,48 @@ typedef ULONG SbxError; // Preserve old type #define SBXID_PROPERTY 0x5250 // PR: SbxProperty // StarBASIC restricts the base data type to different intervals. -// These intervals are fixed due to portability and independent +// These intervals are fixed to create 'portability and independent // of the implementation. Only type double is greedy and takes // what it gets. -#define SbxMAXCHAR ((sal_Unicode)65535) -#define SbxMINCHAR (0) -#define SbxMAXBYTE ( 255) -#define SbxMAXINT ( 32767) -#define SbxMININT (-32768) -#define SbxMAXUINT ((UINT16) 65535) -#define SbxMAXLNG ( 2147483647) -#define SbxMINLNG ((INT32)(-2147483647-1)) -#define SbxMAXULNG ((UINT32) 0xffffffff) +#define SbxMAXCHAR ((sal_Unicode)65535) +#define SbxMINCHAR (0) +#define SbxMAXBYTE ( 255) +#define SbxMAXINT ( 32767) +#define SbxMININT (-32768) +#define SbxMAXUINT ((UINT16) 65535) +#define SbxMAXLNG ( 2147483647) +#define SbxMINLNG ((INT32)(-2147483647-1)) +#define SbxMAXULNG ((UINT32) 0xffffffff) +#define SbxMAXSALUINT64 SAL_MAX_UINT64 #define SbxMAXSALINT64 SAL_MAX_INT64 #define SbxMINSALINT64 SAL_MIN_INT64 -#define SbxMAXSALUINT64 SAL_MAX_UINT64 -#define SbxMAXSNG ( 3.402823e+38) -#define SbxMINSNG (-3.402823e+38) -#define SbxMAXSNG2 ( 1.175494351e-38) -#define SbxMINSNG2 (-1.175494351e-38) -#define SbxMAXCURR ( 922337203685477.5807) -#define SbxMINCURR (-922337203685477.5808) -#define CURRENCY_FACTOR 10000 -#define SbxMAXCURRLNG (SbxMAXLNG/CURRENCY_FACTOR) -#define SbxMINCURRLNG (SbxMINLNG/CURRENCY_FACTOR) + // Currency stored as SbxSALINT64 == sal_Int64 + // value range limits are ~(2^63 - 1)/10000 + // fixed precision has 4 digits right of decimal pt +#define CURRENCY_FACTOR (10000) +#define CURRENCY_FACTOR_SQUARE (100000000) + +// TODO effective MAX/MINCURR limits: +// true value ( 922337203685477.5807) is too precise for correct comparison to 64bit double +#define SbxMAXCURR ( 922337203685477.5807) +#define SbxMINCURR (-922337203685477.5808) + +#define SbxMAXSNG ( 3.402823e+38) +#define SbxMINSNG (-3.402823e+38) +#define SbxMAXSNG2 ( 1.175494351e-38) +#define SbxMINSNG2 (-1.175494351e-38) // Max valid offset index of a Sbx-Array (due to 64K limit) -#define SBX_MAXINDEX 0x3FF0 -#define SBX_MAXINDEX32 SbxMAXLNG +#define SBX_MAXINDEX 0x3FF0 +#define SBX_MAXINDEX32 SbxMAXLNG + -// The numeric values of TRUE and FALSE enum SbxBOOL { SbxFALSE = 0, SbxTRUE = -1 }; -#endif // __RSC +#endif //ifndef __RSC #endif diff --git a/basic/inc/basic/sbxvar.hxx b/basic/inc/basic/sbxvar.hxx index f1af839f2471..1e7840950fd7 100644 --- a/basic/inc/basic/sbxvar.hxx +++ b/basic/inc/basic/sbxvar.hxx @@ -34,169 +34,47 @@ #include <com/sun/star/bridge/oleautomation/Decimal.hpp> #include <basic/sbxcore.hxx> -#ifndef __SBX_64 -#define __SBX_64 - -struct SbxINT64 -{ - INT32 nHigh; UINT32 nLow; - -#if FALSE - SbxINT64() : nHigh( 0 ), nLow( 0 ) {} - SbxINT64( UINT8 n ) : nHigh( 0 ), nLow( n ) {} - SbxINT64( UINT16 n ) : nHigh( 0 ), nLow( n ) {} - SbxINT64( UINT32 n ) : nHigh( 0 ), nLow( n ) {} - SbxINT64( unsigned int n ) : nHigh( 0 ), nLow( n ) {} - SbxINT64( INT8 n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} - SbxINT64( INT16 n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} - SbxINT64( INT32 n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} - SbxINT64( int n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} - SbxINT64( SbxINT64 &r ) : nHigh( r.nHigh ), nLow( r.nLow ) {} - - SbxINT64( BigInt &r ); - SbxINT64( double n ); -#endif - void CHS() - { - nLow ^= (UINT32)-1; - nHigh ^= -1; - nLow++; - if( !nLow ) - nHigh++; - } - - // blc/os2i do not like operator = - void Set(double n) - { - if( n >= 0 ) - { - nHigh = (INT32)(n / (double)4294967296.0); - nLow = (UINT32)(n - ((double)nHigh * (double)4294967296.0) + 0.5); - } - else { - nHigh = (INT32)(-n / (double)4294967296.0); - nLow = (UINT32)(-n - ((double)nHigh * (double)4294967296.0) + 0.5); - CHS(); - } - } - void Set(INT32 n) { nHigh = n < 0 ? -1 : 0; nLow = n; } - - void SetMax() { nHigh = 0x7FFFFFFF; nLow = 0xFFFFFFFF; } - void SetMin() { nHigh = 0x80000000; nLow = 0x00000000; } - void SetNull() { nHigh = 0x00000000; nLow = 0x00000000; } - - int operator ! () const { return !nHigh && !nLow; } - - SbxINT64 &operator -= ( const SbxINT64 &r ); - SbxINT64 &operator += ( const SbxINT64 &r ); - SbxINT64 &operator /= ( const SbxINT64 &r ); - SbxINT64 &operator %= ( const SbxINT64 &r ); - SbxINT64 &operator *= ( const SbxINT64 &r ); - SbxINT64 &operator &= ( const SbxINT64 &r ); - SbxINT64 &operator |= ( const SbxINT64 &r ); - SbxINT64 &operator ^= ( const SbxINT64 &r ); - - friend SbxINT64 operator - ( const SbxINT64 &l, const SbxINT64 &r ); - friend SbxINT64 operator + ( const SbxINT64 &l, const SbxINT64 &r ); - friend SbxINT64 operator / ( const SbxINT64 &l, const SbxINT64 &r ); - friend SbxINT64 operator % ( const SbxINT64 &l, const SbxINT64 &r ); - friend SbxINT64 operator * ( const SbxINT64 &l, const SbxINT64 &r ); - friend SbxINT64 operator & ( const SbxINT64 &l, const SbxINT64 &r ); - friend SbxINT64 operator | ( const SbxINT64 &l, const SbxINT64 &r ); - friend SbxINT64 operator ^ ( const SbxINT64 &l, const SbxINT64 &r ); - - friend SbxINT64 operator - ( const SbxINT64 &r ); - friend SbxINT64 operator ~ ( const SbxINT64 &r ); - - static double GetMin() { return ((double)0x7FFFFFFF*(double)4294967296.0 - + (double)0xFFFFFFFF) - / CURRENCY_FACTOR; } - static double GetMax() { return ((double)0x80000000*(double)4294967296.0 - + (double)0xFFFFFFFF) - / CURRENCY_FACTOR; } -}; - -struct SbxUINT64 -{ - UINT32 nHigh; UINT32 nLow; - void Set(double n) - { - nHigh = (UINT32)(n / (double)4294967296.0); - nLow = (UINT32)(n - ((double)nHigh * (double)4294967296.0)); - } - - void Set(UINT32 n) { nHigh = 0; nLow = n; } - - void SetMax() { nHigh = 0xFFFFFFFF; nLow = 0xFFFFFFFF; } - void SetMin() { nHigh = 0x00000000; nLow = 0x00000000; } - void SetNull() { nHigh = 0x00000000; nLow = 0x00000000; } - - int operator ! () const { return !nHigh && !nLow; } - - SbxUINT64 &operator -= ( const SbxUINT64 &r ); - SbxUINT64 &operator += ( const SbxUINT64 &r ); - SbxUINT64 &operator /= ( const SbxUINT64 &r ); - SbxUINT64 &operator %= ( const SbxUINT64 &r ); - SbxUINT64 &operator *= ( const SbxUINT64 &r ); - SbxUINT64 &operator &= ( const SbxUINT64 &r ); - SbxUINT64 &operator |= ( const SbxUINT64 &r ); - SbxUINT64 &operator ^= ( const SbxUINT64 &r ); - - friend SbxUINT64 operator - ( const SbxUINT64 &l, const SbxUINT64 &r ); - friend SbxUINT64 operator + ( const SbxUINT64 &l, const SbxUINT64 &r ); - friend SbxUINT64 operator / ( const SbxUINT64 &l, const SbxUINT64 &r ); - friend SbxUINT64 operator % ( const SbxUINT64 &l, const SbxUINT64 &r ); - friend SbxUINT64 operator * ( const SbxUINT64 &l, const SbxUINT64 &r ); - friend SbxUINT64 operator & ( const SbxUINT64 &l, const SbxUINT64 &r ); - friend SbxUINT64 operator | ( const SbxUINT64 &l, const SbxUINT64 &r ); - friend SbxUINT64 operator ^ ( const SbxUINT64 &l, const SbxUINT64 &r ); - - friend SbxUINT64 operator ~ ( const SbxUINT64 &r ); -}; - -#endif - #ifndef __SBX_SBXVALUES_HXX #define __SBX_SBXVALUES_HXX -class BigInt; class SbxDecimal; struct SbxValues { union { - sal_Unicode nChar; BYTE nByte; - INT16 nInteger; - INT32 nLong; UINT16 nUShort; + sal_Unicode nChar; + INT16 nInteger; UINT32 nULong; + INT32 nLong; + unsigned int nUInt; + int nInt; + sal_uInt64 uInt64; + sal_Int64 nInt64; + float nSingle; double nDouble; - SbxINT64 nLong64; - SbxUINT64 nULong64; - sal_Int64 nInt64; - sal_uInt64 uInt64; - int nInt; - unsigned int nUInt; - ::rtl::OUString* pOUString; + + rtl::OUString* pOUString; SbxDecimal* pDecimal; SbxBase* pObj; - sal_Unicode* pChar; + BYTE* pByte; - INT16* pInteger; - INT32* pLong; UINT16* pUShort; + sal_Unicode* pChar; + INT16* pInteger; UINT32* pULong; + INT32* pLong; + unsigned int* pUInt; + int* pInt; + sal_uInt64* puInt64; + sal_Int64* pnInt64; + float* pSingle; double* pDouble; - SbxINT64* pLong64; - SbxUINT64* pULong64; - sal_Int64* pnInt64; - sal_uInt64* puInt64; - int* pInt; - unsigned int* pUInt; + void* pData; }; SbxDataType eType; @@ -209,15 +87,15 @@ struct SbxValues SbxValues( long _nLong ): nLong( _nLong ), eType(SbxLONG) {} SbxValues( USHORT _nUShort ): nUShort( _nUShort ), eType(SbxUSHORT) {} SbxValues( ULONG _nULong ): nULong( _nULong ), eType(SbxULONG) {} - SbxValues( float _nSingle ): nSingle( _nSingle ), eType(SbxSINGLE) {} - SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {} SbxValues( int _nInt ): nInt( _nInt ), eType(SbxINT) {} SbxValues( unsigned int _nUInt ): nUInt( _nUInt ), eType(SbxUINT) {} + SbxValues( float _nSingle ): nSingle( _nSingle ), eType(SbxSINGLE) {} + SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {} SbxValues( const ::rtl::OUString* _pString ): pOUString( (::rtl::OUString*)_pString ), eType(SbxSTRING) {} SbxValues( SbxBase* _pObj ): pObj( _pObj ), eType(SbxOBJECT) {} SbxValues( sal_Unicode* _pChar ): pChar( _pChar ), eType(SbxLPSTR) {} SbxValues( void* _pData ): pData( _pData ), eType(SbxPOINTER) {} - SbxValues( const BigInt &rBig ); + }; #endif @@ -255,28 +133,28 @@ public: virtual void Clear(); virtual BOOL IsFixed() const; - BOOL IsInteger() const { return BOOL( GetType() == SbxINTEGER ); } - BOOL IsLong() const { return BOOL( GetType() == SbxLONG ); } - BOOL IsSingle() const { return BOOL( GetType() == SbxSINGLE ); } - BOOL IsDouble() const { return BOOL( GetType() == SbxDOUBLE ); } - BOOL IsString() const { return BOOL( GetType() == SbxSTRING ); } - BOOL IsDate() const { return BOOL( GetType() == SbxDATE ); } - BOOL IsCurrency()const { return BOOL( GetType() == SbxCURRENCY ); } - BOOL IsObject() const { return BOOL( GetType() == SbxOBJECT ); } - BOOL IsDataObject()const{return BOOL( GetType() == SbxDATAOBJECT);} - BOOL IsBool() const { return BOOL( GetType() == SbxBOOL ); } - BOOL IsErr() const { return BOOL( GetType() == SbxERROR ); } - BOOL IsEmpty() const { return BOOL( GetType() == SbxEMPTY ); } - BOOL IsNull() const { return BOOL( GetType() == SbxNULL ); } - BOOL IsChar() const { return BOOL( GetType() == SbxCHAR ); } - BOOL IsByte() const { return BOOL( GetType() == SbxBYTE ); } - BOOL IsUShort() const { return BOOL( GetType() == SbxUSHORT ); } - BOOL IsULong() const { return BOOL( GetType() == SbxULONG ); } - BOOL IsInt() const { return BOOL( GetType() == SbxINT ); } - BOOL IsUInt() const { return BOOL( GetType() == SbxUINT ); } - BOOL IspChar() const { return BOOL( GetType() == SbxLPSTR ); } - BOOL IsNumeric() const; - BOOL IsNumericRTL() const; // #41692 Interface for Basic + BOOL IsInteger() const { return BOOL( GetType() == SbxINTEGER ); } + BOOL IsLong() const { return BOOL( GetType() == SbxLONG ); } + BOOL IsSingle() const { return BOOL( GetType() == SbxSINGLE ); } + BOOL IsDouble() const { return BOOL( GetType() == SbxDOUBLE ); } + BOOL IsString() const { return BOOL( GetType() == SbxSTRING ); } + BOOL IsDate() const { return BOOL( GetType() == SbxDATE ); } + BOOL IsCurrency() const { return BOOL( GetType() == SbxCURRENCY ); } + BOOL IsObject() const { return BOOL( GetType() == SbxOBJECT ); } + BOOL IsDataObject() const { return BOOL( GetType() == SbxDATAOBJECT);} + BOOL IsBool() const { return BOOL( GetType() == SbxBOOL ); } + BOOL IsErr() const { return BOOL( GetType() == SbxERROR ); } + BOOL IsEmpty() const { return BOOL( GetType() == SbxEMPTY ); } + BOOL IsNull() const { return BOOL( GetType() == SbxNULL ); } + BOOL IsChar() const { return BOOL( GetType() == SbxCHAR ); } + BOOL IsByte() const { return BOOL( GetType() == SbxBYTE ); } + BOOL IsUShort() const { return BOOL( GetType() == SbxUSHORT ); } + BOOL IsULong() const { return BOOL( GetType() == SbxULONG ); } + BOOL IsInt() const { return BOOL( GetType() == SbxINT ); } + BOOL IsUInt() const { return BOOL( GetType() == SbxUINT ); } + BOOL IspChar() const { return BOOL( GetType() == SbxLPSTR ); } + BOOL IsNumeric() const; + BOOL IsNumericRTL() const; // #41692 Interface for Basic BOOL ImpIsNumeric( BOOL bOnlyIntntl ) const; // Implementation virtual SbxClassType GetClass() const; @@ -291,61 +169,70 @@ public: inline SbxValues * data() { return &aData; } - SbxINT64 GetCurrency() const; - SbxINT64 GetLong64() const; - SbxUINT64 GetULong64() const; - sal_Int64 GetInt64() const; - sal_uInt64 GetUInt64() const; - INT16 GetInteger() const; - INT32 GetLong() const; - float GetSingle() const; - double GetDouble() const; - double GetDate() const; - BOOL GetBool() const; - UINT16 GetErr() const; - const String& GetString() const; - const String& GetCoreString() const; - ::rtl::OUString GetOUString() const; - SbxDecimal* GetDecimal() const; - SbxBase* GetObject() const; - BOOL HasObject() const; - void* GetData() const; + UINT16 GetErr() const; + + BOOL GetBool() const; + BYTE GetByte() const; sal_Unicode GetChar() const; - BYTE GetByte() const; - UINT16 GetUShort() const; - UINT32 GetULong() const; - int GetInt() const; - - BOOL PutCurrency( const SbxINT64& ); - BOOL PutLong64( const SbxINT64& ); - BOOL PutULong64( const SbxUINT64& ); - BOOL PutInt64( sal_Int64 ); - BOOL PutUInt64( sal_uInt64 ); + UINT16 GetUShort() const; + UINT32 GetULong() const; + int GetInt() const; + INT16 GetInteger() const; + INT32 GetLong() const; + sal_Int64 GetInt64() const; + sal_uInt64 GetUInt64() const; + + sal_Int64 GetCurrency() const; + SbxDecimal* GetDecimal() const; + + float GetSingle() const; + double GetDouble() const; + double GetDate() const; + + const String& GetString() const; + const String& GetCoreString() const; + rtl::OUString GetOUString() const; + + SbxBase* GetObject() const; + BOOL HasObject() const; + void* GetData() const; + + + BOOL PutEmpty(); + BOOL PutNull(); + BOOL PutErr( USHORT ); + + BOOL PutBool( BOOL ); + BOOL PutByte( BYTE ); + BOOL PutChar( sal_Unicode ); + BOOL PutUShort( UINT16 ); + BOOL PutULong( UINT32 ); + BOOL PutInt( int ); BOOL PutInteger( INT16 ); BOOL PutLong( INT32 ); + BOOL PutInt64( sal_Int64 ); + BOOL PutUInt64( sal_uInt64 ); + BOOL PutSingle( float ); BOOL PutDouble( double ); BOOL PutDate( double ); - BOOL PutBool( BOOL ); - BOOL PutErr( USHORT ); - BOOL PutStringExt( const ::rtl::OUString& ); // with extended analysis (International, "TRUE"/"FALSE") + + // with extended analysis (International, "TRUE"/"FALSE") + BOOL PutStringExt( const ::rtl::OUString& ); BOOL PutString( const ::rtl::OUString& ); BOOL PutString( const sal_Unicode* ); // Type = SbxSTRING BOOL PutpChar( const sal_Unicode* ); // Type = SbxLPSTR - BOOL PutDecimal( SbxDecimal* pDecimal ); - BOOL PutObject( SbxBase* ); - BOOL PutData( void* ); - BOOL PutChar( sal_Unicode ); - BOOL PutByte( BYTE ); - BOOL PutUShort( UINT16 ); - BOOL PutULong( UINT32 ); - BOOL PutInt( int ); - BOOL PutEmpty(); - BOOL PutNull(); - // Special decimal methods + // Special methods BOOL PutDecimal( com::sun::star::bridge::oleautomation::Decimal& rAutomationDec ); BOOL fillAutomationDecimal( com::sun::star::bridge::oleautomation::Decimal& rAutomationDec ); + BOOL PutDecimal( SbxDecimal* pDecimal ); + BOOL PutCurrency( const sal_Int64& ); + // Interface for CDbl in Basic + static SbxError ScanNumIntnl( const String& rSrc, double& nVal, BOOL bSingle=FALSE ); + + BOOL PutObject( SbxBase* ); + BOOL PutData( void* ); virtual BOOL Convert( SbxDataType ); virtual BOOL Compute( SbxOperator, const SbxValue& ); @@ -353,12 +240,9 @@ public: BOOL Scan( const String&, USHORT* = NULL ); void Format( String&, const String* = NULL ) const; - // Interface for CDbl in Basic - static SbxError ScanNumIntnl( const String& rSrc, double& nVal, BOOL bSingle=FALSE ); - // The following operators are definied for easier handling. - // Error conditions (overflow, conversions) are not - // taken into consideration. + // TODO: Ensure error conditions (overflow, conversions) + // are taken into consideration in Compute and Compare inline int operator ==( const SbxValue& ) const; inline int operator !=( const SbxValue& ) const; @@ -446,7 +330,7 @@ class SbxVariable : public SbxValue friend class SbMethod; SbxVariableImpl* mpSbxVariableImpl; // Impl data - SfxBroadcaster* pCst; // Broadcaster, if needed + SfxBroadcaster* pCst; // Broadcaster, if needed String maName; // Name, if available SbxArrayRef mpPar; // Parameter-Array, if set USHORT nHash; // Hash-ID for search diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 3a2a0dac6b78..c97945515db3 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -781,13 +781,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue ) oleautomation::Currency aCurrency; if( (aValue >>= aCurrency) ) { - sal_Int64 nValue64 = aCurrency.Value; - SbxINT64 aInt64; - aInt64.nHigh = - sal::static_int_cast< INT32 >( - nValue64 >> 32); - aInt64.nLow = (UINT32)( nValue64 & 0xffffffff ); - pVar->PutCurrency( aInt64 ); + pVar->PutCurrency( aCurrency.Value ); break; } } @@ -960,8 +954,6 @@ Type getUnoTypeForSbxBaseType( SbxDataType eType ) case SbxBYTE: aRetType = ::getCppuType( (sal_Int8*)0 ); break; case SbxUSHORT: aRetType = ::getCppuType( (sal_uInt16*)0 ); break; case SbxULONG: aRetType = ::getCppuType( (sal_uInt32*)0 ); break; - //case SbxLONG64: break; - //case SbxULONG64: break; // map machine-dependent ones on hyper for secureness case SbxINT: aRetType = ::getCppuType( (sal_Int32*)0 ); break; case SbxUINT: aRetType = ::getCppuType( (sal_uInt32*)0 ); break; @@ -1103,7 +1095,7 @@ Type getUnoTypeForSbxValue( SbxValue* pVal ) } // Otherwise it is a No-Uno-Basic-Object -> default==deliver void } - // No objekt, convert basic type + // No object, convert basic type else { aRetType = getUnoTypeForSbxBaseType( eBaseType ); @@ -1192,6 +1184,7 @@ Any sbxToUnoValueImpl( SbxVariable* pVar, bool bBlockConversionToSmallestType = aType = ::getCppuType( (sal_uInt16*)0 ); break; } + // TODO: need to add hyper types ? default: break; } } @@ -1324,13 +1317,8 @@ Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty } else if( rType == ::getCppuType( (oleautomation::Currency*)0 ) ) { - SbxINT64 aInt64 = pVar->GetCurrency(); - oleautomation::Currency aCurrency; - sal_Int64& rnValue64 = aCurrency.Value; - rnValue64 = aInt64.nHigh; - rnValue64 <<= 32; - rnValue64 |= aInt64.nLow; - aRetVal <<= aCurrency; + // assumes per previous code that ole Currency is Int64 + aRetVal <<= (sal_Int64)( pVar->GetInt64() ); break; } else if( rType == ::getCppuType( (oleautomation::Date*)0 ) ) @@ -1363,11 +1351,9 @@ Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty case TypeClass_CLASS: break; case TypeClass_TYPEDEF: break; case TypeClass_UNION: break; - case TypeClass_ENUM: break; case TypeClass_ARRAY: break; */ - // Array -> Sequence case TypeClass_ENUM: { aRetVal = int2enum( pVar->GetLong(), rType ); @@ -1888,8 +1874,6 @@ String Dbg_SbxDataType2String( SbxDataType eType ) case SbxBYTE: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxBYTE") ); break; case SbxUSHORT: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxUSHORT") ); break; case SbxULONG: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxULONG") ); break; - case SbxLONG64: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxLONG64") ); break; - case SbxULONG64: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxULONG64") ); break; case SbxSALINT64: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxINT64") ); break; case SbxSALUINT64: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxUINT64") ); break; case SbxINT: aRet = String( RTL_CONSTASCII_USTRINGPARAM("SbxINT") ); break; diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index b922b556bd2c..4c4cecb08b04 100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -158,12 +158,12 @@ RTLFUNC(CByte) // JSM rPar.Get(0)->PutByte(nByte); } -RTLFUNC(CCur) // JSM +RTLFUNC(CCur) { (void)pBasic; (void)bWrite; - SbxINT64 nCur; + sal_Int64 nCur = 0; if ( rPar.Count() == 2 ) { SbxVariable *pSbxVariable = rPar.Get(1); @@ -175,7 +175,7 @@ RTLFUNC(CCur) // JSM rPar.Get(0)->PutCurrency( nCur ); } -RTLFUNC(CDec) // JSM +RTLFUNC(CDec) { (void)pBasic; (void)bWrite; @@ -881,13 +881,16 @@ BOOL lcl_WriteSbxVariable( const SbxVariable& rVar, SvStream* pStrm, case SbxLONG: case SbxULONG: - case SbxLONG64: - case SbxULONG64: if( bIsVariant ) *pStrm << (USHORT)SbxLONG; // VarType Id *pStrm << rVar.GetLong(); break; - + case SbxSALINT64: + case SbxSALUINT64: + if( bIsVariant ) + *pStrm << (USHORT)SbxSALINT64; // VarType Id + *pStrm << (sal_uInt64)rVar.GetInt64(); + break; case SbxSINGLE: if( bIsVariant ) *pStrm << (USHORT)eType; // VarType Id @@ -983,15 +986,20 @@ BOOL lcl_ReadSbxVariable( SbxVariable& rVar, SvStream* pStrm, case SbxLONG: case SbxULONG: - case SbxLONG64: - case SbxULONG64: { INT32 aInt; *pStrm >> aInt; rVar.PutLong( aInt ); } break; - + case SbxSALINT64: + case SbxSALUINT64: + { + sal_uInt32 aInt; + *pStrm >> aInt; + rVar.PutInt64( (sal_Int64)aInt ); + } + break; case SbxSINGLE: { float nS; @@ -1354,8 +1362,8 @@ RTLFUNC(TypeLen) case SbxDOUBLE: case SbxCURRENCY: case SbxDATE: - case SbxLONG64: - case SbxULONG64: + case SbxSALINT64: + case SbxSALUINT64: nLen = 8; break; diff --git a/basic/source/sbx/makefile.mk b/basic/source/sbx/makefile.mk index cc20080cbe9c..9b76f9698417 100644 --- a/basic/source/sbx/makefile.mk +++ b/basic/source/sbx/makefile.mk @@ -58,7 +58,6 @@ SLOFILES= \ $(SLO)$/sbxsng.obj \ $(SLO)$/sbxuint.obj \ $(SLO)$/sbxulng.obj \ - $(SLO)$/sbxvals.obj \ $(SLO)$/sbxvar.obj diff --git a/basic/source/sbx/sbxbool.cxx b/basic/source/sbx/sbxbool.cxx index 35e36a94a557..03b435af1ef6 100644 --- a/basic/source/sbx/sbxbool.cxx +++ b/basic/source/sbx/sbxbool.cxx @@ -71,14 +71,10 @@ enum SbxBOOL ImpGetBool( const SbxValues* p ) } break; case SbxSALINT64: + case SbxCURRENCY: nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break; case SbxSALUINT64: nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break; - case SbxULONG64: - nRes = !!p->nULong64 ? SbxTRUE : SbxFALSE; break; - case SbxLONG64: - case SbxCURRENCY: - nRes = !!p->nLong64 ? SbxTRUE : SbxFALSE; break; case SbxBYREF | SbxSTRING: case SbxSTRING: case SbxLPSTR: @@ -139,16 +135,11 @@ enum SbxBOOL ImpGetBool( const SbxValues* p ) case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: nRes = ( *p->pDouble != 0 ) ? SbxTRUE : SbxFALSE; break; + case SbxBYREF | SbxCURRENCY: case SbxBYREF | SbxSALINT64: nRes = ( *p->pnInt64 ) ? SbxTRUE : SbxFALSE; break; case SbxBYREF | SbxSALUINT64: nRes = ( *p->puInt64 ) ? SbxTRUE : SbxFALSE; break; - case SbxBYREF | SbxULONG64: - nRes = !!*p->pULong64 ? SbxTRUE : SbxFALSE; break; - case SbxBYREF | SbxLONG64: - case SbxBYREF | SbxCURRENCY: - nRes = !!*p->pLong64 ? SbxTRUE : SbxFALSE; break; - default: SbxBase::SetError( SbxERR_CONVERSION ); nRes = SbxFALSE; } @@ -180,15 +171,11 @@ void ImpPutBool( SbxValues* p, INT16 n ) case SbxDATE: case SbxDOUBLE: p->nDouble = n; break; + case SbxCURRENCY: case SbxSALINT64: - p->nInt64 = n; break; + p->nInt64 = (sal_Int64) n; break; case SbxSALUINT64: - p->uInt64 = n; break; - case SbxULONG64: - p->nULong64.Set( (UINT32)n ); break; - case SbxLONG64: - case SbxCURRENCY: - p->nLong64.Set( (INT32)n ); break; + p->uInt64 = (sal_uInt64) n; break; case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: ImpCreateDecimal( p )->setInt( (INT16)n ); @@ -231,16 +218,11 @@ void ImpPutBool( SbxValues* p, INT16 n ) case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: *p->pDouble = n; break; + case SbxBYREF | SbxCURRENCY: case SbxBYREF | SbxSALINT64: - *p->pnInt64 = n; break; + *p->pnInt64 = (sal_Int64) n; break; case SbxBYREF | SbxSALUINT64: - *p->puInt64 = n; break; - case SbxBYREF | SbxULONG64: - p->pULong64->Set( (UINT32)n ); break; - case SbxBYREF | SbxLONG64: - case SbxBYREF | SbxCURRENCY: - p->pLong64->Set( (INT32)n ); break; - + *p->puInt64 = (sal_uInt64) n; break; default: SbxBase::SetError( SbxERR_CONVERSION ); } diff --git a/basic/source/sbx/sbxbyte.cxx b/basic/source/sbx/sbxbyte.cxx index 727d1174417d..cbdc32c30d4f 100644 --- a/basic/source/sbx/sbxbyte.cxx +++ b/basic/source/sbx/sbxbyte.cxx @@ -95,8 +95,13 @@ start: else nRes = (BYTE) p->nULong; break; + case SbxCURRENCY: case SbxSALINT64: - if( p->nInt64 > SbxMAXBYTE ) + { + sal_Int64 val = p->nInt64; + if ( p->eType == SbxCURRENCY ) + val = val / CURRENCY_FACTOR; + if( val > SbxMAXBYTE ) { SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE; } @@ -105,8 +110,9 @@ start: SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0; } else - nRes = (BYTE) p->nInt64; + nRes = (BYTE) val; break; + } case SbxSALUINT64: if( p->uInt64 > SbxMAXBYTE ) { @@ -129,20 +135,11 @@ start: break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: - case SbxCURRENCY: case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: { double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else if( p->eType == SbxDECIMAL ) + if( p->eType == SbxDECIMAL ) { dVal = 0.0; if( p->pDecimal ) @@ -219,11 +216,7 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: @@ -259,16 +252,12 @@ void ImpPutByte( SbxValues* p, BYTE n ) case SbxDATE: case SbxDOUBLE: p->nDouble = n; break; + case SbxCURRENCY: + p->nInt64 = n * CURRENCY_FACTOR; break; case SbxSALINT64: p->nInt64 = n; break; case SbxSALUINT64: p->uInt64 = n; break; - case SbxULONG64: - p->nULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxLONG64: - p->nLong64 = ImpDoubleToINT64( (double)n ); break; - case SbxCURRENCY: - p->nLong64 = ImpDoubleToCurrency( (double)n ); break; case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: ImpCreateDecimal( p )->setByte( n ); @@ -312,16 +301,12 @@ void ImpPutByte( SbxValues* p, BYTE n ) case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: *p->pDouble = n; break; - case SbxBYREF | SbxULONG64: - *p->pULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxBYREF | SbxLONG64: - *p->pLong64 = ImpDoubleToINT64( (double)n ); break; + case SbxBYREF | SbxCURRENCY: + p->nInt64 = n * CURRENCY_FACTOR; break; case SbxBYREF | SbxSALINT64: *p->pnInt64 = n; break; case SbxBYREF | SbxSALUINT64: *p->puInt64 = n; break; - case SbxBYREF | SbxCURRENCY: - *p->pLong64 = ImpDoubleToCurrency( (double)n ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); diff --git a/basic/source/sbx/sbxchar.cxx b/basic/source/sbx/sbxchar.cxx index f516df8876f8..f579eafa9047 100644 --- a/basic/source/sbx/sbxchar.cxx +++ b/basic/source/sbx/sbxchar.cxx @@ -81,8 +81,15 @@ start: else nRes = (xub_Unicode) p->nULong; break; + case SbxCURRENCY: case SbxSALINT64: - if( p->nInt64 > SbxMAXCHAR ) + { + sal_Int64 val = p->nInt64; + + if ( p->eType == SbxCURRENCY ) + val = val / CURRENCY_FACTOR; + + if( val > SbxMAXCHAR ) { SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR; } @@ -91,8 +98,9 @@ start: SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR; } else - nRes = (xub_Unicode) p->nInt64; + nRes = (xub_Unicode) val; break; + } case SbxSALUINT64: if( p->uInt64 > SbxMAXCHAR ) { @@ -115,20 +123,11 @@ start: break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: - case SbxCURRENCY: case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: { double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else if( p->eType == SbxDECIMAL ) + if( p->eType == SbxDECIMAL ) { dVal = 0.0; if( p->pDecimal ) @@ -202,11 +201,7 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: @@ -239,16 +234,12 @@ start: case SbxDATE: case SbxDOUBLE: p->nDouble = n; break; + case SbxCURRENCY: + p->nInt64 = n * CURRENCY_FACTOR; break; case SbxSALINT64: p->nInt64 = n; break; case SbxSALUINT64: p->uInt64 = n; break; - case SbxULONG64: - p->nULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxLONG64: - p->nLong64 = ImpDoubleToINT64( (double)n ); break; - case SbxCURRENCY: - p->nLong64 = ImpDoubleToCurrency( (double)n ); break; case SbxBYREF | SbxDECIMAL: ImpCreateDecimal( p )->setChar( n ); break; @@ -301,16 +292,12 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: *p->pDouble = (double) n; break; + case SbxBYREF | SbxCURRENCY: + p->nInt64 = n * CURRENCY_FACTOR; break; case SbxBYREF | SbxSALINT64: *p->pnInt64 = n; break; case SbxBYREF | SbxSALUINT64: *p->puInt64 = n; break; - case SbxBYREF | SbxULONG64: - *p->pULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxBYREF | SbxLONG64: - *p->pLong64 = ImpDoubleToINT64( (double)n ); break; - case SbxBYREF | SbxCURRENCY: - *p->pLong64 = ImpDoubleToCurrency( (double)n ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); diff --git a/basic/source/sbx/sbxconv.hxx b/basic/source/sbx/sbxconv.hxx index 8155a98c1f07..ad455b2872af 100644 --- a/basic/source/sbx/sbxconv.hxx +++ b/basic/source/sbx/sbxconv.hxx @@ -47,13 +47,15 @@ extern BOOL ImpConvStringExt( ::rtl::OUString& rSrc, SbxDataType eTargetType ); double ImpRound( double ); INT16 ImpGetInteger( const SbxValues* ); void ImpPutInteger( SbxValues*, INT16 ); + sal_Int64 ImpGetInt64( const SbxValues* ); void ImpPutInt64( SbxValues*, sal_Int64 ); sal_uInt64 ImpGetUInt64( const SbxValues* ); void ImpPutUInt64( SbxValues*, sal_uInt64 ); -sal_Int64 ImpDoubleToSalInt64( double d ); +sal_Int64 ImpDoubleToSalInt64 ( double d ); sal_uInt64 ImpDoubleToSalUInt64( double d ); +double ImpSalInt64ToDouble ( sal_Int64 n ); double ImpSalUInt64ToDouble( sal_uInt64 n ); // SBXLNG.CXX @@ -71,37 +73,18 @@ void ImpPutSingle( SbxValues*, float ); double ImpGetDouble( const SbxValues* ); void ImpPutDouble( SbxValues*, double, BOOL bCoreString=FALSE ); -#if FALSE -// SBX64.CXX - -SbxINT64 ImpGetINT64( const SbxValues* ); -void ImpPutINT64( SbxValues*, const SbxINT64& ); -SbxUINT64 ImpGetUINT64( const SbxValues* ); -void ImpPutUINT64( SbxValues*, const SbxUINT64& ); -#endif - // SBXCURR.CXX -SbxUINT64 ImpDoubleToUINT64( double ); -double ImpUINT64ToDouble( const SbxUINT64& ); -SbxINT64 ImpDoubleToINT64( double ); -double ImpINT64ToDouble( const SbxINT64& ); +sal_Int64 ImpGetCurrency( const SbxValues* ); +void ImpPutCurrency( SbxValues*, const sal_Int64 ); -#if TRUE -INT32 ImpGetCurrLong( const SbxValues* ); -void ImpPutCurrLong( SbxValues*, INT32 ); -INT32 ImpDoubleToCurrLong( double ); -double ImpCurrLongToDouble( INT32 ); -#endif +inline sal_Int64 ImpDoubleToCurrency( double d ) + { if (d > 0) return (sal_Int64)( d * CURRENCY_FACTOR + 0.5); + else return (sal_Int64)( d * CURRENCY_FACTOR - 0.5); + } -SbxINT64 ImpGetCurrency( const SbxValues* ); -void ImpPutCurrency( SbxValues*, const SbxINT64& ); -inline -SbxINT64 ImpDoubleToCurrency( double d ) - { return ImpDoubleToINT64( d * CURRENCY_FACTOR ); } -inline -double ImpCurrencyToDouble( const SbxINT64 &r ) - { return ImpINT64ToDouble( r ) / CURRENCY_FACTOR; } +inline double ImpCurrencyToDouble( const sal_Int64 r ) + { return (double)r / (double)CURRENCY_FACTOR; } // SBXDEC.CXX @@ -124,7 +107,7 @@ void ImpPutString( SbxValues*, const ::rtl::OUString* ); // SBXCHAR.CXX sal_Unicode ImpGetChar( const SbxValues* ); -void ImpPutChar( SbxValues*, sal_Unicode ); +void ImpPutChar( SbxValues*, sal_Unicode ); // SBXBYTE.CXX BYTE ImpGetByte( const SbxValues* ); @@ -143,9 +126,9 @@ void ImpPutULong( SbxValues*, UINT32 ); // SBXBOOL.CXX enum SbxBOOL ImpGetBool( const SbxValues* ); -void ImpPutBool( SbxValues*, INT16 ); +void ImpPutBool( SbxValues*, INT16 ); -// ByteArry <--> String +// ByteArray <--> String SbxArray* StringToByteArray(const ::rtl::OUString& rStr); ::rtl::OUString ByteArrayToString(SbxArray* pArr); diff --git a/basic/source/sbx/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx index d94586c50a12..7775dde239f3 100644 --- a/basic/source/sbx/sbxcurr.cxx +++ b/basic/source/sbx/sbxcurr.cxx @@ -29,101 +29,290 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basic.hxx" -#include <basic/sbx.hxx> #include <tools/errcode.hxx> +#include <vcl/svapp.hxx> // for SvtSysLocale -#define _TLBIGINT_INT64 -#include <tools/bigint.hxx> - +#include <basic/sbx.hxx> #include <basic/sbxvar.hxx> #include "sbxconv.hxx" -static ::rtl::OUString ImpCurrencyToString( const SbxINT64& ); -static SbxINT64 ImpStringToCurrency( const ::rtl::OUString& ); -SbxINT64 ImpGetCurrency( const SbxValues* p ) +static rtl::OUString ImpCurrencyToString( const sal_Int64 &rVal ) { - SbxValues aTmp; - SbxINT64 nRes; + bool isNeg = ( rVal < 0 ); + sal_Int64 absVal = isNeg ? -rVal : rVal; + + SvtSysLocale aSysLocale; + sal_Unicode cDecimalSep = '.'; +#if MAYBEFUTURE + sal_Unicode cThousandSep = ','; + const LocaleDataWrapper& rData = aSysLocale.GetLocaleData(); + cDecimalSep = rData.getNumDecimalSep().GetBuffer()[0]; + cThousandSep = rData.getNumThousandSep().GetBuffer()[0]; +#endif + + rtl::OUString aAbsStr = rtl::OUString::valueOf( absVal ); + rtl::OUStringBuffer aBuf; + + sal_Int32 initialLen = aAbsStr.getLength(); + + bool bLessThanOne = false; + if ( initialLen <= 4 ) // if less the 1 + bLessThanOne = true; + + sal_Int32 nCapacity = 6; // minimum e.g. 0.0000 + + if ( !bLessThanOne ) + { + nCapacity = initialLen + 1; +#if MAYBEFUTURE + if ( initialLen > 5 ) + { + sal_Int32 nThouSeperators = ( initialLen - 5 ) / 3; + nCapacity += nThouSeperators; + } +#endif + } + + if ( isNeg ) + ++nCapacity; + + aBuf.setLength( nCapacity ); + + + sal_Int32 nDigitCount = 0; + sal_Int32 nInsertIndex = nCapacity - 1; + sal_Int32 nEndIndex = isNeg ? 1 : 0; + + for ( sal_Int32 charCpyIndex = aAbsStr.getLength() - 1; nInsertIndex >= nEndIndex; ++nDigitCount ) + { + if ( nDigitCount == 4 ) + aBuf.setCharAt( nInsertIndex--, cDecimalSep ); +#if MAYBEFUTURE + if ( nDigitCount > 4 && ! ( ( nDigitCount - 4 ) % 3) ) + aBuf.setCharAt( nInsertIndex--, cThousandSep ); +#endif + if ( nDigitCount < initialLen ) + aBuf.setCharAt( nInsertIndex--, aAbsStr[ charCpyIndex-- ] ); + else + // Handle leading 0's to right of decimal point + // Note: in VBA the stringification is a little more complex + // but more natural as only the necessary digits + // to the right of the decimal places are displayed + // It would be great to conditionally be able to display like that too + // + // Val OOo (Cur) VBA (Cur) + // --- --------- --------- + // 0 0.0000 0 + // 0.1 0.1000 0.1 + + aBuf.setCharAt( nInsertIndex--, (sal_Unicode)'0' ); + } + if ( isNeg ) + aBuf.setCharAt( nInsertIndex, (sal_Unicode)'-' ); + + aAbsStr = aBuf.makeStringAndClear(); + return aAbsStr; +} + + +static sal_Int64 ImpStringToCurrency( const rtl::OUString &rStr ) +{ + + sal_Int32 nFractDigit = 4; + + SvtSysLocale aSysLocale; + sal_Unicode cDeciPnt = sal_Unicode('.'); + sal_Unicode c1000Sep = sal_Unicode(','); + +#if MAYBEFUTURE + const LocaleDataWrapper& rData = aSysLocale.GetLocaleData(); + sal_Unicode cLocaleDeciPnt = rData.getNumDecimalSep().GetBuffer()[0]; + sal_Unicode cLocale1000Sep = rData.getNumThousandSep().GetBuffer()[0]; + + // score each set of separators (Locale and Basic) on total number of matches + // if one set has more matches use that set + // if tied use the set with the only or rightmost decimal separator match + // currency is fixed pt system: usually expect the decimal pt, 1000sep may occur + sal_Int32 LocaleScore = 0; + sal_Int32 LocaleLastDeci = -1; + sal_Int32 LOBasicScore = 0; + sal_Int32 LOBasicLastDeci = -1; + + for( int idx=0; idx<rStr.getLength(); idx++ ) + { + if ( *(p+idx) == cLocaleDeciPnt ) + { + LocaleScore++; + LocaleLastDeci = idx; + } + if ( *(p+idx) == cLocale1000Sep ) + LocaleScore++; + + if ( *(p+idx) == cDeciPnt ) + { + LOBasicScore++; + LOBasicLastDeci = idx; + } + if ( *(p+idx) == c1000Sep ) + LOBasicScore++; + } + if ( ( LocaleScore > LOBasicScore ) + ||( LocaleScore = LOBasicScore && LocaleLastDeci > LOBasicLastDeci ) ) + { + cDeciPnt = cLocaleDeciPnt; + c1000Sep = cLocale1000Sep; + } +#endif + + // lets use the existing string number conversions + // there is a performance impact here ( multiple string copies ) + // but better I think than a home brewed string parser, if we need a parser + // we should share some existing ( possibly from calc is there a currency + // conversion there ? #TODO check ) + + rtl::OUString sTmp( rStr.trim() ); + const sal_Unicode* p = sTmp.getStr(); + + // normalise string number by removeing thousands & decimal point seperators + rtl::OUStringBuffer sNormalisedNumString( sTmp.getLength() + nFractDigit ); + + if ( *p == '-' || *p == '+' ) + sNormalisedNumString.append( *p ); + + while ( ( *p >= '0' && *p <= '9' ) ) + { + sNormalisedNumString.append( *p++ ); + // #TODO in vba mode set runtime error when a space ( or other ) + // illegal character is found + if( *p == c1000Sep ) + p++; + } + + if( *p == cDeciPnt ) + { + p++; + while( nFractDigit && *p >= '0' && *p <= '9' ) + { + sNormalisedNumString.append( *p++ ); + nFractDigit--; + } + } + // can we raise error here ? ( previous behaviour was more forgiving ) + // so... not sure that could bread existing code, lets see if anyone + // complains. + + if ( p != sTmp.getStr() + sTmp.getLength() ) + SbxBase::SetError( SbxERR_CONVERSION ); + while( nFractDigit ) + { + sNormalisedNumString.append( '0' ); + nFractDigit--; + } + + sal_Int64 result = sNormalisedNumString.makeStringAndClear().toInt64(); + return result; +} + + +sal_Int64 ImpGetCurrency( const SbxValues* p ) +{ + SbxValues aTmp; + sal_Int64 nRes; start: switch( +p->eType ) { + case SbxERROR: case SbxNULL: SbxBase::SetError( SbxERR_CONVERSION ); + nRes = 0; break; case SbxEMPTY: - nRes.SetNull(); break; - case SbxCHAR: - nRes = ImpDoubleToCurrency( (double)p->nChar ); break; + nRes = 0; break; + case SbxCURRENCY: + nRes = p->nInt64; break; case SbxBYTE: - nRes = ImpDoubleToCurrency( (double)p->nByte ); break; - case SbxINTEGER: + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(p->nByte); + break; + case SbxCHAR: + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(p->pChar); + break; case SbxBOOL: - nRes = ImpDoubleToCurrency( (double)p->nInteger ); break; - case SbxERROR: + case SbxINTEGER: + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(p->nInteger); + break; case SbxUSHORT: - nRes = ImpDoubleToCurrency( (double)p->nUShort ); break; - case SbxCURRENCY: - nRes = p->nLong64; break; + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(p->nUShort); + break; case SbxLONG: - nRes = ImpDoubleToCurrency( (double)p->nLong ); + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(p->nLong); break; case SbxULONG: - nRes = ImpDoubleToCurrency( (double)p->nULong ); + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(p->nULong); break; + case SbxSALINT64: - nRes = ImpDoubleToCurrency( (double)p->nInt64 ); - break; + { + nRes = p->nInt64 * CURRENCY_FACTOR; break; + if ( nRes > SbxMAXSALINT64 ) + { + SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64; + } + } case SbxSALUINT64: - nRes = ImpDoubleToCurrency( ImpSalUInt64ToDouble( p->uInt64 ) ); - break; - case SbxSINGLE: - if( p->nSingle > SbxMAXCURR ) + nRes = p->nInt64 * CURRENCY_FACTOR; break; + if ( nRes > SbxMAXSALINT64 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); nRes.SetMax(); + SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64; } - else if( p->nSingle < SbxMINCURR ) + else if ( nRes < SbxMINSALINT64 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); nRes.SetMin(); + SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINSALINT64; } - else - nRes = ImpDoubleToCurrency( (double)p->nSingle ); break; - case SbxDATE: - case SbxDOUBLE: - if( p->nDouble > SbxMAXCURR ) +//TODO: bring back SbxINT64 types here for limits -1 with flag value at SAL_MAX/MIN + case SbxSINGLE: + if( p->nSingle * CURRENCY_FACTOR + 0.5 > (float)SAL_MAX_INT64 + || p->nSingle * CURRENCY_FACTOR - 0.5 < (float)SAL_MIN_INT64 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); nRes.SetMax(); + nRes = SAL_MAX_INT64; + if( p->nSingle * CURRENCY_FACTOR - 0.5 < (float)SAL_MIN_INT64 ) + nRes = SAL_MIN_INT64; + SbxBase::SetError( SbxERR_OVERFLOW ); + break; } - else if( p->nDouble < SbxMINCURR ) + nRes = ImpDoubleToCurrency( (double)p->nSingle ); + break; + + case SbxDATE: + case SbxDOUBLE: + if( p->nDouble * CURRENCY_FACTOR + 0.5 > (double)SAL_MAX_INT64 + || p->nDouble * CURRENCY_FACTOR - 0.5 < (double)SAL_MIN_INT64 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); nRes.SetMin(); + nRes = SAL_MAX_INT64; + if( p->nDouble * CURRENCY_FACTOR - 0.5 < (double)SAL_MIN_INT64 ) + nRes = SAL_MIN_INT64; + SbxBase::SetError( SbxERR_OVERFLOW ); + break; } - else - nRes = ImpDoubleToCurrency( p->nDouble ); + nRes = ImpDoubleToCurrency( p->nDouble ); break; + case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: { double d = 0.0; if( p->pDecimal ) p->pDecimal->getDouble( d ); - if( d > SbxMAXCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); nRes.SetMax(); - } - else if( d < SbxMINCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); nRes.SetMin(); - } - else - nRes = ImpDoubleToCurrency( d ); + nRes = ImpDoubleToCurrency( d ); break; } + + case SbxBYREF | SbxSTRING: case SbxSTRING: case SbxLPSTR: if( !p->pOUString ) - nRes.SetNull(); + nRes=0; else nRes = ImpStringToCurrency( *p->pOUString ); break; @@ -134,23 +323,26 @@ start: nRes = pVal->GetCurrency(); else { - SbxBase::SetError( SbxERR_NO_OBJECT ); nRes.SetNull(); + SbxBase::SetError( SbxERR_NO_OBJECT ); + nRes=0; } break; } case SbxBYREF | SbxCHAR: - nRes = ImpDoubleToCurrency( (double)*p->pChar ); break; + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(*p->pChar); + break; case SbxBYREF | SbxBYTE: - nRes = ImpDoubleToCurrency( (double)*p->pByte ); break; - case SbxBYREF | SbxINTEGER: + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(*p->pByte); + break; case SbxBYREF | SbxBOOL: - nRes = ImpDoubleToCurrency( (double)*p->pInteger ); break; + case SbxBYREF | SbxINTEGER: + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(*p->pInteger); + break; case SbxBYREF | SbxERROR: case SbxBYREF | SbxUSHORT: - nRes = ImpDoubleToCurrency( (double)*p->pUShort ); break; - case SbxBYREF | SbxCURRENCY: - nRes = *p->pLong64; break; + nRes = (sal_Int64)CURRENCY_FACTOR * (sal_Int64)(*p->pUShort); + break; // from here on had to be tested case SbxBYREF | SbxLONG: @@ -162,23 +354,25 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; + case SbxBYREF | SbxCURRENCY: case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: aTmp.uInt64 = *p->puInt64; goto ref; ref: - aTmp.eType = SbxDataType( p->eType & 0x0FFF ); + aTmp.eType = SbxDataType( p->eType & ~SbxBYREF ); p = &aTmp; goto start; default: - SbxBase::SetError( SbxERR_CONVERSION ); nRes.SetNull(); + SbxBase::SetError( SbxERR_CONVERSION ); + nRes=0; } return nRes; } -void ImpPutCurrency( SbxValues* p, const SbxINT64 &r ) + +void ImpPutCurrency( SbxValues* p, const sal_Int64 r ) { - double dVal = ImpCurrencyToDouble( r ); SbxValues aTmp; start: switch( +p->eType ) @@ -204,21 +398,23 @@ start: // from here no longer case SbxSINGLE: - p->nSingle = (float)dVal; break; + p->nSingle = (float)( r / CURRENCY_FACTOR ); break; case SbxDATE: case SbxDOUBLE: - p->nDouble = dVal; break; - case SbxSALINT64: - p->nInt64 = ImpDoubleToSalInt64( dVal ); break; + p->nDouble = ImpCurrencyToDouble( r ); break; case SbxSALUINT64: - p->uInt64 = ImpDoubleToSalUInt64( dVal ); break; + p->uInt64 = r / CURRENCY_FACTOR; break; + case SbxSALINT64: + p->nInt64 = r / CURRENCY_FACTOR; break; + case SbxCURRENCY: - p->nLong64 = r; break; + p->nInt64 = r; break; + case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: { SbxDecimal* pDec = ImpCreateDecimal( p ); - if( !pDec->setDouble( dVal ) ) + if( !pDec->setDouble( ImpCurrencyToDouble( r ) / CURRENCY_FACTOR ) ) SbxBase::SetError( SbxERR_OVERFLOW ); break; } @@ -226,7 +422,7 @@ start: case SbxSTRING: case SbxLPSTR: if( !p->pOUString ) - p->pOUString = new ::rtl::OUString; + p->pOUString = new rtl::OUString; *p->pOUString = ImpCurrencyToString( r ); break; @@ -240,158 +436,100 @@ start: break; } case SbxBYREF | SbxCHAR: - if( dVal > SbxMAXCHAR ) + { + sal_Int64 val = r / CURRENCY_FACTOR; + if( val > SbxMAXCHAR ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMAXCHAR; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMAXCHAR; } - else if( dVal < SbxMINCHAR ) + else if( val < SbxMINCHAR ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMINCHAR; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMINCHAR; } - *p->pChar = (xub_Unicode) dVal; break; + *p->pChar = (sal_Unicode) val; break; + } case SbxBYREF | SbxBYTE: - if( dVal > SbxMAXBYTE ) + { + sal_Int64 val = r / CURRENCY_FACTOR; + if( val > SbxMAXBYTE ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMAXBYTE; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMAXBYTE; } - else if( dVal < 0 ) + else if( val < 0 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = 0; + SbxBase::SetError( SbxERR_OVERFLOW ); val = 0; } - *p->pByte = (BYTE) dVal; break; + *p->pByte = (BYTE) val; break; + } case SbxBYREF | SbxINTEGER: case SbxBYREF | SbxBOOL: - if( dVal > SbxMAXINT ) + { + sal_Int64 val = r / CURRENCY_FACTOR; + if( r > SbxMAXINT ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMAXINT; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMAXINT; } - else if( dVal < SbxMININT ) + else if( r < SbxMININT ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMININT; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMININT; } - *p->pInteger = (INT16) dVal; break; + *p->pInteger = (INT16) r; break; + } case SbxBYREF | SbxERROR: case SbxBYREF | SbxUSHORT: - if( dVal > SbxMAXUINT ) + { + sal_Int64 val = r / CURRENCY_FACTOR; + if( val > SbxMAXUINT ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMAXUINT; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMAXUINT; } - else if( dVal < 0 ) + else if( val < 0 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = 0; + SbxBase::SetError( SbxERR_OVERFLOW ); val = 0; } - *p->pUShort = (UINT16) dVal; break; + *p->pUShort = (UINT16) val; break; + } case SbxBYREF | SbxLONG: - if( dVal > SbxMAXLNG ) + { + sal_Int64 val = r / CURRENCY_FACTOR; + if( val > SbxMAXLNG ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMAXLNG; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMAXLNG; } - else if( dVal < SbxMINLNG ) + else if( val < SbxMINLNG ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMINLNG; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMINLNG; } - *p->pLong = (INT32) dVal; break; + *p->pLong = (INT32) val; break; + } case SbxBYREF | SbxULONG: - if( dVal > SbxMAXULNG ) + { + sal_Int64 val = r / CURRENCY_FACTOR; + if( val > SbxMAXULNG ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = SbxMAXULNG; + SbxBase::SetError( SbxERR_OVERFLOW ); val = SbxMAXULNG; } - else if( dVal < 0 ) + else if( val < 0 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); dVal = 0; + SbxBase::SetError( SbxERR_OVERFLOW ); val = 0; } - *p->pULong = (UINT32) dVal; break; + *p->pULong = (UINT32) val; + break; + } + case SbxBYREF | SbxCURRENCY: + *p->pnInt64 = r; break; case SbxBYREF | SbxSALINT64: - *p->pnInt64 = ImpDoubleToSalInt64( dVal ); break; + *p->pnInt64 = r / CURRENCY_FACTOR; break; case SbxBYREF | SbxSALUINT64: - *p->puInt64 = ImpDoubleToSalUInt64( dVal ); break; + *p->puInt64 = (sal_uInt64)r / CURRENCY_FACTOR; break; case SbxBYREF | SbxSINGLE: - *p->pSingle = (float) dVal; break; + p->nSingle = (float)( r / CURRENCY_FACTOR ); break; case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: - *p->pDouble = (double) dVal; break; - case SbxBYREF | SbxCURRENCY: - *p->pLong64 = r; break; - + *p->pDouble = ImpCurrencyToDouble( r ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); } } -// help functions for the conversion - -static ::rtl::OUString ImpCurrencyToString( const SbxINT64 &r ) -{ - BigInt a10000 = 10000; - - //return GetpApp()->GetAppInternational().GetCurr( BigInt( r ), 4 ); - BigInt aInt( r ); - aInt.Abs(); - BigInt aFrac = aInt; - aInt /= a10000; - aFrac %= a10000; - aFrac += a10000; - - ::rtl::OUString aString; - if( r.nHigh < 0 ) - aString = ::rtl::OUString( (sal_Unicode)'-' ); - aString += aInt.GetString(); - aString += ::rtl::OUString( (sal_Unicode)'.' ); - aString += aFrac.GetString().GetBuffer()+1; - return aString; -} - -static SbxINT64 ImpStringToCurrency( const ::rtl::OUString &r ) -{ - int nDec = 4; - String aStr; - const sal_Unicode* p = r.getStr(); - - if( *p == '-' ) - aStr += *p++; - - while( *p >= '0' && *p <= '9' ) { - aStr += *p++; - if( *p == ',' ) - p++; - } - - if( *p == '.' ) { - p++; - while( nDec && *p >= '0' && *p <= '9' ) { - aStr += *p++; - nDec--; - } - } - while( nDec ) { - aStr += '0'; - nDec--; - } - - BigInt aBig( aStr ); - SbxINT64 nRes; - aBig.INT64( &nRes ); - return nRes; -} - -double ImpINT64ToDouble( const SbxINT64 &r ) -{ return (double)r.nHigh*(double)4294967296.0 + (double)r.nLow; } - -SbxINT64 ImpDoubleToINT64( double d ) -{ - SbxINT64 nRes; - nRes.Set( d ); - return nRes; -} - -double ImpUINT64ToDouble( const SbxUINT64 &r ) -{ return (double)r.nHigh*(double)4294967296.0 + (double)r.nLow; } - -SbxUINT64 ImpDoubleToUINT64( double d ) -{ - SbxUINT64 nRes; - nRes.Set( d ); - return nRes; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/source/sbx/sbxdate.cxx b/basic/source/sbx/sbxdate.cxx index 054373ac9113..ee4c18996846 100644 --- a/basic/source/sbx/sbxdate.cxx +++ b/basic/source/sbx/sbxdate.cxx @@ -67,12 +67,8 @@ double ImpGetDate( const SbxValues* p ) case SbxDATE: case SbxDOUBLE: nRes = p->nDouble; break; - case SbxULONG64: - nRes = ImpUINT64ToDouble( p->nULong64 ); break; - case SbxLONG64: - nRes = ImpINT64ToDouble( p->nLong64 ); break; case SbxCURRENCY: - nRes = ImpCurrencyToDouble( p->nLong64 ); break; + nRes = ImpCurrencyToDouble( p->nInt64 ); break; case SbxSALINT64: nRes = static_cast< double >(p->nInt64); break; case SbxSALUINT64: @@ -178,12 +174,8 @@ double ImpGetDate( const SbxValues* p ) case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: nRes = *p->pDouble; break; - case SbxBYREF | SbxULONG64: - nRes = ImpUINT64ToDouble( *p->pULong64 ); break; - case SbxBYREF | SbxLONG64: - nRes = ImpINT64ToDouble( *p->pLong64 ); break; case SbxBYREF | SbxCURRENCY: - nRes = ImpCurrencyToDouble( *p->pLong64 ); break; + nRes = ImpCurrencyToDouble( *p->pnInt64 ); break; case SbxBYREF | SbxSALINT64: nRes = static_cast< double >(*p->pnInt64); break; case SbxBYREF | SbxSALUINT64: @@ -223,11 +215,7 @@ start: aTmp.pUShort = &p->nUShort; goto direct; case SbxSINGLE: aTmp.pSingle = &p->nSingle; goto direct; - case SbxULONG64: - aTmp.pULong64 = &p->nULong64; goto direct; - case SbxLONG64: case SbxCURRENCY: - aTmp.pLong64 = &p->nLong64; goto direct; case SbxSALINT64: aTmp.pnInt64 = &p->nInt64; goto direct; case SbxSALUINT64: @@ -406,7 +394,7 @@ start: { SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR; } - *p->pLong64 = ImpDoubleToCurrency( n ); break; + *p->pnInt64 = ImpDoubleToCurrency( n ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); diff --git a/basic/source/sbx/sbxdbl.cxx b/basic/source/sbx/sbxdbl.cxx index f0fe163a7a50..570da2cf0626 100644 --- a/basic/source/sbx/sbxdbl.cxx +++ b/basic/source/sbx/sbxdbl.cxx @@ -62,7 +62,7 @@ double ImpGetDouble( const SbxValues* p ) case SbxDOUBLE: nRes = p->nDouble; break; case SbxCURRENCY: - nRes = ImpCurrencyToDouble( p->nLong64 ); break; + nRes = ImpCurrencyToDouble( p->nInt64 ); break; case SbxSALINT64: nRes = static_cast< double >(p->nInt64); break; case SbxSALUINT64: @@ -129,7 +129,7 @@ double ImpGetDouble( const SbxValues* p ) case SbxBYREF | SbxDOUBLE: nRes = *p->pDouble; break; case SbxBYREF | SbxCURRENCY: - nRes = ImpCurrencyToDouble( *p->pLong64 ); break; + nRes = ImpCurrencyToDouble( *p->pnInt64 ); break; case SbxBYREF | SbxSALINT64: nRes = static_cast< double >(*p->pnInt64); break; case SbxBYREF | SbxSALUINT64: @@ -156,7 +156,6 @@ start: case SbxBOOL: aTmp.pInteger = &p->nInteger; goto direct; case SbxLONG: - case SbxCURRENCY: aTmp.pLong = &p->nLong; goto direct; case SbxULONG: aTmp.pULong = &p->nULong; goto direct; @@ -177,6 +176,18 @@ start: aTmp.eType = SbxDataType( p->eType | SbxBYREF ); p = &aTmp; goto start; + case SbxCURRENCY: + if( n > SbxMAXCURR ) + { + SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCURR; + } + else if( n < SbxMINCURR ) + { + SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR; + } + p->nInt64 = ImpDoubleToCurrency( n ); + break; + // from here on no longer case SbxSALINT64: p->nInt64 = ImpDoubleToSalInt64( n ); break; @@ -298,7 +309,7 @@ start: { SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR; } - *p->pLong64 = ImpDoubleToCurrency( n ); break; + *p->pnInt64 = ImpDoubleToCurrency( n ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); diff --git a/basic/source/sbx/sbxdec.cxx b/basic/source/sbx/sbxdec.cxx index 8dcf1d44df61..3841a2b3660d 100644 --- a/basic/source/sbx/sbxdec.cxx +++ b/basic/source/sbx/sbxdec.cxx @@ -36,14 +36,11 @@ #include <com/sun/star/bridge/oleautomation/Decimal.hpp> -// int GnDecCounter = 0; - // Implementation SbxDecimal SbxDecimal::SbxDecimal( void ) { setInt( 0 ); mnRefCount = 0; - // GnDecCounter++; } SbxDecimal::SbxDecimal( const SbxDecimal& rDec ) @@ -54,7 +51,6 @@ SbxDecimal::SbxDecimal( const SbxDecimal& rDec ) (void)rDec; #endif mnRefCount = 0; - // GnDecCounter++; } SbxDecimal::SbxDecimal @@ -494,38 +490,32 @@ start: if( !pnDecRes->setSingle( p->nSingle ) ) SbxBase::SetError( SbxERR_OVERFLOW ); break; + case SbxCURRENCY: + { + if( !pnDecRes->setDouble( ImpCurrencyToDouble( p->nInt64 ) ) ) + SbxBase::SetError( SbxERR_OVERFLOW ); + break; + } case SbxSALINT64: { - double d = (double)p->nInt64; - pnDecRes->setDouble( d ); + if( !pnDecRes->setDouble( (double)p->nInt64 ) ) + SbxBase::SetError( SbxERR_OVERFLOW ); break; } case SbxSALUINT64: { - double d = ImpSalUInt64ToDouble( p->uInt64 ); - pnDecRes->setDouble( d ); + if( !pnDecRes->setDouble( (double)p->uInt64 ) ) + SbxBase::SetError( SbxERR_OVERFLOW ); break; } case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: - case SbxCURRENCY: - { - double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else - dVal = p->nDouble; - + { + double dVal = p->nDouble; if( !pnDecRes->setDouble( dVal ) ) SbxBase::SetError( SbxERR_OVERFLOW ); break; - } + } case SbxLPSTR: case SbxSTRING: case SbxBYREF | SbxSTRING: @@ -564,11 +554,7 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: @@ -608,17 +594,17 @@ start: case SbxERROR: case SbxUSHORT: aTmp.pUShort = &p->nUShort; goto direct; - case SbxSALUINT64: - aTmp.puInt64 = &p->uInt64; goto direct; case SbxINTEGER: case SbxBOOL: aTmp.pInteger = &p->nInteger; goto direct; case SbxLONG: aTmp.pLong = &p->nLong; goto direct; + case SbxCURRENCY: case SbxSALINT64: aTmp.pnInt64 = &p->nInt64; goto direct; - case SbxCURRENCY: - aTmp.pLong64 = &p->nLong64; goto direct; + case SbxSALUINT64: + aTmp.puInt64 = &p->uInt64; goto direct; + direct: aTmp.eType = SbxDataType( p->eType | SbxBYREF ); p = &aTmp; goto start; @@ -630,8 +616,6 @@ start: if( pDec != p->pDecimal ) { releaseDecimalPtr( p->pDecimal ); - // if( p->pDecimal ) - // p->pDecimal->ReleaseRef(); p->pDecimal = pDec; if( pDec ) pDec->addRef(); @@ -653,20 +637,6 @@ start: p->nDouble = d; break; } - case SbxULONG64: - { - double d; - pDec->getDouble( d ); - p->nULong64 = ImpDoubleToUINT64( d ); - break; - } - case SbxLONG64: - { - double d; - pDec->getDouble( d ); - p->nLong64 = ImpDoubleToINT64( d ); - break; - } case SbxLPSTR: case SbxSTRING: @@ -731,6 +701,13 @@ start: *p->pULong = 0; } break; + case SbxBYREF | SbxCURRENCY: + double d; + if( !pDec->getDouble( d ) ) + SbxBase::SetError( SbxERR_OVERFLOW ); + pDec->getDouble( d ); + *p->pnInt64 = ImpDoubleToCurrency( d ); + break; case SbxBYREF | SbxSALINT64: { double d; @@ -755,8 +732,8 @@ start: SbxBase::SetError( SbxERR_OVERFLOW ); *p->pSingle = 0; } + *p->pSingle = (float) n; break; - // *p->pSingle = (float) n; break; case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: if( !pDec->getDouble( *p->pDouble ) ) diff --git a/basic/source/sbx/sbxint.cxx b/basic/source/sbx/sbxint.cxx index e15ece1b6d82..ec25f07a21fe 100644 --- a/basic/source/sbx/sbxint.cxx +++ b/basic/source/sbx/sbxint.cxx @@ -96,6 +96,22 @@ start: else nRes = (INT16) ImpRound( p->nSingle ); break; + case SbxCURRENCY: + { + sal_Int64 tstVal = (sal_Int64) p->nInt64 / (sal_Int64) CURRENCY_FACTOR; + + if( tstVal > SbxMAXINT ) + { + SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT; + } + else if( tstVal < SbxMININT ) + { + SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT; + } + else + nRes = (INT16) (tstVal); + break; + } case SbxSALINT64: if( p->nInt64 > SbxMAXINT ) { @@ -118,22 +134,12 @@ start: break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: - case SbxCURRENCY: case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: + { + double dVal = 0.0; + if( p->eType == SbxDECIMAL ) { - double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else if( p->eType == SbxDECIMAL ) - { - dVal = 0.0; if( p->pDecimal ) p->pDecimal->getDouble( dVal ); } @@ -151,7 +157,7 @@ start: else nRes = (INT16) ImpRound( dVal ); break; - } + } case SbxLPSTR: case SbxSTRING: case SbxBYREF | SbxSTRING: @@ -208,11 +214,7 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: @@ -249,7 +251,7 @@ start: aTmp.eType = SbxDataType( p->eType | SbxBYREF ); p = &aTmp; goto start; - // frome here no longer + // from here no tests needed case SbxINTEGER: case SbxBOOL: p->nInteger = n; break; @@ -260,14 +262,10 @@ start: case SbxDATE: case SbxDOUBLE: p->nDouble = n; break; + case SbxCURRENCY: + p->nInt64 = n * CURRENCY_FACTOR; break; case SbxSALINT64: p->nInt64 = n; break; - case SbxULONG64: - p->nULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxLONG64: - p->nLong64 = ImpDoubleToINT64( (double)n ); break; - case SbxCURRENCY: - p->nLong64 = ImpDoubleToCurrency( (double)n ); break; case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: ImpCreateDecimal( p )->setInt( n ); @@ -323,12 +321,15 @@ start: SbxBase::SetError( SbxERR_OVERFLOW ); n = 0; } *p->pULong = (UINT32) n; break; + case SbxBYREF | SbxCURRENCY: + *p->pnInt64 = n * CURRENCY_FACTOR; break; case SbxBYREF | SbxSALINT64: *p->pnInt64 = n; break; case SbxBYREF | SbxSALUINT64: if( n < 0 ) { - SbxBase::SetError( SbxERR_OVERFLOW ); *p->puInt64 = 0; + SbxBase::SetError( SbxERR_OVERFLOW ); + *p->puInt64 = 0; } else *p->puInt64 = n; @@ -338,12 +339,6 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: *p->pDouble = (double) n; break; - case SbxBYREF | SbxULONG64: - *p->pULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxBYREF | SbxLONG64: - *p->pLong64 = ImpDoubleToINT64( (double)n ); break; - case SbxBYREF | SbxCURRENCY: - *p->pLong64 = ImpDoubleToCurrency( (double)n ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); @@ -385,6 +380,7 @@ sal_uInt64 ImpDoubleToSalUInt64( double d ) return nRes; } + double ImpSalUInt64ToDouble( sal_uInt64 n ) { double d = 0.0; @@ -416,33 +412,20 @@ start: nRes = p->nInteger; break; case SbxERROR: case SbxUSHORT: - nRes = p->nUShort; break; + nRes = (sal_Int64) p->nUShort; break; case SbxLONG: - nRes = p->nLong; break; + nRes = (sal_Int64) p->nLong; break; case SbxULONG: nRes = (sal_Int64) p->nULong; break; case SbxSINGLE: - nRes = ImpDoubleToSalInt64( (double)p->nSingle ); + nRes = (sal_Int64) p->nSingle; break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: - case SbxCURRENCY: - { - double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else - dVal = p->nDouble; - - nRes = ImpDoubleToSalInt64( dVal ); + nRes = (sal_Int64) p->nDouble; break; - } + case SbxCURRENCY: + nRes = p->nInt64 / CURRENCY_FACTOR; break; case SbxSALINT64: nRes = p->nInt64; break; case SbxSALUINT64: @@ -472,7 +455,7 @@ start: if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK ) nRes = 0; else - nRes = ImpDoubleToSalInt64( d ); + nRes = (sal_Int64) d; } } break; @@ -499,10 +482,15 @@ start: nRes = *p->pLong; break; case SbxBYREF | SbxULONG: nRes = *p->pULong; break; + case SbxBYREF | SbxCURRENCY: + nRes = p->nInt64 / CURRENCY_FACTOR; break; case SbxBYREF | SbxSALINT64: nRes = *p->pnInt64; break; // from here the values has to be checked + case SbxBYREF | SbxSALUINT64: + aTmp.uInt64 = *p->puInt64; goto ref; + case SbxBYREF | SbxERROR: case SbxBYREF | SbxUSHORT: aTmp.nUShort = *p->pUShort; goto ref; @@ -511,13 +499,6 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: - case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; - case SbxBYREF | SbxSALUINT64: - aTmp.uInt64 = *p->puInt64; goto ref; ref: aTmp.eType = SbxDataType( p->eType & 0x0FFF ); p = &aTmp; goto start; @@ -543,11 +524,6 @@ start: case SbxINTEGER: case SbxBOOL: aTmp.pInteger = &p->nInteger; goto direct; - case SbxULONG64: - aTmp.pULong64 = &p->nULong64; goto direct; - case SbxLONG64: - case SbxCURRENCY: - aTmp.pLong64 = &p->nLong64; goto direct; case SbxULONG: aTmp.pULong = &p->nULong; goto direct; case SbxERROR: @@ -555,6 +531,9 @@ start: aTmp.pUShort = &p->nUShort; goto direct; case SbxLONG: aTmp.pnInt64 = &p->nInt64; goto direct; + case SbxCURRENCY: + case SbxSALINT64: + aTmp.pnInt64 = &p->nInt64; goto direct; case SbxSALUINT64: aTmp.puInt64 = &p->uInt64; goto direct; @@ -562,9 +541,6 @@ start: aTmp.eType = SbxDataType( p->eType | SbxBYREF ); p = &aTmp; goto start; - // Check not neccessary - case SbxSALINT64: - p->nInt64 = n; break; case SbxSINGLE: p->nSingle = (float) n; break; case SbxDATE: @@ -660,16 +636,7 @@ start: case SbxBYREF | SbxDOUBLE: *p->pDouble = (double) n; break; case SbxBYREF | SbxCURRENCY: - if( n > SbxMAXCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR; - } - else if( n < SbxMINCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMINCURR; - } - *p->pLong64 = ImpDoubleToCurrency( (double)n ); break; - + *p->pnInt64 = n * CURRENCY_FACTOR; break; case SbxBYREF | SbxSALINT64: *p->pnInt64 = n; break; case SbxBYREF | SbxSALUINT64: @@ -710,27 +677,16 @@ start: case SbxULONG: nRes = (sal_uInt64) p->nULong; break; case SbxSINGLE: - nRes = ImpDoubleToSalUInt64( (double)p->nSingle ); - break; + nRes = (sal_uInt64) p->nSingle; break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: - case SbxCURRENCY: { - double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else - dVal = p->nDouble; - - nRes = ImpDoubleToSalUInt64( dVal ); +//TODO overflow check + nRes = (sal_uInt64) p->nDouble; break; } + case SbxCURRENCY: + nRes = p->nInt64 * CURRENCY_FACTOR; break; case SbxSALINT64: if( p->nInt64 < 0 ) { @@ -738,6 +694,7 @@ start: } else nRes = (sal_uInt64) p->nInt64; + break; case SbxSALUINT64: nRes = p->uInt64; break; @@ -805,7 +762,7 @@ start: case SbxBYREF | SbxSALUINT64: nRes = *p->puInt64; break; - // from here the values has to be checked + // from here on the value has to be checked case SbxBYREF | SbxERROR: case SbxBYREF | SbxUSHORT: aTmp.nUShort = *p->pUShort; goto ref; @@ -814,11 +771,7 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; ref: @@ -846,11 +799,6 @@ start: case SbxINTEGER: case SbxBOOL: aTmp.pInteger = &p->nInteger; goto direct; - case SbxULONG64: - aTmp.pULong64 = &p->nULong64; goto direct; - case SbxLONG64: - case SbxCURRENCY: - aTmp.pLong64 = &p->nLong64; goto direct; case SbxULONG: aTmp.pULong = &p->nULong; goto direct; case SbxERROR: @@ -858,6 +806,7 @@ start: aTmp.pUShort = &p->nUShort; goto direct; case SbxLONG: aTmp.pnInt64 = &p->nInt64; goto direct; + case SbxCURRENCY: case SbxSALINT64: aTmp.pnInt64 = &p->nInt64; goto direct; case SbxSINGLE: @@ -939,14 +888,12 @@ start: *p->pDouble = (float)ImpSalUInt64ToDouble( n ); break; case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: + *p->pDouble = ImpSalUInt64ToDouble( n ); break; case SbxBYREF | SbxCURRENCY: - if( n > SbxMAXSALINT64 || (sal_Int64)n > SbxMAXCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR; - } - *p->pLong64 = ImpDoubleToCurrency( (double)(sal_Int64) n ); break; - + if ( n > ( SbxMAXSALINT64 / CURRENCY_FACTOR ) ) + SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXSALINT64; + *p->pnInt64 = ( sal_Int64) ( n * CURRENCY_FACTOR ); break; case SbxBYREF | SbxSALUINT64: *p->puInt64 = n; break; case SbxBYREF | SbxSALINT64: diff --git a/basic/source/sbx/sbxlng.cxx b/basic/source/sbx/sbxlng.cxx index 47ae83cb7b21..32e994520c13 100644 --- a/basic/source/sbx/sbxlng.cxx +++ b/basic/source/sbx/sbxlng.cxx @@ -75,28 +75,28 @@ start: else nRes = (INT32) ImpRound( p->nSingle ); break; - case SbxDATE: - case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: case SbxSALINT64: + nRes = p->nInt64; + break; case SbxSALUINT64: + nRes = p->uInt64; + break; case SbxCURRENCY: + { + sal_Int64 tstVal = p->nInt64 / CURRENCY_FACTOR; + nRes = (INT32) (tstVal); + if( tstVal < SbxMINLNG || SbxMAXLNG < tstVal ) SbxBase::SetError( SbxERR_OVERFLOW ); + if( SbxMAXLNG < tstVal ) nRes = SbxMAXLNG; + if( tstVal < SbxMINLNG ) nRes = SbxMINLNG; + break; + } + case SbxDATE: + case SbxDOUBLE: case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: { double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else if( p->eType == SbxSALINT64 ) - dVal = static_cast< double >(p->nInt64); - else if( p->eType == SbxSALUINT64 ) - dVal = ImpSalUInt64ToDouble( p->uInt64 ); - else if( p->eType == SbxDECIMAL ) + if( p->eType == SbxDECIMAL ) { dVal = 0.0; if( p->pDecimal ) @@ -173,15 +173,12 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; + case SbxBYREF | SbxCURRENCY: case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: aTmp.uInt64 = *p->puInt64; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: - case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; + ref: aTmp.eType = SbxDataType( p->eType & 0x0FFF ); p = &aTmp; goto start; @@ -207,11 +204,6 @@ start: case SbxINTEGER: case SbxBOOL: aTmp.pInteger = &p->nInteger; goto direct; - case SbxULONG64: - aTmp.pULong64 = &p->nULong64; goto direct; - case SbxLONG64: - case SbxCURRENCY: - aTmp.pLong64 = &p->nLong64; goto direct; case SbxULONG: aTmp.pULong = &p->nULong; goto direct; case SbxSALUINT64: @@ -231,6 +223,8 @@ start: case SbxDATE: case SbxDOUBLE: p->nDouble = n; break; + case SbxCURRENCY: + p->nInt64 = n * CURRENCY_FACTOR; break; case SbxSALINT64: p->nInt64 = n; break; case SbxDECIMAL: @@ -320,21 +314,7 @@ start: case SbxBYREF | SbxDOUBLE: *p->pDouble = (double) n; break; case SbxBYREF | SbxCURRENCY: - double d; - if( n > SbxMAXCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); d = SbxMAXCURR; - } - else if( n < SbxMINCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); d = SbxMINCURR; - } - else - { - d = n; - } - *p->pLong64 = ImpDoubleToCurrency( d ); break; - + *p->pnInt64 = (sal_Int64)n * (sal_Int64)CURRENCY_FACTOR; break; default: SbxBase::SetError( SbxERR_CONVERSION ); } diff --git a/basic/source/sbx/sbxsng.cxx b/basic/source/sbx/sbxsng.cxx index a6250bf1d570..68bdcfe58609 100644 --- a/basic/source/sbx/sbxsng.cxx +++ b/basic/source/sbx/sbxsng.cxx @@ -59,10 +59,6 @@ start: nRes = (float) p->nULong; break; case SbxSINGLE: nRes = p->nSingle; break; - case SbxSALINT64: - nRes = (float) p->nInt64; break; - case SbxSALUINT64: - nRes = (float) ImpSalUInt64ToDouble( p->uInt64 ); break; case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: if( p->pDecimal ) @@ -72,17 +68,17 @@ start: break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: case SbxCURRENCY: + case SbxSALINT64: + case SbxSALUINT64: { double dVal; if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); + dVal = ImpCurrencyToDouble( p->nInt64 ); + else if( p->eType == SbxSALINT64 ) + dVal = (float) p->nInt64; + else if( p->eType == SbxSALUINT64 ) + dVal = (float) p->uInt64; else dVal = p->nDouble; @@ -96,6 +92,7 @@ start: SbxBase::SetError( SbxERR_OVERFLOW ); nRes = static_cast< float >(SbxMINSNG); } + // tests for underflow - storing value too small for precision of single else if( dVal > 0 && dVal < SbxMAXSNG2 ) { SbxBase::SetError( SbxERR_OVERFLOW ); @@ -167,15 +164,11 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: case SbxBYREF | SbxSALINT64: - nRes = (float) *p->pnInt64; break; - case SbxBYREF | SbxSALUINT64: - nRes = (float) ImpSalUInt64ToDouble( *p->puInt64 ); break; case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; + aTmp.nInt64 = *p->pnInt64; goto ref; + case SbxBYREF | SbxSALUINT64: + aTmp.uInt64 = *p->puInt64; goto ref; ref: aTmp.eType = SbxDataType( p->eType & 0x0FFF ); p = &aTmp; goto start; @@ -206,11 +199,7 @@ start: case SbxERROR: case SbxUSHORT: aTmp.pUShort = &p->nUShort; goto direct; - case SbxULONG64: - aTmp.pULong64 = &p->nULong64; goto direct; - case SbxLONG64: case SbxCURRENCY: - aTmp.pLong64 = &p->nLong64; goto direct; case SbxSALINT64: aTmp.pnInt64 = &p->nInt64; goto direct; case SbxSALUINT64: @@ -334,9 +323,9 @@ start: case SbxBYREF | SbxDOUBLE: *p->pDouble = (double) n; break; case SbxBYREF | SbxSALINT64: - *p->pnInt64 = ImpDoubleToSalInt64( (double) n ); break; + *p->pnInt64 = (sal_Int64)n; break; case SbxBYREF | SbxSALUINT64: - *p->puInt64 = ImpDoubleToSalUInt64( (double) n ); break; + *p->puInt64 = (sal_uInt64)n; break; case SbxBYREF | SbxCURRENCY: double d; if( n > SbxMAXCURR ) @@ -351,7 +340,7 @@ start: { d = n; } - *p->pLong64 = ImpDoubleToCurrency( n ); break; + *p->pnInt64 = ImpDoubleToCurrency( d ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); diff --git a/basic/source/sbx/sbxstr.cxx b/basic/source/sbx/sbxstr.cxx index d4d144e0f2bc..1b634d57d66c 100644 --- a/basic/source/sbx/sbxstr.cxx +++ b/basic/source/sbx/sbxstr.cxx @@ -69,7 +69,7 @@ case SbxDOUBLE: ImpPutDouble( &aTmp, p->nDouble ); break; case SbxCURRENCY: - ImpPutCurrency( &aTmp, p->nLong64 ); break; + ImpPutCurrency( &aTmp, p->nInt64 ); break; case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: ImpPutDecimal( &aTmp, p->pDecimal ); break; @@ -127,7 +127,7 @@ case SbxBYREF | SbxDOUBLE: ImpPutDouble( &aTmp, *p->pDouble ); break; case SbxBYREF | SbxCURRENCY: - ImpPutCurrency( &aTmp, *p->pLong64 ); break; + ImpPutCurrency( &aTmp, *p->pnInt64 ); break; case SbxBYREF | SbxSALINT64: ImpPutInt64( &aTmp, *p->pnInt64 ); break; case SbxBYREF | SbxSALUINT64: @@ -148,9 +148,9 @@ XubString aRes; aTmp.eType = SbxSTRING; if( p->eType == SbxDOUBLE ) - ImpPutDouble( &aTmp, p->nDouble, /*bCoreString=*/TRUE ); + ImpPutDouble( &aTmp, p->nDouble, TRUE ); // true = bCoreString else - ImpPutDouble( &aTmp, *p->pDouble, /*bCoreString=*/TRUE ); + ImpPutDouble( &aTmp, *p->pDouble, TRUE ); // true = bCoreString return aRes; } else @@ -188,8 +188,8 @@ void ImpPutString( SbxValues* p, const ::rtl::OUString* n ) p->nDouble = ImpGetDate( &aTmp ); break; case SbxDOUBLE: p->nDouble = ImpGetDouble( &aTmp ); break; - case SbxULONG64: - p->nLong64 = ImpGetCurrency( &aTmp ); break; + case SbxCURRENCY: + p->nInt64 = ImpGetCurrency( &aTmp ); break; case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: releaseDecimalPtr( p->pDecimal ); @@ -244,13 +244,18 @@ void ImpPutString( SbxValues* p, const ::rtl::OUString* n ) case SbxBYREF | SbxDOUBLE: *p->pDouble = ImpGetDouble( p ); break; case SbxBYREF | SbxCURRENCY: - *p->pLong64 = ImpGetCurrency( p ); break; + *p->pnInt64 = ImpGetCurrency( p ); break; + case SbxBYREF | SbxSALINT64: + *p->pnInt64 = ImpGetInt64( p ); break; + case SbxBYREF | SbxSALUINT64: + *p->puInt64 = ImpGetUInt64( p ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); } delete pTmp; } + // Convert string to an array of bytes, preserving unicode (2bytes per character) SbxArray* StringToByteArray(const ::rtl::OUString& rStr) { @@ -312,4 +317,5 @@ SbxArray* StringToByteArray(const ::rtl::OUString& rStr) return aStrBuf.makeStringAndClear(); } + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/source/sbx/sbxuint.cxx b/basic/source/sbx/sbxuint.cxx index e20abbb3c0c0..3115fd850f89 100644 --- a/basic/source/sbx/sbxuint.cxx +++ b/basic/source/sbx/sbxuint.cxx @@ -81,6 +81,18 @@ start: else nRes = (UINT16) p->nULong; break; + case SbxCURRENCY: + if( p->nInt64 / CURRENCY_FACTOR > SbxMAXUINT ) + { + SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT; + } + else if( p->nInt64 < 0 ) + { + SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0; + } + else + nRes = (UINT16) (p->nInt64 / CURRENCY_FACTOR); + break; case SbxSALINT64: if( p->nInt64 > SbxMAXUINT ) { @@ -115,20 +127,11 @@ start: break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: - case SbxCURRENCY: case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: { double dVal; - if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); - else if( p->eType == SbxDECIMAL ) + if( p->eType == SbxDECIMAL ) { dVal = 0.0; if( p->pDecimal ) @@ -205,11 +208,7 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: @@ -243,16 +242,12 @@ start: case SbxDATE: case SbxDOUBLE: p->nDouble = n; break; + case SbxCURRENCY: + p->nInt64 = n * CURRENCY_FACTOR; break; case SbxSALINT64: p->nInt64 = n; break; case SbxSALUINT64: p->uInt64 = n; break; - case SbxULONG64: - p->nULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxLONG64: - p->nLong64 = ImpDoubleToINT64( (double)n ); break; - case SbxCURRENCY: - p->nLong64 = ImpDoubleToCurrency( (double)n ); break; case SbxDECIMAL: case SbxBYREF | SbxDECIMAL: ImpCreateDecimal( p )->setUInt( n ); @@ -314,16 +309,12 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: *p->pDouble = n; break; + case SbxBYREF | SbxCURRENCY: + *p->pnInt64 = n * CURRENCY_FACTOR; break; case SbxBYREF | SbxSALINT64: *p->pnInt64 = n; break; case SbxBYREF | SbxSALUINT64: *p->puInt64 = n; break; - case SbxBYREF | SbxULONG64: - *p->pULong64 = ImpDoubleToUINT64( (double)n ); break; - case SbxBYREF | SbxLONG64: - *p->pLong64 = ImpDoubleToINT64( (double)n ); break; - case SbxBYREF | SbxCURRENCY: - *p->pLong64 = ImpDoubleToCurrency( (double)n ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); diff --git a/basic/source/sbx/sbxulng.cxx b/basic/source/sbx/sbxulng.cxx index cfaeee07d4b0..10c1dbd4f8d7 100644 --- a/basic/source/sbx/sbxulng.cxx +++ b/basic/source/sbx/sbxulng.cxx @@ -85,8 +85,6 @@ start: break; case SbxDATE: case SbxDOUBLE: - case SbxLONG64: - case SbxULONG64: case SbxSALINT64: case SbxSALUINT64: case SbxCURRENCY: @@ -95,11 +93,7 @@ start: { double dVal; if( p->eType == SbxCURRENCY ) - dVal = ImpCurrencyToDouble( p->nLong64 ); - else if( p->eType == SbxLONG64 ) - dVal = ImpINT64ToDouble( p->nLong64 ); - else if( p->eType == SbxULONG64 ) - dVal = ImpUINT64ToDouble( p->nULong64 ); + dVal = ImpCurrencyToDouble( p->nInt64 ); else if( p->eType == SbxSALINT64 ) dVal = static_cast< double >(p->nInt64); else if( p->eType == SbxSALUINT64 ) @@ -181,15 +175,11 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: aTmp.nDouble = *p->pDouble; goto ref; + case SbxBYREF | SbxCURRENCY: case SbxBYREF | SbxSALINT64: aTmp.nInt64 = *p->pnInt64; goto ref; case SbxBYREF | SbxSALUINT64: aTmp.uInt64 = *p->puInt64; goto ref; - case SbxBYREF | SbxULONG64: - aTmp.nULong64 = *p->pULong64; goto ref; - case SbxBYREF | SbxLONG64: - case SbxBYREF | SbxCURRENCY: - aTmp.nLong64 = *p->pLong64; goto ref; ref: aTmp.eType = SbxDataType( p->eType & 0x0FFF ); p = &aTmp; goto start; @@ -213,8 +203,9 @@ start: case SbxDATE: case SbxDOUBLE: p->nDouble = n; break; + case SbxCURRENCY: case SbxSALINT64: - p->nInt64 = n; break; + aTmp.pnInt64 = &p->nInt64; goto direct; case SbxSALUINT64: p->uInt64 = n; break; case SbxDECIMAL: @@ -235,11 +226,6 @@ start: case SbxERROR: case SbxUSHORT: aTmp.pUShort = &p->nUShort; goto direct; - case SbxULONG64: - aTmp.pULong64 = &p->nULong64; goto direct; - case SbxLONG64: - case SbxCURRENCY: - aTmp.pLong64 = &p->nLong64; goto direct; direct: aTmp.eType = SbxDataType( p->eType | SbxBYREF ); p = &aTmp; goto start; @@ -299,21 +285,12 @@ start: case SbxBYREF | SbxDATE: case SbxBYREF | SbxDOUBLE: *p->pDouble = n; break; + case SbxBYREF | SbxCURRENCY: + *p->pnInt64 = n * CURRENCY_FACTOR; break; case SbxBYREF | SbxSALINT64: *p->pnInt64 = n; break; case SbxBYREF | SbxSALUINT64: *p->puInt64 = n; break; - case SbxBYREF | SbxCURRENCY: - double d; - if( n > SbxMAXCURR ) - { - SbxBase::SetError( SbxERR_OVERFLOW ); d = SbxMAXCURR; - } - else - { - d = n; - } - *p->pLong64 = ImpDoubleToCurrency( n ); break; default: SbxBase::SetError( SbxERR_CONVERSION ); diff --git a/basic/source/sbx/sbxvalue.cxx b/basic/source/sbx/sbxvalue.cxx index d49aa0f495f2..df4fe7b4a753 100644 --- a/basic/source/sbx/sbxvalue.cxx +++ b/basic/source/sbx/sbxvalue.cxx @@ -29,154 +29,18 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_basic.hxx" -#define _TLBIGINT_INT64 -#include <tools/bigint.hxx> +#include <math.h> #include <tools/stream.hxx> #include <basic/sbx.hxx> #include "sbxconv.hxx" -#include <math.h> #include "runtime.hxx" TYPEINIT1(SbxValue,SbxBase) -/////////////////////////// SbxINT64 ///////////////////////////////////// -SbxINT64 &SbxINT64::operator -= ( const SbxINT64 &r ) -{ - BigInt b( *this ); - b -= BigInt( r ); - b.INT64( this ); - return *this; -} -SbxINT64 &SbxINT64::operator += ( const SbxINT64 &r ) -{ - BigInt b( *this ); - b += BigInt( r ); - b.INT64( this ); - return *this; -} -SbxINT64 &SbxINT64::operator *= ( const SbxINT64 &r ) -{ - BigInt b( *this ); - b *= BigInt( r ); - b.INT64( this ); - return *this; -} -SbxINT64 &SbxINT64::operator %= ( const SbxINT64 &r ) -{ - BigInt b( *this ); - b %= BigInt( r ); - b.INT64( this ); - return *this; -} -SbxINT64 &SbxINT64::operator /= ( const SbxINT64 &r ) -{ - BigInt b( *this ); - b /= BigInt( r ); - b.INT64( this ); - return *this; -} -SbxINT64 &SbxINT64::operator &= ( const SbxINT64 &r ) -{ - nHigh &= r.nHigh; - nLow &= r.nLow; - return *this; -} -SbxINT64 &SbxINT64::operator |= ( const SbxINT64 &r ) -{ - nHigh |= r.nHigh; - nLow |= r.nLow; - return *this; -} -SbxINT64 &SbxINT64::operator ^= ( const SbxINT64 &r ) -{ - nHigh ^= r.nHigh; - nLow ^= r.nLow; - return *this; -} - -SbxINT64 operator - ( const SbxINT64 &l, const SbxINT64 &r ) -{ - SbxINT64 a(l); - a -= r; - return a; -} -SbxINT64 operator + ( const SbxINT64 &l, const SbxINT64 &r ) -{ - SbxINT64 a(l); - a += r; - return a; -} -SbxINT64 operator / ( const SbxINT64 &l, const SbxINT64 &r ) -{ - SbxINT64 a(l); - a /= r; - return a; -} -SbxINT64 operator % ( const SbxINT64 &l, const SbxINT64 &r ) -{ - SbxINT64 a(l); - a %= r; - return a; -} -SbxINT64 operator * ( const SbxINT64 &l, const SbxINT64 &r ) -{ - SbxINT64 a(l); - a *= r; - return a; -} -SbxINT64 operator & ( const SbxINT64 &l, const SbxINT64 &r ) -{ - SbxINT64 a; - a.nHigh = r.nHigh & l.nHigh; - a.nLow = r.nLow & l.nLow; - return a; -} -SbxINT64 operator | ( const SbxINT64 &l, const SbxINT64 &r ) -{ - SbxINT64 a; - a.nHigh = r.nHigh | l.nHigh; - a.nLow = r.nLow | l.nLow; - return a; -} -SbxINT64 operator ^ ( const SbxINT64 &r, const SbxINT64 &l ) -{ - SbxINT64 a; - a.nHigh = r.nHigh ^ l.nHigh; - a.nLow = r.nLow ^ l.nLow; - return a; -} - -SbxINT64 operator - ( const SbxINT64 &r ) -{ - SbxINT64 a( r ); - a.CHS(); - return a; -} -SbxINT64 operator ~ ( const SbxINT64 &r ) -{ - SbxINT64 a; - a.nHigh = ~r.nHigh; - a.nLow = ~r.nLow; - return a; -} - -SbxUINT64 &SbxUINT64::operator %= ( const SbxUINT64 &r ) -{ - BigInt b( *this ); - b %= BigInt( r ); - b.UINT64( this ); - return *this; -} -SbxUINT64 &SbxUINT64::operator /= ( const SbxUINT64 &r ) -{ - BigInt b( *this ); - b /= BigInt( r ); - b.UINT64( this ); - return *this; -} -/////////////////////////// Error processing ///////////////////////////// +///////////////////////////// error handling ////////////////////////////// +// bring back ?? was ever in ?? currently ifdef out ? #ifdef _USED // STILL Reverse ENGINEERING! @@ -204,7 +68,6 @@ int matherr( struct _exception* p ) #endif // _USED - ///////////////////////////// constructors ////////////////////////////// SbxValue::SbxValue() : SbxBase() @@ -225,9 +88,9 @@ SbxValue::SbxValue( SbxDataType t, void* p ) : SbxBase() switch( t & 0x0FFF ) { case SbxINTEGER: n |= SbxBYREF; aData.pInteger = (INT16*) p; break; - case SbxULONG64: n |= SbxBYREF; aData.pULong64 = (SbxUINT64*) p; break; - case SbxLONG64: - case SbxCURRENCY: n |= SbxBYREF; aData.pLong64 = (SbxINT64*) p; break; + case SbxSALUINT64: n |= SbxBYREF; aData.puInt64 = (sal_uInt64*) p; break; + case SbxSALINT64: + case SbxCURRENCY: n |= SbxBYREF; aData.pnInt64 = (sal_Int64*) p; break; case SbxLONG: n |= SbxBYREF; aData.pLong = (INT32*) p; break; case SbxSINGLE: n |= SbxBYREF; aData.pSingle = (float*) p; break; case SbxDATE: @@ -237,7 +100,7 @@ SbxValue::SbxValue( SbxDataType t, void* p ) : SbxBase() case SbxUSHORT: case SbxBOOL: n |= SbxBYREF; aData.pUShort = (UINT16*) p; break; case SbxULONG: n |= SbxBYREF; aData.pULong = (UINT32*) p; break; - case SbxCHAR: n |= SbxBYREF; aData.pChar = (xub_Unicode*) p; break; + case SbxCHAR: n |= SbxBYREF; aData.pChar = (sal_Unicode*) p; break; case SbxBYTE: n |= SbxBYREF; aData.pByte = (BYTE*) p; break; case SbxINT: n |= SbxBYREF; aData.pInt = (int*) p; break; case SbxOBJECT: @@ -534,7 +397,7 @@ BOOL SbxValue::Get( SbxValues& rRes ) const case SbxSALUINT64: rRes.uInt64 = ImpGetUInt64( &p->aData ); break; case SbxSINGLE: rRes.nSingle = ImpGetSingle( &p->aData ); break; case SbxDOUBLE: rRes.nDouble = ImpGetDouble( &p->aData ); break; - case SbxCURRENCY:rRes.nLong64 = ImpGetCurrency( &p->aData ); break; + case SbxCURRENCY:rRes.nInt64 = ImpGetCurrency( &p->aData ); break; case SbxDECIMAL: rRes.pDecimal = ImpGetDecimal( &p->aData ); break; case SbxDATE: rRes.nDouble = ImpGetDate( &p->aData ); break; case SbxBOOL: @@ -665,25 +528,23 @@ BOOL SbxValue::GetBool() const #define GET( g, e, t, m ) \ t SbxValue::g() const { SbxValues aRes(e); Get( aRes ); return aRes.m; } -GET( GetByte, SbxBYTE, BYTE, nByte ) -GET( GetChar, SbxCHAR, xub_Unicode, nChar ) -GET( GetCurrency, SbxCURRENCY, SbxINT64, nLong64 ) -GET( GetDate, SbxDATE, double, nDouble ) -GET( GetData, SbxDATAOBJECT, void*, pData ) -GET( GetDouble, SbxDOUBLE, double, nDouble ) -GET( GetErr, SbxERROR, UINT16, nUShort ) -GET( GetInt, SbxINT, int, nInt ) -GET( GetInteger, SbxINTEGER, INT16, nInteger ) -GET( GetLong, SbxLONG, INT32, nLong ) -GET( GetLong64, SbxLONG64, SbxINT64, nLong64 ) -GET( GetObject, SbxOBJECT, SbxBase*, pObj ) -GET( GetSingle, SbxSINGLE, float, nSingle ) -GET( GetULong, SbxULONG, UINT32, nULong ) -GET( GetULong64, SbxULONG64, SbxUINT64, nULong64 ) -GET( GetUShort, SbxUSHORT, UINT16, nUShort ) -GET( GetInt64, SbxSALINT64, sal_Int64, nInt64 ) -GET( GetUInt64, SbxSALUINT64, sal_uInt64, uInt64 ) -GET( GetDecimal, SbxDECIMAL, SbxDecimal*, pDecimal ) +GET( GetByte, SbxBYTE, BYTE, nByte ) +GET( GetChar, SbxCHAR, xub_Unicode, nChar ) +GET( GetCurrency, SbxCURRENCY, sal_Int64, nInt64 ) +GET( GetDate, SbxDATE, double, nDouble ) +GET( GetData, SbxDATAOBJECT, void*, pData ) +GET( GetDouble, SbxDOUBLE, double, nDouble ) +GET( GetErr, SbxERROR, UINT16, nUShort ) +GET( GetInt, SbxINT, int, nInt ) +GET( GetInteger, SbxINTEGER, INT16, nInteger ) +GET( GetLong, SbxLONG, INT32, nLong ) +GET( GetObject, SbxOBJECT, SbxBase*, pObj ) +GET( GetSingle, SbxSINGLE, float, nSingle ) +GET( GetULong, SbxULONG, UINT32, nULong ) +GET( GetUShort, SbxUSHORT, UINT16, nUShort ) +GET( GetInt64, SbxSALINT64, sal_Int64, nInt64 ) +GET( GetUInt64, SbxSALUINT64, sal_uInt64, uInt64 ) +GET( GetDecimal, SbxDECIMAL, SbxDecimal*, pDecimal ) //////////////////////////// Write data ///////////////////////////// @@ -721,7 +582,7 @@ BOOL SbxValue::Put( const SbxValues& rVal ) case SbxSALUINT64: ImpPutUInt64( &p->aData, rVal.uInt64 ); break; case SbxSINGLE: ImpPutSingle( &p->aData, rVal.nSingle ); break; case SbxDOUBLE: ImpPutDouble( &p->aData, rVal.nDouble ); break; - case SbxCURRENCY: ImpPutCurrency( &p->aData, rVal.nLong64 ); break; + case SbxCURRENCY: ImpPutCurrency( &p->aData, rVal.nInt64 ); break; case SbxDECIMAL: ImpPutDecimal( &p->aData, rVal.pDecimal ); break; case SbxDATE: ImpPutDate( &p->aData, rVal.nDouble ); break; case SbxBOOL: ImpPutBool( &p->aData, rVal.nInteger ); break; @@ -935,8 +796,8 @@ BOOL SbxValue::p( t n ) \ { SbxValues aRes(e); aRes.m = n; Put( aRes ); return BOOL( !IsError() ); } PUT( PutByte, SbxBYTE, BYTE, nByte ) -PUT( PutChar, SbxCHAR, xub_Unicode, nChar ) -PUT( PutCurrency, SbxCURRENCY, const SbxINT64&, nLong64 ) +PUT( PutChar, SbxCHAR, sal_Unicode, nChar ) +PUT( PutCurrency, SbxCURRENCY, const sal_Int64&, nInt64 ) PUT( PutDate, SbxDATE, double, nDouble ) PUT( PutData, SbxDATAOBJECT, void*, pData ) PUT( PutDouble, SbxDOUBLE, double, nDouble ) @@ -944,11 +805,9 @@ PUT( PutErr, SbxERROR, UINT16, nUShort ) PUT( PutInt, SbxINT, int, nInt ) PUT( PutInteger, SbxINTEGER, INT16, nInteger ) PUT( PutLong, SbxLONG, INT32, nLong ) -PUT( PutLong64, SbxLONG64, const SbxINT64&, nLong64 ) PUT( PutObject, SbxOBJECT, SbxBase*, pObj ) PUT( PutSingle, SbxSINGLE, float, nSingle ) PUT( PutULong, SbxULONG, UINT32, nULong ) -PUT( PutULong64, SbxULONG64, const SbxUINT64&, nULong64 ) PUT( PutUShort, SbxUSHORT, UINT16, nUShort ) PUT( PutInt64, SbxSALINT64, sal_Int64, nInt64 ) PUT( PutUInt64, SbxSALUINT64, sal_uInt64, uInt64 ) @@ -1183,34 +1042,24 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) else if( eOpType == SbxSTRING && rOp.IsFixed() ) { // Numeric: there is no String allowed on the right side SetError( SbxERR_CONVERSION ); + // falls all the way out } else if( ( eOp >= SbxIDIV && eOp <= SbxNOT ) || eOp == SbxMOD ) { if( GetType() == eOpType ) { - if( GetType() == SbxULONG64 - || GetType() == SbxLONG64 - || GetType() == SbxCURRENCY - || GetType() == SbxULONG ) + if( GetType() == SbxSALUINT64 || GetType() == SbxSALINT64 + || GetType() == SbxCURRENCY || GetType() == SbxULONG ) aL.eType = aR.eType = GetType(); -// else if( GetType() == SbxDouble || GetType() == SbxSingle ) -// aL.eType = aR.eType = SbxLONG64; else if ( bVBAInterop && eOpType == SbxBOOL ) aL.eType = aR.eType = SbxBOOL; else aL.eType = aR.eType = SbxLONG; } - else if( GetType() == SbxCURRENCY || eOpType == SbxCURRENCY - || GetType() == SbxULONG64 || eOpType == SbxULONG64 - || GetType() == SbxLONG64 || eOpType == SbxLONG64 ) - aL.eType = aR.eType = SbxLONG64; -// else if( GetType() == SbxDouble || rOP.GetType() == SbxDouble -// || GetType() == SbxSingle || rOP.GetType() == SbxSingle ) -// aL.eType = aR.eType = SbxLONG64; else aL.eType = aR.eType = SbxLONG; - if( rOp.Get( aR ) ) + if( rOp.Get( aR ) ) // re-do Get after type assigns above { if( rOp.GetType() == SbxEMPTY ) { @@ -1221,13 +1070,17 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) { case SbxIDIV: if( aL.eType == SbxCURRENCY ) - aL.eType = SbxLONG64; - if( aL.eType == SbxLONG64 ) - if( !aR.nLong64 ) SetError( SbxERR_ZERODIV ); - else aL.nLong64 /= aR.nLong64; - else if( aL.eType == SbxULONG64 ) - if( !aR.nULong64 ) SetError( SbxERR_ZERODIV ); - else aL.nULong64 /= aR.nULong64; + if( !aR.nInt64 ) SetError( SbxERR_ZERODIV ); + else { + aL.nInt64 /= aR.nInt64; + aL.nInt64 *= CURRENCY_FACTOR; + } + else if( aL.eType == SbxSALUINT64 ) + if( !aR.uInt64 ) SetError( SbxERR_ZERODIV ); + else aL.uInt64 /= aR.uInt64; + else if( aL.eType == SbxSALINT64 ) + if( !aR.nInt64 ) SetError( SbxERR_ZERODIV ); + else aL.nInt64 /= aR.nInt64; else if( aL.eType == SbxLONG ) if( !aR.nLong ) SetError( SbxERR_ZERODIV ); else aL.nLong /= aR.nLong; @@ -1236,14 +1089,12 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) else aL.nULong /= aR.nULong; break; case SbxMOD: - if( aL.eType == SbxCURRENCY ) - aL.eType = SbxLONG64; - if( aL.eType == SbxLONG64 ) - if( !aR.nLong64 ) SetError( SbxERR_ZERODIV ); - else aL.nLong64 %= aR.nLong64; - else if( aL.eType == SbxULONG64 ) - if( !aR.nULong64 ) SetError( SbxERR_ZERODIV ); - else aL.nULong64 %= aR.nULong64; + if( aL.eType == SbxCURRENCY || aL.eType == SbxSALINT64 ) + if( !aR.nInt64 ) SetError( SbxERR_ZERODIV ); + else aL.nInt64 %= aR.nInt64; + else if( aL.eType == SbxSALUINT64 ) + if( !aR.uInt64 ) SetError( SbxERR_ZERODIV ); + else aL.uInt64 %= aR.uInt64; else if( aL.eType == SbxLONG ) if( !aR.nLong ) SetError( SbxERR_ZERODIV ); else aL.nLong %= aR.nLong; @@ -1253,31 +1104,31 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) break; case SbxAND: if( aL.eType != SbxLONG && aL.eType != SbxULONG ) - aL.nLong64 &= aR.nLong64; + aL.nInt64 &= aR.nInt64; else aL.nLong &= aR.nLong; break; case SbxOR: if( aL.eType != SbxLONG && aL.eType != SbxULONG ) - aL.nLong64 |= aR.nLong64; + aL.nInt64 |= aR.nInt64; else aL.nLong |= aR.nLong; break; case SbxXOR: if( aL.eType != SbxLONG && aL.eType != SbxULONG ) - aL.nLong64 ^= aR.nLong64; + aL.nInt64 ^= aR.nInt64; else aL.nLong ^= aR.nLong; break; case SbxEQV: if( aL.eType != SbxLONG && aL.eType != SbxULONG ) - aL.nLong64 = (aL.nLong64 & aR.nLong64) | (~aL.nLong64 & ~aR.nLong64); + aL.nInt64 = (aL.nInt64 & aR.nInt64) | (~aL.nInt64 & ~aR.nInt64); else aL.nLong = (aL.nLong & aR.nLong) | (~aL.nLong & ~aR.nLong); break; case SbxIMP: if( aL.eType != SbxLONG && aL.eType != SbxULONG ) - aL.nLong64 = ~aL.nLong64 | aR.nLong64; + aL.nInt64 = ~aL.nInt64 | aR.nInt64; else aL.nLong = ~aL.nLong | aR.nLong; break; @@ -1285,7 +1136,7 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) if( aL.eType != SbxLONG && aL.eType != SbxULONG ) { if ( aL.eType != SbxBOOL ) - aL.nLong64 = ~aL.nLong64; + aL.nInt64 = ~aL.nInt64; else aL.nLong = ~aL.nLong; } @@ -1296,8 +1147,8 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) } } } - else if( ( GetType() == SbxDECIMAL || rOp.GetType() == SbxDECIMAL ) && - ( eOp == SbxMUL || eOp == SbxDIV || eOp == SbxPLUS || eOp == SbxMINUS || eOp == SbxNEG ) ) + else if( ( GetType() == SbxDECIMAL || rOp.GetType() == SbxDECIMAL ) + && ( eOp == SbxMUL || eOp == SbxDIV || eOp == SbxPLUS || eOp == SbxMINUS || eOp == SbxNEG ) ) { aL.eType = aR.eType = SbxDECIMAL; bDecimal = true; @@ -1348,57 +1199,86 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) } else if( GetType() == SbxCURRENCY || rOp.GetType() == SbxCURRENCY ) { + double dTest; aL.eType = SbxCURRENCY; aR.eType = SbxCURRENCY; if( rOp.Get( aR ) ) { - static BigInt n10K( 10000 ); - if( rOp.GetType() == SbxEMPTY ) goto Lbl_OpIsEmpty; if( Get( aL ) ) switch( eOp ) { case SbxMUL: - { - // #i20704 Implement directly - BigInt b1( aL.nLong64 ); - BigInt b2( aR.nLong64 ); - b1 *= b2; - b1 /= n10K; - double d = double( b1 ) / 10000.0; - if( d > SbxMAXCURR || d < SbxMINCURR ) + // first overflow check: see if product will fit - test real value of product (hence 2 curr factors) + dTest = (double)aL.nInt64 * (double)aR.nInt64 / (double)CURRENCY_FACTOR_SQUARE; + if( dTest < SbxMINCURR || SbxMAXCURR < dTest) + { + aL.nInt64 = SAL_MAX_INT64; + if( dTest < SbxMINCURR ) aL.nInt64 = SAL_MIN_INT64; SetError( SbxERR_OVERFLOW ); - else - b1.INT64( &aL.nLong64 ); + break; + } + // second overflow check: see if unscaled product overflows - if so use doubles + dTest = (double)aL.nInt64 * (double)aR.nInt64; + if( dTest < SAL_MIN_INT64 || SAL_MAX_INT64 < dTest) + { + aL.nInt64 = (sal_Int64)( dTest / (double)CURRENCY_FACTOR ); + break; + } + // precise calc: multiply then scale back (move decimal pt) + aL.nInt64 *= aR.nInt64; + aL.nInt64 /= CURRENCY_FACTOR; break; - } + case SbxDIV: - if( !aR.nLong64 ) + if( !aR.nInt64 ) { SetError( SbxERR_ZERODIV ); + break; } - else + // first overflow check: see if quotient will fit - calc real value of quotient (curr factors cancel) + dTest = (double)aL.nInt64 / (double)aR.nInt64; + if( dTest < SbxMINCURR || SbxMAXCURR < dTest) { - // #i20704 Implement directly - BigInt b1( aL.nLong64 ); - BigInt b2( aR.nLong64 ); - b1 *= n10K; - b1 /= b2; - double d = double( b1 ) / 10000.0; - if( d > SbxMAXCURR || d < SbxMINCURR ) - SetError( SbxERR_OVERFLOW ); - else - b1.INT64( &aL.nLong64 ); + SetError( SbxERR_OVERFLOW ); + break; + } + // second overflow check: see if scaled dividend overflows - if so use doubles + dTest = (double)aL.nInt64 * (double)CURRENCY_FACTOR; + if( dTest < SAL_MIN_INT64 || SAL_MAX_INT64 < dTest) + { + aL.nInt64 = (sal_Int64)(dTest / (double)aR.nInt64); + break; } + // precise calc: scale (move decimal pt) then divide + aL.nInt64 *= CURRENCY_FACTOR; + aL.nInt64 /= aR.nInt64; break; + case SbxPLUS: - aL.nLong64 += aR.nLong64; break; + dTest = ( (double)aL.nInt64 + (double)aR.nInt64 ) / (double)CURRENCY_FACTOR; + if( dTest < SbxMINCURR || SbxMAXCURR < dTest) + { + SetError( SbxERR_OVERFLOW ); + break; + } + aL.nInt64 += aR.nInt64; + break; + case SbxMINUS: - aL.nLong64 -= aR.nLong64; break; + dTest = ( (double)aL.nInt64 - (double)aR.nInt64 ) / (double)CURRENCY_FACTOR; + if( dTest < SbxMINCURR || SbxMAXCURR < dTest) + { + SetError( SbxERR_OVERFLOW ); + break; + } + aL.nInt64 -= aR.nInt64; + break; case SbxNEG: - aL.nLong64 = -aL.nLong64; break; + aL.nInt64 = -aL.nInt64; + break; default: SetError( SbxERR_NOTIMP ); } @@ -1406,7 +1286,7 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) } else Lbl_OpIsDouble: - { // other operators + { // other types and operators including Date, Double and Single aL.eType = aR.eType = SbxDOUBLE; if( rOp.Get( aR ) ) { @@ -1429,6 +1309,9 @@ Lbl_OpIsDouble: else aL.nDouble /= aR.nDouble; break; case SbxPLUS: aL.nDouble += aR.nDouble; break; + // #45465 Date needs with "+" a special handling: forces date type + if( GetType() == SbxDATE || rOp.GetType() == SbxDATE ) + aL.eType = SbxDATE; case SbxMINUS: aL.nDouble -= aR.nDouble; break; case SbxNEG: @@ -1437,9 +1320,6 @@ Lbl_OpIsDouble: SetError( SbxERR_NOTIMP ); } - // #45465 Date needs with "+" a special handling - if( eOp == SbxPLUS && (GetType() == SbxDATE || rOp.GetType() == SbxDATE ) ) - aL.eType = SbxDATE; } } @@ -1622,6 +1502,8 @@ BOOL SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const BOOL SbxValue::LoadData( SvStream& r, USHORT ) { + // #TODO see if these types are really dumped to any stream + // more than likely this is functionality used in the binfilter alone SbxValue::Clear(); UINT16 nType; r >> nType; @@ -1662,15 +1544,21 @@ BOOL SbxValue::LoadData( SvStream& r, USHORT ) } break; } - case SbxULONG64: - { - r >> aData.nULong64.nHigh >> aData.nULong64.nLow; + case SbxSALUINT64: + case SbxSALINT64: + // Rather ugly use of the union here because we only + // have a SvStream& SvStream::operator>>(sal_uInt64&) available to us + // There is no SvStream::operator>>(sal_Int64&) due to conflict with + // SvStream::operator>>(long&) ( at least on 64 bit linux ) + r >> aData.uInt64; break; - } - case SbxLONG64: case SbxCURRENCY: { - r >> aData.nLong64.nHigh >> aData.nLong64.nLow; + sal_uInt32 tmpHi = 0; + sal_uInt32 tmpLo = 0; + r >> tmpHi >> tmpLo; + aData.nInt64 = ((sal_Int64)tmpHi << 32); + aData.nInt64 |= (sal_Int64)tmpLo; break; } case SbxSTRING: @@ -1779,15 +1667,16 @@ BOOL SbxValue::StoreData( SvStream& r ) const case SbxDOUBLE: r.WriteByteString( GetCoreString(), RTL_TEXTENCODING_ASCII_US ); break; - case SbxULONG64: - { - r << aData.nULong64.nHigh << aData.nULong64.nLow; + case SbxSALUINT64: + case SbxSALINT64: + // see comment in SbxValue::StoreData + r << aData.uInt64; break; - } - case SbxLONG64: case SbxCURRENCY: { - r << aData.nLong64.nHigh << aData.nLong64.nLow; + sal_Int32 tmpHi = ( (aData.nInt64 >> 32) & 0xFFFFFFFF ); + sal_Int32 tmpLo = ( sal_Int32 )aData.nInt64; + r << tmpHi << tmpLo; break; } case SbxSTRING: |