blob: dbeac0062503f167971ac8264ac5f162de37ee80 [file] [log] [blame]
Sean Callanana48fe162010-08-11 03:57:18 +00001//===-- 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
14using namespace lldb_private;
15using namespace clang;
16
17ClangPersistentVariables::ClangPersistentVariables () :
18 m_variables(),
19 m_result_counter(0)
20{
21}
22
23ClangPersistentVariable *
24ClangPersistentVariables::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
37ClangPersistentVariable *
38ClangPersistentVariables::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
52ClangPersistentVariable *
53ClangPersistentVariables::GetVariable (ConstString name)
54{
55 if (m_variables.find(name) == m_variables.end())
56 return NULL;
57
58 return &m_variables[name];
59}