From 83e7bc592c4fb8c0b0c92bd65a5d39dfa7081d15 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 25 Nov 2006 23:01:47 +0100 Subject: [PATCH] Code cleanup: parsePrintExpr() need not return whether there was an error. This indication was only used to avoid a call to inferTypesOfChildren(), but this method is harmless if it is invoked for an error message. So we just call it always if we get some parse result back. Now that we don't need the return value for this indicator, we can use it for the parse result. --- kdbg/dbgdriver.h | 16 ++++++---------- kdbg/debugger.cpp | 14 +++----------- kdbg/debugger.h | 1 - kdbg/gdbdriver.cpp | 9 ++++----- kdbg/gdbdriver.h | 3 +-- kdbg/xsldbgdriver.cpp | 12 +++++------- kdbg/xsldbgdriver.h | 3 +-- 7 files changed, 20 insertions(+), 38 deletions(-) diff --git a/kdbg/dbgdriver.h b/kdbg/dbgdriver.h index 4408371..ab15838 100644 --- a/kdbg/dbgdriver.h +++ b/kdbg/dbgdriver.h @@ -442,16 +442,12 @@ public: * @param output The output of the debugger. * @param wantErrorValue Specifies whether the error message should be * provided as the value of a NKplain variable. If this is false, - * #var will be 0 if the printed value is an error message. - * @param var Returns the variable value. It is set to 0 if there was - * a parse error or if the output is an error message and wantErrorValue - * is false. If it is not 0, #var->text() will return junk and must be - * set using #var->setText(). - * @return false if the output is an error message. Even if true is - * returned, #var might still be 0 (due to a parse error). - */ - virtual bool parsePrintExpr(const char* output, bool wantErrorValue, - VarTree*& var) = 0; + * 0 is returned if the printed value is an error message. + * @return the parsed value. It is 0 if there was a parse error + * or if the output is an error message and #wantErrorValue + * is \c false. The returned object's text() is undefined. + */ + virtual VarTree* parsePrintExpr(const char* output, bool wantErrorValue) = 0; /** * Parses the output of the DCcd command. diff --git a/kdbg/debugger.cpp b/kdbg/debugger.cpp index 0a12a31..f8262d0 100644 --- a/kdbg/debugger.cpp +++ b/kdbg/debugger.cpp @@ -1387,7 +1387,7 @@ bool KDebugger::handlePrint(CmdQueueItem* cmd, const char* output) { ASSERT(cmd->m_expr != 0); - VarTree* variable = parseExpr(output, true); + VarTree* variable = m_d->parsePrintExpr(output, true); if (variable == 0) return false; @@ -1409,7 +1409,7 @@ bool KDebugger::handlePrintDeref(CmdQueueItem* cmd, const char* output) { ASSERT(cmd->m_expr != 0); - VarTree* variable = parseExpr(output, true); + VarTree* variable = m_d->parsePrintExpr(output, true); if (variable == 0) return false; @@ -1441,14 +1441,6 @@ bool KDebugger::handlePrintDeref(CmdQueueItem* cmd, const char* output) return true; } -VarTree* KDebugger::parseExpr(const char* output, bool wantErrorValue) -{ - VarTree* variable; - m_d->parsePrintExpr(output, wantErrorValue, variable); - - return variable; -} - // parse the output of bt void KDebugger::handleBacktrace(const char* output) { @@ -1657,7 +1649,7 @@ void KDebugger::handlePrintStruct(CmdQueueItem* cmd, const char* output) } else if (cmd->m_cmd == DCprintWChar) { partExpr = m_d->parseQCharArray(output, false, true); } else { - partExpr = parseExpr(output, false); + partExpr = m_d->parsePrintExpr(output, false); } bool errorValue = partExpr == 0 || diff --git a/kdbg/debugger.h b/kdbg/debugger.h index a0a2aae..3e497f2 100644 --- a/kdbg/debugger.h +++ b/kdbg/debugger.h @@ -345,7 +345,6 @@ protected: protected slots: void parse(CmdQueueItem* cmd, const char* output); protected: - VarTree* parseExpr(const char* output, bool wantErrorValue); void handleRunCommands(const char* output); void updateAllExprs(); void updateProgEnvironment(const QString& args, const QString& wd, diff --git a/kdbg/gdbdriver.cpp b/kdbg/gdbdriver.cpp index 83ace3a..0098f6b 100644 --- a/kdbg/gdbdriver.cpp +++ b/kdbg/gdbdriver.cpp @@ -2030,17 +2030,16 @@ void GdbDriver::parseLocals(const char* output, QList& newVars) } } -bool GdbDriver::parsePrintExpr(const char* output, bool wantErrorValue, VarTree*& var) +VarTree* GdbDriver::parsePrintExpr(const char* output, bool wantErrorValue) { + VarTree* var = 0; // check for error conditions - if (parseErrorMessage(output, var, wantErrorValue)) + if (!parseErrorMessage(output, var, wantErrorValue)) { - return false; - } else { // parse the variable var = parseVar(output); - return true; } + return var; } bool GdbDriver::parseChangeWD(const char* output, QString& message) diff --git a/kdbg/gdbdriver.h b/kdbg/gdbdriver.h index a2ba341..a660805 100644 --- a/kdbg/gdbdriver.h +++ b/kdbg/gdbdriver.h @@ -59,8 +59,7 @@ public: virtual bool parseBreakpoint(const char* output, int& id, QString& file, int& lineNo, QString& address); virtual void parseLocals(const char* output, QList& newVars); - virtual bool parsePrintExpr(const char* output, bool wantErrorValue, - VarTree*& var); + virtual VarTree* parsePrintExpr(const char* output, bool wantErrorValue); virtual bool parseChangeWD(const char* output, QString& message); virtual bool parseChangeExecutable(const char* output, QString& message); virtual bool parseCoreFile(const char* output); diff --git a/kdbg/xsldbgdriver.cpp b/kdbg/xsldbgdriver.cpp index 1273c45..9b9637f 100644 --- a/kdbg/xsldbgdriver.cpp +++ b/kdbg/xsldbgdriver.cpp @@ -1332,18 +1332,16 @@ XsldbgDriver::parseLocals(const char *output, QList < VarTree > &newVars) } -bool -XsldbgDriver::parsePrintExpr(const char *output, bool wantErrorValue, - VarTree * &var) +VarTree * +XsldbgDriver::parsePrintExpr(const char *output, bool wantErrorValue) { + VarTree* var = 0; // check for error conditions - if (parseErrorMessage(output, var, wantErrorValue)) { - return false; - } else { + if (!parseErrorMessage(output, var, wantErrorValue)) { // parse the variable var = parseVar(output); - return true; } + return var; } bool diff --git a/kdbg/xsldbgdriver.h b/kdbg/xsldbgdriver.h index 43615e1..e605270 100644 --- a/kdbg/xsldbgdriver.h +++ b/kdbg/xsldbgdriver.h @@ -68,8 +68,7 @@ class XsldbgDriver:public DebuggerDriver { QString & file, int &lineNo, QString& address); virtual void parseLocals(const char *output, QList < VarTree > &newVars); - virtual bool parsePrintExpr(const char *output, bool wantErrorValue, - VarTree * &var); + virtual VarTree * parsePrintExpr(const char *output, bool wantErrorValue); virtual bool parseChangeWD(const char *output, QString & message); virtual bool parseChangeExecutable(const char *output, QString & message); -- 2.11.4.GIT