brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · c285f64 Raw
132 lines · c
1//===-- ASTStructExtractor.h ------------------------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H11 12#include "ClangExpressionVariable.h"13#include "ClangFunctionCaller.h"14 15#include "clang/Sema/SemaConsumer.h"16 17namespace lldb_private {18 19/// \class ASTStructExtractor ASTStructExtractor.h20/// "lldb/Expression/ASTStructExtractor.h" Extracts and describes the argument21/// structure for a wrapped function.22///23/// This pass integrates with ClangFunctionCaller, which calls functions with24/// custom sets of arguments.  To avoid having to implement the full calling25/// convention for the target's architecture, ClangFunctionCaller writes a26/// simple wrapper function that takes a pointer to an argument structure that27/// contains room for the address of the function to be called, the values of28/// all its arguments, and room for the function's return value.29///30/// The definition of this struct is itself in the body of the wrapper31/// function, so Clang does the structure layout itself.  ASTStructExtractor32/// reads through the AST for the wrapper function and finds the struct.33class ASTStructExtractor : public clang::SemaConsumer {34public:35  /// Constructor36  ///37  /// \param[in] passthrough38  ///     Since the ASTs must typically go through to the Clang code generator39  ///     in order to produce LLVM IR, this SemaConsumer must allow them to40  ///     pass to the next step in the chain after processing.  Passthrough is41  ///     the next ASTConsumer, or NULL if none is required.42  ///43  /// \param[in] struct_name44  ///     The name of the structure to extract from the wrapper function.45  ///46  /// \param[in] function47  ///     The caller object whose members should be populated with information48  ///     about the argument struct.  ClangFunctionCaller friends49  ///     ASTStructExtractor50  ///     for this purpose.51  ASTStructExtractor(clang::ASTConsumer *passthrough, const char *struct_name,52                     ClangFunctionCaller &function);53 54  /// Destructor55  ~ASTStructExtractor() override;56 57  /// Link this consumer with a particular AST context58  ///59  /// \param[in] Context60  ///     This AST context will be used for types and identifiers, and also61  ///     forwarded to the passthrough consumer, if one exists.62  void Initialize(clang::ASTContext &Context) override;63 64  /// Examine a list of Decls to find the function $__lldb_expr and transform65  /// its code66  ///67  /// \param[in] D68  ///     The list of Decls to search.  These may contain LinkageSpecDecls,69  ///     which need to be searched recursively.  That job falls to70  ///     TransformTopLevelDecl.71  bool HandleTopLevelDecl(clang::DeclGroupRef D) override;72 73  /// Passthrough stub74  void HandleTranslationUnit(clang::ASTContext &Ctx) override;75 76  /// Passthrough stub77  void HandleTagDeclDefinition(clang::TagDecl *D) override;78 79  /// Passthrough stub80  void CompleteTentativeDefinition(clang::VarDecl *D) override;81 82  /// Passthrough stub83  void HandleVTable(clang::CXXRecordDecl *RD) override;84 85  /// Passthrough stub86  void PrintStats() override;87 88  /// Set the Sema object to use when performing transforms, and pass it on89  ///90  /// \param[in] S91  ///     The Sema to use.  Because Sema isn't externally visible, this class92  ///     casts it to an Action for actual use.93  void InitializeSema(clang::Sema &S) override;94 95  /// Reset the Sema to NULL now that transformations are done96  void ForgetSema() override;97 98private:99  /// Hunt the given FunctionDecl for the argument struct and place100  /// information about it into m_function101  ///102  /// \param[in] F103  ///     The FunctionDecl to hunt.104  void ExtractFromFunctionDecl(clang::FunctionDecl *F);105 106  /// Hunt the given Decl for FunctionDecls named the same as the wrapper107  /// function name, recursing as necessary through LinkageSpecDecls, and108  /// calling ExtractFromFunctionDecl on anything that was found109  ///110  /// \param[in] D111  ///     The Decl to hunt.112  void ExtractFromTopLevelDecl(clang::Decl *D);113 114  clang::ASTContext115      *m_ast_context; ///< The AST context to use for identifiers and types.116  clang::ASTConsumer *m_passthrough; ///< The ASTConsumer down the chain, for117                                     ///passthrough.  NULL if it's a118                                     ///SemaConsumer.119  clang::SemaConsumer *m_passthrough_sema; ///< The SemaConsumer down the chain,120                                           ///for passthrough.  NULL if it's an121                                           ///ASTConsumer.122  clang::Sema *m_sema;                     ///< The Sema to use.123 124  ClangFunctionCaller &m_function; ///< The function to populate with125                                   ///information about the argument structure.126  std::string m_struct_name;       ///< The name of the structure to extract.127};128 129} // namespace lldb_private130 131#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H132