}
Expr::Expr() :
- d_node(new Node()), d_em(NULL) {
+ d_node(new Node()), d_exprManager(NULL) {
}
Expr::Expr(ExprManager* em, Node* node) :
- d_node(node), d_em(em) {
+ d_node(node), d_exprManager(em) {
}
Expr::Expr(const Expr& e) :
- d_node(new Node(*e.d_node)), d_em(e.d_em) {
+ d_node(new Node(*e.d_node)), d_exprManager(e.d_exprManager) {
}
ExprManager* Expr::getExprManager() const {
- return d_em;
+ return d_exprManager;
}
Expr::~Expr() {
ExprManagerScope ems(*this);
delete d_node;
d_node = new Node(*e.d_node);
- d_em = e.d_em;
+ d_exprManager = e.d_exprManager;
}
return *this;
}
bool Expr::operator==(const Expr& e) const {
- if(d_em != e.d_em){
+ if(d_exprManager != e.d_exprManager){
return false;
}
Assert(d_node != NULL, "Unexpected NULL expression pointer!");
bool Expr::operator<(const Expr& e) const {
Assert(d_node != NULL, "Unexpected NULL expression pointer!");
Assert(e.d_node != NULL, "Unexpected NULL expression pointer!");
- if(d_em != e.d_em){
+ if(d_exprManager != e.d_exprManager){
return false;
}
return *d_node < *e.d_node;
return d_node->getNumChildren();
}
+const Type* Expr::getType() const {
+ ExprManagerScope ems(*this);
+ return d_node->getType();
+}
+
std::string Expr::toString() const {
ExprManagerScope ems(*this);
Assert(d_node != NULL, "Unexpected NULL expression pointer!");
}
BoolExpr BoolExpr::notExpr() const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- return d_em->mkExpr(NOT, *this);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ return d_exprManager->mkExpr(NOT, *this);
}
BoolExpr BoolExpr::andExpr(const BoolExpr& e) const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- Assert(d_em == e.d_em, "Different expression managers!");
- return d_em->mkExpr(AND, *this, e);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ Assert(d_exprManager == e.d_exprManager, "Different expression managers!");
+ return d_exprManager->mkExpr(AND, *this, e);
}
BoolExpr BoolExpr::orExpr(const BoolExpr& e) const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- Assert(d_em == e.d_em, "Different expression managers!");
- return d_em->mkExpr(OR, *this, e);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ Assert(d_exprManager == e.d_exprManager, "Different expression managers!");
+ return d_exprManager->mkExpr(OR, *this, e);
}
BoolExpr BoolExpr::xorExpr(const BoolExpr& e) const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- Assert(d_em == e.d_em, "Different expression managers!");
- return d_em->mkExpr(XOR, *this, e);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ Assert(d_exprManager == e.d_exprManager, "Different expression managers!");
+ return d_exprManager->mkExpr(XOR, *this, e);
}
BoolExpr BoolExpr::iffExpr(const BoolExpr& e) const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- Assert(d_em == e.d_em, "Different expression managers!");
- return d_em->mkExpr(IFF, *this, e);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ Assert(d_exprManager == e.d_exprManager, "Different expression managers!");
+ return d_exprManager->mkExpr(IFF, *this, e);
}
BoolExpr BoolExpr::impExpr(const BoolExpr& e) const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- Assert(d_em == e.d_em, "Different expression managers!");
- return d_em->mkExpr(IMPLIES, *this, e);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ Assert(d_exprManager == e.d_exprManager, "Different expression managers!");
+ return d_exprManager->mkExpr(IMPLIES, *this, e);
}
BoolExpr BoolExpr::iteExpr(const BoolExpr& then_e, const BoolExpr& else_e) const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- Assert(d_em == then_e.d_em, "Different expression managers!");
- Assert(d_em == else_e.d_em, "Different expression managers!");
- return d_em->mkExpr(ITE, *this, then_e, else_e);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ Assert(d_exprManager == then_e.d_exprManager, "Different expression managers!");
+ Assert(d_exprManager == else_e.d_exprManager, "Different expression managers!");
+ return d_exprManager->mkExpr(ITE, *this, then_e, else_e);
}
Expr BoolExpr::iteExpr(const Expr& then_e, const Expr& else_e) const {
- Assert(d_em != NULL, "Don't have an expression manager for this expression!");
- Assert(d_em == then_e.getExprManager(), "Different expression managers!");
- Assert(d_em == else_e.getExprManager(), "Different expression managers!");
- return d_em->mkExpr(ITE, *this, then_e, else_e);
+ Assert(d_exprManager != NULL, "Don't have an expression manager for this expression!");
+ Assert(d_exprManager == then_e.getExprManager(), "Different expression managers!");
+ Assert(d_exprManager == else_e.getExprManager(), "Different expression managers!");
+ return d_exprManager->mkExpr(ITE, *this, then_e, else_e);
}
void Expr::printAst(std::ostream & o, int indent) const{
*/
size_t getNumChildren() const;
+ /** Returns the type of the expression, if it has been computed.
+ * Returns NULL if the type of the expression is not known.
+ */
+ const Type* getType() const;
+
/**
* Returns the string representation of the expression.
* @return a string representation of the expression
Node* d_node;
/** The responsible expression manager */
- ExprManager* d_em;
+ ExprManager* d_exprManager;
/**
* Returns the actual internal node.
namespace CVC4 {
ExprManager::ExprManager() :
- d_nm(new NodeManager()) {
+ d_nodeManager(new NodeManager()) {
}
ExprManager::~ExprManager() {
- delete d_nm;
+ delete d_nodeManager;
}
const BooleanType* ExprManager::booleanType() {
- NodeManagerScope nms(d_nm);
+ NodeManagerScope nms(d_nodeManager);
return BooleanType::getInstance();
}
const KindType* ExprManager::kindType() {
- NodeManagerScope nms(d_nm);
+ NodeManagerScope nms(d_nodeManager);
return KindType::getInstance();
}
Expr ExprManager::mkExpr(Kind kind) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkNode(kind)));
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkNode(kind)));
}
Expr ExprManager::mkExpr(Kind kind, const Expr& child1) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkNode(kind, child1.getNode())));
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode())));
}
Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkNode(kind, child1.getNode(),
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(),
child2.getNode())));
}
Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2,
const Expr& child3) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkNode(kind, child1.getNode(),
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(),
child2.getNode(), child3.getNode())));
}
Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2,
const Expr& child3, const Expr& child4) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkNode(kind, child1.getNode(),
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(),
child2.getNode(), child3.getNode(),
child4.getNode())));
}
Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2,
const Expr& child3, const Expr& child4,
const Expr& child5) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkNode(kind, child1.getNode(),
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(),
child2.getNode(), child3.getNode(),
child5.getNode())));
}
Expr ExprManager::mkExpr(Kind kind, const vector<Expr>& children) {
- NodeManagerScope nms(d_nm);
+ NodeManagerScope nms(d_nodeManager);
vector<Node> nodes;
vector<Expr>::const_iterator it = children.begin();
nodes.push_back(it->getNode());
++it;
}
- return Expr(this, new Node(d_nm->mkNode(kind, nodes)));
+ return Expr(this, new Node(d_nodeManager->mkNode(kind, nodes)));
}
/** Make a function type from domain to range. */
const FunctionType*
ExprManager::mkFunctionType(const Type* domain,
const Type* range) {
- NodeManagerScope nms(d_nm);
+ NodeManagerScope nms(d_nodeManager);
return FunctionType::getInstance(this, domain, range);
}
const FunctionType*
ExprManager::mkFunctionType(const std::vector<const Type*>& argTypes,
const Type* range) {
- NodeManagerScope nms(d_nm);
+ NodeManagerScope nms(d_nodeManager);
return FunctionType::getInstance(this, argTypes, range);
}
const Type* ExprManager::mkSort(std::string name) {
// FIXME: Sorts should be unique per-ExprManager
- NodeManagerScope nms(d_nm);
+ NodeManagerScope nms(d_nodeManager);
return new SortType(this, name);
}
Expr ExprManager::mkVar(const Type* type, string name) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkVar(type, name)));
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkVar(type, name)));
}
Expr ExprManager::mkVar(const Type* type) {
- NodeManagerScope nms(d_nm);
- return Expr(this, new Node(d_nm->mkVar(type)));
+ NodeManagerScope nms(d_nodeManager);
+ return Expr(this, new Node(d_nodeManager->mkVar(type)));
}
NodeManager* ExprManager::getNodeManager() const {
- return d_nm;
+ return d_nodeManager;
}
} // End namespace CVC4
private:
/** The internal node manager */
- NodeManager* d_nm;
+ NodeManager* d_nodeManager;
/**
* Returns the internal node manager. This should only be used by internal
return NodeManager::currentNM()->mkNode(XOR, *this, right);
}
+const Type* Node::getType() const {
+ Assert( NodeManager::currentNM() != NULL,
+ "There is no current CVC4::NodeManager associated to this thread.\n"
+ "Perhaps a public-facing function is missing a NodeManagerScope ?" );
+ return NodeManager::currentNM()->getType(*this);
+}
+
static void indent(ostream & o, int indent) {
for(int i=0; i < indent; i++) {
o << ' ';
inline std::ostream& operator<<(std::ostream&, const Node&);
class NodeManager;
+class Type;
namespace expr {
class NodeValue;
inline Kind getKind() const;
inline size_t getNumChildren() const;
+ const Type* getType() const;
static Node null();
}
Node NodeManager::mkVar(const Type* type, string name) {
- Node n = NodeBuilder<>(this, VARIABLE);
- n.setAttribute(TypeAttr(), type);
+ Node n = mkVar(type);
n.setAttribute(VarNameAttr(), name);
return n;
}
**/
/* circular dependency; force node.h first */
+#include "expr/attribute.h"
#include "expr/node.h"
#ifndef __CVC4__NODE_MANAGER_H
typedef __gnu_cxx::hash_set<NodeValue*, __gnu_cxx::hash<NodeValue*>, NodeValue::NodeValueEq> NodeValueSet;
NodeValueSet d_nodeValueSet;
- expr::AttributeManager d_am;
+ expr::AttributeManager d_attrManager;
NodeValue* poolLookup(NodeValue* nv) const;
void poolInsert(NodeValue* nv);
public:
- NodeManager() : d_am(this) {
+ NodeManager() : d_attrManager(this) {
poolInsert( &NodeValue::s_null );
}
inline void setAttribute(const Node& n,
const AttrKind&,
const typename AttrKind::value_type& value);
+
+ inline const Type* getType(const Node& n);
};
class NodeManagerScope {
template <class AttrKind>
inline typename AttrKind::value_type NodeManager::getAttribute(const Node& n,
const AttrKind&) const {
- return d_am.getAttribute(n, AttrKind());
+ return d_attrManager.getAttribute(n, AttrKind());
}
template <class AttrKind>
inline bool NodeManager::hasAttribute(const Node& n,
const AttrKind&,
typename AttrKind::value_type* ret) const {
- return d_am.hasAttribute(n, AttrKind(), ret);
+ return d_attrManager.hasAttribute(n, AttrKind(), ret);
}
template <class AttrKind>
inline void NodeManager::setAttribute(const Node& n,
const AttrKind&,
const typename AttrKind::value_type& value) {
- d_am.setAttribute(n, AttrKind(), value);
+ d_attrManager.setAttribute(n, AttrKind(), value);
+}
+
+inline const Type* NodeManager::getType(const Node& n) {
+ return getAttribute(n,CVC4::expr::TypeAttr());
}
}/* CVC4 namespace */
** See the file COPYING in the top-level source directory for licensing
** information.
**
- ** [[ Add file-specific comments here ]]
+ ** A super-class for ANTLR-generated input language parsers
**/
/*
AntlrParser::getType(std::string var_name,
SymbolType type) {
Assert( isDeclared(var_name, type) );
- const Type* t = d_varTypeTable.getObject(var_name);
+ const Type* t = getSymbol(var_name,type).getType();
return t;
}
Assert( !isDeclared(name) ) ;
Expr expr = d_exprManager->mkVar(type, name);
d_varSymbolTable.bindName(name, expr);
- d_varTypeTable.bindName(name,type);
Assert( isDeclared(name) ) ;
return expr;
}
/** The symbol table lookup */
SymbolTable<Expr> d_varSymbolTable;
- /** A temporary hack: keep all the variable types in their own special
- table. These should actually be Expr attributes. */
- SymbolTable<const Type*> d_varTypeTable;
-
/** The sort table */
SymbolTable<const Type*> d_sortTable;
}
void testAttributes() {
- AttributeManager& am = d_nm->d_am;
+ AttributeManager& am = d_nm->d_attrManager;
//Debug.on("boolattr");