DBG: deal with comma separated array index "a[1,2]" instead of "a[1][2]"

git-svn-id: trunk@36166 -
This commit is contained in:
martin 2012-03-19 14:53:56 +00:00
parent dfa6c71041
commit a4e1f89a1c
4 changed files with 112 additions and 12 deletions

View File

@ -143,10 +143,11 @@ type
function GetParts(Index: Integer): TGDBExpressionPart; override;
public
constructor CreateSimple(AText: PChar; ATextLen: Integer);
constructor Create(AText: PChar; ATextLen: Integer);
constructor Create(ATextStr: String);
constructor Create(AText: PChar; ATextLen: Integer); virtual; overload;
constructor Create(ATextStr: String); overload;
destructor Destroy; override;
function PartCount: Integer; override;
function IsCommaSeparated: Boolean;
end;
{ TGDBExpressionPartBracketed }
@ -156,7 +157,7 @@ type
function GetTextFixed(AStringFixed: Boolean): String; override;
function GetPlainText: String;
public
constructor Create(AText: PChar; ATextLen: Integer);
constructor Create(AText: PChar; ATextLen: Integer); override; overload;
end;
{ TGDBExpressionPartListBase }
@ -172,8 +173,10 @@ type
destructor Destroy; override;
procedure Clear;
procedure ClearShared;
function Add(APart: TGDBExpressionPart):Integer;
function PartCount: Integer; override;
function Add(APart: TGDBExpressionPart):Integer;
procedure Insert(AIndex: Integer; APart: TGDBExpressionPart);
procedure Delete(AIndex: Integer);
function PartCount: Integer; override;
end;
TGDBExpressionPartList = class(TGDBExpressionPartListBase)
@ -181,6 +184,13 @@ type
function AddList(APartList: TGDBExpressionPartList):Integer;
end;
{ TGDBExpressionPartCommaList }
TGDBExpressionPartCommaList = class(TGDBExpressionPartList)
protected
function GetTextFixed(AStringFixed: Boolean): String; override;
end;
{ TGDBExpressionPartArrayIdx }
TGDBExpressionPartArrayIdx = class(TGDBExpressionPartBracketed)
@ -209,6 +219,8 @@ type
property ArrayPTypeIsPointer: boolean read GetArrayPTypeIsPointer;
property ArrayPTypeNestIdx: integer read FArrayPTypeNestIdx write FArrayPTypeNestIdx;
property ArrayPTypePointerIdx: integer read FArrayPTypePointerIdx write FArrayPTypePointerIdx;
// for comma separated
function CreateExpressionForSubIndex(AIndex: Integer): TGDBExpressionPartArrayIdx;
end;
{ TGDBExpressionPartArray }
@ -896,6 +908,20 @@ begin
;
end;
{ TGDBExpressionPartCommaList }
function TGDBExpressionPartCommaList.GetTextFixed(AStringFixed: Boolean): String;
var
i: Integer;
begin
Result := '';
if PartCount = 0 then
exit;
Result := Parts[0].GetTextFixed(AStringFixed);
for i := 1 to PartCount - 1 do
Result := Result + ',' + Parts[i].GetTextFixed(AStringFixed);
end;
{ TGDBExpressionPartArrayIdx }
function TGDBExpressionPartArrayIdx.GetArrayPTypeIsDeRef: boolean;
@ -976,6 +1002,12 @@ begin
Result := inherited GetTextFixed(AStringFixed);
end;
function TGDBExpressionPartArrayIdx.CreateExpressionForSubIndex(AIndex: Integer): TGDBExpressionPartArrayIdx;
begin
Result := TGDBExpressionPartArrayIdx.Create
(FText.Ptr^ + Parts[AIndex].GetText + (FText.Ptr + FText.Len-1)^);
end;
{ TGDBExpressionPartList }
function TGDBExpressionPartList.AddList(APartList: TGDBExpressionPartList): Integer;
@ -992,8 +1024,18 @@ end;
{ TGDBExpressionPartArray }
function TGDBExpressionPartArray.GetIndexParts(Index: Integer): TGDBExpressionPartArrayIdx;
var
j: Integer;
begin
Result := TGDBExpressionPartArrayIdx(Parts[Index+1]);
if Result.IsCommaSeparated then begin
Delete(Index+1);
For j := 0 to Result.PartCount-1 do
Insert(Index + 1 + j, Result.CreateExpressionForSubIndex(j));
Result.Free;
Result := TGDBExpressionPartArrayIdx(Parts[Index+1]);
end;
end;
function TGDBExpressionPartArray.GetTextFixed(AStringFixed: Boolean): String;
@ -1135,15 +1177,17 @@ var
s: String;
begin
Result := False;
// Index
for i := 1 to PartCount - 1 do
if Parts[i].NeedValidation(AReqPtr) then
Result := True;
if Parts[0].NeedValidation(AReqPtr)
if Parts[0].NeedValidation(AReqPtr) // Array-Variable
then begin
Result := True;
exit;
end;
if Result then exit;
i := 0;
while i < IndexCount do begin
@ -1337,7 +1381,7 @@ var
procedure ScanToWordStart;
begin
while (CurPtr < EndPtr) and not (CurPtr^ in WordChar)
while (CurPtr < EndPtr) and not( (CurPtr^ in WordChar) or (CurPtr^ = ',') )
do inc(CurPtr);
end;
@ -1425,12 +1469,14 @@ var
CurList: TGDBExpressionPartList;
CurArray: TGDBExpressionPartArray;
CurCast: TGDBExpressionPartCastCall;
FCommaList: TGDBExpressionPartCommaList;
begin
Result := nil;
FCommaList := nil;
CurPtr := AText;
EndPtr := AText + ATextLen;
while (CurPtr < EndPtr) and not(CurPtr^ in ['[', '(']) do inc(CurPtr);
while (CurPtr < EndPtr) and not(CurPtr^ in ['[', '(', ',']) do inc(CurPtr);
if CurPtr = EndPtr then exit; // no fixup needed
CurPtr := AText;
@ -1439,6 +1485,16 @@ begin
while CurPtr < EndPtr do begin
if (CurPtr^ = ',')
then begin
if FCommaList = nil then
FCommaList := TGDBExpressionPartCommaList.Create;
AddExpPart(CurList);
FCommaList.Add(Result);
Result := nil;
inc(CurPtr);
end
else
if CurPtr^ in WordChar
then begin
if CurArray <> nil then CurArray.NeedTypeCast := True;
@ -1484,6 +1540,13 @@ begin
AddExpPart(CurList);
CurList.Free;
if FCommaList <> nil then begin
if Result <> nil then
FCommaList.Add(Result);
Result := FCommaList;
end;
if CurPtr < EndPtr then debugln(['Scan aborted: ', PCLenToString(FText)]);
if CurPtr < EndPtr then FreeAndNil(Result);
end;
@ -1580,6 +1643,16 @@ begin
Result := FList.Add(APart);
end;
procedure TGDBExpressionPartListBase.Insert(AIndex: Integer; APart: TGDBExpressionPart);
begin
FList.Insert(AIndex, APart);
end;
procedure TGDBExpressionPartListBase.Delete(AIndex: Integer);
begin
FList.Delete(AIndex);
end;
function TGDBExpressionPartListBase.PartCount: Integer;
begin
Result := FList.Count;
@ -1639,6 +1712,11 @@ begin
else Result := 1;
end;
function TGDBExpression.IsCommaSeparated: Boolean;
begin
Result := (FExpressionPart <> nil) and (FExpressionPart is TGDBExpressionPartCommaList);
end;
{ TGDBPTypeRequestCache }
function TGDBPTypeRequestCache.GetRequest(Index: Integer): TGDBPTypeRequest;

View File

@ -1580,8 +1580,22 @@
globastatdualarraytrec2[4,3].c := 302; globastatdualarraytrec2[4,3].recs := nil;
// GlobAStatDynDynArrayTRec2 : array [3..5] of array of array of TRecForArray2;
SetLength(GlobAStatDynDynArrayTRec2[3], 3);
SetLength(GlobAStatDynDynArrayTRec2[3][0], 2);
SetLength(GlobAStatDynDynArrayTRec2[3][1], 2);
SetLength(GlobAStatDynDynArrayTRec2[4], 3);
SetLength(GlobAStatDynDynArrayTRec2[4][0], 2);
SetLength(GlobAStatDynDynArrayTRec2[4][1], 2);
GlobAStatDynDynArrayTRec2[3][0][0].c := 300;
GlobAStatDynDynArrayTRec2[3][0][1].c := 301;
GlobAStatDynDynArrayTRec2[3][1][0].c := 310;
GlobAStatDynDynArrayTRec2[3][1][1].c := 311;
GlobAStatDynDynArrayTRec2[4][0][0].c := 400;
GlobAStatDynDynArrayTRec2[4][0][1].c := 401;
GlobAStatDynDynArrayTRec2[4][1][0].c := 410;
GlobAStatDynDynArrayTRec2[4][1][1].c := 411;
SetLength(GlobADynDynStatArrayTRec2, 3);

View File

@ -789,10 +789,10 @@ begin
n := 'abc()[x[123]]';
InitExpr(n, b, r, v);
AssertTrue(n + ' is array', b.Parts[0] is TGDBExpressionPartArray);
AssertTrue(n + ' r.next', (r <> nil) and (r^.Next <> nil));
r2 := r^.Next;
AssertTrue(n + ' ptype', (r <> nil) and ((r^.Request = 'ptype abc()') or (r2^.Request = 'ptype abc()')));
AssertTrue(n + ' ptype2', (r <> nil) and ((r^.Request = 'ptype x') or (r2^.Request = 'ptype x')));
AssertTrue(n + ' r.next', (r <> nil)); // and (r^.Next <> nil));
//r2 := r^.Next;
//AssertTrue(n + ' ptype', (r <> nil) and ((r^.Request = 'ptype abc()') or (r2^.Request = 'ptype abc()')));
//AssertTrue(n + ' ptype2', (r <> nil) and ((r^.Request = 'ptype x') or (r2^.Request = 'ptype x')));
n := 'Cast(foo^.bar[1][foo[2]]+Call[x()]((f+1)^))+bar(1).z.x[1](m)(n)';

View File

@ -1288,6 +1288,7 @@ begin
r := AddRecForArrFmtDef(v+'ArgTDynDynArrayTRec1[1][0]', 1, 85, []);
//if v = 'V' then UpdResMinFpc(r, stDwarf2All, 020600);
r := AddRecForArrFmtDef(v+'ArgTDynDynArrayTRec1[1][1]', 1, 86, []);
r := AddRecForArrFmtDef(v+'ArgTDynDynArrayTRec1[1,1]', 1, 86, []); // comma separated index
//if v = 'V' then UpdResMinFpc(r, stDwarf2All, 020600);
//TDynDynArrayPRec1 = array of array of ^TRecForArray1;
//TDynStatArrayTRec1 = array of array [3..5] of TRecForArray1;
@ -1367,6 +1368,7 @@ begin
r := AddArrayFmtDef('ArgTStatDynArrayTRec1[4]', '.', '', []); // TODO? typename = array of ...
r := AddRecForArrFmtDef('ArgTStatDynArrayTRec1[4][0]', 1, 45, []);
r := AddRecForArrFmtDef('ArgTStatDynArrayTRec1[4][1]', 1, 46, []);
r := AddRecForArrFmtDef('ArgTStatDynArrayTRec1[4,1]', 1, 46, []); // comma separated index
//TStatDynArrayPRec1 = array [3..5] of array of ^TRecForArray1;
//TStatStatArrayTRec1 = array [3..5] of array [3..5] of TRecForArray1;
//TStatStatArrayPRec1 = array [3..5] of array [3..5] of ^TRecForArray1;
@ -1621,6 +1623,12 @@ begin
// stat arrays of named arrays
// comma separated index
r := AddRecForArrFmtDef('GlobAStatDynDynArrayTRec2[4][0][1]', 2, 401, []);
r := AddRecForArrFmtDef('GlobAStatDynDynArrayTRec2[4,0][1]', 2, 401, []);
r := AddRecForArrFmtDef('GlobAStatDynDynArrayTRec2[4][0,1]', 2, 401, []);
r := AddRecForArrFmtDef('GlobAStatDynDynArrayTRec2[4,0,1]', 2, 401, []);
end;
procedure TTestWatches.AddExpectBreakFooMixInfo;