From 9f8c55efe9689db71ff0813bf461aad6e436e673 Mon Sep 17 00:00:00 2001 From: Benjamin Moir Date: Mon, 8 Jan 2024 01:36:34 +1000 Subject: [PATCH] Support anonymous type names as seen in PS2 DWARF (#25) --- src/util/dwarf.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/util/dwarf.rs b/src/util/dwarf.rs index c99b18f..185e255 100644 --- a/src/util/dwarf.rs +++ b/src/util/dwarf.rs @@ -1043,7 +1043,9 @@ fn structure_type_string( include_anonymous_def: bool, ) -> Result { let prefix = if let Some(name) = t.name.as_ref() { - if include_keyword { + if name.starts_with('@') { + struct_def_string(info, typedefs, t)? + } else if include_keyword { match t.kind { StructureKind::Struct => format!("struct {}", name), StructureKind::Class => format!("class {}", name), @@ -1075,7 +1077,9 @@ fn enumeration_type_string( include_anonymous_def: bool, ) -> Result { let prefix = if let Some(name) = t.name.as_ref() { - if include_keyword { + if name.starts_with('@') { + enum_def_string(t)? + } else if include_keyword { format!("enum {}", name) } else { name.clone() @@ -1098,7 +1102,9 @@ fn union_type_string( include_anonymous_def: bool, ) -> Result { let prefix = if let Some(name) = t.name.as_ref() { - if include_keyword { + if name.starts_with('@') { + union_def_string(info, typedefs, t)? + } else if include_keyword { format!("union {}", name) } else { name.clone() @@ -1411,7 +1417,11 @@ pub fn struct_def_string( StructureKind::Class => "class".to_string(), }; if let Some(name) = t.name.as_ref() { - write!(out, " {}", name)?; + if name.starts_with('@') { + write!(out, " /* {} */", name)?; + } else { + write!(out, " {}", name)?; + } } let mut wrote_base = false; for base in &t.bases { @@ -1468,7 +1478,13 @@ pub fn struct_def_string( pub fn enum_def_string(t: &EnumerationType) -> Result { let mut out = match t.name.as_ref() { - Some(name) => format!("enum {} {{\n", name), + Some(name) => { + if name.starts_with('@') { + format!("enum /* {} */ {{\n", name) + } else { + format!("enum {} {{\n", name) + } + } None => "enum {\n".to_string(), }; for member in t.members.iter() { @@ -1480,7 +1496,13 @@ pub fn enum_def_string(t: &EnumerationType) -> Result { pub fn union_def_string(info: &DwarfInfo, typedefs: &TypedefMap, t: &UnionType) -> Result { let mut out = match t.name.as_ref() { - Some(name) => format!("union {} {{\n", name), + Some(name) => { + if name.starts_with('@') { + format!("union /* {} */ {{\n", name) + } else { + format!("union {} {{\n", name) + } + } None => "union {\n".to_string(), }; let mut var_out = String::new();