codetools: fixed CompareTextIgnoringSpace, bug #12177

git-svn-id: trunk@16635 -
This commit is contained in:
mattias 2008-09-18 20:00:12 +00:00
parent 874285d5bb
commit d8e36f10fb
3 changed files with 37 additions and 9 deletions

View File

@ -2503,13 +2503,10 @@ function CompareTextIgnoringSpace(Txt1: PChar; Len1: integer;
A; A -1 A; A -1
} }
var P1, P2: integer; var P1, P2: integer;
InIdentifier: boolean;
begin begin
P1:=0; P1:=0;
P2:=0; P2:=0;
InIdentifier:=false;
while (P1<Len1) and (P2<Len2) do begin while (P1<Len1) and (P2<Len2) do begin
//DebugLn('CompareTextIgnoringSpace P1=',dbgs(P1),' P2=',dbgs(P2));
if (CaseSensitive and (Txt1[P1]=Txt2[P2])) if (CaseSensitive and (Txt1[P1]=Txt2[P2]))
or ((not CaseSensitive) and (UpChars[Txt1[P1]]=UpChars[Txt2[P2]])) then or ((not CaseSensitive) and (UpChars[Txt1[P1]]=UpChars[Txt2[P2]])) then
begin begin
@ -2517,7 +2514,8 @@ begin
inc(P2); inc(P2);
end else begin end else begin
// different chars found // different chars found
if InIdentifier and (IsIdentChar[Txt1[P1]] xor IsIdentChar[Txt2[P2]]) then begin if (P1>0) and (IsIdentChar[Txt1[P1-1]])
and (IsIdentChar[Txt1[P1]] xor IsIdentChar[Txt2[P2]]) then begin
// one identifier is longer than the other // one identifier is longer than the other
if IsIdentChar[Txt1[P1]] then if IsIdentChar[Txt1[P1]] then
// identifier in Txt1 is longer than in Txt2 // identifier in Txt1 is longer than in Txt2
@ -2552,7 +2550,6 @@ begin
exit; exit;
end; end;
end; end;
InIdentifier:=IsIdentChar[Txt1[P1]];
end; end;
// one text was totally read -> check the rest of the other one // one text was totally read -> check the rest of the other one
// skip spaces // skip spaces

View File

@ -5549,6 +5549,7 @@ var
FirstExistingProcBody:=ANode; FirstExistingProcBody:=ANode;
if ANode.StartPos>LastExistingProcBody.StartPos then if ANode.StartPos>LastExistingProcBody.StartPos then
LastExistingProcBody:=ANode; LastExistingProcBody:=ANode;
//DebugLn(['FindTopMostAndBottomMostProcBodies ',TCodeTreeNodeExtension(ExistingNode.Data).Txt]);
ExistingNode:=ProcBodyNodes.FindSuccessor(ExistingNode); ExistingNode:=ProcBodyNodes.FindSuccessor(ExistingNode);
end; end;
end; end;
@ -5690,7 +5691,7 @@ begin
{AnAVLNode:=ClassProcs.FindLowest; {AnAVLNode:=ClassProcs.FindLowest;
while AnAVLNode<>nil do begin while AnAVLNode<>nil do begin
DebugLn(' AAA ',TCodeTreeNodeExtension(AnAVLNode.Data).Txt); DebugLn(' Existing proc headers: ',TCodeTreeNodeExtension(AnAVLNode.Data).Txt);
AnAVLNode:=ClassProcs.FindSuccessor(AnAVLNode); AnAVLNode:=ClassProcs.FindSuccessor(AnAVLNode);
end;} end;}
@ -5752,7 +5753,7 @@ begin
ANodeExt:=TCodeTreeNodeExtension(MissingNode.Data); ANodeExt:=TCodeTreeNodeExtension(MissingNode.Data);
CreateCodeForMissingProcBody(ANodeExt); CreateCodeForMissingProcBody(ANodeExt);
InsertProcBody(ANodeExt); InsertProcBody(ANodeExt);
MissingNode:=ProcBodyNodes.FindPrecessor(MissingNode); MissingNode:=ClassProcs.FindPrecessor(MissingNode);
end; end;
end else begin end else begin
@ -5771,9 +5772,10 @@ begin
MissingNode:=ClassProcs.FindHighest; MissingNode:=ClassProcs.FindHighest;
NearestNodeValid:=false; NearestNodeValid:=false;
while (MissingNode<>nil) do begin while (MissingNode<>nil) do begin
ANodeExt:=TCodeTreeNodeExtension(MissingNode.Data);
ExistingNode:=ProcBodyNodes.Find(MissingNode.Data); ExistingNode:=ProcBodyNodes.Find(MissingNode.Data);
//DebugLn(['TCodeCompletionCodeTool.CreateMissingProcBodies ANodeExt.Txt=',ANodeExt.Txt,' ExistingNode=',ExistingNode<>nil]);
if ExistingNode=nil then begin if ExistingNode=nil then begin
ANodeExt:=TCodeTreeNodeExtension(MissingNode.Data);
// MissingNode does not have a body -> insert proc body // MissingNode does not have a body -> insert proc body
case MethodInsertPolicy of case MethodInsertPolicy of
mipAlphabetically: mipAlphabetically:
@ -5841,7 +5843,7 @@ begin
CreateCodeForMissingProcBody(ANodeExt); CreateCodeForMissingProcBody(ANodeExt);
InsertProcBody(ANodeExt); InsertProcBody(ANodeExt);
end; end;
MissingNode:=ProcBodyNodes.FindPrecessor(MissingNode); MissingNode:=ClassProcs.FindPrecessor(MissingNode);
end; end;
end; end;
Result:=true; Result:=true;

View File

@ -312,6 +312,7 @@ var
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// useful functions // useful functions
function NodeDescriptionAsString(Desc: TCodeTreeNodeDesc): string; function NodeDescriptionAsString(Desc: TCodeTreeNodeDesc): string;
procedure WriteNodeExtTree(Tree: TAVLTree);
function FindCodeTreeNodeExt(Tree: TAVLTree; const Txt: string function FindCodeTreeNodeExt(Tree: TAVLTree; const Txt: string
): TCodeTreeNodeExtension; ): TCodeTreeNodeExtension;
function FindCodeTreeNodeExtAVLNode(Tree: TAVLTree; const Txt: string function FindCodeTreeNodeExtAVLNode(Tree: TAVLTree; const Txt: string
@ -438,6 +439,27 @@ begin
end; end;
end; end;
procedure WriteNodeExtTree(Tree: TAVLTree);
var
Node: TAVLTreeNode;
NodeExt: TCodeTreeNodeExtension;
begin
if Tree=nil then begin
DebugLn(['WriteNodeExtTree Tree=nil']);
exit;
end;
DebugLn(['WriteNodeExtTree ']);
Node:=Tree.FindLowest;
while Node<>nil do begin
NodeExt:=TCodeTreeNodeExtension(Node.Data);
if NodeExt=nil then
DebugLn([' NodeExt=nil'])
else
NodeExt.WriteDebugReport;
Node:=Tree.FindSuccessor(Node);
end;
end;
function FindCodeTreeNodeExt(Tree: TAVLTree; const Txt: string function FindCodeTreeNodeExt(Tree: TAVLTree; const Txt: string
): TCodeTreeNodeExtension; ): TCodeTreeNodeExtension;
var var
@ -927,6 +949,13 @@ end;
procedure TCodeTreeNodeExtension.WriteDebugReport; procedure TCodeTreeNodeExtension.WriteDebugReport;
begin begin
// nothing special // nothing special
DbgOut(' ');
if Node<>nil then
DbgOut('Node=',NodeDescriptionAsString(Node.Desc))
else
DbgOut('Node=nil');
DbgOut(' Position=',dbgs(Position),' Txt="'+Txt+'" ExtTxt1="'+ExtTxt1+'" ExtTxt2="'+ExtTxt2+'" ExtTxt3="'+ExtTxt3+'"');
debugln;
end; end;
{ TCodeTreeNodeMemManager } { TCodeTreeNodeMemManager }