Changeset 5929 for icGREP/icgrep-devel


Ignore:
Timestamp:
Mar 22, 2018, 1:20:47 PM (12 months ago)
Author:
cameron
Message:

mayMatchCC

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

Legend:

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

    r5887 r5929  
    2626namespace re {
    2727
     28bool mayMatchCC(RE * re, CC * cc) {
     29    if (CC * cc0 = dyn_cast<CC>(re)) {
     30        return intersects(cc0, cc);
     31    } else if (Seq * seq = dyn_cast<Seq>(re)) {
     32        for (auto s : * seq) {
     33            if (mayMatchCC(s, cc)) return true;
     34        }
     35        return false;
     36    } else if (Alt * alt = dyn_cast<Alt>(re)) {
     37        for (auto a : * alt) {
     38            if (mayMatchCC(a, cc)) return true;
     39        }
     40        return false;
     41    } else if (Rep * rep = dyn_cast<Rep>(re)) {
     42        return mayMatchCC(rep->getRE(), cc);
     43    } else if (Group * g = dyn_cast<Group>(re)) {
     44        return mayMatchCC(g->getRE(), cc);
     45    } else if (Diff * diff = dyn_cast<Diff>(re)) {
     46        // We only need exclude from the LH operand.
     47        return mayMatchCC(diff->getLH(), cc);
     48    } else if (Intersect * e = dyn_cast<Intersect>(re)) {
     49        // We only need check  one of the operands.
     50        return mayMatchCC(e->getLH(), cc);
     51    } else if (isa<Start>(re) || isa<End>(re) || isa<Assertion>(re)) {
     52        return false;
     53    } else if (Name * n = dyn_cast<Name>(re)) {
     54        if (n->getType() ==  Name::Type::ZeroWidth) {
     55            return false;
     56        }
     57        RE * defn = n->getDefinition();
     58        return mayMatchCC(defn, cc);
     59    } else {
     60        report_fatal_error("exclude_CC: unhandled regexp type");
     61    }
     62}
     63 
     64   
    2865RE * exclude_CC(RE * re, CC * cc) {
     66    if (!mayMatchCC(re, cc)) return re;
    2967    if (CC * cc0 = dyn_cast<CC>(re)) {
    3068        if (intersects(cc0, cc)) return subtractCC(cc0, cc);
  • icGREP/icgrep-devel/icgrep/re/exclude_CC.h

    r5778 r5929  
    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.
     
    1212    class CC;
    1313   
     14    /*  Return true if a string matched by r may contain a character in cc. */
     15    bool mayMatchCC(RE * r, CC * cc);
     16   
    1417    /* Transform a regular expression r so that matched strings do not include
    1518       matches to any character within the given character class cc.
Note: See TracChangeset for help on using the changeset viewer.