/src/serenity/Userland/Libraries/LibJS/Heap/ConservativeVector.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/HashMap.h> |
10 | | #include <AK/IntrusiveList.h> |
11 | | #include <AK/Vector.h> |
12 | | #include <LibJS/Forward.h> |
13 | | #include <LibJS/Heap/Cell.h> |
14 | | #include <LibJS/Heap/HeapRoot.h> |
15 | | |
16 | | namespace JS { |
17 | | |
18 | | class ConservativeVectorBase { |
19 | | public: |
20 | | virtual ReadonlySpan<FlatPtr> possible_values() const = 0; |
21 | | |
22 | | protected: |
23 | | explicit ConservativeVectorBase(Heap&); |
24 | | ~ConservativeVectorBase(); |
25 | | |
26 | | ConservativeVectorBase& operator=(ConservativeVectorBase const&); |
27 | | |
28 | | Heap* m_heap { nullptr }; |
29 | | IntrusiveListNode<ConservativeVectorBase> m_list_node; |
30 | | |
31 | | public: |
32 | | using List = IntrusiveList<&ConservativeVectorBase::m_list_node>; |
33 | | }; |
34 | | |
35 | | template<typename T, size_t inline_capacity> |
36 | | class ConservativeVector final |
37 | | : public ConservativeVectorBase |
38 | | , public Vector<T, inline_capacity> { |
39 | | |
40 | | public: |
41 | | explicit ConservativeVector(Heap& heap) |
42 | 0 | : ConservativeVectorBase(heap) |
43 | 0 | { |
44 | 0 | } Unexecuted instantiation: JS::ConservativeVector<JS::PrivateElement, 0ul>::ConservativeVector(JS::Heap&) Unexecuted instantiation: JS::ConservativeVector<JS::ClassFieldDefinition, 0ul>::ConservativeVector(JS::Heap&) Unexecuted instantiation: JS::ConservativeVector<AK::Variant<JS::ClassFieldDefinition, JS::NonnullGCPtr<JS::ECMAScriptFunctionObject> >, 0ul>::ConservativeVector(JS::Heap&) |
45 | | |
46 | 0 | ~ConservativeVector() = default; Unexecuted instantiation: JS::ConservativeVector<AK::Variant<JS::ClassFieldDefinition, JS::NonnullGCPtr<JS::ECMAScriptFunctionObject> >, 0ul>::~ConservativeVector() Unexecuted instantiation: JS::ConservativeVector<JS::ClassFieldDefinition, 0ul>::~ConservativeVector() Unexecuted instantiation: JS::ConservativeVector<JS::PrivateElement, 0ul>::~ConservativeVector() |
47 | | |
48 | | ConservativeVector(ConservativeVector const& other) |
49 | | : ConservativeVectorBase(*other.m_heap) |
50 | | , Vector<T, inline_capacity>(other) |
51 | | { |
52 | | } |
53 | | |
54 | | ConservativeVector(ConservativeVector&& other) |
55 | | : ConservativeVectorBase(*other.m_heap) |
56 | | , Vector<T, inline_capacity>(move(static_cast<Vector<T, inline_capacity>&>(other))) |
57 | | { |
58 | | } |
59 | | |
60 | | ConservativeVector& operator=(ConservativeVector const& other) |
61 | | { |
62 | | Vector<T, inline_capacity>::operator=(other); |
63 | | ConservativeVectorBase::operator=(other); |
64 | | return *this; |
65 | | } |
66 | | |
67 | | virtual ReadonlySpan<FlatPtr> possible_values() const override |
68 | 0 | { |
69 | 0 | static_assert(sizeof(T) >= sizeof(FlatPtr)); |
70 | 0 | return ReadonlySpan<FlatPtr> { |
71 | 0 | reinterpret_cast<FlatPtr const*>(this->data()), |
72 | 0 | this->size() * sizeof(T) / sizeof(FlatPtr), |
73 | 0 | }; |
74 | 0 | } Unexecuted instantiation: JS::ConservativeVector<JS::PrivateElement, 0ul>::possible_values() const Unexecuted instantiation: JS::ConservativeVector<JS::ClassFieldDefinition, 0ul>::possible_values() const Unexecuted instantiation: JS::ConservativeVector<AK::Variant<JS::ClassFieldDefinition, JS::NonnullGCPtr<JS::ECMAScriptFunctionObject> >, 0ul>::possible_values() const |
75 | | }; |
76 | | |
77 | | } |