Home | History | Annotate | Line # | Download | only in indent
      1 /* $NetBSD: lsym_typedef.c,v 1.9 2023/06/17 22:09:24 rillig Exp $ */
      2 
      3 /*
      4  * Tests for the token lsym_typedef, which represents the keyword 'typedef'
      5  * for giving a type an additional name.
      6  */
      7 
      8 /*
      9  * Since 2019-04-04 and before lexi.c 1.169 from 2022-02-12, indent placed all
     10  * enum constants except the first too far to the right, as if it were a
     11  * statement continuation, but only if the enum declaration followed a
     12  * 'typedef'.
     13  *
     14  * https://gnats.netbsd.org/55453
     15  */
     16 //indent input
     17 typedef enum {
     18     TC1,
     19     TC2
     20 } T;
     21 
     22 enum {
     23     EC1,
     24     EC2
     25 } E;
     26 //indent end
     27 
     28 //indent run -ci4 -i4
     29 typedef enum {
     30     TC1,
     31     TC2
     32 } T;
     33 
     34 enum {
     35     EC1,
     36     EC2
     37 }		E;
     38 //indent end
     39 
     40 //indent run -ci2
     41 typedef enum {
     42 	TC1,
     43 	TC2
     44 } T;
     45 
     46 enum {
     47 	EC1,
     48 	EC2
     49 }		E;
     50 //indent end
     51 
     52 
     53 /*
     54  * Contrary to declarations, type definitions are not affected by the option
     55  * '-di'.
     56  */
     57 //indent input
     58 typedef int number;
     59 //indent end
     60 
     61 //indent run-equals-input
     62 
     63 
     64 /*
     65  * Ensure that a typedef declaration does not introduce an unnecessary line
     66  * break after the '}'.
     67  */
     68 //indent input
     69 typedef struct {
     70 	int member;
     71 	bool bit:1;
     72 } typedef_name;
     73 
     74 struct {
     75 	int member;
     76 	bool bit:1;
     77 } var_name;
     78 //indent end
     79 
     80 //indent run
     81 typedef struct {
     82 	int		member;
     83 	bool		bit:1;
     84 } typedef_name;
     85 
     86 struct {
     87 	int		member;
     88 	bool		bit:1;
     89 }		var_name;
     90 //indent end
     91 
     92 //indent run-equals-input -di0
     93 
     94 
     95 /*
     96  * When 'typedef' or a tag is followed by a name, that name marks a type and a
     97  * following '*' marks a pointer type.
     98  */
     99 //indent input
    100 {
    101 	// $ Syntactically invalid but shows that '*' is not multiplication.
    102 	a = typedef name * y;
    103 	a = (typedef x * y)z;
    104 }
    105 //indent end
    106 
    107 //indent run
    108 {
    109 	// $ Everything before the '*' is treated as a declaration.
    110 	a = typedef name *y;
    111 	a = (typedef x *y)z;
    112 }
    113 //indent end
    114