brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · abeb431 Raw
120 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H11 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 20namespace lldb_private {21 22class ClangASTImporter;23class ClangModulesDeclVendor;24class Target;25class TypeSystemClang;26 27/// \class ClangPersistentVariables ClangPersistentVariables.h28/// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values29/// that need to be preserved between expression invocations.30///31/// A list of variables that can be accessed and updated by any expression.  See32/// ClangPersistentVariable for more discussion.  Also provides an increasing,33/// 0-based counter for naming result variables.34class ClangPersistentVariables35    : public llvm::RTTIExtends<ClangPersistentVariables,36                               PersistentExpressionState> {37public:38  // LLVM RTTI support39  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 48  lldb::ExpressionVariableSP49  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  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>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  void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) {78    m_hand_loaded_clang_modules.push_back(module);79  }80 81  const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() {82    return m_hand_loaded_clang_modules;83  }84 85protected:86  llvm::StringRef87  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 GetNextPersistentVariableName95  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  PersistentDeclMap106      m_persistent_decls; ///< Persistent entities declared by the user.107 108  ClangModulesDeclVendor::ModuleVector109      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_private118 119#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H120