From 46f2563cf6cca60aa52775ea17cfc21a9c4fe262 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 5 Aug 2008 08:24:21 +0200 Subject: [PATCH] support named labels to improve code readability --- Cython/Compiler/Code.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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) -- 2.26.2