1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/* $NetBSD: lsym_tag.c,v 1.10 2023/06/17 22:09:24 rillig Exp $ */
/*
* Tests for the token lsym_tag, which represents one of the keywords
* 'struct', 'union' or 'enum' that declare, define or use a tagged type.
*/
/* TODO: Add systematic tests for 'struct'. */
/* TODO: Add systematic tests for 'union'. */
/* TODO: Add systematic tests for 'enum'. */
//indent input
int
indent_enum_constants(void)
{
enum color {
red,
green
};
enum color colors[] = {
red,
red,
red,
};
/*
* Ensure that the token sequence 'enum type {' only matches if there
* are no other tokens in between, to prevent statement continuations
* from being indented like enum constant declarations.
*
* See https://gnats.netbsd.org/55453.
*/
if (colors[0] == (enum color)1) {
return 1
+ 2
+ 3;
}
return 0;
}
//indent end
//indent run-equals-input -ci2
//indent input
struct stat {
mode_t st_mode;
};
union variant {
enum {
} tag;
int v_int;
long v_long;
bool v_bool;
void *v_pointer;
};
//indent end
//indent run-equals-input
/* See FreeBSD r303485. */
//indent input
int f(struct x *a);
void
t(void)
{
static const struct {
int a;
int b;
} c[] = {
{ D, E },
{ F, G }
};
}
void u(struct x a) {
int b;
struct y c = (struct y *)&a;
}
//indent end
//indent run
int f(struct x *a);
void
t(void)
{
static const struct {
int a;
int b;
} c[] = {
{D, E},
{F, G}
};
}
void
u(struct x a)
{
int b;
struct y c = (struct y *)&a;
}
//indent end
/* Comment between 'struct' and the tag name; doesn't occur in practice. */
//indent input
struct /* comment */ tag var;
//indent end
//indent run -di0
struct /* comment */ tag var;
//indent end
/*
* Ensure that the names of struct members are all indented the same.
* Before 2023-05-15, the indentation depended on their type name.
*/
//indent input
struct outer {
enum {
untagged_constant,
} untagged_member,
second_untagged_member;
enum tag_name {
tagged_constant,
} tagged_member,
second_tagged_member;
};
//indent end
//indent run-equals-input -di0
/*
* The initializer of an enum constant needs to be indented like any other
* initializer, especially the continuation lines.
*/
//indent input
enum multi_line {
ml1 = 1
+ 2
+ offsetof(struct s, member)
+ 3,
ml2 = 1
+ 2
+ offsetof(struct s, member)
+ 3,
};
//indent end
//indent run-equals-input -ci4
//indent run-equals-input -ci4 -nlp
/*
* When 'typedef' or a tag is followed by a name, that name marks a type and a
* following '*' marks a pointer type.
*/
//indent input
{
// $ Syntactically invalid but shows that '*' is not multiplication.
a = struct x * y;
a = (struct x * y)z;
}
//indent end
//indent run
{
// $ Everything before the '*' is treated as a declaration.
a = struct x *y;
a = (struct x *y)z;
}
//indent end
|