[fpc-devel] Adding compiler directives?

Paul Robinson paul at paul-robinson.us
Wed Jan 18 01:07:14 CET 2012

This is reposted because apparently it did not get recieved by the mailing list

From: Paul Robinson <paul at paul-robinson.us>
To: "fpc-devel at lists.freepascal.org" <fpc-devel at lists.freepascal.org> 
Sent: Sunday, January 15, 2012 5:44 PM
Subject: Adding compiler directives?

I would like to ask whether there's a rule or policy on new compiler directives.  I'd like to see some directives added, to do with two features which I think are sorely needed in the compiler.  Since * I * think they are needed, * I * will write the code for them, but I need to find out how to submit them.  I know where they have to go: scandir.pas (or quite possibly a separate unit so as not to clutter that unit up with these routines), and I know how to write them, but there's no point writing them if there is no desire to allow them to be added.  The new directives are first, for printing capability:


These are all the same (all three would be equivalent), and control the generation of listings of source code.  Currently the compiler does not do listings, and I think it's an important feature (Pascal Compilers from mainframe and minicomputer systems did do this, and I miss the functionality.)  There would be options, like $LISTING 55 (the default, a page is 55 lines long) or 

$LISTING PORTRAIT      (Default, 55 lines and about 80 characters), or 


$PRINT OFF - The default, would not generate a listing unless enabled
$PRINT INCLUDE - List include files inline as they are read
$PRINT NOINCLUDE - skip include file listing

$TITLE  - Text here is printed at the top of the page

$SUBTITLE - Text here is printed at the second line

$EJECT - End page and start new page.
$SKIP 10 - put in 10 blank lines
$EJECT IF 10 - Eject if less than 10 lines are left on the page

And so on.

The listing would either be line printer formatted or it might be generated for PDF formatting, with things like keyword highlighting and so forth; that's later.  But the main thing is getting the hooks in place so that this capability is possible.

Then there is the second part of this inquiry which is:

$CROSS  - various options I haven't decided yet

A most desperately missing feature - Cross Reference generation.  I can always write a cross-reference program, and in fact I'm working on one because I can't find the nice one I had that was written about 20 years ago that did much of what I'm thinking of now, but a cross-reference function should be part of the compiler since the compiler "knows" which reference the person is referring to, e.g. if I write

Var I:Integer; (*Line 1*)

procedure Q;
var i,j: integer;  (*Line 5*)

     i :=1;  (*Line 8*)
     j := 5;
    writeln('Hello ',J);


   I := 15; (*Line 13*)

   J := I*12;
  if (J=6) then 




The Cross-reference listing can be something like this (it follows the source code listing, which would include line numbers):

Identifier               Defined                Referenced
I                                    1                 13, 14, 19
I                                    5                 8
J                                    1                 14, 16

...  More items ...

Procedure Q                 

   is defined by Main Program       4   
   is called by  Main Program        15,16
   and calls      Writeln                   10

While it might not be this slick - it might not reference local definitions - at least at first, it is something I am thinking about because listing and cross-reference capability were in compilers 20 years ago and while to get good performance when PCs were slow, it was something that probably had to go, there's no reason we can't restore the capability now.

So, again, I'm not asking for anyone else to do this, I can write the code myself, I just have to know how I would submit changes for approval.

Paul Robinson <paul at paul-robinson.us>

The Lessons of history teach us - if they teach us anything - that no one learns the lessons that history teaches us. 
-- End of Message --

More information about the fpc-devel mailing list