Ignore:
Timestamp:
Dec 28, 2017, 1:15:13 PM (15 months ago)
Author:
nmedfort
Message:

Bug fix for RE local + some clean up of RE local and the RE Compiler

File:
1 edited

Legend:

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

    r5805 r5812  
    1919#include <re/re_intersect.h>
    2020#include <re/re_assertion.h>
    21 #include <re/printer_re.h>
    2221#include <llvm/Support/ErrorHandling.h>
    23 #include <llvm/Support/raw_ostream.h>
    24 #include <llvm/Support/Debug.h>
    2522#include <map>
     23
    2624
    2725using namespace llvm;
     
    2927namespace re {
    3028
    31 RE * reverse_helper(RE * re, std::map<std::string, Name *> & captureMap) {
    32     if (CC * cc = dyn_cast<CC>(re)) {
     29using CaptureMap = std::map<std::string, re::Name *>;
     30
     31RE * reverse(RE * re, CaptureMap & captureMap) {
     32    if (isa<CC>(re)) {
    3333        return re;
    3434    } else if (Range * rg = dyn_cast<Range>(re)) {
     
    3737        std::vector<RE*> list;
    3838        for (auto i = seq->rbegin(); i != seq->rend(); ++i) {
    39             list.push_back(reverse_helper(*i, captureMap));
     39            list.push_back(reverse(*i, captureMap));
    4040        }
    4141        return makeSeq(list.begin(), list.end());
     
    4343        std::vector<RE*> list;
    4444        for (auto i = alt->begin(); i != alt->end(); ++i) {
    45             list.push_back(reverse_helper(*i, captureMap));
     45            list.push_back(reverse(*i, captureMap));
    4646        }
    4747        return makeAlt(list.begin(), list.end());
    4848    } else if (Rep * rep = dyn_cast<Rep>(re)) {
    49         return makeRep(reverse_helper(rep->getRE(), captureMap), rep->getLB(), rep->getUB());
     49        return makeRep(reverse(rep->getRE(), captureMap), rep->getLB(), rep->getUB());
    5050    } else if (Group * g = dyn_cast<Group>(re)) {
    51         return makeGroup(g->getMode(), reverse_helper(g->getRE(), captureMap), g->getSense());
     51        return makeGroup(g->getMode(), reverse(g->getRE(), captureMap), g->getSense());
    5252    } else if (Diff * diff = dyn_cast<Diff>(re)) {
    53         return makeDiff(reverse_helper(diff->getLH(), captureMap), reverse_helper(diff->getRH(), captureMap));
     53        return makeDiff(reverse(diff->getLH(), captureMap), reverse(diff->getRH(), captureMap));
    5454    } else if (Intersect * e = dyn_cast<Intersect>(re)) {
    55         return makeIntersect(reverse_helper(e->getLH(), captureMap), reverse_helper(e->getRH(), captureMap));
     55        return makeIntersect(reverse(e->getLH(), captureMap), reverse(e->getRH(), captureMap));
    5656    } else if (Assertion * a = dyn_cast<Assertion>(re)) {
    57         return makeAssertion(reverse_helper(a->getAsserted(), captureMap), Assertion::reverseKind(a->getKind()), a->getSense());
     57        return makeAssertion(reverse(a->getAsserted(), captureMap), Assertion::reverseKind(a->getKind()), a->getSense());
    5858    } else if (isa<Start>(re)) {
    5959        return makeEnd();
     
    6767                return makeName(n->getNamespace(), n->getName(), Name::Type::UnicodeProperty);
    6868            case Name::Type::ZeroWidth:
    69                 return makeZeroWidth(n->getName(), reverse_helper(n->getDefinition(), captureMap));
    70             case Name::Type::Capture: 
     69                return makeZeroWidth(n->getName(), reverse(n->getDefinition(), captureMap));
     70            case Name::Type::Capture:
    7171                {
    7272                    std::string cname = n->getName();
     
    7777                    else {
    7878                        std::string newName = "\\" + std::to_string(captureMap.size() + 1);
    79                         Name * capture = makeCapture(newName, reverse_helper(n->getDefinition(), captureMap));
     79                        Name * capture = makeCapture(newName, reverse(n->getDefinition(), captureMap));
    8080                        captureMap.insert(std::make_pair(cname, capture));
    8181                        return capture;
     
    9292                    else {
    9393                        std::string newName = "\\" + std::to_string(captureMap.size() + 1);
    94                         Name * capture = makeCapture(newName, reverse_helper(referent->getDefinition(), captureMap));
     94                        Name * capture = makeCapture(newName, reverse(referent->getDefinition(), captureMap));
    9595                        captureMap.insert(std::make_pair(cname, capture));
    9696                        return capture;
     
    111111
    112112RE * reverse(RE * re) {
    113     std::map<std::string, Name *> captureMap;
    114     return reverse_helper(re, captureMap);
     113    CaptureMap captureMap;
     114    return reverse(re, captureMap);
    115115}
     116
    116117}
Note: See TracChangeset for help on using the changeset viewer.