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

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Wed Jul 21 23:48:06 CEST 2010


Revision: 51111
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51111&view=rev
Author:   pidgeot
Date:     2010-07-21 21:48:05 +0000 (Wed, 21 Jul 2010)

Log Message:
-----------
Add else, implied block markers (}, do {)

Remove auto-indenting in addOutputLine

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

Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp	2010-07-21 21:37:30 UTC (rev 51110)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp	2010-07-21 21:48:05 UTC (rev 51111)
@@ -102,7 +102,7 @@
 }
 
 void CodeGenerator::addOutputLine(std::string s) {
-	_curGroup->_code.push_back(indentString(s));
+	_curGroup->_code.push_back(s);
 }
 
 void CodeGenerator::writeAssignment(EntryPtr dst, EntryPtr src) {
@@ -112,8 +112,33 @@
 }
 
 void CodeGenerator::process(GraphVertex v) {
-	// TODO: Add keyword output
 	_curGroup = GET(v);
+
+	// Check if we should add else start or end
+	if (_curGroup->_startElse)
+		addOutputLine("} else {");
+	else {
+		// Check ingoing edges to see if we want to add any extra output
+		InEdgeRange ier = boost::in_edges(v, _g);
+		for (InEdgeIterator ie = ier.first; ie != ier.second; ++ie) {
+			GraphVertex in = boost::source(*ie, _g);
+			GroupPtr inGroup = GET(in);
+			if (inGroup == _curGroup->_prev)
+				continue;
+			switch (inGroup->_type) {
+			case kDoWhileCond:
+				addOutputLine("do {");
+				break;
+			case kWhileCond:
+			case kIfCond:
+				addOutputLine("}");
+				break;
+			default:
+				break;
+			}
+		}
+	}
+
 	ConstInstIterator it = _curGroup->_start;
 	do {
 		switch (it->_type) {
@@ -151,4 +176,7 @@
 				processInst(*it);
 		}
 	} while (it++ != _curGroup->_end);
+
+	if (_curGroup->_endElse != NULL)
+		addOutputLine("}");
 }

Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.h	2010-07-21 21:37:30 UTC (rev 51110)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.h	2010-07-21 21:48:05 UTC (rev 51111)
@@ -262,7 +262,7 @@
 class ArrayEntry : public StackEntry {
 private:
 	const std::string _arrayName; ///< The name of the array.
-	ArrayIdxType _idxs;  ///< std::deque of stack entries representing the indexes used (left-to-right).
+	ArrayIdxType _idxs;           ///< std::deque of stack entries representing the indexes used (left-to-right).
 
 public:
 	/**
@@ -325,9 +325,9 @@
 	std::string indentString(std::string s);
 
 	/**
-	 * Indents a line and adds it to the current group.
+	 * Adds a line of code to the current group.
 	 *
-	 * @param s The string to add.
+	 * @param s The line to add.
 	 */
 	void addOutputLine(std::string s);
 


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