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

Last change on this file since 5768 was 5768, checked in by cameron, 18 months ago

Regular expression system restructuring progress

File size: 3.1 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 (Name * name = dyn_cast<Name>(re)) {
28        if (!inCaseInsensitiveMode || (name->getDefinition() == nullptr)) return re;
29        RE * r = resolveCaseInsensitiveMode(name->getDefinition(), true);
30        Name * n = makeName(name->getNamespace(), name->getName() + "/i", name->getType());
31        n->setDefinition(r);
32        return n;
33    }
34    else if (Seq * seq = dyn_cast<Seq>(re)) {
35        std::vector<RE*> list;
36        for (auto i = seq->begin(); i != seq->end(); ++i) {
37            list.push_back(resolveCaseInsensitiveMode(*i, inCaseInsensitiveMode));
38        }
39        return makeSeq(list.begin(), list.end());
40    } else if (Group * g = dyn_cast<Group>(re)) {
41        if (g->getMode() == Group::Mode::CaseInsensitiveMode) {
42            return resolveCaseInsensitiveMode(g->getRE(), g->getSense() == Group::Sense::On);
43        }
44        else {
45            return makeGroup(g->getMode(), resolveCaseInsensitiveMode(g->getRE(), inCaseInsensitiveMode), g->getSense());
46        }
47    } else if (Alt * alt = dyn_cast<Alt>(re)) {
48        std::vector<RE*> list;
49        for (auto i = alt->begin(); i != alt->end(); ++i) {
50            list.push_back(resolveCaseInsensitiveMode(*i, inCaseInsensitiveMode));
51        }
52        return makeAlt(list.begin(), list.end());
53    } else if (Rep * rep = dyn_cast<Rep>(re)) {
54        return makeRep(resolveCaseInsensitiveMode(rep->getRE(), inCaseInsensitiveMode), rep->getLB(), rep->getUB());
55    } else if (const Diff * diff = dyn_cast<const Diff>(re)) {
56        return makeDiff(resolveCaseInsensitiveMode(diff->getLH(), inCaseInsensitiveMode),
57                        resolveCaseInsensitiveMode(diff->getRH(), inCaseInsensitiveMode));
58    } else if (const Intersect * e = dyn_cast<const Intersect>(re)) {
59        return makeIntersect(resolveCaseInsensitiveMode(e->getLH(), inCaseInsensitiveMode),
60                             resolveCaseInsensitiveMode(e->getRH(), inCaseInsensitiveMode));
61    } else if (const Assertion * a = dyn_cast<Assertion>(re)) {
62        return makeAssertion(resolveCaseInsensitiveMode(a->getAsserted(), inCaseInsensitiveMode), a->getKind(), a->getSense());
63    } else if (isa<Start>(re) || isa<End>(re)) {
64        return re;
65    } else llvm_unreachable("Unknown RE type");
66}
67
68}
Note: See TracBrowser for help on using the repository browser.