From 26feb52b57f3957c95f7f7fa65fa34f6173f8c77 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sat, 25 Nov 2006 23:15:58 +0100 Subject: [PATCH] Move type inference from parse time to display time. This saves some marginal amount of CPU time, but its main purpose is that the type inference now works solely on VarTree items that are hooked into the tree displays, and not on those that are parse results. This lets us later use simpler objects for the parse result. --- kdbg/debugger.cpp | 21 ++++++--------------- kdbg/exprwnd.cpp | 21 +++++++++++++-------- kdbg/exprwnd.h | 8 ++++---- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/kdbg/debugger.cpp b/kdbg/debugger.cpp index 39596ee..0a12a31 100644 --- a/kdbg/debugger.cpp +++ b/kdbg/debugger.cpp @@ -1328,7 +1328,7 @@ void KDebugger::handleLocals(const char* output) } else { // variable in both old and new lists: update TRACE(QString("update var: ") + n); - m_localVariables.updateExpr(newVars.current()); + m_localVariables.updateExpr(newVars.current(), *m_typeTable); // remove the new variable from the list newVars.remove(); delete v; @@ -1340,7 +1340,7 @@ void KDebugger::handleLocals(const char* output) { VarTree* v = newVars.take(0); TRACE("new var: " + v->getText()); - m_localVariables.insertExpr(v); + m_localVariables.insertExpr(v, *m_typeTable); delete v; repaintNeeded = true; } @@ -1360,8 +1360,6 @@ void KDebugger::parseLocals(const char* output, QList& newVars) while (vars.count() > 0) { VarTree* variable = vars.take(0); - // get some types - variable->inferTypesOfChildren(*m_typeTable); /* * When gdb prints local variables, those from the innermost block * come first. We run through the list of already parsed variables @@ -1398,7 +1396,7 @@ bool KDebugger::handlePrint(CmdQueueItem* cmd, const char* output) { TRACE("update expr: " + cmd->m_expr->getText()); - cmd->m_exprWnd->updateExpr(cmd->m_expr, variable); + cmd->m_exprWnd->updateExpr(cmd->m_expr, variable, *m_typeTable); delete variable; } @@ -1434,7 +1432,7 @@ bool KDebugger::handlePrintDeref(CmdQueueItem* cmd, const char* output) // expand the first level for convenience variable->setExpanded(true); TRACE("update ptr: " + cmd->m_expr->getText()); - cmd->m_exprWnd->updateExpr(cmd->m_expr, dummyParent); + cmd->m_exprWnd->updateExpr(cmd->m_expr, dummyParent, *m_typeTable); delete dummyParent; } @@ -1446,15 +1444,8 @@ bool KDebugger::handlePrintDeref(CmdQueueItem* cmd, const char* output) VarTree* KDebugger::parseExpr(const char* output, bool wantErrorValue) { VarTree* variable; + m_d->parsePrintExpr(output, wantErrorValue, variable); - // check for error conditions - bool goodValue = m_d->parsePrintExpr(output, wantErrorValue, variable); - - if (variable != 0 && goodValue) - { - // get some types - variable->inferTypesOfChildren(*m_typeTable); - } return variable; } @@ -1847,7 +1838,7 @@ void KDebugger::addWatch(const QString& t) if (expr.isEmpty()) return; VarTree e(expr, VarTree::NKplain); - VarTree* exprItem = m_watchVariables.insertExpr(&e); + VarTree* exprItem = m_watchVariables.insertExpr(&e, *m_typeTable); // if we are boring ourselves, send down the command if (m_programActive) { diff --git a/kdbg/exprwnd.cpp b/kdbg/exprwnd.cpp index ec5054b..ff7b173 100644 --- a/kdbg/exprwnd.cpp +++ b/kdbg/exprwnd.cpp @@ -286,18 +286,18 @@ void ExprWnd::exprList(QStrList& exprs) } } -VarTree* ExprWnd::insertExpr(VarTree* expr) +VarTree* ExprWnd::insertExpr(VarTree* expr, ProgramTypeTable& typeTable) { // append a new dummy expression VarTree* display = new VarTree(expr->getText(), VarTree::NKplain); insertItem(display); // replace it right away - updateExpr(display, expr); + updateExpr(display, expr, typeTable); return display; } -void ExprWnd::updateExpr(VarTree* expr) +void ExprWnd::updateExpr(VarTree* expr, ProgramTypeTable& typeTable) { // search the root variable KPath path; @@ -307,7 +307,7 @@ void ExprWnd::updateExpr(VarTree* expr) return; } // now update it - if (updateExprRec(static_cast(item), expr)) { + if (updateExprRec(static_cast(item), expr, typeTable)) { updateVisibleItems(); updateValuesWidth(); repaint(); @@ -315,9 +315,11 @@ void ExprWnd::updateExpr(VarTree* expr) collectUnknownTypes(static_cast(item)); } -void ExprWnd::updateExpr(VarTree* display, VarTree* newValues) +void ExprWnd::updateExpr(VarTree* display, VarTree* newValues, ProgramTypeTable& typeTable) { - if (updateExprRec(display, newValues) && display->isVisible()) { + if (updateExprRec(display, newValues, typeTable) && + display->isVisible()) + { updateVisibleItems(); updateValuesWidth(); repaint(); @@ -328,7 +330,7 @@ void ExprWnd::updateExpr(VarTree* display, VarTree* newValues) /* * returns true if there's a visible change */ -bool ExprWnd::updateExprRec(VarTree* display, VarTree* newValues) +bool ExprWnd::updateExprRec(VarTree* display, VarTree* newValues, ProgramTypeTable& typeTable) { bool isExpanded = display->isExpanded(); @@ -379,6 +381,9 @@ bool ExprWnd::updateExprRec(VarTree* display, VarTree* newValues) display->setDelayedExpanding(newValues->m_varKind == VarTree::VKpointer); } + // get some types (after the new m_varKind has been set!) + display->inferTypesOfChildren(typeTable); + // (note that the new value might not have a sub-tree at all) return display->m_valueChanged || isExpanded; /* no visible change if not expanded */ } @@ -424,7 +429,7 @@ bool ExprWnd::updateExprRec(VarTree* display, VarTree* newValues) } } // recurse - if (updateExprRec(vDisplay, vNew)) { + if (updateExprRec(vDisplay, vNew, typeTable)) { childChanged = true; } vDisplay = static_cast(vDisplay->getSibling()); diff --git a/kdbg/exprwnd.h b/kdbg/exprwnd.h index 2e92b06..6791596 100644 --- a/kdbg/exprwnd.h +++ b/kdbg/exprwnd.h @@ -88,10 +88,10 @@ public: void exprList(QStrList& exprs); /** appends a copy of expr to the end of the tree at the topmost level; * returns a pointer to the inserted top-level item */ - VarTree* insertExpr(VarTree* expr); + VarTree* insertExpr(VarTree* expr, ProgramTypeTable& typeTable); /** updates an existing expression */ - void updateExpr(VarTree* expr); - void updateExpr(VarTree* display, VarTree* newValues); + void updateExpr(VarTree* expr, ProgramTypeTable& typeTable); + void updateExpr(VarTree* display, VarTree* newValues, ProgramTypeTable& typeTable); /** updates the value and repaints it for a single item (not the children) */ void updateSingleExpr(VarTree* display, VarTree* newValues); /** updates only the value of the node */ @@ -117,7 +117,7 @@ public: VarTree* selectedItem() const { return static_cast(getCurrentItem()); } protected: - bool updateExprRec(VarTree* display, VarTree* newValues); + bool updateExprRec(VarTree* display, VarTree* newValues, ProgramTypeTable& typeTable); void replaceChildren(VarTree* display, VarTree* newValues); virtual void paintCell(QPainter* painter, int row, int col); virtual int cellWidth(int col) const; -- 2.11.4.GIT