Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
39648 views
//===-- ClangUtilityFunction.h ----------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H1011#include <map>12#include <string>13#include <vector>1415#include "ClangExpressionHelper.h"1617#include "lldb/Expression/UtilityFunction.h"18#include "lldb/lldb-forward.h"19#include "lldb/lldb-private.h"2021namespace lldb_private {2223/// \class ClangUtilityFunction ClangUtilityFunction.h24/// "lldb/Expression/ClangUtilityFunction.h" Encapsulates a single expression25/// for use with Clang26///27/// LLDB uses expressions for various purposes, notably to call functions28/// and as a backend for the expr command. ClangUtilityFunction encapsulates29/// a self-contained function meant to be used from other code. Utility30/// functions can perform error-checking for ClangUserExpressions, or can31/// simply provide a way to push a function into the target for the debugger32/// to call later on.33class ClangUtilityFunction : public UtilityFunction {34// LLVM RTTI support35static char ID;3637public:38bool isA(const void *ClassID) const override {39return ClassID == &ID || UtilityFunction::isA(ClassID);40}41static bool classof(const Expression *obj) { return obj->isA(&ID); }4243/// Constructor44///45/// \param[in] text46/// The text of the function. Must be a full translation unit.47///48/// \param[in] name49/// The name of the function, as used in the text.50///51/// \param[in] enable_debugging52/// Enable debugging of this function.53ClangUtilityFunction(ExecutionContextScope &exe_scope, std::string text,54std::string name, bool enable_debugging);5556~ClangUtilityFunction() override;5758ExpressionTypeSystemHelper *GetTypeSystemHelper() override {59return &m_type_system_helper;60}6162ClangExpressionDeclMap *DeclMap() { return m_type_system_helper.DeclMap(); }6364void ResetDeclMap() { m_type_system_helper.ResetDeclMap(); }6566void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory) {67m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);68}6970bool Install(DiagnosticManager &diagnostic_manager,71ExecutionContext &exe_ctx) override;7273private:74class ClangUtilityFunctionHelper75: public llvm::RTTIExtends<ClangUtilityFunctionHelper,76ClangExpressionHelper> {77public:78// LLVM RTTI support79static char ID;8081/// Return the object that the parser should use when resolving external82/// values. May be NULL if everything should be self-contained.83ClangExpressionDeclMap *DeclMap() override {84return m_expr_decl_map_up.get();85}8687void ResetDeclMap() { m_expr_decl_map_up.reset(); }8889void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory);9091/// Return the object that the parser should allow to access ASTs. May be92/// nullptr if the ASTs do not need to be transformed.93///94/// \param[in] passthrough95/// The ASTConsumer that the returned transformer should send96/// the ASTs to after transformation.97clang::ASTConsumer *98ASTTransformer(clang::ASTConsumer *passthrough) override {99return nullptr;100}101102private:103std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up;104};105106/// The map to use when parsing and materializing the expression.107ClangUtilityFunctionHelper m_type_system_helper;108};109110} // namespace lldb_private111112#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGUTILITYFUNCTION_H113114115