[m-rev.] for review: mangle symbols with a leading digit in java

Julien Fischer juliensf at csse.unimelb.edu.au
Sun Jun 21 23:29:59 AEST 2009


On Fri, 19 Jun 2009, Peter Wang wrote:

> Branches: main
>
> Mangle symbols which would begin with a digit in generated Java code.
>
> compiler/prog_foreign.m:
>        Add a version of name_mangle which mangles symbols beginning with a
>        digit, in the same way as if it contained a character not allowed in C
>        identifiers.
>
> compiler/java_names.m:
> compiler/mlds_to_java.m:
>        Call the new function.
>
>        Don't need to mangle a string in a spot.
>
> compiler/ml_util.m:
>        Unrelated: make a simple change to defns_contain_main to use less
>        nondet stack space.  I ran out of stack space when testing this change
>        on a particular module.  The compiler was built in a debugging grade.
>

...

> diff --git a/compiler/prog_foreign.m b/compiler/prog_foreign.m
> index 347d2f1..d5ed6f6 100644
> --- a/compiler/prog_foreign.m
> +++ b/compiler/prog_foreign.m
> @@ -172,9 +172,15 @@
> :- func sym_name_mangle(sym_name) = string.
>
>     % Mangle an arbitrary name into a C etc identifier.
> +    % Initial digits are allowed.
>     %
> :- func name_mangle(string) = string.
>
> +    % Mangle an arbitrary name into a C etc identifier.
> +    % The resulting identifier will not begin with a digit.
> +    %
> +:- func name_mangle_no_leading_digit(string) = string.
> +
>     % Produces a string of the form Module__Name.
>     %
> :- func qualify_name(string, string) = string.
> @@ -373,12 +379,27 @@ sym_name_mangle(qualified(ModuleName,
> PlainName)) = MangledName :-
>     MangledPlainName = name_mangle(PlainName),
>     MangledName = qualify_name(MangledModuleName, MangledPlainName).
>
> -name_mangle(Name) = MangledName :-
> +name_mangle(Name) = name_mangle_2(yes, Name).
> +
> +name_mangle_no_leading_digit(Name) = name_mangle_2(no, Name).
> +
> +:- func name_mangle_2(bool, string) = string.
> +
> +name_mangle_2(AllowLeadingDigit, Name) = MangledName :-
>     % Warning: any changes to the name mangling algorithm here may also
>     % require changes to extras/dynamic_linking/name_mangle.m,
>     % profiler/demangle.m, util/mdemangle.c and compiler/name_mangle.m.

Presumably that comment only applies to the C name mangling stuff?
That needs to be made clear here.

> -    ( string.is_all_alnum_or_underscore(Name) ->
> +    (
> +        string.is_all_alnum_or_underscore(Name),
> +        (
> +            AllowLeadingDigit = yes
> +        ;
> +            AllowLeadingDigit = no,
> +            string.index(Name, 0, FirstChar),
> +            not char.is_digit(FirstChar)
> +        )
> +    ->
>         % Any names that start with `f_' are changed so that they start with
>         % `f__', so that we can use names starting with `f_' (followed by
>         % anything except an underscore) without fear of name collisions.

I think a better interface would be to parameterize all of the name
mangling functions in this module by the target language, for example:

     :- func name_mangle(compilation_target, string) = string.

etc.

Other than the above it looks okay.

Julien.
--------------------------------------------------------------------------
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