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:
parent
937499dcb1
commit
9d4264fbdd
@ -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;
|
||||
|
@ -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
|
||||
|
24
usr.bin/indent/tests/parens.0
Normal file
24
usr.bin/indent/tests/parens.0
Normal 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));
|
||||
}
|
||||
}
|
2
usr.bin/indent/tests/parens.0.pro
Normal file
2
usr.bin/indent/tests/parens.0.pro
Normal file
@ -0,0 +1,2 @@
|
||||
/* $FreeBSD$ */
|
||||
-ts4 -i4 -di12
|
24
usr.bin/indent/tests/parens.0.stdout
Normal file
24
usr.bin/indent/tests/parens.0.stdout
Normal 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));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user