OSDN Git Service

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