From 93eab7f1d68e12cce2efa7ad56f30ec3accf5a93 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 30 Sep 2017 13:52:36 +0000 Subject: [PATCH] codetools: fixed skipping sourcename, added TPascalParserTool.FindUsesNode git-svn-id: branches/fixes_1_8@55947 - --- components/codetools/codecompletiontool.pas | 8 ++++---- components/codetools/finddeclarationtool.pas | 21 ++++++++------------ components/codetools/pascalparsertool.pas | 17 ++++++++++++++++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 256ed040bf..1584e36c5b 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -1350,10 +1350,8 @@ begin // there is no var/type/const section in front if (ParentNode.Desc=ctnProcedure) and (HeaderNode=nil) then HeaderNode:=ParentNode.FirstChild; - if (HeaderNode=nil) - and (ParentNode.FirstChild<>nil) - and (ParentNode.FirstChild.Desc=ctnUsesSection) then - HeaderNode:=ParentNode.FirstChild; + if (HeaderNode=nil) then + HeaderNode:=FindUsesNode(ParentNode); if CursorNode.Desc in [ctnBeginBlock,ctnAsmBlock] then begin // add the var section directly in front of the begin @@ -6834,6 +6832,8 @@ begin ctnProgram,ctnLibrary,ctnPackage] then begin Node:=CursorNode.FirstChild; + while (Node<>nil) and (Node.Desc=ctnIdentifier) do + Node:=Node.NextBrother; // make sure to insert behind uses section and proc header if (Node<>nil) and (Node.Desc in [ctnUsesSection,ctnProcedureHead]) then begin diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index e2d57fa60e..7581fc5b06 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -2799,13 +2799,18 @@ end; function TFindDeclarationTool.FindUnitInAllUsesSections( const AnUnitName: string; out NamePos, InPos: TAtomPosition): boolean; -var SectionNode, UsesNode: TCodeTreeNode; procedure RaiseInvalidUnitName; begin raise Exception.Create('invalid unit name '+AnUnitName); end; + function FindInSection(UsesNode: TCodeTreeNode): boolean; + begin + Result:=(UsesNode<>nil) + and FindUnitInUsesSection(UsesNode,AnUnitName,NamePos,InPos); + end; + begin Result:=false; NamePos.StartPos:=-1; @@ -2813,18 +2818,8 @@ begin if not IsDottedIdentifier(AnUnitName) then RaiseInvalidUnitName; BuildTree(lsrImplementationUsesSectionEnd); - SectionNode:=Tree.Root; - while (SectionNode<>nil) and (SectionNode.Desc in [ctnProgram, ctnUnit, - ctnPackage,ctnLibrary,ctnInterface,ctnImplementation]) - do begin - UsesNode:=SectionNode.FirstChild; - if (UsesNode<>nil) and (UsesNode.Desc=ctnUsesSection) - and FindUnitInUsesSection(UsesNode,AnUnitName,NamePos,InPos) then begin - Result:=true; - exit; - end; - SectionNode:=SectionNode.NextBrother; - end; + if FindInSection(FindMainUsesNode) then exit; + if FindInSection(FindImplementationUsesNode) then exit; end; function TFindDeclarationTool.GetUnitNameForUsesSection( diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 2306421056..1f4b238676 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -272,6 +272,7 @@ type // sections / scan range function FindRootNode(Desc: TCodeTreeNodeDesc): TCodeTreeNode; function FindInterfaceNode: TCodeTreeNode; + function FindUsesNode(Section: TCodeTreeNode): TCodeTreeNode; function FindMainUsesNode(UseContainsSection: boolean = false): TCodeTreeNode; function FindImplementationNode: TCodeTreeNode; function FindImplementationUsesNode: TCodeTreeNode; @@ -5998,6 +5999,18 @@ begin Result:=FindRootNode(ctnInterface); end; +function TPascalParserTool.FindUsesNode(Section: TCodeTreeNode): TCodeTreeNode; +begin + Result:=nil; + if Section=nil then exit; + Result:=Section.FirstChild; + while (Result<>nil) and (Result.Desc=ctnIdentifier) do + Result:=Result.NextBrother; + if Result=nil then exit; + if Result.Desc<>ctnUsesSection then + Result:=nil; +end; + function TPascalParserTool.FindImplementationNode: TCodeTreeNode; begin Result:=FindRootNode(ctnImplementation); @@ -6122,6 +6135,8 @@ begin exit; end; Result:=Result.FirstChild; + while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do + Result:=Result.NextBrother; // lsrMainUsesSectionStart in unit if Range=lsrMainUsesSectionStart then exit; if Result.Desc=ctnUsesSection then begin @@ -6147,6 +6162,8 @@ begin exit; end; Result:=Result.FirstChild; + while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do + Result:=Result.NextBrother; // lsrImplementationUsesSectionStart if Range=lsrImplementationUsesSectionStart then exit; if Result.Desc=ctnUsesSection then begin