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

Last change on this file since 4405 was 4405, checked in by cameron, 4 years ago

AST support for Lookahead/Lookbehind? assertions

File size: 1.4 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 "re_assertion.h"
12#include <algorithm>
13#include <memory>
14#include <queue>
15
16namespace re {
17
18RE * RE_Simplifier::simplify(RE * re) {
19    if (Alt * alt = dyn_cast<Alt>(re)) {
20        std::vector<RE*> list;
21        list.reserve(alt->size());
22        for (RE * re : *alt) {
23            list.push_back(simplify(re));
24        }
25        re = makeAlt(list.begin(), list.end());
26    }
27    else if (Seq * seq = dyn_cast<Seq>(re)) {
28        std::vector<RE*> list;
29        list.reserve(seq->size());
30        for (RE * re : *seq) {
31            list.push_back(simplify(re));
32        }
33        re = makeSeq(list.begin(), list.end());
34    }
35    else if (Assertion * a = dyn_cast<Assertion>(re)) {
36        re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
37    }
38    else if (Rep * rep = dyn_cast<Rep>(re)) {
39        re = makeRep(simplify(rep->getRE()), rep->getLB(), rep->getUB());
40    }
41    else if (Diff * diff = dyn_cast<Diff>(re)) {
42        re = makeDiff(simplify(diff->getLH()), diff->getRH());
43    }
44    else if (Intersect * e = dyn_cast<Intersect>(re)) {
45        re = makeIntersect(simplify(e->getLH()), e->getRH());
46    }
47    return re;
48}
49
50}
Note: See TracBrowser for help on using the repository browser.