From: Lisandro Dalcin Date: Thu, 22 Jul 2010 14:54:21 +0000 (-0300) Subject: fix C++ namespace for enum items X-Git-Tag: 0.13.beta0~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1479a0215a31aa58a18cedae7d30236d5860e630;p=cython.git fix C++ namespace for enum items --- diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index f36fbdd9..d41e8837 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2216,34 +2216,36 @@ def p_c_enum_definition(s, pos, ctx): s.expect(':') items = [] if s.sy != 'NEWLINE': - p_c_enum_line(s, items) + p_c_enum_line(s, ctx, items) else: s.next() # 'NEWLINE' s.expect_indent() while s.sy not in ('DEDENT', 'EOF'): - p_c_enum_line(s, items) + p_c_enum_line(s, ctx, items) s.expect_dedent() return Nodes.CEnumDefNode( pos, name = name, cname = cname, items = items, typedef_flag = ctx.typedef_flag, visibility = ctx.visibility, in_pxd = ctx.level == 'module_pxd') -def p_c_enum_line(s, items): +def p_c_enum_line(s, ctx, items): if s.sy != 'pass': - p_c_enum_item(s, items) + p_c_enum_item(s, ctx, items) while s.sy == ',': s.next() if s.sy in ('NEWLINE', 'EOF'): break - p_c_enum_item(s, items) + p_c_enum_item(s, ctx, items) else: s.next() s.expect_newline("Syntax error in enum item list") -def p_c_enum_item(s, items): +def p_c_enum_item(s, ctx, items): pos = s.position() name = p_ident(s) cname = p_opt_cname(s) + if cname is None and ctx.namespace is not None: + cname = ctx.namespace + "::" + name value = None if s.sy == '=': s.next() diff --git a/tests/compile/cpp_enums.h b/tests/compile/cpp_enums.h new file mode 100644 index 00000000..4ea444ee --- /dev/null +++ b/tests/compile/cpp_enums.h @@ -0,0 +1,11 @@ +enum Enum1 { + Item1, + Item2 +}; + +namespace Namespace1 { + enum Enum2 { + Item3, + Item4 + }; +} diff --git a/tests/compile/cpp_enums.pyx b/tests/compile/cpp_enums.pyx new file mode 100644 index 00000000..bccfacd6 --- /dev/null +++ b/tests/compile/cpp_enums.pyx @@ -0,0 +1,24 @@ +cdef extern from "cpp_enums.h": + cdef enum Enum1: + Item1 + Item2 + +a = Item1 +b = Item2 + +cdef Enum1 x, y +x = Item1 +y = Item2 + +cdef extern from "cpp_enums.h" namespace "Namespace1": + cdef enum Enum2: + Item3 + Item4 + +c = Item3 +d = Item4 + +cdef Enum2 z, w +z = Item3 +w = Item4 +