Ignore:
Timestamp:
Jun 25, 2015, 3:47:56 PM (4 years ago)
Author:
nmedfort
Message:

Upload of an untested (inactive) UCD compiler.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_cc.cpp

    r4614 r4617  
    156156    return cci;
    157157}
    158 
    159 /** ------------------------------------------------------------------------------------------------------------- *
    160  * @brief rangeIntersect
    161  * @param cc
    162  * @param lo
    163  * @param hi
    164  ** ------------------------------------------------------------------------------------------------------------- */
    165 CC * rangeIntersect(const CC * cc, const codepoint_t lo, const codepoint_t hi) {
    166     assert ("cc cannot be null" && cc);
    167     CC * intersect = makeCC();
    168     for (const auto & i : *cc) {
    169         if ((lo_codepoint(i) <= hi) && (hi_codepoint(i) >= lo)) {
    170             intersect->insert_range(std::max(lo, lo_codepoint(i)), std::min(hi, hi_codepoint(i)));
    171         }
    172     }
    173     return intersect;
    174 }
    175 
    176 /** ------------------------------------------------------------------------------------------------------------- *
    177  * @brief rangeGaps
    178  * @param cc
    179  * @param lo
    180  * @param hi
    181  ** ------------------------------------------------------------------------------------------------------------- */
    182 CC * rangeGaps(const CC * cc, const codepoint_t lo, const codepoint_t hi) {
    183     assert ("cc cannot be null" && cc);
    184     CC * gaps = makeCC();
    185     codepoint_t cp = lo;
    186     if (cp < hi) {
    187         auto i = cc->cbegin(), end = cc->cend();
    188         for (; i != end && cp < hi; ++i) {
    189             if (hi_codepoint(i) < cp) {
    190                 continue;
    191             }
    192             else if (lo_codepoint(i) > cp) {
    193                 gaps->insert_range(cp, lo_codepoint(i) - 1);
    194             }
    195             cp = hi_codepoint(i) + 1;
    196         }
    197         if (cp < hi) {
    198             gaps->insert_range(cp, hi);
    199         }
    200     }
    201     return gaps;
    202 }
    203 
    204 /** ------------------------------------------------------------------------------------------------------------- *
    205  * @brief outerRanges
    206  * @param cc
    207  ** ------------------------------------------------------------------------------------------------------------- */
    208 CC * outerRanges(const CC * cc) {
    209     assert ("cc cannot be null" && cc);
    210     CC * ranges = makeCC();
    211     auto i = cc->cbegin();
    212     const auto end = cc->cend();
    213     for (auto j = i; ++j != end; ) {
    214         if (hi_codepoint(j) > hi_codepoint(i)) {
    215             ranges->insert_range(lo_codepoint(i), hi_codepoint(i));
    216             i = j;
    217         }
    218     }
    219     return ranges;
    220 }
    221 
    222 /** ------------------------------------------------------------------------------------------------------------- *
    223  * @brief innerRanges
    224  * @param cc
    225  ** ------------------------------------------------------------------------------------------------------------- */
    226 CC * innerRanges(const CC * cc) {
    227     assert ("cc cannot be null" && cc);
    228     CC * ranges = makeCC();
    229     auto i = cc->cbegin();
    230     const auto end = cc->cend();
    231     for (auto j = i; ++j != end; ) {
    232         if (hi_codepoint(j) <= hi_codepoint(i)) {
    233             ranges->insert_range(lo_codepoint(j), hi_codepoint(j));
    234         }
    235         else {
    236             i = j;
    237         }
    238     }
    239     return ranges;
    240 }
    241158   
    242159}
  • icGREP/icgrep-devel/icgrep/re/re_cc.h

    r4614 r4617  
    127127    friend CC * makeCC(const codepoint_t lo, const codepoint_t hi);
    128128    friend CC * makeCC(const CC * cc1, const CC * cc2);
     129    friend CC * makeCC(const std::initializer_list<interval_t> list);
     130    friend CC * makeCC(const std::vector<interval_t> & list);
    129131    friend CC * subtractCC(const CC * cc1, const CC * cc2);
     132
    130133    inline CC()
    131134    : RE(ClassTypeId::CC)
     
    146149    CC(const CC * cc1, const CC * cc2);
    147150
     151    template <typename itr>
     152    CC * initialize(itr begin, itr end);
    148153private:   
    149154    IntervalVector mSparseCharSet;
     
    167172}
    168173
    169 inline codepoint_t & lo_codepoint(CC::reference i) {
     174inline codepoint_t & lo_codepoint(interval_t & i) {
    170175    return std::get<0>(i);
    171176}
    172 inline codepoint_t lo_codepoint(CC::const_reference i) {
     177inline codepoint_t lo_codepoint(const interval_t & i) {
    173178    return std::get<0>(i);
    174179}
     
    180185}
    181186
    182 inline codepoint_t & hi_codepoint(CC::reference i) {
     187inline codepoint_t & hi_codepoint(interval_t & i) {
    183188    return std::get<1>(i);
    184189}
    185 inline codepoint_t hi_codepoint(CC::const_reference i) {
     190inline codepoint_t hi_codepoint(const interval_t & i) {
    186191    return std::get<1>(i);
    187192}
     
    191196inline codepoint_t hi_codepoint(const CC::const_iterator i) {
    192197    return hi_codepoint(*i);
     198}
     199
     200template<typename itr>
     201CC * CC::initialize(itr begin, itr end) {
     202    mSparseCharSet.resize(std::distance(begin, end));
     203    for (auto i = begin; i != end; ++i) {
     204        assert (i == begin || lo_codepoint(i) > max_codepoint());
     205        mSparseCharSet[std::distance(begin, i)] = *i;
     206    }
     207    return this;
    193208}
    194209
     
    218233}
    219234
     235inline CC * makeCC(const std::initializer_list<interval_t> list) {
     236    return makeCC()->initialize(list.begin(), list.end());
     237}
     238
     239inline CC * makeCC(const std::vector<interval_t> & list) {
     240    return makeCC()->initialize(list.begin(), list.end());
     241}
     242
    220243CC * subtractCC(const CC * a, const CC * b);
    221244   
     
    224247CC * caseInsensitize(const CC * cc);
    225248
    226 CC * rangeIntersect(const CC * cc, const codepoint_t lo, const codepoint_t hi);
    227 
    228 CC * rangeGaps(const CC * cc, const codepoint_t lo, const codepoint_t hi);
    229 
    230 CC * outerRanges(const CC * cc);
    231 
    232 CC * innerRanges(const CC * cc);
    233 
    234249}
    235250
Note: See TracChangeset for help on using the changeset viewer.