unreal type stores object ref to object, and wrapper for accessing dependencies

This commit is contained in:
Janis 2023-06-19 16:11:58 +02:00
parent 74940c5696
commit e74ed77703

View file

@ -69,6 +69,26 @@ pub enum UnrealType {
Enum(Enum),
}
impl UnrealType {
pub fn obj_ref(&self) -> ObjectRef {
match self {
UnrealType::Class(obj) => obj.obj_ref,
UnrealType::Struct(obj) => obj.obj_ref,
UnrealType::Actor(obj) => obj.obj_ref,
UnrealType::Enum(obj) => obj.obj_ref,
}
}
pub fn get_dependent_types(&self) -> Vec<ObjectRef> {
match self {
UnrealType::Class(obj) | UnrealType::Struct(obj) | UnrealType::Actor(obj) => {
obj.get_dependent_types()
}
UnrealType::Enum(_) => vec![],
}
}
}
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum StructKind {
Object,
@ -78,6 +98,7 @@ pub enum StructKind {
#[derive(Debug, Serialize, Deserialize)]
pub struct Enum {
pub obj_ref: ObjectRef,
pub name: String,
pub full_name: String,
pub values: BTreeMap<u32, String>,
@ -85,6 +106,7 @@ pub struct Enum {
#[derive(Debug, Serialize, Deserialize)]
pub struct Class {
pub obj_ref: ObjectRef,
pub kind: StructKind,
pub size: u32,
pub name: String,
@ -94,9 +116,6 @@ pub struct Class {
pub min_alignment: u32,
pub fields: Vec<ClassField>,
pub methods: Vec<ClassMethod>,
/// types this class depends on; includes super types, types of fields and
/// types of function parameters.
pub dependencies: Vec<ObjectRef>,
}
#[derive(Debug, Serialize, Deserialize)]
@ -209,3 +228,19 @@ pub enum Type {
Class(ObjectRef),
Struct(ObjectRef),
}
impl Type {
pub fn dependent_type(&self) -> Option<ObjectRef> {
match self {
Type::Ptr(ty) | Type::Ref(ty) | Type::Array(ty) | Type::RawArray { ty, .. } => {
ty.dependent_type()
}
Type::WeakPtr(ty) | Type::SoftPtr(ty) | Type::LazyPtr(ty) | Type::AssetPtr(ty) => {
Some(*ty)
}
Type::Enum { underlying, .. } => underlying.dependent_type(),
Type::Class(ty) | Type::Struct(ty) => Some(*ty),
_ => None,
}
}
}