From b3f0f33b39bc1505257e7fccf9a2bd58b9941db4 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 9 Dec 2008 15:42:48 +0100 Subject: [PATCH 01/11] oops! fixed a typo --- src/libs/cplusplus/pp-macro.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/cplusplus/pp-macro.h b/src/libs/cplusplus/pp-macro.h index 73cdab7e3a0..887fff53b0a 100644 --- a/src/libs/cplusplus/pp-macro.h +++ b/src/libs/cplusplus/pp-macro.h @@ -111,7 +111,7 @@ public: } if (variadics) text += QLatin1String("..."); - text += QLatin1Char(' '); + text += QLatin1Char(')'); } text += QLatin1Char(' '); text += QString::fromUtf8(definition.constData(), definition.size()); From 18b3d258641ccf8d1a763ede3ea45b279c76e834 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 9 Dec 2008 16:18:28 +0100 Subject: [PATCH 02/11] some QTC_ASSERT polishing --- src/libs/utils/qtcassert.h | 8 ++-- src/plugins/debugger/breakhandler.cpp | 3 +- src/plugins/debugger/debugger.pro | 2 - src/plugins/debugger/debuggerplugin.cpp | 10 +++- src/plugins/debugger/gdbengine.cpp | 3 +- src/plugins/debugger/gdbmi.cpp | 4 +- src/plugins/debugger/mode.cpp | 5 +- src/plugins/debugger/scriptengine.cpp | 9 ++-- src/plugins/debugger/stackhandler.cpp | 2 +- src/plugins/debugger/watchhandler.cpp | 2 +- src/plugins/projectexplorer/projectnodes.cpp | 48 ++++++++++---------- 11 files changed, 51 insertions(+), 45 deletions(-) diff --git a/src/libs/utils/qtcassert.h b/src/libs/utils/qtcassert.h index d05be20df81..f75d225f6e6 100644 --- a/src/libs/utils/qtcassert.h +++ b/src/libs/utils/qtcassert.h @@ -36,13 +36,11 @@ #include -#ifdef Q_OS_UNIX +// we do not use the 'do {...} while (0)' idiom here to be able to use +// 'break' and 'continue' as 'actions'. + #define QTC_ASSERT(cond, action) \ if(cond){}else{qDebug()<<"ASSERTION"<<#cond<<"FAILED"<<__FILE__<<__LINE__;action;} -#else -#define QTC_ASSERT(cond, action) \ - if(cond){}else{qDebug()<<"ASSERTION"<<#cond<<"FAILED";action;} -#endif #endif // QTC_ASSERT_H diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index 926568517da..e27aa5ec41d 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -34,7 +34,8 @@ #include "breakhandler.h" #include "imports.h" // TextEditor::BaseTextMark -#include "qtcassert.h" + +#include #include #include diff --git a/src/plugins/debugger/debugger.pro b/src/plugins/debugger/debugger.pro index 6b8c2e74ca4..3d67e19c6aa 100644 --- a/src/plugins/debugger/debugger.pro +++ b/src/plugins/debugger/debugger.pro @@ -10,8 +10,6 @@ include(../../plugins/texteditor/texteditor.pri) include(../../plugins/cpptools/cpptools.pri) include(../../libs/cplusplus/cplusplus.pri) -INCLUDEPATH += ../../libs/utils - # DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII QT += gui network script diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 03f86bec249..37406f70cc1 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -39,7 +39,6 @@ #include "gdboptionpage.h" #include "gdbengine.h" #include "mode.h" -#include "qtcassert.h" #include #include @@ -48,20 +47,27 @@ #include #include #include + #include + #include + #include #include + +#include #include #include #include -#include + +#include #include #include #include #include #include + #include #include #include diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp index 13af8e3075b..d7ac5b1aaa1 100644 --- a/src/plugins/debugger/gdbengine.cpp +++ b/src/plugins/debugger/gdbengine.cpp @@ -37,7 +37,6 @@ #include "debuggermanager.h" #include "gdbmi.h" #include "procinterrupt.h" -#include "qtcassert.h" #include "disassemblerhandler.h" #include "breakhandler.h" @@ -49,6 +48,8 @@ #include "startexternaldialog.h" #include "attachexternaldialog.h" +#include + #include #include #include diff --git a/src/plugins/debugger/gdbmi.cpp b/src/plugins/debugger/gdbmi.cpp index 3beadc385fa..f14bb752e3e 100644 --- a/src/plugins/debugger/gdbmi.cpp +++ b/src/plugins/debugger/gdbmi.cpp @@ -32,10 +32,10 @@ ***************************************************************************/ #include "gdbmi.h" -#include "qtcassert.h" + +#include #include -#include #include namespace Debugger { diff --git a/src/plugins/debugger/mode.cpp b/src/plugins/debugger/mode.cpp index c1bbdd550f1..234f09c2079 100644 --- a/src/plugins/debugger/mode.cpp +++ b/src/plugins/debugger/mode.cpp @@ -35,7 +35,6 @@ #include "debuggerconstants.h" #include "debuggermanager.h" -#include "qtcassert.h" #include #include @@ -48,10 +47,14 @@ #include #include #include + #include +#include + #include #include + #include #include #include diff --git a/src/plugins/debugger/scriptengine.cpp b/src/plugins/debugger/scriptengine.cpp index 50f9dcdf4e2..e6387bfdda9 100644 --- a/src/plugins/debugger/scriptengine.cpp +++ b/src/plugins/debugger/scriptengine.cpp @@ -33,19 +33,18 @@ #include "scriptengine.h" -#include "qtcassert.h" +#include "attachexternaldialog.h" +#include "breakhandler.h" #include "debuggerconstants.h" #include "debuggermanager.h" - #include "disassemblerhandler.h" -#include "breakhandler.h" #include "moduleshandler.h" #include "registerhandler.h" #include "stackhandler.h" +#include "startexternaldialog.h" #include "watchhandler.h" -#include "startexternaldialog.h" -#include "attachexternaldialog.h" +#include #include #include diff --git a/src/plugins/debugger/stackhandler.cpp b/src/plugins/debugger/stackhandler.cpp index 818b6b61888..fd70e1e1ab9 100644 --- a/src/plugins/debugger/stackhandler.cpp +++ b/src/plugins/debugger/stackhandler.cpp @@ -33,7 +33,7 @@ #include "stackhandler.h" -#include "qtcassert.h" +#include #include #include diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index e03c91f7100..07824735ebf 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -37,7 +37,7 @@ #include "modeltest.h" #endif -#include "qtcassert.h" +#include #include #include diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index 1c30bbe1094..7c85aae6ae3 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -314,8 +314,8 @@ void ProjectNode::addProjectNodes(const QList &subProjects) emit watcher->foldersAboutToBeAdded(this, folderNodes); foreach (ProjectNode *project, subProjects) { - Q_ASSERT_X(!project->parentFolderNode(), "addProjectNodes", - "Project node has already a parent"); + QTC_ASSERT(!project->parentFolderNode(), + qDebug("Project node has already a parent")); project->setParentFolderNode(this); foreach (NodesWatcher *watcher, m_watchers) project->registerWatcher(watcher); @@ -353,13 +353,13 @@ void ProjectNode::removeProjectNodes(const QList &subProjects) for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) { while ((*projectIter)->path() != (*toRemoveIter)->path()) { ++projectIter; - Q_ASSERT_X(projectIter != m_subProjectNodes.end(), "removeProjectNodes", - "Project to remove is not part of specified folder!"); + QTC_ASSERT(projectIter != m_subProjectNodes.end(), + qDebug("Project to remove is not part of specified folder!")); } while ((*folderIter)->path() != (*toRemoveIter)->path()) { ++folderIter; - Q_ASSERT_X(folderIter != m_subFolderNodes.end(), "removeProjectNodes", - "Project to remove is not part of specified folder!"); + QTC_ASSERT(folderIter != m_subFolderNodes.end(), + qDebug("Project to remove is not part of specified folder!")); } delete *projectIter; projectIter = m_subProjectNodes.erase(projectIter); @@ -386,15 +386,15 @@ void ProjectNode::addFolderNodes(const QList &subFolders, FolderNod watcher->foldersAboutToBeAdded(parentFolder, subFolders); foreach (FolderNode *folder, subFolders) { - Q_ASSERT_X(!folder->parentFolderNode(), "addFolderNodes", - "Project node has already a parent folder"); + QTC_ASSERT(!folder->parentFolderNode(), + qDebug("Project node has already a parent folder")); folder->setParentFolderNode(parentFolder); folder->setProjectNode(this); parentFolder->m_subFolderNodes.append(folder); // project nodes have to be added via addProjectNodes - Q_ASSERT_X(folder->nodeType() != ProjectNodeType, "addFolderNodes", - "project nodes have to be added via addProjectNodes"); + QTC_ASSERT(folder->nodeType() != ProjectNodeType, + qDebug("project nodes have to be added via addProjectNodes")); } qSort(parentFolder->m_subFolderNodes.begin(), parentFolder->m_subFolderNodes.end(), sortNodesByPath); @@ -427,12 +427,12 @@ void ProjectNode::removeFolderNodes(const QList &subFolders, QList::const_iterator toRemoveIter = toRemove.constBegin(); QList::iterator folderIter = parentFolder->m_subFolderNodes.begin(); for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) { - Q_ASSERT_X(((*toRemoveIter)->nodeType() != ProjectNodeType), "removeFolderNodes", - "project nodes have to be removed via removeProjectNodes"); + QTC_ASSERT((*toRemoveIter)->nodeType() != ProjectNodeType, + qDebug("project nodes have to be removed via removeProjectNodes")); while ((*folderIter)->path() != (*toRemoveIter)->path()) { ++folderIter; - Q_ASSERT_X(folderIter != parentFolder->m_subFolderNodes.end(), "removeFileNodes", - "Folder to remove is not part of specified folder!"); + QTC_ASSERT(folderIter != parentFolder->m_subFolderNodes.end(), + qDebug("Folder to remove is not part of specified folder!")); } delete *folderIter; folderIter = parentFolder->m_subFolderNodes.erase(folderIter); @@ -460,8 +460,8 @@ void ProjectNode::addFileNodes(const QList &files, FolderNode *folder emit watcher->filesAboutToBeAdded(folder, files); foreach (FileNode *file, files) { - Q_ASSERT_X(!file->parentFolderNode(), "addFileNodes", - "File node has already a parent folder"); + QTC_ASSERT(!file->parentFolderNode(), + qDebug("File node has already a parent folder")); file->setParentFolderNode(folder); file->setProjectNode(this); @@ -499,8 +499,8 @@ void ProjectNode::removeFileNodes(const QList &files, FolderNode *fol for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) { while ((*filesIter)->path() != (*toRemoveIter)->path()) { ++filesIter; - Q_ASSERT_X(filesIter != folder->m_fileNodes.end(), "removeFileNodes", - "File to remove is not part of specified folder!"); + QTC_ASSERT(filesIter != folder->m_fileNodes.end(), + qDebug("File to remove is not part of specified folder!")); } delete *filesIter; filesIter = folder->m_fileNodes.erase(filesIter); @@ -591,8 +591,8 @@ void SessionNode::addProjectNodes(const QList &projectNodes) emit watcher->foldersAboutToBeAdded(this, folderNodes); foreach (ProjectNode *project, projectNodes) { - Q_ASSERT_X(!project->parentFolderNode(), "addProjectNodes", - "Project node has already a parent folder"); + QTC_ASSERT(!project->parentFolderNode(), + qDebug("Project node has already a parent folder")); project->setParentFolderNode(this); foreach (NodesWatcher *watcher, m_watchers) project->registerWatcher(watcher); @@ -621,13 +621,13 @@ void SessionNode::removeProjectNodes(const QList &projectNodes) for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) { while ((*projectIter)->path() != (*toRemoveIter)->path()) { ++projectIter; - Q_ASSERT_X(projectIter != m_projectNodes.end(), "removeProjectNodes", - "Project to remove is not part of specified folder!"); + QTC_ASSERT(projectIter != m_projectNodes.end(), + qDebug("Project to remove is not part of specified folder!")); } while ((*folderIter)->path() != (*toRemoveIter)->path()) { ++folderIter; - Q_ASSERT_X(folderIter != m_subFolderNodes.end(), "removeProjectNodes", - "Project to remove is not part of specified folder!"); + QTC_ASSERT(folderIter != m_subFolderNodes.end(), + qDebug("Project to remove is not part of specified folder!")); } projectIter = m_projectNodes.erase(projectIter); folderIter = m_subFolderNodes.erase(folderIter); From 9653f4b7e9a5d238fb80f28446c0c04c1dd19b4f Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 9 Dec 2008 16:19:56 +0100 Subject: [PATCH 03/11] Fixed macro locations. --- src/libs/cplusplus/pp-engine.cpp | 10 ++++++---- src/libs/cplusplus/pp-environment.cpp | 6 +++--- src/libs/cplusplus/pp-environment.h | 2 +- src/libs/cplusplus/pp-macro-expander.cpp | 4 ++-- src/plugins/cpptools/cppmodelmanager.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index fd618d27065..d2ed3ee73f3 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -481,12 +481,12 @@ void pp::operator () (const QByteArray &filename, const QByteArray &source, QByteArray *result) { - const QByteArray previousFile = env.current_file; - env.current_file = filename; + const QByteArray previousFile = env.currentFile; + env.currentFile = filename; operator () (source, result); - env.current_file = previousFile; + env.currentFile = previousFile; } pp::State pp::createStateFromSource(const QByteArray &source) const @@ -518,7 +518,7 @@ void pp::operator()(const QByteArray &source, QByteArray *result) result->append(QByteArray::number(_dot->lineno)); result->append(' '); result->append('"'); - result->append(env.current_file); + result->append(env.currentFile); result->append('"'); result->append('\n'); } else { @@ -844,6 +844,8 @@ void pp::processDefine(TokenIterator firstToken, TokenIterator lastToken) } Macro macro; + macro.fileName = env.currentFile; + macro.line = env.currentLine; macro.name = tokenText(*tk); ++tk; // skip T_IDENTIFIER diff --git a/src/libs/cplusplus/pp-environment.cpp b/src/libs/cplusplus/pp-environment.cpp index ff2ca77e4f2..20491727a4c 100644 --- a/src/libs/cplusplus/pp-environment.cpp +++ b/src/libs/cplusplus/pp-environment.cpp @@ -97,8 +97,6 @@ Macro *Environment::bind(const Macro &__macro) Macro *m = new Macro (__macro); m->hashcode = hash_code(m->name); - m->fileName = current_file; - m->line = currentLine; if (++_macro_count == _allocated_macros) { if (! _allocated_macros) @@ -122,11 +120,13 @@ Macro *Environment::bind(const Macro &__macro) return m; } -Macro *Environment::remove (const QByteArray &name) +Macro *Environment::remove(const QByteArray &name) { Macro macro; macro.name = name; macro.hidden = true; + macro.fileName = currentFile; + macro.line = currentLine; return bind(macro); } diff --git a/src/libs/cplusplus/pp-environment.h b/src/libs/cplusplus/pp-environment.h index e2a75d29b81..4200b5ea0ff 100644 --- a/src/libs/cplusplus/pp-environment.h +++ b/src/libs/cplusplus/pp-environment.h @@ -94,7 +94,7 @@ private: void rehash(); public: - QByteArray current_file; + QByteArray currentFile; unsigned currentLine; bool hide_next; diff --git a/src/libs/cplusplus/pp-macro-expander.cpp b/src/libs/cplusplus/pp-macro-expander.cpp index 9ae9702fe18..e17dd873dba 100644 --- a/src/libs/cplusplus/pp-macro-expander.cpp +++ b/src/libs/cplusplus/pp-macro-expander.cpp @@ -73,7 +73,7 @@ const char *MacroExpander::operator () (const char *__first, const char *__last, __result->append(QByteArray::number(env.currentLine)); __result->append(' '); __result->append('"'); - __result->append(env.current_file); + __result->append(env.currentFile); __result->append('"'); __result->append('\n'); ++lines; @@ -218,7 +218,7 @@ const char *MacroExpander::operator () (const char *__first, const char *__last, else if (fast_name == "__FILE__") { __result->append('"'); - __result->append(env.current_file); + __result->append(env.currentFile); __result->append('"'); continue; } diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 5111aa31996..40888d99f3f 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -390,17 +390,17 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type) } else { Document::Ptr previousDoc = switchDocument(Document::create(fileName)); - const QByteArray previousFile = env.current_file; + const QByteArray previousFile = env.currentFile; const unsigned previousLine = env.currentLine; - env.current_file = QByteArray(m_currentDoc->translationUnit()->fileName(), - m_currentDoc->translationUnit()->fileNameLength()); + env.currentFile = QByteArray(m_currentDoc->translationUnit()->fileName(), + m_currentDoc->translationUnit()->fileNameLength()); QByteArray preprocessedCode; m_proc(contents, &preprocessedCode); //qDebug() << preprocessedCode; - env.current_file = previousFile; + env.currentFile = previousFile; env.currentLine = previousLine; m_currentDoc->setSource(preprocessedCode); From 0e27bc5aa3772a8fe529ef457fbe4a313696842b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 9 Dec 2008 16:30:47 +0100 Subject: [PATCH 04/11] Exclude anonymous symbols from the QuickOpen They're not overly useful to have in there, since they don't have a name you could type to jump to them. Reviewed-by: Roberto Raggi --- src/plugins/cpptools/searchsymbols.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/cpptools/searchsymbols.cpp b/src/plugins/cpptools/searchsymbols.cpp index 308449ab581..47f540c6ddb 100644 --- a/src/plugins/cpptools/searchsymbols.cpp +++ b/src/plugins/cpptools/searchsymbols.cpp @@ -153,7 +153,7 @@ bool SearchSymbols::visit(Class *symbol) QString SearchSymbols::scopedSymbolName(const QString &symbolName) const { QString name = _scope; - if (! name.isEmpty()) + if (!name.isEmpty()) name += QLatin1String("::"); name += symbolName; return name; @@ -196,6 +196,9 @@ void SearchSymbols::appendItem(const QString &name, ModelItemInfo::ItemType type, const Symbol *symbol) { + if (!symbol->name()) + return; + const QIcon icon = icons.iconForSymbol(symbol); items.append(ModelItemInfo(name, info, type, QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()), From 187434df96a2c7ebc4025c456c80ce46c54c3062 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 9 Dec 2008 16:39:52 +0100 Subject: [PATCH 05/11] Follow macro under cursor. --- src/plugins/cppeditor/cppeditor.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index ff68bd0bac2..8d4a36178ce 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -520,6 +520,15 @@ void CPPEditor::jumpToDefinition() #endif } } else { + foreach (const Document::MacroUse use, doc->macroUses()) { + if (use.contains(endOfName - 1)) { + const Macro ¯o = use.macro(); + const QString fileName = QString::fromUtf8(macro.fileName); + if (TextEditor::BaseTextEditor::openEditorAt(fileName, macro.line, 0)) + return; // done + } + } + qDebug() << "No results for expression:" << expression; } } From bbc97c394426287c67f9b0248d6fa4afb17afcd2 Mon Sep 17 00:00:00 2001 From: con Date: Tue, 9 Dec 2008 17:04:50 +0100 Subject: [PATCH 06/11] Fixes: - "Problems" -> "Build Issues" --- src/plugins/projectexplorer/taskwindow.cpp | 2 +- src/plugins/projectexplorer/taskwindow.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/projectexplorer/taskwindow.cpp b/src/plugins/projectexplorer/taskwindow.cpp index 236b2069ae0..2e3131e36fc 100644 --- a/src/plugins/projectexplorer/taskwindow.cpp +++ b/src/plugins/projectexplorer/taskwindow.cpp @@ -257,7 +257,7 @@ TaskWindow::TaskWindow() m_listview->setModel(m_model); m_listview->setFrameStyle(QFrame::NoFrame); - m_listview->setWindowTitle(tr("Problems")); + m_listview->setWindowTitle(tr("Build Issues")); m_listview->setSelectionMode(QAbstractItemView::SingleSelection); TaskDelegate *tld = new TaskDelegate(this); m_listview->setItemDelegate(tld); diff --git a/src/plugins/projectexplorer/taskwindow.h b/src/plugins/projectexplorer/taskwindow.h index 70253411530..a3bdf47621d 100644 --- a/src/plugins/projectexplorer/taskwindow.h +++ b/src/plugins/projectexplorer/taskwindow.h @@ -63,7 +63,7 @@ public: QWidget *outputWidget(QWidget *); QList toolBarWidgets(void) const; - QString name() const { return tr("Problems"); } + QString name() const { return tr("Build Issues"); } int priorityInStatusBar() const; void clearContents(); void visibilityChanged(bool visible); From a908e6737c5995bac68daf94d76fa1d0fb0a46bd Mon Sep 17 00:00:00 2001 From: Patrick Star Date: Tue, 9 Dec 2008 17:08:00 +0100 Subject: [PATCH 07/11] Fixes: - crash on windows --- src/plugins/debugger/watchhandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 07824735ebf..053fcadcd19 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -118,7 +118,7 @@ static QByteArray quoteUnprintable(const QByteArray &ba) QByteArray res; char buf[10]; for (int i = 0, n = ba.size(); i != n; ++i) { - char c = ba.at(i); + unsigned char c = ba.at(i); if (isprint(c)) { res += c; } else { From 5f544b4daf99356baf3535cf0b776b8cf5789b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 9 Dec 2008 17:15:00 +0100 Subject: [PATCH 08/11] Added the CppFunctionsFilter to QuickOpen In the GUI this is currently called "Methods" with the shortcut 'm'. --- src/plugins/cpptools/cppfunctionsfilter.cpp | 50 ++++++++++++++++++ src/plugins/cpptools/cppfunctionsfilter.h | 58 +++++++++++++++++++++ src/plugins/cpptools/cpptools.cpp | 2 + src/plugins/cpptools/cpptools.pro | 7 +-- src/plugins/cpptools/searchsymbols.cpp | 17 +++++- 5 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 src/plugins/cpptools/cppfunctionsfilter.cpp create mode 100644 src/plugins/cpptools/cppfunctionsfilter.h diff --git a/src/plugins/cpptools/cppfunctionsfilter.cpp b/src/plugins/cpptools/cppfunctionsfilter.cpp new file mode 100644 index 00000000000..61bb8e2d00d --- /dev/null +++ b/src/plugins/cpptools/cppfunctionsfilter.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception +** version 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +#include "cppfunctionsfilter.h" + +using namespace CppTools::Internal; + +CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager) + : CppQuickOpenFilter(manager, editorManager) +{ + setShortcutString("m"); + setIncludedByDefault(false); + + search.setSymbolsToSearchFor(SearchSymbols::Functions); + search.setSeparateScope(true); +} + +CppFunctionsFilter::~CppFunctionsFilter() +{ +} diff --git a/src/plugins/cpptools/cppfunctionsfilter.h b/src/plugins/cpptools/cppfunctionsfilter.h new file mode 100644 index 00000000000..6e48d65b26f --- /dev/null +++ b/src/plugins/cpptools/cppfunctionsfilter.h @@ -0,0 +1,58 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception +** version 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +#ifndef CPPFUNCTIONSFILTER_H +#define CPPFUNCTIONSFILTER_H + +#include + +namespace CppTools { +namespace Internal { + +class CppFunctionsFilter : public CppQuickOpenFilter +{ + Q_OBJECT + +public: + CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager); + ~CppFunctionsFilter(); + + QString trName() const { return tr("Methods"); } + QString name() const { return QLatin1String("Methods"); } + Priority priority() const { return Medium; } +}; + +} // namespace Internal +} // namespace CppTools + +#endif // CPPFUNCTIONSFILTER_H diff --git a/src/plugins/cpptools/cpptools.cpp b/src/plugins/cpptools/cpptools.cpp index 957f0cae9b0..5e9f6dca45f 100644 --- a/src/plugins/cpptools/cpptools.cpp +++ b/src/plugins/cpptools/cpptools.cpp @@ -34,6 +34,7 @@ #include "cpptools.h" #include "cppclassesfilter.h" #include "cppcodecompletion.h" +#include "cppfunctionsfilter.h" #include "cpphoverhandler.h" #include "cppmodelmanager.h" #include "cpptoolsconstants.h" @@ -89,6 +90,7 @@ bool CppToolsPlugin::initialize(const QStringList & /*arguments*/, QString *) m_core->editorManager()); addAutoReleasedObject(quickOpenFilter); addAutoReleasedObject(new CppClassesFilter(m_modelManager, m_core->editorManager())); + addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, m_core->editorManager())); // Menus Core::IActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS); diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 92905e42ef9..74112379e39 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -10,15 +10,16 @@ unix:QMAKE_CXXFLAGS_DEBUG += -O3 INCLUDEPATH += . DEFINES += CPPTOOLS_LIBRARY CONFIG += help - HEADERS += cpptools_global.h \ cppquickopenfilter.h \ cppclassesfilter.h \ - searchsymbols.h + searchsymbols.h \ + cppfunctionsfilter.h SOURCES += cppquickopenfilter.cpp \ cpptoolseditorsupport.cpp \ cppclassesfilter.cpp \ - searchsymbols.cpp + searchsymbols.cpp \ + cppfunctionsfilter.cpp # Input SOURCES += cpptools.cpp \ diff --git a/src/plugins/cpptools/searchsymbols.cpp b/src/plugins/cpptools/searchsymbols.cpp index 47f540c6ddb..2669ea7bc79 100644 --- a/src/plugins/cpptools/searchsymbols.cpp +++ b/src/plugins/cpptools/searchsymbols.cpp @@ -35,6 +35,7 @@ #include #include +#include using namespace CPlusPlus; using namespace CppTools::Internal; @@ -97,12 +98,24 @@ bool SearchSymbols::visit(Function *symbol) if (!(symbolsToSearchFor & Functions)) return false; + QString extraScope; + if (Name *name = symbol->name()) { + if (QualifiedNameId *nameId = name->asQualifiedNameId()) { + if (nameId->nameCount() > 1) { + extraScope = overview.prettyName(nameId->nameAt(nameId->nameCount() - 2)); + } + } + } + QString fullScope = _scope; + if (!_scope.isEmpty() && !extraScope.isEmpty()) + fullScope += QLatin1String("::"); + fullScope += extraScope; QString name = symbolName(symbol); QString scopedName = scopedSymbolName(name); QString type = overview.prettyType(symbol->type(), - separateScope ? symbol->name() : 0); + separateScope ? symbol->identity() : 0); appendItem(separateScope ? type : scopedName, - separateScope ? _scope : type, + separateScope ? fullScope : type, ModelItemInfo::Method, symbol); return false; } From 1e8b9167ef1c07b0f9c6d59a5de60740dad127d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Tue, 9 Dec 2008 17:16:26 +0100 Subject: [PATCH 09/11] Sort C++ QuickOpen with less than 1000 results In this case it's fast enough and sorting the list makes it easier to find what you're looking for. Though because of the substring matching, what you're looking for might still be way down the list. Reviewed-by: con --- src/plugins/cpptools/cppquickopenfilter.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/cpptools/cppquickopenfilter.cpp b/src/plugins/cpptools/cppquickopenfilter.cpp index a1f1a9b3713..ac69c9cc6df 100644 --- a/src/plugins/cpptools/cppquickopenfilter.cpp +++ b/src/plugins/cpptools/cppquickopenfilter.cpp @@ -75,6 +75,12 @@ void CppQuickOpenFilter::refresh(QFutureInterface &future) Q_UNUSED(future); } +static bool compareLexigraphically(const QuickOpen::FilterEntry &a, + const QuickOpen::FilterEntry &b) +{ + return a.displayName < b.displayName; +} + QList CppQuickOpenFilter::matchesFor(const QString &origEntry) { QString entry = trimWildcards(origEntry); @@ -109,6 +115,9 @@ QList CppQuickOpenFilter::matchesFor(const QString &orig } } + if (entries.size() < 1000) + qSort(entries.begin(), entries.end(), compareLexigraphically); + return entries; } From ae3fda8b8454e946004174e0b335db6034d334b0 Mon Sep 17 00:00:00 2001 From: dt Date: Tue, 9 Dec 2008 17:17:12 +0100 Subject: [PATCH 10/11] Fixes: Don't call Qt4ProFileNode::update on rebuild. Task: Found by Roberto. --- .../qt4projectmanager/directorywatcher.cpp | 54 +++++++++++++++++++ .../qt4projectmanager/directorywatcher.h | 25 +++++++++ src/plugins/qt4projectmanager/qt4nodes.cpp | 30 ++++++++++- src/plugins/qt4projectmanager/qt4nodes.h | 16 ++++-- src/plugins/qt4projectmanager/qt4project.cpp | 10 ++-- 5 files changed, 123 insertions(+), 12 deletions(-) diff --git a/src/plugins/qt4projectmanager/directorywatcher.cpp b/src/plugins/qt4projectmanager/directorywatcher.cpp index 689cd0dfd03..daf47834838 100644 --- a/src/plugins/qt4projectmanager/directorywatcher.cpp +++ b/src/plugins/qt4projectmanager/directorywatcher.cpp @@ -203,5 +203,59 @@ void DirectoryWatcher::updateFileList(const QString &dir) } } +int FileWatcher::m_objectCount = 0; +QHash FileWatcher::m_fileCount; +QFileSystemWatcher *FileWatcher::m_watcher = 0; + +FileWatcher::FileWatcher(QObject *parent) +{ + if (!m_watcher) + m_watcher = new QFileSystemWatcher(); + ++m_objectCount; + connect(m_watcher, SIGNAL(fileChanged(QString)), + this, SLOT(slotFileChanged(QString))); +} + +FileWatcher::~FileWatcher() +{ + foreach (const QString &file, m_files) + removeFile(file); + if (--m_objectCount == 0) { + delete m_watcher; + m_watcher = 0; + } +} + +void FileWatcher::slotFileChanged(const QString &file) +{ + if (m_files.contains(file)) + emit fileChanged(file); +} + +QStringList FileWatcher::files() +{ + return m_files; +} + +void FileWatcher::addFile(const QString &file) +{ + if (m_files.contains(file)) + return; + m_files += file; + if (m_fileCount[file] == 0) + m_watcher->addPath(file); + m_fileCount[file] += 1; +} + +void FileWatcher::removeFile(const QString &file) +{ + m_files.removeOne(file); + m_fileCount[file] -= 1; + if (m_fileCount[file] == 0) + m_watcher->removePath(file); +} + + + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/directorywatcher.h b/src/plugins/qt4projectmanager/directorywatcher.h index 3f5f5a846fa..b529ec07e78 100644 --- a/src/plugins/qt4projectmanager/directorywatcher.h +++ b/src/plugins/qt4projectmanager/directorywatcher.h @@ -87,6 +87,31 @@ private: FileModificationTimeMap m_files; }; +class FileWatcher : public QObject +{ + Q_DISABLE_COPY(FileWatcher) + Q_OBJECT +public: + explicit FileWatcher(QObject *parent = 0); + virtual ~FileWatcher(); + + QStringList files(); + void addFile(const QString &file); + void removeFile(const QString &file); +signals: + void fileChanged(const QString &path); + void debugOutout(const QString &path); + +private slots: + void slotFileChanged(const QString&); + +private: + static int m_objectCount; + static QHash m_fileCount; + static QFileSystemWatcher *m_watcher; + QStringList m_files; +}; + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp index 58486fd9a13..dc004580b2b 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.cpp +++ b/src/plugins/qt4projectmanager/qt4nodes.cpp @@ -87,11 +87,20 @@ Qt4PriFileNode::Qt4PriFileNode(Qt4Project *project, Qt4ProFileNode* qt4ProFileNo m_project(project), m_qt4ProFileNode(qt4ProFileNode), m_projectFilePath(QDir::fromNativeSeparators(filePath)), - m_projectDir(QFileInfo(filePath).absolutePath()) + m_projectDir(QFileInfo(filePath).absolutePath()), + m_fileWatcher(new FileWatcher(this)) { QTC_ASSERT(project, return); setFolderName(QFileInfo(filePath).baseName()); setIcon(QIcon(":/qt4projectmanager/images/qt_project.png")); + m_fileWatcher->addFile(filePath); + connect(m_fileWatcher, SIGNAL(fileChanged(QString)), + this, SLOT(scheduleUpdate())); +} + +void Qt4PriFileNode::scheduleUpdate() +{ + m_qt4ProFileNode->scheduleUpdate(); } void Qt4PriFileNode::update(ProFile *includeFile, ProFileReader *reader) @@ -495,12 +504,17 @@ Qt4ProFileNode::Qt4ProFileNode(Qt4Project *project, if (parent) setParent(parent); + m_updateTimer.setInterval(100); + m_updateTimer.setSingleShot(true); + connect(m_dirWatcher, SIGNAL(directoryChanged(const QString&)), - this, SLOT(update())); + this, SLOT(updateGeneratedFiles())); connect(m_dirWatcher, SIGNAL(fileChanged(const QString&)), this, SLOT(fileChanged(const QString&))); connect(m_project, SIGNAL(activeBuildConfigurationChanged()), this, SLOT(update())); + connect(&m_updateTimer, SIGNAL(timeout()), + this, SLOT(update())); } Qt4ProFileNode::~Qt4ProFileNode() @@ -523,6 +537,11 @@ QStringList Qt4ProFileNode::variableValue(const Qt4Variable var) const return m_varValues.value(var); } +void Qt4ProFileNode::scheduleUpdate() +{ + m_updateTimer.start(); +} + void Qt4ProFileNode::update() { ProFileReader *reader = createProFileReader(); @@ -681,9 +700,11 @@ void Qt4ProFileNode::update() void Qt4ProFileNode::fileChanged(const QString &filePath) { + qDebug()<<"+++++"<getObject(); + // TODO compress modelManager->updateSourceFiles(QStringList() << filePath); } @@ -731,11 +752,16 @@ void Qt4ProFileNode::updateGeneratedFiles() // update generated files + // Already existing FileNodes QList existingFileNodes; foreach (FileNode *file, fileNodes()) { if (file->isGenerated()) existingFileNodes << file; } + + + // Convert uiFile to uiHeaderFilePath, find all headers that correspond + // and try to find them in uicDirs QStringList newFilePaths; foreach (const QString &uicDir, m_varValues[UiDirVar]) { foreach (FileNode *uiFile, uiFiles) { diff --git a/src/plugins/qt4projectmanager/qt4nodes.h b/src/plugins/qt4projectmanager/qt4nodes.h index 97bc06a08f4..6b858bc5259 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.h +++ b/src/plugins/qt4projectmanager/qt4nodes.h @@ -75,6 +75,7 @@ using ProjectExplorer::FileType; class ProFileReader; class DirectoryWatcher; +class FileWatcher; // Type of projects enum Qt4ProjectType { @@ -142,6 +143,9 @@ protected: QString buildDir() const; ProFileReader *createProFileReader() const; +private slots: + void scheduleUpdate(); + private: void save(ProFile *includeFile); bool priFileWritable(const QString &path); @@ -151,7 +155,10 @@ private: Qt4ProFileNode *m_qt4ProFileNode; QString m_projectFilePath; QString m_projectDir; - QTimer *m_saveTimer; + + // TODO we might be better off using an IFile* and the FileManager for + // watching changes to the .pro and .pri files on disk + FileWatcher *m_fileWatcher; // managed by Qt4ProFileNode friend class Qt4ProFileNode; @@ -174,14 +181,13 @@ public: QStringList variableValue(const Qt4Variable var) const; public slots: + void scheduleUpdate(); void update(); - private slots: void fileChanged(const QString &filePath); - -private: void updateGeneratedFiles(); +private: Qt4ProFileNode *createSubProFileNode(const QString &path); QStringList uiDirPaths(ProFileReader *reader) const; @@ -197,9 +203,9 @@ private: Qt4ProjectType m_projectType; QHash m_varValues; bool m_isQBuildProject; + QTimer m_updateTimer; DirectoryWatcher *m_dirWatcher; - friend class Qt4NodeHierarchy; }; diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp index edaabdf154e..c9263201937 100644 --- a/src/plugins/qt4projectmanager/qt4project.cpp +++ b/src/plugins/qt4projectmanager/qt4project.cpp @@ -265,7 +265,7 @@ Qt4Project::~Qt4Project() void Qt4Project::defaultQtVersionChanged() { if (qtVersionId(activeBuildConfiguration()) == 0) - update(); + m_rootProjectNode->update(); } void Qt4Project::qtVersionsChanged() @@ -274,7 +274,7 @@ void Qt4Project::qtVersionsChanged() if (!qt4ProjectManager()->versionManager()->version(qtVersionId(bc))->isValid()) { setQtVersion(bc, 0); if (bc == activeBuildConfiguration()) - update(); + m_rootProjectNode->update(); } } } @@ -507,9 +507,9 @@ void Qt4Project::updateCodeModel() } -/*! - Updates complete project - */ +///*! +// Updates complete project +// */ void Qt4Project::update() { // TODO Maybe remove this method completely? From 9c9308b91b116138ed5cc7753cf59eefd5a86db9 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Wed, 10 Dec 2008 10:47:26 +0100 Subject: [PATCH 11/11] QByteArray::toLong() does not auto-detect the base and also fixed a typo in the evaluator of bit-or expressions. --- src/libs/cplusplus/pp-engine.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index d2ed3ee73f3..83386e8079c 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -164,7 +164,15 @@ protected: bool process_primary() { if ((*_lex)->is(T_INT_LITERAL)) { - _value.set_long(tokenSpell().toLong()); + int base = 10; + const QByteArray spell = tokenSpell(); + if (spell.at(0) == '0') { + if (spell.size() > 1 && (spell.at(1) == 'x' || spell.at(1) == 'X')) + base = 16; + else + base = 8; + } + _value.set_long(tokenSpell().toLong(0, base)); ++(*_lex); return true; } else if (isTokenDefined()) { @@ -367,7 +375,7 @@ protected: { process_xor(); - while ((*_lex)->is(T_CARET)) { + while ((*_lex)->is(T_PIPE)) { const Token op = *(*_lex); ++(*_lex);