OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / Symbol.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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
33 //
34 // Permission is hereby granted, free of charge, to any person obtaining a copy
35 // of this software and associated documentation files (the "Software"), to deal
36 // in the Software without restriction, including without limitation the rights
37 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38 // copies of the Software, and to permit persons to whom the Software is
39 // furnished to do so, subject to the following conditions:
40 //
41 // The above copyright notice and this permission notice shall be included in
42 // all copies or substantial portions of the Software.
43 //
44 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
50 // THE SOFTWARE.
51
52 #ifndef CPLUSPLUS_SYMBOL_H
53 #define CPLUSPLUS_SYMBOL_H
54
55 #include "CPlusPlusForwardDeclarations.h"
56
57
58 namespace CPlusPlus {
59
60 class CPLUSPLUS_EXPORT Symbol
61 {
62     Symbol(const Symbol &other);
63     void operator =(const Symbol &other);
64
65 public:
66     /// Storage class specifier
67     enum Storage {
68         NoStorage = 0,
69         Friend,
70         Auto,
71         Register,
72         Static,
73         Extern,
74         Mutable,
75         Typedef
76     };
77
78     /// Access specifier.
79     enum Visibility {
80         Public,
81         Protected,
82         Private,
83         Package
84     };
85
86 public:
87     /// Constructs a Symbol with the given source location, name and translation unit.
88     Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
89
90     /// Destroy this Symbol.
91     virtual ~Symbol();
92
93     /// Returns this Symbol's source location.
94     unsigned sourceLocation() const;
95
96     /// \returns this Symbol's line number. The line number is 1-based.
97     unsigned line() const;
98
99     /// \returns this Symbol's column number. The column number is 1-based.
100     unsigned column() const;
101
102     /// Returns this Symbol's file name.
103     const StringLiteral *fileId() const;
104
105     /// Returns this Symbol's file name.
106     const char *fileName() const;
107
108     /// Returns this Symbol's file name length.
109     unsigned fileNameLength() const;
110
111     /// Returns this Symbol's name.
112     const Name *name() const;
113
114     /// Sets this Symbol's name.
115     void setName(const Name *name); // ### dangerous
116
117     /// Returns this Symbol's (optional) identifier
118     const Identifier *identifier() const;
119
120     /// Returns this Symbol's storage class specifier.
121     int storage() const;
122
123     /// Sets this Symbol's storage class specifier.
124     void setStorage(int storage);
125
126     /// Returns this Symbol's visibility.
127     int visibility() const;
128
129     /// Sets this Symbol's visibility.
130     void setVisibility(int visibility);
131
132     /// Returns the next chained Symbol.
133     Symbol *next() const;
134
135     /// Returns true if this Symbol has friend storage specifier.
136     bool isFriend() const;
137
138     /// Returns true if this Symbol has register storage specifier.
139     bool isRegister() const;
140
141     /// Returns true if this Symbol has static storage specifier.
142     bool isStatic() const;
143
144     /// Returns true if this Symbol has extern storage specifier.
145     bool isExtern() const;
146
147     /// Returns true if this Symbol has mutable storage specifier.
148     bool isMutable() const;
149
150     /// Returns true if this Symbol has typedef storage specifier.
151     bool isTypedef() const;
152
153     /// Returns true if this Symbol's visibility is public.
154     bool isPublic() const;
155
156     /// Returns true if this Symbol's visibility is protected.
157     bool isProtected() const;
158
159     /// Returns true if this Symbol's visibility is private.
160     bool isPrivate() const;
161
162     /// Returns true if this Symbol is a Scope.
163     bool isScope() const;
164
165     /// Returns true if this Symbol is an Enum.
166     bool isEnum() const;
167
168     /// Returns true if this Symbol is an Function.
169     bool isFunction() const;
170
171     /// Returns true if this Symbol is a Namespace.
172     bool isNamespace() const;
173
174     /// Returns true if this Symbol is a Template.
175     bool isTemplate() const;
176
177     /// Returns true if this Symbol is a Class.
178     bool isClass() const;
179
180     /// Returns true if this Symbol is a Block.
181     bool isBlock() const;
182
183     /// Returns true if this Symbol is a UsingNamespaceDirective.
184     bool isUsingNamespaceDirective() const;
185
186     /// Returns true if this Symbol is a UsingDeclaration.
187     bool isUsingDeclaration() const;
188
189     /// Returns true if this Symbol is a Declaration.
190     bool isDeclaration() const;
191
192     /// Returns true if this Symbol is an Argument.
193     bool isArgument() const;
194
195     /// Returns true if this Symbol is a Typename argument.
196     bool isTypenameArgument() const;
197
198     /// Returns true if this Symbol is a BaseClass.
199     bool isBaseClass() const;
200
201     /// Returns true if this Symbol is a ForwardClassDeclaration.
202     bool isForwardClassDeclaration() const;
203
204     /// Returns true if this Symbol is a QtPropertyDeclaration.
205     bool isQtPropertyDeclaration() const;
206
207     /// Returns true if this Symbol is a QtEnum.
208     bool isQtEnum() const;
209
210     bool isObjCBaseClass() const;
211     bool isObjCBaseProtocol() const;
212
213     /// Returns true if this Symbol is an Objective-C Class declaration.
214     bool isObjCClass() const;
215
216     /// Returns true if this Symbol is an Objective-C Class forward declaration.
217     bool isObjCForwardClassDeclaration() const;
218
219     /// Returns true if this Symbol is an Objective-C Protocol declaration.
220     bool isObjCProtocol() const;
221
222     /// Returns true if this Symbol is an Objective-C Protocol forward declaration.
223     bool isObjCForwardProtocolDeclaration() const;
224
225     /// Returns true if this Symbol is an Objective-C method declaration.
226     bool isObjCMethod() const;
227
228     /// Returns true if this Symbol is an Objective-C @property declaration.
229     bool isObjCPropertyDeclaration() const;
230
231     virtual const Scope *asScope() const { return 0; }
232     virtual const Enum *asEnum() const { return 0; }
233     virtual const Function *asFunction() const { return 0; }
234     virtual const Namespace *asNamespace() const { return 0; }
235     virtual const Template *asTemplate() const { return 0; }
236     virtual const NamespaceAlias *asNamespaceAlias() const { return 0; }
237     virtual const Class *asClass() const { return 0; }
238     virtual const Block *asBlock() const { return 0; }
239     virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const { return 0; }
240     virtual const UsingDeclaration *asUsingDeclaration() const { return 0; }
241     virtual const Declaration *asDeclaration() const { return 0; }
242     virtual const Argument *asArgument() const { return 0; }
243     virtual const TypenameArgument *asTypenameArgument() const { return 0; }
244     virtual const BaseClass *asBaseClass() const { return 0; }
245     virtual const ForwardClassDeclaration *asForwardClassDeclaration() const { return 0; }
246     virtual const QtPropertyDeclaration *asQtPropertyDeclaration() const { return 0; }
247     virtual const QtEnum *asQtEnum() const { return 0; }
248     virtual const ObjCBaseClass *asObjCBaseClass() const { return 0; }
249     virtual const ObjCBaseProtocol *asObjCBaseProtocol() const { return 0; }
250     virtual const ObjCClass *asObjCClass() const { return 0; }
251     virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const { return 0; }
252     virtual const ObjCProtocol *asObjCProtocol() const { return 0; }
253     virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const { return 0; }
254     virtual const ObjCMethod *asObjCMethod() const { return 0; }
255     virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const { return 0; }
256
257     virtual Scope *asScope() { return 0; }
258     virtual Enum *asEnum() { return 0; }
259     virtual Function *asFunction() { return 0; }
260     virtual Namespace *asNamespace() { return 0; }
261     virtual Template *asTemplate() { return 0; }
262     virtual NamespaceAlias *asNamespaceAlias() { return 0; }
263     virtual Class *asClass() { return 0; }
264     virtual Block *asBlock() { return 0; }
265     virtual UsingNamespaceDirective *asUsingNamespaceDirective() { return 0; }
266     virtual UsingDeclaration *asUsingDeclaration() { return 0; }
267     virtual Declaration *asDeclaration() { return 0; }
268     virtual Argument *asArgument() { return 0; }
269     virtual TypenameArgument *asTypenameArgument() { return 0; }
270     virtual BaseClass *asBaseClass() { return 0; }
271     virtual ForwardClassDeclaration *asForwardClassDeclaration() { return 0; }
272     virtual QtPropertyDeclaration *asQtPropertyDeclaration() { return 0; }
273     virtual QtEnum *asQtEnum() { return 0; }
274     virtual ObjCBaseClass *asObjCBaseClass() { return 0; }
275     virtual ObjCBaseProtocol *asObjCBaseProtocol() { return 0; }
276     virtual ObjCClass *asObjCClass() { return 0; }
277     virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() { return 0; }
278     virtual ObjCProtocol *asObjCProtocol() { return 0; }
279     virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() { return 0; }
280     virtual ObjCMethod *asObjCMethod() { return 0; }
281     virtual ObjCPropertyDeclaration *asObjCPropertyDeclaration() { return 0; }
282
283     /// Returns this Symbol's type.
284     virtual FullySpecifiedType type() const = 0;
285
286     /// Returns this Symbol's hash value.
287     unsigned hashCode() const;
288
289     /// Returns this Symbol's index.
290     unsigned index() const;
291
292     const Name *unqualifiedName() const;
293
294     bool isGenerated() const;
295
296     bool isDeprecated() const;
297     void setDeprecated(bool isDeprecated);
298
299     bool isUnavailable() const;
300     void setUnavailable(bool isUnavailable);
301
302     /// Returns this Symbol's eclosing scope.
303     Scope *enclosingScope() const;
304
305     /// Returns the eclosing namespace scope.
306     Namespace *enclosingNamespace() const;
307
308     /// Returns the eclosing template scope.
309     Template *enclosingTemplate() const;
310
311     /// Returns the enclosing class scope.
312     Class *enclosingClass() const;
313
314     /// Returns the enclosing enum scope.
315     Enum *enclosingEnum() const;
316
317     /// Returns the enclosing prototype scope.
318     Function *enclosingFunction() const;
319
320     /// Returns the enclosing Block scope.
321     Block *enclosingBlock() const;
322
323     void setScope(Scope *enclosingScope); // ### make me private
324     void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private
325
326     void visitSymbol(SymbolVisitor *visitor);
327     static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
328
329     virtual void copy(Symbol *other);
330
331 protected:
332     virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
333
334 private:
335     const Name *_name;
336     Scope *_scope;
337     Symbol *_next;
338     const StringLiteral *_fileId;
339     unsigned _sourceLocation;
340     unsigned _hashCode;
341     int _storage;
342     int _visibility;
343     unsigned _index;
344     unsigned _line;
345     unsigned _column;
346
347     bool _isGenerated: 1;
348     bool _isDeprecated: 1;
349     bool _isUnavailable: 1;
350
351     class HashCode;
352
353     friend class SymbolTable;
354 };
355
356 } // namespace CPlusPlus
357
358
359 #endif // CPLUSPLUS_SYMBOL_H