/home/arjun/llvm-project/llvm/include/llvm/ADT/StringMapEntry.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- StringMapEntry.h - String Hash table map interface -------*- 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 | | // This file defines the StringMapEntry class - it is intended to be a low |
10 | | // dependency implementation detail of StringMap that is more suitable for |
11 | | // inclusion in public headers than StringMap.h itself is. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_ADT_STRINGMAPENTRY_H |
16 | | #define LLVM_ADT_STRINGMAPENTRY_H |
17 | | |
18 | | #include "llvm/ADT/StringRef.h" |
19 | | |
20 | | namespace llvm { |
21 | | |
22 | | /// StringMapEntryBase - Shared base class of StringMapEntry instances. |
23 | | class StringMapEntryBase { |
24 | | size_t keyLength; |
25 | | |
26 | | public: |
27 | 40 | explicit StringMapEntryBase(size_t keyLength) : keyLength(keyLength) {} |
28 | | |
29 | 0 | size_t getKeyLength() const { return keyLength; } |
30 | | }; |
31 | | |
32 | | /// StringMapEntryStorage - Holds the value in a StringMapEntry. |
33 | | /// |
34 | | /// Factored out into a separate base class to make it easier to specialize. |
35 | | /// This is primarily intended to support StringSet, which doesn't need a value |
36 | | /// stored at all. |
37 | | template <typename ValueTy> |
38 | | class StringMapEntryStorage : public StringMapEntryBase { |
39 | | public: |
40 | | ValueTy second; |
41 | | |
42 | | explicit StringMapEntryStorage(size_t keyLength) |
43 | 0 | : StringMapEntryBase(keyLength), second() {} Unexecuted instantiation: _ZN4llvm21StringMapEntryStorageIbEC2Em Unexecuted instantiation: _ZN4llvm21StringMapEntryStorageIjEC2Em Unexecuted instantiation: _ZN4llvm21StringMapEntryStorageINS_11SmallVectorIN4mlir6detail12ExpectedDiagELj2EEEEC2Em |
44 | | template <typename... InitTy> |
45 | | StringMapEntryStorage(size_t keyLength, InitTy &&... initVals) |
46 | | : StringMapEntryBase(keyLength), |
47 | 40 | second(std::forward<InitTy>(initVals)...) {} _ZN4llvm21StringMapEntryStorageIPNS_2cl6OptionEEC2IJS3_EEEmDpOT_ Line | Count | Source | 47 | 40 | second(std::forward<InitTy>(initVals)...) {} |
Unexecuted instantiation: _ZN4llvm21StringMapEntryStorageISt10unique_ptrINS_3vfs6detail12InMemoryNodeESt14default_deleteIS4_EEEC2IJS7_EEEmDpOT_ Unexecuted instantiation: _ZN4llvm21StringMapEntryStorageIN4mlir17AbstractOperationEEC2IJS2_EEEmDpOT_ Unexecuted instantiation: _ZN4llvm21StringMapEntryStorageIPN4mlir9OperationEEC2IJS3_EEEmDpOT_ |
48 | | StringMapEntryStorage(StringMapEntryStorage &e) = delete; |
49 | | |
50 | 0 | const ValueTy &getValue() const { return second; } |
51 | 0 | ValueTy &getValue() { return second; } |
52 | | |
53 | | void setValue(const ValueTy &V) { second = V; } |
54 | | }; |
55 | | |
56 | | template <> class StringMapEntryStorage<NoneType> : public StringMapEntryBase { |
57 | | public: |
58 | | explicit StringMapEntryStorage(size_t keyLength, NoneType none = None) |
59 | 0 | : StringMapEntryBase(keyLength) {} |
60 | | StringMapEntryStorage(StringMapEntryStorage &entry) = delete; |
61 | | |
62 | 0 | NoneType getValue() const { return None; } |
63 | | }; |
64 | | |
65 | | /// StringMapEntry - This is used to represent one value that is inserted into |
66 | | /// a StringMap. It contains the Value itself and the key: the string length |
67 | | /// and data. |
68 | | template <typename ValueTy> |
69 | | class StringMapEntry final : public StringMapEntryStorage<ValueTy> { |
70 | | public: |
71 | | using StringMapEntryStorage<ValueTy>::StringMapEntryStorage; |
72 | | |
73 | 0 | StringRef getKey() const { |
74 | 0 | return StringRef(getKeyData(), this->getKeyLength()); |
75 | 0 | } |
76 | | |
77 | | /// getKeyData - Return the start of the string data that is the key for this |
78 | | /// value. The string data is always stored immediately after the |
79 | | /// StringMapEntry object. |
80 | 40 | const char *getKeyData() const { |
81 | 40 | return reinterpret_cast<const char *>(this + 1); |
82 | 40 | } Unexecuted instantiation: _ZNK4llvm14StringMapEntryINS_8NoneTypeEE10getKeyDataEv _ZNK4llvm14StringMapEntryIPNS_2cl6OptionEE10getKeyDataEv Line | Count | Source | 80 | 40 | const char *getKeyData() const { | 81 | 40 | return reinterpret_cast<const char *>(this + 1); | 82 | 40 | } |
Unexecuted instantiation: _ZNK4llvm14StringMapEntryISt10unique_ptrINS_3vfs6detail12InMemoryNodeESt14default_deleteIS4_EEE10getKeyDataEv Unexecuted instantiation: _ZNK4llvm14StringMapEntryIbE10getKeyDataEv Unexecuted instantiation: _ZNK4llvm14StringMapEntryIjE10getKeyDataEv Unexecuted instantiation: _ZNK4llvm14StringMapEntryINS_11SmallVectorIN4mlir6detail12ExpectedDiagELj2EEEE10getKeyDataEv Unexecuted instantiation: _ZNK4llvm14StringMapEntryIN4mlir17AbstractOperationEE10getKeyDataEv Unexecuted instantiation: _ZNK4llvm14StringMapEntryIPN4mlir9OperationEE10getKeyDataEv |
83 | | |
84 | 0 | StringRef first() const { |
85 | 0 | return StringRef(getKeyData(), this->getKeyLength()); |
86 | 0 | } Unexecuted instantiation: _ZNK4llvm14StringMapEntryINS_8NoneTypeEE5firstEv Unexecuted instantiation: _ZNK4llvm14StringMapEntryIPNS_2cl6OptionEE5firstEv Unexecuted instantiation: _ZNK4llvm14StringMapEntryIN4mlir17AbstractOperationEE5firstEv |
87 | | |
88 | | /// Create a StringMapEntry for the specified key construct the value using |
89 | | /// \p InitiVals. |
90 | | template <typename AllocatorTy, typename... InitTy> |
91 | | static StringMapEntry *Create(StringRef key, AllocatorTy &allocator, |
92 | 40 | InitTy &&... initVals) { |
93 | 40 | size_t keyLength = key.size(); |
94 | 40 | |
95 | 40 | // Allocate a new item with space for the string at the end and a null |
96 | 40 | // terminator. |
97 | 40 | size_t allocSize = sizeof(StringMapEntry) + keyLength + 1; |
98 | 40 | size_t alignment = alignof(StringMapEntry); |
99 | 40 | |
100 | 40 | StringMapEntry *newItem = |
101 | 40 | static_cast<StringMapEntry *>(allocator.Allocate(allocSize, alignment)); |
102 | 40 | assert(newItem && "Unhandled out-of-memory"); |
103 | 40 | |
104 | 40 | // Construct the value. |
105 | 40 | new (newItem) StringMapEntry(keyLength, std::forward<InitTy>(initVals)...); |
106 | 40 | |
107 | 40 | // Copy the string information. |
108 | 40 | char *strBuffer = const_cast<char *>(newItem->getKeyData()); |
109 | 40 | if (keyLength > 0) |
110 | 40 | memcpy(strBuffer, key.data(), keyLength); |
111 | 40 | strBuffer[keyLength] = 0; // Null terminate for convenience of clients. |
112 | 40 | return newItem; |
113 | 40 | } _ZN4llvm14StringMapEntryIPNS_2cl6OptionEE6CreateINS_15MallocAllocatorEJS3_EEEPS4_NS_9StringRefERT_DpOT0_ Line | Count | Source | 92 | 40 | InitTy &&... initVals) { | 93 | 40 | size_t keyLength = key.size(); | 94 | 40 | | 95 | 40 | // Allocate a new item with space for the string at the end and a null | 96 | 40 | // terminator. | 97 | 40 | size_t allocSize = sizeof(StringMapEntry) + keyLength + 1; | 98 | 40 | size_t alignment = alignof(StringMapEntry); | 99 | 40 | | 100 | 40 | StringMapEntry *newItem = | 101 | 40 | static_cast<StringMapEntry *>(allocator.Allocate(allocSize, alignment)); | 102 | 40 | assert(newItem && "Unhandled out-of-memory"); | 103 | 40 | | 104 | 40 | // Construct the value. | 105 | 40 | new (newItem) StringMapEntry(keyLength, std::forward<InitTy>(initVals)...); | 106 | 40 | | 107 | 40 | // Copy the string information. | 108 | 40 | char *strBuffer = const_cast<char *>(newItem->getKeyData()); | 109 | 40 | if (keyLength > 0) | 110 | 40 | memcpy(strBuffer, key.data(), keyLength); | 111 | 40 | strBuffer[keyLength] = 0; // Null terminate for convenience of clients. | 112 | 40 | return newItem; | 113 | 40 | } |
Unexecuted instantiation: _ZN4llvm14StringMapEntryISt10unique_ptrINS_3vfs6detail12InMemoryNodeESt14default_deleteIS4_EEE6CreateINS_15MallocAllocatorEJS7_EEEPS8_NS_9StringRefERT_DpOT0_ Unexecuted instantiation: _ZN4llvm14StringMapEntryINS_8NoneTypeEE6CreateINS_15MallocAllocatorEJEEEPS2_NS_9StringRefERT_DpOT0_ Unexecuted instantiation: _ZN4llvm14StringMapEntryIbE6CreateINS_15MallocAllocatorEJEEEPS1_NS_9StringRefERT_DpOT0_ Unexecuted instantiation: _ZN4llvm14StringMapEntryIjE6CreateINS_15MallocAllocatorEJEEEPS1_NS_9StringRefERT_DpOT0_ Unexecuted instantiation: _ZN4llvm14StringMapEntryINS_11SmallVectorIN4mlir6detail12ExpectedDiagELj2EEEE6CreateINS_15MallocAllocatorEJEEEPS6_NS_9StringRefERT_DpOT0_ Unexecuted instantiation: _ZN4llvm14StringMapEntryIN4mlir17AbstractOperationEE6CreateINS_15MallocAllocatorEJS2_EEEPS3_NS_9StringRefERT_DpOT0_ Unexecuted instantiation: _ZN4llvm14StringMapEntryINS_8NoneTypeEE6CreateINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEJEEEPS2_NS_9StringRefERT_DpOT0_ Unexecuted instantiation: _ZN4llvm14StringMapEntryIPN4mlir9OperationEE6CreateINS_15MallocAllocatorEJS3_EEEPS4_NS_9StringRefERT_DpOT0_ |
114 | | |
115 | | /// GetStringMapEntryFromKeyData - Given key data that is known to be embedded |
116 | | /// into a StringMapEntry, return the StringMapEntry itself. |
117 | | static StringMapEntry &GetStringMapEntryFromKeyData(const char *keyData) { |
118 | | char *ptr = const_cast<char *>(keyData) - sizeof(StringMapEntry<ValueTy>); |
119 | | return *reinterpret_cast<StringMapEntry *>(ptr); |
120 | | } |
121 | | |
122 | | /// Destroy - Destroy this StringMapEntry, releasing memory back to the |
123 | | /// specified allocator. |
124 | 0 | template <typename AllocatorTy> void Destroy(AllocatorTy &allocator) { |
125 | 0 | // Free memory referenced by the item. |
126 | 0 | size_t AllocSize = sizeof(StringMapEntry) + this->getKeyLength() + 1; |
127 | 0 | this->~StringMapEntry(); |
128 | 0 | allocator.Deallocate(static_cast<void *>(this), AllocSize, |
129 | 0 | alignof(StringMapEntry)); |
130 | 0 | } Unexecuted instantiation: _ZN4llvm14StringMapEntryIPNS_2cl6OptionEE7DestroyINS_15MallocAllocatorEEEvRT_ Unexecuted instantiation: _ZN4llvm14StringMapEntryISt10unique_ptrINS_3vfs6detail12InMemoryNodeESt14default_deleteIS4_EEE7DestroyINS_15MallocAllocatorEEEvRT_ Unexecuted instantiation: _ZN4llvm14StringMapEntryINS_8NoneTypeEE7DestroyINS_15MallocAllocatorEEEvRT_ Unexecuted instantiation: _ZN4llvm14StringMapEntryIjE7DestroyINS_15MallocAllocatorEEEvRT_ Unexecuted instantiation: _ZN4llvm14StringMapEntryINS_11SmallVectorIN4mlir6detail12ExpectedDiagELj2EEEE7DestroyINS_15MallocAllocatorEEEvRT_ Unexecuted instantiation: _ZN4llvm14StringMapEntryINS_8NoneTypeEE7DestroyINS_20BumpPtrAllocatorImplINS_15MallocAllocatorELm4096ELm4096ELm128EEEEEvRT_ Unexecuted instantiation: _ZN4llvm14StringMapEntryIN4mlir17AbstractOperationEE7DestroyINS_15MallocAllocatorEEEvRT_ Unexecuted instantiation: _ZN4llvm14StringMapEntryIPN4mlir9OperationEE7DestroyINS_15MallocAllocatorEEEvRT_ |
131 | | }; |
132 | | |
133 | | } // end namespace llvm |
134 | | |
135 | | #endif // LLVM_ADT_STRINGMAPENTRY_H |