ClangASTType.h revision 3e1c95a5eccc5fca012fcd91226ea67710b7ff26
1//===-- ClangASTType.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_ClangASTType_h_
11#define liblldb_ClangASTType_h_
12
13#include <string>
14#include "lldb/lldb-private.h"
15#include "lldb/Core/ClangForward.h"
16
17namespace lldb_private {
18
19//----------------------------------------------------------------------
20// A class that can carry around a clang ASTContext and a opaque clang
21// QualType. A clang::QualType can be easily reconstructed from an
22// opaque clang type and often the ASTContext is needed when doing
23// various type related tasks, so this class allows both items to travel
24// in a single very lightweight class that can be used. There are many
25// static equivalents of the member functions that allow the ASTContext
26// and the opaque clang QualType to be specified for ease of use and
27// to avoid code duplication.
28//----------------------------------------------------------------------
29class ClangASTType
30{
31public:
32    ClangASTType (lldb::clang_type_t type, clang::ASTContext *ast_context) :
33        m_type (type),
34        m_ast  (ast_context)
35    {
36    }
37
38    ClangASTType (const ClangASTType &tw) :
39        m_type (tw.m_type),
40        m_ast  (tw.m_ast)
41    {
42    }
43
44    ClangASTType () :
45        m_type (0),
46        m_ast  (0)
47    {
48    }
49
50    virtual ~ClangASTType();
51
52    const ClangASTType &
53    operator= (const ClangASTType &atb)
54    {
55        m_type = atb.m_type;
56        m_ast = atb.m_ast;
57        return *this;
58    }
59
60    lldb::clang_type_t
61    GetOpaqueQualType() const
62    {
63        return m_type;
64    }
65
66    clang::ASTContext *
67    GetASTContext() const
68    {
69        return m_ast;
70    }
71
72    ConstString
73    GetConstTypeName ();
74
75    static ConstString
76    GetConstTypeName (lldb::clang_type_t clang_type);
77
78    static std::string
79    GetTypeNameForQualType (clang::QualType qual_type);
80
81    static std::string
82    GetTypeNameForOpaqueQualType (lldb::clang_type_t opaque_qual_type);
83
84    uint32_t
85    GetClangTypeBitWidth ();
86
87    static uint32_t
88    GetClangTypeBitWidth (clang::ASTContext *ast_context, lldb::clang_type_t opaque_clang_qual_type);
89
90    size_t
91    GetTypeBitAlign ();
92
93    static size_t
94    GetTypeBitAlign (clang::ASTContext *ast_context, lldb::clang_type_t clang_type);
95
96    void
97    DumpValue (ExecutionContext *exe_ctx,
98               Stream *s,
99               lldb::Format format,
100               const DataExtractor &data,
101               uint32_t data_offset,
102               size_t data_byte_size,
103               uint32_t bitfield_bit_size,
104               uint32_t bitfield_bit_offset,
105               bool show_types,
106               bool show_summary,
107               bool verbose,
108               uint32_t depth);
109
110    static void
111    DumpValue (clang::ASTContext *ast_context,
112               lldb::clang_type_t opaque_clang_qual_type,
113               ExecutionContext *exe_ctx,
114               Stream *s,
115               lldb::Format format,
116               const DataExtractor &data,
117               uint32_t data_offset,
118               size_t data_byte_size,
119               uint32_t bitfield_bit_size,
120               uint32_t bitfield_bit_offset,
121               bool show_types,
122               bool show_summary,
123               bool verbose,
124               uint32_t depth);
125
126    bool
127    DumpTypeValue (Stream *s,
128                   lldb::Format format,
129                   const DataExtractor &data,
130                   uint32_t data_offset,
131                   size_t data_byte_size,
132                   uint32_t bitfield_bit_size,
133                   uint32_t bitfield_bit_offset);
134
135
136    static bool
137    DumpTypeValue (clang::ASTContext *ast_context,
138                   lldb::clang_type_t opaque_clang_qual_type,
139                   Stream *s,
140                   lldb::Format format,
141                   const DataExtractor &data,
142                   uint32_t data_offset,
143                   size_t data_byte_size,
144                   uint32_t bitfield_bit_size,
145                   uint32_t bitfield_bit_offset);
146
147    void
148    DumpSummary (ExecutionContext *exe_ctx,
149                 Stream *s,
150                 const DataExtractor &data,
151                 uint32_t data_offset,
152                 size_t data_byte_size);
153
154
155    static void
156    DumpSummary (clang::ASTContext *ast_context,
157                 lldb::clang_type_t opaque_clang_qual_type,
158                 ExecutionContext *exe_ctx,
159                 Stream *s,
160                 const DataExtractor &data,
161                 uint32_t data_offset,
162                 size_t data_byte_size);
163
164    void
165    DumpTypeDescription (Stream *s);
166
167    static void
168    DumpTypeDescription (clang::ASTContext *ast_context,
169                         lldb::clang_type_t opaque_clang_qual_type,
170                         Stream *s);
171
172    void DumpTypeCode (Stream *s);
173
174    static void
175    DumpTypeCode (void *type,
176                  Stream *s);
177
178    lldb::Encoding
179    GetEncoding (uint32_t &count);
180
181    static lldb::Encoding
182    GetEncoding (lldb::clang_type_t opaque_clang_qual_type, uint32_t &count);
183
184    lldb::Format
185    GetFormat ();
186
187    static lldb::Format
188    GetFormat (lldb::clang_type_t opaque_clang_qual_type);
189
190    uint32_t
191    GetTypeByteSize();
192
193    static uint32_t
194    GetTypeByteSize(clang::ASTContext *ast_context,
195                    lldb::clang_type_t opaque_clang_qual_type);
196
197    bool
198    GetValueAsScalar (const DataExtractor &data,
199                      uint32_t data_offset,
200                      size_t data_byte_size,
201                      Scalar &value);
202
203    static bool
204    GetValueAsScalar (clang::ASTContext *ast_context,
205                      lldb::clang_type_t opaque_clang_qual_type,
206                      const DataExtractor &data,
207                      uint32_t data_offset,
208                      size_t data_byte_size,
209                      Scalar &value);
210
211
212    bool
213    IsDefined();
214
215    static bool
216    IsDefined (lldb::clang_type_t opaque_clang_qual_type);
217
218    bool
219    IsConst();
220
221    static bool
222    IsConst (lldb::clang_type_t opaque_clang_qual_type);
223
224    bool
225    SetValueFromScalar (const Scalar &value,
226                        Stream &strm);
227
228    static bool
229    SetValueFromScalar (clang::ASTContext *ast_context,
230                        lldb::clang_type_t opaque_clang_qual_type,
231                        const Scalar &value,
232                        Stream &strm);
233
234    void
235    SetClangType (clang::ASTContext *ast, lldb::clang_type_t type)
236    {
237        m_type = type;
238        m_ast = ast;
239    }
240
241    bool
242    ReadFromMemory (ExecutionContext *exe_ctx,
243                    lldb::addr_t addr,
244                    AddressType address_type,
245                    DataExtractor &data);
246
247    static bool
248    ReadFromMemory (clang::ASTContext *ast_context,
249                    lldb::clang_type_t opaque_clang_qual_type,
250                    ExecutionContext *exe_ctx,
251                    lldb::addr_t addr,
252                    AddressType address_type,
253                    DataExtractor &data);
254
255    bool
256    WriteToMemory (ExecutionContext *exe_ctx,
257                   lldb::addr_t addr,
258                   AddressType address_type,
259                   StreamString &new_value);
260
261    static bool
262    WriteToMemory (clang::ASTContext *ast_context,
263                   lldb::clang_type_t opaque_clang_qual_type,
264                   ExecutionContext *exe_ctx,
265                   lldb::addr_t addr,
266                   AddressType address_type,
267                   StreamString &new_value);
268
269    lldb::clang_type_t
270    GetPointeeType ();
271
272    static lldb::clang_type_t
273    GetPointeeType (lldb::clang_type_t opaque_clang_qual_type);
274
275    static lldb::clang_type_t
276    RemoveFastQualifiers (lldb::clang_type_t);
277
278private:
279    lldb::clang_type_t m_type;
280    clang::ASTContext *m_ast;
281};
282
283
284} // namespace lldb_private
285
286#endif // #ifndef liblldb_ClangASTType_h_
287