lsym_lbrace.c revision 1.5 1 /* $NetBSD: lsym_lbrace.c,v 1.5 2022/04/23 09:59:14 rillig Exp $ */
2
3 /*
4 * Tests for the token lsym_lbrace, which represents a '{' in these contexts:
5 *
6 * In an initializer, '{' starts an inner group of initializers, usually to
7 * initialize a nested struct, union or array.
8 *
9 * In a function body, '{' starts a block.
10 *
11 * In an expression, '(type){' starts a compound literal that is typically
12 * used in an assignment to a struct or array.
13 *
14 * In macro arguments, a '{' is an ordinary character, it does not need to be
15 * balanced. This is in contrast to '(', which must be balanced with ')'.
16 *
17 * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init.
18 */
19
20 /* Brace level in an initializer */
21 #indent input
22 void
23 function(void)
24 {
25 struct person p = {
26 .name = "Name",
27 .age = {{{35}}}, /* C11 6.7.9 allows this. */
28 };
29 }
30 #indent end
31
32 #indent run-equals-input
33
34
35 /* Begin of a block of statements */
36 #indent input
37 void function(void) {{{ body(); }}}
38 #indent end
39
40 #indent run
41 void
42 function(void)
43 /* $ FIXME: Each '{' must be properly indented. */
44 {{{
45 body();
46 }
47 }
48 }
49 #indent end
50
51
52 /* Compound literal */
53 #indent input
54 struct point
55 origin(void)
56 {
57 return (struct point){
58 .x = 0,
59 .y = 0,
60 };
61 }
62 #indent end
63
64 #indent run
65 struct point
66 origin(void)
67 {
68 return (struct point){
69 .x = 0,
70 /* $ FIXME: All initializers must be indented to the same level. */
71 .y = 0,
72 };
73 }
74 #indent end
75