if(r1 == r2) {\r
rNode = r1;\r
} else if(r1 == d_emptyRegexp || r2 == d_emptyRegexp) {\r
- Trace("regexp-intersect") << "INTERSECT Case 1: one empty RE" << std::endl;\r
rNode = d_emptyRegexp;\r
} else if(r1 == d_emptySingleton || r2 == d_emptySingleton) {\r
- Trace("regexp-intersect") << "INTERSECT Case 2: one empty Singleton" << std::endl;\r
Node exp;\r
int r = delta((r1 == d_emptySingleton ? r2 : r1), exp);\r
if(r == 0) {\r
//TODO: variable\r
spflag = true;\r
- //Assert( false, "Unsupported Yet, 892 REO" );\r
} else if(r == 1) {\r
rNode = d_emptySingleton;\r
} else {\r
rNode = d_emptyRegexp;\r
}\r
} else {\r
- Trace("regexp-intersect") << "INTERSECT Case 3: must compare" << std::endl;\r
std::set< unsigned > cset, cset2;\r
- std::vector< unsigned > cdiff;\r
- std::set< Node > vset;\r
+ std::set< Node > vset, vset2;\r
getCharSet(r1, cset, vset);\r
- getCharSet(r2, cset2, vset);\r
- if(vset.empty()) {\r
- std::set_symmetric_difference(cset.begin(), cset.end(), cset2.begin(), cset2.end(), std::back_inserter(cdiff));\r
- if(cdiff.empty()) {\r
- Trace("regexp-intersect") << "INTERSECT Case 3.1: compare" << std::endl;\r
- cset.clear();\r
- firstChars(r1, cset, vset);\r
- std::vector< Node > vec_nodes;\r
- for(std::set<unsigned>::const_iterator itr = cset.begin();\r
- itr != cset.end(); itr++) {\r
- CVC4::String c( CVC4::String::convertUnsignedIntToChar(*itr) );\r
- std::pair< Node, Node > p(r1, r2);\r
- if(cache[ *itr ].find(p) == cache[ *itr ].end()) {\r
- Node r1l = derivativeSingle(r1, c);\r
- Node r2l = derivativeSingle(r2, c);\r
- std::map< unsigned, std::set< PairNodes > > cache2(cache);\r
- PairNodes p(r1l, r2l);\r
- cache2[ *itr ].insert( p );\r
- Node rt = intersectInternal(r1l, r2l, cache2, spflag);\r
- if(spflag) {\r
- //TODO:\r
- return Node::null();\r
- }\r
- rt = Rewriter::rewrite( NodeManager::currentNM()->mkNode(kind::REGEXP_CONCAT, \r
- NodeManager::currentNM()->mkNode(kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst(c)), rt) );\r
- vec_nodes.push_back(rt);\r
+ getCharSet(r2, cset2, vset2);\r
+ if(vset.empty() && vset2.empty()) {\r
+ cset.clear();\r
+ firstChars(r1, cset, vset);\r
+ std::vector< Node > vec_nodes;\r
+ for(std::set<unsigned>::const_iterator itr = cset.begin();\r
+ itr != cset.end(); itr++) {\r
+ CVC4::String c( CVC4::String::convertUnsignedIntToChar(*itr) );\r
+ std::pair< Node, Node > p(r1, r2);\r
+ if(cache[ *itr ].find(p) == cache[ *itr ].end()) {\r
+ Node r1l = derivativeSingle(r1, c);\r
+ Node r2l = derivativeSingle(r2, c);\r
+ std::map< unsigned, std::set< PairNodes > > cache2(cache);\r
+ PairNodes p(r1l, r2l);\r
+ cache2[ *itr ].insert( p );\r
+ Node rt = intersectInternal(r1l, r2l, cache2, spflag);\r
+ if(spflag) {\r
+ //TODO:\r
+ return Node::null();\r
}\r
+ rt = Rewriter::rewrite( NodeManager::currentNM()->mkNode(kind::REGEXP_CONCAT, \r
+ NodeManager::currentNM()->mkNode(kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst(c)), rt) );\r
+ vec_nodes.push_back(rt);\r
}\r
- rNode = vec_nodes.size()==0 ? d_emptyRegexp : vec_nodes.size()==1 ? vec_nodes[0] :\r
- NodeManager::currentNM()->mkNode(kind::REGEXP_UNION, vec_nodes);\r
- rNode = Rewriter::rewrite( rNode );\r
- } else {\r
- Trace("regexp-intersect") << "INTERSECT Case 3.2: diff cset" << std::endl;\r
- rNode = d_emptyRegexp;\r
}\r
+ rNode = vec_nodes.size()==0 ? d_emptyRegexp : vec_nodes.size()==1 ? vec_nodes[0] :\r
+ NodeManager::currentNM()->mkNode(kind::REGEXP_UNION, vec_nodes);\r
+ rNode = Rewriter::rewrite( rNode );\r
} else {\r
//TODO: non-empty var set\r
spflag = true;\r
- //Assert( false, "Unsupported Yet, 927 REO" );\r
}\r
}\r
d_inter_cache[p] = rNode;\r
std::set<unsigned> cset;\r
SetNodes vset;\r
firstChars(r, cset, vset);\r
- Assert(!vset.empty(), "Regexp 1298 Error");\r
std::vector< Node > vec_nodes;\r
for(unsigned i=0; i<d_card; i++) {\r
CVC4::String c = CVC4::String::convertUnsignedIntToChar(i);\r
rNode = vec_nodes.size()==0? d_emptyRegexp : vec_nodes.size()==1? vec_nodes[0] :\r
NodeManager::currentNM()->mkNode(kind::REGEXP_UNION, vec_nodes);\r
}\r
+ rNode = Rewriter::rewrite(rNode);\r
std::pair< Node, int > p(rNode, ret);\r
d_compl_cache[r] = p;\r
}\r
std::string RegExpOpr::niceChar( Node r ) {\r
if(r.isConst()) {\r
std::string s = r.getConst<CVC4::String>().toString() ;\r
- return s == "" ? "{E}" : ( s == " " ? "{ }" : s );\r
+ return s == "" ? "{E}" : ( s == " " ? "{ }" : s.size()>1? "("+s+")" : s );\r
} else {\r
- return r.toString();\r
+ std::string ss = "$" + r.toString();\r
+ return ss;\r
}\r
}\r
std::string RegExpOpr::mkString( Node r ) {\r
break;\r
}\r
case kind::REGEXP_CONCAT: {\r
- //retStr += "(";\r
+ retStr += "(";\r
for(unsigned i=0; i<r.getNumChildren(); ++i) {\r
//if(i != 0) retStr += ".";\r
retStr += mkString( r[i] );\r
}\r
- //retStr += ")";\r
+ retStr += ")";\r
break;\r
}\r
case kind::REGEXP_UNION: {\r