diff --git a/components/codetools/methodjumptool.pas b/components/codetools/methodjumptool.pas index cb7aea18a0..4f91649da2 100644 --- a/components/codetools/methodjumptool.pas +++ b/components/codetools/methodjumptool.pas @@ -78,6 +78,8 @@ type IgnoreJumpCentered: boolean): boolean; function FindNodeInTree(ATree: TAVLTree; const UpperCode: string): TCodeTreeNodeExtension; + procedure WriteCodeTreeNodeExtTree(ExtTree: TAVLTree); + public property AdjustTopLineDueToComment: boolean read FAdjustTopLineDueToComment write FAdjustTopLineDueToComment; end; @@ -442,6 +444,7 @@ begin ProcNode,[phpInUpperCase,phpIgnoreForwards], false); if Result then exit; + // there is no proc with same name and param list // gather forward procs if (ProcNode.Parent.Desc=ctnImplementation) @@ -451,12 +454,17 @@ begin StartNode:=ProcNode.Parent.FirstChild; SearchForNodes:=GatherProcNodes(StartNode, [phpInUpperCase,phpIgnoreProcsWithBody,phpIgnoreMethods],''); + // gather proc bodies SearchInNodes:=GatherProcNodes(StartNode, [phpInUpperCase,phpIgnoreForwards,phpIgnoreMethods],''); + try // remove corresponding procs - RemoveCorrespondingProcNodes(SearchInNodes,SearchForNodes,true); + RemoveCorrespondingProcNodes(SearchForNodes,SearchInNodes,true); + + //writeln('TMethodJumpingCodeTool.FindJumpPoint 2E Unforwarded Body Procs:'); + //WriteCodeTreeNodeExtTree(SearchInNodes); // search for a proc body with same name // and no corresponding forward proc @@ -573,69 +581,80 @@ begin exit; end else begin // search forward procedure + {$IFDEF CTDEBUG} + writeln('TMethodJumpingCodeTool.FindJumpPoint 5A searching exact forward proc ...'); + {$ENDIF} Result:=FindBestProcNode(ProcNode,[phpInUpperCase], StartNode,[phpInUpperCase,phpIgnoreProcsWithBody], false); - if not Result then begin - // there is no proc with same name and param list - // gather forward procs - if (ProcNode.Parent.Desc=ctnImplementation) - and (ProcNode.Parent.PriorBrother.FirstChild<>nil) then - StartNode:=ProcNode.Parent.PriorBrother.FirstChild - else - StartNode:=ProcNode.Parent.FirstChild; - SearchInNodes:=GatherProcNodes(StartNode, - [phpInUpperCase,phpIgnoreProcsWithBody,phpIgnoreMethods],''); - // gather proc bodies - SearchForNodes:=GatherProcNodes(StartNode, - [phpInUpperCase,phpIgnoreForwards,phpIgnoreMethods],''); - try - // remove corresponding procs - RemoveCorrespondingProcNodes(SearchInNodes,SearchForNodes,true); + if Result then exit; + + {$IFDEF CTDEBUG} + writeln('TMethodJumpingCodeTool.FindJumpPoint 5B searching similar forward proc'); + {$ENDIF} + // there is no proc with same name and param list + // gather forward procs + if (ProcNode.Parent.Desc=ctnImplementation) + and (ProcNode.Parent.PriorBrother.FirstChild<>nil) then + StartNode:=ProcNode.Parent.PriorBrother.FirstChild + else + StartNode:=ProcNode.Parent.FirstChild; + SearchInNodes:=GatherProcNodes(StartNode, + [phpInUpperCase,phpIgnoreProcsWithBody,phpIgnoreMethods],''); + + // gather proc bodies + SearchForNodes:=GatherProcNodes(StartNode, + [phpInUpperCase,phpIgnoreForwards,phpIgnoreMethods],''); - // search for a forward proc with same name - // and no corresponding proc body - SearchedProcname:=ExtractProcName(ProcNode,[phpInUpperCase]); - DefAVLNode:=SearchInNodes.FindLowest; - while DefAVLNode<>nil do begin - ANode:=TCodeTreeNodeExtension(DefAVLNode.Data).Node; - if (ANode.StartPosnil do begin + ANode:=TCodeTreeNodeExtension(DefAVLNode.Data).Node; + if (ANode.StartPosnil do begin - ANode:=TCodeTreeNodeExtension(DefAVLNode.Data).Node; - if (ANode.StartPosnil do begin + ANode:=TCodeTreeNodeExtension(DefAVLNode.Data).Node; + if (ANode.StartPos try parent proc ... ProcNode:=ProcNode.Parent; - // try parent proc ... end; end; //while (ProcNode<>nil) and (ProcNode.Desc=ctnProcedure) do begin end; @@ -879,6 +898,30 @@ begin Result:=nil; end; +procedure TMethodJumpingCodeTool.WriteCodeTreeNodeExtTree(ExtTree: TAVLTree); +var + AVLNode: TAVLTreeNode; + ANodeExt: TCodeTreeNodeExtension; +begin + writeln('TMethodJumpingCodeTool.WriteCodeTreeNodeExtTree ExtTree.Count=',ExtTree.Count); + AVLNode:=ExtTree.FindLowest; + while AVLNode<>nil do begin + ANodeExt:=TCodeTreeNodeExtension(AVLNode.Data); + write(' '); + if ANodeExt.Node<>nil then begin + write('Node=',ANodeExt.Node.DescAsString,' Node.Start=',ANodeExt.Node.StartPos); + write(' "',StringToPascalConst(copy(Src,ANodeExt.Node.StartPos,30)),'"'); + end else + write('Node=nil'); + write(' Position=',ANodeExt.Position); + write(' Txt="',ANodeExt.Txt,'"'); + write(' ExtTxt1="',ANodeExt.ExtTxt1,'"'); + write(' ExtTxt2="',ANodeExt.ExtTxt2,'"'); + writeln(); + AVLNode:=ExtTree.FindSuccessor(AVLNode); + end; +end; + function TMethodJumpingCodeTool.JumpToCleanPos(NewCleanPos, NewTopLineCleanPos: integer; var NewPos: TCodeXYPosition; var NewTopLine: integer; IgnoreJumpCentered: boolean): boolean;