@@ -302,6 +302,192 @@ bool CompilerType::IsBeingDefined() const {
302
302
return false ;
303
303
}
304
304
305
+ bool CompilerType::IsInteger () const {
306
+ bool is_signed = false ; // May be reset by the call below.
307
+ return IsIntegerType (is_signed);
308
+ }
309
+
310
+ bool CompilerType::IsFloat () const {
311
+ uint32_t count = 0 ;
312
+ bool is_complex = false ;
313
+ return IsFloatingPointType (count, is_complex);
314
+ }
315
+
316
+ bool CompilerType::IsEnumerationType () const {
317
+ bool is_signed = false ; // May be reset by the call below.
318
+ return IsEnumerationType (is_signed);
319
+ }
320
+
321
+ bool CompilerType::IsUnscopedEnumerationType () const {
322
+ return IsEnumerationType () && !IsScopedEnumerationType ();
323
+ }
324
+
325
+ bool CompilerType::IsIntegerOrUnscopedEnumerationType () const {
326
+ return IsInteger () || IsUnscopedEnumerationType ();
327
+ }
328
+
329
+ bool CompilerType::IsSigned () const {
330
+ return GetTypeInfo () & lldb::eTypeIsSigned;
331
+ }
332
+
333
+ bool CompilerType::IsNullPtrType () const {
334
+ return GetCanonicalType ().GetBasicTypeEnumeration () ==
335
+ lldb::eBasicTypeNullPtr;
336
+ }
337
+
338
+ bool CompilerType::IsBoolean () const {
339
+ return GetCanonicalType ().GetBasicTypeEnumeration () == lldb::eBasicTypeBool;
340
+ }
341
+
342
+ bool CompilerType::IsEnumerationIntegerTypeSigned () const {
343
+ if (IsValid ())
344
+ return GetEnumerationIntegerType ().GetTypeInfo () & lldb::eTypeIsSigned;
345
+
346
+ return false ;
347
+ }
348
+
349
+ bool CompilerType::IsScalarOrUnscopedEnumerationType () const {
350
+ return IsScalarType () || IsUnscopedEnumerationType ();
351
+ }
352
+
353
+ bool CompilerType::IsPromotableIntegerType () const {
354
+ // Unscoped enums are always considered as promotable, even if their
355
+ // underlying type does not need to be promoted (e.g. "int").
356
+ if (IsUnscopedEnumerationType ())
357
+ return true ;
358
+
359
+ switch (GetCanonicalType ().GetBasicTypeEnumeration ()) {
360
+ case lldb::eBasicTypeBool:
361
+ case lldb::eBasicTypeChar:
362
+ case lldb::eBasicTypeSignedChar:
363
+ case lldb::eBasicTypeUnsignedChar:
364
+ case lldb::eBasicTypeShort:
365
+ case lldb::eBasicTypeUnsignedShort:
366
+ case lldb::eBasicTypeWChar:
367
+ case lldb::eBasicTypeSignedWChar:
368
+ case lldb::eBasicTypeUnsignedWChar:
369
+ case lldb::eBasicTypeChar16:
370
+ case lldb::eBasicTypeChar32:
371
+ return true ;
372
+
373
+ default :
374
+ return false ;
375
+ }
376
+
377
+ llvm_unreachable (" All cases handled above." );
378
+ }
379
+
380
+ bool CompilerType::IsPointerToVoid () const {
381
+ if (!IsValid ())
382
+ return false ;
383
+
384
+ return IsPointerType () &&
385
+ GetPointeeType ().GetBasicTypeEnumeration () == lldb::eBasicTypeVoid;
386
+ }
387
+
388
+ bool CompilerType::IsRecordType () const {
389
+ if (!IsValid ())
390
+ return false ;
391
+
392
+ return GetCanonicalType ().GetTypeClass () &
393
+ (lldb::eTypeClassClass | lldb::eTypeClassStruct |
394
+ lldb::eTypeClassUnion);
395
+ }
396
+
397
+ bool CompilerType::IsVirtualBase (CompilerType target_base,
398
+ CompilerType *virtual_base,
399
+ bool carry_virtual) const {
400
+ if (CompareTypes (target_base))
401
+ return carry_virtual;
402
+
403
+ if (!carry_virtual) {
404
+ uint32_t num_virtual_bases = GetNumVirtualBaseClasses ();
405
+ for (uint32_t i = 0 ; i < num_virtual_bases; ++i) {
406
+ uint32_t bit_offset;
407
+ auto base = GetVirtualBaseClassAtIndex (i, &bit_offset);
408
+ if (base.IsVirtualBase (target_base, virtual_base,
409
+ /* carry_virtual*/ true )) {
410
+ if (virtual_base)
411
+ *virtual_base = base;
412
+
413
+ return true ;
414
+ }
415
+ }
416
+ }
417
+
418
+ uint32_t num_direct_bases = GetNumDirectBaseClasses ();
419
+ for (uint32_t i = 0 ; i < num_direct_bases; ++i) {
420
+ uint32_t bit_offset;
421
+ auto base = GetDirectBaseClassAtIndex (i, &bit_offset);
422
+ if (base.IsVirtualBase (target_base, virtual_base, carry_virtual))
423
+ return true ;
424
+ }
425
+
426
+ return false ;
427
+ }
428
+
429
+ bool CompilerType::IsContextuallyConvertibleToBool () const {
430
+ return IsScalarType () || IsUnscopedEnumerationType () || IsPointerType () ||
431
+ IsNullPtrType () || IsArrayType ();
432
+ }
433
+
434
+ bool CompilerType::IsBasicType () const {
435
+ return GetCanonicalType ().GetBasicTypeEnumeration () !=
436
+ lldb::eBasicTypeInvalid;
437
+ }
438
+
439
+ std::string CompilerType::TypeDescription () {
440
+ auto name = GetTypeName ();
441
+ auto canonical_name = GetCanonicalType ().GetTypeName ();
442
+ if (name.IsEmpty () || canonical_name.IsEmpty ())
443
+ return " ''" ; // Should not happen, unless the input is broken somehow.
444
+
445
+ if (name == canonical_name)
446
+ return llvm::formatv (" '{0}'" , name);
447
+
448
+ return llvm::formatv (" '{0}' (canonically referred to as '{1}')" , name,
449
+ canonical_name);
450
+ }
451
+
452
+ bool CompilerType::CompareTypes (CompilerType rhs) const {
453
+ if (*this == rhs)
454
+ return true ;
455
+
456
+ const ConstString name = GetFullyUnqualifiedType ().GetTypeName ();
457
+ const ConstString rhs_name = rhs.GetFullyUnqualifiedType ().GetTypeName ();
458
+ return name == rhs_name;
459
+ }
460
+
461
+ const char *CompilerType::GetTypeTag () {
462
+ switch (GetTypeClass ()) {
463
+ case lldb::eTypeClassClass:
464
+ return " class" ;
465
+ case lldb::eTypeClassEnumeration:
466
+ return " enum" ;
467
+ case lldb::eTypeClassStruct:
468
+ return " struct" ;
469
+ case lldb::eTypeClassUnion:
470
+ return " union" ;
471
+ default :
472
+ return " unknown" ;
473
+ }
474
+ llvm_unreachable (" All cases are covered by code above." );
475
+ }
476
+
477
+ uint32_t CompilerType::GetNumberOfNonEmptyBaseClasses () {
478
+ uint32_t ret = 0 ;
479
+ uint32_t num_direct_bases = GetNumDirectBaseClasses ();
480
+
481
+ for (uint32_t i = 0 ; i < num_direct_bases; ++i) {
482
+ uint32_t bit_offset;
483
+ CompilerType base_type = GetDirectBaseClassAtIndex (i, &bit_offset);
484
+ if (base_type.GetNumFields () > 0 ||
485
+ base_type.GetNumberOfNonEmptyBaseClasses () > 0 )
486
+ ret += 1 ;
487
+ }
488
+ return ret;
489
+ }
490
+
305
491
// Type Completion
306
492
307
493
bool CompilerType::GetCompleteType () const {
0 commit comments