Files
mercury/tests/warnings/simple_code.m
Zoltan Somogyi 0584bc300d Expand obsolete pragmas with an optional "suggested replacements" field.
doc/reference_manual.texi:
NEWS:
    Document the extension.

compiler/prog_item.m:
    Add a field to the representation of obsolete pragmas to hold
    an optional list of suggested possible replacements.

compiler/parse_pragma.m:
    Parse the optional second argument in obsolete pragmas.

    Improve the error messages we generate for several kinds of errors
    we may encounter when parsing pragmas by making them more specific.

compiler/hlds_pred.m:
    Since an obsolete pragma now contains more than one bit of information
    (present vs not present), change their representation from a simple marker
    to a field containing the possible replacements.

    Make a comment about access stats more useful by sorting its contents
    on frequency of access, and putting it before the structure it is about.

compiler/simplify_goal_call.m:
    When generating warnings about calls to obsolete predicates or functions,
    mention the suggested replacements, if there are any.

compiler/add_pragma.m:
    Fill in the new field when adding an obsolete pragma to the HLDS.

compiler/globals.m:
    Add a function for use by new codee in parse_pragma.m.

compiler/canonicalize_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/hlds_out_pred.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out_pragma.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
compiler/table_gen.m:
    Conform to the changes above.

tests/invalid/bad_foreign_code.err_exp:
tests/invalid/bad_foreign_enum.err_exp:
tests/invalid/bad_foreign_export.err_exp:
    Expect the improved error messages from parse_pragma.m.

tests/warnings/simple_code.{m,exp}:
    Add tests of the new forms of the obsolete pragma.
2019-09-09 13:53:21 +10:00

115 lines
1.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module simple_code.
:- interface.
:- pred p(int::in, int::out) is erroneous.
:- implementation.
:- import_module require.
p -->
(
[]
;
{ error("foo") }
),
( { true } ->
{ Z = 2 }
;
{ Z = 3 }
),
( { X = 3, X = 2, Z = 2 } ->
[]
;
[]
),
( { \+ true } ->
[]
;
[]
),
( { \+ det_pred } ->
[]
;
[]
),
( { \+ fail_pred } ->
[]
;
[]
),
{ \+ fail },
{ obsolete1 },
{ obsolete2 },
{ obsolete3 },
( { error("blah") } ->
[]
;
[]
).
:- pred det_pred is det.
det_pred.
:- pred fail_pred is failure.
fail_pred :- fail.
:- pred obsolete1 is det.
:- pragma obsolete(obsolete1/0).
obsolete1.
:- pred obsolete2 is det.
:- pragma obsolete(obsolete2/0, [pred42/0]).
obsolete2.
:- pred obsolete3 is det.
:- pragma obsolete(obsolete3/0, [pred42/0, wonderful.pred43/0]).
obsolete3.
% This should give a warning about the second disjunct never succeeding.
:- pred r(int, int).
:- mode r(in(bound(1)), out(bound(42))) is det.
r(1, 42).
r(2, 21).
% This should not give a warning, because the second disjunct can
% succeed in the first mode.
:- pred q(int, int).
:- mode q(in, out) is semidet.
:- mode q(in(bound(1)), out(bound(42))) is det.
q(1, 42).
q(2, 21).
:- type node ---> a ; b ; c.
:- pred parent(node, node).
:- mode parent(in, out).
:- mode parent(out, in).
parent(a, b).
parent(b, c).
parent(a, c).
:- pred node(node).
:- mode node(out).
node(a).
node(b).
node(c).
:- pred anc(node, node).
:- mode anc(in, out).
:- mode anc(out, in).
anc(X, X) :-
node(X).
anc(X, Z) :-
parent(X, Y),
anc(Y, Z).