summaryrefslogtreecommitdiffstats
path: root/lldb/source/Expression/ClangPersistentVariables.cpp
blob: dbeac0062503f167971ac8264ac5f162de37ee80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//===-- ClangPersistentVariables.cpp ----------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "ClangPersistentVariables.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"

using namespace lldb_private;
using namespace clang;

ClangPersistentVariables::ClangPersistentVariables () :
    m_variables(),
    m_result_counter(0)
{
}

ClangPersistentVariable *
ClangPersistentVariables::CreateVariable (ConstString name, 
                                          TypeFromUser user_type)
{    
    ClangPersistentVariable new_var(user_type);
    
    if (m_variables.find(name) != m_variables.end())
        return NULL;
    
    m_variables[name] = new_var;
    
    return &m_variables[name];
}

ClangPersistentVariable *
ClangPersistentVariables::CreateResultVariable (TypeFromUser user_type)
{    
    StreamString s;
    s.Printf("$%llu", m_result_counter);
    ConstString name(s.GetString().c_str());
    
    ClangPersistentVariable *ret = CreateVariable (name, user_type);
    
    if (ret != NULL)
        ++m_result_counter;
    
    return ret;
}

ClangPersistentVariable *
ClangPersistentVariables::GetVariable (ConstString name)
{    
    if (m_variables.find(name) == m_variables.end())
        return NULL;
    
    return &m_variables[name];
}
OpenPOWER on IntegriCloud