Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / ExpressionParser / Clang / ASTStructExtractor.h
blobc285f64088956419d3dd1117b0965b6fef55b4e2
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H
12 #include "ClangExpressionVariable.h"
13 #include "ClangFunctionCaller.h"
15 #include "clang/Sema/SemaConsumer.h"
17 namespace lldb_private {
19 /// \class ASTStructExtractor ASTStructExtractor.h
20 /// "lldb/Expression/ASTStructExtractor.h" Extracts and describes the argument
21 /// structure for a wrapped function.
22 ///
23 /// This pass integrates with ClangFunctionCaller, which calls functions with
24 /// custom sets of arguments. To avoid having to implement the full calling
25 /// convention for the target's architecture, ClangFunctionCaller writes a
26 /// simple wrapper function that takes a pointer to an argument structure that
27 /// contains room for the address of the function to be called, the values of
28 /// 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 wrapper
31 /// function, so Clang does the structure layout itself. ASTStructExtractor
32 /// reads through the AST for the wrapper function and finds the struct.
33 class ASTStructExtractor : public clang::SemaConsumer {
34 public:
35 /// Constructor
36 ///
37 /// \param[in] passthrough
38 /// Since the ASTs must typically go through to the Clang code generator
39 /// in order to produce LLVM IR, this SemaConsumer must allow them to
40 /// pass to the next step in the chain after processing. Passthrough is
41 /// the next ASTConsumer, or NULL if none is required.
42 ///
43 /// \param[in] struct_name
44 /// The name of the structure to extract from the wrapper function.
45 ///
46 /// \param[in] function
47 /// The caller object whose members should be populated with information
48 /// about the argument struct. ClangFunctionCaller friends
49 /// ASTStructExtractor
50 /// for this purpose.
51 ASTStructExtractor(clang::ASTConsumer *passthrough, const char *struct_name,
52 ClangFunctionCaller &function);
54 /// Destructor
55 ~ASTStructExtractor() override;
57 /// Link this consumer with a particular AST context
58 ///
59 /// \param[in] Context
60 /// This AST context will be used for types and identifiers, and also
61 /// forwarded to the passthrough consumer, if one exists.
62 void Initialize(clang::ASTContext &Context) override;
64 /// Examine a list of Decls to find the function $__lldb_expr and transform
65 /// its code
66 ///
67 /// \param[in] D
68 /// The list of Decls to search. These may contain LinkageSpecDecls,
69 /// which need to be searched recursively. That job falls to
70 /// TransformTopLevelDecl.
71 bool HandleTopLevelDecl(clang::DeclGroupRef D) override;
73 /// Passthrough stub
74 void HandleTranslationUnit(clang::ASTContext &Ctx) override;
76 /// Passthrough stub
77 void HandleTagDeclDefinition(clang::TagDecl *D) override;
79 /// Passthrough stub
80 void CompleteTentativeDefinition(clang::VarDecl *D) override;
82 /// Passthrough stub
83 void HandleVTable(clang::CXXRecordDecl *RD) override;
85 /// Passthrough stub
86 void PrintStats() override;
88 /// Set the Sema object to use when performing transforms, and pass it on
89 ///
90 /// \param[in] S
91 /// The Sema to use. Because Sema isn't externally visible, this class
92 /// casts it to an Action for actual use.
93 void InitializeSema(clang::Sema &S) override;
95 /// Reset the Sema to NULL now that transformations are done
96 void ForgetSema() override;
98 private:
99 /// Hunt the given FunctionDecl for the argument struct and place
100 /// information about it into m_function
102 /// \param[in] F
103 /// The FunctionDecl to hunt.
104 void ExtractFromFunctionDecl(clang::FunctionDecl *F);
106 /// Hunt the given Decl for FunctionDecls named the same as the wrapper
107 /// function name, recursing as necessary through LinkageSpecDecls, and
108 /// calling ExtractFromFunctionDecl on anything that was found
110 /// \param[in] D
111 /// The Decl to hunt.
112 void ExtractFromTopLevelDecl(clang::Decl *D);
114 clang::ASTContext
115 *m_ast_context; ///< The AST context to use for identifiers and types.
116 clang::ASTConsumer *m_passthrough; ///< The ASTConsumer down the chain, for
117 ///passthrough. NULL if it's a
118 ///SemaConsumer.
119 clang::SemaConsumer *m_passthrough_sema; ///< The SemaConsumer down the chain,
120 ///for passthrough. NULL if it's an
121 ///ASTConsumer.
122 clang::Sema *m_sema; ///< The Sema to use.
124 ClangFunctionCaller &m_function; ///< The function to populate with
125 ///information about the argument structure.
126 std::string m_struct_name; ///< The name of the structure to extract.
129 } // namespace lldb_private
131 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H