I think there is no predefined function macro. But you can use
parse_transform/2 instead. Here is my try:
-module(cm_).
-export([parse_transform/2]).
parse_transform(ASTs, _Options) -> [parse_cm(T) || T <- ASTs].
parse_cm({function, _, FuncName, _, _} = T) ->
{FuncName, _} = erl_syntax_lib:analyze_function(T),
erl_syntax_lib:map(
fun(Node) ->
erl_syntax:revert(
case erl_syntax:is_atom(Node, cm_FUNC) of
true -> erl_syntax:atom(FuncName);
false -> Node
end
)
end, T);
parse_cm(T) -> T.
Then, you can use it like below using -compile directive:
-module(test).
-compile([export_all]).
-compile({parse_transform, cm_}).
macro_test() -> lists:foreach(fun(X) -> X end,
[ custom_macro1(), custom_macro2(), custom_macro3()] ).
custom_macro1() ->
io:format("Module:~p Function:~p~n", [?MODULE, cm_FUNC]).
custom_macro2() ->
io:format("Module:~p Function:~p~n", [?MODULE, cm_FUNC]).
custom_macro3() ->
io:format("Module:~p Function:~p~n", [?MODULE, cm_FUNC]).
I haven't tested it throughly, so it might not work in some cases.
--
Yoshi
> --
> Erlang Programming Website:
> http://www.erlangprogramming.org/