source: icGREP/icgrep-devel/icgrep/re/replaceCC.cpp @ 5934

Last change on this file since 5934 was 5934, checked in by cameron, 13 months ago

Multithreaded simple RE mode initial check-in

File size: 2.2 KB
Line 
1#include "replaceCC.h"
2#include <cc/alphabet.h>
3#include <UCD/unicode_set.h>
4#include <re/re_cc.h>
5#include <re/re_name.h>
6#include <re/re_start.h>
7#include <re/re_end.h>
8#include <re/re_any.h>
9#include <re/re_seq.h>
10#include <re/re_alt.h>
11#include <re/re_rep.h>
12#include <re/re_group.h>
13#include <re/re_range.h>
14#include <re/re_diff.h>
15#include <re/re_intersect.h>
16#include <re/re_assertion.h>
17#include <llvm/Support/Casting.h>
18
19using namespace llvm;
20namespace re {
21
22RE * replaceCC(RE * re, CC * toReplace, RE * replacement) {
23    if (CC * cc = dyn_cast<CC>(re)) {
24        if ((cc->getAlphabet() == toReplace->getAlphabet()) &&
25              (cast<UCD::UnicodeSet>(cc) == cast<UCD::UnicodeSet>(toReplace))) {
26            return replacement;
27        } 
28        return re;
29    } else if (Seq * seq = dyn_cast<Seq>(re)) {
30        std::vector<RE *> list;
31        list.reserve(seq->size());
32        for (RE * item : *seq) {
33            item = replaceCC(item, toReplace, replacement);
34            list.push_back(item);
35        }
36        re = makeSeq(list.begin(), list.end());
37    } else if (Alt * alt = dyn_cast<Alt>(re)) {
38        std::vector<RE *> list;
39        list.reserve(alt->size());
40        for (RE * item : *alt) {
41            item = replaceCC(item, toReplace, replacement);
42            list.push_back(item);
43        }
44        re = makeAlt(list.begin(), list.end());
45    } else if (Assertion * a = dyn_cast<Assertion>(re)) {
46        re = makeAssertion(replaceCC(a->getAsserted(), toReplace, replacement), a->getKind(), a->getSense());
47    } else if (Rep * rep = dyn_cast<Rep>(re)) {
48        RE * expr = replaceCC(rep->getRE(), toReplace, replacement);
49        re = makeRep(expr, rep->getLB(), rep->getUB());
50    } else if (Diff * diff = dyn_cast<Diff>(re)) {
51        re = makeDiff(replaceCC(diff->getLH(), toReplace, replacement),
52                      replaceCC(diff->getRH(), toReplace, replacement));
53    } else if (Intersect * e = dyn_cast<Intersect>(re)) {
54        re = makeIntersect(replaceCC(e->getLH(), toReplace, replacement),
55                           replaceCC(e->getRH(), toReplace, replacement));
56    } else if (Group * g = dyn_cast<Group>(re)) {
57        re = makeGroup(g->getMode(), replaceCC(g->getRE(), toReplace, replacement), g->getSense());
58    }
59    return re;
60};
61}
Note: See TracBrowser for help on using the repository browser.