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