[Scummvm-cvs-logs] SF.net SVN: scummvm:[54820] tools/branches/gsoc2010-decompiler

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Tue Dec 7 23:32:34 CET 2010


Revision: 54820
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54820&view=rev
Author:   pidgeot
Date:     2010-12-07 22:32:34 +0000 (Tue, 07 Dec 2010)

Log Message:
-----------
DECOMPILER: Move reference counting to base class

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/Makefile
    tools/branches/gsoc2010-decompiler/decompiler/codegen.h
    tools/branches/gsoc2010-decompiler/decompiler/graph.h

Added Paths:
-----------
    tools/branches/gsoc2010-decompiler/decompiler/refcounted.h

Modified: tools/branches/gsoc2010-decompiler/Makefile
===================================================================
--- tools/branches/gsoc2010-decompiler/Makefile	2010-12-07 22:30:28 UTC (rev 54819)
+++ tools/branches/gsoc2010-decompiler/Makefile	2010-12-07 22:32:34 UTC (rev 54820)
@@ -33,7 +33,7 @@
 	# Enable even more warnings...
 	#CXXFLAGS+= -pedantic	# -pedantic is too pedantic, at least on Mac OS X
 	CXXFLAGS+= -Wpointer-arith -Wcast-align
-	CXXFLAGS+= -Wshadow -Wimplicit -Wundef -Wnon-virtual-dtor -Wwrite-strings
+	CXXFLAGS+= -Wno-shadow -Wimplicit -Wundef -Wnon-virtual-dtor -Wwrite-strings
 
 	# Enable checking of pointers returned by "new"
 	CXXFLAGS+= -fcheck-new

Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.h	2010-12-07 22:30:28 UTC (rev 54819)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.h	2010-12-07 22:32:34 UTC (rev 54820)
@@ -21,6 +21,7 @@
  */
 
 #include "graph.h"
+#include "refcounted.h"
 #include "stack.h"
 
 #include <ostream>
@@ -57,20 +58,10 @@
  */
 typedef boost::intrusive_ptr<StackEntry> EntryPtr;
 
-namespace boost {
-inline void intrusive_ptr_add_ref(StackEntry *p);
-inline void intrusive_ptr_release(StackEntry *p);
-} // End of namespace boost
-
 /**
  * Base class for stack entries.
  */
-class StackEntry {
-private:
-	long _refCount; ///< Reference count used for boost::intrusive_ptr.
-	friend void ::boost::intrusive_ptr_add_ref(StackEntry *p); ///< Allow access by reference counting methods in boost namespace.
-	friend void ::boost::intrusive_ptr_release(StackEntry *p); ///< Allow access by reference counting methods in boost namespace.
-
+class StackEntry : public RefCounted {
 public:
 	const StackEntryType _type; ///< Type of the stack entry.
 
@@ -79,7 +70,7 @@
 	 *
 	 * @param type The StackEntryType of the StackEntry.
 	 */
-	StackEntry(StackEntryType type) : _refCount(0), _type(type) { }
+	StackEntry(StackEntryType type) : _type(type) { }
 
 	virtual ~StackEntry() { }
 
@@ -111,26 +102,7 @@
 	}
 };
 
-namespace boost {
-
 /**
- * Add a reference to a pointer to a StackEntry.
- */
-inline void intrusive_ptr_add_ref(StackEntry *p) {
-	++(p->_refCount);
-}
-
-/**
- * Remove a reference from a pointer to a StackEntry.
- */
-inline void intrusive_ptr_release(StackEntry *p) {
-	if (--(p->_refCount) == 0)
-		delete p;
-}
-
-} // End of namespace boost
-
-/**
  * Stack entry containing an integer.
  */
 class IntEntry : public StackEntry {

Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-12-07 22:30:28 UTC (rev 54819)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-12-07 22:32:34 UTC (rev 54820)
@@ -24,6 +24,7 @@
 #define DEC_GRAPH_H
 
 #include "instruction.h"
+#include "refcounted.h"
 
 #include <ostream>
 #include <utility>
@@ -190,11 +191,6 @@
  */
 typedef std::pair<InEdgeIterator, InEdgeIterator> InEdgeRange;
 
-namespace boost {
-inline void intrusive_ptr_add_ref(Group *p);
-inline void intrusive_ptr_release(Group *p);
-} // End of namespace boost
-
 /**
  * Structure representing a line of code.
  */
@@ -230,12 +226,7 @@
 /**
  * Structure representing a group of instructions.
  */
-struct Group {
-private:
-  long _refCount;	///< Reference count used for boost::intrusive_ptr.
-  friend void ::boost::intrusive_ptr_add_ref(Group *p); ///< Allow access by reference counting methods in boost namespace.
-  friend void ::boost::intrusive_ptr_release(Group *p); ///< Allow access by reference counting methods in boost namespace.
-
+struct Group : public RefCounted {
 public:
 	GraphVertex _vertex;         ///< Vertex the group belongs to.
 	ConstInstIterator _start;    ///< First instruction in the group.
@@ -252,7 +243,7 @@
 	/**
 	 * Parameterless constructor for Group. Required for use with STL and Boost, should not be called manually.
 	 */
-	Group() : _refCount(0), _stackLevel(-1), _type(kNormalGroupType) { }
+	Group() : _stackLevel(-1), _type(kNormalGroupType) { }
 
 	/**
 	 * Constructor for Group.
@@ -262,7 +253,7 @@
 	 * @param end   Last instruction in the group.
 	 * @param prev  Pointer to the previous group, when ordered by address.
 	 */
-	Group(GraphVertex v, ConstInstIterator start, ConstInstIterator end, GroupPtr prev) : _refCount(0) {
+	Group(GraphVertex v, ConstInstIterator start, ConstInstIterator end, GroupPtr prev) {
 		_vertex = v;
 		_start = start;
 		_end = end;
@@ -363,25 +354,6 @@
 	}
 };
 
-namespace boost {
-
-/**
- * Add a reference to a pointer.
- */
-inline void intrusive_ptr_add_ref(Group *p) {
-	++(p->_refCount);
-}
-
-/**
- * Remove a reference from a pointer.
- */
-inline void intrusive_ptr_release(Group *p) {
-	if (--(p->_refCount) == 0)
-		delete p;
-}
-
-} // End of namespace boost
-
 class Engine;
 
 /**

Added: tools/branches/gsoc2010-decompiler/decompiler/refcounted.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/refcounted.h	                        (rev 0)
+++ tools/branches/gsoc2010-decompiler/decompiler/refcounted.h	2010-12-07 22:32:34 UTC (rev 54820)
@@ -0,0 +1,66 @@
+/* ScummVM Tools
+ * Copyright (C) 2010 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef REFCOUNTED_H
+#define REFCOUNTED_H
+
+class RefCounted;
+
+namespace boost {
+inline void intrusive_ptr_add_ref(RefCounted *p);
+inline void intrusive_ptr_release(RefCounted *p);
+} // End of namespace boost
+
+/**
+ * Provides a base implementation of reference counting for use with boost::intrusive_ptr.
+ */
+class RefCounted {
+	private:
+		long _refCount; ///< Reference count used for boost::intrusive_ptr.
+	  friend void ::boost::intrusive_ptr_add_ref(RefCounted *p); ///< Allow access by reference counting methods in boost namespace.
+		friend void ::boost::intrusive_ptr_release(RefCounted *p); ///< Allow access by reference counting methods in boost namespace.
+
+	protected:
+		RefCounted() : _refCount(0) { }
+		virtual ~RefCounted() { }
+};
+
+namespace boost {
+
+/**
+ * Add a reference to a pointer.
+ */
+inline void intrusive_ptr_add_ref(RefCounted *p) {
+	++(p->_refCount);
+}
+
+/**
+ * Remove a reference from a pointer.
+ */
+inline void intrusive_ptr_release(RefCounted *p) {
+	if (--(p->_refCount) == 0)
+		delete p;
+}
+
+} // End of namespace boost
+
+#endif


Property changes on: tools/branches/gsoc2010-decompiler/decompiler/refcounted.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list