1 //===-- CompilerType.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_CompilerType_h_
11 #define liblldb_CompilerType_h_
19 // Other libraries and framework includes
21 #include "lldb/lldb-private.h"
22 #include "lldb/Core/ClangForward.h"
24 namespace lldb_private {
26 //----------------------------------------------------------------------
27 // A class that can carry around a clang ASTContext and a opaque clang
28 // QualType. A clang::QualType can be easily reconstructed from an
29 // opaque clang type and often the ASTContext is needed when doing
30 // various type related tasks, so this class allows both items to travel
31 // in a single very lightweight class that can be used. There are many
32 // static equivalents of the member functions that allow the ASTContext
33 // and the opaque clang QualType to be specified for ease of use and
34 // to avoid code duplication.
35 //----------------------------------------------------------------------
39 //----------------------------------------------------------------------
40 // Constructors and Destructors
41 //----------------------------------------------------------------------
42 CompilerType (TypeSystem *type_system, lldb::opaque_compiler_type_t type);
43 CompilerType (clang::ASTContext *ast_context, clang::QualType qual_type);
45 CompilerType (const CompilerType &rhs) :
47 m_type_system (rhs.m_type_system)
53 m_type_system (nullptr)
59 //----------------------------------------------------------------------
61 //----------------------------------------------------------------------
64 operator= (const CompilerType &rhs)
67 m_type_system = rhs.m_type_system;
71 //----------------------------------------------------------------------
73 //----------------------------------------------------------------------
75 explicit operator bool () const
77 return m_type != nullptr && m_type_system != nullptr;
81 operator < (const CompilerType &rhs) const
83 if (m_type_system == rhs.m_type_system)
84 return m_type < rhs.m_type;
85 return m_type_system < rhs.m_type_system;
91 return m_type != nullptr && m_type_system != nullptr;
95 IsArrayType (CompilerType *element_type,
97 bool *is_incomplete) const;
100 IsVectorType (CompilerType *element_type,
101 uint64_t *size) const;
104 IsArrayOfScalarType () const;
107 IsAggregateType () const;
110 IsAnonymousType () const;
113 IsBeingDefined () const;
119 IsCompleteType () const;
125 IsCStringType (uint32_t &length) const;
131 IsFloatingPointType (uint32_t &count, bool &is_complex) const;
134 IsFunctionType(bool *is_variadic_ptr = nullptr) const;
137 IsHomogeneousAggregate (CompilerType* base_type_ptr) const;
140 GetNumberOfFunctionArguments () const;
143 GetFunctionArgumentAtIndex (const size_t index) const;
146 IsVariadicFunctionType () const;
149 IsFunctionPointerType () const;
152 IsIntegerType (bool &is_signed) const;
155 IsPolymorphicClass () const;
158 IsPossibleCPlusPlusDynamicType(CompilerType *target_type = nullptr) const
160 return IsPossibleDynamicType (target_type, true, false);
164 IsPossibleDynamicType(CompilerType *target_type, // Can pass nullptr
165 bool check_cplusplus,
166 bool check_objc) const;
169 IsPointerToScalarType () const;
172 IsRuntimeGeneratedType () const;
175 IsPointerType(CompilerType *pointee_type = nullptr) const;
178 IsPointerOrReferenceType(CompilerType *pointee_type = nullptr) const;
181 IsReferenceType(CompilerType *pointee_type = nullptr, bool* is_rvalue = nullptr) const;
184 ShouldTreatScalarValueAsAddress () const;
187 IsScalarType () const;
190 IsTypedefType () const;
195 //----------------------------------------------------------------------
197 //----------------------------------------------------------------------
200 GetCompleteType () const;
202 //----------------------------------------------------------------------
203 // AST related queries
204 //----------------------------------------------------------------------
207 GetPointerByteSize () const;
209 //----------------------------------------------------------------------
211 //----------------------------------------------------------------------
214 GetTypeSystem() const
216 return m_type_system;
220 GetConstQualifiedTypeName () const;
223 GetConstTypeName () const;
226 GetTypeName () const;
229 GetDisplayTypeName () const;
232 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr) const;
235 GetMinimumLanguage ();
237 lldb::opaque_compiler_type_t
238 GetOpaqueQualType() const
244 GetTypeClass () const;
247 SetCompilerType (TypeSystem* type_system, lldb::opaque_compiler_type_t type);
250 SetCompilerType (clang::ASTContext *ast, clang::QualType qual_type);
253 GetTypeQualifiers() const;
255 //----------------------------------------------------------------------
256 // Creating related types
257 //----------------------------------------------------------------------
260 GetArrayElementType(uint64_t *stride = nullptr) const;
263 GetCanonicalType () const;
266 GetFullyUnqualifiedType () const;
268 // Returns -1 if this isn't a function of if the function doesn't have a prototype
269 // Returns a value >= 0 if there is a prototype.
271 GetFunctionArgumentCount () const;
274 GetFunctionArgumentTypeAtIndex (size_t idx) const;
277 GetFunctionReturnType () const;
280 GetNumMemberFunctions () const;
282 TypeMemberFunctionImpl
283 GetMemberFunctionAtIndex (size_t idx);
285 //----------------------------------------------------------------------
286 // If this type is a reference to a type (L value or R value reference),
287 // return a new type with the reference removed, else return the current
289 //----------------------------------------------------------------------
291 GetNonReferenceType () const;
293 //----------------------------------------------------------------------
294 // If this type is a pointer type, return the type that the pointer
295 // points to, else return an invalid type.
296 //----------------------------------------------------------------------
298 GetPointeeType () const;
300 //----------------------------------------------------------------------
301 // Return a new CompilerType that is a pointer to this type
302 //----------------------------------------------------------------------
304 GetPointerType () const;
306 //----------------------------------------------------------------------
307 // Return a new CompilerType that is a L value reference to this type if
308 // this type is valid and the type system supports L value references,
309 // else return an invalid type.
310 //----------------------------------------------------------------------
312 GetLValueReferenceType () const;
314 //----------------------------------------------------------------------
315 // Return a new CompilerType that is a R value reference to this type if
316 // this type is valid and the type system supports R value references,
317 // else return an invalid type.
318 //----------------------------------------------------------------------
320 GetRValueReferenceType () const;
322 //----------------------------------------------------------------------
323 // Return a new CompilerType adds a const modifier to this type if
324 // this type is valid and the type system supports const modifiers,
325 // else return an invalid type.
326 //----------------------------------------------------------------------
328 AddConstModifier () const;
330 //----------------------------------------------------------------------
331 // Return a new CompilerType adds a volatile modifier to this type if
332 // this type is valid and the type system supports volatile modifiers,
333 // else return an invalid type.
334 //----------------------------------------------------------------------
336 AddVolatileModifier () const;
338 //----------------------------------------------------------------------
339 // Return a new CompilerType adds a restrict modifier to this type if
340 // this type is valid and the type system supports restrict modifiers,
341 // else return an invalid type.
342 //----------------------------------------------------------------------
344 AddRestrictModifier () const;
346 //----------------------------------------------------------------------
347 // Create a typedef to this type using "name" as the name of the typedef
348 // this type is valid and the type system supports typedefs, else return
350 //----------------------------------------------------------------------
352 CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
354 // If the current object represents a typedef type, get the underlying type
356 GetTypedefedType () const;
358 //----------------------------------------------------------------------
359 // Create related types using the current type's AST
360 //----------------------------------------------------------------------
362 GetBasicTypeFromAST (lldb::BasicType basic_type) const;
364 //----------------------------------------------------------------------
365 // Exploring the type
366 //----------------------------------------------------------------------
369 GetByteSize (ExecutionContextScope *exe_scope) const;
372 GetBitSize (ExecutionContextScope *exe_scope) const;
375 GetEncoding (uint64_t &count) const;
381 GetTypeBitAlign () const;
384 GetNumChildren (bool omit_empty_base_classes) const;
387 GetBasicTypeEnumeration () const;
389 static lldb::BasicType
390 GetBasicTypeEnumeration (const ConstString &name);
392 //----------------------------------------------------------------------
393 // If this type is an enumeration, iterate through all of its enumerators
394 // using a callback. If the callback returns true, keep iterating, else
395 // abort the iteration.
396 //----------------------------------------------------------------------
398 ForEachEnumerator (std::function <bool (const CompilerType &integer_type,
399 const ConstString &name,
400 const llvm::APSInt &value)> const &callback) const;
403 GetNumFields () const;
406 GetFieldAtIndex (size_t idx,
408 uint64_t *bit_offset_ptr,
409 uint32_t *bitfield_bit_size_ptr,
410 bool *is_bitfield_ptr) const;
413 GetNumDirectBaseClasses () const;
416 GetNumVirtualBaseClasses () const;
419 GetDirectBaseClassAtIndex (size_t idx,
420 uint32_t *bit_offset_ptr) const;
423 GetVirtualBaseClassAtIndex (size_t idx,
424 uint32_t *bit_offset_ptr) const;
427 GetIndexOfFieldWithName(const char* name,
428 CompilerType* field_compiler_type = nullptr,
429 uint64_t *bit_offset_ptr = nullptr,
430 uint32_t *bitfield_bit_size_ptr = nullptr,
431 bool *is_bitfield_ptr = nullptr) const;
434 GetChildCompilerTypeAtIndex (ExecutionContext *exe_ctx,
436 bool transparent_pointers,
437 bool omit_empty_base_classes,
438 bool ignore_array_bounds,
439 std::string& child_name,
440 uint32_t &child_byte_size,
441 int32_t &child_byte_offset,
442 uint32_t &child_bitfield_bit_size,
443 uint32_t &child_bitfield_bit_offset,
444 bool &child_is_base_class,
445 bool &child_is_deref_of_parent,
447 uint64_t &language_flags) const;
449 // Lookup a child given a name. This function will match base class names
450 // and member member names in "clang_type" only, not descendants.
452 GetIndexOfChildWithName (const char *name,
453 bool omit_empty_base_classes) const;
455 // Lookup a child member given a name. This function will match member names
456 // only and will descend into "clang_type" children in search for the first
457 // member in this class, or any base class that matches "name".
458 // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
459 // so we catch all names that match a given child name, not just the first.
461 GetIndexOfChildMemberWithName (const char *name,
462 bool omit_empty_base_classes,
463 std::vector<uint32_t>& child_indexes) const;
466 GetNumTemplateArguments () const;
469 GetTemplateArgument (size_t idx,
470 lldb::TemplateArgumentKind &kind) const;
473 GetTypeForFormatters () const;
476 ShouldPrintAsOneLiner (ValueObject* valobj) const;
479 IsMeaninglessWithoutDynamicResolution () const;
481 //------------------------------------------------------------------
482 // Pointers & References
483 //------------------------------------------------------------------
485 // Converts "s" to a floating point value and place resulting floating
486 // point bytes in the "dst" buffer.
488 ConvertStringToFloatValue (const char *s,
490 size_t dst_size) const;
492 //----------------------------------------------------------------------
494 //----------------------------------------------------------------------
496 DumpValue (ExecutionContext *exe_ctx,
499 const DataExtractor &data,
500 lldb::offset_t data_offset,
501 size_t data_byte_size,
502 uint32_t bitfield_bit_size,
503 uint32_t bitfield_bit_offset,
510 DumpTypeValue (Stream *s,
512 const DataExtractor &data,
513 lldb::offset_t data_offset,
514 size_t data_byte_size,
515 uint32_t bitfield_bit_size,
516 uint32_t bitfield_bit_offset,
517 ExecutionContextScope *exe_scope);
520 DumpSummary (ExecutionContext *exe_ctx,
522 const DataExtractor &data,
523 lldb::offset_t data_offset,
524 size_t data_byte_size);
527 DumpTypeDescription () const; // Dump to stdout
530 DumpTypeDescription (Stream *s) const;
533 GetValueAsScalar (const DataExtractor &data,
534 lldb::offset_t data_offset,
535 size_t data_byte_size,
536 Scalar &value) const;
539 SetValueFromScalar (const Scalar &value,
543 ReadFromMemory (ExecutionContext *exe_ctx,
545 AddressType address_type,
546 DataExtractor &data);
549 WriteToMemory (ExecutionContext *exe_ctx,
551 AddressType address_type,
552 StreamString &new_value);
558 m_type_system = nullptr;
562 lldb::opaque_compiler_type_t m_type;
563 TypeSystem *m_type_system;
566 bool operator == (const CompilerType &lhs, const CompilerType &rhs);
567 bool operator != (const CompilerType &lhs, const CompilerType &rhs);
569 } // namespace lldb_private
571 #endif // liblldb_CompilerType_h_