From 0991e39f7d62f6119440008cceaa163e15aee091 Mon Sep 17 00:00:00 2001 From: Juha Date: Tue, 16 May 2023 20:00:09 +0300 Subject: [PATCH] Codetools: Fix renaming dotted unit names + many functions dealing with dotted indentifiers. Issue #40195, patch by CCRDude. --- components/codetools/basiccodetools.pas | 4 +-- components/codetools/customcodetool.pas | 30 ++++++++++++++++++++ components/codetools/finddeclarationtool.pas | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/components/codetools/basiccodetools.pas b/components/codetools/basiccodetools.pas index abe6fbdf9c..4d1f51389b 100644 --- a/components/codetools/basiccodetools.pas +++ b/components/codetools/basiccodetools.pas @@ -5183,7 +5183,7 @@ begin if not IsIdentStartChar[p^] then exit; repeat inc(p); - until not IsIdentChar[p^]; + until not IsDottedIdentChar[p^]; if p^<>'.' then break; inc(p); until false; @@ -5211,7 +5211,7 @@ begin if not IsIdentStartChar[p^] then exit; repeat inc(p); - until not IsIdentChar[p^]; + until not IsDottedIdentChar[p^]; if p^<>'.' then break; inc(p); until false; diff --git a/components/codetools/customcodetool.pas b/components/codetools/customcodetool.pas index 3aaca966ac..256f72b3c2 100644 --- a/components/codetools/customcodetool.pas +++ b/components/codetools/customcodetool.pas @@ -274,6 +274,8 @@ type function CompareSrcIdentifiers(Identifier1, Identifier2: PChar): boolean; function CompareSrcIdentifiers(CleanStartPos: integer; AnIdentifier: PChar): boolean; + function CompareDottedSrcIdentifiers(CleanStartPos: integer; + AnIdentifier: PChar): boolean; function CompareSrcIdentifiersMethod(Identifier1, Identifier2: Pointer): integer; function ExtractIdentifier(CleanStartPos: integer): string; function ExtractDottedIdentifier(CleanStartPos: integer): string; @@ -3138,6 +3140,34 @@ begin Result:=not IsIdentChar[Src[CleanStartPos]]; end; +function TCustomCodeTool.CompareDottedSrcIdentifiers(CleanStartPos: integer; + AnIdentifier: PChar): boolean; +begin + Result:=false; + if (AnIdentifier=nil) or (CleanStartPos<1) or (CleanStartPos>SrcLen) then + exit; + if AnIdentifier^='&' then + Inc(AnIdentifier); + if Src[CleanStartPos]='&' then + begin + Inc(CleanStartPos); + if CleanStartPos>SrcLen then + exit; + end; + while IsDottedIdentChar[AnIdentifier^] do begin + if (UpChars[AnIdentifier^]=UpChars[Src[CleanStartPos]]) then begin + inc(AnIdentifier); + inc(CleanStartPos); + if CleanStartPos>SrcLen then begin + Result:=not IsDottedIdentChar[AnIdentifier^]; + exit; + end; + end else + exit(false); + end; + Result:=not IsDottedIdentChar[Src[CleanStartPos]]; +end; + function TCustomCodeTool.CompareSrcIdentifiersMethod(Identifier1, Identifier2: Pointer): integer; begin diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 3d8efcc880..4ef8dd5795 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -6864,7 +6864,7 @@ var ReadNextAtom; // read name ReadNextUsedUnit(UnitNamePos,UnitInFilePos); // read dotted name + IN file if CurPos.StartPos>SrcLen then break; - if CompareSrcIdentifiers(UnitNamePos.StartPos,UnitNameP) then begin // compare case insensitive + if CompareDottedSrcIdentifiers(UnitNamePos.StartPos,UnitNameP) then begin // compare case insensitive if CleanPosToCaret(UnitNamePos.StartPos,ReferencePos) then begin //DebugLn(['CheckUsesSection found in uses section: ',Dbgs(ReferencePos)]); Result:=true;