IdeDebugger: fix parsing ".." range for arrays (after ^ deref)

(cherry picked from commit b38ca94a08)
This commit is contained in:
Martin 2023-09-03 13:49:27 +02:00
parent ee6a3fed0c
commit c3a1844be1
4 changed files with 68 additions and 2 deletions

View File

@ -289,9 +289,16 @@ begin
if InString then
Continue;
if p^ in ['@', '^', '.', '+', '-', '*', '/', '(', ',', '=', '<', '>', '#', '$', '%', '&', '!'] then
if p^ in ['@', '.', '+', '-', '*', '/', '(', ',', '=', '<', '>', '#', '$', '%', '&', '!'] then
MaybeBeforeRange := False // after operator. A [1..5] would be a set of byte
else
if (p - s >= 2) and
(p[-2] in [#1..#32]) and (p[-1] in ['i', 'I']) and
(p^ in ['n', 'N']) and (p[1] in [#1..#32])
then
MaybeBeforeRange := False // after IN operator. A [1..5] would be a set of byte
else
if p^ in ['a'..'z', 'A'..'Z', '_', ')', ']'] then
MaybeBeforeRange := True // after identifier, or after ")" or "]"

View File

@ -154,6 +154,11 @@
<IsPartOfProject Value="True"/>
<UnitName Value="TestXmlOpts"/>
</Unit>
<Unit>
<Filename Value="testvarious.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TestVarious"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>

View File

@ -3,7 +3,7 @@ program TestIdeDebugger;
{$mode objfpc}{$H+}
uses
Interfaces, Forms, GuiTestRunner, TestWatchResult, TestXmlOpts;
Interfaces, Forms, GuiTestRunner, TestWatchResult, TestXmlOpts, TestVarious;
{$R *.res}

View File

@ -0,0 +1,54 @@
unit TestVarious;
{$mode objfpc}{$H+}
{$INLINE off}
interface
uses
Classes, SysUtils, fpcunit, testutils, testregistry,
IdeDebuggerUtils,
LazLogger;
type
{ TTestIdeDebuggerVarious }
TTestIdeDebuggerVarious = class(TTestCase)
published
procedure TestExpressionForArrayElement;
end;
implementation
{ TTestIdeDebuggerVarious }
procedure TTestIdeDebuggerVarious.TestExpressionForArrayElement;
begin
AssertEquals('a', 'a[11]', GetExpressionForArrayElement('a', 11));
AssertEquals('(a)', '(a)[11]', GetExpressionForArrayElement('(a)', 11));
AssertEquals('a[2]', 'a[2][11]', GetExpressionForArrayElement('a[2]', 11));
AssertEquals('(a * [1..22]) * b[3..33]', '(a * [1..22]) * b[11]', GetExpressionForArrayElement('(a * [1..22]) * b[3..33]', 11));
AssertEquals('(a in [1..22]) * b[3..33]', '(a in [1..22]) * b[11]', GetExpressionForArrayElement('(a in [1..22]) * b[3..33]', 11));
AssertEquals('( an [1..22]) * b[3..33]', '( an [11]) * b[3..33]', GetExpressionForArrayElement('( an [1..22]) * b[3..33]', 11));
AssertEquals('a[2..22]', 'a[11]', GetExpressionForArrayElement('a[2..22]', 11));
AssertEquals('a[-2..22]', 'a[11]', GetExpressionForArrayElement('a[-2..22]', 11));
AssertEquals('a[-22..-2]', 'a[-11]', GetExpressionForArrayElement('a[-22..-2]', -11));
AssertEquals('a[2..22][3..33]', 'a[11][3..33]', GetExpressionForArrayElement('a[2..22][3..33]', 11));
AssertEquals('a[2..22]*b[3..33]', 'a[11]*b[3..33]', GetExpressionForArrayElement('a[2..22]*b[3..33]', 11));
AssertEquals('Foo(a[2..22])', 'Foo(a[11])', GetExpressionForArrayElement('Foo(a[2..22])', 11));
AssertEquals('PCellProps((TFpList((StringGrid1.FGrid.FCellArr.FCols.FList)^[0..3]).FList)^[0..3])^',
'PCellProps((TFpList((StringGrid1.FGrid.FCellArr.FCols.FList)^[2]).FList)^[0..3])^',
GetExpressionForArrayElement('PCellProps((TFpList((StringGrid1.FGrid.FCellArr.FCols.FList)^[0..3]).FList)^[0..3])^', 2)
);
end;
initialization
RegisterTest(TTestIdeDebuggerVarious);
end.