Using SmPL scripts to mangle function arguments
Quoted 2 lines
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?
Quoted 2 lines
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.
Quoted 5 lines
@@
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
Quoted 4 lines
+
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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 11 lines
Quoted 5 lines
@@
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
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 3 lines · Markus Elfring
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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 3 lines
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.
Quoted 9 lines
Here's what I have so far:
@@
expression L, F;
@@-
func_old(L, F, ...);
+func_old(__func_, ...);
Quoted 8 lines
... 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.
Quoted 1 line
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
Quoted 2 lines
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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 33 lines · Thomas Adam
Quoted 3 lines · Markus Elfring
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 likefunc_oldto 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:
Quoted 6 lines
@@
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
Quoted 13 lines
... 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.
Quoted 6 lines
-- Thomas
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 1 line
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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci