mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
Simplify more code in mercury_compile_main.m.
compiler/mercury_compile_main.m:
Simplify the code interpreting the result of calls to lookup_mmc_options.
Eliminate the one remaining redundant computation of the
default option table.
compiler/options_file.m:
Expand the documentation of the predicates that read options files.
Document that the predicates that only look things up in the data
structures representing already-read-in options files can return
only errors, not warnings.
Delete a long-obsolete comment.
compiler/maybe_error.m:
Add a utility predicate that could be useful later. (I thought it
would be useful in this diff, but it wasn't.)
This commit is contained in:
@@ -83,6 +83,9 @@
|
||||
:- pred project_ok1(maybe1(T1)::in, T1::out) is semidet.
|
||||
:- pred det_project_ok1(maybe1(T1)::in, T1::out) is det.
|
||||
|
||||
:- pred separate_ok1_error1(list(maybe1(T1))::in,
|
||||
list(T1)::out, list(error_spec)::out) is det.
|
||||
|
||||
%---------------------------------------------------------------------------%
|
||||
%---------------------------------------------------------------------------%
|
||||
|
||||
@@ -139,6 +142,27 @@ det_project_ok1(Maybe1, Item) :-
|
||||
unexpected($pred, "error1")
|
||||
).
|
||||
|
||||
%---------------------%
|
||||
|
||||
separate_ok1_error1(Maybes, OKs, Specs) :-
|
||||
separate_ok1_error1_loop(Maybes, [], RevOKs, [], Specs),
|
||||
list.reverse(RevOKs, OKs).
|
||||
|
||||
:- pred separate_ok1_error1_loop(list(maybe1(T1))::in,
|
||||
list(T1)::in, list(T1)::out, list(error_spec)::in, list(error_spec)::out)
|
||||
is det.
|
||||
|
||||
separate_ok1_error1_loop([], !RevOKs, !Specs).
|
||||
separate_ok1_error1_loop([Maybe | Maybes], !RevOKs, !Specs) :-
|
||||
(
|
||||
Maybe = ok1(OK),
|
||||
!:RevOKs = [OK | !.RevOKs]
|
||||
;
|
||||
Maybe = error1(CurSpecs),
|
||||
!:Specs = CurSpecs ++ !.Specs
|
||||
),
|
||||
separate_ok1_error1_loop(Maybes, !RevOKs, !Specs).
|
||||
|
||||
%---------------------------------------------------------------------------%
|
||||
:- end_module parse_tree.maybe_error.
|
||||
%---------------------------------------------------------------------------%
|
||||
|
||||
@@ -248,8 +248,9 @@ real_main_after_expansion(ProgressStream, ErrorStream, CmdLineArgs, !IO) :-
|
||||
unexpected($pred,
|
||||
"extra arguments with --arg-file: " ++ string(ExtraArgs))
|
||||
),
|
||||
process_options_arg_file(ArgFile, DetectedGradeFlags, OptionsVariables,
|
||||
MaybeMCFlags, OptionArgs, NonOptionArgs, OptionSpecs, !IO)
|
||||
process_options_arg_file(DefaultOptionTable, ArgFile,
|
||||
DetectedGradeFlags, OptionsVariables, MaybeMCFlags,
|
||||
OptionArgs, NonOptionArgs, OptionSpecs, !IO)
|
||||
else
|
||||
process_options_std(ErrorStream, DefaultOptionTable, CmdLineArgs,
|
||||
DetectedGradeFlags, OptionsVariables, MaybeMCFlags,
|
||||
@@ -311,13 +312,14 @@ real_main_after_expansion(ProgressStream, ErrorStream, CmdLineArgs, !IO) :-
|
||||
io.set_exit_status(1, !IO)
|
||||
).
|
||||
|
||||
:- pred process_options_arg_file(string::in,
|
||||
:- pred process_options_arg_file(option_table::in, string::in,
|
||||
list(string)::out, options_variables::out, maybe(list(string))::out,
|
||||
list(string)::out, list(string)::out, list(error_spec)::out,
|
||||
io::di, io::uo) is det.
|
||||
|
||||
process_options_arg_file(ArgFile, DetectedGradeFlags, OptionsVariables,
|
||||
MaybeMCFlags, OptionArgs, NonOptionArgs, Specs, !IO) :-
|
||||
process_options_arg_file(DefaultOptionTable, ArgFile, DetectedGradeFlags,
|
||||
OptionsVariables, MaybeMCFlags, OptionArgs, NonOptionArgs,
|
||||
Specs, !IO) :-
|
||||
io.environment.get_environment_var_map(EnvVarMap, !IO),
|
||||
% All the configuration and options file options are passed in the
|
||||
% given file, which is created by the parent `mmc --make' process.
|
||||
@@ -338,11 +340,8 @@ process_options_arg_file(ArgFile, DetectedGradeFlags, OptionsVariables,
|
||||
(
|
||||
MaybeArgs1 = yes(Args1),
|
||||
% Separate the option args from the non-option args.
|
||||
% XXX HANDLE_OPTIONS Later calls to handle_given_options
|
||||
% will compute OptionTable0 again and again.
|
||||
% XXX HANDLE_OPTIONS Ignoring _MaybeError seems a bit careless.
|
||||
getopt.init_option_table(option_defaults, OptionTable0),
|
||||
getopt.record_arguments(short_option, long_option, OptionTable0,
|
||||
getopt.record_arguments(short_option, long_option, DefaultOptionTable,
|
||||
Args1, NonOptionArgs, OptionArgs, _MaybeError, _OptionValues)
|
||||
;
|
||||
MaybeArgs1 = no,
|
||||
@@ -353,11 +352,10 @@ process_options_arg_file(ArgFile, DetectedGradeFlags, OptionsVariables,
|
||||
OptionsVariables = options_variables_init(EnvVarMap),
|
||||
MaybeMCFlags = yes([]).
|
||||
|
||||
:- pred process_options_std(io.text_output_stream::in,
|
||||
option_table(option)::in, list(string)::in,
|
||||
list(string)::out, options_variables::out, maybe(list(string))::out,
|
||||
list(string)::out, list(string)::out, list(error_spec)::out,
|
||||
io::di, io::uo) is det.
|
||||
:- pred process_options_std(io.text_output_stream::in, option_table::in,
|
||||
list(string)::in, list(string)::out, options_variables::out,
|
||||
maybe(list(string))::out, list(string)::out, list(string)::out,
|
||||
list(error_spec)::out, io::di, io::uo) is det.
|
||||
|
||||
process_options_std(ErrorStream, DefaultOptionTable, CmdLineArgs,
|
||||
DetectedGradeFlags, OptionsVariables, MaybeMCFlags,
|
||||
@@ -369,7 +367,7 @@ process_options_std(ErrorStream, DefaultOptionTable, CmdLineArgs,
|
||||
% XXX Doing every task in handle_given_options is wasteful
|
||||
% in the very likely case of their being an option file.
|
||||
% We should do just enough to find the setting of the two options
|
||||
% whose values we look up right here.
|
||||
% whose values we look up right here, and the few options we need below.
|
||||
handle_given_options(ErrorStream, DefaultOptionTable, CmdLineArgs,
|
||||
OptionArgs, NonOptionArgs, _Errors0, ArgsGlobals, !IO),
|
||||
globals.lookup_accumulating_option(ArgsGlobals, options_search_directories,
|
||||
@@ -463,15 +461,15 @@ process_options_std_config_file(FlagsArgsGlobals, EnvVarMap, WarnUndef,
|
||||
(
|
||||
ConfigErrors = no,
|
||||
lookup_mmc_options(OptionsVariables, MaybeMCFlags1),
|
||||
Specs0 = ConfigSpecs ++ get_any_errors1(MaybeMCFlags1),
|
||||
Errors0 = contains_errors(FlagsArgsGlobals, Specs0),
|
||||
(
|
||||
Errors0 = no,
|
||||
det_project_ok1(MaybeMCFlags1, MCFlags1),
|
||||
MaybeMCFlags = yes(MCFlags1)
|
||||
MaybeMCFlags1 = ok1(MCFlags1),
|
||||
MaybeMCFlags = yes(MCFlags1),
|
||||
Specs0 = ConfigSpecs
|
||||
;
|
||||
Errors0 = yes,
|
||||
MaybeMCFlags = no
|
||||
MaybeMCFlags1 = error1(MCFlagsSpecs),
|
||||
% All error_specs in MCFlagsSpecs are errors, not warnings.
|
||||
MaybeMCFlags = no,
|
||||
Specs0 = ConfigSpecs ++ MCFlagsSpecs
|
||||
),
|
||||
% XXX Record _StdLibGrades in the final globals structure.
|
||||
maybe_detect_stdlib_grades(FlagsArgsGlobals, OptionsVariables,
|
||||
@@ -497,15 +495,15 @@ process_options_std_config_file(FlagsArgsGlobals, EnvVarMap, WarnUndef,
|
||||
DetectedGradeFlags = [],
|
||||
OptionsVariables = options_variables_init(EnvVarMap),
|
||||
lookup_mmc_options(OptionsVariables, MaybeMCFlags1),
|
||||
Specs = get_any_errors1(MaybeMCFlags1),
|
||||
Errors = contains_errors(FlagsArgsGlobals, Specs),
|
||||
(
|
||||
Errors = no,
|
||||
det_project_ok1(MaybeMCFlags1, MCFlags1),
|
||||
MaybeMCFlags = yes(MCFlags1)
|
||||
MaybeMCFlags1 = ok1(MCFlags1),
|
||||
MaybeMCFlags = yes(MCFlags1),
|
||||
Specs = []
|
||||
;
|
||||
Errors = yes,
|
||||
MaybeMCFlags = no
|
||||
MaybeMCFlags1 = error1(MCFlagsSpecs),
|
||||
% All error_specs in MCFlagsSpecs are errors, not warnings.
|
||||
MaybeMCFlags = no,
|
||||
Specs = MCFlagsSpecs
|
||||
)
|
||||
).
|
||||
|
||||
|
||||
@@ -46,9 +46,10 @@
|
||||
% assignments in those files (and the other files they may include, either
|
||||
% directly or indirectly) and return it as Variables.
|
||||
%
|
||||
% We return two lists of error specs. The second should be printed
|
||||
% only if the option warn_undefined_options_variables is set, while
|
||||
% the first list should be printed unconditionally.
|
||||
% We return two lists of error specs. The first list consists of errors,
|
||||
% which should be printed unconditionally. The second list consists
|
||||
% of warnings, which should be printed only if the option
|
||||
% warn_undefined_options_variables is set.
|
||||
%
|
||||
:- pred read_options_files_named_in_options_file_option(list(string)::in,
|
||||
list(string)::in, options_variables::out,
|
||||
@@ -61,9 +62,10 @@
|
||||
% --options-search-directories, updating the database of make variable
|
||||
% name/value pairs. This is used to read the configuration file.
|
||||
%
|
||||
% We return two lists of error specs. The second should be printed
|
||||
% only if the option warn_undefined_options_variables is set, while
|
||||
% the first list should be printed unconditionally.
|
||||
% We return two lists of error specs. The first list consists of errors,
|
||||
% which should be printed unconditionally. The second list consists
|
||||
% of warnings, which should be printed only if the option
|
||||
% warn_undefined_options_variables is set.
|
||||
%
|
||||
:- pred read_named_options_file(file_name::in,
|
||||
options_variables::in, options_variables::out,
|
||||
@@ -79,9 +81,10 @@
|
||||
%
|
||||
% This is not quite the same as @file syntax as the environment is ignored.
|
||||
%
|
||||
% We return two lists of error specs. The second should be printed
|
||||
% only if the option warn_undefined_options_variables is set, while
|
||||
% the first list should be printed unconditionally.
|
||||
% We return two lists of error specs. The first list consists of errors,
|
||||
% which should be printed unconditionally. The second list consists
|
||||
% of warnings, which should be printed only if the option
|
||||
% warn_undefined_options_variables is set.
|
||||
% XXX But see the comments near the only call to this predicate
|
||||
% in mercury_compile_main.m.
|
||||
%
|
||||
@@ -90,6 +93,13 @@
|
||||
io::di, io::uo) is det.
|
||||
|
||||
%---------------------------------------------------------------------------%
|
||||
%
|
||||
% If any of the following predicates return error1(Specs), Specs will
|
||||
% contain only errors, not warnings. (There is only one piece of code
|
||||
% in this module that generates an error_spec with severity_warning,
|
||||
% and the only exported operations whose call tree includes that code
|
||||
% are ones listed *above*.)
|
||||
%
|
||||
|
||||
% Look up $(MAIN_TARGET).
|
||||
%
|
||||
@@ -410,14 +420,6 @@ read_options_file_params(SearchInfo, PreStack0, IsOptionsFileOptional,
|
||||
[s(FoundDir/FileToFind)], !TIO)
|
||||
),
|
||||
|
||||
% XXX Instead of setting and unsetting the input stream,
|
||||
% we should simply pass FoundStream to read_options_lines.
|
||||
% However, when I (zs) tried that, I quickly found that
|
||||
% the call tree of read_options_lines includes many predicates
|
||||
% for which it is not at all clear whether they *intend*
|
||||
% to read from a current standard input that originates as
|
||||
% FoundStream, or they just *happen* to do so.
|
||||
|
||||
SubSearchInfo = search_info(yes(FoundDir), Search),
|
||||
read_options_lines(SubSearchInfo, InclStack0,
|
||||
FoundStream, FileToFind, 1, !Variables,
|
||||
|
||||
Reference in New Issue
Block a user