Skip to content

Commit

Permalink
Export rules automatically, it doesn't make sense not to.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurii Rashkovskii committed Feb 4, 2012
1 parent 7a43f3e commit 90561c9
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion apps/htoad/src/htoad_deps.erl
Expand Up @@ -3,7 +3,6 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").

-export([init/2,on/3,on_match/3]).
-rules([init,on,on_match]).

init(Engine, #init{}) ->
Expand Down
1 change: 0 additions & 1 deletion apps/htoad/src/htoad_host.erl
Expand Up @@ -5,7 +5,6 @@

-neg_rule({init, [{htoad_argument, {host, '__IGNORE_UNDERSCORE__'}}]}).

-export([init/2, init_with_hostname_overriden/3, linux/2]).
-rules([init, init_with_hostname_overriden, linux]).

init_with_hostname_overriden(Engine, #init{}, {htoad_argument, {host, Hostname}}) ->
Expand Down
2 changes: 1 addition & 1 deletion apps/htoad/src/htoad_htoad.erl
@@ -1,8 +1,8 @@
-module(htoad_htoad).
-include_lib("htoad/include/htoad.hrl").
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").

-export([init/2]).
-rules([init]).

init(Engine, #init{}) ->
Expand Down
1 change: 0 additions & 1 deletion apps/htoad/src/htoad_io.erl
Expand Up @@ -3,7 +3,6 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").

-export([init/2, print/2]).
-rules([init, print]).

init(Engine, #init{}) ->
Expand Down
3 changes: 0 additions & 3 deletions apps/htoad/src/htoad_lfs.erl
Expand Up @@ -5,9 +5,6 @@

-include_lib("kernel/include/file.hrl").

-export([init/2, ensure_file_present/2,
ensure_dir_present/2]).
-export([fs_file_present/2, fs_file_absent/2, fs_dir_present/2, fs_dir_absent/2]).
-rules([init, ensure_file_present, ensure_dir_present,
fs_file_present, fs_file_absent, fs_dir_present, fs_dir_absent]).

Expand Down
3 changes: 1 addition & 2 deletions apps/htoad/src/htoad_pkg.erl
Expand Up @@ -3,8 +3,7 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").

-export([ensure_package/3,
package_not_present/3, package_present/2]).
-export([ensure_package/3, package_not_present/3]).
-export([format_package/1]).

-rules([package_present]).
Expand Down
1 change: 0 additions & 1 deletion apps/htoad/src/htoad_pkg_apt.erl
Expand Up @@ -3,7 +3,6 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").

-export([init/4, ensure_package/3, package_not_present/3]).
-rules([init, ensure_package, package_not_present]).

init(Engine, #init{}, {operating_system_name, linux}, {linux_distribution, "Ubuntu"}) ->
Expand Down
1 change: 0 additions & 1 deletion apps/htoad/src/htoad_pkg_brew.erl
Expand Up @@ -3,7 +3,6 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").

-export([init/3, ensure_package/3, package_not_present/3]).
-rules([init, ensure_package, package_not_present]).

init(Engine, #init{}, {operating_system_name, darwin}) ->
Expand Down
1 change: 0 additions & 1 deletion apps/htoad/src/htoad_shell.erl
Expand Up @@ -3,7 +3,6 @@
-include_lib("htoad/include/toadie.hrl").
-include_lib("htoad/include/stdlib.hrl").

-export([init/3, command/2]).
-rules([init, command]).

init(Engine, #init{}, {operating_system_type, unix}) ->
Expand Down
13 changes: 10 additions & 3 deletions apps/htoad/src/htoad_transform.erl
Expand Up @@ -4,8 +4,10 @@

-record(state,{
rules = [],
rule_functions = [],
current_function = [], %% [] :: atom()
file_requests = [],
exports = [],
options,
absname
}).
Expand All @@ -14,7 +16,10 @@ parse_transform(Forms, Options) ->
{Forms1, State} = parse_trans:transform(fun do_transform/4,
#state{ options = Options },
Forms, Options),
Result = parse_trans:revert(Forms1),
Result0 = parse_trans:revert(Forms1),
Result = lists:foldl(fun ({Fun, Arity}, Acc) ->
parse_trans:export_function(Fun, Arity, Acc)
end, Result0, State#state.rule_functions),
parse_trans:do_insert_forms(above, [{attribute, 0, htoad_file_requests, State#state.file_requests}], Result, parse_trans:initial_context(Result, Options)).

transform(Fun, State, Form, Context) when is_tuple(Form) ->
Expand All @@ -29,18 +34,20 @@ transform(Fun, State, Forms, Context) when is_list(Forms) ->
{parse_trans:revert(Form1),false,State1}.


do_transform(attribute,{attribute, _, export, Exports} = Attr, _Context, #state{} = State) ->
{Attr, true, State#state{ exports = State#state.exports ++ Exports }};
do_transform(attribute,{attribute, _, rules, Rules} = Attr, _Context, #state{} = State) ->
{Attr, false, State#state{ rules = Rules }};

do_transform(attribute,{attribute, _, htoad_absname, AbsName} = Attr, _Context, #state{} = State) ->
{Attr, false, State#state{ absname = AbsName }};

do_transform(function, {function, _, Fun, _Arity, _Cs} = Form, _Context, #state{ rules = Rules } = State) ->
do_transform(function, {function, _, Fun, Arity, _Cs} = Form, _Context, #state{ rules = Rules, rule_functions = RFuns } = State) ->
case lists:member(Fun, Rules) of
false ->
{Form, true, State#state{ current_function = [] }};
true ->
{Form, true, State#state{ current_function = Fun }}
{Form, true, State#state{ current_function = Fun, rule_functions = [{Fun, Arity}|RFuns] -- State#state.exports }}
end;

do_transform(clause, {clause, Line, Head, G, B}, Context,
Expand Down

0 comments on commit 90561c9

Please sign in to comment.