From 6373d6f33ba7cf9fe3cb8391ff183d1455be2765 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 5 Mar 2011 23:17:25 -0500 Subject: [PATCH] Normalize WTK_declare_cfunction -> declare_cfunction. --- Cython/Compiler/CythonScope.py | 21 ++++------ Cython/Compiler/ExprNodes.py | 5 ++- Cython/Compiler/Nodes.py | 8 ++-- Cython/Compiler/PyrexTypes.py | 20 ++++----- Cython/Compiler/Symtab.py | 77 ++++++++-------------------------- 5 files changed, 44 insertions(+), 87 deletions(-) diff --git a/Cython/Compiler/CythonScope.py b/Cython/Compiler/CythonScope.py index 52f27d01..5a8a7cf3 100644 --- a/Cython/Compiler/CythonScope.py +++ b/Cython/Compiler/CythonScope.py @@ -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='') + binding = Binding(name = 'shape', cname = '') + 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 diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 75c92660..72ed2ea1 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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'', return_type, self.pos) + binding = Binding( + name = u'', extern = True, c_visibility = 'public') + type.scope.declare_cfunction( + binding, type = return_type, pos = self.pos) constructor = type.scope.lookup(u'') self.class_type = type self.entry = constructor diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 0410ceef..5fe4ad7f 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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 diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 3b693958..631e0f6b 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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 diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 8cb8dae6..2cfe48bf 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -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 = '' @@ -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 -- 2.26.2