]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / ExpressionParser / Clang / ClangUtilityFunction.h
1 //===-- ClangUtilityFunction.h ----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_ClangUtilityFunction_h_
11 #define liblldb_ClangUtilityFunction_h_
12
13 #include <map>
14 #include <string>
15 #include <vector>
16
17 #include "ClangExpressionHelper.h"
18
19 #include "lldb/Core/ClangForward.h"
20 #include "lldb/Expression/UtilityFunction.h"
21 #include "lldb/lldb-forward.h"
22 #include "lldb/lldb-private.h"
23
24 namespace lldb_private {
25
26 //----------------------------------------------------------------------
27 /// @class ClangUtilityFunction ClangUtilityFunction.h
28 /// "lldb/Expression/ClangUtilityFunction.h" Encapsulates a single expression
29 /// for use with Clang
30 ///
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
36 /// to call later on.
37 //----------------------------------------------------------------------
38 class ClangUtilityFunction : public UtilityFunction {
39 public:
40   class ClangUtilityFunctionHelper : public ClangExpressionHelper {
41   public:
42     ClangUtilityFunctionHelper() {}
43
44     ~ClangUtilityFunctionHelper() override {}
45
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();
52     }
53
54     void ResetDeclMap() { m_expr_decl_map_up.reset(); }
55
56     void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory);
57
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.
61     ///
62     /// @param[in] passthrough
63     ///     The ASTConsumer that the returned transformer should send
64     ///     the ASTs to after transformation.
65     //------------------------------------------------------------------
66     clang::ASTConsumer *
67     ASTTransformer(clang::ASTConsumer *passthrough) override {
68       return nullptr;
69     }
70
71   private:
72     std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up;
73   };
74   //------------------------------------------------------------------
75   /// Constructor
76   ///
77   /// @param[in] text
78   ///     The text of the function.  Must be a full translation unit.
79   ///
80   /// @param[in] name
81   ///     The name of the function, as used in the text.
82   //------------------------------------------------------------------
83   ClangUtilityFunction(ExecutionContextScope &exe_scope, const char *text,
84                        const char *name);
85
86   ~ClangUtilityFunction() override;
87
88   ExpressionTypeSystemHelper *GetTypeSystemHelper() override {
89     return &m_type_system_helper;
90   }
91
92   ClangExpressionDeclMap *DeclMap() { return m_type_system_helper.DeclMap(); }
93
94   void ResetDeclMap() { m_type_system_helper.ResetDeclMap(); }
95
96   void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory) {
97     m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);
98   }
99
100   bool Install(DiagnosticManager &diagnostic_manager,
101                ExecutionContext &exe_ctx) override;
102
103 private:
104   ClangUtilityFunctionHelper m_type_system_helper; ///< The map to use when
105                                                    ///parsing and materializing
106                                                    ///the expression.
107 };
108
109 } // namespace lldb_private
110
111 #endif // liblldb_ClangUtilityFunction_h_