enum generation
This commit is contained in:
parent
b51164304f
commit
221ad25ff6
|
@ -4,8 +4,8 @@ use anyhow::Context;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
sdk::{
|
sdk::{
|
||||||
canonicalize_name, Class, ClassField, ClassMethod, PrimitiveType, ProcessedPackage, Sdk,
|
canonicalize_name, Class, ClassField, ClassMethod, Enum, PrimitiveType, ProcessedPackage,
|
||||||
Type, Types,
|
Sdk, Type, Types,
|
||||||
},
|
},
|
||||||
v2_types::traits::{AsUObject, UObjectNonConst, UStructNonConst},
|
v2_types::traits::{AsUObject, UObjectNonConst, UStructNonConst},
|
||||||
};
|
};
|
||||||
|
@ -127,6 +127,24 @@ impl RustType for Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn generate_enum<W: Write>(enm: &Enum, _sdk: &Sdk, w: &mut W) -> anyhow::Result<()> {
|
||||||
|
let Enum { name, values } = enm;
|
||||||
|
|
||||||
|
writeln!(w, "#[repr(C, u8)]")?;
|
||||||
|
writeln!(
|
||||||
|
w,
|
||||||
|
"#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]"
|
||||||
|
)?;
|
||||||
|
writeln!(w, "pub enum {name} {{")?;
|
||||||
|
|
||||||
|
for (i, value) in values.iter().enumerate() {
|
||||||
|
writeln!(w, "\t{value} = {i},")?;
|
||||||
|
}
|
||||||
|
writeln!(w, "}}")?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_class<W: Write>(class: &Class, _sdk: &Sdk, w: &mut W) -> anyhow::Result<()> {
|
pub fn generate_class<W: Write>(class: &Class, _sdk: &Sdk, w: &mut W) -> anyhow::Result<()> {
|
||||||
let Class {
|
let Class {
|
||||||
is_class,
|
is_class,
|
||||||
|
@ -296,7 +314,7 @@ pub fn generate_method<W: Write>(
|
||||||
for param in &method.parameters {
|
for param in &method.parameters {
|
||||||
match param {
|
match param {
|
||||||
crate::sdk::ParameterKind::Default(parm) => {
|
crate::sdk::ParameterKind::Default(parm) => {
|
||||||
write!(w, ",{}: &", parm.name)?;
|
write!(w, ",{}: ", parm.name)?;
|
||||||
parm.ty.rust_type(sdk, w)?;
|
parm.ty.rust_type(sdk, w)?;
|
||||||
}
|
}
|
||||||
crate::sdk::ParameterKind::Out(parm) => {
|
crate::sdk::ParameterKind::Out(parm) => {
|
||||||
|
@ -326,16 +344,21 @@ pub fn generate_method<W: Write>(
|
||||||
writeln!(w, "let mut params = {params_name}::zeroed();")?;
|
writeln!(w, "let mut params = {params_name}::zeroed();")?;
|
||||||
|
|
||||||
for param in &method.parameters {
|
for param in &method.parameters {
|
||||||
let param = param.as_param();
|
match param {
|
||||||
writeln!(w, "params.{0} = *{0};", param.name)?;
|
crate::sdk::ParameterKind::Default(_) | crate::sdk::ParameterKind::Out(_) => {
|
||||||
|
let param = param.as_param();
|
||||||
|
writeln!(w, "params.{0} = {0};", param.name)?;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(w, "let flags = *func.function_flags();")?;
|
writeln!(w, "let flags = *func.get_function_flags();")?;
|
||||||
writeln!(
|
writeln!(
|
||||||
w,
|
w,
|
||||||
"process_event(self.as_ptr() as *const _, func, &mut params);"
|
"process_event(self.as_ptr() as *const _, func, &mut params as *mut _);"
|
||||||
)?;
|
)?;
|
||||||
writeln!(w, "*func.function_flags_mut() = flags;")?;
|
writeln!(w, "*func.get_function_flags_mut() = flags;")?;
|
||||||
|
|
||||||
for param in &method.parameters {
|
for param in &method.parameters {
|
||||||
match param {
|
match param {
|
||||||
|
@ -393,6 +416,11 @@ pub fn generate_sdk_to_tmp(sdk: &Sdk) -> anyhow::Result<()> {
|
||||||
let file = std::fs::File::create("z:/tmp/ark_sdk/mod.rs")?;
|
let file = std::fs::File::create("z:/tmp/ark_sdk/mod.rs")?;
|
||||||
let mut writer = BufWriter::new(file);
|
let mut writer = BufWriter::new(file);
|
||||||
|
|
||||||
|
writeln!(writer, "use core::cell::UnsafeCell;")?;
|
||||||
|
writeln!(writer, "use core::ptr::NonNull;")?;
|
||||||
|
writeln!(writer, "use super::AsPtr;")?;
|
||||||
|
writeln!(writer, "use super::StaticClass;")?;
|
||||||
|
|
||||||
for (_, pkg) in &sdk.packages {
|
for (_, pkg) in &sdk.packages {
|
||||||
let pkg_name = canonicalize_name(
|
let pkg_name = canonicalize_name(
|
||||||
&pkg.package
|
&pkg.package
|
||||||
|
@ -426,11 +454,11 @@ pub fn generate_package_rust_module<W: Write>(
|
||||||
)
|
)
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
writeln!(w, "use core::ptr::NonNull;\nuse core::cell::UnsafeCell;\n")?;
|
writeln!(w, "use super::*")?;
|
||||||
for (pkg, _) in &pkg.package_dependencies {
|
for (pkg, _) in &pkg.package_dependencies {
|
||||||
writeln!(
|
writeln!(
|
||||||
w,
|
w,
|
||||||
"use super::{};",
|
"use {}::*;",
|
||||||
canonicalize_name(&pkg.get_full_name().context("could not get package name")?)
|
canonicalize_name(&pkg.get_full_name().context("could not get package name")?)
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
@ -441,7 +469,9 @@ pub fn generate_package_rust_module<W: Write>(
|
||||||
generate_class(&class, sdk, w)?;
|
generate_class(&class, sdk, w)?;
|
||||||
generate_class_impl(&class, sdk, w)?;
|
generate_class_impl(&class, sdk, w)?;
|
||||||
}
|
}
|
||||||
Types::Enum(_) => {}
|
Types::Enum(enm) => {
|
||||||
|
generate_enum(enm, sdk, w)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue