From fc832b667376bb9416336593572c8ec1608e8b7b Mon Sep 17 00:00:00 2001 From: Watson Date: Thu, 20 Feb 2014 09:06:35 +0900 Subject: [PATCH] [analyzer] update to checker-276 http://clang-analyzer.llvm.org/release_notes.html --- static-analyzer/Reporter.pyc | Bin 11663 -> 10511 bytes static-analyzer/ScanView.pyc | Bin 24415 -> 23231 bytes static-analyzer/libexec/ccc-analyzer | 147 +++++----- static-analyzer/scan-build | 417 +++++++++++++++------------ static-analyzer/scanview.css | 6 +- static-analyzer/set-xcode-analyzer | 11 +- static-analyzer/sorttable.js | 55 ++-- 7 files changed, 343 insertions(+), 293 deletions(-) diff --git a/static-analyzer/Reporter.pyc b/static-analyzer/Reporter.pyc index c215bbac2e3339e745773196a831bb99edc094a9..557d84777946d08841bedd8ea404bfe439b14e01 100644 GIT binary patch delta 1395 zcmeB=?hoQ%{>;mDHiRX3BgYyhMNI|<2K~_D)S_bj^2Czj{5<`FqAdO7jMU`p)FNFY zbF;}`nbL?*HHY~U5vta+xDZyg*@RV-k+8DK^Vs5uP-V+Lmk3qT9O*=;I?O?YjhmA= zV~BD7e=c_-tZe7LMOfA5MLcJTv2p{SH(|pj+wkuuLY0NUEFx413lB__z+bv*!z5W;T& delta 2547 zcmeAV>W}7N{>;nOzHMIMMvgU1j-Ct*4EmwPsYS*5sX6(T`p)?&sro^sNtM3&C7Jno z`oa07Mad{4#U+U)naR3|d5JldRjEajuQH`k!IT*0OH?q$pT&i8Q#Nm5(PX6Dn92WG zDNTjCZL@<6Gc_EOA{$19khv|(PKCTQnOUKl sa>q=buP}#lQ#QvaCa_R$%;dYO^Qd6T9JMW!o3go3-IN+h=D3Cj09{+0{{R30 diff --git a/static-analyzer/ScanView.pyc b/static-analyzer/ScanView.pyc index f99c2b2637aa1635bbaa78b2b97df4e1c7c544e1..b965bf3639095cb37534c63c39cb0377752a1bf7 100644 GIT binary patch delta 1454 zcmcb=k8%H2Mh@oByj*8PSb{flWUwo0GB7achZd(673-HLmK5jb=@%4b=_hBTCTFJ> z=^B}vZQjT(!Aw}$WG?O+!m2hO=ib6dgt9%n%|s}h+`#{buwj$;3fv$<)iuE@gjH>R zE#yLk!!{R)_!FUQlUNxMswQt2&mh8O2@YLu#{#@a$amlPp9iTdu>!Muf6YMw5t$ zhs{S#KNFGpHvhDIPmF1rw%3U<&Czi;7ZF~t_1VTsSlMKgpnHT>Z4M6JL_}0=b_-of oj53|@7GjirjQB)^vdJpZZwUKfa$w9u!m2hG$C?vk4=qkDD%MZU$*F!s{;Hg0p@K2bHM!WRV2qH#Br2ri%}0$sQ=xX*eADbbHC*%3@;WtK^U!uT z7Zrkdug5l4%8i*k#qS>Frfi<m{Y?`-ccn02tvtX diff --git a/static-analyzer/libexec/ccc-analyzer b/static-analyzer/libexec/ccc-analyzer index 60b0185e..4dedc2f6 100755 --- a/static-analyzer/libexec/ccc-analyzer +++ b/static-analyzer/libexec/ccc-analyzer @@ -29,8 +29,9 @@ my $Compiler; my $Clang; my $DefaultCCompiler; my $DefaultCXXCompiler; +my $IsCXX; -if (`uname -a` =~ m/Darwin/) { +if (`uname -a` =~ m/Darwin/) { $DefaultCCompiler = 'clang'; $DefaultCXXCompiler = 'clang++'; } else { @@ -40,17 +41,21 @@ if (`uname -a` =~ m/Darwin/) { if ($FindBin::Script =~ /c\+\+-analyzer/) { $Compiler = $ENV{'CCC_CXX'}; - if (!defined $Compiler) { $Compiler = $DefaultCXXCompiler; } - + if (!defined $Compiler || ! -x $Compiler) { $Compiler = $DefaultCXXCompiler; } + $Clang = $ENV{'CLANG_CXX'}; - if (!defined $Clang) { $Clang = 'clang++'; } + if (!defined $Clang || ! -x $Clang) { $Clang = 'clang++'; } + + $IsCXX = 1 } else { $Compiler = $ENV{'CCC_CC'}; - if (!defined $Compiler) { $Compiler = $DefaultCCompiler; } + if (!defined $Compiler || ! -x $Compiler) { $Compiler = $DefaultCCompiler; } $Clang = $ENV{'CLANG'}; - if (!defined $Clang) { $Clang = 'clang'; } + if (!defined $Clang || ! -x $Clang) { $Clang = 'clang'; } + + $IsCXX = 0 } ##===----------------------------------------------------------------------===## @@ -64,7 +69,7 @@ my $CleanupFile; my $ResultFile; # Remove any stale files at exit. -END { +END { if (defined $ResultFile && -z $ResultFile) { `rm -f $ResultFile`; } @@ -95,7 +100,7 @@ sub ProcessClangFailure { my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_; my $Dir = "$HtmlDir/failures"; mkpath $Dir; - + my $prefix = "clang_crash"; if ($ErrorType eq $ParserRejects) { $prefix = "clang_parser_rejects"; @@ -113,7 +118,7 @@ sub ProcessClangFailure { DIR => $Dir); system $Clang, @$Args, "-E", "-o", $PPFile; close ($PPH); - + # Create the info file. open (OUT, ">", "$PPFile.info.txt") or die "Cannot open $PPFile.info.txt\n"; print OUT abs_path($file), "\n"; @@ -133,7 +138,7 @@ sub ProcessClangFailure { sub GetCCArgs { my $mode = shift; my $Args = shift; - + pipe (FROM_CHILD, TO_PARENT); my $pid = fork(); if ($pid == 0) { @@ -141,7 +146,7 @@ sub GetCCArgs { open(STDOUT,">&", \*TO_PARENT); open(STDERR,">&", \*TO_PARENT); exec $Clang, "-###", $mode, @$Args; - } + } close(TO_PARENT); my $line; while () { @@ -151,11 +156,10 @@ sub GetCCArgs { waitpid($pid,0); close(FROM_CHILD); - + die "could not find clang line\n" if (!defined $line); - # Strip the newline and initial whitspace - chomp $line; - $line =~ s/^\s+//; + # Strip leading and trailing whitespace characters. + $line =~ s/^\s+|\s+$//g; my @items = quotewords('\s+', 0, $line); my $cmd = shift @items; die "cannot find 'clang' in 'clang' command\n" if (!($cmd =~ /clang/)); @@ -203,7 +207,7 @@ sub Analyze { } # Display Ubiviz graph? - if (defined $ENV{'CCC_UBI'}) { + if (defined $ENV{'CCC_UBI'}) { push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph"; } @@ -224,7 +228,7 @@ sub Analyze { } if ($Verbose == 1) { # We MUST print to stderr. Some clients use the stdout output of - # gcc for various purposes. + # gcc for various purposes. print STDERR join(' ', @PrintArgs); print STDERR "\n"; } @@ -235,7 +239,7 @@ sub Analyze { # Capture the STDERR of clang and send it to a temporary file. # Capture the STDOUT of clang and reroute it to ccc-analyzer's STDERR. # We save the output file in the 'crashes' directory if clang encounters - # any problems with the file. + # any problems with the file. pipe (FROM_CHILD, TO_PARENT); my $pid = fork(); if ($pid == 0) { @@ -247,7 +251,7 @@ sub Analyze { close TO_PARENT; my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir); - + while () { print $ofh $_; print STDERR $_; @@ -289,15 +293,15 @@ sub Analyze { # Have we already spotted this unhandled attribute? next if (defined $attributes_not_handled{$1}); $attributes_not_handled{$1} = 1; - + # Get the name of the attribute file. my $dir = "$HtmlDir/failures"; my $afile = "$dir/attribute_ignored_$1.txt"; - + # Only create another preprocessed file if the attribute file # doesn't exist yet. next if (-e $afile); - + # Add this file to the list of files that contained this attribute. # Generate a preprocessed file if we haven't already. if (!(defined $ppfile)) { @@ -315,7 +319,7 @@ sub Analyze { } } } - + unlink($ofile); } @@ -325,11 +329,6 @@ sub Analyze { my %CompileOptionMap = ( '-nostdinc' => 0, - '-fblocks' => 0, - '-fno-builtin' => 0, - '-fobjc-gc-only' => 0, - '-fobjc-gc' => 0, - '-ffreestanding' => 0, '-include' => 1, '-idirafter' => 1, '-imacros' => 1, @@ -346,18 +345,16 @@ my %LinkerOptionMap = ( ); my %CompilerLinkerOptionMap = ( - '-fobjc-arc' => 0, - '-fno-objc-arc' => 0, - '-fobjc-abi-version' => 0, # This is really a 1 argument, but always has '=' - '-fobjc-legacy-dispatch' => 0, + '-Wwrite-strings' => 0, + '-ftrapv-handler' => 1, # specifically call out separated -f flag '-mios-simulator-version-min' => 0, # This really has 1 argument, but always has '=' '-isysroot' => 1, '-arch' => 1, '-m32' => 0, '-m64' => 0, '-stdlib' => 0, # This is really a 1 argument, but always has '=' + '-target' => 1, '-v' => 0, - '-fpascal-strings' => 0, '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '=' '-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '=' ); @@ -384,22 +381,23 @@ my %IgnoredOptionMap = ( ); my %LangMap = ( - 'c' => 'c', + 'c' => $IsCXX ? 'c++' : 'c', 'cp' => 'c++', 'cpp' => 'c++', 'cxx' => 'c++', 'txx' => 'c++', 'cc' => 'c++', 'C' => 'c++', - 'ii' => 'c++', - 'i' => 'c-cpp-output', + 'ii' => 'c++-cpp-output', + 'i' => $IsCXX ? 'c++-cpp-output' : 'c-cpp-output', 'm' => 'objective-c', 'mi' => 'objective-c-cpp-output', - 'mm' => 'objective-c++' + 'mm' => 'objective-c++', + 'mii' => 'objective-c++-cpp-output', ); my %UniqueOptions = ( - '-isysroot' => 0 + '-isysroot' => 0 ); ##----------------------------------------------------------------------------## @@ -427,8 +425,8 @@ my %Uniqued; # Forward arguments to gcc. my $Status = system($Compiler,@ARGV); -if (defined $ENV{'CCC_ANALYZER_LOG'}) { - print "$Compiler @ARGV\n"; +if (defined $ENV{'CCC_ANALYZER_LOG'}) { + print STDERR "$Compiler @ARGV\n"; } if ($Status) { exit($Status >> 8); } @@ -451,10 +449,13 @@ my $InternalStats = $ENV{'CCC_ANALYZER_INTERNAL_STATS'}; my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'}; if (!defined $OutputFormat) { $OutputFormat = "html"; } +# Get the config options. +my $ConfigOptions = $ENV{'CCC_ANALYZER_CONFIG'}; + # Determine the level of verbosity. my $Verbose = 0; -if (defined $ENV{CCC_ANALYZER_VERBOSE}) { $Verbose = 1; } -if (defined $ENV{CCC_ANALYZER_LOG}) { $Verbose = 2; } +if (defined $ENV{'CCC_ANALYZER_VERBOSE'}) { $Verbose = 1; } +if (defined $ENV{'CCC_ANALYZER_LOG'}) { $Verbose = 2; } # Get the HTML output directory. my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'}; @@ -465,7 +466,7 @@ my $HadArch = 0; # Process the arguments. foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { - my $Arg = $ARGV[$i]; + my $Arg = $ARGV[$i]; my ($ArgKey) = split /=/,$Arg,2; # Modes ccc-analyzer supports @@ -491,10 +492,6 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; } next; } - if ($Arg =~ /-m.*/) { - push @CompileOpts,$Arg; - next; - } # Handle the case where there isn't a space after -iquote if ($Arg =~ /-iquote.*/) { push @CompileOpts,$Arg; @@ -513,7 +510,7 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { # and the linker. if (defined $CompilerLinkerOptionMap{$ArgKey}) { my $Cnt = $CompilerLinkerOptionMap{$ArgKey}; - + # Check if this is an option that should have a unique value, and if so # determine if the value was checked before. if ($UniqueOptions{$Arg}) { @@ -523,8 +520,8 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { } $Uniqued{$Arg} = 1; } - - push @CompileOpts,$Arg; + + push @CompileOpts,$Arg; push @LinkOpts,$Arg; while ($Cnt > 0) { @@ -534,7 +531,7 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { } next; } - + # Ignored options. if (defined $IgnoredOptionMap{$ArgKey}) { my $Cnt = $IgnoredOptionMap{$ArgKey}; @@ -543,10 +540,10 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { } next; } - + # Compile mode flags. if ($Arg =~ /^-[D,I,U](.*)$/) { - my $Tmp = $Arg; + my $Tmp = $Arg; if ($1 eq '') { # FIXME: Check if we are going off the end. ++$i; @@ -555,7 +552,12 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { push @CompileOpts,$Tmp; next; } - + + if ($Arg =~ /-m.*/) { + push @CompileOpts,$Arg; + next; + } + # Language. if ($Arg eq '-x') { $Lang = $ARGV[$i+1]; @@ -568,26 +570,23 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { $Output = $ARGV[$i]; next; } - + # Get the link mode. if ($Arg =~ /^-[l,L,O]/) { if ($Arg eq '-O') { push @LinkOpts,'-O1'; } elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; } else { push @LinkOpts,$Arg; } + + # Must pass this along for the __OPTIMIZE__ macro + if ($Arg =~ /^-O/) { push @CompileOpts,$Arg; } next; } - + if ($Arg =~ /^-std=/) { push @CompileOpts,$Arg; next; } - -# if ($Arg =~ /^-f/) { -# # FIXME: Not sure if the remaining -fxxxx options have no arguments. -# push @CompileOpts,$Arg; -# push @LinkOpts,$Arg; # FIXME: Not sure if these are link opts. -# } - + # Get the compiler/link mode. if ($Arg =~ /^-F(.+)$/) { my $Tmp = $Arg; @@ -610,7 +609,13 @@ foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { ++$i; next; } - + + if ($Arg =~ /^-f/) { + push @CompileOpts,$Arg; + push @LinkOpts,$Arg; + next; + } + # Handle -Wno-. We don't care about extra warnings, but # we should suppress ones that we don't want to see. if ($Arg =~ /^-Wno-/) { @@ -639,7 +644,7 @@ if ($Action eq 'compile' or $Action eq 'link') { $FileLang = $LangMap{$1}; } } - + # FileLang still not defined? Skip the file. next if (!defined $FileLang); @@ -647,8 +652,8 @@ if ($Action eq 'compile' or $Action eq 'link') { next if (!defined $LangsAccepted{$FileLang}); my @CmdArgs; - my @AnalyzeArgs; - + my @AnalyzeArgs; + if ($FileLang ne 'unknown') { push @CmdArgs, '-x', $FileLang; } @@ -664,7 +669,7 @@ if ($Action eq 'compile' or $Action eq 'link') { if (defined $InternalStats) { push @AnalyzeArgs, "-analyzer-stats"; } - + if (defined $Analyses) { push @AnalyzeArgs, split '\s+', $Analyses; } @@ -680,12 +685,15 @@ if ($Action eq 'compile' or $Action eq 'link') { my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist", DIR => $HtmlDir); $ResultFile = $f; - # If the HtmlDir is not set, we sould clean up the plist files. + # If the HtmlDir is not set, we should clean up the plist files. if (!defined $HtmlDir || -z $HtmlDir) { $CleanupFile = $f; } } } + if (defined $ConfigOptions) { + push @AnalyzeArgs, split '\s+', $ConfigOptions; + } push @CmdArgs, @CompileOpts; push @CmdArgs, $file; @@ -707,4 +715,3 @@ if ($Action eq 'compile' or $Action eq 'link') { } exit($Status >> 8); - diff --git a/static-analyzer/scan-build b/static-analyzer/scan-build index 5428c586..540212ac 100755 --- a/static-analyzer/scan-build +++ b/static-analyzer/scan-build @@ -25,14 +25,16 @@ use Sys::Hostname; my $Verbose = 0; # Verbose output from this script. my $Prog = "scan-build"; -my $BuildName = "checker-275"; -my $BuildDate = "2013-05-23 17:38:31"; +my $BuildName = "checker-276"; +my $BuildDate = "2014-02-18 22:53:01"; my $TERM = $ENV{'TERM'}; my $UseColor = (defined $TERM and $TERM =~ 'xterm-.*color' and -t STDOUT and defined $ENV{'SCAN_BUILD_COLOR'}); -my $UserName = HtmlEscape(getpwuid($<) || 'unknown'); +# Portability: getpwuid is not implemented for Win32 (see Perl language +# reference, perlport), use getlogin instead. +my $UserName = HtmlEscape(getlogin() || getpwuid($<) || 'unknown'); my $HostName = HtmlEscape(hostname() || 'unknown'); my $CurrentDir = HtmlEscape(getcwd()); my $CurrentDirSuffix = basename($CurrentDir); @@ -55,7 +57,7 @@ sub Diag { } else { print "$Prog: @_"; - } + } } sub ErrorDiag { @@ -65,7 +67,7 @@ sub ErrorDiag { print STDERR RESET; } else { print STDERR "$Prog: @_"; - } + } } sub DiagCrashes { @@ -116,35 +118,40 @@ my $ClangVersion; # GetHTMLRunDir - Construct an HTML directory name for the current sub-run. ##----------------------------------------------------------------------------## -sub GetHTMLRunDir { - die "Not enough arguments." if (@_ == 0); - my $Dir = shift @_; +sub GetHTMLRunDir { + die "Not enough arguments." if (@_ == 0); + my $Dir = shift @_; my $TmpMode = 0; if (!defined $Dir) { - $Dir = $ENV{'TMPDIR'}; - if (!defined $Dir) { $Dir = "/tmp"; } + $Dir = $ENV{'TMPDIR'} || $ENV{'TEMP'} || $ENV{'TMP'} || "/tmp"; $TmpMode = 1; } - + # Chop off any trailing '/' characters. while ($Dir =~ /\/$/) { chop $Dir; } # Get current date and time. - my @CurrentTime = localtime(); + my @CurrentTime = localtime(); my $year = $CurrentTime[5] + 1900; my $day = $CurrentTime[3]; my $month = $CurrentTime[4] + 1; - my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day); - - # Determine the run number. + my $hour = $CurrentTime[2]; + my $min = $CurrentTime[1]; + my $sec = $CurrentTime[0]; + + my $TimeString = sprintf("%02d%02d%02d", $hour, $min, $sec); + my $DateString = sprintf("%d-%02d-%02d-%s-$$", + $year, $month, $day, $TimeString); + + # Determine the run number. my $RunNumber; - - if (-d $Dir) { + + if (-d $Dir) { if (! -r $Dir) { DieDiag("directory '$Dir' exists but is not readable.\n"); - } - # Iterate over all files in the specified directory. - my $max = 0; + } + # Iterate over all files in the specified directory. + my $max = 0; opendir(DIR, $Dir); my @FILES = grep { -d "$Dir/$_" } readdir(DIR); closedir(DIR); @@ -161,16 +168,18 @@ sub GetHTMLRunDir { next if ($x[0] != $year); next if ($x[1] != $month); next if ($x[2] != $day); - - if ($x[3] > $max) { - $max = $x[3]; - } + next if ($x[3] != $TimeString); + next if ($x[4] != $$); + + if ($x[5] > $max) { + $max = $x[5]; + } } - + $RunNumber = $max + 1; } else { - + if (-x $Dir) { DieDiag("'$Dir' exists but is not a directory.\n"); } @@ -179,14 +188,14 @@ sub GetHTMLRunDir { DieDiag("The directory '/tmp' does not exist or cannot be accessed.\n"); } - # $Dir does not exist. It will be automatically created by the - # clang driver. Set the run number to 1. + # $Dir does not exist. It will be automatically created by the + # clang driver. Set the run number to 1. $RunNumber = 1; } - + die "RunNumber must be defined!" if (!defined $RunNumber); - + # Append the run number. my $NewDir; if ($TmpMode) { @@ -200,24 +209,24 @@ sub GetHTMLRunDir { } sub SetHtmlEnv { - + die "Wrong number of arguments." if (scalar(@_) != 2); - + my $Args = shift; my $Dir = shift; - + die "No build command." if (scalar(@$Args) == 0); - + my $Cmd = $$Args[0]; if ($Cmd =~ /configure/ || $Cmd =~ /autogen/) { return; } - + if ($Verbose) { Diag("Emitting reports for this run to '$Dir'.\n"); } - + $ENV{'CCC_ANALYZER_HTML'} = $Dir; } @@ -227,18 +236,18 @@ sub SetHtmlEnv { sub ComputeDigest { my $FName = shift; - DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName); - + DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName); + # Use Digest::MD5. We don't have to be cryptographically secure. We're # just looking for duplicate files that come from a non-malicious source. # We use Digest::MD5 because it is a standard Perl module that should - # come bundled on most systems. + # come bundled on most systems. open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n"); binmode FILE; my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest; close(FILE); - - # Return the digest. + + # Return the digest. return $Result; } @@ -257,7 +266,7 @@ sub UpdatePrefix { $Prefix = $x; return; } - + chop $Prefix while (!($x =~ /^\Q$Prefix/)); } @@ -330,15 +339,15 @@ sub AddStatLine { my %AlreadyScanned; sub ScanFile { - + my $Index = shift; my $Dir = shift; my $FName = shift; my $Stats = shift; - + # Compute a digest for the report file. Determine if we have already # scanned a file that looks just like it. - + my $digest = ComputeDigest("$Dir/$FName"); if (defined $AlreadyScanned{$digest}) { @@ -346,12 +355,12 @@ sub ScanFile { system ("rm", "-f", "$Dir/$FName"); return; } - + $AlreadyScanned{$digest} = 1; - + # At this point the report file is not world readable. Make it happen. system ("chmod", "644", "$Dir/$FName"); - + # Scan the report file for tags. open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n"); @@ -376,7 +385,7 @@ sub ScanFile { $BugPathLength = $1; } elsif (/$/) { - $BugLine = $1; + $BugLine = $1; } elsif (/$/) { $BugCategory = $1; @@ -387,7 +396,7 @@ sub ScanFile { } close(IN); - + if (!defined $BugCategory) { $BugCategory = "Other"; } @@ -397,7 +406,7 @@ sub ScanFile { AddStatLine($BugDescription, $Stats, $BugFile); return; } - + push @$Index,[ $FName, $BugCategory, $BugType, $BugFile, $BugLine, $BugPathLength ]; } @@ -411,17 +420,17 @@ sub CopyFiles { my $Dir = shift; my $JS = Cwd::realpath("$RealBin/sorttable.js"); - + DieDiag("Cannot find 'sorttable.js'.\n") - if (! -r $JS); + if (! -r $JS); system ("cp", $JS, "$Dir"); DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n") if (! -r "$Dir/sorttable.js"); - + my $CSS = Cwd::realpath("$RealBin/scanview.css"); - + DieDiag("Cannot find 'scanview.css'.\n") if (! -r $CSS); @@ -484,7 +493,7 @@ sub CalcStats { my @filesFound; my $baseDir; -sub FileWanted { +sub FileWanted { my $baseDirRegEx = quotemeta $baseDir; my $file = $File::Find::name; if ($file =~ /report-.*\.html$/) { @@ -495,14 +504,14 @@ sub FileWanted { } sub Postprocess { - + my $Dir = shift; my $BaseDir = shift; my $AnalyzerStats = shift; my $KeepEmpty = shift; - + die "No directory specified." if (!defined $Dir); - + if (! -d $Dir) { Diag("No bugs found.\n"); return 0; @@ -519,12 +528,12 @@ sub Postprocess { Diag("No bugs found.\n"); return 0; } - - # Scan each report file and build an index. + + # Scan each report file and build an index. my @Index; my @Stats; foreach my $file (@filesFound) { ScanFile(\@Index, $Dir, $file, \@Stats); } - + # Scan the failures directory and use the information in the .info files # to update the common prefix directory. my @failures; @@ -533,7 +542,7 @@ sub Postprocess { opendir(DIR, "$Dir/failures"); @failures = grep { /[.]info.txt$/ && !/attribute_ignored/; } readdir(DIR); closedir(DIR); - opendir(DIR, "$Dir/failures"); + opendir(DIR, "$Dir/failures"); @attributes_ignored = grep { /^attribute_ignored/; } readdir(DIR); closedir(DIR); foreach my $file (@failures) { @@ -541,15 +550,15 @@ sub Postprocess { my $Path = ; if (defined $Path) { UpdatePrefix($Path); } close IN; - } + } } - - # Generate an index.html file. - my $FName = "$Dir/index.html"; + + # Generate an index.html file. + my $FName = "$Dir/index.html"; open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n"); - + # Print out the header. - + print OUT < @@ -580,13 +589,13 @@ function CopyCheckedStateToCheckButtons(SummaryCheckButton) { } function returnObjById( id ) { - if (document.getElementById) + if (document.getElementById) var returnVar = document.getElementById(id); else if (document.all) var returnVar = document.all[id]; - else if (document.layers) + else if (document.layers) var returnVar = document.layers[id]; - return returnVar; + return returnVar; } var NumUnchecked = 0; @@ -643,14 +652,14 @@ ENDTEXT if (defined $BuildName) { print OUT "\n

Results in this analysis run are based on analyzer build $BuildName.

\n" } - + my $TotalBugs = scalar(@Index); print OUT < Bug TypeQuantityDisplay? All Bugs$TotalBugs
ENDTEXT - + my $last_category; for my $key ( @@ -660,14 +669,14 @@ ENDTEXT my $res = $x->[1] cmp $y->[1]; $res = $x->[2] cmp $y->[2] if ($res == 0); $res - } keys %Totals ) + } keys %Totals ) { my $val = $Totals{$key}; my $category = $val->[1]; if (!defined $last_category or $last_category ne $category) { $last_category = $category; print OUT "$category\n"; - } + } my $x = lc $key; $x =~ s/[ ,'":\/()]+/_/g; print OUT ""; @@ -700,19 +709,19 @@ ENDTEXT my $regex; my $InFileRegex; my $InFilePrefix = "File:"; - - if (defined $prefix) { - $regex = qr/^\Q$prefix\E/is; + + if (defined $prefix) { + $regex = qr/^\Q$prefix\E/is; $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is; - } + } for my $row ( sort { $a->[2] cmp $b->[2] } @Index ) { my $x = "$row->[1]:$row->[2]"; $x = lc $x; $x =~ s/[ ,'":\/()]+/_/g; - + my $ReportFile = $row->[0]; - + print OUT ""; print OUT ""; print OUT $row->[1]; @@ -720,16 +729,16 @@ ENDTEXT print OUT ""; print OUT $row->[2]; print OUT ""; - - # Update the file prefix. + + # Update the file prefix. my $fname = $row->[3]; if (defined $regex) { $fname =~ s/$regex//; UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix) } - - print OUT ""; + + print OUT ""; my @fname = split /\//,$fname; if ($#fname > 0) { while ($#fname >= 0) { @@ -742,14 +751,14 @@ ENDTEXT } else { print OUT $fname; - } + } print OUT ""; - + # Print out the quantities. for my $j ( 4 .. 5 ) { - print OUT "$row->[$j]"; + print OUT "$row->[$j]"; } - + # Print the rest of the columns. for (my $j = 6; $j <= $#{$row}; ++$j) { print OUT "$row->[$j]" @@ -757,20 +766,20 @@ ENDTEXT # Emit the "View" link. print OUT "View Report"; - + # Emit REPORTBUG markers. print OUT "\n\n"; - + # End the row. print OUT "\n"; } - + print OUT "\n\n\n"; } if (scalar (@failures) || scalar(@attributes_ignored)) { print OUT "

Analyzer Failures

\n"; - + if (scalar @attributes_ignored) { print OUT "The analyzer's parser ignored the following attributes:

\n"; print OUT "\n"; @@ -800,7 +809,7 @@ ENDTEXT } print OUT "
\n"; } - + if (scalar @failures) { print OUT "

The analyzer had problems processing the following files:

\n"; print OUT "\n"; @@ -826,11 +835,11 @@ ENDTEXT print OUT " \n"; } print OUT "
\n"; - } + } print OUT "

Please consider submitting preprocessed files as bug reports.

\n"; } - - print OUT "\n"; + + print OUT "\n"; close(OUT); CopyFiles($Dir); @@ -846,9 +855,9 @@ ENDTEXT if ($Num > 0 && -r "$Dir/index.html") { Diag("Run 'scan-view $Dir' to examine bug reports.\n"); } - + DiagCrashes($Dir) if (scalar @failures || scalar @attributes_ignored); - + return $Num; } @@ -858,16 +867,16 @@ ENDTEXT sub AddIfNotPresent { my $Args = shift; - my $Arg = shift; + my $Arg = shift; my $found = 0; - + foreach my $k (@$Args) { if ($k eq $Arg) { $found = 1; last; } } - + if ($found == 0) { push @$Args, $Arg; } @@ -876,7 +885,8 @@ sub AddIfNotPresent { sub SetEnv { my $Options = shift @_; foreach my $opt ('CC', 'CXX', 'CLANG', 'CLANG_CXX', - 'CCC_ANALYZER_ANALYSIS', 'CCC_ANALYZER_PLUGINS') { + 'CCC_ANALYZER_ANALYSIS', 'CCC_ANALYZER_PLUGINS', + 'CCC_ANALYZER_CONFIG') { die "$opt is undefined\n" if (!defined $opt); $ENV{$opt} = $Options->{$opt}; } @@ -896,6 +906,9 @@ sub SetEnv { } } +# The flag corresponding to the --override-compiler command line option. +my $OverrideCompiler = 0; + sub RunXcodebuild { my $Args = shift; my $IgnoreErrors = shift; @@ -927,7 +940,13 @@ sub RunXcodebuild { } } close(DETECT_XCODE); - + + # If --override-compiler is explicitely requested, resort to the old + # behavior regardless of Xcode version. + if ($OverrideCompiler) { + $oldBehavior = 1; + } + if ($oldBehavior == 0) { my $OutputDir = $Options->{"OUTPUT_DIR"}; my $CLANG = $Options->{"CLANG"}; @@ -941,10 +960,10 @@ sub RunXcodebuild { return (system(@$Args) >> 8); } - + # Default to old behavior where we insert a bogus compiler. SetEnv($Options); - + # Check if using iPhone SDK 3.0 (simulator). If so the compiler being # used should be gcc-4.2. if (!defined $ENV{"CCC_CC"}) { @@ -960,16 +979,16 @@ sub RunXcodebuild { # Disable PCH files until clang supports them. AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO"); - + # When 'CC' is set, xcodebuild uses it to do all linking, even if we are # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++' # (via c++-analyzer) when linking such files. $ENV{"LDPLUSPLUS"} = $CXXAnalyzer; - - return (system(@$Args) >> 8); + + return (system(@$Args) >> 8); } -sub RunBuildCommand { +sub RunBuildCommand { my $Args = shift; my $IgnoreErrors = shift; my $Cmd = $Args->[0]; @@ -983,39 +1002,39 @@ sub RunBuildCommand { # Setup the environment. SetEnv($Options); - - if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or + + if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or $Cmd =~ /(.*\/?cc[^\/]*$)/ or $Cmd =~ /(.*\/?llvm-gcc[^\/]*$)/ or - $Cmd =~ /(.*\/?clang$)/ or + $Cmd =~ /(.*\/?clang$)/ or $Cmd =~ /(.*\/?ccc-analyzer[^\/]*$)/) { if (!($Cmd =~ /ccc-analyzer/) and !defined $ENV{"CCC_CC"}) { - $ENV{"CCC_CC"} = $1; + $ENV{"CCC_CC"} = $1; } - + shift @$Args; unshift @$Args, $CCAnalyzer; } - elsif ($Cmd =~ /(.*\/?g\+\+[^\/]*$)/ or + elsif ($Cmd =~ /(.*\/?g\+\+[^\/]*$)/ or $Cmd =~ /(.*\/?c\+\+[^\/]*$)/ or $Cmd =~ /(.*\/?llvm-g\+\+[^\/]*$)/ or $Cmd =~ /(.*\/?clang\+\+$)/ or $Cmd =~ /(.*\/?c\+\+-analyzer[^\/]*$)/) { if (!($Cmd =~ /c\+\+-analyzer/) and !defined $ENV{"CCC_CXX"}) { - $ENV{"CCC_CXX"} = $1; - } + $ENV{"CCC_CXX"} = $1; + } shift @$Args; unshift @$Args, $CXXAnalyzer; } - elsif ($IgnoreErrors) { - if ($Cmd eq "make" or $Cmd eq "gmake") { - AddIfNotPresent($Args, "CC=$CCAnalyzer"); - AddIfNotPresent($Args, "CXX=$CXXAnalyzer"); + elsif ($Cmd eq "make" or $Cmd eq "gmake") { + AddIfNotPresent($Args, "CC=$CCAnalyzer"); + AddIfNotPresent($Args, "CXX=$CXXAnalyzer"); + if ($IgnoreErrors) { AddIfNotPresent($Args,"-k"); AddIfNotPresent($Args,"-i"); } - } + } return (system(@$Args) >> 8); } @@ -1025,7 +1044,7 @@ sub RunBuildCommand { ##----------------------------------------------------------------------------## sub DisplayHelp { - + print < [build options] @@ -1039,25 +1058,25 @@ print < - + Specifies the output directory for analyzer reports. Subdirectories will be created as needed to represent separate "runs" of the analyzer. If this option is not specified, a directory is created in /tmp (TMPDIR on Mac OS X) to store the reports. - -h + -h --help Display this message. -k --keep-going - + Add a "keep on going" option to the specified build command. This option currently supports make and xcodebuild. This is a convenience option; one can specify this behavior directly using build options. @@ -1069,41 +1088,41 @@ OPTIONS: title will be used. -plist - + By default the output of scan-build is a set of HTML files. This option outputs the results as a set of .plist files. - + -plist-html - + By default the output of scan-build is a set of HTML files. This option outputs the results as a set of HTML and .plist files. - + --status-bugs - + By default, the exit status of scan-build is the same as the executed build command. Specifying this option causes the exit status of scan-build to be 1 if it found potential bugs and 0 otherwise. - --use-cc [compiler path] + --use-cc [compiler path] --use-cc=[compiler path] - + scan-build analyzes a project by interposing a "fake compiler", which executes a real compiler for compilation and the static analyzer for analysis. Because of the current implementation of interposition, scan-build does not know what compiler your project normally uses. Instead, it simply overrides the CC environment variable, and guesses your default compiler. - + In the future, this interposition mechanism to be improved, but if you need scan-build to use a specific compiler for *compilation* then you can use this option to specify a path to that compiler. --use-c++ [compiler path] --use-c++=[compiler path] - + This is the same as "-use-cc" but for C++ code. - + -v - + Enable verbose output from scan-build. A second and third '-v' increases verbosity. @@ -1115,26 +1134,26 @@ OPTIONS: ADVANCED OPTIONS: -no-failure-reports - + Do not create a 'failures' subdirectory that includes analyzer crash reports and preprocessed source files. -stats - + Generates visitation statistics for the project being analyzed. -maxloop - + Specifiy the number of times a block can be visited before giving up. Default is 4. Increase for more comprehensive coverage at a cost of speed. - + -internal-stats - + Generate internal analyzer statistics. - - --use-analyzer [Xcode|path to clang] + + --use-analyzer [Xcode|path to clang] --use-analyzer=[Xcode|path to clang] - + scan-build uses the 'clang' executable relative to itself for static analysis. One can override this behavior with this option by using the 'clang' packaged with Xcode (on OS X) or from the PATH. @@ -1143,6 +1162,14 @@ ADVANCED OPTIONS: Don't remove the build results directory even if no issues were reported. + --override-compiler + Always resort to the ccc-analyzer even when better interposition methods + are available. + + -analyzer-config + + Provide options to pass through to the analyzer's -analyzer-config flag. + CONTROLLING CHECKERS: A default group of checkers are always run unless explicitly disabled. @@ -1150,7 +1177,7 @@ CONTROLLING CHECKERS: -enable-checker [checker name] -disable-checker [checker name] - + LOADING CHECKERS: Loading external checkers using the clang plugin interface: @@ -1175,7 +1202,7 @@ foreach my $lang ("c", "objective-c", "objective-c++", "c++") { close FROM_CHILD; open(STDOUT,">&", \*TO_PARENT); open(STDERR,">&", \*TO_PARENT); - exec $Clang, ( @PluginLoadCommandline_xclang, '--analyze', '-x', $lang, '-', '-###'); + exec $Clang, ( @PluginLoadCommandline_xclang, '--analyze', '-x', $lang, '-', '-###'); } close(TO_PARENT); while() { @@ -1238,7 +1265,7 @@ if (defined $Clang && -x $Clang) { # append a dot, if an additional domain is added in the next iteration $aggregate .= "."; } - + if ($enabled) { print " + "; } @@ -1266,7 +1293,7 @@ BUILD OPTIONS EXAMPLE scan-build -o /tmp/myhtmldir make -j4 - + The above example causes analysis reports to be deposited into a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. A different subdirectory is created each time scan-build analyzes a project. The analyzer @@ -1314,6 +1341,7 @@ my @AnalysesToRun; my $StoreModel; my $ConstraintsModel; my $InternalStats; +my @ConfigOptions; my $OutputFormat = "html"; my $AnalyzerStats = 0; my $MaxLoop = 0; @@ -1326,9 +1354,9 @@ if (!@ARGV) { } while (@ARGV) { - + # Scan for options we recognize. - + my $arg = $ARGV[0]; if ($arg eq "-h" or $arg eq "--help") { @@ -1336,24 +1364,24 @@ while (@ARGV) { shift @ARGV; next; } - + if ($arg eq '-analyze-headers') { - shift @ARGV; + shift @ARGV; $AnalyzeHeaders = 1; next; } - + if ($arg eq "-o") { shift @ARGV; - + if (!@ARGV) { DieDiag("'-o' option requires a target directory name.\n"); } - + # Construct an absolute path. Uses the current working directory # as a base if the original path was not absolute. $HtmlDir = abs_path(shift @ARGV); - + next; } @@ -1372,7 +1400,7 @@ while (@ARGV) { next; } - + if ($arg eq "-k" or $arg eq "--keep-going") { shift @ARGV; $IgnoreErrors = 1; @@ -1382,7 +1410,7 @@ while (@ARGV) { if ($arg =~ /^--use-cc(=(.+))?$/) { shift @ARGV; my $cc; - + if (!defined $2 || $2 eq "") { if (!@ARGV) { DieDiag("'--use-cc' option requires a compiler executable name.\n"); @@ -1392,15 +1420,15 @@ while (@ARGV) { else { $cc = $2; } - + $ENV{"CCC_CC"} = $cc; next; } - + if ($arg =~ /^--use-c\+\+(=(.+))?$/) { shift @ARGV; - my $cxx; - + my $cxx; + if (!defined $2 || $2 eq "") { if (!@ARGV) { DieDiag("'--use-c++' option requires a compiler executable name.\n"); @@ -1410,23 +1438,23 @@ while (@ARGV) { else { $cxx = $2; } - + $ENV{"CCC_CXX"} = $cxx; next; } - + if ($arg eq "-v") { shift @ARGV; $Verbose++; next; } - + if ($arg eq "-V" or $arg eq "--view") { shift @ARGV; - $ViewResults = 1; + $ViewResults = 1; next; } - + if ($arg eq "--status-bugs") { shift @ARGV; $ExitStatusFoundBugs = 1; @@ -1438,7 +1466,7 @@ while (@ARGV) { $StoreModel = shift @ARGV; next; } - + if ($arg eq "-constraints") { shift @ARGV; $ConstraintsModel = shift @ARGV; @@ -1450,7 +1478,7 @@ while (@ARGV) { $InternalStats = 1; next; } - + if ($arg eq "-plist") { shift @ARGV; $OutputFormat = "plist"; @@ -1461,7 +1489,13 @@ while (@ARGV) { $OutputFormat = "plist-html"; next; } - + + if ($arg eq "-analyzer-config") { + shift @ARGV; + push @ConfigOptions, "-analyzer-config", shift @ARGV; + next; + } + if ($arg eq "-no-failure-reports") { $ENV{"CCC_REPORT_FAILURES"} = 0; next; @@ -1506,9 +1540,15 @@ while (@ARGV) { $KeepEmpty = 1; next; } - + + if ($arg eq "--override-compiler") { + shift @ARGV; + $OverrideCompiler = 1; + next; + } + DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/); - + last; } @@ -1529,8 +1569,8 @@ if (!defined $AnalyzerDiscoveryMethod) { " Consider using --use-analyzer to pick a version of 'clang' to use for static analysis.\n"); } } -} -else { +} +else { if ($AnalyzerDiscoveryMethod =~ /^[Xx]code$/) { my $xcrun = `which xcrun`; chomp $xcrun; @@ -1538,9 +1578,9 @@ else { DieDiag("Cannot find 'xcrun' to find 'clang' for analysis.\n"); } $Clang = `$xcrun -toolchain XcodeDefault -find clang`; - chomp $Clang; + chomp $Clang; if ($Clang eq "") { - DieDiag("No 'clang' executable found by 'xcrun'\n"); + DieDiag("No 'clang' executable found by 'xcrun'\n"); } } else { @@ -1584,13 +1624,17 @@ my $AbsRealBin = Cwd::realpath($RealBin); my $Cmd = "$AbsRealBin/libexec/ccc-analyzer"; my $CmdCXX = "$AbsRealBin/libexec/c++-analyzer"; -if (!defined $Cmd || ! -x $Cmd) { +# Portability: use less strict but portable check -e (file exists) instead of +# non-portable -x (file is executable). On some windows ports -x just checks +# file extension to determine if a file is executable (see Perl language +# reference, perlport) +if (!defined $Cmd || ! -e $Cmd) { $Cmd = "$AbsRealBin/ccc-analyzer"; - DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") if(! -x $Cmd); + DieDiag("'ccc-analyzer' does not exist at '$Cmd'\n") if(! -e $Cmd); } -if (!defined $CmdCXX || ! -x $CmdCXX) { +if (!defined $CmdCXX || ! -e $CmdCXX) { $CmdCXX = "$AbsRealBin/c++-analyzer"; - DieDiag("Executable 'c++-analyzer' does not exist at '$CmdCXX'\n") if(! -x $CmdCXX); + DieDiag("'c++-analyzer' does not exist at '$CmdCXX'\n") if(! -e $CmdCXX); } Diag("Using '$Clang' for static analysis\n"); @@ -1604,6 +1648,7 @@ if ($MaxLoop > 0) { push @AnalysesToRun, "-analyzer-max-loop $MaxLoop"; } # interposition. my $CCC_ANALYZER_ANALYSIS = join ' ',@AnalysesToRun; my $CCC_ANALYZER_PLUGINS = join ' ',@PluginsToLoad; +my $CCC_ANALYZER_CONFIG = join ' ',@ConfigOptions; my %Options = ( 'CC' => $Cmd, 'CXX' => $CmdCXX, @@ -1612,6 +1657,7 @@ my %Options = ( 'VERBOSE' => $Verbose, 'CCC_ANALYZER_ANALYSIS' => $CCC_ANALYZER_ANALYSIS, 'CCC_ANALYZER_PLUGINS' => $CCC_ANALYZER_PLUGINS, + 'CCC_ANALYZER_CONFIG' => $CCC_ANALYZER_CONFIG, 'OUTPUT_DIR' => $HtmlDir ); @@ -1657,4 +1703,3 @@ if (defined $OutputFormat) { } exit $ExitStatus; - diff --git a/static-analyzer/scanview.css b/static-analyzer/scanview.css index a0406f37..cf8a5a6a 100644 --- a/static-analyzer/scanview.css +++ b/static-analyzer/scanview.css @@ -10,7 +10,7 @@ th, table thead { text-align:center; font-weight: bold; font-family: Verdana; white-space:nowrap; -} +} .W { font-size:0px } th, td { padding:5px; padding-left:8px; text-align:left } td.SUMM_DESC { padding-left:12px } @@ -21,7 +21,7 @@ tbody.scrollContent { overflow:auto } table.form_group { background-color: #ccc; - border: 1px solid #333; + border: 1px solid #333; padding: 2px; } @@ -33,7 +33,7 @@ table.form_inner_group { table.form { background-color: #999; - border: 1px solid #333; + border: 1px solid #333; padding: 2px; } diff --git a/static-analyzer/set-xcode-analyzer b/static-analyzer/set-xcode-analyzer index 3076b39d..5ac5c18f 100755 --- a/static-analyzer/set-xcode-analyzer +++ b/static-analyzer/set-xcode-analyzer @@ -8,7 +8,7 @@ import sys if sys.version_info < (2, 7): print "set-xcode-analyzer requires Python 2.7 or later" sys.exit(1) - + import os import subprocess import re @@ -65,7 +65,7 @@ def main(): parser.set_description(__doc__) parser.add_option("--use-checker-build", dest="path", help="Use the Clang located at the provided absolute path, e.g. /Users/foo/checker-1") - parser.add_option("--use-xcode-clang", action="store_const", + parser.add_option("--use-xcode-clang", action="store_const", const="$(CLANG)", dest="default", help="Use the Clang bundled with Xcode") (options, args) = parser.parse_args() @@ -91,7 +91,7 @@ def main(): print "(+) Using the Clang bundled with Xcode" path = options.default isBuiltinAnalyzer = True - + try: xcode_path = subprocess.check_output(["xcode-select", "-print-path"]) except AttributeError: @@ -101,15 +101,14 @@ def main(): # Cut off the 'Developer' dir, as the xcspec lies in another part # of the Xcode.app subtree. xcode_path = os.path.dirname(xcode_path) - + foundSpec = False for x in FindClangSpecs(xcode_path): foundSpec = True ModifySpec(x, isBuiltinAnalyzer, path) - + if foundSpec == False: print "(-) No compiler configuration file was found. Xcode's analyzer has not been updated." if __name__ == '__main__': main() - diff --git a/static-analyzer/sorttable.js b/static-analyzer/sorttable.js index 4352d3be..03ebd926 100644 --- a/static-analyzer/sorttable.js +++ b/static-analyzer/sorttable.js @@ -3,19 +3,19 @@ version 2 7th April 2007 Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ - + Instructions: Download this file Add to your HTML Add class="sortable" to any table you'd like to make sortable Click on the headers to sort - + Thanks to many, many people for contributions and suggestions. Licenced as X11: http://www.kryogenix.org/code/browser/licence.html This basically means: do what you want with it. */ - + var stIsIE = /*@cc_on!@*/false; sorttable = { @@ -26,19 +26,19 @@ sorttable = { arguments.callee.done = true; // kill the timer if (_timer) clearInterval(_timer); - + if (!document.createElement || !document.getElementsByTagName) return; - + sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; - + forEach(document.getElementsByTagName('table'), function(table) { if (table.className.search(/\bsortable\b/) != -1) { sorttable.makeSortable(table); } }); - + }, - + makeSortable: function(table) { if (table.getElementsByTagName('thead').length == 0) { // table doesn't have a tHead. Since it should have, create one and @@ -49,9 +49,9 @@ sorttable = { } // Safari doesn't support table.tHead, sigh if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; - + if (table.tHead.rows.length != 1) return; // can't cope with two header rows - + // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as // "total" rows, for example). This is B&R, since what you're supposed // to do is put them in a tfoot. So, if there are sortbottom rows, @@ -73,7 +73,7 @@ sorttable = { } delete sortbottomrows; } - + // work through each column and calculate its type headrow = table.tHead.rows[0].cells; for (var i=0; i fields. - + hasInputs = (typeof node.getElementsByTagName == 'function') && node.getElementsByTagName('input').length; - + if (node.getAttribute("sorttable_customkey") != null) { return node.getAttribute("sorttable_customkey"); } @@ -240,7 +240,7 @@ sorttable = { } } }, - + reverse: function(tbody) { // reverse the rows in a tbody newrows = []; @@ -252,14 +252,14 @@ sorttable = { } delete newrows; }, - + /* sort functions each sort function takes two parameters, a and b you are comparing a[0] and b[0] */ sort_numeric: function(a,b) { aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); if (isNaN(aa)) aa = 0; - bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); + bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); if (isNaN(bb)) bb = 0; return aa-bb; }, @@ -298,7 +298,7 @@ sorttable = { if (dt1