r2186 - duplicates detector prototype
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 29 Aug 2008 18:32:35 +0000 (18:32 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 29 Aug 2008 18:32:35 +0000 (18:32 +0000)
inc/code.php

index d0e7625eb2db3e71e470023c0e2f114eb05419e2..07ea9636e69427423d9216d6609d9dd06f0f85f8 100644 (file)
@@ -775,6 +775,34 @@ function getRackCodeWarnings ()
                        default:
                                break;
                }
+       // Duplicates. Use the same hash function we used to.
+       $fpcache = array ('SYNT_DEFINITION' => array(), 'SYNT_GRANT' => array());
+       foreach ($rackCode as $sentence)
+               switch ($sentence['type'])
+               {
+                       case 'SYNT_DEFINITION':
+                               $fp = hash (PASSWORD_HASH, serialize (effectiveValue ($sentence['definition'])));
+                               if (isset ($fpcache[$sentence['type']][$fp]))
+                                       $ret[] = array
+                                       (
+                                               'header' => 'line ' . $sentence['lineno'],
+                                               'class' => 'warning',
+                                               'text' => 'Effective definition equals that at line ' . $fpcache[$sentence['type']][$fp]
+                                       );
+                               $fpcache[$sentence['type']][$fp] = $sentence['lineno'];
+                               break;
+                       case 'SYNT_GRANT':
+                               $fp = hash (PASSWORD_HASH, serialize (effectiveValue ($sentence['condition'])));
+                               if (isset ($fpcache[$sentence['type']][$fp]))
+                                       $ret[] = array
+                                       (
+                                               'header' => 'line ' . $sentence['lineno'],
+                                               'class' => 'warning',
+                                               'text' => 'Effective condition equals that at line ' . $fpcache[$sentence['type']][$fp]
+                                       );
+                               $fpcache[$sentence['type']][$fp] = $sentence['lineno'];
+                               break;
+               }
        // bail out
        $nwarnings = count ($ret);
        $ret[] = array
@@ -958,4 +986,12 @@ function invariantExpression ($expr)
        }
 }
 
+// FIXME: First do line number stripping, otherwise hashes will always differ even
+// for the obviously equivalent expressions. In some longer term mean transform the
+// expression into minimalistic and ordered form.
+function effectiveValue ($expr)
+{
+       return $expr;
+}
+
 ?>