ObjCLanguage.cpp 44.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
//===-- ObjCLanguage.cpp ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <mutex>

#include "ObjCLanguage.h"

#include "lldb/Core/PluginManager.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangUtil.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/StreamString.h"

#include "llvm/Support/Threading.h"

#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"

#include "CF.h"
#include "Cocoa.h"
#include "CoreMedia.h"
#include "NSDictionary.h"
#include "NSSet.h"
#include "NSString.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;

void ObjCLanguage::Initialize() {
  PluginManager::RegisterPlugin(GetPluginNameStatic(), "Objective-C Language",
                                CreateInstance);
}

void ObjCLanguage::Terminate() {
  PluginManager::UnregisterPlugin(CreateInstance);
}

lldb_private::ConstString ObjCLanguage::GetPluginNameStatic() {
  static ConstString g_name("objc");
  return g_name;
}

// PluginInterface protocol

lldb_private::ConstString ObjCLanguage::GetPluginName() {
  return GetPluginNameStatic();
}

uint32_t ObjCLanguage::GetPluginVersion() { return 1; }

// Static Functions

Language *ObjCLanguage::CreateInstance(lldb::LanguageType language) {
  switch (language) {
  case lldb::eLanguageTypeObjC:
    return new ObjCLanguage();
  default:
    return nullptr;
  }
}

void ObjCLanguage::MethodName::Clear() {
  m_full.Clear();
  m_class.Clear();
  m_category.Clear();
  m_selector.Clear();
  m_type = eTypeUnspecified;
  m_category_is_valid = false;
}

bool ObjCLanguage::MethodName::SetName(llvm::StringRef name, bool strict) {
  Clear();
  if (name.empty())
    return IsValid(strict);

  // If "strict" is true. then the method must be specified with a '+' or '-'
  // at the beginning. If "strict" is false, then the '+' or '-' can be omitted
  bool valid_prefix = false;

  if (name.size() > 1 && (name[0] == '+' || name[0] == '-')) {
    valid_prefix = name[1] == '[';
    if (name[0] == '+')
      m_type = eTypeClassMethod;
    else
      m_type = eTypeInstanceMethod;
  } else if (!strict) {
    // "strict" is false, the name just needs to start with '['
    valid_prefix = name[0] == '[';
  }

  if (valid_prefix) {
    int name_len = name.size();
    // Objective-C methods must have at least:
    //      "-[" or "+[" prefix
    //      One character for a class name
    //      One character for the space between the class name
    //      One character for the method name
    //      "]" suffix
    if (name_len >= (5 + (strict ? 1 : 0)) && name.back() == ']') {
      m_full.SetString(name);
    }
  }
  return IsValid(strict);
}

bool ObjCLanguage::MethodName::SetName(const char *name, bool strict) {
  return SetName(llvm::StringRef(name), strict);
}

ConstString ObjCLanguage::MethodName::GetClassName() {
  if (!m_class) {
    if (IsValid(false)) {
      const char *full = m_full.GetCString();
      const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
      const char *paren_pos = strchr(class_start, '(');
      if (paren_pos) {
        m_class.SetCStringWithLength(class_start, paren_pos - class_start);
      } else {
        // No '(' was found in the full name, we can definitively say that our
        // category was valid (and empty).
        m_category_is_valid = true;
        const char *space_pos = strchr(full, ' ');
        if (space_pos) {
          m_class.SetCStringWithLength(class_start, space_pos - class_start);
          if (!m_class_category) {
            // No category in name, so we can also fill in the m_class_category
            m_class_category = m_class;
          }
        }
      }
    }
  }
  return m_class;
}

ConstString ObjCLanguage::MethodName::GetClassNameWithCategory() {
  if (!m_class_category) {
    if (IsValid(false)) {
      const char *full = m_full.GetCString();
      const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
      const char *space_pos = strchr(full, ' ');
      if (space_pos) {
        m_class_category.SetCStringWithLength(class_start,
                                              space_pos - class_start);
        // If m_class hasn't been filled in and the class with category doesn't
        // contain a '(', then we can also fill in the m_class
        if (!m_class && strchr(m_class_category.GetCString(), '(') == nullptr) {
          m_class = m_class_category;
          // No '(' was found in the full name, we can definitively say that
          // our category was valid (and empty).
          m_category_is_valid = true;
        }
      }
    }
  }
  return m_class_category;
}

ConstString ObjCLanguage::MethodName::GetSelector() {
  if (!m_selector) {
    if (IsValid(false)) {
      const char *full = m_full.GetCString();
      const char *space_pos = strchr(full, ' ');
      if (space_pos) {
        ++space_pos; // skip the space
        m_selector.SetCStringWithLength(space_pos, m_full.GetLength() -
                                                       (space_pos - full) - 1);
      }
    }
  }
  return m_selector;
}

ConstString ObjCLanguage::MethodName::GetCategory() {
  if (!m_category_is_valid && !m_category) {
    if (IsValid(false)) {
      m_category_is_valid = true;
      const char *full = m_full.GetCString();
      const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
      const char *open_paren_pos = strchr(class_start, '(');
      if (open_paren_pos) {
        ++open_paren_pos; // Skip the open paren
        const char *close_paren_pos = strchr(open_paren_pos, ')');
        if (close_paren_pos)
          m_category.SetCStringWithLength(open_paren_pos,
                                          close_paren_pos - open_paren_pos);
      }
    }
  }
  return m_category;
}

ConstString ObjCLanguage::MethodName::GetFullNameWithoutCategory(
    bool empty_if_no_category) {
  if (IsValid(false)) {
    if (HasCategory()) {
      StreamString strm;
      if (m_type == eTypeClassMethod)
        strm.PutChar('+');
      else if (m_type == eTypeInstanceMethod)
        strm.PutChar('-');
      strm.Printf("[%s %s]", GetClassName().GetCString(),
                  GetSelector().GetCString());
      return ConstString(strm.GetString());
    }

    if (!empty_if_no_category) {
      // Just return the full name since it doesn't have a category
      return GetFullName();
    }
  }
  return ConstString();
}

std::vector<ConstString>
ObjCLanguage::GetMethodNameVariants(ConstString method_name) const {
  std::vector<ConstString> variant_names;
  ObjCLanguage::MethodName objc_method(method_name.GetCString(), false);
  if (!objc_method.IsValid(false)) {
    return variant_names;
  }

  const bool is_class_method =
      objc_method.GetType() == MethodName::eTypeClassMethod;
  const bool is_instance_method =
      objc_method.GetType() == MethodName::eTypeInstanceMethod;
  ConstString name_sans_category =
      objc_method.GetFullNameWithoutCategory(/*empty_if_no_category*/ true);

  if (is_class_method || is_instance_method) {
    if (name_sans_category)
      variant_names.emplace_back(name_sans_category);
  } else {
    StreamString strm;

    strm.Printf("+%s", objc_method.GetFullName().GetCString());
    variant_names.emplace_back(strm.GetString());
    strm.Clear();

    strm.Printf("-%s", objc_method.GetFullName().GetCString());
    variant_names.emplace_back(strm.GetString());
    strm.Clear();

    if (name_sans_category) {
      strm.Printf("+%s", name_sans_category.GetCString());
      variant_names.emplace_back(strm.GetString());
      strm.Clear();

      strm.Printf("-%s", name_sans_category.GetCString());
      variant_names.emplace_back(strm.GetString());
    }
  }

  return variant_names;
}

static void LoadObjCFormatters(TypeCategoryImplSP objc_category_sp) {
  if (!objc_category_sp)
    return;

  TypeSummaryImpl::Flags objc_flags;
  objc_flags.SetCascades(false)
      .SetSkipPointers(true)
      .SetSkipReferences(true)
      .SetDontShowChildren(true)
      .SetDontShowValue(true)
      .SetShowMembersOneLiner(false)
      .SetHideItemNames(false);

  lldb::TypeSummaryImplSP ObjC_BOOL_summary(new CXXFunctionSummaryFormat(
      objc_flags, lldb_private::formatters::ObjCBOOLSummaryProvider, ""));
  objc_category_sp->GetTypeSummariesContainer()->Add(ConstString("BOOL"),
                                                     ObjC_BOOL_summary);
  objc_category_sp->GetTypeSummariesContainer()->Add(ConstString("BOOL &"),
                                                     ObjC_BOOL_summary);
  objc_category_sp->GetTypeSummariesContainer()->Add(ConstString("BOOL *"),
                                                     ObjC_BOOL_summary);

  // we need to skip pointers here since we are special casing a SEL* when
  // retrieving its value
  objc_flags.SetSkipPointers(true);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::ObjCSELSummaryProvider<false>,
                "SEL summary provider", ConstString("SEL"), objc_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::ObjCSELSummaryProvider<false>,
      "SEL summary provider", ConstString("struct objc_selector"), objc_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::ObjCSELSummaryProvider<false>,
      "SEL summary provider", ConstString("objc_selector"), objc_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::ObjCSELSummaryProvider<true>,
      "SEL summary provider", ConstString("objc_selector *"), objc_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::ObjCSELSummaryProvider<true>,
                "SEL summary provider", ConstString("SEL *"), objc_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::ObjCClassSummaryProvider,
                "Class summary provider", ConstString("Class"), objc_flags);

  SyntheticChildren::Flags class_synth_flags;
  class_synth_flags.SetCascades(true).SetSkipPointers(false).SetSkipReferences(
      false);

  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::ObjCClassSyntheticFrontEndCreator,
                  "Class synthetic children", ConstString("Class"),
                  class_synth_flags);

  objc_flags.SetSkipPointers(false);
  objc_flags.SetCascades(true);
  objc_flags.SetSkipReferences(false);

  AddStringSummary(objc_category_sp, "${var.__FuncPtr%A}",
                   ConstString("__block_literal_generic"), objc_flags);

  AddStringSummary(objc_category_sp, "${var.years} years, ${var.months} "
                                     "months, ${var.days} days, ${var.hours} "
                                     "hours, ${var.minutes} minutes "
                                     "${var.seconds} seconds",
                   ConstString("CFGregorianUnits"), objc_flags);
  AddStringSummary(objc_category_sp,
                   "location=${var.location} length=${var.length}",
                   ConstString("CFRange"), objc_flags);

  AddStringSummary(objc_category_sp,
                   "location=${var.location}, length=${var.length}",
                   ConstString("NSRange"), objc_flags);
  AddStringSummary(objc_category_sp, "(${var.origin}, ${var.size}), ...",
                   ConstString("NSRectArray"), objc_flags);

  AddOneLineSummary(objc_category_sp, ConstString("NSPoint"), objc_flags);
  AddOneLineSummary(objc_category_sp, ConstString("NSSize"), objc_flags);
  AddOneLineSummary(objc_category_sp, ConstString("NSRect"), objc_flags);

  AddOneLineSummary(objc_category_sp, ConstString("CGSize"), objc_flags);
  AddOneLineSummary(objc_category_sp, ConstString("CGPoint"), objc_flags);
  AddOneLineSummary(objc_category_sp, ConstString("CGRect"), objc_flags);

  AddStringSummary(objc_category_sp,
                   "red=${var.red} green=${var.green} blue=${var.blue}",
                   ConstString("RGBColor"), objc_flags);
  AddStringSummary(
      objc_category_sp,
      "(t=${var.top}, l=${var.left}, b=${var.bottom}, r=${var.right})",
      ConstString("Rect"), objc_flags);
  AddStringSummary(objc_category_sp, "{(v=${var.v}, h=${var.h})}",
                   ConstString("Point"), objc_flags);
  AddStringSummary(objc_category_sp,
                   "${var.month}/${var.day}/${var.year}  ${var.hour} "
                   ":${var.minute} :${var.second} dayOfWeek:${var.dayOfWeek}",
                   ConstString("DateTimeRect *"), objc_flags);
  AddStringSummary(objc_category_sp, "${var.ld.month}/${var.ld.day}/"
                                     "${var.ld.year} ${var.ld.hour} "
                                     ":${var.ld.minute} :${var.ld.second} "
                                     "dayOfWeek:${var.ld.dayOfWeek}",
                   ConstString("LongDateRect"), objc_flags);
  AddStringSummary(objc_category_sp, "(x=${var.x}, y=${var.y})",
                   ConstString("HIPoint"), objc_flags);
  AddStringSummary(objc_category_sp, "origin=${var.origin} size=${var.size}",
                   ConstString("HIRect"), objc_flags);

  TypeSummaryImpl::Flags appkit_flags;
  appkit_flags.SetCascades(true)
      .SetSkipPointers(false)
      .SetSkipReferences(false)
      .SetDontShowChildren(true)
      .SetDontShowValue(false)
      .SetShowMembersOneLiner(false)
      .SetHideItemNames(false);

  appkit_flags.SetDontShowChildren(false);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("NSArray"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("NSMutableArray"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("__NSArrayI"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("__NSArray0"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSArraySummaryProvider,
                "NSArray summary provider",
                ConstString("__NSSingleObjectArrayI"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("__NSArrayM"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("__NSCFArray"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("_NSCallStackArray"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSArraySummaryProvider,
      "NSArray summary provider", ConstString("CFArrayRef"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSArraySummaryProvider,
                "NSArray summary provider", ConstString("CFMutableArrayRef"),
                appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<false>,
                "NSDictionary summary provider", ConstString("NSDictionary"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<false>,
                "NSDictionary summary provider",
                ConstString("NSMutableDictionary"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<false>,
                "NSDictionary summary provider",
                ConstString("__NSCFDictionary"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<false>,
                "NSDictionary summary provider", ConstString("__NSDictionaryI"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<false>,
                "NSDictionary summary provider",
                ConstString("__NSSingleEntryDictionaryI"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<false>,
                "NSDictionary summary provider", ConstString("__NSDictionaryM"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<true>,
                "NSDictionary summary provider", ConstString("CFDictionaryRef"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDictionarySummaryProvider<true>,
                "NSDictionary summary provider",
                ConstString("CFMutableDictionaryRef"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSSetSummaryProvider<false>,
                "NSSet summary", ConstString("NSSet"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
      "NSMutableSet summary", ConstString("NSMutableSet"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSSetSummaryProvider<true>,
                "CFSetRef summary", ConstString("CFSetRef"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<true>,
      "CFMutableSetRef summary", ConstString("CFMutableSetRef"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSSetSummaryProvider<false>,
                "__NSCFSet summary", ConstString("__NSCFSet"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSSetSummaryProvider<false>,
                "__NSSetI summary", ConstString("__NSSetI"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSSetSummaryProvider<false>,
                "__NSSetM summary", ConstString("__NSSetM"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
      "NSCountedSet summary", ConstString("NSCountedSet"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
      "NSMutableSet summary", ConstString("NSMutableSet"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
      "NSOrderedSet summary", ConstString("NSOrderedSet"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
      "__NSOrderedSetI summary", ConstString("__NSOrderedSetI"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSSetSummaryProvider<false>,
      "__NSOrderedSetM summary", ConstString("__NSOrderedSetM"), appkit_flags);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSError_SummaryProvider,
      "NSError summary provider", ConstString("NSError"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSException_SummaryProvider,
      "NSException summary provider", ConstString("NSException"), appkit_flags);

  // AddSummary(appkit_category_sp, "${var.key%@} -> ${var.value%@}",
  // ConstString("$_lldb_typegen_nspair"), appkit_flags);

  appkit_flags.SetDontShowChildren(true);

  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("__NSArrayM"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("__NSArrayI"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("__NSArray0"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children",
                  ConstString("__NSSingleObjectArrayI"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("NSArray"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("NSMutableArray"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("__NSCFArray"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("_NSCallStackArray"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children",
                  ConstString("CFMutableArrayRef"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSArraySyntheticFrontEndCreator,
                  "NSArray synthetic children", ConstString("CFArrayRef"),
                  ScriptedSyntheticChildren::Flags());

  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children", ConstString("__NSDictionaryM"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children", ConstString("__NSDictionaryI"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children",
      ConstString("__NSSingleEntryDictionaryI"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children", ConstString("__NSCFDictionary"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children", ConstString("NSDictionary"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children", ConstString("NSMutableDictionary"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children", ConstString("CFDictionaryRef"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp,
      lldb_private::formatters::NSDictionarySyntheticFrontEndCreator,
      "NSDictionary synthetic children", ConstString("CFMutableDictionaryRef"),
      ScriptedSyntheticChildren::Flags());

  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSErrorSyntheticFrontEndCreator,
                  "NSError synthetic children", ConstString("NSError"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSExceptionSyntheticFrontEndCreator,
                  "NSException synthetic children", ConstString("NSException"),
                  ScriptedSyntheticChildren::Flags());

  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSSetSyntheticFrontEndCreator,
                  "NSSet synthetic children", ConstString("NSSet"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSSetSyntheticFrontEndCreator,
                  "__NSSetI synthetic children", ConstString("__NSSetI"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSSetSyntheticFrontEndCreator,
                  "__NSSetM synthetic children", ConstString("__NSSetM"),
                  ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator,
      "NSMutableSet synthetic children", ConstString("NSMutableSet"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator,
      "NSOrderedSet synthetic children", ConstString("NSOrderedSet"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator,
      "__NSOrderedSetI synthetic children", ConstString("__NSOrderedSetI"),
      ScriptedSyntheticChildren::Flags());
  AddCXXSynthetic(
      objc_category_sp, lldb_private::formatters::NSSetSyntheticFrontEndCreator,
      "__NSOrderedSetM synthetic children", ConstString("__NSOrderedSetM"),
      ScriptedSyntheticChildren::Flags());

  AddCXXSynthetic(objc_category_sp,
                  lldb_private::formatters::NSIndexPathSyntheticFrontEndCreator,
                  "NSIndexPath synthetic children", ConstString("NSIndexPath"),
                  ScriptedSyntheticChildren::Flags());

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::CFBagSummaryProvider,
      "CFBag summary provider", ConstString("CFBagRef"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBagSummaryProvider,
                "CFBag summary provider", ConstString("__CFBag"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBagSummaryProvider,
                "CFBag summary provider", ConstString("const struct __CFBag"),
                appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::CFBagSummaryProvider,
      "CFBag summary provider", ConstString("CFMutableBagRef"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBinaryHeapSummaryProvider,
                "CFBinaryHeap summary provider", ConstString("CFBinaryHeapRef"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBinaryHeapSummaryProvider,
                "CFBinaryHeap summary provider", ConstString("__CFBinaryHeap"),
                appkit_flags);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSStringSummaryProvider,
      "NSString summary provider", ConstString("NSString"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSStringSummaryProvider,
      "NSString summary provider", ConstString("CFStringRef"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSStringSummaryProvider,
      "NSString summary provider", ConstString("__CFString"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSStringSummaryProvider,
                "NSString summary provider", ConstString("CFMutableStringRef"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSStringSummaryProvider,
                "NSString summary provider", ConstString("NSMutableString"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSStringSummaryProvider,
                "NSString summary provider",
                ConstString("__NSCFConstantString"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSStringSummaryProvider,
      "NSString summary provider", ConstString("__NSCFString"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSStringSummaryProvider,
                "NSString summary provider", ConstString("NSCFConstantString"),
                appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSStringSummaryProvider,
      "NSString summary provider", ConstString("NSCFString"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSStringSummaryProvider,
      "NSString summary provider", ConstString("NSPathStore2"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSStringSummaryProvider,
                "NSString summary provider",
                ConstString("NSTaggedPointerString"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSAttributedStringSummaryProvider,
                "NSAttributedString summary provider",
                ConstString("NSAttributedString"), appkit_flags);
  AddCXXSummary(
      objc_category_sp,
      lldb_private::formatters::NSMutableAttributedStringSummaryProvider,
      "NSMutableAttributedString summary provider",
      ConstString("NSMutableAttributedString"), appkit_flags);
  AddCXXSummary(
      objc_category_sp,
      lldb_private::formatters::NSMutableAttributedStringSummaryProvider,
      "NSMutableAttributedString summary provider",
      ConstString("NSConcreteMutableAttributedString"), appkit_flags);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSBundleSummaryProvider,
      "NSBundle summary provider", ConstString("NSBundle"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDataSummaryProvider<false>,
                "NSData summary provider", ConstString("NSData"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>,
      "NSData summary provider", ConstString("_NSInlineData"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>,
      "NSData summary provider", ConstString("NSConcreteData"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDataSummaryProvider<false>,
                "NSData summary provider", ConstString("NSConcreteMutableData"),
                appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>,
      "NSData summary provider", ConstString("NSMutableData"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDataSummaryProvider<false>,
      "NSData summary provider", ConstString("__NSCFData"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDataSummaryProvider<true>,
      "NSData summary provider", ConstString("CFDataRef"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDataSummaryProvider<true>,
      "NSData summary provider", ConstString("CFMutableDataRef"), appkit_flags);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSMachPortSummaryProvider,
      "NSMachPort summary provider", ConstString("NSMachPort"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSNotificationSummaryProvider,
                "NSNotification summary provider",
                ConstString("NSNotification"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSNotificationSummaryProvider,
                "NSNotification summary provider",
                ConstString("NSConcreteNotification"), appkit_flags);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSNumberSummaryProvider,
      "NSNumber summary provider", ConstString("NSNumber"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSNumberSummaryProvider,
      "CFNumberRef summary provider", ConstString("CFNumberRef"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSNumberSummaryProvider,
      "NSNumber summary provider", ConstString("__NSCFBoolean"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSNumberSummaryProvider,
      "NSNumber summary provider", ConstString("__NSCFNumber"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSNumberSummaryProvider,
      "NSNumber summary provider", ConstString("NSCFBoolean"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSNumberSummaryProvider,
      "NSNumber summary provider", ConstString("NSCFNumber"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSNumberSummaryProvider,
                "NSDecimalNumber summary provider",
                ConstString("NSDecimalNumber"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSURLSummaryProvider,
                "NSURL summary provider", ConstString("NSURL"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSURLSummaryProvider,
      "NSURL summary provider", ConstString("CFURLRef"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSDateSummaryProvider,
                "NSDate summary provider", ConstString("NSDate"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDateSummaryProvider,
      "NSDate summary provider", ConstString("__NSDate"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDateSummaryProvider,
      "NSDate summary provider", ConstString("__NSTaggedDate"), appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSDateSummaryProvider,
      "NSDate summary provider", ConstString("NSCalendarDate"), appkit_flags);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSTimeZoneSummaryProvider,
      "NSTimeZone summary provider", ConstString("NSTimeZone"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSTimeZoneSummaryProvider,
                "NSTimeZone summary provider", ConstString("CFTimeZoneRef"),
                appkit_flags);
  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSTimeZoneSummaryProvider,
      "NSTimeZone summary provider", ConstString("__NSTimeZone"), appkit_flags);

  // CFAbsoluteTime is actually a double rather than a pointer to an object we
  // do not care about the numeric value, since it is probably meaningless to
  // users
  appkit_flags.SetDontShowValue(true);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFAbsoluteTimeSummaryProvider,
                "CFAbsoluteTime summary provider",
                ConstString("CFAbsoluteTime"), appkit_flags);
  appkit_flags.SetDontShowValue(false);

  AddCXXSummary(
      objc_category_sp, lldb_private::formatters::NSIndexSetSummaryProvider,
      "NSIndexSet summary provider", ConstString("NSIndexSet"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::NSIndexSetSummaryProvider,
                "NSIndexSet summary provider", ConstString("NSMutableIndexSet"),
                appkit_flags);

  AddStringSummary(objc_category_sp,
                   "@\"${var.month%d}/${var.day%d}/${var.year%d} "
                   "${var.hour%d}:${var.minute%d}:${var.second}\"",
                   ConstString("CFGregorianDate"), appkit_flags);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBitVectorSummaryProvider,
                "CFBitVector summary provider", ConstString("CFBitVectorRef"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBitVectorSummaryProvider,
                "CFBitVector summary provider",
                ConstString("CFMutableBitVectorRef"), appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBitVectorSummaryProvider,
                "CFBitVector summary provider", ConstString("__CFBitVector"),
                appkit_flags);
  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CFBitVectorSummaryProvider,
                "CFBitVector summary provider",
                ConstString("__CFMutableBitVector"), appkit_flags);
}

static void LoadCoreMediaFormatters(TypeCategoryImplSP objc_category_sp) {
  if (!objc_category_sp)
    return;

  TypeSummaryImpl::Flags cm_flags;
  cm_flags.SetCascades(true)
      .SetDontShowChildren(false)
      .SetDontShowValue(false)
      .SetHideItemNames(false)
      .SetShowMembersOneLiner(false)
      .SetSkipPointers(false)
      .SetSkipReferences(false);

  AddCXXSummary(objc_category_sp,
                lldb_private::formatters::CMTimeSummaryProvider,
                "CMTime summary provider", ConstString("CMTime"), cm_flags);
}

lldb::TypeCategoryImplSP ObjCLanguage::GetFormatters() {
  static llvm::once_flag g_initialize;
  static TypeCategoryImplSP g_category;

  llvm::call_once(g_initialize, [this]() -> void {
    DataVisualization::Categories::GetCategory(GetPluginName(), g_category);
    if (g_category) {
      LoadCoreMediaFormatters(g_category);
      LoadObjCFormatters(g_category);
    }
  });
  return g_category;
}

std::vector<ConstString>
ObjCLanguage::GetPossibleFormattersMatches(ValueObject &valobj,
                                           lldb::DynamicValueType use_dynamic) {
  std::vector<ConstString> result;

  if (use_dynamic == lldb::eNoDynamicValues)
    return result;

  CompilerType compiler_type(valobj.GetCompilerType());

  const bool check_cpp = false;
  const bool check_objc = true;
  bool canBeObjCDynamic =
      compiler_type.IsPossibleDynamicType(nullptr, check_cpp, check_objc);

  if (canBeObjCDynamic && ClangUtil::IsClangType(compiler_type)) {
    do {
      lldb::ProcessSP process_sp = valobj.GetProcessSP();
      if (!process_sp)
        break;
      ObjCLanguageRuntime *runtime = ObjCLanguageRuntime::Get(*process_sp);
      if (runtime == nullptr)
        break;
      ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp(
          runtime->GetClassDescriptor(valobj));
      if (!objc_class_sp)
        break;
      if (ConstString name = objc_class_sp->GetClassName())
        result.push_back(name);
    } while (false);
  }

  return result;
}

std::unique_ptr<Language::TypeScavenger> ObjCLanguage::GetTypeScavenger() {
  class ObjCScavengerResult : public Language::TypeScavenger::Result {
  public:
    ObjCScavengerResult(CompilerType type)
        : Language::TypeScavenger::Result(), m_compiler_type(type) {}

    bool IsValid() override { return m_compiler_type.IsValid(); }

    bool DumpToStream(Stream &stream, bool print_help_if_available) override {
      if (IsValid()) {
        m_compiler_type.DumpTypeDescription(&stream);
        stream.EOL();
        return true;
      }
      return false;
    }

  private:
    CompilerType m_compiler_type;
  };

  class ObjCRuntimeScavenger : public Language::TypeScavenger {
  protected:
    bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
                   ResultSet &results) override {
      bool result = false;

      if (auto *process = exe_scope->CalculateProcess().get()) {
        if (auto *objc_runtime = ObjCLanguageRuntime::Get(*process)) {
          if (auto *decl_vendor = objc_runtime->GetDeclVendor()) {
            ConstString name(key);
            for (const CompilerType &type :
                 decl_vendor->FindTypes(name, /*max_matches*/ UINT32_MAX)) {
              result = true;
              std::unique_ptr<Language::TypeScavenger::Result> result(
                  new ObjCScavengerResult(type));
              results.insert(std::move(result));
            }
          }
        }
      }

      return result;
    }

    friend class lldb_private::ObjCLanguage;
  };

  class ObjCModulesScavenger : public Language::TypeScavenger {
  protected:
    bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
                   ResultSet &results) override {
      bool result = false;

      if (auto *target = exe_scope->CalculateTarget().get()) {
        if (auto *clang_modules_decl_vendor =
                target->GetClangModulesDeclVendor()) {
          ConstString key_cs(key);
          auto types = clang_modules_decl_vendor->FindTypes(
              key_cs, /*max_matches*/ UINT32_MAX);
          if (!types.empty()) {
            result = true;
            std::unique_ptr<Language::TypeScavenger::Result> result(
                new ObjCScavengerResult(types.front()));
            results.insert(std::move(result));
          }
        }
      }

      return result;
    }

    friend class lldb_private::ObjCLanguage;
  };
  
  class ObjCDebugInfoScavenger : public Language::ImageListTypeScavenger {
  public:
    CompilerType AdjustForInclusion(CompilerType &candidate) override {
      LanguageType lang_type(candidate.GetMinimumLanguage());
      if (!Language::LanguageIsObjC(lang_type))
        return CompilerType();
      if (candidate.IsTypedefType())
        return candidate.GetTypedefedType();
      return candidate;
    }
  };

  return std::unique_ptr<TypeScavenger>(
      new Language::EitherTypeScavenger<ObjCModulesScavenger,
                                        ObjCRuntimeScavenger,
                                        ObjCDebugInfoScavenger>());
}

bool ObjCLanguage::GetFormatterPrefixSuffix(ValueObject &valobj,
                                            ConstString type_hint,
                                            std::string &prefix,
                                            std::string &suffix) {
  static ConstString g_CFBag("CFBag");
  static ConstString g_CFBinaryHeap("CFBinaryHeap");

  static ConstString g_NSNumberChar("NSNumber:char");
  static ConstString g_NSNumberShort("NSNumber:short");
  static ConstString g_NSNumberInt("NSNumber:int");
  static ConstString g_NSNumberLong("NSNumber:long");
  static ConstString g_NSNumberInt128("NSNumber:int128_t");
  static ConstString g_NSNumberFloat("NSNumber:float");
  static ConstString g_NSNumberDouble("NSNumber:double");

  static ConstString g_NSData("NSData");
  static ConstString g_NSArray("NSArray");
  static ConstString g_NSString("NSString");
  static ConstString g_NSStringStar("NSString*");

  if (type_hint.IsEmpty())
    return false;

  prefix.clear();
  suffix.clear();

  if (type_hint == g_CFBag || type_hint == g_CFBinaryHeap) {
    prefix = "@";
    return true;
  }

  if (type_hint == g_NSNumberChar) {
    prefix = "(char)";
    return true;
  }
  if (type_hint == g_NSNumberShort) {
    prefix = "(short)";
    return true;
  }
  if (type_hint == g_NSNumberInt) {
    prefix = "(int)";
    return true;
  }
  if (type_hint == g_NSNumberLong) {
    prefix = "(long)";
    return true;
  }
  if (type_hint == g_NSNumberInt128) {
    prefix = "(int128_t)";
    return true;
  }
  if (type_hint == g_NSNumberFloat) {
    prefix = "(float)";
    return true;
  }
  if (type_hint == g_NSNumberDouble) {
    prefix = "(double)";
    return true;
  }

  if (type_hint == g_NSData || type_hint == g_NSArray) {
    prefix = "@\"";
    suffix = "\"";
    return true;
  }

  if (type_hint == g_NSString || type_hint == g_NSStringStar) {
    prefix = "@";
    return true;
  }

  return false;
}

bool ObjCLanguage::IsNilReference(ValueObject &valobj) {
  const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
  bool isObjCpointer =
      (((valobj.GetCompilerType().GetTypeInfo(nullptr)) & mask) == mask);
  if (!isObjCpointer)
    return false;
  bool canReadValue = true;
  bool isZero = valobj.GetValueAsUnsigned(0, &canReadValue) == 0;
  return canReadValue && isZero;
}

bool ObjCLanguage::IsSourceFile(llvm::StringRef file_path) const {
  const auto suffixes = {".h", ".m", ".M"};
  for (auto suffix : suffixes) {
    if (file_path.endswith_lower(suffix))
      return true;
  }
  return false;
}