[m-rev.] Bugfix and new option

Ralph Becket rafe at cs.mu.OZ.AU
Mon Aug 16 17:15:04 AEST 2004


Estimated hours taken: 1
Branches: main

Fix a compiler abort when given an unrecognised option due to the IO state
globals field not being initialised on time.

Add a `--version' option to the compiler.

compiler/handle_options.m:
	Add display_compiler_version/2 and make usage/2 use it.

compiler/mercury_compile.m:
	Add code to handle the `--version' option.
	Fix a bug by ensuring the IO state globals field is initialised
	before it is read.

compiler/options.m:
	Add the `--version' option.

Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.208
diff -u -r1.208 handle_options.m
--- compiler/handle_options.m	20 Jul 2004 04:40:58 -0000	1.208
+++ compiler/handle_options.m	23 Jul 2004 06:04:16 -0000
@@ -35,7 +35,11 @@
 :- pred process_options(list(string)::in, list(string)::out, list(string)::out,
 	maybe_option_table(option)::out) is det.
 
-	% usage_errors(Message)
+	% Display the compiler version.
+	%
+:- pred display_compiler_version(io::di, io::uo) is det.
+
+	% usage_error(Descr, Message)
 	%
 	% Display given list of error messages and then the usage message.
 :- pred usage_errors(list(string)::in, io::di, io::uo) is det.
@@ -1523,16 +1527,21 @@
 	io__set_exit_status(1, !IO),
 	usage(!IO).
 
+display_compiler_version(!IO) :-
+	library__version(Version),
+	io__write_strings([
+		"Mercury Compiler, version ", Version, "\n",
+		"Copyright (C) 1993-2004 The University of Melbourne\n"
+	], !IO).
+
 usage(!IO) :-
 	% usage is called from many places; ensure that we don't print the
 	% duplicate copies of the message.
 	globals__io_printing_usage(AlreadyPrinted, !IO),
 	(
 		AlreadyPrinted = no,
-		library__version(Version),
+		display_compiler_version(!IO),
 		io__write_strings([
-			"Mercury Compiler, version ", Version, "\n",
-			"Copyright (C) 1993-2004 The University of Melbourne\n",
 			"Usage: mmc [<options>] <arguments>\n",
 			"Use `mmc --help' for more information.\n"
 		], !IO)
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.312
diff -u -r1.312 mercury_compile.m
--- compiler/mercury_compile.m	20 Jul 2004 04:41:02 -0000	1.312
+++ compiler/mercury_compile.m	16 Aug 2004 06:57:22 -0000
@@ -177,6 +177,10 @@
 	io__set_output_stream(StdErr, _, !IO),
 	io__command_line_arguments(Args0, !IO),
 
+	% read_args_file and globals__io_printing_usage may attempt
+	% to look up options, so we need to initialize the globals.
+	handle_options([], _, _, _, _, !IO),
+
 	( Args0 = ["--arg-file", ArgFile] ->
 		%
 		% All the configuration and options file options
@@ -184,10 +188,6 @@
 		% by the parent `mmc --make' process.
 		%
 
-		% read_args_file may attempt to look up options,
-		% so we need to initialize the globals..
-		handle_options([], _, _, _, _, !IO),
-
 		options_file__read_args_file(ArgFile, MaybeArgs1, !IO),
 		(
 			MaybeArgs1 = yes(Args1),
@@ -333,6 +333,7 @@
 	usage_errors(Errors, !IO).
 main_2([], OptionVariables, OptionArgs, Args, Link, !IO) :-
 	globals__io_get_globals(Globals, !IO),
+	globals__lookup_bool_option(Globals, version, Version),
 	globals__lookup_bool_option(Globals, help, Help),
 	globals__lookup_bool_option(Globals, generate_source_file_mapping,
 		GenerateMapping),
@@ -345,7 +346,12 @@
 	globals__lookup_bool_option(Globals, filenames_from_stdin,
 		FileNamesFromStdin),
 	globals__lookup_bool_option(Globals, make, Make),
-	( Help = yes ->
+	( Version = yes ->
+		io__stdout_stream(Stdout, !IO),
+		io__set_output_stream(Stdout, OldOutputStream, !IO),
+		display_compiler_version(!IO),
+		io__set_output_stream(OldOutputStream, _, !IO)
+	; Help = yes ->
 		io__stdout_stream(Stdout, !IO),
 		io__set_output_stream(Stdout, OldOutputStream, !IO),
 		long_usage(!IO),
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.429
diff -u -r1.429 options.m
--- compiler/options.m	20 Jul 2004 04:41:04 -0000	1.429
+++ compiler/options.m	23 Jul 2004 03:38:30 -0000
@@ -678,6 +678,7 @@
 					% section
 		;	aditi_user
 		;	help
+		;	version
 		;	fullarch
 		;	compiler_sufficiently_recent
 				% This option is used to test that the compiler
@@ -1307,6 +1308,7 @@
 	aditi			-	bool(no),
 	aditi_user		-	string(""),
 	help 			-	bool(no),
+	version			-	bool(no),
 	fullarch		-	string(""),
 	compiler_sufficiently_recent
 				-	bool(no)
@@ -1966,6 +1968,7 @@
 
 % misc options
 long_option("help",			help).
+long_option("version",			version).
 long_option("filenames-from-stdin",	filenames_from_stdin).
 long_option("aditi",			aditi).
 long_option("aditi-user",		aditi_user).
@@ -4125,7 +4128,9 @@
 		"\tpredicates, and is also used for security checks.",
 		"\tDefaults to the value of the `USER' environment",
 		"\tvariable. If `$USER' is not set, `--aditi-user'",
-		"\tdefaults to the string ""guest""."
+		"\tdefaults to the string ""guest"".",
+		"--version",
+		"\tDisplay the compiler version."
 
 		% The `--fullarch' option is reserved for
 		% use by the `Mercury.config' file.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list