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