1061da546Spatrick //===-- ClangUtilityFunction.h ----------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H 10dda28197Spatrick #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H 11061da546Spatrick 12061da546Spatrick #include <map> 13061da546Spatrick #include <string> 14061da546Spatrick #include <vector> 15061da546Spatrick 16061da546Spatrick #include "ClangExpressionHelper.h" 17061da546Spatrick 18061da546Spatrick #include "lldb/Expression/UtilityFunction.h" 19061da546Spatrick #include "lldb/lldb-forward.h" 20061da546Spatrick #include "lldb/lldb-private.h" 21061da546Spatrick 22061da546Spatrick namespace lldb_private { 23061da546Spatrick 24061da546Spatrick /// \class ClangUtilityFunction ClangUtilityFunction.h 25061da546Spatrick /// "lldb/Expression/ClangUtilityFunction.h" Encapsulates a single expression 26061da546Spatrick /// for use with Clang 27061da546Spatrick /// 28061da546Spatrick /// LLDB uses expressions for various purposes, notably to call functions 29061da546Spatrick /// and as a backend for the expr command. ClangUtilityFunction encapsulates 30061da546Spatrick /// a self-contained function meant to be used from other code. Utility 31061da546Spatrick /// functions can perform error-checking for ClangUserExpressions, or can 32061da546Spatrick /// simply provide a way to push a function into the target for the debugger 33061da546Spatrick /// to call later on. 34061da546Spatrick class ClangUtilityFunction : public UtilityFunction { 35061da546Spatrick // LLVM RTTI support 36061da546Spatrick static char ID; 37061da546Spatrick 38061da546Spatrick public: isA(const void * ClassID)39061da546Spatrick bool isA(const void *ClassID) const override { 40061da546Spatrick return ClassID == &ID || UtilityFunction::isA(ClassID); 41061da546Spatrick } classof(const Expression * obj)42061da546Spatrick static bool classof(const Expression *obj) { return obj->isA(&ID); } 43061da546Spatrick 44061da546Spatrick /// Constructor 45061da546Spatrick /// 46061da546Spatrick /// \param[in] text 47061da546Spatrick /// The text of the function. Must be a full translation unit. 48061da546Spatrick /// 49061da546Spatrick /// \param[in] name 50061da546Spatrick /// The name of the function, as used in the text. 51*be691f3bSpatrick /// 52*be691f3bSpatrick /// \param[in] enable_debugging 53*be691f3bSpatrick /// Enable debugging of this function. 54*be691f3bSpatrick ClangUtilityFunction(ExecutionContextScope &exe_scope, std::string text, 55*be691f3bSpatrick std::string name, bool enable_debugging); 56061da546Spatrick 57061da546Spatrick ~ClangUtilityFunction() override; 58061da546Spatrick GetTypeSystemHelper()59061da546Spatrick ExpressionTypeSystemHelper *GetTypeSystemHelper() override { 60061da546Spatrick return &m_type_system_helper; 61061da546Spatrick } 62061da546Spatrick DeclMap()63061da546Spatrick ClangExpressionDeclMap *DeclMap() { return m_type_system_helper.DeclMap(); } 64061da546Spatrick ResetDeclMap()65061da546Spatrick void ResetDeclMap() { m_type_system_helper.ResetDeclMap(); } 66061da546Spatrick ResetDeclMap(ExecutionContext & exe_ctx,bool keep_result_in_memory)67061da546Spatrick void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory) { 68061da546Spatrick m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory); 69061da546Spatrick } 70061da546Spatrick 71061da546Spatrick bool Install(DiagnosticManager &diagnostic_manager, 72061da546Spatrick ExecutionContext &exe_ctx) override; 73061da546Spatrick 74061da546Spatrick private: 75*be691f3bSpatrick class ClangUtilityFunctionHelper : public ClangExpressionHelper { 76*be691f3bSpatrick public: 77*be691f3bSpatrick ClangUtilityFunctionHelper() = default; 78*be691f3bSpatrick 79*be691f3bSpatrick ~ClangUtilityFunctionHelper() override = default; 80*be691f3bSpatrick 81*be691f3bSpatrick /// Return the object that the parser should use when resolving external 82*be691f3bSpatrick /// values. May be NULL if everything should be self-contained. DeclMap()83*be691f3bSpatrick ClangExpressionDeclMap *DeclMap() override { 84*be691f3bSpatrick return m_expr_decl_map_up.get(); 85*be691f3bSpatrick } 86*be691f3bSpatrick ResetDeclMap()87*be691f3bSpatrick void ResetDeclMap() { m_expr_decl_map_up.reset(); } 88*be691f3bSpatrick 89*be691f3bSpatrick void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory); 90*be691f3bSpatrick 91*be691f3bSpatrick /// Return the object that the parser should allow to access ASTs. May be 92*be691f3bSpatrick /// nullptr if the ASTs do not need to be transformed. 93*be691f3bSpatrick /// 94*be691f3bSpatrick /// \param[in] passthrough 95*be691f3bSpatrick /// The ASTConsumer that the returned transformer should send 96*be691f3bSpatrick /// the ASTs to after transformation. 97*be691f3bSpatrick clang::ASTConsumer * ASTTransformer(clang::ASTConsumer * passthrough)98*be691f3bSpatrick ASTTransformer(clang::ASTConsumer *passthrough) override { 99*be691f3bSpatrick return nullptr; 100*be691f3bSpatrick } 101*be691f3bSpatrick 102*be691f3bSpatrick private: 103*be691f3bSpatrick std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up; 104*be691f3bSpatrick }; 105*be691f3bSpatrick 106*be691f3bSpatrick /// The map to use when parsing and materializing the expression. 107*be691f3bSpatrick ClangUtilityFunctionHelper m_type_system_helper; 108061da546Spatrick }; 109061da546Spatrick 110061da546Spatrick } // namespace lldb_private 111061da546Spatrick 112dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H 113