Skip to content

Commit

Permalink
Merge pull request #39 from ajfAfg/fix-issue-where-direction-of-depen…
Browse files Browse the repository at this point in the history
…dencies-to-be-extracted-was-reversed

fix issue where direction of dependencies to be extracted was reversed
  • Loading branch information
ajfAfg authored Feb 18, 2024
2 parents 0bb6e14 + 7e06e2e commit e3cdfcb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/core/dependency_extractor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extract(CModules) ->
G = extract_(CModules),
case map_size(G) =:= 0 of
true -> none;
false -> {some, G}
false -> {some, inverse_dependencies(G)}
end.

-spec extract_([cerl:c_module()]) -> #{behavior:name() => [behavior:name()]}.
Expand Down Expand Up @@ -130,3 +130,16 @@ extract_from_fun_body({c_values, _, _}, Acc) ->
extract_from_fun_body({c_var, _, _}, Acc) ->
Acc; % TODO: Support
extract_from_fun_body(_, Acc) -> Acc.

-spec inverse_dependencies(#{behavior:name() => [behavior:name()]}) ->
#{behavior:name() => [behavior:name()]}.
inverse_dependencies(Dependencies) ->
maps:fold(fun(Key, Value, NewDependencies) ->
lists:foldl(fun(E, Acc) -> maps:update_with(E, fun(List) -> [Key | List] end, Acc)
end,
NewDependencies,
Value)
end,
maps:from_keys(
maps:keys(Dependencies), []),
Dependencies).
6 changes: 3 additions & 3 deletions test/dependency_extractor_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ extract_dependencies_test_() ->
{inparallel,
[{"extract `gen_server` dependencies.",
?_assertEqual({some,
#{first_server => [second_server],
second_server => [third_server],
third_server => []}},
#{first_server => [],
second_server => [first_server],
third_server => [second_server]}},
dependency_extractor:extract([c_modules:first_server(),
c_modules:second_server(),
c_modules:third_server()]))},
Expand Down

0 comments on commit e3cdfcb

Please sign in to comment.