source: icGREP/icgrep-devel/icgrep/re/re_name_gather.cpp @ 5881

Last change on this file since 5881 was 5881, checked in by cameron, 14 months ago

Grapheme Cluster Break kernel

File size: 2.0 KB
Line 
1#include "re_name_gather.h"
2#include <re/re_name.h>
3#include <re/re_alt.h>
4#include <re/re_cc.h>
5#include <re/re_seq.h>
6#include <re/re_rep.h>
7#include <re/re_range.h>
8#include <re/re_diff.h>
9#include <re/re_intersect.h>
10#include <re/re_assertion.h>
11#include <re/re_group.h>
12#include <re/re_analysis.h>
13#include <re/re_memoizer.hpp>
14#include <cc/alphabet.h>
15#include <UCD/ucd_compiler.hpp>
16#include <UCD/resolve_properties.h>
17#include <boost/container/flat_set.hpp>
18#include <llvm/Support/Casting.h>
19#include <llvm/Support/raw_ostream.h>
20
21using namespace llvm;
22namespace re {
23struct NameGather {
24
25    void gather(RE * re) {
26        assert ("RE object cannot be null!" && re);
27        if (isa<Name>(re)) {
28            RE * defn = cast<Name>(re)->getDefinition();
29            if (defn == nullptr) {
30                mNameSet.emplace(cast<Name>(re));
31            }
32        } else if (isa<Seq>(re)) {
33            for (RE * item : *cast<Seq>(re)) {
34                gather(item);
35            }
36        } else if (isa<Alt>(re)) {
37            for (RE * item : *cast<Alt>(re)) {
38                gather(item);
39            }
40        } else if (isa<Rep>(re)) {
41            gather(cast<Rep>(re)->getRE());
42        } else if (isa<Assertion>(re)) {
43            gather(cast<Assertion>(re)->getAsserted());
44        } else if (Range * rg = dyn_cast<Range>(re)) {
45            gather(rg->getLo());
46            gather(rg->getHi());
47        } else if (isa<Diff>(re)) {
48            gather(cast<Diff>(re)->getLH());
49            gather(cast<Diff>(re)->getRH());
50        } else if (isa<Intersect>(re)) {
51            gather(cast<Intersect>(re)->getLH());
52            gather(cast<Intersect>(re)->getRH());
53        } else if (isa<Group>(re)) {
54            gather(cast<Group>(re)->getRE());
55        }
56    }
57    NameGather(std::set<Name *> & nameSet)
58    : mNameSet(nameSet) {
59
60    }
61
62private:
63
64    std::set<Name *> &               mNameSet;
65
66};
67   
68std::set<Name *> gatherExternalNames(RE * re) {
69    std::set<Name *> nameSet;
70   
71    NameGather nameGather(nameSet);
72    nameGather.gather(re);
73    return nameSet;
74   
75}
76
77}
Note: See TracBrowser for help on using the repository browser.