From 9affc36cb83c7fd9a8aa039f8b0ea69ef877ad66 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 3 Mar 2011 08:55:15 -0500 Subject: [PATCH] Convert CClassDefNode to use explicit visibilities. --- Cython/Compiler/Nodes.py | 33 +++++++++++++++++++-------------- Cython/Compiler/Parsing.py | 9 +++------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index b4730bc0..dbd27620 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3082,7 +3082,9 @@ class PyClassDefNode(ClassDefNode): return None return CClassDefNode(self.pos, - visibility = 'private', + extern = 'false', + c_visibility = 'private', + visibility = 'public', module_name = None, class_name = self.name, base_class_module = base_class_module, @@ -3149,9 +3151,11 @@ class PyClassDefNode(ClassDefNode): class CClassDefNode(ClassDefNode): # An extension type definition. # - # visibility 'private' or 'public' or 'extern' + # extern (same as Binding.extern) + # c_visibility (same as Binding.c_visibility) + # visibility (same as Binding.visibility) # typedef_flag boolean - # api boolean + # api (same as Binding.api) # module_name string or None For import of extern type objects # class_name string Unqualified name of class # as_name string or None Name to declare as in this scope @@ -3240,7 +3244,7 @@ class CClassDefNode(ClassDefNode): else: self.base_type = base_class_entry.type has_body = self.body is not None - if self.module_name and self.visibility != 'extern': + if self.module_name and not self.extern: module_path = self.module_name.split(".") home_scope = env.find_imported_module(module_path, self.pos) if not home_scope: @@ -3248,26 +3252,27 @@ class CClassDefNode(ClassDefNode): else: home_scope = env - if self.visibility == 'extern': + if self.extern: if (self.module_name == '__builtin__' and self.class_name in Builtin.builtin_types and env.qualified_name[:8] != 'cpython.'): # allow overloaded names for cimporting from cpython warning(self.pos, "%s already a builtin Cython type" % self.class_name, 1) - self.entry = home_scope.declare_c_class( - name = self.class_name, - pos = self.pos, + binding = Binding() + binding.pull(self) + binding.name = self.class_name + self.entry = home_scope.WTK_declare_c_class( + binding, + objstruct_cname = self.objstruct_name, + base_type = self.base_type, defining = has_body and self.in_pxd, implementing = has_body and not self.in_pxd, module_name = self.module_name, - base_type = self.base_type, - objstruct_cname = self.objstruct_name, typeobj_cname = self.typeobj_name, - visibility = self.visibility, typedef_flag = self.typedef_flag, - api = self.api, - buffer_defaults = buffer_defaults) - if home_scope is not env and self.visibility == 'extern': + buffer_defaults = buffer_defaults, + pos = self.pos) + if home_scope is not env and self.extern: env.add_imported_entry(self.class_name, self.entry, self.pos) self.scope = scope = self.entry.type.scope if scope is not None: diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index c969dbe2..fe6dde20 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2932,11 +2932,6 @@ def p_c_class_definition(s, pos, ctx, decorators=None): s.expect_newline("Syntax error in C class definition") doc = None body = None - visibility = 'private' - if ctx.extern: - visibility = 'extern' - elif ctx.c_visibility != 'private': - visibility = ctx.c_visibility if ctx.extern: if not module_path: error(pos, "Module name required for 'extern' C class") @@ -2953,7 +2948,9 @@ def p_c_class_definition(s, pos, ctx, decorators=None): else: error(pos, "Invalid class visibility '%s'" % visibility) return Nodes.CClassDefNode(pos, - visibility = visibility, + extern = ctx.extern, + c_visibility = ctx.c_visibility, + visibility = ctx.visibility, typedef_flag = ctx.typedef_flag, api = ctx.api, module_name = ".".join(module_path), -- 2.26.2