Changeset 6226


Ignore:
Timestamp:
Dec 13, 2018, 12:16:02 PM (2 months ago)
Author:
cameron
Message:

Clean-up/refactoring step for REs

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

Legend:

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

    r6171 r6226  
    1717class Assertion : public RE {
    1818public:
    19     static inline bool classof(const RE * re) {
    20         return re->getClassTypeId() == ClassTypeId::Assertion;
    21     }
    22     static inline bool classof(const void *) {
    23         return false;
    24     }
    2519    enum class Kind {Lookbehind, Lookahead, Boundary};
    2620    enum class Sense {Positive, Negative};
    27 
     21   
    2822    RE * getAsserted() const {return mAsserted;}
    2923    Assertion::Kind getKind() const {return mKind;}
    3024    Assertion::Sense getSense() const {return mSense;}
    31     void setAsserted(RE * r) {mAsserted = r;}
    32 
     25   
    3326    static Assertion::Kind reverseKind(Assertion::Kind k);
    3427    static Assertion::Sense negateSense(Assertion::Sense s);
    35 
    36 protected:
    37     friend RE * makeAssertion(RE * asserted, Kind k, Sense s);
     28    static Assertion * Create(RE * asserted, Kind k, Sense s) {
     29        return new Assertion(asserted, k, s);
     30    }
     31    RE_SUBTYPE(Assertion)
     32private:
    3833    Assertion(RE * r, Kind k, Sense s) : RE(ClassTypeId::Assertion), mAsserted(r), mKind(k), mSense(s) {}
    39     virtual ~Assertion() {}
    40 
    41 private:
    4234    RE * mAsserted;
    4335    Kind mKind;
     
    6355        else return makeAlt();
    6456    }
    65     return new Assertion(asserted, k, s);
     57    return Assertion::Create(asserted, k, s);
    6658}
    6759
  • icGREP/icgrep-devel/icgrep/re/re_diff.cpp

    r6223 r6226  
    1919   
    2020RE * makeDiff(RE * lh, RE * rh) {
    21    
    2221    if (LLVM_UNLIKELY(isEmptySeq(lh) && isEmptySeq(rh))) {
    2322        return makeEmptySet();
     
    2524        return lh;
    2625    } else if (LLVM_UNLIKELY(isEmptySet(lh))) {
    27         return makeEmptySet();
     26        return lh;
    2827    } else {
    29         return new Diff(lh, rh);
     28        return Diff::Create(lh, rh);
    3029    }
    3130}
  • icGREP/icgrep-devel/icgrep/re/re_diff.h

    r6173 r6226  
    88class Diff : public RE {
    99public:
    10     static inline bool classof(const RE * re) {
    11         return re->getClassTypeId() == ClassTypeId::Diff;
    12     }
    13     static inline bool classof(const void *) {
    14         return false;
    15     }
    16     RE * getLH() const {
    17         return mLh;
    18     }
    19     RE * getRH() const {
    20         return mRh;
    21     }
    22 protected:
    23     friend RE * makeDiff(RE*, RE*);
    24     Diff(RE * lh, RE * rh)
    25     : RE(ClassTypeId::Diff)
    26     , mLh(lh)
    27     , mRh(rh)
    28     {
    29 
    30     }
    31     virtual ~Diff() {}
     10    RE * getLH() const {return mLh;}
     11    RE * getRH() const {return mRh;}
     12    static Diff * Create(RE * lh, RE * rh) {return new Diff(lh, rh);}
     13    RE_SUBTYPE(Diff)
    3214private:
     15    Diff(RE * lh, RE * rh): RE(ClassTypeId::Diff), mLh(lh), mRh(rh) {}
    3316    RE * const mLh;
    3417    RE * const mRh;
  • icGREP/icgrep-devel/icgrep/re/re_end.h

    r4516 r6226  
    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.
     
    1414class End : public RE {
    1515public:
    16     static inline bool classof(const RE * re) {
    17         return re->getClassTypeId() == ClassTypeId::End;
    18     }
    19     static inline bool classof(const void *) {
    20         return false;
    21     }
    22     virtual ~End() {}
    23 protected:
    24     friend End * makeEnd();
     16    static End * Create() {return new End();}
     17    RE_SUBTYPE(End)
     18private:
    2519    End() : RE(ClassTypeId::End) {}
    2620};
    2721
    28 inline End * makeEnd() {
    29     return new End();
    30 }
     22inline End * makeEnd() {return End::Create();}
    3123
    3224}
  • icGREP/icgrep-devel/icgrep/re/re_group.h

    r6169 r6226  
    1313class Group : public RE {
    1414public:
    15     static inline bool classof(const RE * re) {return re->getClassTypeId() == ClassTypeId::Group;}
    16     static inline bool classof(const void *) {return false;}
    17    
    1815    enum class Mode {CaseInsensitiveMode, GraphemeMode, CompatibilityMode};
    1916    enum class Sense {On, Off};
     
    2118    Sense getSense() const {return mSense;}
    2219    RE * getRE() const {return mExpr;}
    23     friend Group * makeGroup(Mode m, RE * r, Sense s);
    24     void setRE(RE * r) {mExpr = r;}
     20    static Group * Create(Mode m, RE * r, Sense s) {return new Group(m, r, s);}
     21    RE_SUBTYPE(Group)
    2522protected:
    2623    Group(Mode m, RE * r, Sense s) : RE(ClassTypeId::Group), mMode(m), mExpr(r), mSense(s) {}
     
    3330
    3431inline Group * makeGroup(Group::Mode m, RE * r, Group::Sense s = Group::Sense::On) {
    35     return new Group(m, r, s);
     32    return Group::Create(m, r, s);
    3633}
    3734}
  • icGREP/icgrep-devel/icgrep/re/re_intersect.cpp

    r6159 r6226  
    2121            return intersectCC(lh_cc, rh_cc);
    2222    }
    23     return new Intersect(lh, rh);
     23    return Intersect::Create(lh, rh);
    2424}
    2525
  • icGREP/icgrep-devel/icgrep/re/re_intersect.h

    r6223 r6226  
    88class Intersect : public RE {
    99public:
    10     static inline bool classof(const RE * re) {
    11         return re->getClassTypeId() == ClassTypeId::Intersect;
    12     }
    13     static inline bool classof(const void *) {
    14         return false;
    15     }
    16     RE * getLH() const {
    17         return mLh;
    18     }
    19     RE * getRH() const {
    20         return mRh;
    21     }
    22     friend RE * makeIntersect(RE*, RE*);
    23 protected:
    24     Intersect(RE * lh, RE * rh)
    25     : RE(ClassTypeId::Intersect)
    26     , mLh(lh)
    27     , mRh(rh)
    28     {
    29 
    30     }
    31     virtual ~Intersect() {}
     10    RE * getLH() const {return mLh;}
     11    RE * getRH() const {return mRh;}
     12    static Intersect * Create(RE * lh, RE * rh) {return new Intersect(lh, rh);}
     13    RE_SUBTYPE(Intersect)
    3214private:
     15    Intersect(RE * lh, RE * rh): RE(ClassTypeId::Intersect), mLh(lh), mRh(rh) {}
    3316    RE * const mLh;
    3417    RE * const mRh;
  • icGREP/icgrep-devel/icgrep/re/re_range.cpp

    r6173 r6226  
    4444        return lo;
    4545    }
    46     return new Range(lo, hi);
     46    return Range::Create(lo, hi);
    4747}
    4848   
  • icGREP/icgrep-devel/icgrep/re/re_range.h

    r6173 r6226  
    1212class Range : public RE {
    1313public:
    14     static inline bool classof(const RE * re) {
    15         return re->getClassTypeId() == ClassTypeId::Range;
    16     }
    17     static inline bool classof(const void *) {
    18         return false;
    19     }
    20     RE * getLo() const {
    21         return mLo;
    22     }
    23     RE * getHi() const {
    24         return mHi;
    25     }
    26 
    27 protected:
    28     friend RE * makeRange(RE*, RE*);
    29     Range(RE * lh, RE * rh)
    30     : RE(ClassTypeId::Range)
    31     , mLo(lh)
    32     , mHi(rh)
    33     {
    34 
    35     }
    36     virtual ~Range() {}
     14    RE * getLo() const {return mLo;}
     15    RE * getHi() const {return mHi;}
     16    static Range * Create(RE * lh, RE * rh) {return new Range(lh, rh);}
     17    RE_SUBTYPE(Range)
    3718private:
     19    Range(RE * lh, RE * rh) : RE(ClassTypeId::Range), mLo(lh), mHi(rh) {}
    3820    RE * const mLo;
    3921    RE * const mHi;
  • icGREP/icgrep-devel/icgrep/re/re_re.h

    r6225 r6226  
    1212
    1313namespace re {
     14
     15// REs are defined in a class hierarchy supporting llvm::isa, llvm::dyn_cast.
     16#define RE_SUBTYPE(kind) \
     17static inline bool classof(const RE * re) {return re->getClassTypeId() == ClassTypeId::kind;}\
     18static inline bool classof(const void *) {return false;}
    1419
    1520class RE {
  • icGREP/icgrep-devel/icgrep/re/re_rep.cpp

    r6171 r6226  
    4343        int u = rep->getUB();
    4444        if (lb == ub) {
    45             return new Rep(rep->getRE(), l * lb, ubCombine(u, ub));
     45            return Rep::Create(rep->getRE(), l * lb, ubCombine(u, ub));
    4646        }
    4747        else if (u == Rep::UNBOUNDED_REP) {
     
    5151            } else if (l == 1) {
    5252                /*  R{1,}{lb, ub} = R{lb,} */
    53                 return new Rep(rep->getRE(), lb, Rep::UNBOUNDED_REP);
     53                return Rep::Create(rep->getRE(), lb, Rep::UNBOUNDED_REP);
    5454            } else if (lb == 0) {
    5555                /*  R{l,}{0, ub} = R{l,}? */
    56                 return new Rep(rep, 0, 1);
     56                return Rep::Create(rep, 0, 1);
    5757            } else {
    5858                /* R{l,}{lb, ub} = R{l * lb,} */
    59                 return new Rep(rep->getRE(), l * lb, Rep::UNBOUNDED_REP);
     59                return Rep::Create(rep->getRE(), l * lb, Rep::UNBOUNDED_REP);
    6060            }
    6161        }
     
    6464            int n = (u - 2)/(u-l);
    6565            if (lb >= n) {
    66                 return new Rep(rep->getRE(), l * lb, ubCombine(u, ub));
     66                return Rep::Create(rep->getRE(), l * lb, ubCombine(u, ub));
    6767            }
    6868            if ((ub == Rep::UNBOUNDED_REP) || (ub >= n)) {
    69                 RE * r1 = new Rep(rep->getRE(), n * l, ubCombine(u, ub));
     69                RE * r1 = Rep::Create(rep->getRE(), n * l, ubCombine(u, ub));
    7070                RE * r2 = makeRep(rep, lb, n - 1);  // makeRep recursive simplifies.
    7171                return makeAlt({r1, r2});
     
    9090        }
    9191    }
    92     return new Rep(re, lb, ub);
     92    return Rep::Create(re, lb, ub);
    9393}
    9494
  • icGREP/icgrep-devel/icgrep/re/re_rep.h

    r5991 r6226  
    1414class Rep : public RE {
    1515public:
    16     static inline bool classof(const RE * re) {
    17         return re->getClassTypeId() == ClassTypeId::Rep;
    18     }
    19     static inline bool classof(const void *) {
    20         return false;
    21     }
    2216    enum { UNBOUNDED_REP = -1 };
    23     RE * getRE() const;
    24     void setRE(RE * re = nullptr);
    25     int getLB() const;
    26     void setLB(const int lb);
    27     int getUB() const;
    28     void setUB(const int ub);
    29     virtual ~Rep() {}
    30 protected:
    31     friend RE * makeRep(RE *, const int, const int);
    32     Rep(RE * re, const int lb, const int ub);
     17    RE * getRE() const {return mRE;}
     18    int getLB() const {return mLB;}
     19    int getUB() const {return mUB;}
     20    static Rep * Create(RE * r, const int lb, const int ub) {return new Rep(r, lb, ub);}
     21    RE_SUBTYPE(Rep)
    3322private:
     23    Rep(RE * repeated, const int lb, const int ub) : RE(ClassTypeId::Rep), mRE(repeated), mLB(lb), mUB(ub) {}
    3424    RE* mRE;
    3525    int mLB;
    3626    int mUB;
    3727};
    38 
    39 inline Rep::Rep(RE * re, const int lb, const int ub)
    40 : RE(ClassTypeId::Rep)
    41 , mRE(re)
    42 , mLB(lb)
    43 , mUB(ub)
    44 {
    45 
    46 }
    47 
    48 inline RE * Rep::getRE() const {
    49     return mRE;
    50 }
    51 
    52 inline void Rep::setRE(RE * re) {
    53     mRE = re;
    54 }
    55 
    56 inline int Rep::getLB() const {
    57     return mLB;
    58 }
    59 
    60 inline void Rep::setLB(const int lb) {
    61     mLB = lb;
    62 }
    63 
    64 inline int Rep::getUB() const {
    65     return mUB;
    66 }
    67 
    68 inline void Rep::setUB(const int ub) {
    69     mUB = ub;
    70 }
    7128
    7229RE * makeRep(RE * re, const int lower_bound, const int upper_bound);
  • icGREP/icgrep-devel/icgrep/re/re_start.h

    r4516 r6226  
    1414class Start : public RE {
    1515public:
    16     static inline bool classof(const RE * re) {
    17         return re->getClassTypeId() == ClassTypeId::Start;
    18     }
    19     static inline bool classof(const void *) {
    20         return false;
    21     }
    22 protected:
    23     friend Start * makeStart();
     16    static Start * Create() {return new Start();}
     17    RE_SUBTYPE(Start)
     18private:
    2419    Start() : RE(ClassTypeId::Start) {}
    25     virtual ~Start() {}
    2620};
    2721
    28 inline Start * makeStart() {
    29     return new Start();
    30 }
     22inline Start * makeStart() {return Start::Create();}
    3123
    3224}
Note: See TracChangeset for help on using the changeset viewer.