LLDB
mainline
llvm-project
lldb
source
Plugins
ExpressionParser
Clang
ASTStructExtractor.h
Go to the documentation of this file.
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
//===----------------------------------------------------------------------===//
8
9
#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H
10
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H
11
12
#include "
ClangExpressionVariable.h
"
13
#include "
ClangFunctionCaller.h
"
14
15
#include "clang/Sema/SemaConsumer.h"
16
17
namespace
lldb_private
{
18
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);
53
54
/// Destructor
55
~ASTStructExtractor
()
override
;
56
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
;
63
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
;
72
73
/// Passthrough stub
74
void
HandleTranslationUnit
(clang::ASTContext &Ctx)
override
;
75
76
/// Passthrough stub
77
void
HandleTagDeclDefinition
(clang::TagDecl *D)
override
;
78
79
/// Passthrough stub
80
void
CompleteTentativeDefinition
(clang::VarDecl *D)
override
;
81
82
/// Passthrough stub
83
void
HandleVTable
(clang::CXXRecordDecl *RD)
override
;
84
85
/// Passthrough stub
86
void
PrintStats
()
override
;
87
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
;
94
95
/// Reset the Sema to NULL now that transformations are done
96
void
ForgetSema
()
override
;
97
98
private
:
99
/// Hunt the given FunctionDecl for the argument struct and place
100
/// information about it into m_function
101
///
102
/// \param[in] F
103
/// The FunctionDecl to hunt.
104
void
ExtractFromFunctionDecl
(clang::FunctionDecl *F);
105
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
109
///
110
/// \param[in] D
111
/// The Decl to hunt.
112
void
ExtractFromTopLevelDecl
(clang::Decl *D);
113
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.
123
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.
127
};
128
129
}
// namespace lldb_private
130
131
#endif
// LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTSTRUCTEXTRACTOR_H
ClangExpressionVariable.h
ClangFunctionCaller.h
lldb_private::ASTStructExtractor::m_passthrough_sema
clang::SemaConsumer * m_passthrough_sema
The SemaConsumer down the chain, for passthrough.
Definition
ASTStructExtractor.h:119
lldb_private::ASTStructExtractor::ForgetSema
void ForgetSema() override
Reset the Sema to NULL now that transformations are done.
Definition
ASTStructExtractor.cpp:177
lldb_private::ASTStructExtractor::CompleteTentativeDefinition
void CompleteTentativeDefinition(clang::VarDecl *D) override
Passthrough stub.
Definition
ASTStructExtractor.cpp:155
lldb_private::ASTStructExtractor::HandleTagDeclDefinition
void HandleTagDeclDefinition(clang::TagDecl *D) override
Passthrough stub.
Definition
ASTStructExtractor.cpp:150
lldb_private::ASTStructExtractor::PrintStats
void PrintStats() override
Passthrough stub.
Definition
ASTStructExtractor.cpp:165
lldb_private::ASTStructExtractor::HandleTopLevelDecl
bool HandleTopLevelDecl(clang::DeclGroupRef D) override
Examine a list of Decls to find the function $__lldb_expr and transform its code.
Definition
ASTStructExtractor.cpp:131
lldb_private::ASTStructExtractor::m_struct_name
std::string m_struct_name
The name of the structure to extract.
Definition
ASTStructExtractor.h:126
lldb_private::ASTStructExtractor::m_passthrough
clang::ASTConsumer * m_passthrough
The ASTConsumer down the chain, for passthrough.
Definition
ASTStructExtractor.h:116
lldb_private::ASTStructExtractor::ASTStructExtractor
ASTStructExtractor(clang::ASTConsumer *passthrough, const char *struct_name, ClangFunctionCaller &function)
Constructor.
Definition
ASTStructExtractor.cpp:29
lldb_private::ASTStructExtractor::m_sema
clang::Sema * m_sema
The Sema to use.
Definition
ASTStructExtractor.h:122
lldb_private::ASTStructExtractor::m_ast_context
clang::ASTContext * m_ast_context
The AST context to use for identifiers and types.
Definition
ASTStructExtractor.h:115
lldb_private::ASTStructExtractor::ExtractFromFunctionDecl
void ExtractFromFunctionDecl(clang::FunctionDecl *F)
Hunt the given FunctionDecl for the argument struct and place information about it into m_function.
Definition
ASTStructExtractor.cpp:50
lldb_private::ASTStructExtractor::~ASTStructExtractor
~ASTStructExtractor() override
Destructor.
lldb_private::ASTStructExtractor::m_function
ClangFunctionCaller & m_function
The function to populate with information about the argument structure.
Definition
ASTStructExtractor.h:124
lldb_private::ASTStructExtractor::HandleVTable
void HandleVTable(clang::CXXRecordDecl *RD) override
Passthrough stub.
Definition
ASTStructExtractor.cpp:160
lldb_private::ASTStructExtractor::HandleTranslationUnit
void HandleTranslationUnit(clang::ASTContext &Ctx) override
Passthrough stub.
Definition
ASTStructExtractor.cpp:145
lldb_private::ASTStructExtractor::ExtractFromTopLevelDecl
void ExtractFromTopLevelDecl(clang::Decl *D)
Hunt the given Decl for FunctionDecls named the same as the wrapper function name,...
Definition
ASTStructExtractor.cpp:111
lldb_private::ASTStructExtractor::Initialize
void Initialize(clang::ASTContext &Context) override
Link this consumer with a particular AST context.
Definition
ASTStructExtractor.cpp:43
lldb_private::ASTStructExtractor::InitializeSema
void InitializeSema(clang::Sema &S) override
Set the Sema object to use when performing transforms, and pass it on.
Definition
ASTStructExtractor.cpp:170
lldb_private::ClangFunctionCaller
"lldb/Expression/ClangFunctionCaller.h" Encapsulates a function that can be called.
Definition
ClangFunctionCaller.h:57
lldb_private
A class that represents a running process on the host machine.
Definition
SBAddressRange.h:14
Generated on
for LLDB by
1.14.0