ClangASTType.h revision dc0a38c5a727cae5362b218a3180d0f4265a619d
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
33    ClangASTType (clang::ASTContext *ast_context, lldb::clang_type_t type) :
34        m_type (type),
35        m_ast  (ast_context)
36    {
37    }
38
39    ClangASTType (const ClangASTType &tw) :
40        m_type (tw.m_type),
41        m_ast  (tw.m_ast)
42    {
43    }
44
45    ClangASTType () :
46        m_type (0),
47        m_ast  (0)
48    {
49    }
50
51    virtual ~ClangASTType();
52
53    const ClangASTType &
54    operator= (const ClangASTType &atb)
55    {
56        m_type = atb.m_type;
57        m_ast = atb.m_ast;
58        return *this;
59    }
60
61    bool
62    IsValid () const
63    {
64        return m_type != NULL && m_ast != NULL;
65    }
66
67    lldb::clang_type_t
68    GetOpaqueQualType() const
69    {
70        return m_type;
71    }
72
73    clang::ASTContext *
74    GetASTContext() const
75    {
76        return m_ast;
77    }
78
79    ConstString
80    GetConstTypeName ();
81
82    ConstString
83    GetConstQualifiedTypeName ();
84
85    static ConstString
86    GetConstTypeName (clang::ASTContext *ast,
87                      lldb::clang_type_t clang_type);
88
89    static ConstString
90    GetConstQualifiedTypeName (clang::ASTContext *ast,
91                               lldb::clang_type_t clang_type);
92
93    static std::string
94    GetTypeNameForQualType (clang::ASTContext *ast,
95                            clang::QualType qual_type);
96
97    static std::string
98    GetTypeNameForOpaqueQualType (clang::ASTContext *ast,
99                                  lldb::clang_type_t opaque_qual_type);
100
101    uint32_t
102    GetClangTypeBitWidth ();
103
104    static uint32_t
105    GetClangTypeBitWidth (clang::ASTContext *ast_context, lldb::clang_type_t opaque_clang_qual_type);
106
107    size_t
108    GetTypeBitAlign ();
109
110    static size_t
111    GetTypeBitAlign (clang::ASTContext *ast_context, lldb::clang_type_t clang_type);
112
113    lldb::LanguageType
114    GetMinimumLanguage ();
115
116    static lldb::LanguageType
117    GetMinimumLanguage (clang::ASTContext *ctx,
118                        lldb::clang_type_t clang_type);
119
120    static lldb::TypeClass
121    GetTypeClass (clang::ASTContext *ast_context,
122                  lldb::clang_type_t clang_type);
123
124    void
125    DumpValue (ExecutionContext *exe_ctx,
126               Stream *s,
127               lldb::Format format,
128               const DataExtractor &data,
129               uint32_t data_offset,
130               size_t data_byte_size,
131               uint32_t bitfield_bit_size,
132               uint32_t bitfield_bit_offset,
133               bool show_types,
134               bool show_summary,
135               bool verbose,
136               uint32_t depth);
137
138    static void
139    DumpValue (clang::ASTContext *ast_context,
140               lldb::clang_type_t opaque_clang_qual_type,
141               ExecutionContext *exe_ctx,
142               Stream *s,
143               lldb::Format format,
144               const DataExtractor &data,
145               uint32_t data_offset,
146               size_t data_byte_size,
147               uint32_t bitfield_bit_size,
148               uint32_t bitfield_bit_offset,
149               bool show_types,
150               bool show_summary,
151               bool verbose,
152               uint32_t depth);
153
154    bool
155    DumpTypeValue (Stream *s,
156                   lldb::Format format,
157                   const DataExtractor &data,
158                   uint32_t data_offset,
159                   size_t data_byte_size,
160                   uint32_t bitfield_bit_size,
161                   uint32_t bitfield_bit_offset,
162                   ExecutionContextScope *exe_scope);
163
164
165    static bool
166    DumpTypeValue (clang::ASTContext *ast_context,
167                   lldb::clang_type_t opaque_clang_qual_type,
168                   Stream *s,
169                   lldb::Format format,
170                   const DataExtractor &data,
171                   uint32_t data_offset,
172                   size_t data_byte_size,
173                   uint32_t bitfield_bit_size,
174                   uint32_t bitfield_bit_offset,
175                   ExecutionContextScope *exe_scope);
176
177    void
178    DumpSummary (ExecutionContext *exe_ctx,
179                 Stream *s,
180                 const DataExtractor &data,
181                 uint32_t data_offset,
182                 size_t data_byte_size);
183
184
185    static void
186    DumpSummary (clang::ASTContext *ast_context,
187                 lldb::clang_type_t opaque_clang_qual_type,
188                 ExecutionContext *exe_ctx,
189                 Stream *s,
190                 const DataExtractor &data,
191                 uint32_t data_offset,
192                 size_t data_byte_size);
193
194    void
195    DumpTypeDescription (Stream *s);
196
197    static void
198    DumpTypeDescription (clang::ASTContext *ast_context,
199                         lldb::clang_type_t opaque_clang_qual_type,
200                         Stream *s);
201
202    void DumpTypeCode (Stream *s);
203
204    static void
205    DumpTypeCode (void *type,
206                  Stream *s);
207
208    lldb::Encoding
209    GetEncoding (uint32_t &count);
210
211    static lldb::Encoding
212    GetEncoding (lldb::clang_type_t opaque_clang_qual_type, uint32_t &count);
213
214    lldb::Format
215    GetFormat ();
216
217    static lldb::Format
218    GetFormat (lldb::clang_type_t opaque_clang_qual_type);
219
220    uint32_t
221    GetTypeByteSize() const;
222
223    static uint32_t
224    GetTypeByteSize(clang::ASTContext *ast_context,
225                    lldb::clang_type_t opaque_clang_qual_type);
226
227    bool
228    GetValueAsScalar (const DataExtractor &data,
229                      uint32_t data_offset,
230                      size_t data_byte_size,
231                      Scalar &value);
232
233    static bool
234    GetValueAsScalar (clang::ASTContext *ast_context,
235                      lldb::clang_type_t opaque_clang_qual_type,
236                      const DataExtractor &data,
237                      uint32_t data_offset,
238                      size_t data_byte_size,
239                      Scalar &value);
240
241
242    bool
243    IsDefined();
244
245    static bool
246    IsDefined (lldb::clang_type_t opaque_clang_qual_type);
247
248    bool
249    IsConst();
250
251    static bool
252    IsConst (lldb::clang_type_t opaque_clang_qual_type);
253
254    bool
255    SetValueFromScalar (const Scalar &value,
256                        Stream &strm);
257
258    static bool
259    SetValueFromScalar (clang::ASTContext *ast_context,
260                        lldb::clang_type_t opaque_clang_qual_type,
261                        const Scalar &value,
262                        Stream &strm);
263
264    void
265    SetClangType (clang::ASTContext *ast, lldb::clang_type_t type)
266    {
267        m_type = type;
268        m_ast = ast;
269    }
270
271    bool
272    ReadFromMemory (ExecutionContext *exe_ctx,
273                    lldb::addr_t addr,
274                    AddressType address_type,
275                    DataExtractor &data);
276
277    static bool
278    ReadFromMemory (clang::ASTContext *ast_context,
279                    lldb::clang_type_t opaque_clang_qual_type,
280                    ExecutionContext *exe_ctx,
281                    lldb::addr_t addr,
282                    AddressType address_type,
283                    DataExtractor &data);
284
285    bool
286    WriteToMemory (ExecutionContext *exe_ctx,
287                   lldb::addr_t addr,
288                   AddressType address_type,
289                   StreamString &new_value);
290
291    static bool
292    WriteToMemory (clang::ASTContext *ast_context,
293                   lldb::clang_type_t opaque_clang_qual_type,
294                   ExecutionContext *exe_ctx,
295                   lldb::addr_t addr,
296                   AddressType address_type,
297                   StreamString &new_value);
298
299    lldb::clang_type_t
300    GetPointeeType ();
301
302    static lldb::clang_type_t
303    GetPointeeType (lldb::clang_type_t opaque_clang_qual_type);
304
305    lldb::clang_type_t
306    GetArrayElementType (uint32_t& stride);
307
308    static lldb::clang_type_t
309    GetArrayElementType (clang::ASTContext* ast,
310                         lldb::clang_type_t opaque_clang_qual_type,
311						 uint32_t& stride);
312
313    lldb::clang_type_t
314    GetPointerType () const;
315
316    static lldb::clang_type_t
317    GetPointerType (clang::ASTContext *ast_context,
318                    lldb::clang_type_t opaque_clang_qual_type);
319
320    static lldb::clang_type_t
321    RemoveFastQualifiers (lldb::clang_type_t);
322
323    void
324    Clear()
325    {
326        m_type = NULL;
327        m_ast = NULL;
328    }
329
330private:
331    lldb::clang_type_t m_type;
332    clang::ASTContext *m_ast;
333};
334
335bool operator == (const ClangASTType &lhs, const ClangASTType &rhs);
336bool operator != (const ClangASTType &lhs, const ClangASTType &rhs);
337
338
339} // namespace lldb_private
340
341#endif // #ifndef liblldb_ClangASTType_h_
342