1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
32 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
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:
41 // The above copyright notice and this permission notice shall be included in
42 // all copies or substantial portions of the Software.
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
52 #ifndef CPLUSPLUS_SYMBOL_H
53 #define CPLUSPLUS_SYMBOL_H
55 #include "CPlusPlusForwardDeclarations.h"
60 class CPLUSPLUS_EXPORT Symbol
62 Symbol(const Symbol &other);
63 void operator =(const Symbol &other);
66 /// Storage class specifier
87 /// Constructs a Symbol with the given source location, name and translation unit.
88 Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
90 /// Destroy this Symbol.
93 /// Returns this Symbol's source location.
94 unsigned sourceLocation() const;
96 /// \returns this Symbol's line number. The line number is 1-based.
97 unsigned line() const;
99 /// \returns this Symbol's column number. The column number is 1-based.
100 unsigned column() const;
102 /// Returns this Symbol's file name.
103 const StringLiteral *fileId() const;
105 /// Returns this Symbol's file name.
106 const char *fileName() const;
108 /// Returns this Symbol's file name length.
109 unsigned fileNameLength() const;
111 /// Returns this Symbol's name.
112 const Name *name() const;
114 /// Sets this Symbol's name.
115 void setName(const Name *name); // ### dangerous
117 /// Returns this Symbol's (optional) identifier
118 const Identifier *identifier() const;
120 /// Returns this Symbol's storage class specifier.
123 /// Sets this Symbol's storage class specifier.
124 void setStorage(int storage);
126 /// Returns this Symbol's visibility.
127 int visibility() const;
129 /// Sets this Symbol's visibility.
130 void setVisibility(int visibility);
132 /// Returns the next chained Symbol.
133 Symbol *next() const;
135 /// Returns true if this Symbol has friend storage specifier.
136 bool isFriend() const;
138 /// Returns true if this Symbol has register storage specifier.
139 bool isRegister() const;
141 /// Returns true if this Symbol has static storage specifier.
142 bool isStatic() const;
144 /// Returns true if this Symbol has extern storage specifier.
145 bool isExtern() const;
147 /// Returns true if this Symbol has mutable storage specifier.
148 bool isMutable() const;
150 /// Returns true if this Symbol has typedef storage specifier.
151 bool isTypedef() const;
153 /// Returns true if this Symbol's visibility is public.
154 bool isPublic() const;
156 /// Returns true if this Symbol's visibility is protected.
157 bool isProtected() const;
159 /// Returns true if this Symbol's visibility is private.
160 bool isPrivate() const;
162 /// Returns true if this Symbol is a Scope.
163 bool isScope() const;
165 /// Returns true if this Symbol is an Enum.
168 /// Returns true if this Symbol is an Function.
169 bool isFunction() const;
171 /// Returns true if this Symbol is a Namespace.
172 bool isNamespace() const;
174 /// Returns true if this Symbol is a Template.
175 bool isTemplate() const;
177 /// Returns true if this Symbol is a Class.
178 bool isClass() const;
180 /// Returns true if this Symbol is a Block.
181 bool isBlock() const;
183 /// Returns true if this Symbol is a UsingNamespaceDirective.
184 bool isUsingNamespaceDirective() const;
186 /// Returns true if this Symbol is a UsingDeclaration.
187 bool isUsingDeclaration() const;
189 /// Returns true if this Symbol is a Declaration.
190 bool isDeclaration() const;
192 /// Returns true if this Symbol is an Argument.
193 bool isArgument() const;
195 /// Returns true if this Symbol is a Typename argument.
196 bool isTypenameArgument() const;
198 /// Returns true if this Symbol is a BaseClass.
199 bool isBaseClass() const;
201 /// Returns true if this Symbol is a ForwardClassDeclaration.
202 bool isForwardClassDeclaration() const;
204 /// Returns true if this Symbol is a QtPropertyDeclaration.
205 bool isQtPropertyDeclaration() const;
207 /// Returns true if this Symbol is a QtEnum.
208 bool isQtEnum() const;
210 bool isObjCBaseClass() const;
211 bool isObjCBaseProtocol() const;
213 /// Returns true if this Symbol is an Objective-C Class declaration.
214 bool isObjCClass() const;
216 /// Returns true if this Symbol is an Objective-C Class forward declaration.
217 bool isObjCForwardClassDeclaration() const;
219 /// Returns true if this Symbol is an Objective-C Protocol declaration.
220 bool isObjCProtocol() const;
222 /// Returns true if this Symbol is an Objective-C Protocol forward declaration.
223 bool isObjCForwardProtocolDeclaration() const;
225 /// Returns true if this Symbol is an Objective-C method declaration.
226 bool isObjCMethod() const;
228 /// Returns true if this Symbol is an Objective-C @property declaration.
229 bool isObjCPropertyDeclaration() const;
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; }
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; }
283 /// Returns this Symbol's type.
284 virtual FullySpecifiedType type() const = 0;
286 /// Returns this Symbol's hash value.
287 unsigned hashCode() const;
289 /// Returns this Symbol's index.
290 unsigned index() const;
292 const Name *unqualifiedName() const;
294 bool isGenerated() const;
296 bool isDeprecated() const;
297 void setDeprecated(bool isDeprecated);
299 bool isUnavailable() const;
300 void setUnavailable(bool isUnavailable);
302 /// Returns this Symbol's eclosing scope.
303 Scope *enclosingScope() const;
305 /// Returns the eclosing namespace scope.
306 Namespace *enclosingNamespace() const;
308 /// Returns the eclosing template scope.
309 Template *enclosingTemplate() const;
311 /// Returns the enclosing class scope.
312 Class *enclosingClass() const;
314 /// Returns the enclosing enum scope.
315 Enum *enclosingEnum() const;
317 /// Returns the enclosing prototype scope.
318 Function *enclosingFunction() const;
320 /// Returns the enclosing Block scope.
321 Block *enclosingBlock() const;
323 void setScope(Scope *enclosingScope); // ### make me private
324 void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private
326 void visitSymbol(SymbolVisitor *visitor);
327 static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
329 virtual void copy(Symbol *other);
332 virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
338 const StringLiteral *_fileId;
339 unsigned _sourceLocation;
347 bool _isGenerated: 1;
348 bool _isDeprecated: 1;
349 bool _isUnavailable: 1;
353 friend class SymbolTable;
356 } // namespace CPlusPlus
359 #endif // CPLUSPLUS_SYMBOL_H