[m-rev.] for review: make mmc -f warn about multiply defined modules

Peter Wang wangp at students.csse.unimelb.edu.au
Mon Apr 2 14:12:08 AEST 2007


Branches: main

compiler/source_file_map.m:
	When generating a source file mapping, warn if a module is defined in
	multiple files.


Index: compiler/source_file_map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/source_file_map.m,v
retrieving revision 1.20
diff -u -r1.20 source_file_map.m
--- compiler/source_file_map.m	1 Dec 2006 15:04:20 -0000	1.20
+++ compiler/source_file_map.m	1 Apr 2007 09:00:02 -0000
@@ -55,6 +55,7 @@
 :- import_module dir.
 :- import_module map.
 :- import_module maybe.
+:- import_module set.
 :- import_module string.
 
 %-----------------------------------------------------------------------------%
@@ -177,7 +178,8 @@
     io.open_output(ModulesFileName, OpenRes, !IO),
     (
         OpenRes = ok(Stream),
-        list.foldl(write_source_file_map_2(Stream), FileNames, !IO),
+        list.foldl2(write_source_file_map_2(Stream), FileNames, set.init, _,
+            !IO),
         io.close_output(Stream, !IO)
     ;
         OpenRes = error(Error),
@@ -189,12 +191,22 @@
     ).
 
 :- pred write_source_file_map_2(io.output_stream::in, file_name::in,
-    io::di, io::uo) is det.
+    set(module_name)::in, set(module_name)::out, io::di, io::uo) is det.
 
-write_source_file_map_2(MapStream, FileName, !IO) :-
+write_source_file_map_2(MapStream, FileName, SeenModules0, SeenModules, !IO) :-
     find_module_name(FileName, MaybeModuleName, !IO),
     (
         MaybeModuleName = yes(ModuleName),
+        ( set.contains(SeenModules0, ModuleName) ->
+            io.write_string("mercury_compile: module `", !IO),
+            io.write_string(sym_name_to_string(ModuleName), !IO),
+            io.write_string("' defined in multiple files.", !IO),
+            io.nl(!IO),
+            io.set_exit_status(1, !IO),
+            SeenModules = SeenModules0
+        ;
+            set.insert(SeenModules0, ModuleName, SeenModules)
+        ),
         ( string.remove_suffix(FileName, ".m", PartialFileName0) ->
             PartialFileName = PartialFileName0
         ;
@@ -218,7 +230,8 @@
             io.set_output_stream(OldStream, _, !IO)
         )
     ;
-        MaybeModuleName = no
+        MaybeModuleName = no,
+        SeenModules = SeenModules0
     ).
 
 :- func modules_file_name = string.
--------------------------------------------------------------------------
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