mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
checkpatch: dissallow spaces between stars in pointer types
Disallow spaces within multiple pointer stars (*) in both casts and definitions. Both of these would now be reported: (char * *) char * *foo; Also now consistently detects and reports the attributes within these structures making the error report itself clearer. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
fae17daed7
commit
65863862ba
1 changed files with 32 additions and 14 deletions
|
@ -191,7 +191,7 @@ sub build_types {
|
||||||
}x;
|
}x;
|
||||||
$Type = qr{
|
$Type = qr{
|
||||||
$NonptrType
|
$NonptrType
|
||||||
(?:\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+)?$Type};
|
||||||
|
@ -1344,7 +1344,7 @@ sub process {
|
||||||
}
|
}
|
||||||
|
|
||||||
# any (foo ... *) is a pointer cast, and foo is a type
|
# any (foo ... *) is a pointer cast, and foo is a type
|
||||||
while ($s =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/sg) {
|
while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
|
||||||
possible($1, "C:" . $s);
|
possible($1, "C:" . $s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1618,21 +1618,39 @@ sub process {
|
||||||
}
|
}
|
||||||
|
|
||||||
# * goes on variable not on type
|
# * goes on variable not on type
|
||||||
if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) {
|
# (char*[ const])
|
||||||
ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" .
|
if ($line =~ m{\($NonptrType(\s*\*[\s\*]*(?:$Modifier\s*)*)\)}) {
|
||||||
$herecurr);
|
my ($from, $to) = ($1, $1);
|
||||||
|
|
||||||
} elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) {
|
# Should start with a space.
|
||||||
ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" .
|
$to =~ s/^(\S)/ $1/;
|
||||||
$herecurr);
|
# Should not end with a space.
|
||||||
|
$to =~ s/\s+$//;
|
||||||
|
# '*'s should not have spaces between.
|
||||||
|
while ($to =~ s/(.)\s\*/$1\*/) {
|
||||||
|
}
|
||||||
|
|
||||||
} elsif ($line =~ m{\b$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) {
|
#print "from<$from> to<$to>\n";
|
||||||
ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" .
|
if ($from ne $to) {
|
||||||
$herecurr);
|
ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr);
|
||||||
|
}
|
||||||
|
} elsif ($line =~ m{\b$NonptrType(\s*\*[\s\*]*(?:$Modifier\s*)?)($Ident)}) {
|
||||||
|
my ($from, $to, $ident) = ($1, $1, $2);
|
||||||
|
|
||||||
} elsif ($line =~ m{\b$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) {
|
# Should start with a space.
|
||||||
ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" .
|
$to =~ s/^(\S)/ $1/;
|
||||||
$herecurr);
|
# Should not end with a space.
|
||||||
|
$to =~ s/\s+$//;
|
||||||
|
# '*'s should not have spaces between.
|
||||||
|
while ($to =~ s/(.)\s\*/$1\*/) {
|
||||||
|
}
|
||||||
|
# Modifiers should have spaces.
|
||||||
|
$to =~ s/(\b$Modifier$)/$1 /;
|
||||||
|
|
||||||
|
#print "from<$from> to<$to>\n";
|
||||||
|
if ($from ne $to) {
|
||||||
|
ERROR("\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# # no BUG() or BUG_ON()
|
# # no BUG() or BUG_ON()
|
||||||
|
|
Loading…
Reference in a new issue