has_attributes = 1
base_classes = []
namespace = None
-
+
def __init__(self, name, kind, scope, typedef_flag, cname, base_classes,
namespace = None, packed=False):
self.name = name
return "%s %s" % (name, entity_code)
def is_subclass(self, other_type):
- if not base_classes.empty():
- for base_class in self.base_classes:
- if base_class.is_subclass(other_type):
- return 1
+ for base_class in self.base_classes:
+ if base_class.is_subclass(other_type):
+ return 1
return 0
def assignable_from_resolved_type(self, other_type):
+ print self.same_as_resolved_type(other_type)
+ print self.same_as(other_type)
+ print other_type.is_subclass(self)
if self.same_as_resolved_type(other_type):
return 1
- if other.is_subclass(self) or self.same_as(other_type):
+ if other_type.is_subclass(self) or self.same_as(other_type):
return 1
return 0
self.check_for_illegal_incomplete_ctypedef(typedef_flag, pos)
return entry
- def declare_cpp_class(self, name, kind, scope,
- typedef_flag, pos, cname = None, base_classes = [], namespace = None,
- visibility = 'extern', packed = False):
- if visibility != 'extern':
- error(pos, "C++ classes may only be extern")
- if cname is None:
- cname = name
- entry = self.lookup(name)
- if not entry:
- type = PyrexTypes.CppClassType(
- name, kind, scope, typedef_flag, cname, base_classes, namespace, packed)
- entry = self.declare_type(name, type, pos, cname,
- visibility = visibility, defining = scope is not None)
- else:
- if not (entry.is_type and entry.type.is_cpp_class
- and entry.type.kind == kind):
- warning(pos, "'%s' redeclared " % name, 0)
- elif scope and entry.type.scope:
- warning(pos, "'%s' already defined (ignoring second definition)" % name, 0)
- else:
- self.check_previous_typedef_flag(entry, typedef_flag, pos)
- if scope:
- entry.type.scope = scope
- self.type_entries.append(entry)
- if not scope and not entry.type.scope:
- self.check_for_illegal_incomplete_ctypedef(typedef_flag, pos)
- return entry
-
def check_previous_typedef_flag(self, entry, typedef_flag, pos):
if typedef_flag != entry.type.typedef_flag:
error(pos, "'%s' previously declared using '%s'" % (
#
return entry
+ def declare_cpp_class(self, name, kind, scope,
+ typedef_flag, pos, cname = None, base_classes = [], namespace = None,
+ visibility = 'extern', packed = False):
+ def declare_inherited_attributes(entry, base_entry):
+ if base_entry:
+ for base_class in base_entry.type.base_classes:
+ new_entry = self.lookup(base_class)
+ if base_entry:
+ declare_inherited_attributes(entry, new_entry)
+ entry.type.scope.declare_inherited_cpp_attributes(new_entry.type.scope)
+
+ if visibility != 'extern':
+ error(pos, "C++ classes may only be extern")
+ if cname is None:
+ cname = name
+ entry = self.lookup(name)
+ if not entry:
+ type = PyrexTypes.CppClassType(
+ name, kind, scope, typedef_flag, cname, base_classes, namespace, packed)
+ entry = self.declare_type(name, type, pos, cname,
+ visibility = visibility, defining = scope is not None)
+ else:
+ if not (entry.is_type and entry.type.is_cpp_class
+ and entry.type.kind == kind):
+ warning(pos, "'%s' redeclared " % name, 0)
+ elif scope and entry.type.scope:
+ warning(pos, "'%s' already defined (ignoring second definition)" % name, 0)
+ else:
+ self.check_previous_typedef_flag(entry, typedef_flag, pos)
+ if scope:
+ entry.type.scope = scope
+ self.type_entries.append(entry)
+ if not scope and not entry.type.scope:
+ self.check_for_illegal_incomplete_ctypedef(typedef_flag, pos)
+ entry.type.scope = CppClassScope(name)
+ declare_inherited_attributes(entry, entry)
+ return entry
+
def check_for_illegal_incomplete_ctypedef(self, typedef_flag, pos):
if typedef_flag and not self.in_cinclude:
error(pos, "Forward-referenced type must use 'cdef', not 'ctypedef'")
class CppClassScope(Scope):
# Namespace of a C++ class.
+ inherited_var_entries = []
def __init__(self, name="?"):
Scope.__init__(self, name, None, None)
# Add an entry for an attribute.
if not cname:
cname = name
- if visibility != 'extern':
- error(pos, "Visibility for C++ class member are extern only")
if type.is_cfunction:
type = PyrexTypes.CPtrType(type)
entry = self.declare(name, cname, type, pos, visibility)