[m-rev.] for review: --eliminate-local-vars bug in java grade

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Jun 16 15:20:04 AEST 2009


On Tue, 16 Jun 2009, Peter Wang wrote:

> Branches: main
>
> Fix a bug with --eliminate-local-vars on the java grade.
>
> The MLDS does not distinguish between integer and character constants.
> Although we can assign a integer constant to a char variable in Java, if the
> variable is eliminated we must explicitly cast the integer to a char wherever
> the variable appeared.  Due to overloading, Java cannot implicitly cast
> integers to characters in method calls.
>
> compiler/ml_unify_gen.m:
>        Add an explicit cast when generating an integer constant that is
>        really a character.
>
> tests/hard_coded/Mercury.options:
> tests/hard_coded/Mmakefile:
> tests/hard_coded/elim_local_var_char.exp:
> tests/hard_coded/elim_local_var_char.m:
>        Add test case.
>
> diff --git a/compiler/ml_unify_gen.m b/compiler/ml_unify_gen.m
> index f64a6ea..9c3dc18 100644
> --- a/compiler/ml_unify_gen.m
> +++ b/compiler/ml_unify_gen.m
> @@ -106,6 +106,7 @@
> :- import_module ml_backend.ml_code_gen.
> :- import_module ml_backend.ml_type_gen.
> :- import_module ml_backend.ml_util.
> +:- import_module parse_tree.builtin_lib_types.
> :- import_module parse_tree.prog_type.
> :- import_module parse_tree.prog_util.
>
> @@ -441,7 +442,17 @@ ml_gen_static_const_arg_2(Tag, VarType, Var,
> StaticCons, Context, Defns, Rval,
> ml_gen_constant(Tag, VarType, Rval, !Info) :-
>     (
>         Tag = int_tag(Int),
> -        Rval = ml_const(mlconst_int(Int))
> +        IntRval = ml_const(mlconst_int(Int)),
> +        % Add an explicit cast if this is a character constant.  Although we
> +        % can usually rely on implicit casts, if the char variable that the
> +        % constant is assigned to is eliminated, we can end up passing an int
> +        % where a char is expected.  In Java, and probably any language with
> +        % overloading, the explicity cast is required.

s/explicity/explicit/

> +        ( VarType = char_type ->
> +            Rval = ml_unop(cast(mlds_native_char_type), IntRval)
> +        ;
> +            Rval = IntRval
> +        )
>     ;
>         Tag = float_tag(Float),
>         Rval = ml_const(mlconst_float(Float))

That's fine otherwise.

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