Files
mercury/compiler/maybe_error.m
Zoltan Somogyi 307b1dc148 Split up error_util.m into five modules.
compiler/error_spec.m:
    This new module contains the part of the old error_util.m that defines
    the error_spec type, and some functions that can help construct pieces
    of error_specs. Most modules of the compiler that deal with errors
    will need to import only this part of the old error_util.m.

    This change also renames the format_component type to format_piece,
    which matches our long-standing naming convention for variables containing
    (lists of) values of this type.

compiler/write_error_spec.m:
    This new module contains the part of the old error_util.m that
    writes out error specs, and converts them to strings.

    This diff marks as obsolete the versions of predicates that
    write out error specs to the current output stream, without
    *explicitly* specifying the intended stream.

compiler/error_sort.m:
    This new module contains the part of the old error_util.m that
    sorts lists of error specs and error msgs.

compiler/error_type_util.m:
    This new module contains the part of the old error_util.m that
    convert types to format_pieces that generate readable output.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/error_util.m:
    The code remaining in the original error_util.m consists of
    general utility predicates and functions that don't fit into
    any of the modules above.

    Delete an unneeded pair of I/O states from the argument list
    of a predicate.

compiler/file_util.m:
    Move the unable_to_open_file predicate here from error_util.m,
    since it belongs here. Mark another predicate that writes
    to the current output stream as obsolete.

compiler/hlds_error_util.m:
    Mark two predicates that wrote out error_spec to the current output
    stream as obsolete, and add versions that take an explicit output stream.

compiler/Mercury.options:
    Compile the modules that call the newly obsoleted predicates
    with --no-warn-obsolete, for the time being.

compiler/*.m:
    Conform to the changes above, mostly by updating import_module
    declarations, and renaming format_component to format_piece.
2022-10-12 20:50:16 +11:00

145 lines
4.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 2015 The Mercury team.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%---------------------------------------------------------------------------%
:- module parse_tree.maybe_error.
:- interface.
:- import_module parse_tree.error_spec.
:- import_module list.
%---------------------------------------------------------------------------%
:- type maybe_safe_to_continue
---> safe_to_continue
; unsafe_to_continue.
%---------------------------------------------------------------------------%
:- type maybe1(T1)
---> error1(list(error_spec))
; ok1(T1).
:- type maybe2(T1, T2)
---> error2(list(error_spec))
; ok2(T1, T2).
:- type maybe3(T1, T2, T3)
---> error3(list(error_spec))
; ok3(T1, T2, T3).
:- type maybe4(T1, T2, T3, T4)
---> error4(list(error_spec))
; ok4(T1, T2, T3, T4).
:- type maybe5(T1, T2, T3, T4, T5)
---> error5(list(error_spec))
; ok5(T1, T2, T3, T4, T5).
%---------------------%
:- inst maybe1(I) for maybe1/1
---> error1(ground)
; ok1(I).
:- inst maybe2(I1, I2) for maybe2/2
---> error2(ground)
; ok2(I1, I2).
:- inst maybe3(I1, I2, I3) for maybe3/3
---> error3(ground)
; ok3(I1, I2, I3).
:- inst maybe4(I1, I2, I3, I4) for maybe4/4
---> error4(ground)
; ok4(I1, I2, I3, I4).
:- inst maybe5(I1, I2, I3, I4, I5) for maybe5/5
---> error5(ground)
; ok5(I1, I2, I3, I4, I5).
%---------------------%
:- func get_any_errors1(maybe1(T1)) = list(error_spec).
:- func get_any_errors2(maybe2(T1, T2)) = list(error_spec).
:- func get_any_errors3(maybe3(T1, T2, T3)) = list(error_spec).
:- func get_any_errors4(maybe4(T1, T2, T3, T4)) = list(error_spec).
:- func get_any_errors5(maybe5(T1, T2, T3, T4, T5)) = list(error_spec).
:- func get_any_errors_warnings2(maybe2(T1, list(warning_spec))) =
list(error_spec).
:- func get_any_errors_warnings3(maybe3(T1, T2, list(warning_spec))) =
list(error_spec).
:- func get_any_errors_warnings4(maybe4(T1, T2, T3, list(warning_spec))) =
list(error_spec).
:- func get_any_errors_warnings5(maybe5(T1, T2, T3, T4, list(warning_spec))) =
list(error_spec).
:- pred project_ok1(maybe1(T1)::in, T1::out) is semidet.
:- pred det_project_ok1(maybe1(T1)::in, T1::out) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module require.
%---------------------------------------------------------------------------%
get_any_errors1(ok1(_)) = [].
get_any_errors1(error1(Specs)) = Specs.
get_any_errors2(ok2(_, _)) = [].
get_any_errors2(error2(Specs)) = Specs.
get_any_errors3(ok3(_, _, _)) = [].
get_any_errors3(error3(Specs)) = Specs.
get_any_errors4(ok4(_, _, _, _)) = [].
get_any_errors4(error4(Specs)) = Specs.
get_any_errors5(ok5(_, _, _, _, _)) = [].
get_any_errors5(error5(Specs)) = Specs.
%---------------------%
get_any_errors_warnings2(ok2(_, Specs)) = Specs.
get_any_errors_warnings2(error2(Specs)) = Specs.
get_any_errors_warnings3(ok3(_, _, Specs)) = Specs.
get_any_errors_warnings3(error3(Specs)) = Specs.
get_any_errors_warnings4(ok4(_, _, _, Specs)) = Specs.
get_any_errors_warnings4(error4(Specs)) = Specs.
get_any_errors_warnings5(ok5(_, _, _, _, Specs)) = Specs.
get_any_errors_warnings5(error5(Specs)) = Specs.
%---------------------%
project_ok1(Maybe1, Item) :-
(
Maybe1 = ok1(Item)
;
Maybe1 = error1(_Specs),
fail
).
det_project_ok1(Maybe1, Item) :-
(
Maybe1 = ok1(Item)
;
Maybe1 = error1(_Specs),
unexpected($pred, "error1")
).
%---------------------------------------------------------------------------%
:- end_module parse_tree.maybe_error.
%---------------------------------------------------------------------------%