mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 06:47:17 +00:00
Estimated hours taken: 1.5 Branches: main Move the stuff currently in hlds_pred.m that deals with clauses into a new module, hlds_clauses.m. Move the stuff currently in hlds_pred.m that deals with RTTI into a new module, hlds_rtti.m. Move the stuff currently in hlds_module.m that deals with predicate tables into a new module, pred_table.m. These changes make hlds_pred.m and hlds_module.m much more cohesive, but there are no changes in algorithms. compiler/hlds_clauses.m: compiler/hlds_rtti.m: compiler/pred_table.m: New modules as described above. In some cases, fix mixleading or ambiguous predicate names in the process, and convert a few predicates to functions. compiler/hlds_pred.m: compiler/hlds_module.m: Delete the stuff moved to other modules. compiler/*.m: In modules that need the functionality moved a new module, import the new module. It is rare for all the new modules to be needed, and many modules don't need any of the new modules at all. (For example, of the 200+ modules that import hlds_module.m, only about 40 need pred_table.m.) Conform to the few minor changes to e.g. predicate names. compiler/notes/compiler_design.html: Document the new modules.
117 lines
3.6 KiB
Mathematica
117 lines
3.6 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-2006 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: compiler_util.
|
|
% Main author: zs.
|
|
%
|
|
% This module contains code that can be helpful in any compiler module.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module libs.compiler_util.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Call error/1 with a "Sorry, not implemented" message.
|
|
%
|
|
% Use this for features that should be implemented (or at least could be
|
|
% implemented).
|
|
%
|
|
:- func sorry(string, string) = _ is erroneous.
|
|
:- pred sorry(string::in, string::in) is erroneous.
|
|
|
|
% unexpected(ModuleName, Message):
|
|
%
|
|
% Call error/1 with an "Unexpected" message.
|
|
% Use this to handle cases which are not expected to arise (i.e. bugs).
|
|
%
|
|
:- func unexpected(string, string) = _ is erroneous.
|
|
:- pred unexpected(string::in, string::in) is erroneous.
|
|
|
|
% expect(Goal, ModuleName, Message):
|
|
%
|
|
% Call Goal, and call unexpected(ModuleName, Message) if Goal fails.
|
|
%
|
|
:- pred expect((pred)::((pred) is semidet), string::in, string::in) is det.
|
|
|
|
% Record the fact that a warning has been issued; set the exit status
|
|
% to error if the `--halt-at-warn' option is set.
|
|
%
|
|
:- pred record_warning(io::di, io::uo) is det.
|
|
|
|
% Report a warning, and set the exit status to error if the
|
|
% `--halt-at-warn' option is set.
|
|
%
|
|
:- pred report_warning(string::in, io::di, io::uo) is det.
|
|
|
|
% Report a warning to the specified stream, and set the exit status
|
|
% to error if the --halt-at-warn option is set.
|
|
%
|
|
:- pred report_warning(io.output_stream::in, string::in, io::di, io::uo)
|
|
is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module libs.globals.
|
|
:- import_module libs.options.
|
|
|
|
:- import_module bool.
|
|
:- import_module list.
|
|
:- import_module require.
|
|
:- import_module string.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Call error/1 with a "Sorry, not implemented" message.
|
|
%
|
|
sorry(Module, What) = _ :- sorry(Module, What).
|
|
sorry(Module, What) :-
|
|
string.format("%s: Sorry, not implemented: %s",
|
|
[s(Module), s(What)], ErrorMessage),
|
|
error(ErrorMessage).
|
|
|
|
unexpected(Module, What) = _ :- unexpected(Module, What).
|
|
unexpected(Module, What) :-
|
|
string.format("%s: Unexpected: %s", [s(Module), s(What)], ErrorMessage),
|
|
error(ErrorMessage).
|
|
|
|
expect(Goal, Module, Message) :-
|
|
( Goal ->
|
|
true
|
|
;
|
|
unexpected(Module, Message)
|
|
).
|
|
|
|
record_warning(!IO) :-
|
|
globals.io_lookup_bool_option(halt_at_warn, HaltAtWarn, !IO),
|
|
(
|
|
HaltAtWarn = yes,
|
|
io.set_exit_status(1, !IO)
|
|
;
|
|
HaltAtWarn = no
|
|
).
|
|
|
|
report_warning(Message, !IO) :-
|
|
record_warning(!IO),
|
|
io.write_string(Message, !IO).
|
|
|
|
report_warning(Stream, Message, !IO) :-
|
|
record_warning(!IO),
|
|
io.write_string(Stream, Message, !IO).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module compiler_util.
|
|
%-----------------------------------------------------------------------------%
|