cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Indentation when adding an if
@ 2019-06-03  9:35 Christoph Böhmwalder
  2019-06-03  9:59 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Böhmwalder @ 2019-06-03  9:35 UTC (permalink / raw)
  To: cocci

Hi,

Consider the following C code and cocci patch:

#include <stdio.h>

int x;

int main(int argc, char **argv)
{
     if (y)
         do_something(x);
}


@@
identifier x;
@@
- do_something(x);
+ if (x)
+	do_one_thing();
+ else
+	do_another_thing();


For this input, spatch produces the following output:


$ spatch --sp-file test.cocci test.c
init_defs_builtins: /usr/lib/coccinelle/standard.h
HANDLING: test.c
diff =
--- test.c
+++ /tmp/cocci-output-18011-a28e99-test.c
@@ -5,5 +5,8 @@ int x;
  int main(int argc, char **argv)
  {
      if (y)
-        do_something(x);
+        if (x)
+            do_one_thing();
+    else
+        do_another_thing();
  }


Obviously it gets the indentation wrong there. Is this a bug?

Adding curly braces around the outer if (in the C code) yields the 
correct indentation, while adding the braces around the inner if (in the 
cocci patch) does not.

Adding an else branch to the outer if also produces the wrong indentation.

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

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

* Re: [Cocci] Indentation when adding an if
  2019-06-03  9:35 [Cocci] Indentation when adding an if Christoph Böhmwalder
@ 2019-06-03  9:59 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2019-06-03  9:59 UTC (permalink / raw)
  To: Christoph Böhmwalder; +Cc: cocci

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



On Mon, 3 Jun 2019, Christoph Böhmwalder wrote:

> Hi,
>
> Consider the following C code and cocci patch:
>
> #include <stdio.h>
>
> int x;
>
> int main(int argc, char **argv)
> {
>     if (y)
>         do_something(x);
> }
>
>
> @@
> identifier x;
> @@
> - do_something(x);
> + if (x)
> +	do_one_thing();
> + else
> +	do_another_thing();
>
>
> For this input, spatch produces the following output:
>
>
> $ spatch --sp-file test.cocci test.c
> init_defs_builtins: /usr/lib/coccinelle/standard.h
> HANDLING: test.c
> diff =
> --- test.c
> +++ /tmp/cocci-output-18011-a28e99-test.c
> @@ -5,5 +5,8 @@ int x;
>  int main(int argc, char **argv)
>  {
>      if (y)
> -        do_something(x);
> +        if (x)
> +            do_one_thing();
> +    else
> +        do_another_thing();
>  }
>
>
> Obviously it gets the indentation wrong there. Is this a bug?
>
> Adding curly braces around the outer if (in the C code) yields the correct
> indentation, while adding the braces around the inner if (in the cocci patch)
> does not.
>
> Adding an else branch to the outer if also produces the wrong indentation.

This is surely a bug.  Thank you for the report.

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

end of thread, other threads:[~2019-06-03  9:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03  9:35 [Cocci] Indentation when adding an if Christoph Böhmwalder
2019-06-03  9:59 ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).