Ignore:
Timestamp:
Jul 12, 2015, 12:10:59 AM (4 years ago)
Author:
nmedfort
Message:

Moved 'resolveProperties' into CC_NameMap as a single call for each unique Name.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_namemap.cpp

    r4516 r4660  
    88#include <re/re_intersect.h>
    99#include <re/re_assertion.h>
    10 #include <re/printer_re.h>
    11 #include <iostream>
     10#include <UCD/resolve_properties.h>
    1211
    1312using namespace re;
     
    1514namespace cc {
    1615
    17 RE * CC_NameMap::process(RE * re, const CC_type t) {
     16RE * CC_NameMap::process(RE * re, const CC_type type) {
     17
    1818    if (Alt * alt = dyn_cast<Alt>(re)) {
    1919        for (auto i = alt->begin(); i != alt->end(); ++i) {
    20             *i = process(*i, t);
     20            *i = process(*i, type);
    2121        }
    2222    }
    2323    else if (Seq * seq = dyn_cast<Seq>(re)) {
    2424        for (auto i = seq->begin(); i != seq->end(); ++i) {
    25             *i = process(*i, t);
     25            *i = process(*i, type);
    2626        }
    2727    }
    2828    else if (Rep * rep = dyn_cast<Rep>(re)) {
    29         rep->setRE(process(rep->getRE(), t));
     29        rep->setRE(process(rep->getRE(), type));
    3030    }
    3131    else if (Assertion * a = dyn_cast<Assertion>(re)) {
    32         a->setAsserted(process(a->getAsserted(), t));
     32        a->setAsserted(process(a->getAsserted(), type));
    3333    }
    3434    else if (Diff * diff = dyn_cast<Diff>(re)) {
    35         diff->setRH(process(diff->getRH(), t));
    36         diff->setLH(process(diff->getLH(), t));
     35        diff->setRH(process(diff->getRH(), type));
     36        diff->setLH(process(diff->getLH(), type));
    3737    }
    3838    else if (Intersect * e = dyn_cast<Intersect>(re)) {
    39         e->setRH(process(e->getRH(), t));
    40         e->setLH(process(e->getLH(), t));
     39        e->setRH(process(e->getRH(), type));
     40        e->setLH(process(e->getLH(), type));
    4141    }
    42     else if (Name * nameNode = dyn_cast<Name>(re)) {
    43         RE * def = nameNode->getDefinition();
    44         if (def && !isa<CC>(def)) {
    45             nameNode->setDefinition(process(def, t));
    46         }
    47         std::string classname = nameNode->getName();
     42    else if (Name * name = dyn_cast<Name>(re)) {
     43        std::string classname = name->getName();
    4844        auto f = mNameMap.find(classname);
    4945        if (f == mNameMap.end()) {
    50             // Insert into the name map.
    51             return insert(std::move(classname), nameNode);
     46            if (name->getType() == Name::Type::UnicodeProperty) {
     47                resolveProperty(name);
     48            }
     49            RE * def = name->getDefinition();
     50            if (def) {
     51                name->setDefinition(process(def, type));
     52            }
     53            return insert(std::move(classname), name);
    5254        }
    5355        return f->second;
    5456    }
    5557    else if (CC * cc = dyn_cast<CC>(re)) {
    56         std::string classname = cc->canonicalName(t);
     58        std::string classname = cc->canonicalName(type);
    5759        auto f = mNameMap.find(classname);
    5860        if (f == mNameMap.end()) {
    59             Name * n = (t == ByteClass) ? makeByteName(classname, cc) : makeName(classname, cc);
    60             return insert(std::move(classname), n);
     61            return insert(std::move(classname), (type == ByteClass) ? makeByteName(classname, cc) : makeName(classname, cc));
    6162        }
    6263        return f->second;
     
    6869    std::string retval = "";
    6970    for (Name * name : mNameVector) {
    70         retval.append("mNameMap[" +  name->getName() + "] = " + Printer_RE::PrintRE(name->getDefinition()) + "]\n");
     71        retval.append("mNameMap[" +  name->getName() + "] = " + Printer_RE::PrintRE(name->getDefinition()) + "\n");
    7172    }
    7273    return retval;
  • icGREP/icgrep-devel/icgrep/cc/cc_namemap.hpp

    r4603 r4660  
    88#include "re/re_cc.h"
    99
    10 namespace re {
    11     class CC;
    12     class RE;
    13 }
    1410
    1511namespace cc {
     
    2622    re::RE * process(re::RE * re, const re::CC_type t);
    2723
    28     inline const re::Name * operator[](const std::string & name) const {
    29         auto f = mNameMap.find(name);
    30         if (f == mNameMap.end()) {
    31             return nullptr;
    32         }
    33         return f->second;
     24    inline void clear() {
     25        mNameMap.clear();
     26        mNameVector.clear();
    3427    }
    3528
     
    4639private:
    4740
    48     inline re::Name * insert(std::string && name, re::Name * re) {
     41    inline re::Name * insert(NameMap::key_type && name, re::Name * re) {
    4942        mNameMap.insert(std::make_pair(std::move(name), re));
    5043        mNameVector.push_back(re);
Note: See TracChangeset for help on using the changeset viewer.