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

Last change on this file since 6161 was 6161, checked in by cameron, 8 months ago

Simplify Unicode name and anchor resolution, excludeCC

File size: 1.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 <re/re_utility.h>
22#include <llvm/Support/Casting.h>
23#include <llvm/Support/ErrorHandling.h>
24
25using namespace llvm;
26
27namespace re {
28 
29class CC_Remover : public RE_Transformer {
30public:
31    CC_Remover(CC * toExclude) : RE_Transformer(), mExcludedCC(toExclude) {}
32    RE * transformCC (CC * cc) override;
33    RE * transformName (Name * name) override;
34private:
35    CC * mExcludedCC;
36};
37   
38RE * CC_Remover::transformCC(CC * cc) {
39    if (intersects(mExcludedCC, cc)) return subtractCC(cc, mExcludedCC);
40    else return cc;
41}
42
43RE * CC_Remover::transformName(Name * n) {
44    switch (n->getType()) {
45        case Name::Type::Reference:
46        case Name::Type::ZeroWidth:
47            return n;
48        case Name::Type::Capture:
49            return makeCapture(n->getName(), transform(n->getDefinition()));
50        default:
51            RE * defn = n->getDefinition();
52            if (const CC * cc0 = dyn_cast<CC>(defn)) {
53                if (!intersects(mExcludedCC, cc0)) return n;
54            }
55            std::string cc_name = n->getName() + "--" + mExcludedCC->canonicalName();
56            return makeName(cc_name, Name::Type::Unicode, transform(defn));
57            /*
58             return transform(defn);
59             */
60    }
61}
62   
63RE * exclude_CC(RE * re, CC * cc) {
64    return CC_Remover(cc).transform(re);
65}
66}
67
Note: See TracBrowser for help on using the repository browser.