lsym_comma.c revision 1.3 1 /* $NetBSD: lsym_comma.c,v 1.3 2021/11/28 15:26:22 rillig Exp $ */
2 /* $FreeBSD$ */
3
4 /*
5 * Tests for the token lsym_comma, which represents a ',' in these contexts:
6 *
7 * In an expression, the binary operator ',' evaluates its left operand before
8 * its right operand, inserting a sequence point.
9 *
10 * In a declaration, a ',' separates the declarators.
11 *
12 * In a parameter list of a function type, a ',' separates the parameter
13 * declarations.
14 *
15 * In a traditional function definition, a ',' separates the parameter names.
16 *
17 * In a prototype function definition, a ',' separates the parameter
18 * declarations.
19 *
20 * In a function call expression, a ',' separates the arguments.
21 *
22 * In a macro definition, a ',' separates the parameter names.
23 *
24 * In a macro invocation, a ',' separates the arguments.
25 *
26 * In an initializer list, a ',' separates the initializer expressions.
27 */
28
29 /*
30 * The ',' is a binary operator with very low precedence.
31 */
32 #indent input
33 int
34 comma_expression(void)
35 {
36 return 1, 3;
37 return a = b, c = d;
38 }
39 #indent end
40
41 #indent run-equals-input
42
43
44 /*
45 * In a declaration, a ',' separates the declarators.
46 */
47 #indent input
48 int decl, old_style(), prototype(const char *, double *);
49 int a, b, c;
50 #indent end
51
52 #indent run-equals-input -di0
53
54
55 /*
56 * In a parameter list of a function type, a ',' separates the parameter
57 * declarations.
58 */
59 #indent input
60 double dbl_reduce(double init, const double *s, const double *e, double (*merge)(double, double));
61 double dbl_reduce(double, const double *, const double *, double (*)(double, double));
62 void debug_printf(const char *, ...);
63 #indent end
64
65 #indent run-equals-input -di0
66
67
68 /*
69 * In a traditional function definition, a ',' separates the parameter names.
70 */
71 #indent input
72 double
73 trad_dbl_reduce(init, s, e, merge)
74 double init;
75 double *s, *e;
76 double (*merge)()
77 {
78 double x = init;
79 while (s < e)
80 x = merge(x, *s++);
81 return x;
82 }
83 #indent end
84
85 #indent run-equals-input -di0
86
87
88 /*
89 * In a prototype function definition, a ',' separates the parameter
90 * declarations.
91 */
92 #indent input
93 void
94 dbl_reduce(double init, const double *s, const double *e, double (*merge)(double, double))
95 {
96 double x = init;
97 while (s < e)
98 x = merge(x, *s++);
99 return x;
100 }
101 #indent end
102
103 #indent run-equals-input -di0
104
105
106 /*
107 * In a function call expression, a ',' separates the arguments.
108 */
109 #indent input
110 void
111 function(void)
112 {
113 function_call(arg1, arg2);
114 (*indirect_function_call)(arg1, arg2);
115 }
116 #indent end
117
118 #indent run-equals-input -di0
119
120
121 /*
122 * In a macro definition, a ',' separates the parameter names.
123 */
124 #indent input
125 #define no_space(a,b) a ## b
126 #define normal_space(a, b) a ## b
127 #define wide_space(a , b) a ## b
128 #indent end
129
130 /*
131 * Indent does not touch preprocessor directives, except for the spacing
132 * between the '#' and the directive.
133 */
134 #indent run-equals-input
135
136
137 /*
138 * In a macro invocation, a ',' separates the arguments.
139 */
140 #indent input
141 void
142 function(void)
143 {
144 macro_invocation(arg1, arg2);
145 empty_arguments(,,,);
146 }
147 #indent end
148
149 #indent run-equals-input -di0
150
151
152 /*
153 * In an initializer list, a ',' separates the initializer expressions.
154 *
155 * If a ',' starts a line, indent doesn't put a space before it.
156 */
157 #indent input
158 int arr[] = {1, 2, 3};
159 int arr[] = {
160 1,
161 2,
162 3, /* there may be a trailing comma */
163 };
164 #indent end
165
166 #indent run-equals-input -di0
167
168
169 /*
170 * If a ',' starts a line, indent doesn't put a space before it. This style is
171 * uncommon and looks unbalanced since the '1' is not aligned to the other
172 * numbers.
173 */
174 #indent input
175 int arr[] = {
176 1
177 ,2
178 ,3
179 };
180 #indent end
181
182 #indent run-equals-input -di0
183