1/* $NetBSD: opt_eei.c,v 1.15 2023/06/15 09:19:07 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 < 19b) 20 stmt(); 21 if (a 22< 23b) 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 b) 66 stmt(); 67 if (a 68 < 69 b) 70 stmt(); 71 while (a 72 < b) 73 stmt(); 74 switch ( 75 a) 76 stmt(); 77} 78//indent end 79 80/* For indentation 4, the expressions from the 'if' are ambiguous. */ 81//indent run -neei -i4 82{ 83 if (a < 84 b) 85 stmt(); 86 if (a 87 < 88 b) 89 stmt(); 90 while (a 91 < b) 92 stmt(); 93 switch ( 94 a) 95 stmt(); 96} 97//indent end 98 99//indent run -eei -i4 100{ 101 if (a < 102 b) 103 stmt(); 104 if (a 105 < 106 b) 107 stmt(); 108 while (a 109 < b) 110 stmt(); 111 switch ( 112/* $ XXX: No extra indentation necessary. */ 113 a) 114 stmt(); 115} 116//indent end 117 118/* 119 * The -nlp option uses a fixed indentation for continuation lines. The if 120 * statements are disambiguated. 121 */ 122//indent run -eei -i4 -nlp 123{ 124 if (a < 125 b) 126 stmt(); 127 if (a 128 < 129 b) 130 stmt(); 131 while (a 132 < b) 133 stmt(); 134 switch ( 135 a) 136 stmt(); 137} 138//indent end 139 140/* With a continuation indentation of 2, there is no ambiguity at all. */ 141//indent run -eei -i6 -ci2 -nlp 142{ 143 if (a < 144 b) 145 stmt(); 146 if (a 147 < 148 b) 149 stmt(); 150 while (a 151 < b) 152 stmt(); 153 switch ( 154 a) 155 stmt(); 156} 157//indent end 158 159 160/* 161 * Ensure that after a condition with extra indentation, the following 162 * statements are not affected. 163 */ 164//indent input 165{ 166 if ( 167 cond 168 ) 169 stmt( 170 arg 171 ); 172} 173//indent end 174 175//indent run -eei -nlp -i4 176{ 177 if ( 178 cond 179 ) 180 stmt( 181 arg 182 ); 183} 184//indent end 185 186 187/* 188 * When multi-line expressions are aligned on the parentheses, they may have an 189 * ambiguous indentation as well. 190 */ 191//indent input 192{ 193 if (fun( 194 1, 195 2, 196 3)) 197 stmt; 198} 199//indent end 200 201//indent run-equals-input 202 203//indent run -eei 204{ 205 if (fun( 206 1, 207 2, 208 3)) 209 stmt; 210} 211//indent end 212 213 214//indent input 215{ 216 if ((( 217 3 218 ))) 219 stmt; 220 if (((( 221 4 222 )))) 223 stmt; 224} 225//indent end 226 227//indent run -ci2 -nlp -eei 228{ 229 if ((( 230 3 231 ))) 232 stmt; 233 if (((( 234 4 235 )))) 236 stmt; 237} 238//indent end 239