support named labels to improve code readability
authorStefan Behnel <scoder@users.berlios.de>
Tue, 5 Aug 2008 06:24:21 +0000 (08:24 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 5 Aug 2008 06:24:21 +0000 (08:24 +0200)
Cython/Compiler/Code.py

index 79aa5c2e579f18e37147d67f13e1b33087729d76..f87039bcc1fb1e3a2f627e73e2193a8f32664d2f 100644 (file)
@@ -30,14 +30,17 @@ class FunctionContext(object):
         self.temps_used_type = {} # name -> type
         self.temp_counter = 0
 
-    def new_label(self):
+    def new_label(self, name=None):
         n = self.label_counter
         self.label_counter = n + 1
-        return "%s%d" % (Naming.label_prefix, n)
+        label = "%s%d" % (Naming.label_prefix, n)
+        if name is not None:
+            label += '_' + name
+        return label
     
     def new_error_label(self):
         old_err_lbl = self.error_label
-        self.error_label = self.new_label()
+        self.error_label = self.new_label('error')
         return old_err_lbl
     
     def get_loop_labels(self):
@@ -219,7 +222,7 @@ class CCodeWriter(object):
 
 
     # Functions delegated to function scope
-    def new_label(self):               return self.func.new_label()
+    def new_label(self, name=None):    return self.func.new_label(name)
     def new_error_label(self):         return self.func.new_error_label()
     def get_loop_labels(self):         return self.func.get_loop_labels()
     def set_loop_labels(self, labels): return self.func.set_loop_labels(labels)