On Fri, 19 Mar 2010, Wolfram Sang wrote:

> Hello,
> 
> another question (might be obvious, but I tried a number of things without
> success). Given this spatch:
> 
> ===
> 
> @ init @
> identifier struct_name, bin;
> @@
> 
>       struct struct_name {
>               ...
>               struct bin_attribute bin;
>               ...
>       };
> 
> @ main extends init @
> expression E;
> statement S;
> identifier name, err;
> @@
> 
>       struct struct_name *name;

This should match a case with an initialization, thanks to an isomorphism.  
You can use spatch -parse_cocci foo.cocci to be sure that is happening.

But I wonder what is the point of this declaration?  Is it only to be sure 
that name as the right type?  If so, you can specify the type in a 
metavariable declaration of name, ie struct struct_name *name; rather than 
identifier name.  You can also say eg idexpression struct struct_name 
*name; if you want to restrict it to an identifier.  Or local idexpression 
struct struct_name *name; if you want to restrict it to an identifier 
that is also a local variable.  A parameter should be consider to be a 
local variable.

julia

>       ...
> (
>       sysfs_bin_attr_init(&name->bin);
> |
> +     sysfs_bin_attr_init(&name->bin);
>       if (sysfs_create_bin_file(E, &name->bin))
>               S
> |
> +     sysfs_bin_attr_init(&name->bin);
>       err = sysfs_create_bin_file(E, &name->bin);
> )
> 
> ===
> 
> This works well in general. Only problem is that
> 
>       struct struct_name *name;
>       ...
> 
> is too narrow. Places also needing a fix may look like
> 
>       struct struct_name *name = something;
> 
> or even
> 
>       function(..., struct struct_name *name)
>       {
>       }
> 
> So, I want to match something like
> 
>       ... struct struct_name *name ...
> 
> meaning it can be anywhere, e.g. in a function argument or in a declaration,
> etc. Is this possible or do I think too much of grep (=text-matching) here?
> 
> Thanks again,
> 
>    Wolfram
> 
> -- 
> Pengutronix e.K.                           | Wolfram Sang                |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> 
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to