1 //===-- ClangPersistentVariables.h ------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_ClangPersistentVariables_h_
10 #define liblldb_ClangPersistentVariables_h_
12 #include "llvm/ADT/DenseMap.h"
14 #include "ClangExpressionVariable.h"
15 #include "ClangModulesDeclVendor.h"
17 #include "lldb/Expression/ExpressionVariable.h"
19 namespace lldb_private {
21 /// \class ClangPersistentVariables ClangPersistentVariables.h
22 /// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values
23 /// that need to be preserved between expression invocations.
25 /// A list of variables that can be accessed and updated by any expression. See
26 /// ClangPersistentVariable for more discussion. Also provides an increasing,
27 /// 0-based counter for naming result variables.
28 class ClangPersistentVariables : public PersistentExpressionState {
30 ClangPersistentVariables();
32 ~ClangPersistentVariables() override = default;
34 // llvm casting support
35 static bool classof(const PersistentExpressionState *pv) {
36 return pv->getKind() == PersistentExpressionState::eKindClang;
39 lldb::ExpressionVariableSP
40 CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
42 lldb::ExpressionVariableSP CreatePersistentVariable(
43 ExecutionContextScope *exe_scope, ConstString name,
44 const CompilerType &compiler_type, lldb::ByteOrder byte_order,
45 uint32_t addr_byte_size) override;
47 void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
49 llvm::StringRef GetPersistentVariablePrefix(bool is_error) const override {
53 /// Returns the next file name that should be used for user expressions.
54 std::string GetNextExprFileName() {
56 name.append("<user expression ");
57 name.append(std::to_string(m_next_user_file_id++));
62 llvm::Optional<CompilerType>
63 GetCompilerTypeFromPersistentDecl(ConstString type_name) override;
65 void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl);
67 clang::NamedDecl *GetPersistentDecl(ConstString name);
69 void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) {
70 m_hand_loaded_clang_modules.push_back(module);
73 const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() {
74 return m_hand_loaded_clang_modules;
78 /// The counter used by GetNextExprFileName.
79 uint32_t m_next_user_file_id = 0;
80 // The counter used by GetNextPersistentVariableName
81 uint32_t m_next_persistent_variable_id = 0;
83 typedef llvm::DenseMap<const char *, clang::NamedDecl *> PersistentDeclMap;
85 m_persistent_decls; ///< Persistent entities declared by the user.
87 ClangModulesDeclVendor::ModuleVector
88 m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;
89 ///these are the highest-
90 ///< priority source for macros.
93 } // namespace lldb_private
95 #endif // liblldb_ClangPersistentVariables_h_