This adds node-level interfaces for a few missing functions that will be necessary to have a Node-level API for datatypes.
TypeNode dtt = TypeNode::fromType(dt.getDatatypeType());
TypeMatcher m(dtt);
m.doMatching(dtt, TypeNode::fromType(returnType));
- vector<Type> subst;
- m.getMatches(subst);
+ std::vector<TypeNode> sns;
+ m.getMatches(sns);
+ std::vector<Type> subst;
+ for (TypeNode& s : sns)
+ {
+ subst.push_back(s.toType());
+ }
vector<Type> params = dt.getParameters();
return d_constructor.getType().substitute(params, subst);
}
return true;
}
-void TypeMatcher::getTypes(std::vector<Type>& types)
+void TypeMatcher::getTypes(std::vector<TypeNode>& types) const
{
types.clear();
- for (TypeNode& t : d_types)
+ for (const TypeNode& t : d_types)
{
- types.push_back(t.toType());
+ types.push_back(t);
}
}
-void TypeMatcher::getMatches(std::vector<Type>& types)
+void TypeMatcher::getMatches(std::vector<TypeNode>& types) const
{
types.clear();
for (size_t i = 0, nmatch = d_match.size(); i < nmatch; i++)
{
if (d_match[i].isNull())
{
- types.push_back(d_types[i].toType());
+ types.push_back(d_types[i]);
}
else
{
- types.push_back(d_match[i].toType());
+ types.push_back(d_match[i]);
}
}
}
bool doMatching(TypeNode pattern, TypeNode tn);
/** Get the parameter types that this class matched on */
- void getTypes(std::vector<Type>& types);
+ void getTypes(std::vector<TypeNode>& types) const;
/**
* Get the match for the parameter types based on the last call to doMatching.
*/
- void getMatches(std::vector<Type>& types);
+ void getMatches(std::vector<TypeNode>& types) const;
private:
/** The parameter types */
return true;
}
+TypeNode TypeNode::instantiateParametricDatatype(
+ const std::vector<TypeNode>& params) const
+{
+ AssertArgument(getKind() == kind::PARAMETRIC_DATATYPE, *this);
+ AssertArgument(params.size() == getNumChildren() - 1, *this);
+ NodeManager* nm = NodeManager::currentNM();
+ TypeNode cons = nm->mkTypeConst((*this)[0].getConst<DatatypeIndexConstant>());
+ std::vector<TypeNode> paramsNodes;
+ paramsNodes.push_back(cons);
+ for (const TypeNode& t : params)
+ {
+ paramsNodes.push_back(t);
+ }
+ return nm->mkTypeNode(kind::PARAMETRIC_DATATYPE, paramsNodes);
+}
+
/** Is this an instantiated datatype parameter */
bool TypeNode::isParameterInstantiatedDatatype(unsigned n) const {
AssertArgument(getKind() == kind::PARAMETRIC_DATATYPE, *this);
return ss.str();
}
-
}/* CVC4 namespace */
/** Get the return type (for constructor types) */
TypeNode getConstructorRangeType() const;
+ /** Get the domain type (for selector types) */
+ TypeNode getSelectorDomainType() const;
+
+ /** Get the return type (for selector types) */
+ TypeNode getSelectorRangeType() const;
+
/** Get the element type (for set types) */
TypeNode getSetElementType() const;
/** Is this a fully instantiated datatype type */
bool isInstantiatedDatatype() const;
+ /**
+ * Get instantiated datatype type. The type on which this method is called
+ * should be a parametric datatype whose parameter list is the same list as
+ * argument params. This constructs the instantiated version of this
+ * parametric datatype, e.g. passing (par (A) (List A)), { Int } ) to this
+ * method returns (List Int).
+ */
+ TypeNode instantiateParametricDatatype(
+ const std::vector<TypeNode>& params) const;
+
/** Is this an instantiated datatype parameter */
bool isParameterInstantiatedDatatype(unsigned n) const;
return (*this)[getNumChildren()-1];
}
+inline TypeNode TypeNode::getSelectorDomainType() const
+{
+ Assert(isSelector());
+ return (*this)[0];
+}
+
+inline TypeNode TypeNode::getSelectorRangeType() const
+{
+ Assert(isSelector());
+ return (*this)[1];
+}
+
inline bool TypeNode::isSet() const {
return getKind() == kind::SET_TYPE;
}
n, "matching failed for parameterized constructor");
}
}
- std::vector<Type> instTypes;
+ std::vector<TypeNode> instTypes;
m.getMatches(instTypes);
- TypeNode range = TypeNode::fromType(dt.instantiate(instTypes));
+ TypeNode range = t.instantiateParametricDatatype(instTypes);
Debug("typecheck-idt") << "Return " << range << std::endl;
return range;
} else {
n,
"matching failed for selector argument of parameterized datatype");
}
- std::vector<Type> types, matches;
+ std::vector<TypeNode> types, matches;
m.getTypes(types);
m.getMatches(matches);
- Type range = selType[1].toType();
- range = range.substitute(types, matches);
+ TypeNode range = selType[1];
+ range = range.substitute(
+ types.begin(), types.end(), matches.begin(), matches.end());
Debug("typecheck-idt") << "Return " << range << std::endl;
- return TypeNode::fromType(range);
+ return range;
} else {
if (check) {
Debug("typecheck-idt") << "typecheck sel: " << n << std::endl;