opt_eei.c revision 1.6
1/* $NetBSD: opt_eei.c,v 1.6 2021/11/20 16:54:17 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 a single indentation level is the same as the continuation 47 * indentation, the code does not clearly show whether the 'b' belongs to the 48 * condition or the body statement. 49 */ 50#indent run -neei -i4 51bool 52less(int a, int b) 53{ 54 if (a < 55 b) 56 return true; 57 if (a 58 < 59 b) 60 return true; 61} 62#indent end 63 64/* 65 * Adding the extra level of indentation is useful when the standard 66 * indentation is the same as the indentation of statement continuations. In 67 * such a case, the continued condition would have the same indentation as the 68 * following statement, which would be confusing. 69 */ 70#indent run -eei -i4 71bool 72less(int a, int b) 73{ 74 if (a < 75 b) 76 return true; 77 if (a 78 < 79 b) 80 return true; 81} 82#indent end 83 84/* 85 * With an indentation size of 4, the width of the code 'if (' is exactly one 86 * indentation level. With the option '-nlp', the option '-eei' has no effect. 87 * 88 * XXX: This is unexpected since this creates the exact ambiguity that the 89 * option '-eei' is supposed to prevent. 90 */ 91#indent run -eei -i4 -nlp 92bool 93less(int a, int b) 94{ 95 if (a < 96 b) 97 return true; 98 if (a 99 < 100 b) 101 return true; 102} 103#indent end 104 105 106/* 107 * The option '-eei' applies no matter whether the continued expression starts 108 * with a word or an operator like '&&'. The latter cannot start a statement, 109 * so there would be no ambiguity. 110 */ 111#indent input 112{ 113 if (a 114&& b) 115 stmt(); 116} 117#indent end 118 119/* 120 * XXX: The extra indentation is unnecessary since there is no possible 121 * confusion: the standard indentation is 8, the indentation of the continued 122 * condition could have stayed at 4. 123 */ 124#indent run -eei 125{ 126 if (a 127 && b) 128 stmt(); 129} 130#indent end 131 132/* 133 * The extra indentation is necessary here since otherwise the '&&' and the 134 * 'stmt()' would start at the same indentation. 135 */ 136#indent run -eei -i4 137{ 138 if (a 139 && b) 140 stmt(); 141} 142#indent end 143 144/* 145 * With an indentation size of 4, the width of the code 'if (' is exactly one 146 * indentation level. With the option '-nlp', the option '-eei' has no effect. 147 * 148 * XXX: This is unexpected since this creates the exact ambiguity that the 149 * option '-eei' is supposed to prevent. 150 */ 151#indent run -eei -i4 -nlp 152{ 153 if (a 154 && b) 155 stmt(); 156} 157#indent end 158