On Thu, 21 Oct 2010, Andriy Gapon wrote:
>
> I've already successfully used coccinelle for a sufficiently small scale code
> change on FreeBSD:
> http://www.mail-archive.com/[email protected]/msg28468.html
>
> Now I want to take on something bigger, but it seems that I have problems with
> getting coccinelle to correctly parse some FreeBSD header files because of
> specific macros.
>
> Example 1.
> http://svn.freebsd.org/viewvc/base/head/sys/sys/_rmlock.h?view=markup
>
> It seems that LIST_HEAD macro confuses the parser.
> Actual definition of the macro is this:
> #define SLIST_HEAD(name, type) \
> struct name { \
> struct type *slh_first; /* first element */ \
> }
>
> So, it defined a particular structure type, possibly anonymous.
>
> The errors I am getting:
> ERROR-RECOV: found sync '}' at line 54
> ERROR-RECOV: found sync bis, eating } and ;
> parsing pass2: try again
> ERROR-RECOV: found sync '}' at line 54
> ERROR-RECOV: found sync bis, eating } and ;
> parse error
> = File "/usr/src/sys/sys/_rmlock.h", line 49, column 28, charpos = 1975
> around = 'rm_activeReaders', whole content =
> LIST_HEAD(,rm_priotracker)
> rm_activeReaders;
> badcount: 10
> bad: LIST_HEAD(rmpriolist,rm_priotracker);
> bad:
> bad: struct rmlock {
> bad: struct lock_object lock_object;
> bad: volatile cpumask_t rm_writecpus;
> BAD:!!!!! LIST_HEAD(,rm_priotracker) rm_activeReaders;
> bad: union {
> bad: struct mtx _rm_lock_mtx;
> bad: struct sx _rm_lock_sx;
> bad: } _rm_lock;
> bad: };
> ÿÿ
You can make the following definition in a file mymacros.h, and then run
coccinelle with the argument -macro_file mymacros.h
#define LIST_HEAD(x,y) struct unknown
spatch will still complain a little bit, if you have verbose parser error
messages, but it can cope in the end.
> Example 2.
> http://svn.freebsd.org/viewvc/base/head/sys/sys/pcpu.h?view=markup
>
> In this case it seems that the parser has trouble with macros that are
> defined in
> the same file:
> ERROR-RECOV: found sync end of #define, line 70
> parsing pass2: try again
> ERROR-RECOV: found sync end of #define, line 70
> parse error
> = File "/usr/src/sys/sys/pcpu.h", line 71, column 0, charpos = 2500
> around = '', whole content = #define DPCPU_DEFINE(t, n) t
> DPCPU_NAME(n) __section("set_pcpu") __used
> badcount: 1
> bad: #define DPCPU_NAME(n) pcpu_entry_##n
> BAD:!!!!! #define DPCPU_DECLARE(t, n) extern t DPCPU_NAME(n)
Unless you actually want to perform matches or transformations in these
macro definitions, I think you could ignore this.
julia_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)