aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@canonical.com>2009-01-06 17:41:27 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 18:59:17 -0500
commit4635f4fbaf51555509c747eed02a7e7a580ae1e1 (patch)
treed3d9d3d26b1c7d302c1200110c5d51b5340183f6 /scripts
parent8b1b33786b06a222cf3430b1bf942a3681532104 (diff)
checkpatch: track #ifdef/#else/#endif when tracking blocks
When picking up a complete statement or block for analysis we cannot simply track open/close/etc parenthesis we must take into account preprocessor section boundaries. Signed-off-by: Andy Whitcroft <apw@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 67b0c9faa32d..906624c0e9e6 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -405,6 +405,7 @@ sub ctx_statement_block {
405 405
406 my $type = ''; 406 my $type = '';
407 my $level = 0; 407 my $level = 0;
408 my @stack = ([$type, $level]);
408 my $p; 409 my $p;
409 my $c; 410 my $c;
410 my $len = 0; 411 my $len = 0;
@@ -436,6 +437,16 @@ sub ctx_statement_block {
436 $remainder = substr($blk, $off); 437 $remainder = substr($blk, $off);
437 438
438 #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n"; 439 #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
440
441 # Handle nested #if/#else.
442 if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
443 push(@stack, [ $type, $level ]);
444 } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
445 ($type, $level) = @{$stack[$#stack - 1]};
446 } elsif ($remainder =~ /^#\s*endif\b/) {
447 ($type, $level) = @{pop(@stack)};
448 }
449
439 # Statement ends at the ';' or a close '}' at the 450 # Statement ends at the ';' or a close '}' at the
440 # outermost level. 451 # outermost level.
441 if ($level == 0 && $c eq ';') { 452 if ($level == 0 && $c eq ';') {
@@ -582,11 +593,22 @@ sub ctx_block_get {
582 my @res = (); 593 my @res = ();
583 594
584 my $level = 0; 595 my $level = 0;
596 my @stack = ($level);
585 for ($line = $start; $remain > 0; $line++) { 597 for ($line = $start; $remain > 0; $line++) {
586 next if ($rawlines[$line] =~ /^-/); 598 next if ($rawlines[$line] =~ /^-/);
587 $remain--; 599 $remain--;
588 600
589 $blk .= $rawlines[$line]; 601 $blk .= $rawlines[$line];
602
603 # Handle nested #if/#else.
604 if ($rawlines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
605 push(@stack, $level);
606 } elsif ($rawlines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
607 $level = $stack[$#stack - 1];
608 } elsif ($rawlines[$line] =~ /^.\s*#\s*endif\b/) {
609 $level = pop(@stack);
610 }
611
590 foreach my $c (split(//, $rawlines[$line])) { 612 foreach my $c (split(//, $rawlines[$line])) {
591 ##print "C<$c>L<$level><$open$close>O<$off>\n"; 613 ##print "C<$c>L<$level><$open$close>O<$off>\n";
592 if ($off > 0) { 614 if ($off > 0) {