File: SwiftDictionary.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (94 lines) | stat: -rw-r--r-- 3,098 bytes parent folder | download
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
//===-- SwiftDictionary.cpp -------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "SwiftDictionary.h"

#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Target/Process.h"
#include "llvm/ADT/StringRef.h"

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

const DictionaryConfig &
DictionaryConfig::Get() {
  static DictionaryConfig g_config{};
  return g_config;
}

DictionaryConfig::DictionaryConfig()
  : HashedCollectionConfig() {
  m_summaryProviderName =
    ConstString("Swift.Dictionary summary provider");
  m_syntheticChildrenName =
    ConstString("Swift.Dictionary synthetic children");
  m_collection_demangledRegex =
    ConstString("^Swift\\.Dictionary<.+,.+>$");

  // Note: We need have use the old _Tt names here because those are
  // still used to name classes in the ObjC runtime.

  m_nativeStorageRoot_mangled =
    ConstString("$ss22__RawDictionaryStorageCD");
  m_nativeStorageRoot_demangled =
    ConstString("Swift.__RawDictionaryStorage");

  // Native storage class
  m_nativeStorage_mangledRegex_ObjC =
    ConstString("^_TtGCs18_DictionaryStorage.*");
  m_nativeStorage_demangledPrefix =
    ConstString("Swift._DictionaryStorage<");
  m_nativeStorage_demangledRegex =
    ConstString("^Swift\\._DictionaryStorage<.+,.+>$");

  // Type-punned empty dictionary
  m_emptyStorage_mangled_ObjC =
    ConstString("_TtCs26__EmptyDictionarySingleton");
  m_emptyStorage_demangled
    = ConstString("Swift.__EmptyDictionarySingleton");

  // Deferred non-verbatim bridged dictionary
  m_deferredBridgedStorage_mangledRegex_ObjC
    = ConstString("^_TtGCs26_SwiftDeferredNSDictionary.*");
  m_deferredBridgedStorage_demangledPrefix
    = ConstString("Swift._SwiftDeferredNSDictionary<");
  m_deferredBridgedStorage_demangledRegex
    = ConstString("^Swift\\._SwiftDeferredNSDictionary<.+,.+>$");
}

bool
DictionaryConfig::SummaryProvider(
  ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
  auto handler = DictionaryConfig::Get().CreateHandler(valobj);

  if (!handler)
    return false;

  auto count = handler->GetCount();

  stream.Printf("%zu key/value pair%s", count, (count == 1 ? "" : "s"));

  return true;
};

SyntheticChildrenFrontEnd *
DictionaryConfig::SyntheticChildrenCreator(
  CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
  if (!valobj_sp)
    return nullptr;
  return new HashedSyntheticChildrenFrontEnd(
    DictionaryConfig::Get(), valobj_sp);
}