Now offers a summary of the beam file and not the full thing - #2
Now offers a summary of the beam file and not the full thing#2gordonguthrie wants to merge 2 commits into
Conversation
See changes to the README for details
|
Hi @gordonguthrie this is cool, please bare with me, I'll get to it shortly |
| [] | ||
| end | ||
| defp format(behaviours, prefix) do | ||
| [h | t] = behaviours |
There was a problem hiding this comment.
Match in the function clause instead?
| This can be called as so: | ||
|
|
||
| ```elixir | ||
| Decompilerl.summarise('_build/dev/lib/myapp/ebin/Elixir.MyApp.AuthController.beam') |
There was a problem hiding this comment.
It's uncommon for elixir APIs to accept lists as "strings", since strings are binaries by default. What do you think?
| Decompilerl | ||
|
|
||
| usage: decompierl <beam_file> [-o <erl_file> | --output=<erl_file>] | ||
| usage: decompierl <beam_file> [-o <erl_file> | --output=<erl_file> | -s | --summary] |
There was a problem hiding this comment.
my bad, there's a typo there: decompierl
| end | ||
|
|
||
| defp format_summary(map) do | ||
| %{:file => file, |
There was a problem hiding this comment.
IMO it'd be more idiomatic to match (preferably in the function clause) like this:
%{file: file, module: module, ...}| format(behaviours, "Behaviours : "), | ||
| format(exports, "Exported Fns : "), | ||
| get_private_functions(functions, exports) | ||
| |>format("Private Fns : ") |
| lines = [ | ||
| "File : " <> file, | ||
| "Module : " <> module, | ||
| format(behaviours, "Behaviours : "), |
There was a problem hiding this comment.
Would you consider using String.pad_trailing/3 for all the formatting touch ups?
| get_private_functions(functions, exports) | ||
| |>format("Private Fns : ") | ||
| ] | ||
| Enum.join(List.flatten(lines), "\n") |
There was a problem hiding this comment.
There's no need to flatten, iolists are OK to write
| append_value(map, :behaviours, [Atom.to_string(behaviour)]) | ||
| end | ||
|
|
||
| defp process_ast({:function, _, func, arity, _body}, map) do |
There was a problem hiding this comment.
Perhaps glue the function clauses together, i.e. no white space in between?
| end | ||
|
|
||
| defp make_fn_declaration(func, arity) do | ||
| Atom.to_string(func) <> "/" <> Integer.to_string(arity) |
|
|
||
| defp append_value(map, key, valuelist) when is_list(valuelist) do | ||
| %{^key => values} = map | ||
| Map.put(map, key, values ++ valuelist) |
There was a problem hiding this comment.
You could avoid matching and pinning the key with:
Map.update(map, key, xs, &(xs ++ &1))
See changes to the README for details