From: Jakob Koschel <jkl820.git@gmail.com>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: Julia Lawall <julia.lawall@inria.fr>, cocci@inria.fr
Subject: Re: [cocci] Working with parameter/expression lists by SmPL
Date: Thu, 18 Aug 2022 14:51:09 +0200 [thread overview]
Message-ID: <88152C77-84AD-4515-A403-71F827180FD9@gmail.com> (raw)
In-Reply-To: <92b5eb33-9c76-7e45-7651-6296c9795a67@web.de>
Hey,
> On 17. Aug 2022, at 21:48, Markus Elfring <Markus.Elfring@web.de> wrote:
>
>>> I just tried:
>>>
>>> @main4@
>>> parameter list Ps;
>>> @@
>>>
>>> int func1(Ps) {
>>> ...
>>> }
>>>
>>> @main5@
>>> expression list main4.Ps;
>>> identifier func;
>>> @@
>>>
>>> func(Es);
>>> + // add comment
>>>
>>> but that throws:
>>>
>>> meta: semantic error: incompatible inheritance declaration Ps
>>> File "test.cocci", line 45, column 24, charpos = 539
>>> around = ';',
>>> whole content = expression list main4.Ps;
>> OK, there is a specific context in which this works, but it is only for
>> generating semantic patch rules.
>
>
> I would appreciate further explanations for such information.
I've finally managed to get it working. Always when I struggle with coccinelle
and get it working in the end it looks completely obvious.
Thanks a lot of for all the help Markus & Julia!
Let me show what I was trying to archive and how I solved it:
@r1@
parameter list [n] ps;
type t;
identifier i,f;
position p;
@@
f(ps, t i, ...) {
... when any
interesting_func@p(..., i, ...)
... when any
}
@r2@
identifier r1.f;
expression list [r1.n] es;
expression e, e1;
position p;
@@
e = e1
+ // here the argument to interesting_func was assigned
... when any
f(es, e, ...)@p;
I'm running it with this sample code:
int interesting_func(int argc, char *str) {
}
int main(int argc, char *argv[]) {
int x = 0;
func1(x, "asdf");
}
int func1(int number, char *str) {
int y = 0;
char *x = "x";
interesting_func(number, str);
interesting_func(number, x);
interesting_func(y, str);
interesting_func(y, x);
return 0;
}
with the desired result:
diff =
--- test1.c
+++ /tmp/cocci-output-test1.c
@@ -6,7 +6,8 @@ int interesting_func(int argc, char *str
}
int main(int argc, char *argv[]) {
- int x = 0;
+ int x = 0
+ // test;
func1(x, "asdf");
}
Thanks,
Jakob
>
> Regards,
> Markus
>
>
next prev parent reply other threads:[~2022-08-18 12:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 8:54 [cocci] match arbitrary argument position Jakob Koschel
2022-08-16 11:37 ` Julia Lawall
2022-08-16 12:35 ` Jakob Koschel
2022-08-16 17:55 ` Markus Elfring
2022-08-17 14:26 ` Jakob Koschel
2022-08-17 19:21 ` Markus Elfring
2022-08-16 21:07 ` Julia Lawall
2022-08-17 14:18 ` Jakob Koschel
2022-08-17 14:36 ` Julia Lawall
2022-08-17 14:50 ` Jakob Koschel
2022-08-17 15:26 ` Julia Lawall
2022-08-17 19:48 ` [cocci] Working with parameter/expression lists by SmPL Markus Elfring
2022-08-18 12:51 ` Jakob Koschel [this message]
2022-08-18 17:42 ` Markus Elfring
2022-08-19 9:12 ` Jakob Koschel
2022-08-19 9:57 ` Julia Lawall
2022-08-19 10:00 ` Jakob Koschel
2022-08-19 17:00 ` Markus Elfring
2022-08-20 12:57 ` Jakob Koschel
2022-08-21 8:10 ` Markus Elfring
2022-08-21 9:09 ` Julia Lawall
2022-08-21 9:46 ` Markus Elfring
2022-08-21 10:01 ` Julia Lawall
2022-08-21 11:33 ` Markus Elfring
2022-08-18 18:00 ` [cocci] Checking a comment addition Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=88152C77-84AD-4515-A403-71F827180FD9@gmail.com \
--to=jkl820.git@gmail.com \
--cc=Markus.Elfring@web.de \
--cc=cocci@inria.fr \
--cc=julia.lawall@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.