Symbol.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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_SYMBOL_H
  21. #define CPLUSPLUS_SYMBOL_H
  22. #include "CPlusPlusForwardDeclarations.h"
  23. namespace CPlusPlus {
  24. class CPLUSPLUS_EXPORT Symbol
  25. {
  26. Symbol(const Symbol &other);
  27. void operator =(const Symbol &other);
  28. public:
  29. /// Storage class specifier
  30. enum Storage {
  31. NoStorage = 0,
  32. Friend,
  33. Auto,
  34. Register,
  35. Static,
  36. Extern,
  37. Mutable,
  38. Typedef
  39. };
  40. /// Access specifier.
  41. enum Visibility {
  42. Public,
  43. Protected,
  44. Private,
  45. Package
  46. };
  47. public:
  48. /// Constructs a Symbol with the given source location, name and translation unit.
  49. Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  50. Symbol(Clone *clone, Subst *subst, Symbol *original);
  51. /// Destroy this Symbol.
  52. virtual ~Symbol();
  53. /// Returns this Symbol's source location.
  54. unsigned sourceLocation() const;
  55. /// \returns this Symbol's line number. The line number is 1-based.
  56. unsigned line() const;
  57. /// \returns this Symbol's column number. The column number is 1-based.
  58. unsigned column() const;
  59. /// Returns this Symbol's file name.
  60. const StringLiteral *fileId() const;
  61. /// Returns this Symbol's file name.
  62. const char *fileName() const;
  63. /// Returns this Symbol's file name length.
  64. unsigned fileNameLength() const;
  65. /// Returns this Symbol's name.
  66. const Name *name() const;
  67. /// Sets this Symbol's name.
  68. void setName(const Name *name); // ### dangerous
  69. /// Returns this Symbol's (optional) identifier
  70. const Identifier *identifier() const;
  71. /// Returns this Symbol's storage class specifier.
  72. int storage() const;
  73. /// Sets this Symbol's storage class specifier.
  74. void setStorage(int storage);
  75. /// Returns this Symbol's visibility.
  76. int visibility() const;
  77. /// Sets this Symbol's visibility.
  78. void setVisibility(int visibility);
  79. /// Returns the next chained Symbol.
  80. Symbol *next() const;
  81. /// Returns true if this Symbol has friend storage specifier.
  82. bool isFriend() const;
  83. /// Returns true if this Symbol has register storage specifier.
  84. bool isRegister() const;
  85. /// Returns true if this Symbol has static storage specifier.
  86. bool isStatic() const;
  87. /// Returns true if this Symbol has extern storage specifier.
  88. bool isExtern() const;
  89. /// Returns true if this Symbol has mutable storage specifier.
  90. bool isMutable() const;
  91. /// Returns true if this Symbol has typedef storage specifier.
  92. bool isTypedef() const;
  93. /// Returns true if this Symbol's visibility is public.
  94. bool isPublic() const;
  95. /// Returns true if this Symbol's visibility is protected.
  96. bool isProtected() const;
  97. /// Returns true if this Symbol's visibility is private.
  98. bool isPrivate() const;
  99. /// Returns true if this Symbol is a Scope.
  100. bool isScope() const;
  101. /// Returns true if this Symbol is an Enum.
  102. bool isEnum() const;
  103. /// Returns true if this Symbol is an Function.
  104. bool isFunction() const;
  105. /// Returns true if this Symbol is a Namespace.
  106. bool isNamespace() const;
  107. /// Returns true if this Symbol is a Template.
  108. bool isTemplate() const;
  109. /// Returns true if this Symbol is a Class.
  110. bool isClass() const;
  111. /// Returns true if this Symbol is a Block.
  112. bool isBlock() const;
  113. /// Returns true if this Symbol is a UsingNamespaceDirective.
  114. bool isUsingNamespaceDirective() const;
  115. /// Returns true if this Symbol is a UsingDeclaration.
  116. bool isUsingDeclaration() const;
  117. /// Returns true if this Symbol is a Declaration.
  118. bool isDeclaration() const;
  119. /// Returns true if this Symbol is an Argument.
  120. bool isArgument() const;
  121. /// Returns true if this Symbol is a Typename argument.
  122. bool isTypenameArgument() const;
  123. /// Returns true if this Symbol is a BaseClass.
  124. bool isBaseClass() const;
  125. /// Returns true if this Symbol is a ForwardClassDeclaration.
  126. bool isForwardClassDeclaration() const;
  127. /// Returns true if this Symbol is a QtPropertyDeclaration.
  128. bool isQtPropertyDeclaration() const;
  129. /// Returns true if this Symbol is a QtEnum.
  130. bool isQtEnum() const;
  131. bool isObjCBaseClass() const;
  132. bool isObjCBaseProtocol() const;
  133. /// Returns true if this Symbol is an Objective-C Class declaration.
  134. bool isObjCClass() const;
  135. /// Returns true if this Symbol is an Objective-C Class forward declaration.
  136. bool isObjCForwardClassDeclaration() const;
  137. /// Returns true if this Symbol is an Objective-C Protocol declaration.
  138. bool isObjCProtocol() const;
  139. /// Returns true if this Symbol is an Objective-C Protocol forward declaration.
  140. bool isObjCForwardProtocolDeclaration() const;
  141. /// Returns true if this Symbol is an Objective-C method declaration.
  142. bool isObjCMethod() const;
  143. /// Returns true if this Symbol is an Objective-C @property declaration.
  144. bool isObjCPropertyDeclaration() const;
  145. virtual const Scope *asScope() const { return 0; }
  146. virtual const Enum *asEnum() const { return 0; }
  147. virtual const Function *asFunction() const { return 0; }
  148. virtual const Namespace *asNamespace() const { return 0; }
  149. virtual const Template *asTemplate() const { return 0; }
  150. virtual const NamespaceAlias *asNamespaceAlias() const { return 0; }
  151. virtual const Class *asClass() const { return 0; }
  152. virtual const Block *asBlock() const { return 0; }
  153. virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const { return 0; }
  154. virtual const UsingDeclaration *asUsingDeclaration() const { return 0; }
  155. virtual const Declaration *asDeclaration() const { return 0; }
  156. virtual const Argument *asArgument() const { return 0; }
  157. virtual const TypenameArgument *asTypenameArgument() const { return 0; }
  158. virtual const BaseClass *asBaseClass() const { return 0; }
  159. virtual const ForwardClassDeclaration *asForwardClassDeclaration() const { return 0; }
  160. virtual const QtPropertyDeclaration *asQtPropertyDeclaration() const { return 0; }
  161. virtual const QtEnum *asQtEnum() const { return 0; }
  162. virtual const ObjCBaseClass *asObjCBaseClass() const { return 0; }
  163. virtual const ObjCBaseProtocol *asObjCBaseProtocol() const { return 0; }
  164. virtual const ObjCClass *asObjCClass() const { return 0; }
  165. virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() const { return 0; }
  166. virtual const ObjCProtocol *asObjCProtocol() const { return 0; }
  167. virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() const { return 0; }
  168. virtual const ObjCMethod *asObjCMethod() const { return 0; }
  169. virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const { return 0; }
  170. virtual Scope *asScope() { return 0; }
  171. virtual Enum *asEnum() { return 0; }
  172. virtual Function *asFunction() { return 0; }
  173. virtual Namespace *asNamespace() { return 0; }
  174. virtual Template *asTemplate() { return 0; }
  175. virtual NamespaceAlias *asNamespaceAlias() { return 0; }
  176. virtual Class *asClass() { return 0; }
  177. virtual Block *asBlock() { return 0; }
  178. virtual UsingNamespaceDirective *asUsingNamespaceDirective() { return 0; }
  179. virtual UsingDeclaration *asUsingDeclaration() { return 0; }
  180. virtual Declaration *asDeclaration() { return 0; }
  181. virtual Argument *asArgument() { return 0; }
  182. virtual TypenameArgument *asTypenameArgument() { return 0; }
  183. virtual BaseClass *asBaseClass() { return 0; }
  184. virtual ForwardClassDeclaration *asForwardClassDeclaration() { return 0; }
  185. virtual QtPropertyDeclaration *asQtPropertyDeclaration() { return 0; }
  186. virtual QtEnum *asQtEnum() { return 0; }
  187. virtual ObjCBaseClass *asObjCBaseClass() { return 0; }
  188. virtual ObjCBaseProtocol *asObjCBaseProtocol() { return 0; }
  189. virtual ObjCClass *asObjCClass() { return 0; }
  190. virtual ObjCForwardClassDeclaration *asObjCForwardClassDeclaration() { return 0; }
  191. virtual ObjCProtocol *asObjCProtocol() { return 0; }
  192. virtual ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclaration() { return 0; }
  193. virtual ObjCMethod *asObjCMethod() { return 0; }
  194. virtual ObjCPropertyDeclaration *asObjCPropertyDeclaration() { return 0; }
  195. /// Returns this Symbol's type.
  196. virtual FullySpecifiedType type() const = 0;
  197. /// Returns this Symbol's hash value.
  198. unsigned hashCode() const;
  199. /// Returns this Symbol's index.
  200. unsigned index() const;
  201. const Name *unqualifiedName() const;
  202. bool isGenerated() const;
  203. bool isDeprecated() const;
  204. void setDeprecated(bool isDeprecated);
  205. bool isUnavailable() const;
  206. void setUnavailable(bool isUnavailable);
  207. /// Returns this Symbol's eclosing scope.
  208. Scope *enclosingScope() const;
  209. /// Returns the eclosing namespace scope.
  210. Namespace *enclosingNamespace() const;
  211. /// Returns the eclosing template scope.
  212. Template *enclosingTemplate() const;
  213. /// Returns the enclosing class scope.
  214. Class *enclosingClass() const;
  215. /// Returns the enclosing enum scope.
  216. Enum *enclosingEnum() const;
  217. /// Returns the enclosing prototype scope.
  218. Function *enclosingFunction() const;
  219. /// Returns the enclosing Block scope.
  220. Block *enclosingBlock() const;
  221. void setEnclosingScope(Scope *enclosingScope); // ### make me private
  222. void resetEnclosingScope(); // ### make me private
  223. void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private
  224. void visitSymbol(SymbolVisitor *visitor);
  225. static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
  226. virtual void copy(Symbol *other);
  227. protected:
  228. virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
  229. private:
  230. const Name *_name;
  231. Scope *_enclosingScope;
  232. Symbol *_next;
  233. const StringLiteral *_fileId;
  234. unsigned _sourceLocation;
  235. unsigned _hashCode;
  236. int _storage;
  237. int _visibility;
  238. unsigned _index;
  239. unsigned _line;
  240. unsigned _column;
  241. bool _isGenerated: 1;
  242. bool _isDeprecated: 1;
  243. bool _isUnavailable: 1;
  244. class HashCode;
  245. friend class SymbolTable;
  246. };
  247. } // namespace CPlusPlus
  248. #endif // CPLUSPLUS_SYMBOL_H