-pp compiler option

Forum for discussion about the documentation project.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: -pp compiler option

Post by sancho3 »

After some testing I think the most important thing that is missing from the description is the fact that macros are expanded.

When I first read the responses here I thought that #included files would each get their own *.pp.bas file. I see now that when you say "input source file" you are talking about additional .bas files that are going to appear on the fbc command line.
I have never compiled a program in that manner. If you use an IDE most of the time you are compiling a single file that may or may not have some #includes.

I think that the suggested change to "<source>.pp.bas" is a good one.
I like the suggested line "For every input file <source>.bas passed to the compiler, a pre-processed version named <source>.pp.bas is generated."
Perhaps adding "Note that included files and macros will be expanded in place."
Does that make sense?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: -pp compiler option

Post by fxm »

Proposal:
Description:
The -pp compiler option enables the preprocessor-only mode. The code is parsed & checked as usual, but is not compiled. For every input file <source>.bas passed to the compiler, a pre-processed version named <source>.pp.bas is generated.
Specifically, preprocessor commands such as conditional compilation (#if, #ifdef, #ifndef, etc.), text replacement (#define, #macro, etc.) and file inclusion (#include) are processed recursively, and the resulting expanded code is written to the pp.bas file.
Note: I think that if for each sentence the discussion is so rough, we are not ready to get even the beginning of a tutorial for beginners!
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: -pp compiler option

Post by dodicat »

I think most users would isolate a code file in a temp folder and apply a command line option to see what they get.
I have just tried -showincludes.
Which:
[Tells the compiler to display the file names of loaded source code files, in form of a tree. This includes the *.bas files at the toplevel, aswell as the names of #included files as they are being #included. This is intended to be used for debugging #include dependencies, etc.]

I wasn't sure what to expect (In the form of a tree!)
So the help file in this case is a teaser (encourager to test)
But testing is the only way to find out really.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: -pp compiler option

Post by fxm »

Tells the compiler to display the file names of loaded source code files, in form of a tree.
Tells the compiler to display the file names of loaded source code files, in form of a tree structure with indentation.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: -pp compiler option

Post by St_W »

dodicat wrote:I wasn't sure what to expect (In the form of a tree!)
So the help file in this case is a teaser (encourager to test)
IMHO the description is quite clear: you get *.bas files at the toplevel and the names of #included files as they are being #included.
Or do you want an exact specification how the tree view is rendered? I don't think that this is the intent of the feature. Thus I don't really like fxm's suggestion to add some description of the output format. Everybody knows what to expect when the documentation says "tree". And if not there's Wikipedia explaining such basic terms: https://en.wikipedia.org/wiki/Tree_stru ... tree_views

@dodicat: Please suggest an improved formulation/description! And I would also suggest to open a new thread for that as it's unrelated to the "-pp compiler option" topic here.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: -pp compiler option

Post by dkl »

It's probably easiest to put small examples (.bas files, fbc invocation, resulting output). That should set the proper expectations, shouldn't it?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: -pp compiler option

Post by fxm »

Is it about -showincludes or -pp or both?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: -pp compiler option

Post by dodicat »

Nae fxm.
-showincludes is not allowed here.
This is a pp thread only.
PP

Suggestions?
Yea, I have some, but luckily this is a pp thread only.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -pp compiler option

Post by deltarho[1859] »

There is one use for -pp that has not been mentioned. Well, it has actually - in the opening post but it wasn't, how can I put it, expanded upon.

PowerBASIC 'macro/end macro' block is more powerful than FreeBASIC's #Macro...#Endmacro which is simply a multi-line version of #define. I had one which clearly was not working and I spent hours trying to fathom out what I was doing wrong. The FreeBASIC -pp command line option would have been a god send.

I have just included some of my FB macros into a small bas file and made several uses of them. Needless to say the .pp.bas was smaller than the bas but what I saw would be of great help if one of my macros was not working to plan. I did the same thing were some bi files were included. Here, of course, I ended up with a very large file but my test code was at the bottom.

I think it more likely that a bug could creep into a 'heavy' PB macro than a FB macro but to be able to view a FB macro expanded could save a lot of time trying to debug an offending FB macro. Obviously, #define, with parameters, is also expanded.

So, there is a use which is not obvious from the documentation.
sancho3 wrote:I think it may also get by other people.
It got past me and, I suspect, I am not the only one. <smile>

Added: The Wiki entry is still showing source. I agree, with others above, that <source> should be used.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: -pp compiler option

Post by St_W »

dodicat wrote:Suggestions?
Yea, I have some, but luckily this is a pp thread only
If you don't mind to share them (and please be specific) please also don't complain. fxm is propably the only one here who doesn't just talk but actually formulates sentences and integrates them in the wiki.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: -pp compiler option

Post by fxm »

Some small improvements:
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -pp compiler option

Post by deltarho[1859] »

Yours truly wrote:So, there is a use which is not obvious from the documentation.
It is now.

Thanks, fxm.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: -pp compiler option

Post by fxm »

About macro debugging and -pp usage, see also this older topic:
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: -pp compiler option

Post by dodicat »

St_W wrote:
dodicat wrote:Suggestions?
Yea, I have some, but luckily this is a pp thread only
If you don't mind to share them (and please be specific) please also don't complain. fxm is propably the only one here who doesn't just talk but actually formulates sentences and integrates them in the wiki.
I do try and help in other ways in FB.
I am not prone to joining talk stuff on this forum.
Just an occasional opinion.
Also
In the past I have directed members to your library pages, your compiler updates.
I used to always get the latest build from your site.

But I stopped doing this a while back.
Also
I am not keen on being moderated by the hoi polloi.

Anyway, this is even more off topic than -showincludes.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: -pp compiler option

Post by fxm »

dodicat wrote:I am not keen on being moderated by the hoi polloi.
  • vocabulary.com wrote: The hoi polloi is a way of referring to common people, and it is an elitist term usually used by people who consider themselves to be above the masses.
    :-(
Post Reply