1 //===-- TypeSystem.h ------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_SYMBOL_TYPESYSTEM_H 10 #define LLDB_SYMBOL_TYPESYSTEM_H 11 12 #include <functional> 13 #include <mutex> 14 #include <optional> 15 #include <string> 16 17 #include "llvm/ADT/APFloat.h" 18 #include "llvm/ADT/APSInt.h" 19 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/SmallBitVector.h" 21 #include "llvm/Support/Casting.h" 22 #include "llvm/Support/Error.h" 23 #include "llvm/Support/JSON.h" 24 25 #include "lldb/Core/PluginInterface.h" 26 #include "lldb/Expression/Expression.h" 27 #include "lldb/Symbol/CompilerDecl.h" 28 #include "lldb/Symbol/CompilerDeclContext.h" 29 #include "lldb/Symbol/Type.h" 30 #include "lldb/Utility/Scalar.h" 31 #include "lldb/lldb-forward.h" 32 #include "lldb/lldb-private.h" 33 #include "lldb/lldb-types.h" 34 35 class PDBASTParser; 36 37 namespace lldb_private { 38 39 namespace plugin { 40 namespace dwarf { 41 class DWARFDIE; 42 class DWARFASTParser; 43 } // namespace dwarf 44 } // namespace plugin 45 46 namespace npdb { 47 class PdbAstBuilder; 48 } // namespace npdb 49 50 /// Interface for representing a type system. 51 /// 52 /// Implemented by language plugins to define the type system for a given 53 /// language. 54 /// 55 /// This interface extensively used opaque pointers to prevent that generic 56 /// LLDB code has dependencies on language plugins. The type and semantics of 57 /// these opaque pointers are defined by the TypeSystem implementation inside 58 /// the respective language plugin. Opaque pointers from one TypeSystem 59 /// instance should never be passed to a different TypeSystem instance (even 60 /// when the language plugin for both TypeSystem instances is the same). 61 /// 62 /// Most of the functions in this class should not be called directly but only 63 /// called by their respective counterparts in CompilerType, CompilerDecl and 64 /// CompilerDeclContext. 65 /// 66 /// \see lldb_private::CompilerType 67 /// \see lldb_private::CompilerDecl 68 /// \see lldb_private::CompilerDeclContext 69 class TypeSystem : public PluginInterface, 70 public std::enable_shared_from_this<TypeSystem> { 71 public: 72 // Constructors and Destructors 73 TypeSystem(); 74 ~TypeSystem() override; 75 76 // LLVM RTTI support 77 virtual bool isA(const void *ClassID) const = 0; 78 79 static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, 80 Module *module); 81 82 static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, 83 Target *target); 84 85 /// Free up any resources associated with this TypeSystem. Done before 86 /// removing all the TypeSystems from the TypeSystemMap. Finalize()87 virtual void Finalize() {} 88 GetDWARFParser()89 virtual plugin::dwarf::DWARFASTParser *GetDWARFParser() { return nullptr; } 90 GetPDBParser()91 virtual PDBASTParser *GetPDBParser() { return nullptr; } GetNativePDBParser()92 virtual npdb::PdbAstBuilder *GetNativePDBParser() { return nullptr; } 93 GetSymbolFile()94 virtual SymbolFile *GetSymbolFile() const { return m_sym_file; } 95 SetSymbolFile(SymbolFile * sym_file)96 virtual void SetSymbolFile(SymbolFile *sym_file) { m_sym_file = sym_file; } 97 98 // CompilerDecl functions 99 virtual ConstString DeclGetName(void *opaque_decl) = 0; 100 101 virtual ConstString DeclGetMangledName(void *opaque_decl); 102 103 virtual CompilerDeclContext DeclGetDeclContext(void *opaque_decl); 104 105 virtual CompilerType DeclGetFunctionReturnType(void *opaque_decl); 106 107 virtual size_t DeclGetFunctionNumArguments(void *opaque_decl); 108 109 virtual CompilerType DeclGetFunctionArgumentType(void *opaque_decl, 110 size_t arg_idx); 111 112 virtual std::vector<lldb_private::CompilerContext> 113 DeclGetCompilerContext(void *opaque_decl); 114 DeclGetConstantValue(void * opaque_decl)115 virtual Scalar DeclGetConstantValue(void *opaque_decl) { return Scalar(); } 116 117 virtual CompilerType GetTypeForDecl(void *opaque_decl) = 0; 118 119 // CompilerDeclContext functions 120 121 virtual std::vector<CompilerDecl> 122 DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name, 123 const bool ignore_imported_decls); 124 125 virtual ConstString DeclContextGetName(void *opaque_decl_ctx) = 0; 126 127 virtual ConstString 128 DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) = 0; 129 130 virtual bool DeclContextIsClassMethod(void *opaque_decl_ctx) = 0; 131 132 virtual bool DeclContextIsContainedInLookup(void *opaque_decl_ctx, 133 void *other_opaque_decl_ctx) = 0; 134 135 virtual lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) = 0; 136 137 /// Returns the direct parent context of specified type 138 virtual CompilerDeclContext 139 GetCompilerDeclContextForType(const CompilerType &type); 140 141 virtual std::vector<lldb_private::CompilerContext> 142 DeclContextGetCompilerContext(void *opaque_decl_ctx); 143 144 // Tests 145 #ifndef NDEBUG 146 /// Verify the integrity of the type to catch CompilerTypes that mix 147 /// and match invalid TypeSystem/Opaque type pairs. 148 virtual bool Verify(lldb::opaque_compiler_type_t type) = 0; 149 #endif 150 151 virtual bool IsArrayType(lldb::opaque_compiler_type_t type, 152 CompilerType *element_type, uint64_t *size, 153 bool *is_incomplete) = 0; 154 155 virtual bool IsAggregateType(lldb::opaque_compiler_type_t type) = 0; 156 157 virtual bool IsAnonymousType(lldb::opaque_compiler_type_t type); 158 159 virtual bool IsCharType(lldb::opaque_compiler_type_t type) = 0; 160 161 virtual bool IsCompleteType(lldb::opaque_compiler_type_t type) = 0; 162 163 virtual bool IsDefined(lldb::opaque_compiler_type_t type) = 0; 164 165 virtual bool IsFloatingPointType(lldb::opaque_compiler_type_t type, 166 uint32_t &count, bool &is_complex) = 0; 167 168 virtual bool IsFunctionType(lldb::opaque_compiler_type_t type) = 0; 169 170 virtual size_t 171 GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) = 0; 172 173 virtual CompilerType 174 GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, 175 const size_t index) = 0; 176 177 virtual bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) = 0; 178 179 virtual bool 180 IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) = 0; 181 182 virtual bool IsBlockPointerType(lldb::opaque_compiler_type_t type, 183 CompilerType *function_pointer_type_ptr) = 0; 184 185 virtual bool IsIntegerType(lldb::opaque_compiler_type_t type, 186 bool &is_signed) = 0; 187 IsEnumerationType(lldb::opaque_compiler_type_t type,bool & is_signed)188 virtual bool IsEnumerationType(lldb::opaque_compiler_type_t type, 189 bool &is_signed) { 190 is_signed = false; 191 return false; 192 } 193 194 virtual bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) = 0; 195 196 virtual bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type, 197 CompilerType *target_type, // Can pass NULL 198 bool check_cplusplus, bool check_objc) = 0; 199 200 virtual bool IsPointerType(lldb::opaque_compiler_type_t type, 201 CompilerType *pointee_type) = 0; 202 203 virtual bool IsScalarType(lldb::opaque_compiler_type_t type) = 0; 204 205 virtual bool IsVoidType(lldb::opaque_compiler_type_t type) = 0; 206 207 virtual bool CanPassInRegisters(const CompilerType &type) = 0; 208 209 // TypeSystems can support more than one language 210 virtual bool SupportsLanguage(lldb::LanguageType language) = 0; 211 212 static bool SupportsLanguageStatic(lldb::LanguageType language); 213 // Type Completion 214 215 virtual bool GetCompleteType(lldb::opaque_compiler_type_t type) = 0; 216 IsForcefullyCompleted(lldb::opaque_compiler_type_t type)217 virtual bool IsForcefullyCompleted(lldb::opaque_compiler_type_t type) { 218 return false; 219 } 220 221 // AST related queries 222 223 virtual uint32_t GetPointerByteSize() = 0; 224 225 virtual unsigned GetPtrAuthKey(lldb::opaque_compiler_type_t type) = 0; 226 227 virtual unsigned 228 GetPtrAuthDiscriminator(lldb::opaque_compiler_type_t type) = 0; 229 230 virtual bool 231 GetPtrAuthAddressDiversity(lldb::opaque_compiler_type_t type) = 0; 232 233 // Accessors 234 235 virtual ConstString GetTypeName(lldb::opaque_compiler_type_t type, 236 bool BaseOnly) = 0; 237 238 virtual ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) = 0; 239 240 /// Defaults to GetTypeName(type). Override if your language desires 241 /// specialized behavior. 242 virtual ConstString GetMangledTypeName(lldb::opaque_compiler_type_t type); 243 244 virtual uint32_t 245 GetTypeInfo(lldb::opaque_compiler_type_t type, 246 CompilerType *pointee_or_element_compiler_type) = 0; 247 248 virtual lldb::LanguageType 249 GetMinimumLanguage(lldb::opaque_compiler_type_t type) = 0; 250 251 virtual lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) = 0; 252 253 // Creating related types 254 255 virtual CompilerType 256 GetArrayElementType(lldb::opaque_compiler_type_t type, 257 ExecutionContextScope *exe_scope) = 0; 258 259 virtual CompilerType GetArrayType(lldb::opaque_compiler_type_t type, 260 uint64_t size); 261 262 virtual CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) = 0; 263 264 virtual CompilerType 265 GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) = 0; 266 267 // Returns -1 if this isn't a function of if the function doesn't have a 268 // prototype Returns a value >= 0 if there is a prototype. 269 virtual int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) = 0; 270 271 virtual CompilerType 272 GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type, 273 size_t idx) = 0; 274 275 virtual CompilerType 276 GetFunctionReturnType(lldb::opaque_compiler_type_t type) = 0; 277 278 virtual size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) = 0; 279 280 virtual TypeMemberFunctionImpl 281 GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, size_t idx) = 0; 282 283 virtual CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) = 0; 284 285 virtual CompilerType GetPointerType(lldb::opaque_compiler_type_t type) = 0; 286 287 virtual CompilerType 288 GetLValueReferenceType(lldb::opaque_compiler_type_t type); 289 290 virtual CompilerType 291 GetRValueReferenceType(lldb::opaque_compiler_type_t type); 292 293 virtual CompilerType GetAtomicType(lldb::opaque_compiler_type_t type); 294 295 virtual CompilerType AddConstModifier(lldb::opaque_compiler_type_t type); 296 297 virtual CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type); 298 299 virtual CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type); 300 301 virtual CompilerType AddPtrAuthModifier(lldb::opaque_compiler_type_t type, 302 uint32_t payload); 303 304 /// \param opaque_payload The m_payload field of Type, which may 305 /// carry TypeSystem-specific extra information. 306 virtual CompilerType CreateTypedef(lldb::opaque_compiler_type_t type, 307 const char *name, 308 const CompilerDeclContext &decl_ctx, 309 uint32_t opaque_payload); 310 311 // Exploring the type 312 313 virtual const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) = 0; 314 315 virtual llvm::Expected<uint64_t> 316 GetBitSize(lldb::opaque_compiler_type_t type, 317 ExecutionContextScope *exe_scope) = 0; 318 319 virtual lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type, 320 uint64_t &count) = 0; 321 322 virtual lldb::Format GetFormat(lldb::opaque_compiler_type_t type) = 0; 323 324 virtual llvm::Expected<uint32_t> 325 GetNumChildren(lldb::opaque_compiler_type_t type, 326 bool omit_empty_base_classes, 327 const ExecutionContext *exe_ctx) = 0; 328 329 virtual CompilerType GetBuiltinTypeByName(ConstString name); 330 331 virtual lldb::BasicType 332 GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) = 0; 333 ForEachEnumerator(lldb::opaque_compiler_type_t type,std::function<bool (const CompilerType & integer_type,ConstString name,const llvm::APSInt & value)> const & callback)334 virtual void ForEachEnumerator( 335 lldb::opaque_compiler_type_t type, 336 std::function<bool(const CompilerType &integer_type, 337 ConstString name, 338 const llvm::APSInt &value)> const &callback) {} 339 340 virtual uint32_t GetNumFields(lldb::opaque_compiler_type_t type) = 0; 341 342 virtual CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, 343 size_t idx, std::string &name, 344 uint64_t *bit_offset_ptr, 345 uint32_t *bitfield_bit_size_ptr, 346 bool *is_bitfield_ptr) = 0; 347 348 virtual uint32_t 349 GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) = 0; 350 351 virtual uint32_t 352 GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) = 0; 353 354 virtual CompilerType 355 GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, 356 uint32_t *bit_offset_ptr) = 0; 357 358 virtual CompilerType 359 GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx, 360 uint32_t *bit_offset_ptr) = 0; 361 GetStaticFieldWithName(lldb::opaque_compiler_type_t type,llvm::StringRef name)362 virtual CompilerDecl GetStaticFieldWithName(lldb::opaque_compiler_type_t type, 363 llvm::StringRef name) { 364 return CompilerDecl(); 365 } 366 367 virtual llvm::Expected<CompilerType> 368 GetDereferencedType(lldb::opaque_compiler_type_t type, 369 ExecutionContext *exe_ctx, std::string &deref_name, 370 uint32_t &deref_byte_size, int32_t &deref_byte_offset, 371 ValueObject *valobj, uint64_t &language_flags) = 0; 372 373 virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( 374 lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, 375 bool transparent_pointers, bool omit_empty_base_classes, 376 bool ignore_array_bounds, std::string &child_name, 377 uint32_t &child_byte_size, int32_t &child_byte_offset, 378 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, 379 bool &child_is_base_class, bool &child_is_deref_of_parent, 380 ValueObject *valobj, uint64_t &language_flags) = 0; 381 382 // Lookup a child given a name. This function will match base class names and 383 // member member names in "clang_type" only, not descendants. 384 virtual llvm::Expected<uint32_t> 385 GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, 386 llvm::StringRef name, 387 bool omit_empty_base_classes) = 0; 388 389 virtual size_t GetIndexOfChildMemberWithName( 390 lldb::opaque_compiler_type_t type, llvm::StringRef name, 391 bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) = 0; 392 393 virtual CompilerType GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type,llvm::StringRef name)394 GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type, 395 llvm::StringRef name) { 396 return CompilerType(); 397 } 398 399 virtual bool IsTemplateType(lldb::opaque_compiler_type_t type); 400 401 virtual size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type, 402 bool expand_pack); 403 404 virtual lldb::TemplateArgumentKind 405 GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, size_t idx, 406 bool expand_pack); 407 virtual CompilerType 408 GetTypeTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx, 409 bool expand_pack); 410 virtual std::optional<CompilerType::IntegralTemplateArgument> 411 GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx, 412 bool expand_pack); 413 414 // Dumping types 415 416 #ifndef NDEBUG 417 /// Convenience LLVM-style dump method for use in the debugger only. 418 LLVM_DUMP_METHOD virtual void 419 dump(lldb::opaque_compiler_type_t type) const = 0; 420 #endif 421 422 virtual bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s, 423 lldb::Format format, const DataExtractor &data, 424 lldb::offset_t data_offset, size_t data_byte_size, 425 uint32_t bitfield_bit_size, 426 uint32_t bitfield_bit_offset, 427 ExecutionContextScope *exe_scope) = 0; 428 429 /// Dump the type to stdout. 430 virtual void DumpTypeDescription( 431 lldb::opaque_compiler_type_t type, 432 lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0; 433 434 /// Print a description of the type to a stream. The exact implementation 435 /// varies, but the expectation is that eDescriptionLevelFull returns a 436 /// source-like representation of the type, whereas eDescriptionLevelVerbose 437 /// does a dump of the underlying AST if applicable. 438 virtual void DumpTypeDescription( 439 lldb::opaque_compiler_type_t type, Stream &s, 440 lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0; 441 442 /// Dump a textual representation of the internal TypeSystem state to the 443 /// given stream. 444 /// 445 /// This should not modify the state of the TypeSystem if possible. 446 /// 447 /// \param[out] output Stream to dup the AST into. 448 /// \param[in] filter If empty, dump whole AST. If non-empty, will only 449 /// dump decls whose names contain \c filter. 450 virtual void Dump(llvm::raw_ostream &output, llvm::StringRef filter) = 0; 451 452 /// This is used by swift. 453 virtual bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) = 0; 454 455 // TODO: Determine if these methods should move to TypeSystemClang. 456 457 virtual bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type, 458 CompilerType *pointee_type) = 0; 459 460 virtual unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) = 0; 461 462 virtual std::optional<size_t> 463 GetTypeBitAlign(lldb::opaque_compiler_type_t type, 464 ExecutionContextScope *exe_scope) = 0; 465 466 virtual CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) = 0; 467 CreateGenericFunctionPrototype()468 virtual CompilerType CreateGenericFunctionPrototype() { 469 return CompilerType(); 470 } 471 472 virtual CompilerType 473 GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, 474 size_t bit_size) = 0; 475 476 virtual bool IsBeingDefined(lldb::opaque_compiler_type_t type) = 0; 477 478 virtual bool IsConst(lldb::opaque_compiler_type_t type) = 0; 479 480 virtual uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, 481 CompilerType *base_type_ptr) = 0; 482 483 virtual bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) = 0; 484 485 virtual bool IsTypedefType(lldb::opaque_compiler_type_t type) = 0; 486 487 // If the current object represents a typedef type, get the underlying type 488 virtual CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) = 0; 489 490 virtual bool IsVectorType(lldb::opaque_compiler_type_t type, 491 CompilerType *element_type, uint64_t *size) = 0; 492 493 virtual CompilerType 494 GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) = 0; 495 496 virtual CompilerType 497 GetNonReferenceType(lldb::opaque_compiler_type_t type) = 0; 498 499 virtual bool IsReferenceType(lldb::opaque_compiler_type_t type, 500 CompilerType *pointee_type, bool *is_rvalue) = 0; 501 502 virtual bool ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type)503 ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) { 504 return IsPointerOrReferenceType(type, nullptr); 505 } 506 GetUserExpression(llvm::StringRef expr,llvm::StringRef prefix,SourceLanguage language,Expression::ResultType desired_type,const EvaluateExpressionOptions & options,ValueObject * ctx_obj)507 virtual UserExpression *GetUserExpression( 508 llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, 509 Expression::ResultType desired_type, 510 const EvaluateExpressionOptions &options, ValueObject *ctx_obj) { 511 return nullptr; 512 } 513 GetFunctionCaller(const CompilerType & return_type,const Address & function_address,const ValueList & arg_value_list,const char * name)514 virtual FunctionCaller *GetFunctionCaller(const CompilerType &return_type, 515 const Address &function_address, 516 const ValueList &arg_value_list, 517 const char *name) { 518 return nullptr; 519 } 520 521 virtual std::unique_ptr<UtilityFunction> 522 CreateUtilityFunction(std::string text, std::string name); 523 GetPersistentExpressionState()524 virtual PersistentExpressionState *GetPersistentExpressionState() { 525 return nullptr; 526 } 527 528 virtual CompilerType GetTypeForFormatters(void *type); 529 530 virtual LazyBool ShouldPrintAsOneLiner(void *type, ValueObject *valobj); 531 532 // Type systems can have types that are placeholder types, which are meant to 533 // indicate the presence of a type, but offer no actual information about 534 // said types, and leave the burden of actually figuring type information out 535 // to dynamic type resolution. For instance a language with a generics 536 // system, can use placeholder types to indicate "type argument goes here", 537 // without promising uniqueness of the placeholder, nor attaching any 538 // actually idenfiable information to said placeholder. This API allows type 539 // systems to tell LLDB when such a type has been encountered In response, 540 // the debugger can react by not using this type as a cache entry in any 541 // type-specific way For instance, LLDB will currently not cache any 542 // formatters that are discovered on such a type as attributable to the 543 // meaningless type itself, instead preferring to use the dynamic type 544 virtual bool IsMeaninglessWithoutDynamicResolution(void *type); 545 546 virtual std::optional<llvm::json::Value> ReportStatistics(); 547 GetHasForcefullyCompletedTypes()548 bool GetHasForcefullyCompletedTypes() const { 549 return m_has_forcefully_completed_types; 550 } 551 protected: 552 SymbolFile *m_sym_file = nullptr; 553 /// Used for reporting statistics. 554 bool m_has_forcefully_completed_types = false; 555 }; 556 557 class TypeSystemMap { 558 public: 559 TypeSystemMap(); 560 ~TypeSystemMap(); 561 562 // Clear calls Finalize on all the TypeSystems managed by this map, and then 563 // empties the map. 564 void Clear(); 565 566 // Iterate through all of the type systems that are created. Return true from 567 // callback to keep iterating, false to stop iterating. 568 void ForEach(std::function<bool(lldb::TypeSystemSP)> const &callback); 569 570 llvm::Expected<lldb::TypeSystemSP> 571 GetTypeSystemForLanguage(lldb::LanguageType language, Module *module, 572 bool can_create); 573 574 llvm::Expected<lldb::TypeSystemSP> 575 GetTypeSystemForLanguage(lldb::LanguageType language, Target *target, 576 bool can_create); 577 578 /// Check all type systems in the map to see if any have forcefully completed 579 /// types; 580 bool GetHasForcefullyCompletedTypes() const; 581 protected: 582 typedef llvm::DenseMap<uint16_t, lldb::TypeSystemSP> collection; 583 mutable std::mutex m_mutex; ///< A mutex to keep this object happy in 584 /// multi-threaded environments. 585 collection m_map; 586 bool m_clear_in_progress = false; 587 588 private: 589 typedef llvm::function_ref<lldb::TypeSystemSP()> CreateCallback; 590 /// Finds the type system for the given language. If no type system could be 591 /// found for a language and a CreateCallback was provided, the value 592 /// returned by the callback will be treated as the TypeSystem for the 593 /// language. 594 /// 595 /// \param language The language for which the type system should be found. 596 /// \param create_callback A callback that will be called if no previously 597 /// created TypeSystem that fits the given language 598 /// could found. Can be omitted if a non-existent 599 /// type system should be treated as an error 600 /// instead. 601 /// \return The found type system or an error. 602 llvm::Expected<lldb::TypeSystemSP> GetTypeSystemForLanguage( 603 lldb::LanguageType language, 604 std::optional<CreateCallback> create_callback = std::nullopt); 605 }; 606 607 } // namespace lldb_private 608 609 #endif // LLDB_SYMBOL_TYPESYSTEM_H 610