MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / cpp_ty_init_fmt_impl

Function cpp_ty_init_fmt_impl

crates/codegen/src/unrealcpp.rs:6790–6843  ·  view source on GitHub ↗

For UPROPERTY() Unreal expects initialization values for certain types. UE5 strict mode requires all UPROPERTY fields to be explicitly initialized, otherwise the engine logs "property not initialized properly" errors. This includes primitives (bool defaults to true if not initialized to false), and enum types (must be initialized to a valid enum value).

(module_prefix: &str, module: &ModuleDef, ty: &AlgebraicTypeUse)

Source from the content-addressed store, hash-verified

6788// This includes primitives (bool defaults to true if not initialized to false),
6789// and enum types (must be initialized to a valid enum value).
6790fn cpp_ty_init_fmt_impl(module_prefix: &str, module: &ModuleDef, ty: &AlgebraicTypeUse) -> String {
6791 match ty {
6792 AlgebraicTypeUse::Primitive(p) => match p {
6793 PrimitiveType::Bool => " = false".to_string(),
6794 PrimitiveType::I8 => " = 0".to_string(),
6795 PrimitiveType::U8 => " = 0".to_string(),
6796 PrimitiveType::I16 => " = 0".to_string(),
6797 PrimitiveType::U16 => " = 0".to_string(),
6798 PrimitiveType::I32 => " = 0".to_string(),
6799 PrimitiveType::U32 => " = 0".to_string(),
6800 PrimitiveType::I64 => " = 0".to_string(),
6801 PrimitiveType::U64 => " = 0".to_string(),
6802 PrimitiveType::F32 => " = 0.0f".to_string(),
6803 PrimitiveType::F64 => " = 0.0".to_string(),
6804 PrimitiveType::I128 => String::new(),
6805 PrimitiveType::U128 => String::new(),
6806 PrimitiveType::I256 => String::new(),
6807 PrimitiveType::U256 => String::new(),
6808 },
6809 AlgebraicTypeUse::Array(_elem) => String::new(),
6810 AlgebraicTypeUse::String => String::new(),
6811 AlgebraicTypeUse::Identity => String::new(),
6812 AlgebraicTypeUse::ConnectionId => String::new(),
6813 AlgebraicTypeUse::Timestamp => String::new(),
6814 AlgebraicTypeUse::TimeDuration => String::new(),
6815 AlgebraicTypeUse::ScheduleAt => String::new(),
6816 AlgebraicTypeUse::Uuid => String::new(),
6817 AlgebraicTypeUse::Unit => String::new(),
6818 // --------- references to user-defined types ---------
6819 AlgebraicTypeUse::Ref(r) => {
6820 // Enum types must be initialized to a valid enum value in UE5.
6821 // Use the first variant as the default value.
6822 match &module.typespace_for_generate()[*r] {
6823 AlgebraicTypeDef::PlainEnum(plain_enum) => {
6824 let type_name = type_ref_name(module_prefix, module, *r);
6825 if let Some(first_variant) = plain_enum.variants.first() {
6826 let variant_name = first_variant.deref().to_case(Case::Pascal);
6827 format!(" = E{type_name}Type::{variant_name}")
6828 } else {
6829 String::new()
6830 }
6831 }
6832 // Product and Sum types have proper default constructors
6833 AlgebraicTypeDef::Product(_) => String::new(),
6834 AlgebraicTypeDef::Sum(_) => String::new(),
6835 }
6836 }
6837 // Options use the generated optional types
6838 AlgebraicTypeUse::Option(_inner) => String::new(),
6839 // Result use the generated result types
6840 AlgebraicTypeUse::Result { ok_ty: _, err_ty: _ } => String::new(),
6841 AlgebraicTypeUse::Never => unreachable!("never type"),
6842 }
6843}
6844
6845// Given an `AlgebraicTypeUse`, add every referenced type’s generated
6846// header name (`"<FTypeName>.g.h"`) into `out` (a `HashSet` avoids dups).

Callers 3

generate_reducer_fileMethod · 0.85
autogen_cpp_structFunction · 0.85

Calls 6

to_caseMethod · 0.80
type_ref_nameFunction · 0.70
newFunction · 0.50
to_stringMethod · 0.45
derefMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…