[m-rev.] diff: check MLLIBS in Mercury.options

Simon Taylor staylr at gmail.com
Thu Dec 14 16:38:16 AEDT 2006



Estimated hours taken: 3
Branches: main

compiler/options_file.m:
	Check MLLIBS contains only `-l' options.

	Use error_util.m

tests/invalid/invalid_mllibs.{m,err_exp}:
tests/invalid/Mercury.options.invalid:
	Test case.

Index: compiler/options_file.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options_file.m,v
retrieving revision 1.41
diff -u -u -r1.41 options_file.m
--- compiler/options_file.m	1 Dec 2006 15:04:13 -0000	1.41
+++ compiler/options_file.m	13 Dec 2006 11:07:52 -0000
@@ -138,10 +138,10 @@
                 "arguments file does not set MCFLAGS.\n", !IO),
             MaybeMCFlags = no
         ;
-            FlagsResult = var_result_error(Msg),
+            FlagsResult = var_result_error(ErrorSpec),
             MaybeMCFlags = no,
-            io.write_string(Msg, !IO),
-            io.nl(!IO)
+            globals.io_get_globals(Globals, !IO),
+            write_error_spec(ErrorSpec, Globals, 0, _, 0, _, !IO)
         )
     ;
         MaybeVariables = no,
@@ -271,10 +271,14 @@
                 ;
                     ErrorFile = FileToFind
                 ),
-                io.write_string("Error reading options file `", !IO),
-                io.write_string(ErrorFile, !IO),
-                io.write_string("'.\n", !IO),
-                io.set_exit_status(1, !IO)
+                ErrorSpec = error_spec(severity_error, phase_read_files,
+                        [error_msg(no, no, 0,
+                            [always([words("Error reading options file"),
+                                quote(ErrorFile), suffix(".")])
+                            ])
+                        ]),
+                globals.io_get_globals(Globals, !IO),
+                write_error_spec(ErrorSpec, Globals, 0, _, 0, _, !IO)
             ;
                 ErrorIfNotExist = no_error
             )
@@ -893,7 +897,7 @@
     % libraries).
     % `MERCURY_STDLIB_DIR' and `MERCURY_CONFIG_DIR' should come before
     % `MCFLAGS'. Settings in `MCFLAGS' (e.g. `--no-mercury-stdlib-dir')
-    % should override settings of these MERCURY_STDLIB_DIR in the environment.
+    % should override settings of these in the environment.
 options_variable_types =
     [grade_flags, linkage, mercury_linkage, lib_grades, lib_linkages,
     stdlib_dir, config_dir, mmc_flags, c_flags, java_flags, ilasm_flags,
@@ -1012,7 +1016,7 @@
 :- type variable_result(T)
     --->    var_result_set(T)
     ;       var_result_unset
-    ;       var_result_error(string).
+    ;       var_result_error(error_spec).
 
 :- pred lookup_options_variable(options_variables::in,
     options_variable_class::in, options_variable_type::in,
@@ -1050,11 +1054,50 @@
     %       Failing to maintain this order will result in the user being unable
     %       to override the default value of many of the compiler's options.
     %
-    Result =
+    Result0 =
         DefaultFlagsResult  `combine_var_results`
         FlagsResult         `combine_var_results`
         ExtraFlagsResult    `combine_var_results`
-        ModuleFlagsResult.
+        ModuleFlagsResult,
+
+    %
+    % Check the result is valid for the variable type.
+    %
+    (
+        Result0 = var_result_unset, Result = var_result_unset
+    ;
+        Result0 = var_result_error(E), Result = var_result_error(E)
+    ;
+        Result0 = var_result_set(V),
+        ( FlagsVar = ml_libs ->
+            BadLibs = list.filter(
+                        (pred(LibFlag::in) is semidet :-
+                                \+ string__prefix(LibFlag, "-l")
+                                
+                        ), V),
+            (
+                BadLibs = [],
+                Result = Result0
+            ;
+                BadLibs = [_ | _],
+                ErrorSpec = error_spec(severity_error, phase_read_files,
+                        [error_msg(no, no, 0,
+                            [always([words("Error: MLLIBS must contain only"),
+                                words("`-l' options, found") |
+                                list_to_pieces(
+                                    map(func(Lib) = add_quotes(Lib), BadLibs))]
+                                ++ [suffix(".")]
+                            )]
+                        )]
+                    ),
+                globals.io_get_globals(Globals, !IO),
+                write_error_spec(ErrorSpec, Globals, 0, _, 0, _, !IO),
+                Result = var_result_error(ErrorSpec)
+            )
+        ;
+            Result = Result0
+        )
+    ).
 
 :- func combine_var_results(variable_result(list(T)), variable_result(list(T)))
     = variable_result(list(T)).
@@ -1076,9 +1119,9 @@
 
 lookup_variable_words_report_error(Vars, VarName, Result, !IO) :-
     lookup_variable_words(Vars, VarName, Result, !IO),
-    ( Result = var_result_error(Error) ->
-        io.write_string(Error, !IO),
-        io.nl(!IO)
+    ( Result = var_result_error(ErrorSpec) ->
+        globals.io_get_globals(Globals, !IO),
+        write_error_spec(ErrorSpec, Globals, 0, _, 0, _, !IO)
     ;
         true
     ).
@@ -1109,8 +1152,15 @@
             Result = var_result_set(EnvWords)
         ;
             SplitResult = error(Msg),
-            Result = var_result_error("Error: in environment variable `"
-                ++ VarName ++ "': " ++ Msg)
+            
+            ErrorSpec = error_spec(severity_error, phase_read_files,
+                        [error_msg(no, no, 0,
+                            [always([words("Error: in environment variable"),
+                                quote(VarName), suffix(":"), words(Msg)
+                            ])]
+                        )]
+                    ),
+            Result = var_result_error(ErrorSpec)
         )
     ;
         MaybeEnvValue = no,
Index: tests/invalid/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mercury.options,v
retrieving revision 1.18
diff -u -u -r1.18 Mercury.options
--- tests/invalid/Mercury.options	5 Dec 2006 03:51:18 -0000	1.18
+++ tests/invalid/Mercury.options	13 Dec 2006 11:07:52 -0000
@@ -42,6 +42,9 @@
 				--no-automatic-intermodule-optimization \
 				--verbose-error-messages
 MCFLAGS-invalid_event =		--event-set-file-name invalid_event_spec
+MCFLAGS-invalid_mllibs =	--no-errorcheck-only --no-verbose-make \
+				--options-file Mercury.options.invalid \
+				--make invalid_mllibs
 MCFLAGS-loopcheck =		--warn-inferred-erroneous \
 				--verbose-error-messages
 MCFLAGS-method_impl =		--no-intermodule-optimization \
Index: tests/invalid/Mercury.options.invalid
===================================================================
RCS file: tests/invalid/Mercury.options.invalid
diff -N tests/invalid/Mercury.options.invalid
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/Mercury.options.invalid	14 Dec 2006 05:36:24 -0000
@@ -0,0 +1,3 @@
+# Test that we give a proper error message for words in MLLIBS that
+# aren't `-l' options.
+MLLIBS = invalid sdfksjdkljs 
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.202
diff -u -u -r1.202 Mmakefile
--- tests/invalid/Mmakefile	28 Nov 2006 06:17:21 -0000	1.202
+++ tests/invalid/Mmakefile	13 Dec 2006 11:07:52 -0000
@@ -106,6 +106,7 @@
 	invalid_export_detism \
 	invalid_import_detism \
 	invalid_main \
+	invalid_mllibs \
 	invalid_new \
 	invalid_typeclass \
 	io_in_ite_cond \
Index: tests/invalid/invalid_mllibs.err_exp
===================================================================
RCS file: tests/invalid/invalid_mllibs.err_exp
diff -N tests/invalid/invalid_mllibs.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/invalid_mllibs.err_exp	14 Dec 2006 04:09:40 -0000
@@ -0,0 +1,2 @@
+Error: MLLIBS must contain only `-l' options, found `invalid' and
+  `sdfksjdkljs'.
Index: tests/invalid/invalid_mllibs.m
===================================================================
RCS file: tests/invalid/invalid_mllibs.m
diff -N tests/invalid/invalid_mllibs.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/invalid_mllibs.m	14 Dec 2006 04:09:40 -0000
@@ -0,0 +1,14 @@
+% "Hello World" in Mercury.
+
+% This source file is hereby placed in the public domain.  -fjh (the author).
+
+:- module invalid_mllibs.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+main(!IO) :-
+	io.write_string("Hello, world\n", !IO).
Index: tests/invalid/string_format_bad.m
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/string_format_bad.m,v
retrieving revision 1.2
diff -u -u -r1.2 string_format_bad.m
--- tests/invalid/string_format_bad.m	9 Nov 2006 00:47:27 -0000	1.2
+++ tests/invalid/string_format_bad.m	14 Dec 2006 04:03:26 -0000
@@ -15,6 +15,7 @@
 :- import_module int.
 :- import_module list.
 :- import_module stream.
+:- import_module stream.string_writer.
 :- import_module string.
 
 main(!IO) :-
@@ -25,7 +26,7 @@
     io.stdout_stream(OutputStream, !IO),
     io.format("%d", [s("x3")], !IO),
     io.format(OutputStream, "%d", [s("x4")], !IO),
-    stream.format(OutputStream, "%d", [s("x4")], !IO),
+    stream.string_writer.format(OutputStream, "%d", [s("x4")], !IO),
     io.format("%w", [i(5)], !IO),
     io.write_string(p(s("five")), !IO),
     F6 = "%s %f",
Index: tests/invalid/string_format_unknown.m
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/string_format_unknown.m,v
retrieving revision 1.2
diff -u -u -r1.2 string_format_unknown.m
--- tests/invalid/string_format_unknown.m	9 Nov 2006 00:47:27 -0000	1.2
+++ tests/invalid/string_format_unknown.m	14 Dec 2006 04:02:56 -0000
@@ -15,6 +15,7 @@
 :- import_module int.
 :- import_module list.
 :- import_module stream.
+:- import_module stream.string_writer.
 :- import_module string.
 
 main(!IO) :-
@@ -37,7 +38,7 @@
         V6 = [s("six"), V6A],
         copy(V6, C6),
         io.format(OutputStream, F6, C6, !IO),
-        stream.format(OutputStream, F6, C6, !IO),
+        stream.string_writer.format(OutputStream, F6, C6, !IO),
         make_bool(7, T7),
         F7 = "%d %s %d",
         (
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list