Symbol.h 11.2 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
con's avatar
con committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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
54
55

namespace CPlusPlus {
con's avatar
con committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

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

public:
    /// Storage class specifier
    enum Storage {
        NoStorage = 0,
        Friend,
        Register,
        Static,
        Extern,
        Mutable,
        Typedef
    };

    /// Access specifier.
    enum Visibility {
        Public,
        Protected,
78
79
        Private,
        Package
con's avatar
con committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    };

public:
    /// Constructs a Symbol with the given source location, name and translation unit.
    Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);

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

    /// Returns this Symbol's Control object.
    Control *control() const;

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

    /// Returns this Symbol's source offset.
    unsigned sourceOffset() const;

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

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

    /// Returns this Symbol's file name.
    StringLiteral *fileId() const;

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

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

113
114
115
116
117
118
    unsigned startOffset() const;
    void setStartOffset(unsigned offset);

    unsigned endOffset() const;
    void setEndOffset(unsigned offset);

119
120
121
    void getPosition(unsigned *line, unsigned *column = 0, StringLiteral **fileId = 0) const;
    void getStartPosition(unsigned *line, unsigned *column = 0, StringLiteral **fileId = 0) const;
    void getEndPosition(unsigned *line, unsigned *column = 0, StringLiteral **fileId = 0) const;
122

con's avatar
con committed
123
124
125
126
127
128
    /// Returns this Symbol's name.
    Name *name() const;

    /// Sets this Symbol's name.
    void setName(Name *name); // ### dangerous

Roberto Raggi's avatar
Roberto Raggi committed
129
130
131
    /// Returns this Symbol's (optional) identifier
    Identifier *identifier() const;

con's avatar
con committed
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    /// 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 this Symbol's scope.
    Scope *scope() const;

    /// 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;

    /// Returns true if this Symbol is a ScopedSymbol.
    bool isScopedSymbol() const;

    /// 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;

    /// 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;

    /// Returns true if this Symbol is a BaseClass.
    bool isBaseClass() const;

210
211
212
    /// Returns true if this Symbol is a ForwardClassDeclaration.
    bool isForwardClassDeclaration() const;

213
214
215
    bool isObjCBaseClass() const;
    bool isObjCBaseProtocol() const;

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

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

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

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

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

231
232
233
234
235
236
237
238
239
240
241
    virtual const ScopedSymbol *asScopedSymbol() const { return 0; }
    virtual const Enum *asEnum() const { return 0; }
    virtual const Function *asFunction() const { return 0; }
    virtual const Namespace *asNamespace() const { return 0; }
    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; }
    virtual const BaseClass *asBaseClass() const { return 0; }
242
    virtual const ForwardClassDeclaration *asForwardClassDeclaration() const { return 0; }
243
244
    virtual const ObjCBaseClass *asObjCBaseClass() const { return 0; }
    virtual const ObjCBaseProtocol *asObjCBaseProtocol() const { return 0; }
245
246
247
248
    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; }
249
    virtual const ObjCMethod *asObjCMethod() const { return 0; }
250
251
252
253
254
255
256
257
258
259
260
261

    virtual ScopedSymbol *asScopedSymbol() { return 0; }
    virtual Enum *asEnum() { return 0; }
    virtual Function *asFunction() { return 0; }
    virtual Namespace *asNamespace() { return 0; }
    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; }
    virtual BaseClass *asBaseClass() { return 0; }
262
    virtual ForwardClassDeclaration *asForwardClassDeclaration() { return 0; }
263
264
    virtual ObjCBaseClass *asObjCBaseClass() { return 0; }
    virtual ObjCBaseProtocol *asObjCBaseProtocol() { return 0; }
265
266
267
268
    virtual ObjCClass *asObjCClass() { return 0; }
    virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() { return 0; }
    virtual ObjCProtocol *asObjCProtocol() { return 0; }
    virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() { return 0; }
269
    virtual ObjCMethod *asObjCMethod() { return 0; }
con's avatar
con committed
270
271
272
273
274
275
276
277
278
279
280
281

    /// 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;

    Name *identity() const;

282
283
    bool isGenerated() const;

284
285
    Symbol *enclosingSymbol() const;

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
    /// Returns the eclosing namespace scope.
    Scope *enclosingNamespaceScope() const;

    /// Returns the enclosing class scope.
    Scope *enclosingClassScope() const;

    /// Returns the enclosing enum scope.
    Scope *enclosingEnumScope() const;

    /// Returns the enclosing function scope.
    Scope *enclosingFunctionScope() const;

    /// Returns the enclosing Block scope.
    Scope *enclosingBlockScope() const;

con's avatar
con committed
301
    void setScope(Scope *scope); // ### make me private
302
    void setSourceLocation(unsigned sourceLocation); // ### make me private
con's avatar
con committed
303
304
305
306
307
308
309
310
311
312
313
314
315

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

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor) = 0;

    TranslationUnit *translationUnit() const;

private:
    Control *_control;
    unsigned _sourceLocation;
    unsigned _sourceOffset;
316
317
    unsigned _startOffset;
    unsigned _endOffset;
con's avatar
con committed
318
319
320
321
322
323
324
325
    Name *_name;
    unsigned _hashCode;
    int _storage;
    int _visibility;
    Scope *_scope;
    unsigned _index;
    Symbol *_next;

326
327
    bool _isGenerated: 1;

con's avatar
con committed
328
329
330
331
332
333
    class IdentityForName;
    class HashCode;

    friend class Scope;
};

Roberto Raggi's avatar
Roberto Raggi committed
334
335
} // end of namespace CPlusPlus

con's avatar
con committed
336
337

#endif // CPLUSPLUS_SYMBOL_H