From ebd8a5d258584013f61450ff519a0537381b07eb Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 18 Jun 2009 22:42:26 -0700 Subject: [PATCH] Rework namespaces into cname. Otherwise we have to trace namespace arguments all the way through all declarators and types, only to mutate the cnames at the end. --- Cython/Compiler/Nodes.py | 3 +-- Cython/Compiler/Parsing.py | 16 +++++++++++----- Cython/Compiler/PyrexTypes.py | 9 ++------- Cython/Compiler/Symtab.py | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index c892a633..233a9ae2 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -912,7 +912,6 @@ class CppClassNode(CStructOrUnionDefNode): # attributes [CVarDefNode] or None # entry Entry # base_classes [string] - # namespace string or None def analyse_declarations(self, env): scope = None @@ -931,7 +930,7 @@ class CppClassNode(CStructOrUnionDefNode): base_class_types.append(base_class_entry.type) self.entry = env.declare_cpp_class( self.name, "cppclass", scope, 0, self.pos, - self.cname, base_class_types, self.namespace, visibility = self.visibility) + self.cname, base_class_types, visibility = self.visibility) if self.attributes is not None: if self.in_pxd and not env.in_cinclude: self.entry.defined_in_pxd = 1 diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 333a06b6..4b628e4a 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -1963,6 +1963,8 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag, error(s.position(), "Empty declarator") name = "" cname = None + if cname is None and ctx.namespace is not None: + cname = ctx.namespace + "::" + name result = Nodes.CNameDeclaratorNode(pos, name = name, cname = cname, default = rhs) result.calling_convention = calling_convention @@ -2124,7 +2126,7 @@ def p_cdef_extern_block(s, pos, ctx): _, include_file = p_string_literal(s) if s.systring == "namespace": s.next() - ctx.namespace = p_ident(s) + ctx.namespace = p_dotted_name(s, as_allowed=False)[2].replace('.', '::') ctx = ctx(cdef_flag = 1, visibility = 'extern') if p_nogil(s): ctx.nogil = 1 @@ -2141,6 +2143,8 @@ def p_c_enum_definition(s, pos, ctx): name = s.systring s.next() cname = p_opt_cname(s) + if cname is None and ctx.namespace is not None: + cname = ctx.namespace + "::" + name else: name = None cname = None @@ -2195,6 +2199,8 @@ def p_c_struct_or_union_definition(s, pos, ctx): s.next() name = p_ident(s) cname = p_opt_cname(s) + if cname is None and ctx.namespace is not None: + cname = ctx.namespace + "::" + name attributes = None if s.sy == ':': s.next() @@ -2539,13 +2545,14 @@ def p_cpp_class_definition(s, pos, ctx): s.next() module_path = [] class_name = p_ident(s) + cname = p_opt_cname(s) + if cname is None and ctx.namespace is not None: + cname = ctx.namespace + "::" + class_name if s.sy == '.': error(pos, "Qualified class name not allowed C++ class") base_classes = [] objstruct_name = None typeobj_name = None - base_class_module = None - base_class_name = None if s.sy == '(': base_class = True while (base_class): @@ -2581,9 +2588,8 @@ def p_cpp_class_definition(s, pos, ctx): s.expect_newline("Syntax error in C++ class definition") return Nodes.CppClassNode(pos, name = class_name, - cname = None, + cname = cname, base_classes = base_classes, - namespace = ctx.namespace, visibility = ctx.visibility, in_pxd = ctx.level == 'module_pxd', attributes = attributes) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 6f6ba6e9..1847b007 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1374,10 +1374,8 @@ class CppClassType(CType): is_cpp_class = 1 has_attributes = 1 base_classes = [] - namespace = None - - def __init__(self, name, kind, scope, typedef_flag, cname, base_classes, - namespace = None, packed=False): + + def __init__(self, name, kind, scope, typedef_flag, cname, base_classes, packed=False): self.name = name self.cname = cname self.kind = kind @@ -1387,15 +1385,12 @@ class CppClassType(CType): self._convert_code = None self.packed = packed self.base_classes = base_classes - self.namespace = namespace def declaration_code(self, entity_code, for_display = 0, dll_linkage = None, pyrex = 0): if for_display or pyrex: name = self.name else: name = self.cname - if self.namespace is not None: - name = "%s::%s" % (self.namespace.replace('.', '::'), name) return "%s %s" % (name, entity_code) def is_subclass(self, other_type): diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 6a8d7f94..236f3d0c 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1095,7 +1095,7 @@ class ModuleScope(Scope): return entry def declare_cpp_class(self, name, kind, scope, - typedef_flag, pos, cname = None, base_classes = [], namespace = None, + typedef_flag, pos, cname = None, base_classes = [], visibility = 'extern', packed = False): if visibility != 'extern': error(pos, "C++ classes may only be extern") @@ -1104,7 +1104,7 @@ class ModuleScope(Scope): entry = self.lookup(name) if not entry: type = PyrexTypes.CppClassType( - name, kind, scope, typedef_flag, cname, base_classes, namespace, packed) + name, kind, scope, typedef_flag, cname, base_classes, packed) entry = self.declare_type(name, type, pos, cname, visibility = visibility, defining = scope is not None) else: -- 2.26.2