[m-rev.] for review: java back-end fixes
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu May 15 00:38:30 AEST 2003
On 14-May-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Various fixes to make the Java back-end work better.
Review still welcome, but I'll go ahead and commit these now,
together with this additional further change.
compiler/mlds_to_java.m:
...
Fix some bugs where it was not generating correct package
names or module qualifiers for modules in the Mercury
standard library.
diff -u compiler/mlds_to_java.m compiler/mlds_to_java.m
--- compiler/mlds_to_java.m 14 May 2003 08:49:52 -0000
+++ compiler/mlds_to_java.m 14 May 2003 13:04:27 -0000
@@ -87,6 +87,7 @@
:- import_module parse_tree__modules. % for mercury_std_library_name.
:- import_module parse_tree__prog_data.
:- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_util.
:- import_module bool, int, string, library, list, map, set.
:- import_module assoc_list, term, std_util, require.
@@ -94,6 +95,9 @@
%-----------------------------------------------------------------------------%
mlds_to_java__output_mlds(MLDS) -->
+ % Note that the Java file name that we use for modules in the
+ % Mercury standard library do not include a "mercury." prefix;
+ % that's why we don't call mercury_module_name_to_mlds here.
{ ModuleName = mlds__get_module_name(MLDS) },
{ JavaSafeModuleName = valid_module_name(ModuleName) },
module_name_to_file_name(JavaSafeModuleName, ".java", yes,
@@ -307,8 +311,9 @@
ValidSymName = SymName
).
+:- type java_module_name == sym_name.
-:- func valid_module_name(mercury_module_name) = mercury_module_name.
+:- func valid_module_name(java_module_name) = java_module_name.
:- mode valid_module_name(in) = out is det.
valid_module_name(unqualified(String)) = ValidModuleName :-
@@ -959,18 +964,21 @@
:- mode output_src_start(in, in, in, in, in, di, uo) is det.
-output_src_start(Indent, ModuleName, Imports, ForeignDecls, Defns) -->
- { JavaSafeModuleName = valid_module_name(ModuleName) },
- output_auto_gen_comment(ModuleName),
+output_src_start(Indent, MercuryModuleName, Imports, ForeignDecls, Defns) -->
+ { MLDSModuleName = mercury_module_name_to_mlds(MercuryModuleName) },
+ { ModuleSymName = mlds_module_name_to_sym_name(MLDSModuleName) },
+ { JavaSafeModuleName = valid_module_name(ModuleSymName) },
+ output_auto_gen_comment(MercuryModuleName),
indent_line(Indent),
io__write_string("/* :- module "),
- prog_out__write_sym_name(JavaSafeModuleName),
+ prog_out__write_sym_name(MercuryModuleName),
io__write_string(". */\n\n"),
output_package_info(JavaSafeModuleName),
output_imports(Imports),
io__write_list(ForeignDecls, "\n", output_java_decl(Indent)),
io__write_string("public class "),
- prog_out__write_sym_name(JavaSafeModuleName),
+ { unqualify_name(JavaSafeModuleName, ClassName) },
+ io__write_string(ClassName),
io__write_string(" {\n"),
maybe_write_main_driver(Indent + 1, JavaSafeModuleName, Defns).
@@ -992,11 +1000,11 @@
% `main' predicate. Save the command line arguments in the class
% variable `args' in the class `mercury.runtime.JavaInternal'.
%
-:- pred maybe_write_main_driver(indent, mercury_module_name,
+:- pred maybe_write_main_driver(indent, java_module_name,
mlds__defns, io__state, io__state).
:- mode maybe_write_main_driver(in, in, in, di, uo) is det.
-maybe_write_main_driver(Indent, ModuleName, Defns) -->
+maybe_write_main_driver(Indent, JavaSafeModuleName, Defns) -->
(
{ defns_contain_main(Defns) }
->
@@ -1012,7 +1020,7 @@
%
io__write_string("mercury.runtime.JavaInternal.args = args;\n"),
indent_line(Indent + 1),
- prog_out__write_sym_name(ModuleName),
+ prog_out__write_sym_name(JavaSafeModuleName),
io__write_string(".main_2_p_0();\n"),
indent_line(Indent + 1),
io__write_string("return;\n"),
@@ -1027,17 +1035,16 @@
:- mode output_src_end(in, in, di, uo) is det.
output_src_end(Indent, ModuleName) -->
- { JavaSafeModuleName = valid_module_name(ModuleName) },
io__write_string("}\n"),
indent_line(Indent),
io__write_string("// :- end_module "),
- prog_out__write_sym_name(JavaSafeModuleName),
+ prog_out__write_sym_name(ModuleName),
io__write_string(".\n").
% Output a Java comment saying that the file was automatically
% generated and give details such as the compiler version.
%
-:- pred output_auto_gen_comment(module_name, io__state, io__state).
+:- pred output_auto_gen_comment(mercury_module_name, io__state, io__state).
:- mode output_auto_gen_comment(in, di, uo) is det.
output_auto_gen_comment(ModuleName) -->
@@ -1051,6 +1058,7 @@
io__write_string("//\n"),
io__write_string("//\n"),
io__nl.
+
%-----------------------------------------------------------------------------%
%
% Code to output declarations and definitions.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list