[Implemented] New compiler option: preprocess only

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

[Implemented] New compiler option: preprocess only

Post by milan1612 »

I'd like to have a new compiler option, which causes the compiler to preprocess the
sourcecode and output the code into a new file without actually compiling it.
With preprocessing I mean to instantiate all macros and constants as well as executing
conditional clauses like CompilerIf. It should also merge all included files into a single one.

EDIT: It should probably also strip all comments from the source code...

Why? Because that would make it easier to process the code further with own tools :)
Last edited by milan1612 on Sat Jan 16, 2010 12:26 pm, edited 1 time in total.
Windows 7 & PureBasic 4.4
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: New compiler option: preprocess only

Post by luis »

I would like that too, for the same reasons.

When macros are still not expanded, the source can be really a mess to parse.. :P
"Have you tried turning it off and on again ?"
A little PureBasic review
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: New compiler option: preprocess only

Post by c4s »

+1 - Very good idea!
As an addition we could select what should/shouldn't be preprocessed: Constants, Macros, CompilerIfs, Includes...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: New compiler option: preprocess only

Post by Mistrel »

How would you propose this to work for include files? Or data sections?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: New compiler option: preprocess only

Post by Fred »

From what i understand, it would output a very big .pb file with all macro/constants/compilerdirectives/includes resolved, right ? Could be interesting.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Re: New compiler option: preprocess only

Post by milan1612 »

Yes, that's what I mean. Almost every C and C++ compiler has this feature - some even
have a seperate executable just for preprocessing the code (e.g GCC cpp.exe).
Windows 7 & PureBasic 4.4
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: New compiler option: preprocess only

Post by einander »

I like the idea.
Calling XIncludeFile at the start of a new project makes the coding fast and easy, but moving by hand the needed parts from big includes (in my case, 20000 lines with lots of procedures, constants, macros, structures, prototypes and globals) to the main source is a pain.
____________
There's always someone with a bigger IncludeFile.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: New compiler option: preprocess only

Post by PB »

I'd like to see this, too. Perhaps for the next beta?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: New compiler option: preprocess only

Post by davido »

+1
DE AA EB
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: New compiler option: preprocess only

Post by Kiffi »

that would be great! Image

+1

TIA & Greetings ... Kiffi
Hygge
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: New compiler option: preprocess only

Post by skywalk »

I could really use this! Needless to say, writing a PB syntax converter is not trivial.
Debugging complex macros would be so much easier and stepping through flattened code would be more fluid for complex problems and many includes. I have to sometimes close the IDE when debugging fails after multiple runs of stepping and exiting and jumping to includes.

I see less benefit to stripping the comments though. We can do that already with small code.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: New compiler option: preprocess only

Post by luis »

skywalk wrote: I see less benefit to stripping the comments though. We can do that already with small code.
I absolutely agree comments should not be stripped. They could be there for more reasons then just remarks: markers, documentation generation, pseudo-language processed by a parser, etc. and nobody beside me can decide if they can be useful in the final single-source-all-included or not.

It's trivial to remove them if you want to do so.
"Have you tried turning it off and on again ?"
A little PureBasic review
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: New compiler option: preprocess only

Post by gnasen »

This would be really nice for debugging macros, i like that idea. If a macro drives me crazy I have to replace it at the moment by hand to debug it :?
pb 5.11
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: New compiler option: preprocess only

Post by PB »

Bump. :twisted:

Just found out today that this feature would save me a lot of work.
Why? I just loaded an old source of mine that used an IncludeFile.
That IncludeFile has now changed dramatically from what it was
originally, meaning the old source won't compile with it anymore.

If a pre-processor option existed, then my old source would have
had code from the old IncludeFile in it, which means I could still
compile the old code today without problem. Instead, I now have
to fix the "broken" new IncludeFile to work with it. :(

So yes, please implement a pre-processor output very soon. :)
It means that what we compile, can be forever stored as a "gold"
single source file of that app. This is extremely important.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: New compiler option: preprocess only

Post by Kwai chang caine »

+10

For a time even KCC understand what the MASTERS say 8)
Because i have asking exactely the same thing there are 5 years in 2009 in the french forum :(
http://www.purebasic.fr/french/viewtopi ... 14#p105514

And even FRED answer me, perhaps a futur version :|
FRED wrote:Faudrait une sortie préprocessée du code source, mais pour l'instant PB ne permet pas ca.. Peut etre pour une prochaine version !
http://www.purebasic.fr/french/viewtopi ... 31#p105531

I'm happy, because i see KCC ask not alway, only shit question :lol: :lol:
FRED never listen little KCC.. :oops: perhaps this time.... :D
ImageThe happiness is a road...
Not a destination
Post Reply