source: icGREP/icgrep-devel/icgrep/re/re_star_normal.cpp @ 6171

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

NullablePrefix/Suffix? removal using RE_Transformer; clean out some setters

File size: 1.2 KB
Line 
1#include "re_star_normal.h"
2#include <re/re_name.h>
3#include <re/re_any.h>
4#include <re/re_start.h>
5#include <re/re_end.h>
6#include <re/re_alt.h>
7#include <re/re_cc.h>
8#include <re/re_seq.h>
9#include <re/re_rep.h>
10#include <re/re_diff.h>
11#include <re/re_intersect.h>
12#include <re/re_assertion.h>
13#include <re/re_analysis.h>
14#include <re/re_nullable.h>
15
16using namespace llvm;
17
18namespace re {
19
20RE * star_rule(RE * re) {
21    if (Seq * seq = dyn_cast<Seq>(re)) {
22        if (isNullable(re)) {
23            std::vector<RE *> list;
24            list.reserve(seq->size());
25            for (RE * r : *seq) {
26                if (Rep * rep = dyn_cast<Rep>(r)) {
27                    if (rep->getLB() == 0) {
28                        list.push_back(rep->getRE());
29                    }
30                } else if (!isEmptySeq(r)) {
31                    list.push_back(r);
32                }
33            }
34            return makeAlt(list.begin(), list.end());
35        }
36    }
37    return re;
38}
39
40RE * RE_Star_Normal::transformRep(Rep * rep) {
41    RE * e0 = rep->getRE();
42    RE * e = transform(e0);
43    if (rep->getLB() == 0 && rep->getUB() == Rep::UNBOUNDED_REP) {
44        e = star_rule(e);
45    }
46    if (e == e0) return rep;
47    return makeRep(e, rep->getLB(), rep->getUB());
48}
49
50}
Note: See TracBrowser for help on using the repository browser.