Symbols.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  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. #ifndef CPLUSPLUS_SYMBOLS_H
  21. #define CPLUSPLUS_SYMBOLS_H
  22. #include "CPlusPlusForwardDeclarations.h"
  23. #include "Symbol.h"
  24. #include "Type.h"
  25. #include "FullySpecifiedType.h"
  26. #include "Scope.h"
  27. #include <vector>
  28. namespace CPlusPlus {
  29. class CPLUSPLUS_EXPORT UsingNamespaceDirective: public Symbol
  30. {
  31. public:
  32. UsingNamespaceDirective(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  33. UsingNamespaceDirective(Clone *clone, Subst *subst, UsingNamespaceDirective *original);
  34. virtual ~UsingNamespaceDirective();
  35. // Symbol's interface
  36. virtual FullySpecifiedType type() const;
  37. virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const
  38. { return this; }
  39. virtual UsingNamespaceDirective *asUsingNamespaceDirective()
  40. { return this; }
  41. protected:
  42. virtual void visitSymbol0(SymbolVisitor *visitor);
  43. };
  44. class CPLUSPLUS_EXPORT UsingDeclaration: public Symbol
  45. {
  46. public:
  47. UsingDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  48. UsingDeclaration(Clone *clone, Subst *subst, UsingDeclaration *original);
  49. virtual ~UsingDeclaration();
  50. // Symbol's interface
  51. virtual FullySpecifiedType type() const;
  52. virtual const UsingDeclaration *asUsingDeclaration() const
  53. { return this; }
  54. virtual UsingDeclaration *asUsingDeclaration()
  55. { return this; }
  56. protected:
  57. virtual void visitSymbol0(SymbolVisitor *visitor);
  58. };
  59. class CPLUSPLUS_EXPORT NamespaceAlias: public Symbol
  60. {
  61. public:
  62. NamespaceAlias(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  63. NamespaceAlias(Clone *clone, Subst *subst, NamespaceAlias *original);
  64. virtual ~NamespaceAlias();
  65. const Name *namespaceName() const;
  66. void setNamespaceName(const Name *namespaceName);
  67. // Symbol's interface
  68. virtual FullySpecifiedType type() const;
  69. virtual const NamespaceAlias *asNamespaceAlias() const
  70. { return this; }
  71. virtual NamespaceAlias *asNamespaceAlias()
  72. { return this; }
  73. protected:
  74. virtual void visitSymbol0(SymbolVisitor *visitor);
  75. private:
  76. const Name *_namespaceName;
  77. };
  78. class CPLUSPLUS_EXPORT Declaration: public Symbol
  79. {
  80. public:
  81. Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  82. Declaration(Clone *clone, Subst *subst, Declaration *original);
  83. virtual ~Declaration();
  84. void setType(const FullySpecifiedType &type);
  85. void setInitializer(StringLiteral const* initializer);
  86. // Symbol's interface
  87. virtual FullySpecifiedType type() const;
  88. const StringLiteral *getInitializer() const;
  89. virtual const Declaration *asDeclaration() const
  90. { return this; }
  91. virtual Declaration *asDeclaration()
  92. { return this; }
  93. virtual EnumeratorDeclaration *asEnumeratorDeclarator()
  94. { return 0; }
  95. virtual const EnumeratorDeclaration *asEnumeratorDeclarator() const
  96. { return 0; }
  97. protected:
  98. virtual void visitSymbol0(SymbolVisitor *visitor);
  99. private:
  100. FullySpecifiedType _type;
  101. const StringLiteral *_initializer;
  102. };
  103. class CPLUSPLUS_EXPORT EnumeratorDeclaration: public Declaration
  104. {
  105. public:
  106. EnumeratorDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  107. virtual ~EnumeratorDeclaration();
  108. const StringLiteral *constantValue() const;
  109. void setConstantValue(const StringLiteral *constantValue);
  110. virtual EnumeratorDeclaration *asEnumeratorDeclarator()
  111. { return this; }
  112. virtual const EnumeratorDeclaration *asEnumeratorDeclarator() const
  113. { return this; }
  114. private:
  115. const StringLiteral *_constantValue;
  116. };
  117. class CPLUSPLUS_EXPORT Argument: public Symbol
  118. {
  119. public:
  120. Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  121. Argument(Clone *clone, Subst *subst, Argument *original);
  122. virtual ~Argument();
  123. void setType(const FullySpecifiedType &type);
  124. bool hasInitializer() const;
  125. const StringLiteral *initializer() const;
  126. void setInitializer(const StringLiteral *initializer);
  127. // Symbol's interface
  128. virtual FullySpecifiedType type() const;
  129. virtual const Argument *asArgument() const
  130. { return this; }
  131. virtual Argument *asArgument()
  132. { return this; }
  133. protected:
  134. virtual void visitSymbol0(SymbolVisitor *visitor);
  135. private:
  136. const StringLiteral *_initializer;
  137. FullySpecifiedType _type;
  138. };
  139. class CPLUSPLUS_EXPORT TypenameArgument: public Symbol
  140. {
  141. public:
  142. TypenameArgument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  143. TypenameArgument(Clone *clone, Subst *subst, TypenameArgument *original);
  144. virtual ~TypenameArgument();
  145. void setType(const FullySpecifiedType &type);
  146. // Symbol's interface
  147. virtual FullySpecifiedType type() const;
  148. virtual const TypenameArgument *asTypenameArgument() const
  149. { return this; }
  150. virtual TypenameArgument *asTypenameArgument()
  151. { return this; }
  152. protected:
  153. virtual void visitSymbol0(SymbolVisitor *visitor);
  154. private:
  155. FullySpecifiedType _type;
  156. };
  157. class CPLUSPLUS_EXPORT Block: public Scope
  158. {
  159. public:
  160. Block(TranslationUnit *translationUnit, unsigned sourceLocation);
  161. Block(Clone *clone, Subst *subst, Block *original);
  162. virtual ~Block();
  163. // Symbol's interface
  164. virtual FullySpecifiedType type() const;
  165. virtual const Block *asBlock() const
  166. { return this; }
  167. virtual Block *asBlock()
  168. { return this; }
  169. protected:
  170. virtual void visitSymbol0(SymbolVisitor *visitor);
  171. };
  172. class CPLUSPLUS_EXPORT ForwardClassDeclaration: public Symbol, public Type
  173. {
  174. public:
  175. ForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  176. ForwardClassDeclaration(Clone *clone, Subst *subst, ForwardClassDeclaration *original);
  177. virtual ~ForwardClassDeclaration();
  178. // Symbol's interface
  179. virtual FullySpecifiedType type() const;
  180. virtual const ForwardClassDeclaration *asForwardClassDeclaration() const
  181. { return this; }
  182. virtual ForwardClassDeclaration *asForwardClassDeclaration()
  183. { return this; }
  184. // Type's interface
  185. virtual const ForwardClassDeclaration *asForwardClassDeclarationType() const
  186. { return this; }
  187. virtual ForwardClassDeclaration *asForwardClassDeclarationType()
  188. { return this; }
  189. protected:
  190. virtual void visitSymbol0(SymbolVisitor *visitor);
  191. virtual void accept0(TypeVisitor *visitor);
  192. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  193. };
  194. class CPLUSPLUS_EXPORT Enum: public Scope, public Type
  195. {
  196. public:
  197. Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  198. Enum(Clone *clone, Subst *subst, Enum *original);
  199. virtual ~Enum();
  200. bool isScoped() const;
  201. void setScoped(bool scoped);
  202. // Symbol's interface
  203. virtual FullySpecifiedType type() const;
  204. virtual const Enum *asEnum() const
  205. { return this; }
  206. virtual Enum *asEnum()
  207. { return this; }
  208. // Type's interface
  209. virtual const Enum *asEnumType() const
  210. { return this; }
  211. virtual Enum *asEnumType()
  212. { return this; }
  213. protected:
  214. virtual void visitSymbol0(SymbolVisitor *visitor);
  215. virtual void accept0(TypeVisitor *visitor);
  216. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  217. private:
  218. bool _isScoped;
  219. };
  220. class CPLUSPLUS_EXPORT Function: public Scope, public Type
  221. {
  222. public:
  223. enum MethodKey {
  224. NormalMethod,
  225. SlotMethod,
  226. SignalMethod,
  227. InvokableMethod
  228. };
  229. public:
  230. Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  231. Function(Clone *clone, Subst *subst, Function *original);
  232. virtual ~Function();
  233. bool isNormal() const;
  234. bool isSignal() const;
  235. bool isSlot() const;
  236. bool isInvokable() const;
  237. int methodKey() const;
  238. void setMethodKey(int key);
  239. FullySpecifiedType returnType() const;
  240. void setReturnType(const FullySpecifiedType &returnType);
  241. /** Convenience function that returns whether the function returns something (including void). */
  242. bool hasReturnType() const;
  243. unsigned argumentCount() const;
  244. Symbol *argumentAt(unsigned index) const;
  245. /** Convenience function that returns whether the function receives any arguments. */
  246. bool hasArguments() const;
  247. unsigned minimumArgumentCount() const;
  248. bool isVirtual() const;
  249. void setVirtual(bool isVirtual);
  250. bool isOverride() const;
  251. void setOverride(bool isOverride);
  252. bool isFinal() const;
  253. void setFinal(bool isFinal);
  254. bool isVariadic() const;
  255. void setVariadic(bool isVariadic);
  256. bool isConst() const;
  257. void setConst(bool isConst);
  258. bool isVolatile() const;
  259. void setVolatile(bool isVolatile);
  260. bool isPureVirtual() const;
  261. void setPureVirtual(bool isPureVirtual);
  262. bool isSignatureEqualTo(const Function *other, Matcher *matcher = 0) const;
  263. bool isAmbiguous() const; // internal
  264. void setAmbiguous(bool isAmbiguous); // internal
  265. bool maybeValidPrototype(unsigned actualArgumentCount) const;
  266. // Symbol's interface
  267. virtual FullySpecifiedType type() const;
  268. virtual const Function *asFunction() const
  269. { return this; }
  270. virtual Function *asFunction()
  271. { return this; }
  272. // Type's interface
  273. virtual const Function *asFunctionType() const
  274. { return this; }
  275. virtual Function *asFunctionType()
  276. { return this; }
  277. protected:
  278. virtual void visitSymbol0(SymbolVisitor *visitor);
  279. virtual void accept0(TypeVisitor *visitor);
  280. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  281. private:
  282. FullySpecifiedType _returnType;
  283. struct Flags {
  284. unsigned _isVirtual: 1;
  285. unsigned _isOverride: 1;
  286. unsigned _isFinal: 1;
  287. unsigned _isVariadic: 1;
  288. unsigned _isPureVirtual: 1;
  289. unsigned _isConst: 1;
  290. unsigned _isVolatile: 1;
  291. unsigned _isAmbiguous: 1;
  292. unsigned _methodKey: 3;
  293. };
  294. union {
  295. unsigned _flags;
  296. Flags f;
  297. };
  298. };
  299. class CPLUSPLUS_EXPORT Template: public Scope, public Type
  300. {
  301. public:
  302. Template(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  303. Template(Clone *clone, Subst *subst, Template *original);
  304. virtual ~Template();
  305. unsigned templateParameterCount() const;
  306. Symbol *templateParameterAt(unsigned index) const;
  307. Symbol *declaration() const;
  308. // Symbol's interface
  309. virtual FullySpecifiedType type() const;
  310. virtual const Template *asTemplate() const
  311. { return this; }
  312. virtual Template *asTemplate()
  313. { return this; }
  314. // Type's interface
  315. virtual const Template *asTemplateType() const
  316. { return this; }
  317. virtual Template *asTemplateType()
  318. { return this; }
  319. protected:
  320. virtual void visitSymbol0(SymbolVisitor *visitor);
  321. virtual void accept0(TypeVisitor *visitor);
  322. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  323. };
  324. class CPLUSPLUS_EXPORT Namespace: public Scope, public Type
  325. {
  326. public:
  327. Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  328. Namespace(Clone *clone, Subst *subst, Namespace *original);
  329. virtual ~Namespace();
  330. // Symbol's interface
  331. virtual FullySpecifiedType type() const;
  332. virtual const Namespace *asNamespace() const
  333. { return this; }
  334. virtual Namespace *asNamespace()
  335. { return this; }
  336. // Type's interface
  337. virtual const Namespace *asNamespaceType() const
  338. { return this; }
  339. virtual Namespace *asNamespaceType()
  340. { return this; }
  341. bool isInline() const
  342. { return _isInline; }
  343. void setInline(bool onoff)
  344. { _isInline = onoff; }
  345. protected:
  346. virtual void visitSymbol0(SymbolVisitor *visitor);
  347. virtual void accept0(TypeVisitor *visitor);
  348. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  349. private:
  350. bool _isInline;
  351. };
  352. class CPLUSPLUS_EXPORT BaseClass: public Symbol
  353. {
  354. public:
  355. BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  356. BaseClass(Clone *clone, Subst *subst, BaseClass *original);
  357. virtual ~BaseClass();
  358. bool isVirtual() const;
  359. void setVirtual(bool isVirtual);
  360. // Symbol's interface
  361. virtual FullySpecifiedType type() const;
  362. void setType(const FullySpecifiedType &type);
  363. virtual const BaseClass *asBaseClass() const
  364. { return this; }
  365. virtual BaseClass *asBaseClass()
  366. { return this; }
  367. protected:
  368. virtual void visitSymbol0(SymbolVisitor *visitor);
  369. private:
  370. bool _isVirtual;
  371. FullySpecifiedType _type;
  372. };
  373. class CPLUSPLUS_EXPORT Class: public Scope, public Type
  374. {
  375. public:
  376. Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  377. Class(Clone *clone, Subst *subst, Class *original);
  378. virtual ~Class();
  379. enum Key {
  380. ClassKey,
  381. StructKey,
  382. UnionKey
  383. };
  384. bool isClass() const;
  385. bool isStruct() const;
  386. bool isUnion() const;
  387. Key classKey() const;
  388. void setClassKey(Key key);
  389. unsigned baseClassCount() const;
  390. BaseClass *baseClassAt(unsigned index) const;
  391. void addBaseClass(BaseClass *baseClass);
  392. // Symbol's interface
  393. virtual FullySpecifiedType type() const;
  394. virtual const Class *asClass() const
  395. { return this; }
  396. virtual Class *asClass()
  397. { return this; }
  398. // Type's interface
  399. virtual const Class *asClassType() const
  400. { return this; }
  401. virtual Class *asClassType()
  402. { return this; }
  403. protected:
  404. virtual void visitSymbol0(SymbolVisitor *visitor);
  405. virtual void accept0(TypeVisitor *visitor);
  406. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  407. private:
  408. Key _key;
  409. std::vector<BaseClass *> _baseClasses;
  410. };
  411. class CPLUSPLUS_EXPORT QtPropertyDeclaration: public Symbol
  412. {
  413. public:
  414. enum Flag {
  415. NoFlags = 0,
  416. ReadFunction = 1 << 0,
  417. WriteFunction = 1 << 1,
  418. MemberVariable = 1 << 2,
  419. ResetFunction = 1 << 3,
  420. NotifyFunction = 1 << 4,
  421. DesignableFlag = 1 << 5,
  422. DesignableFunction = 1 << 6,
  423. ScriptableFlag = 1 << 7,
  424. ScriptableFunction = 1 << 8,
  425. StoredFlag = 1 << 9,
  426. StoredFunction = 1 << 10,
  427. UserFlag = 1 << 11,
  428. UserFunction = 1 << 12,
  429. ConstantFlag = 1 << 13,
  430. FinalFlag = 1 << 14
  431. };
  432. public:
  433. QtPropertyDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  434. QtPropertyDeclaration(Clone *clone, Subst *subst, QtPropertyDeclaration *original);
  435. virtual ~QtPropertyDeclaration();
  436. void setType(const FullySpecifiedType &type);
  437. void setFlags(int flags);
  438. int flags() const;
  439. // Symbol's interface
  440. virtual FullySpecifiedType type() const;
  441. virtual const QtPropertyDeclaration *asQtPropertyDeclaration() const
  442. { return this; }
  443. virtual QtPropertyDeclaration *asQtPropertyDeclaration()
  444. { return this; }
  445. protected:
  446. virtual void visitSymbol0(SymbolVisitor *visitor);
  447. private:
  448. FullySpecifiedType _type;
  449. int _flags;
  450. };
  451. class CPLUSPLUS_EXPORT QtEnum: public Symbol
  452. {
  453. public:
  454. QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  455. QtEnum(Clone *clone, Subst *subst, QtEnum *original);
  456. virtual ~QtEnum();
  457. // Symbol's interface
  458. virtual FullySpecifiedType type() const;
  459. virtual const QtEnum *asQtEnum() const
  460. { return this; }
  461. virtual QtEnum *asQtEnum()
  462. { return this; }
  463. protected:
  464. virtual void visitSymbol0(SymbolVisitor *visitor);
  465. };
  466. class CPLUSPLUS_EXPORT ObjCBaseClass: public Symbol
  467. {
  468. public:
  469. ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  470. ObjCBaseClass(Clone *clone, Subst *subst, ObjCBaseClass *original);
  471. virtual ~ObjCBaseClass();
  472. // Symbol's interface
  473. virtual FullySpecifiedType type() const;
  474. virtual const ObjCBaseClass *asObjCBaseClass() const
  475. { return this; }
  476. virtual ObjCBaseClass *asObjCBaseClass()
  477. { return this; }
  478. protected:
  479. virtual void visitSymbol0(SymbolVisitor *visitor);
  480. };
  481. class CPLUSPLUS_EXPORT ObjCBaseProtocol: public Symbol
  482. {
  483. public:
  484. ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  485. ObjCBaseProtocol(Clone *clone, Subst *subst, ObjCBaseProtocol *original);
  486. virtual ~ObjCBaseProtocol();
  487. // Symbol's interface
  488. virtual FullySpecifiedType type() const;
  489. virtual const ObjCBaseProtocol *asObjCBaseProtocol() const
  490. { return this; }
  491. virtual ObjCBaseProtocol *asObjCBaseProtocol()
  492. { return this; }
  493. protected:
  494. virtual void visitSymbol0(SymbolVisitor *visitor);
  495. };
  496. class CPLUSPLUS_EXPORT ObjCForwardProtocolDeclaration: public Symbol, public Type
  497. {
  498. public:
  499. ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  500. ObjCForwardProtocolDeclaration(Clone *clone, Subst *subst, ObjCForwardProtocolDeclaration *original);
  501. virtual ~ObjCForwardProtocolDeclaration();
  502. // Symbol's interface
  503. virtual FullySpecifiedType type() const;
  504. virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const
  505. { return this; }
  506. virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration()
  507. { return this; }
  508. // Type's interface
  509. virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType() const
  510. { return this; }
  511. virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType()
  512. { return this; }
  513. protected:
  514. virtual void visitSymbol0(SymbolVisitor *visitor);
  515. virtual void accept0(TypeVisitor *visitor);
  516. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  517. };
  518. class CPLUSPLUS_EXPORT ObjCProtocol: public Scope, public Type
  519. {
  520. public:
  521. ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  522. ObjCProtocol(Clone *clone, Subst *subst, ObjCProtocol *original);
  523. virtual ~ObjCProtocol();
  524. unsigned protocolCount() const;
  525. ObjCBaseProtocol *protocolAt(unsigned index) const;
  526. void addProtocol(ObjCBaseProtocol *protocol);
  527. // Symbol's interface
  528. virtual FullySpecifiedType type() const;
  529. virtual const ObjCProtocol *asObjCProtocol() const
  530. { return this; }
  531. virtual ObjCProtocol *asObjCProtocol()
  532. { return this; }
  533. // Type's interface
  534. virtual const ObjCProtocol *asObjCProtocolType() const
  535. { return this; }
  536. virtual ObjCProtocol *asObjCProtocolType()
  537. { return this; }
  538. protected:
  539. virtual void visitSymbol0(SymbolVisitor *visitor);
  540. virtual void accept0(TypeVisitor *visitor);
  541. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  542. private:
  543. std::vector<ObjCBaseProtocol *> _protocols;
  544. };
  545. class CPLUSPLUS_EXPORT ObjCForwardClassDeclaration: public Symbol, public Type
  546. {
  547. public:
  548. ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  549. ObjCForwardClassDeclaration(Clone *clone, Subst *subst, ObjCForwardClassDeclaration *original);
  550. virtual ~ObjCForwardClassDeclaration();
  551. // Symbol's interface
  552. virtual FullySpecifiedType type() const;
  553. virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const
  554. { return this; }
  555. virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration()
  556. { return this; }
  557. // Type's interface
  558. virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType() const
  559. { return this; }
  560. virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType()
  561. { return this; }
  562. protected:
  563. virtual void visitSymbol0(SymbolVisitor *visitor);
  564. virtual void accept0(TypeVisitor *visitor);
  565. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  566. };
  567. class CPLUSPLUS_EXPORT ObjCClass: public Scope, public Type
  568. {
  569. public:
  570. ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  571. ObjCClass(Clone *clone, Subst *subst, ObjCClass *original);
  572. virtual ~ObjCClass();
  573. bool isInterface() const;
  574. void setInterface(bool isInterface);
  575. bool isCategory() const;
  576. const Name *categoryName() const;
  577. void setCategoryName(const Name *categoryName);
  578. ObjCBaseClass *baseClass() const;
  579. void setBaseClass(ObjCBaseClass *baseClass);
  580. unsigned protocolCount() const;
  581. ObjCBaseProtocol *protocolAt(unsigned index) const;
  582. void addProtocol(ObjCBaseProtocol *protocol);
  583. // Symbol's interface
  584. virtual FullySpecifiedType type() const;
  585. virtual const ObjCClass *asObjCClass() const
  586. { return this; }
  587. virtual ObjCClass *asObjCClass()
  588. { return this; }
  589. // Type's interface
  590. virtual const ObjCClass *asObjCClassType() const
  591. { return this; }
  592. virtual ObjCClass *asObjCClassType()
  593. { return this; }
  594. protected:
  595. virtual void visitSymbol0(SymbolVisitor *visitor);
  596. virtual void accept0(TypeVisitor *visitor);
  597. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  598. private:
  599. const Name *_categoryName;
  600. ObjCBaseClass * _baseClass;
  601. std::vector<ObjCBaseProtocol *> _protocols;
  602. bool _isInterface;
  603. };
  604. class CPLUSPLUS_EXPORT ObjCMethod: public Scope, public Type
  605. {
  606. public:
  607. ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  608. ObjCMethod(Clone *clone, Subst *subst, ObjCMethod *original);
  609. virtual ~ObjCMethod();
  610. FullySpecifiedType returnType() const;
  611. void setReturnType(const FullySpecifiedType &returnType);
  612. /** Convenience function that returns whether the function returns something (including void). */
  613. bool hasReturnType() const;
  614. unsigned argumentCount() const;
  615. Symbol *argumentAt(unsigned index) const;
  616. /** Convenience function that returns whether the function receives any arguments. */
  617. bool hasArguments() const;
  618. bool isVariadic() const;
  619. void setVariadic(bool isVariadic);
  620. // Symbol's interface
  621. virtual FullySpecifiedType type() const;
  622. virtual const ObjCMethod *asObjCMethod() const
  623. { return this; }
  624. virtual ObjCMethod *asObjCMethod()
  625. { return this; }
  626. // Type's interface
  627. virtual const ObjCMethod *asObjCMethodType() const
  628. { return this; }
  629. virtual ObjCMethod *asObjCMethodType()
  630. { return this; }
  631. protected:
  632. virtual void visitSymbol0(SymbolVisitor *visitor);
  633. virtual void accept0(TypeVisitor *visitor);
  634. virtual bool match0(const Type *otherType, Matcher *matcher) const;
  635. private:
  636. FullySpecifiedType _returnType;
  637. struct Flags {
  638. unsigned _isVariadic: 1;
  639. };
  640. union {
  641. unsigned _flags;
  642. Flags f;
  643. };
  644. };
  645. class CPLUSPLUS_EXPORT ObjCPropertyDeclaration: public Symbol
  646. {
  647. public:
  648. enum PropertyAttributes {
  649. None = 0,
  650. Assign = 1 << 0,
  651. Retain = 1 << 1,
  652. Copy = 1 << 2,
  653. ReadOnly = 1 << 3,
  654. ReadWrite = 1 << 4,
  655. Getter = 1 << 5,
  656. Setter = 1 << 6,
  657. NonAtomic = 1 << 7,
  658. WritabilityMask = ReadOnly | ReadWrite,
  659. SetterSemanticsMask = Assign | Retain | Copy
  660. };
  661. public:
  662. ObjCPropertyDeclaration(TranslationUnit *translationUnit,
  663. unsigned sourceLocation,
  664. const Name *name);
  665. ObjCPropertyDeclaration(Clone *clone, Subst *subst, ObjCPropertyDeclaration *original);
  666. virtual ~ObjCPropertyDeclaration();
  667. bool hasAttribute(int attribute) const;
  668. void setAttributes(int attributes);
  669. bool hasGetter() const;
  670. bool hasSetter() const;
  671. const Name *getterName() const;
  672. void setGetterName(const Name *getterName);
  673. const Name *setterName() const;
  674. void setSetterName(const Name *setterName);
  675. void setType(const FullySpecifiedType &type);
  676. // Symbol's interface
  677. virtual FullySpecifiedType type() const;
  678. virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const
  679. { return this; }
  680. virtual ObjCPropertyDeclaration *asObjCPropertyDeclaration()
  681. { return this; }
  682. protected:
  683. virtual void visitSymbol0(SymbolVisitor *visitor);
  684. private:
  685. const Name *_getterName;
  686. const Name *_setterName;
  687. FullySpecifiedType _type;
  688. int _propertyAttributes;
  689. };
  690. } // namespace CPlusPlus
  691. #endif // CPLUSPLUS_SYMBOLS_H