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

Last change on this file since 5206 was 5091, checked in by xuedongx, 3 years ago

delete GCB as a separate type.

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