* [Cocci] Newline escape in preprocessor
@ 2020-10-23 3:33 Mansour Moufid
2020-10-23 6:05 ` Julia Lawall
2020-10-23 15:00 ` [Cocci] Adjusting replacement lists with SmPL? Markus Elfring
0 siblings, 2 replies; 5+ messages in thread
From: Mansour Moufid @ 2020-10-23 3:33 UTC (permalink / raw)
To: cocci
Hi,
I'd like to add a statement after another within a preprocessor
expression, but spatch adds the line without an escape (backslash).
x.c:
#define X(a) x(a);
(I know the above is not technically correct but it's super common.)
x.cocci:
@@
expression e;
@@
x(e);
+ y(e);
output:
$ spatch --sp-file x.cocci x.c
HANDLING: x.c
diff =
--- x.c
+++ /tmp/cocci-output-80658-7f90b1-x.c
@@ -1 +1,2 @@
#define X(a) x(a);
+y(a);
I can think of two solutions, if an expression is inside a
preprocessor statement: add a backslash before every newline, or skip
the newline.
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Cocci] Newline escape in preprocessor
2020-10-23 3:33 [Cocci] Newline escape in preprocessor Mansour Moufid
@ 2020-10-23 6:05 ` Julia Lawall
2020-10-23 15:00 ` [Cocci] Adjusting replacement lists with SmPL? Markus Elfring
1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2020-10-23 6:05 UTC (permalink / raw)
To: Mansour Moufid; +Cc: cocci
On Thu, 22 Oct 2020, Mansour Moufid wrote:
> Hi,
>
> I'd like to add a statement after another within a preprocessor
> expression, but spatch adds the line without an escape (backslash).
>
> x.c:
>
> #define X(a) x(a);
>
> (I know the above is not technically correct but it's super common.)
>
> x.cocci:
>
> @@
> expression e;
> @@
> x(e);
> + y(e);
>
> output:
>
> $ spatch --sp-file x.cocci x.c
> HANDLING: x.c
> diff =
> --- x.c
> +++ /tmp/cocci-output-80658-7f90b1-x.c
> @@ -1 +1,2 @@
> #define X(a) x(a);
> +y(a);
>
> I can think of two solutions, if an expression is inside a
> preprocessor statement: add a backslash before every newline, or skip
> the newline.
Indeed Coccinelle is not aware that the added code is within a #define.
Maybe it is easy to add that.
Thanks for the report.
julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Cocci] Adjusting replacement lists with SmPL?
2020-10-23 3:33 [Cocci] Newline escape in preprocessor Mansour Moufid
2020-10-23 6:05 ` Julia Lawall
@ 2020-10-23 15:00 ` Markus Elfring
2020-10-23 15:11 ` Julia Lawall
1 sibling, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2020-10-23 15:00 UTC (permalink / raw)
To: Mansour Moufid; +Cc: cocci
> I'd like to add a statement after another within a preprocessor expression,
How do you think about to refer to a “#define directive”?
> but spatch adds the line without an escape (backslash).
I imagine that we stumble on another target conflict here.
https://github.com/coccinelle/coccinelle/issues/139
Do you really want to adjust a bit of text according to a preprocessing definition?
> #define X(a) x(a);
>
> (I know the above is not technically correct but it's super common.)
I stumble on understanding difficulties for this information.
Would you like to clarify the knowledge about correctness a bit more?
> @@
> expression e;
> @@
> x(e);
> + y(e);
How should the scope be specified that a change should be performed
only for preprocessor code (replacement lists for your transformation approach)?
> I can think of two solutions, if an expression is inside a
> preprocessor statement: add a backslash before every newline, or skip
> the newline.
Would you like to choose the preferred coding style for such an use case?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Cocci] Adjusting replacement lists with SmPL?
2020-10-23 15:00 ` [Cocci] Adjusting replacement lists with SmPL? Markus Elfring
@ 2020-10-23 15:11 ` Julia Lawall
2020-10-25 2:04 ` Mansour Moufid
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2020-10-23 15:11 UTC (permalink / raw)
To: Markus Elfring; +Cc: cocci
[-- Attachment #1: Type: text/plain, Size: 1629 bytes --]
On Fri, 23 Oct 2020, Markus Elfring wrote:
> > I'd like to add a statement after another within a preprocessor expression,
> >
> > How do you think about to refer to a “#define directive”?
> >
> >
> > > but spatch adds the line without an escape (backslash).
> >
> > I imagine that we stumble on another target conflict here.
> > https://github.com/coccinelle/coccinelle/issues/139
> >
> > Do you really want to adjust a bit of text according to a preprocessing
> > definition?
> >
> >
> > > #define X(a) x(a);
> > >
> > > (I know the above is not technically correct but it's super common.)
> >
> > I stumble on understanding difficulties for this information.
> > Would you like to clarify the knowledge about correctness a bit more?
> >
> >
> > > @@
> > > expression e;
> > > @@
> > > x(e);
> > > + y(e);
> >
> > How should the scope be specified that a change should be performed
> > only for preprocessor code (replacement lists for your transformation
> > approach)?
I don't think he is asking that. He means, if the call to x happens to be
in a macro definition, how can he ensure that the transformed code treats
newlines in the right way.
julia
> >
> >
> > > I can think of two solutions, if an expression is inside a
> > > preprocessor statement: add a backslash before every newline, or skip
> > > the newline.
> >
> > Would you like to choose the preferred coding style for such an use case?
> >
> > Regards,
> > Markus
> > _______________________________________________
> > Cocci mailing list
> > Cocci@systeme.lip6.fr
> > https://systeme.lip6.fr/mailman/listinfo/cocci
> >
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Cocci] Adjusting replacement lists with SmPL?
2020-10-23 15:11 ` Julia Lawall
@ 2020-10-25 2:04 ` Mansour Moufid
0 siblings, 0 replies; 5+ messages in thread
From: Mansour Moufid @ 2020-10-25 2:04 UTC (permalink / raw)
To: cocci
On Fri, Oct 23, 2020 at 11:00 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > I'd like to add a statement after another within a preprocessor expression,
>
> How do you think about to refer to a “#define directive”?
I mean, not specifically in the #define, but anywhere.
(I don't try to patch preprocessor directives with spatch, I use sed for that.)
> > #define X(a) x(a);
> >
> > (I know the above is not technically correct but it's super common.)
>
> I stumble on understanding difficulties for this information.
> Would you like to clarify the knowledge about correctness a bit more?
A trailing colon in a #define leads to code like this:
{
X(1)
X(2)
...
}
... which of course does not parse. It would be better to use a do {
... } while (0), or better yet an inline function. But unfortunately
the above style is very common.
On Fri, Oct 23, 2020 at 11:11 AM Julia Lawall <julia.lawall@inria.fr> wrote:
> I don't think he is asking that. He means, if the call to x happens to be
> in a macro definition, how can he ensure that the transformed code treats
> newlines in the right way.
Yes, exactly. :)
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-10-25 2:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 3:33 [Cocci] Newline escape in preprocessor Mansour Moufid
2020-10-23 6:05 ` Julia Lawall
2020-10-23 15:00 ` [Cocci] Adjusting replacement lists with SmPL? Markus Elfring
2020-10-23 15:11 ` Julia Lawall
2020-10-25 2:04 ` Mansour Moufid
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).