mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-26 22:29:25 +02:00
codetools: find declaration of dotted program name
git-svn-id: branches/fixes_1_8@55852 -
This commit is contained in:
parent
d1fa8908c2
commit
820a9b860c
@ -58,7 +58,7 @@ const
|
|||||||
// CodeTreeNodeDescriptors
|
// CodeTreeNodeDescriptors
|
||||||
ctnNone = 0;
|
ctnNone = 0;
|
||||||
|
|
||||||
ctnProgram = 1;
|
ctnProgram = 1; // children are ctnInterface, each namespace and sourcename
|
||||||
ctnPackage = 2;
|
ctnPackage = 2;
|
||||||
ctnLibrary = 3;
|
ctnLibrary = 3;
|
||||||
ctnUnit = 4;
|
ctnUnit = 4;
|
||||||
|
@ -8951,8 +8951,10 @@ var
|
|||||||
function ResolveUseUnit(StartUseUnitNode: TCodeTreeNode): TCodeTreeNode;
|
function ResolveUseUnit(StartUseUnitNode: TCodeTreeNode): TCodeTreeNode;
|
||||||
// IsStart=true, NextAtomType=vatPoint,
|
// IsStart=true, NextAtomType=vatPoint,
|
||||||
// StartUseUnitNameNode.Desc=ctnUseUnit
|
// StartUseUnitNameNode.Desc=ctnUseUnit
|
||||||
// -> Find the longest namespaced used unit, that fits the start of the
|
// -> Find the longest namespaced used unit (ctnUseUnitNamespace,ctnUseUnitClearName)
|
||||||
|
// or the source name (ctnIdentifier), that fits the start of the
|
||||||
// current identifier a.b.c...
|
// current identifier a.b.c...
|
||||||
|
//
|
||||||
|
|
||||||
function GetPrevUseUnit(UseUnitNode: TCodeTreeNode): TCodeTreeNode;
|
function GetPrevUseUnit(UseUnitNode: TCodeTreeNode): TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
@ -9012,7 +9014,7 @@ var
|
|||||||
until CurPos.Flag<>cafPoint;
|
until CurPos.Flag<>cafPoint;
|
||||||
//debugln(['ResolveUsenit DottedIdentifier="',DottedIdentifier,'"']);
|
//debugln(['ResolveUsenit DottedIdentifier="',DottedIdentifier,'"']);
|
||||||
|
|
||||||
// find longest dotted unit name in uses
|
// find longest dotted unit name in uses and source name
|
||||||
UseUnitNode:=StartUseUnitNode;
|
UseUnitNode:=StartUseUnitNode;
|
||||||
BestNode:=nil;
|
BestNode:=nil;
|
||||||
BestLevel:=0;
|
BestLevel:=0;
|
||||||
@ -9022,13 +9024,13 @@ var
|
|||||||
if (Node<>nil)
|
if (Node<>nil)
|
||||||
and CompareSrcIdentifiers(CurAtom.StartPos,Node.StartPos) then begin
|
and CompareSrcIdentifiers(CurAtom.StartPos,Node.StartPos) then begin
|
||||||
// found candidate
|
// found candidate
|
||||||
//debugln(['ResolveUsenit Candidate=',ExtractNode(Node,[])]);
|
//debugln(['ResolveUseUnit Candidate=',ExtractNode(Node,[])]);
|
||||||
Level:=1;
|
Level:=1;
|
||||||
p:=PChar(DottedIdentifier);
|
p:=PChar(DottedIdentifier);
|
||||||
repeat
|
repeat
|
||||||
inc(p,GetIdentLen(p));
|
inc(p,GetIdentLen(p));
|
||||||
if p^='.' then inc(p);
|
if p^='.' then inc(p);
|
||||||
//writeln('ResolveUsenit p=',p,' NextBrother=',Node.NextBrother<>nil);
|
//writeln('ResolveUseUnit p=',p,' NextBrother=',Node.NextBrother<>nil);
|
||||||
if Node.NextBrother=nil then begin
|
if Node.NextBrother=nil then begin
|
||||||
// fits
|
// fits
|
||||||
if Level>BestLevel then begin
|
if Level>BestLevel then begin
|
||||||
@ -9041,7 +9043,7 @@ var
|
|||||||
break;
|
break;
|
||||||
end else begin
|
end else begin
|
||||||
Node:=Node.NextBrother;
|
Node:=Node.NextBrother;
|
||||||
//writeln('ResolveUsenit p=',p,' node=',GetIdentifier(@Src[Node.StartPos]));
|
//writeln('ResolveUseUnit p=',p,' node=',GetIdentifier(@Src[Node.StartPos]));
|
||||||
if not CompareSrcIdentifiers(Node.StartPos,p) then
|
if not CompareSrcIdentifiers(Node.StartPos,p) then
|
||||||
break;
|
break;
|
||||||
inc(Level);
|
inc(Level);
|
||||||
@ -9049,10 +9051,61 @@ var
|
|||||||
until false;
|
until false;
|
||||||
end;
|
end;
|
||||||
until UseUnitNode=nil;
|
until UseUnitNode=nil;
|
||||||
//debugln(['ResolveUsenit collected candidates Best=',ExtractNode(BestNode,[])]);
|
//debugln(['ResolveUseUnit collected candidates Best=',ExtractNode(BestNode,[])]);
|
||||||
|
|
||||||
Result:=BestNode.FirstChild;
|
//debugln(['ResolveUseUnit Src=',Tree.Root.DescAsString,' Name=',GetSourceName(false),' DottedIdentifier="',DottedIdentifier,'"']);
|
||||||
|
// check source name
|
||||||
|
if (Tree.Root.Desc in AllSourceTypes)
|
||||||
|
and (Tree.Root.FirstChild<>nil)
|
||||||
|
and CompareSrcIdentifiers(Tree.Root.FirstChild.StartPos,PChar(DottedIdentifier))
|
||||||
|
then begin
|
||||||
|
// found candidate
|
||||||
|
Level:=1;
|
||||||
|
Node:=Tree.Root.FirstChild;
|
||||||
|
//debugln(['ResolveUseUnit Candidate SrcName']);
|
||||||
|
p:=PChar(DottedIdentifier);
|
||||||
|
repeat
|
||||||
|
//debugln('ResolveUseUnit SrcName p=',p,' Node=',ExtractNode(Node,[]));
|
||||||
|
if (Node.NextBrother=nil) or (Node.NextBrother.Desc<>ctnIdentifier) then begin
|
||||||
|
// fits
|
||||||
|
//debugln(['ResolveUseUnit FITS Level=',Level,' Best=',BestLevel]);
|
||||||
|
if Level>BestLevel then begin
|
||||||
|
// source name fits best
|
||||||
|
Result:=Tree.Root.FirstChild;
|
||||||
|
// move cursor forward
|
||||||
|
while (Result.NextBrother<>nil)
|
||||||
|
and (NextAtom.EndPos<EndPos) do begin
|
||||||
|
if (Result.NextBrother.Desc<>ctnIdentifier) then
|
||||||
|
exit(Tree.Root);
|
||||||
|
ReadNextExpressionAtom; // read point
|
||||||
|
ReadNextExpressionAtom; // read namespace/unitname
|
||||||
|
//debugln(['ResolveUseUnit Next ',GetAtom(CurAtom)]);
|
||||||
|
Result:=Result.NextBrother;
|
||||||
|
end;
|
||||||
|
exit;
|
||||||
|
//debugln(['ResolveUseUnit SrcName fits better']);
|
||||||
|
end;
|
||||||
|
break;
|
||||||
|
end else if p^=#0 then begin
|
||||||
|
// source name too long
|
||||||
|
break;
|
||||||
|
end else begin
|
||||||
|
Node:=Node.NextBrother;
|
||||||
|
inc(p,GetIdentLen(p));
|
||||||
|
if p^='.' then inc(p);
|
||||||
|
//debugln('ResolveUseUnit SrcName NEXT p=',p,' Node=',ExtractNode(Node,[]));
|
||||||
|
if not CompareSrcIdentifiers(Node.StartPos,p) then
|
||||||
|
break;
|
||||||
|
inc(Level);
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result:=BestNode;
|
||||||
|
if Result=nil then exit;
|
||||||
|
|
||||||
|
// Result is now a ctnUseUnit
|
||||||
|
Result:=Result.FirstChild;
|
||||||
// move cursor forward
|
// move cursor forward
|
||||||
while (Result.NextBrother<>nil) and (NextAtom.EndPos<EndPos) do begin
|
while (Result.NextBrother<>nil) and (NextAtom.EndPos<EndPos) do begin
|
||||||
ReadNextExpressionAtom; // read point
|
ReadNextExpressionAtom; // read point
|
||||||
|
@ -1254,10 +1254,12 @@ begin
|
|||||||
exit(false);
|
exit(false);
|
||||||
repeat
|
repeat
|
||||||
// read unit name
|
// read unit name
|
||||||
|
repeat
|
||||||
ReadNextToken;
|
ReadNextToken;
|
||||||
if (TokenType<>lsttWord)
|
if (TokenType<>lsttWord)
|
||||||
or WordIsKeyWord.DoItCaseInsensitive(@Src[SrcPos]) then exit(false);
|
or WordIsKeyWord.DoItCaseInsensitive(@Src[SrcPos]) then exit(false);
|
||||||
ReadNextToken;
|
ReadNextToken;
|
||||||
|
until TokenType<>lsttPoint;
|
||||||
if TokenIs('in') then begin
|
if TokenIs('in') then begin
|
||||||
// read "in" filename
|
// read "in" filename
|
||||||
ReadNextToken;
|
ReadNextToken;
|
||||||
|
@ -690,6 +690,10 @@ begin
|
|||||||
if (CurPos.Flag<>cafWord)
|
if (CurPos.Flag<>cafWord)
|
||||||
or (CurSection in [ctnUnit,ctnPackage]) then
|
or (CurSection in [ctnUnit,ctnPackage]) then
|
||||||
AtomIsIdentifierSaveE;
|
AtomIsIdentifierSaveE;
|
||||||
|
CreateChildNode;
|
||||||
|
CurNode.Desc:=ctnIdentifier;
|
||||||
|
CurNode.EndPos:=CurPos.EndPos;
|
||||||
|
EndChildNode;
|
||||||
aName:=GetAtom;
|
aName:=GetAtom;
|
||||||
ReadNextAtom; // read ';' (or 'platform;' or 'unimplemented;')
|
ReadNextAtom; // read ';' (or 'platform;' or 'unimplemented;')
|
||||||
if CurPos.Flag=cafPoint then begin
|
if CurPos.Flag=cafPoint then begin
|
||||||
@ -2093,8 +2097,10 @@ begin
|
|||||||
EndChildNode;
|
EndChildNode;
|
||||||
if CurPos.Flag=cafSemicolon then break;
|
if CurPos.Flag=cafSemicolon then break;
|
||||||
if CurPos.Flag<>cafComma then
|
if CurPos.Flag<>cafComma then
|
||||||
if ExceptionOnError then
|
if ExceptionOnError then begin
|
||||||
SaveRaiseCharExpectedButAtomFound(20170421195538,';')
|
CTDumpStack;
|
||||||
|
SaveRaiseCharExpectedButAtomFound(20170421195538,';');
|
||||||
|
end
|
||||||
else exit;
|
else exit;
|
||||||
until (CurPos.StartPos>SrcLen);
|
until (CurPos.StartPos>SrcLen);
|
||||||
CurNode.EndPos:=CurPos.EndPos;
|
CurNode.EndPos:=CurPos.EndPos;
|
||||||
|
@ -4,6 +4,8 @@ unit unitdots.dot;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
type
|
||||||
|
TColor = longint;
|
||||||
var
|
var
|
||||||
test: integer;
|
test: integer;
|
||||||
foo: integer;
|
foo: integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user