1 //===-- ClangPersistentVariables.cpp ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Expression/ClangPersistentVariables.h"
11 #include "lldb/Core/DataExtractor.h"
12 #include "lldb/Core/Log.h"
13 #include "lldb/Core/StreamString.h"
14 #include "lldb/Core/Value.h"
16 #include "llvm/ADT/StringMap.h"
19 using namespace lldb_private;
21 ClangPersistentVariables::ClangPersistentVariables () :
22 ClangExpressionVariableList(),
23 m_next_persistent_variable_id (0)
27 ClangExpressionVariableSP
28 ClangPersistentVariables::CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp)
30 ClangExpressionVariableSP var_sp (CreateVariable(valobj_sp));
34 ClangExpressionVariableSP
35 ClangPersistentVariables::CreatePersistentVariable (ExecutionContextScope *exe_scope,
36 const ConstString &name,
37 const TypeFromUser& user_type,
38 lldb::ByteOrder byte_order,
39 uint32_t addr_byte_size)
41 ClangExpressionVariableSP var_sp (GetVariable(name));
44 var_sp = CreateVariable(exe_scope, name, user_type, byte_order, addr_byte_size);
50 ClangPersistentVariables::RemovePersistentVariable (lldb::ClangExpressionVariableSP variable)
52 RemoveVariable(variable);
54 const char *name = variable->GetName().AsCString();
60 if (strtoul(name, NULL, 0) == m_next_persistent_variable_id - 1)
61 m_next_persistent_variable_id--;
65 ClangPersistentVariables::GetNextPersistentVariableName ()
68 ::snprintf (name_cstr, sizeof(name_cstr), "$%u", m_next_persistent_variable_id++);
69 ConstString name(name_cstr);
74 ClangPersistentVariables::RegisterPersistentType (const ConstString &name,
75 clang::TypeDecl *type_decl)
77 m_persistent_types.insert(std::pair<const char*, clang::TypeDecl*>(name.GetCString(), type_decl));
81 ClangPersistentVariables::GetPersistentType (const ConstString &name)
83 PersistentTypeMap::const_iterator i = m_persistent_types.find(name.GetCString());
85 if (i == m_persistent_types.end())