codetools: find declaration: started search in type of var/const

git-svn-id: trunk@29407 -
This commit is contained in:
mattias 2011-02-07 10:05:58 +00:00
parent 73701772d8
commit 0c415f0a1d
2 changed files with 32 additions and 10 deletions

View File

@ -42,6 +42,7 @@ var
X: Integer;
Y: Integer;
Filename: String;
Line: String;
begin
if (ParamCount>=1) and (Paramcount<3) then begin
writeln('Usage:');
@ -87,22 +88,29 @@ begin
writeln('FPCTARGET=',Options.TargetOS);
writeln('FPCTARGETCPU=',Options.TargetProcessor);
if (ParamCount>=3) then begin
Options.TestPascalFile:=CleanAndExpandFilename(ParamStr(1));
Filename:=CleanAndExpandFilename(ParamStr(1));
X:=StrToInt(ParamStr(2));
Y:=StrToInt(ParamStr(3));
end;
writeln('File: ',Filename,' Line=',Y,' Column=',X);
// Step 1: load the file
Code:=CodeToolBoss.LoadFile(Filename,false,false);
if Code=nil then
raise Exception.Create('loading failed '+Filename);
Line:=Code.GetLine(Y-1);
writeln('Line ',Y,': ',copy(Line,1,X-1),'|',copy(Line,X,length(Line)));
// Step 2: find declaration
if CodeToolBoss.FindDeclaration(Code,X,Y,NewCode,NewX,NewY,NewTopLine) then
begin
writeln('Declaration found: ',NewCode.Filename,' Line=',NewY,' Column=',NewX);
end else begin
writeln('Parse error: ',CodeToolBoss.ErrorMessage);
if CodeToolBoss.ErrorMessage<>'' then
writeln('Parse error: ',CodeToolBoss.ErrorMessage)
else
writeln('Declaration not found');
end;
except
on E: Exception do begin

View File

@ -2713,6 +2713,7 @@ var
NameNode:=ContextNode.FirstChild;
if NameNode=nil then exit;
end;
if (fdfCollect in Params.Flags)
or CompareSrcIdentifiers(NameNode.StartPos,Params.Identifier)
then begin
@ -2740,13 +2741,18 @@ var
end;
end;
function SearchInConstant: boolean;
function SearchInTypeOfVarConst: boolean;
// returns: true if ok to exit
// false if search should continue
begin
Result:=false;
if (ContextNode.Parent.Desc in [ctnVarDefinition,ctnConstDefinition]) then
Result:=FindIdentifierInTypeOfConstant(ContextNode.Parent,Params);
//debugln(['SearchInTypeOfVarConst ',ContextNode.Parent.DescAsString]);
if ContextNode.Parent.Desc in [ctnConstDefinition,ctnVarDefinition] then
begin
if FindIdentifierInTypeOfConstant(ContextNode.Parent,Params) then begin
Result:=CheckResult(true,false);
end;
end;
end;
function SearchInEnumDefinition: boolean;
@ -3089,7 +3095,7 @@ begin
end;
if FirstSearchedNode=nil then FirstSearchedNode:=ContextNode;
LastSearchedNode:=ContextNode;
case ContextNode.Desc of
ctnTypeSection, ctnVarSection, ctnConstSection, ctnResStrSection,
@ -3111,8 +3117,10 @@ begin
ctnGlobalProperty, ctnGenericType:
if SearchInTypeVarConstPropDefinition then exit;
ctnConstant:
if SearchInConstant then exit;
ctnIdentifier:
if (ContextNode.Parent.Desc in [ctnConstDefinition,ctnVarDefinition])
and (ContextNode=ContextNode.Parent.FirstChild)
and SearchInTypeOfVarConst then exit;
ctnEnumIdentifier:
if SearchInEnumDefinition then exit;
@ -5997,11 +6005,17 @@ function TFindDeclarationTool.FindIdentifierInTypeOfConstant(
{ const a: atype = context;
for example: const p: TPoint = (x:0; y:0);
}
var
TypeNode: TCodeTreeNode;
begin
Result:=false;
if VarConstNode.FirstChild=nil then exit;
if VarConstNode.Desc=ctnIdentifier then begin
//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);
end;
end;