Cleaned up function calling from expressions for various debugger subsystems.

I'd hoped to use std::function, but I don't want to dive any further into the
arcane YACC syntax.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3080 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-11-17 01:36:44 +00:00
parent 021e0caa55
commit f0539ae7e1
9 changed files with 47 additions and 57 deletions

View File

@ -33,12 +33,9 @@ class CartDebugWidget;
#include "DebuggerSystem.hxx"
#include "System.hxx"
// pointer types for CartDebug instance methods
// Pointer type for CartDebug instance methods
class CartDebug;
typedef int (CartDebug::*CARTDEBUG_INT_METHOD)();
// call the pointed-to method on the (global) CPU debugger object.
#define CALL_CARTDEBUG_METHOD(method) ( ( Debugger::debugger().cartDebug().*method)() )
typedef int (CartDebug::*CartMethod)();
class CartState : public DebuggerState
{

View File

@ -24,11 +24,8 @@
#include "System.hxx"
#include "DebuggerSystem.hxx"
// pointer types for CpuDebug instance methods
typedef int (CpuDebug::*CPUDEBUG_INT_METHOD)() const;
// call the pointed-to method on the (global) CPU debugger object.
#define CALL_CPUDEBUG_METHOD(method) ( ( Debugger::debugger().cpuDebug().*method)() )
// Pointer type for CpuDebug instance methods
typedef int (CpuDebug::*CpuMethod)() const;
class CpuState : public DebuggerState
{

View File

@ -102,12 +102,12 @@ class ConstExpression : public Expression
class CpuMethodExpression : public Expression
{
public:
CpuMethodExpression(CPUDEBUG_INT_METHOD method) : Expression(), myMethod(method) { }
CpuMethodExpression(CpuMethod method) : Expression(), myMethod(method) { }
uInt16 evaluate() const
{ return CALL_CPUDEBUG_METHOD(myMethod); }
{ return (Debugger::debugger().cpuDebug().*myMethod)(); }
private:
CPUDEBUG_INT_METHOD myMethod;
CpuMethod myMethod;
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -284,12 +284,12 @@ class PlusExpression : public Expression
class CartMethodExpression : public Expression
{
public:
CartMethodExpression(CARTDEBUG_INT_METHOD method) : Expression(), myMethod(method) { }
CartMethodExpression(CartMethod method) : Expression(), myMethod(method) { }
uInt16 evaluate() const
{ return CALL_CARTDEBUG_METHOD(myMethod); }
{ return (Debugger::debugger().cartDebug().*myMethod)(); }
private:
CARTDEBUG_INT_METHOD myMethod;
CartMethod myMethod;
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -314,12 +314,12 @@ class ShiftRightExpression : public Expression
class TiaMethodExpression : public Expression
{
public:
TiaMethodExpression(TIADEBUG_INT_METHOD method) : Expression(), myMethod(method) { }
TiaMethodExpression(TiaMethod method) : Expression(), myMethod(method) { }
uInt16 evaluate() const
{ return CALL_TIADEBUG_METHOD(myMethod); }
{ return (Debugger::debugger().tiaDebug().*myMethod)(); }
private:
TIADEBUG_INT_METHOD myMethod;
TiaMethod myMethod;
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -26,13 +26,9 @@ class TIA;
#include "DebuggerSystem.hxx"
// pointer types for TIADebug instance methods
// (used by TiaMethodExpression)
// Pointer type for TIADebug instance methods
class TIADebug;
typedef int (TIADebug::*TIADEBUG_INT_METHOD)() const;
// call the pointed-to method on the (global) debugger object.
#define CALL_TIADEBUG_METHOD(method) ( ( Debugger::debugger().tiaDebug().*method)() )
typedef int (TIADebug::*TiaMethod)() const;
// Indices for various IntArray in TiaState
enum {

View File

@ -171,7 +171,7 @@ int const_to_int(char *c) {
}
// special methods that get e.g. CPU registers
CPUDEBUG_INT_METHOD getCpuSpecial(char *c)
CpuMethod getCpuSpecial(char* c)
{
if(BSPF_equalsIgnoreCase(c, "a"))
return &CpuDebug::a;
@ -202,7 +202,7 @@ CPUDEBUG_INT_METHOD getCpuSpecial(char *c)
}
// special methods that get Cart RAM/ROM internal state
CARTDEBUG_INT_METHOD getCartSpecial(char *c)
CartMethod getCartSpecial(char* c)
{
if(BSPF_equalsIgnoreCase(c, "_bank"))
return &CartDebug::getBank;
@ -213,7 +213,7 @@ CARTDEBUG_INT_METHOD getCartSpecial(char *c)
}
// special methods that get TIA internal state
TIADEBUG_INT_METHOD getTiaSpecial(char *c)
TiaMethod getTiaSpecial(char* c)
{
if(BSPF_equalsIgnoreCase(c, "_scan"))
return &TIADebug::scanlines;
@ -252,9 +252,9 @@ int yylex() {
case ST_IDENTIFIER:
{
CARTDEBUG_INT_METHOD cartMeth;
CPUDEBUG_INT_METHOD cpuMeth;
TIADEBUG_INT_METHOD tiaMeth;
CartMethod cartMeth;
CpuMethod cpuMeth;
TiaMethod tiaMeth;
char *bufp = idbuf;
*bufp++ = *c++; // might be a base prefix
@ -275,7 +275,7 @@ int yylex() {
// the specials. Who would do that, though?
if(Debugger::debugger().cartDebug().getAddress(idbuf) > -1) {
yylval.equate = idbuf;
yylval.Equate = idbuf;
return EQUATE;
} else if( (cpuMeth = getCpuSpecial(idbuf)) ) {
yylval.cpuMethod = cpuMeth;
@ -287,7 +287,7 @@ int yylex() {
yylval.tiaMethod = tiaMeth;
return TIA_METHOD;
} else if( Debugger::debugger().getFunctionDef(idbuf) != EmptyString ) {
yylval.function = idbuf;
yylval.DefinedFunction = idbuf;
return FUNCTION;
} else {
yylval.val = const_to_int(idbuf);

View File

@ -27,7 +27,7 @@ class Expression;
//#endif
namespace YaccParser {
int parse(const char *);
int parse(const char*);
Expression* getResult();
const string& errorMessage();
}

View File

@ -27,22 +27,22 @@ void yyerror(const char *e) {
%union {
int val;
char *equate;
CARTDEBUG_INT_METHOD cartMethod;
CPUDEBUG_INT_METHOD cpuMethod;
TIADEBUG_INT_METHOD tiaMethod;
Expression *exp;
char *function;
char* Equate;
CartMethod cartMethod;
CpuMethod cpuMethod;
TiaMethod tiaMethod;
Expression* exp;
char* DefinedFunction;
}
/* Terminals */
%token <val> NUMBER
%token <val> ERR
%token <equate> EQUATE
%token <Equate> EQUATE
%token <cartMethod> CART_METHOD
%token <cpuMethod> CPU_METHOD
%token <tiaMethod> TIA_METHOD
%token <function> FUNCTION
%token <DefinedFunction> FUNCTION
/* Non-terminals */
%type <exp> expression
@ -98,7 +98,7 @@ expression: expression '+' expression { if(DEBUG_EXP) fprintf(stderr, " +"); $$
| CPU_METHOD { if(DEBUG_EXP) fprintf(stderr, " (CpuMethod)"); $$ = new CpuMethodExpression($1); lastExp = $$; }
| CART_METHOD { if(DEBUG_EXP) fprintf(stderr, " (CartMethod)"); $$ = new CartMethodExpression($1); lastExp = $$; }
| TIA_METHOD { if(DEBUG_EXP) fprintf(stderr, " (TiaMethod)"); $$ = new TiaMethodExpression($1); lastExp = $$; }
| FUNCTION { if(DEBUG_EXP) fprintf(stderr, " (function)"); $$ = new FunctionExpression($1); lastExp = $$; }
| FUNCTION { if(DEBUG_EXP) fprintf(stderr, " (DefinedFunction)"); $$ = new FunctionExpression($1); lastExp = $$; }
| ERR { if(DEBUG_EXP) fprintf(stderr, " ERR: "); yyerror((char*)"Invalid label or constant"); return 1; }
;
%%

View File

@ -172,12 +172,12 @@ union YYSTYPE
#line 28 "stella.y" /* yacc.c:355 */
int val;
char *equate;
CARTDEBUG_INT_METHOD cartMethod;
CPUDEBUG_INT_METHOD cpuMethod;
TIADEBUG_INT_METHOD tiaMethod;
Expression *exp;
char *function;
char* Equate;
CartMethod cartMethod;
CpuMethod cpuMethod;
TiaMethod tiaMethod;
Expression* exp;
char* DefinedFunction;
#line 183 "y.tab.c" /* yacc.c:355 */
};
@ -1511,7 +1511,7 @@ yyreduce:
case 31:
#line 97 "stella.y" /* yacc.c:1646 */
{ if(DEBUG_EXP) fprintf(stderr, " %s", (yyvsp[0].equate)); (yyval.exp) = new EquateExpression((yyvsp[0].equate)); lastExp = (yyval.exp); }
{ if(DEBUG_EXP) fprintf(stderr, " %s", (yyvsp[0].Equate)); (yyval.exp) = new EquateExpression((yyvsp[0].Equate)); lastExp = (yyval.exp); }
#line 1516 "y.tab.c" /* yacc.c:1646 */
break;
@ -1535,7 +1535,7 @@ yyreduce:
case 35:
#line 101 "stella.y" /* yacc.c:1646 */
{ if(DEBUG_EXP) fprintf(stderr, " (function)"); (yyval.exp) = new FunctionExpression((yyvsp[0].function)); lastExp = (yyval.exp); }
{ if(DEBUG_EXP) fprintf(stderr, " (DefinedFunction)"); (yyval.exp) = new FunctionExpression((yyvsp[0].DefinedFunction)); lastExp = (yyval.exp); }
#line 1540 "y.tab.c" /* yacc.c:1646 */
break;

View File

@ -93,12 +93,12 @@ union YYSTYPE
#line 28 "stella.y" /* yacc.c:1909 */
int val;
char *equate;
CARTDEBUG_INT_METHOD cartMethod;
CPUDEBUG_INT_METHOD cpuMethod;
TIADEBUG_INT_METHOD tiaMethod;
Expression *exp;
char *function;
char* Equate;
CartMethod cartMethod;
CpuMethod cpuMethod;
TiaMethod tiaMethod;
Expression* exp;
char* DefinedFunction;
#line 104 "y.tab.h" /* yacc.c:1909 */
};