All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Problems: Adding Include directives, Adding ({}) construct
@ 2017-02-27 13:04 sebald.ziegler.cocci at ikolus.de
  2017-03-02  7:21 ` Julia Lawall
  2017-03-03 16:19 ` Julia Lawall
  0 siblings, 2 replies; 5+ messages in thread
From: sebald.ziegler.cocci at ikolus.de @ 2017-02-27 13:04 UTC (permalink / raw)
  To: cocci

Hi,

I am trying to use coccinelle to add an include directive before the other 
includes and one after the includes:

@PreInclude@
@@
+ #include "pre.h"
#include ...


@PostInclude@
@@
#include ...
+ #include "post.h"

this works well if the source file (all includes are always at the top of the 
file) contains more than one include directive. However, if there is only one 
include directive -> only the PreInclude rule is executed.

So for this program:
#include <stdio.h>

int main() {
    return 0;
}

This is the result:
#include "pre.h"
#include <stdio.h>

int main() {
    return 0;
}

So it seems that only one rule can match some code line/code pattern. Am I 
mistaken? What could be an approach that works for both the single include 
directive and multiple include directives case?


Another Question:
With the following rule I want to add a macro definition just above the main 
function:
@macro_square@
@@
+ #define SQUARE(x) ({printf("SQUARE(x)\n"); x*x; })
int main(int argc, char ** argv) {
...
}

If I execute spatch on the program above this error is reported (coccinelle 
version: 1.0.6):
plus: parse error: 
  File "/tmp/testing/test.c-brackets.cocci", line 3, column 21, charpos = 39
  around = '{',
  whole content = + #define SQUARE(x) ({printf("SQUARE(x)\n"); x*x; })

Is this kind of code not supported or did I make a mistake somewhere?

Thank you for any information and hints!

Regards,
Sebald

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

end of thread, other threads:[~2017-03-07 16:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-27 13:04 [Cocci] Problems: Adding Include directives, Adding ({}) construct sebald.ziegler.cocci at ikolus.de
2017-03-02  7:21 ` Julia Lawall
2017-03-07 16:12   ` sebald.ziegler.cocci at ikolus.de
2017-03-07 16:25     ` Julia Lawall
2017-03-03 16:19 ` 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.