]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ng_expr_info: more complete analysis passes
authorJustin Viiret <justin.viiret@intel.com>
Thu, 8 Jun 2017 00:33:23 +0000 (10:33 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Fri, 9 Jun 2017 00:12:03 +0000 (10:12 +1000)
src/hs.cpp
src/nfagraph/ng_expr_info.cpp
src/nfagraph/ng_expr_info.h

index 3345934797cf3791e11554064db09d7968297011..e3c1f811c996bbb471dd2707bd56a843905e7856 100644 (file)
 #include "compiler/error.h"
 #include "nfagraph/ng.h"
 #include "nfagraph/ng_expr_info.h"
-#include "nfagraph/ng_extparam.h"
-#include "nfagraph/ng_fuzzy.h"
-#include "parser/parse_error.h"
 #include "parser/Parser.h"
+#include "parser/parse_error.h"
 #include "parser/prefilter.h"
 #include "parser/unsupported.h"
 #include "util/compile_error.h"
@@ -394,14 +392,7 @@ hs_error_t hs_expression_info_int(const char *expression, unsigned int flags,
             throw ParseError("Internal error.");
         }
 
-        // validate graph's suitability for fuzzing
-        validate_fuzzy_compile(*g, expr.edit_distance, expr.utf8, cc.grey);
-
-        // fuzz graph - this must happen before any transformations are made
-        make_fuzzy(*g, expr.edit_distance, cc.grey);
-
-        propagateExtendedParams(*g, expr, rm);
-        fillExpressionInfo(rm, *g, expr, &local_info);
+        fillExpressionInfo(rm, cc, *g, expr, &local_info);
     }
     catch (const CompileError &e) {
         // Compiler error occurred
index 6a625ddf7947a7eb3da414f4996765941f0e6179..5f5bbea749aa81fd046eba9f7d9d20a3554f2aad 100644 (file)
 #include "ng_asserts.h"
 #include "ng_depth.h"
 #include "ng_edge_redundancy.h"
+#include "ng_extparam.h"
+#include "ng_fuzzy.h"
 #include "ng_holder.h"
+#include "ng_prune.h"
 #include "ng_reports.h"
 #include "ng_util.h"
 #include "ue2common.h"
+#include "compiler/expression_info.h"
 #include "parser/position.h" // for POS flags
 #include "util/boundary_reports.h"
 #include "util/compile_context.h"
@@ -135,15 +139,48 @@ bool hasOffsetAdjust(const ReportManager &rm, const NGHolder &g) {
     return false;
 }
 
-void fillExpressionInfo(ReportManager &rm, NGHolder &g,
-                        const ExpressionInfo &expr, hs_expr_info *info) {
+void fillExpressionInfo(ReportManager &rm, const CompileContext &cc,
+                        NGHolder &g, ExpressionInfo &expr,
+                        hs_expr_info *info) {
     assert(info);
 
+    // remove reports that aren't on vertices connected to accept.
+    clearReports(g);
+
+    assert(allMatchStatesHaveReports(g));
+
+    /*
+     * Note: the following set of analysis passes / transformations should
+     * match those in NG::addGraph().
+     */
+
     /* ensure utf8 starts at cp boundary */
     ensureCodePointStart(rm, g, expr);
+
+    if (can_never_match(g)) {
+        throw CompileError(expr.index, "Pattern can never match.");
+    }
+
+    // validate graph's suitability for fuzzing
+    validate_fuzzy_compile(g, expr.edit_distance, expr.utf8, cc.grey);
+
     resolveAsserts(rm, g, expr);
+    assert(allMatchStatesHaveReports(g));
+
+    // fuzz graph - this must happen before any transformations are made
+    make_fuzzy(g, expr.edit_distance, cc.grey);
+
+    pruneUseless(g);
+    pruneEmptyVertices(g);
+
+    if (can_never_match(g)) {
+        throw CompileError(expr.index, "Pattern can never match.");
+    }
+
     optimiseVirtualStarts(g);
 
+    propagateExtendedParams(g, expr, rm);
+
     removeLeadingVirtualVerticesFromRoot(g, g.start);
     removeLeadingVirtualVerticesFromRoot(g, g.startDs);
 
index e518738c49113a8ba95f9201bde5ea33d36ccacb..f9bd68093929761a19cc13dbbe053181ee8045e1 100644 (file)
@@ -41,9 +41,10 @@ namespace ue2 {
 class ExpressionInfo;
 class NGHolder;
 class ReportManager;
+struct CompileContext;
 
-void fillExpressionInfo(ReportManager &rm, NGHolder &g,
-                        const ExpressionInfo &expr, hs_expr_info *info);
+void fillExpressionInfo(ReportManager &rm, const CompileContext &cc,
+                        NGHolder &g, ExpressionInfo &expr, hs_expr_info *info);
 
 } // namespace ue2