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 
15 #include "ClangModulesDeclVendor.h"
16 
18 
19 namespace lldb_private {
20 
21 class ClangASTImporter;
22 class TypeSystemClang;
23 
24 /// \class ClangPersistentVariables ClangPersistentVariables.h
25 /// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values
26 /// that need to be preserved between expression invocations.
27 ///
28 /// A list of variables that can be accessed and updated by any expression. See
29 /// ClangPersistentVariable for more discussion. Also provides an increasing,
30 /// 0-based counter for naming result variables.
32 public:
34 
35  ~ClangPersistentVariables() override = default;
36 
37  // llvm casting support
38  static bool classof(const PersistentExpressionState *pv) {
40  }
41 
42  std::shared_ptr<ClangASTImporter> GetClangASTImporter();
43 
44  lldb::ExpressionVariableSP
45  CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
46 
47  lldb::ExpressionVariableSP CreatePersistentVariable(
48  ExecutionContextScope *exe_scope, ConstString name,
49  const CompilerType &compiler_type, lldb::ByteOrder byte_order,
50  uint32_t addr_byte_size) override;
51 
52  void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
53 
54  ConstString GetNextPersistentVariableName(bool is_error = false) override;
55 
56  /// Returns the next file name that should be used for user expressions.
58  std::string name;
59  name.append("<user expression ");
60  name.append(std::to_string(m_next_user_file_id++));
61  name.append(">");
62  return name;
63  }
64 
65  llvm::Optional<CompilerType>
67 
68  void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl,
69  TypeSystemClang *ctx);
70 
71  clang::NamedDecl *GetPersistentDecl(ConstString name);
72 
74  m_hand_loaded_clang_modules.push_back(module);
75  }
76 
79  }
80 
81 protected:
82  llvm::StringRef
83  GetPersistentVariablePrefix(bool is_error = false) const override {
84  return "$";
85  }
86 
87 private:
88  /// The counter used by GetNextExprFileName.
90  // The counter used by GetNextPersistentVariableName
92 
93  struct PersistentDecl {
94  /// The persistent decl.
95  clang::NamedDecl *m_decl = nullptr;
96  /// The TypeSystemClang for the ASTContext of m_decl.
98  };
99 
100  typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap;
102  m_persistent_decls; ///< Persistent entities declared by the user.
103 
105  m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;
106  ///these are the highest-
107  ///< priority source for macros.
108  std::shared_ptr<ClangASTImporter> m_ast_importer_sp;
109 };
110 
111 } // namespace lldb_private
112 
113 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
ExpressionVariable.h
lldb_private::ClangPersistentVariables::GetPersistentDecl
clang::NamedDecl * GetPersistentDecl(ConstString name)
Definition: ClangPersistentVariables.cpp:100
lldb_private::ClangPersistentVariables
Definition: ClangPersistentVariables.h:31
ClangModulesDeclVendor.h
lldb_private::ClangPersistentVariables::PersistentDecl
Definition: ClangPersistentVariables.h:93
lldb_private::ClangPersistentVariables::m_hand_loaded_clang_modules
ClangModulesDeclVendor::ModuleVector m_hand_loaded_clang_modules
These are Clang modules we hand-loaded; these are the highest- priority source for macros.
Definition: ClangPersistentVariables.h:105
lldb_private::ClangPersistentVariables::PersistentDecl::m_decl
clang::NamedDecl * m_decl
The persistent decl.
Definition: ClangPersistentVariables.h:95
lldb_private::ClangPersistentVariables::GetClangASTImporter
std::shared_ptr< ClangASTImporter > GetClangASTImporter()
Definition: ClangPersistentVariables.cpp:105
lldb_private::PersistentExpressionState::getKind
LLVMCastKind getKind() const
Definition: ExpressionVariable.h:208
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::ClangModulesDeclVendor::ModuleVector
std::vector< ModuleID > ModuleVector
Definition: ClangModulesDeclVendor.h:37
lldb_private::PersistentExpressionState::eKindClang
@ eKindClang
Definition: ExpressionVariable.h:206
lldb_private::ClangPersistentVariables::GetCompilerTypeFromPersistentDecl
llvm::Optional< CompilerType > GetCompilerTypeFromPersistentDecl(ConstString type_name) override
Definition: ClangPersistentVariables.cpp:69
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ClangPersistentVariables::AddHandLoadedClangModule
void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module)
Definition: ClangPersistentVariables.h:73
lldb_private::ClangModulesDeclVendor::ModuleID
uintptr_t ModuleID
Definition: ClangModulesDeclVendor.h:36
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::ClangPersistentVariables::m_next_user_file_id
uint32_t m_next_user_file_id
The counter used by GetNextExprFileName.
Definition: ClangPersistentVariables.h:89
lldb_private::ClangPersistentVariables::~ClangPersistentVariables
~ClangPersistentVariables() override=default
lldb_private::ClangPersistentVariables::ClangPersistentVariables
ClangPersistentVariables()
Definition: ClangPersistentVariables.cpp:26
lldb_private::ClangPersistentVariables::GetHandLoadedClangModules
const ClangModulesDeclVendor::ModuleVector & GetHandLoadedClangModules()
Definition: ClangPersistentVariables.h:77
uint32_t
lldb_private::ClangPersistentVariables::classof
static bool classof(const PersistentExpressionState *pv)
Definition: ClangPersistentVariables.h:38
lldb_private::ClangPersistentVariables::PersistentDecl::m_context
TypeSystemClang * m_context
The TypeSystemClang for the ASTContext of m_decl.
Definition: ClangPersistentVariables.h:97
lldb_private::ClangPersistentVariables::GetNextPersistentVariableName
ConstString GetNextPersistentVariableName(bool is_error=false) override
Return a new persistent variable name with the specified prefix.
Definition: ClangPersistentVariables.cpp:113
lldb_private::ClangPersistentVariables::RegisterPersistentDecl
void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl, TypeSystemClang *ctx)
Definition: ClangPersistentVariables.cpp:84
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::ClangPersistentVariables::PersistentDeclMap
llvm::DenseMap< const char *, PersistentDecl > PersistentDeclMap
Definition: ClangPersistentVariables.h:100
lldb_private::ClangPersistentVariables::m_next_persistent_variable_id
uint32_t m_next_persistent_variable_id
Definition: ClangPersistentVariables.h:91
lldb_private::PersistentExpressionState
Definition: ExpressionVariable.h:203
lldb_private::ClangPersistentVariables::CreatePersistentVariable
lldb::ExpressionVariableSP CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override
Definition: ClangPersistentVariables.cpp:29
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:106
ClangExpressionVariable.h
lldb_private::ClangPersistentVariables::GetNextExprFileName
std::string GetNextExprFileName()
Returns the next file name that should be used for user expressions.
Definition: ClangPersistentVariables.h:57
lldb_private::ClangPersistentVariables::m_persistent_decls
PersistentDeclMap m_persistent_decls
Persistent entities declared by the user.
Definition: ClangPersistentVariables.h:102
lldb_private::ClangPersistentVariables::m_ast_importer_sp
std::shared_ptr< ClangASTImporter > m_ast_importer_sp
Definition: ClangPersistentVariables.h:108
lldb_private::ClangPersistentVariables::GetPersistentVariablePrefix
llvm::StringRef GetPersistentVariablePrefix(bool is_error=false) const override
Definition: ClangPersistentVariables.h:83
lldb_private::ClangPersistentVariables::RemovePersistentVariable
void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override
Definition: ClangPersistentVariables.cpp:42
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138