psym_decl.c revision 1.5
1/* $NetBSD: psym_decl.c,v 1.5 2023/06/14 09:31:05 rillig Exp $ */ 2 3/* 4 * Tests for the parser symbol psym_decl, which represents a declaration. 5 * 6 * Since C99, declarations and statements can be mixed in blocks. 7 * 8 * In C, a label can be followed by a statement but not by a declaration. 9 * 10 * Indent distinguishes global and local declarations. 11 * 12 * Declarations can be for functions or for variables. 13 */ 14 15//indent input 16int global_var; 17int global_array = [1,2,3,4]; 18int global_array = [ 191 20,2, 213, 224, 23]; 24//indent end 25 26//indent run -di0 27int global_var; 28int global_array = [1, 2, 3, 4]; 29int global_array = [ 30 1 31 ,2, 32 3, 33 4, 34]; 35//indent end 36 37 38// Declarations can be nested. 39//indent input 40struct level_1 { 41 union level_2 { 42 enum level_3 { 43 level_3_c_1, 44 level_3_c_2, 45 } level_3; 46 } level_2; 47} level_1; 48//indent end 49 50// The outermost declarator 'level_1' is indented as a global variable. 51// The inner declarators 'level_2' and 'level_3' are indented as local 52// variables. 53// XXX: This is inconsistent, as in practice, struct members are usually 54// aligned, while local variables aren't. 55//indent run-equals-input -ldi0 56