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
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
@ -6858,6 +6856,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

View File

@ -2850,13 +2850,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;
@ -2864,18 +2869,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(

View File

@ -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