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

Last change on this file since 4846 was 4846, checked in by nmedfort, 4 years ago

Bug fix for bounded expressions + grapheme cluster mode.

File size: 2.0 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_grapheme_boundary.hpp>
14#include <re/re_analysis.h>
15#include <algorithm>
16#include <memory>
17#include <queue>
18
19namespace re {
20
21RE * RE_Simplifier::simplify(RE * re) {
22    if (Alt * alt = dyn_cast<Alt>(re)) {
23        std::vector<RE *> list;
24        list.reserve(alt->size());
25        for (RE * re : *alt) {
26            list.push_back(simplify(re));
27        }
28        re = makeAlt(list.begin(), list.end());
29    } else if (Seq * seq = dyn_cast<Seq>(re)) {
30        std::vector<RE *> list;
31        list.reserve(seq->size());
32        for (RE * re : *seq) {
33            list.push_back(simplify(re));
34        }
35        re = makeSeq(list.begin(), list.end());
36    } else if (Assertion * a = dyn_cast<Assertion>(re)) {
37        re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
38    } else if (Rep * rep = dyn_cast<Rep>(re)) {
39        RE * expr = simplify(rep->getRE());
40        if (GraphemeBoundary * gp = dyn_cast<GraphemeBoundary>(expr)) {
41            if (gp->getExpression() && isUnicodeUnitLength(gp->getExpression())) {
42                rep->setRE(gp->getExpression());
43                gp->setExpression(rep);
44                return gp;
45            }
46        }
47        re = makeRep(expr, rep->getLB(), rep->getUB());
48    } else if (Diff * diff = dyn_cast<Diff>(re)) {
49        re = makeDiff(simplify(diff->getLH()), diff->getRH());
50    } else if (Intersect * e = dyn_cast<Intersect>(re)) {
51        re = makeIntersect(simplify(e->getLH()), e->getRH());
52    } else if (GraphemeBoundary * gp = dyn_cast<GraphemeBoundary>(re)) {
53        if (gp->getExpression() && isa<GraphemeBoundary>(gp->getExpression())) {
54            re = gp->getExpression();
55        }
56    }
57    return re;
58}
59
60}
Note: See TracBrowser for help on using the repository browser.