(
module_prefix: &str,
module: &ModuleDef,
name: &str,
sum_type: &SumTypeDef,
api_macro: &str,
module_name: &str,
)
| 6363 | } |
| 6364 | |
| 6365 | fn autogen_cpp_sum( |
| 6366 | module_prefix: &str, |
| 6367 | module: &ModuleDef, |
| 6368 | name: &str, |
| 6369 | sum_type: &SumTypeDef, |
| 6370 | api_macro: &str, |
| 6371 | module_name: &str, |
| 6372 | ) -> String { |
| 6373 | use convert_case::Case; |
| 6374 | |
| 6375 | /* ------------------------------------------------------------------ */ |
| 6376 | /* 1. gather #includes for every variant payload -------------------- */ |
| 6377 | /* ------------------------------------------------------------------ */ |
| 6378 | let mut includes = HashSet::<String>::new(); |
| 6379 | for (_, alg_ty) in &sum_type.variants { |
| 6380 | collect_includes_for_type(module_prefix, module, alg_ty, &mut includes, module_name); |
| 6381 | } |
| 6382 | |
| 6383 | includes.insert("Kismet/BlueprintFunctionLibrary.h".to_string()); |
| 6384 | |
| 6385 | let include_slices: Vec<&str> = includes.iter().map(|s| s.as_str()).collect(); |
| 6386 | |
| 6387 | // /* ------------------------------------------------------------------ */ |
| 6388 | // /* 2. emit boiler-plate + forward decls ----------------------------- */ |
| 6389 | // /* ------------------------------------------------------------------ */ |
| 6390 | let type_name = format!("{name}Type"); |
| 6391 | let mut output = UnrealCppAutogen::new(&include_slices, &type_name, false); |
| 6392 | |
| 6393 | /* ------------------------------------------------------------------ */ |
| 6394 | /* 3. generate the tag enum ----------------------------------------- */ |
| 6395 | /* ------------------------------------------------------------------ */ |
| 6396 | writeln!(output, "UENUM(BlueprintType)\nenum class E{name}Tag : uint8\n{{"); |
| 6397 | |
| 6398 | let mut variant_type = HashSet::<String>::new(); |
| 6399 | |
| 6400 | for (ix, (variant, _variant_type)) in sum_type.variants.iter().enumerate() { |
| 6401 | let comma = if ix + 1 == sum_type.variants.len() { "" } else { "," }; |
| 6402 | writeln!(output, " {}{}", variant.to_case(Case::Pascal), comma); |
| 6403 | |
| 6404 | let variant_cpp_type = cpp_ty_fmt_with_module(module_prefix, module, _variant_type, module_name).to_string(); |
| 6405 | variant_type.insert(variant_cpp_type); |
| 6406 | } |
| 6407 | writeln!(output, "}};\n"); |
| 6408 | |
| 6409 | /* ------------------------------------------------------------------ */ |
| 6410 | /* 4. generate the UStruct ----------------------------------- */ |
| 6411 | /* ------------------------------------------------------------------ */ |
| 6412 | |
| 6413 | writeln!(output, "USTRUCT(BlueprintType)\nstruct {api_macro} F{name}Type\n{{"); |
| 6414 | writeln!(output, " GENERATED_BODY()\n"); |
| 6415 | |
| 6416 | // default ctor |
| 6417 | writeln!(output, "public:\n F{name}Type() = default;\n"); |
| 6418 | |
| 6419 | // data + tag |
| 6420 | writeln!( |
| 6421 | output, |
| 6422 | " TVariant<{}> MessageData;", |
no test coverage detected
searching dependent graphs…