Control.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_CONTROL_H
  21. #define CPLUSPLUS_CONTROL_H
  22. #include "CPlusPlusForwardDeclarations.h"
  23. #include "ASTfwd.h"
  24. #include "Names.h"
  25. namespace CPlusPlus {
  26. class CPLUSPLUS_EXPORT TopLevelDeclarationProcessor
  27. {
  28. public:
  29. virtual ~TopLevelDeclarationProcessor() {}
  30. virtual bool processDeclaration(DeclarationAST *ast) = 0;
  31. };
  32. class CPLUSPLUS_EXPORT Control
  33. {
  34. public:
  35. Control();
  36. ~Control();
  37. TranslationUnit *translationUnit() const;
  38. TranslationUnit *switchTranslationUnit(TranslationUnit *unit);
  39. TopLevelDeclarationProcessor *topLevelDeclarationProcessor() const;
  40. void setTopLevelDeclarationProcessor(TopLevelDeclarationProcessor *processor);
  41. DiagnosticClient *diagnosticClient() const;
  42. void setDiagnosticClient(DiagnosticClient *diagnosticClient);
  43. /// Returns the canonical anonymous name id
  44. const AnonymousNameId *anonymousNameId(unsigned classTokenIndex);
  45. /// Returns the canonical template name id.
  46. const TemplateNameId *templateNameId(const Identifier *id,
  47. bool isSpecialization,
  48. const FullySpecifiedType *const args = 0,
  49. unsigned argc = 0);
  50. /// Returns the canonical destructor name id.
  51. const DestructorNameId *destructorNameId(const Name *name);
  52. /// Returns the canonical operator name id.
  53. const OperatorNameId *operatorNameId(OperatorNameId::Kind operatorId);
  54. /// Returns the canonical conversion name id.
  55. const ConversionNameId *conversionNameId(const FullySpecifiedType &type);
  56. /// Returns the canonical qualified name id.
  57. const QualifiedNameId *qualifiedNameId(const Name *base, const Name *name);
  58. const SelectorNameId *selectorNameId(const Name *const *names,
  59. unsigned nameCount,
  60. bool hasArguments);
  61. /// Returns a Type object of type VoidType.
  62. VoidType *voidType();
  63. /// Returns a Type object of type IntegerType.
  64. IntegerType *integerType(int integerId);
  65. /// Returns a Type object of type FloatType.
  66. FloatType *floatType(int floatId);
  67. /// Returns a Type object of type PointertoMemberType.
  68. PointerToMemberType *pointerToMemberType(const Name *memberName,
  69. const FullySpecifiedType &elementType);
  70. /// Returns a Type object of type PointerType.
  71. PointerType *pointerType(const FullySpecifiedType &elementType);
  72. /// Returns a Type object of type ReferenceType.
  73. ReferenceType *referenceType(const FullySpecifiedType &elementType, bool rvalueRef);
  74. /// Retruns a Type object of type ArrayType.
  75. ArrayType *arrayType(const FullySpecifiedType &elementType, unsigned size = 0);
  76. /// Returns a Type object of type NamedType.
  77. NamedType *namedType(const Name *name);
  78. /// Creates a new Declaration symbol.
  79. Declaration *newDeclaration(unsigned sourceLocation, const Name *name);
  80. /// Creates a new EnumeratorDeclaration symbol.
  81. EnumeratorDeclaration *newEnumeratorDeclaration(unsigned sourceLocation, const Name *name);
  82. /// Creates a new Argument symbol.
  83. Argument *newArgument(unsigned sourceLocation, const Name *name = 0);
  84. /// Creates a new Argument symbol.
  85. TypenameArgument *newTypenameArgument(unsigned sourceLocation, const Name *name = 0);
  86. /// Creates a new Function symbol.
  87. Function *newFunction(unsigned sourceLocation, const Name *name = 0);
  88. /// Creates a new Namespace symbol.
  89. Namespace *newNamespace(unsigned sourceLocation, const Name *name = 0);
  90. /// Creates a new Template symbol.
  91. Template *newTemplate(unsigned sourceLocation, const Name *name = 0);
  92. /// Creates a new Namespace symbol.
  93. NamespaceAlias *newNamespaceAlias(unsigned sourceLocation, const Name *name = 0);
  94. /// Creates a new BaseClass symbol.
  95. BaseClass *newBaseClass(unsigned sourceLocation, const Name *name = 0);
  96. /// Creates a new Class symbol.
  97. Class *newClass(unsigned sourceLocation, const Name *name = 0);
  98. /// Creates a new Enum symbol.
  99. Enum *newEnum(unsigned sourceLocation, const Name *name = 0);
  100. /// Creates a new Block symbol.
  101. Block *newBlock(unsigned sourceLocation);
  102. /// Creates a new UsingNamespaceDirective symbol.
  103. UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, const Name *name = 0);
  104. /// Creates a new UsingDeclaration symbol.
  105. UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, const Name *name = 0);
  106. /// Creates a new ForwardClassDeclaration symbol.
  107. ForwardClassDeclaration *newForwardClassDeclaration(unsigned sourceLocation, const Name *name = 0);
  108. /// Creates a new QtPropertyDeclaration symbol.
  109. QtPropertyDeclaration *newQtPropertyDeclaration(unsigned sourceLocation, const Name *name = 0);
  110. /// Creates a new QtEnum symbol.
  111. QtEnum *newQtEnum(unsigned sourceLocation, const Name *name = 0);
  112. ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name);
  113. ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, const Name *name);
  114. /// Creates a new Objective-C class symbol.
  115. ObjCClass *newObjCClass(unsigned sourceLocation, const Name *name = 0);
  116. /// Creates a new Objective-C class forward declaration symbol.
  117. ObjCForwardClassDeclaration *newObjCForwardClassDeclaration(unsigned sourceLocation, const Name *name = 0);
  118. /// Creates a new Objective-C protocol symbol.
  119. ObjCProtocol *newObjCProtocol(unsigned sourceLocation, const Name *name = 0);
  120. /// Creates a new Objective-C protocol forward declaration symbol.
  121. ObjCForwardProtocolDeclaration *newObjCForwardProtocolDeclaration(unsigned sourceLocation, const Name *name = 0);
  122. /// Creates a new Objective-C method symbol.
  123. ObjCMethod *newObjCMethod(unsigned sourceLocation, const Name *name = 0);
  124. /// Creates a new Objective-C @property declaration symbol.
  125. ObjCPropertyDeclaration *newObjCPropertyDeclaration(unsigned sourceLocation, const Name *name);
  126. const Identifier *deprecatedId() const;
  127. const Identifier *unavailableId() const;
  128. // Objective-C specific context keywords.
  129. const Identifier *objcGetterId() const;
  130. const Identifier *objcSetterId() const;
  131. const Identifier *objcReadwriteId() const;
  132. const Identifier *objcReadonlyId() const;
  133. const Identifier *objcAssignId() const;
  134. const Identifier *objcRetainId() const;
  135. const Identifier *objcCopyId() const;
  136. const Identifier *objcNonatomicId() const;
  137. // C++11 context keywords
  138. const Identifier *cpp11Override() const;
  139. const Identifier *cpp11Final() const;
  140. const OperatorNameId *findOperatorNameId(OperatorNameId::Kind operatorId) const;
  141. const Identifier *findIdentifier(const char *chars, unsigned size) const;
  142. const Identifier *identifier(const char *chars, unsigned size);
  143. const Identifier *identifier(const char *chars);
  144. typedef const Identifier *const *IdentifierIterator;
  145. typedef const StringLiteral *const *StringLiteralIterator;
  146. typedef const NumericLiteral *const *NumericLiteralIterator;
  147. IdentifierIterator firstIdentifier() const;
  148. IdentifierIterator lastIdentifier() const;
  149. StringLiteralIterator firstStringLiteral() const;
  150. StringLiteralIterator lastStringLiteral() const;
  151. NumericLiteralIterator firstNumericLiteral() const;
  152. NumericLiteralIterator lastNumericLiteral() const;
  153. const StringLiteral *stringLiteral(const char *chars, unsigned size);
  154. const StringLiteral *stringLiteral(const char *chars);
  155. const NumericLiteral *numericLiteral(const char *chars, unsigned size);
  156. const NumericLiteral *numericLiteral(const char *chars);
  157. Symbol **firstSymbol() const;
  158. Symbol **lastSymbol() const;
  159. unsigned symbolCount() const;
  160. bool hasSymbol(Symbol *symbol) const;
  161. void addSymbol(Symbol *symbol);
  162. void squeeze();
  163. private:
  164. class Data;
  165. friend class Data;
  166. Data *d;
  167. };
  168. } // namespace CPlusPlus
  169. #endif // CPLUSPLUS_CONTROL_H