From owner-svn-src-head@freebsd.org Fri Jun 1 08:54:53 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1E918F71418; Fri, 1 Jun 2018 08:54:53 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AD1F86BC55; Fri, 1 Jun 2018 08:54:52 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8884126A25; Fri, 1 Jun 2018 08:54:52 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w518sqmp081322; Fri, 1 Jun 2018 08:54:52 GMT (envelope-from pstef@FreeBSD.org) Received: (from pstef@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w518spmY081318; Fri, 1 Jun 2018 08:54:51 GMT (envelope-from pstef@FreeBSD.org) Message-Id: <201806010854.w518spmY081318@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pstef set sender to pstef@FreeBSD.org using -f From: Piotr Pawel Stefaniak Date: Fri, 1 Jun 2018 08:54:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334475 - in head/usr.bin/indent: . tests X-SVN-Group: head X-SVN-Commit-Author: pstef X-SVN-Commit-Paths: in head/usr.bin/indent: . tests X-SVN-Commit-Revision: 334475 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jun 2018 08:54:53 -0000 Author: pstef Date: Fri Jun 1 08:54:51 2018 New Revision: 334475 URL: https://svnweb.freebsd.org/changeset/base/334475 Log: indent(1): identifiers inside parentheses are not declarations Also make lparen position calculation consider tab stops. This improves function pointer typedef formatting. Added: head/usr.bin/indent/tests/parens.0 (contents, props changed) head/usr.bin/indent/tests/parens.0.pro (contents, props changed) head/usr.bin/indent/tests/parens.0.stdout (contents, props changed) Modified: head/usr.bin/indent/indent.c head/usr.bin/indent/tests/Makefile Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Fri Jun 1 05:51:40 2018 (r334474) +++ head/usr.bin/indent/indent.c Fri Jun 1 08:54:51 2018 (r334475) @@ -552,7 +552,7 @@ check_type: *e_code++ = ' '; ps.want_blank = false; if (ps.in_decl && !ps.block_init && !ps.dumped_decl_indent && - !is_procname) { + !is_procname && ps.paren_level == 0) { /* function pointer declarations */ if (troff) { sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token); @@ -565,7 +565,7 @@ check_type: } if (!troff) *e_code++ = token[0]; - ps.paren_indents[ps.p_l_follow - 1] = e_code - s_code; + ps.paren_indents[ps.p_l_follow - 1] = count_spaces_until(1, s_code, e_code) - 1; if (sp_sw && ps.p_l_follow == 1 && extra_expression_indent && ps.paren_indents[0] < 2 * ps.ind_size) ps.paren_indents[0] = 2 * ps.ind_size; @@ -620,7 +620,7 @@ check_type: case unary_op: /* this could be any unary operation */ if (!ps.dumped_decl_indent && ps.in_decl && !is_procname && - !ps.block_init) { + !ps.block_init && ps.paren_level == 0) { /* pointer declarations */ if (troff) { if (ps.want_blank) @@ -755,7 +755,7 @@ check_type: ps.just_saw_decl--; if (ps.in_decl && s_code == e_code && !ps.block_init && - !ps.dumped_decl_indent) { + !ps.dumped_decl_indent && ps.paren_level == 0) { /* indent stray semicolons in declarations */ indent_declaration(dec_ind - 1, tabs_to_var); ps.dumped_decl_indent = true; @@ -977,7 +977,7 @@ check_type: if (ps.in_decl) { /* if we are in a declaration, we must indent * identifier */ if (type_code != funcname || !procnames_start_line) { - if (!ps.block_init && !ps.dumped_decl_indent) { + if (!ps.block_init && !ps.dumped_decl_indent && ps.paren_level == 0) { if (troff) { if (ps.want_blank) *e_code++ = ' '; @@ -1049,7 +1049,7 @@ check_type: * if comma does not start the * line */ if (ps.in_decl && is_procname == 0 && !ps.block_init && - !ps.dumped_decl_indent) { + !ps.dumped_decl_indent && ps.paren_level == 0) { /* indent leading commas and not the actual identifiers */ indent_declaration(dec_ind - 1, tabs_to_var); ps.dumped_decl_indent = true; Modified: head/usr.bin/indent/tests/Makefile ============================================================================== --- head/usr.bin/indent/tests/Makefile Fri Jun 1 05:51:40 2018 (r334474) +++ head/usr.bin/indent/tests/Makefile Fri Jun 1 08:54:51 2018 (r334475) @@ -23,6 +23,9 @@ ${PACKAGE}FILES+= nsac.0.stdout ${PACKAGE}FILES+= nsac.0.pro ${PACKAGE}FILES+= offsetof.0 ${PACKAGE}FILES+= offsetof.0.stdout +${PACKAGE}FILES+= parens.0 +${PACKAGE}FILES+= parens.0.stdout +${PACKAGE}FILES+= parens.0.pro ${PACKAGE}FILES+= sac.0 ${PACKAGE}FILES+= sac.0.stdout ${PACKAGE}FILES+= sac.0.pro Added: head/usr.bin/indent/tests/parens.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/indent/tests/parens.0 Fri Jun 1 08:54:51 2018 (r334475) @@ -0,0 +1,24 @@ +/* $FreeBSD$ */ +typedef void (*xxxxxxxxxxx) (int, + char); + +typedef char (*xxxxxxxxxxxxxxxxxxxxxxxxxxxx) (int *, + unsigned *, + char, + float *); + +void +test(void) +{ + char chars[secondf(firstf(B), + *here)]; + + float xxx = yyyyyyyyyyyyyy(zzzzzzzzzzzzz(p1, + (p2), + p3)); + + if (1) { + char *xxx = firstf(secondf2(p1, + p2)); + } +} Added: head/usr.bin/indent/tests/parens.0.pro ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/indent/tests/parens.0.pro Fri Jun 1 08:54:51 2018 (r334475) @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +-ts4 -i4 -di12 Added: head/usr.bin/indent/tests/parens.0.stdout ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/indent/tests/parens.0.stdout Fri Jun 1 08:54:51 2018 (r334475) @@ -0,0 +1,24 @@ +/* $FreeBSD$ */ +typedef void (*xxxxxxxxxxx) (int, + char); + +typedef char (*xxxxxxxxxxxxxxxxxxxxxxxxxxxx) (int *, + unsigned *, + char, + float *); + +void +test(void) +{ + char chars[secondf(firstf(B), + *here)]; + + float xxx = yyyyyyyyyyyyyy(zzzzzzzzzzzzz(p1, + (p2), + p3)); + + if (1) { + char *xxx = firstf(secondf2(p1, + p2)); + } +}