From: Dejan Jovanović Date: Sun, 28 Feb 2010 00:57:25 +0000 (+0000) Subject: * context.h - Changed cdlist::push_back to use a new copy constructor instead of... X-Git-Tag: cvc5-1.0.0~9211 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5a9b381769557608fa0183a166a26b73305703ef;p=cvc5.git * context.h - Changed cdlist::push_back to use a new copy constructor instead of the assignment operator. This is important as Nodes, for example, check that d_nv != NULL in the assignemnt operator. * node.h - Simplified the constructors, apparently it's ok to write ~ref_count in the template declaration. All the constructed nodes are now the ref-counted ones, i.e. eqNode() will return a ref-counted node. --- diff --git a/src/context/context.h b/src/context/context.h index 6462cccaa..6a35945b7 100644 --- a/src/context/context.h +++ b/src/context/context.h @@ -707,7 +707,8 @@ public: void push_back(const T& data) { makeCurrent(); if (d_size == d_sizeAlloc) grow(); - d_list[d_size++] = data; + ::new((void*)(d_list + d_size)) T(data); + ++ d_size; } /** diff --git a/src/expr/node.h b/src/expr/node.h index fe2016747..5655d7e3a 100644 --- a/src/expr/node.h +++ b/src/expr/node.h @@ -119,8 +119,7 @@ template * not. * @param node the node to make copy of */ - template - NodeTemplate(const NodeTemplate& node); + NodeTemplate(const NodeTemplate& node); /** * Copy constructor. Note that GCC does NOT recognize an instantiation of @@ -128,7 +127,7 @@ template * provide an explicit one here. * @param node the node to make copy of */ - NodeTemplate(const NodeTemplate& node); + NodeTemplate(const NodeTemplate& node); /** * Assignment operator for nodes, copies the relevant information from node @@ -136,8 +135,15 @@ template * @param node the node to copy * @return reference to this node */ - template - NodeTemplate& operator=(const NodeTemplate& node); + NodeTemplate& operator=(const NodeTemplate& node); + + /** + * Assignment operator for nodes, copies the relevant information from node + * to this node. + * @param node the node to copy + * @return reference to this node + */ + NodeTemplate& operator=(const NodeTemplate& node); /** * Destructor. If ref_count is true it will decrement the reference count @@ -418,16 +424,16 @@ template */ void printAst(std::ostream & o, int indent = 0) const; - NodeTemplate eqNode(const NodeTemplate& right) const; + NodeTemplate eqNode(const NodeTemplate& right) const; - NodeTemplate notNode() const; - NodeTemplate andNode(const NodeTemplate& right) const; - NodeTemplate orNode(const NodeTemplate& right) const; - NodeTemplate iteNode(const NodeTemplate& thenpart, + NodeTemplate notNode() const; + NodeTemplate andNode(const NodeTemplate& right) const; + NodeTemplate orNode(const NodeTemplate& right) const; + NodeTemplate iteNode(const NodeTemplate& thenpart, const NodeTemplate& elsepart) const; - NodeTemplate iffNode(const NodeTemplate& right) const; - NodeTemplate impNode(const NodeTemplate& right) const; - NodeTemplate xorNode(const NodeTemplate& right) const; + NodeTemplate iffNode(const NodeTemplate& right) const; + NodeTemplate impNode(const NodeTemplate& right) const; + NodeTemplate xorNode(const NodeTemplate& right) const; private: @@ -555,16 +561,15 @@ template // the code for these two "conversion/copy constructors" is identical, but // apparently we need both. see comment in the class. template - template - NodeTemplate::NodeTemplate(const NodeTemplate& e) { - Assert(e.d_nv != NULL, "Expecting a non-NULL expression value!"); - d_nv = e.d_nv; - if(ref_count) - d_nv->inc(); - } + NodeTemplate::NodeTemplate(const NodeTemplate& e) { + Assert(e.d_nv != NULL, "Expecting a non-NULL expression value!"); + d_nv = e.d_nv; + if(ref_count) + d_nv->inc(); + } template - NodeTemplate::NodeTemplate(const NodeTemplate& e) { + NodeTemplate::NodeTemplate(const NodeTemplate& e) { Assert(e.d_nv != NULL, "Expecting a non-NULL expression value!"); d_nv = e.d_nv; if(ref_count) @@ -588,64 +593,78 @@ template } template - template - NodeTemplate& NodeTemplate:: - operator=(const NodeTemplate& e) { - Assert(d_nv != NULL, "Expecting a non-NULL expression value!"); - Assert(e.d_nv != NULL, "Expecting a non-NULL expression value on RHS!"); - if(EXPECT_TRUE( d_nv != e.d_nv )) { - if(ref_count) - d_nv->dec(); - d_nv = e.d_nv; - if(ref_count) - d_nv->inc(); - } - return *this; + NodeTemplate& NodeTemplate:: + operator=(const NodeTemplate& e) { + Assert(d_nv != NULL, "Expecting a non-NULL expression value!"); + Assert(e.d_nv != NULL, "Expecting a non-NULL expression value on RHS!"); + if(EXPECT_TRUE( d_nv != e.d_nv )) { + if(ref_count) + d_nv->dec(); + d_nv = e.d_nv; + if(ref_count) + d_nv->inc(); + } + return *this; + } + +template + NodeTemplate& NodeTemplate:: + operator=(const NodeTemplate& e) { + Assert(d_nv != NULL, "Expecting a non-NULL expression value!"); + Assert(e.d_nv != NULL, "Expecting a non-NULL expression value on RHS!"); + if(EXPECT_TRUE( d_nv != e.d_nv )) { + if(ref_count) + d_nv->dec(); + d_nv = e.d_nv; + if(ref_count) + d_nv->inc(); } + return *this; + } template - NodeTemplate NodeTemplate::eqNode(const NodeTemplate< + NodeTemplate NodeTemplate::eqNode(const NodeTemplate< ref_count>& right) const { return NodeManager::currentNM()->mkNode(kind::EQUAL, *this, right); } template - NodeTemplate NodeTemplate::notNode() const { + NodeTemplate NodeTemplate::notNode() const { return NodeManager::currentNM()->mkNode(kind::NOT, *this); } template - NodeTemplate NodeTemplate::andNode(const NodeTemplate< + NodeTemplate NodeTemplate::andNode(const NodeTemplate< ref_count>& right) const { return NodeManager::currentNM()->mkNode(kind::AND, *this, right); } template - NodeTemplate NodeTemplate::orNode(const NodeTemplate< + NodeTemplate NodeTemplate::orNode(const NodeTemplate< ref_count>& right) const { return NodeManager::currentNM()->mkNode(kind::OR, *this, right); } template - NodeTemplate NodeTemplate::iteNode(const NodeTemplate< + NodeTemplate NodeTemplate::iteNode(const NodeTemplate< ref_count>& thenpart, const NodeTemplate& elsepart) const { return NodeManager::currentNM()->mkNode(kind::ITE, *this, thenpart, elsepart); } template - NodeTemplate NodeTemplate::iffNode(const NodeTemplate< + NodeTemplate NodeTemplate::iffNode(const NodeTemplate< ref_count>& right) const { return NodeManager::currentNM()->mkNode(kind::IFF, *this, right); } template - NodeTemplate NodeTemplate::impNode(const NodeTemplate< + NodeTemplate NodeTemplate::impNode(const NodeTemplate< ref_count>& right) const { return NodeManager::currentNM()->mkNode(kind::IMPLIES, *this, right); } template - NodeTemplate NodeTemplate::xorNode(const NodeTemplate< + NodeTemplate NodeTemplate::xorNode(const NodeTemplate< ref_count>& right) const { return NodeManager::currentNM()->mkNode(kind::XOR, *this, right); }