Home | History | Annotate | Line # | Download | only in indent
      1 /* $NetBSD: lsym_colon.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
      2 
      3 /*
      4  * Tests for the token lsym_colon, which represents a ':' in these contexts:
      5  *
      6  * After a label that is the target of a 'goto' statement.
      7  *
      8  * In a 'switch' statement, after a 'case' label or a 'default' label.
      9  *
     10  * As part of the conditional operator '?:'.
     11  *
     12  * In the declaration of a struct member that is a bit-field.
     13  *
     14  * Since C11, in the _Generic selection to separate the type from its
     15  * corresponding expression.
     16  *
     17  * See also:
     18  *	label.c
     19  *	lsym_case_label.c	for the C11 _Generic expression
     20  *	lsym_question.c
     21  */
     22 
     23 /*
     24  * The ':' marks a label that can be used in a 'goto' statement.
     25  */
     26 //indent input
     27 void endless(void)
     28 {
     29 label1:
     30 goto label2;
     31 
     32     if (true)if (true)if (true)if (true)label2 :goto label1;
     33 }
     34 //indent end
     35 
     36 //indent run
     37 void
     38 endless(void)
     39 {
     40 label1:
     41 	goto label2;
     42 
     43 	if (true)
     44 		if (true)
     45 			if (true)
     46 				if (true)
     47 			label2:		goto label1;
     48 }
     49 //indent end
     50 
     51 
     52 /*
     53  * The ':' is used in a 'switch' statement, after a 'case' label or a
     54  * 'default' label.
     55  */
     56 //indent input
     57 void
     58 example(void)
     59 {
     60 	switch (expr) {
     61 	case 'x':
     62 		return;
     63 	default:
     64 		return;
     65 	}
     66 }
     67 //indent end
     68 
     69 //indent run-equals-input
     70 
     71 
     72 /*
     73  * The ':' is used as part of the conditional operator '?:'.
     74  */
     75 //indent input
     76 int constant_expression = true?4:12345;
     77 //indent end
     78 
     79 //indent run
     80 int		constant_expression = true ? 4 : 12345;
     81 //indent end
     82 
     83 
     84 /*
     85  * The ':' is used in the declaration of a struct member that is a bit-field.
     86  */
     87 //indent input
     88 struct bit_field {
     89 	bool flag:1;
     90 	int maybe_signed : 4;
     91 	signed int definitely_signed:3;
     92 	signed int : 0;/* padding */
     93 	unsigned int definitely_unsigned:3;
     94 	unsigned int:0;/* padding */
     95 };
     96 //indent end
     97 
     98 //indent run
     99 struct bit_field {
    100 	bool		flag:1;
    101 	int		maybe_signed:4;
    102 	signed int	definitely_signed:3;
    103 /* $ XXX: Placing the colon directly at the type looks inconsistent. */
    104 	signed int:	0;	/* padding */
    105 	unsigned int	definitely_unsigned:3;
    106 /* $ XXX: Placing the colon directly at the type looks inconsistent. */
    107 	unsigned int:	0;	/* padding */
    108 };
    109 //indent end
    110