2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-11-28 15:36:54 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-11-28 15:36:54 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-11-28 15:36:54 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-11-28 15:36:54 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-11-28 15:36:54 +01:00
|
|
|
|
|
|
|
|
#include "searchsymbols.h"
|
|
|
|
|
|
2010-07-19 14:46:53 +02:00
|
|
|
#include <cplusplus/LookupContext.h>
|
2014-03-13 16:53:17 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/scopedswap.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2010-09-07 14:13:54 +02:00
|
|
|
#include <QDebug>
|
2008-11-28 15:36:54 +01:00
|
|
|
|
|
|
|
|
using namespace CPlusPlus;
|
2011-11-25 12:05:58 +01:00
|
|
|
using namespace CppTools;
|
2008-11-28 15:36:54 +01:00
|
|
|
|
2014-04-14 16:52:01 +02:00
|
|
|
typedef Utils::ScopedSwap<IndexItem::Ptr> ScopedIndexItemPtr;
|
2014-03-13 16:53:17 +01:00
|
|
|
typedef Utils::ScopedSwap<QString> ScopedScope;
|
|
|
|
|
|
2010-07-19 14:46:53 +02:00
|
|
|
SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
|
2012-11-23 11:47:39 +01:00
|
|
|
SymbolSearcher::Classes
|
|
|
|
|
| SymbolSearcher::Functions
|
|
|
|
|
| SymbolSearcher::Enums
|
|
|
|
|
| SymbolSearcher::Declarations;
|
2010-07-19 14:46:53 +02:00
|
|
|
|
2014-05-30 12:08:03 +02:00
|
|
|
SearchSymbols::SearchSymbols(CppTools::Internal::StringTable &stringTable)
|
2014-02-25 16:16:11 +01:00
|
|
|
: strings(stringTable)
|
|
|
|
|
, symbolsToSearchFor(SymbolSearcher::Classes | SymbolSearcher::Functions | SymbolSearcher::Enums)
|
2008-11-28 15:36:54 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 18:32:38 +03:00
|
|
|
void SearchSymbols::setSymbolsToSearchFor(const SymbolTypes &types)
|
2008-11-28 15:36:54 +01:00
|
|
|
{
|
2008-12-05 09:02:08 +01:00
|
|
|
symbolsToSearchFor = types;
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-14 16:52:01 +02:00
|
|
|
IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope)
|
2008-11-28 15:36:54 +01:00
|
|
|
{
|
2014-04-14 16:52:01 +02:00
|
|
|
IndexItem::Ptr root = IndexItem::create(findOrInsert(doc->fileName()), 100);
|
2014-03-13 16:53:17 +01:00
|
|
|
|
|
|
|
|
{ // RAII scope
|
2014-04-14 16:52:01 +02:00
|
|
|
ScopedIndexItemPtr parentRaii(_parent, root);
|
2014-03-13 16:53:17 +01:00
|
|
|
QString newScope = scope;
|
|
|
|
|
ScopedScope scopeRaii(_scope, newScope);
|
|
|
|
|
|
2014-04-14 16:52:01 +02:00
|
|
|
QTC_ASSERT(_parent, return IndexItem::Ptr());
|
|
|
|
|
QTC_ASSERT(root, return IndexItem::Ptr());
|
2014-03-13 16:53:17 +01:00
|
|
|
QTC_ASSERT(_parent->fileName() == findOrInsert(doc->fileName()),
|
2014-04-14 16:52:01 +02:00
|
|
|
return IndexItem::Ptr());
|
2014-03-13 16:53:17 +01:00
|
|
|
|
|
|
|
|
for (unsigned i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)
|
|
|
|
|
accept(doc->globalSymbolAt(i));
|
|
|
|
|
|
|
|
|
|
strings.scheduleGC();
|
|
|
|
|
m_paths.clear();
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-13 16:53:17 +01:00
|
|
|
root->squeeze();
|
|
|
|
|
return root;
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(Enum *symbol)
|
|
|
|
|
{
|
2012-11-23 11:47:39 +01:00
|
|
|
if (!(symbolsToSearchFor & SymbolSearcher::Enums))
|
2008-11-28 15:36:54 +01:00
|
|
|
return false;
|
|
|
|
|
|
2014-02-25 16:57:18 +01:00
|
|
|
QString name = overview.prettyName(symbol->name());
|
2014-04-14 16:52:01 +02:00
|
|
|
IndexItem::Ptr newParent = addChildItem(name, QString(), _scope, IndexItem::Enum, symbol);
|
2014-03-13 16:53:17 +01:00
|
|
|
if (!newParent)
|
|
|
|
|
newParent = _parent;
|
2014-04-14 16:52:01 +02:00
|
|
|
ScopedIndexItemPtr parentRaii(_parent, newParent);
|
2014-03-13 16:53:17 +01:00
|
|
|
|
|
|
|
|
QString newScope = scopedSymbolName(name, symbol);
|
|
|
|
|
ScopedScope scopeRaii(_scope, newScope);
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0, ei = symbol->memberCount(); i != ei; ++i)
|
2010-08-11 12:26:02 +02:00
|
|
|
accept(symbol->memberAt(i));
|
2014-03-13 16:53:17 +01:00
|
|
|
|
2008-11-28 15:36:54 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(Function *symbol)
|
|
|
|
|
{
|
2014-07-16 16:35:03 +02:00
|
|
|
processFunction(symbol);
|
2008-11-28 15:36:54 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(Namespace *symbol)
|
|
|
|
|
{
|
2010-09-07 14:13:54 +02:00
|
|
|
QString name = scopedSymbolName(symbol);
|
2014-03-13 16:53:17 +01:00
|
|
|
QString newScope = name;
|
|
|
|
|
ScopedScope raii(_scope, newScope);
|
2010-08-11 12:26:02 +02:00
|
|
|
for (unsigned i = 0; i < symbol->memberCount(); ++i) {
|
|
|
|
|
accept(symbol->memberAt(i));
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(Declaration *symbol)
|
|
|
|
|
{
|
2013-05-15 11:20:17 +02:00
|
|
|
if (!(symbolsToSearchFor & SymbolSearcher::Declarations)) {
|
2013-06-18 11:01:56 +02:00
|
|
|
// if we're searching for functions, still allow signal declarations to show up.
|
2013-05-15 11:20:17 +02:00
|
|
|
if (symbolsToSearchFor & SymbolSearcher::Functions) {
|
2013-06-18 11:01:56 +02:00
|
|
|
Function *funTy = symbol->type()->asFunctionType();
|
2014-07-16 16:35:03 +02:00
|
|
|
if (!funTy) {
|
|
|
|
|
if (!symbol->type()->asObjCMethodType())
|
|
|
|
|
return false;
|
|
|
|
|
} else if (!funTy->isSignal()) {
|
2013-05-15 11:20:17 +02:00
|
|
|
return false;
|
2014-07-16 16:35:03 +02:00
|
|
|
}
|
2013-05-15 11:20:17 +02:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-14 21:08:08 +02:00
|
|
|
|
2014-02-25 16:57:18 +01:00
|
|
|
if (symbol->name()) {
|
|
|
|
|
QString name = overview.prettyName(symbol->name());
|
|
|
|
|
QString type = overview.prettyType(symbol->type());
|
2014-03-13 16:53:17 +01:00
|
|
|
addChildItem(name, type, _scope,
|
2014-04-14 16:52:01 +02:00
|
|
|
symbol->type()->asFunctionType() ? IndexItem::Function
|
|
|
|
|
: IndexItem::Declaration,
|
2014-03-13 16:53:17 +01:00
|
|
|
symbol);
|
2014-02-25 16:57:18 +01:00
|
|
|
}
|
|
|
|
|
|
2008-11-28 15:36:54 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(Class *symbol)
|
|
|
|
|
{
|
2014-07-16 16:35:03 +02:00
|
|
|
processClass(symbol);
|
2014-03-13 16:53:17 +01:00
|
|
|
|
2008-11-28 15:36:54 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-08 14:21:19 +02:00
|
|
|
bool SearchSymbols::visit(CPlusPlus::UsingNamespaceDirective *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::UsingDeclaration *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::NamespaceAlias *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::Argument *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::TypenameArgument *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::BaseClass *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::Template *)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::Block *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ForwardClassDeclaration *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCBaseClass *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCBaseProtocol *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 16:35:03 +02:00
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCClass *symbol)
|
2010-09-08 14:21:19 +02:00
|
|
|
{
|
2014-07-16 16:35:03 +02:00
|
|
|
processClass(symbol);
|
|
|
|
|
|
2010-09-08 14:21:19 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCForwardClassDeclaration *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 16:35:03 +02:00
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCProtocol *symbol)
|
2010-09-08 14:21:19 +02:00
|
|
|
{
|
2014-07-16 16:35:03 +02:00
|
|
|
processClass(symbol);
|
|
|
|
|
|
2010-09-08 14:21:19 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCForwardProtocolDeclaration *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 16:35:03 +02:00
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCMethod *symbol)
|
2010-09-08 14:21:19 +02:00
|
|
|
{
|
2014-07-16 16:35:03 +02:00
|
|
|
processFunction(symbol);
|
2010-09-08 14:21:19 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-16 16:35:03 +02:00
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCPropertyDeclaration *symbol)
|
2010-09-08 14:21:19 +02:00
|
|
|
{
|
2014-07-16 16:35:03 +02:00
|
|
|
processFunction(symbol);
|
2010-09-08 14:21:19 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 16:57:18 +01:00
|
|
|
QString SearchSymbols::scopedSymbolName(const QString &symbolName, const Symbol *symbol) const
|
2008-11-28 15:36:54 +01:00
|
|
|
{
|
|
|
|
|
QString name = _scope;
|
2008-12-09 16:30:47 +01:00
|
|
|
if (!name.isEmpty())
|
2008-11-28 15:36:54 +01:00
|
|
|
name += QLatin1String("::");
|
2014-02-25 16:57:18 +01:00
|
|
|
name += scopeName(symbolName, symbol);
|
2008-12-05 12:21:18 +01:00
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SearchSymbols::scopedSymbolName(const Symbol *symbol) const
|
|
|
|
|
{
|
2014-02-25 16:57:18 +01:00
|
|
|
return scopedSymbolName(overview.prettyName(symbol->name()), symbol);
|
2008-12-05 12:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-25 16:57:18 +01:00
|
|
|
QString SearchSymbols::scopeName(const QString &name, const Symbol *symbol) const
|
2008-12-05 12:21:18 +01:00
|
|
|
{
|
2014-02-25 16:57:18 +01:00
|
|
|
if (!name.isEmpty())
|
|
|
|
|
return name;
|
|
|
|
|
|
|
|
|
|
if (symbol->isNamespace()) {
|
|
|
|
|
return QLatin1String("<anonymous namespace>");
|
|
|
|
|
} else if (symbol->isEnum()) {
|
|
|
|
|
return QLatin1String("<anonymous enum>");
|
|
|
|
|
} else if (const Class *c = symbol->asClass()) {
|
|
|
|
|
if (c->isUnion())
|
|
|
|
|
return QLatin1String("<anonymous union>");
|
|
|
|
|
else if (c->isStruct())
|
|
|
|
|
return QLatin1String("<anonymous struct>");
|
|
|
|
|
else
|
|
|
|
|
return QLatin1String("<anonymous class>");
|
|
|
|
|
} else {
|
|
|
|
|
return QLatin1String("<anonymous symbol>");
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|
2008-12-05 12:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-14 16:52:01 +02:00
|
|
|
IndexItem::Ptr SearchSymbols::addChildItem(const QString &symbolName, const QString &symbolType,
|
|
|
|
|
const QString &symbolScope, IndexItem::ItemType itemType,
|
|
|
|
|
Symbol *symbol)
|
2008-12-05 12:21:18 +01:00
|
|
|
{
|
2013-08-16 12:09:50 +02:00
|
|
|
if (!symbol->name() || symbol->isGenerated())
|
2014-04-14 16:52:01 +02:00
|
|
|
return IndexItem::Ptr();
|
2008-12-09 16:30:47 +01:00
|
|
|
|
2010-09-06 16:46:23 +02:00
|
|
|
QString path = m_paths.value(symbol->fileId(), QString());
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
|
path = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
|
|
|
|
|
m_paths.insert(symbol->fileId(), path);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-05 12:21:18 +01:00
|
|
|
const QIcon icon = icons.iconForSymbol(symbol);
|
2014-04-14 16:52:01 +02:00
|
|
|
IndexItem::Ptr newItem = IndexItem::create(findOrInsert(symbolName),
|
|
|
|
|
findOrInsert(symbolType),
|
|
|
|
|
findOrInsert(symbolScope),
|
|
|
|
|
itemType,
|
|
|
|
|
findOrInsert(path),
|
|
|
|
|
symbol->line(),
|
|
|
|
|
symbol->column() - 1, // 1-based vs 0-based column
|
|
|
|
|
icon);
|
2014-03-13 16:53:17 +01:00
|
|
|
_parent->addChild(newItem);
|
|
|
|
|
return newItem;
|
|
|
|
|
}
|
2014-07-16 16:35:03 +02:00
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void SearchSymbols::processClass(T *clazz)
|
|
|
|
|
{
|
|
|
|
|
QString name = overview.prettyName(clazz->name());
|
|
|
|
|
|
|
|
|
|
IndexItem::Ptr newParent;
|
|
|
|
|
if (symbolsToSearchFor & SymbolSearcher::Classes)
|
|
|
|
|
newParent = addChildItem(name, QString(), _scope, IndexItem::Class, clazz);
|
|
|
|
|
if (!newParent)
|
|
|
|
|
newParent = _parent;
|
|
|
|
|
ScopedIndexItemPtr parentRaii(_parent, newParent);
|
|
|
|
|
|
|
|
|
|
QString newScope = scopedSymbolName(name, clazz);
|
|
|
|
|
ScopedScope scopeRaii(_scope, newScope);
|
|
|
|
|
for (unsigned i = 0, ei = clazz->memberCount(); i != ei; ++i)
|
|
|
|
|
accept(clazz->memberAt(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void SearchSymbols::processFunction(T *func)
|
|
|
|
|
{
|
|
|
|
|
if (!(symbolsToSearchFor & SymbolSearcher::Functions) || !func->name())
|
|
|
|
|
return;
|
|
|
|
|
QString name = overview.prettyName(func->name());
|
|
|
|
|
QString type = overview.prettyType(func->type());
|
|
|
|
|
addChildItem(name, type, _scope, IndexItem::Function, func);
|
|
|
|
|
}
|