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