[fpc-devel] possibility to include compiler info (line number) as integer rather than string

Sven Barth pascaldragon at googlemail.com
Fri Feb 24 23:16:02 CET 2012

On 24.02.2012 22:49, Seth Grover wrote:
> Quoting http://www.freepascal.org/docs-html/prog/progsu38.html
> --------------------
> the {$INCLUDE} directive inserts a string constant in the source code.
> ...
>      Linenumer on which the directive is found.
> --------------------
> How hard would it be for me to modify the FPC preprocessor to add an
> option (INTLINE or something) to insert a numeric constant in the
> source code rather than a string constant?
> If that would be doable, could anyone give me a pointer on where in
> the source code I'd look to begin? I haven't delved much into that
> realm of the compiler's code as of yet.

{$INCLUDE ...} is handled in compiler/scanner.pas in dir_include. You'll 
find a "hs='LINE'" there, which gets the line number, and further below 
a "hs:=''''+hs+''''" which converts hs to a string constant and inserts 
it into the scanner.

So basically you'll need to add a new directive (normally in 
compiler/scandir.pas, which should be sufficient in your case), add the 
ingredients above without the conversion to a string constant and that 
should be it in theory (note: I have not tested this, just a quick 
glance at the code).

Note: To add your directive procedure to the scanner you need to 
register it in InitScannerDirectives at the bottom of unit scandir.


More information about the fpc-devel mailing list