Ignore:
Timestamp:
Mar 10, 2018, 11:44:44 AM (16 months ago)
Author:
cameron
Message:

RE compiler restructuring progress

File:
1 edited

Legend:

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

    r5872 r5897  
    1919#include <cc/alphabet.h>
    2020#include <boost/container/flat_set.hpp>
    21 #include <sstream>
     21#include <llvm/Support/ErrorHandling.h>
     22
    2223
    2324using namespace boost::container;
     
    159160}
    160161
    161 RE * resolveAnchors(RE * r, RE * breakRE) {
     162struct AnchorResolution {
     163    RE * mAnchorRE;
     164    bool mIsNegated;
     165    RE * resolve(RE * r);
     166};
     167   
     168RE * AnchorResolution::resolve(RE * r) {
    162169    if (!hasAnchor(r)) return r;
    163170    if (const Alt * alt = dyn_cast<Alt>(r)) {
     
    165172        list.reserve(alt->size());
    166173        for (RE * item : *alt) {
    167             item = resolveAnchors(item, breakRE);
     174            item = resolve(item);
    168175            list.push_back(item);
    169176        }
     
    173180        list.reserve(seq->size());
    174181        for (RE * item : *seq) {
    175             item = resolveAnchors(item, breakRE);
     182            item = resolve(item);
    176183            list.push_back(item);
    177184        }
    178185        return makeSeq(list.begin(), list.end());
    179186    } else if (Assertion * a = dyn_cast<Assertion>(r)) {
    180         return makeAssertion(resolveAnchors(a->getAsserted(), breakRE), a->getKind(), a->getSense());
     187        return makeAssertion(resolve(a->getAsserted()), a->getKind(), a->getSense());
    181188    } else if (Rep * rep = dyn_cast<Rep>(r)) {
    182         return makeRep(resolveAnchors(rep->getRE(), breakRE), rep->getLB(), rep->getUB());
     189        return makeRep(resolve(rep->getRE()), rep->getLB(), rep->getUB());
    183190    } else if (Diff * diff = dyn_cast<Diff>(r)) {
    184         return makeDiff(resolveAnchors(diff->getLH(), breakRE), resolveAnchors(diff->getRH(), breakRE));
     191        return makeDiff(resolve(diff->getLH()), resolve(diff->getRH()));
    185192    } else if (Intersect * e = dyn_cast<Intersect>(r)) {
    186         return makeIntersect(resolveAnchors(e->getLH(), breakRE), resolveAnchors(e->getRH(), breakRE));
     193        return makeIntersect(resolve(e->getLH()), resolve(e->getRH()));
    187194    } else if (isa<Start>(r)) {
    188         return makeAlt({r, makeLookBehindAssertion(breakRE)});
     195        if (mIsNegated) return makeNegativeLookBehindAssertion(mAnchorRE);
     196        else return makeAlt({makeSOT(),
     197                             makeLookBehindAssertion(mAnchorRE)});
    189198    } else if (isa<End>(r)) {
    190         return makeAlt({r, makeLookAheadAssertion(breakRE)});
    191     }
    192 }
    193 }
     199        if (mIsNegated) return makeNegativeLookAheadAssertion(mAnchorRE);
     200        else return makeAlt({makeEOT(),
     201                             makeLookAheadAssertion(mAnchorRE)});
     202    }
     203}
     204
     205RE * resolveAnchors(RE * r, RE * breakRE) {
     206    AnchorResolution a;
     207    if (const CC * cc = dyn_cast<CC>(breakRE)) {
     208        a.mIsNegated = true;
     209        if (cc->getAlphabet() == &cc::Unicode) {
     210            a.mAnchorRE = makeDiff(makeCC(0, 0x10FFFF), breakRE);
     211        } else if (cc->getAlphabet() == &cc::Byte) {
     212            a.mAnchorRE = makeDiff(makeByte(0, 0xFF), breakRE);
     213        } else {
     214            llvm::report_fatal_error("resolveAnchors: unexpected alphabet " + cc->getAlphabet()->getName());
     215        }
     216    } else {
     217        a.mIsNegated = false;
     218        a.mAnchorRE = breakRE;
     219    }
     220    return a.resolve(r);
     221}
     222                                                       
     223}
Note: See TracChangeset for help on using the changeset viewer.