Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit) |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 4 | # (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc) |
| 5 | # Licensed under the terms of the GNU GPL License version 2 |
| 6 | |
| 7 | use strict; |
| 8 | |
| 9 | my $P = $0; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 10 | $P =~ s@.*/@@g; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 11 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 12 | my $V = '0.16'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 13 | |
| 14 | use Getopt::Long qw(:config no_auto_abbrev); |
| 15 | |
| 16 | my $quiet = 0; |
| 17 | my $tree = 1; |
| 18 | my $chk_signoff = 1; |
| 19 | my $chk_patch = 1; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 20 | my $tst_type = 0; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 21 | my $tst_only; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 22 | my $emacs = 0; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 23 | my $terse = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 24 | my $file = 0; |
| 25 | my $check = 0; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 26 | my $summary = 1; |
| 27 | my $mailback = 0; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 28 | my $summary_file = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 29 | my $root; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 30 | my %debug; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 31 | GetOptions( |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 32 | 'q|quiet+' => \$quiet, |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 33 | 'tree!' => \$tree, |
| 34 | 'signoff!' => \$chk_signoff, |
| 35 | 'patch!' => \$chk_patch, |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 36 | 'emacs!' => \$emacs, |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 37 | 'terse!' => \$terse, |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 38 | 'file!' => \$file, |
| 39 | 'subjective!' => \$check, |
| 40 | 'strict!' => \$check, |
| 41 | 'root=s' => \$root, |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 42 | 'summary!' => \$summary, |
| 43 | 'mailback!' => \$mailback, |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 44 | 'summary-file!' => \$summary_file, |
| 45 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 46 | 'debug=s' => \%debug, |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 47 | 'test-type!' => \$tst_type, |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 48 | 'test-only=s' => \$tst_only, |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 49 | ) or exit; |
| 50 | |
| 51 | my $exit = 0; |
| 52 | |
| 53 | if ($#ARGV < 0) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 54 | print "usage: $P [options] patchfile\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 55 | print "version: $V\n"; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 56 | print "options: -q => quiet\n"; |
| 57 | print " --no-tree => run without a kernel tree\n"; |
| 58 | print " --terse => one line per report\n"; |
| 59 | print " --emacs => emacs compile window format\n"; |
| 60 | print " --file => check a source file\n"; |
| 61 | print " --strict => enable more subjective tests\n"; |
| 62 | print " --root => path to the kernel tree root\n"; |
| 63 | print " --no-summary => suppress the per-file summary\n"; |
| 64 | print " --summary-file => include the filename in summary\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 65 | exit(1); |
| 66 | } |
| 67 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 68 | my $dbg_values = 0; |
| 69 | my $dbg_possible = 0; |
| 70 | for my $key (keys %debug) { |
| 71 | eval "\${dbg_$key} = '$debug{$key}';" |
| 72 | } |
| 73 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 74 | if ($terse) { |
| 75 | $emacs = 1; |
| 76 | $quiet++; |
| 77 | } |
| 78 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 79 | if ($tree) { |
| 80 | if (defined $root) { |
| 81 | if (!top_of_kernel_tree($root)) { |
| 82 | die "$P: $root: --root does not point at a valid tree\n"; |
| 83 | } |
| 84 | } else { |
| 85 | if (top_of_kernel_tree('.')) { |
| 86 | $root = '.'; |
| 87 | } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ && |
| 88 | top_of_kernel_tree($1)) { |
| 89 | $root = $1; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (!defined $root) { |
| 94 | print "Must be run from the top-level dir. of a kernel tree\n"; |
| 95 | exit(2); |
| 96 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 99 | my $emitted_corrupt = 0; |
| 100 | |
| 101 | our $Ident = qr{[A-Za-z_][A-Za-z\d_]*}; |
| 102 | our $Storage = qr{extern|static|asmlinkage}; |
| 103 | our $Sparse = qr{ |
| 104 | __user| |
| 105 | __kernel| |
| 106 | __force| |
| 107 | __iomem| |
| 108 | __must_check| |
| 109 | __init_refok| |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 110 | __kprobes |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 111 | }x; |
| 112 | our $Attribute = qr{ |
| 113 | const| |
| 114 | __read_mostly| |
| 115 | __kprobes| |
| 116 | __(?:mem|cpu|dev|)(?:initdata|init) |
| 117 | }x; |
| 118 | our $Inline = qr{inline|__always_inline|noinline}; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 119 | our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; |
| 120 | our $Lval = qr{$Ident(?:$Member)*}; |
| 121 | |
| 122 | our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*}; |
| 123 | our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; |
| 124 | our $Operators = qr{ |
| 125 | <=|>=|==|!=| |
| 126 | =>|->|<<|>>|<|>|!|~| |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 127 | &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 128 | }x; |
| 129 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 130 | our $NonptrType; |
| 131 | our $Type; |
| 132 | our $Declare; |
| 133 | |
| 134 | our @typeList = ( |
| 135 | qr{void}, |
| 136 | qr{char}, |
| 137 | qr{short}, |
| 138 | qr{int}, |
| 139 | qr{long}, |
| 140 | qr{unsigned}, |
| 141 | qr{float}, |
| 142 | qr{double}, |
| 143 | qr{bool}, |
| 144 | qr{long\s+int}, |
| 145 | qr{long\s+long}, |
| 146 | qr{long\s+long\s+int}, |
| 147 | qr{(?:__)?(?:u|s|be|le)(?:8|16|32|64)}, |
| 148 | qr{struct\s+$Ident}, |
| 149 | qr{union\s+$Ident}, |
| 150 | qr{enum\s+$Ident}, |
| 151 | qr{${Ident}_t}, |
| 152 | qr{${Ident}_handler}, |
| 153 | qr{${Ident}_handler_fn}, |
| 154 | ); |
| 155 | |
| 156 | sub build_types { |
| 157 | my $all = "(?: \n" . join("|\n ", @typeList) . "\n)"; |
| 158 | $NonptrType = qr{ |
| 159 | \b |
| 160 | (?:const\s+)? |
| 161 | (?:unsigned\s+)? |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 162 | (?: |
| 163 | $all| |
| 164 | (?:typeof|__typeof__)\s*\(\s*\**\s*$Ident\s*\) |
| 165 | ) |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 166 | (?:\s+$Sparse|\s+const)* |
| 167 | \b |
| 168 | }x; |
| 169 | $Type = qr{ |
| 170 | \b$NonptrType\b |
| 171 | (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 172 | (?:\s+$Inline|\s+$Sparse|\s+$Attribute)* |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 173 | }x; |
| 174 | $Declare = qr{(?:$Storage\s+)?$Type}; |
| 175 | } |
| 176 | build_types(); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 177 | |
| 178 | $chk_signoff = 0 if ($file); |
| 179 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 180 | my @dep_includes = (); |
| 181 | my @dep_functions = (); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 182 | my $removal = "Documentation/feature-removal-schedule.txt"; |
| 183 | if ($tree && -f "$root/$removal") { |
| 184 | open(REMOVE, "<$root/$removal") || |
| 185 | die "$P: $removal: open failed - $!\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 186 | while (<REMOVE>) { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 187 | if (/^Check:\s+(.*\S)/) { |
| 188 | for my $entry (split(/[, ]+/, $1)) { |
| 189 | if ($entry =~ m@include/(.*)@) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 190 | push(@dep_includes, $1); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 191 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 192 | } elsif ($entry !~ m@/@) { |
| 193 | push(@dep_functions, $entry); |
| 194 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 195 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 200 | my @rawlines = (); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 201 | my @lines = (); |
| 202 | my $vname; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 203 | for my $filename (@ARGV) { |
| 204 | if ($file) { |
| 205 | open(FILE, "diff -u /dev/null $filename|") || |
| 206 | die "$P: $filename: diff failed - $!\n"; |
| 207 | } else { |
| 208 | open(FILE, "<$filename") || |
| 209 | die "$P: $filename: open failed - $!\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 210 | } |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 211 | if ($filename eq '-') { |
| 212 | $vname = 'Your patch'; |
| 213 | } else { |
| 214 | $vname = $filename; |
| 215 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 216 | while (<FILE>) { |
| 217 | chomp; |
| 218 | push(@rawlines, $_); |
| 219 | } |
| 220 | close(FILE); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 221 | if (!process($filename)) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 222 | $exit = 1; |
| 223 | } |
| 224 | @rawlines = (); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 225 | @lines = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | exit($exit); |
| 229 | |
| 230 | sub top_of_kernel_tree { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 231 | my ($root) = @_; |
| 232 | |
| 233 | my @tree_check = ( |
| 234 | "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile", |
| 235 | "README", "Documentation", "arch", "include", "drivers", |
| 236 | "fs", "init", "ipc", "kernel", "lib", "scripts", |
| 237 | ); |
| 238 | |
| 239 | foreach my $check (@tree_check) { |
| 240 | if (! -e $root . '/' . $check) { |
| 241 | return 0; |
| 242 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 243 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 244 | return 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | sub expand_tabs { |
| 248 | my ($str) = @_; |
| 249 | |
| 250 | my $res = ''; |
| 251 | my $n = 0; |
| 252 | for my $c (split(//, $str)) { |
| 253 | if ($c eq "\t") { |
| 254 | $res .= ' '; |
| 255 | $n++; |
| 256 | for (; ($n % 8) != 0; $n++) { |
| 257 | $res .= ' '; |
| 258 | } |
| 259 | next; |
| 260 | } |
| 261 | $res .= $c; |
| 262 | $n++; |
| 263 | } |
| 264 | |
| 265 | return $res; |
| 266 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 267 | sub copy_spacing { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 268 | (my $res = shift) =~ tr/\t/ /c; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 269 | return $res; |
| 270 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 271 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 272 | sub line_stats { |
| 273 | my ($line) = @_; |
| 274 | |
| 275 | # Drop the diff line leader and expand tabs |
| 276 | $line =~ s/^.//; |
| 277 | $line = expand_tabs($line); |
| 278 | |
| 279 | # Pick the indent from the front of the line. |
| 280 | my ($white) = ($line =~ /^(\s*)/); |
| 281 | |
| 282 | return (length($line), length($white)); |
| 283 | } |
| 284 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 285 | my $sanitise_quote = ''; |
| 286 | |
| 287 | sub sanitise_line_reset { |
| 288 | my ($in_comment) = @_; |
| 289 | |
| 290 | if ($in_comment) { |
| 291 | $sanitise_quote = '*/'; |
| 292 | } else { |
| 293 | $sanitise_quote = ''; |
| 294 | } |
| 295 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 296 | sub sanitise_line { |
| 297 | my ($line) = @_; |
| 298 | |
| 299 | my $res = ''; |
| 300 | my $l = ''; |
| 301 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 302 | my $qlen = 0; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 303 | my $off = 0; |
| 304 | my $c; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 305 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 306 | # Always copy over the diff marker. |
| 307 | $res = substr($line, 0, 1); |
| 308 | |
| 309 | for ($off = 1; $off < length($line); $off++) { |
| 310 | $c = substr($line, $off, 1); |
| 311 | |
| 312 | # Comments we are wacking completly including the begin |
| 313 | # and end, all to $;. |
| 314 | if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') { |
| 315 | $sanitise_quote = '*/'; |
| 316 | |
| 317 | substr($res, $off, 2, "$;$;"); |
| 318 | $off++; |
| 319 | next; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 320 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 321 | if (substr($line, $off, 2) eq $sanitise_quote) { |
| 322 | $sanitise_quote = ''; |
| 323 | substr($res, $off, 2, "$;$;"); |
| 324 | $off++; |
| 325 | next; |
| 326 | } |
| 327 | |
| 328 | # A \ in a string means ignore the next character. |
| 329 | if (($sanitise_quote eq "'" || $sanitise_quote eq '"') && |
| 330 | $c eq "\\") { |
| 331 | substr($res, $off, 2, 'XX'); |
| 332 | $off++; |
| 333 | next; |
| 334 | } |
| 335 | # Regular quotes. |
| 336 | if ($c eq "'" || $c eq '"') { |
| 337 | if ($sanitise_quote eq '') { |
| 338 | $sanitise_quote = $c; |
| 339 | |
| 340 | substr($res, $off, 1, $c); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 341 | next; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 342 | } elsif ($sanitise_quote eq $c) { |
| 343 | $sanitise_quote = ''; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 346 | |
| 347 | #print "SQ:$sanitise_quote\n"; |
| 348 | if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") { |
| 349 | substr($res, $off, 1, $;); |
| 350 | } elsif ($off != 0 && $sanitise_quote && $c ne "\t") { |
| 351 | substr($res, $off, 1, 'X'); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 352 | } else { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 353 | substr($res, $off, 1, $c); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 354 | } |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | # The pathname on a #include may be surrounded by '<' and '>'. |
| 358 | if ($res =~ /^.#\s*include\s+\<(.*)\>/) { |
| 359 | my $clean = 'X' x length($1); |
| 360 | $res =~ s@\<.*\>@<$clean>@; |
| 361 | |
| 362 | # The whole of a #error is a string. |
| 363 | } elsif ($res =~ /^.#\s*(?:error|warning)\s+(.*)\b/) { |
| 364 | my $clean = 'X' x length($1); |
| 365 | $res =~ s@(#\s*(?:error|warning)\s+).*@$1$clean@; |
| 366 | } |
| 367 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 368 | return $res; |
| 369 | } |
| 370 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 371 | sub ctx_statement_block { |
| 372 | my ($linenr, $remain, $off) = @_; |
| 373 | my $line = $linenr - 1; |
| 374 | my $blk = ''; |
| 375 | my $soff = $off; |
| 376 | my $coff = $off - 1; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 377 | my $coff_set = 0; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 378 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 379 | my $loff = 0; |
| 380 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 381 | my $type = ''; |
| 382 | my $level = 0; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 383 | my $p; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 384 | my $c; |
| 385 | my $len = 0; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 386 | |
| 387 | my $remainder; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 388 | while (1) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 389 | #warn "CSB: blk<$blk> remain<$remain>\n"; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 390 | # If we are about to drop off the end, pull in more |
| 391 | # context. |
| 392 | if ($off >= $len) { |
| 393 | for (; $remain > 0; $line++) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 394 | next if ($lines[$line] =~ /^-/); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 395 | $remain--; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 396 | $loff = $len; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 397 | $blk .= $lines[$line] . "\n"; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 398 | $len = length($blk); |
| 399 | $line++; |
| 400 | last; |
| 401 | } |
| 402 | # Bail if there is no further context. |
| 403 | #warn "CSB: blk<$blk> off<$off> len<$len>\n"; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 404 | if ($off >= $len) { |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 405 | last; |
| 406 | } |
| 407 | } |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 408 | $p = $c; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 409 | $c = substr($blk, $off, 1); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 410 | $remainder = substr($blk, $off); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 411 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 412 | #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n"; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 413 | # Statement ends at the ';' or a close '}' at the |
| 414 | # outermost level. |
| 415 | if ($level == 0 && $c eq ';') { |
| 416 | last; |
| 417 | } |
| 418 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 419 | # An else is really a conditional as long as its not else if |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 420 | if ($level == 0 && $coff_set == 0 && |
| 421 | (!defined($p) || $p =~ /(?:\s|\}|\+)/) && |
| 422 | $remainder =~ /^(else)(?:\s|{)/ && |
| 423 | $remainder !~ /^else\s+if\b/) { |
| 424 | $coff = $off + length($1) - 1; |
| 425 | $coff_set = 1; |
| 426 | #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n"; |
| 427 | #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n"; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 430 | if (($type eq '' || $type eq '(') && $c eq '(') { |
| 431 | $level++; |
| 432 | $type = '('; |
| 433 | } |
| 434 | if ($type eq '(' && $c eq ')') { |
| 435 | $level--; |
| 436 | $type = ($level != 0)? '(' : ''; |
| 437 | |
| 438 | if ($level == 0 && $coff < $soff) { |
| 439 | $coff = $off; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 440 | $coff_set = 1; |
| 441 | #warn "CSB: mark coff<$coff>\n"; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | if (($type eq '' || $type eq '{') && $c eq '{') { |
| 445 | $level++; |
| 446 | $type = '{'; |
| 447 | } |
| 448 | if ($type eq '{' && $c eq '}') { |
| 449 | $level--; |
| 450 | $type = ($level != 0)? '{' : ''; |
| 451 | |
| 452 | if ($level == 0) { |
| 453 | last; |
| 454 | } |
| 455 | } |
| 456 | $off++; |
| 457 | } |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 458 | if ($off == $len) { |
| 459 | $line++; |
| 460 | $remain--; |
| 461 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 462 | |
| 463 | my $statement = substr($blk, $soff, $off - $soff + 1); |
| 464 | my $condition = substr($blk, $soff, $coff - $soff + 1); |
| 465 | |
| 466 | #warn "STATEMENT<$statement>\n"; |
| 467 | #warn "CONDITION<$condition>\n"; |
| 468 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 469 | #print "coff<$coff> soff<$off> loff<$loff>\n"; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 470 | |
| 471 | return ($statement, $condition, |
| 472 | $line, $remain + 1, $off - $loff + 1, $level); |
| 473 | } |
| 474 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 475 | sub statement_lines { |
| 476 | my ($stmt) = @_; |
| 477 | |
| 478 | # Strip the diff line prefixes and rip blank lines at start and end. |
| 479 | $stmt =~ s/(^|\n)./$1/g; |
| 480 | $stmt =~ s/^\s*//; |
| 481 | $stmt =~ s/\s*$//; |
| 482 | |
| 483 | my @stmt_lines = ($stmt =~ /\n/g); |
| 484 | |
| 485 | return $#stmt_lines + 2; |
| 486 | } |
| 487 | |
| 488 | sub statement_rawlines { |
| 489 | my ($stmt) = @_; |
| 490 | |
| 491 | my @stmt_lines = ($stmt =~ /\n/g); |
| 492 | |
| 493 | return $#stmt_lines + 2; |
| 494 | } |
| 495 | |
| 496 | sub statement_block_size { |
| 497 | my ($stmt) = @_; |
| 498 | |
| 499 | $stmt =~ s/(^|\n)./$1/g; |
| 500 | $stmt =~ s/^\s*{//; |
| 501 | $stmt =~ s/}\s*$//; |
| 502 | $stmt =~ s/^\s*//; |
| 503 | $stmt =~ s/\s*$//; |
| 504 | |
| 505 | my @stmt_lines = ($stmt =~ /\n/g); |
| 506 | my @stmt_statements = ($stmt =~ /;/g); |
| 507 | |
| 508 | my $stmt_lines = $#stmt_lines + 2; |
| 509 | my $stmt_statements = $#stmt_statements + 1; |
| 510 | |
| 511 | if ($stmt_lines > $stmt_statements) { |
| 512 | return $stmt_lines; |
| 513 | } else { |
| 514 | return $stmt_statements; |
| 515 | } |
| 516 | } |
| 517 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 518 | sub ctx_statement_full { |
| 519 | my ($linenr, $remain, $off) = @_; |
| 520 | my ($statement, $condition, $level); |
| 521 | |
| 522 | my (@chunks); |
| 523 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 524 | # Grab the first conditional/block pair. |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 525 | ($statement, $condition, $linenr, $remain, $off, $level) = |
| 526 | ctx_statement_block($linenr, $remain, $off); |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 527 | #print "F: c<$condition> s<$statement> remain<$remain>\n"; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 528 | push(@chunks, [ $condition, $statement ]); |
| 529 | if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) { |
| 530 | return ($level, $linenr, @chunks); |
| 531 | } |
| 532 | |
| 533 | # Pull in the following conditional/block pairs and see if they |
| 534 | # could continue the statement. |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 535 | for (;;) { |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 536 | ($statement, $condition, $linenr, $remain, $off, $level) = |
| 537 | ctx_statement_block($linenr, $remain, $off); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 538 | #print "C: c<$condition> s<$statement> remain<$remain>\n"; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 539 | last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s)); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 540 | #print "C: push\n"; |
| 541 | push(@chunks, [ $condition, $statement ]); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | return ($level, $linenr, @chunks); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 547 | sub ctx_block_get { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 548 | my ($linenr, $remain, $outer, $open, $close, $off) = @_; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 549 | my $line; |
| 550 | my $start = $linenr - 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 551 | my $blk = ''; |
| 552 | my @o; |
| 553 | my @c; |
| 554 | my @res = (); |
| 555 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 556 | my $level = 0; |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 557 | for ($line = $start; $remain > 0; $line++) { |
| 558 | next if ($rawlines[$line] =~ /^-/); |
| 559 | $remain--; |
| 560 | |
| 561 | $blk .= $rawlines[$line]; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 562 | foreach my $c (split(//, $rawlines[$line])) { |
| 563 | ##print "C<$c>L<$level><$open$close>O<$off>\n"; |
| 564 | if ($off > 0) { |
| 565 | $off--; |
| 566 | next; |
| 567 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 568 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 569 | if ($c eq $close && $level > 0) { |
| 570 | $level--; |
| 571 | last if ($level == 0); |
| 572 | } elsif ($c eq $open) { |
| 573 | $level++; |
| 574 | } |
| 575 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 576 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 577 | if (!$outer || $level <= 1) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 578 | push(@res, $rawlines[$line]); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 581 | last if ($level == 0); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 584 | return ($level, @res); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 585 | } |
| 586 | sub ctx_block_outer { |
| 587 | my ($linenr, $remain) = @_; |
| 588 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 589 | my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0); |
| 590 | return @r; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 591 | } |
| 592 | sub ctx_block { |
| 593 | my ($linenr, $remain) = @_; |
| 594 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 595 | my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0); |
| 596 | return @r; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 597 | } |
| 598 | sub ctx_statement { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 599 | my ($linenr, $remain, $off) = @_; |
| 600 | |
| 601 | my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off); |
| 602 | return @r; |
| 603 | } |
| 604 | sub ctx_block_level { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 605 | my ($linenr, $remain) = @_; |
| 606 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 607 | return ctx_block_get($linenr, $remain, 0, '{', '}', 0); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 608 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 609 | sub ctx_statement_level { |
| 610 | my ($linenr, $remain, $off) = @_; |
| 611 | |
| 612 | return ctx_block_get($linenr, $remain, 0, '(', ')', $off); |
| 613 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 614 | |
| 615 | sub ctx_locate_comment { |
| 616 | my ($first_line, $end_line) = @_; |
| 617 | |
| 618 | # Catch a comment on the end of the line itself. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 619 | my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 620 | return $current_comment if (defined $current_comment); |
| 621 | |
| 622 | # Look through the context and try and figure out if there is a |
| 623 | # comment. |
| 624 | my $in_comment = 0; |
| 625 | $current_comment = ''; |
| 626 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 627 | my $line = $rawlines[$linenr - 1]; |
| 628 | #warn " $line\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 629 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
| 630 | $in_comment = 1; |
| 631 | } |
| 632 | if ($line =~ m@/\*@) { |
| 633 | $in_comment = 1; |
| 634 | } |
| 635 | if (!$in_comment && $current_comment ne '') { |
| 636 | $current_comment = ''; |
| 637 | } |
| 638 | $current_comment .= $line . "\n" if ($in_comment); |
| 639 | if ($line =~ m@\*/@) { |
| 640 | $in_comment = 0; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | chomp($current_comment); |
| 645 | return($current_comment); |
| 646 | } |
| 647 | sub ctx_has_comment { |
| 648 | my ($first_line, $end_line) = @_; |
| 649 | my $cmt = ctx_locate_comment($first_line, $end_line); |
| 650 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 651 | ##print "LINE: $rawlines[$end_line - 1 ]\n"; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 652 | ##print "CMMT: $cmt\n"; |
| 653 | |
| 654 | return ($cmt ne ''); |
| 655 | } |
| 656 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 657 | sub cat_vet { |
| 658 | my ($vet) = @_; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 659 | my ($res, $coded); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 660 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 661 | $res = ''; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 662 | while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) { |
| 663 | $res .= $1; |
| 664 | if ($2 ne '') { |
| 665 | $coded = sprintf("^%c", unpack('C', $2) + 64); |
| 666 | $res .= $coded; |
| 667 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 668 | } |
| 669 | $res =~ s/$/\$/; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 670 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 671 | return $res; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 674 | my $av_preprocessor = 0; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 675 | my $av_pending; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 676 | my @av_paren_type; |
| 677 | |
| 678 | sub annotate_reset { |
| 679 | $av_preprocessor = 0; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 680 | $av_pending = '_'; |
| 681 | @av_paren_type = ('E'); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 682 | } |
| 683 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 684 | sub annotate_values { |
| 685 | my ($stream, $type) = @_; |
| 686 | |
| 687 | my $res; |
| 688 | my $cur = $stream; |
| 689 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 690 | print "$stream\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 691 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 692 | while (length($cur)) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 693 | @av_paren_type = ('E') if ($#av_paren_type < 0); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 694 | print " <" . join('', @av_paren_type) . |
| 695 | "> <$type> " if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 696 | if ($cur =~ /^(\s+)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 697 | print "WS($1)\n" if ($dbg_values > 1); |
| 698 | if ($1 =~ /\n/ && $av_preprocessor) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 699 | $type = pop(@av_paren_type); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 700 | $av_preprocessor = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 703 | } elsif ($cur =~ /^($Type)/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 704 | print "DECLARE($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 705 | $type = 'T'; |
| 706 | |
| 707 | } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 708 | print "DEFINE($1)\n" if ($dbg_values > 1); |
| 709 | $av_preprocessor = 1; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 710 | $av_pending = 'N'; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 711 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 712 | } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if))/o) { |
| 713 | print "PRE_START($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 714 | $av_preprocessor = 1; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 715 | |
| 716 | push(@av_paren_type, $type); |
| 717 | push(@av_paren_type, $type); |
| 718 | $type = 'N'; |
| 719 | |
| 720 | } elsif ($cur =~ /^(#\s*(?:else|elif))/o) { |
| 721 | print "PRE_RESTART($1)\n" if ($dbg_values > 1); |
| 722 | $av_preprocessor = 1; |
| 723 | |
| 724 | push(@av_paren_type, $av_paren_type[$#av_paren_type]); |
| 725 | |
| 726 | $type = 'N'; |
| 727 | |
| 728 | } elsif ($cur =~ /^(#\s*(?:endif))/o) { |
| 729 | print "PRE_END($1)\n" if ($dbg_values > 1); |
| 730 | |
| 731 | $av_preprocessor = 1; |
| 732 | |
| 733 | # Assume all arms of the conditional end as this |
| 734 | # one does, and continue as if the #endif was not here. |
| 735 | pop(@av_paren_type); |
| 736 | push(@av_paren_type, $type); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 737 | $type = 'N'; |
| 738 | |
| 739 | } elsif ($cur =~ /^(\\\n)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 740 | print "PRECONT($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 741 | |
| 742 | } elsif ($cur =~ /^(sizeof)\s*(\()?/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 743 | print "SIZEOF($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 744 | if (defined $2) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 745 | $av_pending = 'V'; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 746 | } |
| 747 | $type = 'N'; |
| 748 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 749 | } elsif ($cur =~ /^(if|while|typeof|__typeof__|for)\b/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 750 | print "COND($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 751 | $av_pending = 'N'; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 752 | $type = 'N'; |
| 753 | |
| 754 | } elsif ($cur =~/^(return|case|else)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 755 | print "KEYWORD($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 756 | $type = 'N'; |
| 757 | |
| 758 | } elsif ($cur =~ /^(\()/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 759 | print "PAREN('$1')\n" if ($dbg_values > 1); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 760 | push(@av_paren_type, $av_pending); |
| 761 | $av_pending = '_'; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 762 | $type = 'N'; |
| 763 | |
| 764 | } elsif ($cur =~ /^(\))/o) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 765 | my $new_type = pop(@av_paren_type); |
| 766 | if ($new_type ne '_') { |
| 767 | $type = $new_type; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 768 | print "PAREN('$1') -> $type\n" |
| 769 | if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 770 | } else { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 771 | print "PAREN('$1')\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | } elsif ($cur =~ /^($Ident)\(/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 775 | print "FUNC($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 776 | $av_pending = 'V'; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 777 | |
| 778 | } elsif ($cur =~ /^($Ident|$Constant)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 779 | print "IDENT($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 780 | $type = 'V'; |
| 781 | |
| 782 | } elsif ($cur =~ /^($Assignment)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 783 | print "ASSIGN($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 784 | $type = 'N'; |
| 785 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 786 | } elsif ($cur =~/^(;|{|})/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 787 | print "END($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 788 | $type = 'E'; |
| 789 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 790 | } elsif ($cur =~ /^(;|\?|:|\[)/o) { |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 791 | print "CLOSE($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 792 | $type = 'N'; |
| 793 | |
| 794 | } elsif ($cur =~ /^($Operators)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 795 | print "OP($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 796 | if ($1 ne '++' && $1 ne '--') { |
| 797 | $type = 'N'; |
| 798 | } |
| 799 | |
| 800 | } elsif ($cur =~ /(^.)/o) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 801 | print "C($1)\n" if ($dbg_values > 1); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 802 | } |
| 803 | if (defined $1) { |
| 804 | $cur = substr($cur, length($1)); |
| 805 | $res .= $type x length($1); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | return $res; |
| 810 | } |
| 811 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 812 | sub possible { |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 813 | my ($possible, $line) = @_; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 814 | |
| 815 | #print "CHECK<$possible>\n"; |
| 816 | if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ && |
| 817 | $possible ne 'goto' && $possible ne 'return' && |
| 818 | $possible ne 'struct' && $possible ne 'enum' && |
| 819 | $possible ne 'case' && $possible ne 'else' && |
| 820 | $possible ne 'typedef') { |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 821 | warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 822 | push(@typeList, $possible); |
| 823 | build_types(); |
| 824 | } |
| 825 | } |
| 826 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 827 | my $prefix = ''; |
| 828 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 829 | sub report { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 830 | if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) { |
| 831 | return 0; |
| 832 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 833 | my $line = $prefix . $_[0]; |
| 834 | |
| 835 | $line = (split('\n', $line))[0] . "\n" if ($terse); |
| 836 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 837 | push(our @report, $line); |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 838 | |
| 839 | return 1; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 840 | } |
| 841 | sub report_dump { |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 842 | our @report; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 843 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 844 | sub ERROR { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 845 | if (report("ERROR: $_[0]\n")) { |
| 846 | our $clean = 0; |
| 847 | our $cnt_error++; |
| 848 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 849 | } |
| 850 | sub WARN { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 851 | if (report("WARNING: $_[0]\n")) { |
| 852 | our $clean = 0; |
| 853 | our $cnt_warn++; |
| 854 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 855 | } |
| 856 | sub CHK { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 857 | if ($check && report("CHECK: $_[0]\n")) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 858 | our $clean = 0; |
| 859 | our $cnt_chk++; |
| 860 | } |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 863 | sub process { |
| 864 | my $filename = shift; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 865 | |
| 866 | my $linenr=0; |
| 867 | my $prevline=""; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 868 | my $prevrawline=""; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 869 | my $stashline=""; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 870 | my $stashrawline=""; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 871 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 872 | my $length; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 873 | my $indent; |
| 874 | my $previndent=0; |
| 875 | my $stashindent=0; |
| 876 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 877 | our $clean = 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 878 | my $signoff = 0; |
| 879 | my $is_patch = 0; |
| 880 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 881 | our @report = (); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 882 | our $cnt_lines = 0; |
| 883 | our $cnt_error = 0; |
| 884 | our $cnt_warn = 0; |
| 885 | our $cnt_chk = 0; |
| 886 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 887 | # Trace the real file/line as we go. |
| 888 | my $realfile = ''; |
| 889 | my $realline = 0; |
| 890 | my $realcnt = 0; |
| 891 | my $here = ''; |
| 892 | my $in_comment = 0; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 893 | my $comment_edge = 0; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 894 | my $first_line = 0; |
| 895 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 896 | my $prev_values = 'E'; |
| 897 | |
| 898 | # suppression flags |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 899 | my %suppress_ifbraces; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 900 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 901 | # Pre-scan the patch sanitizing the lines. |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 902 | # Pre-scan the patch looking for any __setup documentation. |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 903 | # |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 904 | my @setup_docs = (); |
| 905 | my $setup_docs = 0; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 906 | |
| 907 | sanitise_line_reset(); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 908 | my $line; |
| 909 | foreach my $rawline (@rawlines) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 910 | $linenr++; |
| 911 | $line = $rawline; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 912 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 913 | if ($rawline=~/^\+\+\+\s+(\S+)/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 914 | $setup_docs = 0; |
| 915 | if ($1 =~ m@Documentation/kernel-parameters.txt$@) { |
| 916 | $setup_docs = 1; |
| 917 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 918 | #next; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 919 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 920 | if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { |
| 921 | $realline=$1-1; |
| 922 | if (defined $2) { |
| 923 | $realcnt=$3+1; |
| 924 | } else { |
| 925 | $realcnt=1+1; |
| 926 | } |
| 927 | |
| 928 | # Guestimate if this is a continuing comment. Run |
| 929 | # the context looking for a comment "edge". If this |
| 930 | # edge is a close comment then we must be in a comment |
| 931 | # at context start. |
| 932 | my $edge; |
| 933 | for (my $ln = $linenr; $ln < ($linenr + $realcnt); $ln++) { |
| 934 | next if ($line =~ /^-/); |
| 935 | ($edge) = ($rawlines[$ln - 1] =~ m@(/\*|\*/)@); |
| 936 | last if (defined $edge); |
| 937 | } |
| 938 | if (defined $edge && $edge eq '*/') { |
| 939 | $in_comment = 1; |
| 940 | } |
| 941 | |
| 942 | # Guestimate if this is a continuing comment. If this |
| 943 | # is the start of a diff block and this line starts |
| 944 | # ' *' then it is very likely a comment. |
| 945 | if (!defined $edge && |
| 946 | $rawlines[$linenr] =~ m@^.\s* \*(?:\s|$)@) |
| 947 | { |
| 948 | $in_comment = 1; |
| 949 | } |
| 950 | |
| 951 | ##print "COMMENT:$in_comment edge<$edge> $rawline\n"; |
| 952 | sanitise_line_reset($in_comment); |
| 953 | |
| 954 | } elsif ($realcnt) { |
| 955 | # Standardise the strings and chars within the input to |
| 956 | # simplify matching. |
| 957 | $line = sanitise_line($rawline); |
| 958 | } |
| 959 | push(@lines, $line); |
| 960 | |
| 961 | if ($realcnt > 1) { |
| 962 | $realcnt-- if ($line =~ /^(?:\+| |$)/); |
| 963 | } else { |
| 964 | $realcnt = 0; |
| 965 | } |
| 966 | |
| 967 | #print "==>$rawline\n"; |
| 968 | #print "-->$line\n"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 969 | |
| 970 | if ($setup_docs && $line =~ /^\+/) { |
| 971 | push(@setup_docs, $line); |
| 972 | } |
| 973 | } |
| 974 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 975 | $prefix = ''; |
| 976 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 977 | $realcnt = 0; |
| 978 | $linenr = 0; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 979 | foreach my $line (@lines) { |
| 980 | $linenr++; |
| 981 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 982 | my $rawline = $rawlines[$linenr - 1]; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 983 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 984 | #extract the line range in the file after the patch is applied |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 985 | if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 986 | $is_patch = 1; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 987 | $first_line = $linenr + 1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 988 | $realline=$1-1; |
| 989 | if (defined $2) { |
| 990 | $realcnt=$3+1; |
| 991 | } else { |
| 992 | $realcnt=1+1; |
| 993 | } |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 994 | annotate_reset(); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 995 | $prev_values = 'E'; |
| 996 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 997 | %suppress_ifbraces = (); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 998 | next; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 999 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1000 | # track the line number as we move through the hunk, note that |
| 1001 | # new versions of GNU diff omit the leading space on completely |
| 1002 | # blank context lines so we need to count that too. |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1003 | } elsif ($line =~ /^( |\+|$)/) { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1004 | $realline++; |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1005 | $realcnt-- if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1006 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1007 | # Measure the line length and indent. |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1008 | ($length, $indent) = line_stats($rawline); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1009 | |
| 1010 | # Track the previous line. |
| 1011 | ($prevline, $stashline) = ($stashline, $line); |
| 1012 | ($previndent, $stashindent) = ($stashindent, $indent); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1013 | ($prevrawline, $stashrawline) = ($stashrawline, $rawline); |
| 1014 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1015 | #warn "line<$line>\n"; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1016 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1017 | } elsif ($realcnt == 1) { |
| 1018 | $realcnt--; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | #make up the handle for any error we report on this line |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1022 | $prefix = "$filename:$realline: " if ($emacs && $file); |
| 1023 | $prefix = "$filename:$linenr: " if ($emacs && !$file); |
| 1024 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1025 | $here = "#$linenr: " if (!$file); |
| 1026 | $here = "#$realline: " if ($file); |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1027 | |
| 1028 | # extract the filename as it passes |
| 1029 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 1030 | $realfile = $1; |
| 1031 | $realfile =~ s@^[^/]*/@@; |
| 1032 | |
| 1033 | if ($realfile =~ m@include/asm/@) { |
| 1034 | ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); |
| 1035 | } |
| 1036 | next; |
| 1037 | } |
| 1038 | |
Randy Dunlap | 389834b | 2007-06-08 13:47:03 -0700 | [diff] [blame] | 1039 | $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1040 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1041 | my $hereline = "$here\n$rawline\n"; |
| 1042 | my $herecurr = "$here\n$rawline\n"; |
| 1043 | my $hereprev = "$here\n$prevrawline\n$rawline\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1044 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1045 | $cnt_lines++ if ($realcnt != 0); |
| 1046 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1047 | #check the patch for a signoff: |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1048 | if ($line =~ /^\s*signed-off-by:/i) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1049 | # This is a signoff, if ugly, so do not double report. |
| 1050 | $signoff++; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1051 | if (!($line =~ /^\s*Signed-off-by:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1052 | WARN("Signed-off-by: is the preferred form\n" . |
| 1053 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1054 | } |
| 1055 | if ($line =~ /^\s*signed-off-by:\S/i) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1056 | WARN("space required after Signed-off-by:\n" . |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1057 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1061 | # Check for wrappage within a valid hunk of the file |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1062 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1063 | ERROR("patch seems to be corrupt (line wrapped?)\n" . |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1064 | $herecurr) if (!$emitted_corrupt++); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php |
| 1068 | if (($realfile =~ /^$/ || $line =~ /^\+/) && |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1069 | !($rawline =~ m/^( |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1070 | [\x09\x0A\x0D\x20-\x7E] # ASCII |
| 1071 | | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte |
| 1072 | | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs |
| 1073 | | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte |
| 1074 | | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates |
| 1075 | | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1076 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1077 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1078 | )*$/x )) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1079 | ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1080 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1081 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1082 | #ignore lines being removed |
| 1083 | if ($line=~/^-/) {next;} |
| 1084 | |
| 1085 | # check we are in a valid source file if not then ignore this hunk |
| 1086 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1087 | |
| 1088 | #trailing whitespace |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1089 | if ($line =~ /^\+.*\015/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1090 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1091 | ERROR("DOS line endings\n" . $herevet); |
| 1092 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1093 | } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { |
| 1094 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1095 | ERROR("trailing whitespace\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1096 | } |
| 1097 | #80 column limit |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1098 | if ($line =~ /^\+/ && !($prevrawline=~/\/\*\*/) && $length > 80) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1099 | WARN("line over 80 characters\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1102 | # check for adding lines without a newline. |
| 1103 | if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { |
| 1104 | WARN("adding a line without newline at end of file\n" . $herecurr); |
| 1105 | } |
| 1106 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1107 | # check we are in a valid source file *.[hc] if not then ignore this hunk |
| 1108 | next if ($realfile !~ /\.[hc]$/); |
| 1109 | |
| 1110 | # at the beginning of a line any tabs must come first and anything |
| 1111 | # more than 8 must use tabs. |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1112 | if ($rawline =~ /^\+\s* \t\s*\S/ || |
| 1113 | $rawline =~ /^\+\s* \s*/) { |
| 1114 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1115 | ERROR("use tabs not spaces\n" . $herevet); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1118 | # check for RCS/CVS revision markers |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1119 | if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1120 | WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); |
| 1121 | } |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1122 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1123 | # Check for potential 'bare' types |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1124 | if ($realcnt) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1125 | my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); |
| 1126 | $s =~ s/\n./ /g; |
| 1127 | $s =~ s/{.*$//; |
| 1128 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1129 | # Ignore goto labels. |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1130 | if ($s =~ /$Ident:\*$/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1131 | |
| 1132 | # Ignore functions being called |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1133 | } elsif ($s =~ /^.\s*$Ident\s*\(/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1134 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1135 | # definitions in global scope can only start with types |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1136 | } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) { |
| 1137 | possible($1, $s); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1138 | |
| 1139 | # declarations always start with types |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1140 | } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=|,)/) { |
| 1141 | possible($1, $s); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1142 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1143 | |
| 1144 | # any (foo ... *) is a pointer cast, and foo is a type |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1145 | while ($s =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) { |
| 1146 | possible($1, $s); |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1147 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1148 | |
| 1149 | # Check for any sort of function declaration. |
| 1150 | # int foo(something bar, other baz); |
| 1151 | # void (*store_gdt)(x86_descr_ptr *); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1152 | if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) { |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1153 | my ($name_len) = length($1); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1154 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1155 | my $ctx = $s; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1156 | substr($ctx, 0, $name_len + 1, ''); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1157 | $ctx =~ s/\)[^\)]*$//; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1158 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1159 | for my $arg (split(/\s*,\s*/, $ctx)) { |
| 1160 | if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/ || $arg =~ /^($Ident)$/) { |
| 1161 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1162 | possible($1, $s); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1169 | # |
| 1170 | # Checks which may be anchored in the context. |
| 1171 | # |
| 1172 | |
| 1173 | # Check for switch () and associated case and default |
| 1174 | # statements should be at the same indent. |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1175 | if ($line=~/\bswitch\s*\(.*\)/) { |
| 1176 | my $err = ''; |
| 1177 | my $sep = ''; |
| 1178 | my @ctx = ctx_block_outer($linenr, $realcnt); |
| 1179 | shift(@ctx); |
| 1180 | for my $ctx (@ctx) { |
| 1181 | my ($clen, $cindent) = line_stats($ctx); |
| 1182 | if ($ctx =~ /^\+\s*(case\s+|default:)/ && |
| 1183 | $indent != $cindent) { |
| 1184 | $err .= "$sep$ctx\n"; |
| 1185 | $sep = ''; |
| 1186 | } else { |
| 1187 | $sep = "[...]\n"; |
| 1188 | } |
| 1189 | } |
| 1190 | if ($err ne '') { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1191 | ERROR("switch and case should be at the same indent\n$hereline$err"); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | # if/while/etc brace do not go on next line, unless defining a do while loop, |
| 1196 | # or if that brace on the next line is for something else |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1197 | if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) { |
| 1198 | my $pre_ctx = "$1$2"; |
| 1199 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1200 | my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1201 | my $ctx_ln = $linenr + $#ctx + 1; |
| 1202 | my $ctx_cnt = $realcnt - $#ctx - 1; |
| 1203 | my $ctx = join("\n", @ctx); |
| 1204 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1205 | ##warn "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1206 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1207 | # Skip over any removed lines in the context following statement. |
| 1208 | while (defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^-/) { |
| 1209 | $ctx_ln++; |
| 1210 | } |
| 1211 | ##warn "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n"; |
| 1212 | |
| 1213 | if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { |
| 1214 | ERROR("that open brace { should be on the previous line\n" . |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1215 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1216 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1217 | if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && |
| 1218 | $ctx =~ /\)\s*\;\s*$/ && |
| 1219 | defined $lines[$ctx_ln - 1]) |
| 1220 | { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1221 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); |
| 1222 | if ($nindent > $indent) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1223 | WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1224 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
| 1225 | } |
| 1226 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1229 | # Track the 'values' across context and added lines. |
| 1230 | my $opline = $line; $opline =~ s/^./ /; |
| 1231 | my $curr_values = annotate_values($opline . "\n", $prev_values); |
| 1232 | $curr_values = $prev_values . $curr_values; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1233 | if ($dbg_values) { |
| 1234 | my $outline = $opline; $outline =~ s/\t/ /g; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1235 | print "$linenr > .$outline\n"; |
| 1236 | print "$linenr > $curr_values\n"; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1237 | } |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1238 | $prev_values = substr($curr_values, -1); |
| 1239 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1240 | #ignore lines not being added |
| 1241 | if ($line=~/^[^\+]/) {next;} |
| 1242 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1243 | # TEST: allow direct testing of the type matcher. |
| 1244 | if ($tst_type && $line =~ /^.$Declare$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1245 | ERROR("TEST: is type $Declare\n" . $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1246 | next; |
| 1247 | } |
| 1248 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1249 | # check for initialisation to aggregates open brace on the next line |
| 1250 | if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ && |
| 1251 | $line =~ /^.\s*{/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1252 | ERROR("that open brace { should be on the previous line\n" . $hereprev); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1255 | # |
| 1256 | # Checks which are anchored on the added line. |
| 1257 | # |
| 1258 | |
| 1259 | # check for malformed paths in #include statements (uses RAW line) |
| 1260 | if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) { |
| 1261 | my $path = $1; |
| 1262 | if ($path =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1263 | ERROR("malformed #include filename\n" . |
| 1264 | $herecurr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1265 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1266 | } |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1267 | |
| 1268 | # no C99 // comments |
| 1269 | if ($line =~ m{//}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1270 | ERROR("do not use C99 // comments\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1271 | } |
| 1272 | # Remove C99 comments. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1273 | $line =~ s@//.*@@; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1274 | $opline =~ s@//.*@@; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1275 | |
| 1276 | #EXPORT_SYMBOL should immediately follow its function closing }. |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1277 | if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) || |
| 1278 | ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { |
| 1279 | my $name = $1; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1280 | if (($prevline !~ /^}/) && |
| 1281 | ($prevline !~ /^\+}/) && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1282 | ($prevline !~ /^ }/) && |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1283 | ($prevline !~ /^.DECLARE_$Ident\(\Q$name\E\)/) && |
| 1284 | ($prevline !~ /^.LIST_HEAD\(\Q$name\E\)/) && |
| 1285 | ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=|\[)/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1286 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1290 | # check for external initialisers. |
| 1291 | if ($line =~ /^.$Type\s*$Ident\s*=\s*(0|NULL);/) { |
| 1292 | ERROR("do not initialise externals to 0 or NULL\n" . |
| 1293 | $herecurr); |
| 1294 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1295 | # check for static initialisers. |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1296 | if ($line =~ /\s*static\s.*=\s*(0|NULL);/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1297 | ERROR("do not initialise statics to 0 or NULL\n" . |
| 1298 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1301 | # check for new typedefs, only function parameters and sparse annotations |
| 1302 | # make sense. |
| 1303 | if ($line =~ /\btypedef\s/ && |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1304 | $line !~ /\btypedef\s+$Type\s+\(\s*\*?$Ident\s*\)\s*\(/ && |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1305 | $line !~ /\b__bitwise(?:__|)\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1306 | WARN("do not add new typedefs\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | # * goes on variable not on type |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1310 | if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1311 | ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" . |
| 1312 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1313 | |
| 1314 | } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1315 | ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . |
| 1316 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1317 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1318 | } elsif ($line =~ m{$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1319 | ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . |
| 1320 | $herecurr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1321 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1322 | } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1323 | ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . |
| 1324 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | # # no BUG() or BUG_ON() |
| 1328 | # if ($line =~ /\b(BUG|BUG_ON)\b/) { |
| 1329 | # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n"; |
| 1330 | # print "$herecurr"; |
| 1331 | # $clean = 0; |
| 1332 | # } |
| 1333 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1334 | if ($line =~ /\bLINUX_VERSION_CODE\b/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1335 | WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1336 | } |
| 1337 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1338 | # printk should use KERN_* levels. Note that follow on printk's on the |
| 1339 | # same line do not need a level, so we use the current block context |
| 1340 | # to try and find and validate the current printk. In summary the current |
| 1341 | # printk includes all preceeding printk's which have no newline on the end. |
| 1342 | # we assume the first bad printk is the one to report. |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1343 | if ($line =~ /\bprintk\((?!KERN_)\s*"/) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1344 | my $ok = 0; |
| 1345 | for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { |
| 1346 | #print "CHECK<$lines[$ln - 1]\n"; |
| 1347 | # we have a preceeding printk if it ends |
| 1348 | # with "\n" ignore it, else it is to blame |
| 1349 | if ($lines[$ln - 1] =~ m{\bprintk\(}) { |
| 1350 | if ($rawlines[$ln - 1] !~ m{\\n"}) { |
| 1351 | $ok = 1; |
| 1352 | } |
| 1353 | last; |
| 1354 | } |
| 1355 | } |
| 1356 | if ($ok == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1357 | WARN("printk() should include KERN_ facility level\n" . $herecurr); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1358 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1361 | # function brace can't be on same line, except for #defines of do while, |
| 1362 | # or if closed on same line |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1363 | if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).*\s{/) and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1364 | !($line=~/\#define.*do\s{/) and !($line=~/}/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1365 | ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1366 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1367 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1368 | # open braces for enum, union and struct go on the same line. |
| 1369 | if ($line =~ /^.\s*{/ && |
| 1370 | $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { |
| 1371 | ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); |
| 1372 | } |
| 1373 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1374 | # check for spaces between functions and their parentheses. |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1375 | while ($line =~ /($Ident)\s+\(/g) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1376 | my $name = $1; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1377 | my $ctx_before = substr($line, 0, $-[1]); |
| 1378 | my $ctx = "$ctx_before$name"; |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1379 | |
| 1380 | # Ignore those directives where spaces _are_ permitted. |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1381 | if ($name =~ /^(?: |
| 1382 | if|for|while|switch|return|case| |
| 1383 | volatile|__volatile__| |
| 1384 | __attribute__|format|__extension__| |
| 1385 | asm|__asm__)$/x) |
| 1386 | { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1387 | |
| 1388 | # cpp #define statements have non-optional spaces, ie |
| 1389 | # if there is a space between the name and the open |
| 1390 | # parenthesis it is simply not a parameter group. |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1391 | } elsif ($ctx_before =~ /^.\#\s*define\s*$/) { |
| 1392 | |
| 1393 | # cpp #elif statement condition may start with a ( |
| 1394 | } elsif ($ctx =~ /^.\#\s*elif\s*$/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1395 | |
| 1396 | # If this whole things ends with a type its most |
| 1397 | # likely a typedef for a function. |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1398 | } elsif ($ctx =~ /$Type$/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1399 | |
| 1400 | } else { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1401 | WARN("space prohibited between function name and open parenthesis '('\n" . $herecurr); |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1402 | } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1403 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1404 | # Check operator spacing. |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1405 | if (!($line=~/\#\s*include/)) { |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1406 | my $ops = qr{ |
| 1407 | <<=|>>=|<=|>=|==|!=| |
| 1408 | \+=|-=|\*=|\/=|%=|\^=|\|=|&=| |
| 1409 | =>|->|<<|>>|<|>|=|!|~| |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1410 | &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1411 | }x; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1412 | my @elements = split(/($ops|;)/, $opline); |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1413 | my $off = 0; |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1414 | |
| 1415 | my $blank = copy_spacing($opline); |
| 1416 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1417 | for (my $n = 0; $n < $#elements; $n += 2) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1418 | $off += length($elements[$n]); |
| 1419 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1420 | # Pick up the preceeding and succeeding characters. |
| 1421 | my $ca = substr($opline, 0, $off); |
| 1422 | my $cc = ''; |
| 1423 | if (length($opline) >= ($off + length($elements[$n + 1]))) { |
| 1424 | $cc = substr($opline, $off + length($elements[$n + 1])); |
| 1425 | } |
| 1426 | my $cb = "$ca$;$cc"; |
| 1427 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1428 | my $a = ''; |
| 1429 | $a = 'V' if ($elements[$n] ne ''); |
| 1430 | $a = 'W' if ($elements[$n] =~ /\s$/); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1431 | $a = 'C' if ($elements[$n] =~ /$;$/); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1432 | $a = 'B' if ($elements[$n] =~ /(\[|\()$/); |
| 1433 | $a = 'O' if ($elements[$n] eq ''); |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1434 | $a = 'E' if ($ca =~ /^\s*$/); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1435 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1436 | my $op = $elements[$n + 1]; |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1437 | |
| 1438 | my $c = ''; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1439 | if (defined $elements[$n + 2]) { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1440 | $c = 'V' if ($elements[$n + 2] ne ''); |
| 1441 | $c = 'W' if ($elements[$n + 2] =~ /^\s/); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1442 | $c = 'C' if ($elements[$n + 2] =~ /^$;/); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1443 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); |
| 1444 | $c = 'O' if ($elements[$n + 2] eq ''); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1445 | $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1446 | } else { |
| 1447 | $c = 'E'; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1450 | my $ctx = "${a}x${c}"; |
| 1451 | |
| 1452 | my $at = "(ctx:$ctx)"; |
| 1453 | |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1454 | my $ptr = substr($blank, 0, $off) . "^"; |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1455 | my $hereptr = "$hereline$ptr\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1456 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1457 | # Classify operators into binary, unary, or |
| 1458 | # definitions (* only) where they have more |
| 1459 | # than one mode. |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1460 | my $op_type = substr($curr_values, $off + 1, 1); |
| 1461 | my $op_left = substr($curr_values, $off, 1); |
| 1462 | my $is_unary; |
| 1463 | if ($op_type eq 'T') { |
| 1464 | $is_unary = 2; |
| 1465 | } elsif ($op_left eq 'V') { |
| 1466 | $is_unary = 0; |
| 1467 | } else { |
| 1468 | $is_unary = 1; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1469 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1470 | #if ($op eq '-' || $op eq '&' || $op eq '*') { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1471 | # print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n"; |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1472 | #} |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1473 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1474 | # Ignore operators passed as parameters. |
| 1475 | if ($op_type ne 'V' && |
| 1476 | $ca =~ /\s$/ && $cc =~ /^\s*,/) { |
| 1477 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1478 | # # Ignore comments |
| 1479 | # } elsif ($op =~ /^$;+$/) { |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1480 | |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1481 | # ; should have either the end of line or a space or \ after it |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1482 | } elsif ($op eq ';') { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1483 | if ($ctx !~ /.x[WEBC]/ && |
| 1484 | $cc !~ /^\\/ && $cc !~ /^;/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1485 | ERROR("space required after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | # // is a comment |
| 1489 | } elsif ($op eq '//') { |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1490 | |
| 1491 | # -> should have no spaces |
| 1492 | } elsif ($op eq '->') { |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1493 | if ($ctx =~ /Wx.|.xW/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1494 | ERROR("spaces prohibited around that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | # , must have a space on the right. |
| 1498 | } elsif ($op eq ',') { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1499 | if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1500 | ERROR("space required after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1503 | # '*' as part of a type definition -- reported already. |
| 1504 | } elsif ($op eq '*' && $is_unary == 2) { |
| 1505 | #warn "'*' is part of type\n"; |
| 1506 | |
| 1507 | # unary operators should have a space before and |
| 1508 | # none after. May be left adjacent to another |
| 1509 | # unary operator, or a cast |
| 1510 | } elsif ($op eq '!' || $op eq '~' || |
| 1511 | ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1512 | if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1513 | ERROR("space required before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1514 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1515 | if ($ctx =~ /.xW/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1516 | ERROR("space prohibited after that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | # unary ++ and unary -- are allowed no space on one side. |
| 1520 | } elsif ($op eq '++' or $op eq '--') { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1521 | if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { |
| 1522 | ERROR("space required one side of that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1523 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1524 | if ($ctx =~ /Wx[BE]/ || |
| 1525 | ($ctx =~ /Wx./ && $cc =~ /^;/)) { |
| 1526 | ERROR("space prohibited before that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1527 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1528 | if ($ctx =~ /ExW/) { |
| 1529 | ERROR("space prohibited after that '$op' $at\n" . $hereptr); |
| 1530 | } |
| 1531 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1532 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1533 | # << and >> may either have or not have spaces both sides |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1534 | } elsif ($op eq '<<' or $op eq '>>' or |
| 1535 | $op eq '&' or $op eq '^' or $op eq '|' or |
| 1536 | $op eq '+' or $op eq '-' or |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1537 | $op eq '*' or $op eq '/' or |
| 1538 | $op eq '%') |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1539 | { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1540 | if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1541 | ERROR("need consistent spacing around '$op' $at\n" . |
| 1542 | $hereptr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | # All the others need spaces both sides. |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1546 | } elsif ($ctx !~ /[EWC]x[CWE]/) { |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1547 | # Ignore email addresses <foo@bar> |
| 1548 | if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) && |
| 1549 | !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1550 | ERROR("spaces required around that '$op' $at\n" . $hereptr); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1551 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1552 | } |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1553 | $off += length($elements[$n + 1]); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1557 | # check for multiple assignments |
| 1558 | if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1559 | CHK("multiple assignments should be avoided\n" . $herecurr); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1562 | ## # check for multiple declarations, allowing for a function declaration |
| 1563 | ## # continuation. |
| 1564 | ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ && |
| 1565 | ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { |
| 1566 | ## |
| 1567 | ## # Remove any bracketed sections to ensure we do not |
| 1568 | ## # falsly report the parameters of functions. |
| 1569 | ## my $ln = $line; |
| 1570 | ## while ($ln =~ s/\([^\(\)]*\)//g) { |
| 1571 | ## } |
| 1572 | ## if ($ln =~ /,/) { |
| 1573 | ## WARN("declaring multiple variables together should be avoided\n" . $herecurr); |
| 1574 | ## } |
| 1575 | ## } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1576 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1577 | #need space before brace following if, while, etc |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1578 | if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || |
| 1579 | $line =~ /do{/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1580 | ERROR("space required before the open brace '{'\n" . $herecurr); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | # closing brace should have a space following it when it has anything |
| 1584 | # on the line |
| 1585 | if ($line =~ /}(?!(?:,|;|\)))\S/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1586 | ERROR("space required after that close brace '}'\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1589 | # check spacing on square brackets |
| 1590 | if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1591 | ERROR("space prohibited after that open square bracket '['\n" . $herecurr); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1592 | } |
| 1593 | if ($line =~ /\s\]/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1594 | ERROR("space prohibited before that close square bracket ']'\n" . $herecurr); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | # check spacing on paretheses |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1598 | if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && |
| 1599 | $line !~ /for\s*\(\s+;/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1600 | ERROR("space prohibited after that open parenthesis '('\n" . $herecurr); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1601 | } |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1602 | if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1603 | $line !~ /for\s*\(.*;\s+\)/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1604 | ERROR("space prohibited before that close parenthesis ')'\n" . $herecurr); |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1607 | #goto labels aren't indented, allow a single space however |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1608 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1609 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1610 | WARN("labels should not be indented\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | # Need a space before open parenthesis after if, while etc |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1614 | if ($line=~/\b(if|while|for|switch)\(/) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1615 | ERROR("space required before the open parenthesis '('\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | # Check for illegal assignment in if conditional. |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1619 | if ($line =~ /\bif\s*\(/) { |
| 1620 | my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); |
| 1621 | |
| 1622 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1623 | ERROR("do not use assignment in if condition\n" . $herecurr); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | # Find out what is on the end of the line after the |
| 1627 | # conditional. |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1628 | substr($s, 0, length($c), ''); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1629 | $s =~ s/\n.*//g; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1630 | $s =~ s/$;//g; # Remove any comments |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1631 | if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/ && |
| 1632 | $c !~ /^.\#\s*if/) |
| 1633 | { |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1634 | ERROR("trailing statements should be on next line\n" . $herecurr); |
| 1635 | } |
| 1636 | } |
| 1637 | |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1638 | # Check for bitwise tests written as boolean |
| 1639 | if ($line =~ / |
| 1640 | (?: |
| 1641 | (?:\[|\(|\&\&|\|\|) |
| 1642 | \s*0[xX][0-9]+\s* |
| 1643 | (?:\&\&|\|\|) |
| 1644 | | |
| 1645 | (?:\&\&|\|\|) |
| 1646 | \s*0[xX][0-9]+\s* |
| 1647 | (?:\&\&|\|\||\)|\]) |
| 1648 | )/x) |
| 1649 | { |
| 1650 | WARN("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr); |
| 1651 | } |
| 1652 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1653 | # if and else should not have general statements after it |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1654 | if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) { |
| 1655 | my $s = $1; |
| 1656 | $s =~ s/$;//g; # Remove any comments |
| 1657 | if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { |
| 1658 | ERROR("trailing statements should be on next line\n" . $herecurr); |
| 1659 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | # Check for }<nl>else {, these must be at the same |
| 1663 | # indent level to be relevant to each other. |
| 1664 | if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and |
| 1665 | $previndent == $indent) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1666 | ERROR("else should follow close brace '}'\n" . $hereprev); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1669 | if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and |
| 1670 | $previndent == $indent) { |
| 1671 | my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); |
| 1672 | |
| 1673 | # Find out what is on the end of the line after the |
| 1674 | # conditional. |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1675 | substr($s, 0, length($c), ''); |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 1676 | $s =~ s/\n.*//g; |
| 1677 | |
| 1678 | if ($s =~ /^\s*;/) { |
| 1679 | ERROR("while should follow close brace '}'\n" . $hereprev); |
| 1680 | } |
| 1681 | } |
| 1682 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1683 | #studly caps, commented out until figure out how to distinguish between use of existing and adding new |
| 1684 | # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { |
| 1685 | # print "No studly caps, use _\n"; |
| 1686 | # print "$herecurr"; |
| 1687 | # $clean = 0; |
| 1688 | # } |
| 1689 | |
| 1690 | #no spaces allowed after \ in define |
| 1691 | if ($line=~/\#define.*\\\s$/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1692 | WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1695 | #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) |
| 1696 | if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) { |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1697 | my $checkfile = "$root/include/linux/$1.h"; |
| 1698 | if (-f $checkfile && $1 ne 'irq.h') { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1699 | WARN("Use #include <linux/$1.h> instead of <asm/$1.h>\n" . |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1700 | $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1704 | # multi-statement macros should be enclosed in a do while loop, grab the |
| 1705 | # first statement and ensure its the whole macro if its not enclosed |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1706 | # in a known good container |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1707 | if ($prevline =~ /\#define.*\\/ && |
| 1708 | $prevline !~/(?:do\s+{|\(\{|\{)/ && |
| 1709 | $line !~ /(?:do\s+{|\(\{|\{)/ && |
| 1710 | $line !~ /^.\s*$Declare\s/) { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1711 | # Grab the first statement, if that is the entire macro |
| 1712 | # its ok. This may start either on the #define line |
| 1713 | # or the one below. |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1714 | my $ln = $linenr; |
| 1715 | my $cnt = $realcnt; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1716 | my $off = 0; |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1717 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1718 | # If the macro starts on the define line start |
| 1719 | # grabbing the statement after the identifier |
| 1720 | $prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$}; |
| 1721 | ##print "1<$1> 2<$2>\n"; |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1722 | if (defined $2 && $2 ne '') { |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1723 | $off = length($1); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1724 | $ln--; |
| 1725 | $cnt++; |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1726 | while ($lines[$ln - 1] =~ /^-/) { |
| 1727 | $ln--; |
| 1728 | $cnt++; |
| 1729 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1730 | } |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1731 | my @ctx = ctx_statement($ln, $cnt, $off); |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1732 | my $ctx_ln = $ln + $#ctx + 1; |
| 1733 | my $ctx = join("\n", @ctx); |
| 1734 | |
| 1735 | # Pull in any empty extension lines. |
| 1736 | while ($ctx =~ /\\$/ && |
| 1737 | $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) { |
| 1738 | $ctx .= $lines[$ctx_ln - 1]; |
| 1739 | $ctx_ln++; |
| 1740 | } |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1741 | |
| 1742 | if ($ctx =~ /\\$/) { |
| 1743 | if ($ctx =~ /;/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1744 | ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n"); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1745 | } else { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1746 | ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n"); |
Andy Whitcroft | d8aaf12 | 2007-06-23 17:16:44 -0700 | [diff] [blame] | 1747 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1748 | } |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1751 | # check for redundant bracing round if etc |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1752 | if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) { |
| 1753 | my ($level, $endln, @chunks) = |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1754 | ctx_statement_full($linenr, $realcnt, 1); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1755 | #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n"; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1756 | #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"; |
| 1757 | if ($#chunks > 0 && $level == 0) { |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1758 | my $allowed = 0; |
| 1759 | my $seen = 0; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1760 | my $herectx = $here . "\n"; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1761 | my $ln = $linenr - 1; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1762 | for my $chunk (@chunks) { |
| 1763 | my ($cond, $block) = @{$chunk}; |
| 1764 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1765 | # If the condition carries leading newlines, then count those as offsets. |
| 1766 | my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s); |
| 1767 | my $offset = statement_rawlines($whitespace) - 1; |
| 1768 | |
| 1769 | #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n"; |
| 1770 | |
| 1771 | # We have looked at and allowed this specific line. |
| 1772 | $suppress_ifbraces{$ln + $offset} = 1; |
| 1773 | |
| 1774 | $herectx .= "$rawlines[$ln + $offset]\n[...]\n"; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1775 | $ln += statement_rawlines($block) - 1; |
| 1776 | |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1777 | substr($block, 0, length($cond), ''); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1778 | |
| 1779 | $seen++ if ($block =~ /^\s*{/); |
| 1780 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1781 | #print "cond<$cond> block<$block> allowed<$allowed>\n"; |
| 1782 | if (statement_lines($cond) > 1) { |
| 1783 | #print "APW: ALLOWED: cond<$cond>\n"; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1784 | $allowed = 1; |
| 1785 | } |
| 1786 | if ($block =~/\b(?:if|for|while)\b/) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1787 | #print "APW: ALLOWED: block<$block>\n"; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1788 | $allowed = 1; |
| 1789 | } |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1790 | if (statement_block_size($block) > 1) { |
| 1791 | #print "APW: ALLOWED: lines block<$block>\n"; |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1792 | $allowed = 1; |
| 1793 | } |
| 1794 | } |
| 1795 | if ($seen && !$allowed) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1796 | WARN("braces {} are not necessary for any arm of this statement\n" . $herectx); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1800 | if (!defined $suppress_ifbraces{$linenr - 1} && |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1801 | $line =~ /\b(if|while|for|else)\b/) { |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1802 | my $allowed = 0; |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1803 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1804 | # Check the pre-context. |
| 1805 | if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) { |
| 1806 | #print "APW: ALLOWED: pre<$1>\n"; |
| 1807 | $allowed = 1; |
| 1808 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1809 | |
| 1810 | my ($level, $endln, @chunks) = |
| 1811 | ctx_statement_full($linenr, $realcnt, $-[0]); |
| 1812 | |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1813 | # Check the condition. |
| 1814 | my ($cond, $block) = @{$chunks[0]}; |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1815 | #print "CHECKING<$linenr> cond<$cond> block<$block>\n"; |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1816 | if (defined $cond) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1817 | substr($block, 0, length($cond), ''); |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1818 | } |
| 1819 | if (statement_lines($cond) > 1) { |
| 1820 | #print "APW: ALLOWED: cond<$cond>\n"; |
| 1821 | $allowed = 1; |
| 1822 | } |
| 1823 | if ($block =~/\b(?:if|for|while)\b/) { |
| 1824 | #print "APW: ALLOWED: block<$block>\n"; |
| 1825 | $allowed = 1; |
| 1826 | } |
| 1827 | if (statement_block_size($block) > 1) { |
| 1828 | #print "APW: ALLOWED: lines block<$block>\n"; |
| 1829 | $allowed = 1; |
| 1830 | } |
| 1831 | # Check the post-context. |
| 1832 | if (defined $chunks[1]) { |
| 1833 | my ($cond, $block) = @{$chunks[1]}; |
| 1834 | if (defined $cond) { |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1835 | substr($block, 0, length($cond), ''); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1836 | } |
Andy Whitcroft | cf65504 | 2008-03-04 14:28:20 -0800 | [diff] [blame] | 1837 | if ($block =~ /^\s*\{/) { |
| 1838 | #print "APW: ALLOWED: chunk-1 block<$block>\n"; |
| 1839 | $allowed = 1; |
| 1840 | } |
| 1841 | } |
| 1842 | if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) { |
| 1843 | my $herectx = $here . "\n";; |
| 1844 | my $end = $linenr + statement_rawlines($block) - 1; |
| 1845 | |
| 1846 | for (my $ln = $linenr - 1; $ln < $end; $ln++) { |
| 1847 | $herectx .= $rawlines[$ln] . "\n";; |
| 1848 | } |
| 1849 | |
| 1850 | WARN("braces {} are not necessary for single statement blocks\n" . $herectx); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1854 | # don't include deprecated include files (uses RAW line) |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1855 | for my $inc (@dep_includes) { |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1856 | if ($rawline =~ m@\#\s*include\s*\<$inc>@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1857 | ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1858 | } |
| 1859 | } |
| 1860 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1861 | # don't use deprecated functions |
| 1862 | for my $func (@dep_functions) { |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1863 | if ($line =~ /\b$func\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1864 | ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | # no volatiles please |
Andy Whitcroft | 6c72ffa | 2007-10-18 03:05:08 -0700 | [diff] [blame] | 1869 | my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; |
| 1870 | if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1871 | WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1874 | # SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated |
| 1875 | if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) { |
| 1876 | ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr); |
| 1877 | } |
| 1878 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1879 | # warn about #if 0 |
| 1880 | if ($line =~ /^.#\s*if\s+0\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1881 | CHK("if this code is redundant consider removing it\n" . |
| 1882 | $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 1885 | # check for needless kfree() checks |
| 1886 | if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { |
| 1887 | my $expr = $1; |
| 1888 | if ($line =~ /\bkfree\(\Q$expr\E\);/) { |
| 1889 | WARN("kfree(NULL) is safe this check is probabally not required\n" . $hereprev); |
| 1890 | } |
| 1891 | } |
| 1892 | |
Andy Whitcroft | 00df344 | 2007-06-08 13:47:06 -0700 | [diff] [blame] | 1893 | # warn about #ifdefs in C files |
| 1894 | # if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { |
| 1895 | # print "#ifdef in C files should be avoided\n"; |
| 1896 | # print "$herecurr"; |
| 1897 | # $clean = 0; |
| 1898 | # } |
| 1899 | |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1900 | # warn about spacing in #ifdefs |
| 1901 | if ($line =~ /^.#\s*(ifdef|ifndef|elif)\s\s+/) { |
| 1902 | ERROR("exactly one space required after that #$1\n" . $herecurr); |
| 1903 | } |
| 1904 | |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1905 | # check for spinlock_t definitions without a comment. |
| 1906 | if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { |
| 1907 | my $which = $1; |
| 1908 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1909 | CHK("$1 definition without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1910 | } |
| 1911 | } |
| 1912 | # check for memory barriers without a comment. |
| 1913 | if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { |
| 1914 | if (!ctx_has_comment($first_line, $linenr)) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1915 | CHK("memory barrier without comment\n" . $herecurr); |
Andy Whitcroft | 4a0df2e | 2007-06-08 13:46:39 -0700 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | # check of hardware specific defines |
Andy Whitcroft | 22f2a2e | 2007-08-10 13:01:03 -0700 | [diff] [blame] | 1919 | if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1920 | CHK("architecture specific defines should be avoided\n" . $herecurr); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1921 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1922 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1923 | # check the location of the inline attribute, that it is between |
| 1924 | # storage class and type. |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1925 | if ($line =~ /\b$Type\s+$Inline\b/ || |
| 1926 | $line =~ /\b$Inline\s+$Storage\b/) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1927 | ERROR("inline keyword should sit between storage class and type\n" . $herecurr); |
| 1928 | } |
| 1929 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1930 | # Check for __inline__ and __inline, prefer inline |
| 1931 | if ($line =~ /\b(__inline__|__inline)\b/) { |
| 1932 | WARN("plain inline is preferred over $1\n" . $herecurr); |
| 1933 | } |
| 1934 | |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 1935 | # check for new externs in .c files. |
| 1936 | if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) { |
| 1937 | WARN("externs should be avoided in .c files\n" . $herecurr); |
| 1938 | } |
| 1939 | |
| 1940 | # checks for new __setup's |
| 1941 | if ($rawline =~ /\b__setup\("([^"]*)"/) { |
| 1942 | my $name = $1; |
| 1943 | |
| 1944 | if (!grep(/$name/, @setup_docs)) { |
| 1945 | CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); |
| 1946 | } |
Andy Whitcroft | 653d487 | 2007-06-23 17:16:34 -0700 | [diff] [blame] | 1947 | } |
Andy Whitcroft | 9c0ca6f | 2007-10-16 23:29:38 -0700 | [diff] [blame] | 1948 | |
| 1949 | # check for pointless casting of kmalloc return |
| 1950 | if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { |
| 1951 | WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); |
| 1952 | } |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1953 | |
| 1954 | # check for gcc specific __FUNCTION__ |
| 1955 | if ($line =~ /__FUNCTION__/) { |
| 1956 | WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); |
| 1957 | } |
Andy Whitcroft | 773647a | 2008-03-28 14:15:58 -0700 | [diff] [blame] | 1958 | |
| 1959 | # check for semaphores used as mutexes |
| 1960 | if ($line =~ /\b(DECLARE_MUTEX|init_MUTEX)\s*\(/) { |
| 1961 | WARN("mutexes are preferred for single holder semaphores\n" . $herecurr); |
| 1962 | } |
| 1963 | # check for semaphores used as mutexes |
| 1964 | if ($line =~ /\binit_MUTEX_LOCKED\s*\(/) { |
| 1965 | WARN("consider using a completion\n" . $herecurr); |
| 1966 | } |
| 1967 | # recommend strict_strto* over simple_strto* |
| 1968 | if ($line =~ /\bsimple_(strto.*?)\s*\(/) { |
| 1969 | WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr); |
| 1970 | } |
| 1971 | |
| 1972 | # use of NR_CPUS is usually wrong |
| 1973 | # ignore definitions of NR_CPUS and usage to define arrays as likely right |
| 1974 | if ($line =~ /\bNR_CPUS\b/ && |
| 1975 | $line !~ /^.#\s*define\s+NR_CPUS\s+/ && |
| 1976 | $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/) |
| 1977 | { |
| 1978 | WARN("usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); |
| 1979 | } |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | # If we have no input at all, then there is nothing to report on |
| 1983 | # so just keep quiet. |
| 1984 | if ($#rawlines == -1) { |
| 1985 | exit(0); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 1988 | # In mailback mode only produce a report in the negative, for |
| 1989 | # things that appear to be patches. |
| 1990 | if ($mailback && ($clean == 1 || !$is_patch)) { |
| 1991 | exit(0); |
| 1992 | } |
| 1993 | |
| 1994 | # This is not a patch, and we are are in 'no-patch' mode so |
| 1995 | # just keep quiet. |
| 1996 | if (!$chk_patch && !$is_patch) { |
| 1997 | exit(0); |
| 1998 | } |
| 1999 | |
| 2000 | if (!$is_patch) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 2001 | ERROR("Does not appear to be a unified-diff format patch\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 2002 | } |
| 2003 | if ($is_patch && $chk_signoff && $signoff == 0) { |
Andy Whitcroft | de7d4f0 | 2007-07-15 23:37:22 -0700 | [diff] [blame] | 2004 | ERROR("Missing Signed-off-by: line(s)\n"); |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 2007 | print report_dump(); |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 2008 | if ($summary && !($clean == 1 && $quiet == 1)) { |
| 2009 | print "$filename " if ($summary_file); |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 2010 | print "total: $cnt_error errors, $cnt_warn warnings, " . |
| 2011 | (($check)? "$cnt_chk checks, " : "") . |
| 2012 | "$cnt_lines lines checked\n"; |
| 2013 | print "\n" if ($quiet == 0); |
Andy Whitcroft | f0a594c | 2007-07-19 01:48:34 -0700 | [diff] [blame] | 2014 | } |
Andy Whitcroft | 8905a67 | 2007-11-28 16:21:06 -0800 | [diff] [blame] | 2015 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 2016 | if ($clean == 1 && $quiet == 0) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 2017 | print "$vname has no obvious style problems and is ready for submission.\n" |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 2018 | } |
| 2019 | if ($clean == 0 && $quiet == 0) { |
Andy Whitcroft | c2fdda0 | 2008-02-08 04:20:54 -0800 | [diff] [blame] | 2020 | print "$vname has style problems, please review. If any of these errors\n"; |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 2021 | print "are false positives report them to the maintainer, see\n"; |
| 2022 | print "CHECKPATCH in MAINTAINERS.\n"; |
| 2023 | } |
Andy Whitcroft | 13214ad | 2008-02-08 04:22:03 -0800 | [diff] [blame] | 2024 | |
Andy Whitcroft | 0a920b5 | 2007-06-01 00:46:48 -0700 | [diff] [blame] | 2025 | return $clean; |
| 2026 | } |