Commit 34dd6f27 authored by Robert Bradshaw's avatar Robert Bradshaw

More work on cpp types.

parent 17c3c6fc
...@@ -2132,7 +2132,7 @@ def p_cdef_extern_block(s, pos, ctx): ...@@ -2132,7 +2132,7 @@ def p_cdef_extern_block(s, pos, ctx):
return Nodes.CDefExternNode(pos, return Nodes.CDefExternNode(pos,
include_file = include_file, include_file = include_file,
body = body, body = body,
namespace = namespace) namespace = ctx.namespace)
def p_c_enum_definition(s, pos, ctx): def p_c_enum_definition(s, pos, ctx):
# s.sy == ident 'enum' # s.sy == ident 'enum'
......
...@@ -1387,15 +1387,13 @@ class CppClassType(CType): ...@@ -1387,15 +1387,13 @@ class CppClassType(CType):
self.namespace = namespace self.namespace = namespace
def declaration_code(self, entity_code, for_display = 0, dll_linkage = None, pyrex = 0): def declaration_code(self, entity_code, for_display = 0, dll_linkage = None, pyrex = 0):
inherited = "" if for_display or pyrex:
for base_class in self.base_classes: return self.name
if inherited != "": else:
inherited += " : public " cname = self.cname
inherited += base_class if self.namespace is not None:
if base_class != baseclasses[-1]: cname = "%s::%s" % (self.namespace.replace('.', '::'), cname)
inherited += " , " return cname
return "%s%s" % (self.name, inherited)
def is_subclass(self, other_type): def is_subclass(self, other_type):
if not base_classes.empty(): if not base_classes.empty():
...@@ -1407,10 +1405,13 @@ class CppClassType(CType): ...@@ -1407,10 +1405,13 @@ class CppClassType(CType):
def assignable_from_resolved_type(self, other_type): def assignable_from_resolved_type(self, other_type):
if self.same_as_resolved_type(other_type): if self.same_as_resolved_type(other_type):
return 1 return 1
if self.is_subclass(other) or self.same_as(other_type): if other.is_subclass(self) or self.same_as(other_type):
return 1 return 1
return 0 return 0
def attributes_known(self):
return self.scope is not None
class CEnumType(CType): class CEnumType(CType):
# name string # name string
# cname string or None # cname string or None
......
...@@ -389,12 +389,14 @@ class Scope(object): ...@@ -389,12 +389,14 @@ class Scope(object):
visibility = 'extern', packed = False): visibility = 'extern', packed = False):
if visibility != 'extern': if visibility != 'extern':
error(pos, "C++ classes may only be extern") error(pos, "C++ classes may only be extern")
if cname is None:
cname = name
entry = self.lookup(name)
if not entry: if not entry:
type = PyrexTypes.CppClassType( type = PyrexTypes.CppClassType(
name, kind, scope, typedef_flag, cname, base_classes, namespace, packed) name, kind, scope, typedef_flag, cname, base_classes, namespace, packed)
entry = self.declare_type(name, type, pos, cname, entry = self.declare_type(name, type, pos, cname,
visibility = visibility, defining = scope is not None) visibility = visibility, defining = scope is not None)
self.sue_entries.append(entry)
else: else:
if not (entry.is_type and entry.type.is_cpp_class if not (entry.is_type and entry.type.is_cpp_class
and entry.type.kind == kind): and entry.type.kind == kind):
...@@ -1589,8 +1591,8 @@ class CppClassScope(Scope): ...@@ -1589,8 +1591,8 @@ class CppClassScope(Scope):
# Add an entry for an attribute. # Add an entry for an attribute.
if not cname: if not cname:
cname = name cname = name
if visibility != 'extern': if visibility != 'extern':
error("Visibility for C++ class member are extern only") error(pos, "Visibility for C++ class member are extern only")
if type.is_cfunction: if type.is_cfunction:
type = PyrexTypes.CPtrType(type) type = PyrexTypes.CPtrType(type)
entry = self.declare(name, cname, type, pos, visibility) entry = self.declare(name, cname, type, pos, visibility)
......
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