]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Symbol/CompilerType.h
Merge ^/head r338731 through r338987.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Symbol / CompilerType.h
1 //===-- CompilerType.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_CompilerType_h_
11 #define liblldb_CompilerType_h_
12
13 // C Includes
14 // C++ Includes
15 #include <functional>
16 #include <string>
17 #include <vector>
18
19 // Other libraries and framework includes
20 // Project includes
21 #include "lldb/Core/ClangForward.h"
22 #include "lldb/lldb-private.h"
23 #include "llvm/ADT/APSInt.h"
24
25 namespace lldb_private {
26
27 class DataExtractor;
28
29 //----------------------------------------------------------------------
30 // A class that can carry around a clang ASTContext and a opaque clang
31 // QualType. A clang::QualType can be easily reconstructed from an opaque clang
32 // type and often the ASTContext is needed when doing various type related
33 // tasks, so this class allows both items to travel in a single very
34 // lightweight class that can be used. There are many static equivalents of the
35 // member functions that allow the ASTContext and the opaque clang QualType to
36 // be specified for ease of use and to avoid code duplication.
37 //----------------------------------------------------------------------
38 class CompilerType {
39 public:
40   //----------------------------------------------------------------------
41   // Constructors and Destructors
42   //----------------------------------------------------------------------
43   CompilerType(TypeSystem *type_system, lldb::opaque_compiler_type_t type);
44   CompilerType(clang::ASTContext *ast_context, clang::QualType qual_type);
45
46   CompilerType(const CompilerType &rhs)
47       : m_type(rhs.m_type), m_type_system(rhs.m_type_system) {}
48
49   CompilerType() : m_type(nullptr), m_type_system(nullptr) {}
50
51   ~CompilerType();
52
53   //----------------------------------------------------------------------
54   // Operators
55   //----------------------------------------------------------------------
56
57   const CompilerType &operator=(const CompilerType &rhs) {
58     m_type = rhs.m_type;
59     m_type_system = rhs.m_type_system;
60     return *this;
61   }
62
63   //----------------------------------------------------------------------
64   // Tests
65   //----------------------------------------------------------------------
66
67   explicit operator bool() const {
68     return m_type != nullptr && m_type_system != nullptr;
69   }
70
71   bool operator<(const CompilerType &rhs) const {
72     if (m_type_system == rhs.m_type_system)
73       return m_type < rhs.m_type;
74     return m_type_system < rhs.m_type_system;
75   }
76
77   bool IsValid() const { return m_type != nullptr && m_type_system != nullptr; }
78
79   bool IsArrayType(CompilerType *element_type, uint64_t *size,
80                    bool *is_incomplete) const;
81
82   bool IsVectorType(CompilerType *element_type, uint64_t *size) const;
83
84   bool IsArrayOfScalarType() const;
85
86   bool IsAggregateType() const;
87
88   bool IsAnonymousType() const;
89
90   bool IsBeingDefined() const;
91
92   bool IsCharType() const;
93
94   bool IsCompleteType() const;
95
96   bool IsConst() const;
97
98   bool IsCStringType(uint32_t &length) const;
99
100   bool IsDefined() const;
101
102   bool IsFloatingPointType(uint32_t &count, bool &is_complex) const;
103
104   bool IsFunctionType(bool *is_variadic_ptr = nullptr) const;
105
106   uint32_t IsHomogeneousAggregate(CompilerType *base_type_ptr) const;
107
108   size_t GetNumberOfFunctionArguments() const;
109
110   CompilerType GetFunctionArgumentAtIndex(const size_t index) const;
111
112   bool IsVariadicFunctionType() const;
113
114   bool IsFunctionPointerType() const;
115
116   bool IsBlockPointerType(CompilerType *function_pointer_type_ptr) const;
117
118   bool IsIntegerType(bool &is_signed) const;
119
120   bool IsEnumerationType(bool &is_signed) const;
121
122   bool IsIntegerOrEnumerationType(bool &is_signed) const;
123
124   bool IsPolymorphicClass() const;
125
126   bool
127   IsPossibleCPlusPlusDynamicType(CompilerType *target_type = nullptr) const {
128     return IsPossibleDynamicType(target_type, true, false);
129   }
130
131   bool IsPossibleDynamicType(CompilerType *target_type, // Can pass nullptr
132                              bool check_cplusplus, bool check_objc) const;
133
134   bool IsPointerToScalarType() const;
135
136   bool IsRuntimeGeneratedType() const;
137
138   bool IsPointerType(CompilerType *pointee_type = nullptr) const;
139
140   bool IsPointerOrReferenceType(CompilerType *pointee_type = nullptr) const;
141
142   bool IsReferenceType(CompilerType *pointee_type = nullptr,
143                        bool *is_rvalue = nullptr) const;
144
145   bool ShouldTreatScalarValueAsAddress() const;
146
147   bool IsScalarType() const;
148
149   bool IsTypedefType() const;
150
151   bool IsVoidType() const;
152
153   //----------------------------------------------------------------------
154   // Type Completion
155   //----------------------------------------------------------------------
156
157   bool GetCompleteType() const;
158
159   //----------------------------------------------------------------------
160   // AST related queries
161   //----------------------------------------------------------------------
162
163   size_t GetPointerByteSize() const;
164
165   //----------------------------------------------------------------------
166   // Accessors
167   //----------------------------------------------------------------------
168
169   TypeSystem *GetTypeSystem() const { return m_type_system; }
170
171   ConstString GetConstQualifiedTypeName() const;
172
173   ConstString GetConstTypeName() const;
174
175   ConstString GetTypeName() const;
176
177   ConstString GetDisplayTypeName() const;
178
179   uint32_t
180   GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr) const;
181
182   lldb::LanguageType GetMinimumLanguage();
183
184   lldb::opaque_compiler_type_t GetOpaqueQualType() const { return m_type; }
185
186   lldb::TypeClass GetTypeClass() const;
187
188   void SetCompilerType(TypeSystem *type_system,
189                        lldb::opaque_compiler_type_t type);
190
191   void SetCompilerType(clang::ASTContext *ast, clang::QualType qual_type);
192
193   unsigned GetTypeQualifiers() const;
194
195   //----------------------------------------------------------------------
196   // Creating related types
197   //----------------------------------------------------------------------
198
199   CompilerType GetArrayElementType(uint64_t *stride = nullptr) const;
200
201   CompilerType GetArrayType(uint64_t size) const;
202
203   CompilerType GetCanonicalType() const;
204
205   CompilerType GetFullyUnqualifiedType() const;
206
207   // Returns -1 if this isn't a function of if the function doesn't have a
208   // prototype Returns a value >= 0 if there is a prototype.
209   int GetFunctionArgumentCount() const;
210
211   CompilerType GetFunctionArgumentTypeAtIndex(size_t idx) const;
212
213   CompilerType GetFunctionReturnType() const;
214
215   size_t GetNumMemberFunctions() const;
216
217   TypeMemberFunctionImpl GetMemberFunctionAtIndex(size_t idx);
218
219   //----------------------------------------------------------------------
220   // If this type is a reference to a type (L value or R value reference),
221   // return a new type with the reference removed, else return the current type
222   // itself.
223   //----------------------------------------------------------------------
224   CompilerType GetNonReferenceType() const;
225
226   //----------------------------------------------------------------------
227   // If this type is a pointer type, return the type that the pointer points
228   // to, else return an invalid type.
229   //----------------------------------------------------------------------
230   CompilerType GetPointeeType() const;
231
232   //----------------------------------------------------------------------
233   // Return a new CompilerType that is a pointer to this type
234   //----------------------------------------------------------------------
235   CompilerType GetPointerType() const;
236
237   //----------------------------------------------------------------------
238   // Return a new CompilerType that is a L value reference to this type if this
239   // type is valid and the type system supports L value references, else return
240   // an invalid type.
241   //----------------------------------------------------------------------
242   CompilerType GetLValueReferenceType() const;
243
244   //----------------------------------------------------------------------
245   // Return a new CompilerType that is a R value reference to this type if this
246   // type is valid and the type system supports R value references, else return
247   // an invalid type.
248   //----------------------------------------------------------------------
249   CompilerType GetRValueReferenceType() const;
250
251   //----------------------------------------------------------------------
252   // Return a new CompilerType adds a const modifier to this type if this type
253   // is valid and the type system supports const modifiers, else return an
254   // invalid type.
255   //----------------------------------------------------------------------
256   CompilerType AddConstModifier() const;
257
258   //----------------------------------------------------------------------
259   // Return a new CompilerType adds a volatile modifier to this type if this
260   // type is valid and the type system supports volatile modifiers, else return
261   // an invalid type.
262   //----------------------------------------------------------------------
263   CompilerType AddVolatileModifier() const;
264
265   //----------------------------------------------------------------------
266   // Return a new CompilerType adds a restrict modifier to this type if this
267   // type is valid and the type system supports restrict modifiers, else return
268   // an invalid type.
269   //----------------------------------------------------------------------
270   CompilerType AddRestrictModifier() const;
271
272   //----------------------------------------------------------------------
273   // Create a typedef to this type using "name" as the name of the typedef this
274   // type is valid and the type system supports typedefs, else return an
275   // invalid type.
276   //----------------------------------------------------------------------
277   CompilerType CreateTypedef(const char *name,
278                              const CompilerDeclContext &decl_ctx) const;
279
280   // If the current object represents a typedef type, get the underlying type
281   CompilerType GetTypedefedType() const;
282
283   //----------------------------------------------------------------------
284   // Create related types using the current type's AST
285   //----------------------------------------------------------------------
286   CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) const;
287
288   //----------------------------------------------------------------------
289   // Exploring the type
290   //----------------------------------------------------------------------
291
292   struct IntegralTemplateArgument;
293
294   uint64_t GetByteSize(ExecutionContextScope *exe_scope) const;
295
296   uint64_t GetBitSize(ExecutionContextScope *exe_scope) const;
297
298   lldb::Encoding GetEncoding(uint64_t &count) const;
299
300   lldb::Format GetFormat() const;
301
302   size_t GetTypeBitAlign() const;
303
304   uint32_t GetNumChildren(bool omit_empty_base_classes) const;
305
306   lldb::BasicType GetBasicTypeEnumeration() const;
307
308   static lldb::BasicType GetBasicTypeEnumeration(const ConstString &name);
309
310   //----------------------------------------------------------------------
311   // If this type is an enumeration, iterate through all of its enumerators
312   // using a callback. If the callback returns true, keep iterating, else abort
313   // the iteration.
314   //----------------------------------------------------------------------
315   void ForEachEnumerator(
316       std::function<bool(const CompilerType &integer_type,
317                          const ConstString &name,
318                          const llvm::APSInt &value)> const &callback) const;
319
320   uint32_t GetNumFields() const;
321
322   CompilerType GetFieldAtIndex(size_t idx, std::string &name,
323                                uint64_t *bit_offset_ptr,
324                                uint32_t *bitfield_bit_size_ptr,
325                                bool *is_bitfield_ptr) const;
326
327   uint32_t GetNumDirectBaseClasses() const;
328
329   uint32_t GetNumVirtualBaseClasses() const;
330
331   CompilerType GetDirectBaseClassAtIndex(size_t idx,
332                                          uint32_t *bit_offset_ptr) const;
333
334   CompilerType GetVirtualBaseClassAtIndex(size_t idx,
335                                           uint32_t *bit_offset_ptr) const;
336
337   uint32_t GetIndexOfFieldWithName(const char *name,
338                                    CompilerType *field_compiler_type = nullptr,
339                                    uint64_t *bit_offset_ptr = nullptr,
340                                    uint32_t *bitfield_bit_size_ptr = nullptr,
341                                    bool *is_bitfield_ptr = nullptr) const;
342
343   CompilerType GetChildCompilerTypeAtIndex(
344       ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
345       bool omit_empty_base_classes, bool ignore_array_bounds,
346       std::string &child_name, uint32_t &child_byte_size,
347       int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
348       uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
349       bool &child_is_deref_of_parent, ValueObject *valobj,
350       uint64_t &language_flags) const;
351
352   // Lookup a child given a name. This function will match base class names and
353   // member member names in "clang_type" only, not descendants.
354   uint32_t GetIndexOfChildWithName(const char *name,
355                                    bool omit_empty_base_classes) const;
356
357   // Lookup a child member given a name. This function will match member names
358   // only and will descend into "clang_type" children in search for the first
359   // member in this class, or any base class that matches "name".
360   // TODO: Return all matches for a given name by returning a
361   // vector<vector<uint32_t>>
362   // so we catch all names that match a given child name, not just the first.
363   size_t
364   GetIndexOfChildMemberWithName(const char *name, bool omit_empty_base_classes,
365                                 std::vector<uint32_t> &child_indexes) const;
366
367   size_t GetNumTemplateArguments() const;
368
369   lldb::TemplateArgumentKind GetTemplateArgumentKind(size_t idx) const;
370   CompilerType GetTypeTemplateArgument(size_t idx) const;
371
372   // Returns the value of the template argument and its type.
373   llvm::Optional<IntegralTemplateArgument>
374   GetIntegralTemplateArgument(size_t idx) const;
375
376   CompilerType GetTypeForFormatters() const;
377
378   LazyBool ShouldPrintAsOneLiner(ValueObject *valobj) const;
379
380   bool IsMeaninglessWithoutDynamicResolution() const;
381
382   //------------------------------------------------------------------
383   // Pointers & References
384   //------------------------------------------------------------------
385
386   // Converts "s" to a floating point value and place resulting floating point
387   // bytes in the "dst" buffer.
388   size_t ConvertStringToFloatValue(const char *s, uint8_t *dst,
389                                    size_t dst_size) const;
390
391   //----------------------------------------------------------------------
392   // Dumping types
393   //----------------------------------------------------------------------
394   void DumpValue(ExecutionContext *exe_ctx, Stream *s, lldb::Format format,
395                  const DataExtractor &data, lldb::offset_t data_offset,
396                  size_t data_byte_size, uint32_t bitfield_bit_size,
397                  uint32_t bitfield_bit_offset, bool show_types,
398                  bool show_summary, bool verbose, uint32_t depth);
399
400   bool DumpTypeValue(Stream *s, lldb::Format format, const DataExtractor &data,
401                      lldb::offset_t data_offset, size_t data_byte_size,
402                      uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
403                      ExecutionContextScope *exe_scope);
404
405   void DumpSummary(ExecutionContext *exe_ctx, Stream *s,
406                    const DataExtractor &data, lldb::offset_t data_offset,
407                    size_t data_byte_size);
408
409   void DumpTypeDescription() const; // Dump to stdout
410
411   void DumpTypeDescription(Stream *s) const;
412
413   bool GetValueAsScalar(const DataExtractor &data, lldb::offset_t data_offset,
414                         size_t data_byte_size, Scalar &value) const;
415
416   bool SetValueFromScalar(const Scalar &value, Stream &strm);
417
418   bool ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t addr,
419                       AddressType address_type, DataExtractor &data);
420
421   bool WriteToMemory(ExecutionContext *exe_ctx, lldb::addr_t addr,
422                      AddressType address_type, StreamString &new_value);
423
424   void Clear() {
425     m_type = nullptr;
426     m_type_system = nullptr;
427   }
428
429 private:
430   lldb::opaque_compiler_type_t m_type;
431   TypeSystem *m_type_system;
432 };
433
434 bool operator==(const CompilerType &lhs, const CompilerType &rhs);
435 bool operator!=(const CompilerType &lhs, const CompilerType &rhs);
436
437 struct CompilerType::IntegralTemplateArgument {
438   llvm::APSInt value;
439   CompilerType type;
440 };
441
442 } // namespace lldb_private
443
444 #endif // liblldb_CompilerType_h_