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