mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 19:39:28 +02:00
codetools: find references: search simple function Result references
This commit is contained in:
parent
977f3e8331
commit
2504c0fce0
@ -2064,6 +2064,54 @@ var
|
|||||||
CleanCursorPos: integer;
|
CleanCursorPos: integer;
|
||||||
CursorNode, ClassNode: TCodeTreeNode;
|
CursorNode, ClassNode: TCodeTreeNode;
|
||||||
DirectSearch, SkipChecks, SearchForward: boolean;
|
DirectSearch, SkipChecks, SearchForward: boolean;
|
||||||
|
|
||||||
|
function IsPredefinedResult: boolean;
|
||||||
|
var
|
||||||
|
ANode: TCodeTreeNode;
|
||||||
|
p: Integer;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
p:=GetIdentStartPosition(Src,CleanCursorPos);
|
||||||
|
if p<1 then exit;
|
||||||
|
if CompareIdentifiers('Result',@Src[p])<>0 then exit;
|
||||||
|
|
||||||
|
if CursorNode.Desc<>ctnBeginBlock then exit;
|
||||||
|
if not CursorNode.HasParentOfType(ctnProcedure) then exit;
|
||||||
|
if not (cmsResult in Scanner.CompilerModeSwitches) then begin
|
||||||
|
debugln('Predefined "Result" inside a function body is not allowed');
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
ANode:=CursorNode.Parent;
|
||||||
|
while ANode<>nil do begin
|
||||||
|
if (ANode.Desc = ctnProcedure) then begin
|
||||||
|
if CompareIdentifiers('function',@Src[ANode.StartPos])=0 then
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
ANode:=ANode.Parent
|
||||||
|
end;
|
||||||
|
if ANode=nil then exit;
|
||||||
|
CursorNode:=ANode;
|
||||||
|
MoveCursorToCleanPos(CleanCursorPos);
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function FindFunctionResultTypeNode: TCodeTreeNode;
|
||||||
|
var ANode: TCodeTreeNode;
|
||||||
|
begin
|
||||||
|
Result:=nil;
|
||||||
|
if CursorNode.Desc<>ctnProcedure then exit;
|
||||||
|
ANode:=CursorNode.FirstChild;
|
||||||
|
if ANode.Desc<>ctnProcedureHead then exit;
|
||||||
|
ANode:=ANode.FirstChild;
|
||||||
|
while ANode<>nil do begin
|
||||||
|
if ANode.Desc=ctnIdentifier then break;
|
||||||
|
ANode:=Anode.NextBrother;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if (ANode<>nil) and (ANode.Desc=ctnIdentifier) then
|
||||||
|
Result:=ANode;
|
||||||
|
end;
|
||||||
|
|
||||||
function CheckIfNodeIsForwardDefinedClass(ANode: TCodeTreeNode;
|
function CheckIfNodeIsForwardDefinedClass(ANode: TCodeTreeNode;
|
||||||
ATool: TFindDeclarationTool): Boolean;
|
ATool: TFindDeclarationTool): Boolean;
|
||||||
var
|
var
|
||||||
@ -2272,7 +2320,6 @@ var
|
|||||||
BlockBottomLine := NewSkipBlockBottomLine;
|
BlockBottomLine := NewSkipBlockBottomLine;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
CleanPosInFront: integer;
|
CleanPosInFront: integer;
|
||||||
CursorAtIdentifier: boolean;
|
CursorAtIdentifier: boolean;
|
||||||
@ -2321,8 +2368,8 @@ begin
|
|||||||
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
||||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
if (fsfFindMainDeclaration in SearchSmartFlags)
|
if (fsfFindMainDeclaration in SearchSmartFlags)
|
||||||
and CleanPosIsDeclarationIdentifier(CleanCursorPos,CursorNode)
|
and CleanPosIsDeclarationIdentifier(CleanCursorPos,CursorNode) then
|
||||||
then begin
|
begin
|
||||||
//DebugLn(['TFindDeclarationTool.FindDeclaration CleanPosIsDeclarationIdentifier ',CursorNode.DescAsString]);
|
//DebugLn(['TFindDeclarationTool.FindDeclaration CleanPosIsDeclarationIdentifier ',CursorNode.DescAsString]);
|
||||||
NewExprType.Desc:=xtContext;
|
NewExprType.Desc:=xtContext;
|
||||||
NewExprType.Context.Tool:=Self;
|
NewExprType.Context.Tool:=Self;
|
||||||
@ -2427,6 +2474,23 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
exit;
|
exit;
|
||||||
|
end else if IsPredefinedResult then begin
|
||||||
|
// "Result" is allowed
|
||||||
|
Result:=false;
|
||||||
|
CleanCursorPos:=GetIdentStartPosition(Src,CleanCursorPos);
|
||||||
|
NewExprType.Desc:=xtContext;
|
||||||
|
NewExprType.Context.Tool:=Self;
|
||||||
|
NewExprType.Context.Node:=FindFunctionResultTypeNode();
|
||||||
|
if (NewExprType.Context.Node<>nil) and (NewExprType.Context.Node.StartPos<CleanCursorPos)
|
||||||
|
then begin
|
||||||
|
CleanPosToCaret(CleanCursorPos, NewPos);
|
||||||
|
NewTopLine := NewPos.Y;
|
||||||
|
BlockTopLine := NewTopLine;
|
||||||
|
BlockBottomLine := NewPos.Y;
|
||||||
|
Result:=true;
|
||||||
|
end else
|
||||||
|
NewExprType.Context.Node:=CursorNode;
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
DirectSearch:=false;
|
DirectSearch:=false;
|
||||||
@ -3697,7 +3761,7 @@ begin
|
|||||||
Result += lowercase(Node.Parent.DescAsString)+' ';
|
Result += lowercase(Node.Parent.DescAsString)+' ';
|
||||||
MoveCursorToNodeStart(Node);
|
MoveCursorToNodeStart(Node);
|
||||||
Result := Result + ReadIdentifierWithDots+' ';
|
Result := Result + ReadIdentifierWithDots+' ';
|
||||||
end
|
end;
|
||||||
else
|
else
|
||||||
DebugLn('ToDo: TFindDeclarationTool.GetSmartHint ',Node.DescAsString);
|
DebugLn('ToDo: TFindDeclarationTool.GetSmartHint ',Node.DescAsString);
|
||||||
end;
|
end;
|
||||||
@ -6573,6 +6637,8 @@ var
|
|||||||
var
|
var
|
||||||
p: LongInt;
|
p: LongInt;
|
||||||
begin
|
begin
|
||||||
|
if Node.Desc=ctnBeginBlock then
|
||||||
|
exit; // e.g. Result in function
|
||||||
p:=Node.StartPos;
|
p:=Node.StartPos;
|
||||||
if Node.Desc in [ctnProcedure,ctnProcedureHead] then begin
|
if Node.Desc in [ctnProcedure,ctnProcedureHead] then begin
|
||||||
MoveCursorToProcName(Node,true);
|
MoveCursorToProcName(Node,true);
|
||||||
@ -6748,7 +6814,7 @@ var
|
|||||||
then begin
|
then begin
|
||||||
// declaration itself found
|
// declaration itself found
|
||||||
//debugln(['ReadIdentifier declaration itself found, adding ...']);
|
//debugln(['ReadIdentifier declaration itself found, adding ...']);
|
||||||
AddReference(IdentStartPos)
|
AddReference(IdentStartPos);
|
||||||
end
|
end
|
||||||
else if CleanPosIsDeclarationIdentifier(IdentStartPos,CursorNode) then begin
|
else if CleanPosIsDeclarationIdentifier(IdentStartPos,CursorNode) then begin
|
||||||
// this identifier is another declaration with the same name
|
// this identifier is another declaration with the same name
|
||||||
|
@ -240,8 +240,7 @@ const
|
|||||||
DefaultCompilerModeSwitches: array[TCompilerMode] of TCompilerModeSwitches = (
|
DefaultCompilerModeSwitches: array[TCompilerMode] of TCompilerModeSwitches = (
|
||||||
// cmFPC
|
// cmFPC
|
||||||
[cmsString_pchar,cmsNested_comment,cmsRepeat_forward,cmsCvar_support,
|
[cmsString_pchar,cmsNested_comment,cmsRepeat_forward,cmsCvar_support,
|
||||||
cmsInitfinal,cmsHintdirective,cmsProperty,cmsDefault_inline,
|
cmsInitfinal,cmsHintdirective,cmsProperty,cmsDefault_inline],
|
||||||
cmsResult],
|
|
||||||
// cmDELPHI
|
// cmDELPHI
|
||||||
[cmsClass,cmsObjpas,cmsResult,cmsString_pchar,
|
[cmsClass,cmsObjpas,cmsResult,cmsString_pchar,
|
||||||
cmsPointer_2_procedure,cmsAutoderef,cmsTp_procvar,cmsInitfinal,cmsDefault_ansistring,
|
cmsPointer_2_procedure,cmsAutoderef,cmsTp_procvar,cmsInitfinal,cmsDefault_ansistring,
|
||||||
@ -260,7 +259,7 @@ const
|
|||||||
// cmGPC
|
// cmGPC
|
||||||
[cmsTp_procvar],
|
[cmsTp_procvar],
|
||||||
// cmTP
|
// cmTP
|
||||||
[cmsResult,cmsTp_procvar,cmsDuplicate_names],
|
[cmsTp_procvar,cmsDuplicate_names],
|
||||||
// cmOBJFPC
|
// cmOBJFPC
|
||||||
[cmsClass,cmsObjpas,cmsResult,cmsString_pchar,cmsNested_comment,
|
[cmsClass,cmsObjpas,cmsResult,cmsString_pchar,cmsNested_comment,
|
||||||
cmsRepeat_forward,cmsCvar_support,cmsInitfinal,cmsOut,cmsDefault_para,
|
cmsRepeat_forward,cmsCvar_support,cmsInitfinal,cmsOut,cmsDefault_para,
|
||||||
|
@ -1354,6 +1354,16 @@ begin
|
|||||||
Err:=Format(lisIdentifierCannotBeDotted,[FNewIdentifier]);
|
Err:=Format(lisIdentifierCannotBeDotted,[FNewIdentifier]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if ok
|
||||||
|
and (FNode.Desc=ctnBeginBlock) // 'Result'
|
||||||
|
and (CompareIdentifiers(PChar(FNewIdentifier),
|
||||||
|
PChar(FOldIdentifier))<>0) // only case change allowed
|
||||||
|
then begin
|
||||||
|
// Result inside function
|
||||||
|
ok:=false;
|
||||||
|
Err:=Format(lisIdentifierIsReservedWord,['Result']);
|
||||||
|
end;
|
||||||
|
|
||||||
if ok and (FTool<>nil) then begin
|
if ok and (FTool<>nil) then begin
|
||||||
i:=1;
|
i:=1;
|
||||||
while ok and (i<=length(FNewIdentifier)) do begin
|
while ok and (i<=length(FNewIdentifier)) do begin
|
||||||
|
6374
ide/lazarusidestrconsts.pas.orig
Normal file
6374
ide/lazarusidestrconsts.pas.orig
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user