All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Cocci] Using SmPL scripts to mangle function arguments
@ 2020-05-17  9:22 Markus Elfring
  2020-05-17  9:45 ` Julia Lawall
  2020-05-26  1:21 ` Thomas Adam
  0 siblings, 2 replies; 7+ messages in thread
From: Markus Elfring @ 2020-05-17  9:22 UTC (permalink / raw)
  To: Thomas Adam; +Cc: cocci

> Hence, func_new() reduces the number of arguments to just one
> -- a format string, and variadic arguments.

* Does this wording contain a contradiction?

* Would you like to fiddle with any more variadic functions?


> My question is how would I go about trying to get coccinelle to help me
> translate this?  Is this even possible?

Generally, yes.

A more complete source code transformation approach can become challenging.


> @@
> expression O1, O2, O3
> @@
>
> - func_old(O1, O2, O3, ...);

Can it be that the item “charstring” would contain multiple expressions?

If you would like to reuse the last function parameters,
the passed code should be stored into corresponding metavariables
of a type like “constant” or “expression list”.
https://github.com/coccinelle/coccinelle/blob/7cf2c23e64066d5249a64a316cc5347831f7a63f/docs/manual/cocci_syntax.tex#L199


> + func_new("%s: ...", __func__, O3);
>
> I suspect I might be stretching coccinelle's abilities in trying to craft
> new parameters, but I thought I'd ask.

I imagine that the clarification of corresponding application details
can become more interesting.

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Using SmPL scripts to mangle function arguments
  2020-05-17  9:22 [Cocci] Using SmPL scripts to mangle function arguments Markus Elfring
@ 2020-05-17  9:45 ` Julia Lawall
  2020-05-26  1:21 ` Thomas Adam
  1 sibling, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2020-05-17  9:45 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 493 bytes --]

> > @@
> > expression O1, O2, O3
> > @@
> >
> > - func_old(O1, O2, O3, ...);
>
> Can it be that the item “charstring” would contain multiple expressions?
>
> If you would like to reuse the last function parameters,
> the passed code should be stored into corresponding metavariables
> of a type like “constant” or “expression list”.


Making O3 an expression list could be useful.  Or you can just put the
part that doesn't change on a shared line with no - or + annotation.

julia

[-- 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] 7+ messages in thread

* Re: [Cocci] Using SmPL scripts to mangle function arguments
  2020-05-17  9:22 [Cocci] Using SmPL scripts to mangle function arguments Markus Elfring
  2020-05-17  9:45 ` Julia Lawall
@ 2020-05-26  1:21 ` Thomas Adam
  2020-05-26  6:00   ` Markus Elfring
                     ` (2 more replies)
  1 sibling, 3 replies; 7+ messages in thread
From: Thomas Adam @ 2020-05-26  1:21 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

On Sun, 17 May 2020 at 10:22, Markus Elfring <Markus.Elfring@web.de> wrote:
> Generally, yes.
>
> A more complete source code transformation approach can become challenging.

So I've decided to try and take a different approach, and have
rethrough the function interface.

Rather than try and modify the arguments in the way I was, I think it
makes sense to largely keep the existing function signatures.

So for example, currently there is:

func_old(int level, const char *func, const char *fmt, ...);

What I'm after here is to modify func_old, such that I drop the "int
level" parameter, and change the *func occurrences to "__func__", and
drag the variadic arguments with the transformation, hence, I'd like
func_old to now look like:

func_old(const char *func, const char *fmt, ...);

So what was once:

func_old(ERR, "MyFunction", "%s: hello: %d, %d", myvar, x, y);

Should now be:

func_old(__func__,  "%s: hello: %d, %d", myvar, x, y);

I'm having trouble expressing my smPL to understand the ellipses
correctly.  Here's what I have so far:

@@
expression L, F;
@@

- func_old(L, F, ...);
+ func_old(__func_, ...);

... but here, things fall apart:

init_defs_builtins: /usr/bin/../lib/coccinelle/standard.h
File "contrib/coccinelle/remove_debug.cocci", line 6, column 21, charpos = 68
  around = '...',
  whole content = + func_old(__func__, ...);

Any ideas on what I'm doing wrong?  If there's appropriate
documentation on this, please feel free to point me toward it.  I feel
as though I'm missing something obvious here, so thanks for your time
and for any help you can give.

-- Thomas
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Using SmPL scripts to mangle function arguments
  2020-05-26  1:21 ` Thomas Adam
@ 2020-05-26  6:00   ` Markus Elfring
  2020-05-26  6:41   ` Julia Lawall
  2020-05-27 14:21   ` Markus Elfring
  2 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-05-26  6:00 UTC (permalink / raw)
  To: Thomas Adam; +Cc: Coccinelle

> func_old(__func__,  "%s: hello: %d, %d", myvar, x, y);
>
> I'm having trouble expressing my smPL to understand the ellipses correctly.

This can be usual.


> Here's what I have so far:
>
> @@
> expression L, F;
> @@
>
> - func_old(L, F, ...);
> + func_old(__func_, ...);
>
> ... but here, things fall apart:
>
> init_defs_builtins: /usr/bin/../lib/coccinelle/standard.h
> File "contrib/coccinelle/remove_debug.cocci", line 6, column 21, charpos = 68
>   around = '...',
>   whole content = + func_old(__func__, ...);
>
> Any ideas on what I'm doing wrong?

Yes.

I hope also that some error messages from the Coccinelle software can become
more helpful.


> If there's appropriate documentation on this, please feel free to point me toward it.

How do you find the available descriptions in the section “4.1  Basic dots”?
http://coccinelle.lip6.fr/docs/main_grammar004.html#sec6


> I feel as though I'm missing something obvious here, so thanks for your time
> and for any help you can give.

The SmPL ellipsis refers to variable and unknown source code.
You tried a simple change specification out which expresses that a specific
function call should be adjusted in the same line.
But how can anything be readded when the content is unknown?

I suggest to increase the precision for the known change aspects like the following.

@replacement@
expression L, F;
@@
-func_old
+current_func
         (
-         L, F
+         __func__
          , ...
         )


Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Using SmPL scripts to mangle function arguments
  2020-05-26  1:21 ` Thomas Adam
  2020-05-26  6:00   ` Markus Elfring
@ 2020-05-26  6:41   ` Julia Lawall
  2020-05-27 14:21   ` Markus Elfring
  2 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2020-05-26  6:41 UTC (permalink / raw)
  To: Thomas Adam; +Cc: Coccinelle



On Tue, 26 May 2020, Thomas Adam wrote:

> On Sun, 17 May 2020 at 10:22, Markus Elfring <Markus.Elfring@web.de> wrote:
> > Generally, yes.
> >
> > A more complete source code transformation approach can become challenging.
>
> So I've decided to try and take a different approach, and have
> rethrough the function interface.
>
> Rather than try and modify the arguments in the way I was, I think it
> makes sense to largely keep the existing function signatures.
>
> So for example, currently there is:
>
> func_old(int level, const char *func, const char *fmt, ...);
>
> What I'm after here is to modify func_old, such that I drop the "int
> level" parameter, and change the *func occurrences to "__func__", and
> drag the variadic arguments with the transformation, hence, I'd like
> func_old to now look like:
>
> func_old(const char *func, const char *fmt, ...);
>
> So what was once:
>
> func_old(ERR, "MyFunction", "%s: hello: %d, %d", myvar, x, y);
>
> Should now be:
>
> func_old(__func__,  "%s: hello: %d, %d", myvar, x, y);
>
> I'm having trouble expressing my smPL to understand the ellipses
> correctly.  Here's what I have so far:
>
> @@
> expression L, F;
> @@
>
> - func_old(L, F, ...);
> + func_old(__func_, ...);


You can't add ...  Coccinelle has no idea what it refers to.  You can just
put:

func_old(
- L,F
+ __func__
  ,...)

julia

>
> ... but here, things fall apart:
>
> init_defs_builtins: /usr/bin/../lib/coccinelle/standard.h
> File "contrib/coccinelle/remove_debug.cocci", line 6, column 21, charpos = 68
>   around = '...',
>   whole content = + func_old(__func__, ...);
>
> Any ideas on what I'm doing wrong?  If there's appropriate
> documentation on this, please feel free to point me toward it.  I feel
> as though I'm missing something obvious here, so thanks for your time
> and for any help you can give.
>
> -- Thomas
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Using SmPL scripts to mangle function arguments
  2020-05-26  1:21 ` Thomas Adam
  2020-05-26  6:00   ` Markus Elfring
  2020-05-26  6:41   ` Julia Lawall
@ 2020-05-27 14:21   ` Markus Elfring
  2 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-05-27 14:21 UTC (permalink / raw)
  To: Thomas Adam; +Cc: Coccinelle

> I'm having trouble expressing my smPL to understand the ellipses correctly.

I am curious how the application of scripts for the semantic patch language
will grow according to your software development needs.
https://github.com/fvwmorg/fvwm3/blob/4a639a8648f4f6a2a6273a827f2299c6cccaf30c/contrib/coccinelle/remove_debug.cocci

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Using SmPL scripts to mangle function arguments
@ 2020-05-26 11:23 Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-05-26 11:23 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

> > @@
> > expression L, F;
> > @@
> >
> > - func_old(L, F, ...);
> > + func_old(__func_, ...);
>
> You can't add ...  Coccinelle has no idea what it refers to.

The software knows something about the involved source code.
This knowledge can be applied according to the functionality
of the SmPL ellipsis for deletions already.
The situation is different for code additions so far.
I am curious if this detail will eventually change somehow.

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2020-05-27 14:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-17  9:22 [Cocci] Using SmPL scripts to mangle function arguments Markus Elfring
2020-05-17  9:45 ` Julia Lawall
2020-05-26  1:21 ` Thomas Adam
2020-05-26  6:00   ` Markus Elfring
2020-05-26  6:41   ` Julia Lawall
2020-05-27 14:21   ` Markus Elfring
2020-05-26 11:23 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.