Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ASTStructExtractor.h
39648 views
//===-- ASTStructExtractor.h ------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H1011#include "ClangExpressionVariable.h"12#include "ClangFunctionCaller.h"1314#include "clang/Sema/SemaConsumer.h"1516namespace lldb_private {1718/// \class ASTStructExtractor ASTStructExtractor.h19/// "lldb/Expression/ASTStructExtractor.h" Extracts and describes the argument20/// structure for a wrapped function.21///22/// This pass integrates with ClangFunctionCaller, which calls functions with23/// custom sets of arguments. To avoid having to implement the full calling24/// convention for the target's architecture, ClangFunctionCaller writes a25/// simple wrapper function that takes a pointer to an argument structure that26/// contains room for the address of the function to be called, the values of27/// all its arguments, and room for the function's return value.28///29/// The definition of this struct is itself in the body of the wrapper30/// function, so Clang does the structure layout itself. ASTStructExtractor31/// reads through the AST for the wrapper function and finds the struct.32class ASTStructExtractor : public clang::SemaConsumer {33public:34/// Constructor35///36/// \param[in] passthrough37/// Since the ASTs must typically go through to the Clang code generator38/// in order to produce LLVM IR, this SemaConsumer must allow them to39/// pass to the next step in the chain after processing. Passthrough is40/// the next ASTConsumer, or NULL if none is required.41///42/// \param[in] struct_name43/// The name of the structure to extract from the wrapper function.44///45/// \param[in] function46/// The caller object whose members should be populated with information47/// about the argument struct. ClangFunctionCaller friends48/// ASTStructExtractor49/// for this purpose.50ASTStructExtractor(clang::ASTConsumer *passthrough, const char *struct_name,51ClangFunctionCaller &function);5253/// Destructor54~ASTStructExtractor() override;5556/// Link this consumer with a particular AST context57///58/// \param[in] Context59/// This AST context will be used for types and identifiers, and also60/// forwarded to the passthrough consumer, if one exists.61void Initialize(clang::ASTContext &Context) override;6263/// Examine a list of Decls to find the function $__lldb_expr and transform64/// its code65///66/// \param[in] D67/// The list of Decls to search. These may contain LinkageSpecDecls,68/// which need to be searched recursively. That job falls to69/// TransformTopLevelDecl.70bool HandleTopLevelDecl(clang::DeclGroupRef D) override;7172/// Passthrough stub73void HandleTranslationUnit(clang::ASTContext &Ctx) override;7475/// Passthrough stub76void HandleTagDeclDefinition(clang::TagDecl *D) override;7778/// Passthrough stub79void CompleteTentativeDefinition(clang::VarDecl *D) override;8081/// Passthrough stub82void HandleVTable(clang::CXXRecordDecl *RD) override;8384/// Passthrough stub85void PrintStats() override;8687/// Set the Sema object to use when performing transforms, and pass it on88///89/// \param[in] S90/// The Sema to use. Because Sema isn't externally visible, this class91/// casts it to an Action for actual use.92void InitializeSema(clang::Sema &S) override;9394/// Reset the Sema to NULL now that transformations are done95void ForgetSema() override;9697private:98/// Hunt the given FunctionDecl for the argument struct and place99/// information about it into m_function100///101/// \param[in] F102/// The FunctionDecl to hunt.103void ExtractFromFunctionDecl(clang::FunctionDecl *F);104105/// Hunt the given Decl for FunctionDecls named the same as the wrapper106/// function name, recursing as necessary through LinkageSpecDecls, and107/// calling ExtractFromFunctionDecl on anything that was found108///109/// \param[in] D110/// The Decl to hunt.111void ExtractFromTopLevelDecl(clang::Decl *D);112113clang::ASTContext114*m_ast_context; ///< The AST context to use for identifiers and types.115clang::ASTConsumer *m_passthrough; ///< The ASTConsumer down the chain, for116///passthrough. NULL if it's a117///SemaConsumer.118clang::SemaConsumer *m_passthrough_sema; ///< The SemaConsumer down the chain,119///for passthrough. NULL if it's an120///ASTConsumer.121clang::Sema *m_sema; ///< The Sema to use.122123ClangFunctionCaller &m_function; ///< The function to populate with124///information about the argument structure.125std::string m_struct_name; ///< The name of the structure to extract.126};127128} // namespace lldb_private129130#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H131132133