Files
mercury/tests/hard_coded/construct_mangle.m
Zoltan Somogyi 89b05266a1 Provide alternatives to can-fail library functions.
library/array.m:
library/assoc_list.m:
library/bimap.m:
library/bitmap.m:
library/construct.m:
library/deconstruct.m:
library/dir.m:
library/hash_table.m:
library/injection.m:
library/io.stream_db.m:
library/kv_list.m:
library/list.m:
library/map.m:
library/robdd.m:
library/stream.string_writer.m:
library/term_conversion.m:
library/term_to_xml.m:
library/tree234.m:
library/type_desc.m:
library/version_hash_table.m:
    For nearly every ordinary function in this directory that can fail in its
    primary mode (all of which were semidet functions),

    - provide a semidet predicate as an alternative, if it did not
      already exist,

    - implement the function in terms of the predicate, instead of vice versa,

    - mark the semidet function as obsolete in favor of the semidet predicate
      version,

    - fix all the resulting warnings, and then

    - comment out the obsolete pragmas (at least for now).

    Note that this diff does not touch the semidet function in the
    enum typeclass, or the functions that implement that method
    in instances.

NEWS.md:
    Announce the new predicates in the (documented) modules of the library.

browser/term_rep.m:
compiler/lp_rational.m:
compiler/mcsolver.m:
compiler/mode_ordering.m:
compiler/mode_robdd.equiv_vars.m:
compiler/mode_robdd.implications.m:
compiler/old_type_constraints.m:
compiler/pickle.m:
compiler/prog_event.m:
compiler/type_ctor_info.m:
compiler/var_table.m:
tests/hard_coded/bitmap_empty.m:
tests/hard_coded/construct_mangle.m:
tests/hard_coded/construct_packed.m:
tests/hard_coded/construct_test.m:
tests/hard_coded/dummy_type_construct.m:
tests/hard_coded/expand.m:
tests/hard_coded/foreign_enum_rtti.m:
tests/hard_coded/subtype_rtti.m:
tests/hard_coded/term_to_univ_test.m:
tests/hard_coded/type_to_term.m:
tests/hard_coded/type_to_term_bug.m:
    Stop calling the semidet functions from the library that were temporarily
    marked obsolete.

    In a few places, add explicit type qualification to avoid warnings
    about unresolved polymorphism.

tests/hard_coded/test_injection.exp:
    Expect an abort message from the predicate version of a semidet function.

tests/declarative_debugger/ho_2.exp2:
    Update this .exp file for a previous commit.
2024-08-09 09:14:46 +02:00

135 lines
3.5 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
% Test construction of name mangled functors (e.g. on Java).
%---------------------------------------------------------------------------%
:- module construct_mangle.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module construct.
:- import_module type_desc.
:- import_module univ.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
test_type(type_of(_ : requires_mangling), !IO),
test_type(type_of(_ : '$singleton'(int)), !IO).
% This must not be an enumeration as enumerations on Java are represented
% in a way such that name mangling doesn't apply.
%
:- type requires_mangling
---> (' ')
; ('!')
; ('"')
; ('#')
; ('$')
; ('%')
; ('&')
; ('''')
; ('(')
; (')')
; ('*')
; ('+')
; (',')
; ('-')
; ('.')
; ('/')
; ('0')
; ('1')
; ('2')
; ('3')
; ('4')
; ('5')
; ('6')
; ('7')
; ('8')
; ('9')
; (':')
; (';')
; ('<')
; ('=')
; ('>')
; ('?')
; ('@')
; ('[')
; ('\\')
; (']')
; ('^')
; ('_')
; ('`')
; ('{')
; ('|')
; ('}')
; ('~')
; ('\\=')
; ('>=')
; ('=<')
; ('{}')
; ('[|]')
; ('[]')
; ('abc~!@#$%^&*()_+|xyz')
; f_this_also_requires_mangling
; force_non_enum(int)
; requires_mangling % functor has same name/arity as type
; requires_mangling(int). % same name, different arity
:- type '$singleton'(T)
---> '$singleton'(T).
% XXX the Java backend currently generates invalid code for this type
% :- type '$blah'
% ---> '$blah'(int)
% ; '$blah2'.
:- pred test_type(type_desc::in, io::di, io::uo) is det.
test_type(Type, !IO) :-
( if num_functors(Type, NumFunctors) then
list.foldl(test_functor(Type), 0 .. NumFunctors - 1, !IO)
else
io.write_string("failed\n", !IO)
),
io.write_string("----\n", !IO).
:- pred test_functor(type_desc::in, int::in, io::di, io::uo) is det.
test_functor(Type, FunctorNumber, !IO) :-
( if get_functor(Type, FunctorNumber, Name, Arity, _ArgTypes) then
% Assume that any arguments are ints.
ArgUnivs = list.map(int_univ, 1 .. Arity),
( if
find_functor(Type, Name, Arity, FunctorNumber, _),
construct(Type, FunctorNumber, ArgUnivs, Univ)
then
io.write(Univ, !IO),
io.nl(!IO)
else
io.write_string("failed FunctorNumber = ", !IO),
io.write_int(FunctorNumber, !IO),
io.nl(!IO)
)
else
io.write_string("failed FunctorNumber = ", !IO),
io.write_int(FunctorNumber, !IO),
io.nl(!IO)
).
:- func int_univ(int) = univ.
int_univ(I) = univ(I).