3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-21 21:33:39 +00:00

Merge branch 'upstream-master' into release-1.0

Conflicts:
	src/cmd_context/check_logic.cpp
	src/cmd_context/cmd_context.cpp
	src/cmd_context/cmd_context.h
	src/smt/params/smt_params_helper.pyg
	src/smt/smt_context.cpp
This commit is contained in:
Murphy Berzish 2017-02-18 15:04:44 -05:00
commit 235ea79043
588 changed files with 21784 additions and 15202 deletions

View file

@ -1573,7 +1573,8 @@ private:
return false;
}
}
expr * p = m_manager.mk_pattern(ts.size(), (app*const*)(ts.c_ptr()));
expr_ref p(m_manager);
p = m_manager.mk_pattern(ts.size(), (app*const*)(ts.c_ptr()));
if (!p || (!ignore_user_patterns() && !m_pattern_validator(num_bindings, p, children[0]->line(), children[0]->pos()))) {
set_error("invalid pattern", children[0]);
return false;
@ -1581,8 +1582,11 @@ private:
patterns.push_back(p);
}
else if (children[0]->string() == symbol("ex_act") && ts.size() == 1) {
app * sk_hack = m_manager.mk_app(m_sk_hack, 1, ts.c_ptr());
expr * p = m_manager.mk_pattern(1, &sk_hack);
app_ref sk_hack(m_manager);
sk_hack = m_manager.mk_app(m_sk_hack, 1, ts.c_ptr());
app * sk_hackp = sk_hack.get();
expr_ref p(m_manager);
p = m_manager.mk_pattern(1, &sk_hackp);
if (!p || (!ignore_user_patterns() && !m_pattern_validator(num_bindings, p, children[0]->line(), children[0]->pos()))) {
set_error("invalid pattern", children[0]);
return false;

View file

@ -112,7 +112,6 @@ namespace smt2 {
typedef std::pair<symbol, expr*> named_expr;
named_expr m_last_named_expr;
ast_manager & m() const { return m_ctx.m(); }
pdecl_manager & pm() const { return m_ctx.pm(); }
sexpr_manager & sm() const { return m_ctx.sm(); }
@ -120,7 +119,7 @@ namespace smt2 {
bool m_ignore_user_patterns;
bool m_ignore_bad_patterns;
bool m_display_error_for_vs;
bool ignore_user_patterns() const { return m_ignore_user_patterns; }
bool ignore_bad_patterns() const { return m_ignore_bad_patterns; }
bool use_vs_format() const { return m_display_error_for_vs; }
@ -132,7 +131,7 @@ namespace smt2 {
m_decl(d), m_spos(spos) {
}
};
typedef psort_frame sort_frame;
enum expr_frame_kind { EF_APP, EF_LET, EF_LET_DECL, EF_QUANT, EF_ATTR_EXPR, EF_PATTERN };
@ -141,17 +140,17 @@ namespace smt2 {
expr_frame_kind m_kind;
expr_frame(expr_frame_kind k):m_kind(k) {}
};
struct app_frame : public expr_frame {
symbol m_f;
unsigned m_expr_spos;
unsigned m_param_spos;
bool m_as_sort;
app_frame(symbol const & f, unsigned expr_spos, unsigned param_spos, bool as_sort):
expr_frame(EF_APP),
m_f(f),
m_expr_spos(expr_spos),
m_param_spos(param_spos),
expr_frame(EF_APP),
m_f(f),
m_expr_spos(expr_spos),
m_param_spos(param_spos),
m_as_sort(as_sort) {}
};
@ -166,8 +165,8 @@ namespace smt2 {
unsigned m_sort_spos;
unsigned m_expr_spos;
quant_frame(bool forall, unsigned pat_spos, unsigned nopat_spos, unsigned sym_spos, unsigned sort_spos, unsigned expr_spos):
expr_frame(EF_QUANT), m_forall(forall), m_weight(1),
m_pat_spos(pat_spos), m_nopat_spos(nopat_spos),
expr_frame(EF_QUANT), m_forall(forall), m_weight(1),
m_pat_spos(pat_spos), m_nopat_spos(nopat_spos),
m_sym_spos(sym_spos), m_sort_spos(sort_spos),
m_expr_spos(expr_spos) {}
};
@ -178,7 +177,7 @@ namespace smt2 {
unsigned m_expr_spos;
let_frame(unsigned sym_spos, unsigned expr_spos):expr_frame(EF_LET), m_in_decls(true), m_sym_spos(sym_spos), m_expr_spos(expr_spos) {}
};
struct let_decl_frame : public expr_frame {
let_decl_frame():expr_frame(EF_LET_DECL) {}
};
@ -189,9 +188,9 @@ namespace smt2 {
unsigned m_expr_spos;
symbol m_last_symbol;
attr_expr_frame(expr_frame * prev, unsigned sym_spos, unsigned expr_spos):
expr_frame(EF_ATTR_EXPR),
m_prev(prev),
m_sym_spos(sym_spos),
expr_frame(EF_ATTR_EXPR),
m_prev(prev),
m_sym_spos(sym_spos),
m_expr_spos(expr_spos) {}
};
@ -231,12 +230,12 @@ namespace smt2 {
m_expr_stack = alloc(expr_ref_vector, m());
return *(m_expr_stack.get());
}
template<typename T>
static unsigned size(scoped_ptr<T> & v) {
return v.get() == 0 ? 0 : v->size();
}
template<typename T>
static void shrink(scoped_ptr<T> & v, unsigned old_sz) {
if (v.get() == 0) {
@ -258,7 +257,7 @@ namespace smt2 {
m_nopattern_stack = alloc(expr_ref_vector, m());
return *(m_nopattern_stack.get());
}
svector<symbol> & symbol_stack() {
return m_symbol_stack;
}
@ -337,7 +336,7 @@ namespace smt2 {
bool sync_after_error() {
while (true) {
try {
while (curr_is_rparen())
while (curr_is_rparen())
next();
if (m_num_open_paren < 0)
m_num_open_paren = 0;
@ -346,7 +345,7 @@ namespace smt2 {
SASSERT(m_num_open_paren >= 0);
while (m_num_open_paren > 0 || !curr_is_lparen()) {
TRACE("sync", tout << "sync(): curr: " << curr() << "\n";
tout << "m_num_open_paren: " << m_num_open_paren << ", line: " << m_scanner.get_line() << ", pos: "
tout << "m_num_open_paren: " << m_num_open_paren << ", line: " << m_scanner.get_line() << ", pos: "
<< m_scanner.get_pos() << "\n";);
if (curr() == scanner::EOF_TOKEN) {
return false;
@ -374,7 +373,7 @@ namespace smt2 {
}
throw parser_exception(msg);
}
symbol const & curr_id() const { return m_scanner.get_id(); }
rational curr_numeral() const { return m_scanner.get_number(); }
@ -411,15 +410,20 @@ namespace smt2 {
void check_int_or_float(char const * msg) { if (!curr_is_int() && !curr_is_float()) throw parser_exception(msg); }
void check_float(char const * msg) { if (!curr_is_float()) throw parser_exception(msg); }
char const * m_current_file;
void set_current_file(char const * s) { m_current_file = s; }
void error(unsigned line, unsigned pos, char const * msg) {
m_ctx.set_cancel(false);
if (use_vs_format()) {
m_ctx.diagnostic_stream() << "Z3(" << line << ", " << pos << "): ERROR: " << msg;
if (msg[strlen(msg)-1] != '\n')
m_ctx.diagnostic_stream() << std::endl;
m_ctx.diagnostic_stream() << std::endl;
}
else {
m_ctx.regular_stream() << "(error \"line " << line << " column " << pos << ": " << escaped(msg, true) << "\")" << std::endl;
m_ctx.regular_stream() << "(error \"";
if (m_current_file) m_ctx.regular_stream() << m_current_file << ": ";
m_ctx.regular_stream()<< "line " << line << " column " << pos << ": " << escaped(msg, true) << "\")" << std::endl;
}
if (m_ctx.exit_on_error()) {
exit(1);
@ -440,7 +444,7 @@ namespace smt2 {
m_ctx.regular_stream() << "(error : " << escaped(msg, true) << "\")" << std::endl;
}
}
void unknown_sort(symbol id, char const* context = "") {
std::string msg = context;
if (context[0]) msg += ": ";
@ -453,10 +457,10 @@ namespace smt2 {
unsigned num_parens = 0;
do {
switch (curr()) {
case scanner::LEFT_PAREN:
num_parens++;
case scanner::LEFT_PAREN:
num_parens++;
break;
case scanner::RIGHT_PAREN:
case scanner::RIGHT_PAREN:
if (num_parens == 0)
throw parser_exception("invalid s-expression, unexpected ')'");
num_parens--;
@ -574,7 +578,7 @@ namespace smt2 {
else {
if (ignore_unknow_sort)
return 0;
unknown_sort(id);
unknown_sort(id);
UNREACHABLE();
return 0;
}
@ -588,7 +592,7 @@ namespace smt2 {
check_identifier("invalid indexed sort, symbol expected");
symbol id = curr_id();
psort_decl * d = m_ctx.find_psort_decl(id);
if (d == 0)
if (d == 0)
unknown_sort(id);
next();
sbuffer<unsigned> args;
@ -613,13 +617,13 @@ namespace smt2 {
SASSERT(curr_is_identifier());
symbol id = curr_id();
psort_decl * d = m_ctx.find_psort_decl(id);
if (d == 0)
if (d == 0)
unknown_sort(id);
next();
void * mem = m_stack.allocate(sizeof(psort_frame));
new (mem) psort_frame(*this, d, psort_stack().size());
}
void pop_psort_app_frame() {
SASSERT(curr_is_rparen());
psort_frame * fr = static_cast<psort_frame*>(m_stack.top());
@ -656,7 +660,7 @@ namespace smt2 {
else {
check_lparen_next("invalid sort, symbol, '_' or '(' expected");
if (!curr_is_identifier())
throw parser_exception("invalid sort, symbol or '_' expected");
throw parser_exception("invalid sort, symbol or '_' expected");
if (curr_id_is_underscore()) {
psort_stack().push_back(pm().mk_psort_cnst(parse_indexed_sort()));
}
@ -674,13 +678,13 @@ namespace smt2 {
SASSERT(curr_is_identifier());
symbol id = curr_id();
psort_decl * d = m_ctx.find_psort_decl(id);
if (d == 0)
if (d == 0)
unknown_sort(id);
next();
void * mem = m_stack.allocate(sizeof(sort_frame));
new (mem) sort_frame(*this, d, sort_stack().size());
}
void pop_sort_app_frame() {
SASSERT(curr_is_rparen());
sort_frame * fr = static_cast<sort_frame*>(m_stack.top());
@ -719,8 +723,8 @@ namespace smt2 {
}
else {
check_lparen_next("invalid sort, symbol, '_' or '(' expected");
if (!curr_is_identifier())
throw parser_exception(std::string(context) + " invalid sort, symbol or '_' expected");
if (!curr_is_identifier())
throw parser_exception(std::string(context) + " invalid sort, symbol or '_' expected");
if (curr_id_is_underscore()) {
sort_stack().push_back(parse_indexed_sort());
}
@ -735,7 +739,7 @@ namespace smt2 {
}
unsigned parse_sorts(char const* context) {
unsigned sz = 0;
unsigned sz = 0;
check_lparen_next(context);
while (!curr_is_rparen()) {
parse_sort(context);
@ -958,7 +962,7 @@ namespace smt2 {
}
// parse expression state
enum pe_state {
enum pe_state {
PES_EXPR, // expecting <expr>
PES_DECL, // expecting (<id> <expr>)
PES_PATTERN,
@ -1024,7 +1028,7 @@ namespace smt2 {
else {
// just consume pattern
next();
consume_sexpr();
consume_sexpr();
}
}
else if (id == m_nopattern) {
@ -1043,9 +1047,9 @@ namespace smt2 {
else {
std::ostringstream str;
str << "unknown attribute " << id;
warning_msg(str.str().c_str());
warning_msg("%s", str.str().c_str());
next();
// just consume the
// just consume the
consume_sexpr();
}
if (curr_is_rparen())
@ -1060,13 +1064,13 @@ namespace smt2 {
switch (fr->m_kind) {
case EF_LET:
return static_cast<let_frame*>(fr)->m_in_decls ? PES_DECL : PES_EXPR;
case EF_ATTR_EXPR:
case EF_ATTR_EXPR:
return consume_attributes(static_cast<attr_expr_frame*>(fr));
default:
return PES_EXPR;
}
}
void parse_numeral(bool is_int) {
SASSERT(!is_int || curr_is_int());
SASSERT(is_int || curr_is_float());
@ -1123,7 +1127,7 @@ namespace smt2 {
expr_stack().push_back(0); // empty pattern
return;
}
if (curr_is_lparen()) {
// multi-pattern
void * mem = m_stack.allocate(sizeof(pattern_frame));
@ -1213,9 +1217,9 @@ namespace smt2 {
SASSERT(curr_id_is_forall() || curr_id_is_exists());
SASSERT(!is_forall || curr_id_is_forall());
SASSERT(is_forall || curr_id_is_exists());
next();
next();
void * mem = m_stack.allocate(sizeof(quant_frame));
new (mem) quant_frame(is_forall, pattern_stack().size(), nopattern_stack().size(), symbol_stack().size(),
new (mem) quant_frame(is_forall, pattern_stack().size(), nopattern_stack().size(), symbol_stack().size(),
sort_stack().size(), expr_stack().size());
m_num_expr_frames++;
unsigned num_vars = parse_sorted_vars();
@ -1257,11 +1261,11 @@ namespace smt2 {
next();
return r;
}
check_lparen_next("invalid (indexed) identifier, '(_' or symbol expected");
check_lparen_next("invalid (indexed) identifier, '(_' or symbol expected");
return parse_indexed_identifier_core();
}
// parse:
// parse:
// 'as' <identifier> <sort> ')'
// '_' <identifier> <num>+ ')'
// 'as' <identifier '(' '_' <identifier> (<num>|<func-decl-ref>)+ ')' <sort> ')'
@ -1283,7 +1287,7 @@ namespace smt2 {
}
}
// parse:
// parse:
// <identifier>
// '(' 'as' <identifier> <sort> ')'
// '(' '_' <identifier> <num>+ ')'
@ -1309,8 +1313,8 @@ namespace smt2 {
throw parser_exception(msg.c_str());
}
rational m_last_bv_numeral; // for bv, bvbin, bvhex
rational m_last_bv_numeral; // for bv, bvbin, bvhex
// return true if *s == [0-9]+
bool is_bv_decimal(char const * s) {
TRACE("is_bv_num", tout << "is_bv_decimal: " << s << "\n";);
@ -1349,7 +1353,7 @@ namespace smt2 {
return false;
return true;
}
// return true if *s == hex[0-9,a-f,A-F]+
bool is_bv_hex(char const * s) {
SASSERT(*s == 'h');
@ -1357,7 +1361,7 @@ namespace smt2 {
if (*s != 'e') return false;
++s;
if (*s != 'x') return false;
++s;
++s;
rational & n = m_last_bv_numeral;
unsigned i = 0;
n = rational(0);
@ -1368,7 +1372,7 @@ namespace smt2 {
}
else if ('a' <= *s && *s <= 'f') {
n *= rational(16);
n += rational(10 + (*s - 'a'));
n += rational(10 + (*s - 'a'));
}
else if ('A' <= *s && *s <= 'F') {
n *= rational(16);
@ -1385,11 +1389,11 @@ namespace smt2 {
}
}
// Return true if
// Return true if
// n == bv[0-9]+ OR
// n == bvhex[0-9,a-f,A-F]+ OR
// n == bvbin[0-1]+
// It store the bit-vector value in m_last_bv_numeral
// n == bvbin[0-1]+
// It store the bit-vector value in m_last_bv_numeral
bool is_bv_num(symbol const & n) {
char const * s = n.bare_str();
if (*s != 'b') return false;
@ -1433,7 +1437,7 @@ namespace smt2 {
}
next();
}
// if has_as == true, then the sort of t must be equal to sort_stack().pop_back()
// if that is the case, pop the top of sort_stack()
void check_qualifier(expr * t, bool has_as) {
@ -1571,7 +1575,7 @@ namespace smt2 {
unsigned num_args = expr_stack().size() - fr->m_expr_spos;
unsigned num_indices = m_param_stack.size() - fr->m_param_spos;
expr_ref t_ref(m());
m_ctx.mk_app(fr->m_f,
m_ctx.mk_app(fr->m_f,
num_args,
expr_stack().c_ptr() + fr->m_expr_spos,
num_indices,
@ -1655,7 +1659,7 @@ namespace smt2 {
fr->m_qid = symbol(m_scanner.get_line());
if (!m().is_bool(expr_stack().back()))
throw parser_exception("quantifier body must be a Boolean expression");
quantifier * new_q = m().mk_quantifier(fr->m_forall,
quantifier * new_q = m().mk_quantifier(fr->m_forall,
num_decls,
sort_stack().c_ptr() + fr->m_sort_spos,
symbol_stack().c_ptr() + fr->m_sym_spos,
@ -1716,7 +1720,7 @@ namespace smt2 {
case EF_APP:
pop_app_frame(static_cast<app_frame*>(fr));
break;
case EF_LET:
case EF_LET:
pop_let_frame(static_cast<let_frame*>(fr));
break;
case EF_LET_DECL:
@ -1742,7 +1746,7 @@ namespace smt2 {
void parse_expr() {
m_num_expr_frames = 0;
do {
TRACE("parse_expr", tout << "curr(): " << curr() << ", m_num_expr_frames: " << m_num_expr_frames
TRACE("parse_expr", tout << "curr(): " << curr() << ", m_num_expr_frames: " << m_num_expr_frames
<< ", expr_stack().size(): " << expr_stack().size() << "\n";);
if (curr_is_rparen()) {
if (m_num_expr_frames == 0)
@ -1826,7 +1830,7 @@ namespace smt2 {
SASSERT(curr_is_identifier());
SASSERT(curr_id() == m_declare_sort);
next();
check_identifier("invalid sort declaration, symbol expected");
symbol id = curr_id();
if (m_ctx.find_psort_decl(id) != 0)
@ -1840,7 +1844,7 @@ namespace smt2 {
check_int("invalid sort declaration, arity (<numeral>) or ')' expected");
rational n = curr_numeral();
if (!n.is_unsigned())
throw parser_exception("invalid sort declaration, arity is too big to fit in an unsigned machine integer");
throw parser_exception("invalid sort declaration, arity is too big to fit in an unsigned machine integer");
psort_decl * decl = pm().mk_psort_user_decl(n.get_unsigned(), id, 0);
m_ctx.insert(decl);
next();
@ -1900,12 +1904,12 @@ namespace smt2 {
}
void parse_define_fun_rec() {
// ( define-fun-rec hfun_defi )
// ( define-fun-rec hfun_defi )
SASSERT(curr_is_identifier());
SASSERT(curr_id() == m_define_fun_rec);
SASSERT(m_num_bindings == 0);
next();
expr_ref_vector binding(m());
svector<symbol> ids;
func_decl_ref f(m());
@ -1918,7 +1922,7 @@ namespace smt2 {
}
void parse_define_funs_rec() {
// ( define-funs-rec ( hfun_decin+1 ) ( htermin+1 ) )
// ( define-funs-rec ( hfun_decin+1 ) ( htermin+1 ) )
SASSERT(curr_is_identifier());
SASSERT(curr_id() == m_define_funs_rec);
SASSERT(m_num_bindings == 0);
@ -1948,14 +1952,14 @@ namespace smt2 {
check_lparen("invalid recursive function definition, '(' expected");
next();
parse_rec_fun_decl(f, binding, id);
decls.push_back(f);
bindings.push_back(binding);
ids.push_back(id);
check_rparen("invalid recursive function definition, ')' expected");
next();
next();
}
next();
}
@ -1978,7 +1982,7 @@ namespace smt2 {
sort_stack().shrink(sort_spos);
expr_stack().shrink(expr_spos);
m_env.end_scope();
m_num_bindings = 0;
m_num_bindings = 0;
}
void parse_rec_fun_bodies(func_decl_ref_vector const& decls, vector<expr_ref_vector> const& bindings, vector<svector<symbol> >const & ids) {
@ -1991,10 +1995,10 @@ namespace smt2 {
}
if (i != decls.size()) {
throw parser_exception("the number of declarations does not match number of supplied definitions");
throw parser_exception("the number of declarations does not match number of supplied definitions");
}
check_rparen("invalid recursive function definition, ')' expected");
next();
next();
}
void parse_rec_fun_body(func_decl* f, expr_ref_vector const& bindings, svector<symbol> const& ids) {
@ -2008,19 +2012,19 @@ namespace smt2 {
for (unsigned i = 0; i < num_vars; ++i) {
m_env.insert(ids[i], local(bindings[i], num_vars));
}
parse_expr();
parse_expr();
body = expr_stack().back();
expr_stack().pop_back();
symbol_stack().shrink(sym_spos);
m_env.end_scope();
m_num_bindings = 0;
m_num_bindings = 0;
if (m().get_sort(body) != f->get_range()) {
std::ostringstream buffer;
buffer << "invalid function definition, sort mismatch. Expcected "
<< mk_pp(f->get_range(), m()) << " but function body has sort "
<< mk_pp(f->get_range(), m()) << " but function body has sort "
<< mk_pp(m().get_sort(body), m());
throw parser_exception(buffer.str().c_str());
}
}
m_ctx.insert_rec_fun(f, bindings, ids, body);
}
@ -2211,9 +2215,9 @@ namespace smt2 {
SASSERT(curr_id() == m_check_sat_assuming);
next();
unsigned spos = expr_stack().size();
check_rparen_next("invalid check-sat-assuming command, '(', expected");
check_lparen_next("invalid check-sat-assuming command, '(', expected");
parse_assumptions();
check_rparen_next("invalid check-sat-assuming command, ')', expected");
check_rparen_next("invalid check-sat-assuming command, ')', expected");
m_ctx.check_sat(expr_stack().size() - spos, expr_stack().c_ptr() + spos);
next();
expr_stack().shrink(spos);
@ -2229,7 +2233,7 @@ namespace smt2 {
m_scanner.start_caching();
m_cache_end = 0;
m_cached_strings.resize(0);
check_lparen_next("invalid get-value command, '(' expected");
while (!curr_is_rparen()) {
parse_expr();
@ -2269,7 +2273,7 @@ namespace smt2 {
SASSERT(curr_id() == m_reset);
next();
check_rparen("invalid reset command, ')' expected");
m_ctx.reset();
m_ctx.reset();
reset();
m_ctx.print_success();
next();
@ -2351,7 +2355,7 @@ namespace smt2 {
}
next();
}
void parse_next_cmd_arg() {
SASSERT(m_curr_cmd != 0);
cmd_arg_kind k = m_curr_cmd->next_arg_kind(m_ctx);
@ -2360,7 +2364,7 @@ namespace smt2 {
check_int("invalid command argument, unsigned integer expected");
rational n = curr_numeral();
if (!n.is_unsigned())
throw parser_exception("invalid command argument, numeral is too big to fit in an unsigned machine integer");
throw parser_exception("invalid command argument, numeral is too big to fit in an unsigned machine integer");
m_curr_cmd->set_next_arg(m_ctx, n.get_unsigned());
next();
break;
@ -2473,7 +2477,7 @@ namespace smt2 {
m_curr_cmd = m_ctx.find_cmd(s);
if (m_curr_cmd == 0) {
parse_unknown_cmd();
return;
return;
}
next();
unsigned arity = m_curr_cmd->get_arity();
@ -2503,14 +2507,14 @@ namespace smt2 {
return;
}
else {
if (arity != VAR_ARITY && i == arity)
if (arity != VAR_ARITY && i == arity)
throw parser_exception("invalid command, too many arguments");
parse_next_cmd_arg();
}
i++;
}
}
void parse_cmd() {
SASSERT(curr_is_lparen());
int line = m_scanner.get_line();
@ -2559,7 +2563,7 @@ namespace smt2 {
return;
}
if (s == m_declare_datatypes) {
parse_declare_datatypes();
parse_declare_datatypes();
return;
}
if (s == m_get_value) {
@ -2586,8 +2590,8 @@ namespace smt2 {
}
public:
parser(cmd_context & ctx, std::istream & is, bool interactive, params_ref const & p):
m_ctx(ctx),
parser(cmd_context & ctx, std::istream & is, bool interactive, params_ref const & p, char const * filename=0):
m_ctx(ctx),
m_params(p),
m_scanner(ctx, is, interactive),
m_curr(scanner::NULL_TOKEN),
@ -2625,14 +2629,15 @@ namespace smt2 {
m_check_sat_assuming("check-sat-assuming"),
m_define_fun_rec("define-fun-rec"),
m_define_funs_rec("define-funs-rec"),
m_underscore("_"),
m_num_open_paren(0) {
m_underscore("_"),
m_num_open_paren(0),
m_current_file(filename) {
// the following assertion does not hold if ctx was already attached to an AST manager before the parser object is created.
// SASSERT(!m_ctx.has_manager());
updt_params();
}
~parser() {
reset_stack();
}
@ -2643,7 +2648,7 @@ namespace smt2 {
m_ignore_bad_patterns = p.ignore_bad_patterns();
m_display_error_for_vs = p.error_for_visual_studio();
}
void reset() {
reset_stack();
m_num_bindings = 0;
@ -2658,7 +2663,7 @@ namespace smt2 {
m_env .reset();
m_sort_id2param_idx .reset();
m_dt_name2idx .reset();
m_bv_util = 0;
m_arith_util = 0;
m_seq_util = 0;
@ -2708,9 +2713,9 @@ namespace smt2 {
return !found_errors;
}
catch (parser_exception & ex) {
if (ex.has_pos())
if (ex.has_pos())
error(ex.line(), ex.pos(), ex.msg());
else
else
error(ex.msg());
}
catch (ast_exception & ex) {
@ -2733,8 +2738,8 @@ namespace smt2 {
};
};
bool parse_smt2_commands(cmd_context & ctx, std::istream & is, bool interactive, params_ref const & ps) {
smt2::parser p(ctx, is, interactive, ps);
bool parse_smt2_commands(cmd_context & ctx, std::istream & is, bool interactive, params_ref const & ps, char const * filename) {
smt2::parser p(ctx, is, interactive, ps, filename);
return p();
}

View file

@ -21,6 +21,6 @@ Revision History:
#include"cmd_context.h"
bool parse_smt2_commands(cmd_context & ctx, std::istream & is, bool interactive = false, params_ref const & p = params_ref());
bool parse_smt2_commands(cmd_context & ctx, std::istream & is, bool interactive = false, params_ref const & p = params_ref(), char const * filename = 0);
#endif

View file

@ -23,10 +23,12 @@ namespace smt2 {
void scanner::next() {
if (m_cache_input)
m_cache.push_back(m_curr);
SASSERT(m_curr != EOF);
m_cache.push_back(m_curr);
SASSERT(!m_at_eof);
if (m_interactive) {
m_curr = m_stream.get();
if (m_stream.eof())
m_at_eof = true;
}
else if (m_bpos < m_bend) {
m_curr = m_buffer[m_bpos];
@ -37,7 +39,7 @@ namespace smt2 {
m_bend = static_cast<unsigned>(m_stream.gcount());
m_bpos = 0;
if (m_bpos == m_bend) {
m_curr = EOF;
m_at_eof = true;
}
else {
m_curr = m_buffer[m_bpos];
@ -52,7 +54,7 @@ namespace smt2 {
next();
while (true) {
char c = curr();
if (c == EOF)
if (m_at_eof)
return;
if (c == '\n') {
new_line();
@ -70,7 +72,7 @@ namespace smt2 {
next();
while (true) {
char c = curr();
if (c == EOF) {
if (m_at_eof) {
throw scanner_exception("unexpected end of quoted symbol", m_line, m_spos);
}
else if (c == '\n') {
@ -90,7 +92,7 @@ namespace smt2 {
}
scanner::token scanner::read_symbol_core() {
while (true) {
while (!m_at_eof) {
char c = curr();
signed char n = m_normalized[static_cast<unsigned char>(c)];
if (n == 'a' || n == '0' || n == '-') {
@ -104,6 +106,7 @@ namespace smt2 {
return SYMBOL_TOKEN;
}
}
return EOF_TOKEN;
}
scanner::token scanner::read_symbol() {
@ -167,7 +170,7 @@ namespace smt2 {
m_string.reset();
while (true) {
char c = curr();
if (c == EOF)
if (m_at_eof)
throw scanner_exception("unexpected end of string", m_line, m_spos);
if (c == '\n') {
new_line();
@ -237,10 +240,11 @@ namespace smt2 {
}
}
scanner::scanner(cmd_context & ctx, std::istream& stream, bool interactive):
scanner::scanner(cmd_context & ctx, std::istream& stream, bool interactive) :
m_interactive(interactive),
m_spos(0),
m_curr(0), // avoid Valgrind warning
m_at_eof(false),
m_line(1),
m_pos(0),
m_bv_size(UINT_MAX),
@ -289,9 +293,13 @@ namespace smt2 {
}
scanner::token scanner::scan() {
while (true) {
while (true) {
signed char c = curr();
m_pos = m_spos;
if (m_at_eof)
return EOF_TOKEN;
switch (m_normalized[(unsigned char) c]) {
case ' ':
next();
@ -327,8 +335,6 @@ namespace smt2 {
return read_symbol();
else
return read_signed_number();
case -1:
return EOF_TOKEN;
default: {
scanner_exception ex("unexpected character", m_line, m_spos);
next();

View file

@ -34,6 +34,7 @@ namespace smt2 {
bool m_interactive;
int m_spos; // position in the current line of the stream
char m_curr; // current char;
bool m_at_eof;
int m_line; // line
int m_pos; // start position of the token