Page 1 of 2

[Implemented] New compiler option: preprocess only

Posted: Wed Jan 13, 2010 12:49 pm
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 :)

Re: New compiler option: preprocess only

Posted: Wed Jan 13, 2010 1:06 pm
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

Re: New compiler option: preprocess only

Posted: Wed Jan 13, 2010 1:19 pm
by c4s
+1 - Very good idea!
As an addition we could select what should/shouldn't be preprocessed: Constants, Macros, CompilerIfs, Includes...

Re: New compiler option: preprocess only

Posted: Thu Jan 14, 2010 4:39 am
by Mistrel
How would you propose this to work for include files? Or data sections?

Re: New compiler option: preprocess only

Posted: Thu Jan 14, 2010 9:22 am
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.

Re: New compiler option: preprocess only

Posted: Thu Jan 14, 2010 10:28 am
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).

Re: New compiler option: preprocess only

Posted: Thu Jan 14, 2010 11:32 am
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.

Re: New compiler option: preprocess only

Posted: Thu Nov 14, 2013 12:01 pm
by PB
I'd like to see this, too. Perhaps for the next beta?

Re: New compiler option: preprocess only

Posted: Thu Nov 14, 2013 3:06 pm
by davido
+1

Re: New compiler option: preprocess only

Posted: Thu Nov 14, 2013 3:55 pm
by Kiffi
that would be great! Image

+1

TIA & Greetings ... Kiffi

Re: New compiler option: preprocess only

Posted: Thu Nov 14, 2013 4:27 pm
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.

Re: New compiler option: preprocess only

Posted: Thu Nov 14, 2013 4:55 pm
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.

Re: New compiler option: preprocess only

Posted: Thu Nov 14, 2013 9:46 pm
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 :?

Re: New compiler option: preprocess only

Posted: Mon Feb 17, 2014 6:41 am
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.

Re: New compiler option: preprocess only

Posted: Mon Feb 17, 2014 9:47 am
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