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