Browse Source

Fixed iterate_markers and improved tests for lines.

avkonst 11 years ago
parent
commit
d1ec6ad3a3

+ 29 - 7
mainline/core/db/loader.py

@@ -337,15 +337,37 @@ class FileData(LoadableData):
         
     def iterate_markers(self, filter_group = Marker.T.COMMENT |
                          Marker.T.STRING | Marker.T.PREPROCESSOR,
-                         region_id = None, exclude_children = True):
+                         region_id = None, exclude_children = True, merge = False):
         self.load_markers()
+        
+        if merge == True:
+            next_marker = None
+            for marker in self.iterate_markers(filter_group, region_id, exclude_children, merge = False):
+                if next_marker != None:
+                    if next_marker.get_offset_end() == marker.get_offset_begin():
+                        # sequential markers
+                        next_marker = Marker(next_marker.get_offset_begin(),
+                                             marker.get_offset_end(),
+                                             next_marker.get_type() | marker.get_type())
+                    else:
+                        yield next_marker
+                        next_marker = None
+                if next_marker == None:
+                    next_marker = Marker(marker.get_offset_begin(),
+                                         marker.get_offset_end(),
+                                         marker.get_type())
 
         if region_id == None:
-            # TODO bug here - does not handle CODE markers
-            for each in self.markers:
-                if each.group & filter_group:
-                    yield each
-        
+            next_code_marker_start = 0
+            for marker in self.markers:
+                if Marker.T.CODE & filter_group and next_code_marker_start < marker.get_offset_begin():
+                    yield Marker(next_code_marker_start, marker.get_offset_begin(), Marker.T.CODE)
+                if marker.group & filter_group:
+                    yield marker
+                next_code_marker_start = marker.get_offset_end()
+            if Marker.T.CODE & filter_group and next_code_marker_start < len(self.get_content()):
+                yield Marker(next_code_marker_start, len(self.get_content()), Marker.T.CODE)
+            
         else:
             # per region
             region = self.get_region(region_id)
@@ -433,7 +455,7 @@ class FileData(LoadableData):
                             
                 # including subregions
                 else:
-                    next_code_marker_start = region.get_offset_begin() #TODO bug here global region does not start at 0
+                    next_code_marker_start = region.get_offset_begin()
                     for marker in self.markers[region._first_marker_ind:]:
                         if marker.get_offset_begin() >= region.get_offset_end():
                             break

+ 1 - 1
mainline/tests/general/test_basic/sources/simple.cpp

@@ -15,7 +15,7 @@ class A
 		{
 			for (int i = 0; i < 0 && i > 0; i++)
 			{
-				// crazy, right?
+				int a; // right?
 			}
 		}
 	}

+ 1 - 1
mainline/tests/general/test_basic/sources_changed/simple.cpp

@@ -15,7 +15,7 @@ class A
 		{
 			for (int i = 0; i < 0 && i > 0; i++)
 			{
-				// crazy, right?
+				int a; // right?
 			}
 		}
 	}

+ 5 - 5
mainline/tests/general/test_basic/test_std_lines_metrics_view_nest_per_file_stdout.gold.txt

@@ -72,7 +72,7 @@ data:
 .   .   .   .   .   .   .   .   .   .   .   offset_begin="88"
 .   .   .   .   .   .   .   .   .   .   data:  
 .   .   .   .   .   .   .   .   .   .   .   std.code.lines: 
-.   .   .   .   .   .   .   .   .   .   .   .   code="10"
+.   .   .   .   .   .   .   .   .   .   .   .   code="11"
 .   .   .   .   .   .   .   .   .   .   .   .   total="12"
 .   .   .   .   .   .   .   .   .   .   .   .   preprocessor="0"
 .   .   .   .   .   .   .   .   .   .   .   .   comments="2"
@@ -151,9 +151,9 @@ data:
 .   .   std.code.lines:  
 .   .   .   code: 
 .   .   .   .   count="8"
-.   .   .   .   max="10"
-.   .   .   .   avg="5.0"
-.   .   .   .   total="40.0"
+.   .   .   .   max="11"
+.   .   .   .   avg="5.125"
+.   .   .   .   total="41.0"
 .   .   .   .   min="0" 
 .   .   .   .   distribution-bars:
 .   .   .   .   
@@ -184,7 +184,7 @@ data:
 .   .   .   .   
 .   .   .   .   .   distribution-bar: 
 .   .   .   .   .   .   count="1"
-.   .   .   .   .   .   metric="10"
+.   .   .   .   .   .   metric="11"
 .   .   .   .   .   .   ratio="0.125"
 .   .   .   total: 
 .   .   .   .   count="8"

+ 4 - 4
mainline/tests/general/test_basic/test_std_lines_metrics_view_txt_stdout.gold.txt

@@ -15,9 +15,9 @@ data:
 .   .   std.code.lines:  
 .   .   .   code: 
 .   .   .   .   count="8"
-.   .   .   .   max="10"
-.   .   .   .   avg="5.0"
-.   .   .   .   total="40.0"
+.   .   .   .   max="11"
+.   .   .   .   avg="5.125"
+.   .   .   .   total="41.0"
 .   .   .   .   min="0" 
 .   .   .   .   distribution-bars:
 .   .   .   .   
@@ -48,7 +48,7 @@ data:
 .   .   .   .   
 .   .   .   .   .   distribution-bar: 
 .   .   .   .   .   .   count="1"
-.   .   .   .   .   .   metric="10"
+.   .   .   .   .   .   metric="11"
 .   .   .   .   .   .   ratio="0.125"
 .   .   .   total: 
 .   .   .   .   count="8"