[phc-internals] [phc commit] r1822 - trunk/src/lib

codesite-noreply at google.com codesite-noreply at google.com
Sun Oct 26 21:17:20 GMT 2008


Author: paul.biggar
Date: Sun Oct 26 14:17:10 2008
New Revision: 1822

Modified:
    trunk/src/lib/List.h

Log:
We werent able to use Lists of non-Objects, as the type held in a List had  
to have a clone() method. This removes that requirement. Its been tested on  
the dataflow branch by replacing all uses of std::list with List. Using  
Lists everywhere means garbage collection will work.


Modified: trunk/src/lib/List.h
==============================================================================
--- trunk/src/lib/List.h	(original)
+++ trunk/src/lib/List.h	Sun Oct 26 14:17:10 2008
@@ -12,6 +12,30 @@
  #include "lib/Object.h"
  #include "process_ir/Foreach.h"

+// XXX HACK
+/* The implementation of List requires a clone() method, because it was
+ * originally designed for the maketea derived clone() methods. But we  
want to
+ * use List instead of std::list to make sure garbage collection is used
+ * everywhere.  This "hack" allows us to call Object::clone(), and fail if
+ * clone() is called for classes that don't support it (all other classes).
+ */
+template<Object*>
+Object* phc_clone (Object* object)
+{
+	if (object == NULL)
+		return NULL;
+
+	return object->clone ();
+}
+
+template<typename T>
+T phc_clone (T object)
+{
+	assert (0);
+}
+
+
+
  template<typename _Tp, typename _Alloc = phc_allocator<_Tp> >
  class List : public std::list<_Tp, _Alloc>, virtual public Object
  {
@@ -57,17 +81,14 @@
  	// shallow copy (or call a copy-constructor, which?) if not. I think that
  	// checking for a clonable trait of _Tp might do that (involves adding  
such
  	// a trait to Object, which is OK).
+	//
  	List* clone()
  	{
  		List* result = new List<_Tp, _Alloc>;

-		typename List<_Tp, _Alloc>::const_iterator i;
-		for(i = begin(); i != end(); i++)
+		foreach (_Tp elem, *this)
  		{
-			if(*i)
-				result->push_back((*i)->clone());
-			else
-				result->push_back(NULL);
+			result->push_back (phc_clone (elem));
  		}
  	
  		return result;


More information about the phc-internals mailing list