From f0539ae7e15cca23572d67ccbca6601a7ffcb437 Mon Sep 17 00:00:00 2001 From: stephena Date: Mon, 17 Nov 2014 01:36:44 +0000 Subject: [PATCH] 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 --- src/debugger/CartDebug.hxx | 7 ++----- src/debugger/CpuDebug.hxx | 7 ++----- src/debugger/DebuggerExpressions.hxx | 18 +++++++++--------- src/debugger/TIADebug.hxx | 8 ++------ src/yacc/YaccParser.cxx | 16 ++++++++-------- src/yacc/YaccParser.hxx | 2 +- src/yacc/stella.y | 18 +++++++++--------- src/yacc/y.tab.c | 16 ++++++++-------- src/yacc/y.tab.h | 12 ++++++------ 9 files changed, 47 insertions(+), 57 deletions(-) diff --git a/src/debugger/CartDebug.hxx b/src/debugger/CartDebug.hxx index 727e1db55..9061601d7 100644 --- a/src/debugger/CartDebug.hxx +++ b/src/debugger/CartDebug.hxx @@ -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 { diff --git a/src/debugger/CpuDebug.hxx b/src/debugger/CpuDebug.hxx index be4236c07..2c741ca14 100644 --- a/src/debugger/CpuDebug.hxx +++ b/src/debugger/CpuDebug.hxx @@ -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 { diff --git a/src/debugger/DebuggerExpressions.hxx b/src/debugger/DebuggerExpressions.hxx index 6267f46b9..fc9d96d32 100644 --- a/src/debugger/DebuggerExpressions.hxx +++ b/src/debugger/DebuggerExpressions.hxx @@ -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; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/TIADebug.hxx b/src/debugger/TIADebug.hxx index 5485be097..a3fff9c73 100644 --- a/src/debugger/TIADebug.hxx +++ b/src/debugger/TIADebug.hxx @@ -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 { diff --git a/src/yacc/YaccParser.cxx b/src/yacc/YaccParser.cxx index aa68d6ac6..719a1b2c7 100644 --- a/src/yacc/YaccParser.cxx +++ b/src/yacc/YaccParser.cxx @@ -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); diff --git a/src/yacc/YaccParser.hxx b/src/yacc/YaccParser.hxx index e6f6809b5..148c91206 100644 --- a/src/yacc/YaccParser.hxx +++ b/src/yacc/YaccParser.hxx @@ -27,7 +27,7 @@ class Expression; //#endif namespace YaccParser { - int parse(const char *); + int parse(const char*); Expression* getResult(); const string& errorMessage(); } diff --git a/src/yacc/stella.y b/src/yacc/stella.y index 7864bacd7..cc2e0f180 100644 --- a/src/yacc/stella.y +++ b/src/yacc/stella.y @@ -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 NUMBER %token ERR -%token EQUATE +%token EQUATE %token CART_METHOD %token CPU_METHOD %token TIA_METHOD -%token FUNCTION +%token FUNCTION /* Non-terminals */ %type 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; } ; %% diff --git a/src/yacc/y.tab.c b/src/yacc/y.tab.c index 84e0047f1..a388b5491 100644 --- a/src/yacc/y.tab.c +++ b/src/yacc/y.tab.c @@ -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; diff --git a/src/yacc/y.tab.h b/src/yacc/y.tab.h index 4f1865d6b..3a776e6fe 100644 --- a/src/yacc/y.tab.h +++ b/src/yacc/y.tab.h @@ -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 */ };