mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-24 21:50:29 +01:00
codetools: find declaration: fixed resolving complex alias, bug #27312
git-svn-id: trunk@50272 -
This commit is contained in:
parent
05335610bd
commit
5215fb80eb
@ -4606,12 +4606,10 @@ var
|
|||||||
TestContext: TFindContext;
|
TestContext: TFindContext;
|
||||||
IdentStart: LongInt;
|
IdentStart: LongInt;
|
||||||
SubParams: TFindDeclarationParams;
|
SubParams: TFindDeclarationParams;
|
||||||
aNode: TCodeTreeNode;
|
ExprType: TExpressionType;
|
||||||
AnUnitIdentifier: String;
|
|
||||||
UnitInFilename: AnsiString;
|
|
||||||
NewCode: TCodeBuffer;
|
|
||||||
begin
|
begin
|
||||||
IsPredefined:=false;
|
IsPredefined:=false;
|
||||||
|
|
||||||
SubParams:=TFindDeclarationParams.Create(Params);
|
SubParams:=TFindDeclarationParams.Create(Params);
|
||||||
try
|
try
|
||||||
SubParams.GenParams := Params.GenParams;
|
SubParams.GenParams := Params.GenParams;
|
||||||
@ -4621,7 +4619,6 @@ var
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
SubParams.Flags:=[fdfSearchInParentNodes,fdfExceptionOnNotFound]
|
SubParams.Flags:=[fdfSearchInParentNodes,fdfExceptionOnNotFound]
|
||||||
+(fdfGlobals*SubParams.Flags);
|
+(fdfGlobals*SubParams.Flags);
|
||||||
SubParams.SetIdentifier(Self,@Src[IdentStart],nil);
|
|
||||||
SubParams.ContextNode:=StartNode.Parent;
|
SubParams.ContextNode:=StartNode.Parent;
|
||||||
if (SubParams.ContextNode.Desc in (AllIdentifierDefinitions))
|
if (SubParams.ContextNode.Desc in (AllIdentifierDefinitions))
|
||||||
then begin
|
then begin
|
||||||
@ -4634,56 +4631,30 @@ var
|
|||||||
if SubParams.ContextNode.Desc=ctnProcedureHead then
|
if SubParams.ContextNode.Desc=ctnProcedureHead then
|
||||||
// skip search in proc parameters
|
// skip search in proc parameters
|
||||||
SubParams.ContextNode:=SubParams.ContextNode.Parent;
|
SubParams.ContextNode:=SubParams.ContextNode.Parent;
|
||||||
|
|
||||||
|
MoveCursorToCleanPos(CleanPos);
|
||||||
|
ReadNextAtom;
|
||||||
|
ReadNextAtom;
|
||||||
|
if (CurPos.Flag=cafPoint) or AtomIsChar('<') then begin
|
||||||
|
// this is an expression, e.g. A.B or A<B>
|
||||||
|
ExprType:=FindExpressionTypeOfTerm(CleanPos,-1,SubParams,false);
|
||||||
|
if ExprType.Desc=xtContext then begin
|
||||||
|
Context:=ExprType.Context;
|
||||||
|
end else begin
|
||||||
|
IsPredefined:=true;
|
||||||
|
end;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
SubParams.SetIdentifier(Self,@Src[IdentStart],nil);
|
||||||
TypeFound:=FindIdentifierInContext(SubParams);
|
TypeFound:=FindIdentifierInContext(SubParams);
|
||||||
if TypeFound and (SubParams.NewNode.Desc=ctnUseUnit)
|
|
||||||
and (SubParams.NewCodeTool=Self)
|
|
||||||
then begin
|
|
||||||
{$IFDEF ShowTriedBaseContexts}
|
|
||||||
debugln(['TFindDeclarationTool.FindBaseTypeOfNode.SearchIdentifier is an entry in the uses section, getting tool...']);
|
|
||||||
{$ENDIF}
|
|
||||||
AnUnitIdentifier:=ExtractUsedUnitName(SubParams.NewNode,@UnitInFilename);
|
|
||||||
NewCode:=FindUnitSource(AnUnitIdentifier,UnitInFilename,true,SubParams.NewNode.StartPos);
|
|
||||||
if Assigned(FOnGetCodeToolForBuffer) then
|
|
||||||
SubParams.NewCodeTool:=FOnGetCodeToolForBuffer(Self,NewCode,false)
|
|
||||||
else if NewCode=TCodeBuffer(Scanner.MainCode) then
|
|
||||||
SubParams.NewCodeTool:=Self;
|
|
||||||
if (SubParams.NewCodeTool=nil) then begin
|
|
||||||
CurPos.StartPos:=-1;
|
|
||||||
RaiseException(Format('Unable to create codetool for "%s"',[NewCode.Filename]));
|
|
||||||
end;
|
|
||||||
SubParams.NewCodeTool.BuildTree(lsrImplementationStart);
|
|
||||||
SubParams.NewNode:=SubParams.NewCodeTool.Tree.Root;
|
|
||||||
end;
|
|
||||||
if TypeFound and (SubParams.NewNode.Desc in [ctnUnit,ctnLibrary,ctnPackage])
|
if TypeFound and (SubParams.NewNode.Desc in [ctnUnit,ctnLibrary,ctnPackage])
|
||||||
then begin
|
then begin
|
||||||
// identifier is a unit
|
// identifier is a unit
|
||||||
// => check for AUnitName.typename
|
// => type expected
|
||||||
MoveCursorToCleanPos(IdentStart);
|
MoveCursorToCleanPos(IdentStart);
|
||||||
ReadNextAtom; // read AUnitName
|
ReadNextAtom; // read AUnitName
|
||||||
if not ReadNextAtomIsChar('.') then
|
|
||||||
SaveRaiseCharExpectedButAtomFound('.');
|
SaveRaiseCharExpectedButAtomFound('.');
|
||||||
ReadNextAtom; // read type identifier
|
|
||||||
IdentStart:=CurPos.StartPos;
|
|
||||||
{$IFDEF ShowTriedBaseContexts}
|
|
||||||
debugln(['TFindDeclarationTool.FindBaseTypeOfNode.SearchIdentifier searching identifier "',GetIdentifier(@Src[IdentStart]),'" in unit ...']);
|
|
||||||
{$ENDIF}
|
|
||||||
AtomIsIdentifierE;
|
|
||||||
SubParams.SetIdentifier(Self,@Src[IdentStart],nil);
|
|
||||||
SubParams.Flags:=[fdfExceptionOnNotFound];
|
|
||||||
if SubParams.NewCodeTool=Self then begin
|
|
||||||
// search in whole unit/program
|
|
||||||
aNode:=Tree.Root;
|
|
||||||
if aNode.Desc=ctnUnit then begin
|
|
||||||
aNode:=FindImplementationNode;
|
|
||||||
if aNode=nil then
|
|
||||||
aNode:=FindInterfaceNode;
|
|
||||||
end;
|
|
||||||
SubParams.ContextNode:=aNode;
|
|
||||||
TypeFound:=FindIdentifierInContext(SubParams);
|
|
||||||
end else begin
|
|
||||||
// search in interface
|
|
||||||
TypeFound:=SubParams.NewCodeTool.FindIdentifierInInterface(Self,SubParams);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
if TypeFound and (SubParams.NewNode.Desc=ctnGenericParameter) then begin
|
if TypeFound and (SubParams.NewNode.Desc=ctnGenericParameter) then begin
|
||||||
TypeFound:=SubParams.FindGenericParamType;
|
TypeFound:=SubParams.FindGenericParamType;
|
||||||
@ -4710,9 +4681,7 @@ var
|
|||||||
end else begin
|
end else begin
|
||||||
// predefined identifier
|
// predefined identifier
|
||||||
IsPredefined:=true;
|
IsPredefined:=true;
|
||||||
exit;
|
|
||||||
end;
|
end;
|
||||||
// ToDo: resolve sub classes
|
|
||||||
|
|
||||||
finally
|
finally
|
||||||
SubParams.Free;
|
SubParams.Free;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user