ClangPersistentVariables.cpp revision 254721
1214455Srpaulo//===-- ClangPersistentVariables.cpp ----------------------------*- C++ -*-===// 2214455Srpaulo// 3214455Srpaulo// The LLVM Compiler Infrastructure 4214455Srpaulo// 5214455Srpaulo// This file is distributed under the University of Illinois Open Source 6214455Srpaulo// License. See LICENSE.TXT for details. 7214455Srpaulo// 8214455Srpaulo//===----------------------------------------------------------------------===// 9214455Srpaulo 10214455Srpaulo#include "lldb/Expression/ClangPersistentVariables.h" 11214455Srpaulo#include "lldb/Core/DataExtractor.h" 12214455Srpaulo#include "lldb/Core/Log.h" 13214455Srpaulo#include "lldb/Core/StreamString.h" 14214455Srpaulo#include "lldb/Core/Value.h" 15214455Srpaulo 16214455Srpaulo#include "llvm/ADT/StringMap.h" 17214455Srpaulo 18214455Srpaulousing namespace lldb; 19214455Srpaulousing namespace lldb_private; 20214455Srpaulo 21214455SrpauloClangPersistentVariables::ClangPersistentVariables () : 22214455Srpaulo ClangExpressionVariableList(), 23214455Srpaulo m_next_persistent_variable_id (0) 24214455Srpaulo{ 25214455Srpaulo} 26214455Srpaulo 27214455SrpauloClangExpressionVariableSP 28214455SrpauloClangPersistentVariables::CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp) 29214455Srpaulo{ 30214455Srpaulo ClangExpressionVariableSP var_sp (CreateVariable(valobj_sp)); 31214455Srpaulo return var_sp; 32} 33 34ClangExpressionVariableSP 35ClangPersistentVariables::CreatePersistentVariable (ExecutionContextScope *exe_scope, 36 const ConstString &name, 37 const TypeFromUser& user_type, 38 lldb::ByteOrder byte_order, 39 uint32_t addr_byte_size) 40{ 41 ClangExpressionVariableSP var_sp (GetVariable(name)); 42 43 if (!var_sp) 44 var_sp = CreateVariable(exe_scope, name, user_type, byte_order, addr_byte_size); 45 46 return var_sp; 47} 48 49void 50ClangPersistentVariables::RemovePersistentVariable (lldb::ClangExpressionVariableSP variable) 51{ 52 RemoveVariable(variable); 53 54 const char *name = variable->GetName().AsCString(); 55 56 if (*name != '$') 57 return; 58 name++; 59 60 if (strtoul(name, NULL, 0) == m_next_persistent_variable_id - 1) 61 m_next_persistent_variable_id--; 62} 63 64ConstString 65ClangPersistentVariables::GetNextPersistentVariableName () 66{ 67 char name_cstr[256]; 68 ::snprintf (name_cstr, sizeof(name_cstr), "$%u", m_next_persistent_variable_id++); 69 ConstString name(name_cstr); 70 return name; 71} 72 73void 74ClangPersistentVariables::RegisterPersistentType (const ConstString &name, 75 clang::TypeDecl *type_decl) 76{ 77 m_persistent_types.insert(std::pair<const char*, clang::TypeDecl*>(name.GetCString(), type_decl)); 78} 79 80clang::TypeDecl * 81ClangPersistentVariables::GetPersistentType (const ConstString &name) 82{ 83 PersistentTypeMap::const_iterator i = m_persistent_types.find(name.GetCString()); 84 85 if (i == m_persistent_types.end()) 86 return NULL; 87 else 88 return i->second; 89} 90