From 2984ce161c60c3f78bbdf1f9d15d634c6986577d Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Mon, 28 Apr 2008 22:29:10 -0700 Subject: [PATCH] public enum --- Cython/Compiler/Nodes.py | 17 +++++++++++++++-- Cython/Compiler/Parsing.py | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 522b50c0..40bf51eb 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -757,10 +757,23 @@ class CEnumDefNode(StatNode): item.analyse_declarations(env, self.entry) def analyse_expressions(self, env): - pass + if self.visibility == 'public': + self.temp = env.allocate_temp_pyobject() + env.release_temp(self.temp) def generate_execution_code(self, code): - pass + if self.visibility == 'public': + for item in self.entry.enum_values: + code.putln("%s = PyInt_FromLong(%s); %s" % ( + self.temp, + item.cname, + code.error_goto_if_null(self.temp, item.pos))) + code.putln('if (PyObject_SetAttrString(%s, "%s", %s) < 0) %s' % ( + Naming.module_cname, + item.name, + self.temp, + code.error_goto(item.pos))) + code.putln("%s = 0;" % self.temp) class CEnumDefItemNode(StatNode): diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index b4133efb..dcb928da 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -1090,6 +1090,8 @@ def p_for_bounds(s): 'relation2': rel2, 'bound2': bound2, 'step': step } + else: + s.error("Expected 'in' or 'from'") def p_for_from_relation(s): if s.sy in inequality_relations: -- 2.26.2