Control.cpp 26.5 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 25 26 27
// 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 "Control.h"
#include "Literals.h"
#include "LiteralTable.h"
#include "TranslationUnit.h"
#include "CoreTypes.h"
#include "Symbols.h"
#include "Names.h"
28
#include "TypeMatcher.h"
Roberto Raggi's avatar
Roberto Raggi committed
29 30
#include <map>
#include <set>
31
#include <algorithm>
con's avatar
con committed
32

Roberto Raggi's avatar
Roberto Raggi committed
33
using namespace CPlusPlus;
con's avatar
con committed
34

Roberto Raggi's avatar
Roberto Raggi committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
namespace {

template <typename _Tp>
struct Compare;

template <> struct Compare<IntegerType>
{
    bool operator()(const IntegerType &ty, const IntegerType &otherTy) const
    { return ty.kind() < otherTy.kind(); }
};

template <> struct Compare<FloatType>
{
    bool operator()(const FloatType &ty, const FloatType &otherTy) const
    { return ty.kind() < otherTy.kind(); }
};

template <> struct Compare<PointerToMemberType>
{
    bool operator()(const PointerToMemberType &ty, const PointerToMemberType &otherTy) const
    {
        if (ty.memberName() < otherTy.memberName())
            return true;

        else if (ty.memberName() == otherTy.memberName())
            return ty.elementType() < otherTy.elementType();

        return false;
    }
};

template <> struct Compare<PointerType>
{
    bool operator()(const PointerType &ty, const PointerType &otherTy) const
    {
        return ty.elementType() < otherTy.elementType();
    }
};

template <> struct Compare<ReferenceType>
{
    bool operator()(const ReferenceType &ty, const ReferenceType &otherTy) const
    {
        return ty.elementType() < otherTy.elementType();
    }
};

template <> struct Compare<NamedType>
{
    bool operator()(const NamedType &ty, const NamedType &otherTy) const
    {
        return ty.name() < otherTy.name();
    }
};

template <> struct Compare<ArrayType>
{
    bool operator()(const ArrayType &ty, const ArrayType &otherTy) const
    {
        if (ty.size() < otherTy.size())
            return true;

        else if (ty.size() == otherTy.size())
            return ty.elementType() < otherTy.elementType();

        return false;
    }
};

104 105 106 107 108 109 110 111
template <> struct Compare<AnonymousNameId>
{
    bool operator()(const AnonymousNameId &name, const AnonymousNameId &otherName) const
    {
        return name.classTokenIndex() < otherName.classTokenIndex();
    }
};

Roberto Raggi's avatar
Roberto Raggi committed
112 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 138 139 140 141
template <> struct Compare<DestructorNameId>
{
    bool operator()(const DestructorNameId &name, const DestructorNameId &otherName) const
    {
        return name.identifier() < otherName.identifier();
    }
};

template <> struct Compare<OperatorNameId>
{
    bool operator()(const OperatorNameId &name, const OperatorNameId &otherName) const
    {
        return name.kind() < otherName.kind();
    }
};

template <> struct Compare<ConversionNameId>
{
    bool operator()(const ConversionNameId &name, const ConversionNameId &otherName) const
    {
        return name.type() < otherName.type();
    }
};
template <> struct Compare<TemplateNameId>
{
    bool operator()(const TemplateNameId &name, const TemplateNameId &otherName) const
    {
        const Identifier *id = name.identifier();
        const Identifier *otherId = otherName.identifier();

142 143 144 145 146 147 148 149 150 151 152 153
        if (id == otherId) {
            // we have to differentiate TemplateNameId with respect to specialization or
            // instantiation
            if (name.isSpecialization() == otherName.isSpecialization()) {
                return std::lexicographical_compare(name.firstTemplateArgument(),
                                                    name.lastTemplateArgument(),
                                                    otherName.firstTemplateArgument(),
                                                    otherName.lastTemplateArgument());
            } else {
                return name.isSpecialization();
            }
        }
Roberto Raggi's avatar
Roberto Raggi committed
154 155 156 157 158 159 160 161

        return id < otherId;
    }
};
template <> struct Compare<QualifiedNameId>
{
    bool operator()(const QualifiedNameId &name, const QualifiedNameId &otherName) const
    {
162 163
        if (name.base() == otherName.base())
            return name.name() < otherName.name();
Roberto Raggi's avatar
Roberto Raggi committed
164

165
        return name.base() < otherName.base();
Roberto Raggi's avatar
Roberto Raggi committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
    }
};

template <> struct Compare<SelectorNameId>
{
    bool operator()(const SelectorNameId &name, const SelectorNameId &otherName) const
    {
        if (name.hasArguments() == otherName.hasArguments())
            return std::lexicographical_compare(name.firstName(), name.lastName(),
                                                otherName.firstName(), otherName.lastName());

        return name.hasArguments() < otherName.hasArguments();
    }
};


Roberto Raggi's avatar
Roberto Raggi committed
182 183 184
template <typename _Tp>
class Table: public std::set<_Tp, Compare<_Tp> >
{
185
    typedef std::set<_Tp, Compare<_Tp> > _Base;
Roberto Raggi's avatar
Roberto Raggi committed
186 187
public:
    _Tp *intern(const _Tp &element)
188
    { return const_cast<_Tp *>(&*_Base::insert(element).first); }
Roberto Raggi's avatar
Roberto Raggi committed
189 190 191 192
};

} // end of anonymous namespace

193 194 195 196 197 198 199
template <typename _Iterator>
static void delete_array_entries(_Iterator first, _Iterator last)
{
    for (; first != last; ++first)
        delete *first;
}

con's avatar
con committed
200 201
template <typename _Array>
static void delete_array_entries(const _Array &a)
202
{ delete_array_entries(a.begin(), a.end()); }
203

con's avatar
con committed
204 205 206 207
class Control::Data
{
public:
    Data(Control *control)
Erik Verbruggen's avatar
Erik Verbruggen committed
208 209 210 211 212 213 214 215 216 217 218 219 220
        : control(control)
        , translationUnit(0)
        , diagnosticClient(0)
        , deprecatedId(0)
        , unavailableId(0)
        , objcGetterId(0)
        , objcSetterId(0)
        , objcReadwriteId(0)
        , objcReadonlyId(0)
        , objcAssignId(0)
        , objcRetainId(0)
        , objcCopyId(0)
        , objcNonatomicId(0)
221
        , processor(0)
222
    {}
con's avatar
con committed
223 224 225 226

    ~Data()
    {
        // symbols
227
        delete_array_entries(symbols);
con's avatar
con committed
228 229
    }

230 231 232 233 234
    const AnonymousNameId *findOrInsertAnonymousNameId(unsigned classTokenIndex)
    {
        return anonymousNameIds.intern(AnonymousNameId(classTokenIndex));
    }

Roberto Raggi's avatar
Roberto Raggi committed
235
    template <typename _Iterator>
236 237
    const TemplateNameId *findOrInsertTemplateNameId(const Identifier *id, bool isSpecialization,
                                                     _Iterator first, _Iterator last)
con's avatar
con committed
238
    {
239
        return templateNameIds.intern(TemplateNameId(id, isSpecialization, first, last));
con's avatar
con committed
240 241
    }

242
    const DestructorNameId *findOrInsertDestructorNameId(const Name *name)
con's avatar
con committed
243
    {
244
        return destructorNameIds.intern(DestructorNameId(name));
con's avatar
con committed
245 246
    }

247
    const OperatorNameId *findOrInsertOperatorNameId(OperatorNameId::Kind kind)
con's avatar
con committed
248
    {
Roberto Raggi's avatar
Roberto Raggi committed
249
        return operatorNameIds.intern(OperatorNameId(kind));
con's avatar
con committed
250 251
    }

Roberto Raggi's avatar
Roberto Raggi committed
252
    const ConversionNameId *findOrInsertConversionNameId(const FullySpecifiedType &type)
con's avatar
con committed
253
    {
Roberto Raggi's avatar
Roberto Raggi committed
254
        return conversionNameIds.intern(ConversionNameId(type));
con's avatar
con committed
255 256
    }

257
    const QualifiedNameId *findOrInsertQualifiedNameId(const Name *base, const Name *name)
con's avatar
con committed
258
    {
259
        return qualifiedNameIds.intern(QualifiedNameId(base, name));
con's avatar
con committed
260 261
    }

Roberto Raggi's avatar
Roberto Raggi committed
262 263
    template <typename _Iterator>
    const SelectorNameId *findOrInsertSelectorNameId(_Iterator first, _Iterator last, bool hasArguments)
264
    {
Roberto Raggi's avatar
Roberto Raggi committed
265
        return selectorNameIds.intern(SelectorNameId(first, last, hasArguments));
266 267
    }

con's avatar
con committed
268 269
    IntegerType *findOrInsertIntegerType(int kind)
    {
Roberto Raggi's avatar
Roberto Raggi committed
270
        return integerTypes.intern(IntegerType(kind));
con's avatar
con committed
271 272 273 274
    }

    FloatType *findOrInsertFloatType(int kind)
    {
Roberto Raggi's avatar
Roberto Raggi committed
275
        return floatTypes.intern(FloatType(kind));
con's avatar
con committed
276 277
    }

Roberto Raggi's avatar
Roberto Raggi committed
278
    PointerToMemberType *findOrInsertPointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
con's avatar
con committed
279
    {
Roberto Raggi's avatar
Roberto Raggi committed
280
        return pointerToMemberTypes.intern(PointerToMemberType(memberName, elementType));
con's avatar
con committed
281 282
    }

283
    PointerType *findOrInsertPointerType(const FullySpecifiedType &elementType)
con's avatar
con committed
284
    {
Roberto Raggi's avatar
Roberto Raggi committed
285
        return pointerTypes.intern(PointerType(elementType));
con's avatar
con committed
286 287
    }

288
    ReferenceType *findOrInsertReferenceType(const FullySpecifiedType &elementType, bool rvalueRef)
con's avatar
con committed
289
    {
290
        return referenceTypes.intern(ReferenceType(elementType, rvalueRef));
con's avatar
con committed
291 292
    }

293
    ArrayType *findOrInsertArrayType(const FullySpecifiedType &elementType, unsigned size)
con's avatar
con committed
294
    {
Roberto Raggi's avatar
Roberto Raggi committed
295
        return arrayTypes.intern(ArrayType(elementType, size));
con's avatar
con committed
296 297
    }

Roberto Raggi's avatar
Roberto Raggi committed
298
    NamedType *findOrInsertNamedType(const Name *name)
con's avatar
con committed
299
    {
Roberto Raggi's avatar
Roberto Raggi committed
300
        return namedTypes.intern(NamedType(name));
con's avatar
con committed
301 302
    }

Roberto Raggi's avatar
Roberto Raggi committed
303
    Declaration *newDeclaration(unsigned sourceLocation, const Name *name)
con's avatar
con committed
304
    {
305
        Declaration *declaration = new Declaration(translationUnit, sourceLocation, name);
306
        symbols.push_back(declaration);
con's avatar
con committed
307 308 309
        return declaration;
    }

310 311 312 313 314 315 316
    EnumeratorDeclaration *newEnumeratorDeclaration(unsigned sourceLocation, const Name *name)
    {
        EnumeratorDeclaration *decl = new EnumeratorDeclaration(translationUnit, sourceLocation, name);
        symbols.push_back(decl);
        return decl;
    }

Roberto Raggi's avatar
Roberto Raggi committed
317
    Argument *newArgument(unsigned sourceLocation, const Name *name)
con's avatar
con committed
318
    {
319
        Argument *argument = new Argument(translationUnit, sourceLocation, name);
320
        symbols.push_back(argument);
con's avatar
con committed
321 322 323
        return argument;
    }

Roberto Raggi's avatar
Roberto Raggi committed
324 325
    TypenameArgument *newTypenameArgument(unsigned sourceLocation, const Name *name)
    {
326
        TypenameArgument *argument = new TypenameArgument(translationUnit, sourceLocation, name);
Roberto Raggi's avatar
Roberto Raggi committed
327 328 329 330
        symbols.push_back(argument);
        return argument;
    }

Roberto Raggi's avatar
Roberto Raggi committed
331
    Function *newFunction(unsigned sourceLocation, const Name *name)
con's avatar
con committed
332
    {
333
        Function *function = new Function(translationUnit, sourceLocation, name);
334
        symbols.push_back(function);
con's avatar
con committed
335 336 337
        return function;
    }

Roberto Raggi's avatar
Roberto Raggi committed
338
    BaseClass *newBaseClass(unsigned sourceLocation, const Name *name)
con's avatar
con committed
339
    {
340
        BaseClass *baseClass = new BaseClass(translationUnit, sourceLocation, name);
341
        symbols.push_back(baseClass);
con's avatar
con committed
342 343 344 345 346 347
        return baseClass;
    }

    Block *newBlock(unsigned sourceLocation)
    {
        Block *block = new Block(translationUnit, sourceLocation);
348
        symbols.push_back(block);
con's avatar
con committed
349 350 351
        return block;
    }

Roberto Raggi's avatar
Roberto Raggi committed
352
    Class *newClass(unsigned sourceLocation, const Name *name)
con's avatar
con committed
353
    {
354
        Class *klass = new Class(translationUnit, sourceLocation, name);
355
        symbols.push_back(klass);
con's avatar
con committed
356 357 358
        return klass;
    }

Roberto Raggi's avatar
Roberto Raggi committed
359
    Namespace *newNamespace(unsigned sourceLocation, const Name *name)
con's avatar
con committed
360
    {
361 362 363 364 365 366 367 368
        Namespace *ns = new Namespace(translationUnit, sourceLocation, name);
        symbols.push_back(ns);
        return ns;
    }

    Template *newTemplate(unsigned sourceLocation, const Name *name)
    {
        Template *ns = new Template(translationUnit, sourceLocation, name);
369
        symbols.push_back(ns);
con's avatar
con committed
370 371 372
        return ns;
    }

373 374
    NamespaceAlias *newNamespaceAlias(unsigned sourceLocation, const Name *name)
    {
375
        NamespaceAlias *ns = new NamespaceAlias(translationUnit, sourceLocation, name);
376 377 378 379
        symbols.push_back(ns);
        return ns;
    }

Roberto Raggi's avatar
Roberto Raggi committed
380
    UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, const Name *name)
con's avatar
con committed
381
    {
382
        UsingNamespaceDirective *u = new UsingNamespaceDirective(translationUnit, sourceLocation, name);
383
        symbols.push_back(u);
con's avatar
con committed
384 385 386
        return u;
    }

Roberto Raggi's avatar
Roberto Raggi committed
387
    ForwardClassDeclaration *newForwardClassDeclaration(unsigned sourceLocation, const Name *name)
388
    {
389
        ForwardClassDeclaration *c = new ForwardClassDeclaration(translationUnit, sourceLocation, name);
390
        symbols.push_back(c);
391 392 393
        return c;
    }

394 395 396 397 398 399 400
    QtPropertyDeclaration *newQtPropertyDeclaration(unsigned sourceLocation, const Name *name)
    {
        QtPropertyDeclaration *d = new QtPropertyDeclaration(translationUnit, sourceLocation, name);
        symbols.push_back(d);
        return d;
    }

401 402 403 404 405 406 407
    QtEnum *newQtEnum(unsigned sourceLocation, const Name *name)
    {
        QtEnum *d = new QtEnum(translationUnit, sourceLocation, name);
        symbols.push_back(d);
        return d;
    }

Roberto Raggi's avatar
Roberto Raggi committed
408
    ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name)
409 410
    {
        ObjCBaseClass *c = new ObjCBaseClass(translationUnit, sourceLocation, name);
411
        symbols.push_back(c);
412 413 414
        return c;
    }

Roberto Raggi's avatar
Roberto Raggi committed
415
    ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, const Name *name)
416 417
    {
        ObjCBaseProtocol *p = new ObjCBaseProtocol(translationUnit, sourceLocation, name);
418
        symbols.push_back(p);
419 420 421
        return p;
    }

Roberto Raggi's avatar
Roberto Raggi committed
422
    ObjCClass *newObjCClass(unsigned sourceLocation, const Name *name)
423 424
    {
        ObjCClass *c = new ObjCClass(translationUnit, sourceLocation, name);
425
        symbols.push_back(c);
426 427 428
        return c;
    }

Roberto Raggi's avatar
Roberto Raggi committed
429
    ObjCForwardClassDeclaration *newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name)
430 431
    {
        ObjCForwardClassDeclaration *fwd = new ObjCForwardClassDeclaration(translationUnit, sourceLocation, name);
432
        symbols.push_back(fwd);
433 434 435
        return fwd;
    }

Roberto Raggi's avatar
Roberto Raggi committed
436
    ObjCProtocol *newObjCProtocol(unsigned sourceLocation, const Name *name)
437 438
    {
        ObjCProtocol *p = new ObjCProtocol(translationUnit, sourceLocation, name);
439
        symbols.push_back(p);
440 441 442
        return p;
    }

Roberto Raggi's avatar
Roberto Raggi committed
443
    ObjCForwardProtocolDeclaration *newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name)
444 445
    {
        ObjCForwardProtocolDeclaration *fwd = new ObjCForwardProtocolDeclaration(translationUnit, sourceLocation, name);
446
        symbols.push_back(fwd);
447 448 449
        return fwd;
    }

Roberto Raggi's avatar
Roberto Raggi committed
450
    ObjCMethod *newObjCMethod(unsigned sourceLocation, const Name *name)
451 452
    {
        ObjCMethod *method = new ObjCMethod(translationUnit, sourceLocation, name);
453
        symbols.push_back(method);
454 455 456
        return method;
    }

Roberto Raggi's avatar
Roberto Raggi committed
457
    ObjCPropertyDeclaration *newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name)
458 459
    {
        ObjCPropertyDeclaration *decl = new ObjCPropertyDeclaration(translationUnit, sourceLocation, name);
460
        symbols.push_back(decl);
461 462 463
        return decl;
    }

Roberto Raggi's avatar
Roberto Raggi committed
464
    Enum *newEnum(unsigned sourceLocation, const Name *name)
con's avatar
con committed
465
    {
466
        Enum *e = new Enum(translationUnit, sourceLocation, name);
467
        symbols.push_back(e);
con's avatar
con committed
468 469 470
        return e;
    }

Roberto Raggi's avatar
Roberto Raggi committed
471
    UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, const Name *name)
con's avatar
con committed
472
    {
473
        UsingDeclaration *u = new UsingDeclaration(translationUnit, sourceLocation, name);
474
        symbols.push_back(u);
con's avatar
con committed
475 476 477 478 479 480
        return u;
    }

    Control *control;
    TranslationUnit *translationUnit;
    DiagnosticClient *diagnosticClient;
481 482 483

    TypeMatcher matcher;

con's avatar
con committed
484 485 486 487 488 489 490
    LiteralTable<Identifier> identifiers;
    LiteralTable<StringLiteral> stringLiterals;
    LiteralTable<NumericLiteral> numericLiterals;

    // ### replace std::map with lookup tables. ASAP!

    // names
491
    Table<AnonymousNameId> anonymousNameIds;
Roberto Raggi's avatar
Roberto Raggi committed
492 493 494 495 496 497
    Table<DestructorNameId> destructorNameIds;
    Table<OperatorNameId> operatorNameIds;
    Table<ConversionNameId> conversionNameIds;
    Table<TemplateNameId> templateNameIds;
    Table<QualifiedNameId> qualifiedNameIds;
    Table<SelectorNameId> selectorNameIds;
con's avatar
con committed
498 499 500

    // types
    VoidType voidType;
Roberto Raggi's avatar
Roberto Raggi committed
501 502 503 504 505 506 507
    Table<IntegerType> integerTypes;
    Table<FloatType> floatTypes;
    Table<PointerToMemberType> pointerToMemberTypes;
    Table<PointerType> pointerTypes;
    Table<ReferenceType> referenceTypes;
    Table<ArrayType> arrayTypes;
    Table<NamedType> namedTypes;
con's avatar
con committed
508 509

    // symbols
510
    std::vector<Symbol *> symbols;
511

Erik Verbruggen's avatar
Erik Verbruggen committed
512
    const Identifier *deprecatedId;
513
    const Identifier *unavailableId;
514
    // ObjC context keywords:
Roberto Raggi's avatar
Roberto Raggi committed
515 516 517 518 519 520 521 522
    const Identifier *objcGetterId;
    const Identifier *objcSetterId;
    const Identifier *objcReadwriteId;
    const Identifier *objcReadonlyId;
    const Identifier *objcAssignId;
    const Identifier *objcRetainId;
    const Identifier *objcCopyId;
    const Identifier *objcNonatomicId;
523 524
    const Identifier *cpp11Override;
    const Identifier *cpp11Final;
525
    TopLevelDeclarationProcessor *processor;
con's avatar
con committed
526 527 528
};

Control::Control()
529 530 531
{
    d = new Data(this);

532 533 534 535 536 537 538 539 540 541 542
    d->deprecatedId = identifier("deprecated");
    d->unavailableId = identifier("unavailable");

    d->objcGetterId = identifier("getter");
    d->objcSetterId = identifier("setter");
    d->objcReadwriteId = identifier("readwrite");
    d->objcReadonlyId = identifier("readonly");
    d->objcAssignId = identifier("assign");
    d->objcRetainId = identifier("retain");
    d->objcCopyId = identifier("copy");
    d->objcNonatomicId = identifier("nonatomic");
543 544 545

    d->cpp11Override = identifier("override");
    d->cpp11Final = identifier("final");
546
}
con's avatar
con committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566

Control::~Control()
{ delete d; }

TranslationUnit *Control::translationUnit() const
{ return d->translationUnit; }

TranslationUnit *Control::switchTranslationUnit(TranslationUnit *unit)
{
    TranslationUnit *previousTranslationUnit = d->translationUnit;
    d->translationUnit = unit;
    return previousTranslationUnit;
}

DiagnosticClient *Control::diagnosticClient() const
{ return d->diagnosticClient; }

void Control::setDiagnosticClient(DiagnosticClient *diagnosticClient)
{ d->diagnosticClient = diagnosticClient; }

567 568 569
const AnonymousNameId *Control::anonymousNameId(unsigned classTokenIndex)
{ return d->findOrInsertAnonymousNameId(classTokenIndex); }

570 571 572 573 574 575 576 577 578
const OperatorNameId *Control::findOperatorNameId(OperatorNameId::Kind operatorId) const
{
    Table<OperatorNameId>::const_iterator i = d->operatorNameIds.find(operatorId);
    if (i == d->operatorNameIds.end())
        return 0;
    else
        return &*i;
}

Roberto Raggi's avatar
Roberto Raggi committed
579
const Identifier *Control::findIdentifier(const char *chars, unsigned size) const
580 581
{ return d->identifiers.findLiteral(chars, size); }

582
const Identifier *Control::identifier(const char *chars, unsigned size)
con's avatar
con committed
583 584
{ return d->identifiers.findOrInsertLiteral(chars, size); }

585
const Identifier *Control::identifier(const char *chars)
con's avatar
con committed
586
{
Roberto Raggi's avatar
Roberto Raggi committed
587
    unsigned length = std::strlen(chars);
588
    return identifier(chars, length);
con's avatar
con committed
589 590
}

591 592 593 594 595 596
Control::IdentifierIterator Control::firstIdentifier() const
{ return d->identifiers.begin(); }

Control::IdentifierIterator Control::lastIdentifier() const
{ return d->identifiers.end(); }

597 598 599 600 601 602 603 604 605 606 607 608
Control::StringLiteralIterator Control::firstStringLiteral() const
{ return d->stringLiterals.begin(); }

Control::StringLiteralIterator Control::lastStringLiteral() const
{ return d->stringLiterals.end(); }

Control::NumericLiteralIterator Control::firstNumericLiteral() const
{ return d->numericLiterals.begin(); }

Control::NumericLiteralIterator Control::lastNumericLiteral() const
{ return d->numericLiterals.end(); }

609
const StringLiteral *Control::stringLiteral(const char *chars, unsigned size)
con's avatar
con committed
610 611
{ return d->stringLiterals.findOrInsertLiteral(chars, size); }

612
const StringLiteral *Control::stringLiteral(const char *chars)
con's avatar
con committed
613
{
Roberto Raggi's avatar
Roberto Raggi committed
614
    unsigned length = std::strlen(chars);
615
    return stringLiteral(chars, length);
con's avatar
con committed
616 617
}

618
const NumericLiteral *Control::numericLiteral(const char *chars, unsigned size)
con's avatar
con committed
619 620
{ return d->numericLiterals.findOrInsertLiteral(chars, size); }

621
const NumericLiteral *Control::numericLiteral(const char *chars)
con's avatar
con committed
622
{
Roberto Raggi's avatar
Roberto Raggi committed
623
    unsigned length = std::strlen(chars);
624
    return numericLiteral(chars, length);
con's avatar
con committed
625 626
}

Roberto Raggi's avatar
Roberto Raggi committed
627
const TemplateNameId *Control::templateNameId(const Identifier *id,
628
                                              bool isSpecialization,
Roberto Raggi's avatar
Roberto Raggi committed
629 630
                                              const FullySpecifiedType *const args,
                                              unsigned argv)
con's avatar
con committed
631
{
632
    return d->findOrInsertTemplateNameId(id, isSpecialization, args, args + argv);
con's avatar
con committed
633 634
}

635 636
const DestructorNameId *Control::destructorNameId(const Name *name)
{ return d->findOrInsertDestructorNameId(name); }
con's avatar
con committed
637

638
const OperatorNameId *Control::operatorNameId(OperatorNameId::Kind kind)
con's avatar
con committed
639 640
{ return d->findOrInsertOperatorNameId(kind); }

Roberto Raggi's avatar
Roberto Raggi committed
641
const ConversionNameId *Control::conversionNameId(const FullySpecifiedType &type)
con's avatar
con committed
642 643
{ return d->findOrInsertConversionNameId(type); }

644
const QualifiedNameId *Control::qualifiedNameId(const Name *base, const Name *name)
con's avatar
con committed
645
{
646
    return d->findOrInsertQualifiedNameId(base, name);
con's avatar
con committed
647 648
}

Roberto Raggi's avatar
Roberto Raggi committed
649 650 651
const SelectorNameId *Control::selectorNameId(const Name *const *names,
                                              unsigned nameCount,
                                              bool hasArguments)
652
{
Roberto Raggi's avatar
Roberto Raggi committed
653
    return d->findOrInsertSelectorNameId(names, names + nameCount, hasArguments);
654 655 656
}


con's avatar
con committed
657 658 659 660 661 662 663 664 665
VoidType *Control::voidType()
{ return &d->voidType; }

IntegerType *Control::integerType(int kind)
{ return d->findOrInsertIntegerType(kind); }

FloatType *Control::floatType(int kind)
{ return d->findOrInsertFloatType(kind); }

Roberto Raggi's avatar
Roberto Raggi committed
666
PointerToMemberType *Control::pointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
con's avatar
con committed
667 668
{ return d->findOrInsertPointerToMemberType(memberName, elementType); }

669
PointerType *Control::pointerType(const FullySpecifiedType &elementType)
con's avatar
con committed
670 671
{ return d->findOrInsertPointerType(elementType); }

672 673
ReferenceType *Control::referenceType(const FullySpecifiedType &elementType, bool rvalueRef)
{ return d->findOrInsertReferenceType(elementType, rvalueRef); }
con's avatar
con committed
674

675
ArrayType *Control::arrayType(const FullySpecifiedType &elementType, unsigned size)
con's avatar
con committed
676 677
{ return d->findOrInsertArrayType(elementType, size); }

Roberto Raggi's avatar
Roberto Raggi committed
678
NamedType *Control::namedType(const Name *name)
con's avatar
con committed
679 680
{ return d->findOrInsertNamedType(name); }

Roberto Raggi's avatar
Roberto Raggi committed
681
Argument *Control::newArgument(unsigned sourceLocation, const Name *name)
con's avatar
con committed
682 683
{ return d->newArgument(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
684 685 686
TypenameArgument *Control::newTypenameArgument(unsigned sourceLocation, const Name *name)
{ return d->newTypenameArgument(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
687
Function *Control::newFunction(unsigned sourceLocation, const Name *name)
con's avatar
con committed
688 689
{ return d->newFunction(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
690
Namespace *Control::newNamespace(unsigned sourceLocation, const Name *name)
con's avatar
con committed
691 692
{ return d->newNamespace(sourceLocation, name); }

693 694 695
Template *Control::newTemplate(unsigned sourceLocation, const Name *name)
{ return d->newTemplate(sourceLocation, name); }

696 697 698
NamespaceAlias *Control::newNamespaceAlias(unsigned sourceLocation, const Name *name)
{ return d->newNamespaceAlias(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
699
BaseClass *Control::newBaseClass(unsigned sourceLocation, const Name *name)
con's avatar
con committed
700 701
{ return d->newBaseClass(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
702
Class *Control::newClass(unsigned sourceLocation, const Name *name)
con's avatar
con committed
703 704
{ return d->newClass(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
705
Enum *Control::newEnum(unsigned sourceLocation, const Name *name)
con's avatar
con committed
706 707 708 709 710
{ return d->newEnum(sourceLocation, name); }

Block *Control::newBlock(unsigned sourceLocation)
{ return d->newBlock(sourceLocation); }

Roberto Raggi's avatar
Roberto Raggi committed
711
Declaration *Control::newDeclaration(unsigned sourceLocation, const Name *name)
con's avatar
con committed
712 713
{ return d->newDeclaration(sourceLocation, name); }

714 715 716
EnumeratorDeclaration *Control::newEnumeratorDeclaration(unsigned sourceLocation, const Name *name)
{ return d->newEnumeratorDeclaration(sourceLocation, name); }

con's avatar
con committed
717
UsingNamespaceDirective *Control::newUsingNamespaceDirective(unsigned sourceLocation,
Roberto Raggi's avatar
Roberto Raggi committed
718
                                                                const Name *name)
con's avatar
con committed
719 720
{ return d->newUsingNamespaceDirective(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
721
UsingDeclaration *Control::newUsingDeclaration(unsigned sourceLocation, const Name *name)
con's avatar
con committed
722 723
{ return d->newUsingDeclaration(sourceLocation, name); }

724
ForwardClassDeclaration *Control::newForwardClassDeclaration(unsigned sourceLocation,
Roberto Raggi's avatar
Roberto Raggi committed
725
                                                             const Name *name)
726 727
{ return d->newForwardClassDeclaration(sourceLocation, name); }

728 729 730 731
QtPropertyDeclaration *Control::newQtPropertyDeclaration(unsigned sourceLocation,
                                                         const Name *name)
{ return d->newQtPropertyDeclaration(sourceLocation, name); }

732 733 734
QtEnum *Control::newQtEnum(unsigned sourceLocation, const Name *name)
{ return d->newQtEnum(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
735
ObjCBaseClass *Control::newObjCBaseClass(unsigned sourceLocation, const Name *name)
736 737
{ return d->newObjCBaseClass(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
738
ObjCBaseProtocol *Control::newObjCBaseProtocol(unsigned sourceLocation, const Name *name)
739 740
{ return d->newObjCBaseProtocol(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
741
ObjCClass *Control::newObjCClass(unsigned sourceLocation, const Name *name)
742 743
{ return d->newObjCClass(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
744
ObjCForwardClassDeclaration *Control::newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name)
745 746
{ return d->newObjCForwardClassDeclaration(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
747
ObjCProtocol *Control::newObjCProtocol(unsigned sourceLocation, const Name *name)
748 749
{ return d->newObjCProtocol(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
750
ObjCForwardProtocolDeclaration *Control::newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name)
751
{ return d->newObjCForwardProtocolDeclaration(sourceLocation, name); }
752

Roberto Raggi's avatar
Roberto Raggi committed
753
ObjCMethod *Control::newObjCMethod(unsigned sourceLocation, const Name *name)
754 755
{ return d->newObjCMethod(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
756
ObjCPropertyDeclaration *Control::newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name)
757 758
{ return d->newObjCPropertyDeclaration(sourceLocation, name); }

Erik Verbruggen's avatar
Erik Verbruggen committed
759 760 761
const Identifier *Control::deprecatedId() const
{ return d->deprecatedId; }

762 763 764
const Identifier *Control::unavailableId() const
{ return d->unavailableId; }

Roberto Raggi's avatar
Roberto Raggi committed
765
const Identifier *Control::objcGetterId() const
766 767
{ return d->objcGetterId; }

Roberto Raggi's avatar
Roberto Raggi committed
768
const Identifier *Control::objcSetterId() const
769 770
{ return d->objcSetterId; }

Roberto Raggi's avatar
Roberto Raggi committed
771
const Identifier *Control::objcReadwriteId() const
772 773
{ return d->objcReadwriteId; }

Roberto Raggi's avatar
Roberto Raggi committed
774
const Identifier *Control::objcReadonlyId() const
775 776
{ return d->objcReadonlyId; }

Roberto Raggi's avatar
Roberto Raggi committed
777
const Identifier *Control::objcAssignId() const
778 779
{ return d->objcAssignId; }

Roberto Raggi's avatar
Roberto Raggi committed
780
const Identifier *Control::objcRetainId() const
781 782
{ return d->objcRetainId; }

Roberto Raggi's avatar
Roberto Raggi committed
783
const Identifier *Control::objcCopyId() const
784
{ return d->objcCopyId; }
Roberto Raggi's avatar
Roberto Raggi committed
785

Roberto Raggi's avatar
Roberto Raggi committed
786
const Identifier *Control::objcNonatomicId() const
787
{ return d->objcNonatomicId; }
788

789 790 791 792 793 794
const Identifier *Control::cpp11Override() const
{ return d->cpp11Override; }

const Identifier *Control::cpp11Final() const
{ return d->cpp11Final; }

795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
Symbol **Control::firstSymbol() const
{
    if (d->symbols.empty())
        return 0;

    return &*d->symbols.begin();
}

Symbol **Control::lastSymbol() const
{
    if (d->symbols.empty())
        return 0;

    return &*d->symbols.begin() + d->symbols.size();
}

811 812 813 814
bool Control::hasSymbol(Symbol *symbol) const
{
    return std::find(d->symbols.begin(), d->symbols.end(), symbol) != d->symbols.end();
}
815 816 817 818 819

void Control::squeeze()
{
    d->numericLiterals.reset();
}
820 821 822 823 824 825 826 827 828 829

TopLevelDeclarationProcessor *Control::topLevelDeclarationProcessor() const
{
    return d->processor;
}

void Control::setTopLevelDeclarationProcessor(CPlusPlus::TopLevelDeclarationProcessor *processor)
{
    d->processor = processor;
}
830 831 832 833 834

void Control::addSymbol(Symbol *symbol)
{
    d->symbols.push_back(symbol);
}