cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Strange behavior with replacing multiple typedefs
@ 2018-09-16 14:58 Moustafa Mahmoud
  2018-09-16 15:07 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Moustafa Mahmoud @ 2018-09-16 14:58 UTC (permalink / raw)
  To: cocci

Hello all,
I am facing this problem with typedefs, what I am trying to achieve is
convering multiple typedefs into single ones.


typedef int x,y;

into :

typedef  int x;
typedef int y;


when I try to replace them inside functions, everything works as expected\

My Rule :
@rule1@
identifier fn;
type t;
metavariable mm;
@@

++ typedef t mm;
fn(...){
<+...
- typedef t mm;
...+>
}

The C Code

typedef int;
typedef int mr,e4;

int main()
{
    typedef int sss, ssd;
}

The Diff :
diff =
--- typedef.c
+++ /tmp/cocci-output-91048-e42770-typedef.c
@@ -3,7 +3,8 @@
 typedef int;
 typedef int mr,e4;

+typedef int ssd;
+typedef int sss;
 int main()
 {
-    typedef int sss, ssd;
 }
\ No newline at end of file


However if I try to generalize it

@rule1@
type t;
metavariable mm;
@@

++ typedef t mm;
- typedef t mm;



The C Code:

typedef int;
typedef int mr,e4;

int main()
{
    typedef int sss, ssd;
}

What I get is this :

 typedef int;
-typedef int mr,e4;
+typedef int e4;
+typedef int mr;
+typedef int;

 int main()
 {
-    typedef int sss, ssd;
+    typedef int ssd;
+    typedef int sss;
+    typedef int;
 }
\ No newline at end of file


You can notice the extra  "+  typedef int;" , why are those produced ? is
there a way to achieve what  want without them ?

Thank you very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20180916/4f7fbf15/attachment.html>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-16 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-16 14:58 [Cocci] Strange behavior with replacing multiple typedefs Moustafa Mahmoud
2018-09-16 15:07 ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).