diff options
author | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2019-08-01 09:08:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-01 09:08:46 -0500 |
commit | 79881c196e29ef341166e7a31c1183e8b537d069 (patch) | |
tree | 25466cceb67c54895bf012fd745dd864d356b153 /src/theory/strings/regexp_operation.cpp | |
parent | 7537ff075dbb2d814d722d2d72586ce78235467c (diff) |
Regular expression intersection modes (#3134)
Diffstat (limited to 'src/theory/strings/regexp_operation.cpp')
-rw-r--r-- | src/theory/strings/regexp_operation.cpp | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/src/theory/strings/regexp_operation.cpp b/src/theory/strings/regexp_operation.cpp index f11254794..7286e2fb4 100644 --- a/src/theory/strings/regexp_operation.cpp +++ b/src/theory/strings/regexp_operation.cpp @@ -47,24 +47,61 @@ RegExpOpr::RegExpOpr() RegExpOpr::~RegExpOpr() {} bool RegExpOpr::checkConstRegExp( Node r ) { - Trace("strings-regexp-cstre") << "RegExp-CheckConstRegExp starts with /" << mkString( r ) << "/" << std::endl; - bool ret = true; - if( d_cstre_cache.find( r ) != d_cstre_cache.end() ) { - ret = d_cstre_cache[r]; - } else { - if(r.getKind() == kind::STRING_TO_REGEXP) { - Node tmp = Rewriter::rewrite( r[0] ); - ret = tmp.isConst(); - } else { - for(unsigned i=0; i<r.getNumChildren(); ++i) { - if(!checkConstRegExp(r[i])) { - ret = false; break; + Trace("strings-regexp-cstre") + << "RegExpOpr::checkConstRegExp /" << mkString(r) << "/" << std::endl; + RegExpConstType rct = getRegExpConstType(r); + return rct != RE_C_VARIABLE; +} + +RegExpConstType RegExpOpr::getRegExpConstType(Node r) +{ + std::unordered_map<Node, RegExpConstType, NodeHashFunction>::iterator it; + std::vector<TNode> visit; + TNode cur; + visit.push_back(r); + do + { + cur = visit.back(); + visit.pop_back(); + it = d_constCache.find(cur); + + if (it == d_constCache.end()) + { + Kind ck = cur.getKind(); + if (ck == STRING_TO_REGEXP) + { + Node tmp = Rewriter::rewrite(cur[0]); + d_constCache[cur] = + tmp.isConst() ? RE_C_CONRETE_CONSTANT : RE_C_VARIABLE; + } + else if (ck == REGEXP_SIGMA || ck == REGEXP_RANGE) + { + d_constCache[cur] = RE_C_CONSTANT; + } + else + { + d_constCache[cur] = RE_C_UNKNOWN; + visit.push_back(cur); + visit.insert(visit.end(), cur.begin(), cur.end()); + } + } + else if (it->second == RE_C_UNKNOWN) + { + RegExpConstType ret = RE_C_CONRETE_CONSTANT; + for (const Node& cn : cur) + { + it = d_constCache.find(cn); + Assert(it != d_constCache.end()); + if (it->second > ret) + { + ret = it->second; } } + d_constCache[cur] = ret; } - d_cstre_cache[r] = ret; - } - return ret; + } while (!visit.empty()); + Assert(d_constCache.find(r) != d_constCache.end()); + return d_constCache[r]; } // 0-unknown, 1-yes, 2-no |