Convert CFuncDefNode to use explicit visibilities.
authorW. Trevor King <wking@drexel.edu>
Thu, 3 Mar 2011 12:59:52 +0000 (07:59 -0500)
committerW. Trevor King <wking@drexel.edu>
Thu, 3 Mar 2011 12:59:52 +0000 (07:59 -0500)
Cython/Compiler/Nodes.py
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/Parsing.py

index cfced8c6d0fe2e57b2e69268721605a9303c7e5f..edd0f4dba3c61073a4917d02d89bbc1bd70e08de 100644 (file)
@@ -1618,17 +1618,19 @@ class CFuncDefNode(FuncDefNode):
     #  C function definition.
     #
     #  modifiers     ['inline']
-    #  visibility    'private' or 'public' or 'extern'
+    #  extern        (same as Binding.extern)
+    #  c_visibility  (same as Binding.c_visibility)
+    #  visibility    (same as Binding.visibility)
     #  base_type     CBaseTypeNode
     #  declarator    CDeclaratorNode
     #  body          StatListNode
-    #  api           boolean
+    #  api           (same as Binding.api)
     #  decorators    [DecoratorNode]        list of decorators
     #
     #  with_gil      boolean    Acquire GIL around body
     #  type          CFuncType
     #  py_func       wrapper for calling from Python
-    #  overridable   whether or not this is a cpdef function
+    #  overridable   (same as Binding.overridable)
     #  inline_in_pxd whether this is an inline function in a pxd file
 
     child_attrs = ["base_type", "declarator", "body", "py_func"]
@@ -1664,16 +1666,16 @@ class CFuncDefNode(FuncDefNode):
             formal_arg.cname = type_arg.cname
             if type_arg.type.is_buffer and 'inline' in self.modifiers:
                 warning(formal_arg.pos, "Buffer unpacking not optimized away.", 1)
-        name = name_declarator.name
-        cname = name_declarator.cname
-        self.entry = env.declare_cfunction(
-            name, type, self.pos,
-            cname = cname, visibility = self.visibility,
-            defining = self.body is not None,
-            api = self.api, modifiers = self.modifiers)
+        binding = Binding()
+        binding.pull(self)
+        binding.name = name_declarator.name
+        binding.cname = name_declarator.cname
+        self.entry = env.WTK_declare_cfunction(
+            binding, type = type, defining = self.body is not None,
+            modifiers = self.modifiers, pos = self.pos)
         self.entry.inline_func_in_pxd = self.inline_in_pxd
         self.return_type = type.return_type
-        if self.return_type.is_array and visibility != 'extern':
+        if self.return_type.is_array and not self.extern:
             error(self.pos,
                 "Function cannot return an array")
 
@@ -1697,7 +1699,7 @@ class CFuncDefNode(FuncDefNode):
             self.py_func.analyse_declarations(env)
             self.entry.as_variable = self.py_func.entry
             # Reset scope entry the above cfunction
-            env.entries[name] = self.entry
+            env.entries[self.entry.name] = self.entry
             if not env.is_module_scope or Options.lookup_module_cpdef:
                 self.override = OverrideCheckNode(self.pos, py_func = self.py_func)
                 self.body = StatListNode(self.pos, stats=[self.override, self.body])
@@ -1990,7 +1992,9 @@ class DefNode(FuncDefNode):
                             type = cfunc_type,
                             with_gil = cfunc_type.with_gil,
                             nogil = cfunc_type.nogil,
-                            visibility = 'private',
+                            extern = 0,
+                            c_visibility = 'private',
+                            visibility = 'public',
                             api = False,
                             directive_locals = getattr(cfunc, 'directive_locals', {}))
 
index e4f0a00e507f65dfc8730b47177f54d226144b8c..b99c9d594b89b9ffb33a8fe6f106de0bdd7b5db6 100644 (file)
@@ -518,7 +518,7 @@ class PxdPostParse(CythonTransform, SkipDeclarations):
         if isinstance(node, Nodes.CFuncDefNode):
             if u'inline' in node.modifiers and self.scope_type == 'pxd':
                 node.inline_in_pxd = True
-                if node.visibility != 'private':
+                if node.c_visibility != 'private':
                     err = self.ERR_NOGO_WITH_INLINE % node.visibility
                 elif node.api:
                     err = self.ERR_NOGO_WITH_INLINE % 'api'
index f6c684225c36136abf85e2d65e911cbea51fc26a..a8967d9141d5250c10fe3222480c1bf41b1cdfe5 100644 (file)
@@ -2722,15 +2722,12 @@ def p_c_func_or_var_declaration(s, pos, ctx, decorators=None):
         if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd') and not ctx.templates:
             s.error("C function definition not allowed here")
         doc, suite = p_suite(s, Ctx(level = 'function'), with_doc = 1)
-        visibility = 'private'
-        if ctx.extern:
-            visibility = 'extern'
-        elif ctx.c_visibility != 'private':
-            visibility = ctx.c_visibility
         result = Nodes.CFuncDefNode(pos,
             cdef_flag = ctx.cdef_flag,
             overridable = ctx.overridable,
-            visibility = visibility,
+            extern = ctx.extern,
+            c_visibility = ctx.c_visibility,
+            visibility = ctx.visibility,
             base_type = base_type,
             declarator = declarator,
             decorators = decorators,