Normalize WTK_declare_cfunction -> declare_cfunction.
authorW. Trevor King <wking@drexel.edu>
Sun, 6 Mar 2011 04:17:25 +0000 (23:17 -0500)
committerW. Trevor King <wking@drexel.edu>
Sun, 6 Mar 2011 04:17:25 +0000 (23:17 -0500)
Cython/Compiler/CythonScope.py
Cython/Compiler/ExprNodes.py
Cython/Compiler/Nodes.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Symtab.py

index 52f27d0198667ef3688026420d720dad05a72432..5a8a7cf38d99ee36c25352a26b1d6cf0a6dd8a2b 100644 (file)
@@ -11,11 +11,9 @@ class CythonScope(ModuleScope):
         ModuleScope.__init__(self, u'cython', None, context)
         self.pxd_file_loaded = True
 
-        self.shape_entry = self.declare_cfunction('shape',
-                                                  shape_func_type,
-                                                  pos=None,
-                                                  defining = 1,
-                                                  cname='<error>')
+        binding = Binding(name = 'shape', cname = '<error>')
+        self.shape_entry = self.declare_cfunction(
+            binding, type = shape_func_type, defining = 1)
 
     def lookup_type(self, name):
         # This function should go away when types are all first-level objects.
@@ -38,12 +36,11 @@ def create_utility_scope(context):
         binding, base_type = c_void_type, pos = None)
     type_object.is_void = True
 
-    utility_scope.declare_cfunction(
-                'PyObject_TypeCheck',
-                CFuncType(c_bint_type, [CFuncTypeArg("o", py_object_type, None),
-                                        CFuncTypeArg("t", c_ptr_type(type_object), None)]),
-                pos = None,
-                defining = 1,
-                cname = 'PyObject_TypeCheck')
+    binding = Binding(
+        name = 'PyObject_TypeCheck', cname = 'PyObject_TypeCheck')
+    func_type = CFuncType(
+        c_bint_type, [CFuncTypeArg("o", py_object_type, None),
+                      CFuncTypeArg("t", c_ptr_type(type_object), None)])
+    utility_scope.declare_cfunction(binding, type = func_type, defining = 1)
 
     return utility_scope
index 75c9266002051a1f3e243304a957a6384017be58..72ed2ea1b2ef18d875beaf586dc8de02b20ca260 100755 (executable)
@@ -1244,7 +1244,10 @@ class NewExprNode(AtomicExprNode):
         if constructor is None:
             return_type = PyrexTypes.CFuncType(type, [])
             return_type = PyrexTypes.CPtrType(return_type)
-            type.scope.declare_cfunction(u'<init>', return_type, self.pos)
+            binding = Binding(
+                name = u'<init>', extern = True, c_visibility = 'public')
+            type.scope.declare_cfunction(
+                binding, type = return_type, pos = self.pos)
             constructor = type.scope.lookup(u'<init>')
         self.class_type = type
         self.entry = constructor
index 0410ceefb1b2d1f7b3555be997a880279650c23b..5fe4ad7fc658cd6486920cdf6b5f24d48fffcbbc 100644 (file)
@@ -958,9 +958,9 @@ class CVarDefNode(StatNode):
             binding = Binding(name=name, cname=cname)
             binding.pull(self)
             if type.is_cfunction:
-                entry = dest_scope.WTK_declare_cfunction(
-                    binding, type = type, pos = declarator.pos,
-                    in_pxd = self.in_pxd)
+                entry = dest_scope.declare_cfunction(
+                    binding, type = type, in_pxd = self.in_pxd,
+                    pos = declarator.pos)
                 if entry is not None:
                     entry.directive_locals = self.directive_locals
             else:
@@ -1678,7 +1678,7 @@ class CFuncDefNode(FuncDefNode):
         binding.pull(self)
         binding.name = name_declarator.name
         binding.cname = name_declarator.cname
-        self.entry = env.WTK_declare_cfunction(
+        self.entry = env.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
index 3b69395866704c4e83823f1d5fec9d33b45c87f8..631e0f6b6e9c5aaaded0c2cfc105a2248c1d32f7 100755 (executable)
@@ -2,6 +2,7 @@
 #   Pyrex - Types
 #
 
+from Binding import Binding
 from Code import UtilityCode
 import StringEncoding
 import Naming
@@ -685,12 +686,11 @@ class CNumericType(CType):
                     extern=1)
             scope.parent_type = self
             scope.directives = {}
+            binding = Binding(name = 'conjugate', cname = ' ')
+            func_type = CFuncType(
+                self, [CFuncTypeArg("self", self, None)], nogil=True)
             entry = scope.declare_cfunction(
-                    "conjugate",
-                    CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True),
-                    pos=None,
-                    defining=1,
-                    cname=" ")
+                binding, type = func_type, defining = 1)
         return True
 
 
@@ -1192,12 +1192,12 @@ class CComplexType(CNumericType):
             scope.directives = {}
             scope.declare_var("real", self.real_type, None, "real", is_cdef=True)
             scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True)
+            binding = Binding(
+                name = 'conjugate', cname = '__Pyx_c_conj%s' % self.funcsuffix)
+            func_type = CFuncType(
+                self, [CFuncTypeArg('self', self, None)], nogil=True)
             entry = scope.declare_cfunction(
-                    "conjugate",
-                    CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True),
-                    pos=None,
-                    defining=1,
-                    cname="__Pyx_c_conj%s" % self.funcsuffix)
+                binding, type = func_type, defining = 1)
 
         return True
 
index 8cb8dae6f22e8902e6b0d2155a44609b02fa8723..2cfe48bf7ac650e1f6f4f59ce0a9ace482c34c3f 100644 (file)
@@ -635,19 +635,8 @@ class Scope(object):
     def register_pyfunction(self, entry):
         self.pyfunc_entries.append(entry)
 
-    def declare_cfunction(self, name, type, pos,
-                          cname = None, visibility = 'private', defining = 0,
-                          api = 0, in_pxd = 0, modifiers = (), utility_code = None):
-        binding = self._WTK_setup(name, cname, visibility)
-        binding.api = api
-        return self.WTK_declare_cfunction(
-            binding,
-            pos, type, defining, in_pxd, modifiers, utility_code)
-
-    def WTK_declare_cfunction(
-        self, binding, pos, type, defining = 0,
-        in_pxd = 0, modifiers = (), utility_code = None):
-
+    def declare_cfunction(self, binding, type, defining = 0, in_pxd = 0,
+                          modifiers = (), utility_code = None, pos = None):
         # Add an entry for a C function.
         if not binding.cname:
             if binding.api or binding.c_visibility != 'private':
@@ -846,9 +835,8 @@ class BuiltinScope(Scope):
         # If python_equiv == "*", the Python equivalent has the same name
         # as the entry, otherwise it has the name specified by python_equiv.
         binding.name = EncodedString(binding.name)
-        entry = self.WTK_declare_cfunction(
-            binding, pos=None, type=type,
-            utility_code = utility_code)
+        entry = self.declare_cfunction(
+            binding, type=type, utility_code = utility_code)
         if python_equiv:
             if python_equiv == "*":
                 python_equiv = binding.name
@@ -1564,22 +1552,11 @@ class StructOrUnionScope(Scope):
                   "C struct/union member cannot be a Python object")
         return entry
 
-    def declare_cfunction(self, name, type, pos,
-                          cname = None, visibility = 'private', defining = 0,
-                          api = 0, in_pxd = 0, modifiers = (), utility_code = None):
-        binding = self._WTK_setup(name, cname, visibility)
-        binding.api = api
-        return self.WTK_declare_cfunction(
-            binding,
-            pos, type, defining, in_pxd, modifiers, utility_code)
-
-    def WTK_declare_cfunction(
-        self, binding, pos, type, defining = 0,
-        in_pxd = 0, modifiers = (), utility_code = None):
+    def declare_cfunction(self, binding, type, defining = 0, in_pxd = 0,
+                          modifiers = (), utility_code = None, pos = None):
         return self.WTK_declare_var(binding, type, pos=pos)
 
 
-
 class ClassScope(Scope):
     #  Abstract base class for namespace of
     #  Python class or extension type.
@@ -1768,18 +1745,8 @@ class CClassScope(ClassScope):
             name = EncodedString("__cinit__")
         return ClassScope.lookup_here(self, name)
 
-    def declare_cfunction(self, name, type, pos,
-                          cname = None, visibility = 'private', defining = 0,
-                          api = 0, in_pxd = 0, modifiers = (), utility_code = None):
-        binding = self._WTK_setup(name, cname, visibility)
-        binding.api = api
-        return self.WTK_declare_cfunction(
-            binding,
-            pos, type, defining, in_pxd, modifiers, utility_code)
-
-    def WTK_declare_cfunction(
-        self, binding, pos, type, defining = 0,
-        in_pxd = 0, modifiers = (), utility_code = None):
+    def declare_cfunction(self, binding, type, defining = 0, in_pxd = 0,
+                          modifiers = (), utility_code = None, pos = None):
         if get_special_method_signature(binding.name):
             error(pos, "Special methods must be declared with 'def', not 'cdef'")
         args = type.args
@@ -1836,9 +1803,8 @@ class CClassScope(ClassScope):
         binding.name = EncodedString(binding.name)
         #entry = self.declare_cfunction(binding.name, type, None, binding.cname, visibility='extern',
         #                               utility_code = utility_code)
-        entry = self.WTK_declare_cfunction(
-            binding, pos=None, type=type,
-            utility_code = utility_code)  # WTK: need all declare_cfunction-s wrapped
+        entry = self.declare_cfunction(
+            binding, type=type, utility_code = utility_code)
         var_entry = WTK_Entry(
             Binding(name=binding.name, cname=binding.name), py_object_type)
         var_entry.is_variable = 1
@@ -1945,18 +1911,10 @@ class CppClassScope(Scope):
             error(pos, "no matching function for call to %s::%s()" %
                   (self.default_constructor, self.default_constructor))
 
-    def declare_cfunction(self, name, type, pos,
-                          cname = None, visibility = 'extern', defining = 0,
-                          api = 0, in_pxd = 0, modifiers = (), utility_code = None):
-        binding = self._WTK_setup(name, cname, visibility)
-        binding.api = api
-        return self.WTK_declare_cfunction(
-            binding,
-            pos, type, defining, in_pxd, modifiers, utility_code)
-
-    def WTK_declare_cfunction(
-        self, binding, pos, type, defining = 0,
-        in_pxd = 0, modifiers = (), utility_code = None):
+    def declare_cfunction(self, binding, type, defining = 0, in_pxd = 0,
+                          modifiers = (), utility_code = None, pos = None):
+        if not binding.extern:
+            error(pos, "c++ cfunctions must be 'extern'")
         if binding.name == self.name.split('::')[-1] and binding.cname is None:
             self.check_base_default_constructor(pos)
             binding.name = '<init>'
@@ -1988,7 +1946,7 @@ class CppClassScope(Scope):
         for base_entry in base_scope.cfunc_entries:
             binding = Binding()
             binding.pull(base_entry)
-            entry = self.WTK_declare_cfunction(
+            entry = self.declare_cfunction(
                 binding, type = base_entry.type,
                 modifiers = base_entry.func_modifiers,
                 utility_code = base_entry.utility_code,
@@ -2014,9 +1972,8 @@ class CppClassScope(Scope):
                 for e in entry.all_alternatives():
                     binding = Binding()
                     binding.pull(e)
-                    scope.WTK_declare_cfunction(
-                        binding,
-                        type = e.type.specialize(values),
+                    scope.declare_cfunction(
+                        binding, type = e.type.specialize(values),
                         utility_code = e.utility_code, pos = e.pos)
         return scope