On Fri, 25 Mar 2011, Michael Stefaniuc wrote: > Julia Lawall wrote: > >> Im now somewhat unclear on the -macro_file <> option, > >> despite it helping my situation dramatically - > >> Why would you not parse #included headers by default ? > >> at least when theyre on the include path, like #include "perl.h" > > > > The default is to parse a header file that has a name that resembles that > > of the file. So if you are working on video.c, it will parse video.h. At > > least in the context of Linux, that is the file that is most likely to > > have the definitions that are relevant to theproblem at hand. > > > > Parsing header files takes time. A lot of semantic patches don't need > > that information. I often use the option -no_includes, when my semantic > > patch is not sensitive to type information. > Oh yes, parsing header files is really really slow. I'm using coccinelle > on the Wine source and there I would have to recursively parse the > includes to get meaningful results. But that makes my cocci scripts slow > (orders of magnitude!) to the point that it becomes unpractical to use them. > > > A goal of Coccinelle is to let you make transformations on macro uses as > > well and to be independent of the configuration. If we just applied cpp > > based on the header files that we can find, then neither of those would be > > possible. > Yepp, I make regular use of matching and sometimes replacing macros. > > > When Coccinelle has the definition of a macro, sometimes it does take that > > into acount in constructing the internal representation. But in that case > > the tokens involved in the use of the macro become passed, and one can't > > do any transformation on them. So taking into account a macro definition > > is not necessarily a desirable thing. > > > > These decisions were taken in the context of Linux code, where the use of > > macros is mostly limited to code that stays within the syntax of C. > Works for Wine too. I do have to use a macro file but that one is pretty > short http://people.redhat.com/mstefani/wine/coccinelle/macros . Most of > the entries in there are due to the peculiarities of the Win32 API.
Thanks for the feedback! Sometimes it can be useful to expand the semantic patch a little to avoid the need to include a header file to get type information. For example, if one is looking for an expression of a particular type, and one knows that the x field of an A structure has that type, then one can make a rule for e->x (where e may be declared as having type A, if needed) rather than including lots of header files to find the definition of A. Of course it's a tradeoff as to how man special cases you want to consider. julia _______________________________________________ Cocci mailing list [email protected] http://lists.diku.dk/mailman/listinfo/cocci (Web access from inside DIKUs LAN only)
