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
|
|
|
|
|
|
|
|
#ifndef SEARCHSYMBOLS_H
|
|
|
|
|
#define SEARCHSYMBOLS_H
|
|
|
|
|
|
2011-11-25 12:05:58 +01:00
|
|
|
#include "cpptools_global.h"
|
2012-11-23 11:47:39 +01:00
|
|
|
#include "cppindexingsupport.h"
|
|
|
|
|
|
2008-11-28 15:36:54 +01:00
|
|
|
#include <cplusplus/CppDocument.h>
|
|
|
|
|
#include <cplusplus/Icons.h>
|
|
|
|
|
#include <cplusplus/Overview.h>
|
|
|
|
|
|
2013-08-20 17:16:25 +02:00
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QHash>
|
2008-11-28 15:36:54 +01:00
|
|
|
|
2008-12-05 16:39:33 +01:00
|
|
|
#include <functional>
|
|
|
|
|
|
2008-11-28 15:36:54 +01:00
|
|
|
namespace CppTools {
|
|
|
|
|
|
2011-11-25 12:05:58 +01:00
|
|
|
struct CPPTOOLS_EXPORT ModelItemInfo
|
2008-11-28 15:36:54 +01:00
|
|
|
{
|
2014-03-29 21:13:26 +03:00
|
|
|
enum ItemType { Enum, Class, Function, Declaration };
|
2008-11-28 15:36:54 +01:00
|
|
|
|
|
|
|
|
ModelItemInfo()
|
2009-10-21 16:47:28 +02:00
|
|
|
: type(Declaration),
|
2010-07-19 14:46:53 +02:00
|
|
|
line(0),
|
|
|
|
|
column(0)
|
2008-11-28 15:36:54 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
ModelItemInfo(const QString &symbolName,
|
|
|
|
|
const QString &symbolType,
|
2013-08-20 17:16:25 +02:00
|
|
|
const QString &symbolScope,
|
2008-11-28 15:36:54 +01:00
|
|
|
ItemType type,
|
|
|
|
|
const QString &fileName,
|
|
|
|
|
int line,
|
2010-07-20 12:21:27 +02:00
|
|
|
int column,
|
2008-11-28 15:36:54 +01:00
|
|
|
const QIcon &icon)
|
|
|
|
|
: symbolName(symbolName),
|
|
|
|
|
symbolType(symbolType),
|
2013-08-20 17:16:25 +02:00
|
|
|
symbolScope(symbolScope),
|
2008-11-28 15:36:54 +01:00
|
|
|
fileName(fileName),
|
2010-09-06 16:46:23 +02:00
|
|
|
icon(icon),
|
|
|
|
|
type(type),
|
2008-11-28 15:36:54 +01:00
|
|
|
line(line),
|
2010-09-06 16:46:23 +02:00
|
|
|
column(column)
|
2008-11-28 15:36:54 +01:00
|
|
|
{ }
|
|
|
|
|
|
2010-07-19 14:46:53 +02:00
|
|
|
ModelItemInfo(const ModelItemInfo &otherInfo)
|
|
|
|
|
: symbolName(otherInfo.symbolName),
|
|
|
|
|
symbolType(otherInfo.symbolType),
|
2013-08-20 17:16:25 +02:00
|
|
|
symbolScope(otherInfo.symbolScope),
|
2010-07-19 14:46:53 +02:00
|
|
|
fileName(otherInfo.fileName),
|
2010-09-06 16:46:23 +02:00
|
|
|
icon(otherInfo.icon),
|
|
|
|
|
type(otherInfo.type),
|
2010-07-19 14:46:53 +02:00
|
|
|
line(otherInfo.line),
|
2010-09-06 16:46:23 +02:00
|
|
|
column(otherInfo.column)
|
2013-08-20 17:16:25 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QString scopedSymbolName() const
|
|
|
|
|
{
|
|
|
|
|
return symbolScope.isEmpty()
|
|
|
|
|
? symbolName
|
|
|
|
|
: symbolScope + QLatin1String("::") + symbolName;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-23 10:51:39 +02:00
|
|
|
bool unqualifiedNameAndScope(const QString &defaultName, QString *name, QString *scope) const
|
2013-09-12 14:06:36 +02:00
|
|
|
{
|
|
|
|
|
*name = defaultName;
|
|
|
|
|
*scope = symbolScope;
|
|
|
|
|
const QString qualifiedName = scopedSymbolName();
|
|
|
|
|
const int colonColonPosition = qualifiedName.lastIndexOf(QLatin1String("::"));
|
|
|
|
|
if (colonColonPosition != -1) {
|
|
|
|
|
*name = qualifiedName.mid(colonColonPosition + 2);
|
|
|
|
|
*scope = qualifiedName.left(colonColonPosition);
|
2013-09-23 10:51:39 +02:00
|
|
|
return true;
|
2013-09-12 14:06:36 +02:00
|
|
|
}
|
2013-09-23 10:51:39 +02:00
|
|
|
return false;
|
2013-09-12 14:06:36 +02:00
|
|
|
}
|
|
|
|
|
|
2013-09-12 15:26:55 +02:00
|
|
|
static QString representDeclaration(const QString &name, const QString &type)
|
2013-08-20 17:16:25 +02:00
|
|
|
{
|
2013-09-12 15:26:55 +02:00
|
|
|
if (type.isEmpty())
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
const QString padding = type.endsWith(QLatin1Char('*'))
|
|
|
|
|
? QString()
|
|
|
|
|
: QString(QLatin1Char(' '));
|
|
|
|
|
return type + padding + name;
|
2013-08-20 17:16:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString shortNativeFilePath() const
|
|
|
|
|
{ return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(fileName)); }
|
2010-07-19 14:46:53 +02:00
|
|
|
|
2013-09-12 14:06:36 +02:00
|
|
|
QString symbolName; // as found in the code, therefore might be qualified
|
2008-11-28 15:36:54 +01:00
|
|
|
QString symbolType;
|
2013-08-20 17:16:25 +02:00
|
|
|
QString symbolScope;
|
2008-11-28 15:36:54 +01:00
|
|
|
QString fileName;
|
2010-09-06 16:46:23 +02:00
|
|
|
QIcon icon;
|
|
|
|
|
ItemType type;
|
2008-11-28 15:36:54 +01:00
|
|
|
int line;
|
2010-07-20 12:21:27 +02:00
|
|
|
int column;
|
2008-11-28 15:36:54 +01:00
|
|
|
};
|
|
|
|
|
|
2013-02-26 11:14:02 +01:00
|
|
|
class SearchSymbols: public std::binary_function<CPlusPlus::Document::Ptr, int, QList<ModelItemInfo> >,
|
2008-11-28 15:36:54 +01:00
|
|
|
protected CPlusPlus::SymbolVisitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-11-23 11:47:39 +01:00
|
|
|
typedef SymbolSearcher::SymbolTypes SymbolTypes;
|
2008-11-28 15:36:54 +01:00
|
|
|
|
2010-07-19 14:46:53 +02:00
|
|
|
static SymbolTypes AllTypes;
|
|
|
|
|
|
2008-11-28 15:36:54 +01:00
|
|
|
SearchSymbols();
|
|
|
|
|
|
2014-05-19 18:32:38 +03:00
|
|
|
void setSymbolsToSearchFor(const SymbolTypes &types);
|
2008-11-28 15:36:54 +01:00
|
|
|
|
2013-02-26 11:14:02 +01:00
|
|
|
QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc, int sizeHint = 500)
|
|
|
|
|
{ return operator()(doc, sizeHint, QString()); }
|
2008-11-28 15:36:54 +01:00
|
|
|
|
2013-02-26 11:14:02 +01:00
|
|
|
QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc, int sizeHint, const QString &scope);
|
2008-11-28 15:36:54 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
using SymbolVisitor::visit;
|
|
|
|
|
|
|
|
|
|
void accept(CPlusPlus::Symbol *symbol)
|
|
|
|
|
{ CPlusPlus::Symbol::visitSymbol(symbol, this); }
|
|
|
|
|
|
|
|
|
|
QString switchScope(const QString &scope);
|
2010-09-08 14:21:19 +02:00
|
|
|
|
|
|
|
|
virtual bool visit(CPlusPlus::UsingNamespaceDirective *);
|
|
|
|
|
virtual bool visit(CPlusPlus::UsingDeclaration *);
|
|
|
|
|
virtual bool visit(CPlusPlus::NamespaceAlias *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Declaration *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Argument *);
|
|
|
|
|
virtual bool visit(CPlusPlus::TypenameArgument *);
|
|
|
|
|
virtual bool visit(CPlusPlus::BaseClass *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Enum *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Function *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Namespace *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Template *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Class *);
|
|
|
|
|
virtual bool visit(CPlusPlus::Block *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ForwardClassDeclaration *);
|
|
|
|
|
|
|
|
|
|
// Objective-C
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCBaseClass *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCBaseProtocol *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCClass *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCForwardClassDeclaration *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCProtocol *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCForwardProtocolDeclaration *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCMethod *);
|
|
|
|
|
virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *);
|
2008-12-05 12:21:18 +01:00
|
|
|
|
2014-02-25 16:57:18 +01:00
|
|
|
QString scopedSymbolName(const QString &symbolName, const CPlusPlus::Symbol *symbol) const;
|
2008-12-05 12:21:18 +01:00
|
|
|
QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
|
2014-02-25 16:57:18 +01:00
|
|
|
QString scopeName(const QString &name, const CPlusPlus::Symbol *symbol) const;
|
2013-08-20 17:16:25 +02:00
|
|
|
void appendItem(const QString &symbolName,
|
|
|
|
|
const QString &symbolType,
|
|
|
|
|
const QString &symbolScope,
|
2008-12-05 12:21:18 +01:00
|
|
|
ModelItemInfo::ItemType type,
|
2010-07-19 14:46:53 +02:00
|
|
|
CPlusPlus::Symbol *symbol);
|
2008-11-28 15:36:54 +01:00
|
|
|
|
|
|
|
|
private:
|
2008-12-05 12:21:18 +01:00
|
|
|
QString findOrInsert(const QString &s)
|
|
|
|
|
{ return *strings.insert(s); }
|
|
|
|
|
|
|
|
|
|
QSet<QString> strings; // Used to avoid QString duplication
|
|
|
|
|
|
2008-11-28 15:36:54 +01:00
|
|
|
QString _scope;
|
|
|
|
|
CPlusPlus::Overview overview;
|
|
|
|
|
CPlusPlus::Icons icons;
|
|
|
|
|
QList<ModelItemInfo> items;
|
2008-12-05 09:02:08 +01:00
|
|
|
SymbolTypes symbolsToSearchFor;
|
2010-09-06 16:46:23 +02:00
|
|
|
QHash<const CPlusPlus::StringLiteral *, QString> m_paths;
|
2008-11-28 15:36:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace CppTools
|
|
|
|
|
|
2011-11-25 12:05:58 +01:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes)
|
|
|
|
|
Q_DECLARE_METATYPE(CppTools::ModelItemInfo)
|
2008-11-28 15:36:54 +01:00
|
|
|
|
|
|
|
|
#endif // SEARCHSYMBOLS_H
|