searchsymbols.h 4.58 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30 31 32

#ifndef SEARCHSYMBOLS_H
#define SEARCHSYMBOLS_H

33
#include "cpptools_global.h"
34
#include "cppindexingsupport.h"
35
#include "indexitem.h"
36
#include "stringtable.h"
37

38 39 40 41
#include <cplusplus/CppDocument.h>
#include <cplusplus/Icons.h>
#include <cplusplus/Overview.h>

42 43 44
#include <QString>
#include <QSet>
#include <QHash>
45 46 47

namespace CppTools {

48
class SearchSymbols: protected CPlusPlus::SymbolVisitor
49 50
{
public:
51
    typedef SymbolSearcher::SymbolTypes SymbolTypes;
52

53 54
    static SymbolTypes AllTypes;

55
    SearchSymbols(Internal::StringTable &stringTable);
56

57
    void setSymbolsToSearchFor(const SymbolTypes &types);
58

59 60
    IndexItem::Ptr operator()(CPlusPlus::Document::Ptr doc)
    { return operator()(doc, QString()); }
61

62
    IndexItem::Ptr operator()(CPlusPlus::Document::Ptr doc, const QString &scope);
63 64 65 66 67 68 69

protected:
    using SymbolVisitor::visit;

    void accept(CPlusPlus::Symbol *symbol)
    { CPlusPlus::Symbol::visitSymbol(symbol, this); }

Roberto Raggi's avatar
Roberto Raggi committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    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 *);
88
    virtual bool visit(CPlusPlus::ObjCClass *symbol);
Roberto Raggi's avatar
Roberto Raggi committed
89
    virtual bool visit(CPlusPlus::ObjCForwardClassDeclaration *);
90
    virtual bool visit(CPlusPlus::ObjCProtocol *symbol);
Roberto Raggi's avatar
Roberto Raggi committed
91
    virtual bool visit(CPlusPlus::ObjCForwardProtocolDeclaration *);
92 93
    virtual bool visit(CPlusPlus::ObjCMethod *symbol);
    virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *symbol);
94

95
    QString scopedSymbolName(const QString &symbolName, const CPlusPlus::Symbol *symbol) const;
96
    QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
97
    QString scopeName(const QString &name, const CPlusPlus::Symbol *symbol) const;
98 99 100
    IndexItem::Ptr addChildItem(const QString &symbolName, const QString &symbolType,
                                const QString &symbolScope, IndexItem::ItemType type,
                                CPlusPlus::Symbol *symbol);
101

102 103 104 105
private:
    template<class T> void processClass(T *clazz);
    template<class T> void processFunction(T *func);

106
private:
107
    QString findOrInsert(const QString &s)
108
    { return strings.insert(s); }
109

110
    Internal::StringTable &strings;            // Used to avoid QString duplication
111

112
    IndexItem::Ptr _parent;
113 114 115
    QString _scope;
    CPlusPlus::Overview overview;
    CPlusPlus::Icons icons;
116
    SymbolTypes symbolsToSearchFor;
117
    QHash<const CPlusPlus::StringLiteral *, QString> m_paths;
118 119 120 121
};

} // namespace CppTools

122
Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes)
123 124

#endif // SEARCHSYMBOLS_H