Erlang Refactoring

Thomas Lindgren <>
Wed Jun 21 13:35:41 CEST 2006



--- "Joe Armstrong (AL/EAB)"
<> wrote:

> I want some program that changes all the filenames
> and
> module names in a consistent manner, and which tries
> to keep the formatting of my programs intact.
> 
> Is there such a program? - << in the form of a
> function I
> evaluate in the Erlang shell - ie with no
> incomprehensible GUI >>

Not that I know. Maybe you could do a partial solution
with Richard C.'s syntax_tools, which I think can do
transformations while preserve formatting. However,
for full automation, you also have to handle atoms
used to name modules:

   M = glurk,
   M:F(X).

This requires flow analysis. Actually, it can be even
worse than that. You can also do this:

   M = list_to_atom("prefix" ++ Lst),
   M:F(X).

and these:

   M1 = read_from_mnesia(Key),
   M2 = read_from_remote_node(Node),
   M1:f(), M2:g().

Automated transformations may be (probably are)
stumped by those cases. In a program optimization tool
I wrote (EUC 2001), I inserted runtime conversions
where the atom was used instead:

  new_name_of(M1):f()

new_name_of(old_mod) -> new_mod;
...

If you accept false positives, then conservatively
mark all call sites that MAY be affected by the
rewrite. An ambitious extension is to use or repurpose
one of the static analyzers that have appeared in
recent years, in order to remove as many of these
false positives as possible.

Best,
Thomas



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the erlang-questions mailing list