Files
mercury/tests/invalid/exported_foreign_enum.m
Zoltan Somogyi 727e9b9210 Fix some tests/invalid failures.
tests/invalid/bad_fact_table_decls.m:
tests/invalid/bad_fact_table_decls_[123]:
    Add dummy fact table data files for this test case,
    because mmc --make reports an error if they do not exist,
    and stops looking for the errors that this test case
    is intended to exercise.

tests/invalid/exist_foreign_error.err_exp3:
    Update this expected output file to expect color in diagnostics.

tests/invalid/exported_foreign_enum.{m,err_exp}:
    This test case was set up only for C grades. Change it to test
    the same functionality in Java and C# grades as well, and simplify it
    by using just one interface and implementation section each.

tests/invalid/bad_tscp.{m,err_exp}:
tests/invalid_make_int/bad_tscp.{m,int_err_exp}:
    Move the bad_tscp test case from invalid to invalid_make_int,
    because for a while now, the compiler has been reporting
    the errors we are testing for when making interface files.

tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
    Stop referring to the moved test case.

tests/invalid_make_int/Mercury.options:
tests/invalid_make_int/Mmakefile:
    Copy the references to the moved test case.

    Add a missing module's (redundant_imports's) setup to Mercury.options.
2025-09-14 10:12:51 +10:00

150 lines
3.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module exported_foreign_enum.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- type t1
---> f11
; f12
; f13(int).
:- type t2
---> f21
; f22
; f23.
%---------------------------------------------------------------------------%
:- implementation.
main(!IO) :-
( test(bar) ->
io.write_string("Success.\n", !IO)
;
io.write_string("ERROR.\n", !IO)
).
:- pred test(foo::in) is semidet.
:- pragma foreign_proc("C",
test(X::in),
[will_not_call_mercury, promise_pure],
"
if (X == FOO_bar) {
SUCCESS_INDICATOR = MR_TRUE;
} else {
SUCCESS_INDICATOR = MR_FALSE;
}
").
:- pragma foreign_proc("Java",
test(X::in),
[will_not_call_mercury, promise_pure],
"
if (X == FOO_bar) {
SUCCESS_INDICATOR = true;
} else {
SUCCESS_INDICATOR = false;
}
").
:- pragma foreign_proc("C#",
test(X::in),
[will_not_call_mercury, promise_pure],
"
if (X == FOO_bar) {
SUCCESS_INDICATOR = true;
} else {
SUCCESS_INDICATOR = false;
}
").
%---------------------------------------------------------------------------%
:- type foo
---> foo(int)
; bar
; baz.
:- pragma foreign_export_enum("C", foo/0, [prefix("FOO_")]).
:- pragma foreign_export_enum("Java", foo/0, [prefix("FOO_")]).
:- pragma foreign_export_enum("C#", foo/0, [prefix("FOO_")]).
:- pragma foreign_enum("C", foo/0, [
foo - "400",
bar - "500",
baz - "600"
]).
:- pragma foreign_enum("Java", foo/0, [
foo - "400",
bar - "500",
baz - "600"
]).
:- pragma foreign_enum("C#", foo/0, [
foo - "400",
bar - "500",
baz - "600"
]).
%---------------------------------------------------------------------------%
:- pragma foreign_enum("C", t1/0, [
f11 - "14",
f12 - "15",
f13 - "16"
]).
:- pragma foreign_enum("Java", t1/0, [
f11 - "14",
f12 - "15",
f13 - "16"
]).
:- pragma foreign_enum("C#", t1/0, [
f11 - "14",
f12 - "15",
f13 - "16"
]).
%---------------------------------------------------------------------------%
:- pragma foreign_enum("C", t2/0, [
f21 - "24",
f22 - "25",
f23 - "26"
]).
:- pragma foreign_enum("Java", t2/0, [
f21 - "24",
f22 - "25",
f23 - "26"
]).
:- pragma foreign_enum("C#", t2/0, [
f21 - "24",
f22 - "25",
f23 - "26"
]).
%---------------------------------------------------------------------------%
:- type t3 == t1.
:- pragma foreign_enum("C", t3/0, [
f31 - "34",
f32 - "35",
f33 - "36"
]).
:- pragma foreign_enum("Java", t3/0, [
f31 - "34",
f32 - "35",
f33 - "36"
]).
:- pragma foreign_enum("C#", t3/0, [
f31 - "34",
f32 - "35",
f33 - "36"
]).
%---------------------------------------------------------------------------%