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 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 IsVariadicFunctionType () const;
162 IsFunctionPointerType () const;
165 IsIntegerType (bool &is_signed) const;
168 IsObjCClassType () const;
171 IsObjCClassTypeAndHasIVars (bool check_superclass) const;
174 IsObjCObjectOrInterfaceType () const;
177 IsObjCObjectPointerType (ClangASTType *target_type = NULL);
180 IsPolymorphicClass () const;
183 IsPossibleCPlusPlusDynamicType (ClangASTType *target_type = NULL) const
185 return IsPossibleDynamicType (target_type, true, false);
189 IsPossibleDynamicType (ClangASTType *target_type, // Can pass NULL
190 bool check_cplusplus,
191 bool check_objc) const;
195 IsPointerToScalarType () const;
198 IsPointerType (ClangASTType *pointee_type = NULL) const;
201 IsPointerOrReferenceType (ClangASTType *pointee_type = NULL) const;
204 IsReferenceType (ClangASTType *pointee_type = NULL) const;
207 IsScalarType () const;
210 IsTypedefType () const;
216 GetCXXClassName (std::string &class_name) const;
219 GetObjCClassName (std::string &class_name);
222 //----------------------------------------------------------------------
224 //----------------------------------------------------------------------
227 GetCompleteType () const;
229 //----------------------------------------------------------------------
230 // AST related queries
231 //----------------------------------------------------------------------
234 GetPointerByteSize () const;
236 //----------------------------------------------------------------------
238 //----------------------------------------------------------------------
241 GetASTContext() const
247 GetConstQualifiedTypeName () const;
250 GetConstTypeName () const;
253 GetTypeName () const;
256 GetTypeInfo (ClangASTType *pointee_or_element_clang_type = NULL) const;
259 GetMinimumLanguage ();
262 GetOpaqueQualType() const
268 GetTypeClass () const;
271 SetClangType (clang::ASTContext *ast, lldb::clang_type_t type)
278 SetClangType (clang::ASTContext *ast, clang::QualType qual_type);
281 GetTypeQualifiers() const;
283 //----------------------------------------------------------------------
284 // Creating related types
285 //----------------------------------------------------------------------
288 AddConstModifier () const;
291 AddRestrictModifier () const;
294 AddVolatileModifier () const;
296 // Using the current type, create a new typedef to that type using "typedef_name"
297 // as the name and "decl_ctx" as the decl context.
299 CreateTypedefType (const char *typedef_name,
300 clang::DeclContext *decl_ctx) const;
303 GetArrayElementType (uint64_t& stride) const;
306 GetCanonicalType () const;
309 GetFullyUnqualifiedType () const;
311 // Returns -1 if this isn't a function of if the fucntion doesn't have a prototype
312 // Returns a value >= 0 if there is a prototype.
314 GetFunctionArgumentCount () const;
317 GetFunctionArgumentTypeAtIndex (size_t idx);
320 GetFunctionReturnType () const;
323 GetLValueReferenceType () const;
326 GetNonReferenceType () const;
329 GetPointeeType () const;
332 GetPointerType () const;
335 GetRValueReferenceType () const;
337 // If the current object represents a typedef type, get the underlying type
339 GetTypedefedType () const;
342 RemoveFastQualifiers () const;
344 //----------------------------------------------------------------------
345 // Create related types using the current type's AST
346 //----------------------------------------------------------------------
348 GetBasicTypeFromAST (lldb::BasicType basic_type) const;
350 //----------------------------------------------------------------------
351 // Exploring the type
352 //----------------------------------------------------------------------
355 GetByteSize () const;
361 GetEncoding (uint64_t &count) const;
367 GetTypeBitAlign () const;
370 GetNumChildren (bool omit_empty_base_classes) const;
373 GetBasicTypeEnumeration () const;
375 static lldb::BasicType
376 GetBasicTypeEnumeration (const ConstString &name);
379 GetNumDirectBaseClasses () const;
382 GetNumVirtualBaseClasses () const;
385 GetNumFields () const;
388 GetDirectBaseClassAtIndex (size_t idx,
389 uint32_t *bit_offset_ptr) const;
392 GetVirtualBaseClassAtIndex (size_t idx,
393 uint32_t *bit_offset_ptr) const;
396 GetFieldAtIndex (size_t idx,
398 uint64_t *bit_offset_ptr,
399 uint32_t *bitfield_bit_size_ptr,
400 bool *is_bitfield_ptr) const;
403 GetIndexOfFieldWithName (const char* name,
404 ClangASTType* field_clang_type = NULL,
405 uint64_t *bit_offset_ptr = NULL,
406 uint32_t *bitfield_bit_size_ptr = NULL,
407 bool *is_bitfield_ptr = NULL) const;
410 GetNumPointeeChildren () const;
413 GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
414 const char *parent_name,
416 bool transparent_pointers,
417 bool omit_empty_base_classes,
418 bool ignore_array_bounds,
419 std::string& child_name,
420 uint32_t &child_byte_size,
421 int32_t &child_byte_offset,
422 uint32_t &child_bitfield_bit_size,
423 uint32_t &child_bitfield_bit_offset,
424 bool &child_is_base_class,
425 bool &child_is_deref_of_parent) const;
427 // Lookup a child given a name. This function will match base class names
428 // and member member names in "clang_type" only, not descendants.
430 GetIndexOfChildWithName (const char *name,
431 bool omit_empty_base_classes) const;
433 // Lookup a child member given a name. This function will match member names
434 // only and will descend into "clang_type" children in search for the first
435 // member in this class, or any base class that matches "name".
436 // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
437 // so we catch all names that match a given child name, not just the first.
439 GetIndexOfChildMemberWithName (const char *name,
440 bool omit_empty_base_classes,
441 std::vector<uint32_t>& child_indexes) const;
444 GetNumTemplateArguments () const;
447 GetTemplateArgument (size_t idx,
448 lldb::TemplateArgumentKind &kind) const;
451 //----------------------------------------------------------------------
452 // Modifying RecordType
453 //----------------------------------------------------------------------
455 AddFieldToRecordType (const char *name,
456 const ClangASTType &field_type,
457 lldb::AccessType access,
458 uint32_t bitfield_bit_size);
461 BuildIndirectFields ();
464 AddVariableToRecordType (const char *name,
465 const ClangASTType &var_type,
466 lldb::AccessType access);
468 clang::CXXMethodDecl *
469 AddMethodToCXXRecordType (const char *name,
470 const ClangASTType &method_type,
471 lldb::AccessType access,
480 clang::CXXBaseSpecifier *
481 CreateBaseClassSpecifier (lldb::AccessType access,
486 DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes,
487 unsigned num_base_classes);
490 SetBaseClassesForClassType (clang::CXXBaseSpecifier const * const *base_classes,
491 unsigned num_base_classes);
495 SetObjCSuperClass (const ClangASTType &superclass_clang_type);
498 AddObjCClassProperty (const char *property_name,
499 const ClangASTType &property_clang_type,
500 clang::ObjCIvarDecl *ivar_decl,
501 const char *property_setter_name,
502 const char *property_getter_name,
503 uint32_t property_attributes,
504 ClangASTMetadata *metadata);
506 clang::ObjCMethodDecl *
507 AddMethodToObjCObjectType (const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]")
508 const ClangASTType &method_clang_type,
509 lldb::AccessType access,
513 GetDeclContextForType () const;
517 SetDefaultAccessForRecordFields (int default_accessibility,
518 int *assigned_accessibilities,
519 size_t num_assigned_accessibilities);
522 SetHasExternalStorage (bool has_extern);
525 //------------------------------------------------------------------
527 //------------------------------------------------------------------
530 SetTagTypeKind (int kind) const;
532 //------------------------------------------------------------------
534 //------------------------------------------------------------------
536 StartTagDeclarationDefinition ();
539 CompleteTagDeclarationDefinition ();
541 //----------------------------------------------------------------------
542 // Modifying Enumeration types
543 //----------------------------------------------------------------------
545 AddEnumerationValueToEnumerationType (const ClangASTType &enumerator_qual_type,
546 const Declaration &decl,
549 uint32_t enum_value_bit_size);
554 GetEnumerationIntegerType () const;
557 //------------------------------------------------------------------
558 // Pointers & References
559 //------------------------------------------------------------------
561 // Call this function using the class type when you want to make a
562 // member pointer type to pointee_type.
564 CreateMemberPointerType (const ClangASTType &pointee_type) const;
567 // Converts "s" to a floating point value and place resulting floating
568 // point bytes in the "dst" buffer.
570 ConvertStringToFloatValue (const char *s,
572 size_t dst_size) const;
573 //----------------------------------------------------------------------
575 //----------------------------------------------------------------------
577 DumpValue (ExecutionContext *exe_ctx,
580 const DataExtractor &data,
581 lldb::offset_t data_offset,
582 size_t data_byte_size,
583 uint32_t bitfield_bit_size,
584 uint32_t bitfield_bit_offset,
591 DumpTypeValue (Stream *s,
593 const DataExtractor &data,
594 lldb::offset_t data_offset,
595 size_t data_byte_size,
596 uint32_t bitfield_bit_size,
597 uint32_t bitfield_bit_offset,
598 ExecutionContextScope *exe_scope);
601 DumpSummary (ExecutionContext *exe_ctx,
603 const DataExtractor &data,
604 lldb::offset_t data_offset,
605 size_t data_byte_size);
608 DumpTypeDescription () const; // Dump to stdout
611 DumpTypeDescription (Stream *s) const;
614 GetValueAsScalar (const DataExtractor &data,
615 lldb::offset_t data_offset,
616 size_t data_byte_size,
617 Scalar &value) const;
620 SetValueFromScalar (const Scalar &value,
624 ReadFromMemory (ExecutionContext *exe_ctx,
626 AddressType address_type,
627 DataExtractor &data);
630 WriteToMemory (ExecutionContext *exe_ctx,
632 AddressType address_type,
633 StreamString &new_value);
637 GetAsRecordDecl () const;
639 clang::CXXRecordDecl *
640 GetAsCXXRecordDecl () const;
642 clang::ObjCInterfaceDecl *
643 GetAsObjCInterfaceDecl () const;
656 return clang::QualType::getFromOpaquePtr(m_type);
657 return clang::QualType();
660 GetCanonicalQualType () const
663 return clang::QualType::getFromOpaquePtr(m_type).getCanonicalType();
664 return clang::QualType();
668 lldb::clang_type_t m_type;
669 clang::ASTContext *m_ast;
673 bool operator == (const ClangASTType &lhs, const ClangASTType &rhs);
674 bool operator != (const ClangASTType &lhs, const ClangASTType &rhs);
677 } // namespace lldb_private
679 #endif // #ifndef liblldb_ClangASTType_h_