Changeset 6239 for icGREP


Ignore:
Timestamp:
Dec 15, 2018, 9:29:27 PM (2 months ago)
Author:
cameron
Message:

Final Lookahead Promotion

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

Legend:

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

    r5896 r6239  
    11/*
    2  *  Copyright (c) 2017 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.
     
    1010#include "re_alt.h"
    1111#include "re_nullable.h"
     12#include <re/re_toolchain.h>
    1213
    1314using namespace llvm;
     
    4041    return re;
    4142}
     43   
     44   
     45struct FinalLookaheadPromotion : public RE_Transformer {
     46    FinalLookaheadPromotion() : RE_Transformer("FinalLookaheadPromotion") {}
     47    RE * transformSeq(Seq * s) override {
     48        if (s->empty()) return s;
     49        RE * t = transform(s->back());
     50        if (s == t) return s;
     51        std::vector<RE *> elems;
     52        for (unsigned i = 0; i < s->size() - 1; i++) {
     53            elems.push_back((*s)[i]);
     54        }
     55        elems.push_back(t);
     56        return makeSeq(elems.begin(), elems.end());
     57    }
     58    RE * transformRep(Rep * r) override { return r;}
     59    RE * transformAssertion(Assertion * a) override {
     60        if ((a->getKind() == Assertion::Kind::Lookahead) && (a->getSense() == Assertion::Sense::Positive)) {
     61            return transform(a->getAsserted());
     62        }
     63        return a;
     64    }
     65};
     66   
     67RE * lookaheadPromotion(RE * r) {
     68    return FinalLookaheadPromotion().transformRE(r);
    4269}
     70}
  • icGREP/icgrep-devel/icgrep/re/re_assertion.h

    r6226 r6239  
    8989   
    9090RE * expandBoundaryAssertion(RE * r);
     91   
     92RE * lookaheadPromotion(RE * r);
    9193}
    9294
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r6223 r6239  
    9090    }
    9191    r = removeUnneededCaptures(r);
     92    r = lookaheadPromotion(r);
    9293    r = resolveGraphemeMode(r, false /* not in grapheme mode at top level*/);
    9394    r = re::resolveUnicodeNames(r);
Note: See TracChangeset for help on using the changeset viewer.