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

Last change on this file since 5887 was 5887, checked in by cameron, 15 months ago

Separate compilation of Unicode property kernels

File size: 2.8 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        if (intersects(cc0, cc)) return subtractCC(cc0, cc);
31        else return cc0;
32    } else if (Seq * seq = dyn_cast<Seq>(re)) {
33        std::vector<RE*> list;
34        for (auto s : * seq) {
35            list.push_back(exclude_CC(s, cc));
36        }
37        return makeSeq(list.begin(), list.end());
38    } else if (Alt * alt = dyn_cast<Alt>(re)) {
39        std::vector<RE*> list;
40        for (auto a : * alt) {
41            list.push_back(exclude_CC(a, cc));
42        }
43        return makeAlt(list.begin(), list.end());
44    } else if (Rep * rep = dyn_cast<Rep>(re)) {
45        return makeRep(exclude_CC(rep->getRE(), cc), rep->getLB(), rep->getUB());
46    } else if (Group * g = dyn_cast<Group>(re)) {
47        return makeGroup(g->getMode(), exclude_CC(g->getRE(), cc), g->getSense());
48    } else if (Diff * diff = dyn_cast<Diff>(re)) {
49        // We only need exclude from the LH operand.
50        return makeDiff(exclude_CC(diff->getLH(), cc), diff->getRH());
51    } else if (Intersect * e = dyn_cast<Intersect>(re)) {
52        // We only need exclude from the one of the operands.
53        return makeIntersect(exclude_CC(e->getLH(), cc), e->getRH());
54    } else if (isa<Start>(re) || isa<End>(re) || isa<Assertion>(re)) {
55        return re;
56    } else if (Name * n = dyn_cast<Name>(re)) {
57        switch (n->getType()) {
58            case Name::Type::Reference:
59            case Name::Type::ZeroWidth:
60                return re;
61            case Name::Type::Capture:
62                return makeCapture(n->getName(), exclude_CC(n->getDefinition(), cc));
63            default:
64                RE * defn = n->getDefinition();
65                if (const CC * cc0 = dyn_cast<CC>(defn)) {
66                    if (!intersects(cc0, cc)) return re;
67                }
68                std::string cc_name = n->getName() + "--" + cc->canonicalName();
69                return makeName(cc_name, Name::Type::Unicode, exclude_CC(defn, cc));
70                /*
71                return exclude_CC(defn, cc);
72                */
73        }
74    } else {
75        report_fatal_error("exclude_CC: unhandled regexp type");
76    }
77}
78}
79
Note: See TracBrowser for help on using the repository browser.