Control.cpp 24.1 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
con's avatar
con committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// 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"
#include "Array.h"
57
#include "TypeMatcher.h"
Roberto Raggi's avatar
Roberto Raggi committed
58 59
#include <map>
#include <set>
con's avatar
con committed
60

Roberto Raggi's avatar
Roberto Raggi committed
61
using namespace CPlusPlus;
con's avatar
con committed
62

Roberto Raggi's avatar
Roberto Raggi committed
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
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;
    }
};

Roberto Raggi's avatar
Roberto Raggi committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
template <> struct Compare<NameId>
{
    bool operator()(const NameId &name, const NameId &otherName) const
    {
        return name.identifier() < otherName.identifier();
    }
};

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();

        if (id == otherId)
            return std::lexicographical_compare(name.firstTemplateArgument(), name.lastTemplateArgument(),
                                                otherName.firstTemplateArgument(), otherName.lastTemplateArgument());

        return id < otherId;
    }
};
template <> struct Compare<QualifiedNameId>
{
    bool operator()(const QualifiedNameId &name, const QualifiedNameId &otherName) const
    {
        if (name.isGlobal() == otherName.isGlobal())
            return std::lexicographical_compare(name.firstName(), name.lastName(),
                                                otherName.firstName(), otherName.lastName());

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

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
202 203 204 205 206 207 208 209 210 211
template <typename _Tp>
class Table: public std::set<_Tp, Compare<_Tp> >
{
public:
    _Tp *intern(const _Tp &element)
    { return const_cast<_Tp *>(&*insert(element).first); }
};

} // end of anonymous namespace

212 213 214 215 216 217 218
template <typename _Iterator>
static void delete_array_entries(_Iterator first, _Iterator last)
{
    for (; first != last; ++first)
        delete *first;
}

con's avatar
con committed
219 220
template <typename _Array>
static void delete_array_entries(const _Array &a)
221
{ delete_array_entries(a.begin(), a.end()); }
222

con's avatar
con committed
223 224 225 226 227 228
class Control::Data
{
public:
    Data(Control *control)
        : control(control),
          translationUnit(0),
Roberto Raggi's avatar
Roberto Raggi committed
229
          diagnosticClient(0)
230
    {}
con's avatar
con committed
231 232 233 234

    ~Data()
    {
        // symbols
235
        delete_array_entries(symbols);
con's avatar
con committed
236 237
    }

Roberto Raggi's avatar
Roberto Raggi committed
238
    const NameId *findOrInsertNameId(const Identifier *id)
con's avatar
con committed
239 240 241
    {
        if (! id)
            return 0;
Roberto Raggi's avatar
Roberto Raggi committed
242 243

        return nameIds.intern(NameId(id));
con's avatar
con committed
244 245
    }

Roberto Raggi's avatar
Roberto Raggi committed
246 247
    template <typename _Iterator>
    const TemplateNameId *findOrInsertTemplateNameId(const Identifier *id, _Iterator first, _Iterator last)
con's avatar
con committed
248
    {
Roberto Raggi's avatar
Roberto Raggi committed
249
        return templateNameIds.intern(TemplateNameId(id, first, last));
con's avatar
con committed
250 251
    }

Roberto Raggi's avatar
Roberto Raggi committed
252
    const DestructorNameId *findOrInsertDestructorNameId(const Identifier *id)
con's avatar
con committed
253
    {
Roberto Raggi's avatar
Roberto Raggi committed
254
        return destructorNameIds.intern(DestructorNameId(id));
con's avatar
con committed
255 256
    }

Roberto Raggi's avatar
Roberto Raggi committed
257
    const OperatorNameId *findOrInsertOperatorNameId(int kind)
con's avatar
con committed
258
    {
Roberto Raggi's avatar
Roberto Raggi committed
259
        return operatorNameIds.intern(OperatorNameId(kind));
con's avatar
con committed
260 261
    }

Roberto Raggi's avatar
Roberto Raggi committed
262
    const ConversionNameId *findOrInsertConversionNameId(const FullySpecifiedType &type)
con's avatar
con committed
263
    {
Roberto Raggi's avatar
Roberto Raggi committed
264
        return conversionNameIds.intern(ConversionNameId(type));
con's avatar
con committed
265 266
    }

Roberto Raggi's avatar
Roberto Raggi committed
267 268
    template <typename _Iterator>
    const QualifiedNameId *findOrInsertQualifiedNameId(_Iterator first, _Iterator last, bool isGlobal)
con's avatar
con committed
269
    {
Roberto Raggi's avatar
Roberto Raggi committed
270
        return qualifiedNameIds.intern(QualifiedNameId(first, last, isGlobal));
con's avatar
con committed
271 272
    }

Roberto Raggi's avatar
Roberto Raggi committed
273 274
    template <typename _Iterator>
    const SelectorNameId *findOrInsertSelectorNameId(_Iterator first, _Iterator last, bool hasArguments)
275
    {
Roberto Raggi's avatar
Roberto Raggi committed
276
        return selectorNameIds.intern(SelectorNameId(first, last, hasArguments));
277 278
    }

con's avatar
con committed
279 280
    IntegerType *findOrInsertIntegerType(int kind)
    {
Roberto Raggi's avatar
Roberto Raggi committed
281
        return integerTypes.intern(IntegerType(kind));
con's avatar
con committed
282 283 284 285
    }

    FloatType *findOrInsertFloatType(int kind)
    {
Roberto Raggi's avatar
Roberto Raggi committed
286
        return floatTypes.intern(FloatType(kind));
con's avatar
con committed
287 288
    }

Roberto Raggi's avatar
Roberto Raggi committed
289
    PointerToMemberType *findOrInsertPointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
con's avatar
con committed
290
    {
Roberto Raggi's avatar
Roberto Raggi committed
291
        return pointerToMemberTypes.intern(PointerToMemberType(memberName, elementType));
con's avatar
con committed
292 293
    }

294
    PointerType *findOrInsertPointerType(const FullySpecifiedType &elementType)
con's avatar
con committed
295
    {
Roberto Raggi's avatar
Roberto Raggi committed
296
        return pointerTypes.intern(PointerType(elementType));
con's avatar
con committed
297 298
    }

299
    ReferenceType *findOrInsertReferenceType(const FullySpecifiedType &elementType)
con's avatar
con committed
300
    {
Roberto Raggi's avatar
Roberto Raggi committed
301
        return referenceTypes.intern(ReferenceType(elementType));
con's avatar
con committed
302 303
    }

304
    ArrayType *findOrInsertArrayType(const FullySpecifiedType &elementType, unsigned size)
con's avatar
con committed
305
    {
Roberto Raggi's avatar
Roberto Raggi committed
306
        return arrayTypes.intern(ArrayType(elementType, size));
con's avatar
con committed
307 308
    }

Roberto Raggi's avatar
Roberto Raggi committed
309
    NamedType *findOrInsertNamedType(const Name *name)
con's avatar
con committed
310
    {
Roberto Raggi's avatar
Roberto Raggi committed
311
        return namedTypes.intern(NamedType(name));
con's avatar
con committed
312 313
    }

Roberto Raggi's avatar
Roberto Raggi committed
314
    Declaration *newDeclaration(unsigned sourceLocation, const Name *name)
con's avatar
con committed
315 316 317
    {
        Declaration *declaration = new Declaration(translationUnit,
                                                   sourceLocation, name);
318
        symbols.push_back(declaration);
con's avatar
con committed
319 320 321
        return declaration;
    }

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

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

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

Roberto Raggi's avatar
Roberto Raggi committed
346
    BaseClass *newBaseClass(unsigned sourceLocation, const Name *name)
con's avatar
con committed
347 348 349
    {
        BaseClass *baseClass = new BaseClass(translationUnit,
                                             sourceLocation, name);
350
        symbols.push_back(baseClass);
con's avatar
con committed
351 352 353 354 355 356
        return baseClass;
    }

    Block *newBlock(unsigned sourceLocation)
    {
        Block *block = new Block(translationUnit, sourceLocation);
357
        symbols.push_back(block);
con's avatar
con committed
358 359 360
        return block;
    }

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

Roberto Raggi's avatar
Roberto Raggi committed
369
    Namespace *newNamespace(unsigned sourceLocation, const Name *name)
con's avatar
con committed
370 371 372
    {
        Namespace *ns = new Namespace(translationUnit,
                                      sourceLocation, name);
373
        symbols.push_back(ns);
con's avatar
con committed
374 375 376
        return ns;
    }

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

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

Roberto Raggi's avatar
Roberto Raggi committed
393
    ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name)
394 395
    {
        ObjCBaseClass *c = new ObjCBaseClass(translationUnit, sourceLocation, name);
396
        symbols.push_back(c);
397 398 399
        return c;
    }

Roberto Raggi's avatar
Roberto Raggi committed
400
    ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, const Name *name)
401 402
    {
        ObjCBaseProtocol *p = new ObjCBaseProtocol(translationUnit, sourceLocation, name);
403
        symbols.push_back(p);
404 405 406
        return p;
    }

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

Roberto Raggi's avatar
Roberto Raggi committed
414
    ObjCForwardClassDeclaration *newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name)
415 416
    {
        ObjCForwardClassDeclaration *fwd = new ObjCForwardClassDeclaration(translationUnit, sourceLocation, name);
417
        symbols.push_back(fwd);
418 419 420
        return fwd;
    }

Roberto Raggi's avatar
Roberto Raggi committed
421
    ObjCProtocol *newObjCProtocol(unsigned sourceLocation, const Name *name)
422 423
    {
        ObjCProtocol *p = new ObjCProtocol(translationUnit, sourceLocation, name);
424
        symbols.push_back(p);
425 426 427
        return p;
    }

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

Roberto Raggi's avatar
Roberto Raggi committed
435
    ObjCMethod *newObjCMethod(unsigned sourceLocation, const Name *name)
436 437
    {
        ObjCMethod *method = new ObjCMethod(translationUnit, sourceLocation, name);
438
        symbols.push_back(method);
439 440 441
        return method;
    }

Roberto Raggi's avatar
Roberto Raggi committed
442
    ObjCPropertyDeclaration *newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name)
443 444
    {
        ObjCPropertyDeclaration *decl = new ObjCPropertyDeclaration(translationUnit, sourceLocation, name);
445
        symbols.push_back(decl);
446 447 448
        return decl;
    }

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

Roberto Raggi's avatar
Roberto Raggi committed
457
    UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, const Name *name)
con's avatar
con committed
458 459 460
    {
        UsingDeclaration *u = new UsingDeclaration(translationUnit,
                                                   sourceLocation, name);
461
        symbols.push_back(u);
con's avatar
con committed
462 463 464 465 466 467
        return u;
    }

    Control *control;
    TranslationUnit *translationUnit;
    DiagnosticClient *diagnosticClient;
468 469 470

    TypeMatcher matcher;

con's avatar
con committed
471 472 473 474 475 476 477
    LiteralTable<Identifier> identifiers;
    LiteralTable<StringLiteral> stringLiterals;
    LiteralTable<NumericLiteral> numericLiterals;

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

    // names
Roberto Raggi's avatar
Roberto Raggi committed
478 479 480 481 482 483 484
    Table<NameId> nameIds;
    Table<DestructorNameId> destructorNameIds;
    Table<OperatorNameId> operatorNameIds;
    Table<ConversionNameId> conversionNameIds;
    Table<TemplateNameId> templateNameIds;
    Table<QualifiedNameId> qualifiedNameIds;
    Table<SelectorNameId> selectorNameIds;
con's avatar
con committed
485 486 487

    // types
    VoidType voidType;
Roberto Raggi's avatar
Roberto Raggi committed
488 489 490 491 492 493 494
    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
495 496

    // symbols
497
    std::vector<Symbol *> symbols;
498 499

    // ObjC context keywords:
Roberto Raggi's avatar
Roberto Raggi committed
500 501 502 503 504 505 506 507
    const Identifier *objcGetterId;
    const Identifier *objcSetterId;
    const Identifier *objcReadwriteId;
    const Identifier *objcReadonlyId;
    const Identifier *objcAssignId;
    const Identifier *objcRetainId;
    const Identifier *objcCopyId;
    const Identifier *objcNonatomicId;
con's avatar
con committed
508 509 510
};

Control::Control()
511 512 513 514 515 516 517 518 519 520 521 522
{
    d = new Data(this);

    d->objcGetterId = findOrInsertIdentifier("getter");
    d->objcSetterId = findOrInsertIdentifier("setter");
    d->objcReadwriteId = findOrInsertIdentifier("readwrite");
    d->objcReadonlyId = findOrInsertIdentifier("readonly");
    d->objcAssignId = findOrInsertIdentifier("assign");
    d->objcRetainId = findOrInsertIdentifier("retain");
    d->objcCopyId = findOrInsertIdentifier("copy");
    d->objcNonatomicId = findOrInsertIdentifier("nonatomic");
}
con's avatar
con committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542

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; }

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

Roberto Raggi's avatar
Roberto Raggi committed
546
const Identifier *Control::findOrInsertIdentifier(const char *chars, unsigned size)
con's avatar
con committed
547 548
{ return d->identifiers.findOrInsertLiteral(chars, size); }

Roberto Raggi's avatar
Roberto Raggi committed
549
const Identifier *Control::findOrInsertIdentifier(const char *chars)
con's avatar
con committed
550
{
Roberto Raggi's avatar
Roberto Raggi committed
551
    unsigned length = std::strlen(chars);
con's avatar
con committed
552 553 554
    return findOrInsertIdentifier(chars, length);
}

555 556 557 558 559 560
Control::IdentifierIterator Control::firstIdentifier() const
{ return d->identifiers.begin(); }

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

561 562 563 564 565 566 567 568 569 570 571 572
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(); }

Roberto Raggi's avatar
Roberto Raggi committed
573
const StringLiteral *Control::findOrInsertStringLiteral(const char *chars, unsigned size)
con's avatar
con committed
574 575
{ return d->stringLiterals.findOrInsertLiteral(chars, size); }

Roberto Raggi's avatar
Roberto Raggi committed
576
const StringLiteral *Control::findOrInsertStringLiteral(const char *chars)
con's avatar
con committed
577
{
Roberto Raggi's avatar
Roberto Raggi committed
578
    unsigned length = std::strlen(chars);
con's avatar
con committed
579 580 581
    return findOrInsertStringLiteral(chars, length);
}

Roberto Raggi's avatar
Roberto Raggi committed
582
const NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars, unsigned size)
con's avatar
con committed
583 584
{ return d->numericLiterals.findOrInsertLiteral(chars, size); }

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

Roberto Raggi's avatar
Roberto Raggi committed
591
const NameId *Control::nameId(const Identifier *id)
con's avatar
con committed
592 593
{ return d->findOrInsertNameId(id); }

Roberto Raggi's avatar
Roberto Raggi committed
594 595 596
const TemplateNameId *Control::templateNameId(const Identifier *id,
                                              const FullySpecifiedType *const args,
                                              unsigned argv)
con's avatar
con committed
597
{
Roberto Raggi's avatar
Roberto Raggi committed
598
    return d->findOrInsertTemplateNameId(id, args, args + argv);
con's avatar
con committed
599 600
}

Roberto Raggi's avatar
Roberto Raggi committed
601
const DestructorNameId *Control::destructorNameId(const Identifier *id)
con's avatar
con committed
602 603
{ return d->findOrInsertDestructorNameId(id); }

Roberto Raggi's avatar
Roberto Raggi committed
604
const OperatorNameId *Control::operatorNameId(int kind)
con's avatar
con committed
605 606
{ return d->findOrInsertOperatorNameId(kind); }

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

Roberto Raggi's avatar
Roberto Raggi committed
610 611 612
const QualifiedNameId *Control::qualifiedNameId(const Name *const *names,
                                                unsigned nameCount,
                                                bool isGlobal)
con's avatar
con committed
613
{
Roberto Raggi's avatar
Roberto Raggi committed
614
    return d->findOrInsertQualifiedNameId(names, names + nameCount, isGlobal);
con's avatar
con committed
615 616
}

Roberto Raggi's avatar
Roberto Raggi committed
617 618 619
const SelectorNameId *Control::selectorNameId(const Name *const *names,
                                              unsigned nameCount,
                                              bool hasArguments)
620
{
Roberto Raggi's avatar
Roberto Raggi committed
621
    return d->findOrInsertSelectorNameId(names, names + nameCount, hasArguments);
622 623 624
}


con's avatar
con committed
625 626 627 628 629 630 631 632 633
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
634
PointerToMemberType *Control::pointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
con's avatar
con committed
635 636
{ return d->findOrInsertPointerToMemberType(memberName, elementType); }

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

640
ReferenceType *Control::referenceType(const FullySpecifiedType &elementType)
con's avatar
con committed
641 642
{ return d->findOrInsertReferenceType(elementType); }

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

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

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

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

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

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

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

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

Roberto Raggi's avatar
Roberto Raggi committed
667
Enum *Control::newEnum(unsigned sourceLocation, const Name *name)
con's avatar
con committed
668 669 670 671 672
{ return d->newEnum(sourceLocation, name); }

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

Roberto Raggi's avatar
Roberto Raggi committed
673
Declaration *Control::newDeclaration(unsigned sourceLocation, const Name *name)
con's avatar
con committed
674 675 676
{ return d->newDeclaration(sourceLocation, name); }

UsingNamespaceDirective *Control::newUsingNamespaceDirective(unsigned sourceLocation,
Roberto Raggi's avatar
Roberto Raggi committed
677
                                                                const Name *name)
con's avatar
con committed
678 679
{ return d->newUsingNamespaceDirective(sourceLocation, name); }

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

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

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

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

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

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

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

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

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

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

Roberto Raggi's avatar
Roberto Raggi committed
711
const Identifier *Control::objcGetterId() const
712 713
{ return d->objcGetterId; }

Roberto Raggi's avatar
Roberto Raggi committed
714
const Identifier *Control::objcSetterId() const
715 716
{ return d->objcSetterId; }

Roberto Raggi's avatar
Roberto Raggi committed
717
const Identifier *Control::objcReadwriteId() const
718 719
{ return d->objcReadwriteId; }

Roberto Raggi's avatar
Roberto Raggi committed
720
const Identifier *Control::objcReadonlyId() const
721 722
{ return d->objcReadonlyId; }

Roberto Raggi's avatar
Roberto Raggi committed
723
const Identifier *Control::objcAssignId() const
724 725
{ return d->objcAssignId; }

Roberto Raggi's avatar
Roberto Raggi committed
726
const Identifier *Control::objcRetainId() const
727 728
{ return d->objcRetainId; }

Roberto Raggi's avatar
Roberto Raggi committed
729
const Identifier *Control::objcCopyId() const
730
{ return d->objcCopyId; }
Roberto Raggi's avatar
Roberto Raggi committed
731

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