Names.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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_NAMES_H
  21. #define CPLUSPLUS_NAMES_H
  22. #include "CPlusPlusForwardDeclarations.h"
  23. #include "Name.h"
  24. #include "FullySpecifiedType.h"
  25. #include <vector>
  26. namespace CPlusPlus {
  27. class CPLUSPLUS_EXPORT QualifiedNameId: public Name
  28. {
  29. public:
  30. QualifiedNameId(const Name *base, const Name *name)
  31. : _base(base), _name(name) {}
  32. virtual ~QualifiedNameId();
  33. virtual const Identifier *identifier() const;
  34. const Name *base() const;
  35. const Name *name() const;
  36. virtual const QualifiedNameId *asQualifiedNameId() const
  37. { return this; }
  38. protected:
  39. virtual void accept0(NameVisitor *visitor) const;
  40. virtual bool match0(const Name *otherName, Matcher *matcher) const;
  41. private:
  42. const Name *_base;
  43. const Name *_name;
  44. };
  45. class CPLUSPLUS_EXPORT DestructorNameId: public Name
  46. {
  47. public:
  48. DestructorNameId(const Name *name);
  49. virtual ~DestructorNameId();
  50. virtual const Name *name() const;
  51. virtual const Identifier *identifier() const;
  52. virtual const DestructorNameId *asDestructorNameId() const
  53. { return this; }
  54. protected:
  55. virtual void accept0(NameVisitor *visitor) const;
  56. virtual bool match0(const Name *otherName, Matcher *matcher) const;
  57. private:
  58. const Name *_name;
  59. };
  60. class CPLUSPLUS_EXPORT TemplateNameId: public Name
  61. {
  62. public:
  63. template <typename Iterator>
  64. TemplateNameId(const Identifier *identifier, bool isSpecialization, Iterator first,
  65. Iterator last)
  66. : _identifier(identifier)
  67. , _templateArguments(first, last)
  68. , _isSpecialization(isSpecialization) {}
  69. virtual ~TemplateNameId();
  70. virtual const Identifier *identifier() const;
  71. // ### find a better name
  72. unsigned templateArgumentCount() const;
  73. const FullySpecifiedType &templateArgumentAt(unsigned index) const;
  74. virtual const TemplateNameId *asTemplateNameId() const
  75. { return this; }
  76. typedef std::vector<FullySpecifiedType>::const_iterator TemplateArgumentIterator;
  77. TemplateArgumentIterator firstTemplateArgument() const { return _templateArguments.begin(); }
  78. TemplateArgumentIterator lastTemplateArgument() const { return _templateArguments.end(); }
  79. bool isSpecialization() const { return _isSpecialization; }
  80. // this is temporary solution needed in ClassOrNamespace::nestedType
  81. // when we try to find correct specialization for instantiation
  82. void setIsSpecialization(bool isSpecialization) { _isSpecialization = isSpecialization; }
  83. // Comparator needed to distinguish between two different TemplateNameId(e.g.:used in std::map)
  84. struct Compare: std::binary_function<const TemplateNameId *, const TemplateNameId *, bool> {
  85. bool operator()(const TemplateNameId *name, const TemplateNameId *other) const;
  86. };
  87. protected:
  88. virtual void accept0(NameVisitor *visitor) const;
  89. virtual bool match0(const Name *otherName, Matcher *matcher) const;
  90. private:
  91. const Identifier *_identifier;
  92. std::vector<FullySpecifiedType> _templateArguments;
  93. // now TemplateNameId can be a specialization or an instantiation
  94. bool _isSpecialization;
  95. };
  96. class CPLUSPLUS_EXPORT OperatorNameId: public Name
  97. {
  98. public:
  99. /*
  100. new delete new[] delete[]
  101. + - * / % ^ & | ~
  102. ! = < > += -= *= /= %=
  103. ^= &= |= << >> >>= <<= == !=
  104. <= >= && || ++ -- , ->* ->
  105. () []
  106. */
  107. enum Kind {
  108. InvalidOp,
  109. NewOp,
  110. DeleteOp,
  111. NewArrayOp,
  112. DeleteArrayOp,
  113. PlusOp,
  114. MinusOp,
  115. StarOp,
  116. SlashOp,
  117. PercentOp,
  118. CaretOp,
  119. AmpOp,
  120. PipeOp,
  121. TildeOp,
  122. ExclaimOp,
  123. EqualOp,
  124. LessOp,
  125. GreaterOp,
  126. PlusEqualOp,
  127. MinusEqualOp,
  128. StarEqualOp,
  129. SlashEqualOp,
  130. PercentEqualOp,
  131. CaretEqualOp,
  132. AmpEqualOp,
  133. PipeEqualOp,
  134. LessLessOp,
  135. GreaterGreaterOp,
  136. LessLessEqualOp,
  137. GreaterGreaterEqualOp,
  138. EqualEqualOp,
  139. ExclaimEqualOp,
  140. LessEqualOp,
  141. GreaterEqualOp,
  142. AmpAmpOp,
  143. PipePipeOp,
  144. PlusPlusOp,
  145. MinusMinusOp,
  146. CommaOp,
  147. ArrowStarOp,
  148. ArrowOp,
  149. FunctionCallOp,
  150. ArrayAccessOp
  151. };
  152. public:
  153. OperatorNameId(Kind kind);
  154. virtual ~OperatorNameId();
  155. Kind kind() const;
  156. virtual const Identifier *identifier() const;
  157. virtual const OperatorNameId *asOperatorNameId() const
  158. { return this; }
  159. protected:
  160. virtual void accept0(NameVisitor *visitor) const;
  161. virtual bool match0(const Name *otherName, Matcher *matcher) const;
  162. private:
  163. Kind _kind;
  164. };
  165. class CPLUSPLUS_EXPORT ConversionNameId: public Name
  166. {
  167. public:
  168. ConversionNameId(const FullySpecifiedType &type);
  169. virtual ~ConversionNameId();
  170. FullySpecifiedType type() const;
  171. virtual const Identifier *identifier() const;
  172. virtual const ConversionNameId *asConversionNameId() const
  173. { return this; }
  174. protected:
  175. virtual void accept0(NameVisitor *visitor) const;
  176. virtual bool match0(const Name *otherName, Matcher *matcher) const;
  177. private:
  178. FullySpecifiedType _type;
  179. };
  180. class CPLUSPLUS_EXPORT SelectorNameId: public Name
  181. {
  182. public:
  183. template <typename Iterator>
  184. SelectorNameId(Iterator first, Iterator last, bool hasArguments)
  185. : _names(first, last), _hasArguments(hasArguments) {}
  186. virtual ~SelectorNameId();
  187. virtual const Identifier *identifier() const;
  188. unsigned nameCount() const;
  189. const Name *nameAt(unsigned index) const;
  190. bool hasArguments() const;
  191. virtual const SelectorNameId *asSelectorNameId() const
  192. { return this; }
  193. typedef std::vector<const Name *>::const_iterator NameIterator;
  194. NameIterator firstName() const { return _names.begin(); }
  195. NameIterator lastName() const { return _names.end(); }
  196. protected:
  197. virtual void accept0(NameVisitor *visitor) const;
  198. virtual bool match0(const Name *otherName, Matcher *matcher) const;
  199. private:
  200. std::vector<const Name *> _names;
  201. bool _hasArguments;
  202. };
  203. class CPLUSPLUS_EXPORT AnonymousNameId: public Name
  204. {
  205. public:
  206. AnonymousNameId(unsigned classTokenIndex);
  207. virtual ~AnonymousNameId();
  208. unsigned classTokenIndex() const;
  209. virtual const Identifier *identifier() const;
  210. virtual const AnonymousNameId *asAnonymousNameId() const
  211. { return this; }
  212. protected:
  213. virtual void accept0(NameVisitor *visitor) const;
  214. virtual bool match0(const Name *otherName, Matcher *matcher) const;
  215. private:
  216. unsigned _classTokenIndex;
  217. };
  218. } // namespace CPlusPlus
  219. #endif // CPLUSPLUS_NAMES_H