partial/selective Macro expansion scpp

R

reppisch

Hi Ng,
i am looking for a method of expanding a macro while the rest of the
code remains untouched.

I have some code which does macro voodo / ifdef's which i would like to
strip and simplify.

The Faq pointed me to scpp but i could not compile it. the lex.c
generated by flex 2.5.4 is broken.

This problem occured also in 2004 in this group.
any Ideas where to get a working copy or how to compile it??

Regards,
Michael

-- snip --
It generates code using 'yyconst', which it doesn't declare anywhere
(presumably it's supposed to be defined as 'const').


It generates code using 'yy_cp' which likewise isn't (always)
declared (it's declared in some funcxtions but not in others).
 
R

Robert Gamble

reppisch said:
Hi Ng,
i am looking for a method of expanding a macro while the rest of the
code remains untouched.

I have some code which does macro voodo / ifdef's which i would like to
strip and simplify.

The Faq pointed me to scpp but i could not compile it. the lex.c
generated by flex 2.5.4 is broken.

This problem occured also in 2004 in this group.
any Ideas where to get a working copy or how to compile it??

Here's a thought: Instead of providing a string of vague references and
expecting a solution to an unclear problem, why don't you explain
exactly what you are trying to accomplish and provide an example of
what you might have tried already. If you do that we might actually be
able to help.

Robert Gamble
 
C

cbmanica

reppisch said:
i am looking for a method of expanding a macro while the rest of the
code remains untouched.

Depending on your implementation (it's possible with GCC, for example)
and exactly what your situation is, it may be possible and feasible to
simply run the preprocessor on the source files in question.
It generates code using 'yyconst', which it doesn't declare anywhere
(presumably it's supposed to be defined as 'const').

<ot>It's been too long since I used (f)lex to give helpful advice here,
but I feel confident advising you to STFW and RTFM; the chances of flex
being genuinely broken are not high.</ot>
 
M

michi

Here's a thought: Instead of providing a string of vague references
Btw: g$$gle news does not provide message-Ids (anymore).
and
expecting a solution to an unclear problem, why don't you explain
exactly what you are trying to accomplish and provide an example of
what you might have tried already.
I'm sorry if i couldn't make my self more clear.
i'll try to show it in a sample.

a.h contains some macros like
--------
#define LOG(a,b,c,d) FancyLogFunction(__LINE__,__FILE__,a,c,d,b);

b.h contains some obfuscating voodoo like:
--------
#ifdef VOODO
#define VOODOOLOG(a,b) LOG(a,b,"const",strlen(b))
#else
#define VOODOOLOG(a,b) /* nothing */
#endif

c.c:
--------
#include "a.h"
#include "b.h"

....
VOODOLOG("this","that");
....


now i want to siplify things
and get some source like this:

c-processed.c
--------
#include "a.h"
#include "b.h"

....
LOG("this","that","const",strlen("that"));
....

So i want to have the file c.c *partially* preprocessed by expanding
*only* the VOODOLOG Macro.

I tried to do this with scpp but it does not compile on "modern" systems
since it produces a syntactically wrong output from flex while in the
make- Process.

By using the -E option on gcc i would end up in a fully dereferenced
c-file which is not what i want.

Doing the expansion manually is not an option since this only a very
simple sample and chaces are good to do it wrong somewhere.
 
R

Robert Gamble

michi said:
Btw: g$$gle news does not provide message-Ids (anymore).
and
I'm sorry if i couldn't make my self more clear.
i'll try to show it in a sample.

a.h contains some macros like
--------
#define LOG(a,b,c,d) FancyLogFunction(__LINE__,__FILE__,a,c,d,b);

b.h contains some obfuscating voodoo like:
--------
#ifdef VOODO
#define VOODOOLOG(a,b) LOG(a,b,"const",strlen(b))
#else
#define VOODOOLOG(a,b) /* nothing */
#endif

c.c:
--------
#include "a.h"
#include "b.h"

...
VOODOLOG("this","that");

I assume that should be VOODOOLOG and that VOODO has been defined
before b.h was included.
...


now i want to siplify things
and get some source like this:

c-processed.c
--------
#include "a.h"
#include "b.h"

...
LOG("this","that","const",strlen("that"));
...

So i want to have the file c.c *partially* preprocessed by expanding
*only* the VOODOLOG Macro.

Either don't include a.h or undefine LOG somewhere before the VOODOLOG
macro invocation if you don't want the macro expanded a second time.
Why do you want to do this, what are you trying to accomplish? Why do
you even have the macro in a.h if you do not want to use it?
I tried to do this with scpp but it does not compile on "modern" systems
since it produces a syntactically wrong output from flex while in the
make- Process.

By using the -E option on gcc i would end up in a fully dereferenced
c-file which is not what i want.

Right, most compilers don't have an option to do "partial
preprocessing".
Doing the expansion manually is not an option since this only a very
simple sample and chaces are good to do it wrong somewhere.

Robert Gamble
 
B

Ben Pfaff

michi said:
Btw: g$$gle news does not provide message-Ids (anymore).

If you'd spend 30 seconds looking, you'd see that it does. You
can find an article with a given message-id with the advanced
search feature. You can see the message-id of an article with
Show Original.
 
M

michi

Robert said:
I assume that should be VOODOOLOG and that VOODO has been defined
before b.h was included. right.


Either don't include a.h
> or undefine LOG somewhere before the VOODOLOG
macro invocation if you don't want the macro expanded a second time.
which would prevent expansion of the LOG-macro but the rest of the code
*would* be expanded as far as possible.

Why do you want to do this, what are you trying to accomplish? Why do
you even have the macro in a.h if you do not want to use it?
I'd like to use LOG instead of VOODOLOG to make the code more
transparent. This was only a silly sample.

The macro-framework has grown behind the scenes makes the code
unreadable, difficult to debug and allmost impossible to analyze with
tools like sourcenavigator or doxygen.

Do you think it's a good idea to have macors around like
#define FCT_TRC(rc,n,p,x) FCT_TRC_TXT(rc,n,p,x,"")
#define FCT_TRC_TXT(rc,n,p,x,t) { if(((rc)=n p)<0) { LOG_L(#n,rc,t);
x } }
#define LOG_L(f,rc,trc) LOG((C1, C2, C3, (int)(rc), f, trc))

and end up in "function" calls like
FKT_TRC(iRet, someFunction, (arg1, arg2), goto EMERGENCY_EXIT;);
?

I call that preprocessor abuse.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top