mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-28 15:54:18 +00:00
One option, --warn-non-contiguous-decls, generates warnings if the
mode declarations of a predicate or function aren't in a contiguous block
immediately following the pred or func declaration. Since this is a rare
kind of "style error", this option is enabled by default.
Two options, --warn-inconsistent-pred-order-clauses and
--warn-inconsistent-pred-order-foreign-procs, warn about inconsistencies
between (a) the order in which predicates (and functions) are declared,
and (b) the order in which they are defined. The two options differ in
their scope. The latter applies to all predicates and functions defined
in the module, while the former applies only to those whose definitions
include Mercury clauses.
Since an exported predicate or function may need nonexported auxiliary
predicates and/or functions, imposing a single order the declarations and
definitions of *all* the predicates and functions in a module is not a good
idea. Instead, both options divide the predicates and functions defined
in a module two groups, the exported and the nonexported, and expect
a consistent order only within each group.
The result is output that looks like this:
time.m:021: Warning: the order of the declarations and definitions of the
time.m:021: exported predicates is inconsistent, as shown by this diff:
time.m:021:
time.m:021: --- declaration order
time.m:021: +++ definition order
time.m:021: @@ -1,7 +1,7 @@
time.m:021: predicate `clock'/3
time.m:021: -predicate `time'/3
time.m:021: predicate `times'/4
time.m:021: function `clk_tck'/0
time.m:021: +predicate `time'/3
time.m:021: function `difftime'/2
time.m:021: predicate `localtime'/4
time.m:021: function `localtime'/1
compiler/options.m:
doc/user_guide.texi:
Add the new options.
compiler/style_checks.m:
A new module that generates the new warnings if warranted.
compiler/check_hlds.m:
compiler/notes/compiler_design.html:
Include and document the new module.
compiler/mercury_compile_front_end.m:
Invoke the new module if any of the three new options is set.
compiler/hlds_pred.m:
Record the item number of every predicate, function, and mode declaration
in the module being compiled. We need this for information for the
new warnings.
compiler/hlds_module.m:
Record the context of the module declaration. We use this context
for warnings about inconsistent order, since there isn't a better one.
compiler/hlds_clauses.m:
Add a mechanism to retrieve the item numbers of a set of clauses
even if they are contiguous.
Document some old data types.
compiler/error_util.m:
Add a new phase for style checks.
compiler/accumulator.m:
compiler/add_class.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/from_ground_term_util.m:
compiler/lambda.m:
compiler/make_hlds.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile.m:
compiler/par_loop_control.m:
compiler/polymorphism.m:
compiler/stm_expand.m:
compiler/table_gen.m:
compiler/unify_proc.m:
Conform the changes to the HLDS above.
compiler/typecheck_errors.m:
Fix style of error messages.
library/array2d.m:
library/assoc_list.m:
library/benchmarking.m:
library/bit_buffer.write.m:
library/bool.m:
library/builtin.m:
library/construct.m:
library/cord.m:
library/counter.m:
library/float.m:
library/injection.m:
library/lazy.m:
library/lexer.m:
library/ops.m:
library/private_builtin.m:
library/profiling_builtin.m:
library/prolog.m:
library/queue.m:
library/rational.m:
library/require.m:
library/stack.m:
library/std_util.m:
library/store.m:
library/thread.semaphore.m:
library/tree234.m:
library/univ.m:
library/version_store.m:
Move declarations or definitions around to avoid some of the warnings
that we can now generate. (There are many more left.)
Make some minor style improvements in the process.
tests/warnings/inconsistent_pred_order.{m,exp}:
tests/warnings/non_contiguous_decls.{m,exp}:
New test cases to test the new options. They are both copies of
tests/benchmarks/queens.m, with intentionally-screwed-up style.
tests/warnings/Mmakefile:
Enable the new test cases.
tests/warnings/Mercury.options:
Specify the options being tested for the new test cases.
tests/benchmarks/queens.m:
Bring the style of this module up to date (before copying it).
tests/invalid/mode_decl_in_wrong_section.err_exp:
Expect the warnings we now generate.
158 lines
4.0 KiB
Mathematica
158 lines
4.0 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1996-1997,2000,2002-2007,2009-2010 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU Library General
|
|
% Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% File: bool.m.
|
|
% Main authors: fjh, zs.
|
|
% Stability: medium to high.
|
|
%
|
|
% This module exports the boolean type `bool' and some operations on bools.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module bool.
|
|
:- interface.
|
|
|
|
:- import_module enum.
|
|
:- import_module list.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% The boolean type.
|
|
% Unlike most languages, we use `yes' and `no' as boolean constants
|
|
% rather than `true' and `false'. This is to avoid confusion
|
|
% with the predicates `true' and `fail'.
|
|
:- type bool
|
|
---> no
|
|
; yes.
|
|
|
|
:- instance enum(bool).
|
|
|
|
% not(A) = yes iff A = no.
|
|
%
|
|
:- func not(bool) = bool.
|
|
:- pred not(bool::in, bool::out) is det.
|
|
|
|
% or(A, B) = yes iff A = yes, or B = yes, or both.
|
|
%
|
|
:- func or(bool, bool) = bool.
|
|
:- pred or(bool::in, bool::in, bool::out) is det.
|
|
|
|
% xor(A, B) = yes iff A = yes, or B = yes, but not both.
|
|
%
|
|
:- func xor(bool, bool) = bool.
|
|
|
|
% and(A, B) = yes iff A = yes and B = yes.
|
|
%
|
|
:- func and(bool, bool) = bool.
|
|
:- pred and(bool::in, bool::in, bool::out) is det.
|
|
|
|
% or_list(As) = yes iff there exists an element of As equal to yes.
|
|
% (Note that or_list([]) = no.)
|
|
%
|
|
:- func or_list(list(bool)) = bool.
|
|
:- pred or_list(list(bool)::in, bool::out) is det.
|
|
|
|
% and_list(As) = yes iff every element of As is equal to yes.
|
|
% (Note that and_list([]) = yes.)
|
|
%
|
|
:- func and_list(list(bool)) = bool.
|
|
:- pred and_list(list(bool)::in, bool::out) is det.
|
|
|
|
% pred_to_bool(P) = (if P then yes else no).
|
|
%
|
|
:- func pred_to_bool((pred)::((pred) is semidet)) = (bool::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
% Important:
|
|
% The representation of bool values should correspond with the definitions of
|
|
% MR_TRUE and MR_FALSE in runtime/mercury_std.h.
|
|
|
|
:- pragma foreign_export_enum("C#", bool/0, [],
|
|
[
|
|
no - "NO",
|
|
yes - "YES"
|
|
]).
|
|
|
|
:- pragma foreign_export_enum("Java", bool/0, [],
|
|
[
|
|
no - "NO",
|
|
yes - "YES"
|
|
]).
|
|
|
|
:- instance enum(bool) where [
|
|
to_int(Bool) = bool_to_int(Bool),
|
|
from_int(bool_to_int(Bool)) = Bool
|
|
].
|
|
|
|
:- func bool_to_int(bool) = int.
|
|
:- mode bool_to_int(in) = out is det.
|
|
:- mode bool_to_int(out) = in is semidet.
|
|
|
|
bool_to_int(no) = 0.
|
|
bool_to_int(yes) = 1.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
bool.not(X) = Result :-
|
|
bool.not(X, Result).
|
|
|
|
bool.not(no, yes).
|
|
bool.not(yes, no).
|
|
|
|
bool.or(X, Y) = Result :-
|
|
bool.or(X, Y, Result).
|
|
|
|
bool.or(yes, _, yes).
|
|
bool.or(no, Bool, Bool).
|
|
|
|
bool.xor(no, no) = no.
|
|
bool.xor(no, yes) = yes.
|
|
bool.xor(yes, no) = yes.
|
|
bool.xor(yes, yes) = no.
|
|
|
|
bool.and(X, Y) = Result :-
|
|
bool.and(X, Y, Result).
|
|
|
|
bool.and(no, _, no).
|
|
bool.and(yes, Bool, Bool).
|
|
|
|
bool.or_list(List) = Result :-
|
|
bool.or_list(List, Result).
|
|
|
|
bool.or_list([], no).
|
|
bool.or_list([Bool | Bools], Result) :-
|
|
(
|
|
Bool = yes,
|
|
Result = yes
|
|
;
|
|
Bool = no,
|
|
bool.or_list(Bools, Result)
|
|
).
|
|
|
|
bool.and_list(List) = Result :-
|
|
bool.and_list(List, Result).
|
|
|
|
bool.and_list([], yes).
|
|
bool.and_list([Bool | Bools], Result) :-
|
|
(
|
|
Bool = no,
|
|
Result = no
|
|
;
|
|
Bool = yes,
|
|
bool.and_list(Bools, Result)
|
|
).
|
|
|
|
pred_to_bool(P) = (if P then yes else no).
|
|
|
|
%---------------------------------------------------------------------------%
|