mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 14:20:38 +02:00
codetools: fixed skipping sourcename, added TPascalParserTool.FindUsesNode
git-svn-id: trunk@55946 -
This commit is contained in:
parent
ccf46cda1d
commit
4cee79f31d
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user