From 34dd6f27fa72aa153d705d807c5860c4178f9f4b Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Mon, 8 Jun 2009 21:07:55 -0700 Subject: [PATCH] More work on cpp types. --- Cython/Compiler/Parsing.py | 2 +- Cython/Compiler/PyrexTypes.py | 21 +++++++++++---------- Cython/Compiler/Symtab.py | 8 +++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 4c806ae3..f0a9d421 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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' diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 66150598..6a54d91e 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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 diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 32e0b1b5..32ce96ed 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -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) -- 2.26.2