]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - scripts/calc-must-ids.pl
Source Format Enforcement (#532)
[thirdparty/squid.git] / scripts / calc-must-ids.pl
index 4ee8441dd59611c942b63c439e700201fa5ef3e7..d18ac11fef480c1e414f336cc84a742779dbe0e2 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-## Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+## Copyright (C) 1996-2020 The Squid Software Foundation and contributors
 ##
 ## Squid software is distributed under GPLv2+ license and includes
 ## contributions from numerous individuals and organizations.
@@ -30,9 +30,10 @@ while ($file = shift @ARGV)  {
 }
 sub FileNameHash
 {
-# Please keep in sync this function with the FileNameHash function in
-# src/base/TextException.cc file
     my($name) = @_;
+
+    # Keep in sync with FileNameHash() in src/base/Here.cc!
+
     $name =~  s/.*\///g;
     my($i) = 0;
     my($j) =0;
@@ -41,26 +42,33 @@ sub FileNameHash
     for($j=0; $j < @na; $j++) {
         $n = $n ^ (271 * ord($na[$j])); 
     }
-    $i = $n ^ ($j *271);
-    
-    # Currently 18bits of a 32 bit integer used  for filename hash 
-    # (max hash=262143),  and 14 bits for storing line number
-    $i = $i % 262143;
-    return $i;
+    return $n ^ ($j *271);
 }
 
 sub ComputeMustIds
 {
     my($file) = @_;
-    my($hash) = FileNameHash($file);
+
+    # Keep in sync with SourceLocation::id() in src/base/Here.cc!
+
+    my $fullHash = &FileNameHash($file);
+    my $hash = $fullHash % 0x3FFFF;
+
     if(!open(IN, "<$file")) {
         printf STDERR "error opening file $file. Ignore ...";
         return;
     }
     while(<IN>) {
         my($line) = $_;
+
+        next if $line =~ /^\s*#/; # ignore simple single-line C++ macros
+        $line =~ s@//.*@@; # strip simple // comments
+        $line =~ s@/[*].*?[*]/@@; # strip simple single-line /* comments */
+
         my($id);
-        if ( $line =~ /^\s*Must\s*\(/  || $line =~ /^\s*throw\s*TexcHere\s*\(/){
+        if ($line =~ /\bMust2?\s*\(/ || # Must(...) and Must2(...)
+            $line =~ /\bTexcHere\s*\(/ || # TexcHere(...)
+            $line =~ /\bHere\s*\(\s*\)/) { # Here()
             $line =~ s/^\s*//;
             $id= ($hash <<14) | ($. & 0x3FFF);
             $id += ERR_DETAIL_EXCEPTION_START;