Symbols.h 23.2 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 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
54
55
// 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_SYMBOLS_H
#define CPLUSPLUS_SYMBOLS_H

#include "CPlusPlusForwardDeclarations.h"
#include "Symbol.h"
#include "Type.h"
#include "FullySpecifiedType.h"
56
#include <vector>
Roberto Raggi's avatar
Roberto Raggi committed
57
58

namespace CPlusPlus {
con's avatar
con committed
59

60
class CPLUSPLUS_EXPORT TemplateParameters
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
public:
    TemplateParameters(Scope *scope);
    TemplateParameters(TemplateParameters *previous, Scope *scope);
    ~TemplateParameters();

    TemplateParameters *previous() const;
    Scope *scope() const;

private:
    TemplateParameters *_previous;
    Scope *_scope;
};

con's avatar
con committed
75
76
77
class CPLUSPLUS_EXPORT UsingNamespaceDirective: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
78
    UsingNamespaceDirective(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
79
80
81
82
83
    virtual ~UsingNamespaceDirective();

    // Symbol's interface
    virtual FullySpecifiedType type() const;

84
85
86
87
88
89
    virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const
    { return this; }

    virtual UsingNamespaceDirective *asUsingNamespaceDirective()
    { return this; }

con's avatar
con committed
90
91
92
93
94
95
96
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
};

class CPLUSPLUS_EXPORT UsingDeclaration: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
97
    UsingDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
98
99
100
101
102
    virtual ~UsingDeclaration();

    // Symbol's interface
    virtual FullySpecifiedType type() const;

103
104
105
106
107
108
    virtual const UsingDeclaration *asUsingDeclaration() const
    { return this; }

    virtual UsingDeclaration *asUsingDeclaration()
    { return this; }

con's avatar
con committed
109
110
111
112
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
};

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class CPLUSPLUS_EXPORT NamespaceAlias: public Symbol
{
public:
    NamespaceAlias(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
    virtual ~NamespaceAlias();

    const Name *namespaceName() const;
    void setNamespaceName(const Name *namespaceName);

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    virtual const NamespaceAlias *asNamespaceAlias() const
    { return this; }

    virtual NamespaceAlias *asNamespaceAlias()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
    const Name *_namespaceName;
};

con's avatar
con committed
138
139
140
class CPLUSPLUS_EXPORT Declaration: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
141
    Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
142
143
    virtual ~Declaration();

144
145
    TemplateParameters *templateParameters() const;
    void setTemplateParameters(TemplateParameters *templateParameters);
con's avatar
con committed
146

147
    void setType(const FullySpecifiedType &type);
con's avatar
con committed
148
149
150
151

    // Symbol's interface
    virtual FullySpecifiedType type() const;

152
153
154
155
156
157
    virtual const Declaration *asDeclaration() const
    { return this; }

    virtual Declaration *asDeclaration()
    { return this; }

con's avatar
con committed
158
159
160
161
162
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
    FullySpecifiedType _type;
163
    TemplateParameters *_templateParameters;
con's avatar
con committed
164
165
166
167
168
};

class CPLUSPLUS_EXPORT Argument: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
169
    Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
170
171
    virtual ~Argument();

172
    void setType(const FullySpecifiedType &type);
con's avatar
con committed
173
174

    bool hasInitializer() const;
175
176
177

    const StringLiteral *initializer() const;
    void setInitializer(const StringLiteral *initializer);
con's avatar
con committed
178
179
180
181

    // Symbol's interface
    virtual FullySpecifiedType type() const;

182
183
184
185
186
187
    virtual const Argument *asArgument() const
    { return this; }

    virtual Argument *asArgument()
    { return this; }

con's avatar
con committed
188
189
190
191
192
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
    FullySpecifiedType _type;
193
    const StringLiteral *_initializer;
con's avatar
con committed
194
195
};

Roberto Raggi's avatar
Roberto Raggi committed
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
class CPLUSPLUS_EXPORT TypenameArgument: public Symbol
{
public:
    TypenameArgument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
    virtual ~TypenameArgument();

    void setType(const FullySpecifiedType &type);

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    virtual const TypenameArgument *asTypenameArgument() const
    { return this; }

    virtual TypenameArgument *asTypenameArgument()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
    FullySpecifiedType _type;
};

con's avatar
con committed
220
221
222
class CPLUSPLUS_EXPORT ScopedSymbol: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
223
    ScopedSymbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
224
225
226
227
228
229
230
    virtual ~ScopedSymbol();

    unsigned memberCount() const;
    Symbol *memberAt(unsigned index) const;
    Scope *members() const;
    void addMember(Symbol *member);

231
232
233
234
235
236
    virtual const ScopedSymbol *asScopedSymbol() const
    { return this; }

    virtual ScopedSymbol *asScopedSymbol()
    { return this; }

237
238
239
240
241
242
243
244
    /// Set the start offset of the scope for this symbol
    unsigned startOffset() const;
    void setStartOffset(unsigned offset);

    /// Set the end offset of the scope for this symbol
    unsigned endOffset() const;
    void setEndOffset(unsigned offset);

con's avatar
con committed
245
246
247
248
249
250
251
252
253
254
255
256
257
private:
    Scope *_members;
};

class CPLUSPLUS_EXPORT Block: public ScopedSymbol
{
public:
    Block(TranslationUnit *translationUnit, unsigned sourceLocation);
    virtual ~Block();

    // Symbol's interface
    virtual FullySpecifiedType type() const;

258
259
260
261
262
263
    virtual const Block *asBlock() const
    { return this; }

    virtual Block *asBlock()
    { return this; }

con's avatar
con committed
264
265
266
267
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
};

268
269
270
class CPLUSPLUS_EXPORT ForwardClassDeclaration: public Symbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
271
    ForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
272
273
    virtual ~ForwardClassDeclaration();

274
275
    TemplateParameters *templateParameters() const;
    void setTemplateParameters(TemplateParameters *templateParameters);
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

    virtual FullySpecifiedType type() const;

    virtual bool isEqualTo(const Type *other) const;

    virtual const ForwardClassDeclaration *asForwardClassDeclaration() const
    { return this; }

    virtual ForwardClassDeclaration *asForwardClassDeclaration()
    { return this; }

    virtual const ForwardClassDeclaration *asForwardClassDeclarationType() const
    { return this; }

    virtual ForwardClassDeclaration *asForwardClassDeclarationType()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
296
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
297
298

private:
299
    TemplateParameters *_templateParameters;
300
301
};

con's avatar
con committed
302
303
304
class CPLUSPLUS_EXPORT Enum: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
305
    Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
306
307
308
309
310
311
312
313
    virtual ~Enum();

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    // Type's interface
    virtual bool isEqualTo(const Type *other) const;

314
315
316
317
318
319
    virtual const Enum *asEnum() const
    { return this; }

    virtual Enum *asEnum()
    { return this; }

320
321
322
323
324
325
    virtual const Enum *asEnumType() const
    { return this; }

    virtual Enum *asEnumType()
    { return this; }

con's avatar
con committed
326
327
328
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
329
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
330
331
332
333
334
335
336
337
};

class CPLUSPLUS_EXPORT Function: public ScopedSymbol, public Type
{
public:
    enum MethodKey {
        NormalMethod,
        SlotMethod,
338
339
        SignalMethod,
        InvokableMethod
con's avatar
con committed
340
341
342
    };

public:
Roberto Raggi's avatar
Roberto Raggi committed
343
    Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
344
345
346
347
348
    virtual ~Function();

    bool isNormal() const;
    bool isSignal() const;
    bool isSlot() const;
349
    bool isInvokable() const;
con's avatar
con committed
350
351
352
    int methodKey() const;
    void setMethodKey(int key);

353
354
    unsigned templateParameterCount() const; // ### remove me
    Symbol *templateParameterAt(unsigned index) const; // ### remove me
con's avatar
con committed
355

356
357
    TemplateParameters *templateParameters() const;
    void setTemplateParameters(TemplateParameters *templateParameters);
con's avatar
con committed
358
359

    FullySpecifiedType returnType() const;
360
    void setReturnType(const FullySpecifiedType &returnType);
con's avatar
con committed
361

362
363
364
    /** Convenience function that returns whether the function returns something (including void). */
    bool hasReturnType() const;

con's avatar
con committed
365
366
367
368
    unsigned argumentCount() const;
    Symbol *argumentAt(unsigned index) const;
    Scope *arguments() const;

369
370
371
    /** Convenience function that returns whether the function receives any arguments. */
    bool hasArguments() const;

372
373
374
    bool isVirtual() const;
    void setVirtual(bool isVirtual);

con's avatar
con committed
375
376
377
378
379
380
381
382
383
384
385
386
    bool isVariadic() const;
    void setVariadic(bool isVariadic);

    bool isConst() const;
    void setConst(bool isConst);

    bool isVolatile() const;
    void setVolatile(bool isVolatile);

    bool isPureVirtual() const;
    void setPureVirtual(bool isPureVirtual);

387
388
389
390
#ifdef ICHECK_BUILD
    bool isEqualTo(const Function* fct, bool ignoreName = false) const;
#endif

con's avatar
con committed
391
392
393
394
395
396
    // Symbol's interface
    virtual FullySpecifiedType type() const;

    // Type's interface
    virtual bool isEqualTo(const Type *other) const;

397
398
399
400
401
402
    virtual const Function *asFunction() const
    { return this; }

    virtual Function *asFunction()
    { return this; }

403
404
405
406
407
408
    virtual const Function *asFunctionType() const
    { return this; }

    virtual Function *asFunctionType()
    { return this; }

409
410
411
    bool isAmbiguous() const; // internal
    void setAmbiguous(bool isAmbiguous); // internal

con's avatar
con committed
412
413
414
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
415
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
416
417

private:
418
    TemplateParameters *_templateParameters;
con's avatar
con committed
419
    FullySpecifiedType _returnType;
420
    struct Flags {
421
        unsigned _isVirtual: 1;
422
423
424
425
426
427
428
        unsigned _isVariadic: 1;
        unsigned _isPureVirtual: 1;
        unsigned _isConst: 1;
        unsigned _isVolatile: 1;
        unsigned _isAmbiguous: 1;
        unsigned _methodKey: 3;
    };
con's avatar
con committed
429
430
    union {
        unsigned _flags;
431
        Flags f;
con's avatar
con committed
432
433
434
435
436
437
438
    };
    Scope *_arguments;
};

class CPLUSPLUS_EXPORT Namespace: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
439
    Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
440
441
442
443
444
445
446
447
    virtual ~Namespace();

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    // Type's interface
    virtual bool isEqualTo(const Type *other) const;

448
449
450
451
452
453
    virtual const Namespace *asNamespace() const
    { return this; }

    virtual Namespace *asNamespace()
    { return this; }

454
455
456
457
458
459
    virtual const Namespace *asNamespaceType() const
    { return this; }

    virtual Namespace *asNamespaceType()
    { return this; }

con's avatar
con committed
460
461
462
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
463
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
464
465
466
467
468
};

class CPLUSPLUS_EXPORT BaseClass: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
469
    BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
470
471
472
473
474
475
476
    virtual ~BaseClass();

    bool isVirtual() const;
    void setVirtual(bool isVirtual);

    // Symbol's interface
    virtual FullySpecifiedType type() const;
Roberto Raggi's avatar
Roberto Raggi committed
477
    void setType(const FullySpecifiedType &type);
con's avatar
con committed
478

479
480
481
482
483
484
    virtual const BaseClass *asBaseClass() const
    { return this; }

    virtual BaseClass *asBaseClass()
    { return this; }

con's avatar
con committed
485
486
487
488
489
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
    bool _isVirtual;
Roberto Raggi's avatar
Roberto Raggi committed
490
    FullySpecifiedType _type;
con's avatar
con committed
491
492
493
494
495
};

class CPLUSPLUS_EXPORT Class: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
496
    Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
497
498
499
500
501
502
503
504
505
506
507
508
509
510
    virtual ~Class();

    enum Key {
        ClassKey,
        StructKey,
        UnionKey
    };

    bool isClass() const;
    bool isStruct() const;
    bool isUnion() const;
    Key classKey() const;
    void setClassKey(Key key);

511
512
    unsigned templateParameterCount() const; // ### remove me
    Symbol *templateParameterAt(unsigned index) const; // ### remove me
con's avatar
con committed
513

514
515
    TemplateParameters *templateParameters() const;
    void setTemplateParameters(TemplateParameters *templateParameters);
con's avatar
con committed
516
517
518
519
520
521
522
523
524
525
526

    unsigned baseClassCount() const;
    BaseClass *baseClassAt(unsigned index) const;
    void addBaseClass(BaseClass *baseClass);

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    // Type's interface
    virtual bool isEqualTo(const Type *other) const;

527
528
529
530
531
532
    virtual const Class *asClass() const
    { return this; }

    virtual Class *asClass()
    { return this; }

533
534
535
536
537
538
    virtual const Class *asClassType() const
    { return this; }

    virtual Class *asClassType()
    { return this; }

con's avatar
con committed
539
540
541
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
542
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
543
544
545

private:
    Key _key;
546
    TemplateParameters *_templateParameters;
547
    std::vector<BaseClass *> _baseClasses;
con's avatar
con committed
548
549
};

550
551
552
class CPLUSPLUS_EXPORT ObjCBaseClass: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
553
    ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
    virtual ~ObjCBaseClass();

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    virtual const ObjCBaseClass *asObjCBaseClass() const
    { return this; }

    virtual ObjCBaseClass *asObjCBaseClass()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
};

class CPLUSPLUS_EXPORT ObjCBaseProtocol: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
574
    ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
    virtual ~ObjCBaseProtocol();

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    virtual const ObjCBaseProtocol *asObjCBaseProtocol() const
    { return this; }

    virtual ObjCBaseProtocol *asObjCBaseProtocol()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
};

592
class CPLUSPLUS_EXPORT ObjCForwardProtocolDeclaration: public Symbol, public Type
593
594
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
595
    ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
596
597
598
599
    virtual ~ObjCForwardProtocolDeclaration();

    virtual FullySpecifiedType type() const;

600
601
    virtual bool isEqualTo(const Type *other) const;

602
603
604
605
606
607
    virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const
    { return this; }

    virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration()
    { return this; }

608
609
610
611
612
613
    virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType() const
    { return this; }

    virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType()
    { return this; }

614
615
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
616
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
617
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
618
619
620
621
622
};

class CPLUSPLUS_EXPORT ObjCProtocol: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
623
    ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
624
625
    virtual ~ObjCProtocol();

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
626
627
628
    unsigned protocolCount() const;
    ObjCBaseProtocol *protocolAt(unsigned index) const;
    void addProtocol(ObjCBaseProtocol *protocol);
629

630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
    // Symbol's interface
    virtual FullySpecifiedType type() const;

    // Type's interface
    virtual bool isEqualTo(const Type *other) const;

    virtual const ObjCProtocol *asObjCProtocol() const
    { return this; }

    virtual ObjCProtocol *asObjCProtocol()
    { return this; }

    virtual const ObjCProtocol *asObjCProtocolType() const
    { return this; }

    virtual ObjCProtocol *asObjCProtocolType()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
651
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
652
653

private:
654
    std::vector<ObjCBaseProtocol *> _protocols;
655
656
};

657
class CPLUSPLUS_EXPORT ObjCForwardClassDeclaration: public Symbol, public Type
658
659
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
660
    ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
661
662
663
664
    virtual ~ObjCForwardClassDeclaration();

    virtual FullySpecifiedType type() const;

665
666
    virtual bool isEqualTo(const Type *other) const;

667
668
669
670
671
672
    virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const
    { return this; }

    virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration()
    { return this; }

673
674
675
676
677
678
    virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType() const
    { return this; }

    virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType()
    { return this; }

679
680
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
681
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
682
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
683
684
685
686
687
688
689

private:
};

class CPLUSPLUS_EXPORT ObjCClass: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
690
    ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
691
692
    virtual ~ObjCClass();

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
693
694
    bool isInterface() const;
    void setInterface(bool isInterface);
695

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
696
697
698
    bool isCategory() const;
    const Name *categoryName() const;
    void setCategoryName(const Name *categoryName);
699

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
700
701
    ObjCBaseClass *baseClass() const;
    void setBaseClass(ObjCBaseClass *baseClass);
702

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
703
704
705
    unsigned protocolCount() const;
    ObjCBaseProtocol *protocolAt(unsigned index) const;
    void addProtocol(ObjCBaseProtocol *protocol);
706

707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
    // Symbol's interface
    virtual FullySpecifiedType type() const;

    // Type's interface
    virtual bool isEqualTo(const Type *other) const;

    virtual const ObjCClass *asObjCClass() const
    { return this; }

    virtual ObjCClass *asObjCClass()
    { return this; }

    virtual const ObjCClass *asObjCClassType() const
    { return this; }

    virtual ObjCClass *asObjCClassType()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
728
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
729
730

private:
731
    bool _isInterface;
Roberto Raggi's avatar
Roberto Raggi committed
732
    const Name *_categoryName;
733
    ObjCBaseClass * _baseClass;
734
    std::vector<ObjCBaseProtocol *> _protocols;
735
736
};

737
738
739
class CPLUSPLUS_EXPORT ObjCMethod: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
740
    ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
741
742
743
    virtual ~ObjCMethod();

    FullySpecifiedType returnType() const;
744
    void setReturnType(const FullySpecifiedType &returnType);
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

    /** Convenience function that returns whether the function returns something (including void). */
    bool hasReturnType() const;

    unsigned argumentCount() const;
    Symbol *argumentAt(unsigned index) const;
    Scope *arguments() const;

    /** Convenience function that returns whether the function receives any arguments. */
    bool hasArguments() const;

    bool isVariadic() const;
    void setVariadic(bool isVariadic);

    // Symbol's interface
    virtual FullySpecifiedType type() const;

    // Type's interface
    virtual bool isEqualTo(const Type *other) const;

    virtual const ObjCMethod *asObjCMethod() const
    { return this; }

    virtual ObjCMethod *asObjCMethod()
    { return this; }

    virtual const ObjCMethod *asObjCMethodType() const
    { return this; }

    virtual ObjCMethod *asObjCMethodType()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
780
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
781
782
783
784
785
786
787
788
789
790
791
792
793

private:
    FullySpecifiedType _returnType;
    struct Flags {
        unsigned _isVariadic: 1;
    };
    union {
        unsigned _flags;
        Flags f;
    };
    Scope *_arguments;
};

794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
class CPLUSPLUS_EXPORT ObjCPropertyDeclaration: public Symbol
{
public:
    enum PropertyAttributes {
        None = 0,
        Assign = 1 << 0,
        Retain = 1 << 1,
        Copy = 1 << 2,
        ReadOnly = 1 << 3,
        ReadWrite = 1 << 4,
        Getter = 1 << 5,
        Setter = 1 << 6,
        NonAtomic = 1 << 7,

        WritabilityMask = ReadOnly | ReadWrite,
Roberto Raggi's avatar
Roberto Raggi committed
809
        SetterSemanticsMask = Assign | Retain | Copy
810
811
812
813
814
    };

public:
    ObjCPropertyDeclaration(TranslationUnit *translationUnit,
                            unsigned sourceLocation,
Roberto Raggi's avatar
Roberto Raggi committed
815
                            const Name *name);
816
817
    virtual ~ObjCPropertyDeclaration();

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
818
819
    bool hasAttribute(int attribute) const;
    void setAttributes(int attributes);
820

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
821
822
    bool hasGetter() const;
    bool hasSetter() const;
823

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
824
    const Name *getterName() const;
825

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
826
    void setGetterName(const Name *getterName);
827

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
828
829
    const Name *setterName() const;
    void setSetterName(const Name *setterName);
830

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
831
    void setType(const FullySpecifiedType &type);
832
833
834
835

    // Symbol's interface
    virtual FullySpecifiedType type() const;

Erik Verbruggen's avatar
Erik Verbruggen committed
836
    virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const
837
838
839
840
841
842
843
844
845
846
847
    { return this; }

    virtual ObjCPropertyDeclaration *asObjCPropertyDeclaration()
    { return this; }

protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
    FullySpecifiedType _type;
    int _propertyAttributes;
Roberto Raggi's avatar
Roberto Raggi committed
848
849
    const Name *_getterName;
    const Name *_setterName;
850
851
};

Roberto Raggi's avatar
Roberto Raggi committed
852
853
} // end of namespace CPlusPlus

con's avatar
con committed
854
855

#endif // CPLUSPLUS_SYMBOLS_H