Commit 598b2537 authored by Robert Bradshaw's avatar Robert Bradshaw

Class members in cdef classes

parent c4043e82
...@@ -1370,9 +1370,8 @@ class CClassDefNode(StatNode): ...@@ -1370,9 +1370,8 @@ class CClassDefNode(StatNode):
env.allocate_vtable_names(self.entry) env.allocate_vtable_names(self.entry)
def analyse_expressions(self, env): def analyse_expressions(self, env):
scope = self.entry.type.scope
if self.body: if self.body:
self.body.analyse_expressions(scope) self.body.analyse_expressions(env)
def generate_function_definitions(self, env, code): def generate_function_definitions(self, env, code):
if self.body: if self.body:
......
...@@ -1050,6 +1050,7 @@ class CClassScope(ClassScope): ...@@ -1050,6 +1050,7 @@ class CClassScope(ClassScope):
def declare_var(self, name, type, pos, def declare_var(self, name, type, pos,
cname = None, visibility = 'private', is_cdef = 0): cname = None, visibility = 'private', is_cdef = 0):
if is_cdef:
# Add an entry for an attribute. # Add an entry for an attribute.
if self.defined: if self.defined:
error(pos, error(pos,
...@@ -1082,13 +1083,23 @@ class CClassScope(ClassScope): ...@@ -1082,13 +1083,23 @@ class CClassScope(ClassScope):
error(pos, error(pos,
"Non-generic Python attribute cannot be exposed for writing from Python") "Non-generic Python attribute cannot be exposed for writing from Python")
return entry return entry
else:
# Add an entry for a class attribute.
entry = Scope.declare_var(self, name, type, pos,
cname, visibility, is_cdef)
entry.is_pyglobal = 1
entry.namespace_cname = "(PyObject *)%s" % self.parent_type.typeptr_cname
if Options.intern_names:
entry.interned_cname = self.intern(name)
return entry
def declare_pyfunction(self, name, pos): def declare_pyfunction(self, name, pos):
# Add an entry for a method. # Add an entry for a method.
if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'): if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'):
error(pos, "Special method %s must be implemented via __richcmp__" error(pos, "Special method %s must be implemented via __richcmp__"
% name) % name)
entry = self.declare_var(name, py_object_type, pos) entry = self.declare(name, name, py_object_type, pos)
special_sig = get_special_method_signature(name) special_sig = get_special_method_signature(name)
if special_sig: if special_sig:
# Special methods get put in the method table with a particular # Special methods get put in the method table with a particular
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment