Symbols.cpp 28.9 KB
Newer Older
con's avatar
con committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// 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.

#include "Symbols.h"
#include "Names.h"
#include "TypeVisitor.h"
#include "SymbolVisitor.h"
Roberto Raggi's avatar
Roberto Raggi committed
25
#include "TypeMatcher.h"
con's avatar
con committed
26 27
#include "Scope.h"

Roberto Raggi's avatar
Roberto Raggi committed
28
using namespace CPlusPlus;
con's avatar
con committed
29 30

UsingNamespaceDirective::UsingNamespaceDirective(TranslationUnit *translationUnit,
Roberto Raggi's avatar
Roberto Raggi committed
31
                                                 unsigned sourceLocation, const Name *name)
con's avatar
con committed
32 33 34 35 36 37 38 39 40 41 42 43
    : Symbol(translationUnit, sourceLocation, name)
{ }

UsingNamespaceDirective::~UsingNamespaceDirective()
{ }

FullySpecifiedType UsingNamespaceDirective::type() const
{ return FullySpecifiedType(); }

void UsingNamespaceDirective::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
NamespaceAlias::NamespaceAlias(TranslationUnit *translationUnit,
                               unsigned sourceLocation, const Name *name)
    : Symbol(translationUnit, sourceLocation, name), _namespaceName(0)
{ }

NamespaceAlias::~NamespaceAlias()
{ }

const Name *NamespaceAlias::namespaceName() const
{ return _namespaceName; }

void NamespaceAlias::setNamespaceName(const Name *namespaceName)
{ _namespaceName = namespaceName; }

FullySpecifiedType NamespaceAlias::type() const
{ return FullySpecifiedType(); }

void NamespaceAlias::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }


con's avatar
con committed
65
UsingDeclaration::UsingDeclaration(TranslationUnit *translationUnit,
Roberto Raggi's avatar
Roberto Raggi committed
66
                                   unsigned sourceLocation, const Name *name)
con's avatar
con committed
67 68 69 70 71 72 73 74 75 76 77 78
    : Symbol(translationUnit, sourceLocation, name)
{ }

UsingDeclaration::~UsingDeclaration()
{ }

FullySpecifiedType UsingDeclaration::type() const
{ return FullySpecifiedType(); }

void UsingDeclaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
79
Declaration::Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
Roberto Raggi's avatar
Roberto Raggi committed
80
    : Symbol(translationUnit, sourceLocation, name)
con's avatar
con committed
81 82 83
{ }

Declaration::~Declaration()
Roberto Raggi's avatar
Roberto Raggi committed
84
{ }
con's avatar
con committed
85

86
void Declaration::setType(const FullySpecifiedType &type)
con's avatar
con committed
87 88 89 90 91 92 93 94
{ _type = type; }

FullySpecifiedType Declaration::type() const
{ return _type; }

void Declaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

95 96 97 98 99 100 101 102 103 104 105 106 107 108
EnumeratorDeclaration::EnumeratorDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
    : Declaration(translationUnit, sourceLocation, name)
    , _constantValue(0)
{}

EnumeratorDeclaration::~EnumeratorDeclaration()
{}

const StringLiteral *EnumeratorDeclaration::constantValue() const
{ return _constantValue; }

void EnumeratorDeclaration::setConstantValue(const StringLiteral *constantValue)
{ _constantValue = constantValue; }

Roberto Raggi's avatar
Roberto Raggi committed
109
Argument::Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
con's avatar
con committed
110
    : Symbol(translationUnit, sourceLocation, name),
111
      _initializer(0)
con's avatar
con committed
112 113 114 115 116 117
{ }

Argument::~Argument()
{ }

bool Argument::hasInitializer() const
118 119 120
{ return _initializer != 0; }

const StringLiteral *Argument::initializer() const
con's avatar
con committed
121 122
{ return _initializer; }

123 124
void Argument::setInitializer(const StringLiteral *initializer)
{ _initializer = initializer; }
con's avatar
con committed
125

126
void Argument::setType(const FullySpecifiedType &type)
con's avatar
con committed
127 128 129 130 131 132 133 134
{ _type = type; }

FullySpecifiedType Argument::type() const
{ return _type; }

void Argument::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
TypenameArgument::TypenameArgument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
    : Symbol(translationUnit, sourceLocation, name)
{ }

TypenameArgument::~TypenameArgument()
{ }

void TypenameArgument::setType(const FullySpecifiedType &type)
{ _type = type; }

FullySpecifiedType TypenameArgument::type() const
{ return _type; }

void TypenameArgument::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
151
Function::Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
Roberto Raggi's avatar
Roberto Raggi committed
152
    : Scope(translationUnit, sourceLocation, name),
153 154
      _flags(0)
{ }
con's avatar
con committed
155 156

Function::~Function()
Roberto Raggi's avatar
Roberto Raggi committed
157
{ }
con's avatar
con committed
158 159

bool Function::isNormal() const
160
{ return f._methodKey == NormalMethod; }
con's avatar
con committed
161 162

bool Function::isSignal() const
163
{ return f._methodKey == SignalMethod; }
con's avatar
con committed
164 165

bool Function::isSlot() const
166
{ return f._methodKey == SlotMethod; }
con's avatar
con committed
167

168 169 170
bool Function::isInvokable() const
{ return f._methodKey == InvokableMethod; }

con's avatar
con committed
171
int Function::methodKey() const
172
{ return f._methodKey; }
con's avatar
con committed
173 174

void Function::setMethodKey(int key)
175
{ f._methodKey = key; }
con's avatar
con committed
176 177 178

bool Function::isEqualTo(const Type *other) const
{
179
    const Function *o = other->asFunctionType();
con's avatar
con committed
180 181
    if (! o)
        return false;
182 183 184 185
    else if (isConst() != o->isConst())
        return false;
    else if (isVolatile() != o->isVolatile())
        return false;
186
#ifdef ICHECK_BUILD
Wolfgang Beck's avatar
Wolfgang Beck committed
187 188 189
    else if (isInvokable() != o->isInvokable())
        return false;
    else if (isSignal() != o->isSignal())
190 191
        return false;
#endif
192

193 194
    const Name *l = unqualifiedName();
    const Name *r = o->unqualifiedName();
con's avatar
con committed
195
    if (l == r || (l && l->isEqualTo(r))) {
196
        if (argumentCount() != o->argumentCount())
con's avatar
con committed
197 198 199
            return false;
        else if (! _returnType.isEqualTo(o->_returnType))
            return false;
200 201 202
        for (unsigned i = 0; i < argumentCount(); ++i) {
            Symbol *l = argumentAt(i);
            Symbol *r = o->argumentAt(i);
con's avatar
con committed
203 204 205 206 207 208 209 210
            if (! l->type().isEqualTo(r->type()))
                return false;
        }
        return true;
    }
    return false;
}

211 212 213 214 215 216 217 218 219 220 221 222 223 224
#ifdef ICHECK_BUILD
bool Function::isEqualTo(const Function* fct, bool ignoreName/* = false*/) const
{
    if(!ignoreName)
        return isEqualTo((Type*)fct);

    if (! fct)
        return false;
    else if (isConst() != fct->isConst())
        return false;
    else if (isVolatile() != fct->isVolatile())
        return false;
    else if (isInvokable() != fct->isInvokable())
        return false;
Wolfgang Beck's avatar
Wolfgang Beck committed
225 226
    else if (isSignal() != fct->isSignal())
        return false;
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

    if (_arguments->symbolCount() != fct->_arguments->symbolCount())
        return false;
    else if (! _returnType.isEqualTo(fct->_returnType))
        return false;
    for (unsigned i = 0; i < _arguments->symbolCount(); ++i) {
        Symbol *l = _arguments->symbolAt(i);
        Symbol *r = fct->_arguments->symbolAt(i);
        if (! l->type().isEqualTo(r->type()))
            return false;
    }
    return true;
}
#endif

con's avatar
con committed
242 243 244
void Function::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
245 246 247 248 249 250 251 252
bool Function::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const Function *otherTy = otherType->asFunctionType())
        return matcher->match(this, otherTy);

    return false;
}

con's avatar
con committed
253
FullySpecifiedType Function::type() const
254 255 256 257 258 259
{
    FullySpecifiedType ty(const_cast<Function *>(this));
    ty.setConst(isConst());
    ty.setVolatile(isVolatile());
    return ty;
}
con's avatar
con committed
260 261 262 263

FullySpecifiedType Function::returnType() const
{ return _returnType; }

264
void Function::setReturnType(const FullySpecifiedType &returnType)
con's avatar
con committed
265 266
{ _returnType = returnType; }

267 268 269 270 271 272
bool Function::hasReturnType() const
{
    const FullySpecifiedType ty = returnType();
    return ty.isValid() || ty.isSigned() || ty.isUnsigned();
}

con's avatar
con committed
273 274
unsigned Function::argumentCount() const
{
275
    const unsigned c = memberCount();
276 277
    if (c > 0 && memberAt(0)->type()->isVoidType())
        return 0;
278 279 280
    if (c > 0 && memberAt(c - 1)->isBlock())
        return c - 1;
    return c;
con's avatar
con committed
281 282 283
}

Symbol *Function::argumentAt(unsigned index) const
284
{ return memberAt(index); }
con's avatar
con committed
285

286 287 288 289 290 291
bool Function::hasArguments() const
{
    return ! (argumentCount() == 0 ||
              (argumentCount() == 1 && argumentAt(0)->type()->isVoidType()));
}

Roberto Raggi's avatar
Roberto Raggi committed
292 293 294 295
unsigned Function::minimumArgumentCount() const
{
    unsigned index = 0;

296 297
    for (; index < argumentCount(); ++index) {
        if (Argument *arg = argumentAt(index)->asArgument()) {
Roberto Raggi's avatar
Roberto Raggi committed
298 299 300 301 302 303 304 305
            if (arg->hasInitializer())
                break;
        }
    }

    return index;
}

306 307 308 309 310 311
bool Function::isVirtual() const
{ return f._isVirtual; }

void Function::setVirtual(bool isVirtual)
{ f._isVirtual = isVirtual; }

con's avatar
con committed
312
bool Function::isVariadic() const
313
{ return f._isVariadic; }
con's avatar
con committed
314 315

void Function::setVariadic(bool isVariadic)
316
{ f._isVariadic = isVariadic; }
con's avatar
con committed
317 318

bool Function::isConst() const
319
{ return f._isConst; }
con's avatar
con committed
320 321

void Function::setConst(bool isConst)
322
{ f._isConst = isConst; }
con's avatar
con committed
323 324

bool Function::isVolatile() const
325
{ return f._isVolatile; }
con's avatar
con committed
326 327

void Function::setVolatile(bool isVolatile)
328
{ f._isVolatile = isVolatile; }
con's avatar
con committed
329 330

bool Function::isPureVirtual() const
331
{ return f._isPureVirtual; }
con's avatar
con committed
332 333

void Function::setPureVirtual(bool isPureVirtual)
334
{ f._isPureVirtual = isPureVirtual; }
con's avatar
con committed
335

336
bool Function::isAmbiguous() const
337
{ return f._isAmbiguous; }
338 339

void Function::setAmbiguous(bool isAmbiguous)
340
{ f._isAmbiguous = isAmbiguous; }
341

con's avatar
con committed
342 343 344 345 346 347 348 349 350
void Function::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < memberCount(); ++i) {
            visitSymbol(memberAt(i), visitor);
        }
    }
}

351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
bool Function::maybeValidPrototype(unsigned actualArgumentCount) const
{
    unsigned minNumberArguments = 0;

    for (; minNumberArguments < this->argumentCount(); ++minNumberArguments) {
        Argument *arg = this->argumentAt(minNumberArguments)->asArgument();

        if (arg->hasInitializer())
            break;
    }

    if (actualArgumentCount < minNumberArguments) {
        // not enough arguments.
        return false;

    } else if (! this->isVariadic() && actualArgumentCount > this->argumentCount()) {
        // too many arguments.
        return false;
    }

    return true;
}


con's avatar
con committed
375
Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation)
Roberto Raggi's avatar
Roberto Raggi committed
376
    : Scope(translationUnit, sourceLocation, /*name = */ 0)
con's avatar
con committed
377 378 379 380 381 382 383 384 385
{ }

Block::~Block()
{ }

FullySpecifiedType Block::type() const
{ return FullySpecifiedType(); }

void Block::visitSymbol0(SymbolVisitor *visitor)
386 387 388 389 390 391 392
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < memberCount(); ++i) {
            visitSymbol(memberAt(i), visitor);
        }
    }
}
con's avatar
con committed
393

Roberto Raggi's avatar
Roberto Raggi committed
394
Enum::Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
Roberto Raggi's avatar
Roberto Raggi committed
395
    : Scope(translationUnit, sourceLocation, name)
con's avatar
con committed
396 397 398 399 400 401 402 403 404 405
{ }

Enum::~Enum()
{ }

FullySpecifiedType Enum::type() const
{ return FullySpecifiedType(const_cast<Enum *>(this)); }

bool Enum::isEqualTo(const Type *other) const
{
406
    const Enum *o = other->asEnumType();
con's avatar
con committed
407 408
    if (! o)
        return false;
409 410
    const Name *l = unqualifiedName();
    const Name *r = o->unqualifiedName();
con's avatar
con committed
411 412 413 414 415 416 417 418 419 420
    if (l == r)
        return true;
    else if (! l)
        return false;
    return l->isEqualTo(r);
}

void Enum::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
421 422 423 424 425 426 427 428
bool Enum::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const Enum *otherTy = otherType->asEnumType())
        return matcher->match(this, otherTy);

    return false;
}

con's avatar
con committed
429 430 431 432 433 434 435 436 437
void Enum::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < memberCount(); ++i) {
            visitSymbol(memberAt(i), visitor);
        }
    }
}

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
Template::Template(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
    : Scope(translationUnit, sourceLocation, name)
{ }

Template::~Template()
{ }

unsigned Template::templateParameterCount() const
{
    if (declaration() != 0)
        return memberCount() - 1;

    return 0;
}

Symbol *Template::templateParameterAt(unsigned index) const
{ return memberAt(index); }

Symbol *Template::declaration() const
{
    if (isEmpty())
        return 0;

    if (Symbol *s = memberAt(memberCount() - 1)) {
        if (s->isClass() || s->isForwardClassDeclaration() ||
            s->isTemplate() || s->isFunction() || s->isDeclaration())
            return s;
    }

    return 0;
}

FullySpecifiedType Template::type() const
{ return FullySpecifiedType(const_cast<Template *>(this)); }

bool Template::isEqualTo(const Type *other) const
{ return other == this; }

void Template::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < memberCount(); ++i) {
            visitSymbol(memberAt(i), visitor);
        }
    }
}

void Template::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

bool Template::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const Template *otherTy = otherType->asTemplateType())
        return matcher->match(this, otherTy);
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
495
Namespace::Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
Roberto Raggi's avatar
Roberto Raggi committed
496
    : Scope(translationUnit, sourceLocation, name)
con's avatar
con committed
497 498 499 500 501 502 503
{ }

Namespace::~Namespace()
{ }

bool Namespace::isEqualTo(const Type *other) const
{
504
    const Namespace *o = other->asNamespaceType();
con's avatar
con committed
505 506
    if (! o)
        return false;
507 508
    const Name *l = unqualifiedName();
    const Name *r = o->unqualifiedName();
con's avatar
con committed
509 510 511 512 513 514 515 516
    if (l == r || (l && l->isEqualTo(r)))
        return true;
    return false;
}

void Namespace::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
517 518 519 520 521 522 523 524
bool Namespace::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const Namespace *otherTy = otherType->asNamespaceType())
        return matcher->match(this, otherTy);

    return false;
}

con's avatar
con committed
525 526 527 528 529 530 531 532 533 534 535 536
void Namespace::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < memberCount(); ++i) {
            visitSymbol(memberAt(i), visitor);
        }
    }
}

FullySpecifiedType Namespace::type() const
{ return FullySpecifiedType(const_cast<Namespace *>(this)); }

Roberto Raggi's avatar
Roberto Raggi committed
537
BaseClass::BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
con's avatar
con committed
538 539 540 541 542 543 544 545
    : Symbol(translationUnit, sourceLocation, name),
      _isVirtual(false)
{ }

BaseClass::~BaseClass()
{ }

FullySpecifiedType BaseClass::type() const
Roberto Raggi's avatar
Roberto Raggi committed
546 547 548 549
{ return _type; }

void BaseClass::setType(const FullySpecifiedType &type)
{ _type = type; }
con's avatar
con committed
550 551 552 553 554 555 556 557

bool BaseClass::isVirtual() const
{ return _isVirtual; }

void BaseClass::setVirtual(bool isVirtual)
{ _isVirtual = isVirtual; }

void BaseClass::visitSymbol0(SymbolVisitor *visitor)
558 559 560
{ visitor->visit(this); }

ForwardClassDeclaration::ForwardClassDeclaration(TranslationUnit *translationUnit,
Roberto Raggi's avatar
Roberto Raggi committed
561
                                                 unsigned sourceLocation, const Name *name)
Roberto Raggi's avatar
Roberto Raggi committed
562
    : Symbol(translationUnit, sourceLocation, name)
563 564 565
{ }

ForwardClassDeclaration::~ForwardClassDeclaration()
Roberto Raggi's avatar
Roberto Raggi committed
566
{ }
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587

FullySpecifiedType ForwardClassDeclaration::type() const
{ return FullySpecifiedType(const_cast<ForwardClassDeclaration *>(this)); }

bool ForwardClassDeclaration::isEqualTo(const Type *other) const
{
    if (const ForwardClassDeclaration *otherClassFwdTy = other->asForwardClassDeclarationType()) {
        if (name() == otherClassFwdTy->name())
            return true;
        else if (name() && otherClassFwdTy->name())
            return name()->isEqualTo(otherClassFwdTy->name());

        return false;
    }
    return false;
}

void ForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

void ForwardClassDeclaration::accept0(TypeVisitor *visitor)
con's avatar
con committed
588 589
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
590 591 592 593 594 595 596 597
bool ForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const ForwardClassDeclaration *otherTy = otherType->asForwardClassDeclarationType())
        return matcher->match(this, otherTy);

    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
598
Class::Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
Roberto Raggi's avatar
Roberto Raggi committed
599
    : Scope(translationUnit, sourceLocation, name),
Roberto Raggi's avatar
Roberto Raggi committed
600
      _key(ClassKey)
con's avatar
con committed
601 602 603
{ }

Class::~Class()
Roberto Raggi's avatar
Roberto Raggi committed
604
{ }
con's avatar
con committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623

bool Class::isClass() const
{ return _key == ClassKey; }

bool Class::isStruct() const
{ return _key == StructKey; }

bool Class::isUnion() const
{ return _key == UnionKey; }

Class::Key Class::classKey() const
{ return _key; }

void Class::setClassKey(Key key)
{ _key = key; }

void Class::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
624 625 626 627 628 629 630 631
bool Class::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const Class *otherTy = otherType->asClassType())
        return matcher->match(this, otherTy);

    return false;
}

con's avatar
con committed
632
unsigned Class::baseClassCount() const
633
{ return _baseClasses.size(); }
con's avatar
con committed
634 635 636 637 638 639 640 641 642 643 644 645

BaseClass *Class::baseClassAt(unsigned index) const
{ return _baseClasses.at(index); }

void Class::addBaseClass(BaseClass *baseClass)
{ _baseClasses.push_back(baseClass); }

FullySpecifiedType Class::type() const
{ return FullySpecifiedType(const_cast<Class *>(this)); }

bool Class::isEqualTo(const Type *other) const
{
646
    const Class *o = other->asClassType();
con's avatar
con committed
647 648
    if (! o)
        return false;
649 650
    const Name *l = unqualifiedName();
    const Name *r = o->unqualifiedName();
con's avatar
con committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
    if (l == r || (l && l->isEqualTo(r)))
        return true;
    else
        return false;
}

void Class::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < _baseClasses.size(); ++i) {
            visitSymbol(_baseClasses.at(i), visitor);
        }
        for (unsigned i = 0; i < memberCount(); ++i) {
            visitSymbol(memberAt(i), visitor);
        }
    }
}

669 670 671

QtPropertyDeclaration::QtPropertyDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
    : Symbol(translationUnit, sourceLocation, name)
672
    , _flags(NoFlags)
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
{ }

QtPropertyDeclaration::~QtPropertyDeclaration()
{ }

void QtPropertyDeclaration::setType(const FullySpecifiedType &type)
{ _type = type; }

void QtPropertyDeclaration::setFlags(int flags)
{ _flags = flags; }

int QtPropertyDeclaration::flags() const
{ return _flags; }

FullySpecifiedType QtPropertyDeclaration::type() const
{ return _type; }

void QtPropertyDeclaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }


694 695 696 697 698 699 700 701 702 703 704 705 706 707
QtEnum::QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
    : Symbol(translationUnit, sourceLocation, name)
{ }

QtEnum::~QtEnum()
{ }

FullySpecifiedType QtEnum::type() const
{ return FullySpecifiedType(); }

void QtEnum::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }


Roberto Raggi's avatar
Roberto Raggi committed
708
ObjCBaseClass::ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
709 710 711 712 713 714 715 716 717 718 719 720
    : Symbol(translationUnit, sourceLocation, name)
{ }

ObjCBaseClass::~ObjCBaseClass()
{ }

FullySpecifiedType ObjCBaseClass::type() const
{ return FullySpecifiedType(); }

void ObjCBaseClass::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
721
ObjCBaseProtocol::ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
722 723 724 725 726 727 728 729 730 731 732 733
    : Symbol(translationUnit, sourceLocation, name)
{ }

ObjCBaseProtocol::~ObjCBaseProtocol()
{ }

FullySpecifiedType ObjCBaseProtocol::type() const
{ return FullySpecifiedType(); }

void ObjCBaseProtocol::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
734
ObjCClass::ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name):
735 736 737 738
    Scope(translationUnit, sourceLocation, name),
    _categoryName(0),
    _baseClass(0),
    _isInterface(false)
739 740 741 742 743 744
{
}

ObjCClass::~ObjCClass()
{}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
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
bool ObjCClass::isInterface() const
{ return _isInterface; }

void ObjCClass::setInterface(bool isInterface)
{ _isInterface = isInterface; }

bool ObjCClass::isCategory() const
{ return _categoryName != 0; }

const Name *ObjCClass::categoryName() const
{ return _categoryName; }

void ObjCClass::setCategoryName(const Name *categoryName)
{ _categoryName = categoryName; }

ObjCBaseClass *ObjCClass::baseClass() const
{ return _baseClass; }

void ObjCClass::setBaseClass(ObjCBaseClass *baseClass)
{ _baseClass = baseClass; }

unsigned ObjCClass::protocolCount() const
{ return _protocols.size(); }

ObjCBaseProtocol *ObjCClass::protocolAt(unsigned index) const
{ return _protocols.at(index); }

void ObjCClass::addProtocol(ObjCBaseProtocol *protocol)
{ _protocols.push_back(protocol); }

775 776 777 778 779 780 781 782 783
FullySpecifiedType ObjCClass::type() const
{ return FullySpecifiedType(const_cast<ObjCClass *>(this)); }

bool ObjCClass::isEqualTo(const Type *other) const
{
    const ObjCClass *o = other->asObjCClassType();
    if (!o)
        return false;

784 785
    const Name *l = unqualifiedName();
    const Name *r = o->unqualifiedName();
786 787 788 789 790 791 792 793 794
    if (l == r || (l && l->isEqualTo(r)))
        return true;
    else
        return false;
}

void ObjCClass::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
795 796 797
        if (_baseClass)
            visitSymbol(_baseClass, visitor);

798 799
        for (unsigned i = 0; i < _protocols.size(); ++i)
            visitSymbol(_protocols.at(i), visitor);
800 801 802

        for (unsigned i = 0; i < memberCount(); ++i)
            visitSymbol(memberAt(i), visitor);
803 804 805 806 807 808
    }
}

void ObjCClass::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
809 810 811 812 813 814 815 816
bool ObjCClass::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const ObjCClass *otherTy = otherType->asObjCClassType())
        return matcher->match(this, otherTy);

    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
817
ObjCProtocol::ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name):
Roberto Raggi's avatar
Roberto Raggi committed
818
        Scope(translationUnit, sourceLocation, name)
819 820 821 822 823 824
{
}

ObjCProtocol::~ObjCProtocol()
{}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
825 826 827 828 829 830 831 832 833
unsigned ObjCProtocol::protocolCount() const
{ return _protocols.size(); }

ObjCBaseProtocol *ObjCProtocol::protocolAt(unsigned index) const
{ return _protocols.at(index); }

void ObjCProtocol::addProtocol(ObjCBaseProtocol *protocol)
{ _protocols.push_back(protocol); }

834 835 836 837 838 839 840 841 842
FullySpecifiedType ObjCProtocol::type() const
{ return FullySpecifiedType(const_cast<ObjCProtocol *>(this)); }

bool ObjCProtocol::isEqualTo(const Type *other) const
{
    const ObjCProtocol *o = other->asObjCProtocolType();
    if (!o)
        return false;

843 844
    const Name *l = unqualifiedName();
    const Name *r = o->unqualifiedName();
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
    if (l == r || (l && l->isEqualTo(r)))
        return true;
    else
        return false;
}

void ObjCProtocol::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < _protocols.size(); ++i)
            visitSymbol(_protocols.at(i), visitor);
    }
}

void ObjCProtocol::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
862 863 864 865 866 867 868 869
bool ObjCProtocol::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const ObjCProtocol *otherTy = otherType->asObjCProtocolType())
        return matcher->match(this, otherTy);

    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
870 871
ObjCForwardClassDeclaration::ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation,
                                                         const Name *name):
872 873 874 875 876 877 878 879
        Symbol(translationUnit, sourceLocation, name)
{
}

ObjCForwardClassDeclaration::~ObjCForwardClassDeclaration()
{}

FullySpecifiedType ObjCForwardClassDeclaration::type() const
Erik Verbruggen's avatar
Erik Verbruggen committed
880
{ return FullySpecifiedType(); }
881

882 883 884 885 886 887 888 889 890 891 892 893 894 895
bool ObjCForwardClassDeclaration::isEqualTo(const Type *other) const
{
    if (const ObjCForwardClassDeclaration *otherFwdClass = other->asObjCForwardClassDeclarationType()) {
        if (name() == otherFwdClass->name())
            return true;
        else if (name() && otherFwdClass->name())
            return name()->isEqualTo(otherFwdClass->name());
        else
            return false;
    }

    return false;
}

896 897 898
void ObjCForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

899 900 901
void ObjCForwardClassDeclaration::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
902 903 904 905 906 907 908 909
bool ObjCForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const ObjCForwardClassDeclaration *otherTy = otherType->asObjCForwardClassDeclarationType())
        return matcher->match(this, otherTy);

    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
910 911
ObjCForwardProtocolDeclaration::ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation,
                                                               const Name *name):
912 913 914 915 916 917 918 919
        Symbol(translationUnit, sourceLocation, name)
{
}

ObjCForwardProtocolDeclaration::~ObjCForwardProtocolDeclaration()
{}

FullySpecifiedType ObjCForwardProtocolDeclaration::type() const
Erik Verbruggen's avatar
Erik Verbruggen committed
920
{ return FullySpecifiedType(); }
921

922 923 924 925 926 927 928 929 930 931 932 933 934 935
bool ObjCForwardProtocolDeclaration::isEqualTo(const Type *other) const
{
    if (const ObjCForwardProtocolDeclaration *otherFwdProtocol = other->asObjCForwardProtocolDeclarationType()) {
        if (name() == otherFwdProtocol->name())
            return true;
        else if (name() && otherFwdProtocol->name())
            return name()->isEqualTo(otherFwdProtocol->name());
        else
            return false;
    }

    return false;
}

936 937 938
void ObjCForwardProtocolDeclaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }

939 940 941
void ObjCForwardProtocolDeclaration::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
942 943 944 945 946 947 948 949
bool ObjCForwardProtocolDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const ObjCForwardProtocolDeclaration *otherTy = otherType->asObjCForwardProtocolDeclarationType())
        return matcher->match(this, otherTy);

    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
950
ObjCMethod::ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
Roberto Raggi's avatar
Roberto Raggi committed
951
    : Scope(translationUnit, sourceLocation, name),
952
     _flags(0)
Roberto Raggi's avatar
Roberto Raggi committed
953
{ }
954 955

ObjCMethod::~ObjCMethod()
Roberto Raggi's avatar
Roberto Raggi committed
956
{ }
957 958 959 960 961 962 963

bool ObjCMethod::isEqualTo(const Type *other) const
{
    const ObjCMethod *o = other->asObjCMethodType();
    if (! o)
        return false;

964 965
    const Name *l = unqualifiedName();
    const Name *r = o->unqualifiedName();
966
    if (l == r || (l && l->isEqualTo(r))) {
Roberto Raggi's avatar
Roberto Raggi committed
967
        if (argumentCount() != o->argumentCount())
968 969 970
            return false;
        else if (! _returnType.isEqualTo(o->_returnType))
            return false;
Roberto Raggi's avatar
Roberto Raggi committed
971 972 973
        for (unsigned i = 0; i < argumentCount(); ++i) {
            Symbol *l = argumentAt(i);
            Symbol *r = o->argumentAt(i);
974 975 976 977 978 979 980 981 982 983 984
            if (! l->type().isEqualTo(r->type()))
                return false;
        }
        return true;
    }
    return false;
}

void ObjCMethod::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }

Roberto Raggi's avatar
Roberto Raggi committed
985 986 987 988 989 990 991 992
bool ObjCMethod::matchType0(const Type *otherType, TypeMatcher *matcher) const
{
    if (const ObjCMethod *otherTy = otherType->asObjCMethodType())
        return matcher->match(this, otherTy);

    return false;
}

993 994 995 996 997 998
FullySpecifiedType ObjCMethod::type() const
{ return FullySpecifiedType(const_cast<ObjCMethod *>(this)); }

FullySpecifiedType ObjCMethod::returnType() const
{ return _returnType; }

999
void ObjCMethod::setReturnType(const FullySpecifiedType &returnType)
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
{ _returnType = returnType; }

bool ObjCMethod::hasReturnType() const
{
    const FullySpecifiedType ty = returnType();
    return ty.isValid() || ty.isSigned() || ty.isUnsigned();
}

unsigned ObjCMethod::argumentCount() const
{
1010 1011 1012 1013
    const unsigned c = memberCount();
    if (c > 0 && memberAt(c - 1)->isBlock())
        return c - 1;
    return c;
1014 1015 1016
}

Symbol *ObjCMethod::argumentAt(unsigned index) const
Roberto Raggi's avatar
Roberto Raggi committed
1017 1018 1019
{
    return memberAt(index);
}
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041

bool ObjCMethod::hasArguments() const
{
    return ! (argumentCount() == 0 ||
              (argumentCount() == 1 && argumentAt(0)->type()->isVoidType()));
}

bool ObjCMethod::isVariadic() const
{ return f._isVariadic; }

void ObjCMethod::setVariadic(bool isVariadic)
{ f._isVariadic = isVariadic; }

void ObjCMethod::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
        for (unsigned i = 0; i < memberCount(); ++i) {
            visitSymbol(memberAt(i), visitor);
        }
    }
}

1042 1043
ObjCPropertyDeclaration::ObjCPropertyDeclaration(TranslationUnit *translationUnit,
                                                 unsigned sourceLocation,
Roberto Raggi's avatar
Roberto Raggi committed
1044
                                                 const Name *name):
1045 1046
    Symbol(translationUnit, sourceLocation, name),
    _getterName(0),
1047 1048
    _setterName(0),
    _propertyAttributes(None)
1049 1050 1051 1052 1053
{}

ObjCPropertyDeclaration::~ObjCPropertyDeclaration()
{}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
bool ObjCPropertyDeclaration::hasAttribute(int attribute) const
{ return _propertyAttributes & attribute; }

void ObjCPropertyDeclaration::setAttributes(int attributes)
{ _propertyAttributes = attributes; }

bool ObjCPropertyDeclaration::hasGetter() const
{ return hasAttribute(Getter); }

bool ObjCPropertyDeclaration::hasSetter() const
{ return hasAttribute(Setter); }

const Name *ObjCPropertyDeclaration::getterName() const
{ return _getterName; }

void ObjCPropertyDeclaration::setGetterName(const Name *getterName)
{ _getterName = getterName; }

const Name *ObjCPropertyDeclaration::setterName() const
{ return _setterName; }

void ObjCPropertyDeclaration::setSetterName(const Name *setterName)
{ _setterName = setterName; }

void ObjCPropertyDeclaration::setType(const FullySpecifiedType &type)
{ _type = type; }

1081 1082
FullySpecifiedType ObjCPropertyDeclaration::type() const
{ return _type; }
Roberto Raggi's avatar
Roberto Raggi committed
1083

1084 1085 1086 1087 1088
void ObjCPropertyDeclaration::visitSymbol0(SymbolVisitor *visitor)
{
    if (visitor->visit(this)) {
    }
}