codetools: added ctnSrcName

git-svn-id: branches/fixes_1_8@55952 -
This commit is contained in:
mattias 2017-09-30 19:21:24 +00:00
parent 2fec1e02cb
commit 417d0e5727
5 changed files with 50 additions and 30 deletions

View File

@ -1037,7 +1037,7 @@ begin
end;
if InsertPos<1 then begin
InsertNode:=FindFirstSectionChild;
while (InsertNode<>nil) and (InsertNode.Desc=ctnIdentifier) do
if (InsertNode<>nil) and (InsertNode.Desc=ctnSrcName) then
InsertNode:=InsertNode.NextBrother;
if InsertNode<>nil then begin
Indent:=Beauty.GetLineIndent(Src,InsertNode.StartPos);
@ -6832,7 +6832,7 @@ begin
ctnProgram,ctnLibrary,ctnPackage]
then begin
Node:=CursorNode.FirstChild;
while (Node<>nil) and (Node.Desc=ctnIdentifier) do
if (Node<>nil) and (Node.Desc=ctnSrcName) then
Node:=Node.NextBrother;
// make sure to insert behind uses section and proc header
if (Node<>nil) and (Node.Desc in [ctnUsesSection,ctnProcedureHead]) then

View File

@ -58,7 +58,7 @@ const
// CodeTreeNodeDescriptors
ctnNone = 0;
ctnProgram = 1; // children are ctnInterface, each namespace and sourcename
ctnProgram = 1; // children are ctnSrcName, ctnUsesSection
ctnPackage = 2;
ctnLibrary = 3;
ctnUnit = 4;
@ -84,9 +84,10 @@ const
ctnConstDefinition = 22;
ctnGlobalProperty = 23;
ctnVarArgs = 24;
ctnUseUnit = 25; // StartPos=unit, EndPos=unitname+inFilename, children ctnUseUnitNamespace, ctnUseUnitClearName, parent ctnUsesSection
ctnUseUnitNamespace = 26; // <namespace>.clearname.pas, parent ctnUseUnit
ctnUseUnitClearName = 27; // namespace.<clearname>.pas, parent ctnUseUnit
ctnSrcName = 25; // children are ctnIdentifier
ctnUseUnit = 26; // StartPos=unit, EndPos=unitname+inFilename, children ctnUseUnitNamespace, ctnUseUnitClearName, parent ctnUsesSection
ctnUseUnitNamespace = 27; // <namespace>.clearname.pas, parent ctnUseUnit
ctnUseUnitClearName = 28; // namespace.<clearname>.pas, parent ctnUseUnit
ctnClass = 30;
ctnClassInterface = 31;
@ -407,6 +408,8 @@ begin
ctnPackage: Result:='Package';
ctnLibrary: Result:='Library';
ctnUnit: Result:='Unit';
ctnSrcName: Result:='SourceName';
ctnUseUnit: Result:='use unit';
ctnUseUnitNamespace: Result:='Namespace';
ctnUseUnitClearName: Result:='Use unit name';
ctnInterface: Result:='Interface Section';
@ -429,7 +432,6 @@ begin
ctnVarDefinition: Result:='Var';
ctnConstDefinition: Result:='Const';
ctnGlobalProperty: Result:='Global Property';
ctnUseUnit: Result:='use unit';
ctnVarArgs: Result:='VarArgs';
ctnProperty: Result:='Property'; // can start with 'class property'

View File

@ -752,7 +752,7 @@ type
function FindIdentifierInAncestors(ClassNode: TCodeTreeNode;
Params: TFindDeclarationParams): boolean;
function FindIdentifierInUsesSection(UsesNode: TCodeTreeNode;
Params: TFindDeclarationParams; FindMissingFPCUnits: Boolean): boolean; // ToDo: dotted
Params: TFindDeclarationParams; FindMissingFPCUnits: Boolean): boolean;
function FindIdentifierInHiddenUsedUnits(
Params: TFindDeclarationParams): boolean;
function FindIdentifierInUsedUnit(const AnUnitName: string;
@ -5446,6 +5446,13 @@ begin
then begin
// this is the ON variable node, the type comes right behind
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
if (Result.Node.Desc in [ctnIdentifier,ctnOnIdentifier])
then begin
@ -8973,7 +8980,7 @@ var
DottedIdentifier: String;
begin
Result:=StartUseUnitNode.FirstChild;
//debugln(['ResolveUsenit START ',NextAtomType,' ',StartUseUnitNode.DescAsString]);
//debugln(['ResolveUsenit START ',NextAtomType,' ',StartUseUnitNode.DescAsString,' "',GetIdentifier(@Src[CurAtom.StartPos]),'"']);
// find all candidates
Count:=0;
HasNamespace:=false;
@ -8991,7 +8998,7 @@ var
UseUnitNode:=GetPrevUseUnit(UseUnitNode);
until UseUnitNode=nil;
//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
//debugln(['ResolveUsenit collect candidates ...']);
@ -9052,33 +9059,34 @@ var
// check source name
if (Tree.Root.Desc in AllSourceTypes)
and (Tree.Root.FirstChild<>nil)
and (Tree.Root.FirstChild.Desc=ctnSrcName)
and CompareSrcIdentifiers(Tree.Root.FirstChild.StartPos,PChar(DottedIdentifier))
then begin
// found candidate
Level:=1;
Node:=Tree.Root.FirstChild;
Node:=Tree.Root.FirstChild.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
if (Node.FirstChild=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;
Result:=Tree.Root.FirstChild.FirstChild;
// move cursor forward
while (Result.NextBrother<>nil)
and (NextAtom.EndPos<EndPos) do begin
if (Result.NextBrother.Desc<>ctnIdentifier) then
if (Result.NextBrother=nil) 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']);
exit;
end;
break;
end else if p^=#0 then begin
@ -9428,8 +9436,13 @@ var
{$IFDEF ShowExprEval}
debugln([' FindExpressionTypeOfTerm ResolveChildren ExprType=',ExprTypeToString(ExprType)]);
{$ENDIF}
if (ExprType.Context.Node=nil) then exit;
if (ExprType.Context.Node.Desc in AllUsableSourceTypes) then begin
NewNode:=ExprType.Context.Node;
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
// unit name of this unit => implementation
// Note: allowed for programs too

View File

@ -643,8 +643,7 @@ begin
then begin
// parse source from the beginning
if CurNode<>nil then
while CurNode.FirstChild<>nil do
Tree.DeleteNode(CurNode.FirstChild);
DoDeleteNodes(CurNode.FirstChild);
if (CurPos.StartPos=1) and (Src<>'') then begin
// skip shebang
@ -699,8 +698,14 @@ begin
if (CurPos.Flag<>cafWord)
or (CurSection in [ctnUnit,ctnPackage]) then
AtomIsIdentifierSaveE;
if aNameSpace='' then begin
CreateChildNode;
CurNode.Desc:=ctnSrcName;
end;
CreateChildNode;
CurNode.Desc:=ctnIdentifier;
CurNode.EndPos:=CurPos.EndPos;
EndChildNode;
aName:=GetAtom;
ReadNextAtom; // read ';' (or 'platform;' or 'unimplemented;')
if CurPos.Flag=cafPoint then begin
@ -709,7 +714,7 @@ begin
end else
break;
until false;
while CurNode.Desc=ctnIdentifier do begin
if CurNode.Desc=ctnSrcName then begin
CurNode.EndPos:=CurPos.StartPos;
EndChildNode;
end;
@ -804,7 +809,7 @@ begin
MoveCursorToCleanPos(Node.StartPos);
end else begin
SubNode:=Node.FirstChild;
while (SubNode<>nil) and (SubNode.Desc=ctnIdentifier) do
if (SubNode<>nil) and (SubNode.Desc=ctnSrcName) then
SubNode:=SubNode.NextBrother;
if (SubNode<>nil) and (SubNode.Desc=ctnUsesSection) then begin
// uses section is already parsed
@ -6015,7 +6020,7 @@ begin
Result:=nil;
if Section=nil then exit;
Result:=Section.FirstChild;
while (Result<>nil) and (Result.Desc=ctnIdentifier) do
if (Result<>nil) and (Result.Desc=ctnSrcName) then
Result:=Result.NextBrother;
if Result=nil then exit;
if Result.Desc<>ctnUsesSection then
@ -6087,7 +6092,7 @@ begin
if Result=nil then exit;
end;
Result:=Result.FirstChild;
while (Result<>nil) and (Result.Desc=ctnIdentifier) do
if (Result<>nil) and (Result.Desc=ctnSrcName) then
Result:=Result.NextBrother;
if (Result=nil) then exit;
if (Result.Desc<>ctnUsesSection) then Result:=nil;
@ -6131,7 +6136,7 @@ begin
// lsrSourceName
if Range=lsrSourceName then begin
if (Result.Desc in AllSourceTypes) and (Result.FirstChild<>nil)
and (Result.FirstChild.Desc=ctnIdentifier) then
and (Result.FirstChild.Desc=ctnSrcName) then
Result:=Result.FirstChild;
exit;
end;
@ -6149,7 +6154,7 @@ begin
exit;
end;
Result:=Result.FirstChild;
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
Result:=Result.NextBrother;
// lsrMainUsesSectionStart in unit
if Range=lsrMainUsesSectionStart then exit;
@ -6176,7 +6181,7 @@ begin
exit;
end;
Result:=Result.FirstChild;
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
Result:=Result.NextBrother;
// lsrImplementationUsesSectionStart
if Range=lsrImplementationUsesSectionStart then exit;
@ -6222,7 +6227,7 @@ begin
exit;
end;
Result:=Result.FirstChild;
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
Result:=Result.NextBrother;
if Result.Desc<>ctnUsesSection then exit;
// lsrMainUsesSectionStart in program
@ -6239,7 +6244,7 @@ begin
exit;
end;
Result:=Result.FirstChild;
while (Result.NextBrother<>nil) and (Result.Desc=ctnIdentifier) do
if (Result.NextBrother<>nil) and (Result.Desc=ctnSrcName) then
Result:=Result.NextBrother;
if Result.Desc=ctnUsesSection then
Result:=Result.NextSkipChilds;
@ -6269,7 +6274,7 @@ begin
Result:=FindSectionNodeAtPos(P);
if Result=nil then exit;
UsesNode:=Result.FirstChild;
while (UsesNode<>nil) and (UsesNode.Desc=ctnIdentifier) do
if (UsesNode<>nil) and (UsesNode.Desc=ctnSrcName) then
UsesNode:=UsesNode.NextBrother;
if (UsesNode<>nil) and (UsesNode.Desc=ctnUsesSection) then
begin

View File

@ -1839,7 +1839,7 @@ begin
ctnProperty:
Result:=GetPropertyNameIdentifier(Node);
ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition,
ctnEnumIdentifier,ctnIdentifier:
ctnEnumIdentifier,ctnIdentifier,ctnSrcName:
Result:=@Src[Node.StartPos];
end;
end;