blob: dce0316983c948986ce87eb925ec806aa82b5973 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- ClangExpressionVariable.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 "lldb/Expression/ClangExpressionVariable.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "clang/AST/ASTContext.h"
17
18using namespace lldb_private;
19using namespace clang;
20
21ClangExpressionVariableList::ClangExpressionVariableList() :
22 m_variables()
23{
24}
25
26ClangExpressionVariableList::~ClangExpressionVariableList()
27{
28 uint32_t num_variables = m_variables.size();
29 uint32_t var_index;
30
31 for (var_index = 0; var_index < num_variables; ++var_index)
32 delete m_variables[var_index].m_value;
33}
34
35Value *
Sean Callanan4a7c6c62010-08-13 22:52:29 +000036ValueForDecl(const VarDecl *var_decl)
Chris Lattner24943d22010-06-08 16:52:24 +000037{
38 Value *ret = new Value;
39
40 ret->SetContext(Value::eContextTypeOpaqueClangQualType,
41 var_decl->getType().getAsOpaquePtr());
42
Sean Callanan4a7c6c62010-08-13 22:52:29 +000043 uint64_t bit_width = var_decl->getASTContext().getTypeSize(var_decl->getType());
Chris Lattner24943d22010-06-08 16:52:24 +000044
45 uint32_t byte_size = (bit_width + 7 ) / 8;
46
47 ret->ResizeData(byte_size);
48
49 return ret;
50}
51
52Value *
Sean Callanan4a7c6c62010-08-13 22:52:29 +000053ClangExpressionVariableList::GetVariableForVarDecl (const VarDecl *var_decl, uint32_t& idx, bool can_create)
Chris Lattner24943d22010-06-08 16:52:24 +000054{
55 uint32_t num_variables = m_variables.size();
56 uint32_t var_index;
57
58 for (var_index = 0; var_index < num_variables; ++var_index)
59 {
60 if (m_variables[var_index].m_var_decl == var_decl)
61 {
62 idx = var_index;
63 return m_variables[var_index].m_value;
64 }
65 }
66
67 if (!can_create)
68 return NULL;
69
70 idx = m_variables.size();
71
72 ClangExpressionVariable val;
73 val.m_var_decl = var_decl;
Sean Callanan4a7c6c62010-08-13 22:52:29 +000074 val.m_value = ValueForDecl(var_decl);
Chris Lattner24943d22010-06-08 16:52:24 +000075 m_variables.push_back(val);
76
77 return m_variables.back().m_value;
78}
79
80Value *
81ClangExpressionVariableList::GetVariableAtIndex (uint32_t idx)
82{
83 if (idx < m_variables.size())
84 return m_variables[idx].m_value;
85
86 return NULL;
87}