MG: bugfixes, finddeclaration cache dependencies

git-svn-id: trunk@1579 -
This commit is contained in:
lazarus 2002-04-02 16:44:41 +00:00
parent 47e3ef52e6
commit 0e2a403556
6 changed files with 262 additions and 31 deletions

View File

@ -45,6 +45,7 @@ type
procedure Add(ANode: TAVLTreeNode); procedure Add(ANode: TAVLTreeNode);
function Add(Data: Pointer): TAVLTreeNode; function Add(Data: Pointer): TAVLTreeNode;
procedure Delete(ANode: TAVLTreeNode); procedure Delete(ANode: TAVLTreeNode);
procedure Remove(Data: Pointer);
procedure MoveDataLeftMost(var ANode: TAVLTreeNode); procedure MoveDataLeftMost(var ANode: TAVLTreeNode);
procedure MoveDataRightMost(var ANode: TAVLTreeNode); procedure MoveDataRightMost(var ANode: TAVLTreeNode);
property OnCompare: TListSortCompare read FOnCompare write SetOnCompare; property OnCompare: TListSortCompare read FOnCompare write SetOnCompare;
@ -56,6 +57,7 @@ type
procedure WriteReportToStream(s: TStream; var StreamSize: integer); procedure WriteReportToStream(s: TStream; var StreamSize: integer);
function ReportAsString: string; function ReportAsString: string;
constructor Create(OnCompareMethod: TListSortCompare); constructor Create(OnCompareMethod: TListSortCompare);
constructor Create;
destructor Destroy; override; destructor Destroy; override;
end; end;
@ -81,11 +83,20 @@ type
destructor Destroy; override; destructor Destroy; override;
end; end;
implementation implementation
var NodeMemManager: TAVLTreeNodeMemManager; var NodeMemManager: TAVLTreeNodeMemManager;
function ComparePointer(Data1, Data2: Pointer): integer;
begin
if Data1>Data2 then Result:=-1
else if Data1<Data2 then Result:=1
else Result:=0;
end;
{ TAVLTree } { TAVLTree }
function TAVLTree.Add(Data: Pointer): TAVLTreeNode; function TAVLTree.Add(Data: Pointer): TAVLTreeNode;
@ -446,6 +457,11 @@ begin
FCount:=0; FCount:=0;
end; end;
constructor TAVLTree.Create;
begin
Create(@ComparePointer);
end;
procedure TAVLTree.Delete(ANode: TAVLTreeNode); procedure TAVLTree.Delete(ANode: TAVLTreeNode);
var OldParent, OldLeft, OldRight, Successor, OldSuccParent, OldSuccLeft, var OldParent, OldLeft, OldRight, Successor, OldSuccParent, OldSuccLeft,
OldSuccRight: TAVLTreeNode; OldSuccRight: TAVLTreeNode;
@ -568,6 +584,14 @@ begin
Delete(ANode); Delete(ANode);
end; end;
procedure TAVLTree.Remove(Data: Pointer);
var ANode: TAVLTreeNode;
begin
ANode:=Find(Data);
if ANode<>nil then
Delete(ANode);
end;
destructor TAVLTree.Destroy; destructor TAVLTree.Destroy;
begin begin
Clear; Clear;
@ -709,6 +733,7 @@ var RealCount: integer;
Result:=-2; exit; Result:=-2; exit;
end; end;
if OnCompare(ANode.Left.Data,ANode.Data)>0 then begin if OnCompare(ANode.Left.Data,ANode.Data)>0 then begin
writeln('CCC-3 ',HexStr(Cardinal(ANode.Data),8),' ',HexStr(Cardinal(ANode.Left.Data),8));
Result:=-3; exit; Result:=-3; exit;
end; end;
Result:=CheckNode(ANode.Left); Result:=CheckNode(ANode.Left);
@ -720,6 +745,7 @@ var RealCount: integer;
Result:=-4; exit; Result:=-4; exit;
end; end;
if OnCompare(ANode.Data,ANode.Right.Data)>0 then begin if OnCompare(ANode.Data,ANode.Right.Data)>0 then begin
writeln('CCC-5 ',HexStr(Cardinal(ANode.Data),8),' ',HexStr(Cardinal(ANode.Right.Data),8));
Result:=-5; exit; Result:=-5; exit;
end; end;
Result:=CheckNode(ANode.Right); Result:=CheckNode(ANode.Right);

View File

@ -168,6 +168,17 @@ type
destructor Destroy; override; destructor Destroy; override;
end; end;
{
4. CodeTool Cache Dependencies
Node- and BaseTypeCache depends on their codetool and the
node- and basetypecaches of other codetools (=used codetools). The used
codetools dependencies are saved in the TCodeToolDependencies, which is
simple an TAVLTree of codetools. This allows to decide, wether the cache of
a codetools must be rebuild.
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
type type

View File

@ -258,6 +258,9 @@ type
FLastNodeCachesGlobalWriteLockStep: integer; FLastNodeCachesGlobalWriteLockStep: integer;
FRootNodeCache: TCodeTreeNodeCache; FRootNodeCache: TCodeTreeNodeCache;
FFirstBaseTypeCache: TBaseTypeCache; FFirstBaseTypeCache: TBaseTypeCache;
FDependentCodeTools: TAVLTree;// the codetools, that depend on this codetool
FDependsOnCodeTools: TAVLTree;// the codetools, that this codetool depends on
FClearingDependentNodeCaches: boolean;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
DebugPrefix: string; DebugPrefix: string;
procedure IncPrefix; procedure IncPrefix;
@ -295,6 +298,9 @@ type
protected protected
procedure DoDeleteNodes; override; procedure DoDeleteNodes; override;
procedure ClearNodeCaches(Force: boolean); procedure ClearNodeCaches(Force: boolean);
procedure ClearDependentNodeCaches;
procedure ClearDependsOnToolRelationships;
procedure AddToolDependency(DependOnTool: TFindDeclarationTool);
function CreateNewNodeCache(Node: TCodeTreeNode): TCodeTreeNodeCache; function CreateNewNodeCache(Node: TCodeTreeNode): TCodeTreeNodeCache;
function CreateNewBaseTypeCache(Node: TCodeTreeNode): TBaseTypeCache; function CreateNewBaseTypeCache(Node: TCodeTreeNode): TBaseTypeCache;
procedure CreateBaseTypeCaches(NodeStack: PCodeTreeNodeStack; procedure CreateBaseTypeCaches(NodeStack: PCodeTreeNodeStack;
@ -370,7 +376,6 @@ type
read FOnGetCodeToolForBuffer write FOnGetCodeToolForBuffer; read FOnGetCodeToolForBuffer write FOnGetCodeToolForBuffer;
property OnGetUnitSourceSearchPath: TOnGetSearchPath property OnGetUnitSourceSearchPath: TOnGetSearchPath
read FOnGetUnitSourceSearchPath write FOnGetUnitSourceSearchPath; read FOnGetUnitSourceSearchPath write FOnGetUnitSourceSearchPath;
procedure ActivateGlobalWriteLock; override;
function ConsistencyCheck: integer; override; function ConsistencyCheck: integer; override;
end; end;
@ -2875,7 +2880,6 @@ begin
// ToDo: build codetree for ppu, ppw, dcu files // ToDo: build codetree for ppu, ppw, dcu files
// build tree for pascal source // build tree for pascal source
ClearNodeCaches(false);
BuildTree(true); BuildTree(true);
// search identifier in cache // search identifier in cache
@ -2936,7 +2940,7 @@ begin
FInterfaceIdentifierCache.Add(OldInput.Identifier,Params.NewNode, FInterfaceIdentifierCache.Add(OldInput.Identifier,Params.NewNode,
Params.NewCleanPos); Params.NewCleanPos);
end else begin end else begin
// do not save proc identifiers. // do not save proc identifiers
end; end;
end else end else
// identifier does not exist in interface // identifier does not exist in interface
@ -3017,6 +3021,7 @@ begin
Params.Flags:=[fdfIgnoreUsedUnits]+(fdfGlobalsSameIdent*Params.Flags) Params.Flags:=[fdfIgnoreUsedUnits]+(fdfGlobalsSameIdent*Params.Flags)
-[fdfExceptionOnNotFound]; -[fdfExceptionOnNotFound];
Result:=NewCodeTool.FindIdentifierInInterface(Self,Params); Result:=NewCodeTool.FindIdentifierInInterface(Self,Params);
AddToolDependency(NewCodeTool);
if Result then if Result then
// do not reload param input, so that find next is possible // do not reload param input, so that find next is possible
exit exit
@ -3990,6 +3995,10 @@ destructor TFindDeclarationTool.Destroy;
begin begin
FInterfaceIdentifierCache.Free; FInterfaceIdentifierCache.Free;
FInterfaceIdentifierCache:=nil; FInterfaceIdentifierCache:=nil;
FDependsOnCodeTools.Free;
FDependsOnCodeTools:=nil;
FDependentCodeTools.Free;
FDependentCodeTools:=nil;
inherited Destroy; inherited Destroy;
end; end;
@ -4000,9 +4009,15 @@ var
GlobalWriteLockStep: integer; GlobalWriteLockStep: integer;
BaseTypeCache: TBaseTypeCache; BaseTypeCache: TBaseTypeCache;
begin begin
if not Force then begin // clear dependent codetools
// check if node cache must be cleared ClearDependentNodeCaches;
if Assigned(OnGetGlobalWriteLockInfo) then begin ClearDependsOnToolRelationships;
// check if there is something cached
if (FFirstNodeCache=nil) and (FFirstBaseTypeCache=nil)
and (FRootNodeCache=nil) then
exit;
// quick check: check if in the same GlobalWriteLockStep
if (not Force) and Assigned(OnGetGlobalWriteLockInfo) then begin
OnGetGlobalWriteLockInfo(GlobalWriteLockIsSet,GlobalWriteLockStep); OnGetGlobalWriteLockInfo(GlobalWriteLockIsSet,GlobalWriteLockStep);
if GlobalWriteLockIsSet then begin if GlobalWriteLockIsSet then begin
// The global write lock is set. That means, input variables and code // The global write lock is set. That means, input variables and code
@ -4017,7 +4032,6 @@ begin
end; end;
end; end;
end; end;
end;
// clear node caches // clear node caches
while FFirstNodeCache<>nil do begin while FFirstNodeCache<>nil do begin
NodeCache:=FFirstNodeCache; NodeCache:=FFirstNodeCache;
@ -4035,6 +4049,57 @@ begin
end; end;
end; end;
procedure TFindDeclarationTool.ClearDependentNodeCaches;
var
ANode: TAVLTreeNode;
ATool: TFindDeclarationTool;
begin
if (FDependentCodeTools=nil) or FClearingDependentNodeCaches then exit;
FClearingDependentNodeCaches:=true;
try
ANode:=FDependentCodeTools.FindLowest;
while ANode<>nil do begin
ATool:=TFindDeclarationTool(ANode.Data);
ATool.ClearNodeCaches(true);
ANode:=FDependentCodeTools.FindSuccessor(ANode);
end;
FDependentCodeTools.Clear;
finally
FClearingDependentNodeCaches:=false;
end;
end;
procedure TFindDeclarationTool.ClearDependsOnToolRelationships;
var
ANode: TAVLTreeNode;
ATool: TFindDeclarationTool;
begin
if FDependsOnCodeTools=nil then exit;
ANode:=FDependsOnCodeTools.FindLowest;
while ANode<>nil do begin
ATool:=TFindDeclarationTool(ANode.Data);
if not ATool.FClearingDependentNodeCaches then
ATool.FDependentCodeTools.Remove(Self);
ANode:=FDependsOnCodeTools.FindSuccessor(ANode);
end;
FDependsOnCodeTools.Clear;
end;
procedure TFindDeclarationTool.AddToolDependency(
DependOnTool: TFindDeclarationTool);
// this tool depends on DependOnTool
begin
if DependOnTool.FDependentCodeTools=nil then
DependOnTool.FDependentCodeTools:=TAVLTree.Create;
if DependOnTool.FDependentCodeTools.Find(Self)=nil then
DependOnTool.FDependentCodeTools.Add(Self);
if FDependsOnCodeTools=nil then
FDependsOnCodeTools:=TAVLTree.Create;
if FDependsOnCodeTools.Find(DependOnTool)=nil then begin
FDependsOnCodeTools.Add(DependOnTool);
end;
end;
function TFindDeclarationTool.ConsistencyCheck: integer; function TFindDeclarationTool.ConsistencyCheck: integer;
var ANodeCache: TCodeTreeNodeCache; var ANodeCache: TCodeTreeNodeCache;
begin begin
@ -4052,12 +4117,20 @@ begin
end; end;
ANodeCache:=ANodeCache.Next; ANodeCache:=ANodeCache.Next;
end; end;
end; if FDependentCodeTools<>nil then begin
Result:=FDependentCodeTools.ConsistencyCheck;
procedure TFindDeclarationTool.ActivateGlobalWriteLock; if Result<>0 then begin
begin dec(Result,200);
inherited; exit;
ClearNodeCaches(false); end;
end;
if FDependsOnCodeTools<>nil then begin
Result:=FDependsOnCodeTools.ConsistencyCheck;
if Result<>0 then begin
dec(Result,300);
exit;
end;
end;
end; end;
function TFindDeclarationTool.GetNodeCache(Node: TCodeTreeNode; function TFindDeclarationTool.GetNodeCache(Node: TCodeTreeNode;

View File

@ -1,4 +1,11 @@
{ $Id$ }
{ {
/***************************************************************************
findreplacedialog.pp
--------------------
***************************************************************************/
Author: Mattias Gaertner Author: Mattias Gaertner
Abstract: Abstract:
@ -73,6 +80,7 @@ type
procedure OkButtonClick(Sender:TObject); procedure OkButtonClick(Sender:TObject);
procedure ReplaceAllButtonClick(Sender:TObject); procedure ReplaceAllButtonClick(Sender:TObject);
procedure CancelButtonClick(Sender:TObject); procedure CancelButtonClick(Sender:TObject);
procedure FormResize(Sender: TObject);
property Options:TSynSearchOptions read GetOptions write SetOptions; property Options:TSynSearchOptions read GetOptions write SetOptions;
property FindText:AnsiString read GetFindText write SetFindText; property FindText:AnsiString read GetFindText write SetFindText;
property ReplaceText:AnsiString read GetReplaceText write SetReplaceText; property ReplaceText:AnsiString read GetReplaceText write SetReplaceText;
@ -96,7 +104,7 @@ begin
inherited Create(TheOwner); inherited Create(TheOwner);
if LazarusResources.Find(ClassName)=nil then begin if LazarusResources.Find(ClassName)=nil then begin
Caption:=''; Caption:='';
Width:=317; Width:=400;
Height:=285; Height:=285;
{$IFDEF DeleteMeWhenComboBoxFocusIsFixed} {$IFDEF DeleteMeWhenComboBoxFocusIsFixed}
@ -316,8 +324,11 @@ begin
OnClick:=@CancelButtonClick; OnClick:=@CancelButtonClick;
Visible:=true; Visible:=true;
end; end;
OnResize:=@FormResize;
end; end;
fReplaceAllClickedLast:=false; fReplaceAllClickedLast:=false;
FormResize(Self);
TextToFindComboBox.SetFocus; TextToFindComboBox.SetFocus;
end; end;
@ -363,6 +374,109 @@ begin
ModalResult:=mrCancel; ModalResult:=mrCancel;
end; end;
procedure TLazFindReplaceDialog.FormResize(Sender: TObject);
var MaxX, TxtLabelWidth, OptionsWidth, ButtonWidth: integer;
begin
TxtLabelWidth:=100;
MaxX:=ClientWidth;
OptionsWidth:=(MaxX-3*4) div 2;
ButtonWidth:=90;
with TextToFindLabel do begin
Left:=8;
Top:=8;
Width:=TxtLabelWidth;
end;
with TextToFindComboBox do begin
Left:=TextToFindLabel.Left+TextToFindLabel.Width+2;
Top:=TextToFindLabel.Top-4;
Width:=MaxX-Left-4;
end;
with ReplaceWithLabel do begin
Left:=TextToFindLabel.Left;
Top:=TextToFindLabel.Top+TextToFindLabel.Height+8;
Width:=TextToFindLabel.Width;
end;
with ReplaceTextComboBox do begin
Left:=TextToFindComboBox.Left;
Top:=ReplaceWithLabel.Top-4;
Width:=MaxX-Left-4;
end;
with OptionsGroupBox do begin
Left:=4;
Top:=ReplaceWithLabel.Top+ReplaceWithLabel.Height+3;
Width:=OptionsWidth;
Height:=110;
end;
with CaseSensitiveCheckBox do begin
Left:=8;
Top:=3;
Width:=Parent.ClientWidth-Left;
end;
with WholeWordsOnlyCheckBox do begin
Left:=8;
Top:=CaseSensitiveCheckBox.Top+CaseSensitiveCheckBox.Height+5;
Width:=Parent.ClientWidth-Left;
end;
with RegularExpressionsCheckBox do begin
Left:=8;
Top:=WholeWordsOnlyCheckBox.Top+WholeWordsOnlyCheckBox.Height+5;
Width:=Parent.ClientWidth-Left;
end;
with PromptOnReplaceCheckBox do begin
Left:=8;
Top:=RegularExpressionsCheckBox.Top+RegularExpressionsCheckBox.Height+5;
Width:=Parent.ClientWidth-Left;
end;
with OriginRadioGroup do begin
Left:=OptionsGroupBox.Left+OptionsGroupBox.Width+4;
Top:=OptionsGroupBox.Top;
Width:=OptionsWidth;
Height:=OptionsGroupBox.Height;
end;
with ScopeRadioGroup do begin
Left:=OptionsGroupBox.Left;
Top:=OptionsGroupBox.Top+OptionsGroupBox.Height+5;
Width:=OptionsWidth;
Height:=65;
end;
with DirectionRadioGroup do begin
Left:=OriginRadioGroup.Left;
Top:=OriginRadioGroup.Top+OriginRadioGroup.Height+5;
Width:=OptionsWidth;
Height:=65;
end;
with OkButton do begin
Left:=MaxX-10-3*(ButtonWidth+7);
Top:=245;
Width:=75;
end;
with ReplaceAllButton do begin
Left:=MaxX-10-2*(ButtonWidth+7);
Top:=245;
Width:=75;
end;
with CancelButton do begin
Left:=MaxX-10-1*(ButtonWidth+7);
Top:=245;
Width:=75;
end;
end;
function TLazFindReplaceDialog.GetComponentText(c: TFindDlgComponent): string; function TLazFindReplaceDialog.GetComponentText(c: TFindDlgComponent): string;
begin begin
case c of case c of

View File

@ -1,4 +1,4 @@
// included by stdctrls.pp
function TButtonControl.GetChecked: Boolean; function TButtonControl.GetChecked: Boolean;
@ -18,4 +18,5 @@ begin
end; end;
{------------------------------------------------------------------------------} // included by stdctrls.pp

View File

@ -1,3 +1,5 @@
// included by stdctrls.pp
{****************************************************************************** {******************************************************************************
TCustomCheckbox TCustomCheckbox
******************************************************************************} ******************************************************************************}
@ -153,6 +155,9 @@ end;
{ {
$Log$ $Log$
Revision 1.3 2002/04/02 16:44:41 lazarus
MG: bugfixes, finddeclaration cache dependencies
Revision 1.2 2002/02/08 16:45:09 lazarus Revision 1.2 2002/02/08 16:45:09 lazarus
MG: added codetools options MG: added codetools options
@ -190,4 +195,5 @@ end;
stoppok stoppok
} }
// included by stdctrls.pp