Value.h revision 87c871847dba627a07cf6f4ac8cfb4d6722eccb5
1//===-- Value.h -------------------------------------------------*- 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#ifndef liblldb_Value_h_
11#define liblldb_Value_h_
12
13// C Includes
14// C++ Includes
15#include <vector>
16// Other libraries and framework includes
17// Project includes
18#include "lldb/lldb-private.h"
19#include "lldb/Core/ClangForward.h"
20#include "lldb/Core/DataBufferHeap.h"
21#include "lldb/Core/Error.h"
22#include "lldb/Core/Scalar.h"
23
24namespace lldb_private {
25
26class Value
27{
28public:
29
30    // Values Less than zero are an error, greater than or equal to zero
31    // returns what the Scalar result is.
32    enum ValueType
33    {
34                                        // m_value contains...
35                                        // ============================
36        eValueTypeScalar,               // raw scalar value
37        eValueTypeFileAddress,          // file address value
38        eValueTypeLoadAddress,          // load address value
39        eValueTypeHostAddress           // host address value (for memory in the process that is using liblldb)
40    };
41
42    enum ContextType                    // Type that describes Value::m_context
43    {
44                                        // m_context contains...
45                                        // ====================
46        eContextTypeInvalid,            // undefined
47        eContextTypeOpaqueClangQualType,// void * (an opaque clang::QualType * that can be fed to "static QualType QualType::getFromOpaquePtr(void *)")
48        eContextTypeDCRegisterInfo,     // lldb::RegisterInfo *
49        eContextTypeDCType,             // Type *
50        eContextTypeDCVariable,         // Variable *
51        eContextTypeValue               // Value * (making this a proxy value.  Used when putting locals on the DWARF expression parser stack)
52    };
53
54    Value();
55    Value(const Scalar& scalar);
56    Value(int v);
57    Value(unsigned int v);
58    Value(long v);
59    Value(unsigned long v);
60    Value(long long v);
61    Value(unsigned long long v);
62    Value(float v);
63    Value(double v);
64    Value(long double v);
65    Value(const uint8_t *bytes, int len);
66    Value(const Value &v);
67
68    Value *
69    CreateProxy();
70
71    Value *
72    GetProxyTarget();
73
74    void *
75    GetOpaqueClangQualType();
76
77    ValueType
78    GetValueType() const;
79
80    lldb::AddressType
81    GetValueAddressType () const;
82
83    ContextType
84    GetContextType() const;
85
86    void
87    SetValueType (ValueType value_type);
88
89    void
90    ClearContext ();
91
92    void
93    SetContext (ContextType context_type, void *p);
94
95    lldb::RegisterInfo *
96    GetRegisterInfo();
97
98    Type *
99    GetType();
100
101    Scalar &
102    ResolveValue (ExecutionContext *exe_ctx, clang::ASTContext *ast_context);
103
104    Scalar &
105    GetScalar();
106
107    void
108    ResizeData(int len);
109
110    bool
111    ValueOf(ExecutionContext *exe_ctx, clang::ASTContext *ast_context);
112
113    Variable *
114    GetVariable();
115
116    void
117    Dump (Stream* strm);
118
119    lldb::Format
120    GetValueDefaultFormat ();
121
122    void *
123    GetValueOpaqueClangQualType ();
124
125    size_t
126    GetValueByteSize (clang::ASTContext *ast_context, Error *error_ptr);
127
128    Error
129    GetValueAsData (ExecutionContext *exe_ctx, clang::ASTContext *ast_context, DataExtractor &data, uint32_t data_offset);
130
131    static const char *
132    GetValueTypeAsCString (ValueType context_type);
133
134    static const char *
135    GetContextTypeAsCString (ContextType context_type);
136
137protected:
138    Scalar          m_value;
139    ValueType       m_value_type;
140    void *          m_context;
141    ContextType     m_context_type;
142    DataBufferHeap  m_data_buffer;
143};
144
145class ValueList
146{
147public:
148    ValueList () {}
149    ValueList (const ValueList &rhs);
150
151    ~ValueList () {}
152
153    const ValueList & operator= (const ValueList &rhs);
154
155    // void InsertValue (Value *value, size_t idx);
156    void PushValue (const Value &value);
157
158    size_t GetSize ();
159    Value *GetValueAtIndex(size_t idx);
160    void Clear();
161
162protected:
163
164private:
165    typedef std::vector<Value> collection;
166
167    collection m_values;
168};
169
170} // namespace lldb_private
171
172#endif  // liblldb_Value_h_
173