parser/parser.h
parser/parser_builder.h
parser/parser_exception.h
+ parser/parse_op.h
DESTINATION
${INCLUDE_INSTALL_DIR}/cvc4/parser)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/OptionException.java
${CMAKE_CURRENT_BINARY_DIR}/Options.java
${CMAKE_CURRENT_BINARY_DIR}/OutputLanguage.java
+ ${CMAKE_CURRENT_BINARY_DIR}/ParseOp.java
${CMAKE_CURRENT_BINARY_DIR}/Parser.java
${CMAKE_CURRENT_BINARY_DIR}/ParserBuilder.java
${CMAKE_CURRENT_BINARY_DIR}/ParserEndOfFileException.java
}
addConstructor(c);
}
-
+
+void Datatype::addSygusConstructor(Kind k,
+ const std::string& cname,
+ const std::vector<Type>& cargs,
+ std::shared_ptr<SygusPrintCallback> spc,
+ int weight)
+{
+ ExprManagerScope ems(*d_em);
+ Expr op = d_em->operatorOf(k);
+ addSygusConstructor(op, cname, cargs, spc, weight);
+}
+
void Datatype::setTuple() {
PrettyCheckArgument(
!isResolved(), this, "cannot set tuple to a finalized Datatype");
const std::vector<Type>& cargs,
std::shared_ptr<SygusPrintCallback> spc = nullptr,
int weight = -1);
+ /**
+ * Same as above, with builtin kind k.
+ */
+ void addSygusConstructor(Kind k,
+ const std::string& cname,
+ const std::vector<Type>& cargs,
+ std::shared_ptr<SygusPrintCallback> spc = nullptr,
+ int weight = -1);
/** set that this datatype is a tuple */
void setTuple();
#endif /* SWIGJAVA */
%}
+%include "expr/kind.i"
+
%extend std::vector< CVC4::Datatype > {
/* These member functions have slightly different signatures in
* different swig language packages. The underlying issue is that
line_buffer.h
memory_mapped_input_buffer.cpp
memory_mapped_input_buffer.h
+ parse_op.h
parser.cpp
parser.h
parser_builder.cpp
parser_builder.h
parser_exception.h
- smt2/parse_op.h
smt2/smt2.cpp
smt2/smt2.h
smt2/smt2_input.cpp
using namespace CVC4;
%}
-%include "parser/parser_exception.i"
%include "parser/input.i"
+%include "parser/parse_op.i"
%include "parser/parser.i"
%include "parser/parser_builder.i"
+%include "parser/parser_exception.i"
--- /dev/null
+/********************* */
+/*! \file parse_op.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Andrew Reynolds
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2019 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved. See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Definitions of parsed operators.
+ **/
+
+#include "cvc4parser_public.h"
+
+#ifndef CVC4__PARSER__PARSE_OP_H
+#define CVC4__PARSER__PARSE_OP_H
+
+#include <string>
+
+#include "expr/expr.h"
+#include "expr/kind.h"
+
+namespace CVC4 {
+
+/** A parsed operator
+ *
+ * The purpose of this struct is to store information regarding a parsed term
+ * that might not be ready to associate with an expression.
+ *
+ * While parsing terms in smt2, we may store a combination of one or more of
+ * the following to track how to process this term:
+ * (1) A kind.
+ * (2) A string name.
+ * (3) An expression expr.
+ * (4) A type t.
+ *
+ * Examples:
+ *
+ * - For declared functions f that we have not yet looked up in a symbol table,
+ * we store (2). We may store a name in a state if f is overloaded and we have
+ * not yet parsed its arguments to know how to disambiguate f.
+ * - For tuple selectors (_ tupSel n), we store (1) and (3). Kind is set to
+ * APPLY_SELECTOR, and expr is set to n, which is to be interpreted by the
+ * caller as the n^th generic tuple selector. We do this since there is no
+ * AST expression representing generic tuple select, and we do not have enough
+ * type information at this point to know the type of the tuple we will be
+ * selecting from.
+ * - For array constant specifications prior to type ascription e.g. when we
+ * have parsed "const", we store (1), setting the kind to STORE_ALL.
+ * - For array constant specifications (as const (Array T1 T2)), we store (1)
+ * and (4), where kind is set to STORE_ALL and type is set to (Array T1 T2).
+ * When parsing this as an operator e.g. ((as const (Array T1 T2)) t), we
+ * interpret this operator by converting the next parsed constant of type T2 to
+ * an Array of type (Array T1 T2) over that constant.
+ */
+struct CVC4_PUBLIC ParseOp
+{
+ ParseOp() : d_kind(kind::NULL_EXPR) {}
+ /** The kind associated with the parsed operator, if it exists */
+ Kind d_kind;
+ /** The name associated with the parsed operator, if it exists */
+ std::string d_name;
+ /** The expression associated with the parsed operator, if it exists */
+ Expr d_expr;
+ /** The type associated with the parsed operator, if it exists */
+ Type d_type;
+
+ /* Return true if this is equal to 'p'. */
+ bool operator==(const ParseOp& p) const
+ {
+ return d_kind == p.d_kind && d_name == p.d_name && d_expr == p.d_expr
+ && d_type == p.d_type;
+ }
+};
+
+inline std::ostream& operator<<(std::ostream& os, const ParseOp& p)
+{
+ if (!p.d_expr.isNull())
+ {
+ return os << p.d_expr;
+ }
+ else if (p.d_kind != kind::NULL_EXPR)
+ {
+ return os << p.d_kind;
+ }
+ return os << "ParseOp::unknown";
+}
+
+} // namespace CVC4
+
+#endif /* CVC4__PARSER__PARSE_OP_H */
--- /dev/null
+%{
+#include "parser/parse_op.h"
+%}
+
+%include "parser/parse_op.h"
}
Kind Parser::getKindForFunction(Expr fun) {
+ Kind k = getExprManager()->operatorToKind(fun);
+ if (k != UNDEFINED_KIND)
+ {
+ return k;
+ }
Type t = fun.getType();
if (t.isFunction())
{
{
return APPLY_TESTER;
}
- else
- {
- parseError("internal error: unhandled function application kind");
- return UNDEFINED_KIND;
- }
+ return UNDEFINED_KIND;
}
Type Parser::getSort(const std::string& name) {
#include "expr/kind.h"
#include "expr/symbol_table.h"
#include "parser/input.h"
+#include "parser/parse_op.h"
#include "parser/parser_exception.h"
#include "util/unsafe_interrupt_exception.h"
gterm_ignore,
};
Type d_type;
- Expr d_expr;
+ /** The parsed operator */
+ ParseOp d_op;
std::vector< Expr > d_let_vars;
unsigned d_gterm_type;
std::string d_name;
virtual Expr getExpressionForNameAndType(const std::string& name, Type t);
/**
- * Returns the kind that should be used for applications of expression fun, where
- * fun has "function-like" type, i.e. where checkFunctionLike(fun) returns true.
- * Returns a parse error if fun does not have function-like type.
+ * Returns the kind that should be used for applications of expression fun.
+ * This is a generalization of ExprManager::operatorToKind that also
+ * handles variables whose types are "function-like", i.e. where
+ * checkFunctionLike(fun) returns true.
*
- * For example, this function returns
+ * For examples of the latter, this function returns
* APPLY_UF if fun has function type,
* APPLY_CONSTRUCTOR if fun has constructor type.
*/
#include "parser/antlr_tracing.h"
#include "parser/parser.h"
-#include "parser/smt2/parse_op.h"
+#include "parser/parse_op.h"
#include "smt/command.h"
namespace CVC4 {
std::vector<std::vector<CVC4::SygusGTerm>> sgts;
std::vector<CVC4::Datatype> datatypes;
std::vector<Type> sorts;
- std::vector<std::vector<Expr>> ops;
+ std::vector<std::vector<ParseOp>> ops;
std::vector<std::vector<std::string>> cnames;
std::vector<std::vector<std::vector<CVC4::Type>>> cargs;
std::vector<bool> allow_const;
k = PARSER_STATE->getOperatorKind(name);
sgt.d_name = kind::kindToString(k);
sgt.d_gterm_type = SygusGTerm::gterm_op;
- sgt.d_expr = EXPR_MANAGER->operatorOf(k);
+ sgt.d_op.d_kind = k;
}else{
// what is this sygus term trying to accomplish here, if the
// symbol isn't yet declared?! probably the following line will
}
sgt.d_name = name;
sgt.d_gterm_type = SygusGTerm::gterm_op;
- sgt.d_expr = PARSER_STATE->getVariable(name) ;
+ sgt.d_op.d_expr = PARSER_STATE->getVariable(name) ;
}
}
)
<< "expression " << atomTerm << std::endl;
std::stringstream ss;
ss << atomTerm;
- sgt.d_expr = atomTerm.getExpr();
+ sgt.d_op.d_expr = atomTerm.getExpr();
sgt.d_name = ss.str();
sgt.d_gterm_type = SygusGTerm::gterm_op;
}
Debug("parser-sygus") << "Sygus grammar " << fun
<< " : unary minus integer literal " << name
<< std::endl;
- sgt.d_expr = MK_CONST(Rational(name));
+ sgt.d_op.d_expr = MK_CONST(Rational(name));
sgt.d_name = name;
sgt.d_gterm_type = SygusGTerm::gterm_op;
}else if( PARSER_STATE->isDeclared(name,SYM_VARIABLE) ){
Debug("parser-sygus") << "Sygus grammar " << fun << " : symbol "
<< name << std::endl;
- sgt.d_expr = PARSER_STATE->getExpressionForName(name);
+ sgt.d_op.d_expr = PARSER_STATE->getExpressionForName(name);
sgt.d_name = name;
sgt.d_gterm_type = SygusGTerm::gterm_op;
}else{
+++ /dev/null
-/********************* */
-/*! \file parse_op.h
- ** \verbatim
- ** Top contributors (to current version):
- ** Andrew Reynolds
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2019 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved. See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief Definitions of parsed operators in smt2.
- **/
-
-#include "cvc4parser_private.h"
-
-#ifndef CVC4__PARSER__SMT2__PARSE_OP_H
-#define CVC4__PARSER__SMT2__PARSE_OP_H
-
-#include <string>
-
-#include "expr/expr.h"
-#include "expr/kind.h"
-
-namespace CVC4 {
-
-/** A parsed operator
- *
- * The purpose of this struct is to store information regarding a parsed term
- * in the smt2 language that might not be ready to associate with an
- * expression.
- *
- * While parsing terms in smt2, we may store a combination of one or more of
- * the following to track how to process this term:
- * (1) A kind.
- * (2) A string name.
- * (3) An expression expr.
- * (4) A type t.
- *
- * Examples:
- *
- * - For declared functions f that we have not yet looked up in a symbol table,
- * we store (2). We may store a name in a state if f is overloaded and we have
- * not yet parsed its arguments to know how to disambiguate f.
- * - For tuple selectors (_ tupSel n), we store (1) and (3). Kind is set to
- * APPLY_SELECTOR, and expr is set to n, which is to be interpreted by the
- * caller as the n^th generic tuple selector. We do this since there is no
- * AST expression representing generic tuple select, and we do not have enough
- * type information at this point to know the type of the tuple we will be
- * selecting from.
- * - For array constant specifications prior to type ascription e.g. when we
- * have parsed "const", we store (1), setting the kind to STORE_ALL.
- * - For array constant specifications (as const (Array T1 T2)), we store (1)
- * and (4), where kind is set to STORE_ALL and type is set to (Array T1 T2).
- * When parsing this as an operator e.g. ((as const (Array T1 T2)) t), we
- * interpret this operator by converting the next parsed constant of type T2 to
- * an Array of type (Array T1 T2) over that constant.
- */
-struct ParseOp
-{
- ParseOp() : d_kind(kind::NULL_EXPR) {}
- /** The kind associated with the parsed operator, if it exists */
- Kind d_kind;
- /** The name associated with the parsed operator, if it exists */
- std::string d_name;
- /** The expression associated with the parsed operator, if it exists */
- Expr d_expr;
- /** The type associated with the parsed operator, if it exists */
- Type d_type;
-};
-
-} // namespace CVC4
-
-#endif /* CVC4__PARSER__SMT2__PARSE_OP_H */
int index,
std::vector<CVC4::Datatype>& datatypes,
std::vector<CVC4::Type>& sorts,
- std::vector<std::vector<CVC4::Expr>>& ops,
+ std::vector<std::vector<ParseOp>>& ops,
std::vector<std::vector<std::string>>& cnames,
std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
std::vector<bool>& allow_const,
{
if (sgt.d_gterm_type == SygusGTerm::gterm_op)
{
- Debug("parser-sygus") << "Add " << sgt.d_expr << " to datatype " << index
- << std::endl;
+ Debug("parser-sygus") << "Add " << sgt.d_op << " to datatype "
+ << index << std::endl;
Kind oldKind;
Kind newKind = kind::UNDEFINED_KIND;
//convert to UMINUS if one child of MINUS
- if( sgt.d_children.size()==1 && sgt.d_expr==getExprManager()->operatorOf(kind::MINUS) ){
+ if (sgt.d_children.size() == 1 && sgt.d_op.d_kind == kind::MINUS)
+ {
oldKind = kind::MINUS;
newKind = kind::UMINUS;
}
if( newKind!=kind::UNDEFINED_KIND ){
- Expr newExpr = getExprManager()->operatorOf(newKind);
- Debug("parser-sygus") << "Replace " << sgt.d_expr << " with " << newExpr << std::endl;
- sgt.d_expr = newExpr;
+ Debug("parser-sygus")
+ << "Replace " << sgt.d_op.d_kind << " with " << newKind << std::endl;
+ sgt.d_op.d_kind = newKind;
std::string oldName = kind::kindToString(oldKind);
std::string newName = kind::kindToString(newKind);
size_t pos = 0;
sgt.d_name.replace(pos, oldName.length(), newName);
}
}
- ops[index].push_back( sgt.d_expr );
+ ops[index].push_back(sgt.d_op);
cnames[index].push_back( sgt.d_name );
cargs[index].push_back( std::vector< CVC4::Type >() );
for( unsigned i=0; i<sgt.d_children.size(); i++ ){
std::stringstream ss;
ss << consts[i];
Debug("parser-sygus") << "...add for constant " << ss.str() << std::endl;
- ops[index].push_back( consts[i] );
+ ParseOp constOp;
+ constOp.d_expr = consts[i];
+ ops[index].push_back(constOp);
cnames[index].push_back( ss.str() );
cargs[index].push_back( std::vector< CVC4::Type >() );
}
std::stringstream ss;
ss << sygus_vars[i];
Debug("parser-sygus") << "...add for variable " << ss.str() << std::endl;
- ops[index].push_back( sygus_vars[i] );
+ ParseOp varOp;
+ varOp.d_expr = sygus_vars[i];
+ ops[index].push_back(varOp);
cnames[index].push_back( ss.str() );
cargs[index].push_back( std::vector< CVC4::Type >() );
}
}
}
-bool Smt2::pushSygusDatatypeDef( Type t, std::string& dname,
- std::vector< CVC4::Datatype >& datatypes,
- std::vector< CVC4::Type>& sorts,
- std::vector< std::vector<CVC4::Expr> >& ops,
- std::vector< std::vector<std::string> >& cnames,
- std::vector< std::vector< std::vector< CVC4::Type > > >& cargs,
- std::vector< bool >& allow_const,
- std::vector< std::vector< std::string > >& unresolved_gterm_sym ){
+bool Smt2::pushSygusDatatypeDef(
+ Type t,
+ std::string& dname,
+ std::vector<CVC4::Datatype>& datatypes,
+ std::vector<CVC4::Type>& sorts,
+ std::vector<std::vector<ParseOp>>& ops,
+ std::vector<std::vector<std::string>>& cnames,
+ std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
+ std::vector<bool>& allow_const,
+ std::vector<std::vector<std::string>>& unresolved_gterm_sym)
+{
sorts.push_back(t);
datatypes.push_back(Datatype(getExprManager(), dname));
- ops.push_back(std::vector<Expr>());
+ ops.push_back(std::vector<ParseOp>());
cnames.push_back(std::vector<std::string>());
cargs.push_back(std::vector<std::vector<CVC4::Type> >());
allow_const.push_back(false);
return true;
}
-bool Smt2::popSygusDatatypeDef( std::vector< CVC4::Datatype >& datatypes,
- std::vector< CVC4::Type>& sorts,
- std::vector< std::vector<CVC4::Expr> >& ops,
- std::vector< std::vector<std::string> >& cnames,
- std::vector< std::vector< std::vector< CVC4::Type > > >& cargs,
- std::vector< bool >& allow_const,
- std::vector< std::vector< std::string > >& unresolved_gterm_sym ){
+bool Smt2::popSygusDatatypeDef(
+ std::vector<CVC4::Datatype>& datatypes,
+ std::vector<CVC4::Type>& sorts,
+ std::vector<std::vector<ParseOp>>& ops,
+ std::vector<std::vector<std::string>>& cnames,
+ std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
+ std::vector<bool>& allow_const,
+ std::vector<std::vector<std::string>>& unresolved_gterm_sym)
+{
sorts.pop_back();
datatypes.pop_back();
ops.pop_back();
return true;
}
-Type Smt2::processSygusNestedGTerm( int sub_dt_index, std::string& sub_dname, std::vector< CVC4::Datatype >& datatypes,
- std::vector< CVC4::Type>& sorts,
- std::vector< std::vector<CVC4::Expr> >& ops,
- std::vector< std::vector<std::string> >& cnames,
- std::vector< std::vector< std::vector< CVC4::Type > > >& cargs,
- std::vector< bool >& allow_const,
- std::vector< std::vector< std::string > >& unresolved_gterm_sym,
- std::map< CVC4::Type, CVC4::Type >& sygus_to_builtin,
- std::map< CVC4::Type, CVC4::Expr >& sygus_to_builtin_expr, Type sub_ret ) {
+Type Smt2::processSygusNestedGTerm(
+ int sub_dt_index,
+ std::string& sub_dname,
+ std::vector<CVC4::Datatype>& datatypes,
+ std::vector<CVC4::Type>& sorts,
+ std::vector<std::vector<ParseOp>>& ops,
+ std::vector<std::vector<std::string>>& cnames,
+ std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
+ std::vector<bool>& allow_const,
+ std::vector<std::vector<std::string>>& unresolved_gterm_sym,
+ std::map<CVC4::Type, CVC4::Type>& sygus_to_builtin,
+ std::map<CVC4::Type, CVC4::Expr>& sygus_to_builtin_expr,
+ Type sub_ret)
+{
Type t = sub_ret;
Debug("parser-sygus") << "Argument is ";
if( t.isNull() ){
if( cargs[sub_dt_index].empty() ){
parseError(std::string("Internal error : datatype for nested gterm does not have a constructor."));
}
- Expr sop = ops[sub_dt_index][0];
+ ParseOp op = ops[sub_dt_index][0];
Type curr_t;
- if( sop.getKind() != kind::BUILTIN && ( sop.isConst() || cargs[sub_dt_index][0].empty() ) ){
+ if (!op.d_expr.isNull()
+ && (op.d_expr.isConst() || cargs[sub_dt_index][0].empty()))
+ {
+ Expr sop = op.d_expr;
curr_t = sop.getType();
Debug("parser-sygus") << ": it is constant/0-arg cons " << sop << " with type " << sop.getType() << ", debug=" << sop.isConst() << " " << cargs[sub_dt_index][0].size() << std::endl;
// only cache if it is a singleton datatype (has unique expr)
d_sygus_bound_var_type[sop] = t;
}
}
- }else{
+ }
+ else
+ {
std::vector< Expr > children;
- if( sop.getKind() != kind::BUILTIN ){
- children.push_back( sop );
- }
for( unsigned i=0; i<cargs[sub_dt_index][0].size(); i++ ){
std::map< CVC4::Type, CVC4::Expr >::iterator it = sygus_to_builtin_expr.find( cargs[sub_dt_index][0][i] );
if( it==sygus_to_builtin_expr.end() ){
children.push_back( it->second );
}
}
- Kind sk = sop.getKind() != kind::BUILTIN
- ? getKindForFunction(sop)
- : getExprManager()->operatorToKind(sop);
- Debug("parser-sygus") << ": operator " << sop << " with " << sop.getKind() << " " << sk << std::endl;
- Expr e = getExprManager()->mkExpr( sk, children );
+ Expr e = applyParseOp(op, children);
Debug("parser-sygus") << ": constructed " << e << ", which has type " << e.getType() << std::endl;
curr_t = e.getType();
sygus_to_builtin_expr[t] = e;
int startIndex,
std::vector<CVC4::Datatype>& datatypes,
std::vector<CVC4::Type>& sorts,
- std::vector<std::vector<CVC4::Expr>>& ops)
+ std::vector<std::vector<ParseOp>>& ops)
{
if( startIndex>0 ){
CVC4::Datatype tmp_dt = datatypes[0];
Type tmp_sort = sorts[0];
- std::vector< Expr > tmp_ops;
+ std::vector<ParseOp> tmp_ops;
tmp_ops.insert( tmp_ops.end(), ops[0].begin(), ops[0].end() );
datatypes[0] = datatypes[startIndex];
sorts[0] = sorts[startIndex];
}
}
-void Smt2::mkSygusDatatype( CVC4::Datatype& dt, std::vector<CVC4::Expr>& ops,
- std::vector<std::string>& cnames, std::vector< std::vector< CVC4::Type > >& cargs,
- std::vector<std::string>& unresolved_gterm_sym,
- std::map< CVC4::Type, CVC4::Type >& sygus_to_builtin ) {
+void Smt2::mkSygusDatatype(CVC4::Datatype& dt,
+ std::vector<ParseOp>& ops,
+ std::vector<std::string>& cnames,
+ std::vector<std::vector<CVC4::Type>>& cargs,
+ std::vector<std::string>& unresolved_gterm_sym,
+ std::map<CVC4::Type, CVC4::Type>& sygus_to_builtin)
+{
Debug("parser-sygus") << "Making sygus datatype " << dt.getName() << std::endl;
Debug("parser-sygus") << " add constructors..." << std::endl;
Expr lbvl = makeSygusBoundVarList(dt, i, ltypes, largs);
// make the let_body
- std::vector<Expr> children;
- if (ops[i].getKind() != kind::BUILTIN)
- {
- children.push_back(ops[i]);
- }
- children.insert(children.end(), largs.begin(), largs.end());
- Kind sk = ops[i].getKind() != kind::BUILTIN
- ? getKindForFunction(ops[i])
- : getExprManager()->operatorToKind(ops[i]);
- Expr body = getExprManager()->mkExpr(sk, children);
+ Expr body = applyParseOp(ops[i], largs);
// replace by lambda
- ops[i] = getExprManager()->mkExpr(kind::LAMBDA, lbvl, body);
+ ParseOp pLam;
+ pLam.d_expr = getExprManager()->mkExpr(kind::LAMBDA, lbvl, body);
+ ops[i] = pLam;
Debug("parser-sygus") << " ...replace op : " << ops[i] << std::endl;
// callback prints as the expression
spc = std::make_shared<printer::SygusExprPrintCallback>(body, largs);
}
else
{
- if (ops[i].getType().isBitVector() && ops[i].isConst())
+ Expr sop = ops[i].d_expr;
+ if (!sop.isNull() && sop.getType().isBitVector() && sop.isConst())
{
- Debug("parser-sygus") << "--> Bit-vector constant " << ops[i] << " ("
+ Debug("parser-sygus") << "--> Bit-vector constant " << sop << " ("
<< cnames[i] << ")" << std::endl;
// Since there are multiple output formats for bit-vectors and
// we are required by sygus standards to print in the exact input
// the given name.
spc = std::make_shared<printer::SygusNamedPrintCallback>(cnames[i]);
}
- else if (ops[i].getKind() == kind::VARIABLE)
+ else if (!sop.isNull() && sop.getKind() == kind::VARIABLE)
{
Debug("parser-sygus") << "--> Defined function " << ops[i]
<< std::endl;
// turn f into (lammbda (x) (f x))
// in a degenerate case, ops[i] may be a defined constant,
// in which case we do not replace by a lambda.
- if (ops[i].getType().isFunction())
+ if (sop.getType().isFunction())
{
std::vector<Type> ftypes =
- static_cast<FunctionType>(ops[i].getType()).getArgTypes();
+ static_cast<FunctionType>(sop.getType()).getArgTypes();
std::vector<Expr> largs;
Expr lbvl = makeSygusBoundVarList(dt, i, ftypes, largs);
- largs.insert(largs.begin(), ops[i]);
+ largs.insert(largs.begin(), sop);
Expr body = getExprManager()->mkExpr(kind::APPLY_UF, largs);
- ops[i] = getExprManager()->mkExpr(kind::LAMBDA, lbvl, body);
+ ops[i].d_expr = getExprManager()->mkExpr(kind::LAMBDA, lbvl, body);
Debug("parser-sygus") << " ...replace op : " << ops[i]
<< std::endl;
}
cnames[i] = ss.str();
Debug("parser-sygus") << " construct the datatype " << cnames[i] << "..."
<< std::endl;
- // add the sygus constructor
- dt.addSygusConstructor(ops[i], cnames[i], cargs[i], spc);
+ // Add the sygus constructor, either using the expression operator of
+ // ops[i], or the kind.
+ if (!ops[i].d_expr.isNull())
+ {
+ dt.addSygusConstructor(ops[i].d_expr, cnames[i], cargs[i], spc);
+ }
+ else if (ops[i].d_kind != kind::NULL_EXPR)
+ {
+ dt.addSygusConstructor(ops[i].d_kind, cnames[i], cargs[i], spc);
+ }
+ else
+ {
+ std::stringstream ss;
+ ss << "unexpected parse operator for sygus constructor" << ops[i];
+ parseError(ss.str());
+ }
Debug("parser-sygus") << " finished constructing the datatype"
<< std::endl;
}
dt.addSygusConstructor(id_op, unresolved_gterm_sym[i], id_carg, sepc);
//add to operators
- ops.push_back( id_op );
+ ParseOp idOp;
+ idOp.d_expr = id_op;
+ ops.push_back(idOp);
}
}else{
std::stringstream ss;
{
// An explicit operator, e.g. an indexed symbol.
args.insert(args.begin(), p.d_expr);
- if (p.d_expr.getType().isTester())
+ Kind fkind = getKindForFunction(p.d_expr);
+ if (fkind != kind::UNDEFINED_KIND)
{
+ // Some operators may require a specific kind.
// Testers are handled differently than other indexed operators,
// since they require a kind.
- kind = kind::APPLY_TESTER;
+ kind = fkind;
}
}
else
// Second phase: apply the arguments to the parse op
ExprManager* em = getExprManager();
// handle special cases
- if (p.d_kind == kind::STORE_ALL)
+ if (p.d_kind == kind::STORE_ALL && !p.d_type.isNull())
{
if (args.size() != 1)
{
}
return em->mkConst(ArrayStoreAll(p.d_type, constVal));
}
- else if (p.d_kind == kind::APPLY_SELECTOR)
+ else if (p.d_kind == kind::APPLY_SELECTOR && !p.d_expr.isNull())
{
- if (p.d_expr.isNull())
- {
- parseError("Could not process parsed tuple selector.");
- }
// tuple selector case
Integer x = p.d_expr.getConst<Rational>().getNumerator();
if (!x.fitsUnsignedInt())
}
else if (p.d_kind != kind::NULL_EXPR)
{
- std::stringstream ss;
- ss << "Could not process parsed qualified identifier kind " << p.d_kind;
- parseError(ss.str());
+ // it should not have an expression or type specified at this point
+ if (!p.d_expr.isNull() || !p.d_type.isNull())
+ {
+ std::stringstream ss;
+ ss << "Could not process parsed qualified identifier kind " << p.d_kind;
+ parseError(ss.str());
+ }
+ // otherwise it is a simple application
+ kind = p.d_kind;
}
else if (isBuiltinOperator)
{
#include <utility>
#include "api/cvc4cpp.h"
+#include "parser/parse_op.h"
#include "parser/parser.h"
-#include "parser/smt2/parse_op.h"
#include "smt/command.h"
#include "theory/logic_info.h"
#include "util/abstract_value.h"
int index,
std::vector<CVC4::Datatype>& datatypes,
std::vector<CVC4::Type>& sorts,
- std::vector<std::vector<CVC4::Expr>>& ops,
+ std::vector<std::vector<ParseOp>>& ops,
std::vector<std::vector<std::string>>& cnames,
std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
std::vector<bool>& allow_const,
std::string& dname,
std::vector<CVC4::Datatype>& datatypes,
std::vector<CVC4::Type>& sorts,
- std::vector<std::vector<CVC4::Expr>>& ops,
+ std::vector<std::vector<ParseOp>>& ops,
std::vector<std::vector<std::string>>& cnames,
std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
std::vector<bool>& allow_const,
bool popSygusDatatypeDef(
std::vector<CVC4::Datatype>& datatypes,
std::vector<CVC4::Type>& sorts,
- std::vector<std::vector<CVC4::Expr>>& ops,
+ std::vector<std::vector<ParseOp>>& ops,
std::vector<std::vector<std::string>>& cnames,
std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
std::vector<bool>& allow_const,
int startIndex,
std::vector<CVC4::Datatype>& datatypes,
std::vector<CVC4::Type>& sorts,
- std::vector<std::vector<CVC4::Expr>>& ops);
+ std::vector<std::vector<ParseOp>>& ops);
- void mkSygusDatatype( CVC4::Datatype& dt, std::vector<CVC4::Expr>& ops,
- std::vector<std::string>& cnames, std::vector< std::vector< CVC4::Type > >& cargs,
- std::vector<std::string>& unresolved_gterm_sym,
- std::map< CVC4::Type, CVC4::Type >& sygus_to_builtin );
+ void mkSygusDatatype(CVC4::Datatype& dt,
+ std::vector<ParseOp>& ops,
+ std::vector<std::string>& cnames,
+ std::vector<std::vector<CVC4::Type>>& cargs,
+ std::vector<std::string>& unresolved_gterm_sym,
+ std::map<CVC4::Type, CVC4::Type>& sygus_to_builtin);
/**
* Adds a constructor to sygus datatype dt whose sygus operator is term.
private:
std::map< CVC4::Expr, CVC4::Type > d_sygus_bound_var_type;
- Type processSygusNestedGTerm( int sub_dt_index, std::string& sub_dname, std::vector< CVC4::Datatype >& datatypes,
- std::vector< CVC4::Type>& sorts,
- std::vector< std::vector<CVC4::Expr> >& ops,
- std::vector< std::vector<std::string> >& cnames,
- std::vector< std::vector< std::vector< CVC4::Type > > >& cargs,
- std::vector< bool >& allow_const,
- std::vector< std::vector< std::string > >& unresolved_gterm_sym,
- std::map< CVC4::Type, CVC4::Type >& sygus_to_builtin,
- std::map< CVC4::Type, CVC4::Expr >& sygus_to_builtin_expr, Type sub_ret );
+ Type processSygusNestedGTerm(
+ int sub_dt_index,
+ std::string& sub_dname,
+ std::vector<CVC4::Datatype>& datatypes,
+ std::vector<CVC4::Type>& sorts,
+ std::vector<std::vector<ParseOp>>& ops,
+ std::vector<std::vector<std::string>>& cnames,
+ std::vector<std::vector<std::vector<CVC4::Type>>>& cargs,
+ std::vector<bool>& allow_const,
+ std::vector<std::vector<std::string>>& unresolved_gterm_sym,
+ std::map<CVC4::Type, CVC4::Type>& sygus_to_builtin,
+ std::map<CVC4::Type, CVC4::Expr>& sygus_to_builtin_expr,
+ Type sub_ret);
/** make sygus bound var list
*