Commit f45463d8e2 (tdf#93727 Support date
literals in basic, 2017-05-24) introduced correct parsing of literals
like #2025-09-26#. However, it didn't retain the value type; there was
a discussion about that in gerrit, but no solution was found, and type
was set to double.
Later, a similar problem (storing type of value in compiled image) was
fixed in commit 5eedb3beea (tdf#142460:
properly handle boolean values in string pool, 2021-06-25).
This change reuses the same method to store date type using 'd' char in
the string pool.
Change-Id: I32e8497ece1f30980ba6d4fca248687b817348f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191555
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
1. If a string is passed as argument, it is returned without any changes.
For that, SbRtl_Str checks argument type, skipping processing for string.
2. Non-negative numbers are preceded by a blank space.
That already was implemented.
3. Negative numbers are preceded by a minus sign.
That was done incorrectly - a space was added for any number.
4. Dates are converted into locale-dependent strings.
That wasn't done at all - dates were converted to strings representing
the serial date. A check is implemented SbxValue::Format, to handle this.
Additionally, Format function was improved to handle such input without
format string (taking into account that it handles strings that can be
converted to numbers differently).
Change-Id: I5ac0429950e4ea8bf69b0091502b4e6dc1f4957d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191549
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
When a value is convertible to number, check if the format string
is for numbers of text (in SbxValue::Format). If the value is not
convertible to number, handle it according to the format string in
printfmtstr.
Change-Id: I6e11aeffd8dd8581ebc868762944e9d6d9393514
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190348
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
SbiRuntime::FindElement ends with a call to CheckArray(). The latter
takes a variable, checks if that is an array and if it has parameters;
and if both are true, tries to obtain an element of the array defined
by the parameters as array indexes (using SbxDimArray::Get).
The problem was, that the variable may actually be array; it may have
parameters; but this array can be the result of a function call; the
variable may be SbxMethod; and the parameters may be for the function,
not array indexes.
Specifically, the call like
Iif(True, Array("A","B"), Array("B","A"))
searched for an entity named Iif; found that it was a RTL method;
prepared the arguments for it (consisting of four elements: 0 - the
method itself; 1 - boolean True; 2 - array ["A", "B"]; 3 - array
["B", "A"]); the function executed, putting the correct value to the
params[0], which was the method itself (so its value became an array);
and finally, the SbxMethod variable with the array value got passed
to CheckArray. The latter found out that it's an array, and that it
has parameters (those four) - and tried to get the element, which
index was defined by the parameters.
Here comes the specifics of LibreOffice Basic's argument handling.
SbxDimArray::Get only cares about first arguments expected by the
array dimensions; it ignores the rest. Since the array was single-
dimensional, it only considered parameter 1 (parameter 0 is, by
convention, reserved for return value). That was a boolean. When it
was False, its GetInteger returned 0; and finally, CheckArray took
element 0 from the array, returning a scalar value, as if it was
Iif(False, Array("A","B"), Array("B","A"))(0)
But when the boolean was True, another Basic specific took place:
its numerical value is -1; and trying to get element -1 from the
array resulted in "Index out of defined range".
This change disambiguates between the cases of array index, and
function parameters, checking if the variable itself, and its 0th
parameter are both SbxMethods. Then it doesn't try to treat the
parameters as indexes into the array.
Change-Id: I597f94a7e688c8bba12d87a1bd5871491c25cac0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187145
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Resetting parameters in this function was introduced in commit
0b21b8b146 (initial commit for vba blob
( not including container_control stuff ), 2010-10-06). Unfortunately,
the reason for that is not explained.
The problem that it creates is that this code gets called eventually
from SbiRuntime::FindElement (which sets parameters using SetupArgs,
then calls SbiRuntime::CheckArray in the end, which calls GetObject,
which performs actual data access).
In SbiRuntime::CheckArray, the immediate problem was, that parameters
were referenced using a raw pointer; when the parageters were cleared
in GetObject, the pointer got dangling.
But it wasn't enough to use e.g. SbxArrayRef there, to keep the array
alive; the object will be accessed later, and needs its parameters to
work. On the other hand, it feels wrong to reinstate parameters after
the call to GetObject in SbiRuntime::CheckArray (getting the object
can run just any code path). So I chose to try and drop the resetting
of parameters in SbUnoObject::Notify. Let's see, if something breaks.
Change-Id: Icadfcfb8b7e5e87b2de46166963fd97532f8713c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186432
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Commit 81e1e0a2a6 changed string-to-number
procedure from SvNumberFormatter to only use SbxValue::ScanNumIntnl. But
the latter can only handle strings with simple numbers, not with dates,
times and the like.
This change restores use of SvNumberFormatter to convert input strings
to number, when SbxValue::ScanNumIntnl fails. The code is re-structured
for performance, to avoid creating SvNumberFormatter twice, and repeated
calls to GetOUString.
Change-Id: I89a4fc041fe24fe00b099ab4fbee371d1f6b5567
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185047
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Since the initial import, there is a code in SbiExpression::Term, that
checks if the defined symbol is used as object (e.g., dot notation to
access its members), and then, if its defined type is Variant, then it
is corrected to Object. There is no rationale for this in comments; so
I have no way to know what could break if that core is dropped.
It's obvious that at least for procedure arguments, such correction is
wrong: the argument definition is the procedure's API; and the actual
use of the symbol should not unexpectedly change what is advertised.
This change limits the application of the correction to non-arguments.
If it should be dropped completely is a separate question.
Change-Id: Ia902afa3f744d0d51510ba6903be45f78e2f6429
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180665
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Commit 9cdb73ff28 (INTEGRATION: CWS jl5vba
(1.25.94); FILE MERGED, 2004-03-17) has introduced handling of decimal,
currency, and date for VBASupport mode in sbunoobj.cxx. However, in
getUnoTypeForSbxBaseType, it changed the behavior for date type in the
non-VBASupport mode, obviously by mistake. This change swaps the code
in the 'if' branches, to what appears to be the original intention.
Change-Id: I88cddf7cec1a980f56de96ae1c5e64d8e7630b77
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180637
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
The problem is, that having a local variable referring the same value
as the original expression 'foo' is not the same as referencing 'foo'
itself. After 'foo' is re-assigned, the local variable still refers
to the original value, not the new one.
It seems impossible to implement the reference using existing codegen
primitives, to imitate the true reference to 'foo', not to its value.
If we implement it by changing the runtime, the bytecode won't work
identically in older versions; if we introduce a new bytecode, that
would be an incompatible change.
As a workaround, only create the local With variable, when the block
variable is created using some function (as much as known by parser).
I think that there would be cases when this would still not work as
intended: an example is a property implemented using getter function;
the parser would likely treat the property as a variable, and avoid
creation of the local variable; and the getter would be called every
time a dot access will happen (which was the essence of tdf#132064).
However, this seems a better alternative to the bug fixed here.
Change-Id: I50bf679762fd2e73f215a000fa0ab60fd6ae7453
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174564
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Other "WITH" blocks create the symbol that can be found by pPool->Find,
but can be not accessible at the call site.
Change-Id: I85ecc763a1bb3fd692c2c98e674047fdbde3f8f5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173417
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
SbiRuntime::StepPUT, SbiRuntime::StepSET, SbiRuntime::StepVBASET call
checkUnoStructCopy eventually, which copies the UNO struct by value.
This is not what we need. On the other hand, SbiRuntime::StepPUTC only
makes the by-ref assignment, and makes the reference const; but Basic
code never assigns anything to the internal variable itself, only to
its members.
I hope that this time, I get it right.
Change-Id: I2b4a51a2dca9e7106e14e03360ef0d5a50b60079
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173305
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
In commit f3f46b5fe7 (tdf#132064: make
With statement only evaluate its argument once, 2024-08-17), I made
a mistake, clearing the internal variable in the end of SbiParser::With
using an Erase call, which does not just clears the variable itself,
but destroys the underlying object, which is not what we need.
I don't know how to refer to a global Nothing object to assign to the
variable; so just create an own internal Nothing, and use it in the
assignment.
Change-Id: Ic8ce52e0402d8461a9b9e4ee07614c4f0a46a95e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172006
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This is implemented by creating a unique variable at entry of the
block, using it as the "with parent", and clearing afterwards. It
uses an invalid name, so can't be used by a user. The generation
of the bytecode is done in compatible way; only existing opcodes
were used (which was the reason to choose the implementation with
a variable), so compiled binaries in password-protected libraries
are expected to work with older versions.
The functional changes are:
1. The argument of With statement is evaluated immediately at the
start of the block; previously, it evaluated first time, when the
leading dot operator was used, and could even be never evaluated,
if the operator wasn't used. This is consistent with VBA, and has
a benefit that the lifetime of the object is guaranteed to cover
the whole block (might be useful if other block statements depend
on the object, similar to Python's 'with' statement contexts).
2. The primary goal of the change: it is only ever evaluated once,
no matter how many times was the dot operator used in the block.
Change-Id: I4dbd520538a57e3668ab706e8f45740db5d33393
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171980
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Don't execute On expression GoSub Statement; On expression GoTo
Statement if the expression lies out of range.
Change-Id: I5c1de25918b5e812d7ec82034f8d56351374d56a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165960
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Tested-by: Jenkins
Previously, BASIC CCur used a custom, single-purpose currency string
parser which did not properly accommodate the user's locale setting.
This change replaces the custom parser with SvNumberFormatter, which
does correctly respect system locale.
Change-Id: I179915eb080e876e5e550dd350fdb86d7fa2bf4c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160848
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
cppu::UnoType<sal_uInt8> corresponds to UNO boolean, so its use made the
unsigned values be converted to a true/false in Any; and additionally,
using such a boolean Any, even having a 'true' value, as a parameter to
a double argument would make operator >>=(const Any &, double &) return
false, giving the resulting double equal to 0.
The wrong conversion of UShorts and ULongs to cppu::UnoType<sal_uInt8>
(aka TypeClass_BOOLEAN) was introduced in commit
11f9aa4fcb
Author Andreas Bregas <ab@openoffice.org>
Date Thu May 10 14:22:42 2001 +0000
#79615# sbxToUnoValue(): Choose smallest possible type for numeric values
Treating of unsigned Basic Byte as a signed cppu::UnoType<sal_Int8> (aka
TypeClass_BYTE) was already introduced in
commit c25ec0608a
Author Jens-Heiner Rechtien <hr@openoffice.org>
Date Mon Sep 18 15:18:56 2000 +0000
initial import
Then, in commit 553cf2a834
Author Andreas Bregas <ab@openoffice.org>
Date Fri Jun 08 14:59:57 2001 +0000
#87927# Map TypeClass_BYTE to SbxINTEGER instead of SbxBYTE because of signed/unsigned problem
an attempt was made to handle obviously this same problem, changing the
corresponding UNO type to TypeClass_SHORT. But it seems that it created
problems when passing arrays of Byte through UNO to COM, where it needed
to convert to a safearray, so this decision was reverted in commit
dd6ba6b64a
Author Mikhail Voytenko <mav@openoffice.org>
Date Thu Jul 08 21:33:48 2010 +0200
mib17: #162917# let basic byte use one byte, let olebridge convert sequence to safearray correctly
This change tries to avoid the problem that caused the latter revert,
by only treating Bytes as UNO shorts in getUnoTypeForSbxValue, where
scalar Byte values are considered, keeping old handling for arrays.
Change-Id: I805108743376e2fc27dd21a27c31759b76dc0d09
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136526
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Moves the custom cleanup logic to overridden SbxMethod::Clear, to simplify
the cleanup code and make sure it restores empty Variant correctly.
Change-Id: I01fa0529acd9ac787ffcda60fd6836ade4afdcb1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136108
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
...like my local ASan+UBSan build, which now happened to fail once with
> Failed: TestReplacePerformance (t = 60 s)
> Tests passed: 0
> Tests failed: 1
when the machine was under load during a parallelizing `make check`, following
up on 3564b5c6e9 "Adapt test to slow builds"
Change-Id: I8f0c8f7e6e145b6d5009f48d2af865ea5caab375
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132335
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
First, the integer function result is returned in a 64-bit register (RAX),
and truncation it to sal_Int32 breaks any pointer return value.
Second, using explicit (not vararg) first function double argument would
pass it through XMM0, without also copying it to RCX (which is guaranteed
for varargs).
Ref: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention
Change-Id: I08212c44d8690d6910068b13c16af2ce899c94f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129808
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>