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

Last change on this file since 6104 was 5835, checked in by nmedfort, 21 months ago

Revised RE_Minimizer to use alphabets + minor optimizations to RE functions

File size: 1.6 KB
RevLine 
[3850]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
[4194]7#ifndef RE_SEQ_H
8#define RE_SEQ_H
[3850]9
10#include "re_re.h"
[5267]11#include <llvm/Support/Casting.h>
[3850]12
[4194]13namespace re {
14
15class Seq : public Vector {
[3850]16public:
[4194]17    static inline bool classof(const RE * re) {
18        return re->getClassTypeId() == ClassTypeId::Seq;
19    }
20    static inline bool classof(const void *) {
21        return false;
22    }
23    virtual ~Seq() {}
24protected:
[4249]25    friend Seq * makeSeq();
[5835]26    template<typename iterator> friend RE * makeSeq(const iterator, const iterator);
[4249]27    Seq()
28    : Vector(ClassTypeId::Seq) {
[4194]29
30    }
[4249]31    Seq(iterator begin, iterator end)
32    : Vector(ClassTypeId::Seq, begin, end) {
[4194]33
34    }
[3850]35};
36
[4249]37inline Seq * makeSeq() {
38    return new Seq();
[4194]39}
40
[5835]41template<typename iterator>
42inline RE * makeSeq(const iterator begin, const iterator end) {
43    Seq * seq = makeSeq();
[4203]44    for (auto i = begin; i != end; ++i) {
[5835]45        RE * const item = *i;
46        if (LLVM_UNLIKELY(llvm::isa<Seq>(item))) {
47            for (RE * const innerItem : *llvm::cast<Seq>(item)) {
48                seq->push_back(innerItem);
49            }
[4852]50        } else {
[5835]51            seq->push_back(item);
[4203]52        }
53    }
[5835]54    if (seq->size() == 1) {
55        return seq->front();
[4203]56    }
[5835]57    return seq;
[4194]58}
59
[4203]60inline RE * makeSeq(RE::InitializerList list) {
[4249]61    return makeSeq(list.begin(), list.end());
[4203]62}
63
[5810]64inline bool isEmptySeq(RE * s) {
65    return llvm::isa<Seq>(s) && llvm::cast<Seq>(s)->empty();
[4203]66}
[5810]67}
[4203]68
[5197]69#endif // RE_SEQ_H
[3850]70
71
72
73
Note: See TracBrowser for help on using the repository browser.