mirror of https://github.com/stella-emu/stella.git
Some reorganization of debugger Expression classes, and using unique_ptr.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3073 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
690b681fe7
commit
526fbed5e6
|
@ -144,9 +144,6 @@ Debugger::Debugger(OSystem& osystem, Console& console)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Debugger::~Debugger()
|
||||
{
|
||||
for(auto& f: myFunctions)
|
||||
delete f.second;
|
||||
|
||||
delete myBreakPoints;
|
||||
delete myReadTraps;
|
||||
delete myWriteTraps;
|
||||
|
@ -242,9 +239,11 @@ string Debugger::autoExec()
|
|||
{
|
||||
// TODO - check this for memory leaks
|
||||
int res = YaccParser::parse(builtin_functions[i][1]);
|
||||
if(res != 0) cerr << "ERROR in builtin function!" << endl;
|
||||
Expression* exp = YaccParser::getResult();
|
||||
addFunction(builtin_functions[i][0], builtin_functions[i][1], exp, true);
|
||||
if(res == 0)
|
||||
addFunction(builtin_functions[i][0], builtin_functions[i][1],
|
||||
YaccParser::getResult(), true);
|
||||
else
|
||||
cerr << "ERROR in builtin function!" << endl;
|
||||
}
|
||||
return buf.str();
|
||||
}
|
||||
|
@ -536,9 +535,8 @@ void Debugger::setQuitState()
|
|||
bool Debugger::addFunction(const string& name, const string& definition,
|
||||
Expression* exp, bool builtin)
|
||||
{
|
||||
myFunctions.insert(make_pair(name, exp));
|
||||
if(!builtin)
|
||||
myFunctionDefs.insert(make_pair(name, definition));
|
||||
myFunctions.insert(make_pair(name, unique_ptr<Expression>(exp)));
|
||||
myFunctionDefs.insert(make_pair(name, definition));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -551,7 +549,6 @@ bool Debugger::delFunction(const string& name)
|
|||
return false;
|
||||
|
||||
myFunctions.erase(name);
|
||||
delete iter->second;
|
||||
|
||||
const auto& def_iter = myFunctionDefs.find(name);
|
||||
if(def_iter == myFunctionDefs.end())
|
||||
|
@ -562,10 +559,10 @@ bool Debugger::delFunction(const string& name)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
const Expression* Debugger::getFunction(const string& name) const
|
||||
const Expression& Debugger::getFunction(const string& name) const
|
||||
{
|
||||
const auto& iter = myFunctions.find(name);
|
||||
return iter != myFunctions.end() ? iter->second : nullptr;
|
||||
return iter != myFunctions.end() ? *(iter->second.get()) : EmptyExpression;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -48,7 +48,7 @@ class ButtonWidget;
|
|||
#include "Stack.hxx"
|
||||
#include "bspf.hxx"
|
||||
|
||||
typedef map<string,Expression*> FunctionMap;
|
||||
typedef map<string,unique_ptr<Expression>> FunctionMap;
|
||||
typedef map<string,string> FunctionDefMap;
|
||||
|
||||
/*
|
||||
|
@ -118,9 +118,9 @@ class Debugger : public DialogContainer
|
|||
bool addFunction(const string& name, const string& def,
|
||||
Expression* exp, bool builtin = false);
|
||||
bool delFunction(const string& name);
|
||||
const Expression* getFunction(const string& name) const;
|
||||
const Expression& getFunction(const string& name) const;
|
||||
|
||||
const string& getFunctionDef(const string& name) const; // FIXME - dead code
|
||||
const string& getFunctionDef(const string& name) const;
|
||||
const FunctionDefMap getFunctionDefMap() const;
|
||||
string builtinHelp() const;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
class BinAndExpression : public Expression
|
||||
{
|
||||
public:
|
||||
BinAndExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
BinAndExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() & myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -45,7 +45,7 @@ class BinAndExpression : public Expression
|
|||
class BinNotExpression : public Expression
|
||||
{
|
||||
public:
|
||||
BinNotExpression(Expression* left) : Expression(left, 0) {}
|
||||
BinNotExpression(Expression* left) : Expression(left) { }
|
||||
uInt16 evaluate() const
|
||||
{ return ~(myLHS->evaluate()); }
|
||||
};
|
||||
|
@ -54,7 +54,7 @@ class BinNotExpression : public Expression
|
|||
class BinOrExpression : public Expression
|
||||
{
|
||||
public:
|
||||
BinOrExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
BinOrExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() | myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ class BinOrExpression : public Expression
|
|||
class BinXorExpression : public Expression
|
||||
{
|
||||
public:
|
||||
BinXorExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
BinXorExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() ^ myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -72,7 +72,7 @@ class BinXorExpression : public Expression
|
|||
class ByteDerefExpression : public Expression
|
||||
{
|
||||
public:
|
||||
ByteDerefExpression(Expression* left): Expression(left, 0) {}
|
||||
ByteDerefExpression(Expression* left): Expression(left) { }
|
||||
uInt16 evaluate() const
|
||||
{ return Debugger::debugger().peek(myLHS->evaluate()); }
|
||||
};
|
||||
|
@ -81,7 +81,7 @@ class ByteDerefExpression : public Expression
|
|||
class ByteDerefOffsetExpression : public Expression
|
||||
{
|
||||
public:
|
||||
ByteDerefOffsetExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
ByteDerefOffsetExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return Debugger::debugger().peek(myLHS->evaluate() + myRHS->evaluate()); }
|
||||
};
|
||||
|
@ -90,7 +90,7 @@ class ByteDerefOffsetExpression : public Expression
|
|||
class ConstExpression : public Expression
|
||||
{
|
||||
public:
|
||||
ConstExpression(const int value) : Expression(0, 0), myValue(value) {}
|
||||
ConstExpression(const int value) : Expression(), myValue(value) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myValue; }
|
||||
|
||||
|
@ -102,7 +102,7 @@ class ConstExpression : public Expression
|
|||
class CpuMethodExpression : public Expression
|
||||
{
|
||||
public:
|
||||
CpuMethodExpression(CPUDEBUG_INT_METHOD method) : Expression(0, 0), myMethod(method) {}
|
||||
CpuMethodExpression(CPUDEBUG_INT_METHOD method) : Expression(), myMethod(method) { }
|
||||
uInt16 evaluate() const
|
||||
{ return CALL_CPUDEBUG_METHOD(myMethod); }
|
||||
|
||||
|
@ -114,7 +114,7 @@ class CpuMethodExpression : public Expression
|
|||
class DivExpression : public Expression
|
||||
{
|
||||
public:
|
||||
DivExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
DivExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ int denom = myRHS->evaluate();
|
||||
return denom == 0 ? 0 : myLHS->evaluate() / denom; }
|
||||
|
@ -124,7 +124,7 @@ class DivExpression : public Expression
|
|||
class EqualsExpression : public Expression
|
||||
{
|
||||
public:
|
||||
EqualsExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
EqualsExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() == myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -133,7 +133,7 @@ class EqualsExpression : public Expression
|
|||
class EquateExpression : public Expression
|
||||
{
|
||||
public:
|
||||
EquateExpression(const string& label) : Expression(0, 0), myLabel(label) {}
|
||||
EquateExpression(const string& label) : Expression(), myLabel(label) { }
|
||||
uInt16 evaluate() const
|
||||
{ return Debugger::debugger().cartDebug().getAddress(myLabel); }
|
||||
|
||||
|
@ -145,13 +145,9 @@ class EquateExpression : public Expression
|
|||
class FunctionExpression : public Expression
|
||||
{
|
||||
public:
|
||||
FunctionExpression(const string& label) : Expression(0, 0), myLabel(label) {}
|
||||
FunctionExpression(const string& label) : Expression(), myLabel(label) { }
|
||||
uInt16 evaluate() const
|
||||
{
|
||||
const Expression* exp = Debugger::debugger().getFunction(myLabel);
|
||||
if(exp) return exp->evaluate();
|
||||
else return 0;
|
||||
}
|
||||
{ return Debugger::debugger().getFunction(myLabel).evaluate(); }
|
||||
|
||||
private:
|
||||
string myLabel;
|
||||
|
@ -161,7 +157,7 @@ class FunctionExpression : public Expression
|
|||
class GreaterEqualsExpression : public Expression
|
||||
{
|
||||
public:
|
||||
GreaterEqualsExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
GreaterEqualsExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() >= myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -170,7 +166,7 @@ class GreaterEqualsExpression : public Expression
|
|||
class GreaterExpression : public Expression
|
||||
{
|
||||
public:
|
||||
GreaterExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
GreaterExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() > myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -179,7 +175,7 @@ class GreaterExpression : public Expression
|
|||
class HiByteExpression : public Expression
|
||||
{
|
||||
public:
|
||||
HiByteExpression(Expression* left) : Expression(left, 0) {}
|
||||
HiByteExpression(Expression* left) : Expression(left) { }
|
||||
uInt16 evaluate() const
|
||||
{ return 0xff & (myLHS->evaluate() >> 8); }
|
||||
};
|
||||
|
@ -188,7 +184,7 @@ class HiByteExpression : public Expression
|
|||
class LessEqualsExpression : public Expression
|
||||
{
|
||||
public:
|
||||
LessEqualsExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
LessEqualsExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() <= myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -197,7 +193,7 @@ class LessEqualsExpression : public Expression
|
|||
class LessExpression : public Expression
|
||||
{
|
||||
public:
|
||||
LessExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
LessExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() < myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -206,7 +202,7 @@ class LessExpression : public Expression
|
|||
class LoByteExpression : public Expression
|
||||
{
|
||||
public:
|
||||
LoByteExpression(Expression* left) : Expression(left, 0) {}
|
||||
LoByteExpression(Expression* left) : Expression(left) { }
|
||||
uInt16 evaluate() const
|
||||
{ return 0xff & myLHS->evaluate(); }
|
||||
};
|
||||
|
@ -215,7 +211,7 @@ class LoByteExpression : public Expression
|
|||
class LogAndExpression : public Expression
|
||||
{
|
||||
public:
|
||||
LogAndExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
LogAndExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() && myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -224,7 +220,7 @@ class LogAndExpression : public Expression
|
|||
class LogNotExpression : public Expression
|
||||
{
|
||||
public:
|
||||
LogNotExpression(Expression* left) : Expression(left, 0) {}
|
||||
LogNotExpression(Expression* left) : Expression(left) { }
|
||||
uInt16 evaluate() const
|
||||
{ return !(myLHS->evaluate()); }
|
||||
};
|
||||
|
@ -233,7 +229,7 @@ class LogNotExpression : public Expression
|
|||
class LogOrExpression : public Expression
|
||||
{
|
||||
public:
|
||||
LogOrExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
LogOrExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() || myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -242,7 +238,7 @@ class LogOrExpression : public Expression
|
|||
class MinusExpression : public Expression
|
||||
{
|
||||
public:
|
||||
MinusExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
MinusExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() - myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -251,7 +247,7 @@ class MinusExpression : public Expression
|
|||
class ModExpression : public Expression
|
||||
{
|
||||
public:
|
||||
ModExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
ModExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ int rhs = myRHS->evaluate();
|
||||
return rhs == 0 ? 0 : myLHS->evaluate() % rhs; }
|
||||
|
@ -261,7 +257,7 @@ class ModExpression : public Expression
|
|||
class MultExpression : public Expression
|
||||
{
|
||||
public:
|
||||
MultExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
MultExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() * myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -270,7 +266,7 @@ class MultExpression : public Expression
|
|||
class NotEqualsExpression : public Expression
|
||||
{
|
||||
public:
|
||||
NotEqualsExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
NotEqualsExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() != myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -279,7 +275,7 @@ class NotEqualsExpression : public Expression
|
|||
class PlusExpression : public Expression
|
||||
{
|
||||
public:
|
||||
PlusExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
PlusExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() + myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -288,7 +284,7 @@ class PlusExpression : public Expression
|
|||
class CartMethodExpression : public Expression
|
||||
{
|
||||
public:
|
||||
CartMethodExpression(CARTDEBUG_INT_METHOD method) : Expression(0, 0), myMethod(method) {}
|
||||
CartMethodExpression(CARTDEBUG_INT_METHOD method) : Expression(), myMethod(method) { }
|
||||
uInt16 evaluate() const
|
||||
{ return CALL_CARTDEBUG_METHOD(myMethod); }
|
||||
|
||||
|
@ -300,7 +296,7 @@ class CartMethodExpression : public Expression
|
|||
class ShiftLeftExpression : public Expression
|
||||
{
|
||||
public:
|
||||
ShiftLeftExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
ShiftLeftExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() << myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -309,7 +305,7 @@ class ShiftLeftExpression : public Expression
|
|||
class ShiftRightExpression : public Expression
|
||||
{
|
||||
public:
|
||||
ShiftRightExpression(Expression* left, Expression* right) : Expression(left, right) {}
|
||||
ShiftRightExpression(Expression* left, Expression* right) : Expression(left, right) { }
|
||||
uInt16 evaluate() const
|
||||
{ return myLHS->evaluate() >> myRHS->evaluate(); }
|
||||
};
|
||||
|
@ -318,7 +314,7 @@ class ShiftRightExpression : public Expression
|
|||
class TiaMethodExpression : public Expression
|
||||
{
|
||||
public:
|
||||
TiaMethodExpression(TIADEBUG_INT_METHOD method) : Expression(0, 0), myMethod(method) {}
|
||||
TiaMethodExpression(TIADEBUG_INT_METHOD method) : Expression(), myMethod(method) { }
|
||||
uInt16 evaluate() const
|
||||
{ return CALL_TIADEBUG_METHOD(myMethod); }
|
||||
|
||||
|
@ -330,7 +326,7 @@ class TiaMethodExpression : public Expression
|
|||
class UnaryMinusExpression : public Expression
|
||||
{
|
||||
public:
|
||||
UnaryMinusExpression(Expression* left) : Expression(left, 0) {}
|
||||
UnaryMinusExpression(Expression* left) : Expression(left) { }
|
||||
uInt16 evaluate() const
|
||||
{ return -(myLHS->evaluate()); }
|
||||
};
|
||||
|
@ -339,7 +335,7 @@ class UnaryMinusExpression : public Expression
|
|||
class WordDerefExpression : public Expression
|
||||
{
|
||||
public:
|
||||
WordDerefExpression(Expression* left) : Expression(left, 0) {}
|
||||
WordDerefExpression(Expression* left) : Expression(left) { }
|
||||
uInt16 evaluate() const
|
||||
{ return Debugger::debugger().dpeek(myLHS->evaluate()); }
|
||||
};
|
||||
|
|
|
@ -34,13 +34,16 @@
|
|||
class Expression
|
||||
{
|
||||
public:
|
||||
Expression(Expression* lhs, Expression* rhs) : myLHS(lhs), myRHS(rhs) { }
|
||||
Expression(Expression* lhs = nullptr, Expression* rhs = nullptr)
|
||||
: myLHS(lhs), myRHS(rhs) { }
|
||||
virtual ~Expression() { }
|
||||
|
||||
virtual uInt16 evaluate() const = 0;
|
||||
virtual uInt16 evaluate() const { return 0; }
|
||||
|
||||
protected:
|
||||
unique_ptr<Expression> myLHS, myRHS;
|
||||
};
|
||||
|
||||
static const Expression EmptyExpression;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -286,7 +286,7 @@ int yylex() {
|
|||
} else if( (tiaMeth = getTiaSpecial(idbuf)) ) {
|
||||
yylval.tiaMethod = tiaMeth;
|
||||
return TIA_METHOD;
|
||||
} else if( Debugger::debugger().getFunction(idbuf) != 0) {
|
||||
} else if( Debugger::debugger().getFunctionDef(idbuf) != EmptyString ) {
|
||||
yylval.function = idbuf;
|
||||
return FUNCTION;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue