I was interested in trying to collect a list of the __CALLER__
locations throughout a code base where a macro is used. I’ve been able to use :ets
to store the information while the macros are being expanded, but once compilation finishes that erlang VM shuts down and I lose the table. I’ve tried to use Module.put_attribute
, but whenever I call it elixir tells me the module in question is already compiled.
My goals are:
- build datastructure containing marco invocation information
- have that datastructure available at runtime in some form (define a function that returns it, put it in a module attribute, etc)
Right now I have the full datastructure in an :ets:
table at the end of macro expansion and can’t figure out how to save it. The module containing the macros is already defined and I can’t put a new attribute on it. Is there a way to call a macro in a module after all other macros are expanded (i.e. to create a function that returns the unquoted
copy of the data)?