public enum
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 29 Apr 2008 05:29:10 +0000 (22:29 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 29 Apr 2008 05:29:10 +0000 (22:29 -0700)
Cython/Compiler/Nodes.py
Cython/Compiler/Parsing.py

index 522b50c0c7f2929fd208f419ed2634a6211f96e8..40bf51eb61ce419bd9884f33095e25e17197c7a5 100644 (file)
@@ -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):
index b4133efb9d5301c62dc60e27f763e197dd4cd8fc..dcb928da6dbe5b8649189a95230845c0581359b4 100644 (file)
@@ -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: