ASTConsumer.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the ASTConsumer class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_AST_ASTCONSUMER_H
  18. #define LLVM_CLANG_AST_ASTCONSUMER_H
  19. namespace clang {
  20. class ASTContext;
  21. class CXXMethodDecl;
  22. class CXXRecordDecl;
  23. class Decl;
  24. class DeclGroupRef;
  25. class ASTMutationListener;
  26. class ASTDeserializationListener; // layering violation because void* is ugly
  27. class SemaConsumer; // layering violation required for safe SemaConsumer
  28. class TagDecl;
  29. class VarDecl;
  30. class FunctionDecl;
  31. class ImportDecl;
  32. /// ASTConsumer - This is an abstract interface that should be implemented by
  33. /// clients that read ASTs. This abstraction layer allows the client to be
  34. /// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
  35. class ASTConsumer {
  36. /// Whether this AST consumer also requires information about
  37. /// semantic analysis.
  38. bool SemaConsumer;
  39. friend class SemaConsumer;
  40. public:
  41. ASTConsumer() : SemaConsumer(false) { }
  42. virtual ~ASTConsumer() {}
  43. /// Initialize - This is called to initialize the consumer, providing the
  44. /// ASTContext.
  45. virtual void Initialize(ASTContext &Context) {}
  46. /// HandleTopLevelDecl - Handle the specified top-level declaration. This is
  47. /// called by the parser to process every top-level Decl*.
  48. ///
  49. /// \returns true to continue parsing, or false to abort parsing.
  50. virtual bool HandleTopLevelDecl(DeclGroupRef D);
  51. /// This callback is invoked each time an inline (method or friend)
  52. /// function definition in a class is completed.
  53. virtual void HandleInlineFunctionDefinition(FunctionDecl *D) {}
  54. /// HandleInterestingDecl - Handle the specified interesting declaration. This
  55. /// is called by the AST reader when deserializing things that might interest
  56. /// the consumer. The default implementation forwards to HandleTopLevelDecl.
  57. virtual void HandleInterestingDecl(DeclGroupRef D);
  58. /// HandleTranslationUnit - This method is called when the ASTs for entire
  59. /// translation unit have been parsed.
  60. virtual void HandleTranslationUnit(ASTContext &Ctx) {}
  61. /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
  62. /// (e.g. struct, union, enum, class) is completed. This allows the client to
  63. /// hack on the type, which can occur at any point in the file (because these
  64. /// can be defined in declspecs).
  65. virtual void HandleTagDeclDefinition(TagDecl *D) {}
  66. /// This callback is invoked the first time each TagDecl is required to
  67. /// be complete.
  68. virtual void HandleTagDeclRequiredDefinition(const TagDecl *D) {}
  69. /// Invoked when a function is implicitly instantiated.
  70. /// Note that at this point point it does not have a body, its body is
  71. /// instantiated at the end of the translation unit and passed to
  72. /// HandleTopLevelDecl.
  73. virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {}
  74. /// Handle the specified top-level declaration that occurred inside
  75. /// and ObjC container.
  76. /// The default implementation ignored them.
  77. virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D);
  78. /// Handle an ImportDecl that was implicitly created due to an
  79. /// inclusion directive.
  80. /// The default implementation passes it to HandleTopLevelDecl.
  81. virtual void HandleImplicitImportDecl(ImportDecl *D);
  82. /// CompleteTentativeDefinition - Callback invoked at the end of a translation
  83. /// unit to notify the consumer that the given tentative definition should be
  84. /// completed.
  85. ///
  86. /// The variable declaration itself will be a tentative
  87. /// definition. If it had an incomplete array type, its type will
  88. /// have already been changed to an array of size 1. However, the
  89. /// declaration remains a tentative definition and has not been
  90. /// modified by the introduction of an implicit zero initializer.
  91. virtual void CompleteTentativeDefinition(VarDecl *D) {}
  92. /// CompleteExternalDeclaration - Callback invoked at the end of a translation
  93. /// unit to notify the consumer that the given external declaration should be
  94. /// completed.
  95. virtual void CompleteExternalDeclaration(VarDecl *D) {}
  96. /// Callback invoked when an MSInheritanceAttr has been attached to a
  97. /// CXXRecordDecl.
  98. virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
  99. /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
  100. // variable has been instantiated.
  101. virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {}
  102. /// Callback involved at the end of a translation unit to
  103. /// notify the consumer that a vtable for the given C++ class is
  104. /// required.
  105. ///
  106. /// \param RD The class whose vtable was used.
  107. virtual void HandleVTable(CXXRecordDecl *RD) {}
  108. /// If the consumer is interested in entities getting modified after
  109. /// their initial creation, it should return a pointer to
  110. /// an ASTMutationListener here.
  111. virtual ASTMutationListener *GetASTMutationListener() { return nullptr; }
  112. /// If the consumer is interested in entities being deserialized from
  113. /// AST files, it should return a pointer to a ASTDeserializationListener here
  114. virtual ASTDeserializationListener *GetASTDeserializationListener() {
  115. return nullptr;
  116. }
  117. /// PrintStats - If desired, print any statistics.
  118. virtual void PrintStats() {}
  119. /// This callback is called for each function if the Parser was
  120. /// initialized with \c SkipFunctionBodies set to \c true.
  121. ///
  122. /// \return \c true if the function's body should be skipped. The function
  123. /// body may be parsed anyway if it is needed (for instance, if it contains
  124. /// the code completion point or is constexpr).
  125. virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
  126. };
  127. } // end namespace clang.
  128. #endif
  129. #ifdef __GNUC__
  130. #pragma GCC diagnostic pop
  131. #endif