* [Cocci] How can i rename a specific structure field?
@ 2014-10-02 20:12 jmiguel hernandez
2014-10-02 20:22 ` Julia Lawall
2014-10-02 20:44 ` Lars-Peter Clausen
0 siblings, 2 replies; 7+ messages in thread
From: jmiguel hernandez @ 2014-10-02 20:12 UTC (permalink / raw)
To: cocci
if i have this
typedef struct type1 {
char8 a;
char8 b;
char8 c;
}
typedef struct _interface {
type1 field1;
}interface;
and want to change to
typedef struct type1 {
char8 d;
char8 b;
char8 c;
}
typedef struct _protocol {
type1 *field1;
}interface;
interface *p
-p->field->a
+p->field->d
I have tried just changing field1 to field2. This gives parsing errors.
@@
typedef interface;
interface *p;
typedef type1;
type1 field1;
@@
<...
-p->field1
+p->fieldnew
...>
also, similar question. What if i want to change the type.
typedef struct _interface {
type2 *field1;
}interface;
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20141002/89ff092a/attachment.html>
^ permalink raw reply [flat|nested] 7+ messages in thread* [Cocci] How can i rename a specific structure field? 2014-10-02 20:12 [Cocci] How can i rename a specific structure field? jmiguel hernandez @ 2014-10-02 20:22 ` Julia Lawall 2014-10-02 20:44 ` Lars-Peter Clausen 1 sibling, 0 replies; 7+ messages in thread From: Julia Lawall @ 2014-10-02 20:22 UTC (permalink / raw) To: cocci On Thu, 2 Oct 2014, jmiguel hernandez wrote: > if i have this? > > typedef struct type1 { > ? char8 a; > ? char8 b; > ? char8 c; > } > > typedef struct _interface?{ > ? type1 field1; > }interface; > > and want to change to? > > typedef struct type1 { > ? char8 d; > ? char8 b; > ? char8 c; > } > > typedef struct _protocol { > ? type1 *field1; > }interface; > > interface *p > > -p->field->a > +p->field->d > > I have tried just changing field1 to field2. This gives parsing errors.? > > @@ > typedef interface; > interface *p; > typedef type1; > type1 field1; > @@ > <... > -p->field1 > +p->fieldnew > ...> Drop the <... ...>. You can think of it as being implicit when the patter is at top level. The problem is that you have declared field1 to be an expression of type type1. field1 is not that. It is just the name of a field in a structure. It should be declared as an identifier. Once you know that p has type interface*, field1 should be unambiguous. You don't have to specify the type of the field. > also, similar question. What if i want to change the type.? > > typedef struct _interface?{ > ? type2 *field1; > }interface; Not sure to understand what is wanted here. Perhaps if you get the right answer for the previous question, this one will also be clear. julia ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] How can i rename a specific structure field? 2014-10-02 20:12 [Cocci] How can i rename a specific structure field? jmiguel hernandez 2014-10-02 20:22 ` Julia Lawall @ 2014-10-02 20:44 ` Lars-Peter Clausen [not found] ` <CAHsAT8Knor4wG+398-BZ15Upwv1PWz=6VOGQvEXcHSGzimkD9Q@mail.gmail.com> 1 sibling, 1 reply; 7+ messages in thread From: Lars-Peter Clausen @ 2014-10-02 20:44 UTC (permalink / raw) To: cocci On 10/02/2014 10:12 PM, jmiguel hernandez wrote: > if i have this > > typedef struct type1 { > char8 a; > char8 b; > char8 c; > } > > typedef struct _interface { > type1 field1; > }interface; > > and want to change to > > typedef struct type1 { > char8 d; > char8 b; > char8 c; > } > > typedef struct _protocol { > type1 *field1; > }interface; > > interface *p > > -p->field->a > +p->field->d > > I have tried just changing field1 to field2. This gives parsing errors. > > @@ > typedef interface; > interface *p; > typedef type1; > type1 field1; > @@ > <... > -p->field1 > +p->fieldnew > ...> If you want to change the field from being embedded in the parent struct to a pointer and rename the field at the same time the way to go is @@ typedef interface; interface *p; @@ p->field1 -.a +->b That replaces the ".a" with a "->b" - Lars ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAHsAT8Knor4wG+398-BZ15Upwv1PWz=6VOGQvEXcHSGzimkD9Q@mail.gmail.com>]
* [Cocci] Fwd: How can i rename a specific structure field? [not found] ` <CAHsAT8Knor4wG+398-BZ15Upwv1PWz=6VOGQvEXcHSGzimkD9Q@mail.gmail.com> @ 2014-10-06 17:11 ` jmiguel hernandez 2014-10-06 17:32 ` Julia Lawall 0 siblings, 1 reply; 7+ messages in thread From: jmiguel hernandez @ 2014-10-06 17:11 UTC (permalink / raw) To: cocci ?Forgot to reply to the list :S? Thank you, i was trying to Move a any field from a structure inside a data structure a. @@ typedef interface; interface *p; identifier fld; @@ p->field1 -.fld +.a.fld But it looks like it is not matching anything. The type for p must match, and also the name of field1. i am moving some elements from field1 into "struct a" which is on field1. So ideally, i was thinking on using a dependency like https://github.com/coccinelle/coccinellery/blob/master/iserr/patch1.cocci for the exceptions. but at this point i will be satified if i can just move everything from field1 into a. I also tried this, and defining fld as field instead of identifier. @@ typedef interface; interface *p; identifier fld; @@ -p->field1.fld +p->field1.a.fld i am sorry i am just getting to understand the grammar. I wonder if there is an example slightly similar about structure transformations i could read. Thanks On Thu, Oct 2, 2014 at 3:44 PM, Lars-Peter Clausen <lars@metafoo.de> wrote: > On 10/02/2014 10:12 PM, jmiguel hernandez wrote: > >> if i have this >> >> typedef struct type1 { >> char8 a; >> char8 b; >> char8 c; >> } >> >> typedef struct _interface { >> type1 field1; >> }interface; >> >> and want to change to >> >> typedef struct type1 { >> char8 d; >> char8 b; >> char8 c; >> } >> >> typedef struct _protocol { >> type1 *field1; >> }interface; >> >> interface *p >> >> -p->field->a >> +p->field->d >> >> I have tried just changing field1 to field2. This gives parsing errors. >> >> @@ >> typedef interface; >> interface *p; >> typedef type1; >> type1 field1; >> @@ >> <... >> -p->field1 >> +p->fieldnew >> ...> >> > > If you want to change the field from being embedded in the parent struct > to a pointer and rename the field at the same time the way to go is > > @@ > typedef interface; > interface *p; > @@ > p->field1 > -.a > +->b > > That replaces the ".a" with a "->b" > > - Lars > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20141006/c5e80af7/attachment.html> ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] Fwd: How can i rename a specific structure field? 2014-10-06 17:11 ` [Cocci] Fwd: " jmiguel hernandez @ 2014-10-06 17:32 ` Julia Lawall 2014-10-06 18:14 ` jmiguel hernandez 0 siblings, 1 reply; 7+ messages in thread From: Julia Lawall @ 2014-10-06 17:32 UTC (permalink / raw) To: cocci On Mon, 6 Oct 2014, jmiguel hernandez wrote: > > ?Forgot to reply to the list :S? > > > Thank you, > i was trying to Move a any field from a structure inside a data structure > a.? > > @@ > typedef interface; > interface *p; > identifier fld; > @@ > p->field1 > -.fld > +.a.fld? > > But it looks like it is not matching anything. The type for p must match, > and also the name of field1.? > i am moving some elements from field1 into "struct a" which is on field1. So > ideally, i was thinking on using a dependencylike?https://github.com/coccinelle/coccinellery/blob/master/iserr/patch1.co > cci for the exceptions. ? Could you send a small example of C code before and after the expected transformation? thanks, julia > but at this point i will be satified if i can just move everything from > field1 into a. > I also tried this, and defining fld as field instead of identifier.? > > @@ > typedef interface; > interface *p; > identifier fld; > @@ > -p->field1.fld > +p->field1.a.fld > > i am sorry i am just getting to understand the grammar. I wonder if there is > an example slightly similar about structure transformations i could read. > Thanks? > > > On Thu, Oct 2, 2014 at 3:44 PM, Lars-Peter Clausen <lars@metafoo.de> wrote: > On 10/02/2014 10:12 PM, jmiguel hernandez wrote: > if i have this > > typedef struct type1 { > ? ?char8 a; > ? ?char8 b; > ? ?char8 c; > } > > typedef struct _interface { > ? ?type1 field1; > }interface; > > and want to change to > > typedef struct type1 { > ? ?char8 d; > ? ?char8 b; > ? ?char8 c; > } > > typedef struct _protocol { > ? ?type1 *field1; > }interface; > > interface *p > > -p->field->a > +p->field->d > > I have tried just changing field1 to field2. This > gives parsing errors. > > @@ > typedef interface; > interface *p; > typedef type1; > type1 field1; > @@ > <... > -p->field1 > +p->fieldnew > ...> > > > If you want to change the field from being embedded in the parent > struct to a pointer and rename the field at the same time the way to > go is > > @@ > typedef interface; > interface *p; > @@ > p->field1 > -.a > +->b > > That replaces the ".a" with a "->b" > > - Lars > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] Fwd: How can i rename a specific structure field? 2014-10-06 17:32 ` Julia Lawall @ 2014-10-06 18:14 ` jmiguel hernandez 2014-10-07 7:27 ` Julia Lawall 0 siblings, 1 reply; 7+ messages in thread From: jmiguel hernandez @ 2014-10-06 18:14 UTC (permalink / raw) To: cocci //I had something similar to this typedef struct { unsigned char field1; TYPE3 field2; unsigned char field3; } CONFIGURATION; typedef struct _INTERFACE { CONFIGURATION *Configuration; TYPE2 *Interface2; } INTERFACES; //I need to regroup the fields. typedef struct { unsigned char field3; } GROUP2; typedef struct { unsigned char field1; TYPE3 field2; } GROUP; typedef struct { GROUP *fieldnew1; GROUP2 *fieldnew2; } CONFIGURATION2; typedef struct _INTERFACE { CONFIGURATION Configuration; TYPE2 Interface2; } INTERFACE2; So, i need to replace the references. INTERFACE2 *a; a->Configuration->field1 <==> a->Configuration.fieldnew1.field1 a->Configuration->field2.boolean <==> a->Configuration.fieldnew1.field2.boolean a->Configuration->field3 <==> a->Configuration.fieldnew2.field3 On Mon, Oct 6, 2014 at 12:32 PM, Julia Lawall <julia.lawall@lip6.fr> wrote: > On Mon, 6 Oct 2014, jmiguel hernandez wrote: > > > > > ?Forgot to reply to the list :S? > > > > > > Thank you, > > i was trying to Move a any field from a structure inside a data structure > > a. > > > > @@ > > typedef interface; > > interface *p; > > identifier fld; > > @@ > > p->field1 > > -.fld > > +.a.fld > > > > But it looks like it is not matching anything. The type for p must match, > > and also the name of field1. > > i am moving some elements from field1 into "struct a" which is on > field1. So > > ideally, i was thinking on using a dependencylike > https://github.com/coccinelle/coccinellery/blob/master/iserr/patch1.co > > cci for the exceptions. > > Could you send a small example of C code before and after the expected > transformation? > > thanks, > julia > > > > but at this point i will be satified if i can just move everything from > > field1 into a. > > I also tried this, and defining fld as field instead of identifier. > > > > @@ > > typedef interface; > > interface *p; > > identifier fld; > > @@ > > -p->field1.fld > > +p->field1.a.fld > > > > i am sorry i am just getting to understand the grammar. I wonder if > there is > > an example slightly similar about structure transformations i could read. > > Thanks > > > > > > On Thu, Oct 2, 2014 at 3:44 PM, Lars-Peter Clausen <lars@metafoo.de> > wrote: > > On 10/02/2014 10:12 PM, jmiguel hernandez wrote: > > if i have this > > > > typedef struct type1 { > > char8 a; > > char8 b; > > char8 c; > > } > > > > typedef struct _interface { > > type1 field1; > > }interface; > > > > and want to change to > > > > typedef struct type1 { > > char8 d; > > char8 b; > > char8 c; > > } > > > > typedef struct _protocol { > > type1 *field1; > > }interface; > > > > interface *p > > > > -p->field->a > > +p->field->d > > > > I have tried just changing field1 to field2. This > > gives parsing errors. > > > > @@ > > typedef interface; > > interface *p; > > typedef type1; > > type1 field1; > > @@ > > <... > > -p->field1 > > +p->fieldnew > > ...> > > > > > > If you want to change the field from being embedded in the parent > > struct to a pointer and rename the field at the same time the way to > > go is > > > > @@ > > typedef interface; > > interface *p; > > @@ > > p->field1 > > -.a > > +->b > > > > That replaces the ".a" with a "->b" > > > > - Lars > > > > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20141006/48856bda/attachment-0001.html> ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] Fwd: How can i rename a specific structure field? 2014-10-06 18:14 ` jmiguel hernandez @ 2014-10-07 7:27 ` Julia Lawall 0 siblings, 0 replies; 7+ messages in thread From: Julia Lawall @ 2014-10-07 7:27 UTC (permalink / raw) To: cocci I'm sorry, but this is not helpful enough. For example, your semantic patch contains the type interface, but the code contains INTERFACES and INTERFACE2. Without having an exact semantic patch that you want to run and an exact C file on which you expect an exact result, all I can do is make something that does something, but I can't tell if it does what you actually want to do. I don't actually need the typedefs. Coccinelle doesn't care about why you want to make the transformation, only about the code that you want to transform. For example, I made the following semantic patch: @@ typedef interface; interface *p; identifier field1,fld; @@ p->field1 - ->fld + ->a.fld and the following C program: int main () { interface *a; a->Configuration->field1; a->Configuration->field2.boolean; a->Configuration->field3; } This works fine, but I don't know if it is what you want to do. julia On Mon, 6 Oct 2014, jmiguel hernandez wrote: > > //I had something similar to this? > > typedef struct { > ? unsigned char ? ? ? ? ? ? ? field1; > ? TYPE3 ? ? ? ? ? ? ? ? ? ? ? field2; > ? unsigned char ? ? ? ? ? ? ? field3; > } CONFIGURATION; > > typedef struct _INTERFACE { > ? CONFIGURATION ? ? ? ?*Configuration; > ? TYPE2 ? ? ? ? ? ? ? ?*Interface2; > } INTERFACES; > > > //I need to regroup the fields. > > > typedef struct { > ? unsigned char ? ? ? ? ? ? ? field3; > } GROUP2; > > typedef struct { > ? unsigned char ? ? ? ? ? ? ? field1; > ? TYPE3 ? ? ? ? ? ? ? ? ? ? ? field2; > } GROUP; > > typedef struct { > ? GROUP ? ? ? ? ? ? ? ? ? ? ? *fieldnew1; > ? GROUP2 ? ? ? ? ? ? ? ? ? ? ?*fieldnew2; > } CONFIGURATION2; > > > typedef struct _INTERFACE { > ? CONFIGURATION ? ? ? ?Configuration; > ? TYPE2 ? ? ? ? ? ? ? ?Interface2; > } INTERFACE2; > > So, i need to replace the references.? > ? > INTERFACE2 *a;? > > a->Configuration->field1 ?<==> a->Configuration.fieldnew1.field1 > a->Configuration->field2.boolean ?<==> > a->Configuration.fieldnew1.field2.boolean > a->Configuration->field3 <==> a->Configuration.fieldnew2.field3 > > > > On Mon, Oct 6, 2014 at 12:32 PM, Julia Lawall <julia.lawall@lip6.fr> wrote: > On Mon, 6 Oct 2014, jmiguel hernandez wrote: > > > > > ?Forgot to reply to the list :S? > > > > > > Thank you, > > i was trying to Move a any field from a structure inside a > data structure > > a.? > > > > @@ > > typedef interface; > > interface *p; > > identifier fld; > > @@ > > p->field1 > > -.fld > > +.a.fld? > > > > But it looks like it is not matching anything. The type for p > must match, > > and also the name of field1.? > > i am moving some elements from field1 into "struct a" which is > on field1. So > > ideally, i was thinking on using adependencylike?https://github.com/coccinelle/coccinellery/blob/master/iserr > /patch1.co > > cci for the exceptions. ? > > Could you send a small example of C code before and after the > expected > transformation? > > thanks, > julia > > > > but at this point i will be satified if i can just move > everything from > > field1 into a. > > I also tried this, and defining fld as field instead of > identifier.? > > > > @@ > > typedef interface; > > interface *p; > > identifier fld; > > @@ > > -p->field1.fld > > +p->field1.a.fld > > > > i am sorry i am just getting to understand the grammar. I > wonder if there is > > an example slightly similar about structure transformations i > could read. > > Thanks? > > > > > > On Thu, Oct 2, 2014 at 3:44 PM, Lars-Peter Clausen > <lars@metafoo.de> wrote: > >? ? ? ?On 10/02/2014 10:12 PM, jmiguel hernandez wrote: > >? ? ? ? ? ? ?if i have this > > > >? ? ? ? ? ? ?typedef struct type1 { > >? ? ? ? ? ? ?? ?char8 a; > >? ? ? ? ? ? ?? ?char8 b; > >? ? ? ? ? ? ?? ?char8 c; > >? ? ? ? ? ? ?} > > > >? ? ? ? ? ? ?typedef struct _interface { > >? ? ? ? ? ? ?? ?type1 field1; > >? ? ? ? ? ? ?}interface; > > > >? ? ? ? ? ? ?and want to change to > > > >? ? ? ? ? ? ?typedef struct type1 { > >? ? ? ? ? ? ?? ?char8 d; > >? ? ? ? ? ? ?? ?char8 b; > >? ? ? ? ? ? ?? ?char8 c; > >? ? ? ? ? ? ?} > > > >? ? ? ? ? ? ?typedef struct _protocol { > >? ? ? ? ? ? ?? ?type1 *field1; > >? ? ? ? ? ? ?}interface; > > > >? ? ? ? ? ? ?interface *p > > > >? ? ? ? ? ? ?-p->field->a > >? ? ? ? ? ? ?+p->field->d > > > >? ? ? ? ? ? ?I have tried just changing field1 to field2. This > >? ? ? ? ? ? ?gives parsing errors. > > > >? ? ? ? ? ? ?@@ > >? ? ? ? ? ? ?typedef interface; > >? ? ? ? ? ? ?interface *p; > >? ? ? ? ? ? ?typedef type1; > >? ? ? ? ? ? ?type1 field1; > >? ? ? ? ? ? ?@@ > >? ? ? ? ? ? ?<... > >? ? ? ? ? ? ?-p->field1 > >? ? ? ? ? ? ?+p->fieldnew > >? ? ? ? ? ? ?...> > > > > > > If you want to change the field from being embedded in the > parent > > struct to a pointer and rename the field at the same time the > way to > > go is > > > > @@ > > typedef interface; > > interface *p; > > @@ > > p->field1 > > -.a > > +->b > > > > That replaces the ".a" with a "->b" > > > > - Lars > > > > > > > > > > > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-10-07 7:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-02 20:12 [Cocci] How can i rename a specific structure field? jmiguel hernandez
2014-10-02 20:22 ` Julia Lawall
2014-10-02 20:44 ` Lars-Peter Clausen
[not found] ` <CAHsAT8Knor4wG+398-BZ15Upwv1PWz=6VOGQvEXcHSGzimkD9Q@mail.gmail.com>
2014-10-06 17:11 ` [Cocci] Fwd: " jmiguel hernandez
2014-10-06 17:32 ` Julia Lawall
2014-10-06 18:14 ` jmiguel hernandez
2014-10-07 7:27 ` Julia Lawall
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.