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

Last change on this file since 5240 was 5240, checked in by nmedfort, 2 years ago

Cleaned up memory leaks + some warning messages.

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