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