Commit 91cb5195 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: expand parenthesis alignment test to declarations, functions and assignments

Currently the parenthesis alignment test works only on misalignments of
if statements like

	if (foo(bar,
			baz)

Expand the test to find misalignments like:

static inline int foo(int bar,
			int baz)

and

	foo(bar,
			baz);

and

	foo = bar(baz,
			qux);

Expand the $Inline keyword for __inline and __inline__ too.
Add $Inline to $Declare so it also matches "static inline <foo>".

These checks are only performed with --strict.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7ebd05ef
...@@ -281,7 +281,7 @@ our $Attribute = qr{ ...@@ -281,7 +281,7 @@ our $Attribute = qr{
__weak __weak
}x; }x;
our $Modifier; our $Modifier;
our $Inline = qr{inline|__always_inline|noinline}; our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__};
our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
our $Lval = qr{$Ident(?:$Member)*}; our $Lval = qr{$Ident(?:$Member)*};
...@@ -304,6 +304,8 @@ our $Operators = qr{ ...@@ -304,6 +304,8 @@ our $Operators = qr{
&&|\|\||,|\^|\+\+|--|&|\||$Arithmetic &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
}x; }x;
our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
our $NonptrType; our $NonptrType;
our $NonptrTypeWithAttr; our $NonptrTypeWithAttr;
our $Type; our $Type;
...@@ -429,7 +431,7 @@ sub build_types { ...@@ -429,7 +431,7 @@ sub build_types {
(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)? (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)?
(?:\s+$Inline|\s+$Modifier)* (?:\s+$Inline|\s+$Modifier)*
}x; }x;
$Declare = qr{(?:$Storage\s+)?$Type}; $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
} }
build_types(); build_types();
...@@ -1607,7 +1609,7 @@ sub pos_last_openparen { ...@@ -1607,7 +1609,7 @@ sub pos_last_openparen {
} }
} }
return $last_openparen + 1; return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
} }
sub process { sub process {
...@@ -2200,7 +2202,7 @@ sub process { ...@@ -2200,7 +2202,7 @@ sub process {
# check multi-line statement indentation matches previous line # check multi-line statement indentation matches previous line
if ($^V && $^V ge 5.10.0 && if ($^V && $^V ge 5.10.0 &&
$prevline =~ /^\+(\t*)(if \(|$Ident\().*(\&\&|\|\||,)\s*$/) { $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|$Ident\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
$prevline =~ /^\+(\t*)(.*)$/; $prevline =~ /^\+(\t*)(.*)$/;
my $oldindent = $1; my $oldindent = $1;
my $rest = $2; my $rest = $2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment