mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 10:49:09 +02:00
codetools: added ctnSrcName
git-svn-id: branches/fixes_1_8@55952 -
This commit is contained in:
parent
2fec1e02cb
commit
417d0e5727
@ -1037,7 +1037,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
if InsertPos<1 then begin
|
if InsertPos<1 then begin
|
||||||
InsertNode:=FindFirstSectionChild;
|
InsertNode:=FindFirstSectionChild;
|
||||||
while (InsertNode<>nil) and (InsertNode.Desc=ctnIdentifier) do
|
if (InsertNode<>nil) and (InsertNode.Desc=ctnSrcName) then
|
||||||
InsertNode:=InsertNode.NextBrother;
|
InsertNode:=InsertNode.NextBrother;
|
||||||
if InsertNode<>nil then begin
|
if InsertNode<>nil then begin
|
||||||
Indent:=Beauty.GetLineIndent(Src,InsertNode.StartPos);
|
Indent:=Beauty.GetLineIndent(Src,InsertNode.StartPos);
|
||||||
@ -6832,7 +6832,7 @@ 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
|
if (Node<>nil) and (Node.Desc=ctnSrcName) then
|
||||||
Node:=Node.NextBrother;
|
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
|
||||||
|
@ -58,7 +58,7 @@ const
|
|||||||
// CodeTreeNodeDescriptors
|
// CodeTreeNodeDescriptors
|
||||||
ctnNone = 0;
|
ctnNone = 0;
|
||||||
|
|
||||||
ctnProgram = 1; // children are ctnInterface, each namespace and sourcename
|
ctnProgram = 1; // children are ctnSrcName, ctnUsesSection
|
||||||
ctnPackage = 2;
|
ctnPackage = 2;
|
||||||
ctnLibrary = 3;
|
ctnLibrary = 3;
|
||||||
ctnUnit = 4;
|
ctnUnit = 4;
|
||||||
@ -84,9 +84,10 @@ const
|
|||||||
ctnConstDefinition = 22;
|
ctnConstDefinition = 22;
|
||||||
ctnGlobalProperty = 23;
|
ctnGlobalProperty = 23;
|
||||||
ctnVarArgs = 24;
|
ctnVarArgs = 24;
|
||||||
ctnUseUnit = 25; // StartPos=unit, EndPos=unitname+inFilename, children ctnUseUnitNamespace, ctnUseUnitClearName, parent ctnUsesSection
|
ctnSrcName = 25; // children are ctnIdentifier
|
||||||
ctnUseUnitNamespace = 26; // <namespace>.clearname.pas, parent ctnUseUnit
|
ctnUseUnit = 26; // StartPos=unit, EndPos=unitname+inFilename, children ctnUseUnitNamespace, ctnUseUnitClearName, parent ctnUsesSection
|
||||||
ctnUseUnitClearName = 27; // namespace.<clearname>.pas, parent ctnUseUnit
|
ctnUseUnitNamespace = 27; // <namespace>.clearname.pas, parent ctnUseUnit
|
||||||
|
ctnUseUnitClearName = 28; // namespace.<clearname>.pas, parent ctnUseUnit
|
||||||
|
|
||||||
ctnClass = 30;
|
ctnClass = 30;
|
||||||
ctnClassInterface = 31;
|
ctnClassInterface = 31;
|
||||||
@ -407,6 +408,8 @@ begin
|
|||||||
ctnPackage: Result:='Package';
|
ctnPackage: Result:='Package';
|
||||||
ctnLibrary: Result:='Library';
|
ctnLibrary: Result:='Library';
|
||||||
ctnUnit: Result:='Unit';
|
ctnUnit: Result:='Unit';
|
||||||
|
ctnSrcName: Result:='SourceName';
|
||||||
|
ctnUseUnit: Result:='use unit';
|
||||||
ctnUseUnitNamespace: Result:='Namespace';
|
ctnUseUnitNamespace: Result:='Namespace';
|
||||||
ctnUseUnitClearName: Result:='Use unit name';
|
ctnUseUnitClearName: Result:='Use unit name';
|
||||||
ctnInterface: Result:='Interface Section';
|
ctnInterface: Result:='Interface Section';
|
||||||
@ -429,7 +432,6 @@ begin
|
|||||||
ctnVarDefinition: Result:='Var';
|
ctnVarDefinition: Result:='Var';
|
||||||
ctnConstDefinition: Result:='Const';
|
ctnConstDefinition: Result:='Const';
|
||||||
ctnGlobalProperty: Result:='Global Property';
|
ctnGlobalProperty: Result:='Global Property';
|
||||||
ctnUseUnit: Result:='use unit';
|
|
||||||
ctnVarArgs: Result:='VarArgs';
|
ctnVarArgs: Result:='VarArgs';
|
||||||
|
|
||||||
ctnProperty: Result:='Property'; // can start with 'class property'
|
ctnProperty: Result:='Property'; // can start with 'class property'
|
||||||
|
@ -752,7 +752,7 @@ type
|
|||||||
function FindIdentifierInAncestors(ClassNode: TCodeTreeNode;
|
function FindIdentifierInAncestors(ClassNode: TCodeTreeNode;
|
||||||
Params: TFindDeclarationParams): boolean;
|
Params: TFindDeclarationParams): boolean;
|
||||||
function FindIdentifierInUsesSection(UsesNode: TCodeTreeNode;
|
function FindIdentifierInUsesSection(UsesNode: TCodeTreeNode;
|
||||||
Params: TFindDeclarationParams; FindMissingFPCUnits: Boolean): boolean; // ToDo: dotted
|
Params: TFindDeclarationParams; FindMissingFPCUnits: Boolean): boolean;
|
||||||
function FindIdentifierInHiddenUsedUnits(
|
function FindIdentifierInHiddenUsedUnits(
|
||||||
Params: TFindDeclarationParams): boolean;
|
Params: TFindDeclarationParams): boolean;
|
||||||
function FindIdentifierInUsedUnit(const AnUnitName: string;
|
function FindIdentifierInUsedUnit(const AnUnitName: string;
|
||||||
@ -5446,6 +5446,13 @@ begin
|
|||||||
then begin
|
then begin
|
||||||
// this is the ON variable node, the type comes right behind
|
// this is the ON variable node, the type comes right behind
|
||||||
Result.Node:=Result.Node.NextBrother;
|
Result.Node:=Result.Node.NextBrother;
|
||||||
|
end else if Result.Node.Desc=ctnSrcName then begin
|
||||||
|
break;
|
||||||
|
end else if (Result.Node.Desc=ctnIdentifier)
|
||||||
|
and (Result.Node.Parent.Desc=ctnSrcName) then begin
|
||||||
|
if (Result.Node.NextBrother=nil) then
|
||||||
|
Result.Node:=Result.Node.Parent;
|
||||||
|
break;
|
||||||
end else
|
end else
|
||||||
if (Result.Node.Desc in [ctnIdentifier,ctnOnIdentifier])
|
if (Result.Node.Desc in [ctnIdentifier,ctnOnIdentifier])
|
||||||
then begin
|
then begin
|
||||||
@ -8973,7 +8980,7 @@ var
|
|||||||
DottedIdentifier: String;
|
DottedIdentifier: String;
|
||||||
begin
|
begin
|
||||||
Result:=StartUseUnitNode.FirstChild;
|
Result:=StartUseUnitNode.FirstChild;
|
||||||
//debugln(['ResolveUsenit START ',NextAtomType,' ',StartUseUnitNode.DescAsString]);
|
//debugln(['ResolveUsenit START ',NextAtomType,' ',StartUseUnitNode.DescAsString,' "',GetIdentifier(@Src[CurAtom.StartPos]),'"']);
|
||||||
// find all candidates
|
// find all candidates
|
||||||
Count:=0;
|
Count:=0;
|
||||||
HasNamespace:=false;
|
HasNamespace:=false;
|
||||||
@ -8991,7 +8998,7 @@ var
|
|||||||
UseUnitNode:=GetPrevUseUnit(UseUnitNode);
|
UseUnitNode:=GetPrevUseUnit(UseUnitNode);
|
||||||
until UseUnitNode=nil;
|
until UseUnitNode=nil;
|
||||||
//debugln(['ResolveUsenit CandidateCount=',Count,' HasNamespace=',HasNamespace]);
|
//debugln(['ResolveUsenit CandidateCount=',Count,' HasNamespace=',HasNamespace]);
|
||||||
if (Count<=1) or not HasNamespace then exit;
|
if not HasNamespace then exit;
|
||||||
|
|
||||||
// multiple uses start with this identifier -> collect candidates
|
// multiple uses start with this identifier -> collect candidates
|
||||||
//debugln(['ResolveUsenit collect candidates ...']);
|
//debugln(['ResolveUsenit collect candidates ...']);
|
||||||
@ -9052,33 +9059,34 @@ var
|
|||||||
// check source name
|
// check source name
|
||||||
if (Tree.Root.Desc in AllSourceTypes)
|
if (Tree.Root.Desc in AllSourceTypes)
|
||||||
and (Tree.Root.FirstChild<>nil)
|
and (Tree.Root.FirstChild<>nil)
|
||||||
|
and (Tree.Root.FirstChild.Desc=ctnSrcName)
|
||||||
and CompareSrcIdentifiers(Tree.Root.FirstChild.StartPos,PChar(DottedIdentifier))
|
and CompareSrcIdentifiers(Tree.Root.FirstChild.StartPos,PChar(DottedIdentifier))
|
||||||
then begin
|
then begin
|
||||||
// found candidate
|
// found candidate
|
||||||
Level:=1;
|
Level:=1;
|
||||||
Node:=Tree.Root.FirstChild;
|
Node:=Tree.Root.FirstChild.FirstChild;
|
||||||
//debugln(['ResolveUseUnit Candidate SrcName']);
|
//debugln(['ResolveUseUnit Candidate SrcName']);
|
||||||
p:=PChar(DottedIdentifier);
|
p:=PChar(DottedIdentifier);
|
||||||
repeat
|
repeat
|
||||||
//debugln('ResolveUseUnit SrcName p=',p,' Node=',ExtractNode(Node,[]));
|
//debugln('ResolveUseUnit SrcName p=',p,' Node=',ExtractNode(Node,[]));
|
||||||
if (Node.NextBrother=nil) or (Node.NextBrother.Desc<>ctnIdentifier) then begin
|
if (Node.FirstChild=nil) or (Node.NextBrother.Desc<>ctnIdentifier) then begin
|
||||||
// fits
|
// fits
|
||||||
//debugln(['ResolveUseUnit FITS Level=',Level,' Best=',BestLevel]);
|
//debugln(['ResolveUseUnit FITS Level=',Level,' Best=',BestLevel]);
|
||||||
if Level>BestLevel then begin
|
if Level>BestLevel then begin
|
||||||
// source name fits best
|
// source name fits best
|
||||||
Result:=Tree.Root.FirstChild;
|
Result:=Tree.Root.FirstChild.FirstChild;
|
||||||
// move cursor forward
|
// move cursor forward
|
||||||
while (Result.NextBrother<>nil)
|
while (Result.NextBrother<>nil)
|
||||||
and (NextAtom.EndPos<EndPos) do begin
|
and (NextAtom.EndPos<EndPos) do begin
|
||||||
if (Result.NextBrother.Desc<>ctnIdentifier) then
|
if (Result.NextBrother=nil) then
|
||||||
exit(Tree.Root);
|
exit(Tree.Root);
|
||||||
ReadNextExpressionAtom; // read point
|
ReadNextExpressionAtom; // read point
|
||||||
ReadNextExpressionAtom; // read namespace/unitname
|
ReadNextExpressionAtom; // read namespace/unitname
|
||||||
//debugln(['ResolveUseUnit Next ',GetAtom(CurAtom)]);
|
//debugln(['ResolveUseUnit Next ',GetAtom(CurAtom)]);
|
||||||
Result:=Result.NextBrother;
|
Result:=Result.NextBrother;
|
||||||
end;
|
end;
|
||||||
exit;
|
|
||||||
//debugln(['ResolveUseUnit SrcName fits better']);
|
//debugln(['ResolveUseUnit SrcName fits better']);
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
break;
|
break;
|
||||||
end else if p^=#0 then begin
|
end else if p^=#0 then begin
|
||||||
@ -9428,8 +9436,13 @@ var
|
|||||||
{$IFDEF ShowExprEval}
|
{$IFDEF ShowExprEval}
|
||||||
debugln([' FindExpressionTypeOfTerm ResolveChildren ExprType=',ExprTypeToString(ExprType)]);
|
debugln([' FindExpressionTypeOfTerm ResolveChildren ExprType=',ExprTypeToString(ExprType)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if (ExprType.Context.Node=nil) then exit;
|
NewNode:=ExprType.Context.Node;
|
||||||
if (ExprType.Context.Node.Desc in AllUsableSourceTypes) then begin
|
if (NewNode=nil) then exit;
|
||||||
|
if (NewNode.Desc in AllUsableSourceTypes)
|
||||||
|
or (NewNode.Desc=ctnSrcName)
|
||||||
|
or ((NewNode.Desc=ctnIdentifier) and (NewNode.Parent.Desc=ctnSrcName)
|
||||||
|
and (NewNode.NextBrother=nil))
|
||||||
|
then begin
|
||||||
if ExprType.Context.Tool=Self then begin
|
if ExprType.Context.Tool=Self then begin
|
||||||
// unit name of this unit => implementation
|
// unit name of this unit => implementation
|
||||||
// Note: allowed for programs too
|
// Note: allowed for programs too
|
||||||
|
@ -643,8 +643,7 @@ begin
|
|||||||
then begin
|
then begin
|
||||||
// parse source from the beginning
|
// parse source from the beginning
|
||||||
if CurNode<>nil then
|
if CurNode<>nil then
|
||||||
while CurNode.FirstChild<>nil do
|
DoDeleteNodes(CurNode.FirstChild);
|
||||||
Tree.DeleteNode(CurNode.FirstChild);
|
|
||||||
|
|
||||||
if (CurPos.StartPos=1) and (Src<>'') then begin
|
if (CurPos.StartPos=1) and (Src<>'') then begin
|
||||||
// skip shebang
|
// skip shebang
|
||||||
@ -699,8 +698,14 @@ begin
|
|||||||
if (CurPos.Flag<>cafWord)
|
if (CurPos.Flag<>cafWord)
|
||||||
or (CurSection in [ctnUnit,ctnPackage]) then
|
or (CurSection in [ctnUnit,ctnPackage]) then
|
||||||
AtomIsIdentifierSaveE;
|
AtomIsIdentifierSaveE;
|
||||||
|
if aNameSpace='' then begin
|
||||||
|
CreateChildNode;
|
||||||
|
CurNode.Desc:=ctnSrcName;
|
||||||
|
end;
|
||||||
CreateChildNode;
|
CreateChildNode;
|
||||||
CurNode.Desc:=ctnIdentifier;
|
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
|
||||||
@ -709,7 +714,7 @@ begin
|
|||||||
end else
|
end else
|
||||||
break;
|
break;
|
||||||
until false;
|
until false;
|
||||||
while CurNode.Desc=ctnIdentifier do begin
|
if CurNode.Desc=ctnSrcName then begin
|
||||||
CurNode.EndPos:=CurPos.StartPos;
|
CurNode.EndPos:=CurPos.StartPos;
|
||||||
EndChildNode;
|
EndChildNode;
|
||||||
end;
|
end;
|
||||||
@ -804,7 +809,7 @@ begin
|
|||||||
MoveCursorToCleanPos(Node.StartPos);
|
MoveCursorToCleanPos(Node.StartPos);
|
||||||
end else begin
|
end else begin
|
||||||
SubNode:=Node.FirstChild;
|
SubNode:=Node.FirstChild;
|
||||||
while (SubNode<>nil) and (SubNode.Desc=ctnIdentifier) do
|
if (SubNode<>nil) and (SubNode.Desc=ctnSrcName) then
|
||||||
SubNode:=SubNode.NextBrother;
|
SubNode:=SubNode.NextBrother;
|
||||||
if (SubNode<>nil) and (SubNode.Desc=ctnUsesSection) then begin
|
if (SubNode<>nil) and (SubNode.Desc=ctnUsesSection) then begin
|
||||||
// uses section is already parsed
|
// uses section is already parsed
|
||||||
@ -6015,7 +6020,7 @@ begin
|
|||||||
Result:=nil;
|
Result:=nil;
|
||||||
if Section=nil then exit;
|
if Section=nil then exit;
|
||||||
Result:=Section.FirstChild;
|
Result:=Section.FirstChild;
|
||||||
while (Result<>nil) and (Result.Desc=ctnIdentifier) do
|
if (Result<>nil) and (Result.Desc=ctnSrcName) then
|
||||||
Result:=Result.NextBrother;
|
Result:=Result.NextBrother;
|
||||||
if Result=nil then exit;
|
if Result=nil then exit;
|
||||||
if Result.Desc<>ctnUsesSection then
|
if Result.Desc<>ctnUsesSection then
|
||||||
@ -6087,7 +6092,7 @@ begin
|
|||||||
if Result=nil then exit;
|
if Result=nil then exit;
|
||||||
end;
|
end;
|
||||||
Result:=Result.FirstChild;
|
Result:=Result.FirstChild;
|
||||||
while (Result<>nil) and (Result.Desc=ctnIdentifier) do
|
if (Result<>nil) and (Result.Desc=ctnSrcName) then
|
||||||
Result:=Result.NextBrother;
|
Result:=Result.NextBrother;
|
||||||
if (Result=nil) then exit;
|
if (Result=nil) then exit;
|
||||||
if (Result.Desc<>ctnUsesSection) then Result:=nil;
|
if (Result.Desc<>ctnUsesSection) then Result:=nil;
|
||||||
@ -6131,7 +6136,7 @@ begin
|
|||||||
// lsrSourceName
|
// lsrSourceName
|
||||||
if Range=lsrSourceName then begin
|
if Range=lsrSourceName then begin
|
||||||
if (Result.Desc in AllSourceTypes) and (Result.FirstChild<>nil)
|
if (Result.Desc in AllSourceTypes) and (Result.FirstChild<>nil)
|
||||||
and (Result.FirstChild.Desc=ctnIdentifier) then
|
and (Result.FirstChild.Desc=ctnSrcName) then
|
||||||
Result:=Result.FirstChild;
|
Result:=Result.FirstChild;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -6149,7 +6154,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Result:=Result.FirstChild;
|
Result:=Result.FirstChild;
|
||||||
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
|
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
|
||||||
Result:=Result.NextBrother;
|
Result:=Result.NextBrother;
|
||||||
// lsrMainUsesSectionStart in unit
|
// lsrMainUsesSectionStart in unit
|
||||||
if Range=lsrMainUsesSectionStart then exit;
|
if Range=lsrMainUsesSectionStart then exit;
|
||||||
@ -6176,7 +6181,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Result:=Result.FirstChild;
|
Result:=Result.FirstChild;
|
||||||
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
|
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
|
||||||
Result:=Result.NextBrother;
|
Result:=Result.NextBrother;
|
||||||
// lsrImplementationUsesSectionStart
|
// lsrImplementationUsesSectionStart
|
||||||
if Range=lsrImplementationUsesSectionStart then exit;
|
if Range=lsrImplementationUsesSectionStart then exit;
|
||||||
@ -6222,7 +6227,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Result:=Result.FirstChild;
|
Result:=Result.FirstChild;
|
||||||
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
|
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
|
||||||
Result:=Result.NextBrother;
|
Result:=Result.NextBrother;
|
||||||
if Result.Desc<>ctnUsesSection then exit;
|
if Result.Desc<>ctnUsesSection then exit;
|
||||||
// lsrMainUsesSectionStart in program
|
// lsrMainUsesSectionStart in program
|
||||||
@ -6239,7 +6244,7 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Result:=Result.FirstChild;
|
Result:=Result.FirstChild;
|
||||||
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
|
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
|
||||||
Result:=Result.NextBrother;
|
Result:=Result.NextBrother;
|
||||||
if Result.Desc=ctnUsesSection then
|
if Result.Desc=ctnUsesSection then
|
||||||
Result:=Result.NextSkipChilds;
|
Result:=Result.NextSkipChilds;
|
||||||
@ -6269,7 +6274,7 @@ begin
|
|||||||
Result:=FindSectionNodeAtPos(P);
|
Result:=FindSectionNodeAtPos(P);
|
||||||
if Result=nil then exit;
|
if Result=nil then exit;
|
||||||
UsesNode:=Result.FirstChild;
|
UsesNode:=Result.FirstChild;
|
||||||
while (UsesNode<>nil) and (UsesNode.Desc=ctnIdentifier) do
|
if (UsesNode<>nil) and (UsesNode.Desc=ctnSrcName) then
|
||||||
UsesNode:=UsesNode.NextBrother;
|
UsesNode:=UsesNode.NextBrother;
|
||||||
if (UsesNode<>nil) and (UsesNode.Desc=ctnUsesSection) then
|
if (UsesNode<>nil) and (UsesNode.Desc=ctnUsesSection) then
|
||||||
begin
|
begin
|
||||||
|
@ -1839,7 +1839,7 @@ begin
|
|||||||
ctnProperty:
|
ctnProperty:
|
||||||
Result:=GetPropertyNameIdentifier(Node);
|
Result:=GetPropertyNameIdentifier(Node);
|
||||||
ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition,
|
ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition,
|
||||||
ctnEnumIdentifier,ctnIdentifier:
|
ctnEnumIdentifier,ctnIdentifier,ctnSrcName:
|
||||||
Result:=@Src[Node.StartPos];
|
Result:=@Src[Node.StartPos];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user