source: icGREP/icgrep-devel/icgrep/re/re_re.h @ 4200

Last change on this file since 4200 was 4200, checked in by nmedfort, 5 years ago

Replaced dynamic_cast with llvm::dyn_cast in pablo code; implemented make functions for pablo constructors. Disabled RTTI.

File size: 2.9 KB
Line 
1/*
2 *  Copyright (c) 2014 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_H
8#define RE_H
9
10#include <vector>
11#include <assert.h>
12#include <llvm/Support/Casting.h>
13
14using namespace llvm;
15
16namespace re {
17
18class Vector;
19class Pair;
20
21class Alt;
22class CC;
23class Diff;
24class End;
25class Intersect;
26class Name;
27class Permute;
28class Rep;
29class Seq;
30class Start;
31class SymDiff;
32class Union;
33
34class RE {
35public:
36    enum class ClassTypeId : unsigned {
37        Alt
38        , CC
39        , Diff
40        , End
41        , Intersect
42        , Name
43        , Permute
44        , Rep
45        , Seq
46        , Start
47        , SymDiff
48        , Union
49    };
50    inline ClassTypeId getClassTypeId() const {
51        return mClassTypeId;
52    }
53    virtual RE * clone() const = 0;
54    virtual ~RE() = 0;
55protected:
56    inline RE(const ClassTypeId id)
57    : mClassTypeId(id) {
58
59    }
60    const ClassTypeId mClassTypeId;
61};
62
63//template <typename To, typename From>
64//inline static bool isa(const From * object) {
65//    return To::classof(object);
66//}
67
68//template <typename To, typename From>
69//inline static To * dyn_cast(From * object) {
70//    if (isa<To, From>(object)) {
71//        return reinterpret_cast<To *>(object);
72//    }
73//    return nullptr;
74//}
75
76class Vector : public RE, public std::vector<RE*> {
77public:
78    virtual ~Vector() {
79        for (RE * re : *this) {
80            delete re;
81        }
82    }
83protected:
84    inline Vector(const ClassTypeId id)
85    : RE(id)
86    , std::vector<RE*>()
87    {
88
89    }
90    inline Vector(const ClassTypeId id, const iterator begin, const iterator end)
91    : RE(id)
92    , std::vector<RE*>(begin, end) {
93
94    }
95    inline Vector(const ClassTypeId id, const const_iterator begin, const const_iterator end, const bool deep_copy)
96    : RE(id) {
97        assert (deep_copy && "Not intended as a shallow copy constructor.");
98        this->resize(std::distance(begin, end));
99        for (auto i = begin; i != end; ++i) {
100            this->assign(std::distance(begin, i), (*i)->clone());
101        }
102    }
103};
104
105//class Pair : public RE {
106//protected:
107//    inline Pair(const ClassTypeId id)
108//    : RE(id)
109//    , _lh(nullptr)
110//    , _rh(nullptr)
111//    {
112
113//    }
114//    inline Pair(const ClassTypeId id, const RE * lh, const RE * rh)
115//    : RE(id)
116//    , _lh(lh)
117//    , _rh(rh)
118//    {
119
120//    }
121//    virtual ~Pair() {
122//        delete _lh;
123//        delete _rh;
124//    }
125//protected:
126//    const RE * _lh;
127//    const RE * _rh;
128//};
129
130//static Diff * makeDiff(const RE * lh, const RE * rh);
131
132//static Intersect * makeIntersect(const RE * lh, const RE * rh);
133
134//static Permute * makePermute();
135//static Permute * makePermute(Vector::iterator begin, Vector::iterator end);
136
137//static SymDiff * makeSymDiff(const RE * lh, const RE * rh);
138
139//static Union * makeUnion(const RE * lh, const RE * rh);
140
141}
142
143#endif // RE_H
144
145
Note: See TracBrowser for help on using the repository browser.