Sean Callanan | a48fe16 | 2010-08-11 03:57:18 +0000 | [diff] [blame^] | 1 | //===-- ClangPersistentVariables.cpp ----------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "ClangPersistentVariables.h" |
| 11 | #include "lldb/Core/Log.h" |
| 12 | #include "lldb/Core/StreamString.h" |
| 13 | |
| 14 | using namespace lldb_private; |
| 15 | using namespace clang; |
| 16 | |
| 17 | ClangPersistentVariables::ClangPersistentVariables () : |
| 18 | m_variables(), |
| 19 | m_result_counter(0) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | ClangPersistentVariable * |
| 24 | ClangPersistentVariables::CreateVariable (ConstString name, |
| 25 | TypeFromUser user_type) |
| 26 | { |
| 27 | ClangPersistentVariable new_var(user_type); |
| 28 | |
| 29 | if (m_variables.find(name) != m_variables.end()) |
| 30 | return NULL; |
| 31 | |
| 32 | m_variables[name] = new_var; |
| 33 | |
| 34 | return &m_variables[name]; |
| 35 | } |
| 36 | |
| 37 | ClangPersistentVariable * |
| 38 | ClangPersistentVariables::CreateResultVariable (TypeFromUser user_type) |
| 39 | { |
| 40 | StreamString s; |
| 41 | s.Printf("$%llu", m_result_counter); |
| 42 | ConstString name(s.GetString().c_str()); |
| 43 | |
| 44 | ClangPersistentVariable *ret = CreateVariable (name, user_type); |
| 45 | |
| 46 | if (ret != NULL) |
| 47 | ++m_result_counter; |
| 48 | |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | ClangPersistentVariable * |
| 53 | ClangPersistentVariables::GetVariable (ConstString name) |
| 54 | { |
| 55 | if (m_variables.find(name) == m_variables.end()) |
| 56 | return NULL; |
| 57 | |
| 58 | return &m_variables[name]; |
| 59 | } |