Skip to content

Commit

Permalink
Remove usage of strum, fix various clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-Yom committed May 29, 2022
1 parent 6dc4add commit 1e350a7
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 97 deletions.
35 changes: 1 addition & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ members = ["hlbc-cli", "hlbc-derive"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
hlbc-derive = { version = "0.1", path = "hlbc-derive" }
hlbc-derive = { version = "0.2", path = "hlbc-derive" }
byteorder = "1"
anyhow = "1"
strum = "0.24"
strum_macros = "0.24"
petgraph = { version = "0.6", default-features = false, features = ["graphmap"], optional = true }

[features]
Expand Down
6 changes: 3 additions & 3 deletions hlbc-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ fn index_range(max: usize) -> impl Parser<char, IndexIter, Error = Simple<char>>
let a = a.unwrap_or(0).max(0);
let b = b.unwrap_or(max);
if range == ".." {
Box::new((a..b.min(max)).into_iter()) as IndexIter
Box::new(a..b.min(max)) as IndexIter
} else {
Box::new((a..=b.min(max - 1)).into_iter()) as IndexIter
Box::new(a..=b.min(max - 1)) as IndexIter
}
}),
num().map(|i| Box::new((i..(i + 1)).into_iter()) as IndexIter),
num().map(|i| Box::new(i..(i + 1)) as IndexIter),
))
.labelled("index range")
}
Expand Down
10 changes: 5 additions & 5 deletions hlbc-cli/src/decompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub fn decompile_class(code: &Bytecode, obj: &TypeObj) -> String {
writeln!(
&mut buf,
"class {} {}{{",
obj.name.display(&code),
obj.name.display(code),
if let Some(e) = obj.super_ {
is_static = e.0 == 12;
format!("extends {} ", e.display(&code))
format!("extends {} ", e.display(code))
} else {
"".to_string()
}
Expand All @@ -34,8 +34,8 @@ pub fn decompile_class(code: &Bytecode, obj: &TypeObj) -> String {
&mut buf,
"{indent}{}var {}: {}",
if is_static { "static " } else { "" },
f.name.display(&code),
f.t.display(&code)
f.name.display(code),
f.t.display(code)
)
.unwrap();
}
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn decompile_function_body(code: &Bytecode, indent: &str, f: &Function) -> S
write!(
&mut buf,
"{dst} = {}",
decompile_closure(code, &indent, fun.resolve_as_fn(code).unwrap())
decompile_closure(code, indent, fun.resolve_as_fn(code).unwrap())
)
.unwrap();
}
Expand Down
76 changes: 36 additions & 40 deletions hlbc-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
Command::Entrypoint => {
println!(
"{}",
code.functions[code.findexes.get(&code.entrypoint).unwrap().0]
.display_header(&code)
code.functions[code.findexes.get(&code.entrypoint).unwrap().0].display_header(code)
);
}
Command::Int(range) => {
Expand Down Expand Up @@ -194,31 +193,31 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
for i in range {
print_i!(i);
let t = &code.types[i];
println!("{}", t.display(&code));
println!("{}", t.display(code));
match t {
Type::Obj(obj) => {
if let Some(sup) = obj.super_ {
println!("extends {}", sup.display(&code));
println!("extends {}", sup.display(code));
}
println!("global: {}", obj.global.0);
println!("fields:");
for f in &obj.own_fields {
println!(" {}: {}", f.name.display(&code), f.t.display(&code));
println!(" {}: {}", f.name.display(code), f.t.display(code));
}
println!("protos:");
for p in &obj.protos {
println!(
" {}: {}",
p.name.display(&code),
p.findex.display_header(&code)
p.name.display(code),
p.findex.display_header(code)
);
}
println!("bindings:");
for (fi, fun) in &obj.bindings {
println!(
" {}: {}",
fi.display_obj(t, &code),
fun.display_header(&code)
fi.display_obj(t, code),
fun.display_header(code)
);
}
}
Expand All @@ -233,11 +232,11 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
if c.name.0 == 0 {
"_".to_string()
} else {
c.name.display(&code)
c.name.display(code)
}
);
for (i, p) in c.params.iter().enumerate() {
println!(" {i}: {}", p.display(&code));
println!(" {i}: {}", p.display(code));
}
}
}
Expand All @@ -248,13 +247,13 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
Command::Global(range) => {
for i in range {
print_i!(i);
println!("{}", code.globals[i].display(&code));
println!("{}", code.globals[i].display(code));
}
}
Command::Native(range) => {
for i in range {
print_i!(i);
println!("{}", code.natives[i].display_header(&code));
println!("{}", code.natives[i].display_header(code));
}
}
Command::Constant(range) => {
Expand All @@ -268,9 +267,9 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
print_i!(findex);
if let Some(&(i, fun)) = code.findexes.get(&RefFun(findex)) {
if fun {
println!("{}", code.functions[i].display_header(&code));
println!("{}", code.functions[i].display_header(code));
} else {
println!("{}", code.natives[i].display_header(&code));
println!("{}", code.natives[i].display_header(code));
}
} else {
println!("unknown");
Expand All @@ -282,9 +281,9 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
print_i!(findex);
if let Some(&(i, fun)) = code.findexes.get(&RefFun(findex)) {
if fun {
println!("{}", code.functions[i].display(&code));
println!("{}", code.functions[i].display(code));
} else {
println!("{}", code.natives[i].display_header(&code));
println!("{}", code.natives[i].display_header(code));
}
} else {
println!("unknown");
Expand All @@ -294,7 +293,7 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
Command::SearchFunction(str) => {
// TODO search for function
if let Some(&i) = code.fnames.get(&str) {
println!("{}", code.functions[i].display_header(&code));
println!("{}", code.functions[i].display_header(code));
} else {
println!("unknown");
}
Expand All @@ -305,7 +304,7 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
FileOrIndex::File(str) => {
if let Some(idx) =
debug_files
.into_iter()
.iter()
.enumerate()
.find_map(
|(i, d): (usize, &String)| {
Expand All @@ -321,7 +320,7 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
for (i, f) in code.functions.iter().enumerate() {
if f.debug_info.as_ref().unwrap()[f.ops.len() - 1].0 == idx {
print_i!(i);
println!("{}", f.display_header(&code));
println!("{}", f.display_header(code));
}
}
} else {
Expand All @@ -333,26 +332,26 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
for (i, f) in code.functions.iter().enumerate() {
if f.debug_info.as_ref().unwrap()[f.ops.len() - 1].0 == idx {
print_i!(i);
println!("{}", f.display_header(&code));
println!("{}", f.display_header(code));
}
}
}
}
}
Command::FileOf(idx) => {
let debug_files = require_debug_info!();
if let Some(p) = RefFun(idx).resolve(&code) {
if let Some(p) = RefFun(idx).resolve(code) {
match p {
RefFunPointee::Fun(f) => {
let idx = f.debug_info.as_ref().unwrap()[f.ops.len() - 1].0;
println!(
"{} is in file@{idx} : {}",
f.display_header(&code),
f.display_header(code),
&debug_files[idx]
);
}
RefFunPointee::Native(n) => {
println!("{} can't be in any file", n.display_header(&code))
println!("{} can't be in any file", n.display_header(code))
}
}
}
Expand All @@ -366,8 +365,8 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
{
use hlbc::analysis::graph::{call_graph, display_graph};

let graph = call_graph(&code, RefFun(idx), depth);
println!("{}", display_graph(&graph, &code));
let graph = call_graph(code, RefFun(idx), depth);
println!("{}", display_graph(&graph, code));
}

#[cfg(not(feature = "graph"))]
Expand All @@ -388,13 +387,10 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
"constant@{i} expanding to global@{} (now also searching for global)",
c.global.0
);
iter_ops(&code).for_each(|(f, (i, o))| match o {
iter_ops(code).for_each(|(f, (i, o))| match o {
Opcode::GetGlobal { global, .. } => {
if *global == c.global {
println!(
"in {} at {i}: GetGlobal",
f.display_header(&code)
);
println!("in {} at {i}: GetGlobal", f.display_header(code));
}
}
_ => {}
Expand All @@ -403,10 +399,10 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
}
}
}
iter_ops(&code).for_each(|(f, (i, o))| match o {
iter_ops(code).for_each(|(f, (i, o))| match o {
Opcode::String { ptr, .. } => {
if ptr.0 == idx {
println!("{} at {i}: String", f.display_header(&code));
println!("{} at {i}: String", f.display_header(code));
}
}
_ => {}
Expand All @@ -415,7 +411,7 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
ElementRef::Global(idx) => {
println!(
"Finding references to global@{idx} : {}\n",
code.globals[idx].display(&code)
code.globals[idx].display(code)
);
if let Some(constants) = &code.constants {
for (i, c) in constants.iter().enumerate() {
Expand All @@ -426,10 +422,10 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
}
println!();

iter_ops(&code).for_each(|(f, (i, o))| match o {
iter_ops(code).for_each(|(f, (i, o))| match o {
Opcode::GetGlobal { global, .. } | Opcode::SetGlobal { global, .. } => {
if global.0 == idx {
println!("{} at {i}: {}", f.display_header(&code), o.name());
println!("{} at {i}: {}", f.display_header(code), o.name());
}
}
_ => {}
Expand All @@ -438,14 +434,14 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
ElementRef::Fn(idx) => {
println!(
"Finding references to fn@{idx} : {}\n",
RefFun(idx).display_header(&code)
RefFun(idx).display_header(code)
);
code.functions
.iter()
.flat_map(|f| repeat(f).zip(find_fun_refs(f)))
.for_each(|(f, (i, o, fun))| {
if fun.0 == idx {
println!("{} at {i}: {}", f.display_header(&code), o.name());
println!("{} at {i}: {}", f.display_header(code), o.name());
}
});
}
Expand All @@ -454,8 +450,8 @@ callgraph <findex> <depth> | Create a dot call graph froma function and a max
let ty = &code.types[idx];
match ty {
Type::Obj(obj) => {
println!("Dumping type@{idx} : {}", ty.display(&code));
println!("{}", decompiler::decompile_class(&code, obj));
println!("Dumping type@{idx} : {}", ty.display(code));
println!("{}", decompiler::decompile_class(code, obj));
}
_ => println!("Type {idx} is not an obj"),
}
Expand Down
2 changes: 1 addition & 1 deletion hlbc-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hlbc-derive"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
license = "MIT"
description = "Procedural macros for the 'hlbc' crate"
Expand Down
Loading

0 comments on commit 1e350a7

Please sign in to comment.