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

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

delete GCB as a separate type.

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