Permalink
Browse files

Add support for cpdef enum

  • Loading branch information...
vitek committed Jul 18, 2011
1 parent 53e4c10 commit a2d93b1bbb4400231676a2c7601bd8e34a3104d7
Showing with 17 additions and 5 deletions.
  1. +1 −1 Cython/Compiler/Nodes.py
  2. +1 −1 Cython/Compiler/ParseTreeTransforms.py
  3. +4 −3 Cython/Compiler/Parsing.py
  4. +11 −0 tests/run/cpdef_enum.pyx
View
@@ -1093,7 +1093,7 @@ def analyse_expressions(self, env):
pass
def generate_execution_code(self, code):
- if self.visibility == 'public' or self.api:
+ if self.visibility == 'public' or self.api or self.is_overridable:
temp = code.funcstate.allocate_temp(PyrexTypes.py_object_type, manage_ref=True)
for item in self.entry.enum_values:
code.putln("%s = PyInt_FromLong(%s); %s" % (
@@ -1530,7 +1530,7 @@ def visit_CBaseTypeNode(self, node):
return None
def visit_CEnumDefNode(self, node):
- if node.visibility == 'public':
+ if node.visibility == 'public' or node.is_overridable:
return node
else:
return None
@@ -2413,10 +2413,10 @@ def p_cdef_statement(s, ctx):
elif s.sy == 'IDENT' and s.systring in ("struct", "union", "enum", "packed"):
if ctx.level not in ('module', 'module_pxd'):
error(pos, "C struct/union/enum definition not allowed here")
- if ctx.overridable:
- error(pos, "C struct/union/enum cannot be declared cpdef")
if s.systring == "enum":
return p_c_enum_definition(s, pos, ctx)
+ if ctx.overridable:
+ error(pos, "C struct/union cannot be declared cpdef")
else:
return p_c_struct_or_union_definition(s, pos, ctx)
else:
@@ -2472,7 +2472,8 @@ def p_c_enum_definition(s, pos, ctx):
return Nodes.CEnumDefNode(
pos, name = name, cname = cname, items = items,
typedef_flag = ctx.typedef_flag, visibility = ctx.visibility,
- api = ctx.api, in_pxd = ctx.level == 'module_pxd')
+ api = ctx.api, in_pxd = ctx.level == 'module_pxd',
+ is_overridable = ctx.overridable)
def p_c_enum_line(s, ctx, items):
if s.sy != 'pass':
View
@@ -0,0 +1,11 @@
+"""
+>>> sys.modules['cpdef_enum'].FOO
+1
+>>> sys.modules['cpdef_enum'].BAR
+2
+"""
+import sys
+
+cpdef enum:
+ FOO = 1
+ BAR = 2

0 comments on commit a2d93b1

Please sign in to comment.