codetools: fixed ExtractFuncResultType for complex types and class operator

This commit is contained in:
mattias 2024-11-10 18:03:33 +01:00
parent 6f72566182
commit dfb7c2bd04
4 changed files with 22 additions and 18 deletions

View File

@ -70,14 +70,14 @@ interface
{$I codetools.inc}
{off $DEFINE CTDEBUG}
{$DEFINE VerboseCompletionAdds}
{off $DEFINE VerboseCompletionAdds}
{off $DEFINE VerboseUpdateProcBodySignatures}
{off $DEFINE VerboseCompleteMethod}
{off $DEFINE VerboseCreateMissingClassProcBodies}
{off $DEFINE VerboseCompleteLocalVarAssign}
{off $DEFINE VerboseCompleteEventAssign}
{off $DEFINE EnableCodeCompleteTemplates}
{$DEFINE VerboseGetPossibleInitsForVariable}
{off $DEFINE VerboseGetPossibleInitsForVariable}
{off $DEFINE VerboseGuessTypeOfIdentifier}
uses
@ -9417,7 +9417,7 @@ begin
RaiseException(20170421201833,'oops, I lost your class');
ProcNode:=FindProcNode(CursorNode,FJumpToProcHead,[phpInUpperCase,phpIgnoreForwards]);
if ProcNode=nil then begin
debugln(['TCodeCompletionCodeTool.ApplyChangesAndJumpToFirstNewProc Proc="',FJumpToProcHead.Name,'"']);
debugln(['TCodeCompletionCodeTool.ApplyChangesAndJumpToFirstNewProc Proc="',FJumpToProcHead.Name,'":"',FJumpToProcHead.ResultType,'" ',dbgs(FJumpToProcHead.Group)]);
RaiseException(20170421201835,ctsNewProcBodyNotFound);
end;
Result:=FindJumpPointInProcNode(ProcNode,NewPos,NewTopLine, BlockTopLine, BlockBottomLine);

View File

@ -839,6 +839,7 @@ begin
Txt:=CurProcName;
Flags:=Ord(ExtractProcedureGroup(ANode));
if TPascalMethodGroup(Flags)=mgClassOperator then
// for class operator the result type is part of the signature
ExtTxt4:=ExtractFuncResultType(ANode,Attr);
end;
Result.Add(NewNodeExt);

View File

@ -1346,6 +1346,7 @@ function TPascalParserTool.KeyWordFuncClassMethod: boolean;
class operator Inc(Rec: TRec1): TRec1;
class operator Initialize(var Rec: TRec1);
class operator Finalize(var Rec: TRec1);
class operator +(a,b:T):W; inline;
proc specifiers without parameters:
stdcall, virtual, abstract, dynamic, overload, override, cdecl, inline,
@ -1407,7 +1408,7 @@ begin
ReadNextAtom;
if IsGeneric or (Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE]) then
ReadGenericParamList(IsGeneric,true);
if (CurPos.Flag<>cafPoint) then begin
if (CurPos.Flag<>cafPoint) or (pphIsOperator in ParseAttr) then begin
// read rest
ReadTilProcedureHeadEnd(ParseAttr,HasForwardModifier);
end else begin
@ -1777,7 +1778,7 @@ function TPascalParserTool.ReadTilProcedureHeadEnd(
procedure Intf.Method = ImplementingMethodName;
function CommitUrlCacheEntry; // only Delphi
procedure MacProcName(c: char; ...); external;
operator + (dp1: TPoint; dp2: TPoint) dps: TPoint;
operator + (dp1: TPoint; dp2: TPoint) dps: TPoint; inline;
Add('Inc(Rec: TRec1): TRec1;
generic function RandomFrom<T>(const AValues:array of T):T;

View File

@ -312,6 +312,8 @@ type
procedure CalcMemSize(Stats: TCTMemStats); override;
end;
function dbgs(Group: TPascalMethodGroup): string; overload;
function CompareMethodHeaders(
const Method1Name: string; Method1Group: TPascalMethodGroup; const Method1ResultType: string;
const Method2Name: string; Method2Group: TPascalMethodGroup; const Method2ResultType: string): Integer; overload;
@ -324,6 +326,11 @@ function CompareCodeTreeNodeExtMethodHeaders(NodeData1, NodeData2: pointer): int
implementation
function dbgs(Group: TPascalMethodGroup): string;
begin
str(Group,Result);
end;
function CompareMethodHeaders(const Method1Name: string;
Method1Group: TPascalMethodGroup; const Method1ResultType: string;
const Method2Name: string; Method2Group: TPascalMethodGroup;
@ -2880,25 +2887,20 @@ end;
function TPascalReaderTool.ExtractFuncResultType(ProcNode: TCodeTreeNode;
Attr: TProcHeadAttributes): string;
var
aNode: TCodeTreeNode;
begin
Result := '';
if (ProcNode=nil) then exit;
if ProcNode.Desc=ctnProcedure then
ProcNode:=ProcNode.FirstChild;
if (ProcNode=nil) or(ProcNode.Desc<>ctnProcedureHead) then
if (ProcNode=nil) or (ProcNode.Desc<>ctnProcedureHead) then
Exit;
MoveCursorToCleanPos(ProcNode.EndPos);
CurNode:=ProcNode;
ReadPriorAtom;
if CurPos.Flag<>cafSemicolon then
Exit;
ReadPriorAtom;
if CurPos.Flag<>cafWord then
Exit;
if phpInUpperCase in Attr then
Result := GetUpAtom
else
Result := GetAtom;
aNode:=ProcNode.LastChild;
if aNode=nil then exit;
if aNode.Desc in [ctnIdentifier,ctnSpecialize] then begin
Result:=ExtractNode(aNode,Attr);
end;
end;
function TPascalReaderTool.ExtractDefinitionName(DefinitionNode: TCodeTreeNode