1 //===-- ClangASTType.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_ClangASTType_h_
11 #define liblldb_ClangASTType_h_
14 #include "lldb/lldb-private.h"
15 #include "lldb/Core/ClangForward.h"
16 #include "clang/AST/Type.h"
18 namespace lldb_private {
20 //----------------------------------------------------------------------
21 // A class that can carry around a clang ASTContext and a opaque clang
22 // QualType. A clang::QualType can be easily reconstructed from an
23 // opaque clang type and often the ASTContext is needed when doing
24 // various type related tasks, so this class allows both items to travel
25 // in a single very lightweight class that can be used. There are many
26 // static equivalents of the member functions that allow the ASTContext
27 // and the opaque clang QualType to be specified for ease of use and
28 // to avoid code duplication.
29 //----------------------------------------------------------------------
34 eTypeHasChildren = (1u << 0),
35 eTypeHasValue = (1u << 1),
36 eTypeIsArray = (1u << 2),
37 eTypeIsBlock = (1u << 3),
38 eTypeIsBuiltIn = (1u << 4),
39 eTypeIsClass = (1u << 5),
40 eTypeIsCPlusPlus = (1u << 6),
41 eTypeIsEnumeration = (1u << 7),
42 eTypeIsFuncPrototype = (1u << 8),
43 eTypeIsMember = (1u << 9),
44 eTypeIsObjC = (1u << 10),
45 eTypeIsPointer = (1u << 11),
46 eTypeIsReference = (1u << 12),
47 eTypeIsStructUnion = (1u << 13),
48 eTypeIsTemplate = (1u << 14),
49 eTypeIsTypedef = (1u << 15),
50 eTypeIsVector = (1u << 16),
51 eTypeIsScalar = (1u << 17),
52 eTypeIsInteger = (1u << 18),
53 eTypeIsFloat = (1u << 19),
54 eTypeIsComplex = (1u << 20),
55 eTypeIsSigned = (1u << 21)
59 //----------------------------------------------------------------------
60 // Constructors and Destructors
61 //----------------------------------------------------------------------
62 ClangASTType (clang::ASTContext *ast_context, lldb::clang_type_t type) :
68 ClangASTType (clang::ASTContext *ast_context, clang::QualType qual_type);
70 ClangASTType (const ClangASTType &rhs) :
84 //----------------------------------------------------------------------
86 //----------------------------------------------------------------------
89 operator= (const ClangASTType &rhs)
97 //----------------------------------------------------------------------
99 //----------------------------------------------------------------------
101 explicit operator bool () const
103 return m_type != NULL && m_ast != NULL;
107 operator < (const ClangASTType &rhs) const
109 if (m_ast == rhs.m_ast)
110 return m_type < rhs.m_type;
111 return m_ast < rhs.m_ast;
117 return m_type != NULL && m_ast != NULL;
121 IsArrayType (ClangASTType *element_type,
123 bool *is_incomplete) const;
126 IsArrayOfScalarType () const;
129 IsAggregateType () const;
132 IsBeingDefined () const;
138 IsCompleteType () const;
144 IsCStringType (uint32_t &length) const;
147 IsCXXClassType () const;
153 IsFloatingPointType (uint32_t &count, bool &is_complex) const;
156 IsFunctionType (bool *is_variadic_ptr = NULL) const;
159 GetNumberOfFunctionArguments () const;
162 GetFunctionArgumentAtIndex (const size_t index);
165 IsVariadicFunctionType () const;
168 IsFunctionPointerType () const;
171 IsIntegerType (bool &is_signed) const;
174 IsObjCClassType () const;
177 IsObjCClassTypeAndHasIVars (bool check_superclass) const;
180 IsObjCObjectOrInterfaceType () const;
183 IsObjCObjectPointerType (ClangASTType *target_type = NULL);
186 IsPolymorphicClass () const;
189 IsPossibleCPlusPlusDynamicType (ClangASTType *target_type = NULL) const
191 return IsPossibleDynamicType (target_type, true, false);
195 IsPossibleDynamicType (ClangASTType *target_type, // Can pass NULL
196 bool check_cplusplus,
197 bool check_objc) const;
201 IsPointerToScalarType () const;
204 IsRuntimeGeneratedType () const;
207 IsPointerType (ClangASTType *pointee_type = NULL) const;
210 IsPointerOrReferenceType (ClangASTType *pointee_type = NULL) const;
213 IsReferenceType (ClangASTType *pointee_type = NULL) const;
216 IsScalarType () const;
219 IsTypedefType () const;
225 GetCXXClassName (std::string &class_name) const;
228 GetObjCClassName (std::string &class_name);
231 //----------------------------------------------------------------------
233 //----------------------------------------------------------------------
236 GetCompleteType () const;
238 //----------------------------------------------------------------------
239 // AST related queries
240 //----------------------------------------------------------------------
243 GetPointerByteSize () const;
245 //----------------------------------------------------------------------
247 //----------------------------------------------------------------------
250 GetASTContext() const
256 GetConstQualifiedTypeName () const;
259 GetConstTypeName () const;
262 GetTypeName () const;
265 GetTypeInfo (ClangASTType *pointee_or_element_clang_type = NULL) const;
268 GetMinimumLanguage ();
271 GetOpaqueQualType() const
277 GetTypeClass () const;
280 SetClangType (clang::ASTContext *ast, lldb::clang_type_t type)
287 SetClangType (clang::ASTContext *ast, clang::QualType qual_type);
290 GetTypeQualifiers() const;
292 //----------------------------------------------------------------------
293 // Creating related types
294 //----------------------------------------------------------------------
297 AddConstModifier () const;
300 AddRestrictModifier () const;
303 AddVolatileModifier () const;
305 // Using the current type, create a new typedef to that type using "typedef_name"
306 // as the name and "decl_ctx" as the decl context.
308 CreateTypedefType (const char *typedef_name,
309 clang::DeclContext *decl_ctx) const;
312 GetArrayElementType (uint64_t& stride) const;
315 GetCanonicalType () const;
318 GetFullyUnqualifiedType () const;
320 // Returns -1 if this isn't a function of if the fucntion doesn't have a prototype
321 // Returns a value >= 0 if there is a prototype.
323 GetFunctionArgumentCount () const;
326 GetFunctionArgumentTypeAtIndex (size_t idx);
329 GetFunctionReturnType () const;
332 GetLValueReferenceType () const;
335 GetNonReferenceType () const;
338 GetPointeeType () const;
341 GetPointerType () const;
344 GetRValueReferenceType () const;
346 // If the current object represents a typedef type, get the underlying type
348 GetTypedefedType () const;
351 RemoveFastQualifiers () const;
353 //----------------------------------------------------------------------
354 // Create related types using the current type's AST
355 //----------------------------------------------------------------------
357 GetBasicTypeFromAST (lldb::BasicType basic_type) const;
359 //----------------------------------------------------------------------
360 // Exploring the type
361 //----------------------------------------------------------------------
364 GetByteSize () const;
370 GetEncoding (uint64_t &count) const;
376 GetTypeBitAlign () const;
379 GetNumChildren (bool omit_empty_base_classes) const;
382 GetBasicTypeEnumeration () const;
384 static lldb::BasicType
385 GetBasicTypeEnumeration (const ConstString &name);
388 GetNumDirectBaseClasses () const;
391 GetNumVirtualBaseClasses () const;
394 GetNumFields () const;
397 GetDirectBaseClassAtIndex (size_t idx,
398 uint32_t *bit_offset_ptr) const;
401 GetVirtualBaseClassAtIndex (size_t idx,
402 uint32_t *bit_offset_ptr) const;
405 GetFieldAtIndex (size_t idx,
407 uint64_t *bit_offset_ptr,
408 uint32_t *bitfield_bit_size_ptr,
409 bool *is_bitfield_ptr) const;
412 GetIndexOfFieldWithName (const char* name,
413 ClangASTType* field_clang_type = NULL,
414 uint64_t *bit_offset_ptr = NULL,
415 uint32_t *bitfield_bit_size_ptr = NULL,
416 bool *is_bitfield_ptr = NULL) const;
419 GetNumPointeeChildren () const;
422 GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
423 const char *parent_name,
425 bool transparent_pointers,
426 bool omit_empty_base_classes,
427 bool ignore_array_bounds,
428 std::string& child_name,
429 uint32_t &child_byte_size,
430 int32_t &child_byte_offset,
431 uint32_t &child_bitfield_bit_size,
432 uint32_t &child_bitfield_bit_offset,
433 bool &child_is_base_class,
434 bool &child_is_deref_of_parent) const;
436 // Lookup a child given a name. This function will match base class names
437 // and member member names in "clang_type" only, not descendants.
439 GetIndexOfChildWithName (const char *name,
440 bool omit_empty_base_classes) const;
442 // Lookup a child member given a name. This function will match member names
443 // only and will descend into "clang_type" children in search for the first
444 // member in this class, or any base class that matches "name".
445 // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
446 // so we catch all names that match a given child name, not just the first.
448 GetIndexOfChildMemberWithName (const char *name,
449 bool omit_empty_base_classes,
450 std::vector<uint32_t>& child_indexes) const;
453 GetNumTemplateArguments () const;
456 GetTemplateArgument (size_t idx,
457 lldb::TemplateArgumentKind &kind) const;
460 //----------------------------------------------------------------------
461 // Modifying RecordType
462 //----------------------------------------------------------------------
464 AddFieldToRecordType (const char *name,
465 const ClangASTType &field_type,
466 lldb::AccessType access,
467 uint32_t bitfield_bit_size);
470 BuildIndirectFields ();
473 AddVariableToRecordType (const char *name,
474 const ClangASTType &var_type,
475 lldb::AccessType access);
477 clang::CXXMethodDecl *
478 AddMethodToCXXRecordType (const char *name,
479 const ClangASTType &method_type,
480 lldb::AccessType access,
489 clang::CXXBaseSpecifier *
490 CreateBaseClassSpecifier (lldb::AccessType access,
495 DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes,
496 unsigned num_base_classes);
499 SetBaseClassesForClassType (clang::CXXBaseSpecifier const * const *base_classes,
500 unsigned num_base_classes);
504 SetObjCSuperClass (const ClangASTType &superclass_clang_type);
507 AddObjCClassProperty (const char *property_name,
508 const ClangASTType &property_clang_type,
509 clang::ObjCIvarDecl *ivar_decl,
510 const char *property_setter_name,
511 const char *property_getter_name,
512 uint32_t property_attributes,
513 ClangASTMetadata *metadata);
515 clang::ObjCMethodDecl *
516 AddMethodToObjCObjectType (const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]")
517 const ClangASTType &method_clang_type,
518 lldb::AccessType access,
522 GetDeclContextForType () const;
526 SetDefaultAccessForRecordFields (int default_accessibility,
527 int *assigned_accessibilities,
528 size_t num_assigned_accessibilities);
531 SetHasExternalStorage (bool has_extern);
534 //------------------------------------------------------------------
536 //------------------------------------------------------------------
539 SetTagTypeKind (int kind) const;
541 //------------------------------------------------------------------
543 //------------------------------------------------------------------
545 StartTagDeclarationDefinition ();
548 CompleteTagDeclarationDefinition ();
550 //----------------------------------------------------------------------
551 // Modifying Enumeration types
552 //----------------------------------------------------------------------
554 AddEnumerationValueToEnumerationType (const ClangASTType &enumerator_qual_type,
555 const Declaration &decl,
558 uint32_t enum_value_bit_size);
563 GetEnumerationIntegerType () const;
566 //------------------------------------------------------------------
567 // Pointers & References
568 //------------------------------------------------------------------
570 // Call this function using the class type when you want to make a
571 // member pointer type to pointee_type.
573 CreateMemberPointerType (const ClangASTType &pointee_type) const;
576 // Converts "s" to a floating point value and place resulting floating
577 // point bytes in the "dst" buffer.
579 ConvertStringToFloatValue (const char *s,
581 size_t dst_size) const;
582 //----------------------------------------------------------------------
584 //----------------------------------------------------------------------
586 DumpValue (ExecutionContext *exe_ctx,
589 const DataExtractor &data,
590 lldb::offset_t data_offset,
591 size_t data_byte_size,
592 uint32_t bitfield_bit_size,
593 uint32_t bitfield_bit_offset,
600 DumpTypeValue (Stream *s,
602 const DataExtractor &data,
603 lldb::offset_t data_offset,
604 size_t data_byte_size,
605 uint32_t bitfield_bit_size,
606 uint32_t bitfield_bit_offset,
607 ExecutionContextScope *exe_scope);
610 DumpSummary (ExecutionContext *exe_ctx,
612 const DataExtractor &data,
613 lldb::offset_t data_offset,
614 size_t data_byte_size);
617 DumpTypeDescription () const; // Dump to stdout
620 DumpTypeDescription (Stream *s) const;
623 GetValueAsScalar (const DataExtractor &data,
624 lldb::offset_t data_offset,
625 size_t data_byte_size,
626 Scalar &value) const;
629 SetValueFromScalar (const Scalar &value,
633 ReadFromMemory (ExecutionContext *exe_ctx,
635 AddressType address_type,
636 DataExtractor &data);
639 WriteToMemory (ExecutionContext *exe_ctx,
641 AddressType address_type,
642 StreamString &new_value);
646 GetAsRecordDecl () const;
648 clang::CXXRecordDecl *
649 GetAsCXXRecordDecl () const;
651 clang::ObjCInterfaceDecl *
652 GetAsObjCInterfaceDecl () const;
665 return clang::QualType::getFromOpaquePtr(m_type);
666 return clang::QualType();
669 GetCanonicalQualType () const
672 return clang::QualType::getFromOpaquePtr(m_type).getCanonicalType();
673 return clang::QualType();
677 lldb::clang_type_t m_type;
678 clang::ASTContext *m_ast;
682 bool operator == (const ClangASTType &lhs, const ClangASTType &rhs);
683 bool operator != (const ClangASTType &lhs, const ClangASTType &rhs);
686 } // namespace lldb_private
688 #endif // #ifndef liblldb_ClangASTType_h_