Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 1 | //===-- ASTStructExtractor.h ------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef liblldb_ASTStructExtractor_h_ |
| 11 | #define liblldb_ASTStructExtractor_h_ |
| 12 | |
Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 13 | #include "ClangExpressionVariable.h" |
| 14 | #include "ClangFunctionCaller.h" |
| 15 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 16 | #include "lldb/Core/ClangForward.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 17 | #include "clang/Sema/SemaConsumer.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 18 | |
| 19 | namespace lldb_private { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 20 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 21 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 22 | /// @class ASTStructExtractor ASTStructExtractor.h |
| 23 | /// "lldb/Expression/ASTStructExtractor.h" |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 24 | /// @brief Extracts and describes the argument structure for a wrapped function. |
| 25 | /// |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 26 | /// This pass integrates with ClangFunctionCaller, which calls functions with |
| 27 | /// custom |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 28 | /// sets of arguments. To avoid having to implement the full calling convention |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 29 | /// for the target's architecture, ClangFunctionCaller writes a simple wrapper |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 30 | /// function that takes a pointer to an argument structure that contains room |
| 31 | /// for the address of the function to be called, the values of all its |
| 32 | /// arguments, and room for the function's return value. |
| 33 | /// |
| 34 | /// The definition of this struct is itself in the body of the wrapper function, |
| 35 | /// so Clang does the structure layout itself. ASTStructExtractor reads through |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 36 | /// the AST for the wrapper function and finds the struct. |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 37 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 38 | class ASTStructExtractor : public clang::SemaConsumer { |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 39 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 40 | //---------------------------------------------------------------------- |
| 41 | /// Constructor |
| 42 | /// |
| 43 | /// @param[in] passthrough |
| 44 | /// Since the ASTs must typically go through to the Clang code generator |
| 45 | /// in order to produce LLVM IR, this SemaConsumer must allow them to |
| 46 | /// pass to the next step in the chain after processing. Passthrough is |
| 47 | /// the next ASTConsumer, or NULL if none is required. |
| 48 | /// |
| 49 | /// @param[in] struct_name |
| 50 | /// The name of the structure to extract from the wrapper function. |
| 51 | /// |
| 52 | /// @param[in] function |
| 53 | /// The caller object whose members should be populated with information |
| 54 | /// about the argument struct. ClangFunctionCaller friends |
| 55 | /// ASTStructExtractor |
| 56 | /// for this purpose. |
| 57 | //---------------------------------------------------------------------- |
| 58 | ASTStructExtractor(clang::ASTConsumer *passthrough, const char *struct_name, |
| 59 | ClangFunctionCaller &function); |
| 60 | |
| 61 | //---------------------------------------------------------------------- |
| 62 | /// Destructor |
| 63 | //---------------------------------------------------------------------- |
| 64 | ~ASTStructExtractor() override; |
| 65 | |
| 66 | //---------------------------------------------------------------------- |
| 67 | /// Link this consumer with a particular AST context |
| 68 | /// |
| 69 | /// @param[in] Context |
| 70 | /// This AST context will be used for types and identifiers, and also |
| 71 | /// forwarded to the passthrough consumer, if one exists. |
| 72 | //---------------------------------------------------------------------- |
| 73 | void Initialize(clang::ASTContext &Context) override; |
| 74 | |
| 75 | //---------------------------------------------------------------------- |
| 76 | /// Examine a list of Decls to find the function $__lldb_expr and |
| 77 | /// transform its code |
| 78 | /// |
| 79 | /// @param[in] D |
| 80 | /// The list of Decls to search. These may contain LinkageSpecDecls, |
| 81 | /// which need to be searched recursively. That job falls to |
| 82 | /// TransformTopLevelDecl. |
| 83 | //---------------------------------------------------------------------- |
| 84 | bool HandleTopLevelDecl(clang::DeclGroupRef D) override; |
| 85 | |
| 86 | //---------------------------------------------------------------------- |
| 87 | /// Passthrough stub |
| 88 | //---------------------------------------------------------------------- |
| 89 | void HandleTranslationUnit(clang::ASTContext &Ctx) override; |
| 90 | |
| 91 | //---------------------------------------------------------------------- |
| 92 | /// Passthrough stub |
| 93 | //---------------------------------------------------------------------- |
| 94 | void HandleTagDeclDefinition(clang::TagDecl *D) override; |
| 95 | |
| 96 | //---------------------------------------------------------------------- |
| 97 | /// Passthrough stub |
| 98 | //---------------------------------------------------------------------- |
| 99 | void CompleteTentativeDefinition(clang::VarDecl *D) override; |
| 100 | |
| 101 | //---------------------------------------------------------------------- |
| 102 | /// Passthrough stub |
| 103 | //---------------------------------------------------------------------- |
| 104 | void HandleVTable(clang::CXXRecordDecl *RD) override; |
| 105 | |
| 106 | //---------------------------------------------------------------------- |
| 107 | /// Passthrough stub |
| 108 | //---------------------------------------------------------------------- |
| 109 | void PrintStats() override; |
| 110 | |
| 111 | //---------------------------------------------------------------------- |
| 112 | /// Set the Sema object to use when performing transforms, and pass it on |
| 113 | /// |
| 114 | /// @param[in] S |
| 115 | /// The Sema to use. Because Sema isn't externally visible, this class |
| 116 | /// casts it to an Action for actual use. |
| 117 | //---------------------------------------------------------------------- |
| 118 | void InitializeSema(clang::Sema &S) override; |
| 119 | |
| 120 | //---------------------------------------------------------------------- |
| 121 | /// Reset the Sema to NULL now that transformations are done |
| 122 | //---------------------------------------------------------------------- |
| 123 | void ForgetSema() override; |
Pavel Labath | 083645b | 2015-08-18 09:18:19 +0000 | [diff] [blame] | 124 | |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 125 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 126 | //---------------------------------------------------------------------- |
| 127 | /// Hunt the given FunctionDecl for the argument struct and place |
| 128 | /// information about it into m_function |
| 129 | /// |
| 130 | /// @param[in] F |
| 131 | /// The FunctionDecl to hunt. |
| 132 | //---------------------------------------------------------------------- |
| 133 | void ExtractFromFunctionDecl(clang::FunctionDecl *F); |
| 134 | |
| 135 | //---------------------------------------------------------------------- |
| 136 | /// Hunt the given Decl for FunctionDecls named the same as the wrapper |
| 137 | /// function name, recursing as necessary through LinkageSpecDecls, and |
| 138 | /// calling ExtractFromFunctionDecl on anything that was found |
| 139 | /// |
| 140 | /// @param[in] D |
| 141 | /// The Decl to hunt. |
| 142 | //---------------------------------------------------------------------- |
| 143 | void ExtractFromTopLevelDecl(clang::Decl *D); |
| 144 | |
| 145 | clang::ASTContext |
| 146 | *m_ast_context; ///< The AST context to use for identifiers and types. |
| 147 | clang::ASTConsumer *m_passthrough; ///< The ASTConsumer down the chain, for |
| 148 | ///passthrough. NULL if it's a |
| 149 | ///SemaConsumer. |
| 150 | clang::SemaConsumer *m_passthrough_sema; ///< The SemaConsumer down the chain, |
| 151 | ///for passthrough. NULL if it's an |
| 152 | ///ASTConsumer. |
| 153 | clang::Sema *m_sema; ///< The Sema to use. |
| 154 | clang::Action |
| 155 | *m_action; ///< The Sema to use, cast to an Action so it's usable. |
| 156 | |
| 157 | ClangFunctionCaller &m_function; ///< The function to populate with |
| 158 | ///information about the argument structure. |
| 159 | std::string m_struct_name; ///< The name of the structure to extract. |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 160 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 161 | |
Pavel Labath | 083645b | 2015-08-18 09:18:19 +0000 | [diff] [blame] | 162 | } // namespace lldb_private |
Sean Callanan | 1a8d409 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 163 | |
Pavel Labath | 083645b | 2015-08-18 09:18:19 +0000 | [diff] [blame] | 164 | #endif // liblldb_ASTStructExtractor_h_ |