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: };
⋮


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)


I understand that I need to provide some help/hints to the parser for correctly
treating the macros in question.  I.e. somehow tweaking coccinelle/standard.h or
my private copy of it.  But I don't know what exactly to do.

I will appreciate any help.
Thank you very much!
-- 
Andriy Gapon
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to