[Scummvm-cvs-logs] SF.net SVN: scummvm:[51260] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Sat Jul 24 23:31:33 CEST 2010
Revision: 51260
http://scummvm.svn.sourceforge.net/scummvm/?rev=51260&view=rev
Author: pidgeot
Date: 2010-07-24 21:31:33 +0000 (Sat, 24 Jul 2010)
Log Message:
-----------
Move some code from header files to .cpp files
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-24 21:18:07 UTC (rev 51259)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.cpp 2010-07-24 21:31:33 UTC (rev 51260)
@@ -33,6 +33,63 @@
static int dupindex = 0;
+std::ostream &IntEntry::print(std::ostream &output) const {
+ if (_isSigned)
+ output << _val;
+ else
+ output << (uint32)_val;
+ return output;
+}
+
+std::ostream &VarEntry::print(std::ostream &output) const {
+ return output << _varName;
+}
+
+std::ostream &BinaryOpEntry::print(std::ostream &output) const {
+ return output << "(" << _lhs << " " << _op << " " << _rhs << ")";
+}
+
+std::ostream &UnaryOpEntry::print(std::ostream &output) const {
+ return output << _op << "(" << _operand << ")";
+}
+
+std::ostream &DupEntry::print(std::ostream &output) const {
+ return output << "dup[" << _idx << "]";
+}
+
+std::ostream &ArrayEntry::print(std::ostream &output) const {
+ output << _arrayName;
+ for (EntryList::const_iterator i = _idxs.begin(); i != _idxs.end(); ++i)
+ output << "[" << *i << "]";
+ return output;
+}
+
+std::ostream &StringEntry::print(std::ostream &output) const {
+ return output << _str;
+}
+
+std::ostream &ListEntry::print(std::ostream &output) const {
+ output << "[";
+ for (EntryList::const_iterator i = _items.begin(); i != _items.end(); ++i) {
+ if (i != _items.begin())
+ output << ", ";
+ output << *i;
+ }
+ output << "]";
+ return output;
+}
+
+std::ostream &CallEntry::print(std::ostream &output) const {
+ output << _funcName << "(";
+ for (EntryList::const_iterator i = _args.begin(); i != _args.end(); ++i) {
+ if (i != _args.begin())
+ output << ", ";
+ output << *i;
+ }
+ output << ")";
+ return output;
+}
+
EntryPtr StackEntry::dup(std::ostream &output) {
if (_type == seDup)
return this;
@@ -42,6 +99,10 @@
return dupEntry;
}
+EntryPtr IntEntry::dup(std::ostream &output) {
+ return new IntEntry(_val, _isSigned);
+}
+
std::string CodeGenerator::indentString(std::string s) {
std::stringstream stream;
stream << std::string(kIndentAmount * _indentLevel, ' ') << s;
Modified: tools/branches/gsoc2010-decompiler/decompiler/codegen.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-07-24 21:18:07 UTC (rev 51259)
+++ tools/branches/gsoc2010-decompiler/decompiler/codegen.h 2010-07-24 21:31:33 UTC (rev 51260)
@@ -33,18 +33,18 @@
class Engine;
-typedef int StackEntryType;
+enum StackEntryType {
+ seInt,
+ seVar,
+ seBinOp,
+ seUnaryOp,
+ seDup,
+ seArray,
+ seString,
+ seList,
+ seCall
+};
-const StackEntryType seInt = 0;
-const StackEntryType seVar = 1;
-const StackEntryType seBinOp = 2;
-const StackEntryType seUnaryOp = 3;
-const StackEntryType seDup = 4;
-const StackEntryType seArray = 5;
-const StackEntryType seString = 6;
-const StackEntryType seList = 7;
-const StackEntryType seCall = 8;
-
class StackEntry;
/**
@@ -140,8 +140,7 @@
* @param val The value contained in the stack entry.
* @param isSigned Whether or not the value is signed. This will affect output.
*/
- IntEntry(int32 val, bool isSigned) : StackEntry(seInt), _val(val), _isSigned(isSigned) {
- }
+ IntEntry(int32 val, bool isSigned) : StackEntry(seInt), _val(val), _isSigned(isSigned) { }
/**
* Constructor for IntEntry.
@@ -149,20 +148,11 @@
* @param val The value contained in the stack entry.
* @param isSigned Whether or not the value is signed. This will affect output.
*/
- IntEntry(uint32 val, bool isSigned) : StackEntry(seInt), _val(val), _isSigned(isSigned) {
- }
+ IntEntry(uint32 val, bool isSigned) : StackEntry(seInt), _val(val), _isSigned(isSigned) { }
- virtual std::ostream &print(std::ostream &output) const {
- if (_isSigned)
- output << _val;
- else
- output << (uint32)_val;
- return output;
- }
+ virtual std::ostream &print(std::ostream &output) const;
- virtual EntryPtr dup(std::ostream &output) {
- return new IntEntry(_val, _isSigned);
- }
+ virtual EntryPtr dup(std::ostream &output);
};
/**
@@ -180,9 +170,7 @@
*/
VarEntry(std::string varName) : StackEntry(seVar), _varName(varName) { }
- virtual std::ostream &print(std::ostream &output) const {
- return output << _varName;
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -190,9 +178,9 @@
*/
class BinaryOpEntry : public StackEntry {
private:
- const EntryPtr _lhs; ///< Stack entry representing the left side of the operator.
- const EntryPtr _rhs; ///< Stack entry representing the right side of the operator.
- const std::string _op; ///< The operator for this entry.
+ const EntryPtr _lhs; ///< Stack entry representing the left side of the operator.
+ const EntryPtr _rhs; ///< Stack entry representing the right side of the operator.
+ const std::string _op; ///< The operator for this entry.
public:
/**
@@ -203,12 +191,9 @@
* @param op The operator for this entry.
*/
BinaryOpEntry(EntryPtr lhs, EntryPtr rhs, std::string op) :
- StackEntry(seBinOp), _lhs(lhs), _rhs(rhs), _op(op) {
- }
+ StackEntry(seBinOp), _lhs(lhs), _rhs(rhs), _op(op) { }
- virtual std::ostream &print(std::ostream &output) const {
- return output << "(" << _lhs << " " << _op << " " << _rhs << ")";
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -217,7 +202,7 @@
class UnaryOpEntry : public StackEntry {
private:
const EntryPtr _operand; ///< The operand the operation is performed on.
- const std::string _op; ///< The operator for this entry.
+ const std::string _op; ///< The operator for this entry.
public:
/**
@@ -229,9 +214,7 @@
UnaryOpEntry(EntryPtr operand, std::string op) :
StackEntry(seUnaryOp), _operand(operand), _op(op) { }
- virtual std::ostream &print(std::ostream &output) const {
- return output << _op << "(" << _operand << ")";
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -249,9 +232,7 @@
*/
DupEntry(int idx) : StackEntry(seDup), _idx(idx) { }
- virtual std::ostream &print(std::ostream &output) const {
- return output << "dup[" << _idx << "]";
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -276,12 +257,7 @@
*/
ArrayEntry(std::string arrayName, std::deque<EntryPtr> idxs) : StackEntry(seArray), _arrayName(arrayName), _idxs(idxs) { }
- virtual std::ostream &print(std::ostream &output) const {
- output << _arrayName;
- for (EntryList::const_iterator i = _idxs.begin(); i != _idxs.end(); ++i)
- output << "[" << *i << "]";
- return output;
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -299,9 +275,7 @@
*/
StringEntry(std::string str) : StackEntry(seString), _str(str) { }
- virtual std::ostream &print(std::ostream &output) const {
- return output << _str;
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -319,16 +293,7 @@
*/
ListEntry(EntryList items) : StackEntry(seList), _items(items) { }
- virtual std::ostream &print(std::ostream &output) const {
- output << "[";
- for (EntryList::const_iterator i = _items.begin(); i != _items.end(); ++i) {
- if (i != _items.begin())
- output << ", ";
- output << *i;
- }
- output << "]";
- return output;
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -348,16 +313,7 @@
*/
CallEntry(std::string funcName, EntryList args) : StackEntry(seCall), _funcName(funcName), _args(args) { }
- virtual std::ostream &print(std::ostream &output) const {
- output << _funcName << "(";
- for (EntryList::const_iterator i = _args.begin(); i != _args.end(); ++i) {
- if (i != _args.begin())
- output << ", ";
- output << *i;
- }
- output << ")";
- return output;
- }
+ virtual std::ostream &print(std::ostream &output) const;
};
/**
@@ -447,7 +403,7 @@
void addArg(EntryPtr p);
public:
- virtual ~CodeGenerator() {};
+ virtual ~CodeGenerator() { }
/**
* Constructor for CodeGenerator.
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