Commit ebd8a5d2 authored by Robert Bradshaw's avatar Robert Bradshaw

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.
parent 1b1626c1
...@@ -912,7 +912,6 @@ class CppClassNode(CStructOrUnionDefNode): ...@@ -912,7 +912,6 @@ class CppClassNode(CStructOrUnionDefNode):
# attributes [CVarDefNode] or None # attributes [CVarDefNode] or None
# entry Entry # entry Entry
# base_classes [string] # base_classes [string]
# namespace string or None
def analyse_declarations(self, env): def analyse_declarations(self, env):
scope = None scope = None
...@@ -931,7 +930,7 @@ class CppClassNode(CStructOrUnionDefNode): ...@@ -931,7 +930,7 @@ class CppClassNode(CStructOrUnionDefNode):
base_class_types.append(base_class_entry.type) base_class_types.append(base_class_entry.type)
self.entry = env.declare_cpp_class( self.entry = env.declare_cpp_class(
self.name, "cppclass", scope, 0, self.pos, 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.attributes is not None:
if self.in_pxd and not env.in_cinclude: if self.in_pxd and not env.in_cinclude:
self.entry.defined_in_pxd = 1 self.entry.defined_in_pxd = 1
......
...@@ -1963,6 +1963,8 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag, ...@@ -1963,6 +1963,8 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
error(s.position(), "Empty declarator") error(s.position(), "Empty declarator")
name = "" name = ""
cname = None cname = None
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + name
result = Nodes.CNameDeclaratorNode(pos, result = Nodes.CNameDeclaratorNode(pos,
name = name, cname = cname, default = rhs) name = name, cname = cname, default = rhs)
result.calling_convention = calling_convention result.calling_convention = calling_convention
...@@ -2124,7 +2126,7 @@ def p_cdef_extern_block(s, pos, ctx): ...@@ -2124,7 +2126,7 @@ def p_cdef_extern_block(s, pos, ctx):
_, include_file = p_string_literal(s) _, include_file = p_string_literal(s)
if s.systring == "namespace": if s.systring == "namespace":
s.next() 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') ctx = ctx(cdef_flag = 1, visibility = 'extern')
if p_nogil(s): if p_nogil(s):
ctx.nogil = 1 ctx.nogil = 1
...@@ -2141,6 +2143,8 @@ def p_c_enum_definition(s, pos, ctx): ...@@ -2141,6 +2143,8 @@ def p_c_enum_definition(s, pos, ctx):
name = s.systring name = s.systring
s.next() s.next()
cname = p_opt_cname(s) cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + name
else: else:
name = None name = None
cname = None cname = None
...@@ -2195,6 +2199,8 @@ def p_c_struct_or_union_definition(s, pos, ctx): ...@@ -2195,6 +2199,8 @@ def p_c_struct_or_union_definition(s, pos, ctx):
s.next() s.next()
name = p_ident(s) name = p_ident(s)
cname = p_opt_cname(s) cname = p_opt_cname(s)
if cname is None and ctx.namespace is not None:
cname = ctx.namespace + "::" + name
attributes = None attributes = None
if s.sy == ':': if s.sy == ':':
s.next() s.next()
...@@ -2539,13 +2545,14 @@ def p_cpp_class_definition(s, pos, ctx): ...@@ -2539,13 +2545,14 @@ def p_cpp_class_definition(s, pos, ctx):
s.next() s.next()
module_path = [] module_path = []
class_name = p_ident(s) 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 == '.': if s.sy == '.':
error(pos, "Qualified class name not allowed C++ class") error(pos, "Qualified class name not allowed C++ class")
base_classes = [] base_classes = []
objstruct_name = None objstruct_name = None
typeobj_name = None typeobj_name = None
base_class_module = None
base_class_name = None
if s.sy == '(': if s.sy == '(':
base_class = True base_class = True
while (base_class): while (base_class):
...@@ -2581,9 +2588,8 @@ def p_cpp_class_definition(s, pos, ctx): ...@@ -2581,9 +2588,8 @@ def p_cpp_class_definition(s, pos, ctx):
s.expect_newline("Syntax error in C++ class definition") s.expect_newline("Syntax error in C++ class definition")
return Nodes.CppClassNode(pos, return Nodes.CppClassNode(pos,
name = class_name, name = class_name,
cname = None, cname = cname,
base_classes = base_classes, base_classes = base_classes,
namespace = ctx.namespace,
visibility = ctx.visibility, visibility = ctx.visibility,
in_pxd = ctx.level == 'module_pxd', in_pxd = ctx.level == 'module_pxd',
attributes = attributes) attributes = attributes)
......
...@@ -1374,10 +1374,8 @@ class CppClassType(CType): ...@@ -1374,10 +1374,8 @@ class CppClassType(CType):
is_cpp_class = 1 is_cpp_class = 1
has_attributes = 1 has_attributes = 1
base_classes = [] base_classes = []
namespace = None
def __init__(self, name, kind, scope, typedef_flag, cname, base_classes, def __init__(self, name, kind, scope, typedef_flag, cname, base_classes, packed=False):
namespace = None, packed=False):
self.name = name self.name = name
self.cname = cname self.cname = cname
self.kind = kind self.kind = kind
...@@ -1387,15 +1385,12 @@ class CppClassType(CType): ...@@ -1387,15 +1385,12 @@ class CppClassType(CType):
self._convert_code = None self._convert_code = None
self.packed = packed self.packed = packed
self.base_classes = base_classes self.base_classes = base_classes
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):
if for_display or pyrex: if for_display or pyrex:
name = self.name name = self.name
else: else:
name = self.cname name = self.cname
if self.namespace is not None:
name = "%s::%s" % (self.namespace.replace('.', '::'), name)
return "%s %s" % (name, entity_code) return "%s %s" % (name, entity_code)
def is_subclass(self, other_type): def is_subclass(self, other_type):
......
...@@ -1095,7 +1095,7 @@ class ModuleScope(Scope): ...@@ -1095,7 +1095,7 @@ class ModuleScope(Scope):
return entry return entry
def declare_cpp_class(self, name, kind, scope, 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): 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")
...@@ -1104,7 +1104,7 @@ class ModuleScope(Scope): ...@@ -1104,7 +1104,7 @@ class ModuleScope(Scope):
entry = self.lookup(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, 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)
else: else:
......
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