aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@shadowen.org>2008-07-24 00:29:10 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-24 13:47:26 -0400
commit1f65f947a6a875e1fe7867dc08e981c4101d435d (patch)
tree2dec76eed9d3dd6a48bc226fbe3a6d2fa813af9c
parentd2506586586c59f5db0e2ce00d5d31ccec6260b8 (diff)
checkpatch: add checks for question mark and colon spacing
Add checks for the question mark colon operator spacing, and also check the other uses of colon. Colon means a number of things: - it introduces the else part of the ?: operator, - it terminates a goto label, - it terminates the case value, - it separates the identifier from the bit size on bit fields, and - it is used to introduce option types in asm(). Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rwxr-xr-xscripts/checkpatch.pl81
1 files changed, 72 insertions, 9 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8a3b0fd67ad7..88027f237cdf 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -689,17 +689,20 @@ sub cat_vet {
689my $av_preprocessor = 0; 689my $av_preprocessor = 0;
690my $av_pending; 690my $av_pending;
691my @av_paren_type; 691my @av_paren_type;
692my $av_pend_colon;
692 693
693sub annotate_reset { 694sub annotate_reset {
694 $av_preprocessor = 0; 695 $av_preprocessor = 0;
695 $av_pending = '_'; 696 $av_pending = '_';
696 @av_paren_type = ('E'); 697 @av_paren_type = ('E');
698 $av_pend_colon = 'O';
697} 699}
698 700
699sub annotate_values { 701sub annotate_values {
700 my ($stream, $type) = @_; 702 my ($stream, $type) = @_;
701 703
702 my $res; 704 my $res;
705 my $var = '_' x length($stream);
703 my $cur = $stream; 706 my $cur = $stream;
704 707
705 print "$stream\n" if ($dbg_values > 1); 708 print "$stream\n" if ($dbg_values > 1);
@@ -784,7 +787,12 @@ sub annotate_values {
784 $av_pending = 'N'; 787 $av_pending = 'N';
785 $type = 'N'; 788 $type = 'N';
786 789
787 } elsif ($cur =~/^(return|case|else|goto)/o) { 790 } elsif ($cur =~/^(case)/o) {
791 print "CASE($1)\n" if ($dbg_values > 1);
792 $av_pend_colon = 'C';
793 $type = 'N';
794
795 } elsif ($cur =~/^(return|else|goto)/o) {
788 print "KEYWORD($1)\n" if ($dbg_values > 1); 796 print "KEYWORD($1)\n" if ($dbg_values > 1);
789 $type = 'N'; 797 $type = 'N';
790 798
@@ -809,6 +817,15 @@ sub annotate_values {
809 $type = 'V'; 817 $type = 'V';
810 $av_pending = 'V'; 818 $av_pending = 'V';
811 819
820 } elsif ($cur =~ /^($Ident\s*):/) {
821 if ($type eq 'E') {
822 $av_pend_colon = 'L';
823 } elsif ($type eq 'T') {
824 $av_pend_colon = 'B';
825 }
826 print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
827 $type = 'V';
828
812 } elsif ($cur =~ /^($Ident|$Constant)/o) { 829 } elsif ($cur =~ /^($Ident|$Constant)/o) {
813 print "IDENT($1)\n" if ($dbg_values > 1); 830 print "IDENT($1)\n" if ($dbg_values > 1);
814 $type = 'V'; 831 $type = 'V';
@@ -820,8 +837,24 @@ sub annotate_values {
820 } elsif ($cur =~/^(;|{|})/) { 837 } elsif ($cur =~/^(;|{|})/) {
821 print "END($1)\n" if ($dbg_values > 1); 838 print "END($1)\n" if ($dbg_values > 1);
822 $type = 'E'; 839 $type = 'E';
840 $av_pend_colon = 'O';
841
842 } elsif ($cur =~ /^(\?)/o) {
843 print "QUESTION($1)\n" if ($dbg_values > 1);
844 $type = 'N';
845
846 } elsif ($cur =~ /^(:)/o) {
847 print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
848
849 substr($var, length($res), 1, $av_pend_colon);
850 if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
851 $type = 'E';
852 } else {
853 $type = 'N';
854 }
855 $av_pend_colon = 'O';
823 856
824 } elsif ($cur =~ /^(;|\?|:|\[)/o) { 857 } elsif ($cur =~ /^(;|\[)/o) {
825 print "CLOSE($1)\n" if ($dbg_values > 1); 858 print "CLOSE($1)\n" if ($dbg_values > 1);
826 $type = 'N'; 859 $type = 'N';
827 860
@@ -840,7 +873,7 @@ sub annotate_values {
840 } 873 }
841 } 874 }
842 875
843 return $res; 876 return ($res, $var);
844} 877}
845 878
846sub possible { 879sub possible {
@@ -1294,12 +1327,14 @@ sub process {
1294 1327
1295 # Track the 'values' across context and added lines. 1328 # Track the 'values' across context and added lines.
1296 my $opline = $line; $opline =~ s/^./ /; 1329 my $opline = $line; $opline =~ s/^./ /;
1297 my $curr_values = annotate_values($opline . "\n", $prev_values); 1330 my ($curr_values, $curr_vars) =
1331 annotate_values($opline . "\n", $prev_values);
1298 $curr_values = $prev_values . $curr_values; 1332 $curr_values = $prev_values . $curr_values;
1299 if ($dbg_values) { 1333 if ($dbg_values) {
1300 my $outline = $opline; $outline =~ s/\t/ /g; 1334 my $outline = $opline; $outline =~ s/\t/ /g;
1301 print "$linenr > .$outline\n"; 1335 print "$linenr > .$outline\n";
1302 print "$linenr > $curr_values\n"; 1336 print "$linenr > $curr_values\n";
1337 print "$linenr > $curr_vars\n";
1303 } 1338 }
1304 $prev_values = substr($curr_values, -1); 1339 $prev_values = substr($curr_values, -1);
1305 1340
@@ -1490,7 +1525,8 @@ sub process {
1490 <<=|>>=|<=|>=|==|!=| 1525 <<=|>>=|<=|>=|==|!=|
1491 \+=|-=|\*=|\/=|%=|\^=|\|=|&=| 1526 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
1492 =>|->|<<|>>|<|>|=|!|~| 1527 =>|->|<<|>>|<|>|=|!|~|
1493 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% 1528 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
1529 \?|:
1494 }x; 1530 }x;
1495 my @elements = split(/($ops|;)/, $opline); 1531 my @elements = split(/($ops|;)/, $opline);
1496 my $off = 0; 1532 my $off = 0;
@@ -1554,6 +1590,9 @@ sub process {
1554 # print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n"; 1590 # print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n";
1555 #} 1591 #}
1556 1592
1593 # Get the full operator variant.
1594 my $opv = $op . substr($curr_vars, $off, 1);
1595
1557 # Ignore operators passed as parameters. 1596 # Ignore operators passed as parameters.
1558 if ($op_type ne 'V' && 1597 if ($op_type ne 'V' &&
1559 $ca =~ /\s$/ && $cc =~ /^\s*,/) { 1598 $ca =~ /\s$/ && $cc =~ /^\s*,/) {
@@ -1571,8 +1610,10 @@ sub process {
1571 # // is a comment 1610 # // is a comment
1572 } elsif ($op eq '//') { 1611 } elsif ($op eq '//') {
1573 1612
1574 # -> should have no spaces 1613 # No spaces for:
1575 } elsif ($op eq '->') { 1614 # ->
1615 # : when part of a bitfield
1616 } elsif ($op eq '->' || $opv eq ':B') {
1576 if ($ctx =~ /Wx.|.xW/) { 1617 if ($ctx =~ /Wx.|.xW/) {
1577 ERROR("spaces prohibited around that '$op' $at\n" . $hereptr); 1618 ERROR("spaces prohibited around that '$op' $at\n" . $hereptr);
1578 } 1619 }
@@ -1628,11 +1669,33 @@ sub process {
1628 $hereptr); 1669 $hereptr);
1629 } 1670 }
1630 1671
1672 # A colon needs no spaces before when it is
1673 # terminating a case value or a label.
1674 } elsif ($opv eq ':C' || $opv eq ':L') {
1675 if ($ctx =~ /Wx./) {
1676 ERROR("space prohibited before that '$op' $at\n" . $hereptr);
1677 }
1678
1631 # All the others need spaces both sides. 1679 # All the others need spaces both sides.
1632 } elsif ($ctx !~ /[EWC]x[CWE]/) { 1680 } elsif ($ctx !~ /[EWC]x[CWE]/) {
1681 my $ok = 0;
1682
1633 # Ignore email addresses <foo@bar> 1683 # Ignore email addresses <foo@bar>
1634 if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) && 1684 if (($op eq '<' &&
1635 !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) { 1685 $cc =~ /^\S+\@\S+>/) ||
1686 ($op eq '>' &&
1687 $ca =~ /<\S+\@\S+$/))
1688 {
1689 $ok = 1;
1690 }
1691
1692 # Ignore ?:
1693 if (($opv eq ':O' && $ca =~ /\?$/) ||
1694 ($op eq '?' && $cc =~ /^:/)) {
1695 $ok = 1;
1696 }
1697
1698 if ($ok == 0) {
1636 ERROR("spaces required around that '$op' $at\n" . $hereptr); 1699 ERROR("spaces required around that '$op' $at\n" . $hereptr);
1637 } 1700 }
1638 } 1701 }