opt_eei.c revision 1.9
1/* $NetBSD: opt_eei.c,v 1.9 2023/05/15 12:11: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/* $ 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/* $ FIXME: Needs extra indentation. */ 131 b) 132 stmt(); 133 if (a 134/* $ FIXME: Needs extra indentation. */ 135 < 136/* $ FIXME: Needs extra indentation. */ 137 b) 138 stmt(); 139 while (a 140/* $ FIXME: Needs extra indentation. */ 141 < b) 142 stmt(); 143 switch ( 144/* $ FIXME: Needs extra indentation. */ 145 a) 146 stmt(); 147} 148//indent end 149 150/* With a continuation indentation of 2, there is no ambiguity at all. */ 151//indent run -eei -i6 -ci2 -nlp 152{ 153 if (a < 154 b) 155 stmt(); 156 if (a 157 < 158 b) 159 stmt(); 160 while (a 161 < b) 162 stmt(); 163 switch ( 164 a) 165 stmt(); 166} 167//indent end 168