Type.h revision ef80aabe53b7fdf61309ba6d3d6865c94c681345
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/ConstString.h"
16#include "lldb/Core/UserID.h"
17#include "lldb/Symbol/Declaration.h"
18#include <set>
19
20namespace lldb_private {
21
22class Type : public UserID
23{
24public:
25    typedef enum EncodingDataTypeTag
26    {
27        eEncodingInvalid,
28        eEncodingIsUID,                 ///< This type is the type whose UID is m_encoding_uid
29        eEncodingIsConstUID,            ///< This type is the type whose UID is m_encoding_uid with the const qualifier added
30        eEncodingIsRestrictUID,         ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added
31        eEncodingIsVolatileUID,         ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added
32        eEncodingIsTypedefUID,          ///< This type is pointer to a type whose UID is m_encoding_uid
33        eEncodingIsPointerUID,          ///< This type is pointer to a type whose UID is m_encoding_uid
34        eEncodingIsLValueReferenceUID,  ///< This type is L value reference to a type whose UID is m_encoding_uid
35        eEncodingIsRValueReferenceUID,  ///< This type is R value reference to a type whose UID is m_encoding_uid
36        eEncodingIsSyntheticUID
37    } EncodingDataType;
38
39    typedef enum ResolveStateTag
40    {
41        eResolveStateUnresolved = 0,
42        eResolveStateForward    = 1,
43        eResolveStateLayout     = 2,
44        eResolveStateFull       = 3
45    } ResolveState;
46
47    Type (lldb::user_id_t uid,
48          SymbolFile* symbol_file,
49          const ConstString &name,
50          uint32_t byte_size,
51          SymbolContextScope *context,
52          lldb::user_id_t encoding_uid,
53          EncodingDataType encoding_uid_type,
54          const Declaration& decl,
55          lldb::clang_type_t clang_qual_type,
56          ResolveState clang_type_resolve_state);
57
58    // This makes an invalid type.  Used for functions that return a Type when they
59    // get an error.
60    Type();
61
62    Type (const Type &rhs);
63
64    const Type&
65    operator= (const Type& rhs);
66
67    void
68    Dump(Stream *s, bool show_context);
69
70    void
71    DumpTypeName(Stream *s);
72
73
74    void
75    GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name);
76
77    SymbolFile *
78    GetSymbolFile()
79    {
80        return m_symbol_file;
81    }
82    const SymbolFile *
83    GetSymbolFile() const
84    {
85        return m_symbol_file;
86    }
87
88    TypeList*
89    GetTypeList();
90
91    const ConstString&
92    GetName();
93
94    uint32_t
95    GetByteSize();
96
97    uint32_t
98    GetNumChildren (bool omit_empty_base_classes);
99
100    bool
101    IsAggregateType ();
102
103    bool
104    IsValidType ()
105    {
106        return m_encoding_uid_type != eEncodingInvalid;
107    }
108
109    void
110    SetByteSize(uint32_t byte_size);
111
112    const ConstString &
113    GetName () const
114    {
115        return m_name;
116    }
117
118    void
119    DumpValue(ExecutionContext *exe_ctx,
120              Stream *s,
121              const DataExtractor &data,
122              uint32_t data_offset,
123              bool show_type,
124              bool show_summary,
125              bool verbose,
126              lldb::Format format = lldb::eFormatDefault);
127
128    bool
129    DumpValueInMemory(ExecutionContext *exe_ctx,
130                      Stream *s,
131                      lldb::addr_t address,
132                      AddressType address_type,
133                      bool show_types,
134                      bool show_summary,
135                      bool verbose);
136
137    bool
138    ReadFromMemory (ExecutionContext *exe_ctx,
139                    lldb::addr_t address,
140                    AddressType address_type,
141                    DataExtractor &data);
142
143    bool
144    WriteToMemory (ExecutionContext *exe_ctx,
145                   lldb::addr_t address,
146                   AddressType address_type,
147                   DataExtractor &data);
148
149    bool
150    GetIsDeclaration() const;
151
152    void
153    SetIsDeclaration(bool b);
154
155    bool
156    GetIsExternal() const;
157
158    void
159    SetIsExternal(bool b);
160
161    lldb::Format
162    GetFormat ();
163
164    lldb::Encoding
165    GetEncoding (uint32_t &count);
166
167    SymbolContextScope *
168    GetSymbolContextScope()
169    {
170        return m_context;
171    }
172    const SymbolContextScope *
173    GetSymbolContextScope() const
174    {
175        return m_context;
176    }
177    void
178    SetSymbolContextScope(SymbolContextScope *context)
179    {
180        m_context = context;
181    }
182
183    const lldb_private::Declaration &
184    GetDeclaration () const;
185
186    // Get the clang type, and resolve definitions for any
187    // class/struct/union/enum types completely.
188    lldb::clang_type_t
189    GetClangFullType ();
190
191    // Get the clang type, and resolve definitions enough so that the type could
192    // have layout performed. This allows ptrs and refs to class/struct/union/enum
193    // types remain forward declarations.
194    lldb::clang_type_t
195    GetClangLayoutType ();
196
197    // Get the clang type and leave class/struct/union/enum types as forward
198    // declarations if they haven't already been fully defined.
199    lldb::clang_type_t
200    GetClangForwardType ();
201
202    clang::ASTContext *
203    GetClangAST ();
204
205    ClangASTContext &
206    GetClangASTContext ();
207
208    static int
209    Compare(const Type &a, const Type &b);
210
211    void
212    SetEncodingType (Type *encoding_type)
213    {
214        m_encoding_type = encoding_type;
215    }
216
217    uint32_t
218    GetEncodingMask ();
219
220    void *
221    CreateClangPointerType (Type *type);
222
223    void *
224    CreateClangTypedefType (Type *typedef_type, Type *base_type);
225
226    // For C++98 references (&)
227    void *
228    CreateClangLValueReferenceType (Type *type);
229
230    // For C++0x references (&&)
231    void *
232    CreateClangRValueReferenceType (Type *type);
233
234
235protected:
236    ConstString m_name;
237    SymbolFile *m_symbol_file;
238    SymbolContextScope *m_context; // The symbol context in which this type is defined
239    Type *m_encoding_type;
240    uint32_t m_encoding_uid;
241    EncodingDataType m_encoding_uid_type;
242    uint32_t m_byte_size;
243    Declaration m_decl;
244    lldb::clang_type_t m_clang_type;
245    ResolveState m_clang_type_resolve_state;
246
247    Type *
248    GetEncodingType ();
249
250    bool
251    ResolveClangType (ResolveState clang_type_resolve_state);
252};
253
254
255///
256/// Sometimes you can find the name of the type corresponding to an object, but we don't have debug
257/// information for it.  If that is the case, you can return one of these objects, and then if it
258/// has a full type, you can use that, but if not at least you can print the name for informational
259/// purposes.
260///
261
262class TypeAndOrName
263{
264public:
265    TypeAndOrName ();
266    TypeAndOrName (lldb::TypeSP &type_sp);
267    TypeAndOrName (const char *type_str);
268    TypeAndOrName (const TypeAndOrName &rhs);
269    TypeAndOrName (ConstString &type_const_string);
270
271    TypeAndOrName &
272    operator= (const TypeAndOrName &rhs);
273
274    ConstString GetName () const;
275    lldb::TypeSP      GetTypeSP () const {
276        return m_type_sp;
277    };
278
279    void
280    SetName (ConstString &type_name_const_str);
281
282    void
283    SetName (const char *type_name_str);
284
285    void
286    SetTypeSP (lldb::TypeSP type_sp);
287
288    bool
289    IsEmpty ();
290
291private:
292    lldb::TypeSP m_type_sp;
293    ConstString m_type_name;
294};
295
296} // namespace lldb_private
297
298#endif  // liblldb_Type_h_
299
300