"save" command now actually saves functions correctly: their definitions

go in the savefile, not their Expression pointer addresses :)

Also, we no longer attempt to save the builtin functions.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@730 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
urchlay 2005-08-20 18:19:52 +00:00
parent 74efb7b66d
commit e4172891d9
3 changed files with 32 additions and 13 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Debugger.cxx,v 1.83 2005-08-16 18:34:12 stephena Exp $ // $Id: Debugger.cxx,v 1.84 2005-08-20 18:19:51 urchlay Exp $
//============================================================================ //============================================================================
#include "bspf.hxx" #include "bspf.hxx"
@ -116,7 +116,7 @@ Debugger::Debugger(OSystem* osystem)
int res = YaccParser::parse(f.c_str()); int res = YaccParser::parse(f.c_str());
if(res != 0) cerr << "ERROR in builtin function!" << endl; if(res != 0) cerr << "ERROR in builtin function!" << endl;
Expression *exp = YaccParser::getResult(); Expression *exp = YaccParser::getResult();
addFunction(builtin_functions[i][0], exp); addFunction(builtin_functions[i][0], builtin_functions[i][1], exp, true);
} }
} }
@ -988,8 +988,9 @@ cerr << "Debugger::resizeDialog()\n";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Debugger::addFunction(string name, Expression *exp) { void Debugger::addFunction(string name, string definition, Expression *exp, bool builtin) {
functions.insert(make_pair(name, exp)); functions.insert(make_pair(name, exp));
if(!builtin) functionDefs.insert(make_pair(name, definition));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1000,6 +1001,12 @@ void Debugger::delFunction(string name) {
functions.erase(name); functions.erase(name);
delete iter->second; delete iter->second;
FunctionDefMap::iterator def_iter = functionDefs.find(name);
if(def_iter == functionDefs.end())
return;
functionDefs.erase(name);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1012,8 +1019,17 @@ Expression *Debugger::getFunction(string name) {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const FunctionMap Debugger::getFunctionMap() { string Debugger::getFunctionDef(string name) {
return functions; FunctionDefMap::iterator iter = functionDefs.find(name);
if(iter == functionDefs.end())
return "";
else
return iter->second;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const FunctionDefMap Debugger::getFunctionDefMap() {
return functionDefs;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Debugger.hxx,v 1.67 2005-08-10 12:23:42 stephena Exp $ // $Id: Debugger.hxx,v 1.68 2005-08-20 18:19:52 urchlay Exp $
//============================================================================ //============================================================================
#ifndef DEBUGGER_HXX #ifndef DEBUGGER_HXX
@ -45,6 +45,7 @@ typedef multimap<string,string> ListFile;
typedef ListFile::const_iterator ListIter; typedef ListFile::const_iterator ListIter;
typedef map<string,Expression*> FunctionMap; typedef map<string,Expression*> FunctionMap;
typedef map<string,string> FunctionDefMap;
#if 1 #if 1
enum { enum {
@ -82,7 +83,7 @@ typedef uInt16 (Debugger::*DEBUGGER_WORD_METHOD)();
for all debugging operations in Stella (parser, 6502 debugger, etc). for all debugging operations in Stella (parser, 6502 debugger, etc).
@author Stephen Anthony @author Stephen Anthony
@version $Id: Debugger.hxx,v 1.67 2005-08-10 12:23:42 stephena Exp $ @version $Id: Debugger.hxx,v 1.68 2005-08-20 18:19:52 urchlay Exp $
*/ */
class Debugger : public DialogContainer class Debugger : public DialogContainer
{ {
@ -129,10 +130,11 @@ class Debugger : public DialogContainer
*/ */
void quit(); void quit();
void addFunction(string name, Expression *exp); void addFunction(string name, string def, Expression *exp, bool builtin=false);
string getFunctionDef(string name);
void delFunction(string name); void delFunction(string name);
Expression *getFunction(string name); Expression *getFunction(string name);
const FunctionMap getFunctionMap(); const FunctionDefMap getFunctionDefMap();
const string builtinHelp(); const string builtinHelp();
/** /**
@ -362,6 +364,7 @@ class Debugger : public DialogContainer
static Debugger* myStaticDebugger; static Debugger* myStaticDebugger;
FunctionMap functions; FunctionMap functions;
FunctionDefMap functionDefs;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DebuggerParser.cxx,v 1.75 2005-08-05 02:28:21 urchlay Exp $ // $Id: DebuggerParser.cxx,v 1.76 2005-08-20 18:19:52 urchlay Exp $
//============================================================================ //============================================================================
#include "bspf.hxx" #include "bspf.hxx"
@ -1161,8 +1161,8 @@ bool DebuggerParser::saveScriptFile(string file) {
ofstream out(file.c_str()); ofstream out(file.c_str());
FunctionMap funcs = debugger->getFunctionMap(); FunctionDefMap funcs = debugger->getFunctionDefMap();
for(FunctionMap::const_iterator i = funcs.begin(); i != funcs.end(); ++i) for(FunctionDefMap::const_iterator i = funcs.begin(); i != funcs.end(); ++i)
out << "function " << i->first << " " << i->second << endl; out << "function " << i->first << " " << i->second << endl;
for(unsigned int i=0; i<watches.size(); i++) for(unsigned int i=0; i<watches.size(); i++)
@ -1424,7 +1424,7 @@ void DebuggerParser::executeFunction() {
int res = YaccParser::parse(argStrings[1].c_str()); int res = YaccParser::parse(argStrings[1].c_str());
if(res == 0) { if(res == 0) {
debugger->addFunction(argStrings[0], YaccParser::getResult()); debugger->addFunction(argStrings[0], argStrings[1], YaccParser::getResult());
commandResult = "Added function " + argStrings[0]; commandResult = "Added function " + argStrings[0];
} else { } else {
commandResult = red("invalid expression"); commandResult = red("invalid expression");