mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 15:20:33 +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
|
// 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
|
||||||
|
@ -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(
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user