[m-rev.] diff: fix a bug in get_comment_forwards

Peter Ross pro at missioncriticalit.com
Tue Nov 14 15:03:49 AEDT 2006


Hi,


===================================================================


Estimated hours taken: 0.5
Branches: main

compiler/xml_documentation.m:
	Fix a bug where get_comment_forwards was recursivey calling
	get_comment_backwards.
	If we try and look up a comment for a line which doesn't exist
	(can happen if we search for a continuation of a comment before
	the first line of the module or after the last line of the module)
	we now return the "" instead of throwing an exception.


Index: compiler/xml_documentation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/xml_documentation.m,v
retrieving revision 1.7
diff -u -r1.7 xml_documentation.m
--- compiler/xml_documentation.m	9 Nov 2006 04:28:03 -0000	1.7
+++ compiler/xml_documentation.m	14 Nov 2006 04:00:32 -0000
@@ -250,16 +250,19 @@
 :- func get_comment_forwards(comments, int) = string.
 
 get_comment_forwards(Comments, Line) = Comment :-
-    LineType = map.lookup(Comments ^ line_types, Line),
-    (
-        LineType = comment(CurrentComment),
-        CommentBelow = get_comment_backwards(Comments, Line + 1),
-        Comment = CurrentComment ++ CommentBelow
+    ( map.search(Comments ^ line_types, Line, LineType) ->
+        (
+            LineType = comment(CurrentComment),
+            CommentBelow = get_comment_forwards(Comments, Line + 1),
+            Comment = CurrentComment ++ CommentBelow
+        ;
+            ( LineType = blank
+            ; LineType = code
+            ; LineType = code_and_comment(_)
+            ),
+            Comment = ""
+        )
     ;
-        ( LineType = blank
-        ; LineType = code
-        ; LineType = code_and_comment(_)
-        ),
         Comment = ""
     ).
 
@@ -271,16 +274,19 @@
 :- func get_comment_backwards(comments, int) = string.
 
 get_comment_backwards(Comments, Line) = Comment :-
-    LineType = map.lookup(Comments ^ line_types, Line),
-    (
-        LineType = comment(CurrentComment),
-        CommentAbove = get_comment_backwards(Comments, Line - 1),
-        Comment = CommentAbove ++ CurrentComment
+    ( map.search(Comments ^ line_types, Line, LineType) ->
+        (
+            LineType = comment(CurrentComment),
+            CommentAbove = get_comment_backwards(Comments, Line - 1),
+            Comment = CommentAbove ++ CurrentComment
+        ;
+            ( LineType = blank
+            ; LineType = code
+            ; LineType = code_and_comment(_)
+            ),
+            Comment = ""
+        )
     ;
-        ( LineType = blank
-        ; LineType = code
-        ; LineType = code_and_comment(_)
-        ),
         Comment = ""
     ).
 

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