All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Match #define in cocci
@ 2016-09-14 13:31 Waldemar Rymarkiewicz
  2016-09-14 14:16 ` Julia Lawall
  0 siblings, 1 reply; 10+ messages in thread
From: Waldemar Rymarkiewicz @ 2016-09-14 13:31 UTC (permalink / raw)
  To: cocci

Hi,

I'm new to cocci and try to understand how all this things work. I
have a problem with matching a #define  in a patch.

I wan to match local definition

   #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

and  add #undef  it first. The output should be like this

   #undef  pr_fmt
   #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

I tried many approaches but seems like parser have a problem with
parsing #defines.

Is that possible to achieve  what I expect in cocci ?


Cheers
/Waldek

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

* [Cocci] Match #define in cocci
  2016-09-14 13:31 [Cocci] Match #define in cocci Waldemar Rymarkiewicz
@ 2016-09-14 14:16 ` Julia Lawall
  2016-09-15  5:57   ` Waldemar Rymarkiewicz
  0 siblings, 1 reply; 10+ messages in thread
From: Julia Lawall @ 2016-09-14 14:16 UTC (permalink / raw)
  To: cocci



On Wed, 14 Sep 2016, Waldemar Rymarkiewicz wrote:

> Hi,
>
> I'm new to cocci and try to understand how all this things work. I
> have a problem with matching a #define  in a patch.
>
> I wan to match local definition
>
>    #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> and  add #undef  it first. The output should be like this
>
>    #undef  pr_fmt
>    #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> I tried many approaches but seems like parser have a problem with
> parsing #defines.
>
> Is that possible to achieve  what I expect in cocci ?

Could you send the exact semantic patch that you tried?  Coccinelle should
allos parsing #defines.

julia

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

* [Cocci] Match #define in cocci
  2016-09-14 14:16 ` Julia Lawall
@ 2016-09-15  5:57   ` Waldemar Rymarkiewicz
  2016-09-15  6:03     ` Julia Lawall
  0 siblings, 1 reply; 10+ messages in thread
From: Waldemar Rymarkiewicz @ 2016-09-15  5:57 UTC (permalink / raw)
  To: cocci

>
> Could you send the exact semantic patch that you tried?  Coccinelle should
> allos parsing #defines.

Simply

@@
@@
-#define pr_fmt(fmt) KBUILD_MODNAME

works, but

@@
@@
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

fails  with

Fatal error: exception Failure("minus: parse error: \n = File
\"patches/1021-pr_fmt_undef.cocci\", line 4, column 38,  charpos =
59\n    around = '\"', whole content = #define pr_fmt(fmt)
KBUILD_MODNAME \": \" fmt\n")

but even if I want to match just

@@
@@
-#define pr_fmt(fmt) KBUILD_MODNAME  fmt

it also fails with

Fatal error: exception Failure("minus: parse error: \n = File
\"patches/1021-pr_fmt_undef.cocci\", line 4, column 0,  charpos = 21\n
   around = '#define pr_fmt(', whole content = #define pr_fmt(fmt)
KBUILD_MODNAME fmt\n")


Thanks,
/Waldek

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

* [Cocci] Match #define in cocci
  2016-09-15  5:57   ` Waldemar Rymarkiewicz
@ 2016-09-15  6:03     ` Julia Lawall
  2016-09-15  6:41       ` Waldemar Rymarkiewicz
  0 siblings, 1 reply; 10+ messages in thread
From: Julia Lawall @ 2016-09-15  6:03 UTC (permalink / raw)
  To: cocci



On Thu, 15 Sep 2016, Waldemar Rymarkiewicz wrote:

> >
> > Could you send the exact semantic patch that you tried?  Coccinelle should
> > allos parsing #defines.
>
> Simply
>
> @@
> @@
> -#define pr_fmt(fmt) KBUILD_MODNAME
>
> works, but
>
> @@
> @@
> -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> fails  with
>
> Fatal error: exception Failure("minus: parse error: \n = File
> \"patches/1021-pr_fmt_undef.cocci\", line 4, column 38,  charpos =
> 59\n    around = '\"', whole content = #define pr_fmt(fmt)
> KBUILD_MODNAME \": \" fmt\n")
>
> but even if I want to match just
>
> @@
> @@
> -#define pr_fmt(fmt) KBUILD_MODNAME  fmt
>
> it also fails with
>
> Fatal error: exception Failure("minus: parse error: \n = File
> \"patches/1021-pr_fmt_undef.cocci\", line 4, column 0,  charpos = 21\n
>    around = '#define pr_fmt(', whole content = #define pr_fmt(fmt)
> KBUILD_MODNAME fmt\n")

OK, thanks I will look into it.  At least in the last case, that is not
the intended behavior.

julia

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

* [Cocci] Match #define in cocci
  2016-09-15  6:03     ` Julia Lawall
@ 2016-09-15  6:41       ` Waldemar Rymarkiewicz
  2016-09-15  7:44         ` Waldemar Rymarkiewicz
  2016-09-15  8:11         ` [Cocci] Match #define with SmPL SF Markus Elfring
  0 siblings, 2 replies; 10+ messages in thread
From: Waldemar Rymarkiewicz @ 2016-09-15  6:41 UTC (permalink / raw)
  To: cocci

> OK, thanks I will look into it.  At least in the last case, that is not
> the intended behavior.
>

One more, I use 1.0.2 version as I had a problem with  1.0.5
compilation previously.
I will try bump to 1.0. 5 anyway and check the behavior.

/Waldek

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

* [Cocci] Match #define in cocci
  2016-09-15  6:41       ` Waldemar Rymarkiewicz
@ 2016-09-15  7:44         ` Waldemar Rymarkiewicz
  2016-09-15  7:59           ` Julia Lawall
  2016-09-15  8:11         ` [Cocci] Match #define with SmPL SF Markus Elfring
  1 sibling, 1 reply; 10+ messages in thread
From: Waldemar Rymarkiewicz @ 2016-09-15  7:44 UTC (permalink / raw)
  To: cocci

On 15 September 2016 at 08:41, Waldemar Rymarkiewicz
<waldemar.rymarkiewicz@gmail.com> wrote:
>> OK, thanks I will look into it.  At least in the last case, that is not
>> the intended behavior.
>>
>
> One more, I use 1.0.2 version as I had a problem with  1.0.5
> compilation previously.
> I will try bump to 1.0. 5 anyway and check the behavior.
>

Now I use
  spatch version 1.0.5-00089-g0849d71 compiled with OCaml version 4.02.3
  Flags passed to the configure script: [none]
  Python scripting support: yes
  Syntax of regular expresssions: PCRE

and still cannot mach

@@
@@
-#define pr_fmt(fmt) KBUILD_MODNAME fmt

minus: parse error:
  File "patches/1021-pr_fmt_undef.cocci", line 3, column 1, charpos = 7
  around = '#define pr_fmt(',
  whole content = -#define pr_fmt(fmt) KBUILD_MODNAME fmt


/Waldek

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

* [Cocci] Match #define in cocci
  2016-09-15  7:44         ` Waldemar Rymarkiewicz
@ 2016-09-15  7:59           ` Julia Lawall
  0 siblings, 0 replies; 10+ messages in thread
From: Julia Lawall @ 2016-09-15  7:59 UTC (permalink / raw)
  To: cocci



On Thu, 15 Sep 2016, Waldemar Rymarkiewicz wrote:

> On 15 September 2016 at 08:41, Waldemar Rymarkiewicz
> <waldemar.rymarkiewicz@gmail.com> wrote:
> >> OK, thanks I will look into it.  At least in the last case, that is not
> >> the intended behavior.
> >>
> >
> > One more, I use 1.0.2 version as I had a problem with  1.0.5
> > compilation previously.
> > I will try bump to 1.0. 5 anyway and check the behavior.
> >
>
> Now I use
>   spatch version 1.0.5-00089-g0849d71 compiled with OCaml version 4.02.3
>   Flags passed to the configure script: [none]
>   Python scripting support: yes
>   Syntax of regular expresssions: PCRE
>
> and still cannot mach
>
> @@
> @@
> -#define pr_fmt(fmt) KBUILD_MODNAME fmt
>
> minus: parse error:
>   File "patches/1021-pr_fmt_undef.cocci", line 3, column 1, charpos = 7
>   around = '#define pr_fmt(',
>   whole content = -#define pr_fmt(fmt) KBUILD_MODNAME fmt

Yeah, I didn't expect it to work, but the github version is better in
other ways :)

julia

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

* [Cocci] Match #define with SmPL
  2016-09-15  6:41       ` Waldemar Rymarkiewicz
  2016-09-15  7:44         ` Waldemar Rymarkiewicz
@ 2016-09-15  8:11         ` SF Markus Elfring
  2016-09-20 12:38           ` Waldemar Rymarkiewicz
  1 sibling, 1 reply; 10+ messages in thread
From: SF Markus Elfring @ 2016-09-15  8:11 UTC (permalink / raw)
  To: cocci

> One more, I use 1.0.2 version as I had a problem with  1.0.5
> compilation previously.

Thanks that you added a bit more version information to your bug report.


> I will try bump to 1.0. 5 anyway and check the behavior.

Thanks for your interest to try additional software variants out.

I have tried also the following script out for the semantic patch language
of the software combination "Coccinelle 1.0.5-00089-g0849d71-dirty (OCaml 4.03.0)"
a moment ago.


@macro_deletion@
@@
-#define pr_fmt(fmt) "SVM: " fmt


elfring at Sonne:~/Projekte/Linux/next-patched> spatch.opt ~/Projekte/Coccinelle/Probe/delete_macro1.cocci arch/x86/kvm/svm.c
init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
minus: parse error: 
  File "/home/elfring/Projekte/Coccinelle/Probe/delete_macro1.cocci", line 3, column 29, charpos = 49
  around = 'fmt',
  whole content = -#define pr_fmt(fmt) "SVM: " fmt


Do you eventually know any more software developers who would like to help in the task
"Completion of support for preprocessor statements by the Coccinelle software"?


I would be also looking for an interface to store the text from the macro definition
into a corresponding data structure.

* How do think about to look at another "story" like "Checking printk() calls with SmPL"
  once more?
  https://github.com/coccinelle/coccinelle/issues/54#issuecomment-169988424

* Which metavariable types would be appropriate for the discussed source code transformation?


I would like to point another detail out for further considerations according to
your initial request.

1. I guess that you should use the SmPL asterisk functionality if you are interested
   in only finding (or "matching") a bit of code.

@macro_definition@
@@
*#define pr_fmt(fmt) "SVM: " fmt


init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
minus: parse error: 
  File "/home/elfring/Projekte/Coccinelle/Probe/show_macro_definition1.cocci", line 3, column 29, charpos = 51
  around = 'fmt',
  whole content = *#define pr_fmt(fmt) "SVM: " fmt


2. Do you want to try another source code adjustment out?

@statement_addition@
@@
+#undef  pr_fmt
 #define pr_fmt(fmt) "SVM: " fmt


elfring at Sonne:~/Projekte/Linux/next-patched> spatch.opt ~/Projekte/Coccinelle/Probe/add_undef1.cocci arch/x86/kvm/svm.c
init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
minus: parse error: 
  File "/home/elfring/Projekte/Coccinelle/Probe/add_undef1.cocci", line 4, column 29, charpos = 69
  around = 'fmt',
  whole content =  #define pr_fmt(fmt) "SVM: " fmt


How often would you like to use such search patterns for your source files?

Regards,
Markus

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

* [Cocci] Match #define with SmPL
  2016-09-15  8:11         ` [Cocci] Match #define with SmPL SF Markus Elfring
@ 2016-09-20 12:38           ` Waldemar Rymarkiewicz
  2016-09-20 18:20             ` SF Markus Elfring
  0 siblings, 1 reply; 10+ messages in thread
From: Waldemar Rymarkiewicz @ 2016-09-20 12:38 UTC (permalink / raw)
  To: cocci

> I would be also looking for an interface to store the text from the macro definition
> into a corresponding data structure.
>
> * How do think about to look at another "story" like "Checking printk() calls with SmPL"
>   once more?
>   https://github.com/coccinelle/coccinelle/issues/54#issuecomment-169988424
>
> * Which metavariable types would be appropriate for the discussed source code transformation?
>
>
> I would like to point another detail out for further considerations according to
> your initial request.
>
> 1. I guess that you should use the SmPL asterisk functionality if you are interested
>    in only finding (or "matching") a bit of code.
>
> @macro_definition@
> @@
> *#define pr_fmt(fmt) "SVM: " fmt
>
>
> init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
> minus: parse error:
>   File "/home/elfring/Projekte/Coccinelle/Probe/show_macro_definition1.cocci", line 3, column 29, charpos = 51
>   around = 'fmt',
>   whole content = *#define pr_fmt(fmt) "SVM: " fmt
>
>
> 2. Do you want to try another source code adjustment out?
>
> @statement_addition@
> @@
> +#undef  pr_fmt
>  #define pr_fmt(fmt) "SVM: " fmt
>
>
> elfring at Sonne:~/Projekte/Linux/next-patched> spatch.opt ~/Projekte/Coccinelle/Probe/add_undef1.cocci arch/x86/kvm/svm.c
> init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
> minus: parse error:
>   File "/home/elfring/Projekte/Coccinelle/Probe/add_undef1.cocci", line 4, column 29, charpos = 69
>   around = 'fmt',
>   whole content =  #define pr_fmt(fmt) "SVM: " fmt
>
>
> How often would you like to use such search patterns for your source files?

I've already tried all above, but always I get parser error.
Apparently parsing #defines is not working as expected specially if
you use argument list.


/Waldek

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

* [Cocci] Match #define with SmPL
  2016-09-20 12:38           ` Waldemar Rymarkiewicz
@ 2016-09-20 18:20             ` SF Markus Elfring
  0 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2016-09-20 18:20 UTC (permalink / raw)
  To: cocci

>> How often would you like to use such search patterns for your source files?

Would you like to answer this question?


> I've already tried all above,

Your tries were not so clear initially.


> but always I get parser error.

Now we can agree that there open issues for further considerations, can't we?


> Apparently parsing #defines is not working as expected specially if
> you use argument list.

How do you think about to pick this use case up as another software development challenge?

Would you like to extend your development experience in this direction anyhow?

Regards,
Markus

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

end of thread, other threads:[~2016-09-20 18:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14 13:31 [Cocci] Match #define in cocci Waldemar Rymarkiewicz
2016-09-14 14:16 ` Julia Lawall
2016-09-15  5:57   ` Waldemar Rymarkiewicz
2016-09-15  6:03     ` Julia Lawall
2016-09-15  6:41       ` Waldemar Rymarkiewicz
2016-09-15  7:44         ` Waldemar Rymarkiewicz
2016-09-15  7:59           ` Julia Lawall
2016-09-15  8:11         ` [Cocci] Match #define with SmPL SF Markus Elfring
2016-09-20 12:38           ` Waldemar Rymarkiewicz
2016-09-20 18:20             ` SF Markus Elfring

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.