diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 32ed5894cd..db72845c8c 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -9574,6 +9574,22 @@ var Result:=FlagCanBeForwardDefined; end; + function FindPointedTypeBehind(PointerTypeNode: TCodeTreeNode): TCodeTreeNode; + var + IdentNode, Node: TCodeTreeNode; + begin + IdentNode:=PointerTypeNode.FirstChild; + Node:=PointerTypeNode.Parent.NextBrother; + while Node<>nil do begin + if (Node.Desc=ctnTypeDefinition) + and CompareSrcIdentifiers(Node.StartPos, IdentNode.StartPos) + then + exit(Node); + Node:=Node.NextBrother; // all remaing types of current type section + end; + Result:=nil; + end; + procedure ResolveTypeLessProperty; begin if ExprType.Desc<>xtContext then exit; @@ -9930,7 +9946,7 @@ var if Find(Identifier) then exit(true); Params.Load(OldInput,false); end; - + procedure ResolveIdentifier; var ProcNode: TCodeTreeNode; @@ -10087,6 +10103,16 @@ var end; end; end; + end else if (StartNode.Parent<>nil) + and (StartNode.Parent.Desc=ctnPointerType) and (NextAtomType<>vatPoint) then + begin + Node:=FindPointedTypeBehind(StartNode.Parent); + if Node<>nil then begin + ExprType.Context.Tool:=Self; + ExprType.Context.Node:=Node; + ExprType.Desc:=xtContext; + exit; + end; end; end; // find identifier @@ -10455,25 +10481,9 @@ var ExprType.Context.Tool:=Self; ExprType.Context.Node:=StartNode; end; - + procedure ResolveUp; - var NodeBehind: TCodeTreeNode; - - function HasPointedTypeBehind: TCodeTreeNode; - var Node, pNode: TCodeTreeNode; - begin - Result:=nil; - pNode:=ExprType.Context.Node;//ctnPointerType - Node:=pNode.Parent.NextBrother; - while Node<>nil do begin - if (Node.Desc=ctnTypeDefinition) - and CompareSrcIdentifiers(Node.StartPos, pNode.FirstChild{Identifier}.StartPos) - then - exit(Node); - Node:=Node.NextBrother; // all remaing types of current type section - end; - end; - + var NodeBehind, PointerTypeNode: TCodeTreeNode; begin // for example: // 1. 'PInt = ^integer' pointer type @@ -10505,14 +10515,15 @@ var ReadNextAtom; RaisePointNotFound(20191003163249); end; - if (ExprType.Context.Node=nil) - or (ExprType.Context.Node.Desc<>ctnPointerType) then begin + PointerTypeNode:=ExprType.Context.Node; + if (PointerTypeNode=nil) + or (PointerTypeNode.Desc<>ctnPointerType) then begin MoveCursorToCleanPos(CurAtom.StartPos); RaiseExceptionFmt(20170421200550,ctsIllegalQualifier,['^']); end; ExprType.Desc:=xtContext; //first try if this node has a pointed type behind - NodeBehind:=HasPointedTypeBehind; + NodeBehind:=FindPointedTypeBehind(PointerTypeNode); if NodeBehind=nil then ExprType.Context.Node:=ExprType.Context.Node.FirstChild else diff --git a/components/codetools/pascalreadertool.pas b/components/codetools/pascalreadertool.pas index 0d8b589a11..2a0b18e811 100644 --- a/components/codetools/pascalreadertool.pas +++ b/components/codetools/pascalreadertool.pas @@ -271,10 +271,10 @@ type function GetFirstGroupVarNode(VarNode: TCodeTreeNode): TCodeTreeNode; function NodeIsIdentifierInInterface(Node: TCodeTreeNode): boolean; function NodeCanHaveForwardType(TypeNode: TCodeTreeNode): boolean; - function NodeIsForwardType(TypeNode: TCodeTreeNode): boolean; + function NodeIsForwardType(TypeNode: TCodeTreeNode): boolean; // forward class/interface/object, not pointer function FindForwardTypeNode(TypeNode: TCodeTreeNode; - SearchFirst: boolean): TCodeTreeNode; - function FindTypeOfForwardNode(TypeNode: TCodeTreeNode): TCodeTreeNode; + SearchFirst: boolean): TCodeTreeNode; // find for a type the forward type node + function FindTypeOfForwardNode(TypeNode: TCodeTreeNode): TCodeTreeNode; // find the forward type for a type node function FindEndOfWithExpr(WithVarNode: TCodeTreeNode): integer; function ExtractWithBlockExpression(WithVarNode: TCodeTreeNode; Attr: TProcHeadAttributes = []): string; function FindWithBlockStatement(WithVarNode: TCodeTreeNode): TCodeTreeNode; diff --git a/components/codetools/tests/testfinddeclaration.pas b/components/codetools/tests/testfinddeclaration.pas index 0373a17e32..c7c4bf5547 100644 --- a/components/codetools/tests/testfinddeclaration.pas +++ b/components/codetools/tests/testfinddeclaration.pas @@ -1424,7 +1424,7 @@ begin Add([ 'uses unit2;', 'type', - ' PBird = ^TBird;', + ' PBird = ^TBird{declaration:test1.tbird};', ' [attr]', ' TBird = record', ' Speed: word;',