All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Controlling where braces are located?
@ 2019-05-28 22:05 Timur Tabi
  2019-05-28 22:12 ` Julia Lawall
  2019-05-29 12:28 ` Markus Elfring
  0 siblings, 2 replies; 6+ messages in thread
From: Timur Tabi @ 2019-05-28 22:05 UTC (permalink / raw)
  To: cocci

I'm using coccinelle on some C source code that does not follow Linux
kernel coding conventions.  In particular, the first left brace is on
its own line:

if (x == 0)
{
   // ...
}

I have this rule, but spatch puts the left brace on the same line as
if-statement:

 x = BOARDOBJGRP_OBJ_GET(...);
+if (x == NULL)
+{
+    status = ERROR;
+    goto label;
+}

This results in:

+                if (p == NULL) {
+                    status = ERROR;
+                    goto func_exit;
+                }

How can I fix this?
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Controlling where braces are located?
  2019-05-28 22:05 [Cocci] Controlling where braces are located? Timur Tabi
@ 2019-05-28 22:12 ` Julia Lawall
  2019-05-28 23:07   ` Timur Tabi
  2019-05-29 12:28 ` Markus Elfring
  1 sibling, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2019-05-28 22:12 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci

On Tue, 28 May 2019, Timur Tabi wrote:

> I'm using coccinelle on some C source code that does not follow Linux
> kernel coding conventions.  In particular, the first left brace is on
> its own line:
>
> if (x == 0)
> {
>    // ...
> }
>
> I have this rule, but spatch puts the left brace on the same line as
> if-statement:
>
>  x = BOARDOBJGRP_OBJ_GET(...);
> +if (x == NULL)
> +{
> +    status = ERROR;
> +    goto label;
> +}
>
> This results in:
>
> +                if (p == NULL) {
> +                    status = ERROR;
> +                    goto func_exit;
> +                }
>
> How can I fix this?

Try --smpl-spacing.  You will need to make all the spacing in the semantic
patch in the way that you want it to appear in the generated code.

julia

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

* Re: [Cocci] Controlling where braces are located?
  2019-05-28 22:12 ` Julia Lawall
@ 2019-05-28 23:07   ` Timur Tabi
  0 siblings, 0 replies; 6+ messages in thread
From: Timur Tabi @ 2019-05-28 23:07 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci, Timur Tabi

On Tue, May 28, 2019 at 5:12 PM Julia Lawall <julia.lawall@lip6.fr> wrote:
>
> Try --smpl-spacing.  You will need to make all the spacing in the semantic
> patch in the way that you want it to appear in the generated code.

I got weird results with that:

+                if (p == NULL)
+{
+                    status = ERROR;
+                    goto func_exit;
+                }

I tried inserting tab characters before the { in my script, but it
didn't do anything.  The { line is flush-left, and the rest of the
lines are indented properly.
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Controlling where braces are located?
  2019-05-28 22:05 [Cocci] Controlling where braces are located? Timur Tabi
  2019-05-28 22:12 ` Julia Lawall
@ 2019-05-29 12:28 ` Markus Elfring
  2019-05-29 14:54   ` Timur Tabi
  1 sibling, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2019-05-29 12:28 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci

> I have this rule, but spatch puts the left brace on the same line as if-statement:
> How can I fix this?

There are some software development options available.

* Do you expect that the Coccinelle software should pick a coding style up
  from the mentioned source files automatically?

* I would appreciate if more developers will contribute to a feature request
  like “Make change influence configurable for coding style rules”.
  https://github.com/coccinelle/coccinelle/issues/37

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

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

* Re: [Cocci] Controlling where braces are located?
  2019-05-29 12:28 ` Markus Elfring
@ 2019-05-29 14:54   ` Timur Tabi
  2019-05-29 15:07     ` Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2019-05-29 14:54 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

On 5/29/19 7:28 AM, Markus Elfring wrote:
> * Do you expect that the Coccinelle software should pick a coding style up
>    from the mentioned source files automatically?

Automatically?  No.  But it would be nice if I could control some 
commonly-used options, like where braces go, via a command-line 
parameter or a #pragma in the cocci file itself.

> * I would appreciate if more developers will contribute to a feature request
>    like “Make change influence configurable for coding style rules”.
>    https://github.com/coccinelle/coccinelle/issues/37

I don't have anything to contribute other than "I need this feature".
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Controlling where braces are located?
  2019-05-29 14:54   ` Timur Tabi
@ 2019-05-29 15:07     ` Markus Elfring
  0 siblings, 0 replies; 6+ messages in thread
From: Markus Elfring @ 2019-05-29 15:07 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci

> … But it would be nice if I could control some commonly-used options, …

Thanks for your feedback.


> I don't have anything to contribute other than "I need this feature".

Will any programmers appear who would be willing to contribute
more significant development resources?

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

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

end of thread, other threads:[~2019-05-29 15:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28 22:05 [Cocci] Controlling where braces are located? Timur Tabi
2019-05-28 22:12 ` Julia Lawall
2019-05-28 23:07   ` Timur Tabi
2019-05-29 12:28 ` Markus Elfring
2019-05-29 14:54   ` Timur Tabi
2019-05-29 15:07     ` 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.