Support anonymous type names as seen in PS2 DWARF (#25)

This commit is contained in:
Benjamin Moir 2024-01-08 01:36:34 +10:00 committed by GitHub
parent 6b59c677d4
commit 9f8c55efe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 6 deletions

View File

@ -1043,7 +1043,9 @@ fn structure_type_string(
include_anonymous_def: bool, include_anonymous_def: bool,
) -> Result<TypeString> { ) -> Result<TypeString> {
let prefix = if let Some(name) = t.name.as_ref() { 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 { match t.kind {
StructureKind::Struct => format!("struct {}", name), StructureKind::Struct => format!("struct {}", name),
StructureKind::Class => format!("class {}", name), StructureKind::Class => format!("class {}", name),
@ -1075,7 +1077,9 @@ fn enumeration_type_string(
include_anonymous_def: bool, include_anonymous_def: bool,
) -> Result<TypeString> { ) -> Result<TypeString> {
let prefix = if let Some(name) = t.name.as_ref() { 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) format!("enum {}", name)
} else { } else {
name.clone() name.clone()
@ -1098,7 +1102,9 @@ fn union_type_string(
include_anonymous_def: bool, include_anonymous_def: bool,
) -> Result<TypeString> { ) -> Result<TypeString> {
let prefix = if let Some(name) = t.name.as_ref() { 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) format!("union {}", name)
} else { } else {
name.clone() name.clone()
@ -1411,8 +1417,12 @@ pub fn struct_def_string(
StructureKind::Class => "class".to_string(), StructureKind::Class => "class".to_string(),
}; };
if let Some(name) = t.name.as_ref() { if let Some(name) = t.name.as_ref() {
if name.starts_with('@') {
write!(out, " /* {} */", name)?;
} else {
write!(out, " {}", name)?; write!(out, " {}", name)?;
} }
}
let mut wrote_base = false; let mut wrote_base = false;
for base in &t.bases { for base in &t.bases {
if !wrote_base { if !wrote_base {
@ -1468,7 +1478,13 @@ pub fn struct_def_string(
pub fn enum_def_string(t: &EnumerationType) -> Result<String> { pub fn enum_def_string(t: &EnumerationType) -> Result<String> {
let mut out = match t.name.as_ref() { 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(), None => "enum {\n".to_string(),
}; };
for member in t.members.iter() { for member in t.members.iter() {
@ -1480,7 +1496,13 @@ pub fn enum_def_string(t: &EnumerationType) -> Result<String> {
pub fn union_def_string(info: &DwarfInfo, typedefs: &TypedefMap, t: &UnionType) -> Result<String> { pub fn union_def_string(info: &DwarfInfo, typedefs: &TypedefMap, t: &UnionType) -> Result<String> {
let mut out = match t.name.as_ref() { 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(), None => "union {\n".to_string(),
}; };
let mut var_out = String::new(); let mut var_out = String::new();