mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 12:19:16 +02:00
CodeTools: use TAVLTree in TTypeAliasOrderList instead of array of string.
git-svn-id: trunk@50261 -
This commit is contained in:
parent
f8980e1003
commit
99dee96a0a
@ -407,11 +407,18 @@ type
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// TTypeAliasOrderList is used for comparing type aliases in binary operators
|
// TTypeAliasOrderList is used for comparing type aliases in binary operators
|
||||||
|
|
||||||
|
TTypeAliasItem = class
|
||||||
|
public
|
||||||
|
AliasName: string;
|
||||||
|
Position: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
TTypeAliasOrderList = class
|
TTypeAliasOrderList = class
|
||||||
private
|
private
|
||||||
FList: array of string;
|
FTree: TAVLTree;
|
||||||
public
|
public
|
||||||
constructor Create(const AliasNames: array of string);
|
constructor Create(const AliasNames: array of string);
|
||||||
|
destructor Destroy; override;
|
||||||
|
|
||||||
procedure Add(const AliasName: string);
|
procedure Add(const AliasName: string);
|
||||||
procedure Add(const AliasNames: array of string);
|
procedure Add(const AliasNames: array of string);
|
||||||
@ -424,9 +431,11 @@ type
|
|||||||
function Compare(const AliasName1, AliasName2: string): Integer;
|
function Compare(const AliasName1, AliasName2: string): Integer;
|
||||||
function Compare(const Operand1, Operand2: TOperand;
|
function Compare(const Operand1, Operand2: TOperand;
|
||||||
Tool: TFindDeclarationTool; CleanPos: Integer): TOperand;
|
Tool: TFindDeclarationTool; CleanPos: Integer): TOperand;
|
||||||
|
|
||||||
function CalcMemSize: PtrUInt;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function CompareTypeAliasItems(Item1, Item2: Pointer): Integer;
|
||||||
|
function CompareTypeAliasItemString(AliasName, Item: Pointer): Integer;
|
||||||
|
|
||||||
type
|
type
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// TFoundProc is used for comparing overloaded procs
|
// TFoundProc is used for comparing overloaded procs
|
||||||
@ -1268,6 +1277,22 @@ begin
|
|||||||
Result:=xtNone;
|
Result:=xtNone;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function CompareTypeAliasItems(Item1, Item2: Pointer): Integer;
|
||||||
|
var
|
||||||
|
xItem1: TTypeAliasItem absolute Item1;
|
||||||
|
xItem2: TTypeAliasItem absolute Item2;
|
||||||
|
begin
|
||||||
|
Result := CompareIdentifiers(PChar(xItem1.AliasName), PChar(xItem2.AliasName));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CompareTypeAliasItemString(AliasName, Item: Pointer): Integer;
|
||||||
|
var
|
||||||
|
xAliasName: PChar absolute AliasName;
|
||||||
|
xItem: TTypeAliasItem absolute Item;
|
||||||
|
begin
|
||||||
|
Result := CompareIdentifiers(xAliasName, PChar(xItem.AliasName));
|
||||||
|
end;
|
||||||
|
|
||||||
function ExprTypeToString(const ExprType: TExpressionType): string;
|
function ExprTypeToString(const ExprType: TExpressionType): string;
|
||||||
begin
|
begin
|
||||||
Result:='Desc='+ExpressionTypeDescNames[ExprType.Desc]
|
Result:='Desc='+ExpressionTypeDescNames[ExprType.Desc]
|
||||||
@ -1424,42 +1449,31 @@ end;
|
|||||||
{ TTypeAliasOrderList }
|
{ TTypeAliasOrderList }
|
||||||
|
|
||||||
constructor TTypeAliasOrderList.Create(const AliasNames: array of string);
|
constructor TTypeAliasOrderList.Create(const AliasNames: array of string);
|
||||||
var
|
|
||||||
I: Integer;
|
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
SetLength(FList, Length(AliasNames));
|
FTree := TAVLTree.Create(@CompareTypeAliasItems);
|
||||||
for I := Low(AliasNames) to High(AliasNames) do
|
Add(AliasNames);
|
||||||
FList[I] := AliasNames[I];
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTypeAliasOrderList.Add(const AliasNames: array of string);
|
procedure TTypeAliasOrderList.Add(const AliasNames: array of string);
|
||||||
var
|
var
|
||||||
S: string;
|
AliasName: string;
|
||||||
begin
|
begin
|
||||||
for S in AliasNames do
|
for AliasName in AliasNames do
|
||||||
Add(S);
|
Add(AliasName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTypeAliasOrderList.Add(const AliasName: string);
|
procedure TTypeAliasOrderList.Add(const AliasName: string);
|
||||||
|
var
|
||||||
|
NewItem: TTypeAliasItem;
|
||||||
begin
|
begin
|
||||||
if IndexOf(AliasName) > -1 then Exit;
|
if IndexOf(AliasName) > -1 then Exit;
|
||||||
|
|
||||||
SetLength(FList, Length(FList)+1);
|
NewItem := TTypeAliasItem.Create;
|
||||||
FList[High(FList)]:=AliasName;
|
NewItem.AliasName := AliasName;
|
||||||
end;
|
NewItem.Position := FTree.Count;
|
||||||
|
FTree.Add(NewItem);
|
||||||
function TTypeAliasOrderList.CalcMemSize: PtrUInt;
|
|
||||||
var
|
|
||||||
S: string;
|
|
||||||
begin
|
|
||||||
Result :=
|
|
||||||
InstanceSize +
|
|
||||||
Length(FList)*SizeOf(Pointer);
|
|
||||||
|
|
||||||
for S in FList do
|
|
||||||
Result := Result + PtrUInt(Length(S)*SizeOf(Char));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTypeAliasOrderList.Compare(const AliasName1, AliasName2: string
|
function TTypeAliasOrderList.Compare(const AliasName1, AliasName2: string
|
||||||
@ -1511,11 +1525,21 @@ end;
|
|||||||
|
|
||||||
procedure TTypeAliasOrderList.Delete(const Pos: Integer);
|
procedure TTypeAliasOrderList.Delete(const Pos: Integer);
|
||||||
var
|
var
|
||||||
I: Integer;
|
xAVItem, xDelItem: TAVLTreeNode;
|
||||||
|
xItem: TTypeAliasItem;
|
||||||
begin
|
begin
|
||||||
for I := Pos to High(FList)-1 do
|
xDelItem := nil;
|
||||||
FList[I] := FList[I+1];
|
for xAVItem in FTree do
|
||||||
SetLength(FList, Length(FList)-1);
|
begin
|
||||||
|
xItem := TTypeAliasItem(xAVItem.Data);
|
||||||
|
if xItem.Position = Pos then
|
||||||
|
xDelItem := xAVItem
|
||||||
|
else if xItem.Position > Pos then
|
||||||
|
Dec(xItem.Position);
|
||||||
|
end;
|
||||||
|
|
||||||
|
if xDelItem<>nil then
|
||||||
|
FTree.FreeAndDelete(xDelItem);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTypeAliasOrderList.Delete(const AliasName: string);
|
procedure TTypeAliasOrderList.Delete(const AliasName: string);
|
||||||
@ -1527,23 +1551,42 @@ begin
|
|||||||
Delete(xIndex);
|
Delete(xIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTypeAliasOrderList.IndexOf(const AliasName: string): Integer;
|
destructor TTypeAliasOrderList.Destroy;
|
||||||
begin
|
begin
|
||||||
for Result := Low(FList) to High(FList) do
|
FTree.FreeAndClear;
|
||||||
if CompareText(AliasName, FList[Result]) = 0 then
|
FTree.Free;
|
||||||
Exit;
|
|
||||||
Result := -1;
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTypeAliasOrderList.IndexOf(const AliasName: string): Integer;
|
||||||
|
var
|
||||||
|
xAVNode: TAVLTreeNode;
|
||||||
|
begin
|
||||||
|
xAVNode := FTree.FindKey(PChar(AliasName), @CompareTypeAliasItemString);
|
||||||
|
if xAVNode<>nil then
|
||||||
|
Result := TTypeAliasItem(xAVNode.Data).Position
|
||||||
|
else
|
||||||
|
Result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTypeAliasOrderList.Insert(const AliasName: string; const Pos: Integer
|
procedure TTypeAliasOrderList.Insert(const AliasName: string; const Pos: Integer
|
||||||
);
|
);
|
||||||
var
|
var
|
||||||
I: Integer;
|
xAVItem: TAVLTreeNode;
|
||||||
|
xItem, NewItem: TTypeAliasItem;
|
||||||
begin
|
begin
|
||||||
SetLength(FList, Length(FList)+1);
|
for xAVItem in FTree do
|
||||||
for I := High(FList) downto Pos+1 do
|
begin
|
||||||
FList[I] := FList[I-1];
|
xItem := TTypeAliasItem(xAVItem.Data);
|
||||||
FList[Pos] := AliasName;
|
if xItem.Position >= Pos then
|
||||||
|
Inc(xItem.Position);
|
||||||
|
end;
|
||||||
|
|
||||||
|
NewItem := TTypeAliasItem.Create;
|
||||||
|
NewItem.AliasName := AliasName;
|
||||||
|
NewItem.Position := Pos;
|
||||||
|
FTree.Add(NewItem);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTypeAliasOrderList.InsertAfter(const AliasName, AfterAlias: string);
|
procedure TTypeAliasOrderList.InsertAfter(const AliasName, AfterAlias: string);
|
||||||
|
Loading…
Reference in New Issue
Block a user