On Fri, 11 Mar 2011, ygrek wrote:

> On Fri, 11 Mar 2011 08:06:37 +0100 (CET)
> Julia Lawall <[email protected]> wrote:
> 
> > This is the only option that comes to mind.  The problem is that (to the 
> > best of my knowledge) coccinelle only uses the definitions of macros if it 
> > can't parse the code otherwise, and in your case it has no problem parsing 
> > the code.  Perhaps there is a way to generate the isomorphisms 
> > automatically?  You could do it using Coccinelle actually, since you can 
> > match on #define I1 I2 and then write some python or ocaml code to print 
> > out the isomorphism definition.
> 
> Indeed, generating isomorphisms should be easy. But another thing that I 
> don't like is the need to
> write 'using "caml.iso"' in every rule :(

You can put it on the command line: -iso_file caml.iso

> Now I've got another idea - simply create the patch to convert all old names 
> (alloc_small) to new 
> ones (caml_alloc_small) and then apply other patches after this one using new 
> names only. Looks like a win-win :)
>  
> > I don't think there is any need to use a regular expression here, since as 
> > far as I can see you just want to match a set of fixed names.  In the 
> > second argument to caml_alloc you can put:
> > 
> > \(No_scan_tag\|Abstract_tag\|String_tag\|Double_tag\|...\)
> > 
> > (where ... is the rest of your names, not the SmPL ...)
> > 
> > If you do this, the SmPL compiler has more information and can better 
> > optimize your rule.
> 
> Yes, that was my first attempt and it scared me with warnings :
> 
> warning: line 7: should No_scan_tag be a metavariable?
> warning: line 7: should Abstract_tag be a metavariable?
> warning: line 7: should String_tag be a metavariable?
> warning: line 7: should Double_tag be a metavariable?
> warning: line 7: should Double_array_tag be a metavariable?
> warning: line 7: should Custom_tag be a metavariable?

Yes, it assumes that things in argument position are intended to be 
metavariables, but that is not your case.  It will work fine.

> but as I rechecked now it seems to work. Nevertheless regexp is still needed
> for the second case when I want to match everything _except_ this 
> identifiers..

No, I don't think so.  You can just make pattern for what you don't want 
and another for what you do want:

@r@
expression ignore;
expression useful;
expression E;
@@

(
 ignore = foo(12)
|
 useful = foo(E)
)

Now in another rule you can use useful or E, and they will only be for the 
case where the argument of foo is not 12.

> > local idexpression v means that v is restricted to be a local variable.  
> > If you just want it to be a variable, but don't care about it being a 
> > local one, you can drop the local.  If you don't even care about it being 
> > a variable, eg you would like to allow a->b, then you can just put 
> > expression.
> > 
> > Constant is for constants, such as 27.  But it also considers an 
> > identifier that is all capital letters (possibly containing numbers) as a 
> > constant as well, because the names gives to #define in Linux usually have 
> > this form.
> > 
> > An identifier is the name of a structure field, a #define, a function, or 
> > a variable.  Is is the name of something rather than an expression that 
> > has a value.  But it is a bit confusing, because an identifier can be used 
> > in the position of an expression as well.
> 
> Thanks for your answers!
> (I guess the above paragraphs could be really helpful in the manual ;) )

OK, I'll try to find somewhere to put them.

thanks,
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to