source: icGREP/icgrep-devel/icgrep/re/re_toolchain.h

Last change on this file was 6186, checked in by cameron, 6 months ago

Various clean-ups

File size: 3.5 KB
Line 
1/*
2 *  Copyright (c) 2018 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#ifndef RE_TOOLCHAIN_H
8#define RE_TOOLCHAIN_H
9
10#include <map>
11#include <set>
12#include <string>
13#include <llvm/Support/Compiler.h>
14
15namespace llvm { namespace cl { class OptionCategory; } }
16namespace pablo { class PabloKernel; class PabloAST; }
17namespace re { class RE; class CC;}
18namespace re { class Name; class Start; class End; class CC; class Seq; class Alt;
19    class Rep; class Intersect; class Diff; class Range; class Group;
20    class Assertion;
21}
22
23namespace re {
24
25enum RE_PrintFlags {
26    ShowREs, ShowAllREs, ShowStrippedREs, ShowSimplifiedREs
27};
28   
29enum RE_AlgorithmFlags {
30    DisableLog2BoundedRepetition, DisableIfHierarchy, DisableMatchStar, DisableUnicodeMatchStar, 
31    DisableUnicodeLineBreak, UsePregeneratedUnicode
32};
33   
34bool LLVM_READONLY PrintOptionIsSet(RE_PrintFlags flag);
35bool LLVM_READONLY AlgorithmOptionIsSet(RE_AlgorithmFlags flag);
36   
37extern int IfInsertionGap;
38
39const llvm::cl::OptionCategory * LLVM_READONLY re_toolchain_flags();
40   
41   
42void UndefinedNameError (const Name * n);
43
44enum class NameTransformationMode {None, TransformDefinition};
45
46class RE_Transformer {
47    struct MemoizerComparator {
48        bool operator() (const RE * lh, const RE * rh) const;
49    };
50public:
51    RE * transformRE(RE * r);
52protected:
53    RE_Transformer(std::string transformationName, NameTransformationMode m = NameTransformationMode::None)
54    : mTransformationName(std::move(transformationName)), mNameTransform(m) {}
55
56    virtual ~RE_Transformer() {}
57    RE * transform(RE * r);
58    virtual RE * transformName(Name * n);
59    virtual RE * transformStart(Start * s);
60    virtual RE * transformEnd(End * e);
61    virtual RE * transformCC(CC * cc);
62    virtual RE * transformSeq(Seq * s);
63    virtual RE * transformAlt(Alt * a);
64    virtual RE * transformRep(Rep * rep);
65    virtual RE * transformIntersect(Intersect * e);
66    virtual RE * transformDiff(Diff * d);
67    virtual RE * transformRange(Range * rg);
68    virtual RE * transformGroup(Group * g);
69    virtual RE * transformAssertion(Assertion * a);
70private:
71    const std::string mTransformationName;
72    const NameTransformationMode mNameTransform;
73    std::map<RE *, RE *, MemoizerComparator> mMap;
74};
75
76enum class InspectionMode {TraverseNonUnique, IgnoreNonUnique};
77
78class RE_Inspector {
79    struct MemoizerComparator {
80        bool operator() (const RE * lh, const RE * rh) const;
81    };
82public:
83    void inspectRE(RE * r);
84protected:
85    RE_Inspector(const InspectionMode ignoreNonUnique = InspectionMode::IgnoreNonUnique) : mIgnoreNonUnique(ignoreNonUnique) {}
86    virtual ~RE_Inspector() {}
87    void inspect(RE * r);
88    virtual void inspectName(Name * n);
89    virtual void inspectStart(Start * s);
90    virtual void inspectEnd(End * e);
91    virtual void inspectCC(CC * cc);
92    virtual void inspectSeq(Seq * s);
93    virtual void inspectAlt(Alt * a);
94    virtual void inspectRep(Rep * rep);
95    virtual void inspectIntersect(Intersect * e);
96    virtual void inspectDiff(Diff * d);
97    virtual void inspectRange(Range * rg);
98    virtual void inspectGroup(Group * g);
99    virtual void inspectAssertion(Assertion * a);
100private:
101    const InspectionMode mIgnoreNonUnique;
102    std::set<RE *, MemoizerComparator> mMap;
103};
104
105RE * resolveModesAndExternalSymbols(RE * r, bool globallyCaseInsensitive = false);
106
107RE * excludeUnicodeLineBreak(RE * r);
108
109RE * regular_expression_passes(RE * r);
110   
111}
112#endif
Note: See TracBrowser for help on using the repository browser.