From be48e643e64d511b2b70549ab811357b22b8a5b0 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Wed, 11 Oct 2017 18:18:07 -0230 Subject: [PATCH] Second pass at cleanups from increased warning level. --- src/common/FSNodeZIP.hxx | 1 - src/common/PNGLibrary.hxx | 18 ++--- src/common/SDL_lib.hxx | 22 ++++-- src/common/main.cxx | 21 ++--- src/debugger/DiStella.cxx | 1 + src/emucore/Cart4A50.hxx | 11 ++- src/emucore/CartAR.hxx | 11 ++- src/emucore/CompuMate.hxx | 2 - src/emucore/M6532.cxx | 4 - src/emucore/M6532.hxx | 23 ++++-- src/emucore/MindLink.hxx | 2 - src/emucore/Paddles.hxx | 4 +- src/emucore/PropsSet.hxx | 8 +- src/emucore/tia/TIA.hxx | 22 ++++-- src/yacc/YaccParser.cxx | 159 ++++++++++++++++++-------------------- src/yacc/YaccParser.hxx | 30 ++++--- 16 files changed, 177 insertions(+), 162 deletions(-) diff --git a/src/common/FSNodeZIP.hxx b/src/common/FSNodeZIP.hxx index 0487f2b51..15a357ca9 100644 --- a/src/common/FSNodeZIP.hxx +++ b/src/common/FSNodeZIP.hxx @@ -42,7 +42,6 @@ class FilesystemNodeZIP : public AbstractFSNode * Creates a FilesystemNodeZIP for a given path. * * @param path String with the path the new node should point to. - * @param node Raw pointer to use for the internal FSNode */ FilesystemNodeZIP(const string& path); diff --git a/src/common/PNGLibrary.hxx b/src/common/PNGLibrary.hxx index b85f70039..1ee6c6ffd 100644 --- a/src/common/PNGLibrary.hxx +++ b/src/common/PNGLibrary.hxx @@ -46,9 +46,9 @@ class PNGLibrary @param filename The filename to load the PNG image @param surface The FBSurface into which to place the PNG data - @return On success, the FBSurface containing image data, otherwise a - runtime_error is thrown containing a more detailed - error message. + @post On success, the FBSurface containing image data, otherwise a + runtime_error is thrown containing a more detailed + error message. */ void loadImage(const string& filename, FBSurface& surface); @@ -60,9 +60,9 @@ class PNGLibrary @param filename The filename to save the PNG image @param comments The text comments to add to the PNG image - @return On success, the PNG file has been saved to 'filename', - otherwise a runtime_error is thrown containing a - more detailed error message. + @post On success, the PNG file has been saved to 'filename', + otherwise a runtime_error is thrown containing a + more detailed error message. */ void saveImage(const string& filename, const VariantList& comments = EmptyVarList); @@ -75,9 +75,9 @@ class PNGLibrary @param rect The area of the surface to use @param comments The text comments to add to the PNG image - @return On success, the PNG file has been saved to 'filename', - otherwise a runtime_error is thrown containing a - more detailed error message. + @post On success, the PNG file has been saved to 'filename', + otherwise a runtime_error is thrown containing a + more detailed error message. */ void saveImage(const string& filename, const FBSurface& surface, const GUI::Rect& rect = GUI::EmptyRect, diff --git a/src/common/SDL_lib.hxx b/src/common/SDL_lib.hxx index fbcf9999e..4783a9b78 100644 --- a/src/common/SDL_lib.hxx +++ b/src/common/SDL_lib.hxx @@ -18,13 +18,25 @@ #ifndef SDL_LIB_HXX #define SDL_LIB_HXX -#include +/* + * We can't control the quality of code from outside projects, so for now + * just disable warnings for it. + */ +#ifdef __clang__ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wimplicit-fallthrough" + #pragma clang diagnostic ignored "-Wdocumentation" + #include + #pragma clang diagnostic pop +#else + #include +#endif /* - Seems to be needed for ppc64le, doesn't hurt other archs - Note that this is a problem in SDL2, which includes - https://bugzilla.redhat.com/show_bug.cgi?id=1419452 -*/ + * Seems to be needed for ppc64le, doesn't hurt other archs + * Note that this is a problem in SDL2, which includes + * https://bugzilla.redhat.com/show_bug.cgi?id=1419452 + */ #undef vector #undef pixel #undef bool diff --git a/src/common/main.cxx b/src/common/main.cxx index 1e195988c..b0d1b7cca 100644 --- a/src/common/main.cxx +++ b/src/common/main.cxx @@ -38,18 +38,6 @@ #include "CheatManager.hxx" #endif -// Pointer to the main parent osystem object or the null pointer -unique_ptr theOSystem; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Does general Cleanup in case any operation failed (or at end of program) -int Cleanup() -{ - theOSystem->logMessage("Cleanup from main", 2); - theOSystem->saveConfig(); - - return 0; -} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #if defined(BSPF_MAC_OSX) @@ -61,10 +49,17 @@ int main(int argc, char* argv[]) std::ios_base::sync_with_stdio(false); // Create the parent OSystem object - theOSystem = MediaFactory::createOSystem(); + unique_ptr theOSystem = MediaFactory::createOSystem(); theOSystem->loadConfig(); theOSystem->logMessage("Loading config options ...", 2); + auto Cleanup = [&theOSystem]() { + theOSystem->logMessage("Cleanup from main", 2); + theOSystem->saveConfig(); + + return 0; + }; + // Take care of commandline arguments theOSystem->logMessage("Loading commandline arguments ...", 2); string romfile = theOSystem->settings().loadCommandLine(argc, argv); diff --git a/src/debugger/DiStella.cxx b/src/debugger/DiStella.cxx index 744d08012..a0705c6e9 100644 --- a/src/debugger/DiStella.cxx +++ b/src/debugger/DiStella.cxx @@ -713,6 +713,7 @@ void DiStella::disasmFromAddress(uInt32 distart) myPCEnd = myAppData.end + myOffset; return; } + break; // TODO - is this the intent? default: break; diff --git a/src/emucore/Cart4A50.hxx b/src/emucore/Cart4A50.hxx index 60916e6a5..d1e9ea394 100644 --- a/src/emucore/Cart4A50.hxx +++ b/src/emucore/Cart4A50.hxx @@ -152,12 +152,17 @@ class Cartridge4A50 : public Cartridge private: /** - Query/change the given address type to use the given disassembly flags + Query the given address type for the associated disassembly flags. - @param address The address to modify - @param flags A bitfield of DisasmType directives for the given address + @param address The address to query */ uInt8 getAccessFlags(uInt16 address) const override; + /** + Change the given address to use the given disassembly flags. + + @param address The address to modify + @param flags A bitfield of DisasmType directives for the given address + */ void setAccessFlags(uInt16 address, uInt8 flags) override; /** diff --git a/src/emucore/CartAR.hxx b/src/emucore/CartAR.hxx index 9e33ee1d1..2e7bd1387 100644 --- a/src/emucore/CartAR.hxx +++ b/src/emucore/CartAR.hxx @@ -156,12 +156,17 @@ class CartridgeAR : public Cartridge private: /** - Query/change the given address type to use the given disassembly flags + Query the given address type for the associated disassembly flags. - @param address The address to modify - @param flags A bitfield of DisasmType directives for the given address + @param address The address to query */ uInt8 getAccessFlags(uInt16 address) const override; + /** + Change the given address to use the given disassembly flags. + + @param address The address to modify + @param flags A bitfield of DisasmType directives for the given address + */ void setAccessFlags(uInt16 address, uInt8 flags) override; // Handle a change to the bank configuration diff --git a/src/emucore/CompuMate.hxx b/src/emucore/CompuMate.hxx index 429693ce7..b65f24d0e 100644 --- a/src/emucore/CompuMate.hxx +++ b/src/emucore/CompuMate.hxx @@ -109,8 +109,6 @@ class CompuMate Called after *all* digital pins have been written on Port A. Only update on the left controller; the right controller will happen at the same cycle and is redundant. - - @param value The entire contents of the SWCHA register */ void controlWrite(uInt8) override { if(myJack == Controller::Left) myHandler.update(); diff --git a/src/emucore/M6532.cxx b/src/emucore/M6532.cxx index 18a5d0f7e..2dcb2cc0c 100644 --- a/src/emucore/M6532.cxx +++ b/src/emucore/M6532.cxx @@ -461,7 +461,6 @@ uInt32 M6532::timerClocks() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void M6532::createAccessBases() { -#ifdef DEBUGGER_SUPPORT myRAMAccessBase = make_unique(RAM_SIZE); memset(myRAMAccessBase.get(), CartDebug::NONE, RAM_SIZE); myStackAccessBase = make_unique(STACK_SIZE); @@ -471,9 +470,6 @@ void M6532::createAccessBases() myZPAccessDelay = make_unique(RAM_SIZE); memset(myZPAccessDelay.get(), ZP_DELAY, RAM_SIZE); -#else - myRAMAccessBase = myStackAccessBase = myIOAccessBase = nullptr; -#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/M6532.hxx b/src/emucore/M6532.hxx index fbffb4b12..2e4bf4e89 100644 --- a/src/emucore/M6532.hxx +++ b/src/emucore/M6532.hxx @@ -139,17 +139,24 @@ class M6532 : public Device uInt8 timint(); Int32 intimClocks(); uInt32 timerClocks() const; -#ifdef DEBUGGER_SUPPORT - void createAccessBases(); - /** - Query/change the given address type to use the given disassembly flags - @param address The address to modify - @param flags A bitfield of DisasmType directives for the given address + #ifdef DEBUGGER_SUPPORT + void createAccessBases(); + + /** + Query the given address type for the associated disassembly flags. + + @param address The address to query */ uInt8 getAccessFlags(uInt16 address) const override; + /** + Change the given address to use the given disassembly flags. + + @param address The address to modify + @param flags A bitfield of DisasmType directives for the given address + */ void setAccessFlags(uInt16 address, uInt8 flags) override; -#endif // DEBUGGER_SUPPORT + #endif // DEBUGGER_SUPPORT private: // Accessible bits in the interrupt flag register @@ -210,7 +217,7 @@ class M6532 : public Device uInt8 myOutTimer[4]; #ifdef DEBUGGER_SUPPORT - // The arrays containing information about every byte of RIOT + // The arrays containing information about every byte of RIOT // indicating whether and how (RW) it is used. BytePtr myRAMAccessBase; BytePtr myStackAccessBase; diff --git a/src/emucore/MindLink.hxx b/src/emucore/MindLink.hxx index c44404dee..40578a0e9 100644 --- a/src/emucore/MindLink.hxx +++ b/src/emucore/MindLink.hxx @@ -63,8 +63,6 @@ class MindLink : public Controller /** Called after *all* digital pins have been written on Port A. - - @param value The entire contents of the SWCHA register */ void controlWrite(uInt8) override { nextMindlinkBit(); } diff --git a/src/emucore/Paddles.hxx b/src/emucore/Paddles.hxx index 0f7c9777f..a379875b9 100644 --- a/src/emucore/Paddles.hxx +++ b/src/emucore/Paddles.hxx @@ -99,8 +99,8 @@ class Paddles : public Controller range of movement). Note that this specfically does not apply to Stelladaptor-like devices, which uses an absolute value range. - @param sensitivity Value from 1 to 100, representing the percentage - of the range to use + @param range Value from 1 to 100, representing the percentage + of the range to use */ static void setPaddleRange(int range); diff --git a/src/emucore/PropsSet.hxx b/src/emucore/PropsSet.hxx index dabe50a80..230b8abef 100644 --- a/src/emucore/PropsSet.hxx +++ b/src/emucore/PropsSet.hxx @@ -69,8 +69,8 @@ class PropertiesSet @param md5 The md5 of the property to get @param properties The properties with the given MD5, or the default properties if not found - @param defaults Use the built-in defaults, ignoring any properties - from an external file + @param useDefaults Use the built-in defaults, ignoring any properties + from an external file @return True if the set with the specified md5 was found, else false */ @@ -82,12 +82,10 @@ class PropertiesSet checking if it exists. If it doesn't, insert a temporary copy into the set. - @param file The node representing the + @param rom The ROM file used to calculate the MD5 @param md5 The md5 of the property to get @param properties The properties with the given MD5, or the default properties if not found - @param defaults Use the built-in defaults, ignoring any properties - from an external file */ void getMD5WithInsert(const FilesystemNode& rom, const string& md5, Properties& properties); diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 05bd11ec0..f1730179d 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -542,7 +542,7 @@ class TIA : public Device uInt8 resxCounter(); /** - Get the result of the specified collision register. + * Get the result of the specified collision register. */ uInt8 collCXM0P() const; uInt8 collCXM1P() const; @@ -553,17 +553,23 @@ class TIA : public Device uInt8 collCXPPMM() const; uInt8 collCXBLPF() const; -#ifdef DEBUGGER_SUPPORT + #ifdef DEBUGGER_SUPPORT void createAccessBase(); - /** - Query/change the given address type to use the given disassembly flags - @param address The address to modify - @param flags A bitfield of DisasmType directives for the given address - */ + /** + * Query the given address type for the associated disassembly flags. + * + * @param address The address to query + */ uInt8 getAccessFlags(uInt16 address) const override; + /** + * Change the given address to use the given disassembly flags. + * + * @param address The address to modify + * @param flags A bitfield of DisasmType directives for the given address + */ void setAccessFlags(uInt16 address, uInt8 flags) override; -#endif // DEBUGGER_SUPPORT + #endif // DEBUGGER_SUPPORT private: diff --git a/src/yacc/YaccParser.cxx b/src/yacc/YaccParser.cxx index 48e3d5361..4a1a34fd2 100644 --- a/src/yacc/YaccParser.cxx +++ b/src/yacc/YaccParser.cxx @@ -15,59 +15,62 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -//#include "YaccParser.hxx" - -//#ifdef __cplusplus -//extern "C" { -//#endif - #include "Base.hxx" -#include "Expression.hxx" -#include "CartDebug.hxx" -#include "CpuDebug.hxx" -#include "TIADebug.hxx" - #include "DebuggerExpressions.hxx" +#include "YaccParser.hxx" + namespace YaccParser { -#include -#include +#include +#include #include "y.tab.h" -YYSTYPE result; -string errMsg; -#include "y.tab.c" +static YYSTYPE result; +static string errMsg; +void yyerror(const char* e); + +#ifdef __clang__ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wimplicit-fallthrough" + #pragma clang diagnostic ignored "-Wmissing-variable-declarations" + #include "y.tab.c" + #pragma clang diagnostic pop +#else + #include "y.tab.c" +#endif + +enum class State { + DEFAULT, + IDENTIFIER, + OPERATOR, + SPACE +}; + +static State state = State::DEFAULT; +static const char *input, *c; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& errorMessage() { return errMsg; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Expression* getResult() { lastExp = nullptr; return result.exp; } -const char *input, *c; - -enum { - ST_DEFAULT, - ST_IDENTIFIER, - ST_OPERATOR, - ST_SPACE -}; - -int state = ST_DEFAULT; - -//extern int yylval; // bison provides this - -void setInput(const char *in) +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void setInput(const char* in) { input = c = in; - state = ST_DEFAULT; + state = State::DEFAULT; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int parse(const char *in) { lastExp = nullptr; @@ -76,7 +79,8 @@ int parse(const char *in) return yyparse(); } -/* hand-rolled lexer. Hopefully faster than flex... */ +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// hand-rolled lexer. Hopefully faster than flex... inline bool is_base_prefix(char x) { return ( (x=='\\' || x=='$' || x=='#') ); @@ -100,11 +104,13 @@ inline bool is_operator(char x) x=='[' || x==']' ) ); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // const_to_int converts a string into a number, in either the // current base, or (if there's a base override) the selected base. // Returns -1 on error, since negative numbers are the parser's // responsibility, not the lexer's -int const_to_int(char* ch) { +int const_to_int(char* ch) +{ // what base is the input in? Common::Base::Format format = Common::Base::format(); @@ -163,11 +169,28 @@ int const_to_int(char* ch) { return ret; default: - fprintf(stderr, "INVALID BASE in lexer!"); + cerr << "INVALID BASE in lexer!" << endl; return 0; } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// special methods that get Cart RAM/ROM internal state +CartMethod getCartSpecial(char* ch) +{ + if(BSPF::equalsIgnoreCase(ch, "_bank")) + return &CartDebug::getBank; + else if(BSPF::equalsIgnoreCase(ch, "_rwport")) + return &CartDebug::readFromWritePort; + else if(BSPF::equalsIgnoreCase(ch, "__lastread")) + return &CartDebug::lastReadBaseAddress; + else if(BSPF::equalsIgnoreCase(ch, "__lastwrite")) + return &CartDebug::lastWriteBaseAddress; + else + return nullptr; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // special methods that get e.g. CPU registers CpuMethod getCpuSpecial(char* ch) { @@ -199,21 +222,7 @@ CpuMethod getCpuSpecial(char* ch) return nullptr; } -// special methods that get Cart RAM/ROM internal state -CartMethod getCartSpecial(char* ch) -{ - if(BSPF::equalsIgnoreCase(ch, "_bank")) - return &CartDebug::getBank; - else if(BSPF::equalsIgnoreCase(ch, "_rwport")) - return &CartDebug::readFromWritePort; - else if(BSPF::equalsIgnoreCase(ch, "__lastread")) - return &CartDebug::lastReadBaseAddress; - else if(BSPF::equalsIgnoreCase(ch, "__lastwrite")) - return &CartDebug::lastWriteBaseAddress; - else - return nullptr; -} - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // special methods that get TIA internal state TiaMethod getTiaSpecial(char* ch) { @@ -237,28 +246,28 @@ TiaMethod getTiaSpecial(char* ch) return nullptr; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int yylex() { static char idbuf[255]; char o, p; yylval.val = 0; while(*c != '\0') { - //fprintf(stderr, "looking at %c, state %d\n", *c, state); switch(state) { - case ST_SPACE: + case State::SPACE: yylval.val = 0; if(isspace(*c)) { c++; } else if(is_identifier(*c) || is_base_prefix(*c)) { - state = ST_IDENTIFIER; + state = State::IDENTIFIER; } else if(is_operator(*c)) { - state = ST_OPERATOR; + state = State::OPERATOR; } else { - state = ST_DEFAULT; + state = State::DEFAULT; } break; - case ST_IDENTIFIER: + case State::IDENTIFIER: { CartMethod cartMeth; CpuMethod cpuMeth; @@ -268,10 +277,9 @@ int yylex() { *bufp++ = *c++; // might be a base prefix while(is_identifier(*c)) { // may NOT be base prefixes *bufp++ = *c++; - //fprintf(stderr, "yylval==%d, *c==%c\n", yylval, *c); } *bufp = '\0'; - state = ST_DEFAULT; + state = State::DEFAULT; // Note: specials (like "a" for accumulator) have priority over // numbers. So "a" always means accumulator, not hex 0xa. User @@ -306,19 +314,18 @@ int yylex() { } } - case ST_OPERATOR: + case State::OPERATOR: o = *c++; if(!*c) return o; if(isspace(*c)) { - state = ST_SPACE; + state = State::SPACE; return o; } else if(is_identifier(*c) || is_base_prefix(*c)) { - state = ST_IDENTIFIER; + state = State::IDENTIFIER; return o; } else { - state = ST_DEFAULT; + state = State::DEFAULT; p = *c++; - //fprintf(stderr, "o==%c, p==%c\n", o, p); if(o == '>' && p == '=') return GTE; else if(o == '<' && p == '=') @@ -342,15 +349,14 @@ int yylex() { } // break; Never executed - case ST_DEFAULT: - default: + case State::DEFAULT: yylval.val = 0; if(isspace(*c)) { - state = ST_SPACE; + state = State::SPACE; } else if(is_identifier(*c) || is_base_prefix(*c)) { - state = ST_IDENTIFIER; + state = State::IDENTIFIER; } else if(is_operator(*c)) { - state = ST_OPERATOR; + state = State::OPERATOR; } else { yylval.val = *c++; return yylval.val; @@ -359,24 +365,7 @@ int yylex() { } } - //fprintf(stderr, "end of input\n"); return 0; // hit NUL, end of input. } - -#if 0 -int main(int argc, char **argv) { - int l; - - set_input(argv[1]); - while( (l = yylex()) != 0 ) - printf("ret %d, %d\n", l, yylval); - - printf("%d\n", yylval); -} -#endif -} - -//#ifdef __cplusplus -//} -//#endif +} // namespace YaccParser diff --git a/src/yacc/YaccParser.hxx b/src/yacc/YaccParser.hxx index 002914476..b28fc7722 100644 --- a/src/yacc/YaccParser.hxx +++ b/src/yacc/YaccParser.hxx @@ -18,20 +18,26 @@ #ifndef PARSER_HXX #define PARSER_HXX -class Expression; +#include "Expression.hxx" +#include "CartDebug.hxx" +#include "CpuDebug.hxx" +#include "TIADebug.hxx" -//#ifdef __cplusplus -//extern "C" { -//#endif +#include "bspf.hxx" -namespace YaccParser { - int parse(const char*); - Expression* getResult(); - const string& errorMessage(); +// FIXME - Convert this to a proper C++ class using Bison and Flex C++ mode +namespace YaccParser +{ + Expression* getResult(); + const string& errorMessage(); + + void setInput(const char* in); + int parse(const char*); + int const_to_int(char* ch); + + CartMethod getCartSpecial(char* ch); + CpuMethod getCpuSpecial(char* ch); + TiaMethod getTiaSpecial(char* ch); } -//#ifdef __cplusplus -//} -//#endif - #endif