On Sat, 14 Feb 2015, Sören Brinkmann wrote:

> Hi Julia,
> 
> On Sat, 2015-02-14 at 07:56PM +0100, Julia Lawall wrote:
> > On Sat, 14 Feb 2015, Sören Brinkmann wrote:
> > 
> > > Hi,
> > >
> > > I'm just getting my feet wet with coccinelle, so I'm probably missing
> > > something really obvious in my problem.
> > >
> > > I have a codebase that uses plenty of
> > >   typedef struct foo {
> > >           ...
> > >   } bar;
> > >
> > > I want to remove all these typedefs and simply use struct foo instead. I
> > > came up with this patch:
> > >
> > >   /// Convert typdefed structs to structs
> > >
> > >   @ rule1 @
> > >   identifier i;
> > >   type t;
> > >   @@
> > >   -typedef struct i {
> > >   +struct i {
> > >           ...
> > >   - }t;
> > >   + };
> > >
> > >   @@
> > >   identifier rule1.i;
> > >   type rule1.t;
> > >   @@
> > >   -t
> > >   +struct i
> > >   // end of patch
> > >
> > > This seems to work for most occurrences, but there are a couple of
> > > variables defined like this:
> > >
> > >   static const t *const baz[MAX] = {
> > >           ...
> > >   };
> > >
> > > And also function declarations like:
> > >   u32 fn(const t* const baz);
> > >
> > > In such cases, t isn't replaces as I would expect, but those lines
> > > aren't changed at all.
> > >
> > > Other variables and non-const function parameters seem to be replaced as
> > > expected.
> > > Does anybody have an idea what I'm missing?

OK, the issue is that const is considered to be part of the type, so when 
you have a metavariable that contains type foo, it doesn't match an 
occurrence of const foo.  I'm not sure if it is correct to consider const 
to be part of the type, but I'm also not eager to change it.  Could you 
live with the solution of just making one more rule:

@@
identifier rule1.i;
type rule1.t;
@@
 const
-t
+struct i

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to