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

Peter Wang wangp at students.csse.unimelb.edu.au
Mon Apr 2 16:22:34 AEST 2007


On 2007-04-02, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> 
> On Mon, 2 Apr 2007, Peter Wang wrote:
> 
> >Branches: main
> >
> >compiler/source_file_map.m:
> >	When generating a source file mapping, warn if a module is defined in
> >	multiple files.
...
> That's fine although it would also be useful to know what files
> define the same module.

Ok, committed this revised version:

Index: compiler/source_file_map.m
===================================================================
RCS file: /home/mercury/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	2 Apr 2007 06:21:01 -0000
@@ -177,7 +177,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,
+            map.init, _, !IO),
         io.close_output(Stream, !IO)
     ;
         OpenRes = error(Error),
@@ -189,12 +190,26 @@
     ).
 
 :- pred write_source_file_map_2(io.output_stream::in, file_name::in,
+    map(module_name, file_name)::in, map(module_name, file_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),
+        ( map.search(SeenModules0, ModuleName, PrevFileName) ->
+            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.write_string(PrevFileName, !IO),
+            io.write_string(", ", !IO),
+            io.write_string(FileName, !IO),
+            io.write_string(".\n", !IO),
+            io.set_exit_status(1, !IO),
+            SeenModules = SeenModules0
+        ;
+            map.det_insert(SeenModules0, ModuleName, FileName, SeenModules)
+        ),
         ( string.remove_suffix(FileName, ".m", PartialFileName0) ->
             PartialFileName = PartialFileName0
         ;
@@ -218,7 +233,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