namespace theory {
namespace strings {
-RegExpOpr::RegExpOpr() {
+RegExpOpr::RegExpOpr()
+ : d_card( 256 ),
+ RMAXINT( LONG_MAX )
+{
d_emptyString = NodeManager::currentNM()->mkConst( ::CVC4::String("") );
d_true = NodeManager::currentNM()->mkConst( true );
d_false = NodeManager::currentNM()->mkConst( false );
+ d_emptySingleton = NodeManager::currentNM()->mkNode( kind::STRING_TO_REGEXP, d_emptyString );
d_zero = NodeManager::currentNM()->mkConst( ::CVC4::Rational(0) );
d_one = NodeManager::currentNM()->mkConst( ::CVC4::Rational(1) );
- d_emptySingleton = NodeManager::currentNM()->mkNode( kind::STRING_TO_REGEXP, d_emptyString );
std::vector< Node > nvec;
d_emptyRegexp = NodeManager::currentNM()->mkNode( kind::REGEXP_EMPTY, nvec );
d_sigma = NodeManager::currentNM()->mkNode( kind::REGEXP_SIGMA, nvec );
d_sigma_star = NodeManager::currentNM()->mkNode( kind::REGEXP_STAR, d_sigma );
- d_card = 256;
}
int RegExpOpr::gcd ( int a, int b ) {
bool RegExpOpr::containC2(unsigned cnt, Node n) {
if(n.getKind() == kind::REGEXP_RV) {
+ Assert(n[0].getConst<Rational>() <= RMAXINT, "Exceeded LONG_MAX in RegExpOpr::containC2");
unsigned y = n[0].getConst<Rational>().getNumerator().toUnsignedInt();
return cnt == y;
} else if(n.getKind() == kind::REGEXP_CONCAT) {
r1 = d_emptySingleton;
r2 = d_emptySingleton;
} else if(n.getKind() == kind::REGEXP_RV) {
+ Assert(n[0].getConst<Rational>() <= RMAXINT, "Exceeded LONG_MAX in RegExpOpr::containC2");
unsigned y = n[0].getConst<Rational>().getNumerator().toUnsignedInt();
r1 = d_emptySingleton;
if(cnt == y) {
#include <vector>
#include <set>
#include <algorithm>
+#include <climits>
#include "util/hash.h"
#include "util/regexp.h"
#include "theory/theory.h"
Node d_emptyRegexp;
Node d_zero;
Node d_one;
+ CVC4::Rational RMAXINT;
char d_char_start;
char d_char_end;
TheoryStrings::TheoryStrings(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo)
: Theory(THEORY_STRINGS, c, u, out, valuation, logicInfo),
+ RMAXINT(LONG_MAX),
d_notify( *this ),
d_equalityEngine(d_notify, c, "theory::strings::TheoryStrings"),
d_conflict(c, false),
Trace("strings-model") << " } (length is " << lts[i] << ")" << std::endl;
if( lts[i].isConst() ) {
lts_values.push_back( lts[i] );
+ Assert(lts[i].getConst<Rational>() <= RMAXINT, "Exceeded LONG_MAX in string model");
unsigned lvalue = lts[i].getConst<Rational>().getNumerator().toUnsignedInt();
values_used[ lvalue ] = true;
}else{
Node v = d_valuation.getModelValue(lts[i]);
Trace("strings-model") << "Model value for " << lts[i] << " is " << v << std::endl;
lts_values.push_back( v );
+ Assert(v.getConst<Rational>() <= RMAXINT, "Exceeded LONG_MAX in string model");
unsigned lvalue = v.getConst<Rational>().getNumerator().toUnsignedInt();
values_used[ lvalue ] = true;
}else{
//use type enumerator
+ Assert(lts_values[i].getConst<Rational>() <= RMAXINT, "Exceeded LONG_MAX in string model");
StringEnumeratorLength sel(lts_values[i].getConst<Rational>().getNumerator().toUnsignedInt());
for( unsigned j=0; j<pure_eq.size(); j++ ){
Assert( !sel.isFinished() );
#include "context/cdchunk_list.h"
#include "context/cdhashset.h"
+#include <climits>
+
namespace CVC4 {
namespace theory {
namespace strings {
Node d_false;
Node d_zero;
Node d_one;
+ CVC4::Rational RMAXINT;
// Options
bool d_opt_fmf;
bool d_opt_regexp_gcd;
}
}
if(ret != 2) {
- int len = t[ret].getConst<Rational>().getNumerator().toUnsignedInt();
+ unsigned len = t[ret].getConst<Rational>().getNumerator().toUnsignedInt();
if(len < 2) {
ret = 2;
}
retNode = NodeManager::currentNM()->mkConst( ::CVC4::String("") );
} else if( node[1].isConst() && node[2].isConst() ) {
if(node[1].getConst<Rational>().sgn()>=0 && node[2].getConst<Rational>().sgn()>=0) {
- int i = node[1].getConst<Rational>().getNumerator().toUnsignedInt();
- int j = node[2].getConst<Rational>().getNumerator().toUnsignedInt();
+ CVC4::Rational sum(node[1].getConst<Rational>() + node[2].getConst<Rational>());
if( node[0].isConst() ) {
- if( node[0].getConst<String>().size() >= (unsigned) (i + j) ) {
+ CVC4::Rational size(node[0].getConst<String>().size());
+ if( size >= sum ) {
+ //because size is smaller than MAX_INT
+ size_t i = node[1].getConst<Rational>().getNumerator().toUnsignedInt();
+ size_t j = node[2].getConst<Rational>().getNumerator().toUnsignedInt();
retNode = NodeManager::currentNM()->mkConst( node[0].getConst<String>().substr(i, j) );
} else {
retNode = NodeManager::currentNM()->mkConst( ::CVC4::String("") );
}
} else if(node[0].getKind() == kind::STRING_CONCAT && node[0][0].isConst()) {
- if( node[0][0].getConst<String>().size() >= (unsigned) (i + j) ) {
+ CVC4::Rational size2(node[0][0].getConst<String>().size());
+ if( size2 >= sum ) {
+ //because size2 is smaller than MAX_INT
+ size_t i = node[1].getConst<Rational>().getNumerator().toUnsignedInt();
+ size_t j = node[2].getConst<Rational>().getNumerator().toUnsignedInt();
retNode = NodeManager::currentNM()->mkConst( node[0][0].getConst<String>().substr(i, j) );
}
}
if( node[0].isConst() && node[1].isConst() && node[2].isConst() ) {
CVC4::String s = node[0].getConst<String>();
CVC4::String t = node[1].getConst<String>();
- int i = node[2].getConst<Rational>().getNumerator().toUnsignedInt();
+ CVC4::Rational RMAXINT(LONG_MAX);
+ Assert(node[2].getConst<Rational>() <= RMAXINT, "Number exceeds LONG_MAX in string index_of");
+ std::size_t i = node[2].getConst<Rational>().getNumerator().toUnsignedInt();
std::size_t ret = s.find(t, i);
if( ret != std::string::npos ) {
- retNode = NodeManager::currentNM()->mkConst( ::CVC4::Rational((int) ret) );
+ retNode = NodeManager::currentNM()->mkConst( ::CVC4::Rational((unsigned) ret) );
} else {
retNode = NodeManager::currentNM()->mkConst( ::CVC4::Rational(-1) );
}
if(r.getKind() == kind::REGEXP_STAR) {
retNode = r;
} else {
+ CVC4::Rational RMAXINT(LONG_MAX);
+ Assert(node[1].getConst<Rational>() <= RMAXINT, "Exceeded LONG_MAX in string REGEXP_LOOP (1)");
unsigned l = node[1].getConst<Rational>().getNumerator().toUnsignedInt();
std::vector< Node > vec_nodes;
for(unsigned i=0; i<l; i++) {
if(node.getNumChildren() == 3) {
Node n = vec_nodes.size()==0 ? NodeManager::currentNM()->mkNode(kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst(CVC4::String("")))
: vec_nodes.size()==1 ? r : prerewriteConcatRegExp(NodeManager::currentNM()->mkNode(kind::REGEXP_CONCAT, vec_nodes));
+ Assert(node[2].getConst<Rational>() <= RMAXINT, "Exceeded LONG_MAX in string REGEXP_LOOP (2)");
unsigned u = node[2].getConst<Rational>().getNumerator().toUnsignedInt();
if(u <= l) {
retNode = n;
#include "theory/rewriter.h"
#include "theory/type_enumerator.h"
#include "expr/attribute.h"
+#include <climits>
namespace CVC4 {
namespace theory {
#include <string>
#include <set>
#include <sstream>
-#include "util/exception.h"
+#include <cassert>
//#include "util/integer.h"
+#include "util/exception.h"
#include "util/hash.h"
namespace CVC4 {
} else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
} else {
- //Assert(c >= 'A' && c <= 'F');
+ assert(c >= 'A' && c <= 'F');
return c - 'A' + 10;
}
}
}
}
- bool strncmp(const String &y, unsigned int n) const {
- for(unsigned int i=0; i<n; ++i)
+ bool strncmp(const String &y, const std::size_t np) const {
+ std::size_t n = np;
+ std::size_t b = (d_str.size() >= y.d_str.size()) ? d_str.size() : y.d_str.size();
+ std::size_t s = (d_str.size() <= y.d_str.size()) ? d_str.size() : y.d_str.size();
+ if(n > s) {
+ if(b == s) {
+ n = s;
+ } else {
+ return false;
+ }
+ }
+ for(std::size_t i=0; i<n; ++i)
if(d_str[i] != y.d_str[i]) return false;
return true;
}
- bool rstrncmp(const String &y, unsigned int n) const {
- for(unsigned int i=0; i<n; ++i)
+ bool rstrncmp(const String &y, const std::size_t np) const {
+ std::size_t n = np;
+ std::size_t b = (d_str.size() >= y.d_str.size()) ? d_str.size() : y.d_str.size();
+ std::size_t s = (d_str.size() <= y.d_str.size()) ? d_str.size() : y.d_str.size();
+ if(n > s) {
+ if(b == s) {
+ n = s;
+ } else {
+ return false;
+ }
+ }
+ for(std::size_t i=0; i<n; ++i)
if(d_str[d_str.size() - i - 1] != y.d_str[y.d_str.size() - i - 1]) return false;
return true;
}
return ( d_str.size() == 0 );
}
- unsigned int operator[] (const unsigned int i) const {
- //Assert( i < d_str.size() && i >= 0);
+ unsigned int operator[] (const std::size_t i) const {
+ assert( i < d_str.size() );
return d_str[i];
}
/*
return true;
}
- std::size_t find(const String &y, const int start = 0) const {
- if(d_str.size() < y.d_str.size() + (std::size_t) start) return std::string::npos;
- if(y.d_str.size() == 0) return (std::size_t) start;
+ std::size_t find(const String &y, const std::size_t start = 0) const {
+ if(d_str.size() < y.d_str.size() + start) return std::string::npos;
+ 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(int i = start; i <= (int) d_str.size() - (int) 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++) {
if(d_str[i+j] != y.d_str[j]) break;
}
if(j == y.d_str.size()) {
- ret = (std::size_t) i;
+ ret = i;
break;
}
}
}
}
- String substr(unsigned i) const {
+ String substr(std::size_t i) const {
+ assert(i <= d_str.size());
std::vector<unsigned int> ret_vec;
std::vector<unsigned int>::const_iterator itr = d_str.begin() + i;
ret_vec.insert(ret_vec.end(), itr, d_str.end());
return String(ret_vec);
}
- String substr(unsigned i, unsigned j) const {
+ String substr(std::size_t i, std::size_t j) const {
+ assert(i+j <= d_str.size());
std::vector<unsigned int> ret_vec;
std::vector<unsigned int>::const_iterator itr = d_str.begin() + i;
ret_vec.insert( ret_vec.end(), itr, itr + j );
return String(ret_vec);
}
- String prefix(unsigned i) const {
+ String prefix(std::size_t i) const {
return substr(0, i);
}
- String suffix(unsigned i) const {
+ String suffix(std::size_t i) const {
return substr(d_str.size() - i, i);
}
std::size_t overlap(String &y) const;