On Tue, 2015-02-17 at 09:31PM +0100, Julia Lawall wrote:
> On Tue, 17 Feb 2015, Sören Brinkmann wrote:
> 
> > On Tue, 2015-02-17 at 07:56AM +0100, Julia Lawall wrote:
> > > Another patch is below.  With this the code parses, and the 
> > > transformation 
> > > can be made.  However, it considers this to be a duplicate const 
> > > annotation, so I'm not sure that the const is being associated in the 
> > > right way by the parser.
> > 
> > I applied the patch. I do see the mentioned warning now:
> >   Warning: PARSING: duplicate 'const'; value = [1]
> > 
> > The replacement still doesn't happen though. I'm not sure whether I
> > need another rule to catch these declarations. But I think I will
> > just make people fix their code. I think having 'const' appear twice
> > is not right, despite it being parseable.
> 
> Could you send a complete example?  It worked in the example I tried.

Sure. Please fine a test c file and my cocci patch (which grew a bit)
attached. This is the diff I get:
  init_defs_builtins: /usr/local/share/coccinelle/standard.h
  HANDLING: testcase4.c
  diff = 
  --- testcase4.c
  +++ /tmp/cocci-output-7912-c5f1e0-testcase4.c
  @@ -1,21 +1,21 @@
   
  -typedef struct foo {
  +struct foo {
        int member;
  -} foo_t;
  +};
   
  -static foo_t foo;
  -static const foo_t stco_foo;
  +static struct foo foo;
  +static const struct foo stco_foo;
   const foo_t const co_foo_co;
   static const foo_t const stco_foo_co;
   static const foo_t const stco_foo_coarr[] = {
   };
   
  -typedef struct {
  +struct bar {
        int member;
  -} bar_t;
  +};
   
  -static bar_t bar;
  -static const bar_t stco_bar;
  +static struct bar bar;
  +static const struct bar stco_bar;
   const bar_t const co_bar_co;
   static const bar_t const stco_bar_co;
   static const bar_t const stco_bar_coarr[] = {

        Thanks,
        Sören
typedef struct foo {
	int member;
} foo_t;

static foo_t foo;
static const foo_t stco_foo;
const foo_t const co_foo_co;
static const foo_t const stco_foo_co;
static const foo_t const stco_foo_coarr[] = {
};

typedef struct {
	int member;
} bar_t;

static bar_t bar;
static const bar_t stco_bar;
const bar_t const co_bar_co;
static const bar_t const stco_bar_co;
static const bar_t const stco_bar_coarr[] = {
};
/* Convert typdefed structs to structs */

/* Convert typdef to struct declaration */
@ rule1 @
identifier i;
type t;
@@
-typedef struct i {
+struct i {
        ...
}
- t
;

/* Replace type with struct */
@ rule2 @
identifier rule1.i;
type rule1.t;
@@
-t
+struct i

/* Catch occurences of 'const' instances/pointers */
@ rule3 @
identifier rule1.i;
type rule1.t;
@@
const
-t
+struct i

/* Replace typdef forward declarations with struct declaration */
@ rule4 @
identifier i;
type t;
@@
-typedef struct i t;
+struct i;

/* Replace type with struct (forward declarations */
@ rule5 @
identifier rule4.i;
type rule4.t;
@@
-t
+struct i

/* Replace type with struct (forward declarations */
@ rule6 @
identifier rule4.i;
type rule4.t;
@@
const
-t
+struct i

/* Convert unnamed structs */
@ rule7 @
type t;
@@
typedef struct {
        ...
}
t
;

/* Make typename usable as identifier */
@ script:python rule8 @
t << rule7.t;
i;
@@
coccinelle.i = t.rstrip('_t')

@ rule9 @
type rule7.t;
identifier rule8.i;
@@
-typedef struct {
+struct i {
        ...
}
- t
;

/* Replace type with struct */
@ rule10 @
type rule7.t;
identifier rule8.i;
@@
-t
+struct i

/* Catch occurences of 'const' instances/pointers */
@ rule11 @
type rule7.t;
identifier rule8.i;
@@
const
-t
+struct i
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to