codetools: fixed skipping sourcename, added TPascalParserTool.FindUsesNode

git-svn-id: trunk@55946 -
This commit is contained in:
mattias 2017-09-30 13:52:10 +00:00
parent ccf46cda1d
commit 4cee79f31d
3 changed files with 29 additions and 17 deletions

View File

@ -1357,10 +1357,8 @@ begin
// there is no var/type/const section in front // there is no var/type/const section in front
if (ParentNode.Desc=ctnProcedure) and (HeaderNode=nil) then if (ParentNode.Desc=ctnProcedure) and (HeaderNode=nil) then
HeaderNode:=ParentNode.FirstChild; HeaderNode:=ParentNode.FirstChild;
if (HeaderNode=nil) if (HeaderNode=nil) then
and (ParentNode.FirstChild<>nil) HeaderNode:=FindUsesNode(ParentNode);
and (ParentNode.FirstChild.Desc=ctnUsesSection) then
HeaderNode:=ParentNode.FirstChild;
if CursorNode.Desc in [ctnBeginBlock,ctnAsmBlock] then begin if CursorNode.Desc in [ctnBeginBlock,ctnAsmBlock] then begin
// add the var section directly in front of the begin // add the var section directly in front of the begin
@ -6858,6 +6856,8 @@ begin
ctnProgram,ctnLibrary,ctnPackage] ctnProgram,ctnLibrary,ctnPackage]
then begin then begin
Node:=CursorNode.FirstChild; Node:=CursorNode.FirstChild;
while (Node<>nil) and (Node.Desc=ctnIdentifier) do
Node:=Node.NextBrother;
// make sure to insert behind uses section and proc header // make sure to insert behind uses section and proc header
if (Node<>nil) and (Node.Desc in [ctnUsesSection,ctnProcedureHead]) then if (Node<>nil) and (Node.Desc in [ctnUsesSection,ctnProcedureHead]) then
begin begin

View File

@ -2850,13 +2850,18 @@ end;
function TFindDeclarationTool.FindUnitInAllUsesSections( function TFindDeclarationTool.FindUnitInAllUsesSections(
const AnUnitName: string; out NamePos, InPos: TAtomPosition): boolean; const AnUnitName: string; out NamePos, InPos: TAtomPosition): boolean;
var SectionNode, UsesNode: TCodeTreeNode;
procedure RaiseInvalidUnitName; procedure RaiseInvalidUnitName;
begin begin
raise Exception.Create('invalid unit name '+AnUnitName); raise Exception.Create('invalid unit name '+AnUnitName);
end; end;
function FindInSection(UsesNode: TCodeTreeNode): boolean;
begin
Result:=(UsesNode<>nil)
and FindUnitInUsesSection(UsesNode,AnUnitName,NamePos,InPos);
end;
begin begin
Result:=false; Result:=false;
NamePos.StartPos:=-1; NamePos.StartPos:=-1;
@ -2864,18 +2869,8 @@ begin
if not IsDottedIdentifier(AnUnitName) then if not IsDottedIdentifier(AnUnitName) then
RaiseInvalidUnitName; RaiseInvalidUnitName;
BuildTree(lsrImplementationUsesSectionEnd); BuildTree(lsrImplementationUsesSectionEnd);
SectionNode:=Tree.Root; if FindInSection(FindMainUsesNode) then exit;
while (SectionNode<>nil) and (SectionNode.Desc in [ctnProgram, ctnUnit, if FindInSection(FindImplementationUsesNode) then exit;
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;
end; end;
function TFindDeclarationTool.GetUnitNameForUsesSection( function TFindDeclarationTool.GetUnitNameForUsesSection(

View File

@ -272,6 +272,7 @@ type
// sections / scan range // sections / scan range
function FindRootNode(Desc: TCodeTreeNodeDesc): TCodeTreeNode; function FindRootNode(Desc: TCodeTreeNodeDesc): TCodeTreeNode;
function FindInterfaceNode: TCodeTreeNode; function FindInterfaceNode: TCodeTreeNode;
function FindUsesNode(Section: TCodeTreeNode): TCodeTreeNode;
function FindMainUsesNode(UseContainsSection: boolean = false): TCodeTreeNode; function FindMainUsesNode(UseContainsSection: boolean = false): TCodeTreeNode;
function FindImplementationNode: TCodeTreeNode; function FindImplementationNode: TCodeTreeNode;
function FindImplementationUsesNode: TCodeTreeNode; function FindImplementationUsesNode: TCodeTreeNode;
@ -5998,6 +5999,18 @@ begin
Result:=FindRootNode(ctnInterface); Result:=FindRootNode(ctnInterface);
end; 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; function TPascalParserTool.FindImplementationNode: TCodeTreeNode;
begin begin
Result:=FindRootNode(ctnImplementation); Result:=FindRootNode(ctnImplementation);
@ -6122,6 +6135,8 @@ begin
exit; exit;
end; end;
Result:=Result.FirstChild; Result:=Result.FirstChild;
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
Result:=Result.NextBrother;
// lsrMainUsesSectionStart in unit // lsrMainUsesSectionStart in unit
if Range=lsrMainUsesSectionStart then exit; if Range=lsrMainUsesSectionStart then exit;
if Result.Desc=ctnUsesSection then begin if Result.Desc=ctnUsesSection then begin
@ -6147,6 +6162,8 @@ begin
exit; exit;
end; end;
Result:=Result.FirstChild; Result:=Result.FirstChild;
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
Result:=Result.NextBrother;
// lsrImplementationUsesSectionStart // lsrImplementationUsesSectionStart
if Range=lsrImplementationUsesSectionStart then exit; if Range=lsrImplementationUsesSectionStart then exit;
if Result.Desc=ctnUsesSection then begin if Result.Desc=ctnUsesSection then begin