source: icGREP/icgrep-devel/icgrep/re/re_seq.h @ 4272

Last change on this file since 4272 was 4272, checked in by nmedfort, 4 years ago

Implemented slab allocator based on the original Parabix StringPool?; intergrated it with RE and Pablo AST nodes.

File size: 1.6 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_SEQ_H
8#define RE_SEQ_H
9
10#include "re_re.h"
11#include <string>
12#include <initializer_list>
13
14namespace re {
15
16class Seq : public Vector {
17public:
18    static inline bool classof(const RE * re) {
19        return re->getClassTypeId() == ClassTypeId::Seq;
20    }
21    static inline bool classof(const void *) {
22        return false;
23    }
24    virtual ~Seq() {}
25protected:
26    friend Seq * makeSeq();
27    void* operator new (std::size_t size) noexcept {
28        return mAllocator.allocate(size);
29    }
30    template<typename iterator> friend RE * makeSeq(iterator, iterator);
31    Seq()
32    : Vector(ClassTypeId::Seq) {
33
34    }
35    Seq(iterator begin, iterator end)
36    : Vector(ClassTypeId::Seq, begin, end) {
37
38    }
39    template<typename itr> void flatten(itr begin, itr end);
40};
41
42inline Seq * makeSeq() {
43    return new Seq();
44}
45
46template<typename itr>
47void Seq::flatten(itr begin, itr end) {
48    for (auto i = begin; i != end; ++i) {
49        if (Seq * seq = dyn_cast<Seq>(*i)) {
50            flatten<Seq::iterator>(seq->begin(), seq->end());
51            continue;
52        }
53        push_back(*i);
54    }
55}
56
57template<typename itr>
58inline RE * makeSeq(itr begin, itr end) {
59    Seq * seq = makeSeq();
60    seq->flatten(begin, end);
61    if (seq->size() == 1) {
62        return seq->back();
63    }
64    return seq;
65}
66
67inline RE * makeSeq(RE::InitializerList list) {
68    return makeSeq(list.begin(), list.end());
69}
70
71}
72
73#endif // JOIN_H
74
75
76
77
Note: See TracBrowser for help on using the repository browser.