opt_bacc.c revision 1.6
1/* $NetBSD: opt_bacc.c,v 1.6 2021/11/19 22:24:29 rillig Exp $ */ 2/* $FreeBSD$ */ 3 4/* 5 * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional 6 * compilation"). 7 * 8 * The option '-bacc' forces a blank line around every conditional compilation 9 * block. For example, in front of every #ifdef and after every #endif. 10 * Other blank lines surrounding such blocks are swallowed. 11 * 12 * The option '-nbacc' TODO. 13 */ 14 15 16/* Example code without surrounding blank lines. */ 17#indent input 18int a; 19#if 0 20int b; 21#endif 22int c; 23#indent end 24 25/* 26 * XXX: As of 2021-11-19, the option -bacc has no effect on declarations since 27 * process_type resets blank_line_before unconditionally. 28 */ 29#indent run -bacc 30int a; 31/* $ FIXME: expecting a blank line here */ 32#if 0 33int b; 34#endif 35/* $ FIXME: expecting a blank line here */ 36int c; 37#indent end 38 39/* 40 * With '-nbacc' the code is unchanged since there are no blank lines to 41 * remove. 42 */ 43#indent run-equals-input -nbacc 44 45 46/* Example code containing blank lines. */ 47#indent input 48int space_a; 49 50#if 0 51 52int space_b; 53 54#endif 55 56int space_c; 57#indent end 58 59#indent run -bacc 60int space_a; 61/* $ FIXME: expecting a blank line here */ 62#if 0 63 64/* $ FIXME: expecting NO blank line here */ 65int space_b; 66#endif 67 68int space_c; 69#indent end 70 71/* The option '-nbacc' does not remove anything. */ 72#indent run-equals-input -nbacc 73 74 75/* 76 * Preprocessing directives can also occur in function bodies. 77 */ 78#indent input 79const char * 80os_name(void) 81{ 82#if defined(__NetBSD__) || defined(__FreeBSD__) 83 return "BSD"; 84#else 85 return "unknown"; 86#endif 87} 88#indent end 89 90#indent run -bacc 91const char * 92os_name(void) 93{ 94/* $ FIXME: expecting a blank line here. */ 95#if defined(__NetBSD__) || defined(__FreeBSD__) 96/* $ FIXME: expecting NO blank line here. */ 97 98 return "BSD"; 99#else 100/* $ FIXME: expecting NO blank line here. */ 101 102 return "unknown"; 103#endif 104/* $ FIXME: expecting a blank line here. */ 105} 106#indent end 107 108#indent run-equals-input -nbacc 109 110 111/* 112 * Test nested preprocessor directives. 113 */ 114#indent input 115#if outer 116#if inner 117int decl; 118#endif 119#endif 120#indent end 121 122#indent run -di0 -bacc 123#if outer 124 125#if inner 126int decl; 127#endif 128 129#endif 130#indent end 131 132#indent run-equals-input -di0 -nbacc 133 134 135/* 136 * Test nested preprocessor directives that are interleaved with declarations. 137 */ 138#indent input 139#ifdef outer 140int outer_above; 141#ifdef inner 142int inner; 143#endif 144int outer_below; 145#endif 146#indent end 147 148#indent run-equals-input -di0 -bacc 149#indent run-equals-input -di0 -nbacc 150