diff options
author | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2011-04-28 23:32:16 +0000 |
---|---|---|
committer | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2011-04-28 23:32:16 +0000 |
commit | 40449557777db2d1170cb86274f83b431b5fef04 (patch) | |
tree | 92fbf29e66bcce618cd61d1d88494fc8ed6c3d5b /src/util | |
parent | c21ca8353370eb44aa6318e6ee4bffee64197fd8 (diff) |
more fixes/improvements to datatypes theory and transitive closure
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/datatype.cpp | 10 | ||||
-rw-r--r-- | src/util/datatype.h | 8 | ||||
-rw-r--r-- | src/util/trans_closure.cpp | 30 | ||||
-rw-r--r-- | src/util/trans_closure.h | 25 |
4 files changed, 61 insertions, 12 deletions
diff --git a/src/util/datatype.cpp b/src/util/datatype.cpp index 20d63995f..2a3f69fd6 100644 --- a/src/util/datatype.cpp +++ b/src/util/datatype.cpp @@ -399,6 +399,10 @@ void Datatype::Constructor::resolve(ExprManager* em, DatatypeType self, d_tester = em->mkVar(d_name.substr(d_name.find('\0') + 1), em->mkTesterType(self)); d_name.resize(d_name.find('\0')); d_constructor = em->mkVar(d_name, em->mkConstructorType(*this, self)); + //associate constructor with all selectors + for(iterator i = begin(), i_end = end(); i != i_end; ++i) { + (*i).d_constructor = d_constructor; + } } Datatype::Constructor::Constructor(std::string name, std::string tester) : @@ -605,6 +609,12 @@ Expr Datatype::Constructor::Arg::getSelector() const { return d_selector; } +Expr Datatype::Constructor::Arg::getConstructor() const { + CheckArgument(isResolved(), this, + "cannot get a associated constructor for argument of an unresolved datatype constructor"); + return d_constructor; +} + bool Datatype::Constructor::Arg::isUnresolvedSelf() const throw() { return d_selector.isNull() && d_name.size() == d_name.find('\0') + 1; } diff --git a/src/util/datatype.h b/src/util/datatype.h index df7dd1814..75da1405f 100644 --- a/src/util/datatype.h +++ b/src/util/datatype.h @@ -147,6 +147,8 @@ public: std::string d_name; Expr d_selector; + /** the constructor associated with this selector */ + Expr d_constructor; bool d_resolved; explicit Arg(std::string name, Expr selector); @@ -167,6 +169,12 @@ public: Expr getSelector() const; /** + * Get the associated constructor for this constructor argument; this call is + * only permitted after resolution. + */ + Expr getConstructor() const; + + /** * Get the name of the type of this constructor argument * (Datatype field). Can be used for not-yet-resolved Datatypes * (in which case the name of the unresolved type, or "[self]" diff --git a/src/util/trans_closure.cpp b/src/util/trans_closure.cpp index a31dc3378..43c8735ad 100644 --- a/src/util/trans_closure.cpp +++ b/src/util/trans_closure.cpp @@ -74,6 +74,14 @@ bool TransitiveClosure::addEdge(unsigned i, unsigned j) return false; } +bool TransitiveClosure::isConnected(unsigned i, unsigned j) +{ + if( i>=adjMatrix.size() || j>adjMatrix.size() ){ + return false; + }else{ + return adjMatrix[i] != NULL && adjMatrix[i]->read(j); + } +} void TransitiveClosure::debugPrintMatrix() { @@ -89,16 +97,24 @@ void TransitiveClosure::debugPrintMatrix() } } -unsigned TransitiveClosureNode::d_counter = 0; - unsigned TransitiveClosureNode::getId( Node i ){ - std::map< Node, unsigned >::iterator it = nodeMap.find( i ); + context::CDMap< Node, unsigned, NodeHashFunction >::iterator it = nodeMap.find( i ); if( it==nodeMap.end() ){ - nodeMap[i] = d_counter; - d_counter++; - return d_counter-1; + unsigned c = d_counter.get(); + nodeMap[i] = c; + d_counter.set( c + 1 ); + return c; + } + return (*it).second; +} + +void TransitiveClosureNode::debugPrint(){ + for( int i=0; i<(int)currEdges.size(); i++ ){ + cout << "currEdges[ " << i << " ] = " + << currEdges[i].first << " -> " << currEdges[i].second; + //<< "(" << getId( currEdges[i].first ) << " -> " << getId( currEdges[i].second ) << ")"; + cout << std::endl; } - return it->second; } diff --git a/src/util/trans_closure.h b/src/util/trans_closure.h index 4d811d0c9..af16d2e13 100644 --- a/src/util/trans_closure.h +++ b/src/util/trans_closure.h @@ -23,6 +23,10 @@ #include "expr/node.h" #include <map> +#include "context/cdlist.h" +#include "context/cdmap.h" +#include "context/cdo.h" + namespace CVC4 { /* @@ -65,14 +69,14 @@ public: } bool read(unsigned index) { - if (index < 64) return (d_data & (unsigned(1) << index)) != 0; + if (index < 64) return (d_data & (uint64_t(1) << index)) != 0; else if (d_next == NULL) return false; else return d_next->read(index - 64); } void write(unsigned index) { if (index < 64) { - unsigned mask = unsigned(1) << index; + unsigned mask = uint64_t(1) << index; if ((d_data & mask) != 0) return; makeCurrent(); d_data = d_data | mask; @@ -111,6 +115,8 @@ public: /* Add an edge from node i to node j. Return false if successful, true if this edge would create a cycle */ bool addEdge(unsigned i, unsigned j); + /** whether node i is connected to node j */ + bool isConnected(unsigned i, unsigned j); void debugPrintMatrix(); }; @@ -119,17 +125,26 @@ public: * */ class TransitiveClosureNode : public TransitiveClosure{ - static unsigned d_counter; - std::map< Node, unsigned > nodeMap; + context::CDO< unsigned > d_counter; + context::CDMap< Node, unsigned, NodeHashFunction > nodeMap; unsigned getId( Node i ); + //for debugging + context::CDList< std::pair< Node, Node > > currEdges; public: - TransitiveClosureNode(context::Context* context) : TransitiveClosure(context) {} + TransitiveClosureNode(context::Context* context) : + TransitiveClosure(context), d_counter( context, 0 ), nodeMap( context ), currEdges(context) {} ~TransitiveClosureNode(){} /* Add an edge from node i to node j. Return false if successful, true if this edge would create a cycle */ bool addEdgeNode(Node i, Node j) { + currEdges.push_back( std::pair< Node, Node >( i, j ) ); return addEdge( getId( i ), getId( j ) ); } + /** whether node i is connected to node j */ + bool isConnectedNode(Node i, Node j) { + return isConnected( getId( i ), getId( j ) ); + } + void debugPrint(); }; }/* CVC4 namespace */ |