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