attr.analyse_declarations(scope)
class CEnumDefNode(StatNode):
- # name string or None
- # cname string or None
+ # name (same as Binding.name)
+ # cname (same as Binding.cname)
# items [CEnumDefItemNode]
# typedef_flag boolean
- # visibility "public" or "private"
+ # extern (same meaning as Binding.extern)
+ # c_visibility (same as Binding.c_visibility)
+ # visibility (same as Binding.visibility)
# in_pxd boolean
# entry Entry
child_attrs = ["items"]
def analyse_declarations(self, env):
- self.entry = env.declare_enum(self.name, self.pos,
- cname = self.cname, typedef_flag = self.typedef_flag,
- visibility = self.visibility)
+ binding = Binding()
+ binding.pull(self)
+ self.entry = env.WTK_declare_enum(
+ binding, typedef_flag = self.typedef_flag, pos = self.pos)
if self.items is not None:
if self.in_pxd and not env.in_cinclude:
self.entry.defined_in_pxd = 1
if self.visibility == 'public':
temp = code.funcstate.allocate_temp(PyrexTypes.py_object_type, manage_ref=True)
for item in self.entry.enum_values:
+ if item.visibility == 'private':
+ continue
code.putln("%s = PyInt_FromLong(%s); %s" % (
temp,
item.cname,
class CEnumDefItemNode(StatNode):
- # name string
- # cname string or None
+ # name (same as Binding.name)
+ # cname (same as Binding.cname)
# value ExprNode or None
child_attrs = ["value"]
if not self.value.type.is_int:
self.value = self.value.coerce_to(PyrexTypes.c_int_type, env)
self.value.analyse_const_expression(env)
- visibility = 'private'
- if enum_entry.extern:
- visibility = 'extern'
- elif enum_entry.c_visibility != 'private':
- visibility = enum_entry.c_visibility
- entry = env.declare_const(self.name, enum_entry.type,
- self.value, self.pos, cname = self.cname,
- visibility = visibility)
+ binding = Binding()
+ binding.pull(self)
+ entry = env.WTK_declare_const(
+ binding, type = enum_entry.type,
+ value = self.value, pos = self.pos)
enum_entry.enum_values.append(entry)
items = None
s.expect(':')
items = []
+ # Work around overloading of the 'public' keyword.
+ item_ctx = ctx()
+ if item_ctx.c_visibility == 'public':
+ item_ctx.c_visibility = 'public'
+ item_ctx.visibility = 'public'
+ else:
+ item_ctx.c_visibility = 'public'
+ item_ctx.visibility = 'private'
if s.sy != 'NEWLINE':
- p_c_enum_line(s, ctx, items)
+ p_c_enum_line(s, item_ctx, items)
else:
s.next() # 'NEWLINE'
s.expect_indent()
while s.sy not in ('DEDENT', 'EOF'):
- p_c_enum_line(s, ctx, items)
+ p_c_enum_line(s, item_ctx, items)
s.expect_dedent()
- visibility = 'private'
- if ctx.extern:
- visibility = 'extern'
- elif ctx.c_visibility != 'private':
- visibility = ctx.c_visibility
return Nodes.CEnumDefNode(
pos, name = name, cname = cname, items = items,
- typedef_flag = ctx.typedef_flag, visibility = visibility,
+ typedef_flag = ctx.typedef_flag, extern = ctx.extern,
+ c_visibility = ctx.c_visibility, visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd')
def p_c_enum_line(s, ctx, items):
if s.sy == '=':
s.next()
value = p_test(s)
- visibility = 'private'
- if ctx.extern:
- visibility = 'extern'
- elif ctx.c_visibility != 'private':
- visibility = ctx.c_visibility
items.append(Nodes.CEnumDefItemNode(pos,
name = name, cname = cname, value = value,
- visibility = visibility,
+ extern = ctx.extern, visibility = ctx.visibility,
+ c_visibility = ctx.c_visibility,
in_pxd = ctx.level == 'module_pxd'))