Home | History | Annotate | Line # | Download | only in indent
lsym_lbrace.c revision 1.7
      1 /* $NetBSD: lsym_lbrace.c,v 1.7 2023/06/03 21:44:08 rillig Exp $ */
      2 
      3 /*
      4  * Tests for the token lsym_lbrace, which represents a '{' in these contexts:
      5  *
      6  * In an initializer, '{' starts an inner group of initializers, usually to
      7  * initialize a nested struct, union or array.
      8  *
      9  * In a function body, '{' starts a block.
     10  *
     11  * In an expression, '(type){' starts a compound literal that is typically
     12  * used in an assignment to a struct or array.
     13  *
     14  * In macro arguments, a '{' is an ordinary character, it does not need to be
     15  * balanced.  This is in contrast to '(', which must be balanced with ')'.
     16  *
     17  * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init.
     18  */
     19 
     20 /* Brace level in an initializer */
     21 //indent input
     22 void
     23 function(void)
     24 {
     25 	struct person	p = {
     26 		.name = "Name",
     27 		.age = {{{35}}},	/* C11 6.7.9 allows this. */
     28 	};
     29 }
     30 //indent end
     31 
     32 //indent run-equals-input
     33 
     34 
     35 /* Begin of a block of statements */
     36 //indent input
     37 void function(void) {{{ body(); }}}
     38 //indent end
     39 
     40 //indent run
     41 void
     42 function(void)
     43 {
     44 	{
     45 		{
     46 			body();
     47 		}
     48 	}
     49 }
     50 //indent end
     51 
     52 
     53 /* Compound literal */
     54 //indent input
     55 struct point
     56 origin(void)
     57 {
     58 	return (struct point){
     59 		.x = 0,
     60 		.y = 0,
     61 	};
     62 }
     63 //indent end
     64 
     65 //indent run
     66 struct point
     67 origin(void)
     68 {
     69 	return (struct point){
     70 		.x = 0,
     71 /* $ FIXME: All initializers must be indented to the same level. */
     72 			.y = 0,
     73 	};
     74 }
     75 //indent end
     76