tools/icheck/parser/src/shared/cplusplus/Control.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
       
    42 //
       
    43 // Permission is hereby granted, free of charge, to any person obtaining a copy
       
    44 // of this software and associated documentation files (the "Software"), to deal
       
    45 // in the Software without restriction, including without limitation the rights
       
    46 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       
    47 // copies of the Software, and to permit persons to whom the Software is
       
    48 // furnished to do so, subject to the following conditions:
       
    49 //
       
    50 // The above copyright notice and this permission notice shall be included in
       
    51 // all copies or substantial portions of the Software.
       
    52 //
       
    53 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
       
    54 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
       
    55 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
       
    56 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
       
    57 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
       
    58 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
       
    59 // THE SOFTWARE.
       
    60 
       
    61 #include "Control.h"
       
    62 #include "Literals.h"
       
    63 #include "LiteralTable.h"
       
    64 #include "TranslationUnit.h"
       
    65 #include "CoreTypes.h"
       
    66 #include "Symbols.h"
       
    67 #include "Names.h"
       
    68 #include "Array.h"
       
    69 #include "TypeMatcher.h"
       
    70 #include <map>
       
    71 #include <set>
       
    72 
       
    73 using namespace CPlusPlus;
       
    74 
       
    75 namespace {
       
    76 
       
    77 template <typename _Tp>
       
    78 struct Compare;
       
    79 
       
    80 template <> struct Compare<IntegerType>
       
    81 {
       
    82     bool operator()(const IntegerType &ty, const IntegerType &otherTy) const
       
    83     { return ty.kind() < otherTy.kind(); }
       
    84 };
       
    85 
       
    86 template <> struct Compare<FloatType>
       
    87 {
       
    88     bool operator()(const FloatType &ty, const FloatType &otherTy) const
       
    89     { return ty.kind() < otherTy.kind(); }
       
    90 };
       
    91 
       
    92 template <> struct Compare<PointerToMemberType>
       
    93 {
       
    94     bool operator()(const PointerToMemberType &ty, const PointerToMemberType &otherTy) const
       
    95     {
       
    96         if (ty.memberName() < otherTy.memberName())
       
    97             return true;
       
    98 
       
    99         else if (ty.memberName() == otherTy.memberName())
       
   100             return ty.elementType() < otherTy.elementType();
       
   101 
       
   102         return false;
       
   103     }
       
   104 };
       
   105 
       
   106 template <> struct Compare<PointerType>
       
   107 {
       
   108     bool operator()(const PointerType &ty, const PointerType &otherTy) const
       
   109     {
       
   110         return ty.elementType() < otherTy.elementType();
       
   111     }
       
   112 };
       
   113 
       
   114 template <> struct Compare<ReferenceType>
       
   115 {
       
   116     bool operator()(const ReferenceType &ty, const ReferenceType &otherTy) const
       
   117     {
       
   118         return ty.elementType() < otherTy.elementType();
       
   119     }
       
   120 };
       
   121 
       
   122 template <> struct Compare<NamedType>
       
   123 {
       
   124     bool operator()(const NamedType &ty, const NamedType &otherTy) const
       
   125     {
       
   126         return ty.name() < otherTy.name();
       
   127     }
       
   128 };
       
   129 
       
   130 template <> struct Compare<ArrayType>
       
   131 {
       
   132     bool operator()(const ArrayType &ty, const ArrayType &otherTy) const
       
   133     {
       
   134         if (ty.size() < otherTy.size())
       
   135             return true;
       
   136 
       
   137         else if (ty.size() == otherTy.size())
       
   138             return ty.elementType() < otherTy.elementType();
       
   139 
       
   140         return false;
       
   141     }
       
   142 };
       
   143 
       
   144 template <> struct Compare<NameId>
       
   145 {
       
   146     bool operator()(const NameId &name, const NameId &otherName) const
       
   147     {
       
   148         return name.identifier() < otherName.identifier();
       
   149     }
       
   150 };
       
   151 
       
   152 template <> struct Compare<DestructorNameId>
       
   153 {
       
   154     bool operator()(const DestructorNameId &name, const DestructorNameId &otherName) const
       
   155     {
       
   156         return name.identifier() < otherName.identifier();
       
   157     }
       
   158 };
       
   159 
       
   160 template <> struct Compare<OperatorNameId>
       
   161 {
       
   162     bool operator()(const OperatorNameId &name, const OperatorNameId &otherName) const
       
   163     {
       
   164         return name.kind() < otherName.kind();
       
   165     }
       
   166 };
       
   167 
       
   168 template <> struct Compare<ConversionNameId>
       
   169 {
       
   170     bool operator()(const ConversionNameId &name, const ConversionNameId &otherName) const
       
   171     {
       
   172         return name.type() < otherName.type();
       
   173     }
       
   174 };
       
   175 template <> struct Compare<TemplateNameId>
       
   176 {
       
   177     bool operator()(const TemplateNameId &name, const TemplateNameId &otherName) const
       
   178     {
       
   179         const Identifier *id = name.identifier();
       
   180         const Identifier *otherId = otherName.identifier();
       
   181 
       
   182         if (id == otherId)
       
   183             return std::lexicographical_compare(name.firstTemplateArgument(), name.lastTemplateArgument(),
       
   184                                                 otherName.firstTemplateArgument(), otherName.lastTemplateArgument());
       
   185 
       
   186         return id < otherId;
       
   187     }
       
   188 };
       
   189 template <> struct Compare<QualifiedNameId>
       
   190 {
       
   191     bool operator()(const QualifiedNameId &name, const QualifiedNameId &otherName) const
       
   192     {
       
   193         if (name.isGlobal() == otherName.isGlobal())
       
   194             return std::lexicographical_compare(name.firstName(), name.lastName(),
       
   195                                                 otherName.firstName(), otherName.lastName());
       
   196 
       
   197         return name.isGlobal() < otherName.isGlobal();
       
   198     }
       
   199 };
       
   200 
       
   201 template <> struct Compare<SelectorNameId>
       
   202 {
       
   203     bool operator()(const SelectorNameId &name, const SelectorNameId &otherName) const
       
   204     {
       
   205         if (name.hasArguments() == otherName.hasArguments())
       
   206             return std::lexicographical_compare(name.firstName(), name.lastName(),
       
   207                                                 otherName.firstName(), otherName.lastName());
       
   208 
       
   209         return name.hasArguments() < otherName.hasArguments();
       
   210     }
       
   211 };
       
   212 
       
   213 
       
   214 template <typename _Tp>
       
   215 class Table: public std::set<_Tp, Compare<_Tp> >
       
   216 {
       
   217     typedef std::set<_Tp, Compare<_Tp> > _Base;
       
   218 public:
       
   219     _Tp *intern(const _Tp &element)
       
   220     { return const_cast<_Tp *>(&*_Base::insert(element).first); }
       
   221 };
       
   222 
       
   223 } // end of anonymous namespace
       
   224 
       
   225 #ifdef ICHECK_BUILD
       
   226 //Symbian compiler has some difficulties to understand the templates.
       
   227 static void delete_array_entries(std::vector<Symbol *> vt)
       
   228 {
       
   229     std::vector<Symbol *>::iterator it;
       
   230     for (it = vt.begin(); it != vt.end(); ++it) {
       
   231         delete *it;
       
   232     }
       
   233 }
       
   234 #else
       
   235 template <typename _Iterator>
       
   236 static void delete_array_entries(_Iterator first, _Iterator last)
       
   237 {
       
   238     for (; first != last; ++first)
       
   239         delete *first;
       
   240 }
       
   241 
       
   242 template <typename _Array>
       
   243 static void delete_array_entries(const _Array &a)
       
   244 { delete_array_entries(a.begin(), a.end()); }
       
   245 #endif
       
   246 
       
   247 class Control::Data
       
   248 {
       
   249 public:
       
   250     Data(Control *control)
       
   251         : control(control),
       
   252           translationUnit(0),
       
   253           diagnosticClient(0)
       
   254     {}
       
   255 
       
   256     ~Data()
       
   257     {
       
   258         // symbols
       
   259         delete_array_entries(symbols);
       
   260     }
       
   261 
       
   262     const NameId *findOrInsertNameId(const Identifier *id)
       
   263     {
       
   264         if (! id)
       
   265             return 0;
       
   266 
       
   267         return nameIds.intern(NameId(id));
       
   268     }
       
   269 
       
   270     template <typename _Iterator>
       
   271     const TemplateNameId *findOrInsertTemplateNameId(const Identifier *id, _Iterator first, _Iterator last)
       
   272     {
       
   273         return templateNameIds.intern(TemplateNameId(id, first, last));
       
   274     }
       
   275 
       
   276     const DestructorNameId *findOrInsertDestructorNameId(const Identifier *id)
       
   277     {
       
   278         return destructorNameIds.intern(DestructorNameId(id));
       
   279     }
       
   280 
       
   281     const OperatorNameId *findOrInsertOperatorNameId(int kind)
       
   282     {
       
   283         return operatorNameIds.intern(OperatorNameId(kind));
       
   284     }
       
   285 
       
   286     const ConversionNameId *findOrInsertConversionNameId(const FullySpecifiedType &type)
       
   287     {
       
   288         return conversionNameIds.intern(ConversionNameId(type));
       
   289     }
       
   290 
       
   291     template <typename _Iterator>
       
   292     const QualifiedNameId *findOrInsertQualifiedNameId(_Iterator first, _Iterator last, bool isGlobal)
       
   293     {
       
   294         return qualifiedNameIds.intern(QualifiedNameId(first, last, isGlobal));
       
   295     }
       
   296 
       
   297     template <typename _Iterator>
       
   298     const SelectorNameId *findOrInsertSelectorNameId(_Iterator first, _Iterator last, bool hasArguments)
       
   299     {
       
   300         return selectorNameIds.intern(SelectorNameId(first, last, hasArguments));
       
   301     }
       
   302 
       
   303     IntegerType *findOrInsertIntegerType(int kind)
       
   304     {
       
   305         return integerTypes.intern(IntegerType(kind));
       
   306     }
       
   307 
       
   308     FloatType *findOrInsertFloatType(int kind)
       
   309     {
       
   310         return floatTypes.intern(FloatType(kind));
       
   311     }
       
   312 
       
   313     PointerToMemberType *findOrInsertPointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
       
   314     {
       
   315         return pointerToMemberTypes.intern(PointerToMemberType(memberName, elementType));
       
   316     }
       
   317 
       
   318     PointerType *findOrInsertPointerType(const FullySpecifiedType &elementType)
       
   319     {
       
   320         return pointerTypes.intern(PointerType(elementType));
       
   321     }
       
   322 
       
   323     ReferenceType *findOrInsertReferenceType(const FullySpecifiedType &elementType)
       
   324     {
       
   325         return referenceTypes.intern(ReferenceType(elementType));
       
   326     }
       
   327 
       
   328     ArrayType *findOrInsertArrayType(const FullySpecifiedType &elementType, unsigned size)
       
   329     {
       
   330         return arrayTypes.intern(ArrayType(elementType, size));
       
   331     }
       
   332 
       
   333     NamedType *findOrInsertNamedType(const Name *name)
       
   334     {
       
   335         return namedTypes.intern(NamedType(name));
       
   336     }
       
   337 
       
   338     Declaration *newDeclaration(unsigned sourceLocation, const Name *name)
       
   339     {
       
   340         Declaration *declaration = new Declaration(translationUnit,
       
   341                                                    sourceLocation, name);
       
   342         symbols.push_back(declaration);
       
   343         return declaration;
       
   344     }
       
   345 
       
   346     Argument *newArgument(unsigned sourceLocation, const Name *name)
       
   347     {
       
   348         Argument *argument = new Argument(translationUnit,
       
   349                                           sourceLocation, name);
       
   350         symbols.push_back(argument);
       
   351         return argument;
       
   352     }
       
   353 
       
   354     TypenameArgument *newTypenameArgument(unsigned sourceLocation, const Name *name)
       
   355     {
       
   356         TypenameArgument *argument = new TypenameArgument(translationUnit,
       
   357                                                           sourceLocation, name);
       
   358         symbols.push_back(argument);
       
   359         return argument;
       
   360     }
       
   361 
       
   362     Function *newFunction(unsigned sourceLocation, const Name *name)
       
   363     {
       
   364         Function *function = new Function(translationUnit,
       
   365                                           sourceLocation, name);
       
   366         symbols.push_back(function);
       
   367         return function;
       
   368     }
       
   369 
       
   370     BaseClass *newBaseClass(unsigned sourceLocation, const Name *name)
       
   371     {
       
   372         BaseClass *baseClass = new BaseClass(translationUnit,
       
   373                                              sourceLocation, name);
       
   374         symbols.push_back(baseClass);
       
   375         return baseClass;
       
   376     }
       
   377 
       
   378     Block *newBlock(unsigned sourceLocation)
       
   379     {
       
   380         Block *block = new Block(translationUnit, sourceLocation);
       
   381         symbols.push_back(block);
       
   382         return block;
       
   383     }
       
   384 
       
   385     Class *newClass(unsigned sourceLocation, const Name *name)
       
   386     {
       
   387         Class *klass = new Class(translationUnit,
       
   388                                  sourceLocation, name);
       
   389         symbols.push_back(klass);
       
   390         return klass;
       
   391     }
       
   392 
       
   393     Namespace *newNamespace(unsigned sourceLocation, const Name *name)
       
   394     {
       
   395         Namespace *ns = new Namespace(translationUnit,
       
   396                                       sourceLocation, name);
       
   397         symbols.push_back(ns);
       
   398         return ns;
       
   399     }
       
   400 
       
   401     UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, const Name *name)
       
   402     {
       
   403         UsingNamespaceDirective *u = new UsingNamespaceDirective(translationUnit,
       
   404                                                                  sourceLocation, name);
       
   405         symbols.push_back(u);
       
   406         return u;
       
   407     }
       
   408 
       
   409     ForwardClassDeclaration *newForwardClassDeclaration(unsigned sourceLocation, const Name *name)
       
   410     {
       
   411         ForwardClassDeclaration *c = new ForwardClassDeclaration(translationUnit,
       
   412                                                                  sourceLocation, name);
       
   413         symbols.push_back(c);
       
   414         return c;
       
   415     }
       
   416 
       
   417     ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name)
       
   418     {
       
   419         ObjCBaseClass *c = new ObjCBaseClass(translationUnit, sourceLocation, name);
       
   420         symbols.push_back(c);
       
   421         return c;
       
   422     }
       
   423 
       
   424     ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, const Name *name)
       
   425     {
       
   426         ObjCBaseProtocol *p = new ObjCBaseProtocol(translationUnit, sourceLocation, name);
       
   427         symbols.push_back(p);
       
   428         return p;
       
   429     }
       
   430 
       
   431     ObjCClass *newObjCClass(unsigned sourceLocation, const Name *name)
       
   432     {
       
   433         ObjCClass *c = new ObjCClass(translationUnit, sourceLocation, name);
       
   434         symbols.push_back(c);
       
   435         return c;
       
   436     }
       
   437 
       
   438     ObjCForwardClassDeclaration *newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name)
       
   439     {
       
   440         ObjCForwardClassDeclaration *fwd = new ObjCForwardClassDeclaration(translationUnit, sourceLocation, name);
       
   441         symbols.push_back(fwd);
       
   442         return fwd;
       
   443     }
       
   444 
       
   445     ObjCProtocol *newObjCProtocol(unsigned sourceLocation, const Name *name)
       
   446     {
       
   447         ObjCProtocol *p = new ObjCProtocol(translationUnit, sourceLocation, name);
       
   448         symbols.push_back(p);
       
   449         return p;
       
   450     }
       
   451 
       
   452     ObjCForwardProtocolDeclaration *newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name)
       
   453     {
       
   454         ObjCForwardProtocolDeclaration *fwd = new ObjCForwardProtocolDeclaration(translationUnit, sourceLocation, name);
       
   455         symbols.push_back(fwd);
       
   456         return fwd;
       
   457     }
       
   458 
       
   459     ObjCMethod *newObjCMethod(unsigned sourceLocation, const Name *name)
       
   460     {
       
   461         ObjCMethod *method = new ObjCMethod(translationUnit, sourceLocation, name);
       
   462         symbols.push_back(method);
       
   463         return method;
       
   464     }
       
   465 
       
   466     ObjCPropertyDeclaration *newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name)
       
   467     {
       
   468         ObjCPropertyDeclaration *decl = new ObjCPropertyDeclaration(translationUnit, sourceLocation, name);
       
   469         symbols.push_back(decl);
       
   470         return decl;
       
   471     }
       
   472 
       
   473     Enum *newEnum(unsigned sourceLocation, const Name *name)
       
   474     {
       
   475         Enum *e = new Enum(translationUnit,
       
   476                            sourceLocation, name);
       
   477         symbols.push_back(e);
       
   478         return e;
       
   479     }
       
   480 
       
   481     UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, const Name *name)
       
   482     {
       
   483         UsingDeclaration *u = new UsingDeclaration(translationUnit,
       
   484                                                    sourceLocation, name);
       
   485         symbols.push_back(u);
       
   486         return u;
       
   487     }
       
   488 
       
   489     Control *control;
       
   490     TranslationUnit *translationUnit;
       
   491     DiagnosticClient *diagnosticClient;
       
   492 
       
   493     TypeMatcher matcher;
       
   494 
       
   495     LiteralTable<Identifier> identifiers;
       
   496     LiteralTable<StringLiteral> stringLiterals;
       
   497     LiteralTable<NumericLiteral> numericLiterals;
       
   498 
       
   499     // ### replace std::map with lookup tables. ASAP!
       
   500 
       
   501     // names
       
   502     Table<NameId> nameIds;
       
   503     Table<DestructorNameId> destructorNameIds;
       
   504     Table<OperatorNameId> operatorNameIds;
       
   505     Table<ConversionNameId> conversionNameIds;
       
   506     Table<TemplateNameId> templateNameIds;
       
   507     Table<QualifiedNameId> qualifiedNameIds;
       
   508     Table<SelectorNameId> selectorNameIds;
       
   509 
       
   510     // types
       
   511     VoidType voidType;
       
   512     Table<IntegerType> integerTypes;
       
   513     Table<FloatType> floatTypes;
       
   514     Table<PointerToMemberType> pointerToMemberTypes;
       
   515     Table<PointerType> pointerTypes;
       
   516     Table<ReferenceType> referenceTypes;
       
   517     Table<ArrayType> arrayTypes;
       
   518     Table<NamedType> namedTypes;
       
   519 
       
   520     // symbols
       
   521     std::vector<Symbol *> symbols;
       
   522 
       
   523     // ObjC context keywords:
       
   524     const Identifier *objcGetterId;
       
   525     const Identifier *objcSetterId;
       
   526     const Identifier *objcReadwriteId;
       
   527     const Identifier *objcReadonlyId;
       
   528     const Identifier *objcAssignId;
       
   529     const Identifier *objcRetainId;
       
   530     const Identifier *objcCopyId;
       
   531     const Identifier *objcNonatomicId;
       
   532 };
       
   533 
       
   534 Control::Control()
       
   535 {
       
   536     d = new Data(this);
       
   537 
       
   538     d->objcGetterId = findOrInsertIdentifier("getter");
       
   539     d->objcSetterId = findOrInsertIdentifier("setter");
       
   540     d->objcReadwriteId = findOrInsertIdentifier("readwrite");
       
   541     d->objcReadonlyId = findOrInsertIdentifier("readonly");
       
   542     d->objcAssignId = findOrInsertIdentifier("assign");
       
   543     d->objcRetainId = findOrInsertIdentifier("retain");
       
   544     d->objcCopyId = findOrInsertIdentifier("copy");
       
   545     d->objcNonatomicId = findOrInsertIdentifier("nonatomic");
       
   546 }
       
   547 
       
   548 Control::~Control()
       
   549 { delete d; }
       
   550 
       
   551 TranslationUnit *Control::translationUnit() const
       
   552 { return d->translationUnit; }
       
   553 
       
   554 TranslationUnit *Control::switchTranslationUnit(TranslationUnit *unit)
       
   555 {
       
   556     TranslationUnit *previousTranslationUnit = d->translationUnit;
       
   557     d->translationUnit = unit;
       
   558     return previousTranslationUnit;
       
   559 }
       
   560 
       
   561 DiagnosticClient *Control::diagnosticClient() const
       
   562 { return d->diagnosticClient; }
       
   563 
       
   564 void Control::setDiagnosticClient(DiagnosticClient *diagnosticClient)
       
   565 { d->diagnosticClient = diagnosticClient; }
       
   566 
       
   567 const Identifier *Control::findIdentifier(const char *chars, unsigned size) const
       
   568 { return d->identifiers.findLiteral(chars, size); }
       
   569 
       
   570 const Identifier *Control::findOrInsertIdentifier(const char *chars, unsigned size)
       
   571 { return d->identifiers.findOrInsertLiteral(chars, size); }
       
   572 
       
   573 const Identifier *Control::findOrInsertIdentifier(const char *chars)
       
   574 {
       
   575     unsigned length = std::strlen(chars);
       
   576     return findOrInsertIdentifier(chars, length);
       
   577 }
       
   578 
       
   579 Control::IdentifierIterator Control::firstIdentifier() const
       
   580 { return d->identifiers.begin(); }
       
   581 
       
   582 Control::IdentifierIterator Control::lastIdentifier() const
       
   583 { return d->identifiers.end(); }
       
   584 
       
   585 Control::StringLiteralIterator Control::firstStringLiteral() const
       
   586 { return d->stringLiterals.begin(); }
       
   587 
       
   588 Control::StringLiteralIterator Control::lastStringLiteral() const
       
   589 { return d->stringLiterals.end(); }
       
   590 
       
   591 Control::NumericLiteralIterator Control::firstNumericLiteral() const
       
   592 { return d->numericLiterals.begin(); }
       
   593 
       
   594 Control::NumericLiteralIterator Control::lastNumericLiteral() const
       
   595 { return d->numericLiterals.end(); }
       
   596 
       
   597 const StringLiteral *Control::findOrInsertStringLiteral(const char *chars, unsigned size)
       
   598 { return d->stringLiterals.findOrInsertLiteral(chars, size); }
       
   599 
       
   600 const StringLiteral *Control::findOrInsertStringLiteral(const char *chars)
       
   601 {
       
   602     unsigned length = std::strlen(chars);
       
   603     return findOrInsertStringLiteral(chars, length);
       
   604 }
       
   605 
       
   606 const NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars, unsigned size)
       
   607 { return d->numericLiterals.findOrInsertLiteral(chars, size); }
       
   608 
       
   609 const NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars)
       
   610 {
       
   611     unsigned length = std::strlen(chars);
       
   612     return findOrInsertNumericLiteral(chars, length);
       
   613 }
       
   614 
       
   615 const NameId *Control::nameId(const Identifier *id)
       
   616 { return d->findOrInsertNameId(id); }
       
   617 
       
   618 const TemplateNameId *Control::templateNameId(const Identifier *id,
       
   619                                               const FullySpecifiedType *const args,
       
   620                                               unsigned argv)
       
   621 {
       
   622     return d->findOrInsertTemplateNameId(id, args, args + argv);
       
   623 }
       
   624 
       
   625 const DestructorNameId *Control::destructorNameId(const Identifier *id)
       
   626 { return d->findOrInsertDestructorNameId(id); }
       
   627 
       
   628 const OperatorNameId *Control::operatorNameId(int kind)
       
   629 { return d->findOrInsertOperatorNameId(kind); }
       
   630 
       
   631 const ConversionNameId *Control::conversionNameId(const FullySpecifiedType &type)
       
   632 { return d->findOrInsertConversionNameId(type); }
       
   633 
       
   634 const QualifiedNameId *Control::qualifiedNameId(const Name *const *names,
       
   635                                                 unsigned nameCount,
       
   636                                                 bool isGlobal)
       
   637 {
       
   638     return d->findOrInsertQualifiedNameId(names, names + nameCount, isGlobal);
       
   639 }
       
   640 
       
   641 const SelectorNameId *Control::selectorNameId(const Name *const *names,
       
   642                                               unsigned nameCount,
       
   643                                               bool hasArguments)
       
   644 {
       
   645     return d->findOrInsertSelectorNameId(names, names + nameCount, hasArguments);
       
   646 }
       
   647 
       
   648 
       
   649 VoidType *Control::voidType()
       
   650 { return &d->voidType; }
       
   651 
       
   652 IntegerType *Control::integerType(int kind)
       
   653 { return d->findOrInsertIntegerType(kind); }
       
   654 
       
   655 FloatType *Control::floatType(int kind)
       
   656 { return d->findOrInsertFloatType(kind); }
       
   657 
       
   658 PointerToMemberType *Control::pointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
       
   659 { return d->findOrInsertPointerToMemberType(memberName, elementType); }
       
   660 
       
   661 PointerType *Control::pointerType(const FullySpecifiedType &elementType)
       
   662 { return d->findOrInsertPointerType(elementType); }
       
   663 
       
   664 ReferenceType *Control::referenceType(const FullySpecifiedType &elementType)
       
   665 { return d->findOrInsertReferenceType(elementType); }
       
   666 
       
   667 ArrayType *Control::arrayType(const FullySpecifiedType &elementType, unsigned size)
       
   668 { return d->findOrInsertArrayType(elementType, size); }
       
   669 
       
   670 NamedType *Control::namedType(const Name *name)
       
   671 { return d->findOrInsertNamedType(name); }
       
   672 
       
   673 Argument *Control::newArgument(unsigned sourceLocation, const Name *name)
       
   674 { return d->newArgument(sourceLocation, name); }
       
   675 
       
   676 TypenameArgument *Control::newTypenameArgument(unsigned sourceLocation, const Name *name)
       
   677 { return d->newTypenameArgument(sourceLocation, name); }
       
   678 
       
   679 Function *Control::newFunction(unsigned sourceLocation, const Name *name)
       
   680 { return d->newFunction(sourceLocation, name); }
       
   681 
       
   682 Namespace *Control::newNamespace(unsigned sourceLocation, const Name *name)
       
   683 { return d->newNamespace(sourceLocation, name); }
       
   684 
       
   685 BaseClass *Control::newBaseClass(unsigned sourceLocation, const Name *name)
       
   686 { return d->newBaseClass(sourceLocation, name); }
       
   687 
       
   688 Class *Control::newClass(unsigned sourceLocation, const Name *name)
       
   689 { return d->newClass(sourceLocation, name); }
       
   690 
       
   691 Enum *Control::newEnum(unsigned sourceLocation, const Name *name)
       
   692 { return d->newEnum(sourceLocation, name); }
       
   693 
       
   694 Block *Control::newBlock(unsigned sourceLocation)
       
   695 { return d->newBlock(sourceLocation); }
       
   696 
       
   697 Declaration *Control::newDeclaration(unsigned sourceLocation, const Name *name)
       
   698 { return d->newDeclaration(sourceLocation, name); }
       
   699 
       
   700 UsingNamespaceDirective *Control::newUsingNamespaceDirective(unsigned sourceLocation,
       
   701                                                                 const Name *name)
       
   702 { return d->newUsingNamespaceDirective(sourceLocation, name); }
       
   703 
       
   704 UsingDeclaration *Control::newUsingDeclaration(unsigned sourceLocation, const Name *name)
       
   705 { return d->newUsingDeclaration(sourceLocation, name); }
       
   706 
       
   707 ForwardClassDeclaration *Control::newForwardClassDeclaration(unsigned sourceLocation,
       
   708                                                              const Name *name)
       
   709 { return d->newForwardClassDeclaration(sourceLocation, name); }
       
   710 
       
   711 ObjCBaseClass *Control::newObjCBaseClass(unsigned sourceLocation, const Name *name)
       
   712 { return d->newObjCBaseClass(sourceLocation, name); }
       
   713 
       
   714 ObjCBaseProtocol *Control::newObjCBaseProtocol(unsigned sourceLocation, const Name *name)
       
   715 { return d->newObjCBaseProtocol(sourceLocation, name); }
       
   716 
       
   717 ObjCClass *Control::newObjCClass(unsigned sourceLocation, const Name *name)
       
   718 { return d->newObjCClass(sourceLocation, name); }
       
   719 
       
   720 ObjCForwardClassDeclaration *Control::newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name)
       
   721 { return d->newObjCForwardClassDeclaration(sourceLocation, name); }
       
   722 
       
   723 ObjCProtocol *Control::newObjCProtocol(unsigned sourceLocation, const Name *name)
       
   724 { return d->newObjCProtocol(sourceLocation, name); }
       
   725 
       
   726 ObjCForwardProtocolDeclaration *Control::newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name)
       
   727 { return d->newObjCForwardProtocolDeclaration(sourceLocation, name); }
       
   728 
       
   729 ObjCMethod *Control::newObjCMethod(unsigned sourceLocation, const Name *name)
       
   730 { return d->newObjCMethod(sourceLocation, name); }
       
   731 
       
   732 ObjCPropertyDeclaration *Control::newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name)
       
   733 { return d->newObjCPropertyDeclaration(sourceLocation, name); }
       
   734 
       
   735 const Identifier *Control::objcGetterId() const
       
   736 { return d->objcGetterId; }
       
   737 
       
   738 const Identifier *Control::objcSetterId() const
       
   739 { return d->objcSetterId; }
       
   740 
       
   741 const Identifier *Control::objcReadwriteId() const
       
   742 { return d->objcReadwriteId; }
       
   743 
       
   744 const Identifier *Control::objcReadonlyId() const
       
   745 { return d->objcReadonlyId; }
       
   746 
       
   747 const Identifier *Control::objcAssignId() const
       
   748 { return d->objcAssignId; }
       
   749 
       
   750 const Identifier *Control::objcRetainId() const
       
   751 { return d->objcRetainId; }
       
   752 
       
   753 const Identifier *Control::objcCopyId() const
       
   754 { return d->objcCopyId; }
       
   755 
       
   756 const Identifier *Control::objcNonatomicId() const
       
   757 { return d->objcNonatomicId; }