On Fri, Feb 11, 2011 at 23:39, Håkon Løvdal <[email protected]> wrote:
> >From the main_grammar.pdf there is an example of adding static
> in front of a function. However trying to add something other than
> the phrase "static" does not work. Is this by design?
In short, yes.
> $ cat add_before_function_002.cocci
> @@
> type T;
> identifier func;
> @@
>
> + STATIC
> T func(...) { ... }
>
The problem here is that not every string is acceptable by C at that
location, and the storage option of 'static' is case-sensitive to
SmPL. You should be able to do 'auto' or 'inline' for instance -
because they are allowed at that point in the grammar, see
http://coccinelle.lip6.fr/docs/main_grammar006.html
(also see the optional_storage isomorphism at that section which may
be teasing with your mind). Don't let the grammar fool you though: It
looks like the funinfo comes after the fn_ctype, but inside the menhir
coccinelle parser it looks right. The main point still stands however.
> $ spatch -sp_file add_before_function_002.cocci main.c
> init_defs_builtins: /tmp/coccinelle/share/coccinelle/standard.h
> 41 42
> Fatal error: exception Failure("plus: parse error:
> = File "add_before_function_002.cocci", line 7, column 0, charpos = 41
> around = 'T', whole content = T func(...) { ... }
> ")
And spatch tries to be helpful here. The point is that it is afraid
you have made a typo of the storage (or inline) modifier so it doesn't
accept the patch. This also hints that Coccinelle is more than simply
a textual substituter - you can only write patches that makes sense in
C's syntax and grammar.
--
J.
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)