From: Stefan Behnel Date: Tue, 5 Aug 2008 06:24:21 +0000 (+0200) Subject: support named labels to improve code readability X-Git-Tag: 0.9.8.1~96 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=46f2563cf6cca60aa52775ea17cfc21a9c4fe262;p=cython.git support named labels to improve code readability --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 79aa5c2e..f87039bc 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -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)