On Thu, 19 May 2016, Jiaying Liang wrote:

> 
> Hello,
> 
>  
> 
> I am looking for a way to add a field to a c structure definition.
> 
>  
> 
> I have this:
> 
>  
> 
> struct struct_A {
> 
>    int a;
> 
>    int b;
> 
> };
> 
>  
> 
> struct struct_B {
> 
>   int c;
> 
>   int d;
> 
> };
> 
>  
> 
> I want to change “struct struct_A” to:
> 
> struct struct_A {
> 
>   int a;
> 
>   int b;
> 
>   struct struct_B;
> 
> };

Maybe you would like something like this:

@@
@@

struct struct_A {
  ...
+ struct struct_B sb;
};

It could be that you want to add this field not only to the structure that 
has the name struct_A, but to any structure that has a field of type 
struct XXX.  Then you could say:

@@
identifier sa,x;
@@

struct sa {
  ...
  struct XXX x;
  ...
+ struct struct_B sb;
};

Or the structure name might be one that you have stored in a metavariable 
in some other rule r.  So you might have:

@@
identifier r.sa;
@@
  
struct sa {
  ...
+ struct struct_B sb;
};

I hope this help.  Please feel free to write back if you have further 
questions.

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

Reply via email to