UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMAccessor.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
7#include "CoreTypes.h"
8#include "HAL/Platform.h"
9#include "VVMContext.h"
12#include "VerseVM/VVMFunction.h"
14#include "VerseVM/VVMValue.h"
15
16namespace Verse
17{
18
19struct VAccessor : VCell
20{
23
24 static VAccessor& NewUninitialized(FAllocationContext Context, uint32 InNumAccessors)
25 {
27 return *new (Context.AllocateFastCell(Layout.TotalSize)) VAccessor(Context, InNumAccessors);
28 }
29
30 static void SerializeLayout(FAllocationContext Context, VAccessor*& This, FStructuredArchiveVisitor& Visitor);
31 COREUOBJECT_API void SerializeImpl(FAllocationContext Context, FStructuredArchiveVisitor& Visitor);
32
33 // `NumParams` -1 and -2 for getters and setters respectively to align them to trailing array positions
35 {
36 return (GetGettersBegin() + (NumParams - 1));
37 }
39 {
40 return (GetSettersBegin() + (NumParams - 2));
41 }
42 void AddGetter(FAllocationContext Context, uint32 NumParams, VUniqueString& Name)
43 {
44 FindGetter(NumParams)->Set(Context, Name);
45 }
46 void AddSetter(FAllocationContext Context, uint32 NumParams, VUniqueString& Name)
47 {
48 FindSetter(NumParams)->Set(Context, Name);
49 }
50
51private:
52 friend struct VAccessChain;
55
58
61
62 struct FLayout
63 {
66 int32 TotalSize;
67 };
68
69 static FLayout CalcLayout(uint32 NumAccessors)
70 {
73
74 FLayout Layout;
77 Layout.TotalSize = StructBuilder.GetSize();
78 return Layout;
79 }
80
81 FLayout GetLayout() const
82 {
84 }
85
86 VAccessor(FAllocationContext Context, uint32 InNumAccessors)
89 {
90 for (TWriteBarrier<VUniqueString>* Getter = GetGettersBegin(); Getter != GetGettersEnd(); ++Getter)
91 {
92 new (Getter) TWriteBarrier<VUniqueString>{};
93 }
94 for (TWriteBarrier<VUniqueString>* Setter = GetSettersBegin(); Setter != GetGettersEnd(); ++Setter)
95 {
96 new (Setter) TWriteBarrier<VUniqueString>{};
97 }
98 }
99};
100
102{
105
107
111
112 static VAccessChain& New(FAllocationContext Context, VAccessor* InAccessor, VValue InSelf)
113 {
114 FLayout Layout = CalcLayout(InAccessor->NumAccessors);
115 return *new (Context.AllocateFastCell(Layout.TotalSize)) VAccessChain(Context, InAccessor, InSelf);
116 }
117
118 static VAccessChain& New(FAllocationContext Context, VAccessChain& Other, VValue Value)
119 {
120 FLayout Layout = CalcLayout(Other.Accessor->NumAccessors);
121 return *new (Context.AllocateFastCell(Layout.TotalSize)) VAccessChain(Context, Other, Value);
122 }
123
125 {
127 }
128
129private:
131
132 void Add(FAllocationContext Context, VValue Value)
133 {
134 checkSlow(ChainNum + 1 <= MaxArgs());
136 ++ChainNum;
137 }
138
139 TWriteBarrier<VValue>* GetChainBegin() { return BitCast<TWriteBarrier<VValue>*>(BitCast<std::byte*>(this) + GetLayout().ChainOffset); }
141
142 struct FLayout
143 {
145 int32 TotalSize;
146 };
147
149 {
150 return Accessor->NumAccessors + 1;
151 }
152
153 static FLayout CalcLayout(uint32 NumAccessors)
154 {
157
158 FLayout Layout;
159 Layout.ChainOffset = StructBuilder.AddMember(sizeof(TWriteBarrier<VValue>) * NumAccessors + 1, alignof(TWriteBarrier<VValue>));
160 Layout.TotalSize = StructBuilder.GetSize();
161 return Layout;
162 }
163
164 FLayout GetLayout() const
165 {
166 return CalcLayout(Accessor->NumAccessors);
167 }
168
169 VAccessChain(FAllocationContext Context, VAccessor* InAccessor, VValue InSelf)
171 , ChainNum(0)
172 , Accessor(Context, InAccessor)
174 {
175 checkSlow(Accessor.Get() != nullptr);
176 for (TWriteBarrier<VValue>* Arg = GetChainBegin(); Arg != GetChainEnd(); ++Arg)
177 {
178 new (Arg) TWriteBarrier<VValue>{};
179 }
180 Add(Context, *AccessorEnum.Get());
181 }
182
183 VAccessChain(FAllocationContext Context, VAccessChain& Other, VValue Value)
184 : VAccessChain(Context, Other.Accessor.Get(), Other.Self.Get())
185 {
186 ChainNum = Other.ChainNum;
187 for (uint32 Index = 0; Index < ChainNum; ++Index)
188 {
189 (GetChainBegin() + Index)->Set(Context, (Other.GetChainBegin() + Index)->Get());
190 }
191 Add(Context, Value);
192 }
193};
194
195} // namespace Verse
196#endif // WITH_VERSE_VM
#define checkSlow(expr)
Definition AssertionMacros.h:332
return Self
Definition CocoaThread.cpp:337
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
Definition MemStack.h:259
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition StructBuilder.h:14
constexpr int32 AddMember(int32 MemberSize, int32 MemberAlignment)
Definition StructBuilder.h:30
Definition ArrayView.h:139
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
bool SerializeImpl(const UScriptStruct *InSourceEventType, const void *InSourceEventData, FLiveLinkSerializedFrameData &OutSerializedData)
Definition LiveLinkCompression.cpp:126
Definition Archive.h:36
U16 Index
Definition radfft.cpp:71