compiler/mlds_to_c_stmt.m:
compiler/mlds_to_c_class.m:
compiler/mlds_to_c_func.m:
Write out more things in calls to io.format.
Require an enum class to contain at one enum.
compiler/mlds_to_target_util.m:
Delete the output_n_indent and write_indented_line predicates,
since this series of changes has replaced all calls to them.
compiler/indent.m:
compiler/mlds_to_target_util.m:
Move the indent type (a synonym for int) from mlds_to_target_util.m
to indent.m, to prepare for the expansion of its use to other parts
of the compiler.
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_func.m:
compiler/mlds_to_cs_global.m:
compiler/mlds_to_cs_stmt.m:
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_func.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_util.m:
Import indent.m instead of mlds_to_target_util.m to get access
to the indent type.
Do so mostly by including the return value of indent2_string
as an item to be printed by io.format. By including as many things
to be printed as possible in a single call to io.format, people
reading the code can see how those items fit together.
compiler/mlds_to_java_name.m:
To allow more use of io.format still, replace the predicates here,
which each printed an entity of some kind, with functions that return
the string form of that entity.
In one case, tweak the job of the function a bit. The old predicate
output_qual_name_prefix_java used to print a period after the qualifier,
but its replacement function qualifier_to_string_for_java does not.
This is because having the format string in a call to io.format
contain no period between the qualifier and the name being qualified
would violate the law of least astonishment.
compiler/mlds_to_target_util.m:
Add a function version of the existing predicate output_generic_tvars,
named generic_tvars_to_string.
Make generic_tvar_to_string, which converts just one tvar, into a function,
because this fits in better with the rest of the ecosystem.
Add the utility function write_indentstr_line, which is a version of
the existing write_indented_line that takes the indent string, not the
indent level, as an argument. When called from callers which have
already converted the indent level to the its string form, calling
the old predicate would require redundant conversions.
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_func.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mlds_to_java_util.m:
compiler/mlds_to_java_wrap.m:
Make the changes described at the top, using the updates above.
In one place in mlds_to_java_func.m, generate missing indentation.
compiler/mlds_to_cs_data.m:
compiler/mlds_to_java_data.m:
Fix comments about the handling of rvals representing enums,
addressing Julien's review comments. In mlds_to_cs_data.m,
simplify the code the comments are about.
Separate out and simplify the code handling bitwise complements.
compiler/ml_type_gen.m:
Fix some comments.
Some comments were out-of-date. Update the ones I could update;
mark the others as out-of-date to warn readers.
compiler/mlds.m:
Expand some comments, and XXX about a possible improvement.
compiler/mlds_to_java_class.m:
Make clear that updates to a global data structure are used only locally.
compiler/mlds_to_java_stmt.m:
Use more standard variable names.
... and simplify them.
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_type.m:
These two modules contain very similar code, because C# is a near-copy
of Java, and therefore the MLDS->C# translator was created as a near-copy
of the MLDS->Java translator. However, they have diverged over time.
This diff makes them resemble each other more closely again. It does this
partly by putting the contents of both files into the same order, and
partly by fixing unnecessary differences between them (e.g. in what code
is in auxiliary functions and what code is inline).
It also simplifies things in several respects.
First, it deletes the output_type_for_{csharp,java}_dims predicates
after inlining them at their respective only call sites.
Second, while it keeps the old predicate in each module that converted
an MLDS type to a C#/Java type name and a list of array of dimensions
(though in a renamed form), it also adds a function wrapper that returns
the full type name, with the array dimensions applied, because this is
what most of its callers actually want.
Third, don't pass a type constructor category to the predicates now named
mercury_user_type_to_string_and_dims_for_{csharp,java} when what they need
is an mlds_class_kind; pass the mlds_class_kind directly.
Fourth, type_is_array_for_{csharp,java} both used to be defined
using if-then-else chains that tested for a few kinds of mlds_types,
and treated the rest the same. This code was vulnerable to not being
updated when new kinds of mlds_types were added. One of these predicates
had one bug, while the other had two. The bug they shared was that both
returned "not_array" for all mlds_tabling_types, even though some tabling
types *are* arrays. This was inconsequential, since neither target
supports tabling now. The other bug was that type_is_array_for_java
also returned "not_array" for mlds_mostly_generic_array_type, which
is always an array.
Besides these actual bugs, these functions also demanded double
maintenance, since their semantics required them to return "is_array"
if and only if type_to_string_and_dims_for_{csharp,java} returned
a nonempty list of array dimensions. Eliminate this maintenance burden
by deleting both functions, and making all their callers call a new version
of output_type_for_{csharp,java} instead. In all but one situation
(repeated for C# and Java), the callers of type_is_array_for_{csharp,java}
called output_type_for_{csharp,java} just before already, so this
new version, besides printing the target-language type name, also returns
the list of array dimensions that is one of its intermediate products.
compiler/mlds_to_target_util.m:
Update init_arg_wrappers_cs_java to operate on a list of array dimensions,
to conform to the change just above.
Add a function to convert a list of array dimensions to a string,
to allow mlds_to_{cs,java}_type.m to construct type names as strings
without immediately writing out that string. Document the related
functions.
Add a predicate to fix the size of an array in one dimension. Its body
is code that used to be repeated in mlds_to_{cs,java}_type.m.
Simplify some other code.
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_func.m:
compiler/mlds_to_cs_global.m:
compiler/mlds_to_cs_stmt.m:
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_func.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_stmt.m:
Conform to the changes above.
These modules had several pieces of code that converted an MLDS type
to a C#/Java type name and a list of array of dimensions, but then
ignored the dimensions. In every case, this was ok, because the MLDS type
being converted was one whose C#/Java form had no array dimensions,
but it still looked strange. The replacement code calls the
type_to_string_for_{csharp,java} functions, which does not have this
problem.
In mlds_to_java_stmt.m, replace two switches on the same value,
with a block of code between them, with a single switch, in which
each arm calls a predicate whose body used to be the sandwiched-between
block. Unlike the old structure, the new structure makes it easy to see
that the many parentheses in the generated code are balanced.
Add XXXs about some dubious aspects of the code.
compiler/mlds.m:
Add a table listing, for each Mercury builtin type, the name of the
C, Java and C# types that we use to represent values of that type.
The creation of this table was the initial impetus for the
trip-down-the-rabbit-hole described above :-)
compiler/prog_type.m:
Put related functors next to each other.
compiler/mlds_to_c_class.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_c_name.m:
compiler/mlds_to_c_stmt.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_c_util.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_func.m:
compiler/mlds_to_cs_global.m:
compiler/mlds_to_cs_name.m:
compiler/mlds_to_cs_stmt.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_cs_util.m:
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_func.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_name.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mlds_to_java_util.m:
compiler/mlds_to_target_util.m:
As above.
compiler/Mercury.options:
Specify --warn-impliciy-stream-calls for all the modules above.
compiler/file_util.m:
Delete a utility predicate that expects its clients to operate on
implicit streams, since the changes above replaced the last calls to it
with the variant that expects its client to operate on explicit streams.
compiler/mlds_to_cs_data.m:
compiler/mlds_to_java_data.m:
Generate C# and Java code for initializers that shows its structure
by its indentation. To make this possible, make the affected predicates
take arguments that say what to put after the initializer(s).
Document what these predicates do in terms of indentation as well as
in terms of the code they are writing out.
Put a space after cast operators.
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_global.m:
compiler/mlds_to_cs_stmt.m:
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_stmt.m:
Use the new mechanisms in mlds_to_{cs,java}_data.m to generate code
that shows its structure by indentation.
Fix bad line breaks when writing out lists of arguments.
When all call sites to a predicate specify the same value of an argument,
and no other value makes sense for that argument, then delete the argument
after "inlining" its value.
Delete obsolete comments.
compiler/mlds_to_target_util.m:
Add a utility predicate and a type needed by new code in the files above.
compiler/c_util.m:
Add hex_hash32 function to replace similar code in the following
three modules. Avoid using 0xffffffff as that constant may cause the
C compiler to emit warnings.
elds_to_erlang.m:
mlds_to_cs_name.m:
mlds_to_java_class.m:
Use hex_hash32.
compiler/mlds_to_java.m:
Delete this module. Move its contents to the following eleven modules.
compiler/mlds_to_java_class.m:
Code to output class definitions.
compiler/mlds_to_java_data.m:
Code to output lvals, rvals and initializers.
compiler/mlds_to_java_export.m:
Code to output entities (e.g. enums) exported to Java.
compiler/mlds_to_java_file.m:
The top level code, generating whole Java files.
compiler/mlds_to_java_func.m:
Code to output function definitions.
compiler/mlds_to_java_global.m:
Code to output the definitions of global variables.
compiler/mlds_to_java_name.m:
Code to output various kinds of names.
compiler/mlds_to_java_stmt.m:
Code to output statements.
compiler/mlds_to_java_type.m:
Code to output types.
compiler/mlds_to_java_util.m:
Utilities used by the other mlds_to_java_*.m modules.
compiler/mlds_to_java_wrap.m:
Code to create wrapper classes, to help implement function pointers.
compiler/ml_backend.m:
Delete the old module, add the new modules.
compiler/Mercury.options:
Require the new modules to have the declarations and definitions
of their predicates in a consistent order.
compiler/mercury_compile_mlds_back_end.m:
Import mlds_to_java_file.m instead of mlds_to_java.m.
compiler/mlds.m:
compiler/mlds_to_cs.m:
Update some references to the deleted file.
compiler/mlds_to_c_class.m:
Delete some stray ZZZs.