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):
# 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
......
......@@ -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)
......
......@@ -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):
......
......@@ -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:
......
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