From: Markus Elfring <Markus.Elfring@web.de>
To: Eric Wheeler <cocci@lists.ewheeler.net>, cocci@inria.fr
Subject: Re: [cocci] Can Coccinelle concatenate or append to existing string literals?
Date: Sun, 13 Mar 2022 10:45:57 +0100 [thread overview]
Message-ID: <caf9ec38-c627-711d-885d-b975cc914fca@web.de> (raw)
In-Reply-To: <9112994e-3913-54e-dfc1-b1b7f54fc191@ewheeler.net>
> to produce this:
>
> void f()
> {
> - foo("foo");
> + foo("foo_bar");
> }
>
> It looks like `fresh identifier` can do something like this,
> but I can't get it to work with strings.
I suggest to increase the distinction which data parts you would like to modify
for such a transformation attempt.
> Is there a way?
Will another test result for a SmPL script like the following trigger any further
collateral evolution?
@addition@
@@
void f()
{
foo("foo"
+ "_bar"
);
}
Markus_Elfring@Sonne:…Projekte/Coccinelle/Probe> spatch --parse-cocci append_to_string_literal1.cocci
…
plus: parse error:
File "append_to_string_literal1.cocci", line 6, column 10, charpos = 48
around = '"',
whole content = + "_bar"
How will the chances evolve to support string literal concatenations better here
(by the means of the semantic patch language)?
https://en.cppreference.com/w/c/language/string_literal#Explanation
@initialize:python@
@@
import re
@find_update_candidate@
constant input_string;
position pos;
@@
void f()
{
foo@pos(input_string);
}
@script:python selection@
param << find_update_candidate.input_string;
text;
@@
if param == '"foo"':
coccinelle.text = cocci.make_expr('"foo_bar"')
else:
cocci.include_match(False)
@replacement@
constant find_update_candidate.input_string, selection.text;
position find_update_candidate.pos;
@@
void f()
{
foo@pos(
- input_string
+ text
);
}
Markus_Elfring@Sonne:…Projekte/Coccinelle/Probe> spatch append_to_string_literal2.cocci string_literal_usage1.c
…
@@ -1,4 +1,4 @@
void f()
{
-foo("foo");
+foo("foo_bar");
}
Regards,
Markus
next prev parent reply other threads:[~2022-03-13 9:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-13 0:53 [cocci] Can Coccinell concatinate or append to existing string literals? Eric Wheeler
2022-03-13 7:05 ` Julia Lawall
2022-03-13 9:45 ` Markus Elfring [this message]
2022-03-13 9:57 ` [cocci] Can Coccinelle concatenate " Julia Lawall
2022-03-13 13:00 ` Markus Elfring
2022-03-13 16:31 ` [cocci] Can Coccinell concatinate " Luis Chamberlain
2022-03-13 17:24 ` [cocci] Can Coccinelle concatenate " Markus Elfring
2022-03-13 17:33 ` Julia Lawall
2022-03-13 18:30 ` [cocci] Checking the construction of a fresh identifier Markus Elfring
2022-03-15 2:40 ` [cocci] Can Coccinell concatinate or append to existing string literals? Eric Wheeler
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=caf9ec38-c627-711d-885d-b975cc914fca@web.de \
--to=markus.elfring@web.de \
--cc=cocci@inria.fr \
--cc=cocci@lists.ewheeler.net \
/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.