From 482e1ef931d509e2c7f91fecc341a3d88fe46fd6 Mon Sep 17 00:00:00 2001 From: Alex Coyte Date: Wed, 5 Jul 2017 11:00:39 +1000 Subject: [PATCH] Ensure that reports would be sustained after self loop is removed Approximante matching means that is now possible to get a non-standard report on a cyclic during edge redundancy passes which means checks are now needed. --- src/nfagraph/ng_edge_redundancy.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/nfagraph/ng_edge_redundancy.cpp b/src/nfagraph/ng_edge_redundancy.cpp index 3ce62c41..1578d2e4 100644 --- a/src/nfagraph/ng_edge_redundancy.cpp +++ b/src/nfagraph/ng_edge_redundancy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016, Intel Corporation + * Copyright (c) 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -181,6 +181,28 @@ bool removeEdgeRedundancyNearCyclesFwd(NGHolder &g, bool ignore_starts) { return dead_count; } +static +bool checkReportsRev(const NGHolder &g, NFAVertex v, + const set &happy) { + if (g[v].reports.empty()) { + return true; + } + + assert(edge(v, g.accept, g).second || edge(v, g.acceptEod, g).second); + + /* an edge to accept takes priority over eod only accept */ + NFAVertex accept = edge(v, g.accept, g).second ? g.accept : g.acceptEod; + + flat_set happy_reports; + for (NFAVertex u : happy) { + if (edge(u, accept, g).second) { + insert(&happy_reports, g[u].reports); + } + } + + return is_subset_of(g[v].reports, happy_reports); +} + /** \brief Redundant self-loop removal (reverse version). * * A self loop on a vertex v can be removed if: @@ -233,7 +255,8 @@ bool removeEdgeRedundancyNearCyclesRev(NGHolder &g) { happy.insert(u); } - if (!happy.empty() && checkVerticesRev(g, sad, happy)) { + if (!happy.empty() && checkVerticesRev(g, sad, happy) + && checkReportsRev(g, v, happy)) { dead_count++; remove_edge(v, v, g); }