Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / ExpressionParser / Clang / ClangPersistentVariables.h
blobabeb431ccc08bab0846427fb1129a3534883ce61
1 //===-- ClangPersistentVariables.h ------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
12 #include "llvm/ADT/DenseMap.h"
14 #include "ClangExpressionVariable.h"
15 #include "ClangModulesDeclVendor.h"
17 #include "lldb/Expression/ExpressionVariable.h"
18 #include <optional>
20 namespace lldb_private {
22 class ClangASTImporter;
23 class ClangModulesDeclVendor;
24 class Target;
25 class TypeSystemClang;
27 /// \class ClangPersistentVariables ClangPersistentVariables.h
28 /// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values
29 /// that need to be preserved between expression invocations.
30 ///
31 /// A list of variables that can be accessed and updated by any expression. See
32 /// ClangPersistentVariable for more discussion. Also provides an increasing,
33 /// 0-based counter for naming result variables.
34 class ClangPersistentVariables
35 : public llvm::RTTIExtends<ClangPersistentVariables,
36 PersistentExpressionState> {
37 public:
38 // LLVM RTTI support
39 static char ID;
41 ClangPersistentVariables(std::shared_ptr<Target> target_sp);
43 ~ClangPersistentVariables() override = default;
45 std::shared_ptr<ClangASTImporter> GetClangASTImporter();
46 std::shared_ptr<ClangModulesDeclVendor> GetClangModulesDeclVendor();
48 lldb::ExpressionVariableSP
49 CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
51 lldb::ExpressionVariableSP CreatePersistentVariable(
52 ExecutionContextScope *exe_scope, ConstString name,
53 const CompilerType &compiler_type, lldb::ByteOrder byte_order,
54 uint32_t addr_byte_size) override;
56 void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
58 ConstString GetNextPersistentVariableName(bool is_error = false) override;
60 /// Returns the next file name that should be used for user expressions.
61 std::string GetNextExprFileName() {
62 std::string name;
63 name.append("<user expression ");
64 name.append(std::to_string(m_next_user_file_id++));
65 name.append(">");
66 return name;
69 std::optional<CompilerType>
70 GetCompilerTypeFromPersistentDecl(ConstString type_name) override;
72 void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl,
73 std::shared_ptr<TypeSystemClang> ctx);
75 clang::NamedDecl *GetPersistentDecl(ConstString name);
77 void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) {
78 m_hand_loaded_clang_modules.push_back(module);
81 const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() {
82 return m_hand_loaded_clang_modules;
85 protected:
86 llvm::StringRef
87 GetPersistentVariablePrefix(bool is_error = false) const override {
88 return "$";
91 private:
92 /// The counter used by GetNextExprFileName.
93 uint32_t m_next_user_file_id = 0;
94 // The counter used by GetNextPersistentVariableName
95 uint32_t m_next_persistent_variable_id = 0;
97 struct PersistentDecl {
98 /// The persistent decl.
99 clang::NamedDecl *m_decl = nullptr;
100 /// The TypeSystemClang for the ASTContext of m_decl.
101 lldb::TypeSystemWP m_context;
104 typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap;
105 PersistentDeclMap
106 m_persistent_decls; ///< Persistent entities declared by the user.
108 ClangModulesDeclVendor::ModuleVector
109 m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;
110 ///these are the highest-
111 ///< priority source for macros.
112 std::shared_ptr<ClangASTImporter> m_ast_importer_sp;
113 std::shared_ptr<ClangModulesDeclVendor> m_modules_decl_vendor_sp;
114 std::shared_ptr<Target> m_target_sp;
117 } // namespace lldb_private
119 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H