source: icGREP/icgrep-devel/icgrep/re/casing.cpp @ 5766

Last change on this file since 5766 was 5766, checked in by cameron, 22 months ago

Case-insensitive transformation

File size: 2.9 KB
Line 
1#include <re/casing.h>
2#include <re/re_cc.h>
3#include <re/re_alt.h>             // for Alt, makeAlt
4#include <re/re_any.h>             // for makeAny, Any
5#include <re/re_assertion.h>       // for Assertion, Assertion::Sense, Asser...
6#include <re/re_start.h>
7#include <re/re_end.h>
8#include <re/re_diff.h>            // for Diff, makeDiff
9#include <re/re_group.h>
10#include <re/re_intersect.h>       // for Intersect
11#include <re/re_name.h>            // for Name
12#include <re/re_rep.h>             // for Rep, makeRep
13#include <re/re_seq.h>             // for Seq, makeSeq
14#include <vector>                  // for vector, allocator
15#include <llvm/Support/Casting.h>  // for dyn_cast, isa
16#include <llvm/Support/ErrorHandling.h>
17
18
19using namespace llvm;
20
21namespace re {
22RE * resolveCaseInsensitiveMode(RE * re, bool inCaseInsensitiveMode) {
23    if (isa<CC>(re)) {
24        if (inCaseInsensitiveMode) return caseInsensitize(cast<CC>(re));
25        else return re;
26    }
27    else if (isa<Name>(re)) {
28        return re;
29    }
30    else if (Seq * seq = dyn_cast<Seq>(re)) {
31        std::vector<RE*> list;
32        for (auto i = seq->begin(); i != seq->end(); ++i) {
33            list.push_back(resolveCaseInsensitiveMode(*i, inCaseInsensitiveMode));
34        }
35        return makeSeq(list.begin(), list.end());
36    } else if (Group * g = dyn_cast<Group>(re)) {
37        if (g->getMode() == Group::Mode::CaseInsensitiveMode) {
38            return resolveCaseInsensitiveMode(g->getRE(), g->getSense() == Group::Sense::On);
39        }
40        else {
41            return makeGroup(g->getMode(), resolveCaseInsensitiveMode(g->getRE(), inCaseInsensitiveMode), g->getSense());
42        }
43    } else if (Alt * alt = dyn_cast<Alt>(re)) {
44        std::vector<RE*> list;
45        for (auto i = alt->begin(); i != alt->end(); ++i) {
46            list.push_back(resolveCaseInsensitiveMode(*i, inCaseInsensitiveMode));
47        }
48        return makeAlt(list.begin(), list.end());
49    } else if (Rep * rep = dyn_cast<Rep>(re)) {
50        return makeRep(resolveCaseInsensitiveMode(rep->getRE(), inCaseInsensitiveMode), rep->getLB(), rep->getUB());
51    } else if (const Diff * diff = dyn_cast<const Diff>(re)) {
52        return makeDiff(resolveCaseInsensitiveMode(diff->getLH(), inCaseInsensitiveMode),
53                        resolveCaseInsensitiveMode(diff->getRH(), inCaseInsensitiveMode));
54    } else if (const Intersect * e = dyn_cast<const Intersect>(re)) {
55        return makeIntersect(resolveCaseInsensitiveMode(e->getLH(), inCaseInsensitiveMode),
56                             resolveCaseInsensitiveMode(e->getRH(), inCaseInsensitiveMode));
57    } else if (const Assertion * a = dyn_cast<Assertion>(re)) {
58        return makeAssertion(resolveCaseInsensitiveMode(a->getAsserted(), inCaseInsensitiveMode), a->getKind(), a->getSense());
59    } else if (isa<Start>(re) || isa<End>(re)) {
60        return re;
61    } else llvm_unreachable("Unknown RE type");
62}
63
64}
Note: See TracBrowser for help on using the repository browser.