codetools: find declaration: search in type of constant/variable

git-svn-id: trunk@29415 -
This commit is contained in:
mattias 2011-02-07 14:42:26 +00:00
parent 503ab21004
commit 6495ad0a79
2 changed files with 29 additions and 4 deletions

View File

@ -6007,15 +6007,39 @@ function TFindDeclarationTool.FindIdentifierInTypeOfConstant(
}
var
TypeNode: TCodeTreeNode;
ExprType: TExpressionType;
TypeParams: TFindDeclarationParams;
OldInput: TFindDeclarationInput;
begin
Result:=false;
//debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ',VarConstNode.DescAsString]);
TypeNode:=VarConstNode.FirstChild;
if TypeNode=nil then exit;
if TypeNode.Desc=ctnIdentifier then begin
debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ']);
//ExprType:=FindExpressionTypeOfTerm(TypeNode.StartPos,-1,Params);
// resolve type
//debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ']);
TypeParams:=TFindDeclarationParams.Create;
try
TypeParams.ContextNode:=TypeNode;
TypeParams.SetIdentifier(Self,nil,nil);
TypeParams.Flags:=fdfDefaultForExpressions+[fdfIgnoreCurContextNode];
ExprType:=FindExpressionTypeOfTerm(TypeNode.StartPos,-1,TypeParams,false);
//debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ExprType=',ExprTypeToString(ExprType)]);
finally
TypeParams.Free;
end;
if ExprType.Desc=xtContext then begin
if ExprType.Context.Node.Parent=nil then exit;
if not (ExprType.Context.Node.Parent.Desc in [ctnTypeDefinition,ctnGenericType])
then
exit;
// search identifier in type
Params.Save(OldInput);
Params.ContextNode:=ExprType.Context.Node;
Params.Flags:=Params.Flags-[fdfIgnoreCurContextNode,fdfSearchInParentNodes];
Result:=ExprType.Context.Tool.FindIdentifierInContext(Params);
Params.Load(OldInput,true);
end;
end;
end;

View File

@ -1357,7 +1357,7 @@ begin
Result:=nil;
exit;
end;
if Result.Desc=ctnConstDefinition then exit(nil);
if Result.Desc<>ctnVarDefinition then exit(nil);
Result:=Result.NextBrother;
end;
end;
@ -1506,6 +1506,7 @@ end;
function TPascalReaderTool.FindClassNode(CursorNode: TCodeTreeNode
): TCodeTreeNode;
// find class node of a node in a procedure (declaration or body)
begin
while CursorNode<>nil do begin
if CursorNode.Desc in AllClassObjects then begin