Type.h revision 12bec71b323dc520f0e985a86e09c4712559e115
1//===-- Type.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_Type_h_
11#define liblldb_Type_h_
12
13#include "lldb/lldb-private.h"
14#include "lldb/Core/ClangForward.h"
15#include "lldb/Core/UserID.h"
16#include "lldb/Symbol/Declaration.h"
17#include <set>
18
19namespace lldb_private {
20
21class Type : public UserID
22{
23public:
24    typedef enum
25    {
26        eTypeInvalid,
27        eIsTypeWithUID,                 ///< This type is the type whose UID is m_encoding_uid
28        eIsConstTypeWithUID,            ///< This type is the type whose UID is m_encoding_uid with the const qualifier added
29        eIsRestrictTypeWithUID,         ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added
30        eIsVolatileTypeWithUID,         ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added
31        eTypedefToTypeWithUID,          ///< This type is pointer to a type whose UID is m_encoding_uid
32        ePointerToTypeWithUID,          ///< This type is pointer to a type whose UID is m_encoding_uid
33        eLValueReferenceToTypeWithUID,  ///< This type is L value reference to a type whose UID is m_encoding_uid
34        eRValueReferenceToTypeWithUID,   ///< This type is R value reference to a type whose UID is m_encoding_uid
35        eTypeUIDSynthetic
36    } EncodingUIDType;
37
38    Type(lldb::user_id_t uid,
39           SymbolFile* symbol_file,
40           const ConstString &name,
41           uint64_t byte_size,
42           SymbolContextScope *context,
43           lldb::user_id_t encoding_uid,
44           EncodingUIDType encoding_type,
45           const Declaration& decl,
46           void *clang_qual_type);
47
48    // This makes an invalid type.  Used for functions that return a Type when they
49    // get an error.
50    Type();
51
52    const Type&
53    operator= (const Type& rhs);
54
55    void
56    Dump(Stream *s, bool show_context);
57
58    void
59    DumpTypeName(Stream *s);
60
61
62    void
63    GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name);
64
65    SymbolFile *
66    GetSymbolFile()
67    {
68        return m_symbol_file;
69    }
70    const SymbolFile *
71    GetSymbolFile() const
72    {
73        return m_symbol_file;
74    }
75
76    TypeList*
77    GetTypeList();
78
79    const ConstString&
80    GetName();
81
82    uint64_t
83    GetByteSize();
84
85    uint32_t
86    GetNumChildren (bool omit_empty_base_classes);
87
88    bool
89    IsAggregateType ();
90
91    bool
92    IsValidType ()
93    {
94        return m_encoding_uid_type != eTypeInvalid;
95    }
96
97    void
98    SetByteSize(uint32_t byte_size);
99
100    const ConstString &
101    GetName () const
102    {
103        return m_name;
104    }
105
106    static ConstString
107    GetClangTypeName (void *clang_qual_type);
108
109    static void
110    DumpValue(ExecutionContext *exe_ctx,
111              clang::ASTContext *ast_context,
112              void *clang_qual_type,
113              Stream *s,
114              lldb::Format format,
115              const DataExtractor &data,
116              uint32_t data_offset,
117              size_t data_byte_size,
118              uint32_t bitfield_bit_size,
119              uint32_t bitfield_bit_offset,
120              bool show_types,
121              bool show_summary,
122              bool verbose,
123              uint32_t depth);
124
125    static void
126    DumpSummary (ExecutionContext *exe_ctx,
127                 clang::ASTContext *ast_context,
128                 void *clang_qual_type,
129                 Stream *s,
130                 const DataExtractor &data,
131                 uint32_t data_offset,
132                 size_t data_byte_size);
133
134
135    void
136    DumpValue(ExecutionContext *exe_ctx,
137              Stream *s,
138              const DataExtractor &data,
139              uint32_t data_offset,
140              bool show_type,
141              bool show_summary,
142              bool verbose,
143              lldb::Format format = lldb::eFormatDefault);
144
145    bool
146    DumpValueInMemory(ExecutionContext *exe_ctx,
147                      Stream *s,
148                      lldb::addr_t address,
149                      lldb::AddressType address_type,
150                      bool show_types,
151                      bool show_summary,
152                      bool verbose);
153
154    static bool
155    DumpTypeValue ( Stream *s,
156                    clang::ASTContext *ast_context,
157                    void *clang_qual_type,
158                    lldb::Format format,
159                    const DataExtractor &data,
160                    uint32_t data_offset,
161                    size_t data_byte_size,
162                    uint32_t bitfield_bit_size,
163                    uint32_t bitfield_bit_offset);
164
165    static bool
166    GetValueAsScalar (clang::ASTContext *ast_context,
167                      void *clang_qual_type,
168                      const DataExtractor &data,
169                      uint32_t data_offset,
170                      size_t data_byte_size,
171                      Scalar &value);
172
173    static bool
174    SetValueFromScalar (clang::ASTContext *ast_context,
175                        void *clang_qual_type,
176                        const Scalar &value,
177                        Stream &strm);
178
179    bool
180    ReadFromMemory (ExecutionContext *exe_ctx,
181                    lldb::addr_t address,
182                    lldb::AddressType address_type,
183                    DataExtractor &data);
184
185    bool
186    WriteToMemory (ExecutionContext *exe_ctx,
187                   lldb::addr_t address,
188                   lldb::AddressType address_type,
189                   DataExtractor &data);
190
191
192    static bool
193    ReadFromMemory (ExecutionContext *exe_ctx,
194                    clang::ASTContext *ast_context,
195                    void *clang_qual_type,
196                    lldb::addr_t addr,
197                    lldb::AddressType address_type,
198                    DataExtractor &data);
199
200    static bool
201    WriteToMemory (ExecutionContext *exe_ctx,
202                   clang::ASTContext *ast_context,
203                   void *clang_qual_type,
204                   lldb::addr_t addr,
205                   lldb::AddressType address_type,
206                   StreamString &new_value);
207
208    bool
209    GetIsDeclaration() const;
210
211    void
212    SetIsDeclaration(bool b);
213
214    bool
215    GetIsExternal() const;
216
217    void
218    SetIsExternal(bool b);
219
220    lldb::Format
221    GetFormat ();
222
223    lldb::Encoding
224    GetEncoding (uint32_t &count);
225
226    static lldb::Encoding
227    GetEncoding (void *clang_qual_type, uint32_t &count);
228
229    SymbolContextScope *
230    GetSymbolContextScope()
231    {
232        return m_context;
233    }
234    const SymbolContextScope *
235    GetSymbolContextScope() const
236    {
237        return m_context;
238    }
239    void
240    SetSymbolContextScope(SymbolContextScope *context)
241    {
242        m_context = context;
243    }
244
245    void *
246    GetOpaqueClangQualType ();
247
248    clang::ASTContext *
249    GetClangAST ();
250
251    ClangASTContext &
252    GetClangASTContext ();
253
254    void *
255    GetChildClangTypeAtIndex (const char *parent_name,
256                              uint32_t idx,
257                              bool transparent_pointers,
258                              bool omit_empty_base_classes,
259                              ConstString& name,
260                              uint32_t &child_byte_size,
261                              int32_t &child_byte_offset,
262                              uint32_t &child_bitfield_bit_size,
263                              uint32_t &child_bitfield_bit_offset);
264
265    static int
266    Compare(const Type &a, const Type &b);
267
268    static lldb::Format
269    GetFormat (void *clang_qual_type);
270
271    static int
272    DumpClangTypeName(Stream *s, void *clang_qual_type);
273
274protected:
275    ConstString m_name;
276    uint64_t m_byte_size;
277    SymbolFile *m_symbol_file;
278    SymbolContextScope *m_context; // The symbol context in which this type is defined
279    lldb::user_id_t m_encoding_uid;
280    EncodingUIDType m_encoding_uid_type;
281    Declaration m_decl;
282    void *m_clang_qual_type;
283
284    bool ResolveClangType();
285};
286
287} // namespace lldb_private
288
289#endif  // liblldb_Type_h_
290
291