Hi,

I found an unfortunate asymmetry on matching an identifier declared in a
multiple declaration. In short, it works fine on a multiple variables
declaration, but not on a multiple fields declaration.

For example, the following semantic patch, adding parentheses around
uses of integer variables and integer fields:

--- intvar2.cocci:
@findvar@ identifier i; @@
 int i;

@expression@ identifier findvar.i; @@
+(
  i
+)

@findfld@ identifier id, id3; @@
 struct {
 ...
 int id;
 ...} id3;

@expression@ identifier x, findfld.id; @@
+(
  x.id
+)

---
applied on the following program:

--- intvar2.c:
#include <stdio.h>

struct {
  int f1, f2;
  int f3;
} s;

int main() {
  int i1, i2;
  int i3;
  i1 = 11;
  i2 = 22;
  i3 = 33;
  printf("%d, %d, %d\n", i1, i2, i3);
  s.f1 = 44;
  s.f2 = 55;
  s.f3 = 66;
  printf("{%d, %d, %d}\n", s.f1, s.f2, s.f3);
}

---
transforms variables i1, i2, i3, and field f3, but not fields f1 and f2.

Is it possible to turn around this problem? Or even better, to fix
it...?

Thanks,
Nic.


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

Reply via email to