Control.cpp 26.7 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 132 133 134 135 136 137 138 139 140 141
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;
    }
};

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

con's avatar
con committed
142 143 144 145 146 147 148
template <typename _Iterator>
static void delete_map_entries(_Iterator first, _Iterator last)
{
    for (; first != last; ++first)
        delete first->second;
}

149 150 151 152 153 154 155
template <typename _Iterator>
static void delete_array_entries(_Iterator first, _Iterator last)
{
    for (; first != last; ++first)
        delete *first;
}

con's avatar
con committed
156 157 158 159 160 161
template <typename _Map>
static void delete_map_entries(const _Map &m)
{ delete_map_entries(m.begin(), m.end()); }

template <typename _Array>
static void delete_array_entries(const _Array &a)
162
{ delete_array_entries(a.begin(), a.end()); }
163

con's avatar
con committed
164 165 166 167 168 169
class Control::Data
{
public:
    Data(Control *control)
        : control(control),
          translationUnit(0),
Roberto Raggi's avatar
Roberto Raggi committed
170
          diagnosticClient(0)
171
    {}
con's avatar
con committed
172 173 174 175 176 177 178 179 180 181 182 183

    ~Data()
    {
        // names
        delete_map_entries(nameIds);
        delete_map_entries(destructorNameIds);
        delete_map_entries(operatorNameIds);
        delete_map_entries(conversionNameIds);
        delete_map_entries(qualifiedNameIds);
        delete_map_entries(templateNameIds);

        // symbols
184
        delete_array_entries(symbols);
con's avatar
con committed
185 186
    }

Roberto Raggi's avatar
Roberto Raggi committed
187
    NameId *findOrInsertNameId(const Identifier *id)
con's avatar
con committed
188 189 190
    {
        if (! id)
            return 0;
Roberto Raggi's avatar
Roberto Raggi committed
191
        std::map<const Identifier *, NameId *>::iterator it = nameIds.lower_bound(id);
con's avatar
con committed
192 193 194 195 196
        if (it == nameIds.end() || it->first != id)
            it = nameIds.insert(it, std::make_pair(id, new NameId(id)));
        return it->second;
    }

Roberto Raggi's avatar
Roberto Raggi committed
197
    TemplateNameId *findOrInsertTemplateNameId(const Identifier *id,
con's avatar
con committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        const std::vector<FullySpecifiedType> &templateArguments)
    {
        if (! id)
            return 0;
        const TemplateNameIdKey key(id, templateArguments);
        std::map<TemplateNameIdKey, TemplateNameId *>::iterator it =
                templateNameIds.lower_bound(key);
        if (it == templateNameIds.end() || it->first != key) {
            const FullySpecifiedType *args = 0;
            if (templateArguments.size())
                args = &templateArguments[0];
            TemplateNameId *templ = new TemplateNameId(id, args,
                                                       templateArguments.size());
            it = templateNameIds.insert(it, std::make_pair(key, templ));
        }
        return it->second;
    }

Roberto Raggi's avatar
Roberto Raggi committed
216
    DestructorNameId *findOrInsertDestructorNameId(const Identifier *id)
con's avatar
con committed
217 218 219
    {
        if (! id)
            return 0;
Roberto Raggi's avatar
Roberto Raggi committed
220
        std::map<const Identifier *, DestructorNameId *>::iterator it = destructorNameIds.lower_bound(id);
con's avatar
con committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234
        if (it == destructorNameIds.end() || it->first != id)
            it = destructorNameIds.insert(it, std::make_pair(id, new DestructorNameId(id)));
        return it->second;
    }

    OperatorNameId *findOrInsertOperatorNameId(int kind)
    {
        const int key(kind);
        std::map<int, OperatorNameId *>::iterator it = operatorNameIds.lower_bound(key);
        if (it == operatorNameIds.end() || it->first != key)
            it = operatorNameIds.insert(it, std::make_pair(key, new OperatorNameId(kind)));
        return it->second;
    }

235
    ConversionNameId *findOrInsertConversionNameId(const FullySpecifiedType &type)
con's avatar
con committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    {
        std::map<FullySpecifiedType, ConversionNameId *>::iterator it =
                conversionNameIds.lower_bound(type);
        if (it == conversionNameIds.end() || it->first != type)
            it = conversionNameIds.insert(it, std::make_pair(type, new ConversionNameId(type)));
        return it->second;
    }

    QualifiedNameId *findOrInsertQualifiedNameId(const std::vector<Name *> &names, bool isGlobal)
    {
        const QualifiedNameIdKey key(names, isGlobal);
        std::map<QualifiedNameIdKey, QualifiedNameId *>::iterator it =
                qualifiedNameIds.lower_bound(key);
        if (it == qualifiedNameIds.end() || it->first != key) {
            QualifiedNameId *name = new QualifiedNameId(&names[0], names.size(), isGlobal);
            it = qualifiedNameIds.insert(it, std::make_pair(key, name));
        }
        return it->second;
    }

256 257 258 259 260 261 262 263 264
    SelectorNameId *findOrInsertSelectorNameId(const std::vector<Name *> &names, bool hasArguments)
    {
        const SelectorNameIdKey key(names, hasArguments);
        std::map<SelectorNameIdKey, SelectorNameId *>::iterator it = selectorNameIds.lower_bound(key);
        if (it == selectorNameIds.end() || it->first != key)
            it = selectorNameIds.insert(it, std::make_pair(key, new SelectorNameId(&names[0], names.size(), hasArguments)));
        return it->second;
    }

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

    FloatType *findOrInsertFloatType(int kind)
    {
Roberto Raggi's avatar
Roberto Raggi committed
272
        return floatTypes.intern(FloatType(kind));
con's avatar
con committed
273 274
    }

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

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

285
    ReferenceType *findOrInsertReferenceType(const FullySpecifiedType &elementType)
con's avatar
con committed
286
    {
Roberto Raggi's avatar
Roberto Raggi committed
287
        return referenceTypes.intern(ReferenceType(elementType));
con's avatar
con committed
288 289
    }

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

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

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

    Argument *newArgument(unsigned sourceLocation, Name *name)
    {
        Argument *argument = new Argument(translationUnit,
                                          sourceLocation, name);
312
        symbols.push_back(argument);
con's avatar
con committed
313 314 315 316 317 318 319
        return argument;
    }

    Function *newFunction(unsigned sourceLocation, Name *name)
    {
        Function *function = new Function(translationUnit,
                                          sourceLocation, name);
320
        symbols.push_back(function);
con's avatar
con committed
321 322 323 324 325 326 327
        return function;
    }

    BaseClass *newBaseClass(unsigned sourceLocation, Name *name)
    {
        BaseClass *baseClass = new BaseClass(translationUnit,
                                             sourceLocation, name);
328
        symbols.push_back(baseClass);
con's avatar
con committed
329 330 331 332 333 334
        return baseClass;
    }

    Block *newBlock(unsigned sourceLocation)
    {
        Block *block = new Block(translationUnit, sourceLocation);
335
        symbols.push_back(block);
con's avatar
con committed
336 337 338 339 340 341 342
        return block;
    }

    Class *newClass(unsigned sourceLocation, Name *name)
    {
        Class *klass = new Class(translationUnit,
                                 sourceLocation, name);
343
        symbols.push_back(klass);
con's avatar
con committed
344 345 346 347 348 349 350
        return klass;
    }

    Namespace *newNamespace(unsigned sourceLocation, Name *name)
    {
        Namespace *ns = new Namespace(translationUnit,
                                      sourceLocation, name);
351
        symbols.push_back(ns);
con's avatar
con committed
352 353 354 355 356 357 358
        return ns;
    }

    UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, Name *name)
    {
        UsingNamespaceDirective *u = new UsingNamespaceDirective(translationUnit,
                                                                 sourceLocation, name);
359
        symbols.push_back(u);
con's avatar
con committed
360 361 362
        return u;
    }

363 364 365 366
    ForwardClassDeclaration *newForwardClassDeclaration(unsigned sourceLocation, Name *name)
    {
        ForwardClassDeclaration *c = new ForwardClassDeclaration(translationUnit,
                                                                 sourceLocation, name);
367
        symbols.push_back(c);
368 369 370
        return c;
    }

371 372 373
    ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, Name *name)
    {
        ObjCBaseClass *c = new ObjCBaseClass(translationUnit, sourceLocation, name);
374
        symbols.push_back(c);
375 376 377 378 379 380
        return c;
    }

    ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, Name *name)
    {
        ObjCBaseProtocol *p = new ObjCBaseProtocol(translationUnit, sourceLocation, name);
381
        symbols.push_back(p);
382 383 384
        return p;
    }

385 386 387
    ObjCClass *newObjCClass(unsigned sourceLocation, Name *name)
    {
        ObjCClass *c = new ObjCClass(translationUnit, sourceLocation, name);
388
        symbols.push_back(c);
389 390 391 392 393 394
        return c;
    }

    ObjCForwardClassDeclaration *newObjCForwardClassDeclaration(unsigned sourceLocation, Name *name)
    {
        ObjCForwardClassDeclaration *fwd = new ObjCForwardClassDeclaration(translationUnit, sourceLocation, name);
395
        symbols.push_back(fwd);
396 397 398 399 400 401
        return fwd;
    }

    ObjCProtocol *newObjCProtocol(unsigned sourceLocation, Name *name)
    {
        ObjCProtocol *p = new ObjCProtocol(translationUnit, sourceLocation, name);
402
        symbols.push_back(p);
403 404 405 406 407 408
        return p;
    }

    ObjCForwardProtocolDeclaration *newObjCForwardProtocolDeclaration(unsigned sourceLocation, Name *name)
    {
        ObjCForwardProtocolDeclaration *fwd = new ObjCForwardProtocolDeclaration(translationUnit, sourceLocation, name);
409
        symbols.push_back(fwd);
410 411 412
        return fwd;
    }

413 414 415
    ObjCMethod *newObjCMethod(unsigned sourceLocation, Name *name)
    {
        ObjCMethod *method = new ObjCMethod(translationUnit, sourceLocation, name);
416
        symbols.push_back(method);
417 418 419
        return method;
    }

420 421 422
    ObjCPropertyDeclaration *newObjCPropertyDeclaration(unsigned sourceLocation, Name *name)
    {
        ObjCPropertyDeclaration *decl = new ObjCPropertyDeclaration(translationUnit, sourceLocation, name);
423
        symbols.push_back(decl);
424 425 426
        return decl;
    }

con's avatar
con committed
427 428 429 430
    Enum *newEnum(unsigned sourceLocation, Name *name)
    {
        Enum *e = new Enum(translationUnit,
                           sourceLocation, name);
431
        symbols.push_back(e);
con's avatar
con committed
432 433 434 435 436 437 438
        return e;
    }

    UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, Name *name)
    {
        UsingDeclaration *u = new UsingDeclaration(translationUnit,
                                                   sourceLocation, name);
439
        symbols.push_back(u);
con's avatar
con committed
440 441 442 443
        return u;
    }

    struct TemplateNameIdKey {
Roberto Raggi's avatar
Roberto Raggi committed
444
        const Identifier *id;
con's avatar
con committed
445 446
        std::vector<FullySpecifiedType> templateArguments;

Roberto Raggi's avatar
Roberto Raggi committed
447
        TemplateNameIdKey(const Identifier *id, const std::vector<FullySpecifiedType> &templateArguments)
con's avatar
con committed
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
            : id(id), templateArguments(templateArguments)
        { }

        bool operator == (const TemplateNameIdKey &other) const
        { return id == other.id && templateArguments == other.templateArguments; }

        bool operator != (const TemplateNameIdKey &other) const
        { return ! operator==(other); }

        bool operator < (const TemplateNameIdKey &other) const
        {
            if (id == other.id)
                return std::lexicographical_compare(templateArguments.begin(),
                                                    templateArguments.end(),
                                                    other.templateArguments.begin(),
                                                    other.templateArguments.end());
            return id < other.id;
        }
    };

    struct QualifiedNameIdKey {
        std::vector<Name *> names;
        bool isGlobal;

        QualifiedNameIdKey(const std::vector<Name *> &names, bool isGlobal) :
            names(names), isGlobal(isGlobal)
        { }

        bool operator == (const QualifiedNameIdKey &other) const
        { return isGlobal == other.isGlobal && names == other.names; }

        bool operator != (const QualifiedNameIdKey &other) const
        { return ! operator==(other); }

        bool operator < (const QualifiedNameIdKey &other) const
        {
            if (isGlobal == other.isGlobal)
                return std::lexicographical_compare(names.begin(), names.end(),
                                                    other.names.begin(), other.names.end());
            return isGlobal < other.isGlobal;
        }
    };

491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
    struct SelectorNameIdKey {
        std::vector<Name *> _names;
        bool _hasArguments;

        SelectorNameIdKey(const std::vector<Name *> &names, bool hasArguments): _names(names), _hasArguments(hasArguments) {}

        bool operator==(const SelectorNameIdKey &other) const
        { return _names == other._names && _hasArguments == other._hasArguments; }

        bool operator!=(const SelectorNameIdKey &other) const
        { return !operator==(other); }

        bool operator<(const SelectorNameIdKey &other) const
        {
            if (_hasArguments == other._hasArguments)
                return std::lexicographical_compare(_names.begin(), _names.end(), other._names.begin(), other._names.end());
            else
                return _hasArguments < other._hasArguments;
        }
    };

con's avatar
con committed
512 513 514
    Control *control;
    TranslationUnit *translationUnit;
    DiagnosticClient *diagnosticClient;
515 516 517

    TypeMatcher matcher;

con's avatar
con committed
518 519 520 521 522 523 524
    LiteralTable<Identifier> identifiers;
    LiteralTable<StringLiteral> stringLiterals;
    LiteralTable<NumericLiteral> numericLiterals;

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

    // names
Roberto Raggi's avatar
Roberto Raggi committed
525 526
    std::map<const Identifier *, NameId *> nameIds;
    std::map<const Identifier *, DestructorNameId *> destructorNameIds;
con's avatar
con committed
527 528 529 530
    std::map<int, OperatorNameId *> operatorNameIds;
    std::map<FullySpecifiedType, ConversionNameId *> conversionNameIds;
    std::map<TemplateNameIdKey, TemplateNameId *> templateNameIds;
    std::map<QualifiedNameIdKey, QualifiedNameId *> qualifiedNameIds;
531
    std::map<SelectorNameIdKey, SelectorNameId *> selectorNameIds;
con's avatar
con committed
532 533 534

    // types
    VoidType voidType;
Roberto Raggi's avatar
Roberto Raggi committed
535 536 537 538 539 540 541
    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
542 543

    // symbols
544
    std::vector<Symbol *> symbols;
545 546

    // ObjC context keywords:
Roberto Raggi's avatar
Roberto Raggi committed
547 548 549 550 551 552 553 554
    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
555 556 557
};

Control::Control()
558 559 560 561 562 563 564 565 566 567 568 569
{
    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
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589

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
590
const Identifier *Control::findIdentifier(const char *chars, unsigned size) const
591 592
{ return d->identifiers.findLiteral(chars, size); }

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

Roberto Raggi's avatar
Roberto Raggi committed
596
const Identifier *Control::findOrInsertIdentifier(const char *chars)
con's avatar
con committed
597
{
Roberto Raggi's avatar
Roberto Raggi committed
598
    unsigned length = std::strlen(chars);
con's avatar
con committed
599 600 601
    return findOrInsertIdentifier(chars, length);
}

602 603 604 605 606 607
Control::IdentifierIterator Control::firstIdentifier() const
{ return d->identifiers.begin(); }

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

608 609 610 611 612 613 614 615 616 617 618 619
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
620
const StringLiteral *Control::findOrInsertStringLiteral(const char *chars, unsigned size)
con's avatar
con committed
621 622
{ return d->stringLiterals.findOrInsertLiteral(chars, size); }

Roberto Raggi's avatar
Roberto Raggi committed
623
const StringLiteral *Control::findOrInsertStringLiteral(const char *chars)
con's avatar
con committed
624
{
Roberto Raggi's avatar
Roberto Raggi committed
625
    unsigned length = std::strlen(chars);
con's avatar
con committed
626 627 628
    return findOrInsertStringLiteral(chars, length);
}

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

Roberto Raggi's avatar
Roberto Raggi committed
632
const NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars)
con's avatar
con committed
633
{
Roberto Raggi's avatar
Roberto Raggi committed
634
    unsigned length = std::strlen(chars);
con's avatar
con committed
635 636 637
    return findOrInsertNumericLiteral(chars, length);
}

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

Roberto Raggi's avatar
Roberto Raggi committed
641 642 643
TemplateNameId *Control::templateNameId(const Identifier *id,
                                        FullySpecifiedType *const args,
                                        unsigned argv)
con's avatar
con committed
644 645 646 647 648
{
    std::vector<FullySpecifiedType> templateArguments(args, args + argv);
    return d->findOrInsertTemplateNameId(id, templateArguments);
}

Roberto Raggi's avatar
Roberto Raggi committed
649
DestructorNameId *Control::destructorNameId(const Identifier *id)
con's avatar
con committed
650 651 652 653 654
{ return d->findOrInsertDestructorNameId(id); }

OperatorNameId *Control::operatorNameId(int kind)
{ return d->findOrInsertOperatorNameId(kind); }

655
ConversionNameId *Control::conversionNameId(const FullySpecifiedType &type)
con's avatar
con committed
656 657 658 659 660 661 662 663 664 665
{ return d->findOrInsertConversionNameId(type); }

QualifiedNameId *Control::qualifiedNameId(Name *const *names,
                                             unsigned nameCount,
                                             bool isGlobal)
{
    std::vector<Name *> classOrNamespaceNames(names, names + nameCount);
    return d->findOrInsertQualifiedNameId(classOrNamespaceNames, isGlobal);
}

666 667 668 669 670 671 672 673 674
SelectorNameId *Control::selectorNameId(Name *const *names,
                                        unsigned nameCount,
                                        bool hasArguments)
{
    std::vector<Name *> selectorNames(names, names + nameCount);
    return d->findOrInsertSelectorNameId(selectorNames, hasArguments);
}


con's avatar
con committed
675 676 677 678 679 680 681 682 683
VoidType *Control::voidType()
{ return &d->voidType; }

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

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

684
PointerToMemberType *Control::pointerToMemberType(Name *memberName, const FullySpecifiedType &elementType)
con's avatar
con committed
685 686
{ return d->findOrInsertPointerToMemberType(memberName, elementType); }

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

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

693
ArrayType *Control::arrayType(const FullySpecifiedType &elementType, unsigned size)
con's avatar
con committed
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
{ return d->findOrInsertArrayType(elementType, size); }

NamedType *Control::namedType(Name *name)
{ return d->findOrInsertNamedType(name); }

Argument *Control::newArgument(unsigned sourceLocation, Name *name)
{ return d->newArgument(sourceLocation, name); }

Function *Control::newFunction(unsigned sourceLocation, Name *name)
{ return d->newFunction(sourceLocation, name); }

Namespace *Control::newNamespace(unsigned sourceLocation, Name *name)
{ return d->newNamespace(sourceLocation, name); }

BaseClass *Control::newBaseClass(unsigned sourceLocation, Name *name)
{ return d->newBaseClass(sourceLocation, name); }

Class *Control::newClass(unsigned sourceLocation, Name *name)
{ return d->newClass(sourceLocation, name); }

Enum *Control::newEnum(unsigned sourceLocation, Name *name)
{ return d->newEnum(sourceLocation, name); }

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

Declaration *Control::newDeclaration(unsigned sourceLocation, Name *name)
{ return d->newDeclaration(sourceLocation, name); }

UsingNamespaceDirective *Control::newUsingNamespaceDirective(unsigned sourceLocation,
                                                                Name *name)
{ return d->newUsingNamespaceDirective(sourceLocation, name); }

UsingDeclaration *Control::newUsingDeclaration(unsigned sourceLocation, Name *name)
{ return d->newUsingDeclaration(sourceLocation, name); }

730 731 732 733
ForwardClassDeclaration *Control::newForwardClassDeclaration(unsigned sourceLocation,
                                                             Name *name)
{ return d->newForwardClassDeclaration(sourceLocation, name); }

734 735 736 737 738 739
ObjCBaseClass *Control::newObjCBaseClass(unsigned sourceLocation, Name *name)
{ return d->newObjCBaseClass(sourceLocation, name); }

ObjCBaseProtocol *Control::newObjCBaseProtocol(unsigned sourceLocation, Name *name)
{ return d->newObjCBaseProtocol(sourceLocation, name); }

740 741 742 743 744 745 746 747 748 749 750
ObjCClass *Control::newObjCClass(unsigned sourceLocation, Name *name)
{ return d->newObjCClass(sourceLocation, name); }

ObjCForwardClassDeclaration *Control::newObjCForwardClassDeclaration(unsigned sourceLocation, Name *name)
{ return d->newObjCForwardClassDeclaration(sourceLocation, name); }

ObjCProtocol *Control::newObjCProtocol(unsigned sourceLocation, Name *name)
{ return d->newObjCProtocol(sourceLocation, name); }

ObjCForwardProtocolDeclaration *Control::newObjCForwardProtocolDeclaration(unsigned sourceLocation, Name *name)
{ return d->newObjCForwardProtocolDeclaration(sourceLocation, name); }
751

752 753 754
ObjCMethod *Control::newObjCMethod(unsigned sourceLocation, Name *name)
{ return d->newObjCMethod(sourceLocation, name); }

755 756 757
ObjCPropertyDeclaration *Control::newObjCPropertyDeclaration(unsigned sourceLocation, Name *name)
{ return d->newObjCPropertyDeclaration(sourceLocation, name); }

Roberto Raggi's avatar
Roberto Raggi committed
758
const Identifier *Control::objcGetterId() const
759 760
{ return d->objcGetterId; }

Roberto Raggi's avatar
Roberto Raggi committed
761
const Identifier *Control::objcSetterId() const
762 763
{ return d->objcSetterId; }

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

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

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

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

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

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