A preprocessed single source file with macros expanded

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

A preprocessed single source file with macros expanded

Post 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.
"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: A preprocessed single source file with macros expanded

Post by c4s »

I remember a similar request where I already +1'd... Here:
http://www.purebasic.fr/english/viewtop ... =3&t=40658
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: A preprocessed single source file with macros expanded

Post by luis »

Oh, I'm sorry, I missed that...

Thank you.


EDIT: Actually I even replied to that thread... eheheh :oops:
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: A preprocessed single source file with macros expanded

Post 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.
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: A preprocessed single source file with macros expanded

Post 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!
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: A preprocessed single source file with macros expanded

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: A preprocessed single source file with macros expanded

Post 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:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: A preprocessed single source file with macros expanded

Post 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.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: A preprocessed single source file with macros expanded

Post 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]
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply