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

Last change on this file since 6184 was 6173, checked in by nmedfort, 9 months ago

Added RE_Inspector.

Migrated RE passes to RE_Transformer.

Incorporated Memoizer functionality into RE_Transformer/Inspector.

Removed Memoizer.

Bug fix for unicode_set.

File size: 1.7 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 <util/slab_allocator.h>
11#include <vector>
12
13namespace re {
14
15class RE {
16public:
17    using Allocator = SlabAllocator<RE *>;
18    using VectorAllocator = ProxyAllocator<RE *>;
19    enum class ClassTypeId : unsigned {
20        Alt
21        , Assertion
22        , CC
23        , Range
24        , Diff
25        , End
26        , Intersect
27        , Name
28        , Group
29        , Rep
30        , Seq
31        , Start
32    };
33    inline ClassTypeId getClassTypeId() const {
34        return mClassTypeId;
35    }
36    inline static void Reset() {
37        mAllocator.Reset();
38    }
39    typedef std::initializer_list<RE *> InitializerList;
40
41protected:
42    inline RE(const ClassTypeId id)
43    : mClassTypeId(id) {
44
45    }
46    void* operator new (std::size_t size) noexcept {
47        return mAllocator.allocate<uint8_t>(size);
48    }
49    const ClassTypeId mClassTypeId;
50    static Allocator mAllocator;
51};
52
53class Vector : public RE, public std::vector<RE*, RE::VectorAllocator> {
54public:
55    static inline bool classof(const RE * re) {
56        const auto typeId = re->getClassTypeId();
57        return typeId == ClassTypeId::Alt || typeId == ClassTypeId::Seq;
58    }
59    static inline bool classof(const void *) {
60        return false;
61    }
62    virtual ~Vector() {}
63protected:
64    inline Vector(const ClassTypeId id)
65    : RE(id)
66    , std::vector<RE*, RE::VectorAllocator>(mAllocator)
67    {
68
69    }
70    inline Vector(const ClassTypeId id, const iterator begin, const iterator end)
71    : RE(id)
72    , std::vector<RE*, RE::VectorAllocator>(begin, end, mAllocator) {
73
74    }
75};
76
77}
78
79#endif // RE_H
80
81
Note: See TracBrowser for help on using the repository browser.