Skip to content

Commit

Permalink
no newlines when only one thing in an initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaLawall committed Jul 14, 2022
1 parent 02d51a7 commit bcc39cf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parsing_c/unparse_cocci.ml
Expand Up @@ -1103,6 +1103,10 @@ and initialiser nlcomma i =
| Ast.ArInitList(lb,initlist,rb) ->
(match Ast.unwrap initlist with
[] -> mcode print_string lb; mcode print_string rb
| ([_] as lst) -> (* { 0 } is a common idiom *)
mcode print_string lb; pr_space();
initialiser_list nlcomma lst;
pr_space(); mcode print_string rb
| lst ->
mcode print_string lb; start_block();
initialiser_list nlcomma lst;
Expand Down
6 changes: 6 additions & 0 deletions tests/zeroline.c
@@ -0,0 +1,6 @@
int main () {
int x;
int y;
memset(&x,0,4);
memset(&y,0,4);
}
17 changes: 17 additions & 0 deletions tests/zeroline.cocci
@@ -0,0 +1,17 @@
@@
type T;
symbol x;
@@
- T x;
+ T x = { 0 };
...
- memset(&x, 0, ...);

@@
type T;
symbol y;
@@
- T y;
+ T y = { 0,4 };
...
- memset(&y, 0, ...);
7 changes: 7 additions & 0 deletions tests/zeroline.res
@@ -0,0 +1,7 @@
int main () {
int x = { 0 };
int y = {
0,
4
};
}

1 comment on commit bcc39cf

@elfring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add that a clarification request with the topic “How do I disable formatting for the "+"-side of a rule?” by Ævar Arnfjörð Bjarmason triggered this software adjustment.

Please sign in to comment.