}
case kind::CONST_STRING: {
- const std::vector<unsigned int>& s = n.getConst<String>().getVec();
+ //const std::vector<unsigned int>& s = n.getConst<String>().getVec();
+ std::string s = n.getConst<String>().toString();
out << '"';
for(size_t i = 0; i < s.size(); ++i) {
- char c = String::convertUnsignedIntToChar(s[i]);
+ //char c = String::convertUnsignedIntToChar(s[i]);
+ char c = s[i];
if(c == '"') {
if(d_variant == z3str_variant || d_variant == smt2_0_variant) {
out << "\\\"";
}
}
-void RegExpOpr::firstChars( Node r, std::set<char> &pcset, SetNodes &pvset ) {
+void RegExpOpr::firstChars( Node r, std::set<unsigned char> &pcset, SetNodes &pvset ) {
Trace("regexp-fset") << "Start FSET(" << mkString(r) << ")" << std::endl;
- std::map< Node, std::pair< std::set<char>, SetNodes > >::const_iterator itr = d_fset_cache.find(r);
+ std::map< Node, std::pair< std::set<unsigned char>, SetNodes > >::const_iterator itr = d_fset_cache.find(r);
if(itr != d_fset_cache.end()) {
pcset.insert((itr->second).first.begin(), (itr->second).first.end());
pvset.insert((itr->second).second.begin(), (itr->second).second.end());
} else {
- std::set<char> cset;
+ std::set<unsigned char> cset;
SetNodes vset;
int k = r.getKind();
switch( k ) {
break;
}
case kind::REGEXP_SIGMA: {
- for(char i='\0'; i<=d_lastchar; i++) {
+ for(unsigned char i='\0'; i<=d_lastchar; i++) {
cset.insert(i);
}
break;
}
pcset.insert(cset.begin(), cset.end());
pvset.insert(vset.begin(), vset.end());
- std::pair< std::set<char>, SetNodes > p(cset, vset);
+ std::pair< std::set<unsigned char>, SetNodes > p(cset, vset);
d_fset_cache[r] = p;
}
if(Trace.isOn("regexp-fset")) {
Trace("regexp-fset") << "END FSET(" << mkString(r) << ") = {";
- for(std::set<char>::const_iterator itr = pcset.begin();
+ for(std::set<unsigned char>::const_iterator itr = pcset.begin();
itr != pcset.end(); itr++) {
if(itr != pcset.begin()) {
Trace("regexp-fset") << ",";
}
}
-bool RegExpOpr::follow( Node r, CVC4::String c, std::vector< char > &vec_chars ) {
+bool RegExpOpr::follow( Node r, CVC4::String c, std::vector< unsigned char > &vec_chars ) {
int k = r.getKind();
switch( k ) {
case kind::STRING_TO_REGEXP:
{
if(r[0].isConst()) {
if(r[0] != d_emptyString) {
- char t1 = r[0].getConst< CVC4::String >().getFirstChar();
+ unsigned char t1 = r[0].getConst< CVC4::String >().getFirstChar();
if(c.isEmptyString()) {
vec_chars.push_back( t1 );
return true;
} else {
- char t2 = c.getFirstChar();
+ unsigned char t2 = c.getFirstChar();
if(t1 != t2) {
return false;
} else {
break;
case kind::REGEXP_INTER:
{
- std::vector< char > vt2;
+ std::vector< unsigned char > vt2;
for(unsigned i=0; i<r.getNumChildren(); ++i) {
- std::vector< char > v_tmp;
+ std::vector< unsigned char > v_tmp;
if( !follow(r[i], c, v_tmp) ) {
return false;
}
- std::vector< char > vt3(vt2);
+ std::vector< unsigned char > vt3(vt2);
vt2.clear();
std::set_intersection( vt3.begin(), vt3.end(), v_tmp.begin(), v_tmp.end(), vt2.begin() );
if(vt2.size() == 0) {
}
}
-Node RegExpOpr::mkAllExceptOne( char exp_c ) {
+Node RegExpOpr::mkAllExceptOne( unsigned char exp_c ) {
std::vector< Node > vec_nodes;
- for(char c=d_char_start; c<=d_char_end; ++c) {
+ for(unsigned char c=d_char_start; c<=d_char_end; ++c) {
if(c != exp_c ) {
Node n = NodeManager::currentNM()->mkNode( kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst( ::CVC4::String( c ) ) );
vec_nodes.push_back( n );
}
}
-void RegExpOpr::getCharSet( Node r, std::set<char> &pcset, SetNodes &pvset ) {
- std::map< Node, std::pair< std::set<char>, SetNodes > >::const_iterator itr = d_cset_cache.find(r);
+void RegExpOpr::getCharSet( Node r, std::set<unsigned char> &pcset, SetNodes &pvset ) {
+ std::map< Node, std::pair< std::set<unsigned char>, SetNodes > >::const_iterator itr = d_cset_cache.find(r);
if(itr != d_cset_cache.end()) {
pcset.insert((itr->second).first.begin(), (itr->second).first.end());
pvset.insert((itr->second).second.begin(), (itr->second).second.end());
} else {
- std::set<char> cset;
+ std::set<unsigned char> cset;
SetNodes vset;
int k = r.getKind();
switch( k ) {
break;
}
case kind::REGEXP_SIGMA: {
- for(char i='\0'; i<=d_lastchar; i++) {
+ for(unsigned char i='\0'; i<=d_lastchar; i++) {
cset.insert(i);
}
break;
}
case kind::REGEXP_RANGE: {
- char a = r[0].getConst<String>().getFirstChar();
- char b = r[1].getConst<String>().getFirstChar();
- for(char i=a; i<=b; i++) {
+ unsigned char a = r[0].getConst<String>().getFirstChar();
+ unsigned char b = r[1].getConst<String>().getFirstChar();
+ for(unsigned char i=a; i<=b; i++) {
cset.insert(i);
}
break;
}
pcset.insert(cset.begin(), cset.end());
pvset.insert(vset.begin(), vset.end());
- std::pair< std::set<char>, SetNodes > p(cset, vset);
+ std::pair< std::set<unsigned char>, SetNodes > p(cset, vset);
d_cset_cache[r] = p;
Trace("regexp-cset") << "CSET( " << mkString(r) << " ) = { ";
- for(std::set<char>::const_iterator itr = cset.begin();
+ for(std::set<unsigned char>::const_iterator itr = cset.begin();
itr != cset.end(); itr++) {
Trace("regexp-cset") << (*itr) << ",";
}
rNode = itrcache->second;
} else {
Trace("regexp-int-debug") << " ... normal without cache" << std::endl;
- std::vector< char > cset;
- std::set< char > cset1, cset2;
+ std::vector< unsigned char > cset;
+ std::set< unsigned char > cset1, cset2;
std::set< Node > vset1, vset2;
firstChars(r1, cset1, vset1);
firstChars(r2, cset2, vset2);
}
if(Trace.isOn("regexp-int-debug")) {
Trace("regexp-int-debug") << "Try CSET(" << cset.size() << ") = {";
- for(std::vector<char>::const_iterator itr = cset.begin();
+ for(std::vector<unsigned char>::const_iterator itr = cset.begin();
itr != cset.end(); itr++) {
//CVC4::String c( *itr );
if(itr != cset.begin()) {
Trace("regexp-int-debug") << std::endl;
}
std::map< PairNodes, Node > cacheX;
- for(std::vector<char>::const_iterator itr = cset.begin();
+ for(std::vector<unsigned char>::const_iterator itr = cset.begin();
itr != cset.end(); itr++) {
CVC4::String c( *itr );
Trace("regexp-int-debug") << "Try character " << c << " ... " << std::endl;
//TODO: var to be extended
ret = 0;
} else {
- std::set<char> cset;
+ std::set<unsigned char> cset;
SetNodes vset;
firstChars(r, cset, vset);
std::vector< Node > vec_nodes;
- for(char i=0; i<=d_lastchar; i++) {
+ for(unsigned char i=0; i<=d_lastchar; i++) {
CVC4::String c(i);
Node n = NodeManager::currentNM()->mkNode(kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst(c));
Node r2;
typedef std::pair< Node, Node > PairNodes;
private:
- const char d_lastchar;
+ const unsigned char d_lastchar;
Node d_emptyString;
Node d_true;
Node d_false;
Node d_one;
CVC4::Rational RMAXINT;
- char d_char_start;
- char d_char_end;
+ unsigned char d_char_start;
+ unsigned char d_char_end;
Node d_sigma;
Node d_sigma_star;
std::map< PairNodeStr, std::pair< Node, int > > d_deriv_cache;
std::map< Node, std::pair< Node, int > > d_compl_cache;
std::map< Node, bool > d_cstre_cache;
- std::map< Node, std::pair< std::set<char>, std::set<Node> > > d_cset_cache;
- std::map< Node, std::pair< std::set<char>, std::set<Node> > > d_fset_cache;
+ std::map< Node, std::pair< std::set<unsigned char>, std::set<Node> > > d_cset_cache;
+ std::map< Node, std::pair< std::set<unsigned char>, std::set<Node> > > d_fset_cache;
std::map< PairNodes, Node > d_inter_cache;
std::map< Node, Node > d_rm_inter_cache;
std::map< Node, bool > d_norv_cache;
void simplifyNRegExp( Node s, Node r, std::vector< Node > &new_nodes );
std::string niceChar( Node r );
int gcd ( int a, int b );
- Node mkAllExceptOne( char c );
+ Node mkAllExceptOne( unsigned char c );
bool isPairNodesInSet(std::set< PairNodes > &s, Node n1, Node n2);
- void getCharSet( Node r, std::set<char> &pcset, SetNodes &pvset );
+ void getCharSet( Node r, std::set<unsigned char> &pcset, SetNodes &pvset );
bool containC2(unsigned cnt, Node n);
Node convert1(unsigned cnt, Node n);
void convert2(unsigned cnt, Node n, Node &r1, Node &r2);
bool testNoRV(Node r);
Node intersectInternal( Node r1, Node r2, std::map< PairNodes, Node > cache, unsigned cnt );
Node removeIntersection(Node r);
- void firstChars( Node r, std::set<char> &pcset, SetNodes &pvset );
+ void firstChars( Node r, std::set<unsigned char> &pcset, SetNodes &pvset );
//TODO: for intersection
- bool follow( Node r, CVC4::String c, std::vector< char > &vec_chars );
+ bool follow( Node r, CVC4::String c, std::vector< unsigned char > &vec_chars );
/*class CState {
public:
}
case kind::REGEXP_RANGE: {
if(s.size() == index_start + 1) {
- char a = r[0].getConst<String>().getFirstChar();
- char b = r[1].getConst<String>().getFirstChar();
- char c = s.getLastChar();
+ unsigned char a = r[0].getConst<String>().getFirstChar();
+ unsigned char b = r[1].getConst<String>().getFirstChar();
+ unsigned char c = s.getLastChar();
return (a <= c && c <= b);
} else {
return false;
node[0]);
} else if(node.getKind() == kind::REGEXP_RANGE) {
std::vector< Node > vec_nodes;
- char c = node[0].getConst<String>().getFirstChar();
- char end = node[1].getConst<String>().getFirstChar();
+ unsigned char c = node[0].getConst<String>().getFirstChar();
+ unsigned char end = node[1].getConst<String>().getFirstChar();
for(; c<=end; ++c) {
Node n = NodeManager::currentNM()->mkNode( kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst( ::CVC4::String( c ) ) );
vec_nodes.push_back( n );
throw (TypeCheckingExceptionPrivate, AssertionException) {
if( check ) {
TNode::iterator it = n.begin();
- char ch[2];
+ unsigned char ch[2];
for(int i=0; i<2; ++i) {
TypeNode t = (*it).getType(check);
num = num * 8 + (int)s[i+1] - (int)'0';
if(flag && i+2 < s.size() && isdigit(s[i+2]) && s[i+2] < '8') {
num = num * 8 + (int)s[i+2] - (int)'0';
- d_str.push_back( convertCharToUnsignedInt((char)num) );
+ d_str.push_back( convertCharToUnsignedInt((unsigned char)num) );
i += 3;
} else {
- d_str.push_back( convertCharToUnsignedInt((char)num) );
+ d_str.push_back( convertCharToUnsignedInt((unsigned char)num) );
i += 2;
}
} else {
- d_str.push_back( convertCharToUnsignedInt((char)num) );
+ d_str.push_back( convertCharToUnsignedInt((unsigned char)num) );
i++;
}
} else if((unsigned)s[i] > 127) {
}
}
-void String::getCharSet(std::set<char> &cset) const {
+void String::getCharSet(std::set<unsigned char> &cset) const {
for(std::vector<unsigned int>::const_iterator itr = d_str.begin();
itr != d_str.end(); itr++) {
cset.insert( convertUnsignedIntToChar(*itr) );
std::string String::toString() const {
std::string str;
for(unsigned int i=0; i<d_str.size(); ++i) {
- char c = convertUnsignedIntToChar( d_str[i] );
+ unsigned char c = convertUnsignedIntToChar( d_str[i] );
if(isprint( c )) {
if(c == '\\') {
str += "\\\\";
class CVC4_PUBLIC String {
public:
- static unsigned int convertCharToUnsignedInt( char c ) {
- int i = (int)c;
- i = i-65;
- return (unsigned int)(i<0 ? i+256 : i);
+ static unsigned convertCharToUnsignedInt( unsigned char c ) {
+ unsigned i = c;
+ i = i + 191;
+ return (i>=256 ? i-256 : i);
}
- static char convertUnsignedIntToChar( unsigned int i ){
- int ii = i+65;
- return (char)(ii>=256 ? ii-256 : ii);
+ static unsigned char convertUnsignedIntToChar( unsigned i ){
+ unsigned ii = i+65;
+ return (unsigned char)(ii>=256 ? ii-256 : ii);
}
- static bool isPrintable( unsigned int i ){
- char c = convertUnsignedIntToChar( i );
- return isprint( (int)c );
+ static bool isPrintable( unsigned i ){
+ unsigned char c = convertUnsignedIntToChar( i );
+ return (c>=' ' && c<='~');//isprint( (int)c );
}
private:
- std::vector<unsigned int> d_str;
+ std::vector<unsigned> d_str;
- bool isVecSame(const std::vector<unsigned int> &a, const std::vector<unsigned int> &b) const {
+ bool isVecSame(const std::vector<unsigned> &a, const std::vector<unsigned> &b) const {
if(a.size() != b.size()) return false;
else {
- for(unsigned int i=0; i<a.size(); ++i)
- if(a[i] != b[i]) return false;
- return true;
+ return std::equal(a.begin(), a.end(), b.begin());
+ //for(unsigned int i=0; i<a.size(); ++i)
+ //if(a[i] != b[i]) return false;
+ //return true;
}
}
//guarded
- char hexToDec(char c) {
- if(isdigit(c)) {
+ unsigned char hexToDec(unsigned char c) {
+ if(c>='0' && c<='9') {
return c - '0';
} else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
toInternal(stmp);
}
- String(const char c) {
+ String(const unsigned char c) {
d_str.push_back( convertCharToUnsignedInt(c) );
}
- String(const std::vector<unsigned int> &s) : d_str(s) { }
+ String(const std::vector<unsigned> &s) : d_str(s) { }
~String() {}
*/
std::string toString() const;
- unsigned size() const {
+ std::size_t size() const {
return d_str.size();
}
- char getFirstChar() const {
+ unsigned char getFirstChar() const {
return convertUnsignedIntToChar( d_str[0] );
}
- char getLastChar() const {
+ unsigned char getLastChar() const {
assert(d_str.size() != 0);
return convertUnsignedIntToChar( d_str[d_str.size() - 1] );
}
if(y.d_str.size() == 0) return start;
if(d_str.size() == 0) return std::string::npos;
std::size_t ret = std::string::npos;
- for(std::size_t i = start; i <= d_str.size() - y.d_str.size(); i++) {
+ /*for(std::size_t i = start; i <= d_str.size() - y.d_str.size(); i++) {
if(d_str[i] == y.d_str[0]) {
std::size_t j=0;
for(; j<y.d_str.size(); j++) {
break;
}
}
+ }*/
+ std::vector<unsigned>::const_iterator itr = std::search(d_str.begin(), d_str.end(), y.d_str.begin(), y.d_str.end());
+ if(itr != d_str.end()) {
+ ret = itr - d_str.begin();
}
return ret;
}
bool isNumber() const {
if(d_str.size() == 0) return false;
for(unsigned int i=0; i<d_str.size(); ++i) {
- char c = convertUnsignedIntToChar( d_str[i] );
+ unsigned char c = convertUnsignedIntToChar( d_str[i] );
if(c<'0' || c>'9') {
return false;
}
if(isNumber()) {
int ret=0;
for(unsigned int i=0; i<d_str.size(); ++i) {
- char c = convertUnsignedIntToChar( d_str[i] );
+ unsigned char c = convertUnsignedIntToChar( d_str[i] );
ret = ret * 10 + (int)c - (int)'0';
}
return ret;
}
}
- void getCharSet(std::set<char> &cset) const;
+ void getCharSet(std::set<unsigned char> &cset) const;
- std::vector<unsigned int> getVec() const {
+ std::vector<unsigned> getVec() const {
return d_str;
}
};/* class String */