[m-rev.] for review: warn about the deprecated module qualifier

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Feb 9 15:59:37 AEDT 2005


Estimated hours taken: 2
Branches: release

Add a warning for the use of the deprecated module qualifier `:'.
Doing this via a global variable is a bit hacky but it's only
for the 0.12 release and it's easier than reworking the parser
to do it properly.

compiler/prog_io.m:
	Add a global variable and some impure predicates to get/set
	it's value that we can use to record whether the parser
	encountered `:' used as a module qualifier.  We can't use the IO
	state here because these need to be called from within semidet code.

	Emit a warning if a module uses `:' as a module qualifier.

	In error messages about qualified terms that cannot be parsed
	don't refer to module qualifier as `:' if it was `.'.

	Delete a duplicate import of parse_tree.modules.

Julien.

Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.234.2.2
diff -u -r1.234.2.2 prog_io.m
--- compiler/prog_io.m	8 Feb 2005 07:39:15 -0000	1.234.2.2
+++ compiler/prog_io.m	9 Feb 2005 04:40:53 -0000
@@ -264,7 +264,7 @@

 :- import_module libs__globals.
 :- import_module libs__options.
-:- import_module parse_tree__modules.
+:- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_io_dcg.
 :- import_module parse_tree__prog_io_goal.
@@ -282,12 +282,31 @@

 %-----------------------------------------------------------------------------%

+:- pragma promise_pure(prog_io.read_module/11).
 prog_io__read_module(OpenFile, DefaultModuleName,
 		ReturnTimestamp, Error, FileData, ModuleName,
 		Messages, Items, MaybeModuleTimestamp, !IO) :-
 	prog_io__read_module_2(OpenFile, DefaultModuleName,
 		no, ReturnTimestamp, Error, FileData, ModuleName,
-		Messages, Items, MaybeModuleTimestamp, !IO).
+		Messages, Items, MaybeModuleTimestamp, !IO),
+	impure get_deprecated_module_qualifier_flag(UsesDeprecatedQual),
+	( UsesDeprecatedQual = yes ->
+		Warning = [
+			words("Warning: the module"),
+			sym_name(ModuleName),
+			words("uses the deprecated module qualifier `:'."),
+			words("Use `.' instead.")
+		],
+		write_error_pieces_plain(Warning, !IO),
+		record_warning(!IO),
+		%
+		% Reset this global variable so the we don't get
+		% warnings for the next module.
+		%
+		impure set_deprecated_module_qualifier_flag(no)
+	;
+		true
+	).

 prog_io__read_module_if_changed(OpenFile, DefaultModuleName,
 		OldTimestamp, Error, FileData, ModuleName, Messages,
@@ -3962,6 +3981,33 @@

 %-----------------------------------------------------------------------------%

+% In order to issue warning messages for `:' as a module qualifier
+% we set a boolean global variable to yes if `:' as module qualifier
+% is encountered while parsing a module.
+
+:- pragma foreign_decl("C", "extern MR_Bool MC_old_module_qualifier;").
+:- pragma foreign_code("C", "MR_Bool MC_old_module_qualifier = MR_NO;").
+
+:- impure pred set_deprecated_module_qualifier_flag(bool::in) is det.
+:- pragma foreign_proc("C",
+	set_deprecated_module_qualifier_flag(Value::in),
+	[will_not_call_mercury],
+"
+	MC_old_module_qualifier = Value;
+").
+set_deprecated_module_qualifier_flag(_) :- impure private_builtin.imp.
+
+:- impure pred get_deprecated_module_qualifier_flag(bool::out) is det.
+:- pragma foreign_proc("C",
+	get_deprecated_module_qualifier_flag(Value::out),
+	[will_not_call_mercury],
+"
+	Value = MC_old_module_qualifier;
+").
+get_deprecated_module_qualifier_flag(no) :- impure private_builtin.imp.
+
+%-----------------------------------------------------------------------------%
+
 %	A QualifiedTerm is one of
 %		Name(Args)
 %		Module:Name(Args)
@@ -3997,6 +4043,7 @@
 		Result = Result0
 	).

+:- pragma promise_pure(parse_qualified_term/4).
 parse_qualified_term(Term, ContainingTerm, Msg, Result) :-
 	(
 		Term = term__functor(term__atom(FunctorName),
@@ -4011,17 +4058,27 @@
 			parse_symbol_name(ModuleTerm, ModuleResult),
 			(
 				ModuleResult = ok(Module),
+				( FunctorName = ":" ->
+					impure
+					set_deprecated_module_qualifier_flag(
+						yes)
+				;
+					true
+				),
 				Result = ok(qualified(Module, Name), Args)
+
 			;
 				ModuleResult = error(_, _),
 				term__coerce(Term, ErrorTerm),
 				Result = error("module name identifier " ++
-					"expected before ':' in " ++
-					"qualified symbol name", ErrorTerm)
+					"expected before '" ++ FunctorName ++
+					"' in " ++ "qualified symbol name",
+					ErrorTerm)
 			)
 		;
 			term__coerce(Term, ErrorTerm),
-			Result = error("identifier expected after ':' " ++
+			Result = error("identifier expected after '"
+				++ FunctorName ++ "' " ++
 				"in qualified symbol name", ErrorTerm)
 		)
 	;

--------------------------------------------------------------------------
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