Page 1 of 1

A preprocessed single source file with macros expanded

Posted: Wed Nov 16, 2011 12:27 am
by luis
WHAT:

I would like an option to make the compiler generate a single source file (processing all the includes) and an option to expand the macros too.

WHY:

It would be nice to process the resulting file with some kind of tool (for various purposes) and then launch again the compiler on the resulting source. The macro expansion would be nice to simplify the parse of the source, since with macros you can generate code not easily "visible" unless you add to your parser the code to expand the macros too. Since PB do that already, would be nice to have him work for us.

Thank you.

Re: A preprocessed single source file with macros expanded

Posted: Wed Nov 16, 2011 10:20 am
by c4s
I remember a similar request where I already +1'd... Here:
http://www.purebasic.fr/english/viewtop ... =3&t=40658

Re: A preprocessed single source file with macros expanded

Posted: Wed Nov 16, 2011 12:02 pm
by luis
Oh, I'm sorry, I missed that...

Thank you.


EDIT: Actually I even replied to that thread... eheheh :oops:

Re: A preprocessed single source file with macros expanded

Posted: Fri Mar 09, 2012 7:48 pm
by skywalk
Not that this gets you there, but if you purposely compile your code with an error in a Macro, then the Macro is expanded in the 'Macro Error' Window. :wink:
It would be nice to see the final expanded code for lots of reasons already mentioned.

Re: A preprocessed single source file with macros expanded

Posted: Fri Mar 09, 2012 8:41 pm
by luis
skywalk wrote:Not that this gets you there, but if you purposely compile your code with an error in a Macro, then the Macro is expanded in the 'Macro Error' Window. :wink:
Yes I knew it, it's a trick I use when I want to check if a macro is expanded the way it was intended to :mrgreen:

But thanks for the suggestion!

Re: A preprocessed single source file with macros expanded

Posted: Tue Jan 29, 2013 12:35 am
by luis
Sorry to bring this up again, but is there some possibility this will be implemented in the "near" future ?
Not asking for a date... only if it is planned or if there is no hope :)

Because today I stumbled on another case where this feature would have been very useful.
I have to generate some documentation from a lot of sources, many includes, etc, all part of the same library. I have to write the program to extract all that info (present in the sources as comments) and generate a big file with all the documentation for any single procedure.

If this feature were here, I could generate a single big file with all inside and process just that one.
A lot easier.

It's only one of the *many* things that could be done more easily (or at all) with it, and probably the most mundane.

Thank you and please don't shoot me.

Re: A preprocessed single source file with macros expanded

Posted: Tue Jan 29, 2013 1:08 am
by skywalk
I'm also looking forward to this feature.
I'd like to scan this file for any unused declared variables or stray procedures that should not be included.
Searching 1 expanded file will be much easier. :wink:

Re: A preprocessed single source file with macros expanded

Posted: Tue Jan 29, 2013 1:32 am
by BorisTheOld
@luis

While you're waiting, why don't you just write your own preprocessor? The PB macro facility is quite primative, so a few hours work should give you what need.

We use a simple text substitution macro facility in our code generator software. As I recall, it only took a couple of days to write.

Re: A preprocessed single source file with macros expanded

Posted: Sun Feb 03, 2013 10:06 pm
by luis
@BorisTheOld

Because the macros are only one piece of the puzzle on the road to have a single file (see first post).
Because compilerif have so many possible conditions it can be tested against, and I should implement them all.

random example:

Code: Select all

CompilerIf SizeOf(structurename) = 24
 IncludeFile #PB_Compiler_FilePath + "..\code\foo.pb"
CompilerElse
 IncludeFile #PB_Compiler_FilePath + "bar.pb"
CompilerEndIf
good luck

Because PureBasic is not immutable, so I would have to keep up with any new addition / variation to the above features.
But above all because Fred has access to all this already, he just need to output the result, and any change he make to the language would be automatically included for the next version at no cost.
For me it's not trivial and I would hate to spend the time to do this just to find it implemented in the next version.
In short, it's not "worth" the effort, since I can do something else more useful for me in the meantime. Would I like it ? Yes. I want to do it myself ? No. Will I change my mind ? Depends on what I'm doing at a certain time at the pace at which PB will change. Would I shameless use the code from someone else ? Certainly and thankfully.

There are many routines to make "one single file from all the includes" already posted in the forum, but no one really works AFAIK.

I still have hope to see it someday because this is not something only I would appreciate, can be really useful to make many interesting tools.

That's my answer :wink:

[EDIT: THIS REQUEST HAS BEEN IMPLEMENTED]