Print this page
patch cstyle-x86

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/scripts/cstyle.pl
          +++ new/usr/src/tools/scripts/cstyle.pl
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16  # If applicable, add the following below this CDDL HEADER, with the
  17   17  # fields enclosed by brackets "[]" replaced with your own identifying
  18   18  # information: Portions Copyright [yyyy] [name of copyright owner]
  19   19  #
  20   20  # CDDL HEADER END
  21   21  #
  22   22  #
  23   23  # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   24  # Use is subject to license terms.
  25   25  #
  26      -# @(#)cstyle 1.58 98/09/09 (from shannon)
  27      -#ident  "%Z%%M% %I%     %E% SMI"
  28      -#
  29   26  # cstyle - check for some common stylistic errors.
  30   27  #
  31   28  #       cstyle is a sort of "lint" for C coding style.
  32   29  #       It attempts to check for the style used in the
  33   30  #       kernel, sometimes known as "Bill Joy Normal Form".
  34   31  #
  35   32  #       There's a lot this can't check for, like proper indentation
  36   33  #       of code blocks.  There's also a lot more this could check for.
  37   34  #
  38   35  #       A note to the non perl literate:
↓ open down ↓ 436 lines elided ↑ open up ↑
 475  472                  err("missing blank before close comment");
 476  473          }
 477  474          if (/\/\/\S/) {         # C++ comments
 478  475                  err("missing blank after start comment");
 479  476          }
 480  477          # check for unterminated single line comments, but allow them when
 481  478          # they are used to comment out the argument list of a function
 482  479          # declaration.
 483  480          if (/\S.*\/\*/ && !/\S.*\/\*.*\*\// && !/\(\/\*/) {
 484  481                  err("unterminated single line comment");
      482 +        }
      483 +
      484 +        # check that #if doesn't enumerate ISA defines when there are more
      485 +        # concise ways of checking.  E.g., don't do:
      486 +        #     #if defined(__amd64) || defined(__i386)
      487 +        # when there is:
      488 +        #     #ifdef __x86
      489 +        if (/^#if\sdefined\((.*)\)\s\|\|\sdefined\((.*)\)/) {
      490 +                my $first = $1;
      491 +                my $second = $2;
      492 +                ($first, $second) = ($second, $first) if ($first gt $second);
      493 +
      494 +                if (($first eq "__amd64") && ($second eq "__i386")) {
      495 +                        err("#if checking for $first or $second instead of " .
      496 +                            "__x86");
      497 +                }
 485  498          }
 486  499  
 487  500          if (/^(#else|#endif|#include)(.*)$/) {
 488  501                  $prev = $line;
 489  502                  if ($picky) {
 490  503                          my $directive = $1;
 491  504                          my $clause = $2;
 492  505                          # Enforce ANSI rules for #else and #endif: no noncomment
 493  506                          # identifiers are allowed after #endif or #else.  Allow
 494  507                          # C++ comments since they seem to be a fact of life.
↓ open down ↓ 456 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX