Difference between revisions of "Codetools"

From Lazarus wiki
Jump to navigationJump to search
Line 15: Line 15:
 
*FPCDIR: path to the FPC sources, the default is ''~/freepascal/fpc''.  
 
*FPCDIR: path to the FPC sources, the default is ''~/freepascal/fpc''.  
 
*PP: path to the compiler executable (/usr/bin/fpc or /usr/bin/ppc386 or C:\lazarus\ppc386.exe). The codetools need to ask the compiler for the settings. The default is to search for 'fpc' via the PATH variable.
 
*PP: path to the compiler executable (/usr/bin/fpc or /usr/bin/ppc386 or C:\lazarus\ppc386.exe). The codetools need to ask the compiler for the settings. The default is to search for 'fpc' via the PATH variable.
*LAZARUSDIR: path the lazarus sources. Only needed if you want to scan them.
 
 
*FPCTARGETOS: tell the codetools to scan for another operating system (cross compiling). For example: linux, freebsd, darwin, win32, win64, wince
 
*FPCTARGETOS: tell the codetools to scan for another operating system (cross compiling). For example: linux, freebsd, darwin, win32, win64, wince
 
*FPCTARGETCPU: when scanning for another CPU. For example: i386, powerpc, x86_64, arm, sparc
 
*FPCTARGETCPU: when scanning for another CPU. For example: i386, powerpc, x86_64, arm, sparc
 +
*LAZARUSDIR: path of the lazarus sources. Only needed if you want to scan them.
  
 
FPC is a very complex project with lots of search paths, include files and macros. The codetools need to know all these paths and macros in order to parse this jungle. To setup all this easily the codetools contain predefined templates for FPC, Lazarus, Delphi and Kylix source directories.  
 
FPC is a very complex project with lots of search paths, include files and macros. The codetools need to know all these paths and macros in order to parse this jungle. To setup all this easily the codetools contain predefined templates for FPC, Lazarus, Delphi and Kylix source directories.  

Revision as of 10:11, 19 December 2009

Deutsch (de) English (en) français (fr) русский (ru)

What are the codetools

The codetools is a lazarus package providing tools to parse, explore, edit and refactor pascal sources. The codetools are a module of their own and are licensed under GPL. There are many examples how to use the codetools in your own programs under components/codetools/examples.

Using the codetools without the IDE (good for testing)

You can use the codetools without the IDE. This can be used to test a new tool. An easy example is

 <lazarusdir>/components/codetools/examples/methodjumping.lpi

To test find declaration, the codetools need to parse sources. Especially the RTL and FCL sources. The examples use the following environment variables:

  • FPCDIR: path to the FPC sources, the default is ~/freepascal/fpc.
  • PP: path to the compiler executable (/usr/bin/fpc or /usr/bin/ppc386 or C:\lazarus\ppc386.exe). The codetools need to ask the compiler for the settings. The default is to search for 'fpc' via the PATH variable.
  • FPCTARGETOS: tell the codetools to scan for another operating system (cross compiling). For example: linux, freebsd, darwin, win32, win64, wince
  • FPCTARGETCPU: when scanning for another CPU. For example: i386, powerpc, x86_64, arm, sparc
  • LAZARUSDIR: path of the lazarus sources. Only needed if you want to scan them.

FPC is a very complex project with lots of search paths, include files and macros. The codetools need to know all these paths and macros in order to parse this jungle. To setup all this easily the codetools contain predefined templates for FPC, Lazarus, Delphi and Kylix source directories. See for a find declaration example

 <lazarusdir>/components/codetools/examples/finddeclaration.lpi

Because the FPC sources contain multiple versions of some units, and the FPC sources changes often, the codetools does not use a fixed path table, but instead scan first the whole FPC directory structure and try to guess, what source is the right for the current TargetOS and TargetCPU. This scan may take a while depending on your disk speed. All examples save the result in codetools.config, so that on next start the scan is skipped.

Whenever the FPC sources have moved or a unit is renamed, just delete the file codetools.config. The Lazarus IDE has its own config file and does the rescan, whenever the compiler executable has changed or the user forces a 'Environment > Rescan FPC source directory'.

Using the codetools in the IDE with the IDEIntf

See <lazarusdir>/examples/idequickfix/quickfixexample.lpk package. It demonstrates:

  • How to write an IDE package.
 When You install it will register a Quick Fix item.
  • How to write Quick Fix item for compiler messages 'Parameter "Sender" not used'
  • How to use the codetools to
     * parsing a unit
     * conversion of Filename,Line,Column to codetools source position
     * finding a codetools node at a cursor position
     * finding a procedure node and the begin..end node
     * creating a nice insertion position for a statement at the beginning of
       the begin..end block
     * getting the indentation of a line, so that the new line will
       work in sub procedure as well
     * inserting code with the codetools