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>
|
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
|
|
|
|
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
|
|
|
|
2013-08-20 17:16:25 +02:00
|
|
|
SearchSymbols::SearchSymbols() :
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2013-02-26 11:14:02 +01:00
|
|
|
QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, int sizeHint, const QString &scope)
|
2008-11-28 15:36:54 +01:00
|
|
|
{
|
|
|
|
|
QString previousScope = switchScope(scope);
|
|
|
|
|
items.clear();
|
2013-02-26 11:14:02 +01:00
|
|
|
items.reserve(sizeHint);
|
2008-11-28 15:36:54 +01:00
|
|
|
for (unsigned i = 0; i < doc->globalSymbolCount(); ++i) {
|
|
|
|
|
accept(doc->globalSymbolAt(i));
|
|
|
|
|
}
|
|
|
|
|
(void) switchScope(previousScope);
|
2010-09-07 14:13:54 +02:00
|
|
|
QList<ModelItemInfo> result = items;
|
2010-09-06 16:46:23 +02:00
|
|
|
strings.clear();
|
2010-09-07 14:13:54 +02:00
|
|
|
items.clear();
|
|
|
|
|
m_paths.clear();
|
|
|
|
|
return result;
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SearchSymbols::switchScope(const QString &scope)
|
|
|
|
|
{
|
|
|
|
|
QString previousScope = _scope;
|
|
|
|
|
_scope = scope;
|
|
|
|
|
return previousScope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
QString name = symbolName(symbol);
|
2008-12-05 12:21:18 +01:00
|
|
|
QString scopedName = scopedSymbolName(name);
|
|
|
|
|
QString previousScope = switchScope(scopedName);
|
2013-08-20 17:16:25 +02:00
|
|
|
appendItem(name, QString(), previousScope, ModelItemInfo::Enum, symbol);
|
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
|
|
|
}
|
|
|
|
|
(void) switchScope(previousScope);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(Function *symbol)
|
|
|
|
|
{
|
2012-11-23 11:47:39 +01:00
|
|
|
if (!(symbolsToSearchFor & SymbolSearcher::Functions))
|
2008-11-28 15:36:54 +01:00
|
|
|
return false;
|
|
|
|
|
QString name = symbolName(symbol);
|
2013-08-20 17:16:25 +02:00
|
|
|
QString type = overview.prettyType(symbol->type());
|
2014-03-29 21:13:26 +03:00
|
|
|
appendItem(name, type, _scope, ModelItemInfo::Function, 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);
|
2008-11-28 15:36:54 +01:00
|
|
|
QString previousScope = switchScope(name);
|
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
|
|
|
}
|
|
|
|
|
(void) switchScope(previousScope);
|
|
|
|
|
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();
|
|
|
|
|
if (!funTy)
|
|
|
|
|
return false;
|
|
|
|
|
if (!funTy->isSignal())
|
2013-05-15 11:20:17 +02:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-14 21:08:08 +02:00
|
|
|
|
|
|
|
|
QString name = symbolName(symbol);
|
2013-08-20 17:16:25 +02:00
|
|
|
QString type = overview.prettyType(symbol->type());
|
|
|
|
|
appendItem(name, type, _scope,
|
2014-03-29 21:13:26 +03:00
|
|
|
symbol->type()->asFunctionType() ? ModelItemInfo::Function
|
2013-05-15 11:20:17 +02:00
|
|
|
: ModelItemInfo::Declaration,
|
|
|
|
|
symbol);
|
2008-11-28 15:36:54 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(Class *symbol)
|
|
|
|
|
{
|
|
|
|
|
QString name = symbolName(symbol);
|
2008-12-05 12:21:18 +01:00
|
|
|
QString scopedName = scopedSymbolName(name);
|
|
|
|
|
QString previousScope = switchScope(scopedName);
|
2013-11-11 22:20:47 +02:00
|
|
|
if (symbolsToSearchFor & SymbolSearcher::Classes)
|
2013-08-20 17:16:25 +02:00
|
|
|
appendItem(name, QString(), previousScope, ModelItemInfo::Class, symbol);
|
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
|
|
|
}
|
|
|
|
|
(void) switchScope(previousScope);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCClass *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCForwardClassDeclaration *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCProtocol *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCForwardProtocolDeclaration *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCMethod *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchSymbols::visit(CPlusPlus::ObjCPropertyDeclaration *)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-05 12:21:18 +01:00
|
|
|
QString SearchSymbols::scopedSymbolName(const QString &symbolName) 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("::");
|
2008-12-05 12:21:18 +01:00
|
|
|
name += symbolName;
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SearchSymbols::scopedSymbolName(const Symbol *symbol) const
|
|
|
|
|
{
|
|
|
|
|
return scopedSymbolName(symbolName(symbol));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SearchSymbols::symbolName(const Symbol *symbol) const
|
|
|
|
|
{
|
2008-11-28 15:36:54 +01:00
|
|
|
QString symbolName = overview.prettyName(symbol->name());
|
|
|
|
|
if (symbolName.isEmpty()) {
|
|
|
|
|
QString type;
|
|
|
|
|
if (symbol->isNamespace()) {
|
|
|
|
|
type = QLatin1String("namespace");
|
|
|
|
|
} else if (symbol->isEnum()) {
|
|
|
|
|
type = QLatin1String("enum");
|
|
|
|
|
} else if (const Class *c = symbol->asClass()) {
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (c->isUnion())
|
2008-11-28 15:36:54 +01:00
|
|
|
type = QLatin1String("union");
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (c->isStruct())
|
2008-11-28 15:36:54 +01:00
|
|
|
type = QLatin1String("struct");
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2008-11-28 15:36:54 +01:00
|
|
|
type = QLatin1String("class");
|
|
|
|
|
} else {
|
|
|
|
|
type = QLatin1String("symbol");
|
|
|
|
|
}
|
|
|
|
|
symbolName = QLatin1String("<anonymous ");
|
|
|
|
|
symbolName += type;
|
2010-02-01 12:43:56 +01:00
|
|
|
symbolName += QLatin1Char('>');
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|
2008-12-05 12:21:18 +01:00
|
|
|
return symbolName;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-20 17:16:25 +02:00
|
|
|
void SearchSymbols::appendItem(const QString &symbolName, const QString &symbolType,
|
|
|
|
|
const QString &symbolScope, ModelItemInfo::ItemType itemType,
|
2010-07-19 14:46:53 +02:00
|
|
|
Symbol *symbol)
|
2008-12-05 12:21:18 +01:00
|
|
|
{
|
2013-08-16 12:09:50 +02:00
|
|
|
if (!symbol->name() || symbol->isGenerated())
|
2008-12-09 16:30:47 +01:00
|
|
|
return;
|
|
|
|
|
|
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);
|
2013-08-20 17:16:25 +02:00
|
|
|
items.append(ModelItemInfo(findOrInsert(symbolName),
|
|
|
|
|
findOrInsert(symbolType),
|
|
|
|
|
findOrInsert(symbolScope),
|
|
|
|
|
itemType,
|
2010-09-06 16:46:23 +02:00
|
|
|
path,
|
2008-12-05 12:21:18 +01:00
|
|
|
symbol->line(),
|
2010-07-20 12:21:27 +02:00
|
|
|
symbol->column() - 1, // 1-based vs 0-based column
|
2008-12-05 12:21:18 +01:00
|
|
|
icon));
|
2008-11-28 15:36:54 +01:00
|
|
|
}
|