Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jul 2017 14:04:46 +0000 (UTC)
From:      Piotr Pawel Stefaniak <pstef@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r321381 - in head/usr.bin/indent: . tests
Message-ID:  <201707231404.v6NE4kBv033188@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pstef
Date: Sun Jul 23 14:04:45 2017
New Revision: 321381
URL: https://svnweb.freebsd.org/changeset/base/321381

Log:
  indent(1): don't produce unneeded space character in function declarators.

Modified:
  head/usr.bin/indent/indent.c
  head/usr.bin/indent/indent_codes.h
  head/usr.bin/indent/indent_globs.h
  head/usr.bin/indent/lexi.c
  head/usr.bin/indent/tests/binary.0.stdout
  head/usr.bin/indent/tests/comments.0.stdout
  head/usr.bin/indent/tests/declarations.0
  head/usr.bin/indent/tests/declarations.0.stdout
  head/usr.bin/indent/tests/elsecomment.0.stdout
  head/usr.bin/indent/tests/float.0.stdout
  head/usr.bin/indent/tests/label.0.stdout
  head/usr.bin/indent/tests/nsac.0.stdout
  head/usr.bin/indent/tests/offsetof.0.stdout
  head/usr.bin/indent/tests/sac.0.stdout

Modified: head/usr.bin/indent/indent.c
==============================================================================
--- head/usr.bin/indent/indent.c	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/indent.c	Sun Jul 23 14:04:45 2017	(r321381)
@@ -535,11 +535,12 @@ check_type:
 		ps.p_l_follow--;
 	    }
 	    if (ps.want_blank && *token != '[' &&
-		    (ps.last_token != ident || proc_calls_space ||
+		    ((ps.last_token != ident && ps.last_token != funcname) ||
+		    proc_calls_space ||
 		    /* offsetof (1) is never allowed a space; sizeof (2) gets
 		     * one iff -bs; all other keywords (>2) always get a space
 		     * before lparen */
-			(ps.keyword + Bill_Shannon > 2)))
+		    ps.keyword + Bill_Shannon > 2))
 		*e_code++ = ' ';
 	    ps.want_blank = false;
 	    if (ps.in_decl && !ps.block_init && !ps.dumped_decl_indent &&
@@ -576,7 +577,6 @@ check_type:
 	    break;
 
 	case rparen:		/* got a ')' or ']' */
-	    rparen_count--;
 	    if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) {
 		ps.last_u_d = true;
 		ps.cast_mask &= (1 << ps.p_l_follow) - 1;
@@ -738,7 +738,7 @@ check_type:
 				     * structure declaration */
 	    scase = false;	/* these will only need resetting in an error */
 	    squest = 0;
-	    if (ps.last_token == rparen && rparen_count == 0)
+	    if (ps.last_token == rparen)
 		ps.in_parameter_declaration = 0;
 	    ps.cast_mask = 0;
 	    ps.not_cast_mask = 0;
@@ -838,6 +838,7 @@ check_type:
 			&& ps.in_parameter_declaration)
 		    postfix_blankline_requested = 1;
 		ps.in_parameter_declaration = 0;
+		ps.in_decl = false;
 	    }
 	    dec_ind = 0;
 	    parse(lbrace);	/* let parser know about this */
@@ -935,7 +936,6 @@ check_type:
 	case decl:		/* we have a declaration type (int, etc.) */
 	    parse(decl);	/* let parser worry about indentation */
 	    if (ps.last_token == rparen && ps.tos <= 1) {
-		ps.in_parameter_declaration = 1;
 		if (s_code != e_code) {
 		    dump_line();
 		    ps.want_blank = 0;
@@ -964,10 +964,11 @@ check_type:
 	    }
 	    goto copy_id;
 
+	case funcname:
 	case ident:		/* got an identifier or constant */
 	    if (ps.in_decl) {	/* if we are in a declaration, we must indent
 				 * identifier */
-		if (is_procname == 0 || !procnames_start_line) {
+		if (type_code != funcname || !procnames_start_line) {
 		    if (!ps.block_init && !ps.dumped_decl_indent) {
 			if (troff) {
 			    if (ps.want_blank)
@@ -980,7 +981,8 @@ check_type:
 			ps.want_blank = false;
 		    }
 		} else {
-		    if (ps.want_blank)
+		    if (ps.want_blank && !(procnames_start_line &&
+			type_code == funcname))
 			*e_code++ = ' ';
 		    ps.want_blank = false;
 		    if (dec_ind && s_code != e_code) {
@@ -1014,7 +1016,8 @@ check_type:
 		    CHECK_SIZE_CODE;
 		    *e_code++ = *t_ptr;
 		}
-	    ps.want_blank = true;
+	    if (type_code != funcname)
+		ps.want_blank = true;
 	    break;
 
 	case strpfx:

Modified: head/usr.bin/indent/indent_codes.h
==============================================================================
--- head/usr.bin/indent/indent_codes.h	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/indent_codes.h	Sun Jul 23 14:04:45 2017	(r321381)
@@ -70,3 +70,4 @@
 #define period		32
 #define strpfx		33
 #define storage		34
+#define funcname	35

Modified: head/usr.bin/indent/indent_globs.h
==============================================================================
--- head/usr.bin/indent/indent_globs.h	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/indent_globs.h	Sun Jul 23 14:04:45 2017	(r321381)
@@ -330,6 +330,5 @@ struct parser_state {
 }           ps;
 
 int         ifdef_level;
-int	    rparen_count;
 struct parser_state state_stack[5];
 struct parser_state match_state[5];

Modified: head/usr.bin/indent/lexi.c
==============================================================================
--- head/usr.bin/indent/lexi.c	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/lexi.c	Sun Jul 23 14:04:45 2017	(r321381)
@@ -353,7 +353,8 @@ lexi(void)
 		return (ident);
 	    }			/* end of switch */
 	}			/* end of if (found_it) */
-	if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) {
+	if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0 &&
+	    ps.in_parameter_declaration == 0 && ps.block_init == 0) {
 	    char *tp = buf_ptr;
 	    while (tp < buf_end)
 		if (*tp++ == ')' && (*tp == ';' || *tp == ','))
@@ -361,7 +362,7 @@ lexi(void)
 	    strncpy(ps.procname, token, sizeof ps.procname - 1);
 	    if (ps.in_decl)
 		ps.in_parameter_declaration = 1;
-	    rparen_count = 1;
+	    return (last_code = funcname);
     not_proc:;
 	}
 	/*

Modified: head/usr.bin/indent/tests/binary.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/binary.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/binary.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,6 +1,6 @@
 /* $FreeBSD$ */
 #define b00101010 -1
-void 
+void
 t(void)
 {
 	unsigned	a[] = {0b00101010, 0x00005678, 02, 17U};

Modified: head/usr.bin/indent/tests/comments.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/comments.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/comments.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,6 +1,6 @@
 /* $FreeBSD$ */
 /* See r303597, r303598, r309219, and r309343 */
-void 
+void
 t(void)
 {
 	/*

Modified: head/usr.bin/indent/tests/declarations.0
==============================================================================
--- head/usr.bin/indent/tests/declarations.0	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/declarations.0	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,6 +1,32 @@
 /* $FreeBSD$ */
 /* See r303570 */
-void t(void) {
+
+static const struct
+{
+	double		x;
+	double		y, z;
+} n[m + 1] =
+{
+	{
+		.0,
+		.9,
+		5
+	}
+};
+
+typedef struct Complex
+{
+	double		x;
+	double		y;
+}	Complex;
+
+void 
+t1 (char *a, int b,
+	void (*fn)(void))
+{}
+
+void t2 (char *x, int y)
+{
 	int a,
 	b,
 	c;
@@ -18,4 +44,33 @@ void t(void) {
 	,n
 	,o
 	;
+}
+
+const int	int_minimum_size =
+MAXALIGN(offsetof(int, test)) + MAXIMUM_ALIGNOF;
+
+int *int_create(void)
+{
+
+}
+
+static
+_attribute_printf(1, 2)
+void
+print_error(const char *fmt,...)
+{
+
+}
+
+static LIST_HEAD(, alq) ald_active;
+static int ald_shutingdown = 0;
+struct thread *ald_thread;
+
+static int
+do_execve(td, args, mac_p)
+	struct thread *td;
+	struct image_args *args;
+	struct mac *mac_p;
+{
+
 }

Modified: head/usr.bin/indent/tests/declarations.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/declarations.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/declarations.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,8 +1,32 @@
 /* $FreeBSD$ */
 /* See r303570 */
-void 
-t(void)
+
+static const struct {
+	double		x;
+	double		y, z;
+}		n[m + 1] =
 {
+	{
+		.0,
+		.9,
+		5
+	}
+};
+
+typedef struct Complex {
+	double		x;
+	double		y;
+}		Complex;
+
+void
+t1(char *a, int b,
+   void (*fn) (void))
+{
+}
+
+void
+t2(char *x, int y)
+{
 	int		a, b, c;
 	int
 		       *d, *e, *f;
@@ -12,4 +36,34 @@ t(void)
 		       ,n
 		       ,o
 		       ;
+}
+
+const int	int_minimum_size =
+MAXALIGN(offsetof(int, test)) + MAXIMUM_ALIGNOF;
+
+int	       *
+int_create(void)
+{
+
+}
+
+static
+_attribute_printf(1, 2)
+void
+print_error(const char *fmt,...)
+{
+
+}
+
+static LIST_HEAD(, alq) ald_active;
+static int	ald_shutingdown = 0;
+struct thread  *ald_thread;
+
+static int
+do_execve(td, args, mac_p)
+	struct thread  *td;
+	struct image_args *args;
+	struct mac     *mac_p;
+{
+
 }

Modified: head/usr.bin/indent/tests/elsecomment.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/elsecomment.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/elsecomment.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,6 +1,6 @@
 /* $FreeBSD$ */
 /* See r303484 and r309342 */
-void 
+void
 t(void)
 {
 	if (0)

Modified: head/usr.bin/indent/tests/float.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/float.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/float.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,6 +1,6 @@
 /* $FreeBSD$ */
 /* See r303499 */
-void 
+void
 t(void)
 {
 	unsigned long	x = 314UL;

Modified: head/usr.bin/indent/tests/label.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/label.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/label.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,6 +1,6 @@
 /* $FreeBSD$ */
 /* See r303489 */
-void 
+void
 t(void)
 {
         switch (1) {

Modified: head/usr.bin/indent/tests/nsac.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/nsac.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/nsac.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,5 +1,5 @@
 /* $FreeBSD$ */
-void 
+void
 t(void)
 {
 	int		a = (double)8;

Modified: head/usr.bin/indent/tests/offsetof.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/offsetof.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/offsetof.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,6 +1,6 @@
 /* $FreeBSD$ */
 /* See r303718 */
-void 
+void
 t(void)
 {
 	int		n = malloc(offsetof(struct s, f) + 1);

Modified: head/usr.bin/indent/tests/sac.0.stdout
==============================================================================
--- head/usr.bin/indent/tests/sac.0.stdout	Sun Jul 23 07:10:41 2017	(r321380)
+++ head/usr.bin/indent/tests/sac.0.stdout	Sun Jul 23 14:04:45 2017	(r321381)
@@ -1,5 +1,5 @@
 /* $FreeBSD$ */
-void 
+void
 t(void)
 {
 	int		a = (double) 8;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707231404.v6NE4kBv033188>