return t;
}
-Expr ExprManager::mkVar(const std::string& name, Type type, bool isGlobal) {
+Expr ExprManager::mkVar(const std::string& name, Type type, uint32_t flags) {
Assert(NodeManager::currentNM() == NULL, "ExprManager::mkVar() should only be called externally, not from within CVC4 code. Please use mkSkolem().");
NodeManagerScope nms(d_nodeManager);
- Node* n = d_nodeManager->mkVarPtr(name, *type.d_typeNode, isGlobal);
+ Node* n = d_nodeManager->mkVarPtr(name, *type.d_typeNode, flags);
Debug("nm") << "set " << name << " on " << *n << std::endl;
INC_STAT_VAR(type, false);
return Expr(this, n);
}
-Expr ExprManager::mkVar(Type type, bool isGlobal) {
+Expr ExprManager::mkVar(Type type, uint32_t flags) {
Assert(NodeManager::currentNM() == NULL, "ExprManager::mkVar() should only be called externally, not from within CVC4 code. Please use mkSkolem().");
NodeManagerScope nms(d_nodeManager);
INC_STAT_VAR(type, false);
- return Expr(this, d_nodeManager->mkVarPtr(*type.d_typeNode, isGlobal));
+ return Expr(this, d_nodeManager->mkVarPtr(*type.d_typeNode, flags));
}
Expr ExprManager::mkBoundVar(const std::string& name, Type type) {
Type getType(Expr e, bool check = false)
throw(TypeCheckingException);
+ /** Bits for use in mkVar() flags. */
+ enum {
+ VAR_FLAG_NONE = 0,
+ VAR_FLAG_GLOBAL = 1,
+ VAR_FLAG_DEFINED = 2
+ };/* enum */
+
/**
* Create a new, fresh variable. This variable is guaranteed to be
* distinct from every variable thus far in the ExprManager, even
*
* @param name a name to associate to the fresh new variable
* @param type the type for the new variable
- * @param isGlobal whether this variable is to be considered "global"
- * or not. Note that this information isn't used by the ExprManager,
- * but is passed on to the ExprManager's event subscribers like the
- * model-building service; if isGlobal is true, this newly-created
- * variable will still available in models generated after an
- * intervening pop.
+ * @param flags - VAR_FLAG_NONE - no flags;
+ * VAR_FLAG_GLOBAL - whether this variable is to be
+ * considered "global" or not. Note that this information isn't
+ * used by the ExprManager, but is passed on to the ExprManager's
+ * event subscribers like the model-building service; if isGlobal
+ * is true, this newly-created variable will still available in
+ * models generated after an intervening pop.
+ * VAR_FLAG_DEFINED - if this is to be a "defined" symbol, e.g., for
+ * use with SmtEngine::defineFunction(). This keeps a declaration
+ * from being emitted in API dumps (since a subsequent definition is
+ * expected to be dumped instead).
*/
- Expr mkVar(const std::string& name, Type type, bool isGlobal = false);
+ Expr mkVar(const std::string& name, Type type, uint32_t flags = VAR_FLAG_NONE);
/**
* Create a (nameless) new, fresh variable. This variable is guaranteed
* to be distinct from every variable thus far in the ExprManager.
*
* @param type the type for the new variable
- * @param isGlobal whether this variable is to be considered "global"
+ * @param flags - VAR_FLAG_GLOBAL - whether this variable is to be considered "global"
* or not. Note that this information isn't used by the ExprManager,
* but is passed on to the ExprManager's event subscribers like the
* model-building service; if isGlobal is true, this newly-created
* variable will still available in models generated after an
* intervening pop.
*/
- Expr mkVar(Type type, bool isGlobal = false);
+ Expr mkVar(Type type, uint32_t flags = VAR_FLAG_NONE);
/**
* Create a new, fresh variable for use in a binder expression
bool isGlobal;
Node::fromExpr(from_e).getAttribute(GlobalVarAttr(), isGlobal);
NodeManagerScope nullScope(NULL);
- to_e = to->mkVar(name, type, isGlobal);// FIXME thread safety
+ to_e = to->mkVar(name, type, isGlobal ? ExprManager::VAR_FLAG_GLOBAL : ExprManager::VAR_FLAG_NONE);// FIXME thread safety
} else if(n.getKind() == kind::SKOLEM) {
// skolems are only available at the Node level (not the Expr level)
TypeNode typeNode = TypeNode::fromType(type);
virtual void nmNotifyNewSortConstructor(TypeNode tn) { }
virtual void nmNotifyInstantiateSortConstructor(TypeNode ctor, TypeNode sort) { }
virtual void nmNotifyNewDatatypes(const std::vector<DatatypeType>& datatypes) { }
- virtual void nmNotifyNewVar(TNode n, bool isGlobal) { }
- virtual void nmNotifyNewSkolem(TNode n, const std::string& comment, bool isGlobal) { }
+ virtual void nmNotifyNewVar(TNode n, uint32_t flags) { }
+ virtual void nmNotifyNewSkolem(TNode n, const std::string& comment, uint32_t flags) { }
};/* class NodeManagerListener */
class NodeManager {
friend class expr::TypeChecker;
// friends so they can access mkVar() here, which is private
- friend Expr ExprManager::mkVar(const std::string&, Type, bool isGlobal);
- friend Expr ExprManager::mkVar(Type, bool isGlobal);
+ friend Expr ExprManager::mkVar(const std::string&, Type, uint32_t flags);
+ friend Expr ExprManager::mkVar(Type, uint32_t flags);
// friend so it can access NodeManager's d_listeners and notify clients
friend std::vector<DatatypeType> ExprManager::mkMutualDatatypeTypes(const std::vector<Datatype>&, const std::set<Type>&);
* version of this is private to avoid internal uses of mkVar() from
* within CVC4. Such uses should employ mkSkolem() instead.
*/
- Node mkVar(const std::string& name, const TypeNode& type, bool isGlobal = false);
- Node* mkVarPtr(const std::string& name, const TypeNode& type, bool isGlobal = false);
+ Node mkVar(const std::string& name, const TypeNode& type, uint32_t flags = ExprManager::VAR_FLAG_NONE);
+ Node* mkVarPtr(const std::string& name, const TypeNode& type, uint32_t flags = ExprManager::VAR_FLAG_NONE);
/** Create a variable with the given type. */
- Node mkVar(const TypeNode& type, bool isGlobal = false);
- Node* mkVarPtr(const TypeNode& type, bool isGlobal = false);
+ Node mkVar(const TypeNode& type, uint32_t flags = ExprManager::VAR_FLAG_NONE);
+ Node* mkVarPtr(const TypeNode& type, uint32_t flags = ExprManager::VAR_FLAG_NONE);
public:
}
-inline Node NodeManager::mkVar(const std::string& name, const TypeNode& type, bool isGlobal) {
+inline Node NodeManager::mkVar(const std::string& name, const TypeNode& type, uint32_t flags) {
Node n = NodeBuilder<0>(this, kind::VARIABLE);
setAttribute(n, TypeAttr(), type);
setAttribute(n, TypeCheckedAttr(), true);
setAttribute(n, expr::VarNameAttr(), name);
- setAttribute(n, expr::GlobalVarAttr(), isGlobal);
+ setAttribute(n, expr::GlobalVarAttr(), flags & ExprManager::VAR_FLAG_GLOBAL);
for(std::vector<NodeManagerListener*>::iterator i = d_listeners.begin(); i != d_listeners.end(); ++i) {
- (*i)->nmNotifyNewVar(n, isGlobal);
+ (*i)->nmNotifyNewVar(n, flags);
}
return n;
}
inline Node* NodeManager::mkVarPtr(const std::string& name,
- const TypeNode& type, bool isGlobal) {
+ const TypeNode& type, uint32_t flags) {
Node* n = NodeBuilder<0>(this, kind::VARIABLE).constructNodePtr();
setAttribute(*n, TypeAttr(), type);
setAttribute(*n, TypeCheckedAttr(), true);
setAttribute(*n, expr::VarNameAttr(), name);
- setAttribute(*n, expr::GlobalVarAttr(), isGlobal);
+ setAttribute(*n, expr::GlobalVarAttr(), flags & ExprManager::VAR_FLAG_GLOBAL);
for(std::vector<NodeManagerListener*>::iterator i = d_listeners.begin(); i != d_listeners.end(); ++i) {
- (*i)->nmNotifyNewVar(*n, isGlobal);
+ (*i)->nmNotifyNewVar(*n, flags);
}
return n;
}
return n;
}
-inline Node NodeManager::mkVar(const TypeNode& type, bool isGlobal) {
+inline Node NodeManager::mkVar(const TypeNode& type, uint32_t flags) {
Node n = NodeBuilder<0>(this, kind::VARIABLE);
setAttribute(n, TypeAttr(), type);
setAttribute(n, TypeCheckedAttr(), true);
- setAttribute(n, expr::GlobalVarAttr(), isGlobal);
+ setAttribute(n, expr::GlobalVarAttr(), flags & ExprManager::VAR_FLAG_GLOBAL);
for(std::vector<NodeManagerListener*>::iterator i = d_listeners.begin(); i != d_listeners.end(); ++i) {
- (*i)->nmNotifyNewVar(n, isGlobal);
+ (*i)->nmNotifyNewVar(n, flags);
}
return n;
}
-inline Node* NodeManager::mkVarPtr(const TypeNode& type, bool isGlobal) {
+inline Node* NodeManager::mkVarPtr(const TypeNode& type, uint32_t flags) {
Node* n = NodeBuilder<0>(this, kind::VARIABLE).constructNodePtr();
setAttribute(*n, TypeAttr(), type);
setAttribute(*n, TypeCheckedAttr(), true);
- setAttribute(*n, expr::GlobalVarAttr(), isGlobal);
+ setAttribute(*n, expr::GlobalVarAttr(), flags & ExprManager::VAR_FLAG_GLOBAL);
for(std::vector<NodeManagerListener*>::iterator i = d_listeners.begin(); i != d_listeners.end(); ++i) {
- (*i)->nmNotifyNewVar(*n, isGlobal);
+ (*i)->nmNotifyNewVar(*n, flags);
}
return n;
}
} else {
Debug("parser") << " " << *i << " not declared" << std::endl;
if(topLevel) {
- Expr func = PARSER_STATE->mkVar(*i, t, true);
+ Expr func = PARSER_STATE->mkVar(*i, t, ExprManager::VAR_FLAG_GLOBAL);
Command* decl = new DeclareFunctionCommand(*i, func, t);
seq->addCommand(decl);
} else {
// like e.g. FORALL(x:INT = 4): [...]
PARSER_STATE->parseError("cannot construct a definition here; maybe you want a LET");
}
- Debug("parser") << "made " << idList.front() << " = " << f << std::endl;
+ assert(!idList.empty());
for(std::vector<std::string>::const_iterator i = idList.begin(),
i_end = idList.end();
i != i_end;
++i) {
+ Debug("parser") << "making " << *i << " : " << t << " = " << f << std::endl;
PARSER_STATE->checkDeclaration(*i, CHECK_UNDECLARED, SYM_VARIABLE);
- Expr func = EXPR_MANAGER->mkVar(*i, t, true);
+ Expr func = EXPR_MANAGER->mkVar(*i, t, ExprManager::VAR_FLAG_GLOBAL | ExprManager::VAR_FLAG_DEFINED);
PARSER_STATE->defineFunction(*i, f);
Command* decl = new DefineFunctionCommand(*i, func, f);
seq->addCommand(decl);
{ PARSER_STATE->popScope();
Type t = EXPR_MANAGER->mkFunctionType(types, f.getType());
std::string name = "lambda";
- Expr func = PARSER_STATE->mkAnonymousFunction(name, t);
+ Expr func = PARSER_STATE->mkAnonymousFunction(name, t, ExprManager::VAR_FLAG_DEFINED);
Command* cmd = new DefineFunctionCommand(name, func, terms, f);
PARSER_STATE->preemptCommand(cmd);
f = func;
boundVarDecl[ids,t] RPAREN COLON formula[f]
{ PARSER_STATE->popScope();
UNSUPPORTED("array literals not supported yet");
- f = EXPR_MANAGER->mkVar(EXPR_MANAGER->mkArrayType(t, f.getType()), true);
+ f = EXPR_MANAGER->mkVar(EXPR_MANAGER->mkArrayType(t, f.getType()), ExprManager::VAR_FLAG_GLOBAL);
}
;
}
Expr
-Parser::mkVar(const std::string& name, const Type& type,
- bool levelZero) {
- Debug("parser") << "mkVar(" << name << ", " << type << ", " << levelZero << ")" << std::endl;
- Expr expr = d_exprManager->mkVar(name, type, levelZero);
- defineVar(name, expr, levelZero);
+Parser::mkVar(const std::string& name, const Type& type, uint32_t flags) {
+ Debug("parser") << "mkVar(" << name << ", " << type << ")" << std::endl;
+ Expr expr = d_exprManager->mkVar(name, type, flags);
+ defineVar(name, expr, flags & ExprManager::VAR_FLAG_GLOBAL);
return expr;
}
}
Expr
-Parser::mkFunction(const std::string& name, const Type& type,
- bool levelZero) {
+Parser::mkFunction(const std::string& name, const Type& type, uint32_t flags) {
Debug("parser") << "mkVar(" << name << ", " << type << ")" << std::endl;
- Expr expr = d_exprManager->mkVar(name, type, levelZero);
- defineFunction(name, expr, levelZero);
+ Expr expr = d_exprManager->mkVar(name, type, flags);
+ defineFunction(name, expr, flags & ExprManager::VAR_FLAG_GLOBAL);
return expr;
}
Expr
-Parser::mkAnonymousFunction(const std::string& prefix, const Type& type) {
+Parser::mkAnonymousFunction(const std::string& prefix, const Type& type, uint32_t flags) {
stringstream name;
name << prefix << "_anon_" << ++d_anonymousFunctionCount;
- return mkFunction(name.str(), type);
+ return mkFunction(name.str(), type, flags);
}
std::vector<Expr>
-Parser::mkVars(const std::vector<std::string> names,
- const Type& type,
- bool levelZero) {
+Parser::mkVars(const std::vector<std::string> names, const Type& type, uint32_t flags) {
std::vector<Expr> vars;
for(unsigned i = 0; i < names.size(); ++i) {
- vars.push_back(mkVar(names[i], type, levelZero));
+ vars.push_back(mkVar(names[i], type, flags));
}
return vars;
}
std::vector<Expr>
-Parser::mkBoundVars(const std::vector<std::string> names,
- const Type& type) {
+Parser::mkBoundVars(const std::vector<std::string> names, const Type& type) {
std::vector<Expr> vars;
for(unsigned i = 0; i < names.size(); ++i) {
vars.push_back(mkBoundVar(names[i], type));
}
void
-Parser::defineVar(const std::string& name, const Expr& val,
- bool levelZero) {
- Debug("parser") << "defineVar( " << name << " := " << val << " , " << levelZero << ")" << std::endl;;
+Parser::defineVar(const std::string& name, const Expr& val, bool levelZero) {
+ Debug("parser") << "defineVar( " << name << " := " << val << ")" << std::endl;;
d_symtab->bind(name, val, levelZero);
assert( isDeclared(name) );
}
void
-Parser::defineFunction(const std::string& name, const Expr& val,
- bool levelZero) {
+Parser::defineFunction(const std::string& name, const Expr& val, bool levelZero) {
d_symtab->bindDefinedFunction(name, val, levelZero);
assert( isDeclared(name) );
}
/** Create a new CVC4 variable expression of the given type. */
Expr mkVar(const std::string& name, const Type& type,
- bool levelZero = false);
+ uint32_t flags = ExprManager::VAR_FLAG_NONE);
/**
* Create a set of new CVC4 variable expressions of the given type.
*/
std::vector<Expr>
mkVars(const std::vector<std::string> names, const Type& type,
- bool levelZero = false);
+ uint32_t flags = ExprManager::VAR_FLAG_NONE);
/** Create a new CVC4 bound variable expression of the given type. */
Expr mkBoundVar(const std::string& name, const Type& type);
/** Create a new CVC4 function expression of the given type. */
Expr mkFunction(const std::string& name, const Type& type,
- bool levelZero = false);
+ uint32_t flags = ExprManager::VAR_FLAG_NONE);
/**
* Create a new CVC4 function expression of the given type,
* appending a unique index to its name. (That's the ONLY
* difference between mkAnonymousFunction() and mkFunction()).
*/
- Expr mkAnonymousFunction(const std::string& prefix, const Type& type);
+ Expr mkAnonymousFunction(const std::string& prefix, const Type& type,
+ uint32_t flags = ExprManager::VAR_FLAG_NONE);
/** Create a new variable definition (e.g., from a let binding). */
void defineVar(const std::string& name, const Expr& val,
- bool levelZero = false);
+ bool levelZero = false);
/** Create a new function definition (e.g., from a define-fun). */
void defineFunction(const std::string& name, const Expr& val,
// declare the name down here (while parsing term, signature
// must not be extended with the name itself; no recursion
// permitted)
- Expr func = PARSER_STATE->mkFunction(name, t);
+ Expr func = PARSER_STATE->mkFunction(name, t, ExprManager::VAR_FLAG_DEFINED);
$cmd = new DefineFunctionCommand(name, func, terms, expr);
}
| /* value query */
( symbol[name,CHECK_UNDECLARED,SYM_VARIABLE]
{ PARSER_STATE->checkUserSymbol(name); }
term[e,e2]
- { Expr func = PARSER_STATE->mkFunction(name, e.getType());
+ { Expr func = PARSER_STATE->mkFunction(name, e.getType(), ExprManager::VAR_FLAG_DEFINED);
$cmd = new DefineFunctionCommand(name, func, e);
}
| LPAREN_TOK
}
t = EXPR_MANAGER->mkFunctionType(sorts, t);
}
- Expr func = PARSER_STATE->mkFunction(name, t);
+ Expr func = PARSER_STATE->mkFunction(name, t, ExprManager::VAR_FLAG_DEFINED);
$cmd = new DefineFunctionCommand(name, func, terms, e);
}
)
expr = getVariable(name);
} else {
Type t = term ? d_unsorted : getExprManager()->booleanType();
- expr = mkVar(name, t, true); // levelZero
+ expr = mkVar(name, t, ExprManager::VAR_FLAG_GLOBAL); // levelZero
preemptCommand(new DeclareFunctionCommand(name, expr, t));
}
} else { // Its an application
std::vector<Type> sorts(args.size(), d_unsorted);
Type t = term ? d_unsorted : getExprManager()->booleanType();
t = getExprManager()->mkFunctionType(sorts, t);
- expr = mkVar(name, t, true); // levelZero
+ expr = mkVar(name, t, ExprManager::VAR_FLAG_GLOBAL); // levelZero
preemptCommand(new DeclareFunctionCommand(name, expr, t));
}
// args might be rationals, in which case we need to create
tryToStream<CheckSatCommand>(out, c) ||
tryToStream<QueryCommand>(out, c) ||
tryToStream<QuitCommand>(out, c) ||
+ tryToStream<DeclarationSequence>(out, c) ||
tryToStream<CommandSequence>(out, c) ||
tryToStream<DeclareFunctionCommand>(out, c) ||
tryToStream<DeclareTypeCommand>(out, c) ||
static void toStream(std::ostream& out, const DefineFunctionCommand* c) throw() {
Expr func = c->getFunction();
- const vector<Expr>& formals = c->getFormals();
+ const vector<Expr>* formals = &c->getFormals();
out << "(define-fun " << func << " (";
Type type = func.getType();
+ Expr formula = c->getFormula();
if(type.isFunction()) {
- vector<Expr>::const_iterator i = formals.begin();
+ vector<Expr> f;
+ if(formals->empty()) {
+ const vector<Type>& params = FunctionType(type).getArgTypes();
+ for(vector<Type>::const_iterator j = params.begin(); j != params.end(); ++j) {
+ f.push_back(NodeManager::currentNM()->mkSkolem("a", TypeNode::fromType(*j), "",
+ NodeManager::SKOLEM_NO_NOTIFY).toExpr());
+ }
+ formula = NodeManager::currentNM()->toExprManager()->mkExpr(kind::APPLY_UF, formula, f);
+ formals = &f;
+ }
+ vector<Expr>::const_iterator i = formals->begin();
for(;;) {
out << "(" << (*i) << " " << (*i).getType() << ")";
++i;
- if(i != formals.end()) {
+ if(i != formals->end()) {
out << " ";
} else {
break;
}
type = FunctionType(type).getRangeType();
}
- Expr formula = c->getFormula();
out << ") " << type << " " << formula << ")";
}
d_smt.addToModelCommandAndDump(c);
}
- void nmNotifyNewVar(TNode n, bool isGlobal) {
+ void nmNotifyNewVar(TNode n, uint32_t flags) {
DeclareFunctionCommand c(n.getAttribute(expr::VarNameAttr()),
n.toExpr(),
n.getType().toType());
- d_smt.addToModelCommandAndDump(c, isGlobal);
+ if((flags & ExprManager::VAR_FLAG_DEFINED) == 0) {
+ d_smt.addToModelCommandAndDump(c, flags);
+ }
if(n.getType().isBoolean() && !options::incrementalSolving()) {
d_boolVars.push_back(n);
}
}
- void nmNotifyNewSkolem(TNode n, const std::string& comment, bool isGlobal) {
+ void nmNotifyNewSkolem(TNode n, const std::string& comment, uint32_t flags) {
string id = n.getAttribute(expr::VarNameAttr());
DeclareFunctionCommand c(id,
n.toExpr(),
if(Dump.isOn("skolems") && comment != "") {
Dump("skolems") << CommentCommand(id + " is " + comment);
}
- d_smt.addToModelCommandAndDump(c, isGlobal, false, "skolems");
+ if((flags & ExprManager::VAR_FLAG_DEFINED) == 0) {
+ d_smt.addToModelCommandAndDump(c, flags, false, "skolems");
+ }
if(n.getType().isBoolean() && !options::incrementalSolving()) {
d_boolVars.push_back(n);
}
throw TypeCheckingException(func, ss.str());
}
}
- if(Dump.isOn("declarations")) {
- stringstream ss;
- ss << Expr::setlanguage(Expr::setlanguage::getLanguage(Dump.getStream()))
- << func;
- DefineFunctionCommand c(ss.str(), func, formals, formula);
- addToModelCommandAndDump(c, false, true, "declarations");
- }
+
+ stringstream ss;
+ ss << Expr::setlanguage(Expr::setlanguage::getLanguage(Dump.getStream()))
+ << func;
+ DefineFunctionCommand c(ss.str(), func, formals, formula);
+ addToModelCommandAndDump(c, ExprManager::VAR_FLAG_NONE, true, "declarations");
+
SmtScope smts(this);
// Substitute out any abstract values in formula
return SExpr(sexprs);
}
-void SmtEngine::addToModelCommandAndDump(const Command& c, bool isGlobal, bool userVisible, const char* dumpTag) {
+void SmtEngine::addToModelCommandAndDump(const Command& c, uint32_t flags, bool userVisible, const char* dumpTag) {
Trace("smt") << "SMT addToModelCommandAndDump(" << c << ")" << endl;
SmtScope smts(this);
// If we aren't yet fully inited, the user might still turn on
// and expects to find their cardinalities in the model.
if(/* userVisible && */ (!d_fullyInited || options::produceModels())) {
doPendingPops();
- if(isGlobal) {
+ if(flags & ExprManager::VAR_FLAG_GLOBAL) {
d_modelGlobalCommands.push_back(c.clone());
} else {
d_modelCommands->push_back(c.clone());
* Add to Model command. This is used for recording a command
* that should be reported during a get-model call.
*/
- void addToModelCommandAndDump(const Command& c, bool isGlobal = false, bool userVisible = true, const char* dumpTag = "declarations");
+ void addToModelCommandAndDump(const Command& c, uint32_t flags = ExprManager::VAR_FLAG_NONE, bool userVisible = true, const char* dumpTag = "declarations");
/**
* Get the model (only if immediately preceded by a SAT