UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMObject.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#if WITH_VERSE_VM || defined(__INTELLISENSE__)
5
6#include "VerseVM/VVMCell.h"
7#include "VerseVM/VVMHeap.h"
9#include "VerseVM/VVMShape.h"
10
11namespace Verse
12{
13enum class EValueStringFormat;
14struct VUniqueString;
15
19struct VObject : VHeapValue
20{
22
23 FOpResult LoadField(FAllocationContext Context, const VUniqueString& Name, FLoadFieldCacheCase* OutCacheCase = nullptr);
24 FOpResult SetField(FAllocationContext Context, const VUniqueString& Name, VValue Value);
25
26 bool IsStruct() { return IsDeeplyMutable(); }
28
29 void VisitMembersImpl(FAllocationContext Context, FDebuggerVisitor& Visitor);
30
31 COREUOBJECT_API void AppendToStringImpl(FAllocationContext Context, FUtf8StringBuilderBase& Builder, EValueStringFormat Format, TSet<const void*>& VisitedObjects, uint32 RecursionDepth);
33
34 // `TBinaryFunction` should be invocable with `(declval<FUtf8StringView>(), declval<FOpResult>())`.
35 template <typename TBinaryFunction>
36 bool AllFields(FAllocationContext Context, TBinaryFunction);
37
38protected:
39 friend class FInterpreter;
40 friend struct VClass;
41 friend struct VNativeConstructorWrapper;
42
43 VObject(FAllocationContext Context, VEmergentType& InEmergentType);
44
45 static constexpr const size_t DataAlignment = VERSE_HEAP_MIN_ALIGN;
46
47 COREUOBJECT_API FOpResult LoadField(FAllocationContext Context, VEmergentType& EmergentType, const VShape::VEntry* Field, FLoadFieldCacheCase* OutCacheCase = nullptr);
48 static FOpResult SetField(FAllocationContext Context, const VShape& Shape, const VUniqueString& Name, void* Data, VValue Value);
49 static FOpResult SetField(FAllocationContext Context, const VShape::VEntry& Field, void* Data, VValue Value);
50
51 static size_t DataOffset(const VCppClassInfo& CppClassInfo);
52 /*
53 * Mutable variables store their data as a `VRestValue`.
54 * It's not an array of `VValue`s because you can potentially load a class member before actually defining it. i.e.
55 *
56 * ```
57 * c := class {x:int}
58 * C := c{}
59 * Foo(C.X) # allocates a placeholder
60 * C.X := 1 # This is the first time `c.X` actually gets defined.
61 * ```
62 *
63 * This stores the actual data for individual fields. Some constants and procedures are stored in the shape, not the
64 * object (since then there's no need to do an unnecessary index lookup).
65 *
66 * The mapping of offsets to each field are stored in the emergent type's "shape". The reason why the object
67 * doesn't just store the mapping of fields to data itself is that it will eventually help when we implement inline
68 * caches for retrieving fields on objects. It also helps reduce memory usage because multiple objects can share
69 * the same hash table that describes their layouts.
70 */
71 inline void* GetData(const VCppClassInfo& CppClassInfo) const;
72 inline VRestValue* GetFieldData(const VCppClassInfo& CppClassInfo) const;
73};
74
75inline VObject::VObject(FAllocationContext Context, VEmergentType& InEmergentType)
77{
78 // Leave initialization of the data to the subclasses
79}
80
81inline size_t VObject::DataOffset(const VCppClassInfo& CppClassInfo)
82{
83 return Align(CppClassInfo.SizeWithoutFields, DataAlignment);
84}
85
86inline void* VObject::GetData(const VCppClassInfo& CppClassInfo) const
87{
88 return BitCast<uint8*>(this) + DataOffset(CppClassInfo);
89}
90
91inline VRestValue* VObject::GetFieldData(const VCppClassInfo& CppClassInfo) const
92{
93 return BitCast<VRestValue*>(GetData(CppClassInfo));
94}
95} // namespace Verse
96#endif // WITH_VERSE_VM
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ IsStruct
Indicates the property is eligible for shared serialization.
auto GetData(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
Definition StringConv.h:802
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition JsonObject.h:23
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition StringBuilder.h:79
Definition FieldSystemNoiseAlgo.cpp:6
Definition Archive.h:36
EValueStringFormat
Definition VVMValuePrinting.h:17