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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Sat Jul 31 20:10:18 CEST 2010


Revision: 51545
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51545&view=rev
Author:   pidgeot
Date:     2010-07-31 18:10:18 +0000 (Sat, 31 Jul 2010)

Log Message:
-----------
Improve coalescing of else and if blocks

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

Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp	2010-07-31 16:41:42 UTC (rev 51544)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp	2010-07-31 18:10:18 UTC (rev 51545)
@@ -179,7 +179,7 @@
 	_curGroup = GET(v);
 
 	// Check if we should add else start
-	if (_curGroup->_startElse && _curGroup->_type != kIfCond)
+	if (_curGroup->_startElse)
 		addOutputLine("} else {", true, true);
 
 	// Check ingoing edges to see if we want to add any extra output
@@ -244,11 +244,13 @@
 					std::stringstream s;
 					switch (_curGroup->_type) {
 					case kIfCond:
-						if (_curGroup->_startElse) {
+						if (_curGroup->_startElse && _curGroup->_code.size() == 1) {
+							_curGroup->_code.clear();
+							_curGroup->_coalescedElse = true;
 							s << "} else ";
 						}
 						s << "if (" << _stack.pop() << ") {";
-						addOutputLine(s.str(), _curGroup->_startElse, true);
+						addOutputLine(s.str(), _curGroup->_coalescedElse, true);
 						break;
 					case kWhileCond:
 						s << "while (" << _stack.pop() << ") {";
@@ -328,7 +330,7 @@
 	} while (it++ != _curGroup->_end);
 
 	// Add else end if necessary
-	if (_curGroup->_endElse != NULL && (_curGroup->_endElse->_type != kIfCond || !_curGroup->_endElse->_startElse))
+	if (_curGroup->_endElse != NULL && !_curGroup->_endElse->_coalescedElse)
 		addOutputLine("}", true, false);
 }
 

Modified: tools/branches/gsoc2010-decompiler/decompiler/graph.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-07-31 16:41:42 UTC (rev 51544)
+++ tools/branches/gsoc2010-decompiler/decompiler/graph.h	2010-07-31 18:10:18 UTC (rev 51545)
@@ -237,6 +237,7 @@
 	Group *_prev;                ///< Pointer to the previous group, when ordered by address. Used for short-circuit analysis.
 	Group *_next;                ///< Pointer to the next group, when ordered by address.
 	std::vector<CodeLine> _code; ///< Container for decompiled lines of code.
+	bool _coalescedElse;         ///< True if an else starting has been coalesced with another block (e.g. "else if"). If true, an else starting here should not be closed explicitly, but left to the other block.
 
 	/**
 	 * Parameterless constructor for Group. Required for use with STL and Boost, should not be called manually.
@@ -263,6 +264,7 @@
 		if (_prev != NULL)
 			_prev->_next = this;
 		_next = NULL;
+		_coalescedElse = false;
 	}
 
 	/**


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