opt_eei.c revision 1.10 1 /* $NetBSD: opt_eei.c,v 1.10 2023/05/15 12:59:43 rillig Exp $ */
2
3 /*
4 * Tests for the options '-eei' and '-neei'.
5 *
6 * The option '-eei' enables extra indentation on continuation lines of the
7 * expression part of 'if' and 'while' statements. These continuation lines
8 * are indented one extra level to avoid being confused for the first
9 * statement of the body, even if the condition line starts with an operator
10 * such as '&&' or '<' that could not start a statement.
11 *
12 * The option '-neei' indents these conditions in the same way as all other
13 * continued statements.
14 */
15
16 //indent input
17 {
18 if (a <
19 b)
20 stmt();
21 if (a
22 <
23 b)
24 stmt();
25 while (a
26 < b)
27 stmt();
28 switch (
29 a)
30 stmt();
31 }
32 //indent end
33
34 /*
35 * By default, continuation lines are aligned on parentheses, and only a
36 * multi-line switch statement would have ambiguous indentation.
37 */
38 //indent run
39 {
40 if (a <
41 b)
42 stmt();
43 if (a
44 <
45 b)
46 stmt();
47 while (a
48 < b)
49 stmt();
50 switch (
51 a)
52 stmt();
53 }
54 //indent end
55
56 //indent run-equals-prev-output -neei
57
58 /*
59 * For indentation 8, the only expression that needs to be disambiguated is
60 * the one from the switch statement.
61 */
62 //indent run -eei
63 {
64 if (a <
65 /* $ XXX: No extra indentation necessary. */
66 b)
67 stmt();
68 if (a
69 /* $ XXX: No extra indentation necessary. */
70 <
71 /* $ XXX: No extra indentation necessary. */
72 b)
73 stmt();
74 while (a
75 /* $ XXX: No extra indentation necessary. */
76 < b)
77 stmt();
78 switch (
79 a)
80 stmt();
81 }
82 //indent end
83
84 /* For indentation 4, the expressions from the 'if' are ambiguous. */
85 //indent run -neei -i4
86 {
87 if (a <
88 b)
89 stmt();
90 if (a
91 <
92 b)
93 stmt();
94 while (a
95 < b)
96 stmt();
97 switch (
98 a)
99 stmt();
100 }
101 //indent end
102
103 //indent run -eei -i4
104 {
105 if (a <
106 b)
107 stmt();
108 if (a
109 <
110 b)
111 stmt();
112 while (a
113 /* $ XXX: No extra indentation necessary. */
114 < b)
115 stmt();
116 switch (
117 /* $ XXX: No extra indentation necessary. */
118 a)
119 stmt();
120 }
121 //indent end
122
123 /*
124 * The -nlp option uses a fixed indentation for continuation lines. The if
125 * statements are disambiguated.
126 */
127 //indent run -eei -i4 -nlp
128 {
129 if (a <
130 b)
131 stmt();
132 if (a
133 <
134 b)
135 stmt();
136 while (a
137 < b)
138 stmt();
139 switch (
140 a)
141 stmt();
142 }
143 //indent end
144
145 /* With a continuation indentation of 2, there is no ambiguity at all. */
146 //indent run -eei -i6 -ci2 -nlp
147 {
148 if (a <
149 b)
150 stmt();
151 if (a
152 <
153 b)
154 stmt();
155 while (a
156 < b)
157 stmt();
158 switch (
159 a)
160 stmt();
161 }
162 //indent end
163