Convert CClassDefNode to use explicit visibilities.
authorW. Trevor King <wking@drexel.edu>
Thu, 3 Mar 2011 13:55:15 +0000 (08:55 -0500)
committerW. Trevor King <wking@drexel.edu>
Thu, 3 Mar 2011 13:55:15 +0000 (08:55 -0500)
Cython/Compiler/Nodes.py
Cython/Compiler/Parsing.py

index b4730bc0def78d7b3f84b23ec4b948d8af60ae95..dbd2762021430c2e8b4d9c73bac87954c7957599 100644 (file)
@@ -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:
index c969dbe266803e373f9acf6e52121fe9086a00af..fe6dde2019a692b84b63eee884f85cd0e111241c 100644 (file)
@@ -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),