From a427a2843b2cc73ae512c350bbf9e1a4e89124ba Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Thu, 14 Jul 2016 13:34:56 +1000 Subject: [PATCH] rose_build_anchored: clean up remapping Note that there are no EOD reports in the anchored matcher raw_dfas. --- src/rose/rose_build_anchored.cpp | 66 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/rose/rose_build_anchored.cpp b/src/rose/rose_build_anchored.cpp index befd0bad..60732ff9 100644 --- a/src/rose/rose_build_anchored.cpp +++ b/src/rose/rose_build_anchored.cpp @@ -173,47 +173,36 @@ void mergeAnchoredDfas(vector> &dfas, } static -void translateReportSet(flat_set *rset, const RoseBuildImpl &tbi) { - flat_set old; - old.swap(*rset); - for (auto report_id : old) { - DEBUG_PRINTF("updating %u -> %u\n", report_id, - tbi.literal_info[report_id].final_id); - rset->insert(tbi.literal_info[report_id].final_id); +void remapAnchoredReports(raw_dfa &rdfa, const RoseBuildImpl &build) { + for (dstate &ds : rdfa.states) { + assert(ds.reports_eod.empty()); // Not used in anchored matcher. + if (ds.reports.empty()) { + continue; + } + + flat_set new_reports; + for (auto id : ds.reports) { + assert(id < build.literal_info.size()); + new_reports.insert(build.literal_info.at(id).final_id); + } + ds.reports = move(new_reports); } } +/** + * \brief Replaces the report ids currently in the dfas (rose graph literal + * ids) with the final id for each literal. + */ static -void remapAnchoredReports(raw_dfa &dfa, const RoseBuildImpl &tbi) { - for (dstate &ds : dfa.states) { - translateReportSet(&ds.reports, tbi); - translateReportSet(&ds.reports_eod, tbi); - } -} - -/* Replaces the report ids currently in the dfas (rose graph literal ids) with - * the final id used by the runtime. */ -static -void remapAnchoredReports(RoseBuildImpl &tbi) { - for (auto it = tbi.anchored_nfas.begin(); it != tbi.anchored_nfas.end(); - ++it) { - for (auto &rdfa : it->second) { +void remapAnchoredReports(RoseBuildImpl &build) { + for (auto &m : build.anchored_nfas) { + for (auto &rdfa : m.second) { assert(rdfa); - remapAnchoredReports(*rdfa, tbi); + remapAnchoredReports(*rdfa, build); } } } -static -void remapIds(flat_set &reports, const vector &litPrograms) { - flat_set new_reports; - for (auto id : reports) { - assert(id < litPrograms.size()); - new_reports.insert(litPrograms.at(id)); - } - reports = move(new_reports); -} - /** * \brief Replace the reports (which are literal final_ids) in the given * raw_dfa with program offsets. @@ -221,8 +210,17 @@ void remapIds(flat_set &reports, const vector &litPrograms) { static void remapIdsToPrograms(raw_dfa &rdfa, const vector &litPrograms) { for (dstate &ds : rdfa.states) { - remapIds(ds.reports, litPrograms); - remapIds(ds.reports_eod, litPrograms); + assert(ds.reports_eod.empty()); // Not used in anchored matcher. + if (ds.reports.empty()) { + continue; + } + + flat_set new_reports; + for (auto id : ds.reports) { + assert(id < litPrograms.size()); + new_reports.insert(litPrograms.at(id)); + } + ds.reports = move(new_reports); } }