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