"Urs Thuermann" <ur*@isnogud.escape.de> wrote in message

news:m2************@janus.isnogud.escape.de...

Does a tool exist to apply C preprocessor expansion to a C source only

partially, i.e. replace only some directives? I want to replace some

#if's by their expansions, e.g. all #ifdef SOME_SYMBOL, but keep all

other #ifdef OTHER_SYMBOL and all #include directives.

We've used the DMS Software Reengineering Toolkit to do exactly this.

The basic idea is to pick up the conditional directives, symbolically

substitute the status of each #define symbol

(e.g., 0 --> "I'll never use this define again",

1 --> "Assume this is always true",

or the symbol name --> "Leave this conditional"),

simplify the resulting boolean formula symbolically,

and resubstitute the resulting formula. A last optimization

handles the cases of #if 0 or #if 1,

#elseif 0, #elseif 1, #else, etc. to strip away

the dead branches of the conditionals.

There's a paper on how to do this with DMS that

gives more details:

Baxter, I. and Mehlich, M.

Preprocessor Conditional Removal by Simple Partial Evaluation,

2001 Workshop on Analysis, Slicing and Transformation, 2001 ,

available at our website:

http://www.semanticdesigns.com/Company/Publications/
and we have done this multi-million lines systems.

So yes, such a tool exists.

--

Ira Baxter, CTO

www.semanticdesigns.com