Symbols.h 23 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class TemplateParameters
{
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; }

con's avatar
con committed
237
238
239
240
241
242
243
244
245
246
247
248
249
private:
    Scope *_members;
};

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

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

250
251
252
253
254
255
    virtual const Block *asBlock() const
    { return this; }

    virtual Block *asBlock()
    { return this; }

con's avatar
con committed
256
257
258
259
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
};

260
261
262
class CPLUSPLUS_EXPORT ForwardClassDeclaration: public Symbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
263
    ForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
264
265
    virtual ~ForwardClassDeclaration();

266
267
    TemplateParameters *templateParameters() const;
    void setTemplateParameters(TemplateParameters *templateParameters);
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

    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
288
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
289
290

private:
291
    TemplateParameters *_templateParameters;
292
293
};

con's avatar
con committed
294
295
296
class CPLUSPLUS_EXPORT Enum: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
297
    Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
298
299
300
301
302
303
304
305
    virtual ~Enum();

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

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

306
307
308
309
310
311
    virtual const Enum *asEnum() const
    { return this; }

    virtual Enum *asEnum()
    { return this; }

312
313
314
315
316
317
    virtual const Enum *asEnumType() const
    { return this; }

    virtual Enum *asEnumType()
    { return this; }

con's avatar
con committed
318
319
320
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
321
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
322
323
324
325
326
327
328
329
};

class CPLUSPLUS_EXPORT Function: public ScopedSymbol, public Type
{
public:
    enum MethodKey {
        NormalMethod,
        SlotMethod,
330
331
        SignalMethod,
        InvokableMethod
con's avatar
con committed
332
333
334
    };

public:
Roberto Raggi's avatar
Roberto Raggi committed
335
    Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
336
337
338
339
340
    virtual ~Function();

    bool isNormal() const;
    bool isSignal() const;
    bool isSlot() const;
341
    bool isInvokable() const;
con's avatar
con committed
342
343
344
    int methodKey() const;
    void setMethodKey(int key);

345
346
    unsigned templateParameterCount() const; // ### remove me
    Symbol *templateParameterAt(unsigned index) const; // ### remove me
con's avatar
con committed
347

348
349
    TemplateParameters *templateParameters() const;
    void setTemplateParameters(TemplateParameters *templateParameters);
con's avatar
con committed
350
351

    FullySpecifiedType returnType() const;
352
    void setReturnType(const FullySpecifiedType &returnType);
con's avatar
con committed
353

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

con's avatar
con committed
357
358
359
360
    unsigned argumentCount() const;
    Symbol *argumentAt(unsigned index) const;
    Scope *arguments() const;

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

364
365
366
    bool isVirtual() const;
    void setVirtual(bool isVirtual);

con's avatar
con committed
367
368
369
370
371
372
373
374
375
376
377
378
    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);

379
380
381
382
#ifdef ICHECK_BUILD
    bool isEqualTo(const Function* fct, bool ignoreName = false) const;
#endif

con's avatar
con committed
383
384
385
386
387
388
    // Symbol's interface
    virtual FullySpecifiedType type() const;

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

389
390
391
392
393
394
    virtual const Function *asFunction() const
    { return this; }

    virtual Function *asFunction()
    { return this; }

395
396
397
398
399
400
    virtual const Function *asFunctionType() const
    { return this; }

    virtual Function *asFunctionType()
    { return this; }

401
402
403
    bool isAmbiguous() const; // internal
    void setAmbiguous(bool isAmbiguous); // internal

con's avatar
con committed
404
405
406
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
407
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
408
409

private:
410
    TemplateParameters *_templateParameters;
con's avatar
con committed
411
    FullySpecifiedType _returnType;
412
    struct Flags {
413
        unsigned _isVirtual: 1;
414
415
416
417
418
419
420
        unsigned _isVariadic: 1;
        unsigned _isPureVirtual: 1;
        unsigned _isConst: 1;
        unsigned _isVolatile: 1;
        unsigned _isAmbiguous: 1;
        unsigned _methodKey: 3;
    };
con's avatar
con committed
421
422
    union {
        unsigned _flags;
423
        Flags f;
con's avatar
con committed
424
425
426
427
428
429
430
    };
    Scope *_arguments;
};

class CPLUSPLUS_EXPORT Namespace: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
431
    Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
432
433
434
435
436
437
438
439
    virtual ~Namespace();

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

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

440
441
442
443
444
445
    virtual const Namespace *asNamespace() const
    { return this; }

    virtual Namespace *asNamespace()
    { return this; }

446
447
448
449
450
451
    virtual const Namespace *asNamespaceType() const
    { return this; }

    virtual Namespace *asNamespaceType()
    { return this; }

con's avatar
con committed
452
453
454
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
455
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
456
457
458
459
460
};

class CPLUSPLUS_EXPORT BaseClass: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
461
    BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
462
463
464
465
466
467
468
    virtual ~BaseClass();

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

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

471
472
473
474
475
476
    virtual const BaseClass *asBaseClass() const
    { return this; }

    virtual BaseClass *asBaseClass()
    { return this; }

con's avatar
con committed
477
478
479
480
481
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);

private:
    bool _isVirtual;
Roberto Raggi's avatar
Roberto Raggi committed
482
    FullySpecifiedType _type;
con's avatar
con committed
483
484
485
486
487
};

class CPLUSPLUS_EXPORT Class: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
488
    Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
con's avatar
con committed
489
490
491
492
493
494
495
496
497
498
499
500
501
502
    virtual ~Class();

    enum Key {
        ClassKey,
        StructKey,
        UnionKey
    };

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

503
504
    unsigned templateParameterCount() const; // ### remove me
    Symbol *templateParameterAt(unsigned index) const; // ### remove me
con's avatar
con committed
505

506
507
    TemplateParameters *templateParameters() const;
    void setTemplateParameters(TemplateParameters *templateParameters);
con's avatar
con committed
508
509
510
511
512
513
514
515
516
517
518

    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;

519
520
521
522
523
524
    virtual const Class *asClass() const
    { return this; }

    virtual Class *asClass()
    { return this; }

525
526
527
528
529
530
    virtual const Class *asClassType() const
    { return this; }

    virtual Class *asClassType()
    { return this; }

con's avatar
con committed
531
532
533
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
534
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
con's avatar
con committed
535
536
537

private:
    Key _key;
538
    TemplateParameters *_templateParameters;
539
    std::vector<BaseClass *> _baseClasses;
con's avatar
con committed
540
541
};

542
543
544
class CPLUSPLUS_EXPORT ObjCBaseClass: public Symbol
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
545
    ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
    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
566
    ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
    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:
};

584
class CPLUSPLUS_EXPORT ObjCForwardProtocolDeclaration: public Symbol, public Type
585
586
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
587
    ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
588
589
590
591
    virtual ~ObjCForwardProtocolDeclaration();

    virtual FullySpecifiedType type() const;

592
593
    virtual bool isEqualTo(const Type *other) const;

594
595
596
597
598
599
    virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const
    { return this; }

    virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration()
    { return this; }

600
601
602
603
604
605
    virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType() const
    { return this; }

    virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType()
    { return this; }

606
607
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
608
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
609
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
610
611
612
613
614
};

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

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
618
619
620
    unsigned protocolCount() const;
    ObjCBaseProtocol *protocolAt(unsigned index) const;
    void addProtocol(ObjCBaseProtocol *protocol);
621

622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
    // 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
643
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
644
645

private:
646
    std::vector<ObjCBaseProtocol *> _protocols;
647
648
};

649
class CPLUSPLUS_EXPORT ObjCForwardClassDeclaration: public Symbol, public Type
650
651
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
652
    ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
653
654
655
656
    virtual ~ObjCForwardClassDeclaration();

    virtual FullySpecifiedType type() const;

657
658
    virtual bool isEqualTo(const Type *other) const;

659
660
661
662
663
664
    virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const
    { return this; }

    virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration()
    { return this; }

665
666
667
668
669
670
    virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType() const
    { return this; }

    virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType()
    { return this; }

671
672
protected:
    virtual void visitSymbol0(SymbolVisitor *visitor);
673
    virtual void accept0(TypeVisitor *visitor);
Roberto Raggi's avatar
Roberto Raggi committed
674
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
675
676
677
678
679
680
681

private:
};

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

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
685
686
    bool isInterface() const;
    void setInterface(bool isInterface);
687

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
688
689
690
    bool isCategory() const;
    const Name *categoryName() const;
    void setCategoryName(const Name *categoryName);
691

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
692
693
    ObjCBaseClass *baseClass() const;
    void setBaseClass(ObjCBaseClass *baseClass);
694

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
695
696
697
    unsigned protocolCount() const;
    ObjCBaseProtocol *protocolAt(unsigned index) const;
    void addProtocol(ObjCBaseProtocol *protocol);
698

699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
    // 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
720
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
721
722

private:
723
    bool _isInterface;
Roberto Raggi's avatar
Roberto Raggi committed
724
    const Name *_categoryName;
725
    ObjCBaseClass * _baseClass;
726
    std::vector<ObjCBaseProtocol *> _protocols;
727
728
};

729
730
731
class CPLUSPLUS_EXPORT ObjCMethod: public ScopedSymbol, public Type
{
public:
Roberto Raggi's avatar
Roberto Raggi committed
732
    ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
733
734
735
    virtual ~ObjCMethod();

    FullySpecifiedType returnType() const;
736
    void setReturnType(const FullySpecifiedType &returnType);
737
738
739
740
741
742
743
744
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

    /** 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
772
    virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
773
774
775
776
777
778
779
780
781
782
783
784
785

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

786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
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
801
        SetterSemanticsMask = Assign | Retain | Copy
802
803
804
805
806
    };

public:
    ObjCPropertyDeclaration(TranslationUnit *translationUnit,
                            unsigned sourceLocation,
Roberto Raggi's avatar
Roberto Raggi committed
807
                            const Name *name);
808
809
    virtual ~ObjCPropertyDeclaration();

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
810
811
    bool hasAttribute(int attribute) const;
    void setAttributes(int attributes);
812

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
813
814
    bool hasGetter() const;
    bool hasSetter() const;
815

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
816
    const Name *getterName() const;
817

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

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
820
821
    const Name *setterName() const;
    void setSetterName(const Name *setterName);
822

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
823
    void setType(const FullySpecifiedType &type);
824
825
826
827

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

Erik Verbruggen's avatar
Erik Verbruggen committed
828
    virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const
829
830
831
832
833
834
835
836
837
838
839
    { 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
840
841
    const Name *_getterName;
    const Name *_setterName;
842
843
};

Roberto Raggi's avatar
Roberto Raggi committed
844
845
} // end of namespace CPlusPlus

con's avatar
con committed
846
847

#endif // CPLUSPLUS_SYMBOLS_H