Reducing parentheses (with SmPL)?
Hello,
Some information is provided also according to the question “How to remove useless parentheses?” in the documentation of the semantic patch language.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/2548098a0c8b148555f4bf11a12898ecaf023dea/docs/manual/tips.tex#L6-41
Another corresponding file contains a todo tag.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/2548098a0c8b148555f4bf11a12898ecaf023dea/standard.iso#L382-397
It seems that some conditions should be reconsidered.
I would occasionally like to capture detailed expression code by metavariables. I am unsure about the properties of the found expressions which should be reused somehow. Thus I would tend to enclose such data by extra parentheses.
A manual inspection would indicate then for an adjusted code place that this addition would occasionally be redundant.
Can this aspect be better supported automatically?
Regards,
Markus
Quoted 6 lines · Markus Elfring
Hello,
Some information is provided also according to the question “How to remove useless parentheses?” in the documentation of the semantic patch language.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/2548098a0c8b148555f4bf11a12898ecaf023dea/docs/manual/tips.tex#L6-41
Quoted 6 lines
Another corresponding file contains a todo tag.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/2548098a0c8b148555f4bf11a12898ecaf023dea/standard.iso#L382-397It seems that some conditions should be reconsidered.
I would occasionally like to capture detailed expression code by metavariables.
What conditions? What detailed expression code? It is not possible to understand this without more information.
julia
Quoted 9 lines
I am unsure about the properties of the found expressions which should be reused somehow. Thus I would tend to enclose such data by extra parentheses.
A manual inspection would indicate then for an adjusted code place that this addition would occasionally be redundant.
Can this aspect be better supported automatically?Regards,
Markus
Quoted 2 lines
Quoted 2 lines
Another corresponding file contains a todo tag.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/2548098a0c8b148555f4bf11a12898ecaf023dea/standard.iso#L382-397
How do you think about to discuss corresponding imaginations?
Quoted 5 lines
Quoted 3 lines
It seems that some conditions should be reconsidered.
I would occasionally like to capture detailed expression code by metavariables.
What conditions?
I came also along recurring development concerns according to selected source code transformations.
Quoted 1 line
What detailed expression code?
The complexity can vary for found expressions, can't it?
Quoted 2 lines
It is not possible to
understand this without more information.
…>> I am unsure about the properties of the found expressions which should be reused somehow.
Quoted 4 lines
Quoted 4 lines
Thus I would tend to enclose such data by extra parentheses.
A manual inspection would indicate then for an adjusted code place that this addition would occasionally be redundant.
Can this aspect be better supported automatically?
Will any information from this clarification approach get more attention?
Regards,
Markus
Quoted 4 lines · Markus Elfring
Quoted 2 lines
Quoted 2 lines
Another corresponding file contains a todo tag.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/2548098a0c8b148555f4bf11a12898ecaf023dea/standard.iso#L382-397How do you think about to discuss corresponding imaginations?
Te TODO has to do with sizeof. Why is it relevant to the general problem of reducing parentheses?
It's not clear whether you want to reduch parentheses in the semantic patch (the only thing that is affected by an isomorphism) or in the C code.
julia
Quoted 30 lines
Quoted 7 lines
Quoted 5 lines
It seems that some conditions should be reconsidered.
I would occasionally like to capture detailed expression code by metavariables.
What conditions?
I came also along recurring development concerns according to selected source code transformations.
Quoted 1 line
What detailed expression code?
The complexity can vary for found expressions, can't it?
Quoted 2 lines
It is not possible to
understand this without more information.…>> I am unsure about the properties of the found expressions which should be reused somehow.
Quoted 4 lines
Quoted 4 lines
Thus I would tend to enclose such data by extra parentheses.
A manual inspection would indicate then for an adjusted code place that this addition would occasionally be redundant.
Can this aspect be better supported automatically?Will any information from this clarification approach get more attention?
Regards,
Markus
Quoted 2 lines
It's not clear whether you want to reduch parentheses in the semantic patch (the only thing that is affected by an isomorphism) or in the C code.
I imagine that expression properties should be taken better into account for both application domains.
How may an expression look like so that parentheses can be omitted?
Regards,
Markus
Quoted 2 lines
It's not clear whether you want to reduch parentheses in the semantic patch (the only thing that is affected by an isomorphism) or in the C code.
We got used to the order of operations to some degree.
https://en.wikipedia.org/wiki/Order_of_operations
https://en.cppreference.com/w/c/language/value_category.html
How will the support evolve further for safe transformations of expressions?
The entity “expression” is supported by the semantic patch language in a limited way so far.
It is mapped to a single metavariable type. Metavariables matter at different places.
* They can match some source code from context (or minus slice) specifications.
* Metavariable contents can be reused for plus slice specifications. Desirable source code adjustments should be “expressed” here. Which control can we get on the advanced handling of parentheses then?
Regards,
Markus
Quoted 15 lines · Markus Elfring
Quoted 2 lines
It's not clear whether you want to reduch parentheses in the semantic patch (the only thing that is affected by an isomorphism) or in the C code.
We got used to the order of operations to some degree.
https://en.wikipedia.org/wiki/Order_of_operations
https://en.cppreference.com/w/c/language/value_category.htmlHow will the support evolve further for safe transformations of expressions?
The entity “expression” is supported by the semantic patch language in a limited way so far.
It is mapped to a single metavariable type. Metavariables matter at different places.
Quoted 5 lines
* They can match some source code from context (or minus slice) specifications.
* Metavariable contents can be reused for plus slice specifications. Desirable source code adjustments should be “expressed” here. Which control can we get on the advanced handling of parentheses then?
I have no idea what you are trying to do, and you are never going to succeed with your strange way of expressing yourself. If you want to know how to do something, please provide a concrete and minimal example of C code and show what you would like it to be transformed into. That is the only thing I can precisely understand.
julia
Quoted 5 lines
Quoted 3 lines
* Metavariable contents can be reused for plus slice specifications. Desirable source code adjustments should be “expressed” here. Which control can we get on the advanced handling of parentheses then?
I have no idea what you are trying to do,
I find such feedback strange.
Quoted 2 lines
and you are never going to
succeed with your strange way of expressing yourself.
I hope still that remaining communication difficulties can be resolved better.
Quoted 4 lines
If you want to know
how to do something, please provide a concrete and minimal example of C code and show what you would like it to be transformed into. That is the only thing I can precisely understand.
Your public activities seem to indicate that you are capable for more.
* We would occasionally like to transform selected expressions (which were captured by instances of the metavariable type “expression”), don't we?
* Do we care then if it would be needed to specify extra parentheses (or not) for plus slice specifications?
Regards,
Markus
Quoted 20 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
* Metavariable contents can be reused for plus slice specifications. Desirable source code adjustments should be “expressed” here. Which control can we get on the advanced handling of parentheses then?
I have no idea what you are trying to do,
I find such feedback strange.
Quoted 2 lines
and you are never going to
succeed with your strange way of expressing yourself.I hope still that remaining communication difficulties can be resolved better.
Quoted 4 lines
If you want to know
how to do something, please provide a concrete and minimal example of C code and show what you would like it to be transformed into. That is the only thing I can precisely understand.
Quoted 5 lines
Your public activities seem to indicate that you are capable for more.
* We would occasionally like to transform selected expressions (which were captured by instances of the metavariable type “expression”), don't we?
Yes.
Quoted 2 lines
* Do we care then if it would be needed to specify extra parentheses (or not) for plus slice specifications?
No.
julia
Quoted 4 lines
Quoted 3 lines
* We would occasionally like to transform selected expressions (which were captured by instances of the metavariable type “expression”), don't we?
Yes.
Thanks for an agreement on this use case.
Quoted 3 lines
Quoted 2 lines
* Do we care then if it would be needed to specify extra parentheses (or not) for plus slice specifications?
No.
I interpret this feedback in the way that it indicates another communication difficulty.
I am trying to develop adjustments that are consistent and modify source code places in a minimal and required way.
I find the influence of the data handling for parentheses important somehow.
Regards,
Markus
Quoted 10 lines · Markus Elfring
Quoted 4 lines
Quoted 3 lines
* We would occasionally like to transform selected expressions (which were captured by instances of the metavariable type “expression”), don't we?
Yes.
Thanks for an agreement on this use case.
Quoted 2 lines
Quoted 2 lines
* Do we care then if it would be needed to specify extra parentheses (or not) for plus slice specifications?
Quoted 7 lines
Quoted 1 line
No.
I interpret this feedback in the way that it indicates another communication difficulty.
I am trying to develop adjustments that are consistent and modify source code places in a minimal and required way.
I find the influence of the data handling for parentheses important somehow.
If you have some concrete problems please provide those concrete problems rather than vague descriptions.
julia
Quoted 5 lines
Quoted 3 lines
I am trying to develop adjustments that are consistent and modify source code places in a minimal and required way.
I find the influence of the data handling for parentheses important somehow.If you have some concrete problems please provide those concrete problems rather than vague descriptions.
Would you find it really easier to clarify known data processing challenges with the help of another SmPL script example?
@display@
expression e;
statement x, y;
@@
if (
* e
)
x else
y
Regards,
Markus
Quoted 8 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
I am trying to develop adjustments that are consistent and modify source code places in a minimal and required way.
I find the influence of the data handling for parentheses important somehow.If you have some concrete problems please provide those concrete problems rather than vague descriptions.
Would you find it really easier to clarify known data processing challenges with the help of another SmPL script example?
I at least understand th script. But I don't kjnow what problem does it raise?
julia
Quoted 17 lines
@display@
expression e;
statement x, y;
@@
if (
* e) xelse
yRegards,
Markus
Quoted 3 lines
Quoted 2 lines
Would you find it really easier to clarify known data processing challenges with the help of another SmPL script example?
I at least understand th script. But I don't kjnow what problem does it raise?
…>> @display@
Quoted 9 lines
Quoted 9 lines
expression e;
statement x, y;
@@
if (
* e) xelse
y
Repetition:
Would we occasionally like to put the found expression as a subitem into another SmPL plus slice specification?
Will additional parentheses become relevant then (or not)?
Regards,
Markus
Quoted 14 lines · Markus Elfring
Quoted 3 lines
Quoted 2 lines
Would you find it really easier to clarify known data processing challenges with the help of another SmPL script example?
I at least understand th script. But I don't kjnow what problem does it raise?
…>> @display@
Quoted 9 lines
Quoted 9 lines
expression e;
statement x, y;
@@
if (
* e) xelse
y
Quoted 3 lines
Repetition:
Would we occasionally like to put the found expression as a subitem into another SmPL plus slice specification?
I don't know what we would occasionally like to do. I don't know what specific plus slice specification you are referring to. Precedence with respect to arithmetic operators is handled. If you have some other concern in mind please make a concrete example that shows the problem. I can't guess what you think someone might occasionally like to do.
Quoted 1 line
Will additional parentheses become relevant then (or not)?
How about actually trying something and seeing what is the result?
julia
Quoted 3 lines
Quoted 2 lines
Would we occasionally like to put the found expression as a subitem into another SmPL plus slice specification?
I don't know what we would occasionally like to do.
Some SmPL script developers (and users) would like to recombine expressions, don't they?
Quoted 2 lines
I don't know what
specific plus slice specification you are referring to.
You are familiar with data processing attempts which can be expected there.
Quoted 2 lines
Precedence with
respect to arithmetic operators is handled.
Such information belongs to knowledge for expression properties, doesn't it?
Quoted 2 lines
If you have some other
concern in mind please make a concrete example that shows the problem.
I got the impression that I see another need for the extension of supported metavariable types.
Quoted 2 lines
Quoted 1 line
Will additional parentheses become relevant then (or not)?
How about actually trying something and seeing what is the result?
Corresponding software tests happened to some degree.
I am unsure about the circumstances when the problem awareness and development resources will fit together better.
Regards,
Markus
Quoted 3 lines
Quoted 2 lines
Would you find it really easier to clarify known data processing challenges with the help of another SmPL script example?
I at least understand th script. But I don't kjnow what problem does it raise?
Can you recognise development concerns better from another SmPL code variant?
@adjustment@
expression e;
statement s;
@@
-if
+my_result =
(e)
+&& true;
- s
Regards,
Markus
Quoted 11 lines · Markus Elfring
Quoted 3 lines
Quoted 2 lines
Would you find it really easier to clarify known data processing challenges with the help of another SmPL script example?
I at least understand th script. But I don't kjnow what problem does it raise?
Can you recognise development concerns better from another SmPL code variant?
@adjustment@
expression e;
statement s;
@@
Review
Quoted 5 lines
(quoted diff) +2
-2-if +my_result = (e) +&& true; - s
And what is the problem?
If you don't want the parentheses around e, then remove them.
julai
Quoted 13 lines
Review
Quoted 12 lines
Can you recognise development concerns better from another SmPL code variant?
@adjustment@
expression e;
statement s;
@@(quoted diff) +2
-2-if +my_result = (e) +&& true; - sAnd what is the problem?
I would expect that further checks are needed for the determination if remaining parentheses can be redundant.
I find the knowledge that is encapsulated by the metavariable type “expression” incomplete so far.
Quoted 1 line
If you don't want the parentheses around e, then remove them.
How would you determine if extra parentheses are actually required for a part of a recombined expression?
Regards,
Markus
Quoted 20 lines · Markus Elfring
Quoted 13 lines
Review
Quoted 12 lines
Can you recognise development concerns better from another SmPL code variant?
@adjustment@
expression e;
statement s;
@@(quoted diff) +2
-2-if +my_result = (e) +&& true; - sAnd what is the problem?
I would expect that further checks are needed for the determination if remaining parentheses can be redundant.
I find the knowledge that is encapsulated by the metavariable type “expression” incomplete so far.
Quoted 4 lines
Quoted 1 line
If you don't want the parentheses around e, then remove them.
How would you determine if extra parentheses are actually required for a part of a recombined expression?
The pretty printer looks at the context to some extent. If you have a concrete example that illustrates a problem, please provide it. If not, please end this discussion.
julia
Quoted 3 lines
Quoted 2 lines
How would you determine if extra parentheses are actually required for a part of a recombined expression?
The pretty printer looks at the context to some extent.
Would you like to document any special software behaviour accordingly?
Quoted 2 lines
If you have a
concrete example that illustrates a problem, please provide it.
I hope still that the attention can grow also for the avoidance of superfluous parentheses.
Can another information source become more interesting for such implementation details?
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es41-if-in-doubt-about-operator-precedence-parenthesize
Regards,
Markus
Quoted 4 lines
Quoted 2 lines
How would you determine if extra parentheses are actually required for a part of a recombined expression?
The pretty printer looks at the context to some extent. If you have a concrete example that illustrates a problem, please provide it.
Would you dare to acknowledge consequences from (temporary) software limitations also for the discussed use case?
Regards,
Markus
Quoted 13 lines
Review
Quoted 12 lines
Can you recognise development concerns better from another SmPL code variant?
@adjustment@
expression e;
statement s;
@@(quoted diff) +2
-2-if +my_result = (e) +&& true; - sAnd what is the problem?
It is supported (to some degree by the means of the semantic patch language) to construct expressions for the usage within SmPL plus slice specifications. Developers can generally apply the design choice to use additional parentheses then.
Some properties might be even unknown so far according to metavariable instances of the type “expression”.
Programming interfaces can be extended accordingly.
Quoted 1 line
If you don't want the parentheses around e, then remove them.
There is a desire to avoid extra parentheses in the generated diff output. If such difference displays should be accepted as patches for known code bases, it would probably be more helpful if they could adhere better to coding style preferences.
Regards,
Markus
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines
Quoted 4 lines
There is a desire to avoid extra parentheses in the generated diff output. If such difference displays should be accepted as patches for known code bases, it would probably be more helpful if they could adhere better to coding style preferences.
You have sent like 20 messages about this.
Some communication is obviously needed to achieve a better common understanding for the presented topic.
Quoted 2 lines
How about one single concrete
example where the output is not what you hoped for???
Another SmPL script example:
@replacement@
expression condition, context, x, y;
identifier action;
@@
-if (condition)
- { action(context, x); }
-else
- { action(context, y); }
+action(context, (condition) ? (x) : (y));
Questionable test result (by the software combination “Coccinelle 1.3.0” for example):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> git checkout next-20250722 && time /usr/bin/spatch …/Projekte/Coccinelle/Probe/use_selected_call_with_ternary_operator-20250722.cocci fs/xfs/scrub/findparent.c …
@@ -229,11 +229,8 @@ xrep_findparent_live_update(
…
+ xrep_findparent_scan_found(pscan,
+ (p->delta > 0) ? (p->dp->i_ino) : (NULLFSINO));
…
@@ -269,10 +266,8 @@ __xrep_findparent_scan_start(
…
+ xfs_dir_hook_setup(&pscan->dhook,
+ (custom_fn) ? (custom_fn) : (xrep_findparent_live_update));
…
real 0m0,322s user 0m0,138s sys 0m0,022s
Quoted 1 line
On the other hand, Coccinelle cannot guess what are your coding style preferences.
It would be nice if the pattern recognition could be improved another bit. But we tend to concentrate mostly on Linux source code variations so far.
Regards,
Markus
Quoted 34 lines · Markus Elfring
Quoted 5 lines
Quoted 4 lines
There is a desire to avoid extra parentheses in the generated diff output. If such difference displays should be accepted as patches for known code bases, it would probably be more helpful if they could adhere better to coding style preferences.
You have sent like 20 messages about this.
Some communication is obviously needed to achieve a better common understanding for the presented topic.
Quoted 2 lines
How about one single concrete
example where the output is not what you hoped for???Another SmPL script example:
@replacement@
expression condition, context, x, y;
identifier action;
@@(quoted diff) +1
-4-if (condition) - { action(context, x); } -else - { action(context, y); } +action(context, (condition) ? (x) : (y));Questionable test result (by the software combination “Coccinelle 1.3.0” for example):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> git checkout next-20250722 && time/usr/bin/spatch…/Projekte/Coccinelle/Probe/use_selected_call_with_ternary_operator-20250722.coccifs/xfs/scrub/findparent.c…(quoted diff) +2
-0@@ -229,11 +229,8 @@ xrep_findparent_live_update( + xrep_findparent_scan_found(pscan, + (p->delta > 0) ? (p->dp->i_ino) : (NULLFSINO));
Review __xrep_findparent_scan_start(
Quoted 4 lines
(quoted diff) +2
-0@@ -269,10 +266,8 @@ __xrep_findparent_scan_start( + xfs_dir_hook_setup(&pscan->dhook, + (custom_fn) ? (custom_fn) : (xrep_findparent_live_update));
Why is it a surprise to see the () if you put the ()?
julia
Quoted 15 lines
real 0m0,322s user 0m0,138s sys 0m0,022sQuoted 1 line
On the other hand, Coccinelle cannot guess what are your coding style preferences.
It would be nice if the pattern recognition could be improved another bit. But we tend to concentrate mostly on Linux source code variations so far.
Regards,
Markus
Quoted 12 lines
Quoted 12 lines
Another SmPL script example:
@replacement@
expression condition, context, x, y;
identifier action;
@@(quoted diff) +1
-4-if (condition) - { action(context, x); } -else - { action(context, y); } +action(context, (condition) ? (x) : (y));
Quoted 15 lines
Review __xrep_findparent_scan_start(
Quoted 13 lines
Questionable test result (by the software combination “Coccinelle 1.3.0” for example):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> git checkout next-20250722 && time/usr/bin/spatch…/Projekte/Coccinelle/Probe/use_selected_call_with_ternary_operator-20250722.coccifs/xfs/scrub/findparent.c…(quoted diff) +4
-0@@ -229,11 +229,8 @@ xrep_findparent_live_update( + xrep_findparent_scan_found(pscan, + (p->delta > 0) ? (p->dp->i_ino) : (NULLFSINO));@@ -269,10 +266,8 @@ __xrep_findparent_scan_start( + xfs_dir_hook_setup(&pscan->dhook, + (custom_fn) ? (custom_fn) : (xrep_findparent_live_update));Why is it a surprise to see the () if you put the ()?
Am I forced to specify additional parentheses for the desired source code transformation pattern because I can not know so far if the found expressions would really fit into the recombined expressions?
Should pretty-printing approaches take care of corresponding format adjustments?
Regards,
Markus