Files
mercury/tests/dppd/regexp.m
Zoltan Somogyi a0760327b6 Do stricter checking of mode and determinism declarations.
Specifically, we now do three new checks:

BAD_DETISM: We now generate error messages for predicate declarations
that specify a determinism without also specifying argument modes.

BAD_PREDMODE: We now generate error messages for standalone mode declarations
for predicates whose predicate declaration includes modes for the arguments.

BAD_MODE_SECTION: We now generate error messages for standalone mode
declarations that are not in the same section as the predicate's (or
function's) type declaration.

compiler/hlds_pred.m:
    Add a slot to the pred_sub_info. If the predicate is explicitly defined by
    the user in the current module, this contains the id of the section that
    contains its predicate declaration (for the BAD_MODE_SECTION check)
    and whether that predicate declaration also had modes for the arguments
    (for the BAD_PREDMODE check).

compiler/add_pred.m:
    When adding adding new predicate declarations, perform the BAD_DETISM
    check, and record the info needed for the BAD_PREDMODE and BAD_MODE_SECTION
    checks.

    When adding adding new mode declarations, perform the BAD_PREDMODE
    and BAD_MODE_SECTION checks.

compiler/add_class.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_solver.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/dep_par_conj.m:
compiler/higher_order.m:
compiler/make_hlds_passes.m:
compiler/table_gen.m:
compiler/unused_args.m:
    Conform to the changes above.

mdbcomp/builtin_modules.m:
    Add a utility predicate for use by new code in add_pred.m.

compiler/comp_unit_interface.m:
compiler/goal_util.m:
compiler/prog_rename.m:
compiler/quantification.m:
deep_profiler/program_representation_utils.m:
library/calendar.m:
library/mutvar.m:
library/pretty_printer.m:
library/random.m:
library/set_ctree234.m:
library/solutions.m:
library/stream.string_writer.m:
profiler/globals.m:
tests/accumulator/nonrec.m:
tests/accumulator/out_to_in.m:
tests/declarative_debugging/library_forwarding.m:
tests/dppd/applast_impl.m:
tests/dppd/grammar_impl.m:
tests/dppd/regexp.m:
tests/dppd/transpose_impl.m:
tests/hard_coded/copy_pred.m:
tests/hard_coded/ho_func_default_inst.m:
tests/recompilation/unchanged_pred_nr_2.m.1:
tests/recompilation/unchanged_pred_nr_2.m.2:
tests/valid/det_switch.m:
tests/valid/inlining_bug.m:
    Delete determinism declarations from predicate and function declarations
    that have no argument mode information, since the BAD_DETISM check
    now makes these errors.

tests/valid/two_pragma_c_codes.m:
    Move some mode declarations to the right section, since the
    BAD_MODE_SECTION check now generates an error for the old code.

tests/invalid/typeclass_bad_method_mode.{m,err_exp}:
    New test case to test for the BAD_PREDMODE check.

tests/invalid/mode_decl_in_wrong_section.{m,err_exp}:
    New test case to test for the BAD_MODE_SECTION check.

tests/invalid/bad_detism.err_exp:
    Add an expected output for this old, but never enabled test case,
    which tests for new check BAD_DETISM.

tests/invalid/Mmakefile:
    Enable the new test cases.

tests/invalid/typeclass_dup_method_mode.m:
    This test case used to have two bugs. One is now by itself in the new
    typeclass_bad_method_mode.m test case, so modify it to contain only
    the other (indistinguishable modes).

tests/invalid/func_errors.err_exp:
tests/invalid/tc_err1.err_exp:
tests/invalid/undef_lambda_mode.err_exp:
tests/invalid/undef_type_mode_qual.err_exp:
    Expect an extra error message from the BAD_DETISM check.
2016-01-13 02:03:16 +11:00

92 lines
2.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% The "regexp.r1" Benchmark
% Part of the DPPD Library.
%
% A program testing whether a string matches a regular expression (using
% difference lists). Much more naive (and smaller) than the program used
% by Mogensen/Bondorf for Logimix ! The regular expression for this
% benchmark is (a+b)*aab. This benchmark contains no builtins or negations.
:- module regexp.
:- interface.
:- import_module char.
:- import_module list.
:- type regexp
---> empty
; char(char)
; or(regexp, regexp)
; cat(regexp, regexp)
; star(regexp).
:- pred generate1(list(char)).
:- mode generate1(in) is semidet.
:- pred generate2(list(char)::in) is semidet.
:- pred generate3(list(char)::in) is semidet.
:- implementation.
generate1(S) :-
generate(cat(star(or(char(a), char(b))),
cat(char(a), cat(char(a), char(b)))), S, []).
generate2(S) :-
generate(star(cat(or(char(a), char(b)), cat(or(char(c), char(d)),
cat(or(char(e), char(f)), or(char(g), char(h)))))), S, []).
generate3(S) :-
generate(star(cat(or(char(a), char(b)), cat(or(char(a), char(b)),
cat(or(char(a), char(b)), cat(or(char(a), char(b)),
cat(or(char(a), char(b)), or(char(a), char(b)))))))), S, []).
:- pred generate(regexp::in, list(char)::in, list(char)::out) is nondet.
generate(empty, T, T).
generate(char(X), [X | T], T).
generate(or(X, _), H, T) :-
generate(X, H, T).
generate(or(_, Y), H, T) :-
generate(Y, H, T).
generate(cat(X, Y), H, T) :-
generate(X, H, T1),
generate(Y, T1, T).
generate(star(_), T, T).
generate(star(X), H, T) :-
generate(X, H, T1),
generate(star(X), T1, T).
% The partial deduction query
%
% :- generate(cat(star(or(char(a), char(b))),
% cat(char(a), cat(char(a), char(b)))), S, []).
%
% The run-time queries
%
% :- generate(cat(star(or(char(a), char(b))), cat(char(a),
% cat(char(a), char(b)))), [a, a, a, a, a, a, b, b, a, a, a, b], []).
% :- generate(cat(star(or(char(a), char(b))), cat(char(a),
% cat(char(a), char(b)))), [a, a, a, a, a, a, b, b, a, b], []).
% :- generate(cat(star(or(char(a), char(b))), cat(char(a),
% cat(char(a), char(b)))), [a, b, a, b, a, b, a, b, a, b, a], []).
% :- generate(cat(star(or(char(a), char(b))), cat(char(a),
% cat(char(a), char(b)))), [X, Y, Z, V], []).
%
% Example solution
%
% The following can be obtained by the ECCE partial deduction system.
% Although it runs considerably faster than the original program (5 times
% actually) it does not correspond to a deterministic automaton yet.
%
% generate__1(X1) :- generate__2(X1).
% generate__2([a, a, b]).
% generate__2([a | X1]) :- generate__2(X1).
% generate__2([b | X1]) :- generate__2(X1).
%
% Michael Leuschel / K.U. Leuven / michael@cs.kuleuven.ac.be