diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2020-03-21 14:59:27 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-03-24 09:30:38 +0100 |
commit | 16b0bbb671a8080655e27542e576478486810404 (patch) | |
tree | e52bdd72fbc33308ba9ced4dfdaf0a0258dacc35 /basic/source/comp | |
parent | 2846686272931cd8bb0bcd452dd0e8b5b52064b1 (diff) |
tdf#131296: get numeric value with its data type in StepLOADNC
In order to load numeric values, generate SbiOpcode::NUMBER_ opcodes
including the numeric value and its data type instead of SbiOpcode::CONST_.
The numeric value and its data type will be restored in
SbiRuntime::StepLOADNC. When the new compiled code is stored in documents,
e.g. password-protected libraries, leagcy LO versions will just read up to
non-numeric characters, thus correctly obtaining number value and ignoring
the type, so the change is backward-compatible.
To interpret legacy compiled code, old treatment of SbiRuntime::StepLOADI
is restored, reverting commit 0b4f8bf571baf2ccd5a8aafdc4deb41867420be3.
This change reimplements the fix for tdf#129596.
Change-Id: I46ebfc77f9bea69479968950c0fb7264e4a7ab27
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90858
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/source/comp')
-rw-r--r-- | basic/source/comp/exprgen.cxx | 8 | ||||
-rw-r--r-- | basic/source/comp/symtbl.cxx | 11 |
2 files changed, 10 insertions, 9 deletions
diff --git a/basic/source/comp/exprgen.cxx b/basic/source/comp/exprgen.cxx index 3981bef2fb5e..6c60c02b0d7e 100644 --- a/basic/source/comp/exprgen.cxx +++ b/basic/source/comp/exprgen.cxx @@ -72,16 +72,14 @@ void SbiExprNode::Gen( SbiCodeGen& rGen, RecursiveMode eRecMode ) case SbxEMPTY: rGen.Gen( SbiOpcode::EMPTY_ ); break; - case SbxLONG: - case SbxINTEGER: - nStringId = rGen.GetParser()->aGblStrings.Add(nVal, eType); - rGen.Gen( SbiOpcode::CONST_, nStringId ); - break; case SbxSTRING: nStringId = rGen.GetParser()->aGblStrings.Add( aStrVal ); rGen.Gen( SbiOpcode::SCONST_, nStringId ); break; default: + // tdf#131296 - generate SbiOpcode::NUMBER_ instead of SbiOpcode::CONST_ + // for SbxINTEGER and SbxLONG including their numeric value and its data type, + // which will be restored in SbiRuntime::StepLOADNC. nStringId = rGen.GetParser()->aGblStrings.Add( nVal, eType ); rGen.Gen( SbiOpcode::NUMBER_, nStringId ); break; diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx index b05575adfdfb..ac6f1ecd29da 100644 --- a/basic/source/comp/symtbl.cxx +++ b/basic/source/comp/symtbl.cxx @@ -66,10 +66,13 @@ short SbiStringPool::Add( double n, SbxDataType t ) char buf[ 40 ]; switch( t ) { - case SbxINTEGER: snprintf( buf, sizeof(buf), "%d", static_cast<short>(n) ); break; - case SbxLONG: snprintf( buf, sizeof(buf), "%ld", static_cast<long>(n) ); break; - case SbxSINGLE: snprintf( buf, sizeof(buf), "%.6g", static_cast<float>(n) ); break; - case SbxDOUBLE: snprintf( buf, sizeof(buf), "%.16g", n ); break; + // tdf#131296 - store numeric value including its type character + // See GetSuffixType in basic/source/comp/scanner.cxx for type characters + case SbxINTEGER: snprintf( buf, sizeof(buf), "%d%%", static_cast<short>(n) ); break; + case SbxLONG: snprintf( buf, sizeof(buf), "%ld&", static_cast<long>(n) ); break; + case SbxSINGLE: snprintf( buf, sizeof(buf), "%.6g!", static_cast<float>(n) ); break; + case SbxDOUBLE: snprintf( buf, sizeof(buf), "%.16g", n ); break; // default processing in SbiRuntime::StepLOADNC - no type character + case SbxCURRENCY: snprintf(buf, sizeof(buf), "%.16g@", n); break; default: break; } return Add( OUString::createFromAscii( buf ) ); |