ClangASTContext.h revision a4974db9b26cc4f33e16c990304b51f4a1d38611
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 uint64_t metadata = 0); 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 uint64_t metadata = 0); 454 455 static clang::FieldDecl * 456 AddObjCClassIVar (clang::ASTContext *ast, 457 lldb::clang_type_t class_opaque_type, 458 const char *name, 459 lldb::clang_type_t ivar_opaque_type, 460 lldb::AccessType access, 461 uint32_t bitfield_bit_size, 462 bool isSynthesized); 463 464 clang::FieldDecl * 465 AddObjCClassIVar (lldb::clang_type_t class_opaque_type, 466 const char *name, 467 lldb::clang_type_t ivar_opaque_type, 468 lldb::AccessType access, 469 uint32_t bitfield_bit_size, 470 bool isSynthesized) 471 { 472 return ClangASTContext::AddObjCClassIVar (getASTContext(), 473 class_opaque_type, 474 name, 475 ivar_opaque_type, 476 access, 477 bitfield_bit_size, 478 isSynthesized); 479 } 480 481 static bool 482 AddObjCClassProperty 483 ( 484 clang::ASTContext *ast, 485 lldb::clang_type_t class_opaque_type, 486 const char *property_name, 487 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl 488 clang::ObjCIvarDecl *ivar_decl, 489 const char *property_setter_name, 490 const char *property_getter_name, 491 uint32_t property_attributes, 492 uint64_t metadata = 0 493 ); 494 495 bool 496 AddObjCClassProperty 497 ( 498 lldb::clang_type_t class_opaque_type, 499 const char *property_name, 500 lldb::clang_type_t property_opaque_type, 501 clang::ObjCIvarDecl *ivar_decl, 502 const char *property_setter_name, 503 const char *property_getter_name, 504 uint32_t property_attributes, 505 uint64_t metadata = 0 506 ) 507 { 508 return ClangASTContext::AddObjCClassProperty (getASTContext(), 509 class_opaque_type, 510 property_name, 511 property_opaque_type, 512 ivar_decl, 513 property_setter_name, 514 property_getter_name, 515 property_attributes, 516 metadata); 517 } 518 519 bool 520 SetObjCSuperClass (lldb::clang_type_t class_clang_type, 521 lldb::clang_type_t superclass_clang_type); 522 523 static bool 524 ObjCTypeHasIVars (lldb::clang_type_t class_clang_type, bool check_superclass); 525 526 static bool 527 ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, 528 bool check_superclass); 529 530 531 static clang::ObjCMethodDecl * 532 AddMethodToObjCObjectType (clang::ASTContext *ast, 533 lldb::clang_type_t class_opaque_type, 534 const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]") 535 lldb::clang_type_t method_opaque_type, 536 lldb::AccessType access); 537 538 clang::ObjCMethodDecl * 539 AddMethodToObjCObjectType (lldb::clang_type_t class_opaque_type, 540 const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]") 541 lldb::clang_type_t method_opaque_type, 542 lldb::AccessType access) 543 { 544 return AddMethodToObjCObjectType (getASTContext(), 545 class_opaque_type, 546 name, 547 method_opaque_type, 548 access); 549 } 550 551 static bool 552 SetHasExternalStorage (lldb::clang_type_t clang_type, bool has_extern); 553 554 //------------------------------------------------------------------ 555 // Aggregate Types 556 //------------------------------------------------------------------ 557 static bool 558 IsAggregateType (lldb::clang_type_t clang_type); 559 560 // Returns a mask containing bits from the ClangASTContext::eTypeXXX enumerations 561 static uint32_t 562 GetTypeInfo (lldb::clang_type_t clang_type, 563 clang::ASTContext *ast, // The AST for clang_type (can be NULL) 564 lldb::clang_type_t *pointee_or_element_type); // (can be NULL) 565 566 static uint32_t 567 GetNumChildren (clang::ASTContext *ast, 568 lldb::clang_type_t clang_type, 569 bool omit_empty_base_classes); 570 571 static uint32_t 572 GetNumDirectBaseClasses (clang::ASTContext *ast, 573 lldb::clang_type_t clang_type); 574 575 static uint32_t 576 GetNumVirtualBaseClasses (clang::ASTContext *ast, 577 lldb::clang_type_t clang_type); 578 579 static uint32_t 580 GetNumFields (clang::ASTContext *ast, 581 lldb::clang_type_t clang_type); 582 583 static lldb::clang_type_t 584 GetDirectBaseClassAtIndex (clang::ASTContext *ast, 585 lldb::clang_type_t clang_type, 586 uint32_t idx, 587 uint32_t *bit_offset_ptr); 588 589 static lldb::clang_type_t 590 GetVirtualBaseClassAtIndex (clang::ASTContext *ast, 591 lldb::clang_type_t clang_type, 592 uint32_t idx, 593 uint32_t *bit_offset_ptr); 594 595 static lldb::clang_type_t 596 GetFieldAtIndex (clang::ASTContext *ast, 597 lldb::clang_type_t clang_type, 598 uint32_t idx, 599 std::string& name, 600 uint32_t *bit_offset_ptr); 601 602 static uint32_t 603 GetNumPointeeChildren (lldb::clang_type_t clang_type); 604 605 lldb::clang_type_t 606 GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, 607 const char *parent_name, 608 lldb::clang_type_t parent_clang_type, 609 uint32_t idx, 610 bool transparent_pointers, 611 bool omit_empty_base_classes, 612 bool ignore_array_bounds, 613 std::string& child_name, 614 uint32_t &child_byte_size, 615 int32_t &child_byte_offset, 616 uint32_t &child_bitfield_bit_size, 617 uint32_t &child_bitfield_bit_offset, 618 bool &child_is_base_class, 619 bool &child_is_deref_of_parent); 620 621 static lldb::clang_type_t 622 GetChildClangTypeAtIndex (ExecutionContext *exe_ctx, 623 clang::ASTContext *ast, 624 const char *parent_name, 625 lldb::clang_type_t parent_clang_type, 626 uint32_t idx, 627 bool transparent_pointers, 628 bool omit_empty_base_classes, 629 bool ignore_array_bounds, 630 std::string& child_name, 631 uint32_t &child_byte_size, 632 int32_t &child_byte_offset, 633 uint32_t &child_bitfield_bit_size, 634 uint32_t &child_bitfield_bit_offset, 635 bool &child_is_base_class, 636 bool &child_is_deref_of_parent); 637 638 // Lookup a child given a name. This function will match base class names 639 // and member member names in "clang_type" only, not descendants. 640 static uint32_t 641 GetIndexOfChildWithName (clang::ASTContext *ast, 642 lldb::clang_type_t clang_type, 643 const char *name, 644 bool omit_empty_base_classes); 645 646 // Lookup a child member given a name. This function will match member names 647 // only and will descend into "clang_type" children in search for the first 648 // member in this class, or any base class that matches "name". 649 // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>> 650 // so we catch all names that match a given child name, not just the first. 651 static size_t 652 GetIndexOfChildMemberWithName (clang::ASTContext *ast, 653 lldb::clang_type_t clang_type, 654 const char *name, 655 bool omit_empty_base_classes, 656 std::vector<uint32_t>& child_indexes); 657 658 size_t 659 GetNumTemplateArguments (lldb::clang_type_t clang_type) 660 { 661 return GetNumTemplateArguments(getASTContext(), clang_type); 662 } 663 664 lldb::clang_type_t 665 GetTemplateArgument (lldb::clang_type_t clang_type, 666 size_t idx, 667 lldb::TemplateArgumentKind &kind) 668 { 669 return GetTemplateArgument(getASTContext(), clang_type, idx, kind); 670 } 671 672 static size_t 673 GetNumTemplateArguments (clang::ASTContext *ast, 674 lldb::clang_type_t clang_type); 675 676 static lldb::clang_type_t 677 GetTemplateArgument (clang::ASTContext *ast, 678 lldb::clang_type_t clang_type, 679 size_t idx, 680 lldb::TemplateArgumentKind &kind); 681 682 //------------------------------------------------------------------ 683 // clang::TagType 684 //------------------------------------------------------------------ 685 686 bool 687 SetTagTypeKind (lldb::clang_type_t tag_qual_type, 688 int kind); 689 690 //------------------------------------------------------------------ 691 // C++ Base Classes 692 //------------------------------------------------------------------ 693 694 clang::CXXBaseSpecifier * 695 CreateBaseClassSpecifier (lldb::clang_type_t base_class_type, 696 lldb::AccessType access, 697 bool is_virtual, 698 bool base_of_class); 699 700 static void 701 DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, 702 unsigned num_base_classes); 703 704 bool 705 SetBaseClassesForClassType (lldb::clang_type_t class_clang_type, 706 clang::CXXBaseSpecifier const * const *base_classes, 707 unsigned num_base_classes); 708 709 //------------------------------------------------------------------ 710 // DeclContext Functions 711 //------------------------------------------------------------------ 712 713 static clang::DeclContext * 714 GetDeclContextForType (lldb::clang_type_t qual_type); 715 716 //------------------------------------------------------------------ 717 // Namespace Declarations 718 //------------------------------------------------------------------ 719 720 clang::NamespaceDecl * 721 GetUniqueNamespaceDeclaration (const char *name, 722 clang::DeclContext *decl_ctx); 723 724 //------------------------------------------------------------------ 725 // Function Types 726 //------------------------------------------------------------------ 727 728 clang::FunctionDecl * 729 CreateFunctionDeclaration (clang::DeclContext *decl_ctx, 730 const char *name, 731 lldb::clang_type_t function_Type, 732 int storage, 733 bool is_inline); 734 735 static lldb::clang_type_t 736 CreateFunctionType (clang::ASTContext *ast, 737 lldb::clang_type_t result_type, 738 lldb::clang_type_t *args, 739 unsigned num_args, 740 bool is_variadic, 741 unsigned type_quals); 742 743 lldb::clang_type_t 744 CreateFunctionType (lldb::clang_type_t result_type, 745 lldb::clang_type_t *args, 746 unsigned num_args, 747 bool is_variadic, 748 unsigned type_quals) 749 { 750 return ClangASTContext::CreateFunctionType(getASTContext(), 751 result_type, 752 args, 753 num_args, 754 is_variadic, 755 type_quals); 756 } 757 758 clang::ParmVarDecl * 759 CreateParameterDeclaration (const char *name, 760 lldb::clang_type_t param_type, 761 int storage); 762 763 void 764 SetFunctionParameters (clang::FunctionDecl *function_decl, 765 clang::ParmVarDecl **params, 766 unsigned num_params); 767 768 //------------------------------------------------------------------ 769 // Array Types 770 //------------------------------------------------------------------ 771 772 lldb::clang_type_t 773 CreateArrayType (lldb::clang_type_t element_type, 774 size_t element_count, 775 uint32_t bit_stride); 776 777 //------------------------------------------------------------------ 778 // Tag Declarations 779 //------------------------------------------------------------------ 780 bool 781 StartTagDeclarationDefinition (lldb::clang_type_t qual_type); 782 783 bool 784 CompleteTagDeclarationDefinition (lldb::clang_type_t qual_type); 785 786 //------------------------------------------------------------------ 787 // Enumeration Types 788 //------------------------------------------------------------------ 789 lldb::clang_type_t 790 CreateEnumerationType (const char *name, 791 clang::DeclContext *decl_ctx, 792 const Declaration &decl, 793 lldb::clang_type_t integer_qual_type); 794 795 static lldb::clang_type_t 796 GetEnumerationIntegerType (lldb::clang_type_t enum_clang_type); 797 798 bool 799 AddEnumerationValueToEnumerationType (lldb::clang_type_t enum_qual_type, 800 lldb::clang_type_t enumerator_qual_type, 801 const Declaration &decl, 802 const char *name, 803 int64_t enum_value, 804 uint32_t enum_value_bit_size); 805 806 //------------------------------------------------------------------ 807 // Pointers & References 808 //------------------------------------------------------------------ 809 lldb::clang_type_t 810 CreatePointerType (lldb::clang_type_t clang_type); 811 812 static lldb::clang_type_t 813 CreatePointerType (clang::ASTContext *ast, 814 lldb::clang_type_t clang_type); 815 816 static lldb::clang_type_t 817 CreateLValueReferenceType (clang::ASTContext *ast_context, 818 lldb::clang_type_t clang_type); 819 820 static lldb::clang_type_t 821 CreateRValueReferenceType (clang::ASTContext *ast_context, 822 lldb::clang_type_t clang_type); 823 824 lldb::clang_type_t 825 CreateLValueReferenceType (lldb::clang_type_t clang_type) 826 { 827 return ClangASTContext::CreateLValueReferenceType(getASTContext(), clang_type); 828 } 829 830 lldb::clang_type_t 831 CreateRValueReferenceType (lldb::clang_type_t clang_type) 832 { 833 return ClangASTContext::CreateRValueReferenceType(getASTContext(), clang_type); 834 } 835 836 lldb::clang_type_t 837 CreateMemberPointerType (lldb::clang_type_t clang_pointee_type, 838 lldb::clang_type_t clang_class_type); 839 840 uint32_t 841 GetPointerBitSize (); 842 843 static bool 844 IsIntegerType (lldb::clang_type_t clang_type, bool &is_signed); 845 846 static bool 847 IsPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL); 848 849 static bool 850 IsReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL); 851 852 static bool 853 IsPointerOrReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL); 854 855 static bool 856 IsPossibleCPlusPlusDynamicType (clang::ASTContext *ast, 857 lldb::clang_type_t clang_type, 858 lldb::clang_type_t *target_type = NULL); 859 860 static bool 861 IsPossibleDynamicType (clang::ASTContext *ast, 862 lldb::clang_type_t clang_type, 863 lldb::clang_type_t *dynamic_pointee_type = NULL, 864 bool cplusplus = true, 865 bool objc = true); 866 867 static bool 868 IsCStringType (lldb::clang_type_t clang_type, uint32_t &length); 869 870 static bool 871 IsFunctionPointerType (lldb::clang_type_t clang_type); 872 873 static lldb::clang_type_t 874 GetAsArrayType (lldb::clang_type_t clang_type, 875 lldb::clang_type_t *member_type = NULL, 876 uint64_t *size = NULL); 877 878 static bool 879 IsArrayType (lldb::clang_type_t clang_type, 880 lldb::clang_type_t *member_type = NULL, 881 uint64_t *size = NULL) 882 { 883 return GetAsArrayType(clang_type, member_type, size) != 0; 884 } 885 886 //------------------------------------------------------------------ 887 // Typedefs 888 //------------------------------------------------------------------ 889 lldb::clang_type_t 890 CreateTypedefType (const char *name, 891 lldb::clang_type_t clang_type, 892 clang::DeclContext *decl_ctx); 893 894 //------------------------------------------------------------------ 895 // Type names 896 //------------------------------------------------------------------ 897 static bool 898 IsFloatingPointType (lldb::clang_type_t clang_type, uint32_t &count, bool &is_complex); 899 900 // true iff this is one of the types that can "fit" 901 // in a Scalar object 902 static bool 903 IsScalarType (lldb::clang_type_t clang_type); 904 905 static bool 906 IsPointerToScalarType (lldb::clang_type_t clang_type); 907 908 static bool 909 IsArrayOfScalarType (lldb::clang_type_t clang_type); 910 911 static bool 912 GetCXXClassName (lldb::clang_type_t clang_type, 913 std::string &class_name); 914 915 static bool 916 IsCXXClassType (lldb::clang_type_t clang_type); 917 918 static bool 919 IsBeingDefined (lldb::clang_type_t clang_type); 920 921 static bool 922 IsObjCClassType (lldb::clang_type_t clang_type); 923 924 static bool 925 IsObjCObjectPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type); 926 927 static bool 928 GetObjCClassName (lldb::clang_type_t clang_type, 929 std::string &class_name); 930 931 static bool 932 IsCharType (lldb::clang_type_t clang_type); 933 934 static size_t 935 GetArraySize (lldb::clang_type_t clang_type); 936 937 //static bool 938 //ConvertFloatValueToString (clang::ASTContext *ast, 939 // lldb::clang_type_t clang_type, 940 // const uint8_t* bytes, 941 // size_t byte_size, 942 // int apint_byte_order, 943 // std::string &float_str); 944 945 static size_t 946 ConvertStringToFloatValue (clang::ASTContext *ast, 947 lldb::clang_type_t clang_type, 948 const char *s, 949 uint8_t *dst, 950 size_t dst_size); 951 952 //------------------------------------------------------------------ 953 // Qualifiers 954 //------------------------------------------------------------------ 955 static unsigned 956 GetTypeQualifiers(lldb::clang_type_t clang_type); 957protected: 958 //------------------------------------------------------------------ 959 // Classes that inherit from ClangASTContext can see and modify these 960 //------------------------------------------------------------------ 961 std::string m_target_triple; 962 std::auto_ptr<clang::ASTContext> m_ast_ap; 963 std::auto_ptr<clang::LangOptions> m_language_options_ap; 964 std::auto_ptr<clang::FileManager> m_file_manager_ap; 965 std::auto_ptr<clang::FileSystemOptions> m_file_system_options_ap; 966 std::auto_ptr<clang::SourceManager> m_source_manager_ap; 967 std::auto_ptr<clang::DiagnosticsEngine> m_diagnostics_engine_ap; 968 std::auto_ptr<clang::DiagnosticConsumer> m_diagnostic_consumer_ap; 969 std::auto_ptr<clang::TargetOptions> m_target_options_ap; 970 std::auto_ptr<clang::TargetInfo> m_target_info_ap; 971 std::auto_ptr<clang::IdentifierTable> m_identifier_table_ap; 972 std::auto_ptr<clang::SelectorTable> m_selector_table_ap; 973 std::auto_ptr<clang::Builtin::Context> m_builtins_ap; 974 CompleteTagDeclCallback m_callback_tag_decl; 975 CompleteObjCInterfaceDeclCallback m_callback_objc_decl; 976 void * m_callback_baton; 977private: 978 //------------------------------------------------------------------ 979 // For ClangASTContext only 980 //------------------------------------------------------------------ 981 ClangASTContext(const ClangASTContext&); 982 const ClangASTContext& operator=(const ClangASTContext&); 983}; 984 985} // namespace lldb_private 986 987#endif // liblldb_ClangASTContext_h_ 988