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

Last change on this file since 5792 was 5784, checked in by cameron, 19 months ago

Restructuring step/tidy-up for re_passes

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