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