{
return rewriteConstructor(in);
}
- else if (k == kind::APPLY_SELECTOR_TOTAL)
+ else if (k == kind::APPLY_SELECTOR_TOTAL || k == kind::APPLY_SELECTOR)
{
return rewriteSelector(in);
}
RewriteResponse DatatypesRewriter::rewriteSelector(TNode in)
{
+ Kind k = in.getKind();
if (in[0].getKind() == kind::APPLY_CONSTRUCTOR)
{
// Have to be careful not to rewrite well-typed expressions
// e.g. "pred(zero)".
TypeNode tn = in.getType();
TypeNode argType = in[0].getType();
- TNode selector = in.getOperator();
+ Expr selector = in.getOperator().toExpr();
TNode constructor = in[0].getOperator();
size_t constructorIndex = indexOf(constructor);
- const Datatype& dt = Datatype::datatypeOf(selector.toExpr());
+ const Datatype& dt = Datatype::datatypeOf(selector);
const DatatypeConstructor& c = dt[constructorIndex];
Trace("datatypes-rewrite-debug") << "Rewriting collapsable selector : "
<< in;
Trace("datatypes-rewrite-debug") << ", cindex = " << constructorIndex
<< ", selector is " << selector
<< std::endl;
- int selectorIndex = c.getSelectorIndexInternal(selector.toExpr());
+ // The argument that the selector extracts, or -1 if the selector is
+ // is wrongly applied.
+ int selectorIndex = -1;
+ if (k == kind::APPLY_SELECTOR_TOTAL)
+ {
+ // The argument index of internal selectors is obtained by
+ // getSelectorIndexInternal.
+ selectorIndex = c.getSelectorIndexInternal(selector);
+ }
+ else
+ {
+ // The argument index of external selectors (applications of
+ // APPLY_SELECTOR) is given by an attribute and obtained via indexOf below
+ // The argument is only valid if it is the proper constructor.
+ selectorIndex = Datatype::indexOf(selector);
+ if (selectorIndex < 0 || selectorIndex >= c.getNumArgs())
+ {
+ selectorIndex = -1;
+ }
+ else if (c[selectorIndex].getSelector() != selector)
+ {
+ selectorIndex = -1;
+ }
+ }
Trace("datatypes-rewrite-debug") << "Internal selector index is "
<< selectorIndex << std::endl;
if (selectorIndex >= 0)
return RewriteResponse(REWRITE_DONE, in[0][selectorIndex]);
}
}
- else
+ else if (k == kind::APPLY_SELECTOR_TOTAL)
{
Node gt;
bool useTe = true;
for (unsigned j = 0, size = itsr->second.size(); j < size; j++)
{
Node res = itsr->second[j];
- Assert(res.isConst());
+ // The value of this term for this example, or the truth value of
+ // the I/O pair if the role of this enumerator is enum_io.
Node resb;
- if (eiv.getRole() == enum_io)
+ // If the result is not constant, then we cannot determine its value
+ // on this point. In this case, resb remains null.
+ if (res.isConst())
{
- Node out = d_examples_out[j];
- Assert(out.isConst());
- resb = res == out ? d_true : d_false;
- }
- else
- {
- resb = res;
+ if (eiv.getRole() == enum_io)
+ {
+ Node out = d_examples_out[j];
+ Assert(out.isConst());
+ resb = res == out ? d_true : d_false;
+ }
+ else
+ {
+ resb = res;
+ }
}
cond_vals[resb] = true;
results.push_back(resb);
if (Trace.isOn("sygus-sui-enum"))
{
- if (resb.getType().isBoolean())
+ if (resb.isNull())
+ {
+ Trace("sygus-sui-enum") << "_";
+ }
+ else if (resb.getType().isBoolean())
{
Trace("sygus-sui-enum") << (resb == d_true ? "1" : "0");
}
regress1/sygus/crcy-si-rcons.sy
regress1/sygus/crcy-si.sy
regress1/sygus/cube-nia.sy
+ regress1/sygus/double.sy
regress1/sygus/dt-test-ns.sy
regress1/sygus/dup-op.sy
+ regress1/sygus/extract.sy
regress1/sygus/fg_polynomial3.sy
regress1/sygus/find_sc_bvult_bvnot.sy
regress1/sygus/hd-01-d1-prog.sy