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 IsBlockPointerType (CompilerType *function_pointer_type_ptr) const;
155 IsIntegerType (bool &is_signed) const;
158 IsEnumerationType (bool &is_signed) const;
161 IsIntegerOrEnumerationType (bool &is_signed) const;
164 IsPolymorphicClass () const;
167 IsPossibleCPlusPlusDynamicType(CompilerType *target_type = nullptr) const
169 return IsPossibleDynamicType (target_type, true, false);
173 IsPossibleDynamicType(CompilerType *target_type, // Can pass nullptr
174 bool check_cplusplus,
175 bool check_objc) const;
178 IsPointerToScalarType () const;
181 IsRuntimeGeneratedType () const;
184 IsPointerType(CompilerType *pointee_type = nullptr) const;
187 IsPointerOrReferenceType(CompilerType *pointee_type = nullptr) const;
190 IsReferenceType(CompilerType *pointee_type = nullptr, bool* is_rvalue = nullptr) const;
193 ShouldTreatScalarValueAsAddress () const;
196 IsScalarType () const;
199 IsTypedefType () const;
204 //----------------------------------------------------------------------
206 //----------------------------------------------------------------------
209 GetCompleteType () const;
211 //----------------------------------------------------------------------
212 // AST related queries
213 //----------------------------------------------------------------------
216 GetPointerByteSize () const;
218 //----------------------------------------------------------------------
220 //----------------------------------------------------------------------
223 GetTypeSystem() const
225 return m_type_system;
229 GetConstQualifiedTypeName () const;
232 GetConstTypeName () const;
235 GetTypeName () const;
238 GetDisplayTypeName () const;
241 GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr) const;
244 GetMinimumLanguage ();
246 lldb::opaque_compiler_type_t
247 GetOpaqueQualType() const
253 GetTypeClass () const;
256 SetCompilerType (TypeSystem* type_system, lldb::opaque_compiler_type_t type);
259 SetCompilerType (clang::ASTContext *ast, clang::QualType qual_type);
262 GetTypeQualifiers() const;
264 //----------------------------------------------------------------------
265 // Creating related types
266 //----------------------------------------------------------------------
269 GetArrayElementType(uint64_t *stride = nullptr) const;
272 GetCanonicalType () const;
275 GetFullyUnqualifiedType () const;
277 // Returns -1 if this isn't a function of if the function doesn't have a prototype
278 // Returns a value >= 0 if there is a prototype.
280 GetFunctionArgumentCount () const;
283 GetFunctionArgumentTypeAtIndex (size_t idx) const;
286 GetFunctionReturnType () const;
289 GetNumMemberFunctions () const;
291 TypeMemberFunctionImpl
292 GetMemberFunctionAtIndex (size_t idx);
294 //----------------------------------------------------------------------
295 // If this type is a reference to a type (L value or R value reference),
296 // return a new type with the reference removed, else return the current
298 //----------------------------------------------------------------------
300 GetNonReferenceType () const;
302 //----------------------------------------------------------------------
303 // If this type is a pointer type, return the type that the pointer
304 // points to, else return an invalid type.
305 //----------------------------------------------------------------------
307 GetPointeeType () const;
309 //----------------------------------------------------------------------
310 // Return a new CompilerType that is a pointer to this type
311 //----------------------------------------------------------------------
313 GetPointerType () const;
315 //----------------------------------------------------------------------
316 // Return a new CompilerType that is a L value reference to this type if
317 // this type is valid and the type system supports L value references,
318 // else return an invalid type.
319 //----------------------------------------------------------------------
321 GetLValueReferenceType () const;
323 //----------------------------------------------------------------------
324 // Return a new CompilerType that is a R value reference to this type if
325 // this type is valid and the type system supports R value references,
326 // else return an invalid type.
327 //----------------------------------------------------------------------
329 GetRValueReferenceType () const;
331 //----------------------------------------------------------------------
332 // Return a new CompilerType adds a const modifier to this type if
333 // this type is valid and the type system supports const modifiers,
334 // else return an invalid type.
335 //----------------------------------------------------------------------
337 AddConstModifier () const;
339 //----------------------------------------------------------------------
340 // Return a new CompilerType adds a volatile modifier to this type if
341 // this type is valid and the type system supports volatile modifiers,
342 // else return an invalid type.
343 //----------------------------------------------------------------------
345 AddVolatileModifier () const;
347 //----------------------------------------------------------------------
348 // Return a new CompilerType adds a restrict modifier to this type if
349 // this type is valid and the type system supports restrict modifiers,
350 // else return an invalid type.
351 //----------------------------------------------------------------------
353 AddRestrictModifier () const;
355 //----------------------------------------------------------------------
356 // Create a typedef to this type using "name" as the name of the typedef
357 // this type is valid and the type system supports typedefs, else return
359 //----------------------------------------------------------------------
361 CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
363 // If the current object represents a typedef type, get the underlying type
365 GetTypedefedType () const;
367 //----------------------------------------------------------------------
368 // Create related types using the current type's AST
369 //----------------------------------------------------------------------
371 GetBasicTypeFromAST (lldb::BasicType basic_type) const;
373 //----------------------------------------------------------------------
374 // Exploring the type
375 //----------------------------------------------------------------------
378 GetByteSize (ExecutionContextScope *exe_scope) const;
381 GetBitSize (ExecutionContextScope *exe_scope) const;
384 GetEncoding (uint64_t &count) const;
390 GetTypeBitAlign () const;
393 GetNumChildren (bool omit_empty_base_classes) const;
396 GetBasicTypeEnumeration () const;
398 static lldb::BasicType
399 GetBasicTypeEnumeration (const ConstString &name);
401 //----------------------------------------------------------------------
402 // If this type is an enumeration, iterate through all of its enumerators
403 // using a callback. If the callback returns true, keep iterating, else
404 // abort the iteration.
405 //----------------------------------------------------------------------
407 ForEachEnumerator (std::function <bool (const CompilerType &integer_type,
408 const ConstString &name,
409 const llvm::APSInt &value)> const &callback) const;
412 GetNumFields () const;
415 GetFieldAtIndex (size_t idx,
417 uint64_t *bit_offset_ptr,
418 uint32_t *bitfield_bit_size_ptr,
419 bool *is_bitfield_ptr) const;
422 GetNumDirectBaseClasses () const;
425 GetNumVirtualBaseClasses () const;
428 GetDirectBaseClassAtIndex (size_t idx,
429 uint32_t *bit_offset_ptr) const;
432 GetVirtualBaseClassAtIndex (size_t idx,
433 uint32_t *bit_offset_ptr) const;
436 GetIndexOfFieldWithName(const char* name,
437 CompilerType* field_compiler_type = nullptr,
438 uint64_t *bit_offset_ptr = nullptr,
439 uint32_t *bitfield_bit_size_ptr = nullptr,
440 bool *is_bitfield_ptr = nullptr) const;
443 GetChildCompilerTypeAtIndex (ExecutionContext *exe_ctx,
445 bool transparent_pointers,
446 bool omit_empty_base_classes,
447 bool ignore_array_bounds,
448 std::string& child_name,
449 uint32_t &child_byte_size,
450 int32_t &child_byte_offset,
451 uint32_t &child_bitfield_bit_size,
452 uint32_t &child_bitfield_bit_offset,
453 bool &child_is_base_class,
454 bool &child_is_deref_of_parent,
456 uint64_t &language_flags) const;
458 // Lookup a child given a name. This function will match base class names
459 // and member member names in "clang_type" only, not descendants.
461 GetIndexOfChildWithName (const char *name,
462 bool omit_empty_base_classes) const;
464 // Lookup a child member given a name. This function will match member names
465 // only and will descend into "clang_type" children in search for the first
466 // member in this class, or any base class that matches "name".
467 // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
468 // so we catch all names that match a given child name, not just the first.
470 GetIndexOfChildMemberWithName (const char *name,
471 bool omit_empty_base_classes,
472 std::vector<uint32_t>& child_indexes) const;
475 GetNumTemplateArguments () const;
478 GetTemplateArgument (size_t idx,
479 lldb::TemplateArgumentKind &kind) const;
482 GetTypeForFormatters () const;
485 ShouldPrintAsOneLiner (ValueObject* valobj) const;
488 IsMeaninglessWithoutDynamicResolution () const;
490 //------------------------------------------------------------------
491 // Pointers & References
492 //------------------------------------------------------------------
494 // Converts "s" to a floating point value and place resulting floating
495 // point bytes in the "dst" buffer.
497 ConvertStringToFloatValue (const char *s,
499 size_t dst_size) const;
501 //----------------------------------------------------------------------
503 //----------------------------------------------------------------------
505 DumpValue (ExecutionContext *exe_ctx,
508 const DataExtractor &data,
509 lldb::offset_t data_offset,
510 size_t data_byte_size,
511 uint32_t bitfield_bit_size,
512 uint32_t bitfield_bit_offset,
519 DumpTypeValue (Stream *s,
521 const DataExtractor &data,
522 lldb::offset_t data_offset,
523 size_t data_byte_size,
524 uint32_t bitfield_bit_size,
525 uint32_t bitfield_bit_offset,
526 ExecutionContextScope *exe_scope);
529 DumpSummary (ExecutionContext *exe_ctx,
531 const DataExtractor &data,
532 lldb::offset_t data_offset,
533 size_t data_byte_size);
536 DumpTypeDescription () const; // Dump to stdout
539 DumpTypeDescription (Stream *s) const;
542 GetValueAsScalar (const DataExtractor &data,
543 lldb::offset_t data_offset,
544 size_t data_byte_size,
545 Scalar &value) const;
548 SetValueFromScalar (const Scalar &value,
552 ReadFromMemory (ExecutionContext *exe_ctx,
554 AddressType address_type,
555 DataExtractor &data);
558 WriteToMemory (ExecutionContext *exe_ctx,
560 AddressType address_type,
561 StreamString &new_value);
567 m_type_system = nullptr;
571 lldb::opaque_compiler_type_t m_type;
572 TypeSystem *m_type_system;
575 bool operator == (const CompilerType &lhs, const CompilerType &rhs);
576 bool operator != (const CompilerType &lhs, const CompilerType &rhs);
578 } // namespace lldb_private
580 #endif // liblldb_CompilerType_h_