LLDB mainline
ClangPersistentVariables.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
11
12#include "llvm/ADT/DenseMap.h"
13
16
18#include <optional>
19
20namespace lldb_private {
21
22class ClangASTImporter;
23class ClangModulesDeclVendor;
24class Target;
25class TypeSystemClang;
26
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.
35 : public llvm::RTTIExtends<ClangPersistentVariables,
36 PersistentExpressionState> {
37public:
38 // LLVM RTTI support
39 static char ID;
40
41 ClangPersistentVariables(std::shared_ptr<Target> target_sp);
42
43 ~ClangPersistentVariables() override = default;
44
45 std::shared_ptr<ClangASTImporter> GetClangASTImporter();
46 std::shared_ptr<ClangModulesDeclVendor> GetClangModulesDeclVendor();
47
49 CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
50
52 ExecutionContextScope *exe_scope, ConstString name,
53 const CompilerType &compiler_type, lldb::ByteOrder byte_order,
54 uint32_t addr_byte_size) override;
55
57
58 ConstString GetNextPersistentVariableName(bool is_error = false) override;
59
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;
67 }
68
69 std::optional<CompilerType>
71
72 void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl,
73 std::shared_ptr<TypeSystemClang> ctx);
74
75 clang::NamedDecl *GetPersistentDecl(ConstString name);
76
78 m_hand_loaded_clang_modules.push_back(module);
79 }
80
83 }
84
85protected:
86 llvm::StringRef
87 GetPersistentVariablePrefix(bool is_error = false) const override {
88 return "$";
89 }
90
91private:
92 /// The counter used by GetNextExprFileName.
93 uint32_t m_next_user_file_id = 0;
94 // The counter used by GetNextPersistentVariableName
96
98 /// The persistent decl.
99 clang::NamedDecl *m_decl = nullptr;
100 /// The TypeSystemClang for the ASTContext of m_decl.
102 };
103
104 typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap;
106 m_persistent_decls; ///< Persistent entities declared by the user.
107
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;
115};
116
117} // namespace lldb_private
118
119#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
"lldb/Expression/ClangPersistentVariables.h" Manages persistent values that need to be preserved betw...
std::string GetNextExprFileName()
Returns the next file name that should be used for user expressions.
void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl, std::shared_ptr< TypeSystemClang > ctx)
ConstString GetNextPersistentVariableName(bool is_error=false) override
ClangModulesDeclVendor::ModuleVector m_hand_loaded_clang_modules
These are Clang modules we hand-loaded; these are the highest- priority source for macros.
std::shared_ptr< ClangModulesDeclVendor > GetClangModulesDeclVendor()
lldb::ExpressionVariableSP CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override
void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module)
clang::NamedDecl * GetPersistentDecl(ConstString name)
void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override
std::shared_ptr< ClangModulesDeclVendor > m_modules_decl_vendor_sp
~ClangPersistentVariables() override=default
llvm::DenseMap< const char *, PersistentDecl > PersistentDeclMap
PersistentDeclMap m_persistent_decls
Persistent entities declared by the user.
std::shared_ptr< ClangASTImporter > GetClangASTImporter()
std::optional< CompilerType > GetCompilerTypeFromPersistentDecl(ConstString type_name) override
llvm::StringRef GetPersistentVariablePrefix(bool is_error=false) const override
const ClangModulesDeclVendor::ModuleVector & GetHandLoadedClangModules()
std::shared_ptr< ClangASTImporter > m_ast_importer_sp
uint32_t m_next_user_file_id
The counter used by GetNextExprFileName.
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
Definition: lldb-forward.h:351
ByteOrder
Byte ordering definitions.
std::weak_ptr< lldb_private::TypeSystem > TypeSystemWP
Definition: lldb-forward.h:471
lldb::TypeSystemWP m_context
The TypeSystemClang for the ASTContext of m_decl.