This ensures we don't quote symbols that should not be quoted, fixing two issues:
(1) Proofs in the internal calculus don't convert `:args` to `|:args|`.
(2) LFSC identifiers for terms are not quoted based on SMT-LIB restrictions.
Work towards https://github.com/cvc5/cvc5-projects/issues/466, quoted TypeNode names still need to be addressed.
return n;
}
+Node NodeManager::mkRawSymbol(const std::string& name, const TypeNode& type)
+{
+ Node n = NodeBuilder(this, kind::RAW_SYMBOL);
+ n.setAttribute(TypeAttr(), type);
+ n.setAttribute(TypeCheckedAttr(), true);
+ setAttribute(n, expr::VarNameAttr(), name);
+ return n;
+}
+
Node NodeManager::mkNullaryOperator(const TypeNode& type, Kind k)
{
std::map<TypeNode, Node>::iterator it = d_unique_vars[k].find(type);
/** Create a instantiation constant with the given type. */
Node mkInstConstant(const TypeNode& type);
+ /** Create a raw symbol with the given type. */
+ Node mkRawSymbol(const std::string& name, const TypeNode& type);
+
/** Make a new uninterpreted sort value with the given type. */
Node mkUninterpretedSortValue(const TypeNode& type);
string s;
if (n.getAttribute(expr::VarNameAttr(), s))
{
- out << cvc5::internal::quoteSymbol(s);
+ if (n.getKind() == kind::RAW_SYMBOL)
+ {
+ // raw symbols are never quoted
+ out << s;
+ }
+ else
+ {
+ out << cvc5::internal::quoteSymbol(s);
+ }
}
else
{
<< "postConvert " << n << " " << k << std::endl;
if (k == BOUND_VARIABLE)
{
- // ignore internally generated symbols
if (d_symbols.find(n) != d_symbols.end())
{
+ // ignore internally generated symbols
return n;
}
// bound variable v is (bvar x T)
Node bvarOp = getSymbolInternal(k, ftype, "bvar");
return nm->mkNode(APPLY_UF, bvarOp, x, tc);
}
+ else if (k == RAW_SYMBOL)
+ {
+ // ignore internally generated symbols
+ return n;
+ }
else if (k == SKOLEM || k == BOOLEAN_TERM_VARIABLE)
{
// constructors/selectors are represented by skolems, which are defined
{
std::stringstream sss;
sss << LfscNodeConverter::getNameForUserName(ss.str());
- tnn = getSymbolInternal(k, d_sortType, sss.str());
+ tnn = getSymbolInternal(k, d_sortType, sss.str(), false);
cur = nm->mkSort(sss.str());
}
else
TypeNode ftype = nm->mkFunctionType(types, d_sortType);
std::string name;
tn.getAttribute(expr::VarNameAttr(), name);
- op = getSymbolInternal(k, ftype, name);
+ op = getSymbolInternal(k, ftype, name, false);
}
else
{
return it->second;
}
-Node LfscNodeConverter::mkInternalSymbol(const std::string& name, TypeNode tn)
+Node LfscNodeConverter::mkInternalSymbol(const std::string& name,
+ TypeNode tn,
+ bool useRawSym)
{
- Node sym = NodeManager::currentNM()->mkBoundVar(name, tn);
+ // use raw symbol so that it is never quoted
+ NodeManager* nm = NodeManager::currentNM();
+ Node sym = useRawSym ? nm->mkRawSymbol(name, tn) : nm->mkBoundVar(name, tn);
d_symbols.insert(sym);
return sym;
}
-Node LfscNodeConverter::getSymbolInternalFor(Node n, const std::string& name)
+Node LfscNodeConverter::getSymbolInternalFor(Node n,
+ const std::string& name,
+ bool useRawSym)
{
- return getSymbolInternal(n.getKind(), n.getType(), name);
+ return getSymbolInternal(n.getKind(), n.getType(), name, useRawSym);
}
Node LfscNodeConverter::getSymbolInternal(Kind k,
TypeNode tn,
- const std::string& name)
+ const std::string& name,
+ bool useRawSym)
{
std::tuple<Kind, TypeNode, std::string> key(k, tn, name);
std::map<std::tuple<Kind, TypeNode, std::string>, Node>::iterator it =
{
return it->second;
}
- Node sym = mkInternalSymbol(name, tn);
+ Node sym = mkInternalSymbol(name, tn, useRawSym);
d_symbolToBuiltinKind[sym] = k;
d_symbolsMap[key] = sym;
return sym;
* has a distinguished status so that it is *not* printed as (bvar ...). The
* returned variable is always fresh.
*/
- Node mkInternalSymbol(const std::string& name, TypeNode tn);
+ Node mkInternalSymbol(const std::string& name,
+ TypeNode tn,
+ bool useRawSym = true);
/**
* Get builtin kind for internal symbol op
*/
* Get symbol for term, a special case of the method below for the type and
* kind of n.
*/
- Node getSymbolInternalFor(Node n, const std::string& name);
+ Node getSymbolInternalFor(Node n,
+ const std::string& name,
+ bool useRawSym = true);
/**
* Get symbol internal, (k,tn,name) are for caching, name is the name. This
* method returns a fresh symbol of the given name and type. It is frequently
* used when the type of a native operator does not match the type of the
* LFSC operator.
*/
- Node getSymbolInternal(Kind k, TypeNode tn, const std::string& name);
+ Node getSymbolInternal(Kind k,
+ TypeNode tn,
+ const std::string& name,
+ bool useRawSym = true);
/**
* Get character vector, add internal vector of characters for c.
*/
{
const DTypeConstructor& cons = dt[i];
std::string cname = d_tproc.getNameForUserNameOf(cons.getConstructor());
- // for now, must print as node to ensure same policy for printing
- // variable names. For instance, this means that cvc.X is printed as
- // LFSC identifier |cvc.X| if X contains symbols legal in LFSC but not
- // SMT-LIB. (cvc5-projects/issues/466) We should disable printing quote
- // escapes in the smt2 printing of LFSC converted terms.
- Node cc = nm->mkBoundVar(cname, stc);
+ Node cc = nm->mkRawSymbol(cname, stc);
// print constructor/tester
preamble << "(declare " << cc << " term)" << std::endl;
for (size_t j = 0, nargs = cons.getNumArgs(); j < nargs; j++)
const DTypeSelector& arg = cons[j];
// print selector
std::string sname = d_tproc.getNameForUserNameOf(arg.getSelector());
- Node sc = nm->mkBoundVar(sname, stc);
+ Node sc = nm->mkRawSymbol(sname, stc);
preamble << "(declare " << sc << " term)" << std::endl;
}
}
ProofNodeToSExpr::ProofNodeToSExpr()
{
NodeManager* nm = NodeManager::currentNM();
- d_conclusionMarker = nm->mkBoundVar(":conclusion", nm->sExprType());
- d_argsMarker = nm->mkBoundVar(":args", nm->sExprType());
+ // use raw symbols so that `:args` is not converted to `|:args|`
+ d_conclusionMarker = nm->mkRawSymbol(":conclusion", nm->sExprType());
+ d_argsMarker = nm->mkRawSymbol(":args", nm->sExprType());
}
Node ProofNodeToSExpr::convertToSExpr(const ProofNode* pn)
typerule SEXPR ::cvc5::internal::theory::builtin::SExprTypeRule
typerule WITNESS ::cvc5::internal::theory::builtin::WitnessTypeRule
+variable RAW_SYMBOL "a variable that is not quoted in the smt2 printer (internal only)"
+
endtheory