Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
Line
Count
Source
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
14
#include "ClangExpressionVariable.h"
15
#include "ClangModulesDeclVendor.h"
16
17
#include "lldb/Expression/ExpressionVariable.h"
18
#include <optional>
19
20
namespace lldb_private {
21
22
class ClangASTImporter;
23
class ClangModulesDeclVendor;
24
class Target;
25
class 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.
34
class ClangPersistentVariables
35
    : public llvm::RTTIExtends<ClangPersistentVariables,
36
                               PersistentExpressionState> {
37
public:
38
  // LLVM RTTI support
39
  static char ID;
40
41
  ClangPersistentVariables(std::shared_ptr<Target> target_sp);
42
43
2.03k
  ~ClangPersistentVariables() override = default;
44
45
  std::shared_ptr<ClangASTImporter> GetClangASTImporter();
46
  std::shared_ptr<ClangModulesDeclVendor> GetClangModulesDeclVendor();
47
48
  lldb::ExpressionVariableSP
49
  CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
50
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;
55
56
  void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
57
58
  ConstString GetNextPersistentVariableName(bool is_error = false) override;
59
60
  /// Returns the next file name that should be used for user expressions.
61
7.26k
  std::string GetNextExprFileName() {
62
7.26k
    std::string name;
63
7.26k
    name.append("<user expression ");
64
7.26k
    name.append(std::to_string(m_next_user_file_id++));
65
7.26k
    name.append(">");
66
7.26k
    return name;
67
7.26k
  }
68
69
  std::optional<CompilerType>
70
  GetCompilerTypeFromPersistentDecl(ConstString type_name) override;
71
72
  void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl,
73
                              std::shared_ptr<TypeSystemClang> ctx);
74
75
  clang::NamedDecl *GetPersistentDecl(ConstString name);
76
77
7.29k
  void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) {
78
7.29k
    m_hand_loaded_clang_modules.push_back(module);
79
7.29k
  }
80
81
14.0k
  const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() {
82
14.0k
    return m_hand_loaded_clang_modules;
83
14.0k
  }
84
85
protected:
86
  llvm::StringRef
87
7.26k
  GetPersistentVariablePrefix(bool is_error = false) const override {
88
7.26k
    return "$";
89
7.26k
  }
90
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;
96
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;
102
  };
103
104
  typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap;
105
  PersistentDeclMap
106
      m_persistent_decls; ///< Persistent entities declared by the user.
107
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;
115
};
116
117
} // namespace lldb_private
118
119
#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H