On Sun, 30 Jan 2011, SF Markus Elfring wrote:

> > One can declare that a metavariable should have a certain type, so that it 
> > would seem that one could declare that a metavariable should have a 
> > certain function type.
> 
> Did I overlook this feature in the published SmPL grammar description?

It should be possible to declare a metavariable to have any C type.  For 
function types, though it doesn't seem to work in practice.

> Do you use alternative terms for the declaration of meta-variables that
> correspond to a return type and a function name?
> http://coccinelle.lip6.fr/docs/main_grammar006.html
> 
> 
> > I'm not sure that the support for function types is very robust though.
> 
> I guess that the desired detection needs to be separated into a few steps or
> semantic patch rules.
> 1. Does the affected function has got a non-void return type?
>    ÿÿ Match with asterisk notation which will assign some data to the 
> specified
> meta-variables.

I think you would want to use a position variable.

I don't think that giving a metavariable a function type is necessary for 
doing this.  You can just match the declaration of the function itself.

> 2. Further source code adjustments with -/+ notation
>    http://coccinelle.lip6.fr/docs/main_grammar004.html

I'm not sure that a generally applicable transformation can be defined in 
this case.  One would have to think a bit how the return value should be 
used (eg tested, and what the impact of that test should be).

>    I see difficulties in expression of the two known usage patterns here at 
> the
> same time.
>    - Assignment of the return value to a variable of the target language
>    - Passing a return value as a parameter in a function call

Perhaps if one passes it to another function, that could be considered to 
be good enough?  But if one wants to consider that case in a special way, 
it should be possible to do that.  Eg f(...,x,...) where f is a 
metavariable will match any passing of x to some function.
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to