Support __vt, __RTTI, fallback for other builtins

This commit is contained in:
Luke Street 2022-09-03 12:58:01 -04:00
parent 64265e9efb
commit f858991236
1 changed files with 16 additions and 3 deletions

View File

@ -190,7 +190,7 @@ fn demangle_special_function(str: &str, class_name: &str) -> Option<String> {
Some(format!( Some(format!(
"{}{}", "{}{}",
match op { match op {
"dt" => return Some(format!("~{}", class_name)), "dt" => return Some(format!("~{}{}", class_name, args)),
"ct" => class_name, "ct" => class_name,
"nw" => "operator new", "nw" => "operator new",
"nwa" => "operator new[]", "nwa" => "operator new[]",
@ -234,7 +234,8 @@ fn demangle_special_function(str: &str, class_name: &str) -> Option<String> {
"rf" => "operator->", "rf" => "operator->",
"cl" => "operator()", "cl" => "operator()",
"vc" => "operator[]", "vc" => "operator[]",
_ => return None, "vt" => "__vtable",
_ => return Some(format!("__{}{}", op, args)),
}, },
args args
)) ))
@ -252,7 +253,7 @@ pub fn demangle(mut str: &str) -> Option<String> {
str = &str[2..]; str = &str[2..];
} }
{ {
let idx = str.find("__")?; let idx = str.rfind("__")?;
let (fn_name_out, rest) = str.split_at(idx); let (fn_name_out, rest) = str.split_at(idx);
if special { if special {
fn_name = fn_name_out.to_string(); fn_name = fn_name_out.to_string();
@ -494,5 +495,17 @@ mod tests {
demangle("__ct<12CStringTable>__31CObjOwnerDerivedFromIObjUntypedFRCQ24rstl24auto_ptr<12CStringTable>"), demangle("__ct<12CStringTable>__31CObjOwnerDerivedFromIObjUntypedFRCQ24rstl24auto_ptr<12CStringTable>"),
Some("CObjOwnerDerivedFromIObjUntyped::CObjOwnerDerivedFromIObjUntyped<CStringTable>(const rstl::auto_ptr<CStringTable>&)".to_string()) Some("CObjOwnerDerivedFromIObjUntyped::CObjOwnerDerivedFromIObjUntyped<CStringTable>(const rstl::auto_ptr<CStringTable>&)".to_string())
); );
assert_eq!(
demangle("__vt__40TObjOwnerDerivedFromIObj<12CStringTable>"),
Some("TObjOwnerDerivedFromIObj<CStringTable>::__vtable".to_string())
);
assert_eq!(
demangle("__RTTI__40TObjOwnerDerivedFromIObj<12CStringTable>"),
Some("TObjOwnerDerivedFromIObj<CStringTable>::__RTTI".to_string())
);
assert_eq!(
demangle("__init__mNull__Q24rstl66basic_string<c,Q24rstl14char_traits<c>,Q24rstl17rmemory_allocator>"),
Some("rstl::basic_string<char, rstl::char_traits<char>, rstl::rmemory_allocator>::__init__mNull".to_string())
);
} }
} }