svn commit: r334475 - in head/usr.bin/indent: . tests
Piotr Pawel Stefaniak
pstef at FreeBSD.org
Fri Jun 1 08:54:53 UTC 2018
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));
+ }
+}
More information about the svn-src-all
mailing list