1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
32 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
34 // Permission is hereby granted, free of charge, to any person obtaining a copy
35 // of this software and associated documentation files (the "Software"), to deal
36 // in the Software without restriction, including without limitation the rights
37 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38 // copies of the Software, and to permit persons to whom the Software is
39 // furnished to do so, subject to the following conditions:
41 // The above copyright notice and this permission notice shall be included in
42 // all copies or substantial portions of the Software.
44 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
52 #ifndef CPLUSPLUS_SYMBOLS_H
53 #define CPLUSPLUS_SYMBOLS_H
55 #include "CPlusPlusForwardDeclarations.h"
58 #include "FullySpecifiedType.h"
64 class CPLUSPLUS_EXPORT UsingNamespaceDirective: public Symbol
67 UsingNamespaceDirective(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
68 virtual ~UsingNamespaceDirective();
71 virtual FullySpecifiedType type() const;
73 virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const
76 virtual UsingNamespaceDirective *asUsingNamespaceDirective()
80 virtual void visitSymbol0(SymbolVisitor *visitor);
83 class CPLUSPLUS_EXPORT UsingDeclaration: public Symbol
86 UsingDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
87 virtual ~UsingDeclaration();
90 virtual FullySpecifiedType type() const;
92 virtual const UsingDeclaration *asUsingDeclaration() const
95 virtual UsingDeclaration *asUsingDeclaration()
99 virtual void visitSymbol0(SymbolVisitor *visitor);
102 class CPLUSPLUS_EXPORT NamespaceAlias: public Symbol
105 NamespaceAlias(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
106 virtual ~NamespaceAlias();
108 const Name *namespaceName() const;
109 void setNamespaceName(const Name *namespaceName);
111 // Symbol's interface
112 virtual FullySpecifiedType type() const;
114 virtual const NamespaceAlias *asNamespaceAlias() const
117 virtual NamespaceAlias *asNamespaceAlias()
121 virtual void visitSymbol0(SymbolVisitor *visitor);
124 const Name *_namespaceName;
127 class CPLUSPLUS_EXPORT Declaration: public Symbol
130 Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
131 virtual ~Declaration();
133 void setType(const FullySpecifiedType &type);
135 // Symbol's interface
136 virtual FullySpecifiedType type() const;
138 virtual const Declaration *asDeclaration() const
141 virtual Declaration *asDeclaration()
145 virtual void visitSymbol0(SymbolVisitor *visitor);
148 FullySpecifiedType _type;
151 class CPLUSPLUS_EXPORT Argument: public Symbol
154 Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
157 void setType(const FullySpecifiedType &type);
159 bool hasInitializer() const;
161 const StringLiteral *initializer() const;
162 void setInitializer(const StringLiteral *initializer);
164 // Symbol's interface
165 virtual FullySpecifiedType type() const;
167 virtual const Argument *asArgument() const
170 virtual Argument *asArgument()
174 virtual void visitSymbol0(SymbolVisitor *visitor);
177 const StringLiteral *_initializer;
178 FullySpecifiedType _type;
181 class CPLUSPLUS_EXPORT TypenameArgument: public Symbol
184 TypenameArgument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
185 virtual ~TypenameArgument();
187 void setType(const FullySpecifiedType &type);
189 // Symbol's interface
190 virtual FullySpecifiedType type() const;
192 virtual const TypenameArgument *asTypenameArgument() const
195 virtual TypenameArgument *asTypenameArgument()
199 virtual void visitSymbol0(SymbolVisitor *visitor);
202 FullySpecifiedType _type;
205 class CPLUSPLUS_EXPORT Block: public Scope
208 Block(TranslationUnit *translationUnit, unsigned sourceLocation);
211 // Symbol's interface
212 virtual FullySpecifiedType type() const;
214 virtual const Block *asBlock() const
217 virtual Block *asBlock()
221 virtual void visitSymbol0(SymbolVisitor *visitor);
224 class CPLUSPLUS_EXPORT ForwardClassDeclaration: public Symbol, public Type
227 ForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
228 virtual ~ForwardClassDeclaration();
230 virtual FullySpecifiedType type() const;
232 virtual bool isEqualTo(const Type *other) const;
234 virtual const ForwardClassDeclaration *asForwardClassDeclaration() const
237 virtual ForwardClassDeclaration *asForwardClassDeclaration()
240 virtual const ForwardClassDeclaration *asForwardClassDeclarationType() const
243 virtual ForwardClassDeclaration *asForwardClassDeclarationType()
247 virtual void visitSymbol0(SymbolVisitor *visitor);
248 virtual void accept0(TypeVisitor *visitor);
249 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
252 class CPLUSPLUS_EXPORT Enum: public Scope, public Type
255 Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
258 // Symbol's interface
259 virtual FullySpecifiedType type() const;
262 virtual bool isEqualTo(const Type *other) const;
264 virtual const Enum *asEnum() const
267 virtual Enum *asEnum()
270 virtual const Enum *asEnumType() const
273 virtual Enum *asEnumType()
277 virtual void visitSymbol0(SymbolVisitor *visitor);
278 virtual void accept0(TypeVisitor *visitor);
279 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
282 class CPLUSPLUS_EXPORT Function: public Scope, public Type
293 Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
296 bool isNormal() const;
297 bool isSignal() const;
299 bool isInvokable() const;
300 int methodKey() const;
301 void setMethodKey(int key);
303 FullySpecifiedType returnType() const;
304 void setReturnType(const FullySpecifiedType &returnType);
306 /** Convenience function that returns whether the function returns something (including void). */
307 bool hasReturnType() const;
309 unsigned argumentCount() const;
310 Symbol *argumentAt(unsigned index) const;
312 /** Convenience function that returns whether the function receives any arguments. */
313 bool hasArguments() const;
314 unsigned minimumArgumentCount() const;
316 bool isVirtual() const;
317 void setVirtual(bool isVirtual);
319 bool isVariadic() const;
320 void setVariadic(bool isVariadic);
322 bool isConst() const;
323 void setConst(bool isConst);
325 bool isVolatile() const;
326 void setVolatile(bool isVolatile);
328 bool isPureVirtual() const;
329 void setPureVirtual(bool isPureVirtual);
332 bool isEqualTo(const Function* fct, bool ignoreName = false) const;
335 // Symbol's interface
336 virtual FullySpecifiedType type() const;
339 virtual bool isEqualTo(const Type *other) const;
341 virtual const Function *asFunction() const
344 virtual Function *asFunction()
347 virtual const Function *asFunctionType() const
350 virtual Function *asFunctionType()
353 bool isAmbiguous() const; // internal
354 void setAmbiguous(bool isAmbiguous); // internal
356 bool maybeValidPrototype(unsigned actualArgumentCount) const;
359 virtual void visitSymbol0(SymbolVisitor *visitor);
360 virtual void accept0(TypeVisitor *visitor);
361 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
364 FullySpecifiedType _returnType;
366 unsigned _isVirtual: 1;
367 unsigned _isVariadic: 1;
368 unsigned _isPureVirtual: 1;
369 unsigned _isConst: 1;
370 unsigned _isVolatile: 1;
371 unsigned _isAmbiguous: 1;
372 unsigned _methodKey: 3;
380 class CPLUSPLUS_EXPORT Template: public Scope, public Type
383 Template(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
386 unsigned templateParameterCount() const;
387 Symbol *templateParameterAt(unsigned index) const;
388 Symbol *declaration() const;
390 // Symbol's interface
391 virtual FullySpecifiedType type() const;
394 virtual bool isEqualTo(const Type *other) const;
396 virtual const Template *asTemplate() const
399 virtual Template *asTemplate()
402 virtual const Template *asTemplateType() const
405 virtual Template *asTemplateType()
409 virtual void visitSymbol0(SymbolVisitor *visitor);
410 virtual void accept0(TypeVisitor *visitor);
411 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
415 class CPLUSPLUS_EXPORT Namespace: public Scope, public Type
418 Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
419 virtual ~Namespace();
421 // Symbol's interface
422 virtual FullySpecifiedType type() const;
425 virtual bool isEqualTo(const Type *other) const;
427 virtual const Namespace *asNamespace() const
430 virtual Namespace *asNamespace()
433 virtual const Namespace *asNamespaceType() const
436 virtual Namespace *asNamespaceType()
440 virtual void visitSymbol0(SymbolVisitor *visitor);
441 virtual void accept0(TypeVisitor *visitor);
442 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
445 class CPLUSPLUS_EXPORT BaseClass: public Symbol
448 BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
449 virtual ~BaseClass();
451 bool isVirtual() const;
452 void setVirtual(bool isVirtual);
454 // Symbol's interface
455 virtual FullySpecifiedType type() const;
456 void setType(const FullySpecifiedType &type);
458 virtual const BaseClass *asBaseClass() const
461 virtual BaseClass *asBaseClass()
465 virtual void visitSymbol0(SymbolVisitor *visitor);
469 FullySpecifiedType _type;
472 class CPLUSPLUS_EXPORT Class: public Scope, public Type
475 Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
484 bool isClass() const;
485 bool isStruct() const;
486 bool isUnion() const;
487 Key classKey() const;
488 void setClassKey(Key key);
490 unsigned baseClassCount() const;
491 BaseClass *baseClassAt(unsigned index) const;
492 void addBaseClass(BaseClass *baseClass);
494 // Symbol's interface
495 virtual FullySpecifiedType type() const;
498 virtual bool isEqualTo(const Type *other) const;
500 virtual const Class *asClass() const
503 virtual Class *asClass()
506 virtual const Class *asClassType() const
509 virtual Class *asClassType()
513 virtual void visitSymbol0(SymbolVisitor *visitor);
514 virtual void accept0(TypeVisitor *visitor);
515 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
519 std::vector<BaseClass *> _baseClasses;
522 class CPLUSPLUS_EXPORT QtPropertyDeclaration: public Symbol
527 ReadFunction = 1 << 0,
528 WriteFunction = 1 << 1,
529 ResetFunction = 1 << 2,
530 NotifyFunction = 1 << 3,
531 DesignableFlag = 1 << 4,
532 DesignableFunction = 1 << 5,
533 ScriptableFlag = 1 << 6,
534 ScriptableFunction = 1 << 7,
536 StoredFunction = 1 << 9,
538 UserFunction = 1 << 11,
539 ConstantFlag = 1 << 12,
544 QtPropertyDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
545 virtual ~QtPropertyDeclaration();
547 void setType(const FullySpecifiedType &type);
549 void setFlags(int flags);
552 // Symbol's interface
553 virtual FullySpecifiedType type() const;
555 virtual const QtPropertyDeclaration *asQtPropertyDeclaration() const
558 virtual QtPropertyDeclaration *asQtPropertyDeclaration()
562 virtual void visitSymbol0(SymbolVisitor *visitor);
565 FullySpecifiedType _type;
569 class CPLUSPLUS_EXPORT QtEnum: public Symbol
572 QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
575 // Symbol's interface
576 virtual FullySpecifiedType type() const;
578 virtual const QtEnum *asQtEnum() const
581 virtual QtEnum *asQtEnum()
585 virtual void visitSymbol0(SymbolVisitor *visitor);
588 class CPLUSPLUS_EXPORT ObjCBaseClass: public Symbol
591 ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
592 virtual ~ObjCBaseClass();
594 // Symbol's interface
595 virtual FullySpecifiedType type() const;
597 virtual const ObjCBaseClass *asObjCBaseClass() const
600 virtual ObjCBaseClass *asObjCBaseClass()
604 virtual void visitSymbol0(SymbolVisitor *visitor);
607 class CPLUSPLUS_EXPORT ObjCBaseProtocol: public Symbol
610 ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
611 virtual ~ObjCBaseProtocol();
613 // Symbol's interface
614 virtual FullySpecifiedType type() const;
616 virtual const ObjCBaseProtocol *asObjCBaseProtocol() const
619 virtual ObjCBaseProtocol *asObjCBaseProtocol()
623 virtual void visitSymbol0(SymbolVisitor *visitor);
626 class CPLUSPLUS_EXPORT ObjCForwardProtocolDeclaration: public Symbol, public Type
629 ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
630 virtual ~ObjCForwardProtocolDeclaration();
632 virtual FullySpecifiedType type() const;
634 virtual bool isEqualTo(const Type *other) const;
636 virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const
639 virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration()
642 virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType() const
645 virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType()
649 virtual void visitSymbol0(SymbolVisitor *visitor);
650 virtual void accept0(TypeVisitor *visitor);
651 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
654 class CPLUSPLUS_EXPORT ObjCProtocol: public Scope, public Type
657 ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
658 virtual ~ObjCProtocol();
660 unsigned protocolCount() const;
661 ObjCBaseProtocol *protocolAt(unsigned index) const;
662 void addProtocol(ObjCBaseProtocol *protocol);
664 // Symbol's interface
665 virtual FullySpecifiedType type() const;
668 virtual bool isEqualTo(const Type *other) const;
670 virtual const ObjCProtocol *asObjCProtocol() const
673 virtual ObjCProtocol *asObjCProtocol()
676 virtual const ObjCProtocol *asObjCProtocolType() const
679 virtual ObjCProtocol *asObjCProtocolType()
683 virtual void visitSymbol0(SymbolVisitor *visitor);
684 virtual void accept0(TypeVisitor *visitor);
685 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
688 std::vector<ObjCBaseProtocol *> _protocols;
691 class CPLUSPLUS_EXPORT ObjCForwardClassDeclaration: public Symbol, public Type
694 ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
695 virtual ~ObjCForwardClassDeclaration();
697 virtual FullySpecifiedType type() const;
699 virtual bool isEqualTo(const Type *other) const;
701 virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const
704 virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration()
707 virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType() const
710 virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType()
714 virtual void visitSymbol0(SymbolVisitor *visitor);
715 virtual void accept0(TypeVisitor *visitor);
716 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
719 class CPLUSPLUS_EXPORT ObjCClass: public Scope, public Type
722 ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
723 virtual ~ObjCClass();
725 bool isInterface() const;
726 void setInterface(bool isInterface);
728 bool isCategory() const;
729 const Name *categoryName() const;
730 void setCategoryName(const Name *categoryName);
732 ObjCBaseClass *baseClass() const;
733 void setBaseClass(ObjCBaseClass *baseClass);
735 unsigned protocolCount() const;
736 ObjCBaseProtocol *protocolAt(unsigned index) const;
737 void addProtocol(ObjCBaseProtocol *protocol);
739 // Symbol's interface
740 virtual FullySpecifiedType type() const;
743 virtual bool isEqualTo(const Type *other) const;
745 virtual const ObjCClass *asObjCClass() const
748 virtual ObjCClass *asObjCClass()
751 virtual const ObjCClass *asObjCClassType() const
754 virtual ObjCClass *asObjCClassType()
758 virtual void visitSymbol0(SymbolVisitor *visitor);
759 virtual void accept0(TypeVisitor *visitor);
760 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
763 const Name *_categoryName;
764 ObjCBaseClass * _baseClass;
765 std::vector<ObjCBaseProtocol *> _protocols;
769 class CPLUSPLUS_EXPORT ObjCMethod: public Scope, public Type
772 ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
773 virtual ~ObjCMethod();
775 FullySpecifiedType returnType() const;
776 void setReturnType(const FullySpecifiedType &returnType);
778 /** Convenience function that returns whether the function returns something (including void). */
779 bool hasReturnType() const;
781 unsigned argumentCount() const;
782 Symbol *argumentAt(unsigned index) const;
784 /** Convenience function that returns whether the function receives any arguments. */
785 bool hasArguments() const;
787 bool isVariadic() const;
788 void setVariadic(bool isVariadic);
790 // Symbol's interface
791 virtual FullySpecifiedType type() const;
794 virtual bool isEqualTo(const Type *other) const;
796 virtual const ObjCMethod *asObjCMethod() const
799 virtual ObjCMethod *asObjCMethod()
802 virtual const ObjCMethod *asObjCMethodType() const
805 virtual ObjCMethod *asObjCMethodType()
809 virtual void visitSymbol0(SymbolVisitor *visitor);
810 virtual void accept0(TypeVisitor *visitor);
811 virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
814 FullySpecifiedType _returnType;
816 unsigned _isVariadic: 1;
824 class CPLUSPLUS_EXPORT ObjCPropertyDeclaration: public Symbol
827 enum PropertyAttributes {
838 WritabilityMask = ReadOnly | ReadWrite,
839 SetterSemanticsMask = Assign | Retain | Copy
843 ObjCPropertyDeclaration(TranslationUnit *translationUnit,
844 unsigned sourceLocation,
846 virtual ~ObjCPropertyDeclaration();
848 bool hasAttribute(int attribute) const;
849 void setAttributes(int attributes);
851 bool hasGetter() const;
852 bool hasSetter() const;
854 const Name *getterName() const;
856 void setGetterName(const Name *getterName);
858 const Name *setterName() const;
859 void setSetterName(const Name *setterName);
861 void setType(const FullySpecifiedType &type);
863 // Symbol's interface
864 virtual FullySpecifiedType type() const;
866 virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const
869 virtual ObjCPropertyDeclaration *asObjCPropertyDeclaration()
873 virtual void visitSymbol0(SymbolVisitor *visitor);
876 const Name *_getterName;
877 const Name *_setterName;
878 FullySpecifiedType _type;
879 int _propertyAttributes;
882 } // namespace CPlusPlus
885 #endif // CPLUSPLUS_SYMBOLS_H