FpDebug: Change slice-operator. Add "disable" for terms that handle the slice themself (substring)

This commit is contained in:
Martin 2024-07-24 17:15:34 +02:00
parent f9e932cb46
commit c238c026d1

View File

@ -635,12 +635,15 @@ type
TFpPascalExpressionPartOperatorArraySliceController = class(TFpPascalExpressionPartContainer) // enum in set TFpPascalExpressionPartOperatorArraySliceController = class(TFpPascalExpressionPartContainer) // enum in set
private private
FDisableSlice: boolean;
FSlicePart: TFpPascalExpressionPartOperatorArraySlice; FSlicePart: TFpPascalExpressionPartOperatorArraySlice;
FInResetEvaluationForIndex: Boolean; FInResetEvaluationForIndex: Boolean;
FHasVariantPart: Boolean; FHasVariantPart: Boolean;
FCheckedForVariantPart: Boolean; FCheckedForVariantPart: Boolean;
function GetCanDisableSlice: boolean;
protected protected
function DoGetResultValue: TFpValue; override; function DoGetResultValue: TFpValue; override;
procedure ResetEvaluation;
procedure ResetEvaluationForIndex; procedure ResetEvaluationForIndex;
procedure ResetEvaluationForAnchestors; override; procedure ResetEvaluationForAnchestors; override;
public public
@ -649,6 +652,8 @@ type
ATopPart: TFpPascalExpressionPart; ATopPart: TFpPascalExpressionPart;
AStartChar: PChar; AnEndChar: PChar = nil); AStartChar: PChar; AnEndChar: PChar = nil);
function HandleNextPart(APart: TFpPascalExpressionPart): TFpPascalExpressionPart; override; function HandleNextPart(APart: TFpPascalExpressionPart): TFpPascalExpressionPart; override;
property DisableSlice: boolean read FDisableSlice write FDisableSlice;
property CanDisableSlice: boolean read GetCanDisableSlice;
end; end;
{ TFpPascalExpressionPartOperatorArraySlice } { TFpPascalExpressionPartOperatorArraySlice }
@ -656,6 +661,7 @@ type
TFpPascalExpressionPartOperatorArraySlice = class(TFpPascalExpressionPartBinaryOperator) // enum in set TFpPascalExpressionPartOperatorArraySlice = class(TFpPascalExpressionPartBinaryOperator) // enum in set
private private
FCurrentIndex: Int64; FCurrentIndex: Int64;
FController: TFpPascalExpressionPartOperatorArraySliceController;
protected protected
FTouched: boolean; FTouched: boolean;
procedure Init; override; procedure Init; override;
@ -664,6 +670,8 @@ type
function StartValue: Int64; function StartValue: Int64;
function EndValue: Int64; function EndValue: Int64;
procedure CheckForVariantExpressionParts; procedure CheckForVariantExpressionParts;
public
property Controller: TFpPascalExpressionPartOperatorArraySliceController read FController;
end; end;
implementation implementation
@ -1684,8 +1692,10 @@ begin
end; end;
skString, skAnsiString: begin skString, skAnsiString: begin
//TODO: move to FpDwarfValue.member ?? //TODO: move to FpDwarfValue.member ??
if (Count = 2) and (Items[1] is TFpPascalExpressionPartOperatorArraySlice) if (Count = 2) and (Items[1] is TFpPascalExpressionPartOperatorArraySlice) and
TFpPascalExpressionPartOperatorArraySlice(Items[1]).Controller.CanDisableSlice
then begin then begin
TFpPascalExpressionPartOperatorArraySlice(Items[1]).Controller.DisableSlice := True;
Offs := TFpPascalExpressionPartOperatorArraySlice(Items[1]).StartValue; Offs := TFpPascalExpressionPartOperatorArraySlice(Items[1]).StartValue;
Len := TFpPascalExpressionPartOperatorArraySlice(Items[1]).EndValue - Offs + 1; Len := TFpPascalExpressionPartOperatorArraySlice(Items[1]).EndValue - Offs + 1;
TmpVal.GetSubString(Offs, Len, v); TmpVal.GetSubString(Offs, Len, v);
@ -6566,33 +6576,25 @@ begin
Result := Self; Result := Self;
end; end;
function TFpPascalExpressionPartOperatorArraySliceController.GetCanDisableSlice: boolean;
begin
Result := (not FResultValDone);
end;
function TFpPascalExpressionPartOperatorArraySliceController.DoGetResultValue: TFpValue; function TFpPascalExpressionPartOperatorArraySliceController.DoGetResultValue: TFpValue;
var var
tmp: TFpValue; tmp: TFpValue;
begin begin
if (FSlicePart.Parent <> nil) and
(FSlicePart.Parent is TFpPascalExpressionPartBracketIndex) and
(FSlicePart.Parent.Count = 2) // variable and ONE index
then begin
tmp := FSlicePart.Parent.Items[0].ResultValue;
if (tmp <> nil) and (Tmp.Kind in [skString, skAnsiString, skWideString])
then begin
// Handled in TFpPascalExpressionPartBracketIndex.DoGetResultValue
Result := Items[0].ResultValue;
if Result <> nil then
Result.AddReference;
exit;
end;
end;
FSlicePart.FCurrentIndex := FSlicePart.StartValue; FSlicePart.FCurrentIndex := FSlicePart.StartValue;
FSlicePart.FTouched := False; FSlicePart.FTouched := False;
ResetEvaluationForIndex; ResetEvaluationForIndex;
Result := Items[0].ResultValue; Result := Items[0].ResultValue;
if not FSlicePart.FTouched then begin if (not FSlicePart.FTouched) or DisableSlice then begin
// The array slice is not part of the expression ("? :" or Try) // The array slice is not part of the expression ("? :" or Try)
Result.AddReference; // Or already handled.
if Result <> nil then
Result.AddReference;
exit; exit;
end; end;
@ -6611,6 +6613,12 @@ begin
Result := TFpPasParserValueSlicedArray.Create(Self); Result := TFpPasParserValueSlicedArray.Create(Self);
end; end;
procedure TFpPascalExpressionPartOperatorArraySliceController.ResetEvaluation;
begin
inherited ResetEvaluation;
FDisableSlice := False;
end;
procedure TFpPascalExpressionPartOperatorArraySliceController.ResetEvaluationForIndex; procedure TFpPascalExpressionPartOperatorArraySliceController.ResetEvaluationForIndex;
begin begin
FInResetEvaluationForIndex := True; FInResetEvaluationForIndex := True;
@ -6651,7 +6659,7 @@ procedure TFpPascalExpressionPartOperatorArraySlice.SetParent(
AValue: TFpPascalExpressionPartContainer); AValue: TFpPascalExpressionPartContainer);
begin begin
if (Parent = nil) and (AValue <> nil) then if (Parent = nil) and (AValue <> nil) then
TFpPascalExpressionPartOperatorArraySliceController.Create(FExpression, FController := TFpPascalExpressionPartOperatorArraySliceController.Create(FExpression,
Self, AValue.TopParent, FStartChar, FEndChar); Self, AValue.TopParent, FStartChar, FEndChar);
inherited SetParent(AValue); inherited SetParent(AValue);