Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-01

Adding compiler directives?

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Robinson

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

Earlier message 101 lines
From: Paul Robinson To: "" 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: $LIST $LISTING $PRINT  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 $LISTING LANDSCAPE  $PRINT ON $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*)       R:real; procedure Q; var i,j: integer;  (*Line 5*)   begin      i :=1;  (*Line 8*)      j := 5;     writeln('Hello ',J);    ... end; begin      I := 15; (*Line 13*)    J := I*12;   Q;   if (J=6) then      Q   else      I++;  ... end. 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 The Lessons of history teach us - if they teach us anything - that no one learns the lessons that history teaches us.  -- End of Message --

Reply by email

Hans-Peter Diettrich
to Paul Robinson
Show quoted text 10 lines
The new directives are first, for printing capability: $LIST $LISTING $PRINT 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.)

Nowadays the user has full control over his printer, its capabilities, and a bunch of tools to provide listings in various formats, fonts etc. No need for adding all that to an compiler, as opposed to batch processing on old mainframes.

A most desperately missing feature - Cross Reference generation.

Have a look at Lazarus, where you'll find tools that can do much more than the old mainframe utilities.

DoDi

Reply by email

Jonas Maebe
to Paul Robinson: This is reposted because apparently it did not get recieved by the mailing list From:…
Paul Robinson wrote
I would like to ask whether there's a rule or policy on new compiler directives.

In general: the fewer, the merrier :)

The new directives are first, for printing capability:

Printing-related features is not something that we'd ordinarily put into the compiler. Source code formatting (for whatever purpose) is left to other -specialised- tools, such as
* ptop: general purpose source code formatter (included with FPC)
* Lazarus: includes various source code formatting capabilities
* maybe another tool not yet written, possibly based on other existing code

Such tools could be extended to check for specially formatted comments (such as { #PRINT ON }).

Show quoted text 10 lines
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

There is actually already some code for that in the compiler, although it is quite outdated and no longer used. It's in the compiler/ browcol.pas unit. It writes (wrote) out symbol browsing information that can (could) be used by the fp IDE. I don't think it included back references from places where those symbols are used inside the code though, only about where they are defined.

There's also the -vp compiler option, which writes out a file called "tree.log" that represents the parse tree (this option primarily exists to help debugging the compiler). It would not be very difficult to extend that output with adding for each loadn also the unit/line/ column information for each referenced symbol. Its format was however not designed to be easily machine-parseable, and changes from time to time as fields get added to or removed from node types in the compiler.

There's also the Lazarus IDE, which already contains code to extract all of tha information, both regarding definitions and uses (it needs it for its code navigation functionality). So maybe adding some kind of "dump" facility to that code would be better. In fact, in general simply navigating the source code in Lazarus should offer you the same information on demand as a separate cross-reference would (jump to symbol definition immediately lands you at that definition, rather than that you have to manually go looking through papers/source files for the right source file and line number based on a comment).

Jonas

Reply by email

Sven Barth
to Jonas Maebe
Jonas Maebe wrote 17 lines
> 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 There is actually already some code for that in the compiler, although it is quite outdated and no longer used. It's in the compiler/browcol.pas unit. It writes (wrote) out symbol browsing information that can (could) be used by the fp IDE. I don't think it included back references from places where those symbols are used inside the code though, only about where they are defined.

I'm always fascinated by the little gems that are in FPC and the units that come with it (even if it might not work anymore as you wrote). :)

Regards,
Sven

Reply by email