From 8fe9ce785d36795287326fac401041f11aee7fab Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 24 Feb 2011 09:55:21 -0500 Subject: [PATCH] Move Cython.Compiler.Symtab.Entry.name, .cname, and .api into Binding.* objects. --- Cython/Compiler/AnalysedTreeTransforms.py | 8 +- Cython/Compiler/Buffer.py | 42 +++--- Cython/Compiler/Code.py | 44 +++--- Cython/Compiler/ExprNodes.py | 88 +++++++---- Cython/Compiler/ModuleNode.py | 100 ++++++------ Cython/Compiler/Nodes.py | 176 +++++++++++++--------- Cython/Compiler/Optimize.py | 2 +- Cython/Compiler/ParseTreeTransforms.py | 31 ++-- Cython/Compiler/PyrexTypes.py | 8 +- Cython/Compiler/Symtab.py | 143 ++++++++++-------- 10 files changed, 373 insertions(+), 269 deletions(-) diff --git a/Cython/Compiler/AnalysedTreeTransforms.py b/Cython/Compiler/AnalysedTreeTransforms.py index de527e00..e2e0e8f1 100644 --- a/Cython/Compiler/AnalysedTreeTransforms.py +++ b/Cython/Compiler/AnalysedTreeTransforms.py @@ -73,13 +73,13 @@ class AutoTestDictTransform(ScopeTrackingTransform): pos = self.testspos if self.scope_type == 'module': - path = node.entry.name + path = node.entry.python_binding.name elif self.scope_type in ('pyclass', 'cclass'): if isinstance(node, CFuncDefNode): if node.py_func is not None: name = node.py_func.name else: - name = node.entry.name + name = node.entry.python_binding.name else: name = node.name if self.scope_type == 'cclass' and name in self.blacklist: @@ -91,9 +91,9 @@ class AutoTestDictTransform(ScopeTrackingTransform): if isinstance(node.entry.scope, Symtab.PropertyScope): property_method_name = node.entry.scope.name path = "%s.%s.%s" % (class_name, node.entry.scope.name, - node.entry.name) + node.entry.python_binding.name) else: - path = "%s.%s" % (class_name, node.entry.name) + path = "%s.%s" % (class_name, node.entry.python_binding.name) else: assert False self.add_test(node.pos, path, node.doc) diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index 3584234c..7bbcf9f3 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -63,7 +63,7 @@ class IntroduceBufferAuxiliaryVars(CythonTransform): if entry.type.dtype.is_ptr: raise CompileError(node.pos, "Buffers with pointer types not yet supported.") - name = entry.name + name = entry.python_binding.name buftype = entry.type if buftype.ndim > self.max_ndim: self.max_ndim = buftype.ndim @@ -221,7 +221,7 @@ def used_buffer_aux_vars(entry): def put_unpack_buffer_aux_into_scope(buffer_aux, mode, code): # Generate code to copy the needed struct info into local # variables. - bufstruct = buffer_aux.buffer_info_var.cname + bufstruct = buffer_aux.buffer_info_var.c_binding.name varspec = [("strides", buffer_aux.stridevars), ("shape", buffer_aux.shapevars)] @@ -230,13 +230,14 @@ def put_unpack_buffer_aux_into_scope(buffer_aux, mode, code): for field, vars in varspec: code.putln(" ".join(["%s = %s.%s[%d];" % - (s.cname, bufstruct, field, idx) + (s.c_binding.name, bufstruct, field, idx) for idx, s in enumerate(vars)])) def put_acquire_arg_buffer(entry, code, pos): code.globalstate.use_utility_code(acquire_utility_code) buffer_aux = entry.buffer_aux - getbuffer = get_getbuffer_call(code, entry.cname, buffer_aux, entry.type) + getbuffer = get_getbuffer_call( + code, entry.c_binding.name, buffer_aux, entry.type) # Acquire any new buffer code.putln("{") @@ -249,13 +250,14 @@ def put_acquire_arg_buffer(entry, code, pos): def put_release_buffer_code(code, entry): code.globalstate.use_utility_code(acquire_utility_code) - code.putln("__Pyx_SafeReleaseBuffer(&%s);" % entry.buffer_aux.buffer_info_var.cname) + code.putln("__Pyx_SafeReleaseBuffer(&%s);" % + entry.buffer_aux.buffer_info_var.c_binding.name) def get_getbuffer_call(code, obj_cname, buffer_aux, buffer_type): ndim = buffer_type.ndim cast = int(buffer_type.cast) flags = get_flags(buffer_aux, buffer_type) - bufstruct = buffer_aux.buffer_info_var.cname + bufstruct = buffer_aux.buffer_info_var.c_binding.name dtype_typeinfo = get_type_information_cname(code, buffer_type.dtype) @@ -280,7 +282,7 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type, """ code.globalstate.use_utility_code(acquire_utility_code) - bufstruct = buffer_aux.buffer_info_var.cname + bufstruct = buffer_aux.buffer_info_var.c_binding.name flags = get_flags(buffer_aux, buffer_type) code.putln("{") # Set up necesarry stack for getbuffer @@ -347,7 +349,7 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, """ bufaux = entry.buffer_aux - bufstruct = bufaux.buffer_info_var.cname + bufstruct = bufaux.buffer_info_var.c_binding.name negative_indices = directives['wraparound'] and entry.type.negative_indices if directives['boundscheck']: @@ -363,7 +365,7 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, # not unsigned, deal with negative index code.putln("if (%s < 0) {" % cname) if negative_indices: - code.putln("%s += %s;" % (cname, shape.cname)) + code.putln("%s += %s;" % (cname, shape.c_binding.name)) code.putln("if (%s) %s = %d;" % ( code.unlikely("%s < 0" % cname), tmp_cname, dim)) else: @@ -375,7 +377,8 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, else: cast = "(size_t)" code.putln("if (%s) %s = %d;" % ( - code.unlikely("%s >= %s%s" % (cname, cast, shape.cname)), + code.unlikely("%s >= %s%s" % ( + cname, cast, shape.c_binding.name)), tmp_cname, dim)) code.globalstate.use_utility_code(raise_indexerror_code) code.putln("if (%s) {" % code.unlikely("%s != -1" % tmp_cname)) @@ -388,7 +391,8 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, for signed, cname, shape in zip(index_signeds, index_cnames, bufaux.shapevars): if signed != 0: - code.putln("if (%s < 0) %s += %s;" % (cname, cname, shape.cname)) + code.putln("if (%s < 0) %s += %s;" % ( + cname, cname, shape.c_binding.name)) # Create buffer lookup and return it # This is done via utility macros/inline functions, which vary @@ -399,8 +403,8 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, if mode == 'full': for i, s, o in zip(index_cnames, bufaux.stridevars, bufaux.suboffsetvars): params.append(i) - params.append(s.cname) - params.append(o.cname) + params.append(s.c_binding.name) + params.append(o.c_binding.name) funcname = "__Pyx_BufPtrFull%dd" % nd funcgen = buf_lookup_full_code else: @@ -417,7 +421,7 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, assert False for i, s in zip(index_cnames, bufaux.stridevars): params.append(i) - params.append(s.cname) + params.append(s.c_binding.name) # Make sure the utility code is available if funcname not in code.globalstate.utility_codes: @@ -516,8 +520,10 @@ def use_py2_buffer_functions(env): if t.is_extension_type: release = get = None for x in t.scope.pyfunc_entries: - if x.name == u"__getbuffer__": get = x.func_cname - elif x.name == u"__releasebuffer__": release = x.func_cname + if x.python_binding.name == u"__getbuffer__": + get = x.func_cname + elif x.python_binding.name == u"__releasebuffer__": + release = x.func_cname if get: types.append((t.typeptr_cname, get, release)) @@ -629,7 +635,9 @@ def get_type_information_cname(code, dtype, maxdepth=None): typecode.putln("static __Pyx_StructField %s[] = {" % structinfo_name, safe=True) for f, typeinfo in zip(fields, types): typecode.putln(' {&%s, "%s", offsetof(%s, %s)},' % - (typeinfo, f.name, dtype.declaration_code(""), f.cname), safe=True) + (typeinfo, f.python_binding.name, + dtype.declaration_code(""), f.c_binding.name), + safe=True) typecode.putln(' {NULL, NULL, 0}', safe=True) typecode.putln("};", safe=True) else: diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 41221cf8..6e87df9d 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -355,7 +355,6 @@ class StringConst(object): prefix, (is_str and 's') or (is_unicode and 'u') or 'b', self.cname[len(Naming.const_prefix):]) - py_string = PyStringConst( pystring_cname, encoding, is_unicode, is_str, intern) self.py_strings[key] = py_string @@ -558,7 +557,7 @@ class GlobalState(object): w.exit_cfunc_scope() def put_pyobject_decl(self, entry): - self['global_var'].putln("static PyObject *%s;" % entry.cname) + self['global_var'].putln("static PyObject *%s;" % entry.c_binding.name) # constant handling at code generation time @@ -647,20 +646,21 @@ class GlobalState(object): def add_cached_builtin_decl(self, entry): if Options.cache_builtins: - if self.should_declare(entry.cname, entry): + if self.should_declare(entry.c_binding.name, entry): self.put_pyobject_decl(entry) w = self.parts['cached_builtins'] - if entry.name == 'xrange': + if entry.python_binding.name == 'xrange': # replaced by range() in Py3 w.putln('#if PY_MAJOR_VERSION >= 3') self.put_cached_builtin_init( entry.pos, StringEncoding.EncodedString('range'), - entry.cname) + entry.c_binding.name) w.putln('#else') self.put_cached_builtin_init( - entry.pos, StringEncoding.EncodedString(entry.name), - entry.cname) - if entry.name == 'xrange': + entry.pos, + StringEncoding.EncodedString(entry.python_binding.name), + entry.c_binding.name) + if entry.python_binding.name == 'xrange': w.putln('#endif') def put_cached_builtin_init(self, pos, name, cname): @@ -1109,7 +1109,7 @@ class CCodeWriter(object): def put_var_declaration(self, entry, static = 0, dll_linkage = None, definition = True): - #print "Code.put_var_declaration:", entry.name, "definition =", definition ### + #print "Code.put_var_declaration:", entry.python_binding.name, "definition =", definition ### if entry.in_closure: return visibility = entry.visibility @@ -1117,7 +1117,7 @@ class CCodeWriter(object): #print "...private and not definition, skipping" ### return if not entry.used and visibility == "private": - #print "not used and private, skipping", entry.cname ### + #print "not used and private, skipping", entry.c_binding.name ### return storage_class = "" if visibility == 'extern': @@ -1132,7 +1132,7 @@ class CCodeWriter(object): self.put("%s " % storage_class) if visibility != 'public': dll_linkage = None - self.put(entry.type.declaration_code(entry.cname, + self.put(entry.type.declaration_code(entry.c_binding.name, dll_linkage = dll_linkage)) if entry.init is not None: self.put_safe(" = %s" % entry.type.literal_code(entry.init)) @@ -1162,9 +1162,9 @@ class CCodeWriter(object): type = entry.type if (not entry.is_self_arg and not entry.type.is_complete() or entry.type.is_extension_type): - return "(PyObject *)" + entry.cname + return "(PyObject *)" + entry.c_binding.name else: - return entry.cname + return entry.c_binding.name def as_pyobject(self, cname, type): from PyrexTypes import py_object_type, typecast @@ -1247,7 +1247,7 @@ class CCodeWriter(object): def put_var_decref_clear(self, entry): if entry.type.is_pyobject: self.putln("__Pyx_DECREF(%s); %s = 0;" % ( - self.entry_as_pyobject(entry), entry.cname)) + self.entry_as_pyobject(entry), entry.c_binding.name)) def put_var_xdecref(self, entry): if entry.type.is_pyobject: @@ -1256,7 +1256,7 @@ class CCodeWriter(object): def put_var_xdecref_clear(self, entry): if entry.type.is_pyobject: self.putln("__Pyx_XDECREF(%s); %s = 0;" % ( - self.entry_as_pyobject(entry), entry.cname)) + self.entry_as_pyobject(entry), entry.c_binding.name)) def put_var_decrefs(self, entries, used_only = 0): for entry in entries: @@ -1283,15 +1283,19 @@ class CCodeWriter(object): self.putln("%s = %s; Py_INCREF(Py_None);" % (cname, py_none)) def put_init_var_to_py_none(self, entry, template = "%s", nanny=True): - code = template % entry.cname + code = template % entry.c_binding.name #if entry.type.is_extension_type: # code = "((PyObject*)%s)" % code self.put_init_to_py_none(code, entry.type, nanny) def put_pymethoddef(self, entry, term, allow_skip=True): - if entry.is_special or entry.name == '__getattribute__': - if entry.name not in ['__cinit__', '__dealloc__', '__richcmp__', '__next__', '__getreadbuffer__', '__getwritebuffer__', '__getsegcount__', '__getcharbuffer__', '__getbuffer__', '__releasebuffer__']: - if entry.name == '__getattr__' and not self.globalstate.directives['fast_getattr']: + if entry.is_special or entry.python_binding.name == '__getattribute__': + if entry.python_binding.name not in [ + '__cinit__', '__dealloc__', '__richcmp__', '__next__', + '__getreadbuffer__', '__getwritebuffer__', '__getsegcount__', + '__getcharbuffer__', '__getbuffer__', '__releasebuffer__']: + if (entry.python_binding.name == '__getattr__' and + not self.globalstate.directives['fast_getattr']): pass # Python's typeobject.c will automatically fill in our slot # in add_operators() (called by PyType_Ready) with a value @@ -1309,7 +1313,7 @@ class CCodeWriter(object): method_flags += [method_coexist] self.putln( '{__Pyx_NAMESTR("%s"), (PyCFunction)%s, %s, __Pyx_DOCSTR(%s)}%s' % ( - entry.name, + entry.python_binding.name, entry.func_cname, "|".join(method_flags), doc_code, diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 5b339da9..db68f2a4 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1322,7 +1322,7 @@ class NameNode(AtomicExprNode): def get_constant_c_result_code(self): if not self.entry or self.entry.type.is_pyobject: return None - return self.entry.cname + return self.entry.c_binding.name def coerce_to(self, dst_type, env): # If coercing to a generic pyobject and this is a builtin @@ -1335,7 +1335,8 @@ class NameNode(AtomicExprNode): var_entry = entry.as_variable if var_entry: if var_entry.is_builtin and Options.cache_builtins: - var_entry = env.declare_builtin(var_entry.name, self.pos) + var_entry = env.declare_builtin( + var_entry.python_binding.name, self.pos) node = NameNode(self.pos, name = self.name) node.entry = var_entry node.analyse_rvalue_entry(env) @@ -1511,7 +1512,7 @@ class NameNode(AtomicExprNode): entry = self.entry if not entry: return "" # There was an error earlier - return entry.cname + return entry.c_binding.name def generate_result_code(self, code): assert hasattr(self, 'entry') @@ -1522,7 +1523,8 @@ class NameNode(AtomicExprNode): return # Lookup already cached elif entry.is_pyclass_attr: assert entry.type.is_pyobject, "Python global or builtin not a Python object" - interned_cname = code.intern_identifier(self.entry.name) + interned_cname = code.intern_identifier( + self.entry.python_binding.name) if entry.is_builtin: namespace = Naming.builtins_cname else: # entry.is_pyglobal @@ -1537,7 +1539,8 @@ class NameNode(AtomicExprNode): elif entry.is_pyglobal or entry.is_builtin: assert entry.type.is_pyobject, "Python global or builtin not a Python object" - interned_cname = code.intern_identifier(self.entry.name) + interned_cname = code.intern_identifier( + self.entry.python_binding.name) if entry.is_builtin: namespace = Naming.builtins_cname else: # entry.is_pyglobal @@ -1553,13 +1556,20 @@ class NameNode(AtomicExprNode): elif entry.is_local and False: # control flow not good enough yet - assigned = entry.scope.control_flow.get_state((entry.name, 'initialized'), self.pos) + assigned = entry.scope.control_flow.get_state( + (entry.python_binding.name, 'initialized'), self.pos) if assigned is False: - error(self.pos, "local variable '%s' referenced before assignment" % entry.name) + error( + self.pos, + "local variable '%s' referenced before assignment" % + entry.python_binding.name) elif not Options.init_local_none and assigned is None: - code.putln('if (%s == 0) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }' % - (entry.cname, entry.name, code.error_goto(self.pos))) - entry.scope.control_flow.set_state(self.pos, (entry.name, 'initialized'), True) + code.putln( + 'if (%s == 0) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }' % + (entry.c_binding.name, entry.python_binding.name, + code.error_goto(self.pos))) + entry.scope.control_flow.set_state( + self.pos, (entry.python_binding.name, 'initialized'), True) def generate_assignment_code(self, rhs, code): #print "NameNode.generate_assignment_code:", self.name ### @@ -1575,7 +1585,8 @@ class NameNode(AtomicExprNode): # We use this to access class->tp_dict if necessary. if entry.is_pyglobal: assert entry.type.is_pyobject, "Python global or builtin not a Python object" - interned_cname = code.intern_identifier(self.entry.name) + interned_cname = code.intern_identifier( + self.entry.python_binding.name) namespace = self.entry.scope.namespace_cname if entry.is_member: # if the entry is a member we have to cheat: SetAttr does not work @@ -1631,7 +1642,9 @@ class NameNode(AtomicExprNode): code.put_gotref(self.py_result()) if not self.lhs_of_first_assignment: if entry.is_local and not Options.init_local_none: - initialized = entry.scope.control_flow.get_state((entry.name, 'initialized'), self.pos) + initialized = entry.scope.control_flow.get_state( + (entry.python_binding.name, 'initialized'), + self.pos) if initialized is True: code.put_decref(self.result(), self.ctype()) elif initialized is None: @@ -1661,7 +1674,7 @@ class NameNode(AtomicExprNode): code.putln('%s = %s;' % (rhstmp, rhs.result_as(self.ctype()))) buffer_aux = self.entry.buffer_aux - bufstruct = buffer_aux.buffer_info_var.cname + bufstruct = buffer_aux.buffer_info_var.c_binding.name import Buffer Buffer.put_assign_to_buffer(self.result(), rhstmp, buffer_aux, self.entry.type, is_initialized=not self.lhs_of_first_assignment, @@ -1682,12 +1695,12 @@ class NameNode(AtomicExprNode): code.put_error_if_neg(self.pos, 'PyMapping_DelItemString(%s, "%s")' % ( namespace, - self.entry.name)) + self.entry.python_binding.name)) else: code.put_error_if_neg(self.pos, '__Pyx_DelAttrString(%s, "%s")' % ( Naming.module_cname, - self.entry.name)) + self.entry.python_binding.name)) def annotate(self, code): if hasattr(self, 'is_called') and self.is_called: @@ -2776,7 +2789,10 @@ class CallNode(ExprNode): args, kwds = self.explicit_args_kwds() items = [] for arg, member in zip(args, type.scope.var_entries): - items.append(DictItemNode(pos=arg.pos, key=StringNode(pos=arg.pos, value=member.name), value=arg)) + items.append(DictItemNode( + pos=arg.pos, key=StringNode( + pos=arg.pos, value=member.python_binding.name), + value=arg)) if kwds: items += kwds.key_value_pairs self.key_value_pairs = items @@ -2857,9 +2873,10 @@ class SimpleCallNode(CallNode): if result_type.is_extension_type: return result_type elif result_type.is_builtin_type: - if function.entry.name == 'float': + if function.entry.python_binding.name == 'float': return PyrexTypes.c_double_type - elif function.entry.name in Builtin.types_that_construct_their_instance: + elif (function.entry.python_binding.name + in Builtin.types_that_construct_their_instance): return result_type return py_object_type @@ -2897,17 +2914,19 @@ class SimpleCallNode(CallNode): self.arg_tuple = TupleNode(self.pos, args = self.args) self.arg_tuple.analyse_types(env) self.args = None - if func_type is Builtin.type_type and function.is_name and \ - function.entry and \ - function.entry.is_builtin and \ - function.entry.name in Builtin.types_that_construct_their_instance: + if (func_type is Builtin.type_type and function.is_name and + function.entry and + function.entry.is_builtin and + (function.entry.python_binding.name + in Builtin.types_that_construct_their_instance)): # calling a builtin type that returns a specific object type - if function.entry.name == 'float': + if function.entry.python_binding.name == 'float': # the following will come true later on in a transform self.type = PyrexTypes.c_double_type self.result_ctype = PyrexTypes.c_double_type else: - self.type = Builtin.builtin_types[function.entry.name] + self.type = Builtin.builtin_types[ + function.entry.python_binding.name] self.result_ctype = py_object_type self.may_return_none = False elif function.is_name and function.type_entry: @@ -2928,7 +2947,8 @@ class SimpleCallNode(CallNode): self_arg = func_type.args[0] if self_arg.not_none: # C methods must do the None test for self at *call* time self.self = self.self.as_none_safe_node( - "'NoneType' object has no attribute '%s'" % self.function.entry.name, + "'NoneType' object has no attribute '%s'" % + self.function.entry.python_binding.name, 'PyExc_AttributeError') expected_type = self_arg.type self.coerced_self = CloneNode(self.self).coerce_to( @@ -3159,10 +3179,11 @@ class SimpleCallNode(CallNode): raise_py_exception = "__Pyx_CppExn2PyErr()" elif func_type.exception_value.type.is_pyobject: raise_py_exception = ' try { throw; } catch(const std::exception& exn) { PyErr_SetString(%s, exn.what()); } catch(...) { PyErr_SetNone(%s); }' % ( - func_type.exception_value.entry.cname, - func_type.exception_value.entry.cname) + func_type.exception_value.entry.c_binding.name, + func_type.exception_value.entry.c_binding.name) else: - raise_py_exception = '%s(); if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError , "Error converting c++ exception.")' % func_type.exception_value.entry.cname + raise_py_exception = '%s(); if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError , "Error converting c++ exception.")' % ( + func_type.exception_value.entry.c_binding.name) if self.nogil: raise_py_exception = 'Py_BLOCK_THREADS; %s; Py_UNBLOCK_THREADS' % raise_py_exception code.putln( @@ -3483,8 +3504,8 @@ class AttributeNode(ExprNode): if entry and entry.is_cmethod: # Create a temporary entry describing the C method # as an ordinary function. - ubcm_entry = Symtab.Entry(entry.name, - "%s->%s" % (type.vtabptr_cname, entry.cname), + ubcm_entry = Symtab.Entry(entry.python_binding.name, + "%s->%s" % (type.vtabptr_cname, entry.c_binding.name), entry.type) ubcm_entry.is_cfunction = 1 ubcm_entry.func_cname = entry.func_cname @@ -3584,13 +3605,14 @@ class AttributeNode(ExprNode): return self.entry = entry if entry: - if obj_type.is_extension_type and entry.name == "__weakref__": + if (obj_type.is_extension_type and + entry.python_binding.name == "__weakref__"): error(self.pos, "Illegal use of special attribute __weakref__") # methods need the normal attribute lookup # because they do not have struct entries if entry.is_variable or entry.is_cmethod: self.type = entry.type - self.member = entry.cname + self.member = entry.c_binding.name return else: # If it's not a variable or C method, it must be a Python @@ -4219,7 +4241,7 @@ class ListNode(SequenceNode): for arg, member in zip(self.args, self.type.scope.var_entries): code.putln("%s.%s = %s;" % ( self.result(), - member.cname, + member.c_binding.name, arg.result())) else: raise InternalError("List type never specified") diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 72721b6a..6b1e2ae1 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -149,10 +149,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): h_code.putln("%s %s;" % ( Naming.extern_c_macro, entry.type.declaration_code( - entry.cname, dll_linkage = "DL_IMPORT"))) + entry.c_binding.name, dll_linkage = "DL_IMPORT"))) if i_code: i_code.putln("cdef extern %s" % - entry.type.declaration_code(entry.cname, pyrex = 1)) + entry.type.declaration_code(entry.c_binding.name, pyrex = 1)) def api_name(self, env): return env.qualified_name.replace(".", "__") @@ -162,12 +162,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): public_extension_types = [] has_api_extension_types = 0 for entry in env.cfunc_entries: - if entry.api: + if entry.c_binding.api: api_funcs.append(entry) for entry in env.c_class_entries: if entry.visibility == 'public': public_extension_types.append(entry) - if entry.api: + if entry.c_binding.api: has_api_extension_types = 1 if api_funcs or has_api_extension_types: result.api_file = replace_suffix(result.c_file, "_api.h") @@ -189,7 +189,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): h_code.putln("") for entry in api_funcs: type = CPtrType(entry.type) - h_code.putln("static %s;" % type.declaration_code(entry.cname)) + h_code.putln("static %s;" % type.declaration_code( + entry.c_binding.name)) h_code.putln("") h_code.put_h_guard(Naming.api_func_guard + "import_module") h_code.put(import_module_utility_code.impl) @@ -210,8 +211,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): sig = entry.type.signature_string() h_code.putln( 'if (__Pyx_ImportFunction(module, "%s", (void (**)(void))&%s, "%s") < 0) goto bad;' % ( - entry.name, - entry.cname, + entry.python_binding.name, + entry.c_binding.name, sig)) h_code.putln("Py_DECREF(module); module = 0;") for entry in public_extension_types: @@ -244,8 +245,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): var_entries = type.scope.var_entries if var_entries: for entry in var_entries: - i_code.putln("cdef %s" % - entry.type.declaration_code(entry.cname, pyrex = 1)) + i_code.putln("cdef %s" % entry.type.declaration_code( + entry.c_binding.name, pyrex = 1)) else: i_code.putln("pass") i_code.dedent() @@ -412,7 +413,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): type_entries.append(entry) for entry in type_entries: if not entry.in_cinclude: - #print "generate_type_header_code:", entry.name, repr(entry.type) ### + #print "generate_type_header_code:", entry.python_binding.name, repr(entry.type) ### type = entry.type if type.is_typedef: # Must test this first! self.generate_typedef(entry, code) @@ -758,7 +759,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): #for entry in env.type_entries: for entry in type_entries: if not entry.in_cinclude: - #print "generate_type_header_code:", entry.name, repr(entry.type) ### + #print "generate_type_header_code:", entry.python_binding.name, repr(entry.type) ### type = entry.type if type.is_typedef: # Must test this first! self.generate_typedef(entry, code) @@ -790,7 +791,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): else: writer = code writer.putln("") - writer.putln("typedef %s;" % base_type.declaration_code(entry.cname)) + writer.putln("typedef %s;" % base_type.declaration_code( + entry.c_binding.name)) def sue_header_footer(self, type, kind, name): if type.typedef_flag: @@ -829,7 +831,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for attr in var_entries: code.putln( "%s;" % - attr.type.declaration_code(attr.cname)) + attr.type.declaration_code(attr.c_binding.name)) code.putln(footer) if packed: code.putln("#if defined(__SUNPRO_C)") @@ -841,7 +843,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_enum_definition(self, entry, code): code.mark_pos(entry.pos) type = entry.type - name = entry.cname or entry.name or "" + name = entry.c_binding.name or entry.python_binding.name or "" header, footer = \ self.sue_header_footer(type, "enum", name) code.putln("") @@ -860,10 +862,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for value_entry in enum_values: if value_entry.value_node is None: - value_code = value_entry.cname + value_code = value_entry.c_binding.name else: value_code = ("%s = %s" % ( - value_entry.cname, + value_entry.c_binding.name, value_entry.value_node.result())) if value_entry is not last_entry: value_code += "," @@ -903,7 +905,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for method_entry in scope.cfunc_entries: if not method_entry.is_inherited: code.putln( - "%s;" % method_entry.type.declaration_code("(*%s)" % method_entry.name)) + "%s;" % method_entry.type.declaration_code( + "(*%s)" % method_entry.python_binding.name)) code.putln( "};") @@ -944,7 +947,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for attr in type.scope.var_entries: code.putln( "%s;" % - attr.type.declaration_code(attr.cname)) + attr.type.declaration_code(attr.c_binding.name)) code.putln(footer) if type.objtypedef_cname is not None: # Only for exposing public typedef name. @@ -970,7 +973,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): type = entry.type if not definition and entry.defined_in_pxd: type = CPtrType(type) - header = type.declaration_code(entry.cname, + header = type.declaration_code(entry.c_binding.name, dll_linkage = dll_linkage) if entry.visibility == 'private': storage_class = "static " @@ -991,7 +994,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_typeobj_definitions(self, env, code): full_module_name = env.qualified_name for entry in env.c_class_entries: - #print "generate_typeobj_definitions:", entry.name + #print "generate_typeobj_definitions:", entry.python_binding.name #print "...visibility =", entry.visibility if entry.visibility != 'extern': type = entry.type @@ -1089,9 +1092,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): type.vtabslot_cname, struct_type_cast, type.vtabptr_cname)) for entry in py_attrs: - if scope.is_internal or entry.name == "__weakref__": + if scope.is_internal or entry.python_binding.name == "__weakref__": # internal classes do not need None inits - code.putln("p->%s = 0;" % entry.cname) + code.putln("p->%s = 0;" % entry.c_binding.name) else: code.put_init_var_to_py_none(entry, "p->%s", nanny=False) entry = scope.lookup_here("__new__") @@ -1132,7 +1135,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if weakref_slot in scope.var_entries: code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);") for entry in py_attrs: - code.put_xdecref("p->%s" % entry.cname, entry.type, nanny=False) + code.put_xdecref( + "p->%s" % entry.c_binding.name, entry.type, nanny=False) if base_type: tp_dealloc = TypeSlots.get_base_slot_function(scope, tp_slot) if tp_dealloc is None: @@ -1180,7 +1184,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): % slot_func) py_attrs = [] for entry in scope.var_entries: - if entry.type.is_pyobject and entry.name != "__weakref__": + if (entry.type.is_pyobject and + entry.python_binding.name != "__weakref__"): py_attrs.append(entry) if base_type or py_attrs: code.putln("int e;") @@ -1198,7 +1203,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): base_type.typeptr_cname) code.putln("}") for entry in py_attrs: - var_code = "p->%s" % entry.cname + var_code = "p->%s" % entry.c_binding.name code.putln( "if (%s) {" % var_code) @@ -1224,7 +1229,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("static int %s(PyObject *o) {" % slot_func) py_attrs = [] for entry in scope.var_entries: - if entry.type.is_pyobject and entry.name != "__weakref__": + if (entry.type.is_pyobject and + entry.python_binding.name != "__weakref__"): py_attrs.append(entry) if py_attrs: self.generate_self_cast(scope, code) @@ -1239,7 +1245,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("%s->tp_clear(o);" % base_type.typeptr_cname) code.putln("}") for entry in py_attrs: - name = "p->%s" % entry.cname + name = "p->%s" % entry.c_binding.name code.putln("tmp = ((PyObject*)%s);" % name) code.put_init_to_py_none(name, entry.type, nanny=False) code.putln("Py_XDECREF(tmp);") @@ -1551,7 +1557,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_property_get_function(self, property_entry, code): property_scope = property_entry.scope property_entry.getter_cname = property_scope.parent_scope.mangle( - Naming.prop_get_prefix, property_entry.name) + Naming.prop_get_prefix, property_entry.python_binding.name) get_entry = property_scope.lookup_here("__get__") code.putln("") code.putln( @@ -1566,7 +1572,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_property_set_function(self, property_entry, code): property_scope = property_entry.scope property_entry.setter_cname = property_scope.parent_scope.mangle( - Naming.prop_set_prefix, property_entry.name) + Naming.prop_set_prefix, property_entry.python_binding.name) set_entry = property_scope.lookup_here("__set__") del_entry = property_scope.lookup_here("__del__") code.putln("") @@ -1658,7 +1664,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): doc_code = "0" code.putln( '{(char *)"%s", %s, %s, %s, 0},' % ( - entry.name, + entry.python_binding.name, entry.getter_cname or "0", entry.setter_cname or "0", doc_code)) @@ -1698,18 +1704,19 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): entry.type.type_test_code("o"), code.error_goto(entry.pos))) code.putln("Py_INCREF(o);") - code.put_decref(entry.cname, entry.type, nanny=False) + code.put_decref( + entry.c_binding.name, entry.type, nanny=False) code.putln("%s = %s;" % ( - entry.cname, + entry.c_binding.name, PyrexTypes.typecast(entry.type, py_object_type, "o"))) elif entry.type.from_py_function: rhs = "%s(o)" % entry.type.from_py_function if entry.type.is_enum: rhs = PyrexTypes.typecast(entry.type, PyrexTypes.c_long_type, rhs) code.putln("%s = %s; if (%s) %s;" % ( - entry.cname, + entry.c_binding.name, rhs, - entry.type.error_condition(entry.cname), + entry.type.error_condition(entry.c_binding.name), code.error_goto(entry.pos))) else: code.putln('PyErr_Format(PyExc_TypeError, "Cannot convert Python object %s to %s");' % (name, entry.type)) @@ -1864,7 +1871,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if entry.visibility != 'extern': if entry.type.is_pyobject and entry.used: code.putln("Py_DECREF(%s); %s = 0;" % ( - code.entry_as_pyobject(entry), entry.cname)) + code.entry_as_pyobject(entry), + entry.c_binding.name)) code.putln("__Pyx_CleanupGlobals();") if Options.generate_cleanup_code >= 3: code.putln("/*--- Type import cleanup code ---*/") @@ -1873,7 +1881,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if Options.cache_builtins: code.putln("/*--- Builtin cleanup code ---*/") for entry in env.cached_builtins: - code.put_decref_clear(entry.cname, + code.put_decref_clear(entry.c_binding.name, PyrexTypes.py_object_type, nanny=False) code.putln("/*--- Intern cleanup code ---*/") @@ -1881,7 +1889,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): PyrexTypes.py_object_type, nanny=False) # for entry in env.pynum_entries: -# code.put_decref_clear(entry.cname, +# code.put_decref_clear(entry.c_binding.name, # PyrexTypes.py_object_type, # nanny=False) # for entry in env.all_pystring_entries: @@ -1892,7 +1900,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): # for entry in env.default_entries: # if entry.type.is_pyobject and entry.used: # code.putln("Py_DECREF(%s); %s = 0;" % ( -# code.entry_as_pyobject(entry), entry.cname)) +# code.entry_as_pyobject(entry), entry.c_binding.name)) code.putln("Py_INCREF(Py_None); return Py_None;") def generate_main_method(self, env, code): @@ -1990,12 +1998,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_c_function_export_code(self, env, code): # Generate code to create PyCFunction wrappers for exported C functions. for entry in env.cfunc_entries: - if entry.api or entry.defined_in_pxd: + if entry.c_binding.api or entry.defined_in_pxd: env.use_utility_code(function_export_utility_code) signature = entry.type.signature_string() code.putln('if (__Pyx_ExportFunction("%s", (void (*)(void))%s, "%s") < 0) %s' % ( - entry.name, - entry.cname, + entry.python_binding.name, + entry.c_binding.name, signature, code.error_goto(self.pos))) @@ -2027,8 +2035,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln( 'if (__Pyx_ImportFunction(%s, "%s", (void (**)(void))&%s, "%s") < 0) %s' % ( temp, - entry.name, - entry.cname, + entry.python_binding.name, + entry.c_binding.name, entry.type.signature_string(), code.error_goto(self.pos))) code.putln("Py_DECREF(%s); %s = 0;" % (temp, temp)) @@ -2131,7 +2139,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln( 'PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&%s, "%s"); %s' % ( typeobj_cname, - func.name, + func.python_binding.name, code.error_goto_if_null('wrapper', entry.pos))) code.putln( "if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {") @@ -2174,7 +2182,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): tp_weaklistoffset, tp_weaklistoffset, objstruct, - weakref_entry.cname)) + weakref_entry.c_binding.name)) else: error(weakref_entry.pos, "__weakref__ slot must be of type 'object'") @@ -2203,7 +2211,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln( "%s.%s = %s%s;" % ( type.vtable_cname, - meth_entry.cname, + meth_entry.c_binding.name, cast, meth_entry.func_cname)) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 375a4621..3a3242cb 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1016,8 +1016,8 @@ class CStructOrUnionDefNode(StatNode): cname = self.cname, visibility='ignore') struct_entry.type.typedef_flag = False # FIXME: this might be considered a hack ;-) - struct_entry.cname = struct_entry.type.cname = \ - '_' + self.entry.type.typedef_cname + struct_entry.c_binding.name = struct_entry.type.cname = ( + '_' + self.entry.type.typedef_cname) def analyse_expressions(self, env): pass @@ -1094,12 +1094,12 @@ class CEnumDefNode(StatNode): for item in self.entry.enum_values: code.putln("%s = PyInt_FromLong(%s); %s" % ( temp, - item.cname, + item.c_binding.name, code.error_goto_if_null(temp, item.pos))) code.put_gotref(temp) code.putln('if (__Pyx_SetAttrString(%s, "%s", %s) < 0) %s' % ( Naming.module_cname, - item.name, + item.python_binding.name, temp, code.error_goto(item.pos))) code.put_decref_clear(temp, PyrexTypes.py_object_type) @@ -1191,11 +1191,11 @@ class FuncDefNode(StatNode, BlockNode): while genv.is_py_class_scope or genv.is_c_class_scope: genv = genv.outer_scope if self.needs_closure: - lenv = ClosureScope(name=self.entry.name, + lenv = ClosureScope(name=self.entry.python_binding.name, outer_scope = genv, - scope_name=self.entry.cname) + scope_name=self.entry.c_binding.name) else: - lenv = LocalScope(name=self.entry.name, + lenv = LocalScope(name=self.entry.python_binding.name, outer_scope=genv, parent_scope=env) lenv.return_type = self.return_type @@ -1221,10 +1221,12 @@ class FuncDefNode(StatNode, BlockNode): # generate lambda function definitions self.generate_lambda_definitions(lenv, code) - is_getbuffer_slot = (self.entry.name == "__getbuffer__" and - self.entry.scope.is_c_class_scope) - is_releasebuffer_slot = (self.entry.name == "__releasebuffer__" and - self.entry.scope.is_c_class_scope) + is_getbuffer_slot = ( + self.entry.python_binding.name == "__getbuffer__" and + self.entry.scope.is_c_class_scope) + is_releasebuffer_slot = ( + self.entry.python_binding.name == "__releasebuffer__" and + self.entry.scope.is_c_class_scope) is_buffer_slot = is_getbuffer_slot or is_releasebuffer_slot if is_buffer_slot: if 'cython_unused' not in self.modifiers: @@ -1232,10 +1234,11 @@ class FuncDefNode(StatNode, BlockNode): preprocessor_guard = None if self.entry.is_special and not is_buffer_slot: - slot = TypeSlots.method_name_to_slot.get(self.entry.name) + slot = TypeSlots.method_name_to_slot.get( + self.entry.python_binding.name) if slot: preprocessor_guard = slot.preprocessor_guard_code() - if (self.entry.name == '__long__' and + if (self.entry.python_binding.name == '__long__' and not self.entry.scope.lookup_here('__int__')): preprocessor_guard = None @@ -1306,7 +1309,7 @@ class FuncDefNode(StatNode, BlockNode): code.putln("#endif") # ----- set up refnanny if not lenv.nogil: - code.put_setup_refcount_context(self.entry.name) + code.put_setup_refcount_context(self.entry.python_binding.name) # ----- Automatic lead-ins for certain special functions if is_getbuffer_slot: self.getbuffer_init(code) @@ -1343,7 +1346,7 @@ class FuncDefNode(StatNode, BlockNode): if profile: # this looks a bit late, but if we don't get here due to a # fatal error before hand, it's not really worth tracing - code.put_trace_call(self.entry.name, self.pos) + code.put_trace_call(self.entry.python_binding.name, self.pos) # ----- Fetch arguments self.generate_argument_parsing_code(env, code) # If an argument is assigned to in the body, we must @@ -1360,7 +1363,7 @@ class FuncDefNode(StatNode, BlockNode): for entry in lenv.var_entries + lenv.arg_entries: if entry.type.is_buffer and entry.buffer_aux.buffer_info_var.used: code.putln("%s.buf = NULL;" % - entry.buffer_aux.buffer_info_var.cname) + entry.buffer_aux.buffer_info_var.c_binding.name) # ----- Check and convert arguments self.generate_argument_type_tests(code) # ----- Acquire buffer arguments @@ -1401,7 +1404,7 @@ class FuncDefNode(StatNode, BlockNode): code.putln("__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);") for entry in lenv.buffer_entries: Buffer.put_release_buffer_code(code, entry) - #code.putln("%s = 0;" % entry.cname) + #code.putln("%s = 0;" % entry.c_binding.name) code.putln("__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}") err_val = self.error_value() @@ -1446,7 +1449,9 @@ class FuncDefNode(StatNode, BlockNode): code.put_label(code.return_from_error_cleanup_label) if not Options.init_local_none: for entry in lenv.var_entries: - if lenv.control_flow.get_state((entry.name, 'initialized')) is not True: + if lenv.control_flow.get_state( + (entry.python_binding.name, 'initialized') + ) is not True: entry.xdecref_cleanup = 1 for entry in lenv.var_entries: @@ -1454,7 +1459,7 @@ class FuncDefNode(StatNode, BlockNode): if entry.used and not entry.in_closure: code.put_var_decref(entry) elif entry.in_closure and self.needs_closure: - code.put_giveref(entry.cname) + code.put_giveref(entry.c_binding.name) # Decref any increfed args for entry in lenv.arg_entries: if entry.type.is_pyobject: @@ -1475,7 +1480,8 @@ class FuncDefNode(StatNode, BlockNode): if self.return_type.is_pyobject: code.put_xgiveref(self.return_type.as_pyobject(Naming.retval_cname)) - if self.entry.is_special and self.entry.name == "__hash__": + if (self.entry.is_special and + self.entry.python_binding.name == "__hash__"): # Returning -1 for __hash__ is supposed to signal an error # We do as Python instances and coerce -1 into -2. code.putln("if (unlikely(%s == -1) && !PyErr_Occurred()) %s = -2;" % ( @@ -1523,7 +1529,7 @@ class FuncDefNode(StatNode, BlockNode): if arg.type.typeobj_is_available(): code.globalstate.use_utility_code(arg_type_test_utility_code) typeptr_cname = arg.type.typeptr_cname - arg_code = "((PyObject *)%s)" % arg.entry.cname + arg_code = "((PyObject *)%s)" % arg.entry.c_binding.name code.putln( 'if (unlikely(!__Pyx_ArgTypeTest(%s, %s, %d, "%s", %s))) %s' % ( arg_code, @@ -1538,7 +1544,8 @@ class FuncDefNode(StatNode, BlockNode): def generate_arg_none_check(self, arg, code): # Generate None check for one argument. - code.putln('if (unlikely(((PyObject *)%s) == Py_None)) {' % arg.entry.cname) + code.putln('if (unlikely(((PyObject *)%s) == Py_None)) {' % + arg.entry.c_binding.name) code.putln('''PyErr_Format(PyExc_TypeError, "Argument '%s' must not be None"); %s''' % ( arg.name, code.error_goto(arg.pos))) @@ -1572,7 +1579,7 @@ class FuncDefNode(StatNode, BlockNode): # Special code for the __getbuffer__ function # def getbuffer_init(self, code): - info = self.local_scope.arg_entries[1].cname + info = self.local_scope.arg_entries[1].c_binding.name # Python 3.0 betas have a bug in memoryview which makes it call # getbuffer with a NULL parameter. For now we work around this; # the following line should be removed when this bug is fixed. @@ -1581,13 +1588,13 @@ class FuncDefNode(StatNode, BlockNode): code.put_giveref("%s->obj" % info) # Do not refnanny object within structs def getbuffer_error_cleanup(self, code): - info = self.local_scope.arg_entries[1].cname + info = self.local_scope.arg_entries[1].c_binding.name code.put_gotref("%s->obj" % info) code.putln("__Pyx_DECREF(%s->obj); %s->obj = NULL;" % (info, info)) def getbuffer_normal_cleanup(self, code): - info = self.local_scope.arg_entries[1].cname + info = self.local_scope.arg_entries[1].c_binding.name code.putln("if (%s->obj == Py_None) {" % info) code.put_gotref("Py_None") code.putln("__Pyx_DECREF(Py_None); %s->obj = NULL;" % info) @@ -1617,7 +1624,7 @@ class CFuncDefNode(FuncDefNode): directive_locals = {} def unqualified_name(self): - return self.entry.name + return self.entry.python_binding.name def analyse_declarations(self, env): self.directive_locals.update(env.directives['locals']) @@ -1665,7 +1672,7 @@ class CFuncDefNode(FuncDefNode): import ExprNodes py_func_body = self.call_self_node(is_module_scope = env.is_module_scope) self.py_func = DefNode(pos = self.pos, - name = self.entry.name, + name = self.entry.python_binding.name, args = self.args, star_arg = None, starstar_arg = None, @@ -1689,10 +1696,13 @@ class CFuncDefNode(FuncDefNode): args = args[:len(args) - self.type.optional_arg_count] arg_names = [arg.name for arg in args] if is_module_scope: - cfunc = ExprNodes.NameNode(self.pos, name=self.entry.name) + cfunc = ExprNodes.NameNode( + self.pos, name=self.entry.python_binding.name) else: self_arg = ExprNodes.NameNode(self.pos, name=arg_names[0]) - cfunc = ExprNodes.AttributeNode(self.pos, obj=self_arg, attribute=self.entry.name) + cfunc = ExprNodes.AttributeNode( + self.pos, obj=self_arg, + attribute=self.entry.python_binding.name) skip_dispatch = not is_module_scope or Options.lookup_module_cpdef c_call = ExprNodes.SimpleCallNode(self.pos, function=cfunc, args=[ExprNodes.NameNode(self.pos, name=n) for n in arg_names[1-is_module_scope:]], wrapper_call=skip_dispatch) return ReturnStatNode(pos=self.pos, return_type=PyrexTypes.py_object_type, value=c_call) @@ -1785,7 +1795,9 @@ class CFuncDefNode(FuncDefNode): declarator = arg.declarator while not hasattr(declarator, 'name'): declarator = declarator.base - code.putln('%s = %s->%s;' % (arg.cname, Naming.optional_args_cname, self.type.opt_arg_cname(declarator.name))) + code.putln('%s = %s->%s;' % ( + arg.cname, Naming.optional_args_cname, + self.type.opt_arg_cname(declarator.name))) i += 1 for _ in range(self.type.optional_arg_count): code.putln('}') @@ -2164,7 +2176,10 @@ class DefNode(FuncDefNode): entry.doc_cname = \ Naming.funcdoc_prefix + prefix + name if entry.is_special: - if entry.name in TypeSlots.invisible or not entry.doc or (entry.name in '__getattr__' and env.directives['fast_getattr']): + if (entry.python_binding.name in TypeSlots.invisible or + not entry.doc or + (entry.python_binding.name in '__getattr__' and + env.directives['fast_getattr'])): entry.wrapperbase_cname = None else: entry.wrapperbase_cname = Naming.wrapperbase_prefix + prefix + name @@ -2412,17 +2427,20 @@ class DefNode(FuncDefNode): if arg.is_generic: item = PyrexTypes.typecast(arg.type, PyrexTypes.py_object_type, item) entry = arg.entry - code.putln("%s = %s;" % (entry.cname, item)) + code.putln("%s = %s;" % (entry.c_binding.name, item)) if entry.in_closure: code.put_var_incref(entry) else: func = arg.type.from_py_function if func: code.putln("%s = %s(%s); %s" % ( - arg.entry.cname, + arg.entry.c_binding.name, func, item, - code.error_goto_if(arg.type.error_condition(arg.entry.cname), arg.pos))) + code.error_goto_if( + arg.type.error_condition( + arg.entry.c_binding.name), + arg.pos))) else: error(arg.pos, "Cannot convert Python object argument to type '%s'" % arg.type) @@ -2459,32 +2477,34 @@ class DefNode(FuncDefNode): if self.starstar_arg: code.putln("%s = (%s) ? PyDict_Copy(%s) : PyDict_New();" % ( - self.starstar_arg.entry.cname, + self.starstar_arg.entry.c_binding.name, Naming.kwds_cname, Naming.kwds_cname)) code.putln("if (unlikely(!%s)) return %s;" % ( - self.starstar_arg.entry.cname, self.error_value())) + self.starstar_arg.entry.c_binding.name, + self.error_value())) self.starstar_arg.entry.xdecref_cleanup = 0 - code.put_gotref(self.starstar_arg.entry.cname) + code.put_gotref(self.starstar_arg.entry.c_binding.name) if self.self_in_stararg: # need to create a new tuple with 'self' inserted as first item code.put("%s = PyTuple_New(PyTuple_GET_SIZE(%s)+1); if (unlikely(!%s)) " % ( - self.star_arg.entry.cname, + self.star_arg.entry.c_binding.name, Naming.args_cname, - self.star_arg.entry.cname)) + self.star_arg.entry.c_binding.name)) if self.starstar_arg: code.putln("{") - code.put_decref_clear(self.starstar_arg.entry.cname, py_object_type) + code.put_decref_clear( + self.starstar_arg.entry.c_binding.name, py_object_type) code.putln("return %s;" % self.error_value()) code.putln("}") else: code.putln("return %s;" % self.error_value()) - code.put_gotref(self.star_arg.entry.cname) + code.put_gotref(self.star_arg.entry.c_binding.name) code.put_incref(Naming.self_cname, py_object_type) code.put_giveref(Naming.self_cname) code.putln("PyTuple_SET_ITEM(%s, 0, %s);" % ( - self.star_arg.entry.cname, Naming.self_cname)) + self.star_arg.entry.c_binding.name, Naming.self_cname)) temp = code.funcstate.allocate_temp(PyrexTypes.c_py_ssize_t_type, manage_ref=False) code.putln("for (%s=0; %s < PyTuple_GET_SIZE(%s); %s++) {" % ( temp, temp, Naming.args_cname, temp)) @@ -2493,14 +2513,14 @@ class DefNode(FuncDefNode): code.put_incref("item", py_object_type) code.put_giveref("item") code.putln("PyTuple_SET_ITEM(%s, %s+1, item);" % ( - self.star_arg.entry.cname, temp)) + self.star_arg.entry.c_binding.name, temp)) code.putln("}") code.funcstate.release_temp(temp) self.star_arg.entry.xdecref_cleanup = 0 elif self.star_arg: code.put_incref(Naming.args_cname, py_object_type) code.putln("%s = %s;" % ( - self.star_arg.entry.cname, + self.star_arg.entry.c_binding.name, Naming.args_cname)) self.star_arg.entry.xdecref_cleanup = 0 @@ -2617,37 +2637,41 @@ class DefNode(FuncDefNode): if arg.is_generic and arg.default: code.putln( "%s = %s;" % ( - arg.entry.cname, + arg.entry.c_binding.name, arg.calculate_default_value_code(code))) def generate_stararg_init_code(self, max_positional_args, code): if self.starstar_arg: self.starstar_arg.entry.xdecref_cleanup = 0 code.putln('%s = PyDict_New(); if (unlikely(!%s)) return %s;' % ( - self.starstar_arg.entry.cname, - self.starstar_arg.entry.cname, + self.starstar_arg.entry.c_binding.name, + self.starstar_arg.entry.c_binding.name, self.error_value())) - code.put_gotref(self.starstar_arg.entry.cname) + code.put_gotref(self.starstar_arg.entry.c_binding.name) if self.star_arg: self.star_arg.entry.xdecref_cleanup = 0 code.putln('if (PyTuple_GET_SIZE(%s) > %d) {' % ( Naming.args_cname, max_positional_args)) code.put('%s = PyTuple_GetSlice(%s, %d, PyTuple_GET_SIZE(%s)); ' % ( - self.star_arg.entry.cname, Naming.args_cname, + self.star_arg.entry.c_binding.name, Naming.args_cname, max_positional_args, Naming.args_cname)) - code.put_gotref(self.star_arg.entry.cname) + code.put_gotref(self.star_arg.entry.c_binding.name) if self.starstar_arg: code.putln("") - code.putln("if (unlikely(!%s)) {" % self.star_arg.entry.cname) - code.put_decref_clear(self.starstar_arg.entry.cname, py_object_type) + code.putln("if (unlikely(!%s)) {" % + self.star_arg.entry.c_binding.name) + code.put_decref_clear( + self.starstar_arg.entry.c_binding.name, py_object_type) code.putln('return %s;' % self.error_value()) code.putln('}') else: code.putln("if (unlikely(!%s)) return %s;" % ( - self.star_arg.entry.cname, self.error_value())) + self.star_arg.entry.c_binding.name, + self.error_value())) code.putln('} else {') - code.put("%s = %s; " % (self.star_arg.entry.cname, Naming.empty_tuple)) + code.put("%s = %s; " % ( + self.star_arg.entry.c_binding.name, Naming.empty_tuple)) code.put_incref(Naming.empty_tuple, py_object_type) code.putln('}') @@ -2788,7 +2812,9 @@ class DefNode(FuncDefNode): 'if (unlikely(__Pyx_ParseOptionalKeywords(%s, %s, %s, values, %s, "%s") < 0)) ' % ( Naming.kwds_cname, Naming.pykwdlist_cname, - self.starstar_arg and self.starstar_arg.entry.cname or '0', + (self.starstar_arg and + self.starstar_arg.entry.c_binding.name or + '0'), pos_arg_count, self.name)) code.putln(code.error_goto(self.pos)) @@ -2803,7 +2829,7 @@ class DefNode(FuncDefNode): code.putln('} else {') code.putln( "%s = %s;" % ( - arg.entry.cname, + arg.entry.c_binding.name, arg.calculate_default_value_code(code))) code.putln('}') @@ -2815,7 +2841,8 @@ class DefNode(FuncDefNode): if arg.needs_conversion: self.generate_arg_conversion(arg, code) elif arg.entry.in_closure: - code.putln('%s = %s;' % (arg.entry.cname, arg.hdr_cname)) + code.putln('%s = %s;' % ( + arg.entry.c_binding.name, arg.hdr_cname)) if arg.type.is_pyobject: code.put_var_incref(arg.entry) @@ -2835,7 +2862,7 @@ class DefNode(FuncDefNode): else: if new_type.assignable_from(old_type): code.putln( - "%s = %s;" % (arg.entry.cname, arg.hdr_cname)) + "%s = %s;" % (arg.entry.c_binding.name, arg.hdr_cname)) else: error(arg.pos, "Cannot convert 1 argument from '%s' to '%s'" % @@ -2846,14 +2873,16 @@ class DefNode(FuncDefNode): func = new_type.from_py_function # copied from CoerceFromPyTypeNode if func: - lhs = arg.entry.cname + lhs = arg.entry.c_binding.name rhs = "%s(%s)" % (func, arg.hdr_cname) if new_type.is_enum: rhs = PyrexTypes.typecast(new_type, PyrexTypes.c_long_type, rhs) code.putln("%s = %s; %s" % ( lhs, rhs, - code.error_goto_if(new_type.error_condition(arg.entry.cname), arg.pos))) + code.error_goto_if( + new_type.error_condition(arg.entry.c_binding.name), + arg.pos))) else: error(arg.pos, "Cannot convert Python object argument to type '%s'" @@ -2864,10 +2893,10 @@ class DefNode(FuncDefNode): func = old_type.to_py_function if func: code.putln("%s = %s(%s); %s" % ( - arg.entry.cname, + arg.entry.c_binding.name, func, arg.hdr_cname, - code.error_goto_if_null(arg.entry.cname, arg.pos))) + code.error_goto_if_null(arg.entry.c_binding.name, arg.pos))) code.put_var_gotref(arg.entry) else: error(arg.pos, @@ -2912,20 +2941,26 @@ class OverrideCheckNode(StatNode): first_arg = 1 import ExprNodes self.func_node = ExprNodes.RawCNameExprNode(self.pos, py_object_type) - call_tuple = ExprNodes.TupleNode(self.pos, args=[ExprNodes.NameNode(self.pos, name=arg.name) for arg in self.args[first_arg:]]) - call_node = ExprNodes.SimpleCallNode(self.pos, - function=self.func_node, - args=[ExprNodes.NameNode(self.pos, name=arg.name) for arg in self.args[first_arg:]]) + call_tuple = ExprNodes.TupleNode( + self.pos, + args=[ExprNodes.NameNode(self.pos, name=arg.python_binding.name) + for arg in self.args[first_arg:]]) + call_node = ExprNodes.SimpleCallNode( + self.pos, + function=self.func_node, + args=[ExprNodes.NameNode(self.pos, name=arg.python_binding.name) + for arg in self.args[first_arg:]]) self.body = ReturnStatNode(self.pos, value=call_node) self.body.analyse_expressions(env) def generate_execution_code(self, code): - interned_attr_cname = code.intern_identifier(self.py_func.entry.name) + interned_attr_cname = code.intern_identifier( + self.py_func.entry.python_binding.name) # Check to see if we are an extension type if self.py_func.is_module_scope: self_arg = "((PyObject *)%s)" % Naming.module_cname else: - self_arg = "((PyObject *)%s)" % self.args[0].cname + self_arg = "((PyObject *)%s)" % self.args[0].c_binding.name code.putln("/* Check if called by wrapper */") code.putln("if (unlikely(%s)) ;" % Naming.skip_dispatch_cname) code.putln("/* Check if overriden in Python */") @@ -3076,7 +3111,7 @@ class PyClassDefNode(ClassDefNode): self.target.analyse_target_declaration(env) cenv = self.create_scope(env) cenv.directives = env.directives - cenv.class_obj_cname = self.target.entry.cname + cenv.class_obj_cname = self.target.entry.c_binding.name self.body.analyse_declarations(cenv) def analyse_expressions(self, env): @@ -4523,7 +4558,8 @@ class ForFromStatNode(LoopNode, StatNode): # We know target is a NameNode, this is the only ugly case. target_node = ExprNodes.PyTempNode(self.target.pos, None) target_node.allocate(code) - interned_cname = code.intern_identifier(self.target.entry.name) + interned_cname = code.intern_identifier( + self.target.entry.python_binding.name) code.globalstate.use_utility_code(ExprNodes.get_name_interned_utility_code) code.putln("%s = __Pyx_GetName(%s, %s); %s" % ( target_node.result(), diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 48772ed3..9381ce21 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -1989,7 +1989,7 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): builtin_type = None if isinstance(test_type_node, ExprNodes.NameNode): if test_type_node.entry: - entry = env.lookup(test_type_node.entry.name) + entry = env.lookup(test_type_node.entry.python_binding. name) if entry and entry.type and entry.type.is_builtin_type: builtin_type = entry.type if builtin_type and builtin_type is not Builtin.type_type: diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index b78259be..8d655890 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1146,17 +1146,18 @@ property NAME: elif entry.visibility == 'readonly': template = self.basic_property_ro property = template.substitute({ - u"ATTR": ExprNodes.AttributeNode(pos=entry.pos, - obj=ExprNodes.NameNode(pos=entry.pos, name="self"), - attribute=entry.name), + u"ATTR": ExprNodes.AttributeNode( + pos=entry.pos, + obj=ExprNodes.NameNode(pos=entry.pos, name="self"), + attribute=entry.python_binding.name), }, pos=entry.pos).stats[0] - property.name = entry.name + property.name = entry.python_binding.name # --------------------------------------- # XXX This should go to AutoDocTransforms # --------------------------------------- if (Options.docstrings and self.current_directives['embedsignature']): - attr_name = entry.name + attr_name = entry.python_binding.name type_name = entry.type.declaration_code("", for_display=1) default_value = '' if not entry.type.is_pyobject: @@ -1389,7 +1390,9 @@ class CreateClosureClasses(CythonTransform): node.needs_outer_scope = True return - as_name = '%s_%s' % (target_module_scope.next_id(Naming.closure_class_prefix), node.entry.cname) + as_name = '%s_%s' % ( + target_module_scope.next_id(Naming.closure_class_prefix), + node.entry.c_binding.name) entry = target_module_scope.declare_c_class(name = as_name, pos = node.pos, defining = True, implementing = True) @@ -1408,8 +1411,8 @@ class CreateClosureClasses(CythonTransform): node.needs_outer_scope = True for name, entry in in_closure: class_scope.declare_var(pos=entry.pos, - name=entry.name, - cname=entry.cname, + name=entry.python_binding.name, + cname=entry.c_binding.name, type=entry.type, is_cdef=True) node.needs_closure = True @@ -1655,7 +1658,7 @@ class DebugTransform(CythonTransform): pf_cname = node.py_func.entry.func_cname attrs = dict( - name=node.entry.name, + name=node.entry.python_binding.name, cname=node.entry.func_cname, pf_cname=pf_cname, qualified_name=node.local_scope.qualified_name, @@ -1755,17 +1758,17 @@ class DebugTransform(CythonTransform): # We're dealing with a closure where a variable from an outer # scope is accessed, get it from the scope object. cname = '%s->%s' % (Naming.cur_scope_cname, - entry.outer_entry.cname) + entry.outer_entry.c_binding.name) qname = '%s.%s.%s' % (entry.scope.outer_scope.qualified_name, entry.scope.name, - entry.name) + entry.python_binding.name) elif entry.in_closure: cname = '%s->%s' % (Naming.cur_scope_cname, - entry.cname) + entry.c_binding.name) qname = entry.qualified_name else: - cname = entry.cname + cname = entry.c_binding.name qname = entry.qualified_name if not entry.pos: @@ -1777,7 +1780,7 @@ class DebugTransform(CythonTransform): lineno = str(entry.pos[1]) attrs = dict( - name=entry.name, + name=entry.python_binding.name, cname=cname, qualified_name=qname, type=vartype, diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index a5bbb787..e95b711e 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1907,7 +1907,8 @@ class CFuncType(CType): templates = new_templates) def opt_arg_cname(self, arg_name): - return self.op_arg_struct.base_type.scope.lookup(arg_name).cname + return self.op_arg_struct.base_type.scope.lookup( + arg_name).c_binding.name class CFuncTypeArg(object): @@ -1960,9 +1961,10 @@ class StructUtilityCode(object): code.putln("PyObject* member;") code.putln("res = PyDict_New(); if (res == NULL) return NULL;") for member in self.type.scope.var_entries: - nameconst_cname = code.get_py_string_const(member.name, identifier=True) + nameconst_cname = code.get_py_string_const( + member.python_binding.name, identifier=True) code.putln("member = %s(s.%s); if (member == NULL) goto bad;" % ( - member.type.to_py_function, member.cname)) + member.type.to_py_function, member.c_binding.name)) code.putln("if (PyDict_SetItem(res, %s, member) < 0) goto bad;" % nameconst_cname) code.putln("Py_DECREF(member);") code.putln("return res;") diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index a032ce8b..1cfec0f1 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -4,6 +4,7 @@ import re from Cython import Utils +from Binding import CSource, CBinding, PythonBinding from Errors import warning, error, InternalError from StringEncoding import EncodedString import Options, Naming @@ -58,8 +59,9 @@ class BufferAux(object): class Entry(object): # A symbol table entry in a Scope or ModuleNamespace. # - # name string Python name of entity - # cname string C name of entity + # c_source CSource + # c_binding CBinding + # python_binding PythonBinding # type PyrexType Type of entity # doc string Doc string # init string Initial value @@ -115,7 +117,6 @@ class Entry(object): # is_special boolean Is a special method or property accessor # of an extension type # defined_in_pxd boolean Is defined in a .pxd file (not just declared) - # api boolean Generate C API for C class or function # utility_code string Utility code needed when this entry is used # # buffer_aux BufferAux or None Extra information needed for buffer variables @@ -125,6 +126,9 @@ class Entry(object): # might_overflow boolean In an arithmetic expression that could cause # overflow (used for type inference). + c_source = None + c_binding = None + python_binding = None inline_func_in_pxd = False borrowed = 0 init = "" @@ -170,7 +174,6 @@ class Entry(object): is_special = 0 defined_in_pxd = 0 is_implemented = 0 - api = 0 utility_code = None is_overridable = 0 buffer_aux = None @@ -178,8 +181,14 @@ class Entry(object): might_overflow = 0 def __init__(self, name, cname, type, pos = None, init = None): - self.name = name - self.cname = cname + if not self.c_source: + self.c_source = CSource() + if not self.c_binding: + self.c_binding = CBinding() + if not self.python_binding: + self.python_binding = PythonBinding() + self.python_binding.name = name + self.c_binding.name = cname self.type = type self.pos = pos self.init = init @@ -187,10 +196,12 @@ class Entry(object): self.assignments = [] def __repr__(self): - return "Entry(name=%s, type=%s)" % (self.name, self.type) + return "Entry(name=%s, type=%s)" % ( + self.python_binding.name, self.type) def redeclared(self, pos): - error(pos, "'%s' does not match previous declaration" % self.name) + error(pos, "'%s' does not match previous declaration" % + self.python_binding.name) error(self.pos, "Previous declaration is here") def all_alternatives(self): @@ -474,12 +485,13 @@ class Scope(object): def check_previous_typedef_flag(self, entry, typedef_flag, pos): if typedef_flag != entry.type.typedef_flag: error(pos, "'%s' previously declared using '%s'" % ( - entry.name, ("cdef", "ctypedef")[entry.type.typedef_flag])) + entry.python_binding.name, + ("cdef", "ctypedef")[entry.type.typedef_flag])) def check_previous_visibility(self, entry, visibility, pos): if entry.visibility != visibility: error(pos, "'%s' previously declared as '%s'" % ( - entry.name, entry.visibility)) + entry.python_binding.name, entry.visibility)) def declare_enum(self, name, pos, cname, typedef_flag, visibility = 'private'): @@ -541,7 +553,7 @@ class Scope(object): self.declare_var(name, py_object_type, pos, visibility=visibility) entry = self.declare_var(None, py_object_type, pos, cname=name, visibility='private') - entry.name = EncodedString(name) + entry.python_binding.name = EncodedString(name) entry.qualified_name = self.qualify_name(name) entry.signature = pyfunction_signature entry.is_anonymous = True @@ -551,7 +563,7 @@ class Scope(object): # Add an entry for an anonymous Python function. entry = self.declare_var(None, py_object_type, pos, cname=func_cname, visibility='private') - entry.name = EncodedString(func_cname) + entry.python_binding.name = EncodedString(func_cname) entry.func_cname = func_cname entry.signature = pyfunction_signature entry.is_anonymous = True @@ -585,7 +597,8 @@ class Scope(object): # if all alternatives have different cnames, # it's safe to allow signature overrides for alt_entry in entry.all_alternatives(): - if not alt_entry.cname or cname == alt_entry.cname: + if (not alt_entry.c_binding.name or + cname == alt_entry.c_binding.name): break # cname not unique! else: can_override = True @@ -604,7 +617,7 @@ class Scope(object): if in_pxd and visibility != 'extern': entry.defined_in_pxd = 1 if api: - entry.api = 1 + entry.c_binding.api = 1 if not defining and not in_pxd and visibility != 'extern': error(pos, "Non-extern C function '%s' declared but not defined" % name) if defining: @@ -782,7 +795,7 @@ class BuiltinScope(Scope): entry = self.declare_type(name, type, None, visibility='extern') entry.utility_code = utility_code - var_entry = Entry(name = entry.name, + var_entry = Entry(name = entry.python_binding.name, type = self.lookup('type').type, # make sure "type" is the first type declared... pos = entry.pos, cname = "((PyObject*)%s)" % entry.type.typeptr_cname) @@ -911,14 +924,14 @@ class ModuleScope(Scope): error(pos, "undeclared name not builtin: %s"%name) if Options.cache_builtins: for entry in self.cached_builtins: - if entry.name == name: + if entry.python_binding.name == name: return entry entry = self.declare(None, None, py_object_type, pos, 'private') if Options.cache_builtins: entry.is_builtin = 1 entry.is_const = 1 - entry.name = name - entry.cname = Naming.builtin_prefix + name + entry.python_binding.name = name + entry.c_binding.name = Naming.builtin_prefix + name self.cached_builtins.append(entry) self.undeclared_cached_builtins.append(entry) else: @@ -1111,7 +1124,7 @@ class ModuleScope(Scope): error(pos, "Class '%s' previously declared as '%s'" % (name, entry.visibility)) if api: - entry.api = 1 + entry.c_binding.api = 1 if objstruct_cname: if type.objstruct_cname and type.objstruct_cname != objstruct_cname: error(pos, "Object struct name differs from previous declaration") @@ -1155,8 +1168,10 @@ class ModuleScope(Scope): type.vtabslot_cname = Naming.vtabslot_cname if type.vtabslot_cname: #print "...allocating other vtable related cnames" ### - type.vtabstruct_cname = self.mangle(Naming.vtabstruct_prefix, entry.name) - type.vtabptr_cname = self.mangle(Naming.vtabptr_prefix, entry.name) + type.vtabstruct_cname = self.mangle( + Naming.vtabstruct_prefix, entry.python_binding.name) + type.vtabptr_cname = self.mangle( + Naming.vtabptr_prefix, entry.python_binding.name) def check_c_classes_pxd(self): # Performs post-analysis checking and finishing up of extension types @@ -1172,11 +1187,12 @@ class ModuleScope(Scope): for entry in self.c_class_entries: # Check defined if not entry.type.scope: - error(entry.pos, "C class '%s' is declared but not defined" % entry.name) + error(entry.pos, "C class '%s' is declared but not defined" + % entry.python_binding.name) def check_c_class(self, entry): type = entry.type - name = entry.name + name = entry.python_binding.name visibility = entry.visibility # Check defined if not type.scope: @@ -1191,11 +1207,12 @@ class ModuleScope(Scope): for method_entry in type.scope.cfunc_entries: if not method_entry.is_inherited and not method_entry.func_cname: error(method_entry.pos, "C method '%s' is declared but not defined" % - method_entry.name) + method_entry.python_binding.name) # Allocate vtable name if necessary if type.vtabslot_cname: #print "ModuleScope.check_c_classes: allocating vtable cname for", self ### - type.vtable_cname = self.mangle(Naming.vtable_prefix, entry.name) + type.vtable_cname = self.mangle( + Naming.vtable_prefix, entry.python_binding.name) def check_c_classes(self): # Performs post-analysis checking and finishing up of extension types @@ -1216,7 +1233,7 @@ class ModuleScope(Scope): print("Scope.check_c_classes: checking scope " + self.qualified_name) for entry in self.c_class_entries: if debug_check_c_classes: - print("...entry %s %s" % (entry.name, entry)) + print("...entry %s %s" % (entry.python_binding.name, entry)) print("......type = ", entry.type) print("......visibility = ", entry.visibility) self.check_c_class(entry) @@ -1241,7 +1258,7 @@ class ModuleScope(Scope): # we use a read-only C global variable whose name is an # expression that refers to the type object. import Builtin - var_entry = Entry(name = entry.name, + var_entry = Entry(name = entry.python_binding.name, type = Builtin.type_type, pos = entry.pos, cname = "((PyObject*)%s)" % entry.type.typeptr_cname) @@ -1314,7 +1331,9 @@ class LocalScope(Scope): # on the outside and inside, so we make a new entry entry.in_closure = True # Would it be better to declare_var here? - inner_entry = Entry(entry.name, entry.cname, entry.type, entry.pos) + inner_entry = Entry( + entry.python_binding.name, entry.c_binding.name, + entry.type, entry.pos) inner_entry.scope = self inner_entry.is_variable = True inner_entry.outer_entry = entry @@ -1326,16 +1345,18 @@ class LocalScope(Scope): def mangle_closure_cnames(self, outer_scope_cname): for entry in self.entries.values(): if entry.from_closure: - cname = entry.outer_entry.cname + cname = entry.outer_entry.c_binding.name if self.is_passthrough: - entry.cname = cname + entry.c_binding.name = cname else: if cname.startswith(Naming.cur_scope_cname): cname = cname[len(Naming.cur_scope_cname)+2:] - entry.cname = "%s->%s" % (outer_scope_cname, cname) + entry.c_binding.name = "%s->%s" % ( + outer_scope_cname, cname) elif entry.in_closure: - entry.original_cname = entry.cname - entry.cname = "%s->%s" % (Naming.cur_scope_cname, entry.cname) + entry.original_cname = entry.c_binding.name + entry.c_binding.name = "%s->%s" % ( + Naming.cur_scope_cname, entry.c_binding.name) class GeneratorExpressionScope(Scope): """Scope for generator expressions and comprehensions. As opposed @@ -1662,17 +1683,20 @@ class CClassScope(ClassScope): # inherited type, with cnames modified appropriately # to work with this type. def adapt(cname): - return "%s.%s" % (Naming.obj_base_cname, base_entry.cname) + return "%s.%s" % (Naming.obj_base_cname, base_entry.c_binding.name) for base_entry in \ base_scope.inherited_var_entries + base_scope.var_entries: - entry = self.declare(base_entry.name, adapt(base_entry.cname), + entry = self.declare( + base_entry.python_binding.name, + adapt(base_entry.c_binding.name), base_entry.type, None, 'private') entry.is_variable = 1 self.inherited_var_entries.append(entry) for base_entry in base_scope.cfunc_entries: - entry = self.add_cfunction(base_entry.name, base_entry.type, - base_entry.pos, adapt(base_entry.cname), - base_entry.visibility, base_entry.func_modifiers) + entry = self.add_cfunction( + base_entry.python_binding.name, base_entry.type, + base_entry.pos, adapt(base_entry.c_binding.name), + base_entry.visibility, base_entry.func_modifiers) entry.is_inherited = 1 @@ -1751,42 +1775,39 @@ class CppClassScope(Scope): for base_entry in \ base_scope.inherited_var_entries + base_scope.var_entries: #contructor is not inherited - if base_entry.name == "": + if base_entry.python_binding.name == "": continue - #print base_entry.name, self.entries - if base_entry.name in self.entries: - base_entry.name - entry = self.declare(base_entry.name, base_entry.cname, + #print base_entry.python_binding.name, self.entries + if base_entry.python_binding.name in self.entries: + base_entry.python_binding.name + entry = self.declare( + base_entry.python_binding.name, base_entry.c_binding.name, base_entry.type, None, 'extern') entry.is_variable = 1 self.inherited_var_entries.append(entry) for base_entry in base_scope.cfunc_entries: - entry = self.declare_cfunction(base_entry.name, base_entry.type, - base_entry.pos, base_entry.cname, - base_entry.visibility, base_entry.func_modifiers, - utility_code = base_entry.utility_code) + entry = self.declare_cfunction( + base_entry.python_binding.name, base_entry.type, + base_entry.pos, base_entry.c_binding.name, + base_entry.visibility, base_entry.func_modifiers, + utility_code = base_entry.utility_code) entry.is_inherited = 1 def specialize(self, values): scope = CppClassScope(self.name, self.outer_scope) for entry in self.entries.values(): if entry.is_type: - scope.declare_type(entry.name, - entry.type.specialize(values), - entry.pos, - entry.cname) + scope.declare_type( + entry.python_binding.name, entry.type.specialize(values), + entry.pos, entry.c_binding.name) else: -# scope.declare_var(entry.name, -# entry.type.specialize(values), -# entry.pos, -# entry.cname, -# entry.visibility) +# scope.declare_var( +# entry.python_binding.name, entry.type.specialize(values), +# entry.pos, entry.c_binding.name, entry.visibility) for e in entry.all_alternatives(): - scope.declare_cfunction(e.name, - e.type.specialize(values), - e.pos, - e.cname, - utility_code = e.utility_code) + scope.declare_cfunction( + e.python_binding.name, e.type.specialize(values), + e.pos, e.c_binding.name, utility_code = e.utility_code) return scope def add_include_file(self, filename): -- 2.26.2