mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 18:03:36 +00:00
compiler/mercury_compile_main.m:
The handle_given_options predicate, besides computing the direct effect
of a given list of command line arguments on the option table, also
- looks for and reports inconsistencies between option values,
- applies implications between options, and
- constructs the global structure.
The code in the initial part of mercury_compile_main.m has long had
calls to handle_given_options that did not really need any of this work
to be done. The calls were nevertheless there because the later code,
even though it needed unly the updated option table, could only
*use* that updated option table if it was part of a globals structure.
This diff makes a start on fixing that. It replaces two calls
to handle_given_options with calls to getopt.process_options_userdata_io,
which just returns the updated option table. It updates the code following
those two calls to use the updated option table directly, NOT through
a globals structure. The rest of this diff is there to make this possible.
compiler/check_libgrades.m:
Make maybe_detect_stdlib_grades take an option_table, not a globals
structure.
compiler/write_error_spec.m:
Provide a version of write_error_specs that takes an option_table,
not a globals structure.
The changes in the following modules are there to implement this change.
compiler/compiler_util.m:
Provide a version of record_warning that takes an option_table,
not a globals structure.
compiler/error_sort.m:
Provide a version of sort_error_specs that takes an option_table,
not a globals structure.
compiler/error_spec.m:
Provide a version of extract_spec_msgs that takes an option_table,
not a globals structure.
compiler/error_util.m:
Do the same for several functions dealing with severities.
132 lines
4.4 KiB
Mathematica
132 lines
4.4 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-2006, 2009-2010 The University of Melbourne.
|
|
% Copyright (C) 2014-2015, 2018 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.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% 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 libs.globals.
|
|
:- import_module libs.options.
|
|
:- import_module parse_tree.
|
|
:- import_module parse_tree.error_spec.
|
|
|
|
:- import_module io.
|
|
:- import_module list.
|
|
:- import_module maybe.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred maybe_is_error(maybe_error::in, string::out) is semidet.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% This type is useful when defining options and behaviours that may
|
|
% raise either an error or a warning. See
|
|
% pragma_require_tail_recursion.
|
|
%
|
|
:- type warning_or_error
|
|
---> we_warning
|
|
; we_error.
|
|
|
|
% warning_or_error_string(we_warning, "warn").
|
|
% warning_or_error_string(we_error, "error").
|
|
%
|
|
:- pred warning_or_error_string(warning_or_error, string).
|
|
:- mode warning_or_error_string(in, out) is det.
|
|
:- mode warning_or_error_string(out, in) is semidet.
|
|
|
|
:- pred warning_or_error_severity(warning_or_error::in, error_severity::out)
|
|
is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred add_error(error_phase::in, list(format_piece)::in,
|
|
list(error_spec)::in, list(error_spec)::out) is det.
|
|
|
|
:- pred add_warning(error_phase::in, list(format_piece)::in,
|
|
list(error_spec)::in, list(error_spec)::out) 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(globals::in, io::di, io::uo) is det.
|
|
:- pred record_warning_opt_table(option_table::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.text_output_stream::in, globals::in, string::in,
|
|
io::di, io::uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module bool.
|
|
:- import_module getopt.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
maybe_is_error(error(Error), Error).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
warning_or_error_string(we_warning, "warn").
|
|
warning_or_error_string(we_error, "error").
|
|
|
|
warning_or_error_severity(we_warning, severity_warning).
|
|
warning_or_error_severity(we_error, severity_error).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
add_error(Phase, Pieces, !Specs) :-
|
|
Spec = simplest_no_context_spec($pred, severity_error, Phase, Pieces),
|
|
!:Specs = [Spec | !.Specs].
|
|
|
|
add_warning(Phase, Pieces, !Specs) :-
|
|
Spec = simplest_no_context_spec($pred, severity_warning, Phase, Pieces),
|
|
!:Specs = [Spec | !.Specs].
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
record_warning(Globals, !IO) :-
|
|
globals.lookup_bool_option(Globals, halt_at_warn, HaltAtWarn),
|
|
(
|
|
HaltAtWarn = yes,
|
|
io.set_exit_status(1, !IO)
|
|
;
|
|
HaltAtWarn = no
|
|
).
|
|
|
|
record_warning_opt_table(OptionTable, !IO) :-
|
|
getopt.lookup_bool_option(OptionTable, halt_at_warn, HaltAtWarn),
|
|
(
|
|
HaltAtWarn = yes,
|
|
io.set_exit_status(1, !IO)
|
|
;
|
|
HaltAtWarn = no
|
|
).
|
|
|
|
report_warning(Stream, Globals, Message, !IO) :-
|
|
record_warning(Globals, !IO),
|
|
io.write_string(Stream, Message, !IO).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module libs.compiler_util.
|
|
%-----------------------------------------------------------------------------%
|