Fixes https://github.com/cvc5/cvc5/issues/8111.
Having `isConst` return true is required for some rare use cases of regular expressions, e.g. rewrite rule synthesis involving regular expression variables.
typerule REGEXP_LOOP_OP "SimpleTypeRule<RBuiltinOperator>"
typerule REGEXP_LOOP "SimpleTypeRule<RRegExp, ARegExp>"
typerule REGEXP_COMPLEMENT "SimpleTypeRule<RRegExp, ARegExp>"
-typerule STRING_TO_REGEXP "SimpleTypeRule<RRegExp, AString>"
+typerule STRING_TO_REGEXP ::cvc5::theory::strings::StringToRegExpTypeRule
typerule STRING_IN_REGEXP "SimpleTypeRule<RBool, AString, ARegExp>"
typerule REGEXP_NONE "SimpleTypeRule<RRegExp>"
typerule REGEXP_ALLCHAR "SimpleTypeRule<RRegExp>"
+# we return isConst for some regular expressions, including all that we enumerate
+construle STRING_TO_REGEXP ::cvc5::theory::strings::StringToRegExpTypeRule
+
### operators that apply to both strings and sequences
typerule STRING_CONCAT ::cvc5::theory::strings::StringConcatTypeRule
return nodeManager->regExpType();
}
+TypeNode StringToRegExpTypeRule::computeType(NodeManager* nodeManager,
+ TNode n,
+ bool check)
+{
+ if (check)
+ {
+ if (!n[0].getType().isString())
+ {
+ throw TypeCheckingExceptionPrivate(
+ n, "expecting string term in string to regexp");
+ }
+ }
+ return nodeManager->regExpType();
+}
+
+bool StringToRegExpTypeRule::computeIsConst(NodeManager* nodeManager, TNode n)
+{
+ Assert(n.getKind() == kind::STRING_TO_REGEXP);
+ return n[0].isConst();
+}
+
TypeNode ConstSequenceTypeRule::computeType(NodeManager* nodeManager,
TNode n,
bool check)
static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check);
};
+class StringToRegExpTypeRule
+{
+ public:
+ static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check);
+
+ /**
+ * Returns true if the argument to STRING_TO_REGEXP is a constant.
+ *
+ * In general, our implementation of isConst is incomplete for regular
+ * expressions, i.e. it is possible to return isConst for more regular
+ * expression terms.
+ *
+ * However, we at least require returning isConst true for STRING_TO_REGEXP
+ * applied to constant strings, as the regular expression enumerator uses
+ * these.
+ */
+ static bool computeIsConst(NodeManager* nodeManager, TNode n);
+};
+
class ConstSequenceTypeRule
{
public: