Recent

Author Topic: Question about Codetools  (Read 1293 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Question about Codetools
« on: July 20, 2017, 11:57:27 pm »
Lazarus 1.8.0 RC3
macOS 10.12.6 Sierra

Hello, I've been looking at the Codetools package recently as I am planning to make an IDE tool which carries out sorting of implementation code on a procedure basis, based on the sequence of methods as declared in the interface section.

I've been looking at the examples in the Codetools examples, especially the code in /Developer/lazarus/components/codetools/examples/methodjumping.pas. I've run the code against the sample .pas scanexamples/methodjump1.pas and I get the output:
/Developer/lazarus/components/codetools/examples/scanexamples/methodjump1.pas 3,16 TopLine=14 RevertableJump=TRUE
The TopLine is the info i'm interested in because this is the start line number of the procedure in the implementation section.

But, what on earth is the 3,16? It doesn't seem to correspond to anything of interest in the example code, and indeed, looking at the source code, the critical method CodeToolBoss.JumpToMethod is being called with X:=14 and Y:=10; as input parameters. Incidently, it doesn't seem to matter what the value of X is - all integer value >= 1 appear to work.

CodeToolBoss.JumpToMethod in turn calls FCurCodeTool.FindJumpPoint but several layers deeper the value of NewPos is being altered to these mysterious values of 3 and 16. I've tried to debug using Xcode/LLDB but there seems to be a problem whereby Xcode doesn't keep track of a method's scoped variables when a nested procedure of function is called, and the job becomes more like trying to debug a large program with lots of global variables.

So just to re-iterate, does anyone have any idea of where CodeToolBoss.JumpToMethod is getting the output values 3 and 16 from?
« Last Edit: July 21, 2017, 12:14:09 am by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Question about Codetools
« Reply #1 on: July 21, 2017, 11:07:43 pm »
The dangers of late night coding strike again. The position 3, 16 actually means line 16 column 3 which is the first clean bit of code space in the test method, taking indentation into account. I, for some reason, was interpreting it as line 3 column 16. Doh!

This involved some intensive debugging which led to a neat discovery. If anyone is using Phil Hess' excellent ProjectXC project to debug Lazarus code using Xcode (necessary on macOS 10.12 Sierra) you may be interested to know that there is a way of tracking variable declared in outer methods when nested methods are entered. Have a look here to see what I mean... https://forum.lazarus.freepascal.org/index.php/topic,37626.msg253706/topicseen.html#new

Cheers,
Carl

"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

 

TinyPortal © 2005-2018