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

Last change on this file was 6226, checked in by cameron, 9 months ago

Clean-up/refactoring step for REs

File size: 1.4 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_H
8#define RE_H
9
10#include <util/slab_allocator.h>
11#include <vector>
12
13namespace re {
14
15// REs are defined in a class hierarchy supporting llvm::isa, llvm::dyn_cast.
16#define RE_SUBTYPE(kind) \
17static inline bool classof(const RE * re) {return re->getClassTypeId() == ClassTypeId::kind;}\
18static inline bool classof(const void *) {return false;}
19
20class RE {
21public:
22    using Allocator = SlabAllocator<RE *>;
23    using VectorAllocator = ProxyAllocator<RE *>;
24    enum class ClassTypeId : unsigned {
25        Alt
26        , Assertion
27        , CC
28        , Range
29        , Diff
30        , End
31        , Intersect
32        , Name
33        , Group
34        , Rep
35        , Seq
36        , Start
37    };
38    inline ClassTypeId getClassTypeId() const {
39        return mClassTypeId;
40    }
41    inline static void Reset() {
42        mAllocator.Reset();
43    }
44    inline static void PrintStats() {
45        mAllocator.PrintStats();
46    }
47    typedef std::initializer_list<RE *> InitializerList;
48
49protected:
50    inline RE(const ClassTypeId id)
51    : mClassTypeId(id) {
52
53    }
54    void* operator new (std::size_t size) noexcept {
55        return mAllocator.allocate<uint8_t>(size);
56    }
57    const ClassTypeId mClassTypeId;
58    static Allocator mAllocator;
59};
60
61}
62
63#endif // RE_H
64
65
Note: See TracBrowser for help on using the repository browser.