Symbol.h 12.3 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
con's avatar
con committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#ifndef CPLUSPLUS_SYMBOL_H
#define CPLUSPLUS_SYMBOL_H

#include "CPlusPlusForwardDeclarations.h"

Roberto Raggi's avatar
Roberto Raggi committed
57
58

namespace CPlusPlus {
con's avatar
con committed
59
60
61
62
63
64
65
66
67
68
69

class CPLUSPLUS_EXPORT Symbol
{
    Symbol(const Symbol &other);
    void operator =(const Symbol &other);

public:
    /// Storage class specifier
    enum Storage {
        NoStorage = 0,
        Friend,
70
        Auto,
con's avatar
con committed
71
72
73
74
75
76
77
78
79
80
81
        Register,
        Static,
        Extern,
        Mutable,
        Typedef
    };

    /// Access specifier.
    enum Visibility {
        Public,
        Protected,
82
83
        Private,
        Package
con's avatar
con committed
84
85
86
87
    };

public:
    /// Constructs a Symbol with the given source location, name and translation unit.
Roberto Raggi's avatar
Roberto Raggi committed
88
    Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
89
90
91
92
93
94
95

    /// Destroy this Symbol.
    virtual ~Symbol();

    /// Returns this Symbol's source location.
    unsigned sourceLocation() const;

96
    /// \returns this Symbol's line number. The line number is 1-based.
con's avatar
con committed
97
98
    unsigned line() const;

99
    /// \returns this Symbol's column number. The column number is 1-based.
con's avatar
con committed
100
101
102
    unsigned column() const;

    /// Returns this Symbol's file name.
Roberto Raggi's avatar
Roberto Raggi committed
103
    const StringLiteral *fileId() const;
con's avatar
con committed
104
105
106
107
108
109
110
111

    /// Returns this Symbol's file name.
    const char *fileName() const;

    /// Returns this Symbol's file name length.
    unsigned fileNameLength() const;

    /// Returns this Symbol's name.
Roberto Raggi's avatar
Roberto Raggi committed
112
    const Name *name() const;
con's avatar
con committed
113
114

    /// Sets this Symbol's name.
Roberto Raggi's avatar
Roberto Raggi committed
115
    void setName(const Name *name); // ### dangerous
con's avatar
con committed
116

Roberto Raggi's avatar
Roberto Raggi committed
117
    /// Returns this Symbol's (optional) identifier
Roberto Raggi's avatar
Roberto Raggi committed
118
    const Identifier *identifier() const;
Roberto Raggi's avatar
Roberto Raggi committed
119

con's avatar
con committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    /// Returns this Symbol's storage class specifier.
    int storage() const;

    /// Sets this Symbol's storage class specifier.
    void setStorage(int storage);

    /// Returns this Symbol's visibility.
    int visibility() const;

    /// Sets this Symbol's visibility.
    void setVisibility(int visibility);

    /// Returns the next chained Symbol.
    Symbol *next() const;

    /// Returns true if this Symbol has friend storage specifier.
    bool isFriend() const;

    /// Returns true if this Symbol has register storage specifier.
    bool isRegister() const;

    /// Returns true if this Symbol has static storage specifier.
    bool isStatic() const;

    /// Returns true if this Symbol has extern storage specifier.
    bool isExtern() const;

    /// Returns true if this Symbol has mutable storage specifier.
    bool isMutable() const;

    /// Returns true if this Symbol has typedef storage specifier.
    bool isTypedef() const;

    /// Returns true if this Symbol's visibility is public.
    bool isPublic() const;

    /// Returns true if this Symbol's visibility is protected.
    bool isProtected() const;

    /// Returns true if this Symbol's visibility is private.
    bool isPrivate() const;

162
163
    /// Returns true if this Symbol is a Scope.
    bool isScope() const;
con's avatar
con committed
164
165
166
167
168
169
170
171
172
173

    /// Returns true if this Symbol is an Enum.
    bool isEnum() const;

    /// Returns true if this Symbol is an Function.
    bool isFunction() const;

    /// Returns true if this Symbol is a Namespace.
    bool isNamespace() const;

Leandro Melo's avatar
Leandro Melo committed
174
    /// Returns true if this Symbol is a Template.
175
176
    bool isTemplate() const;

con's avatar
con committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
    /// Returns true if this Symbol is a Class.
    bool isClass() const;

    /// Returns true if this Symbol is a Block.
    bool isBlock() const;

    /// Returns true if this Symbol is a UsingNamespaceDirective.
    bool isUsingNamespaceDirective() const;

    /// Returns true if this Symbol is a UsingDeclaration.
    bool isUsingDeclaration() const;

    /// Returns true if this Symbol is a Declaration.
    bool isDeclaration() const;

    /// Returns true if this Symbol is an Argument.
    bool isArgument() const;

Roberto Raggi's avatar
Roberto Raggi committed
195
196
197
    /// Returns true if this Symbol is a Typename argument.
    bool isTypenameArgument() const;

con's avatar
con committed
198
199
200
    /// Returns true if this Symbol is a BaseClass.
    bool isBaseClass() const;

201
202
203
    /// Returns true if this Symbol is a ForwardClassDeclaration.
    bool isForwardClassDeclaration() const;

204
205
206
    /// Returns true if this Symbol is a QtPropertyDeclaration.
    bool isQtPropertyDeclaration() const;

207
208
209
    /// Returns true if this Symbol is a QtEnum.
    bool isQtEnum() const;

210
211
212
    bool isObjCBaseClass() const;
    bool isObjCBaseProtocol() const;

213
    /// Returns true if this Symbol is an Objective-C Class declaration.
214
215
    bool isObjCClass() const;

216
    /// Returns true if this Symbol is an Objective-C Class forward declaration.
217
218
    bool isObjCForwardClassDeclaration() const;

219
    /// Returns true if this Symbol is an Objective-C Protocol declaration.
220
221
    bool isObjCProtocol() const;

222
    /// Returns true if this Symbol is an Objective-C Protocol forward declaration.
223
224
    bool isObjCForwardProtocolDeclaration() const;

225
226
227
    /// Returns true if this Symbol is an Objective-C method declaration.
    bool isObjCMethod() const;

228
229
230
    /// Returns true if this Symbol is an Objective-C @property declaration.
    bool isObjCPropertyDeclaration() const;

Roberto Raggi's avatar
Roberto Raggi committed
231
    virtual const Scope *asScope() const { return 0; }
232
233
234
    virtual const Enum *asEnum() const { return 0; }
    virtual const Function *asFunction() const { return 0; }
    virtual const Namespace *asNamespace() const { return 0; }
235
    virtual const Template *asTemplate() const { return 0; }
236
    virtual const NamespaceAlias *asNamespaceAlias() const { return 0; }
237
238
239
240
241
242
    virtual const Class *asClass() const { return 0; }
    virtual const Block *asBlock() const { return 0; }
    virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const { return 0; }
    virtual const UsingDeclaration *asUsingDeclaration() const { return 0; }
    virtual const Declaration *asDeclaration() const { return 0; }
    virtual const Argument *asArgument() const { return 0; }
Roberto Raggi's avatar
Roberto Raggi committed
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
249
    virtual const ObjCBaseClass *asObjCBaseClass() const { return 0; }
    virtual const ObjCBaseProtocol *asObjCBaseProtocol() const { return 0; }
250
251
252
253
    virtual const ObjCClass *asObjCClass() const { return 0; }
    virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const { return 0; }
    virtual const ObjCProtocol *asObjCProtocol() const { return 0; }
    virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const { return 0; }
254
    virtual const ObjCMethod *asObjCMethod() const { return 0; }
255
    virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const { return 0; }
256

Roberto Raggi's avatar
Roberto Raggi committed
257
    virtual Scope *asScope() { return 0; }
258
259
260
    virtual Enum *asEnum() { return 0; }
    virtual Function *asFunction() { return 0; }
    virtual Namespace *asNamespace() { return 0; }
261
    virtual Template *asTemplate() { return 0; }
262
    virtual NamespaceAlias *asNamespaceAlias() { return 0; }
263
264
265
266
267
268
    virtual Class *asClass() { return 0; }
    virtual Block *asBlock() { return 0; }
    virtual UsingNamespaceDirective *asUsingNamespaceDirective() { return 0; }
    virtual UsingDeclaration *asUsingDeclaration() { return 0; }
    virtual Declaration *asDeclaration() { return 0; }
    virtual Argument *asArgument() { return 0; }
Roberto Raggi's avatar
Roberto Raggi committed
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
275
    virtual ObjCBaseClass *asObjCBaseClass() { return 0; }
    virtual ObjCBaseProtocol *asObjCBaseProtocol() { return 0; }
276
277
278
279
    virtual ObjCClass *asObjCClass() { return 0; }
    virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() { return 0; }
    virtual ObjCProtocol *asObjCProtocol() { return 0; }
    virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() { return 0; }
280
    virtual ObjCMethod *asObjCMethod() { return 0; }
281
    virtual ObjCPropertyDeclaration *asObjCPropertyDeclaration() { return 0; }
con's avatar
con committed
282
283
284
285
286
287
288
289
290
291

    /// Returns this Symbol's type.
    virtual FullySpecifiedType type() const = 0;

    /// Returns this Symbol's hash value.
    unsigned hashCode() const;

    /// Returns this Symbol's index.
    unsigned index() const;

292
    const Name *unqualifiedName() const;
con's avatar
con committed
293

294
295
    bool isGenerated() const;

296
297
298
    bool isDeprecated() const;
    void setDeprecated(bool isDeprecated);

299
300
301
    bool isUnavailable() const;
    void setUnavailable(bool isUnavailable);

Roberto Raggi's avatar
Roberto Raggi committed
302
    /// Returns this Symbol's eclosing scope.
303
    Scope *enclosingScope() const;
304

305
    /// Returns the eclosing namespace scope.
Roberto Raggi's avatar
Roberto Raggi committed
306
    Namespace *enclosingNamespace() const;
307

308
309
310
    /// Returns the eclosing template scope.
    Template *enclosingTemplate() const;

311
    /// Returns the enclosing class scope.
Roberto Raggi's avatar
Roberto Raggi committed
312
    Class *enclosingClass() const;
313
314

    /// Returns the enclosing enum scope.
Roberto Raggi's avatar
Roberto Raggi committed
315
    Enum *enclosingEnum() const;
316

317
    /// Returns the enclosing prototype scope.
Roberto Raggi's avatar
Roberto Raggi committed
318
    Function *enclosingFunction() const;
319
320

    /// Returns the enclosing Block scope.
Roberto Raggi's avatar
Roberto Raggi committed
321
    Block *enclosingBlock() const;
322

323
    void setScope(Scope *enclosingScope); // ### make me private
324
    void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private
con's avatar
con committed
325
326
327
328

    void visitSymbol(SymbolVisitor *visitor);
    static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);

329
330
    virtual void copy(Symbol *other);

con's avatar
con committed
331
332
333
334
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor) = 0;

private:
Roberto Raggi's avatar
Roberto Raggi committed
335
    const Name *_name;
336
337
338
339
    Scope *_scope;
    Symbol *_next;
    const StringLiteral *_fileId;
    unsigned _sourceLocation;
con's avatar
con committed
340
341
342
343
    unsigned _hashCode;
    int _storage;
    int _visibility;
    unsigned _index;
344
345
    unsigned _line;
    unsigned _column;
con's avatar
con committed
346

347
    bool _isGenerated: 1;
348
    bool _isDeprecated: 1;
349
    bool _isUnavailable: 1;
350

con's avatar
con committed
351
352
    class HashCode;

Roberto Raggi's avatar
Roberto Raggi committed
353
    friend class SymbolTable;
con's avatar
con committed
354
355
};

356
} // namespace CPlusPlus
Roberto Raggi's avatar
Roberto Raggi committed
357

con's avatar
con committed
358
359

#endif // CPLUSPLUS_SYMBOL_H