Removing references to ExprManager from Type, moving Type creation into NodeManager
delete d_nodeManager;
}
-const BooleanType* ExprManager::booleanType() {
+const BooleanType* ExprManager::booleanType() const {
NodeManagerScope nms(d_nodeManager);
- return BooleanType::getInstance();
+ d_nodeManager->booleanType();
}
-const KindType* ExprManager::kindType() {
+const KindType* ExprManager::kindType() const {
NodeManagerScope nms(d_nodeManager);
- return KindType::getInstance();
+ d_nodeManager->kindType();
}
Expr ExprManager::mkExpr(Kind kind) {
ExprManager::mkFunctionType(const Type* domain,
const Type* range) {
NodeManagerScope nms(d_nodeManager);
- return FunctionType::getInstance(this, domain, range);
+ return d_nodeManager->mkFunctionType(domain,range);
}
/** Make a function type with input types from argTypes. */
ExprManager::mkFunctionType(const std::vector<const Type*>& argTypes,
const Type* range) {
NodeManagerScope nms(d_nodeManager);
- return FunctionType::getInstance(this, argTypes, range);
+ return d_nodeManager->mkFunctionType(argTypes,range);
}
const Type* ExprManager::mkSort(const std::string& name) {
- // FIXME: Sorts should be unique per-ExprManager
NodeManagerScope nms(d_nodeManager);
- return new SortType(this, name);
+ return d_nodeManager->mkSort(name);
}
Expr ExprManager::mkVar(const Type* type, const std::string& name) {
*/
~ExprManager();
- /** Get the type for booleans. */
- const BooleanType* booleanType();
+ /** Get the type for booleans */
+ const BooleanType* booleanType() const;
+
/** Get the type for sorts. */
- const KindType* kindType();
+ const KindType* kindType() const;
/**
* Make a unary expression of a given kind (TRUE, FALSE,...).
UNDEFINED_KIND = -1,
/** Null Kind */
NULL_EXPR,
+ /** The kind of nodes representing built-in operators */
+ BUILTIN,
return d_nv->getId();
}
+ /**
+ * Returns a node representing the operator of this expression.
+ * If this is an APPLY, then the operator will be a functional term.
+ * Otherwise, it will be a node with kind BUILTIN
+ */
+ inline NodeTemplate<true> getOperator() const {
+ switch(getKind()) {
+ case kind::APPLY:
+ /* The operator is the first child. */
+ return NodeTemplate<true> (d_nv->d_children[0]);
+
+ case kind::EQUAL:
+ case kind::ITE:
+ case kind::TUPLE:
+ case kind::NOT:
+ case kind::AND:
+ case kind::IFF:
+ case kind::IMPLIES:
+ case kind::OR:
+ case kind::XOR:
+ case kind::PLUS:
+ /* Should return a BUILTIN node. */
+ Unimplemented("getOperator() on non-APPLY kind: " + getKind());
+ break;
+
+ case kind::FALSE:
+ case kind::TRUE:
+ case kind::SKOLEM:
+ case kind::VARIABLE:
+ IllegalArgument(*this,"getOperator() called on kind with no operator");
+ break;
+
+ default:
+ Unhandled(getKind());
+ }
+
+ NodeTemplate<true> n; // NULL Node for default return
+ return n;
+ }
+
+ /** Returns true if the node has an operator (i.e., it's not a variable or a constant). */
+ inline bool hasOperator() const {
+ switch(getKind()) {
+ case kind::APPLY:
+ case kind::EQUAL:
+ case kind::ITE:
+ case kind::TUPLE:
+ case kind::FALSE:
+ case kind::TRUE:
+ case kind::NOT:
+ case kind::AND:
+ case kind::IFF:
+ case kind::IMPLIES:
+ case kind::OR:
+ case kind::XOR:
+ case kind::PLUS:
+ return true;
+
+ case kind::SKOLEM:
+ case kind::VARIABLE:
+ return false;
+
+ default:
+ Unhandled(getKind());
+ }
+
+ }
+
/**
* Returns the type of this node.
* @return the type
return *find;
}
}
-
}/* CVC4 namespace */
const AttrKind&,
const typename AttrKind::value_type& value);
+
+ /** Get the type for booleans. */
+ inline const BooleanType* booleanType() const {
+ return BooleanType::getInstance();
+ }
+
+ /** Get the type for sorts. */
+ inline const KindType* kindType() const {
+ return KindType::getInstance();
+ }
+
+ /** Make a function type from domain to range. */
+ inline const FunctionType*
+ mkFunctionType(const Type* domain, const Type* range);
+
+ /** Make a function type with input types from argTypes. */
+ inline const FunctionType*
+ mkFunctionType(const std::vector<const Type*>& argTypes, const Type* range);
+
+ /** Make a new sort with the given name. */
+ inline const Type* mkSort(const std::string& name);
+
inline const Type* getType(TNode n);
};
d_attrManager.setAttribute(n, AttrKind(), value);
}
+/** Make a function type from domain to range.
+ * TODO: Function types should be unique for this manager. */
+const FunctionType*
+NodeManager::mkFunctionType(const Type* domain,
+ const Type* range) {
+ std::vector<const Type*> argTypes;
+ argTypes.push_back(domain);
+ return new FunctionType(argTypes, range);
+}
+
+/** Make a function type with input types from argTypes.
+ * TODO: Function types should be unique for this manager. */
+const FunctionType*
+NodeManager::mkFunctionType(const std::vector<const Type*>& argTypes,
+ const Type* range) {
+ Assert( argTypes.size() > 0 );
+ return new FunctionType(argTypes, range);
+}
+
+const Type*
+NodeManager::mkSort(const std::string& name) {
+ return new SortType(name);
+}
inline const Type* NodeManager::getType(TNode n) {
return getAttribute(n, CVC4::expr::TypeAttr());
}
** Implementation of expression types
**/
-#include "expr/expr_manager.h"
+#include "expr/node_manager.h"
#include "expr/type.h"
#include "util/Assert.h"
#include <string>
return out;
}
-Type::Type(ExprManager* exprManager) :
- d_exprManager(exprManager), d_name(std::string("<undefined>")) {
-}
-
-Type::Type(ExprManager* exprManager, std::string name) :
- d_exprManager(exprManager), d_name(name) {
+Type::Type() :
+ d_name(std::string("<undefined>")) {
}
Type::Type(std::string name) :
d_name(name) {
}
-bool Type::operator==(const Type& t) const {
- return d_exprManager == t.d_exprManager && d_name == t.d_name;
-}
-
-bool Type::operator!=(const Type& t) const {
- return !(*this == t);
-}
-
-ExprManager* Type::getExprManager() const {
- return d_exprManager;
-}
-
std::string Type::getName() const {
return d_name;
}
return true;
}
-FunctionType::FunctionType(ExprManager* exprManager,
- const std::vector<const Type*>& argTypes,
+FunctionType::FunctionType(const std::vector<const Type*>& argTypes,
const Type* range)
- : Type(exprManager), d_argTypes(argTypes), d_rangeType(range) {
+ : d_argTypes(argTypes),
+ d_rangeType(range) {
Assert( argTypes.size() > 0 );
}
FunctionType::~FunctionType() {
}
-FunctionType*
-FunctionType::getInstance(ExprManager* exprManager,
- const Type* domain,
- const Type* range) {
- std::vector<const Type*> argTypes;
- argTypes.push_back(domain);
- return getInstance(exprManager,argTypes,range);
-}
-
- //FIXME: should be singleton
-FunctionType*
-FunctionType::getInstance(ExprManager* exprManager,
- const std::vector<const Type*>& argTypes,
- const Type* range) {
- Assert( argTypes.size() > 0 );
- return new FunctionType(exprManager,argTypes,range);
-}
-
-
const std::vector<const Type*> FunctionType::getArgTypes() const {
return d_argTypes;
}
}
bool FunctionType::isPredicate() const {
- return d_rangeType == d_exprManager->booleanType();
+ return d_rangeType->isBoolean();
}
void FunctionType::toStream(std::ostream& out) const {
return &s_instance;
}
-SortType::SortType(ExprManager* exprManager,std::string name)
- : Type(exprManager,name) {
+SortType::SortType(std::string name)
+ : Type(name) {
}
SortType::~SortType() {
namespace CVC4 {
-class ExprManager;
+class NodeManager;
/**
* Class encapsulating CVC4 expression types.
/** Comparison for disequality */
bool operator!=(const Type& e) const;
- /** Get the ExprManager associated with this type. May be NULL for
- singleton types. */
- ExprManager* getExprManager() const;
-
/** Get the name of this type. May be empty for composite types. */
std::string getName() const;
}
protected:
- /** Create a type associated with exprManager. */
- Type(ExprManager* const exprManager);
-
- /** Create a type associated with exprManager with the given name. */
- Type(ExprManager* const exprManager, std::string name);
+ /** Create an un-named type. */
+ Type();
/** Create a type with the given name. */
Type(std::string name);
/** Destructor */
virtual ~Type() { };
- /** The associated ExprManager */
- ExprManager* d_exprManager;
-
/** The name of the type (may be empty). */
std::string d_name;
};
class BooleanType : public Type {
public:
- static BooleanType* getInstance();
-
/** Is this the boolean type? (Returns true.) */
bool isBoolean() const;
+ static BooleanType* getInstance();
private:
- /** Create a type associated with exprManager. */
+
+ /** Create a type associated with nodeManager. */
BooleanType();
/** Do-nothing private copy constructor operator, to prevent
class FunctionType : public Type {
public:
- static FunctionType* getInstance(ExprManager* exprManager,
- const Type* domain,
- const Type* range);
-
- static FunctionType* getInstance(ExprManager* exprManager,
- const std::vector<const Type*>& argTypes,
- const Type* range);
-
-
/** Retrieve the argument types. The vector will be non-empty. */
const std::vector<const Type*> getArgTypes() const;
private:
- /** Construct a function type associated with exprManager,
- given a vector of argument types and the range type.
-
- @param argTypes a non-empty vector of input types
- @param range the result type
- */
- FunctionType(ExprManager* exprManager,
- const std::vector<const Type*>& argTypes,
+ /** Construct a function type associated with nodeManager,
+ * given a vector of argument types and the range type.
+
+ * @param argTypes a non-empty vector of input types
+ * @param range the result type
+ */
+ FunctionType(const std::vector<const Type*>& argTypes,
const Type* range);
/** Destructor */
/** The result type. */
const Type* d_rangeType;
+ friend class NodeManager;
};
/** Class encapsulating the kind type (the type of types).
- TODO: Should be a singleton per-ExprManager.
*/
class KindType : public Type {
public:
-
- /** Create a type associated with exprManager. */
- static KindType* getInstance();
-
/** Is this the kind type? (Returns true.) */
bool isKind() const;
+ /** Get an instance of the kind type. */
+ static KindType* getInstance();
+
private:
- /** Create a type associated with exprManager. */
KindType();
/* Do-nothing private copy constructor, to prevent
};
/** Class encapsulating a user-defined sort.
- TODO: Should sort be uniquely named per-exprManager and not conflict
+ TODO: Should sort be uniquely named per-nodeManager and not conflict
with any builtins? */
class SortType : public Type {
public:
-
- /** Create a sort associated with exprManager with the given name. */
- SortType(ExprManager* exprManager, std::string name);
-
/** Destructor */
~SortType();
+
+private:
+ /** Create a sort with the given name. */
+ SortType(std::string name);
+
+ friend class NodeManager;
};
/**
//Used in some of the tests
#include <vector>
+#include "expr/expr_manager.h"
#include "expr/node_value.h"
#include "expr/node_builder.h"
#include "expr/node_manager.h"
class NodeBlack : public CxxTest::TestSuite {
private:
+ NodeManager *d_nodeManager;
NodeManagerScope *d_scope;
- NodeManager *d_nm;
public:
void setUp() {
- d_nm = new NodeManager();
- d_scope = new NodeManagerScope(d_nm);
+ d_nodeManager = new NodeManager();
+ d_scope = new NodeManagerScope(d_nodeManager);
}
void tearDown() {
delete d_scope;
- delete d_nm;
+ delete d_nodeManager;
}
bool imp(bool a, bool b) const {
void testOperatorEquals() {
Node a, b, c;
- b = d_nm->mkVar();
+ b = d_nodeManager->mkVar();
a = b;
c = a;
- Node d = d_nm->mkVar();
+ Node d = d_nodeManager->mkVar();
TS_ASSERT(a==a);
TS_ASSERT(a==b);
Node a, b, c;
- b = d_nm->mkVar();
+ b = d_nodeManager->mkVar();
a = b;
c = a;
- Node d = d_nm->mkVar();
+ Node d = d_nodeManager->mkVar();
/*structed assuming operator == works */
TS_ASSERT(iff(a!=a,!(a==a)));
#endif /* CVC4_ASSERTIONS */
//Basic access check
- Node tb = d_nm->mkNode(TRUE);
- Node eb = d_nm->mkNode(FALSE);
- Node cnd = d_nm->mkNode(XOR, tb, eb);
+ Node tb = d_nodeManager->mkNode(TRUE);
+ Node eb = d_nodeManager->mkNode(FALSE);
+ Node cnd = d_nodeManager->mkNode(XOR, tb, eb);
Node ite = cnd.iteNode(tb,eb);
TS_ASSERT(tb == cnd[0]);
/*tests: Node& operator=(const Node&); */
void testOperatorAssign() {
Node a, b;
- Node c = d_nm->mkNode(NOT);
+ Node c = d_nodeManager->mkNode(NOT);
b = c;
TS_ASSERT(b==c);
*/
- Node a = d_nm->mkVar();
- Node b = d_nm->mkVar();
+ Node a = d_nodeManager->mkVar();
+ Node b = d_nodeManager->mkVar();
TS_ASSERT(a<b || b<a);
TS_ASSERT(!(a<b && b<a));
- Node c = d_nm->mkNode(NULL_EXPR);
- Node d = d_nm->mkNode(NULL_EXPR);
+ Node c = d_nodeManager->mkNode(NULL_EXPR);
+ Node d = d_nodeManager->mkNode(NULL_EXPR);
TS_ASSERT(!(c<d));
TS_ASSERT(!(d<c));
*/
//Simple test of descending descendant property
- Node child = d_nm->mkNode(TRUE);
- Node parent = d_nm->mkNode(NOT, child);
+ Node child = d_nodeManager->mkNode(TRUE);
+ Node parent = d_nodeManager->mkNode(NOT, child);
TS_ASSERT(child < parent);
//Slightly less simple test of DD property.
std::vector<Node> chain;
int N = 500;
- Node curr = d_nm->mkNode(NULL_EXPR);
+ Node curr = d_nodeManager->mkNode(NULL_EXPR);
for(int i=0;i<N;i++) {
chain.push_back(curr);
- curr = d_nm->mkNode(AND,curr);
+ curr = d_nodeManager->mkNode(AND,curr);
}
for(int i=0;i<N;i++) {
void testHash() {
/* Not sure how to test this except survial... */
- Node a = d_nm->mkNode(ITE);
- Node b = d_nm->mkNode(ITE);
+ Node a = d_nodeManager->mkNode(ITE);
+ Node b = d_nodeManager->mkNode(ITE);
TS_ASSERT(b.hash() == a.hash());
}
void testEqNode() {
/*Node eqNode(const Node& right) const;*/
- Node left = d_nm->mkNode(TRUE);
- Node right = d_nm->mkNode(NOT,(d_nm->mkNode(FALSE)));
+ Node left = d_nodeManager->mkNode(TRUE);
+ Node right = d_nodeManager->mkNode(NOT,(d_nodeManager->mkNode(FALSE)));
Node eq = left.eqNode(right);
void testNotNode() {
/* Node notNode() const;*/
- Node child = d_nm->mkNode(TRUE);
+ Node child = d_nodeManager->mkNode(TRUE);
Node parent = child.notNode();
TS_ASSERT(NOT == parent.getKind());
void testAndNode() {
/*Node andNode(const Node& right) const;*/
- Node left = d_nm->mkNode(TRUE);
- Node right = d_nm->mkNode(NOT,(d_nm->mkNode(FALSE)));
+ Node left = d_nodeManager->mkNode(TRUE);
+ Node right = d_nodeManager->mkNode(NOT,(d_nodeManager->mkNode(FALSE)));
Node eq = left.andNode(right);
void testOrNode() {
/*Node orNode(const Node& right) const;*/
- Node left = d_nm->mkNode(TRUE);
- Node right = d_nm->mkNode(NOT,(d_nm->mkNode(FALSE)));
+ Node left = d_nodeManager->mkNode(TRUE);
+ Node right = d_nodeManager->mkNode(NOT,(d_nodeManager->mkNode(FALSE)));
Node eq = left.orNode(right);
void testIteNode() {
/*Node iteNode(const Node& thenpart, const Node& elsepart) const;*/
- Node cnd = d_nm->mkNode(PLUS);
- Node thenBranch = d_nm->mkNode(TRUE);
- Node elseBranch = d_nm->mkNode(NOT,(d_nm->mkNode(FALSE)));
+ Node cnd = d_nodeManager->mkNode(PLUS);
+ Node thenBranch = d_nodeManager->mkNode(TRUE);
+ Node elseBranch = d_nodeManager->mkNode(NOT,(d_nodeManager->mkNode(FALSE)));
Node ite = cnd.iteNode(thenBranch,elseBranch);
void testIffNode() {
/* Node iffNode(const Node& right) const; */
- Node left = d_nm->mkNode(TRUE);
- Node right = d_nm->mkNode(NOT,(d_nm->mkNode(FALSE)));
+ Node left = d_nodeManager->mkNode(TRUE);
+ Node right = d_nodeManager->mkNode(NOT,(d_nodeManager->mkNode(FALSE)));
Node eq = left.iffNode(right);
void testImpNode() {
/* Node impNode(const Node& right) const; */
- Node left = d_nm->mkNode(TRUE);
- Node right = d_nm->mkNode(NOT,(d_nm->mkNode(FALSE)));
+ Node left = d_nodeManager->mkNode(TRUE);
+ Node right = d_nodeManager->mkNode(NOT,(d_nodeManager->mkNode(FALSE)));
Node eq = left.impNode(right);
void testXorNode() {
/*Node xorNode(const Node& right) const;*/
- Node left = d_nm->mkNode(TRUE);
- Node right = d_nm->mkNode(NOT,(d_nm->mkNode(FALSE)));
+ Node left = d_nodeManager->mkNode(TRUE);
+ Node right = d_nodeManager->mkNode(NOT,(d_nodeManager->mkNode(FALSE)));
Node eq = left.xorNode(right);
}
void testKindSingleton(Kind k) {
- Node n = d_nm->mkNode(k);
+ Node n = d_nodeManager->mkNode(k);
TS_ASSERT(k == n.getKind());
}
testKindSingleton(ITE);
testKindSingleton(SKOLEM);
}
+
+
+ void testGetOperator() {
+ const Type* sort = d_nodeManager->mkSort("T");
+ const Type* booleanType = d_nodeManager->booleanType();
+ const Type* predType = d_nodeManager->mkFunctionType(sort,booleanType);
+
+ Node f = d_nodeManager->mkVar(predType);
+ Node a = d_nodeManager->mkVar(booleanType);
+ Node fa = d_nodeManager->mkNode(kind::APPLY,f,a);
+
+ TS_ASSERT( fa.hasOperator() );
+ TS_ASSERT( !f.hasOperator() );
+ TS_ASSERT( !a.hasOperator() );
+
+ TS_ASSERT( f == fa.getOperator() );
+ TS_ASSERT_THROWS( f.getOperator(), AssertionException );
+ TS_ASSERT_THROWS( a.getOperator(), AssertionException );
+ }
void testNaryExpForSize(Kind k, int N){
NodeBuilder<> nbz(k);