blob: ce06bc4c99784c7ea043c6657b4c3cff61b70bea (
plain)
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
|
/* $NetBSD: opt_bacc.c,v 1.13 2023/06/15 09:19:07 rillig Exp $ */
/*
* Tests for the options '-bacc' and '-nbacc' ("blank line around conditional
* compilation").
*
* The option '-bacc' forces a blank line around every conditional compilation
* block. For example, in front of every #ifdef and after every #endif.
* Other blank lines surrounding such blocks are swallowed.
*
* The option '-nbacc' leaves the vertical spacing as-is.
*/
/* Example code without surrounding blank lines. */
//indent input
int a;
#if 0
int b;
#endif
int c;
//indent end
//indent run -bacc
int a;
#if 0
int b;
#endif
int c;
//indent end
/* The option '-nbacc' does not remove anything. */
//indent run-equals-input -nbacc
/* Example code containing blank lines. */
//indent input
int space_a;
#if 0
int space_b;
#endif
int space_c;
//indent end
//indent run-equals-input -bacc
/* The option '-nbacc' does not remove anything. */
//indent run-equals-input -nbacc
/*
* Preprocessing directives can also occur in function bodies.
*/
//indent input
const char *
os_name(void)
{
#if defined(__NetBSD__) || defined(__FreeBSD__)
return "BSD";
#else
return "unknown";
#endif
}
//indent end
//indent run -bacc
const char *
os_name(void)
{
#if defined(__NetBSD__) || defined(__FreeBSD__)
return "BSD";
#else
return "unknown";
#endif
}
//indent end
//indent run-equals-input -nbacc
/*
* Test nested preprocessor directives.
*/
//indent input
#if outer
#if inner
int decl;
#endif
#endif
//indent end
//indent run-equals-input -di0 -bacc
//indent run-equals-input -di0 -nbacc
/*
* Test nested preprocessor directives that are interleaved with declarations.
*/
//indent input
#ifdef outer
int outer_above;
#ifdef inner
int inner;
#endif
int outer_below;
#endif
//indent end
//indent run -di0 -bacc
#ifdef outer
int outer_above;
#ifdef inner
int inner;
#endif
int outer_below;
#endif
//indent end
//indent run-equals-input -di0 -nbacc
//indent input
/* before */
#if 0
/* between if and else */
#else
#if 1
#endif
#endif
/* after */
//indent end
//indent run -bacc
/* before */
// $ XXX: The 'before' comment may refer to the '#if', so it is not obvious
// $ XXX: that this blank line is useful.
#if 0
/* between if and else */
#else
// $ XXX: This blank line looks unintended, as both lines are preprocessing
// $ XXX: directives.
#if 1
#endif
#endif
/* after */
//indent end
|