Changeset 6195


Ignore:
Timestamp:
Nov 7, 2018, 8:15:20 PM (5 months ago)
Author:
cameron
Message:

Restructuring step: liminate RE:::Vector

Location:
icGREP/icgrep-devel/icgrep/re
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_alt.h

    r5866 r6195  
    99
    1010#include "re_re.h"
     11#include <util/slab_allocator.h>
     12#include <vector>
    1113#include <re/re_cc.h>
    1214#include <re/re_seq.h>
     
    1719namespace re {
    1820
    19 class Alt : public Vector {
     21class Alt : public RE, public std::vector<RE*, ProxyAllocator<RE *>> {
    2022public:
    2123    static inline bool classof(const RE * re) {
     
    2830    friend Alt * makeAlt();
    2931    template<typename iterator> friend RE * makeAlt(iterator, iterator);
    30     Alt()
    31     : Vector(ClassTypeId::Alt) {
    32 
    33     }
     32    Alt() : RE(ClassTypeId::Alt), std::vector<RE*, ProxyAllocator<RE *>>(mAllocator) {}
    3433    Alt(iterator begin, iterator end)
    35     : Vector(ClassTypeId::Alt, begin, end) {
    36 
    37     }
     34    : RE(ClassTypeId::Alt), std::vector<RE*, ProxyAllocator<RE *>>(begin, end, mAllocator) { }
    3835};
    3936
  • icGREP/icgrep-devel/icgrep/re/re_minimizer.cpp

    r6185 r6195  
    288288
    289289
    290     template <typename T>
    291     static bool unchanged(const Vector * A, const T & B) {
     290    template <typename T1, typename T2>
     291    static bool unchanged(const T1 * A, const T2 & B) {
    292292        if (A->size() != B.size()) {
    293293            return false;
  • icGREP/icgrep-devel/icgrep/re/re_re.h

    r6173 r6195  
    11/*
    2  *  Copyright (c) 2014 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    5151};
    5252
    53 class Vector : public RE, public std::vector<RE*, RE::VectorAllocator> {
    54 public:
    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() {}
    63 protected:
    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 
    7753}
    7854
  • icGREP/icgrep-devel/icgrep/re/re_seq.h

    r6138 r6195  
    99
    1010#include <string>
     11#include <util/slab_allocator.h>
     12#include <vector>
    1113#include <re/re_cc.h>
    1214#include <re/re_re.h>
     
    1618namespace re {
    1719
    18 class Seq : public Vector {
     20class Seq : public RE, public std::vector<RE*, ProxyAllocator<RE *>> {
    1921public:
    2022    static inline bool classof(const RE * re) {
     
    2830    friend Seq * makeSeq();
    2931    template<typename iterator> friend RE * makeSeq(const iterator, const iterator);
    30     Seq()
    31     : Vector(ClassTypeId::Seq) {
    32 
    33     }
     32    Seq() : RE(ClassTypeId::Seq), std::vector<RE*, ProxyAllocator<RE *>>(mAllocator) {}
    3433    Seq(iterator begin, iterator end)
    35     : Vector(ClassTypeId::Seq, begin, end) {
    36 
    37     }
     34    : RE(ClassTypeId::Seq), std::vector<RE*, ProxyAllocator<RE *>>(begin, end, mAllocator) { }
    3835};
    3936
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r6186 r6195  
    128128static bool compare(const RE * const lh, const RE * const rh);
    129129
    130 static bool lessThan(const Vector * const lh, const Vector * const rh) {
    131     assert (lh->getClassTypeId() == rh->getClassTypeId());
    132     assert (lh->getClassTypeId() == RE::ClassTypeId::Alt || lh->getClassTypeId() == RE::ClassTypeId::Seq);
     130static bool lessThan(const Seq * const lh, const Seq * const rh) {
    133131    if (LLVM_LIKELY(lh->size() != rh->size())) {
    134132        return lh->size() < rh->size();
     
    145143}
    146144
     145static bool lessThan(const Alt * const lh, const Alt * const rh) {
     146    if (LLVM_LIKELY(lh->size() != rh->size())) {
     147        return lh->size() < rh->size();
     148    }
     149    for (auto i = lh->begin(), j = rh->begin(); i != lh->end(); ++i, ++j) {
     150        assert (*i && *j);
     151        if (compare(*i, *j)) {
     152            return true;
     153        } else if (compare(*j, *i)) {
     154            return false;
     155        }
     156    }
     157    return false;
     158}
     159   
    147160inline bool lessThan(const Name * const lh, const Name * const rh) {
    148161    if (lh->getType() != rh->getType()) {
     
    239252    switch (typeL) {
    240253        case Type::Alt:
     254            return lessThan(cast<Alt>(lh), cast<Alt>(rh));
    241255        case Type::Seq:
    242             return lessThan(cast<Vector>(lh), cast<Vector>(rh));
     256            return lessThan(cast<Seq>(lh), cast<Seq>(rh));
    243257        case Type::End: case Type::Start:
    244258            return false;
Note: See TracChangeset for help on using the changeset viewer.