OSDN Git Service

313fc54483c68b2970a8bac61d1ad1628d7c287b
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cpptools / searchsymbols.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef SEARCHSYMBOLS_H
35 #define SEARCHSYMBOLS_H
36
37 #include <cplusplus/CppDocument.h>
38 #include <cplusplus/Icons.h>
39 #include <cplusplus/Overview.h>
40 #include <Symbols.h>
41 #include <SymbolVisitor.h>
42
43 #include <QtGui/QIcon>
44 #include <QtCore/QMetaType>
45 #include <QtCore/QString>
46 #include <QtCore/QSet>
47 #include <QtCore/QHash>
48
49 #include <functional>
50
51 namespace CppTools {
52 namespace Internal {
53
54 struct ModelItemInfo
55 {
56     enum ItemType { Enum, Class, Method, Declaration };
57
58     ModelItemInfo()
59         : type(Declaration),
60           line(0),
61           column(0)
62     { }
63
64     ModelItemInfo(const QString &symbolName,
65                   const QString &symbolType,
66                   ItemType type,
67                   QStringList fullyQualifiedName,
68                   const QString &fileName,
69                   int line,
70                   int column,
71                   const QIcon &icon)
72         : symbolName(symbolName),
73           symbolType(symbolType),
74           fullyQualifiedName(fullyQualifiedName),
75           fileName(fileName),
76           icon(icon),
77           type(type),
78           line(line),
79           column(column)
80     { }
81
82     ModelItemInfo(const ModelItemInfo &otherInfo)
83         : symbolName(otherInfo.symbolName),
84           symbolType(otherInfo.symbolType),
85           fullyQualifiedName(otherInfo.fullyQualifiedName),
86           fileName(otherInfo.fileName),
87           icon(otherInfo.icon),
88           type(otherInfo.type),
89           line(otherInfo.line),
90           column(otherInfo.column)
91     {  }
92
93     QString symbolName;
94     QString symbolType;
95     QStringList fullyQualifiedName;
96     QString fileName;
97     QIcon icon;
98     ItemType type;
99     int line;
100     int column;
101 };
102
103 class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList<ModelItemInfo> >,
104                      protected CPlusPlus::SymbolVisitor
105 {
106 public:
107     enum SymbolType {
108         Classes      = 0x1,
109         Functions    = 0x2,
110         Enums        = 0x4,
111         Declarations = 0x8
112     };
113
114     Q_DECLARE_FLAGS(SymbolTypes, SymbolType)
115
116     static SymbolTypes AllTypes;
117
118     SearchSymbols();
119
120     void setSymbolsToSearchFor(SymbolTypes types);
121     void setSeparateScope(bool separateScope);
122
123     QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc)
124     { return operator()(doc, QString()); }
125
126     QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc, const QString &scope);
127
128 protected:
129     using SymbolVisitor::visit;
130
131     void accept(CPlusPlus::Symbol *symbol)
132     { CPlusPlus::Symbol::visitSymbol(symbol, this); }
133
134     QString switchScope(const QString &scope);
135
136     virtual bool visit(CPlusPlus::UsingNamespaceDirective *);
137     virtual bool visit(CPlusPlus::UsingDeclaration *);
138     virtual bool visit(CPlusPlus::NamespaceAlias *);
139     virtual bool visit(CPlusPlus::Declaration *);
140     virtual bool visit(CPlusPlus::Argument *);
141     virtual bool visit(CPlusPlus::TypenameArgument *);
142     virtual bool visit(CPlusPlus::BaseClass *);
143     virtual bool visit(CPlusPlus::Enum *);
144     virtual bool visit(CPlusPlus::Function *);
145     virtual bool visit(CPlusPlus::Namespace *);
146     virtual bool visit(CPlusPlus::Template *);
147     virtual bool visit(CPlusPlus::Class *);
148     virtual bool visit(CPlusPlus::Block *);
149     virtual bool visit(CPlusPlus::ForwardClassDeclaration *);
150
151     // Objective-C
152     virtual bool visit(CPlusPlus::ObjCBaseClass *);
153     virtual bool visit(CPlusPlus::ObjCBaseProtocol *);
154     virtual bool visit(CPlusPlus::ObjCClass *);
155     virtual bool visit(CPlusPlus::ObjCForwardClassDeclaration *);
156     virtual bool visit(CPlusPlus::ObjCProtocol *);
157     virtual bool visit(CPlusPlus::ObjCForwardProtocolDeclaration *);
158     virtual bool visit(CPlusPlus::ObjCMethod *);
159     virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *);
160
161     QString scopedSymbolName(const QString &symbolName) const;
162     QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
163     QString symbolName(const CPlusPlus::Symbol *symbol) const;
164     void appendItem(const QString &name,
165                     const QString &info,
166                     ModelItemInfo::ItemType type,
167                     CPlusPlus::Symbol *symbol);
168
169 private:
170     QString findOrInsert(const QString &s)
171     { return *strings.insert(s); }
172
173     QSet<QString> strings;            // Used to avoid QString duplication
174
175     QString _scope;
176     CPlusPlus::Overview overview;
177     CPlusPlus::Icons icons;
178     QList<ModelItemInfo> items;
179     SymbolTypes symbolsToSearchFor;
180     QHash<const CPlusPlus::StringLiteral *, QString> m_paths;
181     bool separateScope;
182 };
183
184 } // namespace Internal
185 } // namespace CppTools
186
187 Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::Internal::SearchSymbols::SymbolTypes)
188 Q_DECLARE_METATYPE(CppTools::Internal::ModelItemInfo)
189
190 #endif // SEARCHSYMBOLS_H