mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-06 12:18:17 +02:00
codetools: find declaration: started search in type of var/const
git-svn-id: trunk@29407 -
This commit is contained in:
parent
73701772d8
commit
0c415f0a1d
@ -42,6 +42,7 @@ var
|
|||||||
X: Integer;
|
X: Integer;
|
||||||
Y: Integer;
|
Y: Integer;
|
||||||
Filename: String;
|
Filename: String;
|
||||||
|
Line: String;
|
||||||
begin
|
begin
|
||||||
if (ParamCount>=1) and (Paramcount<3) then begin
|
if (ParamCount>=1) and (Paramcount<3) then begin
|
||||||
writeln('Usage:');
|
writeln('Usage:');
|
||||||
@ -87,22 +88,29 @@ begin
|
|||||||
writeln('FPCTARGET=',Options.TargetOS);
|
writeln('FPCTARGET=',Options.TargetOS);
|
||||||
writeln('FPCTARGETCPU=',Options.TargetProcessor);
|
writeln('FPCTARGETCPU=',Options.TargetProcessor);
|
||||||
if (ParamCount>=3) then begin
|
if (ParamCount>=3) then begin
|
||||||
Options.TestPascalFile:=CleanAndExpandFilename(ParamStr(1));
|
Filename:=CleanAndExpandFilename(ParamStr(1));
|
||||||
X:=StrToInt(ParamStr(2));
|
X:=StrToInt(ParamStr(2));
|
||||||
Y:=StrToInt(ParamStr(3));
|
Y:=StrToInt(ParamStr(3));
|
||||||
end;
|
end;
|
||||||
|
writeln('File: ',Filename,' Line=',Y,' Column=',X);
|
||||||
|
|
||||||
// Step 1: load the file
|
// Step 1: load the file
|
||||||
Code:=CodeToolBoss.LoadFile(Filename,false,false);
|
Code:=CodeToolBoss.LoadFile(Filename,false,false);
|
||||||
if Code=nil then
|
if Code=nil then
|
||||||
raise Exception.Create('loading failed '+Filename);
|
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
|
// Step 2: find declaration
|
||||||
if CodeToolBoss.FindDeclaration(Code,X,Y,NewCode,NewX,NewY,NewTopLine) then
|
if CodeToolBoss.FindDeclaration(Code,X,Y,NewCode,NewX,NewY,NewTopLine) then
|
||||||
begin
|
begin
|
||||||
writeln('Declaration found: ',NewCode.Filename,' Line=',NewY,' Column=',NewX);
|
writeln('Declaration found: ',NewCode.Filename,' Line=',NewY,' Column=',NewX);
|
||||||
end else begin
|
end else begin
|
||||||
writeln('Parse error: ',CodeToolBoss.ErrorMessage);
|
if CodeToolBoss.ErrorMessage<>'' then
|
||||||
|
writeln('Parse error: ',CodeToolBoss.ErrorMessage)
|
||||||
|
else
|
||||||
|
writeln('Declaration not found');
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
on E: Exception do begin
|
on E: Exception do begin
|
||||||
|
@ -2713,6 +2713,7 @@ var
|
|||||||
NameNode:=ContextNode.FirstChild;
|
NameNode:=ContextNode.FirstChild;
|
||||||
if NameNode=nil then exit;
|
if NameNode=nil then exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (fdfCollect in Params.Flags)
|
if (fdfCollect in Params.Flags)
|
||||||
or CompareSrcIdentifiers(NameNode.StartPos,Params.Identifier)
|
or CompareSrcIdentifiers(NameNode.StartPos,Params.Identifier)
|
||||||
then begin
|
then begin
|
||||||
@ -2740,13 +2741,18 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SearchInConstant: boolean;
|
function SearchInTypeOfVarConst: boolean;
|
||||||
// returns: true if ok to exit
|
// returns: true if ok to exit
|
||||||
// false if search should continue
|
// false if search should continue
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (ContextNode.Parent.Desc in [ctnVarDefinition,ctnConstDefinition]) then
|
//debugln(['SearchInTypeOfVarConst ',ContextNode.Parent.DescAsString]);
|
||||||
Result:=FindIdentifierInTypeOfConstant(ContextNode.Parent,Params);
|
if ContextNode.Parent.Desc in [ctnConstDefinition,ctnVarDefinition] then
|
||||||
|
begin
|
||||||
|
if FindIdentifierInTypeOfConstant(ContextNode.Parent,Params) then begin
|
||||||
|
Result:=CheckResult(true,false);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SearchInEnumDefinition: boolean;
|
function SearchInEnumDefinition: boolean;
|
||||||
@ -3089,7 +3095,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
if FirstSearchedNode=nil then FirstSearchedNode:=ContextNode;
|
if FirstSearchedNode=nil then FirstSearchedNode:=ContextNode;
|
||||||
LastSearchedNode:=ContextNode;
|
LastSearchedNode:=ContextNode;
|
||||||
|
|
||||||
case ContextNode.Desc of
|
case ContextNode.Desc of
|
||||||
|
|
||||||
ctnTypeSection, ctnVarSection, ctnConstSection, ctnResStrSection,
|
ctnTypeSection, ctnVarSection, ctnConstSection, ctnResStrSection,
|
||||||
@ -3111,8 +3117,10 @@ begin
|
|||||||
ctnGlobalProperty, ctnGenericType:
|
ctnGlobalProperty, ctnGenericType:
|
||||||
if SearchInTypeVarConstPropDefinition then exit;
|
if SearchInTypeVarConstPropDefinition then exit;
|
||||||
|
|
||||||
ctnConstant:
|
ctnIdentifier:
|
||||||
if SearchInConstant then exit;
|
if (ContextNode.Parent.Desc in [ctnConstDefinition,ctnVarDefinition])
|
||||||
|
and (ContextNode=ContextNode.Parent.FirstChild)
|
||||||
|
and SearchInTypeOfVarConst then exit;
|
||||||
|
|
||||||
ctnEnumIdentifier:
|
ctnEnumIdentifier:
|
||||||
if SearchInEnumDefinition then exit;
|
if SearchInEnumDefinition then exit;
|
||||||
@ -5997,11 +6005,17 @@ function TFindDeclarationTool.FindIdentifierInTypeOfConstant(
|
|||||||
{ const a: atype = context;
|
{ const a: atype = context;
|
||||||
for example: const p: TPoint = (x:0; y:0);
|
for example: const p: TPoint = (x:0; y:0);
|
||||||
}
|
}
|
||||||
|
var
|
||||||
|
TypeNode: TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if VarConstNode.FirstChild=nil then exit;
|
//debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ',VarConstNode.DescAsString]);
|
||||||
if VarConstNode.Desc=ctnIdentifier then begin
|
TypeNode:=VarConstNode.FirstChild;
|
||||||
|
if TypeNode=nil then exit;
|
||||||
|
if TypeNode.Desc=ctnIdentifier then begin
|
||||||
debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ']);
|
debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ']);
|
||||||
|
//ExprType:=FindExpressionTypeOfTerm(TypeNode.StartPos,-1,Params);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user