Yes, the trick of using different positions in different branches is a 
good one.

julia


On Thu, 19 May 2011, Francis Galiegue wrote:

> On Thu, May 19, 2011 at 16:43, Francis Galiegue <[email protected]> wrote:
> > On Thu, May 19, 2011 at 15:44, Julia Lawall <[email protected]> wrote:
> >> Sorry.  name is a reserved word.  Change the two occurrences eg to nm.
> >>
> >
> > Yes, that worked! However, the constant was surrounded with quotes, so
> > I had to do a little more manipulations... Here is the final result:
> >
> [...]
> 
> I managed to generalize it to all cases (ie, string constant before or
> after, or none)!
> 
> Here is the final result:
> 
> ----
> @initialize:python@
> 
> import re
> 
> @case2@
> constant char [] c;
> expression e1, e2;
> position p1, p2, p3;
> @@
> 
> (
> stralloc2@p1(c, e2)
> |
> stralloc2@p2(e1, c)
> |
> stralloc2@p3(e1, e2)
> )
> 
> @script:python nm@
> c << case2.c;
> uc;
> newc1;
> newc2;
> @@
> 
> uc = "%s" % c
> uc = re.sub(r'^"', r'', uc)
> uc = re.sub(r'"$', r'', uc)
> coccinelle.newc1 = "\"%s%%s\"" % uc
> coccinelle.newc2 = "\"%%s%s\"" % uc
> 
> @@
> position case2.p1, case2.p2, case2.p3;
> identifier nm.newc1, nm.newc2;
> expression e1, e2;
> @@
> 
> (
> - stralloc2@p1(e1, e2)
> + g_strdup_printf(newc1, e2)
> |
> - stralloc2@p2(e1, e2)
> + g_strdup_printf(newc2, e1)
> |
> - stralloc2@p3(e1, e2)
> + g_strjoin(NULL, e1, e2, NULL)
> )
> 
> ----
> 
> 
> 
> -- 
> Francis Galiegue, [email protected]
> "It seems obvious [...] that at least some 'business intelligence'
> tools invest so much intelligence on the business side that they have
> nothing left for generating SQL queries" (Stéphane Faroult, in "The
> Art of SQL", ISBN 0-596-00894-5)
> 
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to