Skip to content

Commit

Permalink
Simplify and cleanup rebar_xref
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuncer Ayaz committed Jan 13, 2011
1 parent e4036cb commit 150c9d0
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/rebar_xref.erl
Expand Up @@ -121,7 +121,7 @@ filter_away_ignored(UnusedExports) ->
[{Mod, F, A} || {F, A} <- Ignore ++ lists:flatten(Callbacks)]
end,
AttrIgnore = lists:flatten(lists:map(F, lists:usort([M || {M, _, _} <- UnusedExports]))),
[X || X <- UnusedExports, not(lists:member(X, AttrIgnore))].
[X || X <- UnusedExports, not lists:member(X, AttrIgnore)].


kf(Key, List) ->
Expand All @@ -147,6 +147,7 @@ format_fa({_M, F, A}) ->

%%
%% Extract an element from a tuple, or undefined if N > tuple size
%%
safe_element(N, Tuple) ->
case catch(element(N, Tuple)) of
{'EXIT', {badarg, _}} ->
Expand All @@ -155,23 +156,6 @@ safe_element(N, Tuple) ->
Value
end.

%%
%% Extract the line number for a given function def
%%
abstract_code_function_line(Code, Name, Args) ->
[{function, Line, Name, _, _}] = [E || E <- Code,
safe_element(1, E) == function,
safe_element(3, E) == Name,
safe_element(4, E) == Args],
Line.

%%
%% Extract the original source filename from the abstract code
%%
abstract_code_source_file(Code) ->
[{attribute, 1, file, {Name, _}} | _] = Code,
Name.


%%
%% Given a MFA, find the file and LOC where it's defined. Note that
Expand All @@ -182,7 +166,11 @@ find_mfa_source({M, F, A}) ->
{M, Bin, _} = code:get_object_code(M),
{ok, {M, [{abstract_code, AbstractCode}]}} = beam_lib:chunks(Bin, [abstract_code]),
{raw_abstract_v1, Code} = AbstractCode,
Source = abstract_code_source_file(Code),
Line = abstract_code_function_line(Code, F, A),
%% Extract the original source filename from the abstract code
[{attribute, 1, file, {Source, _}} | _] = Code,
%% Extract the line number for a given function def
[{function, Line, F, _, _}] = [E || E <- Code,
safe_element(1, E) == function,
safe_element(3, E) == F,
safe_element(4, E) == A],
{Source, Line}.

0 comments on commit 150c9d0

Please sign in to comment.