ClangASTContext.h revision fafffe000eb4a3902ecefc82446d11e6838167c6
1//===-- ClangASTContext.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_ClangASTContext_h_ 11#define liblldb_ClangASTContext_h_ 12 13// C Includes 14// C++ Includes 15#include <string> 16#include <vector> 17#include <memory> 18#include <stdint.h> 19 20// Other libraries and framework includes 21#include "llvm/ADT/OwningPtr.h" 22#include "llvm/ADT/SmallVector.h" 23#include "clang/AST/TemplateBase.h" 24 25 26// Project includes 27#include "lldb/lldb-enumerations.h" 28#include "lldb/Core/ClangForward.h" 29#include "lldb/Symbol/ClangASTType.h" 30 31namespace lldb_private { 32 33class Declaration; 34 35class ClangASTContext 36{ 37public: 38 enum { 39 eTypeHasChildren = (1u << 0), 40 eTypeHasValue = (1u << 1), 41 eTypeIsArray = (1u << 2), 42 eTypeIsBlock = (1u << 3), 43 eTypeIsBuiltIn = (1u << 4), 44 eTypeIsClass = (1u << 5), 45 eTypeIsCPlusPlus = (1u << 6), 46 eTypeIsEnumeration = (1u << 7), 47 eTypeIsFuncPrototype = (1u << 8), 48 eTypeIsMember = (1u << 9), 49 eTypeIsObjC = (1u << 10), 50 eTypeIsPointer = (1u << 11), 51 eTypeIsReference = (1u << 12), 52 eTypeIsStructUnion = (1u << 13), 53 eTypeIsTemplate = (1u << 14), 54 eTypeIsTypedef = (1u << 15), 55 eTypeIsVector = (1u << 16), 56 eTypeIsScalar = (1u << 17) 57 }; 58 59 typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *); 60 typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, clang::ObjCInterfaceDecl *); 61 62 //------------------------------------------------------------------ 63 // Constructors and Destructors 64 //------------------------------------------------------------------ 65 ClangASTContext (const char *triple = NULL); 66 67 ~ClangASTContext(); 68 69 clang::ASTContext * 70 getASTContext(); 71 72 clang::Builtin::Context * 73 getBuiltinContext(); 74 75 clang::IdentifierTable * 76 getIdentifierTable(); 77 78 clang::LangOptions * 79 getLanguageOptions(); 80 81 clang::SelectorTable * 82 getSelectorTable(); 83 84 clang::FileManager * 85 getFileManager(); 86 87 clang::SourceManager * 88 getSourceManager(); 89 90 clang::DiagnosticsEngine * 91 getDiagnosticsEngine(); 92 93 clang::DiagnosticConsumer * 94 getDiagnosticConsumer(); 95 96 clang::TargetOptions * 97 getTargetOptions(); 98 99 clang::TargetInfo * 100 getTargetInfo(); 101 102 void 103 Clear(); 104 105 const char * 106 GetTargetTriple (); 107 108 void 109 SetTargetTriple (const char *target_triple); 110 111 void 112 SetArchitecture (const ArchSpec &arch); 113 114 bool 115 HasExternalSource (); 116 117 void 118 SetExternalSource (llvm::OwningPtr<clang::ExternalASTSource> &ast_source_ap); 119 120 void 121 RemoveExternalSource (); 122 123 bool 124 GetCompleteType (lldb::clang_type_t clang_type); 125 126 static bool 127 GetCompleteType (clang::ASTContext *ast, 128 lldb::clang_type_t clang_type); 129 130 bool 131 IsCompleteType (lldb::clang_type_t clang_type); 132 133 static bool 134 IsCompleteType (clang::ASTContext *ast, 135 lldb::clang_type_t clang_type); 136 137 bool 138 GetCompleteDecl (clang::Decl *decl) 139 { 140 return ClangASTContext::GetCompleteDecl(getASTContext(), decl); 141 } 142 143 static bool 144 GetCompleteDecl (clang::ASTContext *ast, 145 clang::Decl *decl); 146 147 void SetMetadata (uintptr_t object, 148 uint64_t metadata) 149 { 150 SetMetadata(getASTContext(), object, metadata); 151 } 152 153 static void 154 SetMetadata (clang::ASTContext *ast, 155 uintptr_t object, 156 uint64_t metadata); 157 158 uint64_t GetMetadata (uintptr_t object) 159 { 160 return GetMetadata(getASTContext(), object); 161 } 162 163 static uint64_t 164 GetMetadata (clang::ASTContext *ast, 165 uintptr_t object); 166 167 //------------------------------------------------------------------ 168 // Basic Types 169 //------------------------------------------------------------------ 170 171 lldb::clang_type_t 172 GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding, 173 uint32_t bit_size); 174 175 static lldb::clang_type_t 176 GetBuiltinTypeForEncodingAndBitSize (clang::ASTContext *ast, 177 lldb::Encoding encoding, 178 uint32_t bit_size); 179 180 lldb::clang_type_t 181 GetBuiltinTypeForDWARFEncodingAndBitSize ( 182 const char *type_name, 183 uint32_t dw_ate, 184 uint32_t bit_size); 185 186 static lldb::clang_type_t 187 GetBuiltInType_void(clang::ASTContext *ast); 188 189 lldb::clang_type_t 190 GetBuiltInType_void() 191 { 192 return GetBuiltInType_void(getASTContext()); 193 } 194 195 lldb::clang_type_t 196 GetBuiltInType_bool(); 197 198 lldb::clang_type_t 199 GetBuiltInType_objc_id(); 200 201 lldb::clang_type_t 202 GetBuiltInType_objc_Class(); 203 204 static lldb::clang_type_t 205 GetUnknownAnyType(clang::ASTContext *ast); 206 207 lldb::clang_type_t 208 GetUnknownAnyType() 209 { 210 return ClangASTContext::GetUnknownAnyType(getASTContext()); 211 } 212 213 lldb::clang_type_t 214 GetBuiltInType_objc_selector(); 215 216 lldb::clang_type_t 217 GetCStringType(bool is_const); 218 219 lldb::clang_type_t 220 GetVoidType(); 221 222 lldb::clang_type_t 223 GetVoidType(clang::ASTContext *ast); 224 225 lldb::clang_type_t 226 GetVoidPtrType(bool is_const); 227 228 static lldb::clang_type_t 229 GetVoidPtrType(clang::ASTContext *ast, bool is_const); 230 231 static clang::DeclContext * 232 GetTranslationUnitDecl (clang::ASTContext *ast); 233 234 clang::DeclContext * 235 GetTranslationUnitDecl () 236 { 237 return GetTranslationUnitDecl (getASTContext()); 238 } 239 240 static lldb::clang_type_t 241 CopyType(clang::ASTContext *dest_context, 242 clang::ASTContext *source_context, 243 lldb::clang_type_t clang_type); 244 245 static clang::Decl * 246 CopyDecl (clang::ASTContext *dest_context, 247 clang::ASTContext *source_context, 248 clang::Decl *source_decl); 249 250 static bool 251 AreTypesSame(clang::ASTContext *ast, 252 lldb::clang_type_t type1, 253 lldb::clang_type_t type2, 254 bool ignore_qualifiers = false); 255 256 bool 257 AreTypesSame(lldb::clang_type_t type1, 258 lldb::clang_type_t type2, 259 bool ignore_qualifiers = false) 260 { 261 return ClangASTContext::AreTypesSame(getASTContext(), type1, type2, ignore_qualifiers); 262 } 263 264 265 lldb::clang_type_t 266 GetTypeForDecl (clang::TagDecl *decl); 267 268 lldb::clang_type_t 269 GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl); 270 271 //------------------------------------------------------------------ 272 // CVR modifiers 273 //------------------------------------------------------------------ 274 275 static lldb::clang_type_t 276 AddConstModifier (lldb::clang_type_t clang_type); 277 278 static lldb::clang_type_t 279 AddRestrictModifier (lldb::clang_type_t clang_type); 280 281 static lldb::clang_type_t 282 AddVolatileModifier (lldb::clang_type_t clang_type); 283 284 //------------------------------------------------------------------ 285 // Structure, Unions, Classes 286 //------------------------------------------------------------------ 287 288 lldb::clang_type_t 289 CreateRecordType (clang::DeclContext *decl_ctx, 290 lldb::AccessType access_type, 291 const char *name, 292 int kind, 293 lldb::LanguageType language, 294 clang::CXXRecordDecl **decl = NULL); 295 296 static clang::FieldDecl * 297 AddFieldToRecordType (clang::ASTContext *ast, 298 lldb::clang_type_t record_qual_type, 299 const char *name, 300 lldb::clang_type_t field_type, 301 lldb::AccessType access, 302 uint32_t bitfield_bit_size); 303 304 clang::FieldDecl * 305 AddFieldToRecordType (lldb::clang_type_t record_qual_type, 306 const char *name, 307 lldb::clang_type_t field_type, 308 lldb::AccessType access, 309 uint32_t bitfield_bit_size) 310 { 311 return ClangASTContext::AddFieldToRecordType (getASTContext(), 312 record_qual_type, 313 name, 314 field_type, 315 access, 316 bitfield_bit_size); 317 } 318 319 static void 320 BuildIndirectFields (clang::ASTContext *ast, 321 lldb::clang_type_t record_qual_type); 322 323 void 324 BuildIndirectFields (lldb::clang_type_t record_qual_type) 325 { 326 ClangASTContext::BuildIndirectFields(getASTContext(), 327 record_qual_type); 328 } 329 330 static clang::CXXMethodDecl * 331 AddMethodToCXXRecordType (clang::ASTContext *ast, 332 lldb::clang_type_t record_opaque_type, 333 const char *name, 334 lldb::clang_type_t method_type, 335 lldb::AccessType access, 336 bool is_virtual, 337 bool is_static, 338 bool is_inline, 339 bool is_explicit, 340 bool is_attr_used, 341 bool is_artificial); 342 343 clang::CXXMethodDecl * 344 AddMethodToCXXRecordType (lldb::clang_type_t record_opaque_type, 345 const char *name, 346 lldb::clang_type_t method_type, 347 lldb::AccessType access, 348 bool is_virtual, 349 bool is_static, 350 bool is_inline, 351 bool is_explicit, 352 bool is_attr_used, 353 bool is_artificial) 354 355 { 356 return ClangASTContext::AddMethodToCXXRecordType (getASTContext(), 357 record_opaque_type, 358 name, 359 method_type, 360 access, 361 is_virtual, 362 is_static, 363 is_inline, 364 is_explicit, 365 is_attr_used, 366 is_artificial); 367 } 368 369 class TemplateParameterInfos 370 { 371 public: 372 bool 373 IsValid() const 374 { 375 if (args.empty()) 376 return false; 377 return args.size() == names.size(); 378 } 379 380 size_t 381 GetSize () const 382 { 383 if (IsValid()) 384 return args.size(); 385 return 0; 386 } 387 388 llvm::SmallVector<const char *, 8> names; 389 llvm::SmallVector<clang::TemplateArgument, 8> args; 390 }; 391 392 clang::FunctionTemplateDecl * 393 CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx, 394 clang::FunctionDecl *func_decl, 395 const char *name, 396 const TemplateParameterInfos &infos); 397 398 void 399 CreateFunctionTemplateSpecializationInfo (clang::FunctionDecl *func_decl, 400 clang::FunctionTemplateDecl *Template, 401 const TemplateParameterInfos &infos); 402 403 clang::ClassTemplateDecl * 404 CreateClassTemplateDecl (clang::DeclContext *decl_ctx, 405 lldb::AccessType access_type, 406 const char *class_name, 407 int kind, 408 const TemplateParameterInfos &infos); 409 410 clang::ClassTemplateSpecializationDecl * 411 CreateClassTemplateSpecializationDecl (clang::DeclContext *decl_ctx, 412 clang::ClassTemplateDecl *class_template_decl, 413 int kind, 414 const TemplateParameterInfos &infos); 415 416 lldb::clang_type_t 417 CreateClassTemplateSpecializationType (clang::ClassTemplateSpecializationDecl *class_template_specialization_decl); 418 419 static clang::DeclContext * 420 GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl); 421 422 static clang::DeclContext * 423 GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl); 424 425 426 static bool 427 CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, 428 uint32_t num_params); 429 430 bool 431 FieldIsBitfield (clang::FieldDecl* field, 432 uint32_t& bitfield_bit_size); 433 434 static bool 435 FieldIsBitfield (clang::ASTContext *ast, 436 clang::FieldDecl* field, 437 uint32_t& bitfield_bit_size); 438 439 static bool 440 RecordHasFields (const clang::RecordDecl *record_decl); 441 442 void 443 SetDefaultAccessForRecordFields (lldb::clang_type_t clang_type, 444 int default_accessibility, 445 int *assigned_accessibilities, 446 size_t num_assigned_accessibilities); 447 448 lldb::clang_type_t 449 CreateObjCClass (const char *name, 450 clang::DeclContext *decl_ctx, 451 bool isForwardDecl, 452 bool isInternal); 453 454 static clang::FieldDecl * 455 AddObjCClassIVar (clang::ASTContext *ast, 456 lldb::clang_type_t class_opaque_type, 457 const char *name, 458 lldb::clang_type_t ivar_opaque_type, 459 lldb::AccessType access, 460 uint32_t bitfield_bit_size, 461 bool isSynthesized); 462 463 clang::FieldDecl * 464 AddObjCClassIVar (lldb::clang_type_t class_opaque_type, 465 const char *name, 466 lldb::clang_type_t ivar_opaque_type, 467 lldb::AccessType access, 468 uint32_t bitfield_bit_size, 469 bool isSynthesized) 470 { 471 return ClangASTContext::AddObjCClassIVar (getASTContext(), 472 class_opaque_type, 473 name, 474 ivar_opaque_type, 475 access, 476 bitfield_bit_size, 477 isSynthesized); 478 } 479 480 static bool 481 AddObjCClassProperty 482 ( 483 clang::ASTContext *ast, 484 lldb::clang_type_t class_opaque_type, 485 const char *property_name, 486 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl 487 clang::ObjCIvarDecl *ivar_decl, 488 const char *property_setter_name, 489 const char *property_getter_name, 490 uint32_t property_attributes 491 ); 492 493 bool 494 AddObjCClassProperty 495 ( 496 lldb::clang_type_t class_opaque_type, 497 const char *property_name, 498 lldb::clang_type_t property_opaque_type, 499 clang::ObjCIvarDecl *ivar_decl, 500 const char *property_setter_name, 501 const char *property_getter_name, 502 uint32_t property_attributes 503 ) 504 { 505 return ClangASTContext::AddObjCClassProperty (getASTContext(), 506 class_opaque_type, 507 property_name, 508 property_opaque_type, 509 ivar_decl, 510 property_setter_name, 511 property_getter_name, 512 property_attributes); 513 } 514 515 bool 516 SetObjCSuperClass (lldb::clang_type_t class_clang_type, 517 lldb::clang_type_t superclass_clang_type); 518 519 static bool 520 ObjCTypeHasIVars (lldb::clang_type_t class_clang_type, bool check_superclass); 521 522 static bool 523 ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, 524 bool check_superclass); 525 526 527 static clang::ObjCMethodDecl * 528 AddMethodToObjCObjectType (clang::ASTContext *ast, 529 lldb::clang_type_t class_opaque_type, 530 const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]") 531 lldb::clang_type_t method_opaque_type, 532 lldb::AccessType access); 533 534 clang::ObjCMethodDecl * 535 AddMethodToObjCObjectType (lldb::clang_type_t class_opaque_type, 536 const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]") 537 lldb::clang_type_t method_opaque_type, 538 lldb::AccessType access) 539 { 540 return AddMethodToObjCObjectType (getASTContext(), 541 class_opaque_type, 542 name, 543 method_opaque_type, 544 access); 545 } 546 547 static bool 548 SetHasExternalStorage (lldb::clang_type_t clang_type, bool has_extern); 549 550 //------------------------------------------------------------------ 551 // Aggregate Types 552 //------------------------------------------------------------------ 553 static bool 554 IsAggregateType (lldb::clang_type_t clang_type); 555 556 // Returns a mask containing bits from the ClangASTContext::eTypeXXX enumerations 557 static uint32_t 558 GetTypeInfo (lldb::clang_type_t clang_type, 559 clang::ASTContext *ast, // The AST for clang_type (can be NULL) 560 lldb::clang_type_t *pointee_or_element_type); // (can be NULL) 561 562 static uint32_t 563 GetNumChildren (clang::ASTContext *ast, 564 lldb::clang_type_t clang_type, 565 bool omit_empty_base_classes); 566 567 static uint32_t 568 GetNumDirectBaseClasses (clang::ASTContext *ast, 569 lldb::clang_type_t clang_type); 570 571 static uint32_t 572 GetNumVirtualBaseClasses (clang::ASTContext *ast, 573 lldb::clang_type_t clang_type); 574 575 static uint32_t 576 GetNumFields (clang::ASTContext *ast, 577 lldb::clang_type_t clang_type); 578 579 static lldb::clang_type_t 580 GetDirectBaseClassAtIndex (clang::ASTContext *ast, 581 lldb::clang_type_t clang_type, 582 uint32_t idx, 583 uint32_t *bit_offset_ptr); 584 585 static lldb::clang_type_t 586 GetVirtualBaseClassAtIndex (clang::ASTContext *ast, 587 lldb::clang_type_t clang_type, 588 uint32_t idx, 589 uint32_t *bit_offset_ptr); 590 591 static lldb::clang_type_t 592 GetFieldAtIndex (clang::ASTContext *ast, 593 lldb::clang_type_t clang_type, 594 uint32_t idx, 595 std::string& name, 596 uint32_t *bit_offset_ptr); 597 598 static uint32_t 599 GetNumPointeeChildren (lldb::clang_type_t clang_type); 600 601 lldb::clang_type_t 602 GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, 603 const char *parent_name, 604 lldb::clang_type_t parent_clang_type, 605 uint32_t idx, 606 bool transparent_pointers, 607 bool omit_empty_base_classes, 608 bool ignore_array_bounds, 609 std::string& child_name, 610 uint32_t &child_byte_size, 611 int32_t &child_byte_offset, 612 uint32_t &child_bitfield_bit_size, 613 uint32_t &child_bitfield_bit_offset, 614 bool &child_is_base_class, 615 bool &child_is_deref_of_parent); 616 617 static lldb::clang_type_t 618 GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, 619 clang::ASTContext *ast, 620 const char *parent_name, 621 lldb::clang_type_t parent_clang_type, 622 uint32_t idx, 623 bool transparent_pointers, 624 bool omit_empty_base_classes, 625 bool ignore_array_bounds, 626 std::string& child_name, 627 uint32_t &child_byte_size, 628 int32_t &child_byte_offset, 629 uint32_t &child_bitfield_bit_size, 630 uint32_t &child_bitfield_bit_offset, 631 bool &child_is_base_class, 632 bool &child_is_deref_of_parent); 633 634 // Lookup a child given a name. This function will match base class names 635 // and member member names in "clang_type" only, not descendants. 636 static uint32_t 637 GetIndexOfChildWithName (clang::ASTContext *ast, 638 lldb::clang_type_t clang_type, 639 const char *name, 640 bool omit_empty_base_classes); 641 642 // Lookup a child member given a name. This function will match member names 643 // only and will descend into "clang_type" children in search for the first 644 // member in this class, or any base class that matches "name". 645 // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>> 646 // so we catch all names that match a given child name, not just the first. 647 static size_t 648 GetIndexOfChildMemberWithName (clang::ASTContext *ast, 649 lldb::clang_type_t clang_type, 650 const char *name, 651 bool omit_empty_base_classes, 652 std::vector<uint32_t>& child_indexes); 653 654 size_t 655 GetNumTemplateArguments (lldb::clang_type_t clang_type) 656 { 657 return GetNumTemplateArguments(getASTContext(), clang_type); 658 } 659 660 lldb::clang_type_t 661 GetTemplateArgument (lldb::clang_type_t clang_type, 662 size_t idx, 663 lldb::TemplateArgumentKind &kind) 664 { 665 return GetTemplateArgument(getASTContext(), clang_type, idx, kind); 666 } 667 668 static size_t 669 GetNumTemplateArguments (clang::ASTContext *ast, 670 lldb::clang_type_t clang_type); 671 672 static lldb::clang_type_t 673 GetTemplateArgument (clang::ASTContext *ast, 674 lldb::clang_type_t clang_type, 675 size_t idx, 676 lldb::TemplateArgumentKind &kind); 677 678 //------------------------------------------------------------------ 679 // clang::TagType 680 //------------------------------------------------------------------ 681 682 bool 683 SetTagTypeKind (lldb::clang_type_t tag_qual_type, 684 int kind); 685 686 //------------------------------------------------------------------ 687 // C++ Base Classes 688 //------------------------------------------------------------------ 689 690 clang::CXXBaseSpecifier * 691 CreateBaseClassSpecifier (lldb::clang_type_t base_class_type, 692 lldb::AccessType access, 693 bool is_virtual, 694 bool base_of_class); 695 696 static void 697 DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, 698 unsigned num_base_classes); 699 700 bool 701 SetBaseClassesForClassType (lldb::clang_type_t class_clang_type, 702 clang::CXXBaseSpecifier const * const *base_classes, 703 unsigned num_base_classes); 704 705 //------------------------------------------------------------------ 706 // DeclContext Functions 707 //------------------------------------------------------------------ 708 709 static clang::DeclContext * 710 GetDeclContextForType (lldb::clang_type_t qual_type); 711 712 //------------------------------------------------------------------ 713 // Namespace Declarations 714 //------------------------------------------------------------------ 715 716 clang::NamespaceDecl * 717 GetUniqueNamespaceDeclaration (const char *name, 718 clang::DeclContext *decl_ctx); 719 720 //------------------------------------------------------------------ 721 // Function Types 722 //------------------------------------------------------------------ 723 724 clang::FunctionDecl * 725 CreateFunctionDeclaration (clang::DeclContext *decl_ctx, 726 const char *name, 727 lldb::clang_type_t function_Type, 728 int storage, 729 bool is_inline); 730 731 static lldb::clang_type_t 732 CreateFunctionType (clang::ASTContext *ast, 733 lldb::clang_type_t result_type, 734 lldb::clang_type_t *args, 735 unsigned num_args, 736 bool is_variadic, 737 unsigned type_quals); 738 739 lldb::clang_type_t 740 CreateFunctionType (lldb::clang_type_t result_type, 741 lldb::clang_type_t *args, 742 unsigned num_args, 743 bool is_variadic, 744 unsigned type_quals) 745 { 746 return ClangASTContext::CreateFunctionType(getASTContext(), 747 result_type, 748 args, 749 num_args, 750 is_variadic, 751 type_quals); 752 } 753 754 clang::ParmVarDecl * 755 CreateParameterDeclaration (const char *name, 756 lldb::clang_type_t param_type, 757 int storage); 758 759 void 760 SetFunctionParameters (clang::FunctionDecl *function_decl, 761 clang::ParmVarDecl **params, 762 unsigned num_params); 763 764 //------------------------------------------------------------------ 765 // Array Types 766 //------------------------------------------------------------------ 767 768 lldb::clang_type_t 769 CreateArrayType (lldb::clang_type_t element_type, 770 size_t element_count, 771 uint32_t bit_stride); 772 773 //------------------------------------------------------------------ 774 // Tag Declarations 775 //------------------------------------------------------------------ 776 bool 777 StartTagDeclarationDefinition (lldb::clang_type_t qual_type); 778 779 bool 780 CompleteTagDeclarationDefinition (lldb::clang_type_t qual_type); 781 782 //------------------------------------------------------------------ 783 // Enumeration Types 784 //------------------------------------------------------------------ 785 lldb::clang_type_t 786 CreateEnumerationType (const char *name, 787 clang::DeclContext *decl_ctx, 788 const Declaration &decl, 789 lldb::clang_type_t integer_qual_type); 790 791 static lldb::clang_type_t 792 GetEnumerationIntegerType (lldb::clang_type_t enum_clang_type); 793 794 bool 795 AddEnumerationValueToEnumerationType (lldb::clang_type_t enum_qual_type, 796 lldb::clang_type_t enumerator_qual_type, 797 const Declaration &decl, 798 const char *name, 799 int64_t enum_value, 800 uint32_t enum_value_bit_size); 801 802 //------------------------------------------------------------------ 803 // Pointers & References 804 //------------------------------------------------------------------ 805 lldb::clang_type_t 806 CreatePointerType (lldb::clang_type_t clang_type); 807 808 static lldb::clang_type_t 809 CreatePointerType (clang::ASTContext *ast, 810 lldb::clang_type_t clang_type); 811 812 static lldb::clang_type_t 813 CreateLValueReferenceType (clang::ASTContext *ast_context, 814 lldb::clang_type_t clang_type); 815 816 static lldb::clang_type_t 817 CreateRValueReferenceType (clang::ASTContext *ast_context, 818 lldb::clang_type_t clang_type); 819 820 lldb::clang_type_t 821 CreateLValueReferenceType (lldb::clang_type_t clang_type) 822 { 823 return ClangASTContext::CreateLValueReferenceType(getASTContext(), clang_type); 824 } 825 826 lldb::clang_type_t 827 CreateRValueReferenceType (lldb::clang_type_t clang_type) 828 { 829 return ClangASTContext::CreateRValueReferenceType(getASTContext(), clang_type); 830 } 831 832 lldb::clang_type_t 833 CreateMemberPointerType (lldb::clang_type_t clang_pointee_type, 834 lldb::clang_type_t clang_class_type); 835 836 uint32_t 837 GetPointerBitSize (); 838 839 static bool 840 IsIntegerType (lldb::clang_type_t clang_type, bool &is_signed); 841 842 static bool 843 IsPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL); 844 845 static bool 846 IsReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL); 847 848 static bool 849 IsPointerOrReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL); 850 851 static bool 852 IsPossibleCPlusPlusDynamicType (clang::ASTContext *ast, 853 lldb::clang_type_t clang_type, 854 lldb::clang_type_t *target_type = NULL); 855 856 static bool 857 IsPossibleDynamicType (clang::ASTContext *ast, 858 lldb::clang_type_t clang_type, 859 lldb::clang_type_t *dynamic_pointee_type = NULL, 860 bool cplusplus = true, 861 bool objc = true); 862 863 static bool 864 IsCStringType (lldb::clang_type_t clang_type, uint32_t &length); 865 866 static bool 867 IsFunctionPointerType (lldb::clang_type_t clang_type); 868 869 static lldb::clang_type_t 870 GetAsArrayType (lldb::clang_type_t clang_type, 871 lldb::clang_type_t *member_type = NULL, 872 uint64_t *size = NULL); 873 874 static bool 875 IsArrayType (lldb::clang_type_t clang_type, 876 lldb::clang_type_t *member_type = NULL, 877 uint64_t *size = NULL) 878 { 879 return GetAsArrayType(clang_type, member_type, size) != 0; 880 } 881 882 //------------------------------------------------------------------ 883 // Typedefs 884 //------------------------------------------------------------------ 885 lldb::clang_type_t 886 CreateTypedefType (const char *name, 887 lldb::clang_type_t clang_type, 888 clang::DeclContext *decl_ctx); 889 890 //------------------------------------------------------------------ 891 // Type names 892 //------------------------------------------------------------------ 893 static bool 894 IsFloatingPointType (lldb::clang_type_t clang_type, uint32_t &count, bool &is_complex); 895 896 // true iff this is one of the types that can "fit" 897 // in a Scalar object 898 static bool 899 IsScalarType (lldb::clang_type_t clang_type); 900 901 static bool 902 IsPointerToScalarType (lldb::clang_type_t clang_type); 903 904 static bool 905 IsArrayOfScalarType (lldb::clang_type_t clang_type); 906 907 static bool 908 GetCXXClassName (lldb::clang_type_t clang_type, 909 std::string &class_name); 910 911 static bool 912 IsCXXClassType (lldb::clang_type_t clang_type); 913 914 static bool 915 IsBeingDefined (lldb::clang_type_t clang_type); 916 917 static bool 918 IsObjCClassType (lldb::clang_type_t clang_type); 919 920 static bool 921 IsObjCObjectPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type); 922 923 static bool 924 GetObjCClassName (lldb::clang_type_t clang_type, 925 std::string &class_name); 926 927 static bool 928 IsCharType (lldb::clang_type_t clang_type); 929 930 static size_t 931 GetArraySize (lldb::clang_type_t clang_type); 932 933 //static bool 934 //ConvertFloatValueToString (clang::ASTContext *ast, 935 // lldb::clang_type_t clang_type, 936 // const uint8_t* bytes, 937 // size_t byte_size, 938 // int apint_byte_order, 939 // std::string &float_str); 940 941 static size_t 942 ConvertStringToFloatValue (clang::ASTContext *ast, 943 lldb::clang_type_t clang_type, 944 const char *s, 945 uint8_t *dst, 946 size_t dst_size); 947 948 //------------------------------------------------------------------ 949 // Qualifiers 950 //------------------------------------------------------------------ 951 static unsigned 952 GetTypeQualifiers(lldb::clang_type_t clang_type); 953protected: 954 //------------------------------------------------------------------ 955 // Classes that inherit from ClangASTContext can see and modify these 956 //------------------------------------------------------------------ 957 std::string m_target_triple; 958 std::auto_ptr<clang::ASTContext> m_ast_ap; 959 std::auto_ptr<clang::LangOptions> m_language_options_ap; 960 std::auto_ptr<clang::FileManager> m_file_manager_ap; 961 std::auto_ptr<clang::FileSystemOptions> m_file_system_options_ap; 962 std::auto_ptr<clang::SourceManager> m_source_manager_ap; 963 std::auto_ptr<clang::DiagnosticsEngine> m_diagnostics_engine_ap; 964 std::auto_ptr<clang::DiagnosticConsumer> m_diagnostic_consumer_ap; 965 std::auto_ptr<clang::TargetOptions> m_target_options_ap; 966 std::auto_ptr<clang::TargetInfo> m_target_info_ap; 967 std::auto_ptr<clang::IdentifierTable> m_identifier_table_ap; 968 std::auto_ptr<clang::SelectorTable> m_selector_table_ap; 969 std::auto_ptr<clang::Builtin::Context> m_builtins_ap; 970 CompleteTagDeclCallback m_callback_tag_decl; 971 CompleteObjCInterfaceDeclCallback m_callback_objc_decl; 972 void * m_callback_baton; 973private: 974 //------------------------------------------------------------------ 975 // For ClangASTContext only 976 //------------------------------------------------------------------ 977 ClangASTContext(const ClangASTContext&); 978 const ClangASTContext& operator=(const ClangASTContext&); 979}; 980 981} // namespace lldb_private 982 983#endif // liblldb_ClangASTContext_h_ 984