Control.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. // Copyright (c) 2008 Roberto Raggi <[email protected]>
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. #include "Control.h"
  21. #include "Literals.h"
  22. #include "LiteralTable.h"
  23. #include "TranslationUnit.h"
  24. #include "CoreTypes.h"
  25. #include "Symbols.h"
  26. #include "Names.h"
  27. #include <map>
  28. #include <set>
  29. #include <algorithm>
  30. using namespace CPlusPlus;
  31. namespace {
  32. template <typename T>
  33. struct Compare;
  34. template <> struct Compare<IntegerType>
  35. {
  36. bool operator()(const IntegerType &ty, const IntegerType &otherTy) const
  37. { return ty.kind() < otherTy.kind(); }
  38. };
  39. template <> struct Compare<FloatType>
  40. {
  41. bool operator()(const FloatType &ty, const FloatType &otherTy) const
  42. { return ty.kind() < otherTy.kind(); }
  43. };
  44. template <> struct Compare<PointerToMemberType>
  45. {
  46. bool operator()(const PointerToMemberType &ty, const PointerToMemberType &otherTy) const
  47. {
  48. if (ty.memberName() < otherTy.memberName())
  49. return true;
  50. else if (ty.memberName() == otherTy.memberName())
  51. return ty.elementType() < otherTy.elementType();
  52. return false;
  53. }
  54. };
  55. template <> struct Compare<PointerType>
  56. {
  57. bool operator()(const PointerType &ty, const PointerType &otherTy) const
  58. {
  59. return ty.elementType() < otherTy.elementType();
  60. }
  61. };
  62. template <> struct Compare<ReferenceType>
  63. {
  64. bool operator()(const ReferenceType &ty, const ReferenceType &otherTy) const
  65. {
  66. return ty.elementType() < otherTy.elementType();
  67. }
  68. };
  69. template <> struct Compare<NamedType>
  70. {
  71. bool operator()(const NamedType &ty, const NamedType &otherTy) const
  72. {
  73. return ty.name() < otherTy.name();
  74. }
  75. };
  76. template <> struct Compare<ArrayType>
  77. {
  78. bool operator()(const ArrayType &ty, const ArrayType &otherTy) const
  79. {
  80. if (ty.size() < otherTy.size())
  81. return true;
  82. else if (ty.size() == otherTy.size())
  83. return ty.elementType() < otherTy.elementType();
  84. return false;
  85. }
  86. };
  87. template <> struct Compare<AnonymousNameId>
  88. {
  89. bool operator()(const AnonymousNameId &name, const AnonymousNameId &otherName) const
  90. {
  91. return name.classTokenIndex() < otherName.classTokenIndex();
  92. }
  93. };
  94. template <> struct Compare<DestructorNameId>
  95. {
  96. bool operator()(const DestructorNameId &name, const DestructorNameId &otherName) const
  97. {
  98. return name.identifier() < otherName.identifier();
  99. }
  100. };
  101. template <> struct Compare<OperatorNameId>
  102. {
  103. bool operator()(const OperatorNameId &name, const OperatorNameId &otherName) const
  104. {
  105. return name.kind() < otherName.kind();
  106. }
  107. };
  108. template <> struct Compare<ConversionNameId>
  109. {
  110. bool operator()(const ConversionNameId &name, const ConversionNameId &otherName) const
  111. {
  112. return name.type() < otherName.type();
  113. }
  114. };
  115. template <> struct Compare<TemplateNameId>
  116. {
  117. bool operator()(const TemplateNameId &name, const TemplateNameId &otherName) const
  118. {
  119. const Identifier *id = name.identifier();
  120. const Identifier *otherId = otherName.identifier();
  121. if (id == otherId) {
  122. // we have to differentiate TemplateNameId with respect to specialization or
  123. // instantiation
  124. if (name.isSpecialization() == otherName.isSpecialization()) {
  125. return std::lexicographical_compare(name.firstTemplateArgument(),
  126. name.lastTemplateArgument(),
  127. otherName.firstTemplateArgument(),
  128. otherName.lastTemplateArgument());
  129. } else {
  130. return name.isSpecialization();
  131. }
  132. }
  133. return id < otherId;
  134. }
  135. };
  136. template <> struct Compare<QualifiedNameId>
  137. {
  138. bool operator()(const QualifiedNameId &name, const QualifiedNameId &otherName) const
  139. {
  140. if (name.base() == otherName.base())
  141. return name.name() < otherName.name();
  142. return name.base() < otherName.base();
  143. }
  144. };
  145. template <> struct Compare<SelectorNameId>
  146. {
  147. bool operator()(const SelectorNameId &name, const SelectorNameId &otherName) const
  148. {
  149. if (name.hasArguments() == otherName.hasArguments())
  150. return std::lexicographical_compare(name.firstName(), name.lastName(),
  151. otherName.firstName(), otherName.lastName());
  152. return name.hasArguments() < otherName.hasArguments();
  153. }
  154. };
  155. template <typename T>
  156. class Table: public std::set<T, Compare<T> >
  157. {
  158. typedef std::set<T, Compare<T> > _Base;
  159. public:
  160. T *intern(const T &element)
  161. { return const_cast<T *>(&*_Base::insert(element).first); }
  162. };
  163. } // end of anonymous namespace
  164. template <typename Iterator>
  165. static void delete_array_entries(Iterator first, Iterator last)
  166. {
  167. for (; first != last; ++first)
  168. delete *first;
  169. }
  170. template <typename Array>
  171. static void delete_array_entries(const Array &a)
  172. { delete_array_entries(a.begin(), a.end()); }
  173. class Control::Data
  174. {
  175. public:
  176. Data(Control *control)
  177. : control(control)
  178. , translationUnit(0)
  179. , diagnosticClient(0)
  180. , deprecatedId(0)
  181. , unavailableId(0)
  182. , objcGetterId(0)
  183. , objcSetterId(0)
  184. , objcReadwriteId(0)
  185. , objcReadonlyId(0)
  186. , objcAssignId(0)
  187. , objcRetainId(0)
  188. , objcCopyId(0)
  189. , objcNonatomicId(0)
  190. , cpp11Override(0)
  191. , cpp11Final(0)
  192. , processor(0)
  193. {}
  194. ~Data()
  195. {
  196. // symbols
  197. delete_array_entries(symbols);
  198. }
  199. const AnonymousNameId *findOrInsertAnonymousNameId(unsigned classTokenIndex)
  200. {
  201. return anonymousNameIds.intern(AnonymousNameId(classTokenIndex));
  202. }
  203. template <typename Iterator>
  204. const TemplateNameId *findOrInsertTemplateNameId(const Identifier *id, bool isSpecialization,
  205. Iterator first, Iterator last)
  206. {
  207. return templateNameIds.intern(TemplateNameId(id, isSpecialization, first, last));
  208. }
  209. const DestructorNameId *findOrInsertDestructorNameId(const Name *name)
  210. {
  211. return destructorNameIds.intern(DestructorNameId(name));
  212. }
  213. const OperatorNameId *findOrInsertOperatorNameId(OperatorNameId::Kind kind)
  214. {
  215. return operatorNameIds.intern(OperatorNameId(kind));
  216. }
  217. const ConversionNameId *findOrInsertConversionNameId(const FullySpecifiedType &type)
  218. {
  219. return conversionNameIds.intern(ConversionNameId(type));
  220. }
  221. const QualifiedNameId *findOrInsertQualifiedNameId(const Name *base, const Name *name)
  222. {
  223. return qualifiedNameIds.intern(QualifiedNameId(base, name));
  224. }
  225. template <typename Iterator>
  226. const SelectorNameId *findOrInsertSelectorNameId(Iterator first, Iterator last, bool hasArguments)
  227. {
  228. return selectorNameIds.intern(SelectorNameId(first, last, hasArguments));
  229. }
  230. IntegerType *findOrInsertIntegerType(int kind)
  231. {
  232. return integerTypes.intern(IntegerType(kind));
  233. }
  234. FloatType *findOrInsertFloatType(int kind)
  235. {
  236. return floatTypes.intern(FloatType(kind));
  237. }
  238. PointerToMemberType *findOrInsertPointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
  239. {
  240. return pointerToMemberTypes.intern(PointerToMemberType(memberName, elementType));
  241. }
  242. PointerType *findOrInsertPointerType(const FullySpecifiedType &elementType)
  243. {
  244. return pointerTypes.intern(PointerType(elementType));
  245. }
  246. ReferenceType *findOrInsertReferenceType(const FullySpecifiedType &elementType, bool rvalueRef)
  247. {
  248. return referenceTypes.intern(ReferenceType(elementType, rvalueRef));
  249. }
  250. ArrayType *findOrInsertArrayType(const FullySpecifiedType &elementType, unsigned size)
  251. {
  252. return arrayTypes.intern(ArrayType(elementType, size));
  253. }
  254. NamedType *findOrInsertNamedType(const Name *name)
  255. {
  256. return namedTypes.intern(NamedType(name));
  257. }
  258. Declaration *newDeclaration(unsigned sourceLocation, const Name *name)
  259. {
  260. Declaration *declaration = new Declaration(translationUnit, sourceLocation, name);
  261. symbols.push_back(declaration);
  262. return declaration;
  263. }
  264. EnumeratorDeclaration *newEnumeratorDeclaration(unsigned sourceLocation, const Name *name)
  265. {
  266. EnumeratorDeclaration *decl = new EnumeratorDeclaration(translationUnit, sourceLocation, name);
  267. symbols.push_back(decl);
  268. return decl;
  269. }
  270. Argument *newArgument(unsigned sourceLocation, const Name *name)
  271. {
  272. Argument *argument = new Argument(translationUnit, sourceLocation, name);
  273. symbols.push_back(argument);
  274. return argument;
  275. }
  276. TypenameArgument *newTypenameArgument(unsigned sourceLocation, const Name *name)
  277. {
  278. TypenameArgument *argument = new TypenameArgument(translationUnit, sourceLocation, name);
  279. symbols.push_back(argument);
  280. return argument;
  281. }
  282. Function *newFunction(unsigned sourceLocation, const Name *name)
  283. {
  284. Function *function = new Function(translationUnit, sourceLocation, name);
  285. symbols.push_back(function);
  286. return function;
  287. }
  288. BaseClass *newBaseClass(unsigned sourceLocation, const Name *name)
  289. {
  290. BaseClass *baseClass = new BaseClass(translationUnit, sourceLocation, name);
  291. symbols.push_back(baseClass);
  292. return baseClass;
  293. }
  294. Block *newBlock(unsigned sourceLocation)
  295. {
  296. Block *block = new Block(translationUnit, sourceLocation);
  297. symbols.push_back(block);
  298. return block;
  299. }
  300. Class *newClass(unsigned sourceLocation, const Name *name)
  301. {
  302. Class *klass = new Class(translationUnit, sourceLocation, name);
  303. symbols.push_back(klass);
  304. return klass;
  305. }
  306. Namespace *newNamespace(unsigned sourceLocation, const Name *name)
  307. {
  308. Namespace *ns = new Namespace(translationUnit, sourceLocation, name);
  309. symbols.push_back(ns);
  310. return ns;
  311. }
  312. Template *newTemplate(unsigned sourceLocation, const Name *name)
  313. {
  314. Template *ns = new Template(translationUnit, sourceLocation, name);
  315. symbols.push_back(ns);
  316. return ns;
  317. }
  318. NamespaceAlias *newNamespaceAlias(unsigned sourceLocation, const Name *name)
  319. {
  320. NamespaceAlias *ns = new NamespaceAlias(translationUnit, sourceLocation, name);
  321. symbols.push_back(ns);
  322. return ns;
  323. }
  324. UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, const Name *name)
  325. {
  326. UsingNamespaceDirective *u = new UsingNamespaceDirective(translationUnit, sourceLocation, name);
  327. symbols.push_back(u);
  328. return u;
  329. }
  330. ForwardClassDeclaration *newForwardClassDeclaration(unsigned sourceLocation, const Name *name)
  331. {
  332. ForwardClassDeclaration *c = new ForwardClassDeclaration(translationUnit, sourceLocation, name);
  333. symbols.push_back(c);
  334. return c;
  335. }
  336. QtPropertyDeclaration *newQtPropertyDeclaration(unsigned sourceLocation, const Name *name)
  337. {
  338. QtPropertyDeclaration *d = new QtPropertyDeclaration(translationUnit, sourceLocation, name);
  339. symbols.push_back(d);
  340. return d;
  341. }
  342. QtEnum *newQtEnum(unsigned sourceLocation, const Name *name)
  343. {
  344. QtEnum *d = new QtEnum(translationUnit, sourceLocation, name);
  345. symbols.push_back(d);
  346. return d;
  347. }
  348. ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name)
  349. {
  350. ObjCBaseClass *c = new ObjCBaseClass(translationUnit, sourceLocation, name);
  351. symbols.push_back(c);
  352. return c;
  353. }
  354. ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, const Name *name)
  355. {
  356. ObjCBaseProtocol *p = new ObjCBaseProtocol(translationUnit, sourceLocation, name);
  357. symbols.push_back(p);
  358. return p;
  359. }
  360. ObjCClass *newObjCClass(unsigned sourceLocation, const Name *name)
  361. {
  362. ObjCClass *c = new ObjCClass(translationUnit, sourceLocation, name);
  363. symbols.push_back(c);
  364. return c;
  365. }
  366. ObjCForwardClassDeclaration *newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name)
  367. {
  368. ObjCForwardClassDeclaration *fwd = new ObjCForwardClassDeclaration(translationUnit, sourceLocation, name);
  369. symbols.push_back(fwd);
  370. return fwd;
  371. }
  372. ObjCProtocol *newObjCProtocol(unsigned sourceLocation, const Name *name)
  373. {
  374. ObjCProtocol *p = new ObjCProtocol(translationUnit, sourceLocation, name);
  375. symbols.push_back(p);
  376. return p;
  377. }
  378. ObjCForwardProtocolDeclaration *newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name)
  379. {
  380. ObjCForwardProtocolDeclaration *fwd = new ObjCForwardProtocolDeclaration(translationUnit, sourceLocation, name);
  381. symbols.push_back(fwd);
  382. return fwd;
  383. }
  384. ObjCMethod *newObjCMethod(unsigned sourceLocation, const Name *name)
  385. {
  386. ObjCMethod *method = new ObjCMethod(translationUnit, sourceLocation, name);
  387. symbols.push_back(method);
  388. return method;
  389. }
  390. ObjCPropertyDeclaration *newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name)
  391. {
  392. ObjCPropertyDeclaration *decl = new ObjCPropertyDeclaration(translationUnit, sourceLocation, name);
  393. symbols.push_back(decl);
  394. return decl;
  395. }
  396. Enum *newEnum(unsigned sourceLocation, const Name *name)
  397. {
  398. Enum *e = new Enum(translationUnit, sourceLocation, name);
  399. symbols.push_back(e);
  400. return e;
  401. }
  402. UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, const Name *name)
  403. {
  404. UsingDeclaration *u = new UsingDeclaration(translationUnit, sourceLocation, name);
  405. symbols.push_back(u);
  406. return u;
  407. }
  408. Control *control;
  409. TranslationUnit *translationUnit;
  410. DiagnosticClient *diagnosticClient;
  411. LiteralTable<Identifier> identifiers;
  412. LiteralTable<StringLiteral> stringLiterals;
  413. LiteralTable<NumericLiteral> numericLiterals;
  414. // ### replace std::map with lookup tables. ASAP!
  415. // names
  416. Table<AnonymousNameId> anonymousNameIds;
  417. Table<DestructorNameId> destructorNameIds;
  418. Table<OperatorNameId> operatorNameIds;
  419. Table<ConversionNameId> conversionNameIds;
  420. Table<TemplateNameId> templateNameIds;
  421. Table<QualifiedNameId> qualifiedNameIds;
  422. Table<SelectorNameId> selectorNameIds;
  423. // types
  424. VoidType voidType;
  425. Table<IntegerType> integerTypes;
  426. Table<FloatType> floatTypes;
  427. Table<PointerToMemberType> pointerToMemberTypes;
  428. Table<PointerType> pointerTypes;
  429. Table<ReferenceType> referenceTypes;
  430. Table<ArrayType> arrayTypes;
  431. Table<NamedType> namedTypes;
  432. // symbols
  433. std::vector<Symbol *> symbols;
  434. const Identifier *deprecatedId;
  435. const Identifier *unavailableId;
  436. // ObjC context keywords:
  437. const Identifier *objcGetterId;
  438. const Identifier *objcSetterId;
  439. const Identifier *objcReadwriteId;
  440. const Identifier *objcReadonlyId;
  441. const Identifier *objcAssignId;
  442. const Identifier *objcRetainId;
  443. const Identifier *objcCopyId;
  444. const Identifier *objcNonatomicId;
  445. const Identifier *cpp11Override;
  446. const Identifier *cpp11Final;
  447. TopLevelDeclarationProcessor *processor;
  448. };
  449. Control::Control()
  450. {
  451. d = new Data(this);
  452. d->deprecatedId = identifier("deprecated");
  453. d->unavailableId = identifier("unavailable");
  454. d->objcGetterId = identifier("getter");
  455. d->objcSetterId = identifier("setter");
  456. d->objcReadwriteId = identifier("readwrite");
  457. d->objcReadonlyId = identifier("readonly");
  458. d->objcAssignId = identifier("assign");
  459. d->objcRetainId = identifier("retain");
  460. d->objcCopyId = identifier("copy");
  461. d->objcNonatomicId = identifier("nonatomic");
  462. d->cpp11Override = identifier("override");
  463. d->cpp11Final = identifier("final");
  464. }
  465. Control::~Control()
  466. { delete d; }
  467. TranslationUnit *Control::translationUnit() const
  468. { return d->translationUnit; }
  469. TranslationUnit *Control::switchTranslationUnit(TranslationUnit *unit)
  470. {
  471. TranslationUnit *previousTranslationUnit = d->translationUnit;
  472. d->translationUnit = unit;
  473. return previousTranslationUnit;
  474. }
  475. DiagnosticClient *Control::diagnosticClient() const
  476. { return d->diagnosticClient; }
  477. void Control::setDiagnosticClient(DiagnosticClient *diagnosticClient)
  478. { d->diagnosticClient = diagnosticClient; }
  479. const AnonymousNameId *Control::anonymousNameId(unsigned classTokenIndex)
  480. { return d->findOrInsertAnonymousNameId(classTokenIndex); }
  481. const OperatorNameId *Control::findOperatorNameId(OperatorNameId::Kind operatorId) const
  482. {
  483. Table<OperatorNameId>::const_iterator i = d->operatorNameIds.find(operatorId);
  484. if (i == d->operatorNameIds.end())
  485. return 0;
  486. else
  487. return &*i;
  488. }
  489. const Identifier *Control::findIdentifier(const char *chars, unsigned size) const
  490. { return d->identifiers.findLiteral(chars, size); }
  491. const Identifier *Control::identifier(const char *chars, unsigned size)
  492. { return d->identifiers.findOrInsertLiteral(chars, size); }
  493. const Identifier *Control::identifier(const char *chars)
  494. {
  495. const unsigned length = unsigned(std::strlen(chars));
  496. return identifier(chars, length);
  497. }
  498. Control::IdentifierIterator Control::firstIdentifier() const
  499. { return d->identifiers.begin(); }
  500. Control::IdentifierIterator Control::lastIdentifier() const
  501. { return d->identifiers.end(); }
  502. Control::StringLiteralIterator Control::firstStringLiteral() const
  503. { return d->stringLiterals.begin(); }
  504. Control::StringLiteralIterator Control::lastStringLiteral() const
  505. { return d->stringLiterals.end(); }
  506. Control::NumericLiteralIterator Control::firstNumericLiteral() const
  507. { return d->numericLiterals.begin(); }
  508. Control::NumericLiteralIterator Control::lastNumericLiteral() const
  509. { return d->numericLiterals.end(); }
  510. const StringLiteral *Control::stringLiteral(const char *chars, unsigned size)
  511. { return d->stringLiterals.findOrInsertLiteral(chars, size); }
  512. const StringLiteral *Control::stringLiteral(const char *chars)
  513. {
  514. const unsigned length = unsigned(std::strlen(chars));
  515. return stringLiteral(chars, length);
  516. }
  517. const NumericLiteral *Control::numericLiteral(const char *chars, unsigned size)
  518. { return d->numericLiterals.findOrInsertLiteral(chars, size); }
  519. const NumericLiteral *Control::numericLiteral(const char *chars)
  520. {
  521. const unsigned length = unsigned(std::strlen(chars));
  522. return numericLiteral(chars, length);
  523. }
  524. const TemplateNameId *Control::templateNameId(const Identifier *id,
  525. bool isSpecialization,
  526. const FullySpecifiedType *const args,
  527. unsigned argv)
  528. {
  529. return d->findOrInsertTemplateNameId(id, isSpecialization, args, args + argv);
  530. }
  531. const DestructorNameId *Control::destructorNameId(const Name *name)
  532. { return d->findOrInsertDestructorNameId(name); }
  533. const OperatorNameId *Control::operatorNameId(OperatorNameId::Kind kind)
  534. { return d->findOrInsertOperatorNameId(kind); }
  535. const ConversionNameId *Control::conversionNameId(const FullySpecifiedType &type)
  536. { return d->findOrInsertConversionNameId(type); }
  537. const QualifiedNameId *Control::qualifiedNameId(const Name *base, const Name *name)
  538. {
  539. return d->findOrInsertQualifiedNameId(base, name);
  540. }
  541. const SelectorNameId *Control::selectorNameId(const Name *const *names,
  542. unsigned nameCount,
  543. bool hasArguments)
  544. {
  545. return d->findOrInsertSelectorNameId(names, names + nameCount, hasArguments);
  546. }
  547. VoidType *Control::voidType()
  548. { return &d->voidType; }
  549. IntegerType *Control::integerType(int kind)
  550. { return d->findOrInsertIntegerType(kind); }
  551. FloatType *Control::floatType(int kind)
  552. { return d->findOrInsertFloatType(kind); }
  553. PointerToMemberType *Control::pointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
  554. { return d->findOrInsertPointerToMemberType(memberName, elementType); }
  555. PointerType *Control::pointerType(const FullySpecifiedType &elementType)
  556. { return d->findOrInsertPointerType(elementType); }
  557. ReferenceType *Control::referenceType(const FullySpecifiedType &elementType, bool rvalueRef)
  558. { return d->findOrInsertReferenceType(elementType, rvalueRef); }
  559. ArrayType *Control::arrayType(const FullySpecifiedType &elementType, unsigned size)
  560. { return d->findOrInsertArrayType(elementType, size); }
  561. NamedType *Control::namedType(const Name *name)
  562. { return d->findOrInsertNamedType(name); }
  563. Argument *Control::newArgument(unsigned sourceLocation, const Name *name)
  564. { return d->newArgument(sourceLocation, name); }
  565. TypenameArgument *Control::newTypenameArgument(unsigned sourceLocation, const Name *name)
  566. { return d->newTypenameArgument(sourceLocation, name); }
  567. Function *Control::newFunction(unsigned sourceLocation, const Name *name)
  568. { return d->newFunction(sourceLocation, name); }
  569. Namespace *Control::newNamespace(unsigned sourceLocation, const Name *name)
  570. { return d->newNamespace(sourceLocation, name); }
  571. Template *Control::newTemplate(unsigned sourceLocation, const Name *name)
  572. { return d->newTemplate(sourceLocation, name); }
  573. NamespaceAlias *Control::newNamespaceAlias(unsigned sourceLocation, const Name *name)
  574. { return d->newNamespaceAlias(sourceLocation, name); }
  575. BaseClass *Control::newBaseClass(unsigned sourceLocation, const Name *name)
  576. { return d->newBaseClass(sourceLocation, name); }
  577. Class *Control::newClass(unsigned sourceLocation, const Name *name)
  578. { return d->newClass(sourceLocation, name); }
  579. Enum *Control::newEnum(unsigned sourceLocation, const Name *name)
  580. { return d->newEnum(sourceLocation, name); }
  581. Block *Control::newBlock(unsigned sourceLocation)
  582. { return d->newBlock(sourceLocation); }
  583. Declaration *Control::newDeclaration(unsigned sourceLocation, const Name *name)
  584. { return d->newDeclaration(sourceLocation, name); }
  585. EnumeratorDeclaration *Control::newEnumeratorDeclaration(unsigned sourceLocation, const Name *name)
  586. { return d->newEnumeratorDeclaration(sourceLocation, name); }
  587. UsingNamespaceDirective *Control::newUsingNamespaceDirective(unsigned sourceLocation,
  588. const Name *name)
  589. { return d->newUsingNamespaceDirective(sourceLocation, name); }
  590. UsingDeclaration *Control::newUsingDeclaration(unsigned sourceLocation, const Name *name)
  591. { return d->newUsingDeclaration(sourceLocation, name); }
  592. ForwardClassDeclaration *Control::newForwardClassDeclaration(unsigned sourceLocation,
  593. const Name *name)
  594. { return d->newForwardClassDeclaration(sourceLocation, name); }
  595. QtPropertyDeclaration *Control::newQtPropertyDeclaration(unsigned sourceLocation,
  596. const Name *name)
  597. { return d->newQtPropertyDeclaration(sourceLocation, name); }
  598. QtEnum *Control::newQtEnum(unsigned sourceLocation, const Name *name)
  599. { return d->newQtEnum(sourceLocation, name); }
  600. ObjCBaseClass *Control::newObjCBaseClass(unsigned sourceLocation, const Name *name)
  601. { return d->newObjCBaseClass(sourceLocation, name); }
  602. ObjCBaseProtocol *Control::newObjCBaseProtocol(unsigned sourceLocation, const Name *name)
  603. { return d->newObjCBaseProtocol(sourceLocation, name); }
  604. ObjCClass *Control::newObjCClass(unsigned sourceLocation, const Name *name)
  605. { return d->newObjCClass(sourceLocation, name); }
  606. ObjCForwardClassDeclaration *Control::newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name)
  607. { return d->newObjCForwardClassDeclaration(sourceLocation, name); }
  608. ObjCProtocol *Control::newObjCProtocol(unsigned sourceLocation, const Name *name)
  609. { return d->newObjCProtocol(sourceLocation, name); }
  610. ObjCForwardProtocolDeclaration *Control::newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name)
  611. { return d->newObjCForwardProtocolDeclaration(sourceLocation, name); }
  612. ObjCMethod *Control::newObjCMethod(unsigned sourceLocation, const Name *name)
  613. { return d->newObjCMethod(sourceLocation, name); }
  614. ObjCPropertyDeclaration *Control::newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name)
  615. { return d->newObjCPropertyDeclaration(sourceLocation, name); }
  616. const Identifier *Control::deprecatedId() const
  617. { return d->deprecatedId; }
  618. const Identifier *Control::unavailableId() const
  619. { return d->unavailableId; }
  620. const Identifier *Control::objcGetterId() const
  621. { return d->objcGetterId; }
  622. const Identifier *Control::objcSetterId() const
  623. { return d->objcSetterId; }
  624. const Identifier *Control::objcReadwriteId() const
  625. { return d->objcReadwriteId; }
  626. const Identifier *Control::objcReadonlyId() const
  627. { return d->objcReadonlyId; }
  628. const Identifier *Control::objcAssignId() const
  629. { return d->objcAssignId; }
  630. const Identifier *Control::objcRetainId() const
  631. { return d->objcRetainId; }
  632. const Identifier *Control::objcCopyId() const
  633. { return d->objcCopyId; }
  634. const Identifier *Control::objcNonatomicId() const
  635. { return d->objcNonatomicId; }
  636. const Identifier *Control::cpp11Override() const
  637. { return d->cpp11Override; }
  638. const Identifier *Control::cpp11Final() const
  639. { return d->cpp11Final; }
  640. Symbol **Control::firstSymbol() const
  641. {
  642. if (d->symbols.empty())
  643. return 0;
  644. return &*d->symbols.begin();
  645. }
  646. Symbol **Control::lastSymbol() const
  647. {
  648. if (d->symbols.empty())
  649. return 0;
  650. return &*d->symbols.begin() + d->symbols.size();
  651. }
  652. unsigned Control::symbolCount() const
  653. {
  654. return unsigned(d->symbols.size());
  655. }
  656. bool Control::hasSymbol(Symbol *symbol) const
  657. {
  658. return std::find(d->symbols.begin(), d->symbols.end(), symbol) != d->symbols.end();
  659. }
  660. void Control::squeeze()
  661. {
  662. d->numericLiterals.reset();
  663. }
  664. TopLevelDeclarationProcessor *Control::topLevelDeclarationProcessor() const
  665. {
  666. return d->processor;
  667. }
  668. void Control::setTopLevelDeclarationProcessor(CPlusPlus::TopLevelDeclarationProcessor *processor)
  669. {
  670. d->processor = processor;
  671. }
  672. void Control::addSymbol(Symbol *symbol)
  673. {
  674. d->symbols.push_back(symbol);
  675. }