Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding a single macro in C or C++ source files

I have a large number of c++ source files that I'd like to transform by expanding a single function macro that I specify and leave all other preprocessing directives untouched. The arguments to the macro will, in general involve parens and braces and paren protected commas, so it does not seem straight forward to do this with sed and kin.

Update: Our code has made heavy use of macros to generate boiler plate (eg helper code for swig). As we have better figured out how to do certain things, various of the macros no longer do anything terribly interesting (eg just declare some functions), and many people complain that they make the code harder to read. I'd like to expand the less interesting macros that expand to simple C++ code.

like image 407
user1959101 Avatar asked Jan 08 '13 18:01

user1959101


1 Answers

I did this sort of things by using regular expressions in python. You can write a fairly short script to process a large number of files and run a few regular expressions on each of them. Regular expressions would probably be the most time consuming part.

like image 157
shargors Avatar answered Nov 11 '22 18:11

shargors