Debug("sort") << "instance is " << instantiation << endl;
return instantiation;
- }else if( p.second.isDatatype() ){
- Assert( DatatypeType( p.second ).isParametric() );
+ } else if(p.second.isDatatype()) {
+ Assert( DatatypeType(p.second).isParametric() );
return DatatypeType(p.second).instantiate(params);
- }else {
+ } else {
if(Debug.isOn("sort")) {
Debug("sort") << "instantiating using a sort substitution" << endl;
Debug("sort") << "have formals [";
}
}
-size_t DeclarationScope::lookupArity( const std::string& name ){
+size_t DeclarationScope::lookupArity(const std::string& name) {
pair<vector<Type>, Type> p = (*d_typeMap->find(name)).second;
return p.first.size();
}
/**
* Lookup the arity of a bound parameterized type.
*/
- size_t lookupArity( const std::string& name );
+ size_t lookupArity(const std::string& name);
/**
* Pop a scope level. Deletes all bindings since the last call to
i != i_end;
++i) {
TypeNode* typeNode;
- if( (*i).getNumParameters()==0 ){
+ if( (*i).getNumParameters() == 0 ) {
typeNode = new TypeNode(d_nodeManager->mkTypeConst(*i));
- }else{
+ } else {
TypeNode cons = d_nodeManager->mkTypeConst(*i);
std::vector< TypeNode > params;
params.push_back( cons );
- for( unsigned int ip=0; ip<(*i).getNumParameters(); ip++ ){
+ for( unsigned int ip = 0; ip < (*i).getNumParameters(); ++ip ) {
params.push_back( TypeNode::fromType( (*i).getParameter( ip ) ) );
}
- typeNode = new TypeNode( d_nodeManager->mkTypeNode( kind::PARAMETRIC_DATATYPE, params ) );
+
+ typeNode = new TypeNode(d_nodeManager->mkTypeNode(kind::PARAMETRIC_DATATYPE, params));
}
Type type(d_nodeManager, typeNode);
DatatypeType dtt(type);
i != i_end;
++i) {
std::string name;
- if( (*i).isSort() ){
+ if( (*i).isSort() ) {
name = SortType(*i).getName();
- }else{
+ } else {
Assert( (*i).isSortConstructor() );
name = SortConstructorType(*i).getName();
}
// unresolved SortType used as a placeholder in complex types)
// with "(*resolver).second" (the DatatypeType we created in the
// first step, above).
- if( (*i).isSort() ){
+ if( (*i).isSort() ) {
placeholders.push_back(*i);
replacements.push_back( (*resolver).second );
- }else{
+ } else {
Assert( (*i).isSortConstructor() );
paramTypes.push_back( SortConstructorType(*i) );
paramReplacements.push_back( (*resolver).second );
return DatatypeType(*this);
}
-/** Is this the Datatype type? */
+/** Is this a datatype type? */
bool Type::isDatatype() const {
NodeManagerScope nms(d_nodeManager);
return d_typeNode->isDatatype() || d_typeNode->isParametricDatatype();
return d_typeNode->getAttribute(expr::VarNameAttr());
}
-bool SortType::isParameterized() const
-{
+bool SortType::isParameterized() const {
return false;
}
/** Get the parameter types */
-std::vector<Type> SortType::getParamTypes() const
-{
+std::vector<Type> SortType::getParamTypes() const {
vector<Type> params;
return params;
}
}
const Datatype& DatatypeType::getDatatype() const {
- if( d_typeNode->isParametricDatatype() ){
- Assert( (*d_typeNode)[0].getKind()==kind::DATATYPE_TYPE );
+ if( d_typeNode->isParametricDatatype() ) {
+ Assert( (*d_typeNode)[0].getKind() == kind::DATATYPE_TYPE );
const Datatype& dt = (*d_typeNode)[0].getConst<Datatype>();
return dt;
- }else{
+ } else {
return d_typeNode->getConst<Datatype>();
}
}
return d_typeNode->getNumChildren() - 1;
}
-std::vector<Type> DatatypeType::getParamTypes() const{
+std::vector<Type> DatatypeType::getParamTypes() const {
NodeManagerScope nms(d_nodeManager);
vector<Type> params;
vector<TypeNode> paramNodes = d_typeNode->getParamTypes();
vector<TypeNode>::iterator it = paramNodes.begin();
vector<TypeNode>::iterator it_end = paramNodes.end();
- for(; it != it_end; ++ it) {
+ for(; it != it_end; ++it) {
params.push_back(makeType(*it));
}
return params;
/** Get the name of the sort */
std::string getName() const;
- /** is parameterized */
+ /** Is this type parameterized? */
bool isParameterized() const;
/** Get the parameter types */
std::vector<Type> getParamTypes() const;
+
};/* class SortType */
/**
/** Get the underlying datatype */
const Datatype& getDatatype() const;
- /** is parameterized */
+ /** Is this this datatype parametric? */
bool isParametric() const;
/** Get the parameter types */
std::vector<TypeNode> TypeNode::getParamTypes() const {
vector<TypeNode> params;
- Assert( isParametricDatatype() );
+ Assert(isParametricDatatype());
for(unsigned i = 1, i_end = getNumChildren(); i < i_end; ++i) {
params.push_back((*this)[i]);
}
return getKind() == kind::DATATYPE_TYPE;
}
-/** Is this a datatype type */
+/** Is this a parametric datatype type */
bool TypeNode::isParametricDatatype() const {
return getKind() == kind::PARAMETRIC_DATATYPE;
}
std::vector<TypeNode> getArgTypes() const;
/**
- * Get the paramater types of a parameterized datatype.
+ * Get the paramater types of a parameterized datatype. Fails an
+ * assertion if this type is not a parametric datatype.
*/
std::vector<TypeNode> getParamTypes() const;
return unresolved;
}
-SortConstructorType Parser::mkUnresolvedTypeConstructor(const std::string& name,
- size_t arity)
-{
+SortConstructorType
+Parser::mkUnresolvedTypeConstructor(const std::string& name,
+ size_t arity) {
SortConstructorType unresolved = mkSortConstructor(name,arity);
d_unresolved.insert(unresolved);
return unresolved;
}
-SortConstructorType Parser::mkUnresolvedTypeConstructor(const std::string& name,
- const std::vector<Type>& params){
+
+SortConstructorType
+Parser::mkUnresolvedTypeConstructor(const std::string& name,
+ const std::vector<Type>& params) {
Debug("parser") << "newSortConstructor(P)(" << name << ", " << params.size() << ")"
<< std::endl;
SortConstructorType unresolved = d_exprManager->mkSortConstructor(name, params.size());
if(isDeclared(name, SYM_SORT)) {
throw ParserException(name + " already declared");
}
- if( t.isParametric() ){
+ if( t.isParametric() ) {
std::vector< Type > paramTypes = t.getParamTypes();
defineType(name, paramTypes, t );
- }else{
+ } else {
defineType(name, t);
}
for(Datatype::const_iterator j = dt.begin(),
SortType mkUnresolvedType(const std::string& name);
/**
- * Creates a new "unresolved type," used only during parsing.
+ * Creates a new unresolved (parameterized) type constructor of the given
+ * arity.
*/
SortConstructorType mkUnresolvedTypeConstructor(const std::string& name,
size_t arity);
+ /**
+ * Creates a new unresolved (parameterized) type constructor given the type
+ * parameters.
+ */
SortConstructorType mkUnresolvedTypeConstructor(const std::string& name,
const std::vector<Type>& params);
return RewriteResponse(REWRITE_DONE,
NodeManager::currentNM()->mkConst(result));
} else {
- //const Datatype& dt = in[0].getType().getConst<Datatype>();
const Datatype& dt = DatatypeType(in[0].getType().toType()).getDatatype();
if(dt.getNumConstructors() == 1) {
// only one constructor, so it must be
"DatatypeType(%TYPE%.toType()).getDatatype().isWellFounded()" \
"DatatypeType(%TYPE%.toType()).getDatatype().mkGroundTerm()" \
"util/datatype.h"
-
+
+parameterized APPLY_TYPE_ASCRIPTION ASCRIPTION_TYPE 1 \
+ "type ascription, for nullary, parameteric datatype constructors"
+constant ASCRIPTION_TYPE \
+ ::CVC4::AscriptionType \
+ ::CVC4::AscriptionTypeHashStrategy \
+ "util/ascription_type.h" \
+ "a type parameter for type ascription"
+
endtheory
namespace theory {
namespace datatypes {
-class Matcher
-{
+class Matcher {
private:
std::vector< TypeNode > d_types;
std::vector< TypeNode > d_match;
configuration_private.h \
configuration.cpp \
bitvector.h \
+ ascription_type.h \
datatype.h \
datatype.cpp \
gmp_util.h \
--- /dev/null
+/********************* */
+/*! \file ascription_type.h
+ ** \verbatim
+ ** Original author: mdeters
+ ** Major contributors: none
+ ** Minor contributors (to current version): none
+ ** This file is part of the CVC4 prototype.
+ ** Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
+ ** Courant Institute of Mathematical Sciences
+ ** New York University
+ ** See the file COPYING in the top-level source directory for licensing
+ ** information.\endverbatim
+ **
+ ** \brief A class representing a type ascription
+ **
+ ** A class representing a parameter for the type ascription operator.
+ **/
+
+#include "cvc4_public.h"
+
+#ifndef __CVC4__TYPE_ASCRIPTION_H
+#define __CVC4__TYPE_ASCRIPTION_H
+
+#include "expr/type.h"
+
+namespace CVC4 {
+
+/**
+ * A class used to parameterize a type ascription. For example,
+ * "nil :: list<nat>" is an expression of kind APPLY_TYPE_ASCRIPTION.
+ * The parameter is an ASCRIPTION_TYPE-kinded expression with an
+ * AscriptionType payload. (Essentially, all of this is a way to
+ * coerce a Type into the expression tree.)
+ */
+class CVC4_PUBLIC AscriptionType {
+ Type d_type;
+public:
+ AscriptionType(Type t) throw() : d_type(t) {}
+ Type getType() const throw() { return d_type; }
+ bool operator==(const AscriptionType& other) const throw() {
+ return d_type == other.d_type;
+ }
+ bool operator!=(const AscriptionType& other) const throw() {
+ return d_type != other.d_type;
+ }
+};/* class AscriptionType */
+
+/**
+ * A hash strategy for type ascription operators.
+ */
+struct CVC4_PUBLIC AscriptionTypeHashStrategy {
+ static inline size_t hash(const AscriptionType& at) {
+ return TypeHashFunction()(at.getType());
+ }
+};/* struct AscriptionTypeHashStrategy */
+
+/** An output routine for AscriptionTypes */
+inline std::ostream& operator<<(std::ostream& out, AscriptionType at) {
+ out << at.getType();
+ return out;
+}
+
+}/* CVC4 namespace */
+
+#endif /* __CVC4__TYPE_ASCRIPTION_H */
+
TypeNode t = Node::fromExpr(item).getType();
switch(t.getKind()) {
case kind::CONSTRUCTOR_TYPE:
- //return t[t.getNumChildren() - 1].getConst<Datatype>();
return DatatypeType(t[t.getNumChildren() - 1].toType()).getDatatype();
case kind::SELECTOR_TYPE:
case kind::TESTER_TYPE:
- //return t[0].getConst<Datatype>();
return DatatypeType(t[0].toType()).getDatatype();
default:
Unhandled("arg must be a datatype constructor, selector, or tester");
- }
+ }
}
size_t Datatype::indexOf(Expr item) {
const std::vector< DatatypeType >& paramReplacements)
throw(AssertionException, DatatypeResolutionException) {
- //cout << "resolve " << *this << "..." << std::endl;
AssertArgument(em != NULL, "cannot resolve a Datatype with a NULL expression manager");
CheckArgument(!d_resolved, "cannot resolve a Datatype twice");
AssertArgument(resolutions.find(d_name) != resolutions.end(),
}
d_self = self;
Assert(index == getNumConstructors());
-
- //cout << "done resolve " << *this << std::endl;
}
void Datatype::addConstructor(const Constructor& c) {
return DatatypeType(d_self);
}
-DatatypeType Datatype::getDatatypeType(const std::vector<Type>& params) const throw(AssertionException) {
+DatatypeType Datatype::getDatatypeType(const std::vector<Type>& params)
+ const throw(AssertionException) {
CheckArgument(isResolved(), *this, "Datatype must be resolved to get its DatatypeType");
Assert(!d_self.isNull() && DatatypeType(d_self).isParametric());
return DatatypeType(d_self).instantiate(params);
const std::vector< DatatypeType >& paramReplacements)
throw(AssertionException, DatatypeResolutionException) {
- //cout << "resolve " << *this << "..." << std::endl;
-
AssertArgument(em != NULL, "cannot resolve a Datatype with a NULL expression manager");
CheckArgument(!isResolved(),
"cannot resolve a Datatype constructor twice; "
if(!placeholders.empty()) {
range = range.substitute(placeholders, replacements);
}
- if(!paramTypes.empty() ){
+ if(!paramTypes.empty() ) {
range = doParametricSubstitution( range, paramTypes, paramReplacements );
}
(*i).d_selector = em->mkVar((*i).d_name, em->mkSelectorType(self, range));
for(iterator i = begin(), i_end = end(); i != i_end; ++i) {
(*i).d_constructor = d_constructor;
}
-
- //cout << "done resolve " << *this << std::endl;
}
-Type Datatype::Constructor::doParametricSubstitution( Type range,
- const std::vector< SortConstructorType >& paramTypes,
- const std::vector< DatatypeType >& paramReplacements ){
+Type Datatype::Constructor::doParametricSubstitution( Type range,
+ const std::vector< SortConstructorType >& paramTypes,
+ const std::vector< DatatypeType >& paramReplacements ) {
TypeNode typn = TypeNode::fromType( range );
if(typn.getNumChildren() == 0) {
return range;
origChildren.push_back( (*i).toType() );
children.push_back( doParametricSubstitution( (*i).toType(), paramTypes, paramReplacements ) );
}
- for( int i=0; i<(int)paramTypes.size(); i++ ){
- if( paramTypes[i].getArity()==origChildren.size() ){
+ for( int i=0; i<(int)paramTypes.size(); i++ ) {
+ if( paramTypes[i].getArity()==origChildren.size() ) {
Type tn = paramTypes[i].instantiate( origChildren );
- if( range==tn ){
+ if( range==tn ) {
return paramReplacements[i].instantiate( children );
}
}
}
NodeBuilder<> nb(typn.getKind());
- for( int i=0; i<(int)children.size(); i++ ){
+ for( int i=0; i<(int)children.size(); i++ ) {
nb << TypeNode::fromType( children[i] );
}
return nb.constructTypeNode().toType();
}
Expr Datatype::Constructor::Arg::getConstructor() const {
- CheckArgument(isResolved(), this,
+ CheckArgument(isResolved(), this,
"cannot get a associated constructor for argument of an unresolved datatype constructor");
return d_constructor;
}
-Type Datatype::Constructor::Arg::getSelectorType() const{
+Type Datatype::Constructor::Arg::getSelectorType() const {
return getSelector().getType();
}
/** Get the name of this Datatype. */
inline std::string getName() const throw();
+
/** Get the number of constructors (so far) for this Datatype. */
inline size_t getNumConstructors() const throw();
/** Get the nubmer of parameters */
inline size_t getNumParameters() const throw();
+
/** Get parameter */
inline Type getParameter( unsigned int i ) const;