util/lint/checkpatch: Update "check for missing blank lines after declarations"

This is to reduce difference with linux v5.16.

Change-Id: I1b7bc2b4ec832f0abeda215c381856a5ec153883
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/61469
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martinroth@google.com>
This commit is contained in:
Elyes HAOUAS 2022-01-29 08:11:50 +01:00 committed by Martin Roth
parent ac69049030
commit 249c4044c2
1 changed files with 28 additions and 23 deletions

View File

@ -3259,45 +3259,50 @@ sub process {
} }
# check for missing blank lines after declarations # check for missing blank lines after declarations
if ($sline =~ /^\+\s+\S/ && #Not at char 1 # (declarations must have the same indentation and not be at the start of line)
# actual declarations if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) {
($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || # use temporaries
my $sl = $sline;
my $pl = $prevline;
# remove $Attribute/$Sparse uses to simplify comparisons
$sl =~ s/\b(?:$Attribute|$Sparse)\b//g;
$pl =~ s/\b(?:$Attribute|$Sparse)\b//g;
if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
# function pointer declarations # function pointer declarations
$prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
# foo bar; where foo is some local typedef or #define # foo bar; where foo is some local typedef or #define
$prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
# known declaration macros # known declaration macros
$prevline =~ /^\+\s+$declaration_macros/) && $pl =~ /^\+\s+$declaration_macros/) &&
# for "else if" which can look like "$Ident $Ident" # for "else if" which can look like "$Ident $Ident"
!($prevline =~ /^\+\s+$c90_Keywords\b/ || !($pl =~ /^\+\s+$c90_Keywords\b/ ||
# other possible extensions of declaration lines # other possible extensions of declaration lines
$prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
# not starting a section or a macro "\" extended line # not starting a section or a macro "\" extended line
$prevline =~ /(?:\{\s*|\\)$/) && $pl =~ /(?:\{\s*|\\)$/) &&
# looks like a declaration # looks like a declaration
!($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
# function pointer declarations # function pointer declarations
$sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
# foo bar; where foo is some local typedef or #define # foo bar; where foo is some local typedef or #define
$sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
# known declaration macros # known declaration macros
$sline =~ /^\+\s+$declaration_macros/ || $sl =~ /^\+\s+$declaration_macros/ ||
# start of struct or union or enum # start of struct or union or enum
$sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ || $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
# start or end of block or continuation of declaration # start or end of block or continuation of declaration
$sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ || $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
# bitfield continuation # bitfield continuation
$sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ || $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
# other possible extensions of declaration lines # other possible extensions of declaration lines
$sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) && $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
# indentation of previous and current line are the same
(($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
if (WARN("LINE_SPACING", if (WARN("LINE_SPACING",
"Missing a blank line after declarations\n" . $hereprev) && "Missing a blank line after declarations\n" . $hereprev) &&
$fix) { $fix) {
fix_insert_line($fixlinenr, "\+"); fix_insert_line($fixlinenr, "\+");
} }
} }
}
# check for spaces at the beginning of a line. # check for spaces at the beginning of a line.
# Exceptions: # Exceptions: