codetools: removed jitparsing of procs and proc types

This commit is contained in:
mattias 2025-11-29 17:22:11 +01:00
parent ae57d9d73c
commit e78c573108
10 changed files with 20 additions and 178 deletions

View File

@ -801,8 +801,6 @@ begin
// for procs: use ctnProcedureHead as parent
if ParentNode.Desc=ctnProcedure then
ParentNode:=ParentNode.FirstChild;
if (ParentNode.Desc=ctnProcedureHead) and NodeNeedsBuildSubTree(ParentNode) then
BuildSubTreeForProcHead(ParentNode);
ParamListNode:=ParentNode.FirstChild;
if (ParamListNode<>nil) and (ParamListNode.Desc<>ctnParameterList) then

View File

@ -1899,8 +1899,6 @@ begin
{$ENDIF}
if not ((CursorNode.Desc=ctnBeginBlock)
or CursorNode.HasParentOfType(ctnBeginBlock)) then exit;
if CursorNode.Desc=ctnBeginBlock then
BuildSubTreeForBeginBlock(CursorNode);
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
{$IFDEF VerboseCompleteLocalVarAssign}
@ -2256,8 +2254,6 @@ begin
AClassNode:=nil;
CheckWholeUnitParsed(CursorNode,ProcNode);
if CursorNode.Desc=ctnBeginBlock then
BuildSubTreeForBeginBlock(CursorNode);
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
{$IFDEF VerboseCompleteEventAssign}
@ -2370,8 +2366,6 @@ begin
{$ENDIF}
if not ((CursorNode.Desc=ctnBeginBlock)
or CursorNode.HasParentOfType(ctnBeginBlock)) then exit;
if CursorNode.Desc=ctnBeginBlock then
BuildSubTreeForBeginBlock(CursorNode);
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
{$IFDEF CTDEBUG}
@ -2510,8 +2504,6 @@ begin
{$ENDIF}
if not ((CursorNode.Desc=ctnBeginBlock)
or CursorNode.HasParentOfType(ctnBeginBlock)) then exit;
if CursorNode.Desc=ctnBeginBlock then
BuildSubTreeForBeginBlock(CursorNode);
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
{$IFDEF CTDEBUG}
@ -9562,8 +9554,6 @@ function TCodeCompletionCodeTool.CompleteCode(CursorPos: TCodeXYPosition;
// --> the UpIdentifier must not be preceded by a point ("MyObject.I" - if we want to complete I)
// and then do another check if it is not available with the "with" command, e.g.
MoveCursorToCleanPos(StatementNode.StartPos);
if StatementNode.Desc=ctnBeginBlock then
BuildSubTreeForBeginBlock(StatementNode);
LastAtomIsDot := False;
while CurPos.EndPos < CleanCursorPos do
begin

View File

@ -219,7 +219,7 @@ const
// CodeTreeNodeSubDescriptors
ctnsNone = 0;
ctnsNeedJITParsing = 1 shl 1;
ctnsNeedJITParsing = 1 shl 1; // deprecated in 'Laz 4.99';
ctnsHasParseError = 1 shl 2;
ctnsForwardDeclaration = 1 shl 3;
ctnsHasDefaultValue = 1 shl 4;

View File

@ -476,8 +476,6 @@ end;
procedure TCustomCodeTool.SaveRaiseException(id: int64; const AMessage: string;
ClearNicePos: boolean);
var
Node: TCodeTreeNode;
begin
LastErrorMessage:=AMessage;
LastErrorCurPos:=CurPos;
@ -490,16 +488,6 @@ begin
LastErrorNicePosition:=ErrorNicePosition;
end;
Node:=CurNode;
while (Node<>nil) do begin
if (ctnsNeedJITParsing and Node.SubDesc)>0 then begin
SetNodeParserError(Node,AMessage,CurPos.StartPos,
ErrorNicePosition);
break;
end;
Node:=Node.Parent;
end;
RaiseException(id,AMessage,ClearNicePos);
end;
@ -634,17 +622,12 @@ begin
begin
if (SubDesc and ctnsForwardDeclaration)>0 then Result:=ctsForward;
end;
ctnProcedureHead, ctnBeginBlock:
begin
if (SubDesc and ctnsNeedJITParsing)>0 then Result:=ctsUnparsed;
end;
ctnClass,ctnObject,ctnRecordType,ctnObjCClass,ctnObjCCategory,ctnObjCProtocol,
ctnCPPClass,ctnClassInterface,ctnDispinterface,
ctnTypeHelper,ctnRecordHelper,ctnClassHelper:
begin
Result:='';
if (SubDesc and ctnsForwardDeclaration)>0 then Result:=ctsForward;
if (SubDesc and ctnsNeedJITParsing)>0 then Result:=Result+ctsUnparsed;
end;
end;
if (SubDesc and ctnsHasParseError)>0 then Result:=Result+','+ctsHasError;

View File

@ -5053,7 +5053,7 @@ var
AbortNoCacheResult = false;
Proceed = true;
var
n, n2: TCodeTreeNode;
n: TCodeTreeNode;
DoneTypeName: boolean;
begin
repeat
@ -8443,7 +8443,6 @@ begin
CursorNode := FindDeepestNodeAtPos(CleanCursorPos, True);
end;
if CursorNode.Desc = ctnBeginBlock then begin
BuildSubTreeForBeginBlock(CursorNode);
CursorNode := FindDeepestNodeAtPos(CursorNode, CleanCursorPos, True);
end;
// set cursor on identifier

View File

@ -297,13 +297,10 @@ type
BuildTreeFlags: TBuildTreeFlags = []);
procedure BuildTreeAndGetCleanPos(const CursorPos: TCodeXYPosition;
out CleanCursorPos: integer; BuildTreeFlags: TBuildTreeFlags = []);
procedure BuildSubTreeForBeginBlock(BeginNode: TCodeTreeNode); virtual;
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode); virtual;
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode;
out FunctionResult: TCodeTreeNode);
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode; out FunctionResult: TCodeTreeNode);
procedure BuildSubTree(CleanCursorPos: integer); virtual;
procedure BuildSubTree(ANode: TCodeTreeNode); virtual;
function NodeNeedsBuildSubTree(ANode: TCodeTreeNode): boolean; virtual;
function BuildSubTreeAndFindDeepestNodeAtPos(
P: integer; ExceptionOnNotFound: boolean): TCodeTreeNode;
function BuildSubTreeAndFindDeepestNodeAtPos(StartNode: TCodeTreeNode;
@ -1082,72 +1079,6 @@ begin
{$ENDIF}
end;
procedure TPascalParserTool.BuildSubTreeForBeginBlock(BeginNode: TCodeTreeNode);
// reparse a quick parsed begin..end block and build the child nodes
// create nodes for 'with' and 'case' statements
procedure RaiseBeginExpected;
begin
SaveRaiseException(20170421194949,
'TPascalParserTool.BuildSubTreeForBeginBlock: begin expected, but '
+GetAtom+' found');
end;
var
MaxPos: integer;
begin
if BeginNode=nil then
RaiseException(20170421194953,
'TPascalParserTool.BuildSubTreeForBeginBlock: BeginNode=nil');
if BeginNode.Desc<>ctnBeginBlock then
RaiseException(20170421194958,
'TPascalParserTool.BuildSubTreeForBeginBlock: BeginNode.Desc='
+BeginNode.DescAsString);
if (BeginNode.SubDesc and ctnsNeedJITParsing)=0 then begin
// block already parsed
if (ctnsHasParseError and BeginNode.SubDesc)>0 then
RaiseNodeParserError(BeginNode);
exit;
end;
try
BeginNode.SubDesc:=BeginNode.SubDesc and (not ctnsNeedJITParsing);
// set CursorPos on 'begin'
MoveCursorToNodeStart(BeginNode);
CurSection:=ctnImplementation;
ReadNextAtom;
if not UpAtomIs('BEGIN') then
RaiseBeginExpected;
if BeginNode.EndPos<SrcLen then
Maxpos:=BeginNode.EndPos
else
MaxPos:=SrcLen;
repeat
ReadNextAtom;
if CurPos.StartPos>=MaxPos then break;
if BlockStatementStartKeyWordFuncList.DoIdentifier(@Src[CurPos.StartPos])
then begin
if not ReadTilBlockEnd(false,true) then
SaveRaiseEndOfSourceExpected(20170421195401);
end else if UpAtomIs('WITH') then
ReadWithStatement(true,true)
else if (UpAtomIs('PROCEDURE') or UpAtomIs('FUNCTION')) and AllowAnonymousFunctions then
ReadAnonymousFunction(true);
until false;
except
{$IFDEF ShowIgnoreErrorAfter}
DebugLn('TPascalParserTool.BuildSubTreeForBeginBlock ',MainFilename,' ERROR: ',LastErrorMessage);
{$ENDIF}
if (not IgnoreErrorAfterValid)
or (not IgnoreErrorAfterPositionIsInFrontOfLastErrMessage) then begin
raise;
end;
{$IFDEF ShowIgnoreErrorAfter}
DebugLn('TPascalParserTool.BuildSubTreeForBeginBlock ',MainFilename,' IGNORING ERROR: ',LastErrorMessage);
{$ENDIF}
end;
end;
function TPascalParserTool.KeyWordFuncClassIdentifier: boolean;
{ parse class variable or type or const
@ -2981,7 +2912,7 @@ var BlockType: TEndBlockType;
Format(ctsUnexpectedKeywordInBeginEndBlock,[GetAtom]));
end;
procedure CloseNode; inline;
procedure CloseNode;
begin
if Desc<>ctnNone then begin
CurNode.EndPos:=CurPos.EndPos;
@ -3814,8 +3745,7 @@ function TPascalParserTool.KeyWordFuncBeginEnd: boolean;
end;
var
ChildNodeCreated: boolean;
IsAsm, IsBegin, IsProc: Boolean;
IsProc: Boolean;
EndPos: Integer;
begin
//DebugLn('TPascalParserTool.KeyWordFuncBeginEnd CurNode=',CurNode.DescAsString);
@ -3824,27 +3754,13 @@ begin
[ctnProcedure,ctnProgram,ctnLibrary,ctnImplementation]))
then
SaveRaiseStringExpectedButAtomFound(20170421195640,'end');
IsAsm:=UpAtomIs('ASM');
IsBegin:=UpAtomIs('BEGIN');
IsProc:=CurNode.Desc=ctnProcedure;
ChildNodeCreated:=IsBegin or IsAsm;
if ChildNodeCreated then begin
CreateChildNode;
if IsBegin then
CurNode.Desc:=ctnBeginBlock
else
CurNode.Desc:=ctnAsmBlock;
CurNode.SubDesc:=ctnsNeedJITParsing;
end;
// search "end"
ReadTilBlockEnd(false,false);
ReadTilBlockEnd(false,true);
// close node
if ChildNodeCreated then begin
if IsProc then
CurNode.EndPos:=CurPos.EndPos // proc: the "end" is included
else
CurNode.EndPos:=CurPos.StartPos; // program: "end" is excluded, has its own node ctnEndPoint
EndChildNode;
if not IsProc then begin
// program, implementation: "end" is excluded, has its own node ctnEndPoint
CurNode.LastChild.EndPos:=CurPos.StartPos;
end;
if (CurSection<>ctnInterface)
and (CurNode<>nil) and (CurNode.Desc=ctnProcedure) then begin
@ -5153,10 +5069,9 @@ begin
ReadNextAtom;
CreateChildNode;
CurNode.Desc:=ctnProcedureHead;
CurNode.SubDesc:=ctnsNeedJITParsing;
if (CurPos.Flag=cafRoundBracketOpen) then begin
// read parameter list
ReadParamList(true,false,[]);
ReadParamList(true,false,[phpCreateNodes]);
end;
if IsFunction then begin
if (CurPos.Flag=cafColon) then begin
@ -6450,7 +6365,7 @@ var
begin
Result:=false;
{$IFDEF VerboseReadClosure}
writeln('TPascalParserTool.ReadClosure START Atom=',GetAtom,' CurSection=',NodeDescToStr(CurSection));
writeln('TPascalParserTool.ReadClosure START Atom=',GetAtom,' CurSection=',NodePathAsString(CurNode));
{$ENDIF}
Last:=LastAtoms.GetAtomAt(-1);
if not (Last.Flag in [cafAssignment,cafComma,cafEdgedBracketOpen,cafRoundBracketOpen])
@ -6478,7 +6393,7 @@ begin
ReadParamList(true,false,Attr);
end;
{$IFDEF VerboseReadClosure}
writeln('TPascalParserTool.ReadClosure head end "',GetAtom,'" CurNode=',NodeDescToStr(CurNode.Desc));
writeln('TPascalParserTool.ReadClosure head end "',GetAtom,'" CurNode=',NodeDescriptionAsString(CurNode.Desc));
{$ENDIF}
// read function result
if IsFunction then begin
@ -6492,7 +6407,7 @@ begin
ReadTypeReference(true);
end;
{$IFDEF VerboseReadClosure}
writeln('TPascalParserTool.ReadClosure modifiers ',GetAtom,' CurNode=',NodeDescToStr(CurNode.Desc));
writeln('TPascalParserTool.ReadClosure modifiers ',GetAtom,' CurNode=',NodeDescriptionAsString(CurNode.Desc));
{$ENDIF}
// read modifiers conventions
while (CurPos.StartPos<=SrcLen)
@ -6529,7 +6444,7 @@ begin
until false;
// read begin block
{$IFDEF VerboseReadClosure}
writeln('TPascalParserTool.ReadClosure END ',GetAtom,' CurNode=',NodeDescToStr(CurNode.Desc),' ',CurPos.EndPos);
writeln('TPascalParserTool.ReadClosure END ',GetAtom,' CurNode=',NodeDescriptionAsString(CurNode.Desc),' ',CurPos.EndPos);
{$ENDIF}
end;
@ -6658,8 +6573,7 @@ begin
+'internal error: invalid ProcNode');
end;
ProcHeadNode:=ProcNode.FirstChild;
if (ProcHeadNode<>nil)
and ((ProcHeadNode.SubDesc and ctnsNeedJITParsing)=0) then begin
if (ProcHeadNode<>nil) then begin
// proc head already parsed
if (ProcHeadNode<>nil) and ((ctnsHasParseError and ProcHeadNode.SubDesc)>0)
then
@ -6700,7 +6614,6 @@ begin
SaveRaiseCharExpectedButAtomFound(20170421195925,';')
else
SaveRaiseStringExpectedButAtomFound(20170421195928,'identifier');
ProcHeadNode.SubDesc:=ProcHeadNode.SubDesc and (not ctnsNeedJITParsing);
if not (pphIsType in ParseAttr) then begin
// read procedure name of a class method (the name after the . )
@ -6754,18 +6667,6 @@ begin
case ANode.Desc of
ctnProcedure,ctnProcedureHead:
BuildSubTreeForProcHead(ANode);
ctnBeginBlock:
BuildSubTreeForBeginBlock(ANode);
end;
end;
function TPascalParserTool.NodeNeedsBuildSubTree(ANode: TCodeTreeNode
): boolean;
begin
Result:=false;
if ANode=nil then exit;
if ANode.Desc in (AllClasses+[ctnProcedureHead,ctnBeginBlock]) then begin
Result:=(ANode.SubDesc and ctnsNeedJITParsing)>0;
end;
end;
@ -6778,18 +6679,9 @@ end;
function TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos(
StartNode: TCodeTreeNode; P: integer; ExceptionOnNotFound: boolean
): TCodeTreeNode;
var
Node: TCodeTreeNode;
begin
Result:=FindDeepestNodeAtPos(StartNode,P,ExceptionOnNotFound);
//debugln('TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos A ',Result.DescAsString,' ',dbgs(NodeNeedsBuildSubTree(Result)));
while NodeNeedsBuildSubTree(Result) do begin
BuildSubTree(Result);
Node:=FindDeepestNodeAtPos(Result,P,ExceptionOnNotFound);
if Node=Result then break;
Result:=Node;
//debugln('TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos B ',Result.DescAsString,' ',dbgs(NodeNeedsBuildSubTree(Result)));
end;
// re-raise parse errors
if (Result<>nil) and ((ctnsHasParseError and Result.SubDesc)>0) then
RaiseNodeParserError(Result);

View File

@ -193,8 +193,7 @@ type
ProcSpec: TProcedureSpecifier): boolean;
function ProcNodeHasParamList(ProcNode: TCodeTreeNode): boolean;
function ProcNodeHasOfObject(ProcNode: TCodeTreeNode): boolean;
function GetProcParamList(ProcNode: TCodeTreeNode;
Parse: boolean = true): TCodeTreeNode;
function GetProcParamList(ProcNode: TCodeTreeNode): TCodeTreeNode;
function GetProcResultNode(ProcNode: TCodeTreeNode): TCodeTreeNode;
function NodeIsInAMethod(Node: TCodeTreeNode): boolean;
function NodeIsMethodDecl(ProcNode: TCodeTreeNode): boolean;
@ -2341,8 +2340,6 @@ var
Child: TCodeTreeNode;
begin
//debugln(['TPascalReaderTool.ForEachIdentifierInNode START ',Node.DescAsString]);
if NodeNeedsBuildSubTree(Node) then
BuildSubTree(Node);
if Node.FirstChild<>nil then begin
EndPos:=Node.StartPos;
Child:=Node.FirstChild;
@ -3066,8 +3063,6 @@ begin
begin
ProcNode:=ProcNode.FirstChild;
if ProcNode=nil then exit;
if (ProcNode.SubDesc and ctnsNeedJITParsing)>0 then
BuildSubTreeForProcHead(ProcNode);
ProcNode:=ProcNode.FirstChild;
if (ProcNode=nil) then exit;
if ProcNode.Desc=ctnParameterList then
@ -3635,9 +3630,6 @@ begin
+'internal error: invalid ProcNode');
end;
{$ENDIF}
if (ProcNode.FirstChild=nil)
or ((ProcNode.SubDesc and ctnsNeedJITParsing)>0) then
BuildSubTreeForProcHead(ProcNode);
// ToDo: ppu, dcu
@ -3680,8 +3672,7 @@ begin
Result:=UpAtomIs('OF') and ReadNextUpAtomIs('OBJECT');
end;
function TPascalReaderTool.GetProcParamList(ProcNode: TCodeTreeNode;
Parse: boolean): TCodeTreeNode;
function TPascalReaderTool.GetProcParamList(ProcNode: TCodeTreeNode): TCodeTreeNode;
begin
Result:=ProcNode;
if Result=nil then exit;
@ -3690,8 +3681,6 @@ begin
if Result=nil then exit;
end;
if Result.Desc<>ctnProcedureHead then exit(nil);
if Parse then
BuildSubTreeForProcHead(Result);
Result:=Result.FirstChild;
while Result<>nil do begin
if Result.Desc=ctnParameterList then exit;

View File

@ -8128,14 +8128,12 @@ begin
case Node.Desc of
ctnProcedure,ctnProcedureHead:
BuildSubTreeForProcHead(Node);
ctnBeginBlock:
if WithStatements then
BuildSubTreeForBeginBlock(Node);
ctnImplementation:
if ord(Range)<ord(lsrImplementationStart) then exit;
end;
Node:=Node.Next;
end;
if WithStatements then ;
end;
function TStandardCodeTool.Explore(WithStatements: boolean;

View File

@ -360,12 +360,12 @@ begin
if not Marker.MarkRefPosAsFound(PCodeXYPosition(ListOfPCodeXYPosition[j])^.X, PCodeXYPosition(ListOfPCodeXYPosition[j])^.Y) then begin
if Marker.ExactMarker then begin
WriteSource(CursorPos);
Fail('FindRefs: Returend unknown position. Bad ref at '+MainTool.CleanPosToStr(Marker.CleanPos, True)+' '+format('%d,%d',[CursorPos.X,CursorPos.Y])+' for marker '+s);
Fail('FindRefs: Returend unknown position. Bad ref at '+MainTool.CleanPosToStr(Marker.CleanPos, True)+' '+format('%d,%d',[CursorPos.X,CursorPos.Y])+' for marker "'+Marker.Name+'"');
end;
end;
if Marker.MarkRefPosAsFound(-PCodeXYPosition(ListOfPCodeXYPosition[j])^.X, -PCodeXYPosition(ListOfPCodeXYPosition[j])^.Y) then begin
WriteSource(CursorPos);
Fail('FindRefs: Returend position explicityl excluded from refs. Bad ref at '+MainTool.CleanPosToStr(Marker.CleanPos, True)+' '+format('%d,%d',[CursorPos.X,CursorPos.Y])+' for marker '+s);
Fail('FindRefs: Returend position explicityl excluded from refs. Bad ref at '+MainTool.CleanPosToStr(Marker.CleanPos, True)+' '+format('%d,%d',[CursorPos.X,CursorPos.Y])+' for marker "'+Marker.Name+'"');
end;
end;
end;

View File

@ -1290,13 +1290,6 @@ begin
ctnBeginBlock:
begin
if (CodeNode.SubDesc and ctnsNeedJITParsing)<>0 then
begin
try
Tool.BuildSubTreeForBeginBlock(CodeNode);
except
end;
end;
if (cefcLongProcs in ObserverCats)
and (CodeNode.Parent.Desc=ctnProcedure) then begin
LineCnt:=LineEndCount(Tool.Src,CodeNode.StartPos,CodeNode.EndPos,i);