opt_bacc.c revision 1.11
1/* $NetBSD: opt_bacc.c,v 1.11 2023/05/11 18:13:55 rillig Exp $ */
2
3/*
4 * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional
5 * compilation").
6 *
7 * The option '-bacc' forces a blank line around every conditional compilation
8 * block.  For example, in front of every #ifdef and after every #endif.
9 * Other blank lines surrounding such blocks are swallowed.
10 *
11 * The option '-nbacc' TODO.
12 */
13
14
15/* Example code without surrounding blank lines. */
16//indent input
17int		a;
18#if 0
19int		b;
20#endif
21int		c;
22//indent end
23
24/*
25 * XXX: As of 2021-11-19, the option -bacc has no effect on declarations since
26 * process_type resets out.blank_line_before unconditionally.
27 */
28//indent run -bacc
29int		a;
30/* $ FIXME: expecting a blank line here */
31#if 0
32int		b;
33#endif
34/* $ FIXME: expecting a blank line here */
35int		c;
36//indent end
37
38/*
39 * With '-nbacc' the code is unchanged since there are no blank lines to
40 * remove.
41 */
42//indent run-equals-input -nbacc
43
44
45/* Example code containing blank lines. */
46//indent input
47int		space_a;
48
49#if 0
50
51int		space_b;
52
53#endif
54
55int		space_c;
56//indent end
57
58//indent run-equals-input -bacc
59
60/* The option '-nbacc' does not remove anything. */
61//indent run-equals-input -nbacc
62
63
64/*
65 * Preprocessing directives can also occur in function bodies.
66 */
67//indent input
68const char *
69os_name(void)
70{
71#if defined(__NetBSD__) || defined(__FreeBSD__)
72	return "BSD";
73#else
74	return "unknown";
75#endif
76}
77//indent end
78
79//indent run -bacc
80const char *
81os_name(void)
82{
83/* $ FIXME: expecting a blank line here. */
84#if defined(__NetBSD__) || defined(__FreeBSD__)
85	return "BSD";
86#else
87	return "unknown";
88#endif
89/* $ FIXME: expecting a blank line here. */
90}
91//indent end
92
93//indent run-equals-input -nbacc
94
95
96/*
97 * Test nested preprocessor directives.
98 */
99//indent input
100#if outer
101#if inner
102int decl;
103#endif
104#endif
105//indent end
106
107//indent run-equals-input -di0 -bacc
108
109//indent run-equals-input -di0 -nbacc
110
111
112/*
113 * Test nested preprocessor directives that are interleaved with declarations.
114 */
115//indent input
116#ifdef outer
117int outer_above;
118#ifdef inner
119int inner;
120#endif
121int outer_below;
122#endif
123//indent end
124
125//indent run-equals-input -di0 -bacc
126
127//indent run-equals-input -di0 -nbacc
128