All of lore.kernel.org
 help / color / mirror / Atom feed
* [cocci] Checking a transformation approach for the avoidance of duplicate code
@ 2023-09-02 17:55 Markus Elfring
  2023-09-02 18:08 ` Julia Lawall
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2023-09-02 17:55 UTC (permalink / raw)
  To: cocci; +Cc: Thomas Adam

Hello,

The analysis tool “Cppcheck 2.10.3-3.2” pointed a source code place out
for further development considerations.

https://github.com/fvwmorg/fvwm3/blob/c9d00184ac3ab534e0f0ba5683106879a35857f6/fvwm/colorset.c#L965

(style) Condition 'tint==NULL' is always true [knownConditionTrueFalse]

See also a change suggestion:
Simplify data processing for tint colour in parse_colorset()
https://github.com/fvwmorg/fvwm3/issues/897


I constructed another SmPL script variant for a desirable transformation.


@replacement@
statement s1, s2, s3;
@@
-if (tint != NULL)
-{
- s1
- s2
- cs->tint = GetColor(tint);
- s3
-}
-else if (tint == NULL)
-{
- s1
- s2
- cs->tint = GetColor(black);
- s3
-}
+s1
+s2
+cs->tint = GetColor(tint ? tint : black);
+s3


Now I wonder why a corresponding patch is not generated by the software
“Coccinelle 1.1.1-00478-g0afff7fa” (OCaml 5.0) at the moment.
I would appreciate further advices.

Regards,
Markus

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

* Re: [cocci] Checking a transformation approach for the avoidance of duplicate code
  2023-09-02 17:55 [cocci] Checking a transformation approach for the avoidance of duplicate code Markus Elfring
@ 2023-09-02 18:08 ` Julia Lawall
  2023-09-02 18:25   ` Markus Elfring
  0 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2023-09-02 18:08 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci, Thomas Adam

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



On Sat, 2 Sep 2023, Markus Elfring wrote:

> Hello,
>
> The analysis tool “Cppcheck 2.10.3-3.2” pointed a source code place out
> for further development considerations.
>
> https://github.com/fvwmorg/fvwm3/blob/c9d00184ac3ab534e0f0ba5683106879a35857f6/fvwm/colorset.c#L965
>
> (style) Condition 'tint==NULL' is always true [knownConditionTrueFalse]
>
> See also a change suggestion:
> Simplify data processing for tint colour in parse_colorset()
> https://github.com/fvwmorg/fvwm3/issues/897
>
>
> I constructed another SmPL script variant for a desirable transformation.
>
>
> @replacement@
> statement s1, s2, s3;
> @@
> -if (tint != NULL)
> -{
> - s1
> - s2
> - cs->tint = GetColor(tint);
> - s3
> -}
> -else if (tint == NULL)
> -{
> - s1
> - s2
> - cs->tint = GetColor(black);
> - s3
> -}
> +s1
> +s2
> +cs->tint = GetColor(tint ? tint : black);
> +s3
>
>
> Now I wonder why a corresponding patch is not generated by the software
> “Coccinelle 1.1.1-00478-g0afff7fa” (OCaml 5.0) at the moment.
> I would appreciate further advices.

Probably because in each branch, the first line is a declaration, not a
statement.

julia

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

* Re: [cocci] Checking a transformation approach for the avoidance of duplicate code
  2023-09-02 18:08 ` Julia Lawall
@ 2023-09-02 18:25   ` Markus Elfring
  2023-09-02 18:33     ` Julia Lawall
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2023-09-02 18:25 UTC (permalink / raw)
  To: Julia Lawall, cocci; +Cc: Thomas Adam

>> I constructed another SmPL script variant for a desirable transformation.
>>
>>
>> @replacement@
>> statement s1, s2, s3;
>> @@
>> -if (tint != NULL)
>> -{
>> - s1
>> - s2
>> - cs->tint = GetColor(tint);
>> - s3
>> -}
>> -else if (tint == NULL)
>> -{
>> - s1
>> - s2
>> - cs->tint = GetColor(black);
>> - s3
>> -}
>> +s1
>> +s2
>> +cs->tint = GetColor(tint ? tint : black);
>> +s3
>>
>>
>> Now I wonder why a corresponding patch is not generated by the software
>> “Coccinelle 1.1.1-00478-g0afff7fa” (OCaml 5.0) at the moment.
>> I would appreciate further advices.
>
> Probably because in each branch, the first line is a declaration, not a statement.

How does this feedback fit to other software documentation according to declaration statements?
https://en.cppreference.com/w/cpp/language/statements#Declaration_statements

Regards,
Markus

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

* Re: [cocci] Checking a transformation approach for the avoidance of duplicate code
  2023-09-02 18:25   ` Markus Elfring
@ 2023-09-02 18:33     ` Julia Lawall
  2023-09-02 18:42       ` Markus Elfring
  0 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2023-09-02 18:33 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci, Thomas Adam

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



On Sat, 2 Sep 2023, Markus Elfring wrote:

> >> I constructed another SmPL script variant for a desirable transformation.
> >>
> >>
> >> @replacement@
> >> statement s1, s2, s3;
> >> @@
> >> -if (tint != NULL)
> >> -{
> >> - s1
> >> - s2
> >> - cs->tint = GetColor(tint);
> >> - s3
> >> -}
> >> -else if (tint == NULL)
> >> -{
> >> - s1
> >> - s2
> >> - cs->tint = GetColor(black);
> >> - s3
> >> -}
> >> +s1
> >> +s2
> >> +cs->tint = GetColor(tint ? tint : black);
> >> +s3
> >>
> >>
> >> Now I wonder why a corresponding patch is not generated by the software
> >> “Coccinelle 1.1.1-00478-g0afff7fa” (OCaml 5.0) at the moment.
> >> I would appreciate further advices.
> >
> > Probably because in each branch, the first line is a declaration, not a statement.
>
> How does this feedback fit to other software documentation according to declaration statements?
> https://en.cppreference.com/w/cpp/language/statements#Declaration_statements

Whatever.  In Coccinelle, we decided to do it that way I said it is done.
This makes it easy to search for the first statement that is not a
declaration in a function.

julia

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

* Re: [cocci] Checking a transformation approach for the avoidance of duplicate code
  2023-09-02 18:33     ` Julia Lawall
@ 2023-09-02 18:42       ` Markus Elfring
  2023-09-02 19:01         ` Julia Lawall
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2023-09-02 18:42 UTC (permalink / raw)
  To: Julia Lawall, cocci; +Cc: Thomas Adam

>>>> Now I wonder why a corresponding patch is not generated by the software
>>>> “Coccinelle 1.1.1-00478-g0afff7fa” (OCaml 5.0) at the moment.
>>>> I would appreciate further advices.
>>>
>>> Probably because in each branch, the first line is a declaration, not a statement.
>>
>> How does this feedback fit to other software documentation according to declaration statements?
>> https://en.cppreference.com/w/cpp/language/statements#Declaration_statements
>
> Whatever.  In Coccinelle, we decided to do it that way I said it is done.
> This makes it easy to search for the first statement that is not a
> declaration in a function.

The following SmPL script variant does also not produce an expected patch
for the source file “fvwm/colorset.c”.

@replacement@
declaration d;
statement s1, s2;
@@
-if (tint != NULL)
-{
- d
- s1
- cs->tint = GetColor(tint);
- s2
-}
-else if (tint == NULL)
-{
- d
- s1
- cs->tint = GetColor(black);
- s2
-}
+d
+s1
+cs->tint = GetColor(tint ? tint : black);
+s2


Regards,
Markus

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

* Re: [cocci] Checking a transformation approach for the avoidance of duplicate code
  2023-09-02 18:42       ` Markus Elfring
@ 2023-09-02 19:01         ` Julia Lawall
  2023-09-03  6:40           ` Markus Elfring
  2023-09-03  7:56           ` Markus Elfring
  0 siblings, 2 replies; 12+ messages in thread
From: Julia Lawall @ 2023-09-02 19:01 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci, Thomas Adam

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



On Sat, 2 Sep 2023, Markus Elfring wrote:

> >>>> Now I wonder why a corresponding patch is not generated by the software
> >>>> “Coccinelle 1.1.1-00478-g0afff7fa” (OCaml 5.0) at the moment.
> >>>> I would appreciate further advices.
> >>>
> >>> Probably because in each branch, the first line is a declaration, not a statement.
> >>
> >> How does this feedback fit to other software documentation according to declaration statements?
> >> https://en.cppreference.com/w/cpp/language/statements#Declaration_statements
> >
> > Whatever.  In Coccinelle, we decided to do it that way I said it is done.
> > This makes it easy to search for the first statement that is not a
> > declaration in a function.
>
> The following SmPL script variant does also not produce an expected patch
> for the source file “fvwm/colorset.c”.
>
> @replacement@
> declaration d;
> statement s1, s2;
> @@
> -if (tint != NULL)
> -{
> - d
> - s1
> - cs->tint = GetColor(tint);
> - s2
> -}
> -else if (tint == NULL)
> -{
> - d
> - s1
> - cs->tint = GetColor(black);
> - s2
> -}
> +d
> +s1
> +cs->tint = GetColor(tint ? tint : black);
> +s2

OK the problem seems to be related to s2 matching an if.  I will look into
it.

thanks,
julia

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

* Re: [cocci] Checking a transformation approach for the avoidance of duplicate code
  2023-09-02 19:01         ` Julia Lawall
@ 2023-09-03  6:40           ` Markus Elfring
  2023-09-03  7:56           ` Markus Elfring
  1 sibling, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2023-09-03  6:40 UTC (permalink / raw)
  To: Julia Lawall, cocci; +Cc: Thomas Adam

>> The following SmPL script variant does also not produce an expected patch
>> for the source file “fvwm/colorset.c”.
>>
>> @replacement@
>> declaration d;
>> statement s1, s2;
>> @@
>> -if (tint != NULL)
>> -{
>> - d
>> - s1
>> - cs->tint = GetColor(tint);
>> - s2
>> -}
>> -else if (tint == NULL)
>> -{
>> - d
>> - s1
>> - cs->tint = GetColor(black);
>> - s2
>> -}
>> +d
>> +s1
>> +cs->tint = GetColor(tint ? tint : black);
>> +s2
>
> OK the problem seems to be related to s2 matching an if.  I will look into it.

I tried another SmPL script variant out.

@replacement@
statement s;
@@
-if (tint == NULL)
-{
- ...
- cs->tint = GetColor(black);
- s
-}
+cs->tint = GetColor(tint ? tint : black);
+s


Markus_Elfring@Sonne:…/Projekte/fvwm3> spatch test_tint_determination2.cocci lokal/fvwm/colorset.c
…
@@ -962,14 +962,9 @@ void parse_colorset(int n, char *line)
                                have_pixels_changed = True;
                        }
                }
-               else if (tint == NULL)
-               {
-                       /* default */
-                       Pixel old_tint = cs->tint;
-                       PictureFreeColors(dpy, Pcmap, &cs->tint, 1, 0, True);
-                       cs->tint = GetColor(black);
-                       if (old_tint != cs->tint)
-                       {
+               else {
+                       cs->tint = GetColor(tint ? tint : black);
+                       if (old_tint != cs->tint) {
                                have_pixels_changed = True;
                        }
                }


Do you get any further development ideas from such a test result?

Regards,
Markus

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

* Re: [cocci] Checking a transformation approach for the avoidance of duplicate code
  2023-09-02 19:01         ` Julia Lawall
  2023-09-03  6:40           ` Markus Elfring
@ 2023-09-03  7:56           ` Markus Elfring
  2023-09-03  8:34             ` [cocci] Checking an analysis " Markus Elfring
  1 sibling, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2023-09-03  7:56 UTC (permalink / raw)
  To: Julia Lawall, cocci; +Cc: Thomas Adam

> OK the problem seems to be related to s2 matching an if.  I will look into it.

How will the chances evolve for the clarification of the test result
that the following SmPL script variant does also not find known source code.

https://github.com/fvwmorg/fvwm3/blob/c9d00184ac3ab534e0f0ba5683106879a35857f6/fvwm/colorset.c#L955-L975

@display@
declaration d;
statement s1, s2;
@@
*if (tint != NULL)
*{
* d
* s1
* cs->tint = GetColor(tint);
* s2
*}
*else if (tint == NULL)
*{
* d
* s1
* cs->tint = GetColor(black);
* s2
*}


Would you like to point any debug approaches out for the observed behaviour
of the current Coccinelle software?

Regards,
Markus

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

* Re: [cocci] Checking an analysis approach for the avoidance of duplicate code
  2023-09-03  7:56           ` Markus Elfring
@ 2023-09-03  8:34             ` Markus Elfring
  2023-09-06  7:10               ` Markus Elfring
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2023-09-03  8:34 UTC (permalink / raw)
  To: cocci; +Cc: Thomas Adam

> How will the chances evolve for the clarification of the test result
> that the following SmPL script variant does also not find known source code?
>
> https://github.com/fvwmorg/fvwm3/blob/c9d00184ac3ab534e0f0ba5683106879a35857f6/fvwm/colorset.c#L955-L975

@display@
statement s1, s2;
@@
*if (tint != NULL)
*{
* ...
* s1
* cs->tint = GetColor(tint);
* s2
*}
*else if (tint == NULL)
*{
* ...
* s1
* cs->tint = GetColor(black);
* s2
*}


Will any case distinctions be adjusted in the implementation of the Coccinelle software?

Regards,
Markus

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

* Re: [cocci] Checking an analysis approach for the avoidance of duplicate code
  2023-09-03  8:34             ` [cocci] Checking an analysis " Markus Elfring
@ 2023-09-06  7:10               ` Markus Elfring
  2023-09-06  7:14                 ` Julia Lawall
  0 siblings, 1 reply; 12+ messages in thread
From: Markus Elfring @ 2023-09-06  7:10 UTC (permalink / raw)
  To: cocci; +Cc: Thomas Adam

> Will any case distinctions be adjusted in the implementation of the Coccinelle software?

Would you like to discuss data processing consequences any more for the use case
if multiple metavariables are specified with the same type?

Are there any special constraints to consider for the safe application
of the semantic patch language if a type like “statement” was chosen for some
variable names?

Regards,
Markus

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

* Re: [cocci] Checking an analysis approach for the avoidance of duplicate code
  2023-09-06  7:10               ` Markus Elfring
@ 2023-09-06  7:14                 ` Julia Lawall
  2023-09-06  7:20                   ` Markus Elfring
  0 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2023-09-06  7:14 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci, Thomas Adam

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



On Wed, 6 Sep 2023, Markus Elfring wrote:

> > Will any case distinctions be adjusted in the implementation of the Coccinelle software?
>
> Would you like to discuss data processing consequences any more for the use case
> if multiple metavariables are specified with the same type?
>
> Are there any special constraints to consider for the safe application
> of the semantic patch language if a type like “statement” was chosen for some
> variable names?

None of the above questions make any sense to me, but I did spend some
time yesterday looking at the problem, and I don't have a solution for the
moment.

julia

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

* Re: [cocci] Checking an analysis approach for the avoidance of duplicate code
  2023-09-06  7:14                 ` Julia Lawall
@ 2023-09-06  7:20                   ` Markus Elfring
  0 siblings, 0 replies; 12+ messages in thread
From: Markus Elfring @ 2023-09-06  7:20 UTC (permalink / raw)
  To: Julia Lawall, cocci; +Cc: Thomas Adam

>>> Will any case distinctions be adjusted in the implementation of the Coccinelle software?
>>
>> Would you like to discuss data processing consequences any more for the use case
>> if multiple metavariables are specified with the same type?
>>
>> Are there any special constraints to consider for the safe application
>> of the semantic patch language if a type like “statement” was chosen for some
>> variable names?
>
> None of the above questions make any sense to me,

I hope that such communication difficulties can be resolved better.


> but I did spend some time yesterday looking at the problem,

Thanks for this information.

Which impression did you get from the software situation?


> and I don't have a solution for the moment.

Will any clarifications become more helpful here?

Regards,
Markus

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

end of thread, other threads:[~2023-09-06  7:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-02 17:55 [cocci] Checking a transformation approach for the avoidance of duplicate code Markus Elfring
2023-09-02 18:08 ` Julia Lawall
2023-09-02 18:25   ` Markus Elfring
2023-09-02 18:33     ` Julia Lawall
2023-09-02 18:42       ` Markus Elfring
2023-09-02 19:01         ` Julia Lawall
2023-09-03  6:40           ` Markus Elfring
2023-09-03  7:56           ` Markus Elfring
2023-09-03  8:34             ` [cocci] Checking an analysis " Markus Elfring
2023-09-06  7:10               ` Markus Elfring
2023-09-06  7:14                 ` Julia Lawall
2023-09-06  7:20                   ` 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.