mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 09:16:15 +02:00
cody: dictionary: delete non existing files
git-svn-id: trunk@33935 -
This commit is contained in:
parent
8522c6ff0b
commit
1acd926603
@ -293,7 +293,8 @@ function CompareAnsiStringPtrs(Data1, Data2: Pointer): integer;
|
|||||||
{$IF FPC_FULLVERSION<20701}
|
{$IF FPC_FULLVERSION<20701}
|
||||||
{$DEFINE EnableAVLFindPointerFix}
|
{$DEFINE EnableAVLFindPointerFix}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
function AVLFindPointer(Tree: TAVLTree; Data: Pointer): TAVLTreeNode; {$IFDEF EnableAVLFindPointerFix}inline;{$ENDIF}
|
function AVLFindPointer(Tree: TAVLTree; Data: Pointer): TAVLTreeNode; {$IFNDEF EnableAVLFindPointerFix}inline;{$ENDIF}
|
||||||
|
procedure AVLRemovePointer(Tree: TAVLTree; Data: Pointer); {$IFNDEF EnableAVLFindPointerFix}inline;{$ENDIF}
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -424,6 +425,21 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure AVLRemovePointer(Tree: TAVLTree; Data: Pointer);
|
||||||
|
{$IFDEF EnableAVLFindPointerFix}
|
||||||
|
var
|
||||||
|
Node: TAVLTreeNode;
|
||||||
|
{$ENDIF}
|
||||||
|
begin
|
||||||
|
{$IFDEF EnableAVLFindPointerFix}
|
||||||
|
Node:=AVLFindPointer(Tree,Data);
|
||||||
|
if Node<>nil then
|
||||||
|
Tree.Delete(Node);
|
||||||
|
{$ELSE}
|
||||||
|
Tree.RemovePointer(Data);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
{ TMTAVLTree }
|
{ TMTAVLTree }
|
||||||
|
|
||||||
constructor TMTAVLTree.Create(OnCompareMethod: TListSortCompare);
|
constructor TMTAVLTree.Create(OnCompareMethod: TListSortCompare);
|
||||||
|
@ -104,7 +104,7 @@ type
|
|||||||
property LoadAfterStartInS: integer read FLoadAfterStartInS write SetLoadAfterStartInS;
|
property LoadAfterStartInS: integer read FLoadAfterStartInS write SetLoadAfterStartInS;
|
||||||
procedure BeginCritSec;
|
procedure BeginCritSec;
|
||||||
procedure EndCritSec;
|
procedure EndCritSec;
|
||||||
procedure CheckFileAsync(aFilename: string);
|
procedure CheckFileAsync(aFilename: string); // check eventually if file exists and delete unit/group
|
||||||
property LoadSaveError: string read FLoadSaveError write SetLoadSaveError;
|
property LoadSaveError: string read FLoadSaveError write SetLoadSaveError;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -493,9 +493,8 @@ begin
|
|||||||
if UDGroup<>nil then
|
if UDGroup<>nil then
|
||||||
DeleteGroup(UDGroup,true);
|
DeleteGroup(UDGroup,true);
|
||||||
CurUnit:=FindUnitWithFilename(aFilename);
|
CurUnit:=FindUnitWithFilename(aFilename);
|
||||||
if CurUnit<>nil then begin
|
if CurUnit<>nil then
|
||||||
|
DeleteUnit(CurUnit,true);
|
||||||
end;
|
|
||||||
finally
|
finally
|
||||||
EndCritSec;
|
EndCritSec;
|
||||||
end;
|
end;
|
||||||
@ -761,10 +760,10 @@ begin
|
|||||||
inc(Found); // only count, do not check
|
inc(Found); // only count, do not check
|
||||||
end else begin
|
end else begin
|
||||||
Item:=TUDIdentifier(Node.Data);
|
Item:=TUDIdentifier(Node.Data);
|
||||||
GroupNode:=Item.DUnit.UnitGroups.FindLowest;
|
GroupNode:=Item.DUnit.Groups.FindLowest;
|
||||||
while GroupNode<>nil do begin
|
while GroupNode<>nil do begin
|
||||||
Group:=TUDUnitGroup(GroupNode.Data);
|
Group:=TUDUnitGroup(GroupNode.Data);
|
||||||
GroupNode:=Item.DUnit.UnitGroups.FindSuccessor(GroupNode);
|
GroupNode:=Item.DUnit.Groups.FindSuccessor(GroupNode);
|
||||||
if not FilenameIsAbsolute(Item.DUnit.Filename) then continue;
|
if not FilenameIsAbsolute(Item.DUnit.Filename) then continue;
|
||||||
if Group.Name='' then begin
|
if Group.Name='' then begin
|
||||||
// it's a unit without package
|
// it's a unit without package
|
||||||
@ -787,8 +786,8 @@ begin
|
|||||||
end else if FileExistsCached(Group.Filename) then begin
|
end else if FileExistsCached(Group.Filename) then begin
|
||||||
// lpk exists
|
// lpk exists
|
||||||
end else begin
|
end else begin
|
||||||
// lpk does not exist
|
// lpk does not exist any more
|
||||||
CodyUnitDictionary.BeginCritSec;
|
CodyUnitDictionary.CheckFileAsync(Group.Filename);
|
||||||
end;
|
end;
|
||||||
s:=Item.Name+' in '+Item.DUnit.Name;
|
s:=Item.Name+' in '+Item.DUnit.Name;
|
||||||
if Group.Name<>'' then
|
if Group.Name<>'' then
|
||||||
@ -799,6 +798,9 @@ begin
|
|||||||
FItems.Add(Item.Name+#10+Item.DUnit.Filename+#10+Group.Name+#10+Group.Filename);
|
FItems.Add(Item.Name+#10+Item.DUnit.Filename+#10+Group.Name+#10+Group.Filename);
|
||||||
sl.Add(s);
|
sl.Add(s);
|
||||||
end;
|
end;
|
||||||
|
end else begin
|
||||||
|
// unit does not exist any more
|
||||||
|
CodyUnitDictionary.CheckFileAsync(Item.DUnit.Filename);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -75,7 +75,7 @@ type
|
|||||||
FileAge: longint;
|
FileAge: longint;
|
||||||
ToolStamp: integer;
|
ToolStamp: integer;
|
||||||
FirstIdentifier, LastIdentifier: TUDIdentifier;
|
FirstIdentifier, LastIdentifier: TUDIdentifier;
|
||||||
UnitGroups: TMTAVLTree; // tree of TUDUnitGroup sorted with CompareIDItems
|
Groups: TMTAVLTree; // tree of TUDUnitGroup sorted with CompareIDItems
|
||||||
constructor Create(const aName, aFilename: string);
|
constructor Create(const aName, aFilename: string);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function AddIdentifier(Item: TUDIdentifier): TUDIdentifier;
|
function AddIdentifier(Item: TUDIdentifier): TUDIdentifier;
|
||||||
@ -133,6 +133,7 @@ type
|
|||||||
|
|
||||||
// units
|
// units
|
||||||
function AddUnit(const aFilename: string; aName: string = ''; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
function AddUnit(const aFilename: string; aName: string = ''; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
||||||
|
procedure DeleteUnit(TheUnit: TUDUnit; DeleteEmptyGroups: boolean);
|
||||||
function ParseUnit(UnitFilename: string; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
function ParseUnit(UnitFilename: string; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
||||||
function ParseUnit(Code: TCodeBuffer; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
function ParseUnit(Code: TCodeBuffer; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
||||||
function ParseUnit(Tool: TCodeTool; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
function ParseUnit(Tool: TCodeTool; Group: TUDUnitGroup = nil): TUDUnit; overload;
|
||||||
@ -216,13 +217,13 @@ begin
|
|||||||
ToolStamp:=CTInvalidChangeStamp;
|
ToolStamp:=CTInvalidChangeStamp;
|
||||||
IDCheckUnitNameAndFilename(aName,aFilename);
|
IDCheckUnitNameAndFilename(aName,aFilename);
|
||||||
inherited Create(aName,aFilename);
|
inherited Create(aName,aFilename);
|
||||||
UnitGroups:=TMTAVLTree.Create(@CompareIDItems);
|
Groups:=TMTAVLTree.Create(@CompareIDItems);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TUDUnit.Destroy;
|
destructor TUDUnit.Destroy;
|
||||||
begin
|
begin
|
||||||
// the groups are freed by the TUnitDictionary
|
// the groups are freed by the TUnitDictionary
|
||||||
FreeAndNil(UnitGroups);
|
FreeAndNil(Groups);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -256,12 +257,12 @@ end;
|
|||||||
|
|
||||||
function TUDUnit.IsInGroup(Group: TUDUnitGroup): boolean;
|
function TUDUnit.IsInGroup(Group: TUDUnitGroup): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=AVLFindPointer(UnitGroups,Group)<>nil;
|
Result:=AVLFindPointer(Groups,Group)<>nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TUDUnit.GetDictionary: TUnitDictionary;
|
function TUDUnit.GetDictionary: TUnitDictionary;
|
||||||
begin
|
begin
|
||||||
Result:=TUDUnitGroup(UnitGroups.Root.Data).Dictionary;
|
Result:=TUDUnitGroup(Groups.Root.Data).Dictionary;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TUDUnit.HasIdentifier(Item: TUDIdentifier): boolean;
|
function TUDUnit.HasIdentifier(Item: TUDIdentifier): boolean;
|
||||||
@ -297,7 +298,7 @@ begin
|
|||||||
Result:=NewUnit;
|
Result:=NewUnit;
|
||||||
if AVLFindPointer(Units,NewUnit)<>nil then exit;
|
if AVLFindPointer(Units,NewUnit)<>nil then exit;
|
||||||
Units.Add(Result);
|
Units.Add(Result);
|
||||||
Result.UnitGroups.Add(Self);
|
Result.Groups.Add(Self);
|
||||||
if (Dictionary.NoGroup<>Self) then
|
if (Dictionary.NoGroup<>Self) then
|
||||||
Dictionary.NoGroup.RemoveUnit(NewUnit);
|
Dictionary.NoGroup.RemoveUnit(NewUnit);
|
||||||
Dictionary.IncreaseChangeStamp;
|
Dictionary.IncreaseChangeStamp;
|
||||||
@ -307,7 +308,7 @@ procedure TUDUnitGroup.RemoveUnit(TheUnit: TUDUnit);
|
|||||||
begin
|
begin
|
||||||
if AVLFindPointer(Units,TheUnit)=nil then exit;
|
if AVLFindPointer(Units,TheUnit)=nil then exit;
|
||||||
Units.RemovePointer(TheUnit);
|
Units.RemovePointer(TheUnit);
|
||||||
TheUnit.UnitGroups.RemovePointer(Self);
|
TheUnit.Groups.RemovePointer(Self);
|
||||||
Dictionary.IncreaseChangeStamp;
|
Dictionary.IncreaseChangeStamp;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -403,14 +404,14 @@ begin
|
|||||||
e('unit '+CurUnit.Name+' without filename');
|
e('unit '+CurUnit.Name+' without filename');
|
||||||
if AVLFindPointer(FUnitsByFilename,CurUnit)=nil then
|
if AVLFindPointer(FUnitsByFilename,CurUnit)=nil then
|
||||||
e('unit '+CurUnit.Name+' in FUnitsByName not in FUnitsByFilename');
|
e('unit '+CurUnit.Name+' in FUnitsByName not in FUnitsByFilename');
|
||||||
if CurUnit.UnitGroups.Count=0 then
|
if CurUnit.Groups.Count=0 then
|
||||||
e('unit '+CurUnit.Name+' has not group');
|
e('unit '+CurUnit.Name+' has not group');
|
||||||
if CurUnit.UnitGroups.ConsistencyCheck<>0 then
|
if CurUnit.Groups.ConsistencyCheck<>0 then
|
||||||
e('unit '+CurUnit.Name+' UnitGroups.ConsistencyCheck<>0');
|
e('unit '+CurUnit.Name+' UnitGroups.ConsistencyCheck<>0');
|
||||||
if (LastUnit<>nil)
|
if (LastUnit<>nil)
|
||||||
and (CompareFilenames(LastUnit.Filename,CurUnit.Filename)=0) then
|
and (CompareFilenames(LastUnit.Filename,CurUnit.Filename)=0) then
|
||||||
e('unit '+CurUnit.Name+' exists twice: '+CurUnit.Filename);
|
e('unit '+CurUnit.Name+' exists twice: '+CurUnit.Filename);
|
||||||
SubAVLNode:=CurUnit.UnitGroups.FindLowest;
|
SubAVLNode:=CurUnit.Groups.FindLowest;
|
||||||
LastGroup:=nil;
|
LastGroup:=nil;
|
||||||
while SubAVLNode<>nil do begin
|
while SubAVLNode<>nil do begin
|
||||||
Group:=TUDUnitGroup(SubAVLNode.Data);
|
Group:=TUDUnitGroup(SubAVLNode.Data);
|
||||||
@ -419,7 +420,7 @@ begin
|
|||||||
if LastGroup=Group then
|
if LastGroup=Group then
|
||||||
e('unit '+CurUnit.Name+' twice in group '+Group.Filename);
|
e('unit '+CurUnit.Name+' twice in group '+Group.Filename);
|
||||||
LastGroup:=Group;
|
LastGroup:=Group;
|
||||||
SubAVLNode:=CurUnit.UnitGroups.FindSuccessor(SubAVLNode);
|
SubAVLNode:=CurUnit.Groups.FindSuccessor(SubAVLNode);
|
||||||
end;
|
end;
|
||||||
LastUnit:=CurUnit;
|
LastUnit:=CurUnit;
|
||||||
AVLNode:=UnitsByName.FindSuccessor(AVLNode);
|
AVLNode:=UnitsByName.FindSuccessor(AVLNode);
|
||||||
@ -459,7 +460,7 @@ begin
|
|||||||
LastUnit:=nil;
|
LastUnit:=nil;
|
||||||
while SubAVLNode<>nil do begin
|
while SubAVLNode<>nil do begin
|
||||||
CurUnit:=TUDUnit(SubAVLNode.Data);
|
CurUnit:=TUDUnit(SubAVLNode.Data);
|
||||||
if AVLFindPointer(CurUnit.UnitGroups,Group)=nil then
|
if AVLFindPointer(CurUnit.Groups,Group)=nil then
|
||||||
e('group '+Group.Name+' has not the unit '+CurUnit.Name);
|
e('group '+Group.Name+' has not the unit '+CurUnit.Name);
|
||||||
if LastUnit=CurUnit then
|
if LastUnit=CurUnit then
|
||||||
e('group '+Group.Name+' has unit twice '+CurUnit.Filename);
|
e('group '+Group.Name+' has unit twice '+CurUnit.Filename);
|
||||||
@ -974,8 +975,32 @@ end;
|
|||||||
|
|
||||||
procedure TUnitDictionary.DeleteGroup(Group: TUDUnitGroup;
|
procedure TUnitDictionary.DeleteGroup(Group: TUDUnitGroup;
|
||||||
DeleteUnitsWithoutGroup: boolean);
|
DeleteUnitsWithoutGroup: boolean);
|
||||||
|
var
|
||||||
|
Node: TAVLTreeNode;
|
||||||
|
CurUnit: TUDUnit;
|
||||||
begin
|
begin
|
||||||
|
if Group=NoGroup then
|
||||||
|
raise Exception.Create('The default group can not be deleted');
|
||||||
|
// remove units
|
||||||
|
Node:=Group.Units.FindLowest;
|
||||||
|
while Node<>nil do begin
|
||||||
|
CurUnit:=TUDUnit(Node.Data);
|
||||||
|
AVLRemovePointer(CurUnit.Groups,Group);
|
||||||
|
if CurUnit.Groups.Count=0 then begin
|
||||||
|
if DeleteUnitsWithoutGroup then
|
||||||
|
DeleteUnit(CurUnit,false)
|
||||||
|
else
|
||||||
|
NoGroup.AddUnit(CurUnit);
|
||||||
|
end;
|
||||||
|
Node:=Group.Units.FindSuccessor(Node);
|
||||||
|
end;
|
||||||
|
Group.Units.Clear;
|
||||||
|
// remove group from trees
|
||||||
|
AVLRemovePointer(UnitGroupsByFilename,Group);
|
||||||
|
AVLRemovePointer(UnitGroupsByName,Group);
|
||||||
|
// free group
|
||||||
|
Group.Free;
|
||||||
|
IncreaseChangeStamp;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TUnitDictionary.FindGroupWithFilename(const aFilename: string
|
function TUnitDictionary.FindGroupWithFilename(const aFilename: string
|
||||||
@ -1005,6 +1030,39 @@ begin
|
|||||||
Group.AddUnit(Result);
|
Group.AddUnit(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TUnitDictionary.DeleteUnit(TheUnit: TUDUnit;
|
||||||
|
DeleteEmptyGroups: boolean);
|
||||||
|
var
|
||||||
|
Node: TAVLTreeNode;
|
||||||
|
Group: TUDUnitGroup;
|
||||||
|
Item: TUDIdentifier;
|
||||||
|
begin
|
||||||
|
Node:=TheUnit.Groups.FindLowest;
|
||||||
|
// remove unit from groups
|
||||||
|
while Node<>nil do begin
|
||||||
|
Group:=TUDUnitGroup(Node.Data);
|
||||||
|
AVLRemovePointer(Group.Units,TheUnit);
|
||||||
|
if DeleteEmptyGroups and (Group.Units.Count=0)
|
||||||
|
and (Group<>NoGroup) then
|
||||||
|
DeleteGroup(Group,false);
|
||||||
|
Node:=TheUnit.Groups.FindSuccessor(Node);
|
||||||
|
end;
|
||||||
|
TheUnit.Groups.Clear;
|
||||||
|
// free identifiers
|
||||||
|
while TheUnit.FirstIdentifier<>nil do begin
|
||||||
|
Item:=TheUnit.FirstIdentifier;
|
||||||
|
AVLRemovePointer(Identifiers,Item);
|
||||||
|
Item.Free;
|
||||||
|
TheUnit.FirstIdentifier:=Item.NextInUnit;
|
||||||
|
end;
|
||||||
|
// remove unit from dictionary
|
||||||
|
AVLRemovePointer(UnitsByFilename,TheUnit);
|
||||||
|
AVLRemovePointer(UnitsByName,TheUnit);
|
||||||
|
// free unit
|
||||||
|
TheUnit.Free;
|
||||||
|
IncreaseChangeStamp;
|
||||||
|
end;
|
||||||
|
|
||||||
function TUnitDictionary.ParseUnit(UnitFilename: string; Group: TUDUnitGroup
|
function TUnitDictionary.ParseUnit(UnitFilename: string; Group: TUDUnitGroup
|
||||||
): TUDUnit;
|
): TUDUnit;
|
||||||
var
|
var
|
||||||
@ -1102,6 +1160,7 @@ begin
|
|||||||
Result.FirstIdentifier:=NextItem;
|
Result.FirstIdentifier:=NextItem;
|
||||||
if Result.LastIdentifier=CurItem then
|
if Result.LastIdentifier=CurItem then
|
||||||
Result.LastIdentifier:=PrevItem;
|
Result.LastIdentifier:=PrevItem;
|
||||||
|
AVLRemovePointer(Identifiers,CurItem);
|
||||||
CurItem.Free;
|
CurItem.Free;
|
||||||
CurItem:=NextItem;
|
CurItem:=NextItem;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user