opt_eei.c revision 1.5
1/* $NetBSD: opt_eei.c,v 1.5 2021/11/07 08:03:15 rillig Exp $ */
2/* $FreeBSD$ */
3
4/*
5 * Tests for the options '-eei' and '-neei'.
6 *
7 * The option '-eei' enables extra indentation on continuation lines of the
8 * expression part of 'if' and 'while' statements. These continuation lines
9 * are indented one extra level.
10 *
11 * The option '-neei' indents these conditions in the same way as all other
12 * continued statements.
13 */
14
15#indent input
16bool
17less(int a, int b)
18{
19	if (a <
20	    b)
21		return true;
22	if (a
23	    <
24	    b)
25		return true;
26}
27#indent end
28
29#indent run -eei
30bool
31less(int a, int b)
32{
33	if (a <
34			b)
35		return true;
36	if (a
37			<
38			b)
39		return true;
40}
41#indent end
42
43#indent run-equals-input -neei
44
45/*
46 * When the indentation level is the same as the continuation indentation, the
47 * indentation does not show the structure of the code.
48 */
49#indent run -neei -i4
50bool
51less(int a, int b)
52{
53    if (a <
54	b)
55	return true;
56    if (a
57	<
58	b)
59	return true;
60}
61#indent end
62
63/*
64 * Adding the extra level of indentation is useful when the standard
65 * indentation is the same as the indentation of statement continuations. In
66 * such a case, the continued condition would have the same indentation as the
67 * following statement, which would be confusing.
68 */
69#indent run -eei -i4
70bool
71less(int a, int b)
72{
73    if (a <
74	    b)
75	return true;
76    if (a
77	    <
78	    b)
79	return true;
80}
81#indent end
82
83/*
84 * With an indentation size of 4, the width of the code 'if (' is exactly one
85 * indentation level. With the option '-nlp', the option '-eei' has no effect.
86 *
87 * XXX: This is unexpected since this creates the exact ambiguity that the
88 * option '-eei' is supposed to prevent.
89 */
90#indent run -eei -i4 -nlp
91bool
92less(int a, int b)
93{
94    if (a <
95	b)
96	return true;
97    if (a
98	<
99	b)
100	return true;
101}
102#indent end
103
104
105/*
106 * The option '-eei' applies no matter whether the continued expression starts
107 * with a word or an operator like '&&'. The latter cannot start a statement,
108 * so there would be no ambiguity.
109 */
110#indent input
111{
112	if (a
113&& b)
114	    stmt();
115}
116#indent end
117
118/*
119 * XXX: The extra indentation is unnecessary since there is no possible
120 * confusion: the standard indentation is 8, the indentation of the continued
121 * condition could have stayed at 4.
122 */
123#indent run -eei
124{
125	if (a
126			&& b)
127		stmt();
128}
129#indent end
130
131/*
132 * The extra indentation is necessary here since otherwise the '&&' and the
133 * 'stmt()' would start at the same indentation.
134 */
135#indent run -eei -i4
136{
137    if (a
138	    && b)
139	stmt();
140}
141#indent end
142
143/*
144 * With an indentation size of 4, the width of the code 'if (' is exactly one
145 * indentation level. With the option '-nlp', the option '-eei' has no effect.
146 *
147 * XXX: This is unexpected since this creates the exact ambiguity that the
148 * option '-eei' is supposed to prevent.
149 */
150#indent run -eei -i4 -nlp
151{
152    if (a
153	&& b)
154	stmt();
155}
156#indent end
157