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 // C Includes 14 // C++ Includes 15 #include <string> 16 #include <map> 17 #include <vector> 18 19 // Other libraries and framework includes 20 // Project includes 21 #include "ClangExpressionHelper.h" 22 23 #include "lldb/lldb-forward.h" 24 #include "lldb/lldb-private.h" 25 #include "lldb/Core/ClangForward.h" 26 #include "lldb/Expression/UtilityFunction.h" 27 28 namespace lldb_private 29 { 30 31 //---------------------------------------------------------------------- 32 /// @class ClangUtilityFunction ClangUtilityFunction.h "lldb/Expression/ClangUtilityFunction.h" 33 /// @brief Encapsulates a single expression for use with Clang 34 /// 35 /// LLDB uses expressions for various purposes, notably to call functions 36 /// and as a backend for the expr command. ClangUtilityFunction encapsulates 37 /// a self-contained function meant to be used from other code. Utility 38 /// functions can perform error-checking for ClangUserExpressions, or can 39 /// simply provide a way to push a function into the target for the debugger to 40 /// call later on. 41 //---------------------------------------------------------------------- 42 class ClangUtilityFunction : public UtilityFunction 43 { 44 public: 45 class ClangUtilityFunctionHelper : public ClangExpressionHelper 46 { 47 public: 48 ClangUtilityFunctionHelper () 49 { 50 } 51 52 ~ClangUtilityFunctionHelper() override {} 53 54 //------------------------------------------------------------------ 55 /// Return the object that the parser should use when resolving external 56 /// values. May be NULL if everything should be self-contained. 57 //------------------------------------------------------------------ 58 ClangExpressionDeclMap * 59 DeclMap() override 60 { 61 return m_expr_decl_map_up.get(); 62 } 63 64 void 65 ResetDeclMap() 66 { 67 m_expr_decl_map_up.reset(); 68 } 69 70 void 71 ResetDeclMap (ExecutionContext & exe_ctx, bool keep_result_in_memory); 72 73 //------------------------------------------------------------------ 74 /// Return the object that the parser should allow to access ASTs. 75 /// May be NULL if the ASTs do not need to be transformed. 76 /// 77 /// @param[in] passthrough 78 /// The ASTConsumer that the returned transformer should send 79 /// the ASTs to after transformation. 80 //------------------------------------------------------------------ 81 clang::ASTConsumer * 82 ASTTransformer(clang::ASTConsumer *passthrough) override 83 { 84 return nullptr; 85 } 86 private: 87 std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up; 88 }; 89 //------------------------------------------------------------------ 90 /// Constructor 91 /// 92 /// @param[in] text 93 /// The text of the function. Must be a full translation unit. 94 /// 95 /// @param[in] name 96 /// The name of the function, as used in the text. 97 //------------------------------------------------------------------ 98 ClangUtilityFunction (ExecutionContextScope &exe_scope, 99 const char *text, 100 const char *name); 101 102 ~ClangUtilityFunction() override; 103 104 ExpressionTypeSystemHelper * 105 GetTypeSystemHelper () override 106 { 107 return &m_type_system_helper; 108 } 109 110 ClangExpressionDeclMap * 111 DeclMap() 112 { 113 return m_type_system_helper.DeclMap(); 114 } 115 116 void 117 ResetDeclMap () 118 { 119 m_type_system_helper.ResetDeclMap(); 120 } 121 122 void 123 ResetDeclMap (ExecutionContext & exe_ctx, bool keep_result_in_memory) 124 { 125 m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory); 126 } 127 128 bool 129 Install (Stream &error_stream, ExecutionContext &exe_ctx) override; 130 131 private: 132 ClangUtilityFunctionHelper m_type_system_helper; ///< The map to use when parsing and materializing the expression. 133 }; 134 135 } // namespace lldb_private 136 137 #endif // liblldb_ClangUtilityFunction_h_ 138