source: icGREP/icgrep-devel/icgrep/re/re_simplifier.cpp @ 4308

Last change on this file since 4308 was 4308, checked in by cameron, 5 years ago

Intersect and Diff support

File size: 1.2 KB
Line 
1#include "re_simplifier.h"
2#include "re_cc.h"
3#include "re_name.h"
4#include "re_start.h"
5#include "re_end.h"
6#include "re_seq.h"
7#include "re_alt.h"
8#include "re_rep.h"
9#include "re_diff.h"
10#include "re_intersect.h"
11#include <algorithm>
12#include <memory>
13#include <queue>
14
15namespace re {
16
17RE * RE_Simplifier::simplify(RE * re) {
18    if (Alt * alt = dyn_cast<Alt>(re)) {
19        std::vector<RE*> list;
20        list.reserve(alt->size());
21        for (RE * re : *alt) {
22            list.push_back(simplify(re));
23        }
24        re = makeAlt(list.begin(), list.end());
25    }
26    else if (Seq * seq = dyn_cast<Seq>(re)) {
27        std::vector<RE*> list;
28        list.reserve(seq->size());
29        for (RE * re : *seq) {
30            list.push_back(simplify(re));
31        }
32        re = makeSeq(list.begin(), list.end());
33    }
34    else if (Rep * rep = dyn_cast<Rep>(re)) {
35        re = makeRep(simplify(rep->getRE()), rep->getLB(), rep->getUB());
36    }
37    else if (Diff * diff = dyn_cast<Diff>(re)) {
38        re = makeDiff(simplify(diff->getLH()), diff->getRH());
39    }
40    else if (Intersect * e = dyn_cast<Intersect>(re)) {
41        re = makeIntersect(simplify(e->getLH()), e->getRH());
42    }
43    return re;
44}
45
46}
Note: See TracBrowser for help on using the repository browser.