1 //===-- ClangUtilityFunction.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ClangUtilityFunction_h_
11 #define liblldb_ClangUtilityFunction_h_
17 #include "ClangExpressionHelper.h"
19 #include "lldb/Core/ClangForward.h"
20 #include "lldb/Expression/UtilityFunction.h"
21 #include "lldb/lldb-forward.h"
22 #include "lldb/lldb-private.h"
24 namespace lldb_private {
26 //----------------------------------------------------------------------
27 /// @class ClangUtilityFunction ClangUtilityFunction.h
28 /// "lldb/Expression/ClangUtilityFunction.h" Encapsulates a single expression
29 /// for use with Clang
31 /// LLDB uses expressions for various purposes, notably to call functions
32 /// and as a backend for the expr command. ClangUtilityFunction encapsulates
33 /// a self-contained function meant to be used from other code. Utility
34 /// functions can perform error-checking for ClangUserExpressions, or can
35 /// simply provide a way to push a function into the target for the debugger
37 //----------------------------------------------------------------------
38 class ClangUtilityFunction : public UtilityFunction {
40 class ClangUtilityFunctionHelper : public ClangExpressionHelper {
42 ClangUtilityFunctionHelper() {}
44 ~ClangUtilityFunctionHelper() override {}
46 //------------------------------------------------------------------
47 /// Return the object that the parser should use when resolving external
48 /// values. May be NULL if everything should be self-contained.
49 //------------------------------------------------------------------
50 ClangExpressionDeclMap *DeclMap() override {
51 return m_expr_decl_map_up.get();
54 void ResetDeclMap() { m_expr_decl_map_up.reset(); }
56 void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory);
58 //------------------------------------------------------------------
59 /// Return the object that the parser should allow to access ASTs. May be
60 /// NULL if the ASTs do not need to be transformed.
62 /// @param[in] passthrough
63 /// The ASTConsumer that the returned transformer should send
64 /// the ASTs to after transformation.
65 //------------------------------------------------------------------
67 ASTTransformer(clang::ASTConsumer *passthrough) override {
72 std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up;
74 //------------------------------------------------------------------
78 /// The text of the function. Must be a full translation unit.
81 /// The name of the function, as used in the text.
82 //------------------------------------------------------------------
83 ClangUtilityFunction(ExecutionContextScope &exe_scope, const char *text,
86 ~ClangUtilityFunction() override;
88 ExpressionTypeSystemHelper *GetTypeSystemHelper() override {
89 return &m_type_system_helper;
92 ClangExpressionDeclMap *DeclMap() { return m_type_system_helper.DeclMap(); }
94 void ResetDeclMap() { m_type_system_helper.ResetDeclMap(); }
96 void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory) {
97 m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);
100 bool Install(DiagnosticManager &diagnostic_manager,
101 ExecutionContext &exe_ctx) override;
104 ClangUtilityFunctionHelper m_type_system_helper; ///< The map to use when
105 ///parsing and materializing
109 } // namespace lldb_private
111 #endif // liblldb_ClangUtilityFunction_h_