mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 03:49:30 +02:00
codetools: fixed searching ancestor class *not* in ancestors (loop) and search it in ancestors of enclosing class
git-svn-id: trunk@48292 -
This commit is contained in:
parent
84ebcd98ec
commit
6cfb990ccf
@ -3253,23 +3253,27 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (ContextNode.Desc in (AllClasses-[ctnRecordType]))
|
if (ContextNode.Desc in (AllClasses-[ctnRecordType])) then begin
|
||||||
and (fdfSearchInAncestors in Params.Flags) then begin
|
if (fdfSearchInAncestors in Params.Flags) then begin
|
||||||
// after searching in a class definition, search in its ancestors
|
// after searching in a class definition, search in its ancestors
|
||||||
|
|
||||||
// ToDo: check for cycles in ancestors
|
// ToDo: check for cycles in ancestors
|
||||||
Params.Save(OldInput);
|
Params.Save(OldInput);
|
||||||
Exclude(Params.Flags,fdfExceptionOnNotFound);
|
Exclude(Params.Flags,fdfExceptionOnNotFound);
|
||||||
Result:=FindIdentifierInAncestors(ContextNode,Params);
|
Result:=FindIdentifierInAncestors(ContextNode,Params);
|
||||||
Params.Load(OldInput,true);
|
Params.Load(OldInput,true);
|
||||||
if Result then begin
|
if Result then begin
|
||||||
FindIdentifierInContext:=true;
|
FindIdentifierInContext:=true;
|
||||||
{$IFDEF ShowCollect}
|
{$IFDEF ShowCollect}
|
||||||
if fdfCollect in Params.Flags then
|
if fdfCollect in Params.Flags then
|
||||||
raise Exception.Create('fdfCollect must never return true');
|
raise Exception.Create('fdfCollect must never return true');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
exit(AbortNoCacheResult);
|
exit(AbortNoCacheResult);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
// if this was a nested class, the identifier can be in the ancestors
|
||||||
|
// of the enclosing class
|
||||||
|
Params.Flags:=Params.Flags+[fdfSearchInAncestors];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (ContextNode=StartContextNode)
|
if (ContextNode=StartContextNode)
|
||||||
@ -3480,6 +3484,9 @@ begin
|
|||||||
// -> search in all children
|
// -> search in all children
|
||||||
MoveContextNodeToChildren;
|
MoveContextNodeToChildren;
|
||||||
|
|
||||||
|
ctnClassInheritance:
|
||||||
|
Params.Flags:=Params.Flags-[fdfSearchInAncestors];
|
||||||
|
|
||||||
ctnTypeDefinition, ctnVarDefinition, ctnConstDefinition,
|
ctnTypeDefinition, ctnVarDefinition, ctnConstDefinition,
|
||||||
ctnGenericType, ctnGlobalProperty:
|
ctnGenericType, ctnGlobalProperty:
|
||||||
if SearchInTypeVarConstGlobPropDefinition then exit;
|
if SearchInTypeVarConstGlobPropDefinition then exit;
|
||||||
@ -3604,8 +3611,8 @@ var OldContextNode, CurContextNode: TCodeTreeNode;
|
|||||||
CollectResult: TIdentifierFoundResult;
|
CollectResult: TIdentifierFoundResult;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if Params.ContextNode=nil then exit;
|
|
||||||
CurContextNode:=Params.ContextNode;
|
CurContextNode:=Params.ContextNode;
|
||||||
|
if CurContextNode=nil then exit;
|
||||||
CurContextNode:=CurContextNode.FirstChild;
|
CurContextNode:=CurContextNode.FirstChild;
|
||||||
while CurContextNode<>nil do begin
|
while CurContextNode<>nil do begin
|
||||||
if (CurContextNode.Desc=ctnEnumIdentifier) then begin
|
if (CurContextNode.Desc=ctnEnumIdentifier) then begin
|
||||||
@ -5784,6 +5791,7 @@ function TFindDeclarationTool.FindAncestorOfClassInheritance(
|
|||||||
IdentifierNode: TCodeTreeNode; ResultParams: TFindDeclarationParams;
|
IdentifierNode: TCodeTreeNode; ResultParams: TFindDeclarationParams;
|
||||||
FindClassContext: boolean): boolean;
|
FindClassContext: boolean): boolean;
|
||||||
var
|
var
|
||||||
|
InheritanceNode: TCodeTreeNode;
|
||||||
ClassNode: TCodeTreeNode;
|
ClassNode: TCodeTreeNode;
|
||||||
AncestorContext: TFindContext;
|
AncestorContext: TFindContext;
|
||||||
AncestorStartPos: LongInt;
|
AncestorStartPos: LongInt;
|
||||||
@ -5800,7 +5808,8 @@ begin
|
|||||||
+' not an inheritance node');
|
+' not an inheritance node');
|
||||||
Result:=false;
|
Result:=false;
|
||||||
|
|
||||||
ClassNode:=IdentifierNode.Parent.Parent;
|
InheritanceNode:=IdentifierNode.Parent;
|
||||||
|
ClassNode:=InheritanceNode.Parent;
|
||||||
|
|
||||||
if IdentifierNode.Desc=ctnSpecialize then begin
|
if IdentifierNode.Desc=ctnSpecialize then begin
|
||||||
if (IdentifierNode.FirstChild=nil) then begin
|
if (IdentifierNode.FirstChild=nil) then begin
|
||||||
@ -5820,7 +5829,7 @@ begin
|
|||||||
Params:=TFindDeclarationParams.Create;
|
Params:=TFindDeclarationParams.Create;
|
||||||
try
|
try
|
||||||
Params.Flags:=fdfDefaultForExpressions-[fdfSearchInAncestors];
|
Params.Flags:=fdfDefaultForExpressions-[fdfSearchInAncestors];
|
||||||
Params.ContextNode:=ClassNode;
|
Params.ContextNode:=InheritanceNode;
|
||||||
if CurPos.Flag in [cafRoundBracketClose,cafComma] then begin
|
if CurPos.Flag in [cafRoundBracketClose,cafComma] then begin
|
||||||
// simple identifier
|
// simple identifier
|
||||||
{$IFDEF ShowTriedContexts}
|
{$IFDEF ShowTriedContexts}
|
||||||
@ -5836,7 +5845,7 @@ begin
|
|||||||
// complex identifier
|
// complex identifier
|
||||||
{$IFDEF ShowTriedContexts}
|
{$IFDEF ShowTriedContexts}
|
||||||
DebugLn(['[TFindDeclarationTool.FindAncestorOfClass] ',
|
DebugLn(['[TFindDeclarationTool.FindAncestorOfClass] ',
|
||||||
' search complex ancestor class = "',ExtractNode(IdentifierNode,[]),'"']);
|
' search complex ancestor class = "',ExtractNode(IdentifierNode,[]),'" for class "',ExtractClassName(ClassNode,false),'"']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Params.Flags:=fdfDefaultForExpressions-[fdfSearchInAncestors];
|
Params.Flags:=fdfDefaultForExpressions-[fdfSearchInAncestors];
|
||||||
ExprType:=FindExpressionTypeOfTerm(IdentifierNode.StartPos,IdentifierNode.EndPos,Params,false);
|
ExprType:=FindExpressionTypeOfTerm(IdentifierNode.StartPos,IdentifierNode.EndPos,Params,false);
|
||||||
|
Loading…
Reference in New Issue
Block a user