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

Last change on this file since 5792 was 5779, checked in by cameron, 17 months ago

Remove RE compiler dependency on linebreak/mAny

File size: 2.6 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <re/exclude_CC.h>
8#include <re/re_cc.h>
9#include <re/re_name.h>
10#include <re/re_start.h>
11#include <re/re_end.h>
12#include <re/re_any.h>
13#include <re/re_seq.h>
14#include <re/re_alt.h>
15#include <re/re_rep.h>
16#include <re/re_group.h>
17#include <re/re_range.h>
18#include <re/re_diff.h>
19#include <re/re_intersect.h>
20#include <re/re_assertion.h>
21#include <llvm/Support/Casting.h>
22#include <llvm/Support/ErrorHandling.h>
23
24using namespace llvm;
25
26namespace re {
27
28RE * exclude_CC(RE * re, CC * cc) {
29    if (CC * cc0 = dyn_cast<CC>(re)) {
30        return subtractCC(cc0, cc);
31    } else if (Seq * seq = dyn_cast<Seq>(re)) {
32        std::vector<RE*> list;
33        for (auto s : * seq) {
34            list.push_back(exclude_CC(s, cc));
35        }
36        return makeSeq(list.begin(), list.end());
37    } else if (Alt * alt = dyn_cast<Alt>(re)) {
38        std::vector<RE*> list;
39        for (auto a : * alt) {
40            list.push_back(exclude_CC(a, cc));
41        }
42        return makeAlt(list.begin(), list.end());
43    } else if (Rep * rep = dyn_cast<Rep>(re)) {
44        return makeRep(exclude_CC(rep->getRE(), cc), rep->getLB(), rep->getUB());
45    } else if (Group * g = dyn_cast<Group>(re)) {
46        return makeGroup(g->getMode(), exclude_CC(g->getRE(), cc), g->getSense());
47    } else if (Diff * diff = dyn_cast<Diff>(re)) {
48        // We only need exclude from the LH operand.
49        return makeDiff(exclude_CC(diff->getLH(), cc), diff->getRH());
50    } else if (Intersect * e = dyn_cast<Intersect>(re)) {
51        // We only need exclude from the one of the operands.
52        return makeIntersect(exclude_CC(e->getLH(), cc), e->getRH());
53    } else if (isa<Start>(re) || isa<End>(re) || isa<Assertion>(re)) {
54        return re;
55    } else if (Name * n = dyn_cast<Name>(re)) {
56        switch (n->getType()) {
57            case Name::Type::Byte:
58            case Name::Type::Unicode:
59            case Name::Type::UnicodeProperty:
60                return makeName(subtractCC(cast<CC>(n->getDefinition()), cc));
61            case Name::Type::ZeroWidth:
62                return re;
63            case Name::Type::Capture:
64                return makeCapture(n->getName(), exclude_CC(n->getDefinition(), cc));
65            case Name::Type::Reference:
66                return re;
67            default:
68                report_fatal_error("exclude_CC: unhandled Name type");
69        }
70    } else {
71        report_fatal_error("exclude_CC: unhandled regexp type");
72    }
73}
74}
75
Note: See TracBrowser for help on using the repository browser.