indent(1): identifiers inside parentheses are not declarations

Also make lparen position calculation consider tab stops.

This improves function pointer typedef formatting.
This commit is contained in:
Piotr Pawel Stefaniak 2018-06-01 08:54:51 +00:00
parent 937499dcb1
commit 9d4264fbdd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334475
5 changed files with 59 additions and 6 deletions

View File

@ -552,7 +552,7 @@ main(int argc, char **argv)
*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 @@ main(int argc, char **argv)
}
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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
* 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;

View File

@ -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

View File

@ -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));
}
}

View File

@ -0,0 +1,2 @@
/* $FreeBSD$ */
-ts4 -i4 -di12

View File

@ -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));
}
}