From: Brian Norris <banorris@uci.edu>
Date: Wed, 6 Feb 2013 02:27:35 +0000 (-0800)
Subject: cyclegraph: add wrappers for some common functionality
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f912ca726174373393b4c293ae2e28e404beb76c;p=cdsspec-compiler.git

cyclegraph: add wrappers for some common functionality
---

diff --git a/cyclegraph.cc b/cyclegraph.cc
index 8f095dc..4c6acfe 100644
--- a/cyclegraph.cc
+++ b/cyclegraph.cc
@@ -31,6 +31,27 @@ void CycleGraph::putNode(const ModelAction *act, CycleNode *node)
 #endif
 }
 
+/**
+ * Add a CycleNode to the graph, corresponding to a Promise
+ * @param promise The Promise that should be added
+ * @param node The CycleNode that corresponds to the Promise
+ */
+void CycleGraph::putNode(const Promise *promise, CycleNode *node)
+{
+	const ModelAction *reader = promise->get_action();
+	readerToPromiseNode.put(reader, node);
+}
+
+/**
+ * @brief Remove the Promise node from the graph
+ * @param promise The promise to remove from the graph
+ */
+void CycleGraph::erasePromiseNode(const Promise *promise)
+{
+	const ModelAction *reader = promise->get_action();
+	readerToPromiseNode.put(reader, NULL);
+}
+
 /** @return The corresponding CycleNode, if exists; otherwise NULL */
 CycleNode * CycleGraph::getNode_noCreate(const ModelAction *act) const
 {
@@ -72,11 +93,10 @@ CycleNode * CycleGraph::getNode(const ModelAction *action)
  */
 CycleNode * CycleGraph::getNode(const Promise *promise)
 {
-	const ModelAction *reader = promise->get_action();
 	CycleNode *node = getNode_noCreate(promise);
 	if (node == NULL) {
 		node = new CycleNode(promise);
-		readerToPromiseNode.put(reader, node);
+		putNode(promise, node);
 	}
 	return node;
 }
@@ -95,7 +115,7 @@ bool CycleGraph::resolvePromise(ModelAction *reader, ModelAction *writer,
 		return mergeNodes(w_node, promise_node, mustResolve);
 	/* No existing write-node; just convert the promise-node */
 	promise_node->resolvePromise(writer);
-	readerToPromiseNode.put(reader, NULL); /* erase promise_node */
+	erasePromiseNode(promise_node->getPromise());
 	putNode(writer, promise_node);
 	return true;
 }
@@ -163,8 +183,7 @@ bool CycleGraph::mergeNodes(CycleNode *w_node, CycleNode *p_node,
 		}
 	}
 
-	/* erase p_node */
-	readerToPromiseNode.put(promise->get_action(), NULL);
+	erasePromiseNode(promise);
 	delete p_node;
 
 	return !hasCycles;
diff --git a/cyclegraph.h b/cyclegraph.h
index fcaa213..e96e121 100644
--- a/cyclegraph.h
+++ b/cyclegraph.h
@@ -54,6 +54,8 @@ class CycleGraph {
  private:
 	bool addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
 	void putNode(const ModelAction *act, CycleNode *node);
+	void putNode(const Promise *promise, CycleNode *node);
+	void erasePromiseNode(const Promise *promise);
 	CycleNode * getNode(const ModelAction *act);
 	CycleNode * getNode(const Promise *promise);
 	CycleNode * getNode_noCreate(const ModelAction *act) const;