[m-rev.] diff: mangle erlang variable names
Ian MacLarty
maclarty at csse.unimelb.edu.au
Fri Jun 22 14:52:03 AEST 2007
On Fri, Jun 22, 2007 at 12:10:30PM +1000, Peter Wang wrote:
> Estimated hours taken: 0.25
> Branches: main
>
> compiler/elds_to_erlang.m:
> Mangle Erlang variable names by replacing weird characters with the
> decimal ASCII code.
>
> Index: compiler/elds_to_erlang.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/elds_to_erlang.m,v
> retrieving revision 1.20
> diff -u -r1.20 elds_to_erlang.m
> --- compiler/elds_to_erlang.m 19 Jun 2007 01:10:52 -0000 1.20
> +++ compiler/elds_to_erlang.m 22 Jun 2007 02:08:32 -0000
> @@ -712,13 +712,21 @@
> :- pred output_var_string(string::in, io::di, io::uo) is det.
>
> output_var_string(String, !IO) :-
> - % XXX this assumes all Mercury variable names are a subset of Erlang
> - % variable names
> - % However, the compiler can produce some illegal variable names
> - % which we should mangle e.g. TypeClassInfo_for_+_8
> - io.write_string(String, !IO),
> + % The compiler can produce some illegal variable names e.g.
> + % 'TypeClassInfo_for_+_8' so we need to mangle. We assume the first
> + % character is okay for Erlang (uppercase or underscore).
> + string.foldl(output_var_string_2, String, !IO),
> space(!IO).
>
> +:- pred output_var_string_2(char::in, io::di, io::uo) is det.
> +
> +output_var_string_2(C, !IO) :-
> + (if char.is_alnum_or_underscore(C) then
> + io.write_char(C, !IO)
> + else
> + io.write_int(char.to_int(C), !IO)
> + ).
> +
What if you have to two variables named V_+ and V_43. Won't you get the
same mangled name then (V_43)?
Ian.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list