1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
33 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
35 // Permission is hereby granted, free of charge, to any person obtaining a copy
36 // of this software and associated documentation files (the "Software"), to deal
37 // in the Software without restriction, including without limitation the rights
38 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39 // copies of the Software, and to permit persons to whom the Software is
40 // furnished to do so, subject to the following conditions:
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
55 #include "TypeVisitor.h"
56 #include "SymbolVisitor.h"
57 #include "TypeMatcher.h"
60 using namespace CPlusPlus;
62 UsingNamespaceDirective::UsingNamespaceDirective(TranslationUnit *translationUnit,
63 unsigned sourceLocation, const Name *name)
64 : Symbol(translationUnit, sourceLocation, name)
67 UsingNamespaceDirective::~UsingNamespaceDirective()
70 FullySpecifiedType UsingNamespaceDirective::type() const
71 { return FullySpecifiedType(); }
73 void UsingNamespaceDirective::visitSymbol0(SymbolVisitor *visitor)
74 { visitor->visit(this); }
76 NamespaceAlias::NamespaceAlias(TranslationUnit *translationUnit,
77 unsigned sourceLocation, const Name *name)
78 : Symbol(translationUnit, sourceLocation, name), _namespaceName(0)
81 NamespaceAlias::~NamespaceAlias()
84 const Name *NamespaceAlias::namespaceName() const
85 { return _namespaceName; }
87 void NamespaceAlias::setNamespaceName(const Name *namespaceName)
88 { _namespaceName = namespaceName; }
90 FullySpecifiedType NamespaceAlias::type() const
91 { return FullySpecifiedType(); }
93 void NamespaceAlias::visitSymbol0(SymbolVisitor *visitor)
94 { visitor->visit(this); }
97 UsingDeclaration::UsingDeclaration(TranslationUnit *translationUnit,
98 unsigned sourceLocation, const Name *name)
99 : Symbol(translationUnit, sourceLocation, name)
102 UsingDeclaration::~UsingDeclaration()
105 FullySpecifiedType UsingDeclaration::type() const
106 { return FullySpecifiedType(); }
108 void UsingDeclaration::visitSymbol0(SymbolVisitor *visitor)
109 { visitor->visit(this); }
111 Declaration::Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
112 : Symbol(translationUnit, sourceLocation, name)
115 Declaration::~Declaration()
118 void Declaration::setType(const FullySpecifiedType &type)
121 FullySpecifiedType Declaration::type() const
124 void Declaration::visitSymbol0(SymbolVisitor *visitor)
125 { visitor->visit(this); }
127 Argument::Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
128 : Symbol(translationUnit, sourceLocation, name),
132 Argument::~Argument()
135 bool Argument::hasInitializer() const
136 { return _initializer != 0; }
138 const StringLiteral *Argument::initializer() const
139 { return _initializer; }
141 void Argument::setInitializer(const StringLiteral *initializer)
142 { _initializer = initializer; }
144 void Argument::setType(const FullySpecifiedType &type)
147 FullySpecifiedType Argument::type() const
150 void Argument::visitSymbol0(SymbolVisitor *visitor)
151 { visitor->visit(this); }
153 TypenameArgument::TypenameArgument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
154 : Symbol(translationUnit, sourceLocation, name)
157 TypenameArgument::~TypenameArgument()
160 void TypenameArgument::setType(const FullySpecifiedType &type)
163 FullySpecifiedType TypenameArgument::type() const
166 void TypenameArgument::visitSymbol0(SymbolVisitor *visitor)
167 { visitor->visit(this); }
169 Function::Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
170 : Scope(translationUnit, sourceLocation, name),
174 Function::~Function()
177 bool Function::isNormal() const
178 { return f._methodKey == NormalMethod; }
180 bool Function::isSignal() const
181 { return f._methodKey == SignalMethod; }
183 bool Function::isSlot() const
184 { return f._methodKey == SlotMethod; }
186 bool Function::isInvokable() const
187 { return f._methodKey == InvokableMethod; }
189 int Function::methodKey() const
190 { return f._methodKey; }
192 void Function::setMethodKey(int key)
193 { f._methodKey = key; }
195 bool Function::isEqualTo(const Type *other) const
197 const Function *o = other->asFunctionType();
200 else if (isConst() != o->isConst())
202 else if (isVolatile() != o->isVolatile())
205 else if (isInvokable() != o->isInvokable())
207 else if (isSignal() != o->isSignal())
211 const Name *l = unqualifiedName();
212 const Name *r = o->unqualifiedName();
213 if (l == r || (l && l->isEqualTo(r))) {
214 if (argumentCount() != o->argumentCount())
216 else if (! _returnType.isEqualTo(o->_returnType))
218 for (unsigned i = 0; i < argumentCount(); ++i) {
219 Symbol *l = argumentAt(i);
220 Symbol *r = o->argumentAt(i);
221 if (! l->type().isEqualTo(r->type()))
230 bool Function::isEqualTo(const Function* fct, bool ignoreName/* = false*/) const
233 return isEqualTo((Type*)fct);
237 else if (isConst() != fct->isConst())
239 else if (isVolatile() != fct->isVolatile())
241 else if (isInvokable() != fct->isInvokable())
243 else if (isSignal() != fct->isSignal())
246 if (_arguments->symbolCount() != fct->_arguments->symbolCount())
248 else if (! _returnType.isEqualTo(fct->_returnType))
250 for (unsigned i = 0; i < _arguments->symbolCount(); ++i) {
251 Symbol *l = _arguments->symbolAt(i);
252 Symbol *r = fct->_arguments->symbolAt(i);
253 if (! l->type().isEqualTo(r->type()))
260 void Function::accept0(TypeVisitor *visitor)
261 { visitor->visit(this); }
263 bool Function::matchType0(const Type *otherType, TypeMatcher *matcher) const
265 if (const Function *otherTy = otherType->asFunctionType())
266 return matcher->match(this, otherTy);
271 FullySpecifiedType Function::type() const
273 FullySpecifiedType ty(const_cast<Function *>(this));
274 ty.setConst(isConst());
275 ty.setVolatile(isVolatile());
279 FullySpecifiedType Function::returnType() const
280 { return _returnType; }
282 void Function::setReturnType(const FullySpecifiedType &returnType)
283 { _returnType = returnType; }
285 bool Function::hasReturnType() const
287 const FullySpecifiedType ty = returnType();
288 return ty.isValid() || ty.isSigned() || ty.isUnsigned();
291 unsigned Function::argumentCount() const
293 const unsigned c = memberCount();
294 if (c > 0 && memberAt(0)->type()->isVoidType())
296 if (c > 0 && memberAt(c - 1)->isBlock())
301 Symbol *Function::argumentAt(unsigned index) const
302 { return memberAt(index); }
304 bool Function::hasArguments() const
306 return ! (argumentCount() == 0 ||
307 (argumentCount() == 1 && argumentAt(0)->type()->isVoidType()));
310 unsigned Function::minimumArgumentCount() const
314 for (; index < argumentCount(); ++index) {
315 if (Argument *arg = argumentAt(index)->asArgument()) {
316 if (arg->hasInitializer())
324 bool Function::isVirtual() const
325 { return f._isVirtual; }
327 void Function::setVirtual(bool isVirtual)
328 { f._isVirtual = isVirtual; }
330 bool Function::isVariadic() const
331 { return f._isVariadic; }
333 void Function::setVariadic(bool isVariadic)
334 { f._isVariadic = isVariadic; }
336 bool Function::isConst() const
337 { return f._isConst; }
339 void Function::setConst(bool isConst)
340 { f._isConst = isConst; }
342 bool Function::isVolatile() const
343 { return f._isVolatile; }
345 void Function::setVolatile(bool isVolatile)
346 { f._isVolatile = isVolatile; }
348 bool Function::isPureVirtual() const
349 { return f._isPureVirtual; }
351 void Function::setPureVirtual(bool isPureVirtual)
352 { f._isPureVirtual = isPureVirtual; }
354 bool Function::isAmbiguous() const
355 { return f._isAmbiguous; }
357 void Function::setAmbiguous(bool isAmbiguous)
358 { f._isAmbiguous = isAmbiguous; }
360 void Function::visitSymbol0(SymbolVisitor *visitor)
362 if (visitor->visit(this)) {
363 for (unsigned i = 0; i < memberCount(); ++i) {
364 visitSymbol(memberAt(i), visitor);
369 bool Function::maybeValidPrototype(unsigned actualArgumentCount) const
371 unsigned minNumberArguments = 0;
373 for (; minNumberArguments < this->argumentCount(); ++minNumberArguments) {
374 Argument *arg = this->argumentAt(minNumberArguments)->asArgument();
376 if (arg->hasInitializer())
380 if (actualArgumentCount < minNumberArguments) {
381 // not enough arguments.
384 } else if (! this->isVariadic() && actualArgumentCount > this->argumentCount()) {
385 // too many arguments.
393 Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation)
394 : Scope(translationUnit, sourceLocation, /*name = */ 0)
400 FullySpecifiedType Block::type() const
401 { return FullySpecifiedType(); }
403 void Block::visitSymbol0(SymbolVisitor *visitor)
405 if (visitor->visit(this)) {
406 for (unsigned i = 0; i < memberCount(); ++i) {
407 visitSymbol(memberAt(i), visitor);
412 Enum::Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
413 : Scope(translationUnit, sourceLocation, name)
419 FullySpecifiedType Enum::type() const
420 { return FullySpecifiedType(const_cast<Enum *>(this)); }
422 bool Enum::isEqualTo(const Type *other) const
424 const Enum *o = other->asEnumType();
427 const Name *l = unqualifiedName();
428 const Name *r = o->unqualifiedName();
433 return l->isEqualTo(r);
436 void Enum::accept0(TypeVisitor *visitor)
437 { visitor->visit(this); }
439 bool Enum::matchType0(const Type *otherType, TypeMatcher *matcher) const
441 if (const Enum *otherTy = otherType->asEnumType())
442 return matcher->match(this, otherTy);
447 void Enum::visitSymbol0(SymbolVisitor *visitor)
449 if (visitor->visit(this)) {
450 for (unsigned i = 0; i < memberCount(); ++i) {
451 visitSymbol(memberAt(i), visitor);
456 Template::Template(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
457 : Scope(translationUnit, sourceLocation, name)
460 Template::~Template()
463 unsigned Template::templateParameterCount() const
465 if (declaration() != 0)
466 return memberCount() - 1;
471 Symbol *Template::templateParameterAt(unsigned index) const
472 { return memberAt(index); }
474 Symbol *Template::declaration() const
479 if (Symbol *s = memberAt(memberCount() - 1)) {
480 if (s->isClass() || s->isForwardClassDeclaration() ||
481 s->isTemplate() || s->isFunction() || s->isDeclaration())
488 FullySpecifiedType Template::type() const
489 { return FullySpecifiedType(const_cast<Template *>(this)); }
491 bool Template::isEqualTo(const Type *other) const
492 { return other == this; }
494 void Template::visitSymbol0(SymbolVisitor *visitor)
496 if (visitor->visit(this)) {
497 for (unsigned i = 0; i < memberCount(); ++i) {
498 visitSymbol(memberAt(i), visitor);
503 void Template::accept0(TypeVisitor *visitor)
504 { visitor->visit(this); }
506 bool Template::matchType0(const Type *otherType, TypeMatcher *matcher) const
508 if (const Template *otherTy = otherType->asTemplateType())
509 return matcher->match(this, otherTy);
513 Namespace::Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
514 : Scope(translationUnit, sourceLocation, name)
517 Namespace::~Namespace()
520 bool Namespace::isEqualTo(const Type *other) const
522 const Namespace *o = other->asNamespaceType();
525 const Name *l = unqualifiedName();
526 const Name *r = o->unqualifiedName();
527 if (l == r || (l && l->isEqualTo(r)))
532 void Namespace::accept0(TypeVisitor *visitor)
533 { visitor->visit(this); }
535 bool Namespace::matchType0(const Type *otherType, TypeMatcher *matcher) const
537 if (const Namespace *otherTy = otherType->asNamespaceType())
538 return matcher->match(this, otherTy);
543 void Namespace::visitSymbol0(SymbolVisitor *visitor)
545 if (visitor->visit(this)) {
546 for (unsigned i = 0; i < memberCount(); ++i) {
547 visitSymbol(memberAt(i), visitor);
552 FullySpecifiedType Namespace::type() const
553 { return FullySpecifiedType(const_cast<Namespace *>(this)); }
555 BaseClass::BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
556 : Symbol(translationUnit, sourceLocation, name),
560 BaseClass::~BaseClass()
563 FullySpecifiedType BaseClass::type() const
566 void BaseClass::setType(const FullySpecifiedType &type)
569 bool BaseClass::isVirtual() const
570 { return _isVirtual; }
572 void BaseClass::setVirtual(bool isVirtual)
573 { _isVirtual = isVirtual; }
575 void BaseClass::visitSymbol0(SymbolVisitor *visitor)
576 { visitor->visit(this); }
578 ForwardClassDeclaration::ForwardClassDeclaration(TranslationUnit *translationUnit,
579 unsigned sourceLocation, const Name *name)
580 : Symbol(translationUnit, sourceLocation, name)
583 ForwardClassDeclaration::~ForwardClassDeclaration()
586 FullySpecifiedType ForwardClassDeclaration::type() const
587 { return FullySpecifiedType(const_cast<ForwardClassDeclaration *>(this)); }
589 bool ForwardClassDeclaration::isEqualTo(const Type *other) const
591 if (const ForwardClassDeclaration *otherClassFwdTy = other->asForwardClassDeclarationType()) {
592 if (name() == otherClassFwdTy->name())
594 else if (name() && otherClassFwdTy->name())
595 return name()->isEqualTo(otherClassFwdTy->name());
602 void ForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor)
603 { visitor->visit(this); }
605 void ForwardClassDeclaration::accept0(TypeVisitor *visitor)
606 { visitor->visit(this); }
608 bool ForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const
610 if (const ForwardClassDeclaration *otherTy = otherType->asForwardClassDeclarationType())
611 return matcher->match(this, otherTy);
616 Class::Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
617 : Scope(translationUnit, sourceLocation, name),
624 bool Class::isClass() const
625 { return _key == ClassKey; }
627 bool Class::isStruct() const
628 { return _key == StructKey; }
630 bool Class::isUnion() const
631 { return _key == UnionKey; }
633 Class::Key Class::classKey() const
636 void Class::setClassKey(Key key)
639 void Class::accept0(TypeVisitor *visitor)
640 { visitor->visit(this); }
642 bool Class::matchType0(const Type *otherType, TypeMatcher *matcher) const
644 if (const Class *otherTy = otherType->asClassType())
645 return matcher->match(this, otherTy);
650 unsigned Class::baseClassCount() const
651 { return _baseClasses.size(); }
653 BaseClass *Class::baseClassAt(unsigned index) const
654 { return _baseClasses.at(index); }
656 void Class::addBaseClass(BaseClass *baseClass)
657 { _baseClasses.push_back(baseClass); }
659 FullySpecifiedType Class::type() const
660 { return FullySpecifiedType(const_cast<Class *>(this)); }
662 bool Class::isEqualTo(const Type *other) const
664 const Class *o = other->asClassType();
667 const Name *l = unqualifiedName();
668 const Name *r = o->unqualifiedName();
669 if (l == r || (l && l->isEqualTo(r)))
675 void Class::visitSymbol0(SymbolVisitor *visitor)
677 if (visitor->visit(this)) {
678 for (unsigned i = 0; i < _baseClasses.size(); ++i) {
679 visitSymbol(_baseClasses.at(i), visitor);
681 for (unsigned i = 0; i < memberCount(); ++i) {
682 visitSymbol(memberAt(i), visitor);
688 QtPropertyDeclaration::QtPropertyDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
689 : Symbol(translationUnit, sourceLocation, name)
693 QtPropertyDeclaration::~QtPropertyDeclaration()
696 void QtPropertyDeclaration::setType(const FullySpecifiedType &type)
699 void QtPropertyDeclaration::setFlags(int flags)
702 int QtPropertyDeclaration::flags() const
705 FullySpecifiedType QtPropertyDeclaration::type() const
708 void QtPropertyDeclaration::visitSymbol0(SymbolVisitor *visitor)
709 { visitor->visit(this); }
712 QtEnum::QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
713 : Symbol(translationUnit, sourceLocation, name)
719 FullySpecifiedType QtEnum::type() const
720 { return FullySpecifiedType(); }
722 void QtEnum::visitSymbol0(SymbolVisitor *visitor)
723 { visitor->visit(this); }
726 ObjCBaseClass::ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
727 : Symbol(translationUnit, sourceLocation, name)
730 ObjCBaseClass::~ObjCBaseClass()
733 FullySpecifiedType ObjCBaseClass::type() const
734 { return FullySpecifiedType(); }
736 void ObjCBaseClass::visitSymbol0(SymbolVisitor *visitor)
737 { visitor->visit(this); }
739 ObjCBaseProtocol::ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
740 : Symbol(translationUnit, sourceLocation, name)
743 ObjCBaseProtocol::~ObjCBaseProtocol()
746 FullySpecifiedType ObjCBaseProtocol::type() const
747 { return FullySpecifiedType(); }
749 void ObjCBaseProtocol::visitSymbol0(SymbolVisitor *visitor)
750 { visitor->visit(this); }
752 ObjCClass::ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name):
753 Scope(translationUnit, sourceLocation, name),
760 ObjCClass::~ObjCClass()
763 bool ObjCClass::isInterface() const
764 { return _isInterface; }
766 void ObjCClass::setInterface(bool isInterface)
767 { _isInterface = isInterface; }
769 bool ObjCClass::isCategory() const
770 { return _categoryName != 0; }
772 const Name *ObjCClass::categoryName() const
773 { return _categoryName; }
775 void ObjCClass::setCategoryName(const Name *categoryName)
776 { _categoryName = categoryName; }
778 ObjCBaseClass *ObjCClass::baseClass() const
779 { return _baseClass; }
781 void ObjCClass::setBaseClass(ObjCBaseClass *baseClass)
782 { _baseClass = baseClass; }
784 unsigned ObjCClass::protocolCount() const
785 { return _protocols.size(); }
787 ObjCBaseProtocol *ObjCClass::protocolAt(unsigned index) const
788 { return _protocols.at(index); }
790 void ObjCClass::addProtocol(ObjCBaseProtocol *protocol)
791 { _protocols.push_back(protocol); }
793 FullySpecifiedType ObjCClass::type() const
794 { return FullySpecifiedType(const_cast<ObjCClass *>(this)); }
796 bool ObjCClass::isEqualTo(const Type *other) const
798 const ObjCClass *o = other->asObjCClassType();
802 const Name *l = unqualifiedName();
803 const Name *r = o->unqualifiedName();
804 if (l == r || (l && l->isEqualTo(r)))
810 void ObjCClass::visitSymbol0(SymbolVisitor *visitor)
812 if (visitor->visit(this)) {
814 visitSymbol(_baseClass, visitor);
816 for (unsigned i = 0; i < _protocols.size(); ++i)
817 visitSymbol(_protocols.at(i), visitor);
819 for (unsigned i = 0; i < memberCount(); ++i)
820 visitSymbol(memberAt(i), visitor);
824 void ObjCClass::accept0(TypeVisitor *visitor)
825 { visitor->visit(this); }
827 bool ObjCClass::matchType0(const Type *otherType, TypeMatcher *matcher) const
829 if (const ObjCClass *otherTy = otherType->asObjCClassType())
830 return matcher->match(this, otherTy);
835 ObjCProtocol::ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name):
836 Scope(translationUnit, sourceLocation, name)
840 ObjCProtocol::~ObjCProtocol()
843 unsigned ObjCProtocol::protocolCount() const
844 { return _protocols.size(); }
846 ObjCBaseProtocol *ObjCProtocol::protocolAt(unsigned index) const
847 { return _protocols.at(index); }
849 void ObjCProtocol::addProtocol(ObjCBaseProtocol *protocol)
850 { _protocols.push_back(protocol); }
852 FullySpecifiedType ObjCProtocol::type() const
853 { return FullySpecifiedType(const_cast<ObjCProtocol *>(this)); }
855 bool ObjCProtocol::isEqualTo(const Type *other) const
857 const ObjCProtocol *o = other->asObjCProtocolType();
861 const Name *l = unqualifiedName();
862 const Name *r = o->unqualifiedName();
863 if (l == r || (l && l->isEqualTo(r)))
869 void ObjCProtocol::visitSymbol0(SymbolVisitor *visitor)
871 if (visitor->visit(this)) {
872 for (unsigned i = 0; i < _protocols.size(); ++i)
873 visitSymbol(_protocols.at(i), visitor);
877 void ObjCProtocol::accept0(TypeVisitor *visitor)
878 { visitor->visit(this); }
880 bool ObjCProtocol::matchType0(const Type *otherType, TypeMatcher *matcher) const
882 if (const ObjCProtocol *otherTy = otherType->asObjCProtocolType())
883 return matcher->match(this, otherTy);
888 ObjCForwardClassDeclaration::ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation,
890 Symbol(translationUnit, sourceLocation, name)
894 ObjCForwardClassDeclaration::~ObjCForwardClassDeclaration()
897 FullySpecifiedType ObjCForwardClassDeclaration::type() const
898 { return FullySpecifiedType(); }
900 bool ObjCForwardClassDeclaration::isEqualTo(const Type *other) const
902 if (const ObjCForwardClassDeclaration *otherFwdClass = other->asObjCForwardClassDeclarationType()) {
903 if (name() == otherFwdClass->name())
905 else if (name() && otherFwdClass->name())
906 return name()->isEqualTo(otherFwdClass->name());
914 void ObjCForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor)
915 { visitor->visit(this); }
917 void ObjCForwardClassDeclaration::accept0(TypeVisitor *visitor)
918 { visitor->visit(this); }
920 bool ObjCForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const
922 if (const ObjCForwardClassDeclaration *otherTy = otherType->asObjCForwardClassDeclarationType())
923 return matcher->match(this, otherTy);
928 ObjCForwardProtocolDeclaration::ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation,
930 Symbol(translationUnit, sourceLocation, name)
934 ObjCForwardProtocolDeclaration::~ObjCForwardProtocolDeclaration()
937 FullySpecifiedType ObjCForwardProtocolDeclaration::type() const
938 { return FullySpecifiedType(); }
940 bool ObjCForwardProtocolDeclaration::isEqualTo(const Type *other) const
942 if (const ObjCForwardProtocolDeclaration *otherFwdProtocol = other->asObjCForwardProtocolDeclarationType()) {
943 if (name() == otherFwdProtocol->name())
945 else if (name() && otherFwdProtocol->name())
946 return name()->isEqualTo(otherFwdProtocol->name());
954 void ObjCForwardProtocolDeclaration::visitSymbol0(SymbolVisitor *visitor)
955 { visitor->visit(this); }
957 void ObjCForwardProtocolDeclaration::accept0(TypeVisitor *visitor)
958 { visitor->visit(this); }
960 bool ObjCForwardProtocolDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const
962 if (const ObjCForwardProtocolDeclaration *otherTy = otherType->asObjCForwardProtocolDeclarationType())
963 return matcher->match(this, otherTy);
968 ObjCMethod::ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
969 : Scope(translationUnit, sourceLocation, name),
973 ObjCMethod::~ObjCMethod()
976 bool ObjCMethod::isEqualTo(const Type *other) const
978 const ObjCMethod *o = other->asObjCMethodType();
982 const Name *l = unqualifiedName();
983 const Name *r = o->unqualifiedName();
984 if (l == r || (l && l->isEqualTo(r))) {
985 if (argumentCount() != o->argumentCount())
987 else if (! _returnType.isEqualTo(o->_returnType))
989 for (unsigned i = 0; i < argumentCount(); ++i) {
990 Symbol *l = argumentAt(i);
991 Symbol *r = o->argumentAt(i);
992 if (! l->type().isEqualTo(r->type()))
1000 void ObjCMethod::accept0(TypeVisitor *visitor)
1001 { visitor->visit(this); }
1003 bool ObjCMethod::matchType0(const Type *otherType, TypeMatcher *matcher) const
1005 if (const ObjCMethod *otherTy = otherType->asObjCMethodType())
1006 return matcher->match(this, otherTy);
1011 FullySpecifiedType ObjCMethod::type() const
1012 { return FullySpecifiedType(const_cast<ObjCMethod *>(this)); }
1014 FullySpecifiedType ObjCMethod::returnType() const
1015 { return _returnType; }
1017 void ObjCMethod::setReturnType(const FullySpecifiedType &returnType)
1018 { _returnType = returnType; }
1020 bool ObjCMethod::hasReturnType() const
1022 const FullySpecifiedType ty = returnType();
1023 return ty.isValid() || ty.isSigned() || ty.isUnsigned();
1026 unsigned ObjCMethod::argumentCount() const
1028 const unsigned c = memberCount();
1029 if (c > 0 && memberAt(c - 1)->isBlock())
1034 Symbol *ObjCMethod::argumentAt(unsigned index) const
1036 return memberAt(index);
1039 bool ObjCMethod::hasArguments() const
1041 return ! (argumentCount() == 0 ||
1042 (argumentCount() == 1 && argumentAt(0)->type()->isVoidType()));
1045 bool ObjCMethod::isVariadic() const
1046 { return f._isVariadic; }
1048 void ObjCMethod::setVariadic(bool isVariadic)
1049 { f._isVariadic = isVariadic; }
1051 void ObjCMethod::visitSymbol0(SymbolVisitor *visitor)
1053 if (visitor->visit(this)) {
1054 for (unsigned i = 0; i < memberCount(); ++i) {
1055 visitSymbol(memberAt(i), visitor);
1060 ObjCPropertyDeclaration::ObjCPropertyDeclaration(TranslationUnit *translationUnit,
1061 unsigned sourceLocation,
1063 Symbol(translationUnit, sourceLocation, name),
1066 _propertyAttributes(None)
1069 ObjCPropertyDeclaration::~ObjCPropertyDeclaration()
1072 bool ObjCPropertyDeclaration::hasAttribute(int attribute) const
1073 { return _propertyAttributes & attribute; }
1075 void ObjCPropertyDeclaration::setAttributes(int attributes)
1076 { _propertyAttributes = attributes; }
1078 bool ObjCPropertyDeclaration::hasGetter() const
1079 { return hasAttribute(Getter); }
1081 bool ObjCPropertyDeclaration::hasSetter() const
1082 { return hasAttribute(Setter); }
1084 const Name *ObjCPropertyDeclaration::getterName() const
1085 { return _getterName; }
1087 void ObjCPropertyDeclaration::setGetterName(const Name *getterName)
1088 { _getterName = getterName; }
1090 const Name *ObjCPropertyDeclaration::setterName() const
1091 { return _setterName; }
1093 void ObjCPropertyDeclaration::setSetterName(const Name *setterName)
1094 { _setterName = setterName; }
1096 void ObjCPropertyDeclaration::setType(const FullySpecifiedType &type)
1099 FullySpecifiedType ObjCPropertyDeclaration::type() const
1102 void ObjCPropertyDeclaration::visitSymbol0(SymbolVisitor *visitor)
1104 if (visitor->visit(this)) {