1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
33 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
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:
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
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
53 #ifndef CPLUSPLUS_SYMBOL_H
54 #define CPLUSPLUS_SYMBOL_H
56 #include "CPlusPlusForwardDeclarations.h"
61 class CPLUSPLUS_EXPORT Symbol
63 Symbol(const Symbol &other);
64 void operator =(const Symbol &other);
67 /// Storage class specifier
88 /// Constructs a Symbol with the given source location, name and translation unit.
89 Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
91 /// Destroy this Symbol.
94 /// Returns this Symbol's source location.
95 unsigned sourceLocation() const;
97 /// \returns this Symbol's line number. The line number is 1-based.
98 unsigned line() const;
100 /// \returns this Symbol's column number. The column number is 1-based.
101 unsigned column() const;
103 /// Returns this Symbol's file name.
104 const StringLiteral *fileId() const;
106 /// Returns this Symbol's file name.
107 const char *fileName() const;
109 /// Returns this Symbol's file name length.
110 unsigned fileNameLength() const;
112 /// Returns this Symbol's name.
113 const Name *name() const;
115 /// Sets this Symbol's name.
116 void setName(const Name *name); // ### dangerous
118 /// Returns this Symbol's (optional) identifier
119 const Identifier *identifier() const;
121 /// Returns this Symbol's storage class specifier.
124 /// Sets this Symbol's storage class specifier.
125 void setStorage(int storage);
127 /// Returns this Symbol's visibility.
128 int visibility() const;
130 /// Sets this Symbol's visibility.
131 void setVisibility(int visibility);
133 /// Returns the next chained Symbol.
134 Symbol *next() const;
136 /// Returns true if this Symbol has friend storage specifier.
137 bool isFriend() const;
139 /// Returns true if this Symbol has register storage specifier.
140 bool isRegister() const;
142 /// Returns true if this Symbol has static storage specifier.
143 bool isStatic() const;
145 /// Returns true if this Symbol has extern storage specifier.
146 bool isExtern() const;
148 /// Returns true if this Symbol has mutable storage specifier.
149 bool isMutable() const;
151 /// Returns true if this Symbol has typedef storage specifier.
152 bool isTypedef() const;
154 /// Returns true if this Symbol's visibility is public.
155 bool isPublic() const;
157 /// Returns true if this Symbol's visibility is protected.
158 bool isProtected() const;
160 /// Returns true if this Symbol's visibility is private.
161 bool isPrivate() const;
163 /// Returns true if this Symbol is a Scope.
164 bool isScope() const;
166 /// Returns true if this Symbol is an Enum.
169 /// Returns true if this Symbol is an Function.
170 bool isFunction() const;
172 /// Returns true if this Symbol is a Namespace.
173 bool isNamespace() const;
175 /// Returns true if this Symbol is a Template.
176 bool isTemplate() const;
178 /// Returns true if this Symbol is a Class.
179 bool isClass() const;
181 /// Returns true if this Symbol is a Block.
182 bool isBlock() const;
184 /// Returns true if this Symbol is a UsingNamespaceDirective.
185 bool isUsingNamespaceDirective() const;
187 /// Returns true if this Symbol is a UsingDeclaration.
188 bool isUsingDeclaration() const;
190 /// Returns true if this Symbol is a Declaration.
191 bool isDeclaration() const;
193 /// Returns true if this Symbol is an Argument.
194 bool isArgument() const;
196 /// Returns true if this Symbol is a Typename argument.
197 bool isTypenameArgument() const;
199 /// Returns true if this Symbol is a BaseClass.
200 bool isBaseClass() const;
202 /// Returns true if this Symbol is a ForwardClassDeclaration.
203 bool isForwardClassDeclaration() const;
205 /// Returns true if this Symbol is a QtPropertyDeclaration.
206 bool isQtPropertyDeclaration() const;
208 /// Returns true if this Symbol is a QtEnum.
209 bool isQtEnum() const;
211 bool isObjCBaseClass() const;
212 bool isObjCBaseProtocol() const;
214 /// Returns true if this Symbol is an Objective-C Class declaration.
215 bool isObjCClass() const;
217 /// Returns true if this Symbol is an Objective-C Class forward declaration.
218 bool isObjCForwardClassDeclaration() const;
220 /// Returns true if this Symbol is an Objective-C Protocol declaration.
221 bool isObjCProtocol() const;
223 /// Returns true if this Symbol is an Objective-C Protocol forward declaration.
224 bool isObjCForwardProtocolDeclaration() const;
226 /// Returns true if this Symbol is an Objective-C method declaration.
227 bool isObjCMethod() const;
229 /// Returns true if this Symbol is an Objective-C @property declaration.
230 bool isObjCPropertyDeclaration() const;
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; }
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; }
284 /// Returns this Symbol's type.
285 virtual FullySpecifiedType type() const = 0;
287 /// Returns this Symbol's hash value.
288 unsigned hashCode() const;
290 /// Returns this Symbol's index.
291 unsigned index() const;
293 const Name *unqualifiedName() const;
295 bool isGenerated() const;
297 bool isDeprecated() const;
298 void setDeprecated(bool isDeprecated);
300 bool isUnavailable() const;
301 void setUnavailable(bool isUnavailable);
303 /// Returns this Symbol's eclosing scope.
304 Scope *enclosingScope() const;
306 /// Returns the eclosing namespace scope.
307 Namespace *enclosingNamespace() const;
309 /// Returns the eclosing template scope.
310 Template *enclosingTemplate() const;
312 /// Returns the enclosing class scope.
313 Class *enclosingClass() const;
315 /// Returns the enclosing enum scope.
316 Enum *enclosingEnum() const;
318 /// Returns the enclosing prototype scope.
319 Function *enclosingFunction() const;
321 /// Returns the enclosing Block scope.
322 Block *enclosingBlock() const;
324 void setScope(Scope *enclosingScope); // ### make me private
325 void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private
327 void visitSymbol(SymbolVisitor *visitor);
328 static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
330 virtual void copy(Symbol *other);
333 virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
339 const StringLiteral *_fileId;
340 unsigned _sourceLocation;
348 bool _isGenerated: 1;
349 bool _isDeprecated: 1;
350 bool _isUnavailable: 1;
354 friend class SymbolTable;
357 } // end of namespace CPlusPlus
360 #endif // CPLUSPLUS_SYMBOL_H