From cc414989d028e489133967e0e3a7aa33480e345d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 1 Mar 2011 21:16:30 -0500 Subject: [PATCH] Move Binding attributes back into a flat namespace. --- Cython/Compiler/AnalysedTreeTransforms.py | 8 +- Cython/Compiler/Binding.py | 71 +- Cython/Compiler/Buffer.py | 36 +- Cython/Compiler/Code.py | 52 +- Cython/Compiler/ExprNodes.py | 58 +- Cython/Compiler/ModuleNode.py | 126 ++-- Cython/Compiler/Nodes.py | 144 ++-- Cython/Compiler/Optimize.py | 2 +- Cython/Compiler/ParseTreeTransforms.py | 32 +- Cython/Compiler/Parsing.py | 199 +++-- Cython/Compiler/PyrexTypes.py | 8 +- Cython/Compiler/Symtab.py | 870 +++++++++++----------- Cython/Compiler/TypeSlots.py | 6 +- 13 files changed, 808 insertions(+), 804 deletions(-) diff --git a/Cython/Compiler/AnalysedTreeTransforms.py b/Cython/Compiler/AnalysedTreeTransforms.py index e2e0e8f1..de527e00 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.python_binding.name + path = node.entry.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.python_binding.name + name = node.entry.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.python_binding.name) + node.entry.name) else: - path = "%s.%s" % (class_name, node.entry.python_binding.name) + path = "%s.%s" % (class_name, node.entry.name) else: assert False self.add_test(node.pos, path, node.doc) diff --git a/Cython/Compiler/Binding.py b/Cython/Compiler/Binding.py index f2abd89c..7cef600d 100644 --- a/Cython/Compiler/Binding.py +++ b/Cython/Compiler/Binding.py @@ -3,40 +3,70 @@ # -class CtxAttribute(object): - """Base class for complicated Ctx attributes. +class _BindingAttributes(object): + """Base class for complicated binding attributes. - Having a single base class makes it easier to generate child - contexts. + This class allows us to define methods for generating child + contexts and pushing/pulling well-defined attribute sets. + + Pushes, pulls, and deepcopies are simplified by assuming that all + relevant attribute values are immutable. """ - def deepcopy(self): + def __init__(self, **kwargs): + self.__dict__.update(kwargs) + + def deepcopy(self, **kwargs): + "Return a copy of `self` preserving all attributes." cls = type(self) cpy = cls() - cpy.__dict__.update(self.__dict__) + self.push(cpy) + cpy.__dict__.update(kwargs) return cpy + def push(self, other): + """Push all of `self`'s attributes onto `other` + + Remember that attributes that aren't in `self.__dict__` + (e.g. uninitialized, class-wide defaults) will *not* be + copied. + """ + other.__dict__.update(self.__dict__) + + def pull(self, other): + """Pull all relevant attributes from `other` + + Remember that attributes that aren't in `self.__dict__` + (e.g. uninitialized, class-wide defaults) will *not* be + copied. + """ + for key,value in other.__dict__.iteritems(): + if key in dir(self): + self.__dict__[key] = value + -class CSource(CtxAttribute): +class CSource(_BindingAttributes): """Configure the location of an object's C source. - * name (string): Source symbol name (if the symbol is external) - * namespace (string): C++ namespace (`None` for C objects, set if - the symbol is external) + * source_name (string): Source symbol name (if the symbol is + external) + * source_namespace (string): C++ namespace (`None` for C objects, + set if the symbol is external) * cdef_flag (boolean): Symbol (data) has a C definition. * extern (boolean): Symbol is defined elsewhere (otherwise a local defition is created). """ - name = None - namespace = None + source_name = None + source_namespace = None cdef_flag = 0 extern = 0 -class CBinding(CtxAttribute): +class CBinding(_BindingAttributes): """Configure the presence and behaviour of an object's C bindings. - * name (string): Generated symbol name - * namespace (string): C++ namespace (`None` for C objects) + * c_name (string): Generated symbol name (or source name, is the + symbol is external. + * c_namespace (string): C++ namespace (`None` for C objects) * api (boolean): Add to generated header file * visibility ('private'|'public'): @@ -45,14 +75,14 @@ class CBinding(CtxAttribute): * const (boolean): Symbol data is readonly. """ - name = None + c_name = None namespace = None api = 0 - visibility = 'private' + c_visibility = 'private' const = 0 -class PythonBinding(CtxAttribute): +class PythonBinding(_BindingAttributes): """Configure the presence and behaviour of an object's Python bindings. * name (string): Name to which the object is bound (if the object @@ -70,3 +100,8 @@ class PythonBinding(CtxAttribute): name = None visibility = 'public' #private' overridable = 0 + + +class Binding(CSource, CBinding, PythonBinding): + "Combine all binding attributes in a single, flat namespace." + pass diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index 7bbcf9f3..42f977ff 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.python_binding.name + name = entry.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.c_binding.name + bufstruct = buffer_aux.buffer_info_var.c_name varspec = [("strides", buffer_aux.stridevars), ("shape", buffer_aux.shapevars)] @@ -230,14 +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.c_binding.name, bufstruct, field, idx) + (s.c_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.c_binding.name, buffer_aux, entry.type) + code, entry.c_name, buffer_aux, entry.type) # Acquire any new buffer code.putln("{") @@ -251,13 +251,13 @@ 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.c_binding.name) + entry.buffer_aux.buffer_info_var.c_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.c_binding.name + bufstruct = buffer_aux.buffer_info_var.c_name dtype_typeinfo = get_type_information_cname(code, buffer_type.dtype) @@ -282,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.c_binding.name + bufstruct = buffer_aux.buffer_info_var.c_name flags = get_flags(buffer_aux, buffer_type) code.putln("{") # Set up necesarry stack for getbuffer @@ -349,7 +349,7 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, """ bufaux = entry.buffer_aux - bufstruct = bufaux.buffer_info_var.c_binding.name + bufstruct = bufaux.buffer_info_var.c_name negative_indices = directives['wraparound'] and entry.type.negative_indices if directives['boundscheck']: @@ -365,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.c_binding.name)) + code.putln("%s += %s;" % (cname, shape.c_name)) code.putln("if (%s) %s = %d;" % ( code.unlikely("%s < 0" % cname), tmp_cname, dim)) else: @@ -378,7 +378,7 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, cast = "(size_t)" code.putln("if (%s) %s = %d;" % ( code.unlikely("%s >= %s%s" % ( - cname, cast, shape.c_binding.name)), + cname, cast, shape.c_name)), tmp_cname, dim)) code.globalstate.use_utility_code(raise_indexerror_code) code.putln("if (%s) {" % code.unlikely("%s != -1" % tmp_cname)) @@ -392,7 +392,7 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, directives, pos, bufaux.shapevars): if signed != 0: code.putln("if (%s < 0) %s += %s;" % ( - cname, cname, shape.c_binding.name)) + cname, cname, shape.c_name)) # Create buffer lookup and return it # This is done via utility macros/inline functions, which vary @@ -403,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.c_binding.name) - params.append(o.c_binding.name) + params.append(s.c_name) + params.append(o.c_name) funcname = "__Pyx_BufPtrFull%dd" % nd funcgen = buf_lookup_full_code else: @@ -421,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.c_binding.name) + params.append(s.c_name) # Make sure the utility code is available if funcname not in code.globalstate.utility_codes: @@ -520,9 +520,9 @@ def use_py2_buffer_functions(env): if t.is_extension_type: release = get = None for x in t.scope.pyfunc_entries: - if x.python_binding.name == u"__getbuffer__": + if x.name == u"__getbuffer__": get = x.func_cname - elif x.python_binding.name == u"__releasebuffer__": + elif x.name == u"__releasebuffer__": release = x.func_cname if get: types.append((t.typeptr_cname, get, release)) @@ -635,8 +635,8 @@ 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.python_binding.name, - dtype.declaration_code(""), f.c_binding.name), + (typeinfo, f.name, + dtype.declaration_code(""), f.c_name), safe=True) typecode.putln(' {NULL, NULL, 0}', safe=True) typecode.putln("};", safe=True) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index e5ff8964..209331c6 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -557,7 +557,7 @@ class GlobalState(object): w.exit_cfunc_scope() def put_pyobject_decl(self, entry): - self['global_var'].putln("static PyObject *%s;" % entry.c_binding.name) + self['global_var'].putln("static PyObject *%s;" % entry.c_name) # constant handling at code generation time @@ -646,21 +646,21 @@ class GlobalState(object): def add_cached_builtin_decl(self, entry): if Options.cache_builtins: - if self.should_declare(entry.c_binding.name, entry): + if self.should_declare(entry.c_name, entry): self.put_pyobject_decl(entry) w = self.parts['cached_builtins'] - if entry.python_binding.name == 'xrange': + if entry.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.c_binding.name) + entry.c_name) w.putln('#else') self.put_cached_builtin_init( entry.pos, - StringEncoding.EncodedString(entry.python_binding.name), - entry.c_binding.name) - if entry.python_binding.name == 'xrange': + StringEncoding.EncodedString(entry.name), + entry.c_name) + if entry.name == 'xrange': w.putln('#endif') def put_cached_builtin_init(self, pos, name, cname): @@ -1109,30 +1109,30 @@ class CCodeWriter(object): def put_var_declaration(self, entry, static = 0, dll_linkage = None, definition = True): - #print "Code.put_var_declaration:", entry.python_binding.name, "definition =", definition ### + #print "Code.put_var_declaration:", entry.name, "definition =", definition ### if entry.in_closure: return - if entry.c_binding.visibility == 'private' and not definition: + if entry.c_visibility == 'private' and not definition: #print "...private and not definition, skipping" ### return - if entry.c_binding.visibility == 'private' and not entry.used: - #print "not used and private, skipping", entry.c_binding.name ### + if entry.c_visibility == 'private' and not entry.used: + #print "not used and private, skipping", entry.c_name ### return storage_class = "" - if entry.c_source.extern: + if entry.extern: storage_class = Naming.extern_c_macro - elif entry.c_binding.visibility == 'public': + elif entry.c_visibility == 'public': if not definition: storage_class = Naming.extern_c_macro - elif entry.c_binding.visibility == 'private': + elif entry.c_visibility == 'private': if static: storage_class = "static" if storage_class: self.put("%s " % storage_class) - if (entry.c_source.extern or - entry.c_binding.visibility != 'public'): + if (entry.extern or + entry.c_visibility != 'public'): dll_linkage = None - self.put(entry.type.declaration_code(entry.c_binding.name, + self.put(entry.type.declaration_code(entry.c_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.c_binding.name + return "(PyObject *)" + entry.c_name else: - return entry.c_binding.name + return entry.c_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.c_binding.name)) + self.entry_as_pyobject(entry), entry.c_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.c_binding.name)) + self.entry_as_pyobject(entry), entry.c_name)) def put_var_decrefs(self, entries, used_only = 0): for entry in entries: @@ -1283,18 +1283,18 @@ 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.c_binding.name + code = template % entry.c_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.python_binding.name == '__getattribute__': - if entry.python_binding.name not in [ + 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.python_binding.name == '__getattr__' and + if (entry.name == '__getattr__' and not self.globalstate.directives['fast_getattr']): pass # Python's typeobject.c will automatically fill in our slot @@ -1313,7 +1313,7 @@ class CCodeWriter(object): method_flags += [method_coexist] self.putln( '{__Pyx_NAMESTR("%s"), (PyCFunction)%s, %s, __Pyx_DOCSTR(%s)}%s' % ( - entry.python_binding.name, + entry.name, entry.func_cname, "|".join(method_flags), doc_code, diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index db68f2a4..372d7d45 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.c_binding.name + return self.entry.c_name def coerce_to(self, dst_type, env): # If coercing to a generic pyobject and this is a builtin @@ -1336,7 +1336,7 @@ class NameNode(AtomicExprNode): if var_entry: if var_entry.is_builtin and Options.cache_builtins: var_entry = env.declare_builtin( - var_entry.python_binding.name, self.pos) + var_entry.name, self.pos) node = NameNode(self.pos, name = self.name) node.entry = var_entry node.analyse_rvalue_entry(env) @@ -1512,7 +1512,7 @@ class NameNode(AtomicExprNode): entry = self.entry if not entry: return "" # There was an error earlier - return entry.c_binding.name + return entry.c_name def generate_result_code(self, code): assert hasattr(self, 'entry') @@ -1524,7 +1524,7 @@ class NameNode(AtomicExprNode): 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.python_binding.name) + self.entry.name) if entry.is_builtin: namespace = Naming.builtins_cname else: # entry.is_pyglobal @@ -1540,7 +1540,7 @@ 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.python_binding.name) + self.entry.name) if entry.is_builtin: namespace = Naming.builtins_cname else: # entry.is_pyglobal @@ -1557,19 +1557,19 @@ class NameNode(AtomicExprNode): elif entry.is_local and False: # control flow not good enough yet assigned = entry.scope.control_flow.get_state( - (entry.python_binding.name, 'initialized'), self.pos) + (entry.name, 'initialized'), self.pos) if assigned is False: error( self.pos, "local variable '%s' referenced before assignment" % - entry.python_binding.name) + entry.name) elif not Options.init_local_none and assigned is None: code.putln( 'if (%s == 0) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }' % - (entry.c_binding.name, entry.python_binding.name, + (entry.c_name, entry.name, code.error_goto(self.pos))) entry.scope.control_flow.set_state( - self.pos, (entry.python_binding.name, 'initialized'), True) + self.pos, (entry.name, 'initialized'), True) def generate_assignment_code(self, rhs, code): #print "NameNode.generate_assignment_code:", self.name ### @@ -1586,7 +1586,7 @@ class NameNode(AtomicExprNode): if entry.is_pyglobal: assert entry.type.is_pyobject, "Python global or builtin not a Python object" interned_cname = code.intern_identifier( - self.entry.python_binding.name) + self.entry.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 @@ -1643,7 +1643,7 @@ class NameNode(AtomicExprNode): 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.python_binding.name, 'initialized'), + (entry.name, 'initialized'), self.pos) if initialized is True: code.put_decref(self.result(), self.ctype()) @@ -1674,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.c_binding.name + bufstruct = buffer_aux.buffer_info_var.c_name import Buffer Buffer.put_assign_to_buffer(self.result(), rhstmp, buffer_aux, self.entry.type, is_initialized=not self.lhs_of_first_assignment, @@ -1695,12 +1695,12 @@ class NameNode(AtomicExprNode): code.put_error_if_neg(self.pos, 'PyMapping_DelItemString(%s, "%s")' % ( namespace, - self.entry.python_binding.name)) + self.entry.name)) else: code.put_error_if_neg(self.pos, '__Pyx_DelAttrString(%s, "%s")' % ( Naming.module_cname, - self.entry.python_binding.name)) + self.entry.name)) def annotate(self, code): if hasattr(self, 'is_called') and self.is_called: @@ -2791,7 +2791,7 @@ class CallNode(ExprNode): for arg, member in zip(args, type.scope.var_entries): items.append(DictItemNode( pos=arg.pos, key=StringNode( - pos=arg.pos, value=member.python_binding.name), + pos=arg.pos, value=member.name), value=arg)) if kwds: items += kwds.key_value_pairs @@ -2873,9 +2873,9 @@ class SimpleCallNode(CallNode): if result_type.is_extension_type: return result_type elif result_type.is_builtin_type: - if function.entry.python_binding.name == 'float': + if function.entry.name == 'float': return PyrexTypes.c_double_type - elif (function.entry.python_binding.name + elif (function.entry.name in Builtin.types_that_construct_their_instance): return result_type return py_object_type @@ -2917,16 +2917,16 @@ class SimpleCallNode(CallNode): 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 + (function.entry.name in Builtin.types_that_construct_their_instance)): # calling a builtin type that returns a specific object type - if function.entry.python_binding.name == 'float': + if function.entry.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.python_binding.name] + function.entry.name] self.result_ctype = py_object_type self.may_return_none = False elif function.is_name and function.type_entry: @@ -2948,7 +2948,7 @@ class SimpleCallNode(CallNode): 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.python_binding.name, + self.function.entry.name, 'PyExc_AttributeError') expected_type = self_arg.type self.coerced_self = CloneNode(self.self).coerce_to( @@ -3179,11 +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.c_binding.name, - func_type.exception_value.entry.c_binding.name) + func_type.exception_value.entry.c_name, + func_type.exception_value.entry.c_name) else: raise_py_exception = '%s(); if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError , "Error converting c++ exception.")' % ( - func_type.exception_value.entry.c_binding.name) + func_type.exception_value.entry.c_name) if self.nogil: raise_py_exception = 'Py_BLOCK_THREADS; %s; Py_UNBLOCK_THREADS' % raise_py_exception code.putln( @@ -3504,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.python_binding.name, - "%s->%s" % (type.vtabptr_cname, entry.c_binding.name), + ubcm_entry = Symtab.Entry(entry.name, + "%s->%s" % (type.vtabptr_cname, entry.c_name), entry.type) ubcm_entry.is_cfunction = 1 ubcm_entry.func_cname = entry.func_cname @@ -3606,13 +3606,13 @@ class AttributeNode(ExprNode): self.entry = entry if entry: if (obj_type.is_extension_type and - entry.python_binding.name == "__weakref__"): + entry.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.c_binding.name + self.member = entry.c_name return else: # If it's not a variable or C method, it must be a Python @@ -4241,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.c_binding.name, + member.c_name, arg.result())) else: raise InternalError("List type never specified") diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 9d9124f2..1f015156 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -98,8 +98,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_h_code(self, env, options, result): def h_entries(entries, pxd = 0): return [entry for entry in entries - if (entry.c_binding.visibility == 'public' and - not entry.c_source.extern) + if (entry.c_visibility == 'public' and + not entry.extern) or pxd and entry.defined_in_pxd] h_types = h_entries(env.type_entries) h_vars = h_entries(env.var_entries) @@ -151,10 +151,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): h_code.putln("%s %s;" % ( Naming.extern_c_macro, entry.type.declaration_code( - entry.c_binding.name, dll_linkage = "DL_IMPORT"))) + entry.c_name, dll_linkage = "DL_IMPORT"))) if i_code: i_code.putln("cdef extern %s" % - entry.type.declaration_code(entry.c_binding.name, pyrex = 1)) + entry.type.declaration_code(entry.c_name, pyrex = 1)) def api_name(self, env): return env.qualified_name.replace(".", "__") @@ -164,12 +164,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): public_extension_types = [] has_api_extension_types = 0 for entry in env.cfunc_entries: - if entry.c_binding.api: + if entry.api: api_funcs.append(entry) for entry in env.c_class_entries: - if entry.c_binding.visibility == 'public': + if entry.c_visibility == 'public': public_extension_types.append(entry) - if entry.c_binding.api: + if entry.api: has_api_extension_types = 1 if api_funcs or has_api_extension_types: result.api_file = replace_suffix(result.c_file, "_api.h") @@ -192,7 +192,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for entry in api_funcs: type = CPtrType(entry.type) h_code.putln("static %s;" % type.declaration_code( - entry.c_binding.name)) + entry.c_name)) h_code.putln("") h_code.put_h_guard(Naming.api_func_guard + "import_module") h_code.put(import_module_utility_code.impl) @@ -213,8 +213,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.python_binding.name, - entry.c_binding.name, + entry.name, + entry.c_name, sig)) h_code.putln("Py_DECREF(module); module = 0;") for entry in public_extension_types: @@ -248,7 +248,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if var_entries: for entry in var_entries: i_code.putln("cdef %s" % entry.type.declaration_code( - entry.c_binding.name, pyrex = 1)) + entry.c_name, pyrex = 1)) else: i_code.putln("pass") i_code.dedent() @@ -415,7 +415,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.python_binding.name, repr(entry.type) ### + #print "generate_type_header_code:", entry.name, repr(entry.type) ### type = entry.type if type.is_typedef: # Must test this first! self.generate_typedef(entry, code) @@ -761,7 +761,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.python_binding.name, repr(entry.type) ### + #print "generate_type_header_code:", entry.name, repr(entry.type) ### type = entry.type if type.is_typedef: # Must test this first! self.generate_typedef(entry, code) @@ -794,7 +794,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): writer = code writer.putln("") writer.putln("typedef %s;" % base_type.declaration_code( - entry.c_binding.name)) + entry.c_name)) def sue_header_footer(self, type, kind, name): if type.typedef_flag: @@ -833,7 +833,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for attr in var_entries: code.putln( "%s;" % - attr.type.declaration_code(attr.c_binding.name)) + attr.type.declaration_code(attr.c_name)) code.putln(footer) if packed: code.putln("#if defined(__SUNPRO_C)") @@ -845,7 +845,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_enum_definition(self, entry, code): code.mark_pos(entry.pos) type = entry.type - name = entry.c_binding.name or entry.python_binding.name or "" + name = entry.c_name or entry.name or "" header, footer = \ self.sue_header_footer(type, "enum", name) code.putln("") @@ -864,10 +864,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for value_entry in enum_values: if value_entry.value_node is None: - value_code = value_entry.c_binding.name + value_code = value_entry.c_name else: value_code = ("%s = %s" % ( - value_entry.c_binding.name, + value_entry.c_name, value_entry.value_node.result())) if value_entry is not last_entry: value_code += "," @@ -878,11 +878,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("") name = entry.type.typeobj_cname if name: - if entry.c_source.extern and not entry.in_cinclude: + if entry.extern and not entry.in_cinclude: code.putln("%s DL_IMPORT(PyTypeObject) %s;" % ( Naming.extern_c_macro, name)) - elif entry.c_binding.visibility == 'public': + elif entry.c_visibility == 'public': code.putln("%s DL_EXPORT(PyTypeObject) %s;" % ( Naming.extern_c_macro, name)) @@ -908,7 +908,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if not method_entry.is_inherited: code.putln( "%s;" % method_entry.type.declaration_code( - "(*%s)" % method_entry.python_binding.name)) + "(*%s)" % method_entry.name)) code.putln( "};") @@ -949,7 +949,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for attr in type.scope.var_entries: code.putln( "%s;" % - attr.type.declaration_code(attr.c_binding.name)) + attr.type.declaration_code(attr.c_name)) code.putln(footer) if type.objtypedef_cname is not None: # Only for exposing public typedef name. @@ -967,21 +967,21 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): def generate_cfunction_predeclarations(self, env, code, definition): for entry in env.cfunc_entries: if entry.inline_func_in_pxd or (not entry.in_cinclude and (definition - or entry.defined_in_pxd or entry.c_source.extern)): - if (entry.c_source.extern or - entry.c_binding.visibility == 'public'): + or entry.defined_in_pxd or entry.extern)): + if (entry.extern or + entry.c_visibility == 'public'): dll_linkage = "DL_EXPORT" else: dll_linkage = None type = entry.type if not definition and entry.defined_in_pxd: type = CPtrType(type) - header = type.declaration_code(entry.c_binding.name, + header = type.declaration_code(entry.c_name, dll_linkage = dll_linkage) - if entry.c_binding.visibility == 'private': + if entry.c_visibility == 'private': storage_class = "static " - elif (entry.c_binding.visibility == 'public' and - not entry.c_source.extern): + elif (entry.c_visibility == 'public' and + not entry.extern): storage_class = "" else: storage_class = "%s " % Naming.extern_c_macro @@ -998,9 +998,9 @@ 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.python_binding.name - #print "...c_binding.visibility =", entry.c_binding.visibility - if not entry.c_source.extern: + #print "generate_typeobj_definitions:", entry.name + #print "...c_visibility =", entry.c_visibility + if not entry.extern: type = entry.type scope = type.scope if scope: # could be None if there was an error @@ -1096,9 +1096,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.python_binding.name == "__weakref__": + if scope.is_internal or entry.name == "__weakref__": # internal classes do not need None inits - code.putln("p->%s = 0;" % entry.c_binding.name) + code.putln("p->%s = 0;" % entry.c_name) else: code.put_init_var_to_py_none(entry, "p->%s", nanny=False) entry = scope.lookup_here("__new__") @@ -1140,7 +1140,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);") for entry in py_attrs: code.put_xdecref( - "p->%s" % entry.c_binding.name, entry.type, nanny=False) + "p->%s" % entry.c_name, entry.type, nanny=False) if base_type: tp_dealloc = TypeSlots.get_base_slot_function(scope, tp_slot) if tp_dealloc is None: @@ -1189,7 +1189,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): py_attrs = [] for entry in scope.var_entries: if (entry.type.is_pyobject and - entry.python_binding.name != "__weakref__"): + entry.name != "__weakref__"): py_attrs.append(entry) if base_type or py_attrs: code.putln("int e;") @@ -1207,7 +1207,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): base_type.typeptr_cname) code.putln("}") for entry in py_attrs: - var_code = "p->%s" % entry.c_binding.name + var_code = "p->%s" % entry.c_name code.putln( "if (%s) {" % var_code) @@ -1234,7 +1234,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): py_attrs = [] for entry in scope.var_entries: if (entry.type.is_pyobject and - entry.python_binding.name != "__weakref__"): + entry.name != "__weakref__"): py_attrs.append(entry) if py_attrs: self.generate_self_cast(scope, code) @@ -1249,7 +1249,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.c_binding.name + name = "p->%s" % entry.c_name code.putln("tmp = ((PyObject*)%s);" % name) code.put_init_to_py_none(name, entry.type, nanny=False) code.putln("Py_XDECREF(tmp);") @@ -1561,7 +1561,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.python_binding.name) + Naming.prop_get_prefix, property_entry.name) get_entry = property_scope.lookup_here("__get__") code.putln("") code.putln( @@ -1576,7 +1576,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.python_binding.name) + Naming.prop_set_prefix, property_entry.name) set_entry = property_scope.lookup_here("__set__") del_entry = property_scope.lookup_here("__del__") code.putln("") @@ -1618,7 +1618,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): for suite in TypeSlots.substructures: suite.generate_substructure(scope, code) code.putln("") - if entry.c_binding.visibility == 'public': + if entry.c_visibility == 'public': header = "DL_EXPORT(PyTypeObject) %s = {" else: header = "static PyTypeObject %s = {" @@ -1668,7 +1668,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): doc_code = "0" code.putln( '{(char *)"%s", %s, %s, %s, 0},' % ( - entry.python_binding.name, + entry.name, entry.getter_cname or "0", entry.setter_cname or "0", doc_code)) @@ -1709,18 +1709,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.error_goto(entry.pos))) code.putln("Py_INCREF(o);") code.put_decref( - entry.c_binding.name, entry.type, nanny=False) + entry.c_name, entry.type, nanny=False) code.putln("%s = %s;" % ( - entry.c_binding.name, + entry.c_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.c_binding.name, + entry.c_name, rhs, - entry.type.error_condition(entry.c_binding.name), + entry.type.error_condition(entry.c_name), code.error_goto(entry.pos))) else: code.putln('PyErr_Format(PyExc_TypeError, "Cannot convert Python object %s to %s");' % (name, entry.type)) @@ -1872,11 +1872,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): rev_entries = list(env.var_entries) rev_entries.reverse() for entry in rev_entries: - if not entry.c_source.extern: + if not entry.extern: if entry.type.is_pyobject and entry.used: code.putln("Py_DECREF(%s); %s = 0;" % ( code.entry_as_pyobject(entry), - entry.c_binding.name)) + entry.c_name)) code.putln("__Pyx_CleanupGlobals();") if Options.generate_cleanup_code >= 3: code.putln("/*--- Type import cleanup code ---*/") @@ -1885,7 +1885,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.c_binding.name, + code.put_decref_clear(entry.c_name, PyrexTypes.py_object_type, nanny=False) code.putln("/*--- Intern cleanup code ---*/") @@ -1893,7 +1893,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): PyrexTypes.py_object_type, nanny=False) # for entry in env.pynum_entries: -# code.put_decref_clear(entry.c_binding.name, +# code.put_decref_clear(entry.c_name, # PyrexTypes.py_object_type, # nanny=False) # for entry in env.all_pystring_entries: @@ -1904,7 +1904,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.c_binding.name)) +# code.entry_as_pyobject(entry), entry.c_name)) code.putln("Py_INCREF(Py_None); return Py_None;") def generate_main_method(self, env, code): @@ -1995,19 +1995,19 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): # Generate code to initialise global PyObject * # variables to None. for entry in env.var_entries: - if not entry.c_source.extern: + if not entry.extern: if entry.type.is_pyobject and entry.used: code.put_init_var_to_py_none(entry, nanny=False) 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.c_binding.api or entry.defined_in_pxd: + if entry.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.python_binding.name, - entry.c_binding.name, + entry.name, + entry.c_name, signature, code.error_goto(self.pos))) @@ -2039,8 +2039,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln( 'if (__Pyx_ImportFunction(%s, "%s", (void (**)(void))&%s, "%s") < 0) %s' % ( temp, - entry.python_binding.name, - entry.c_binding.name, + entry.name, + entry.c_name, entry.type.signature_string(), code.error_goto(self.pos))) code.putln("Py_DECREF(%s); %s = 0;" % (temp, temp)) @@ -2049,7 +2049,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): # Generate type import code for extern extension types # and type ready code for non-extern ones. for entry in env.c_class_entries: - if entry.c_source.extern: + if entry.extern: self.generate_type_import_code(env, entry.type, entry.pos, code) else: self.generate_base_type_import_code(env, entry, code) @@ -2127,7 +2127,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): typeobj_cname = type.typeobj_cname scope = type.scope if scope: # could be None if there was an error - if not entry.c_source.extern: + if not entry.extern: for slot in TypeSlots.slot_table: slot.generate_dynamic_init_code(scope, code) code.putln( @@ -2143,7 +2143,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln( 'PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&%s, "%s"); %s' % ( typeobj_cname, - func.python_binding.name, + func.name, code.error_goto_if_null('wrapper', entry.pos))) code.putln( "if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {") @@ -2186,7 +2186,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): tp_weaklistoffset, tp_weaklistoffset, objstruct, - weakref_entry.c_binding.name)) + weakref_entry.c_name)) else: error(weakref_entry.pos, "__weakref__ slot must be of type 'object'") @@ -2215,7 +2215,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln( "%s.%s = %s%s;" % ( type.vtable_cname, - meth_entry.c_binding.name, + meth_entry.c_name, cast, meth_entry.func_cname)) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 6796f26b..bad84378 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1016,7 +1016,7 @@ class CStructOrUnionDefNode(StatNode): cname = self.cname, visibility='ignore') struct_entry.type.typedef_flag = False # FIXME: this might be considered a hack ;-) - struct_entry.c_binding.name = struct_entry.type.cname = ( + struct_entry.c_name = struct_entry.type.cname = ( '_' + self.entry.type.typedef_cname) def analyse_expressions(self, env): @@ -1094,12 +1094,12 @@ class CEnumDefNode(StatNode): for item in self.entry.enum_values: code.putln("%s = PyInt_FromLong(%s); %s" % ( temp, - item.c_binding.name, + item.c_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.python_binding.name, + item.name, temp, code.error_goto(item.pos))) code.put_decref_clear(temp, PyrexTypes.py_object_type) @@ -1120,10 +1120,10 @@ class CEnumDefItemNode(StatNode): self.value = self.value.coerce_to(PyrexTypes.c_int_type, env) self.value.analyse_const_expression(env) visibility = 'private' - if enum_entry.c_source.extern: + if enum_entry.extern: visibility = 'extern' - elif enum_entry.c_binding.visibility != 'private': - visibility = enum_entry.c_binding.visibility + elif enum_entry.c_visibility != 'private': + visibility = enum_entry.c_visibility entry = env.declare_const(self.name, enum_entry.type, self.value, self.pos, cname = self.cname, visibility = visibility) @@ -1196,11 +1196,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.python_binding.name, + lenv = ClosureScope(name=self.entry.name, outer_scope = genv, - scope_name=self.entry.c_binding.name) + scope_name=self.entry.c_name) else: - lenv = LocalScope(name=self.entry.python_binding.name, + lenv = LocalScope(name=self.entry.name, outer_scope=genv, parent_scope=env) lenv.return_type = self.return_type @@ -1227,10 +1227,10 @@ class FuncDefNode(StatNode, BlockNode): self.generate_lambda_definitions(lenv, code) is_getbuffer_slot = ( - self.entry.python_binding.name == "__getbuffer__" and + self.entry.name == "__getbuffer__" and self.entry.scope.is_c_class_scope) is_releasebuffer_slot = ( - self.entry.python_binding.name == "__releasebuffer__" and + self.entry.name == "__releasebuffer__" and self.entry.scope.is_c_class_scope) is_buffer_slot = is_getbuffer_slot or is_releasebuffer_slot if is_buffer_slot: @@ -1240,10 +1240,10 @@ 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.python_binding.name) + self.entry.name) if slot: preprocessor_guard = slot.preprocessor_guard_code() - if (self.entry.python_binding.name == '__long__' and + if (self.entry.name == '__long__' and not self.entry.scope.lookup_here('__int__')): preprocessor_guard = None @@ -1314,7 +1314,7 @@ class FuncDefNode(StatNode, BlockNode): code.putln("#endif") # ----- set up refnanny if not lenv.nogil: - code.put_setup_refcount_context(self.entry.python_binding.name) + code.put_setup_refcount_context(self.entry.name) # ----- Automatic lead-ins for certain special functions if is_getbuffer_slot: self.getbuffer_init(code) @@ -1351,7 +1351,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.python_binding.name, self.pos) + code.put_trace_call(self.entry.name, self.pos) # ----- Fetch arguments self.generate_argument_parsing_code(env, code) # If an argument is assigned to in the body, we must @@ -1368,7 +1368,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.c_binding.name) + entry.buffer_aux.buffer_info_var.c_name) # ----- Check and convert arguments self.generate_argument_type_tests(code) # ----- Acquire buffer arguments @@ -1409,7 +1409,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.c_binding.name) + #code.putln("%s = 0;" % entry.c_name) code.putln("__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}") err_val = self.error_value() @@ -1455,7 +1455,7 @@ class FuncDefNode(StatNode, BlockNode): if not Options.init_local_none: for entry in lenv.var_entries: if lenv.control_flow.get_state( - (entry.python_binding.name, 'initialized') + (entry.name, 'initialized') ) is not True: entry.xdecref_cleanup = 1 @@ -1464,7 +1464,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.c_binding.name) + code.put_giveref(entry.c_name) # Decref any increfed args for entry in lenv.arg_entries: if entry.type.is_pyobject: @@ -1486,7 +1486,7 @@ class FuncDefNode(StatNode, BlockNode): code.put_xgiveref(self.return_type.as_pyobject(Naming.retval_cname)) if (self.entry.is_special and - self.entry.python_binding.name == "__hash__"): + self.entry.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;" % ( @@ -1534,7 +1534,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.c_binding.name + arg_code = "((PyObject *)%s)" % arg.entry.c_name code.putln( 'if (unlikely(!__Pyx_ArgTypeTest(%s, %s, %d, "%s", %s))) %s' % ( arg_code, @@ -1550,7 +1550,7 @@ 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.c_binding.name) + arg.entry.c_name) code.putln('''PyErr_Format(PyExc_TypeError, "Argument '%s' must not be None"); %s''' % ( arg.name, code.error_goto(arg.pos))) @@ -1584,7 +1584,7 @@ class FuncDefNode(StatNode, BlockNode): # Special code for the __getbuffer__ function # def getbuffer_init(self, code): - info = self.local_scope.arg_entries[1].c_binding.name + info = self.local_scope.arg_entries[1].c_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. @@ -1593,13 +1593,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].c_binding.name + info = self.local_scope.arg_entries[1].c_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].c_binding.name + info = self.local_scope.arg_entries[1].c_name code.putln("if (%s->obj == Py_None) {" % info) code.put_gotref("Py_None") code.putln("__Pyx_DECREF(Py_None); %s->obj = NULL;" % info) @@ -1629,7 +1629,7 @@ class CFuncDefNode(FuncDefNode): directive_locals = {} def unqualified_name(self): - return self.entry.python_binding.name + return self.entry.name def analyse_declarations(self, env): self.directive_locals.update(env.directives['locals']) @@ -1677,7 +1677,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.python_binding.name, + name = self.entry.name, args = self.args, star_arg = None, starstar_arg = None, @@ -1702,12 +1702,12 @@ class CFuncDefNode(FuncDefNode): arg_names = [arg.name for arg in args] if is_module_scope: cfunc = ExprNodes.NameNode( - self.pos, name=self.entry.python_binding.name) + self.pos, name=self.entry.name) else: self_arg = ExprNodes.NameNode(self.pos, name=arg_names[0]) cfunc = ExprNodes.AttributeNode( self.pos, obj=self_arg, - attribute=self.entry.python_binding.name) + attribute=self.entry.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) @@ -1760,16 +1760,16 @@ class CFuncDefNode(FuncDefNode): if cname is None: cname = self.entry.func_cname entity = type.function_header_code(cname, ', '.join(arg_decls)) - if (self.entry.c_binding.visibility == 'public' and - not self.entry.c_source.extern): + if (self.entry.c_visibility == 'public' and + not self.entry.extern): dll_linkage = "DL_EXPORT" else: dll_linkage = None header = self.return_type.declaration_code(entity, dll_linkage = dll_linkage) - if self.entry.c_source.extern: + if self.entry.extern: storage_class = "%s " % Naming.extern_c_macro - elif self.entry.c_binding.visibility == 'public': + elif self.entry.c_visibility == 'public': storage_class = "" else: storage_class = "static " @@ -2181,9 +2181,9 @@ class DefNode(FuncDefNode): entry.doc_cname = \ Naming.funcdoc_prefix + prefix + name if entry.is_special: - if (entry.python_binding.name in TypeSlots.invisible or + if (entry.name in TypeSlots.invisible or not entry.doc or - (entry.python_binding.name in '__getattr__' and + (entry.name in '__getattr__' and env.directives['fast_getattr'])): entry.wrapperbase_cname = None else: @@ -2432,19 +2432,19 @@ 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.c_binding.name, item)) + code.putln("%s = %s;" % (entry.c_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.c_binding.name, + arg.entry.c_name, func, item, code.error_goto_if( arg.type.error_condition( - arg.entry.c_binding.name), + arg.entry.c_name), arg.pos))) else: error(arg.pos, "Cannot convert Python object argument to type '%s'" % arg.type) @@ -2482,34 +2482,34 @@ class DefNode(FuncDefNode): if self.starstar_arg: code.putln("%s = (%s) ? PyDict_Copy(%s) : PyDict_New();" % ( - self.starstar_arg.entry.c_binding.name, + self.starstar_arg.entry.c_name, Naming.kwds_cname, Naming.kwds_cname)) code.putln("if (unlikely(!%s)) return %s;" % ( - self.starstar_arg.entry.c_binding.name, + self.starstar_arg.entry.c_name, self.error_value())) self.starstar_arg.entry.xdecref_cleanup = 0 - code.put_gotref(self.starstar_arg.entry.c_binding.name) + code.put_gotref(self.starstar_arg.entry.c_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.c_binding.name, + self.star_arg.entry.c_name, Naming.args_cname, - self.star_arg.entry.c_binding.name)) + self.star_arg.entry.c_name)) if self.starstar_arg: code.putln("{") code.put_decref_clear( - self.starstar_arg.entry.c_binding.name, py_object_type) + self.starstar_arg.entry.c_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.c_binding.name) + code.put_gotref(self.star_arg.entry.c_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.c_binding.name, Naming.self_cname)) + self.star_arg.entry.c_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)) @@ -2518,14 +2518,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.c_binding.name, temp)) + self.star_arg.entry.c_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.c_binding.name, + self.star_arg.entry.c_name, Naming.args_cname)) self.star_arg.entry.xdecref_cleanup = 0 @@ -2642,41 +2642,41 @@ class DefNode(FuncDefNode): if arg.is_generic and arg.default: code.putln( "%s = %s;" % ( - arg.entry.c_binding.name, + arg.entry.c_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.c_binding.name, - self.starstar_arg.entry.c_binding.name, + self.starstar_arg.entry.c_name, + self.starstar_arg.entry.c_name, self.error_value())) - code.put_gotref(self.starstar_arg.entry.c_binding.name) + code.put_gotref(self.starstar_arg.entry.c_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.c_binding.name, Naming.args_cname, + self.star_arg.entry.c_name, Naming.args_cname, max_positional_args, Naming.args_cname)) - code.put_gotref(self.star_arg.entry.c_binding.name) + code.put_gotref(self.star_arg.entry.c_name) if self.starstar_arg: code.putln("") code.putln("if (unlikely(!%s)) {" % - self.star_arg.entry.c_binding.name) + self.star_arg.entry.c_name) code.put_decref_clear( - self.starstar_arg.entry.c_binding.name, py_object_type) + self.starstar_arg.entry.c_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.c_binding.name, + self.star_arg.entry.c_name, self.error_value())) code.putln('} else {') code.put("%s = %s; " % ( - self.star_arg.entry.c_binding.name, Naming.empty_tuple)) + self.star_arg.entry.c_name, Naming.empty_tuple)) code.put_incref(Naming.empty_tuple, py_object_type) code.putln('}') @@ -2818,7 +2818,7 @@ class DefNode(FuncDefNode): Naming.kwds_cname, Naming.pykwdlist_cname, (self.starstar_arg and - self.starstar_arg.entry.c_binding.name or + self.starstar_arg.entry.c_name or '0'), pos_arg_count, self.name)) @@ -2834,7 +2834,7 @@ class DefNode(FuncDefNode): code.putln('} else {') code.putln( "%s = %s;" % ( - arg.entry.c_binding.name, + arg.entry.c_name, arg.calculate_default_value_code(code))) code.putln('}') @@ -2847,7 +2847,7 @@ class DefNode(FuncDefNode): self.generate_arg_conversion(arg, code) elif arg.entry.in_closure: code.putln('%s = %s;' % ( - arg.entry.c_binding.name, arg.hdr_cname)) + arg.entry.c_name, arg.hdr_cname)) if arg.type.is_pyobject: code.put_var_incref(arg.entry) @@ -2867,7 +2867,7 @@ class DefNode(FuncDefNode): else: if new_type.assignable_from(old_type): code.putln( - "%s = %s;" % (arg.entry.c_binding.name, arg.hdr_cname)) + "%s = %s;" % (arg.entry.c_name, arg.hdr_cname)) else: error(arg.pos, "Cannot convert 1 argument from '%s' to '%s'" % @@ -2878,7 +2878,7 @@ class DefNode(FuncDefNode): func = new_type.from_py_function # copied from CoerceFromPyTypeNode if func: - lhs = arg.entry.c_binding.name + lhs = arg.entry.c_name rhs = "%s(%s)" % (func, arg.hdr_cname) if new_type.is_enum: rhs = PyrexTypes.typecast(new_type, PyrexTypes.c_long_type, rhs) @@ -2886,7 +2886,7 @@ class DefNode(FuncDefNode): lhs, rhs, code.error_goto_if( - new_type.error_condition(arg.entry.c_binding.name), + new_type.error_condition(arg.entry.c_name), arg.pos))) else: error(arg.pos, @@ -2898,10 +2898,10 @@ class DefNode(FuncDefNode): func = old_type.to_py_function if func: code.putln("%s = %s(%s); %s" % ( - arg.entry.c_binding.name, + arg.entry.c_name, func, arg.hdr_cname, - code.error_goto_if_null(arg.entry.c_binding.name, arg.pos))) + code.error_goto_if_null(arg.entry.c_name, arg.pos))) code.put_var_gotref(arg.entry) else: error(arg.pos, @@ -2948,24 +2948,24 @@ class OverrideCheckNode(StatNode): self.func_node = ExprNodes.RawCNameExprNode(self.pos, py_object_type) call_tuple = ExprNodes.TupleNode( self.pos, - args=[ExprNodes.NameNode(self.pos, name=arg.python_binding.name) + 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.python_binding.name) + args=[ExprNodes.NameNode(self.pos, name=arg.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.python_binding.name) + self.py_func.entry.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].c_binding.name + self_arg = "((PyObject *)%s)" % self.args[0].c_name code.putln("/* Check if called by wrapper */") code.putln("if (unlikely(%s)) ;" % Naming.skip_dispatch_cname) code.putln("/* Check if overriden in Python */") @@ -3116,7 +3116,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.c_binding.name + cenv.class_obj_cname = self.target.entry.c_name self.body.analyse_declarations(cenv) def analyse_expressions(self, env): @@ -4564,7 +4564,7 @@ class ForFromStatNode(LoopNode, StatNode): target_node = ExprNodes.PyTempNode(self.target.pos, None) target_node.allocate(code) interned_cname = code.intern_identifier( - self.target.entry.python_binding.name) + self.target.entry.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 9381ce21..48772ed3 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.python_binding. name) + entry = env.lookup(test_type_node.entry.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 1d6eab62..eed7a521 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1127,7 +1127,7 @@ property NAME: def visit_CNameDeclaratorNode(self, node): if node.name in self.seen_vars_stack[-1]: entry = self.env_stack[-1].lookup(node.name) - if entry is None or not entry.c_source.extern: + if entry is None or not entry.extern: warning(node.pos, "cdef variable '%s' declared after it is used" % node.name, 2) self.visitchildren(node) return node @@ -1138,12 +1138,12 @@ property NAME: return None def create_Property(self, entry): - if entry.python_binding.visibility == 'public': + if entry.visibility == 'public': if entry.type.is_pyobject: template = self.basic_pyobject_property else: template = self.basic_property - elif entry.python_binding.visibility == 'readonly': + elif entry.visibility == 'readonly': template = self.basic_property_ro else: raise NotImplementedError('private python methods') @@ -1151,15 +1151,15 @@ property NAME: u"ATTR": ExprNodes.AttributeNode( pos=entry.pos, obj=ExprNodes.NameNode(pos=entry.pos, name="self"), - attribute=entry.python_binding.name), + attribute=entry.name), }, pos=entry.pos).stats[0] - property.name = entry.python_binding.name + property.name = entry.name # --------------------------------------- # XXX This should go to AutoDocTransforms # --------------------------------------- if (Options.docstrings and self.current_directives['embedsignature']): - attr_name = entry.python_binding.name + attr_name = entry.name type_name = entry.type.declaration_code("", for_display=1) default_value = '' if not entry.type.is_pyobject: @@ -1394,7 +1394,7 @@ class CreateClosureClasses(CythonTransform): as_name = '%s_%s' % ( target_module_scope.next_id(Naming.closure_class_prefix), - node.entry.c_binding.name) + node.entry.c_name) entry = target_module_scope.declare_c_class(name = as_name, pos = node.pos, defining = True, implementing = True) @@ -1413,8 +1413,8 @@ class CreateClosureClasses(CythonTransform): node.needs_outer_scope = True for name, entry in in_closure: class_scope.declare_var(pos=entry.pos, - name=entry.python_binding.name, - cname=entry.c_binding.name, + name=entry.name, + cname=entry.c_name, type=entry.type, is_cdef=True) node.needs_closure = True @@ -1653,14 +1653,14 @@ class DebugTransform(CythonTransform): self.nested_funcdefs.append(node) return node - # node.entry.c_source.extern + # node.entry.extern if node.py_func is None: pf_cname = '' else: pf_cname = node.py_func.entry.func_cname attrs = dict( - name=node.entry.python_binding.name, + name=node.entry.name, cname=node.entry.func_cname, pf_cname=pf_cname, qualified_name=node.local_scope.qualified_name, @@ -1760,17 +1760,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.c_binding.name) + entry.outer_entry.c_name) qname = '%s.%s.%s' % (entry.scope.outer_scope.qualified_name, entry.scope.name, - entry.python_binding.name) + entry.name) elif entry.in_closure: cname = '%s->%s' % (Naming.cur_scope_cname, - entry.c_binding.name) + entry.c_name) qname = entry.qualified_name else: - cname = entry.c_binding.name + cname = entry.c_name qname = entry.qualified_name if not entry.pos: @@ -1782,7 +1782,7 @@ class DebugTransform(CythonTransform): lineno = str(entry.pos[1]) attrs = dict( - name=entry.python_binding.name, + name=entry.name, cname=cname, qualified_name=qname, type=vartype, diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 5395b9c3..2a2eff3b 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -13,7 +13,7 @@ import re import sys from Cython.Compiler.Scanning import PyrexScanner, FileSourceDescriptor -from Binding import CtxAttribute, CSource, CBinding, PythonBinding +from Binding import Binding import Nodes import ExprNodes import StringEncoding @@ -32,32 +32,17 @@ _LOG.addHandler(logging.StreamHandler()) _LOG.handlers[-1].setLevel(logging.DEBUG) -class Ctx(object): +class Ctx(Binding): # Parsing context level = 'other' typedef_flag = 0 nogil = 0 templates = None - c_source = None - c_binding = None - python_binding = None - - def __init__(self, **kwds): - self.__dict__.update(kwds) - if self.c_source is None: - self.c_source = CSource() - if self.c_binding is None: - self.c_binding = CBinding() - if self.python_binding is None: - self.python_binding = PythonBinding() def __call__(self, **kwds): ctx = Ctx() d = ctx.__dict__ d.update(self.__dict__) - for k,v in self.__dict__.iteritems(): - if isinstance(v, CtxAttribute): - d[k] = v.deepcopy() d.update(kwds) return ctx @@ -1825,7 +1810,7 @@ def p_statement(s, ctx, first_statement = 0): decorators = p_decorators(s) if s.sy not in ('def', 'cdef', 'cpdef', 'class'): s.error("Decorators can only be followed by functions or classes") - elif s.sy == 'pass' and ctx.c_source.cdef_flag: + elif s.sy == 'pass' and ctx.cdef_flag: # empty cdef block return p_pass_statement(s, with_newline = 1) sy = s.sy @@ -1834,23 +1819,23 @@ def p_statement(s, ctx, first_statement = 0): if ctx.level not in ('module', 'module_pxd'): s.error("ctypedef statement not allowed here") return p_ctypedef_statement(s, pos, ctx) - elif ctx.c_source.cdef_flag: + elif ctx.cdef_flag: if ctx.level not in ('module', 'module_pxd', 'function', 'c_class', 'c_class_pxd'): s.error('cdef statement not allowed here') s.level = ctx.level - if ctx.c_binding.api: - if ctx.c_source.cdef_flag: - if ctx.c_source.extern: + if ctx.api: + if ctx.cdef_flag: + if ctx.extern: error(pos, "Cannot combine 'api' with 'extern'") else: s.error("'api' not allowed with this statement") - if ctx.c_source.cdef_flag and p_nogil(s): + if ctx.cdef_flag and p_nogil(s): ctx.nogil = 1 - if ctx.python_binding.overridable: + if ctx.overridable: error(pos, "cdef blocks cannot be declared cpdef") return p_cdef_block(s, ctx) - elif s.sy == ':' and ctx.c_source.cdef_flag: - if ctx.python_binding.overridable: + elif s.sy == ':' and ctx.cdef_flag: + if ctx.overridable: error(pos, "cdef blocks cannot be declared cpdef") return p_cdef_block(s, ctx) elif s.sy == 'def': @@ -1861,19 +1846,19 @@ def p_statement(s, ctx, first_statement = 0): s.level = ctx.level return p_def_statement(s, decorators) elif s.sy == 'class': - if ctx.c_source.cdef_flag: + if ctx.cdef_flag: if ctx.level not in ('module', 'module_pxd'): error(pos, "Extension type definition not allowed here") - if ctx.python_binding.overridable: + if ctx.overridable: error(pos, "Extension types cannot be declared cpdef") return p_c_class_definition(s, pos, ctx, decorators) else: if ctx.level not in ('module', 'function', 'class', 'other'): s.error("class definition not allowed here") return p_class_statement(s, decorators) - elif s.sy == 'from' and ctx.c_source.extern: + elif s.sy == 'from' and ctx.extern: return p_cdef_extern_block(s, pos, ctx) - elif s.sy == 'import' and ctx.c_source.cdef_flag: + elif s.sy == 'import' and ctx.cdef_flag: s.next() return p_cdef_extern_block(s, pos, ctx) elif s.sy == 'include': @@ -1882,15 +1867,15 @@ def p_statement(s, ctx, first_statement = 0): return p_include_statement(s, ctx) elif ctx.level == 'c_class' and s.sy == 'IDENT' and s.systring == 'property': return p_property_decl(s) - elif ctx.c_source.cdef_flag: + elif ctx.cdef_flag: if s.sy == 'IDENT' and s.systring == 'cppclass': - if not ctx.c_source.extern: + if not ctx.extern: error(pos, "C++ classes need to be declared extern") return p_cpp_class_definition(s, pos, ctx) elif s.sy == 'IDENT' and s.systring in ("struct", "union", "enum", "packed"): if ctx.level not in ('module', 'module_pxd'): error(pos, "C struct/union/enum definition not allowed here") - if ctx.python_binding.overridable: + if ctx.overridable: error(pos, "C struct/union/enum cannot be declared cpdef") if s.systring == "enum": return p_c_enum_definition(s, pos, ctx) @@ -1943,7 +1928,7 @@ def p_suite(s, ctx = Ctx(), with_doc = 0, with_pseudo_doc = 0): body = p_statement_list(s, ctx) s.expect_dedent() else: - if ctx.c_binding.api: + if ctx.api: s.error("'api' not allowed with this statement") if ctx.level in ('module', 'class', 'function', 'other'): body = p_simple_statement_list(s, ctx) @@ -2361,9 +2346,9 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag, error(s.position(), "Empty declarator") name = "" cname = None - if cname is None and ctx.c_source.namespace is not None and nonempty: - cname = ctx.c_source.namespace + "::" + name - if name == 'operator' and ctx.c_source.extern and nonempty: + if cname is None and ctx.source_namespace is not None and nonempty: + cname = ctx.source_namespace + "::" + name + if name == 'operator' and ctx.extern and nonempty: op = s.sy if [1 for c in op if c in '+-*/<=>!%&|([^~,']: s.next() @@ -2525,7 +2510,7 @@ def p_cdef_block(s, ctx): def p_cdef_extern_block(s, pos, ctx): _LOG.debug('p_cdef_extern_block(s=)' % (s.sy, s.systring)) - if ctx.python_binding.overridable: + if ctx.overridable: error(pos, "cdef extern blocks cannot be declared cpdef") include_file = None s.expect('from') @@ -2534,18 +2519,18 @@ def p_cdef_extern_block(s, pos, ctx): else: include_file = p_string_literal(s, 'u')[2] ctx = ctx() - ctx.c_source.cdef_flag = 1 - ctx.c_source.extern = 1 + ctx.cdef_flag = 1 + ctx.extern = 1 if s.systring == "namespace": s.next() - ctx.c_source.namespace = p_string_literal(s, 'u')[2] + ctx.source_namespace = p_string_literal(s, 'u')[2] if p_nogil(s): ctx.nogil = 1 body = p_suite(s, ctx) return Nodes.CDefExternNode(pos, include_file = include_file, body = body, - namespace = ctx.c_source.namespace) + namespace = ctx.source_namespace) def p_c_enum_definition(s, pos, ctx): # s.sy == ident 'enum' @@ -2556,8 +2541,8 @@ def p_c_enum_definition(s, pos, ctx): name = s.systring s.next() cname = p_opt_cname(s) - if cname is None and ctx.c_source.namespace is not None: - cname = ctx.c_source.namespace + "::" + name + if cname is None and ctx.source_namespace is not None: + cname = ctx.source_namespace + "::" + name else: name = None cname = None @@ -2573,10 +2558,10 @@ def p_c_enum_definition(s, pos, ctx): p_c_enum_line(s, ctx, items) s.expect_dedent() visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility return Nodes.CEnumDefNode( pos, name = name, cname = cname, items = items, typedef_flag = ctx.typedef_flag, visibility = visibility, @@ -2603,17 +2588,17 @@ def p_c_enum_item(s, ctx, items): ctx = p_binding(s, ctx) name = p_ident(s) cname = p_opt_cname(s) - if cname is None and ctx.c_source.namespace is not None: - cname = ctx.c_source.namespace + "::" + name + if cname is None and ctx.source_namespace is not None: + cname = ctx.source_namespace + "::" + name value = None if s.sy == '=': s.next() value = p_test(s) visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility items.append(Nodes.CEnumDefItemNode(pos, name = name, cname = cname, value = value, visibility = visibility, @@ -2634,8 +2619,8 @@ def p_c_struct_or_union_definition(s, pos, ctx): s.next() name = p_ident(s) cname = p_opt_cname(s) - if cname is None and ctx.c_source.namespace is not None: - cname = ctx.c_source.namespace + "::" + name + if cname is None and ctx.source_namespace is not None: + cname = ctx.source_namespace + "::" + name attributes = None if s.sy == ':': s.next() @@ -2654,18 +2639,18 @@ def p_c_struct_or_union_definition(s, pos, ctx): else: s.expect_newline("Syntax error in struct or union definition") visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility return Nodes.CStructOrUnionDefNode(pos, name = name, cname = cname, kind = kind, attributes = attributes, typedef_flag = ctx.typedef_flag, - cdef_flag = ctx.c_source.cdef_flag, - overridable = ctx.python_binding.overridable, + cdef_flag = ctx.cdef_flag, + overridable = ctx.overridable, visibility = visibility, in_pxd = ctx.level == 'module_pxd', packed = packed) @@ -2675,10 +2660,10 @@ def p_visibility(s, ctx): % (s.sy, s.systring)) pos = s.position() prev_visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: prev_visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - prev_visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + prev_visibility = ctx.c_visibility visibility = prev_visibility if s.sy == 'IDENT' and s.systring in ('extern', 'public', 'readonly'): visibility = s.systring @@ -2687,9 +2672,9 @@ def p_visibility(s, ctx): % (prev_visibility, visibility)) s.next() if visibility == 'extern': - ctx.c_source.extern = 1 + ctx.extern = 1 else: - ctx.c_binding.visibility = visibility + ctx.c_visibility = visibility return ctx def p_c_modifiers(s): @@ -2705,25 +2690,25 @@ def p_binding(s, ctx): _LOG.debug('p_binding(s=)' % (s.sy, s.systring)) new_ctx = ctx() - new_ctx.python_binding.overridable = 0 + new_ctx.overridable = 0 if s.sy == 'cdef': - new_ctx.c_source.cdef_flag = 1 + new_ctx.cdef_flag = 1 s.next() elif s.sy == 'cpdef': - new_ctx.c_source.cdef_flag = 1 - new_ctx.python_binding.overridable = 1 + new_ctx.cdef_flag = 1 + new_ctx.overridable = 1 s.next() elif s.sy == 'ctypedef': new_ctx.typedef_flag = 1 - new_ctx.c_source.cdef_flag = 1 + new_ctx.cdef_flag = 1 s.next() - if new_ctx.c_source.cdef_flag: + if new_ctx.cdef_flag: new_ctx = p_visibility(s, new_ctx) - new_ctx.c_binding.api = ctx.c_binding.api or p_api(s) - _LOG.info(' binding cdef: %s' % new_ctx.c_source.cdef_flag) + new_ctx.api = ctx.api or p_api(s) + _LOG.info(' binding cdef: %s' % new_ctx.cdef_flag) _LOG.info(' binding ctypedef: %s' % new_ctx.typedef_flag) - _LOG.info(' c binding api: %s' % new_ctx.c_binding.api) - _LOG.info(' python binding overridable: %s' % new_ctx.python_binding.overridable) + _LOG.info(' c binding api: %s' % new_ctx.api) + _LOG.info(' python binding overridable: %s' % new_ctx.overridable) return new_ctx def p_c_func_or_var_declaration(s, pos, ctx, decorators=None): @@ -2734,19 +2719,19 @@ def p_c_func_or_var_declaration(s, pos, ctx, decorators=None): base_type = p_c_base_type(s, nonempty = 1, templates = ctx.templates) declarator = p_c_declarator(s, ctx, cmethod_flag = cmethod_flag, assignable = 1, nonempty = 1) - declarator.overridable = ctx.python_binding.overridable + declarator.overridable = ctx.overridable if s.sy == ':': if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd') and not ctx.templates: s.error("C function definition not allowed here") doc, suite = p_suite(s, Ctx(level = 'function'), with_doc = 1) visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility result = Nodes.CFuncDefNode(pos, - cdef_flag = ctx.c_source.cdef_flag, - overridable = ctx.python_binding.overridable, + cdef_flag = ctx.cdef_flag, + overridable = ctx.overridable, visibility = visibility, base_type = base_type, declarator = declarator, @@ -2754,7 +2739,7 @@ def p_c_func_or_var_declaration(s, pos, ctx, decorators=None): body = suite, doc = doc, modifiers = modifiers, - api = ctx.c_binding.api) + api = ctx.api) else: #if api: # s.error("'api' not allowed with variable declaration") @@ -2768,14 +2753,14 @@ def p_c_func_or_var_declaration(s, pos, ctx, decorators=None): declarators.append(declarator) s.expect_newline("Syntax error in C variable declaration") visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility result = Nodes.CVarDefNode(pos, visibility = visibility, - api = ctx.c_binding.api, - overridable = ctx.python_binding.overridable, + api = ctx.api, + overridable = ctx.overridable, base_type = base_type, declarators = declarators, decorators = decorators, @@ -2799,10 +2784,10 @@ def p_ctypedef_statement(s, pos, ctx): declarator = p_c_declarator(s, ctx, is_type = 1, nonempty = 1) s.expect_newline("Syntax error in ctypedef statement") visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility return Nodes.CTypeDefNode( pos, base_type = base_type, declarator = declarator, visibility = visibility, @@ -2919,7 +2904,7 @@ def p_c_class_definition(s, pos, ctx, decorators=None): s.next() module_path.append(class_name) class_name = p_ident(s) - if module_path and not ctx.c_source.extern: + if module_path and not ctx.extern: error(pos, "Qualified class name only allowed for 'extern' C class") if module_path and s.sy == 'IDENT' and s.systring == 'as': s.next() @@ -2942,7 +2927,7 @@ def p_c_class_definition(s, pos, ctx, decorators=None): base_class_module = ".".join(base_class_path[:-1]) base_class_name = base_class_path[-1] if s.sy == '[': - if not (ctx.c_source.extern or ctx.c_binding.visibility == 'public'): + if not (ctx.extern or ctx.c_visibility == 'public'): error(s.position(), "Name options only allowed for 'public' or 'extern' C class") objstruct_name, typeobj_name = p_c_class_options(s) if s.sy == ':': @@ -2956,29 +2941,29 @@ def p_c_class_definition(s, pos, ctx, decorators=None): doc = None body = None visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility - if ctx.c_source.extern: + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility + if ctx.extern: if not module_path: error(pos, "Module name required for 'extern' C class") if typeobj_name: error(pos, "Type object name specification not allowed for 'extern' C class") - elif ctx.c_binding.visibility == 'public': + elif ctx.c_visibility == 'public': if not objstruct_name: error(pos, "Object struct name specification required for 'public' C class") if not typeobj_name: error(pos, "Type object name specification required for 'public' C class") - elif ctx.c_binding.visibility == 'private': - if ctx.c_binding.api: + elif ctx.c_visibility == 'private': + if ctx.api: error(pos, "Only 'public' C class can be declared 'api'") else: error(pos, "Invalid class visibility '%s'" % visibility) return Nodes.CClassDefNode(pos, visibility = visibility, typedef_flag = ctx.typedef_flag, - api = ctx.c_binding.api, + api = ctx.api, module_name = ".".join(module_path), class_name = class_name, as_name = as_name, @@ -3097,8 +3082,8 @@ def p_cpp_class_definition(s, pos, ctx): module_path = [] class_name = p_ident(s) cname = p_opt_cname(s) - if cname is None and ctx.c_source.namespace is not None: - cname = ctx.c_source.namespace + "::" + class_name + if cname is None and ctx.source_namespace is not None: + cname = ctx.source_namespace + "::" + class_name if s.sy == '.': error(pos, "Qualified class name not allowed C++ class") if s.sy == '[': @@ -3127,9 +3112,9 @@ def p_cpp_class_definition(s, pos, ctx): s.expect_indent() attributes = [] body_ctx = Ctx() - body_ctx.c_binding.visibility = p_visibility(s, ctx) - body_ctx.python_binding.visibility = ctx.python_binding.visibility - body_ctx.c_source.extern = ctx.c_source.extern + body_ctx.c_visibility = p_visibility(s, ctx) + body_ctx.visibility = ctx.visibility + body_ctx.extern = ctx.extern body_ctx.templates = templates while s.sy != 'DEDENT': if s.systring == 'cppclass': @@ -3146,10 +3131,10 @@ def p_cpp_class_definition(s, pos, ctx): attributes = None s.expect_newline("Syntax error in C++ class definition") visibility = 'private' - if ctx.c_source.extern: + if ctx.extern: visibility = 'extern' - elif ctx.c_binding.visibility != 'private': - visibility = ctx.c_binding.visibility + elif ctx.c_visibility != 'private': + visibility = ctx.c_visibility return Nodes.CppClassNode(pos, name = class_name, cname = cname, diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 5694f5ef..24aca54a 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1908,7 +1908,7 @@ class CFuncType(CType): def opt_arg_cname(self, arg_name): return self.op_arg_struct.base_type.scope.lookup( - arg_name).c_binding.name + arg_name).c_name class CFuncTypeArg(object): @@ -1962,9 +1962,9 @@ class StructUtilityCode(object): 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.python_binding.name, identifier=True) + member.name, identifier=True) code.putln("member = %s(s.%s); if (member == NULL) goto bad;" % ( - member.type.to_py_function, member.c_binding.name)) + member.type.to_py_function, member.c_name)) code.putln("if (PyDict_SetItem(res, %s, member) < 0) goto bad;" % nameconst_cname) code.putln("Py_DECREF(member);") code.putln("return res;") @@ -2019,7 +2019,7 @@ class CStructOrUnionType(CType): self.to_py_function = None self._convert_code = False return False - forward_decl = not self.entry.c_source.extern + forward_decl = not self.entry.extern self._convert_code = StructUtilityCode(self, forward_decl) env.use_utility_code(self._convert_code) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index a9b56c9c..b86e60d4 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -4,7 +4,7 @@ import re from Cython import Utils -from Binding import CSource, CBinding, PythonBinding +from Binding import Binding from Errors import warning, error, InternalError from StringEncoding import EncodedString import Options, Naming @@ -56,12 +56,9 @@ class BufferAux(object): def __repr__(self): return "" % self.__dict__ -class Entry(object): +class Entry(Binding): # A symbol table entry in a Scope or ModuleNamespace. # - # c_source CSource - # c_binding CBinding - # python_binding PythonBinding # type PyrexType Type of entity # doc string Doc string # init string Initial value @@ -125,9 +122,6 @@ 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 = "" @@ -179,14 +173,8 @@ class Entry(object): might_overflow = 0 def __init__(self, name, cname, type, pos = None, init = None): - 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.name = name + self.c_name = cname self.type = type self.pos = pos self.init = init @@ -194,12 +182,10 @@ class Entry(object): self.assignments = [] def __repr__(self): - return "Entry(name=%s, type=%s)" % ( - self.python_binding.name, self.type) + return "Entry(name=%s, type=%s)" % (self.name, self.type) def redeclared(self, pos): - error(pos, "'%s' does not match previous declaration" % - self.python_binding.name) + error(pos, "'%s' does not match previous declaration" % self.name) error(self.pos, "Previous declaration is here") def all_alternatives(self): @@ -209,14 +195,11 @@ class Entry(object): class WTK_Entry(Entry): # wrapper around Entry allowing a gradual transition to the new # Binding attributes - def __init__(self, c_source, c_binding, python_binding, type, pos = None, - init = None): + def __init__(self, binding, type, pos = None, init = None): Entry.__init__( - self, name=python_binding.name, cname=c_binding.name, + self, name=binding.name, cname=binding.c_name, type=type, pos = pos, init=init) - self.c_source = c_source - self.c_binding = c_binding - self.python_binding = python_binding + binding.push(self) class Scope(object): @@ -352,88 +335,84 @@ class Scope(object): # Return the module-level scope containing this scope. return self.outer_scope.builtin_scope() - def WTK_declare(self, c_source, c_binding, python_binding, type, pos): + def WTK_declare(self, binding, type, pos): # Create new entry, and add to dictionary if # name is not None. Reports a warning if already # declared. if type.is_buffer and not isinstance(self, LocalScope): error(pos, ERR_BUF_LOCALONLY) if (not self.in_cinclude and - c_binding.name and re.match("^_[_A-Z]+$", c_binding.name)): + binding.c_name and re.match("^_[_A-Z]+$", binding.c_name)): # See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names - warning(pos, "'%s' is a reserved name in C." % c_binding.name, -1) + warning(pos, "'%s' is a reserved name in C." % binding.c_name, -1) entries = self.entries - if python_binding.name and python_binding.name in entries: - if c_source.extern: - warning(pos, "'%s' redeclared " % python_binding.name, 0) - elif c_binding.visibility != 'ignore': - error(pos, "'%s' redeclared " % python_binding.name) - entry = WTK_Entry(c_source, c_binding, python_binding, type, pos = pos) + if binding.name and binding.name in entries: + if binding.extern: + warning(pos, "'%s' redeclared " % binding.name, 0) + elif binding.c_visibility != 'ignore': + error(pos, "'%s' redeclared " % binding.name) + entry = WTK_Entry(binding, type, pos = pos) entry.in_cinclude = self.in_cinclude - if python_binding.name: - entry.qualified_name = self.qualify_name(python_binding.name) -# if python_binding.name in entries and self.is_cpp(): -# entries[python_binding.name].overloaded_alternatives.append( + if binding.name: + entry.qualified_name = self.qualify_name(binding.name) +# if binding.name in entries and self.is_cpp(): +# entries[binding.name].overloaded_alternatives.append( # entry) # else: -# entries[python_binding.name] = entry - entries[python_binding.name] = entry +# entries[binding.name] = entry + entries[binding.name] = entry entry.scope = self return entry def _WTK_setup(self, name, cname, visibility): - c_source = CSource() - c_binding = CBinding() - c_binding.name = cname - python_binding = PythonBinding() - python_binding.name = name + binding = Binding(name=name, c_name=cname) if visibility == 'extern': - c_source.extern = 1 - c_binding.visibility = 'public' + binding.extern = 1 + binding.c_visibility = 'public' elif self.outer_scope and visibility not in ('readonly',): - c_binding.visibility = visibility + binding.c_visibility = visibility else: - python_binding.visibility = visibility - if python_binding.visibility != 'private': - c_binding.visibility = 'public' - return (c_source, c_binding, python_binding) + binding.visibility = visibility + if binding.visibility != 'private': + binding.c_visibility = 'public' + return binding def declare(self, name, cname, type, pos, visibility): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - return self.WTK_declare(c_source, c_binding, python_binding, type, pos) + binding = self._WTK_setup(name, cname, visibility) + return self.WTK_declare(binding, type, pos) def qualify_name(self, name): return EncodedString("%s.%s" % (self.qualified_name, name)) def declare_const(self, name, type, value, pos, cname = None, visibility = 'private'): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - return self.WTK_declare_const(c_source, c_binding, python_binding, type, value, pos) + binding = self._WTK_setup(name, cname, visibility) + return self.WTK_declare_const(binding, type, value, pos) - def WTK_declare_const(self, c_source, c_binding, python_binding, + def WTK_declare_const(self, binding, type, value, pos): # Add an entry for a named constant. - if not c_binding.name: - if self.in_cinclude or c_binding.visibility == 'public': - c_binding.name = python_binding.name + if not binding.c_name: + if self.in_cinclude or binding.c_visibility == 'public': + binding.c_name = binding.name else: - c_binding.name = self.mangle( - Naming.enum_prefix, python_binding.name) - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos) + binding.c_name = self.mangle( + Naming.enum_prefix, binding.name) + entry = self.WTK_declare(binding, type, pos) entry.is_const = 1 entry.value_node = value return entry def declare_type(self, name, type, pos, cname = None, visibility = 'private', defining = 1): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - return self.WTK_declare_type(c_source, c_binding, python_binding, type, defining, pos) + binding = self._WTK_setup(name, cname, visibility) + return self.WTK_declare_type(binding, type, defining, pos) - def WTK_declare_type(self, c_source, c_binding, python_binding, + def WTK_declare_type(self, binding, type, defining = 1, pos = None): # Add an entry for a type definition. - if not c_binding.name: - c_binding.name = python_binding.name - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos) + if not binding.c_name: + binding.c_name = binding.name + entry = self.WTK_declare(binding, type, pos) entry.is_type = 1 if defining: self.type_entries.append(entry) @@ -442,67 +421,67 @@ class Scope(object): def declare_typedef(self, name, base_type, pos, cname = None, visibility = 'private'): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility=visibility) - return self.WTK_declare_typedef(c_source, c_binding, python_binding, base_type, pos) + binding = self._WTK_setup(name, cname, visibility=visibility) + return self.WTK_declare_typedef(binding, base_type, pos) - def WTK_declare_typedef(self, c_source, c_binding, python_binding, + def WTK_declare_typedef(self, binding, base_type, pos): - if not c_binding.name: - if self.in_cinclude or c_binding.visibility == 'public': - c_binding.name = python_binding.name + if not binding.c_name: + if self.in_cinclude or binding.c_visibility == 'public': + binding.c_name = binding.name else: - c_binding.name = self.mangle( - Naming.type_prefix, python_binding.name) + binding.c_name = self.mangle( + Naming.type_prefix, binding.name) try: type = PyrexTypes.create_typedef_type( - python_binding.name, base_type, c_binding.name, - c_source.extern) + binding.name, base_type, binding.c_name, + binding.extern) except ValueError, e: error(pos, e.args[0]) type = PyrexTypes.error_type entry = self.WTK_declare_type( - c_source, c_binding, python_binding, type, pos = pos) + binding, type, pos = pos) type.qualified_name = entry.qualified_name return entry def declare_struct_or_union(self, name, kind, scope, typedef_flag, pos, cname = None, visibility = 'private', packed = False): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility=visibility) - return self.WTK_declare_struct_or_union(c_source, c_binding, python_binding, pos, kind, scope, typedef_flag, packed) + binding = self._WTK_setup(name, cname, visibility=visibility) + return self.WTK_declare_struct_or_union(binding, pos, kind, scope, typedef_flag, packed) def WTK_declare_struct_or_union( - self, c_source, c_binding, python_binding, + self, binding, pos, kind, scope, typedef_flag, packed=False): # Add an entry for a struct or union definition. - if not c_binding.name: - if self.in_cinclude or c_binding.visibility == 'public': - c_binding.name = python_binding.name + if not binding.c_name: + if self.in_cinclude or binding.c_visibility == 'public': + binding.c_name = binding.name else: - c_binding.name = self.mangle( - Naming.type_prefix, python_binding.name) - entry = self.lookup_here(python_binding.name) + binding.c_name = self.mangle( + Naming.type_prefix, binding.name) + entry = self.lookup_here(binding.name) if not entry: type = PyrexTypes.CStructOrUnionType( - python_binding.name, kind, scope, typedef_flag, c_binding.name, + binding.name, kind, scope, typedef_flag, binding.c_name, packed) entry = self.WTK_declare_type( - c_source, c_binding, python_binding, type, + binding, type, defining = scope is not None, pos = pos) self.sue_entries.append(entry) type.entry = entry else: if not (entry.is_type and entry.type.is_struct_or_union and entry.type.kind == kind): - warning(pos, "'%s' redeclared " % python_binding.name, 0) + warning(pos, "'%s' redeclared " % binding.name, 0) elif scope and entry.type.scope: warning( pos, "'%s' already defined (ignoring second definition)" % - python_binding.name, 0) + binding.name, 0) else: self.check_previous_typedef_flag(entry, typedef_flag, pos) self.WTK_check_previous_visibility( - entry, c_source, c_binding, python_binding, pos = pos) + entry, binding, pos = pos) if scope: entry.type.scope = scope self.type_entries.append(entry) @@ -513,41 +492,41 @@ class Scope(object): def declare_cpp_class(self, name, scope, pos, cname = None, base_classes = [], visibility = 'extern', templates = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_cpp_class( - c_source, c_binding, python_binding, pos, scope, base_classes, templates) + binding, pos, scope, base_classes, templates) def WTK_declare_cpp_class( - self, c_source, c_binding, python_binding, + self, binding, pos, scope, base_classes = (), templates = None): - if not c_source.extern: + if not binding.extern: error(pos, "C++ classes may only be extern") - if c_binding.name is None: - c_binding.name = python_binding.name - entry = self.lookup_here(python_binding.name) + if binding.c_name is None: + binding.c_name = binding.name + entry = self.lookup_here(binding.name) if not entry: type = PyrexTypes.CppClassType( - python_binding.name, scope, c_binding.name, base_classes, + binding.name, scope, binding.c_name, base_classes, templates = templates) entry = self.WTK_declare_type( - c_source, c_binding, python_binding, type, + binding, type, defining = scope is not None, pos = pos) else: if not (entry.is_type and entry.type.is_cpp_class): - warning(pos, "'%s' redeclared " % python_binding.name, 0) + warning(pos, "'%s' redeclared " % binding.name, 0) elif scope and entry.type.scope: warning( pos, "'%s' already defined (ignoring second definition)" % - python_binding.name, 0) + binding.name, 0) else: if scope: entry.type.scope = scope self.type_entries.append(entry) if templates is not None: for T in templates: - c_source,c_binding,python_binding = self._WTK_setup(T.name, T.name, 'extern') + binding = self._WTK_setup(T.name, T.name, 'extern') template_entry = entry.type.scope.WTK_declare( - c_source, c_binding, python_binding, type=T, pos=None) + binding, type=T, pos=None) template_entry.is_type = 1 def declare_inherited_attributes(entry, base_classes): @@ -563,150 +542,150 @@ 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.python_binding.name, + entry.name, ("cdef", "ctypedef")[entry.type.typedef_flag])) def _check_previous_visibility(self, entry, visibility): - c_source,c_binding,python_binding = self._WTK_setup('dummy', 'dummy', visibility) - return self.WTK__check_previous_visibility(entry, c_source, c_binding, python_binding) + binding = self._WTK_setup('dummy', 'dummy', visibility) + return self.WTK__check_previous_visibility(entry, binding) - def WTK__check_previous_visibility(self, entry, c_source, c_binding, python_binding): + def WTK__check_previous_visibility(self, entry, binding): # Compare the visibility of `entry` with a second # `visibility`. If there is a difference, return a string # representing the conflicting `entry` visibility, otherwise # return an empty string. - if c_source.extern != entry.c_source.extern: + if binding.extern != entry.extern: return 'extern' - if c_binding.visibility != entry.c_binding.visibility: - return entry.c_binding.visibility - if python_binding.visibility != entry.python_binding.visibility: - return entry.python_binding.visibility + if binding.c_visibility != entry.c_visibility: + return entry.c_visibility + if binding.visibility != entry.visibility: + return entry.visibility def check_previous_visibility(self, entry, visibility, pos, type_name=None): - c_source,c_binding,python_binding = self._WTK_setup('dummy', 'dummy', visibility) - return self.WTK_check_previous_visibility(entry, c_source, c_binding, python_binding, pos, type_name) + binding = self._WTK_setup('dummy', 'dummy', visibility) + return self.WTK_check_previous_visibility(entry, binding, pos, type_name) def WTK_check_previous_visibility( - self, entry, c_source, c_binding, python_binding, + self, entry, binding, type_name=None, pos = None): # WTK: check api? Previous code seems to allow you to set the # api flag anywhere. - vis_diff = self.WTK__check_previous_visibility(entry, c_source, c_binding, python_binding) + vis_diff = self.WTK__check_previous_visibility(entry, binding) if vis_diff: if not type_name: type_name = type(entry) error(pos, "%s '%s' previously declared as '%s'" % ( - type_name, entry.python_binding.name, vis_diff)) + type_name, entry.name, vis_diff)) def declare_enum(self, name, pos, cname, typedef_flag, visibility = 'private'): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility=visibility) - return self.WTK_declare_enum(c_source, c_binding, python_binding, pos, typedef_flag) + binding = self._WTK_setup(name, cname, visibility=visibility) + return self.WTK_declare_enum(binding, pos, typedef_flag) - def WTK_declare_enum(self, c_source, c_binding, python_binding, pos, + def WTK_declare_enum(self, binding, pos, typedef_flag): - if python_binding.name: - if not c_binding.name: - if self.in_cinclude or c_binding.visibility == 'public': - c_binding.name = python_binding.name + if binding.name: + if not binding.c_name: + if self.in_cinclude or binding.c_visibility == 'public': + binding.c_name = binding.name else: - c_binding.name = self.mangle( - Naming.type_prefix, python_binding.name) + binding.c_name = self.mangle( + Naming.type_prefix, binding.name) type = PyrexTypes.CEnumType( - python_binding.name, c_binding.name, typedef_flag) + binding.name, binding.c_name, typedef_flag) else: type = PyrexTypes.c_anon_enum_type - entry = self.WTK_declare_type(c_source, c_binding, python_binding, type, pos = pos) + entry = self.WTK_declare_type(binding, type, pos = pos) entry.enum_values = [] self.sue_entries.append(entry) return entry def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = 0): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, pos = pos) + binding, type, is_cdef, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, pos = None): # Add an entry for a variable. - if not c_binding.name: - if c_binding.visibility != 'private': - c_binding.name = python_binding.name + if not binding.c_name: + if binding.c_visibility != 'private': + binding.c_name = binding.name else: - c_binding.name = self.mangle( - Naming.var_prefix, python_binding.name) - if type.is_cpp_class and not c_source.extern: + binding.c_name = self.mangle( + Naming.var_prefix, binding.name) + if type.is_cpp_class and not binding.extern: constructor = type.scope.lookup(u'') if constructor is not None and PyrexTypes.best_match([], constructor.all_alternatives()) is None: error(pos, "C++ class must have a default constructor to be stack allocated") - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos) + entry = self.WTK_declare(binding, type, pos) entry.is_variable = 1 self.control_flow.set_state( - (), (python_binding.name, 'initialized'), False) + (), (binding.name, 'initialized'), False) return entry def declare_builtin(self, name, pos): - c_source,c_binding,python_binding = self._WTK_setup(name, name, visibility='private') - return self.WTK_declare_builtin(c_source, c_binding, python_binding, pos) + binding = self._WTK_setup(name, name, visibility='private') + return self.WTK_declare_builtin(binding, pos) - def WTK_declare_builtin(self, c_source, c_binding, python_binding, pos): - return self.outer_scope.WTK_declare_builtin(c_source, c_binding, python_binding, pos) + def WTK_declare_builtin(self, binding, pos): + return self.outer_scope.WTK_declare_builtin(binding, pos) def _declare_pyfunction(self, name, pos, visibility='extern', entry=None): - c_source,c_binding,python_binding = self._WTK_setup(name, name, visibility) - return self.WTK__declare_pyfunction(c_source, c_binding, python_binding, entry, pos = pos) + binding = self._WTK_setup(name, name, visibility) + return self.WTK__declare_pyfunction(binding, entry, pos = pos) - def WTK__declare_pyfunction(self, c_source, c_binding, python_binding, + def WTK__declare_pyfunction(self, binding, entry = None, pos = None): if entry and not entry.type.is_cfunction: - error(pos, "'%s' already declared" % python_binding.name) + error(pos, "'%s' already declared" % binding.name) error(entry.pos, "Previous declaration is here") - entry = self.WTK_declare_var(c_source, c_binding, python_binding, py_object_type, pos = pos) + entry = self.WTK_declare_var(binding, py_object_type, pos = pos) entry.signature = pyfunction_signature self.pyfunc_entries.append(entry) return entry def declare_pyfunction(self, name, pos, allow_redefine=False, visibility='extern'): - c_source,c_binding,python_binding = self._WTK_setup(name, None, visibility) - return self.WTK_declare_pyfunction(c_source, c_binding, python_binding, allow_redefine, pos) + binding = self._WTK_setup(name, None, visibility) + return self.WTK_declare_pyfunction(binding, allow_redefine, pos) - def WTK_declare_pyfunction(self, c_source, c_binding, python_binding, + def WTK_declare_pyfunction(self, binding, allow_redefine = False, pos = None): # Add an entry for a Python function. - entry = self.lookup_here(python_binding.name) + entry = self.lookup_here(binding.name) if not allow_redefine or Options.disable_function_redefinition: return self.WTK__declare_pyfunction( - c_source, c_binding, python_binding, entry = entry, pos = pos) + binding, entry = entry, pos = pos) if entry: if entry.type.is_unspecified: entry.type = py_object_type elif entry.type is not py_object_type: return self.WTK__declare_pyfunction( - c_source, c_binding, python_binding, entry = entry, + binding, entry = entry, pos = pos) else: # declare entry stub self.WTK_declare_var( - c_source, c_binding, python_binding, py_object_type, pos = pos) - tmp_c_source,tmp_c_binding,tmp_python_binding = self._WTK_setup(None, cname=python_binding.name, visibility='private') - entry = self.WTK_declare_var(tmp_c_source, tmp_c_binding, tmp_python_binding, py_object_type, pos = pos) - entry.python_binding.name = EncodedString(python_binding.name) - entry.qualified_name = self.qualify_name(python_binding.name) + binding, py_object_type, pos = pos) + entry = self.WTK_declare_var(Binding(name=None, c_name=binding.name), + py_object_type, pos = pos) + entry.name = EncodedString(binding.name) + entry.qualified_name = self.qualify_name(binding.name) entry.signature = pyfunction_signature entry.is_anonymous = True return entry def declare_lambda_function(self, func_cname, pos): - c_source,c_binding,python_binding = self._WTK_setup(None, func_cname, 'private') - return self.WTK_declare_lambda_function(c_source, c_binding, python_binding, pos) + binding = self._WTK_setup(None, func_cname, 'private') + return self.WTK_declare_lambda_function(binding, pos) - def WTK_declare_lambda_function(self, c_source, c_binding, python_binding, + def WTK_declare_lambda_function(self, binding, pos = None): # Add an entry for an anonymous Python function. - entry = self.WTK_declare_var(c_source, c_binding, python_binding, py_object_type, pos = pos) - entry.python_binding.name = EncodedString(c_binding.name) - entry.func_cname = c_binding.name + entry = self.WTK_declare_var(binding, py_object_type, pos = pos) + entry.name = EncodedString(binding.c_name) + entry.func_cname = binding.c_name entry.signature = pyfunction_signature entry.is_anonymous = True return entry @@ -720,61 +699,62 @@ class Scope(object): def declare_cfunction(self, name, type, pos, cname = None, visibility = 'private', defining = 0, api = 0, in_pxd = 0, modifiers = (), utility_code = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - c_binding.api = api + binding = self._WTK_setup(name, cname, visibility) + binding.api = api return self.WTK_declare_cfunction( - c_source, c_binding, python_binding, + binding, pos, type, defining, in_pxd, modifiers, utility_code) def WTK_declare_cfunction( - self, c_source, c_binding, python_binding, pos, type, defining = 0, + self, binding, pos, type, defining = 0, in_pxd = 0, modifiers = (), utility_code = None): # Add an entry for a C function. - if not c_binding.name: - if c_binding.api or c_binding.visibility != 'private': - c_binding.name = python_binding.name + if not binding.c_name: + if binding.api or binding.c_visibility != 'private': + binding.c_name = binding.name else: - c_binding.name = self.mangle( - Naming.func_prefix, python_binding.name) - entry = self.lookup_here(python_binding.name) + binding.c_name = self.mangle( + Naming.func_prefix, binding.name) + entry = self.lookup_here(binding.name) if entry: vis_diff = self.WTK__check_previous_visibility( - entry, c_source, c_binding, python_binding) + entry, binding) if vis_diff: warning(pos, "Function '%s' previously declared as '%s'" % ( - python_binding.name, vis_diff), 1) + binding.name, vis_diff), 1) if not entry.type.same_as(type): - if c_source.extern and entry.c_source.extern: + if binding.extern and entry.extern: can_override = False if self.is_cpp(): can_override = True - elif c_binding.name: + elif binding.c_name: # if all alternatives have different cnames, # it's safe to allow signature overrides for alt_entry in entry.all_alternatives(): - if (not alt_entry.c_binding.name or - c_binding.name == alt_entry.c_binding.name): + if (not alt_entry.c_name or + binding.c_name == alt_entry.c_name): break # cname not unique! else: can_override = True if can_override: - temp = self.WTK_add_cfunction(c_source, c_binding, python_binding, pos, type, modifiers) + temp = self.WTK_add_cfunction(binding, pos, type, modifiers) temp.overloaded_alternatives = entry.all_alternatives() entry = temp else: warning(pos, "Function signature does not match previous declaration", 1) entry.type = type else: + print 'EE', entry, binding.extern, entry.extern error(pos, "Function signature does not match previous declaration") else: - entry = self.WTK_add_cfunction(c_source, c_binding, python_binding, pos, type, modifiers) - entry.func_cname = c_binding.name - if in_pxd and not c_source.extern: + entry = self.WTK_add_cfunction(binding, pos, type, modifiers) + entry.func_cname = binding.c_name + if in_pxd and not binding.extern: entry.defined_in_pxd = 1 - if not defining and not in_pxd and not c_source.extern: + if not defining and not in_pxd and not binding.extern: error(pos, "Non-extern C function '%s' declared but not defined" % - python_binding.name) + binding.name) if defining: entry.is_implemented = True if modifiers: @@ -783,13 +763,13 @@ class Scope(object): return entry def add_cfunction(self, name, type, pos, cname, visibility, modifiers): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - return self.WTK_add_cfunction(c_source, c_binding, python_binding, pos, type, modifiers) + binding = self._WTK_setup(name, cname, visibility) + return self.WTK_add_cfunction(binding, pos, type, modifiers) - def WTK_add_cfunction(self, c_source, c_binding, python_binding, pos, type, + def WTK_add_cfunction(self, binding, pos, type, modifiers = ()): # Add a C function entry without giving it a func_cname. - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos) + entry = self.WTK_declare(binding, type, pos) entry.is_cfunction = 1 if modifiers: entry.func_modifiers = modifiers @@ -835,8 +815,8 @@ class Scope(object): # variable if not found. entry = self.lookup_here(name) if not entry: - c_source,c_binding,python_binding = self._WTK_setup(name, None, 'private') - entry = self.WTK_declare_var(c_source, c_binding, python_binding, py_object_type) + binding = self._WTK_setup(name, None, 'private') + entry = self.WTK_declare_var(binding, py_object_type) return entry def lookup_type(self, name): @@ -891,11 +871,11 @@ class PreImportScope(Scope): Scope.__init__(self, Options.pre_import, None, None) def declare_builtin(self, name, pos): - c_source,c_binding,python_binding = self._WTK_setup(name, name, visibility='private') - return self.WTK_declare_builtin(c_source, c_binding, python_binding, pos) + binding = self._WTK_setup(name, name, visibility='private') + return self.WTK_declare_builtin(binding, pos) - def WTK_declare_builtin(self, c_source, c_binding, python_binding, pos): - entry = self.WTK_declare(c_source, c_binding, python_binding, py_object_type, pos) + def WTK_declare_builtin(self, binding, pos): + entry = self.WTK_declare(binding, py_object_type, pos) entry.is_variable = True entry.is_pyglobal = True return entry @@ -913,8 +893,8 @@ class BuiltinScope(Scope): for name, definition in self.builtin_entries.iteritems(): cname, type = definition - c_source,c_binding,python_binding = self._WTK_setup(name, cname, 'private') - self.WTK_declare_var(c_source, c_binding, python_binding, type) + binding = self._WTK_setup(name, cname, 'private') + self.WTK_declare_var(binding, type) def lookup(self, name, language_level=None): # 'language_level' is passed by ModuleScope @@ -924,39 +904,39 @@ class BuiltinScope(Scope): return Scope.lookup(self, name) def declare_builtin(self, name, pos): - c_source,c_binding,python_binding = self._WTK_setup(name, name, visibility='private') - return self.WTK_declare_builtin(c_source, c_binding, python_binding, pos) + binding = self._WTK_setup(name, name, visibility='private') + return self.WTK_declare_builtin(binding, pos) - def WTK_declare_builtin(self, c_source, c_binding, python_binding, pos): - if not hasattr(builtins, python_binding.name): + def WTK_declare_builtin(self, binding, pos): + if not hasattr(builtins, binding.name): if self.outer_scope is not None: return self.outer_scope.WTK_declare_builtin( - c_source, c_binding, python_binding, pos=pos) + binding, pos=pos) else: error(pos, "undeclared name not builtin: %s" % - python_binding.name) + binding.name) def declare_builtin_cfunction(self, name, type, cname, python_equiv = None, utility_code = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, 'extern') - return self.WTK_declare_builtin_cfunction(c_source, c_binding, python_binding, type, python_equiv, utility_code) + binding = self._WTK_setup(name, cname, 'extern') + return self.WTK_declare_builtin_cfunction(binding, type, python_equiv, utility_code) def WTK_declare_builtin_cfunction( - self, c_source, c_binding, python_binding, type, python_equiv = None, + self, binding, type, python_equiv = None, utility_code = None): # If python_equiv == "*", the Python equivalent has the same name # as the entry, otherwise it has the name specified by python_equiv. - python_binding.name = EncodedString(python_binding.name) + binding.name = EncodedString(binding.name) entry = self.WTK_declare_cfunction( - c_source, c_binding, python_binding, pos=None, type=type, + binding, pos=None, type=type, utility_code = utility_code) if python_equiv: if python_equiv == "*": - python_equiv = python_binding.name + python_equiv = binding.name else: python_equiv = EncodedString(python_equiv) - tmp_c_source,tmp_c_binding,tmp_python_binding = self._WTK_setup(python_equiv, python_equiv, 'private') - var_entry = WTK_Entry(tmp_c_source, tmp_c_binding, tmp_python_binding, py_object_type) + var_entry = WTK_Entry( + Binding(name=python_equiv, c_name=python_equiv), py_object_type) var_entry.is_variable = 1 var_entry.is_builtin = 1 var_entry.utility_code = utility_code @@ -964,25 +944,24 @@ class BuiltinScope(Scope): return entry def declare_builtin_type(self, name, cname, utility_code = None, objstruct_cname = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility='extern') - return self.WTK_declare_builtin_type(c_source, c_binding, python_binding, objstruct_cname, utility_code) + binding = self._WTK_setup(name, cname, visibility='extern') + return self.WTK_declare_builtin_type(binding, objstruct_cname, utility_code) - def WTK_declare_builtin_type(self, c_source, c_binding, python_binding, objstruct_cname = None, utility_code = None): - python_binding.name = EncodedString(python_binding.name) - type = PyrexTypes.BuiltinObjectType(python_binding.name, c_binding.name, objstruct_cname) + def WTK_declare_builtin_type(self, binding, objstruct_cname = None, utility_code = None): + binding.name = EncodedString(binding.name) + type = PyrexTypes.BuiltinObjectType(binding.name, binding.c_name, objstruct_cname) # WTK: TODO: visibility checking. CClassCcope visibility splitting - scope = CClassScope(python_binding.name, outer_scope=None, visibility='extern') + scope = CClassScope(binding.name, outer_scope=None, visibility='extern') scope.directives = {} - if python_binding.name == 'bool': + if binding.name == 'bool': scope.directives['final'] = True type.set_scope(scope) - self.type_names[python_binding.name] = 1 - entry = self.WTK_declare_type(c_source, c_binding, python_binding, type) + self.type_names[binding.name] = 1 + entry = self.WTK_declare_type(binding, type) entry.utility_code = utility_code - tmp_c_binding = c_binding.deepcopy() - tmp_c_binding.name = "((PyObject*)%s)" % entry.type.typeptr_cname - var_entry = WTK_Entry(c_source, tmp_c_binding, python_binding, + var_entry = WTK_Entry( + binding.deepcopy(c_name="((PyObject*)%s)" % entry.type.typeptr_cname), type = self.lookup('type').type, # make sure "type" is the first type declared... pos = entry.pos) var_entry.is_variable = 1 @@ -1099,35 +1078,34 @@ class ModuleScope(Scope): return self.outer_scope.lookup(name, language_level = self.context.language_level) def declare_builtin(self, name, pos): - c_source,c_binding,python_binding = self._WTK_setup(name, name, visibility='private') + binding = self._WTK_setup(name, name, visibility='private') # python visibility? - return self.WTK_declare_builtin(c_source, c_binding, python_binding, pos) + return self.WTK_declare_builtin(binding, pos) - def WTK_declare_builtin(self, c_source, c_binding, python_binding, pos): - if (not hasattr(builtins, python_binding.name) - and python_binding.name != 'xrange'): + def WTK_declare_builtin(self, binding, pos): + if (not hasattr(builtins, binding.name) + and binding.name != 'xrange'): # 'xrange' is special cased in Code.py if self.has_import_star: entry = self.WTK_declare_var( - c_source, c_binding, python_binding, py_object_type, pos = pos) + binding, py_object_type, pos = pos) return entry elif self.outer_scope is not None: return self.outer_scope.WTK_declare_builtin( - c_source, c_binding, python_binding, pos) + binding, pos) else: error(pos, "undeclared name not builtin: %s" % - python_binding.name) + binding.name) if Options.cache_builtins: for entry in self.cached_builtins: - if entry.python_binding.name == python_binding.name: + if entry.name == binding.name: return entry - tmp_c_source,tmp_c_binding,tmp_python_binding = self._WTK_setup(None, None, 'private') - entry = self.WTK_declare(tmp_c_source, tmp_c_binding, tmp_python_binding, py_object_type, pos) + entry = self.WTK_declare(Binding(), py_object_type, pos = pos) if Options.cache_builtins: entry.is_builtin = 1 entry.is_const = 1 - entry.python_binding.name = python_binding.name - entry.c_binding.name = Naming.builtin_prefix + python_binding.name + entry.name = binding.name + entry.c_name = Naming.builtin_prefix + binding.name self.cached_builtins.append(entry) self.undeclared_cached_builtins.append(entry) else: @@ -1174,11 +1152,11 @@ class ModuleScope(Scope): def WTK_add_imported_entry(self, entry, pos, as_name=None): if not as_name: - as_name = entry.python_binding.name + as_name = entry.name if entry not in self.entries: self.entries[as_name] = entry else: - warning(pos, "'%s' redeclared " % entry.python_binding.name, 0) + warning(pos, "'%s' redeclared " % entry.name, 0) def declare_module(self, name, scope, pos): return self.WTK_declare_module(scope, pos, as_name=name) @@ -1213,21 +1191,21 @@ class ModuleScope(Scope): def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = 0): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, pos = pos) + binding, type, is_cdef, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, pos = None): # Add an entry for a global variable. If it is a Python # object type, and not declared with cdef, it will live # in the module dictionary, otherwise it will be a C # global variable. entry = Scope.WTK_declare_var( - self, c_source, c_binding, python_binding, type, is_cdef, pos = pos) - if c_binding.visibility not in ('private', 'public'): + self, binding, type, is_cdef, pos = pos) + if binding.c_visibility not in ('private', 'public'): error(pos, "Module-level variable cannot be declared %s" % - c_binding.visibility) + binding.c_visibility) if not is_cdef: if type is unspecified_type: type = py_object_type @@ -1245,8 +1223,8 @@ class ModuleScope(Scope): def declare_global(self, name, pos): entry = self.lookup_here(name) if not entry: - c_source,c_binding,python_binding = self._WTK_setup(name, name, 'private') - self.WTK_declare_var(c_source, c_binding, python_binding, py_object_type, pos = pos) + binding = self._WTK_setup(name, name, 'private') + self.WTK_declare_var(binding, py_object_type, pos = pos) def use_utility_code(self, new_code): if new_code is not None: @@ -1256,22 +1234,22 @@ class ModuleScope(Scope): module_name = None, base_type = None, objstruct_cname = None, typeobj_cname = None, visibility = 'private', typedef_flag = 0, api = 0, buffer_defaults = None): - c_source,c_binding,python_binding = self._WTK_setup(name, objstruct_cname, visibility) - c_binding.api = api + binding = self._WTK_setup(name, objstruct_cname, visibility) + binding.api = api return self.WTK_declare_c_class( - c_source, c_binding, python_binding, objstruct_cname, None, base_type, defining, implementing, + binding, objstruct_cname, None, base_type, defining, implementing, module_name, typeobj_cname, typedef_flag, buffer_defaults, pos) def WTK_declare_c_class( - self, c_source, c_binding, python_binding, objstruct_cname = None, type=None, base_type=None, + self, binding, objstruct_cname = None, type=None, base_type=None, defining = 0, implementing = 0, module_name = None, typeobj_cname = None, typedef_flag = 0, buffer_defaults = None, pos = None): # If this is a non-extern typedef class, expose the typedef, but use # the non-typedef struct internally to avoid needing forward # declarations for anonymous structs. - if typedef_flag and not c_source.extern: - if c_binding.visibility != 'public': + if typedef_flag and not binding.extern: + if binding.c_visibility != 'public': warning(pos, "ctypedef only valid for public and extern classes", 2) objtypedef_cname = objstruct_cname typedef_flag = 0 @@ -1280,7 +1258,7 @@ class ModuleScope(Scope): # # Look for previous declaration as a type # - entry = self.lookup_here(python_binding.name) + entry = self.lookup_here(binding.name) if entry: type = entry.type if not (entry.is_type and type.is_extension_type): @@ -1299,26 +1277,26 @@ class ModuleScope(Scope): # if not entry: type = PyrexTypes.PyExtensionType( - python_binding.name, typedef_flag, base_type, c_source.extern) + binding.name, typedef_flag, base_type, binding.extern) type.pos = pos type.buffer_defaults = buffer_defaults if objtypedef_cname is not None: type.objtypedef_cname = objtypedef_cname - if c_source.extern: + if binding.extern: type.module_name = module_name else: type.module_name = self.qualified_name type.typeptr_cname = self.mangle( - Naming.typeptr_prefix, python_binding.name) + Naming.typeptr_prefix, binding.name) entry = self.WTK_declare_type( - c_source, c_binding, python_binding, type, defining = 0, pos = pos) + binding, type, defining = 0, pos = pos) entry.is_cclass = True if objstruct_cname: type.objstruct_cname = objstruct_cname - elif c_source.extern or c_binding.visibility != 'public': - c_binding.name = self.mangle( - Naming.objstruct_prefix, python_binding.name) - type.objstruct_cname = c_binding.name + elif binding.extern or binding.c_visibility != 'public': + binding.c_name = self.mangle( + Naming.objstruct_prefix, binding.name) + type.objstruct_cname = binding.c_name else: error(entry.pos, "Object name required for 'public' or 'extern' C class") @@ -1330,12 +1308,12 @@ class ModuleScope(Scope): if not type.scope: if defining or implementing: visibility = 'private' - if c_source.extern: + if binding.extern: visibility = 'extern' - elif c_binding.visibility != 'private': - visibility = c_binding.visibility + elif binding.c_visibility != 'private': + visibility = binding.c_visibility scope = CClassScope( - name = python_binding.name, + name = binding.name, outer_scope = self, visibility = visibility) # WTK: scope visiblity? if base_type and base_type.scope: @@ -1347,10 +1325,10 @@ class ModuleScope(Scope): else: if defining and type.scope.defined: error(pos, "C class '%s' already defined" % - python_binding.name) + binding.name) elif implementing and type.scope.implemented: error(pos, "C class '%s' already implemented" % - python_binding.name) + binding.name) # # Fill in options, checking for compatibility with any previous declaration # @@ -1359,7 +1337,7 @@ class ModuleScope(Scope): if implementing: # So that filenames in runtime exceptions refer to entry.pos = pos # the .pyx file and not the .pxd file self.WTK_check_previous_visibility( - entry, c_source, c_binding, python_binding, type_name='Class', + entry, binding, type_name='Class', pos = pos) if objstruct_cname: if (type.objstruct_cname and @@ -1406,9 +1384,9 @@ class ModuleScope(Scope): if type.vtabslot_cname: #print "...allocating other vtable related cnames" ### type.vtabstruct_cname = self.mangle( - Naming.vtabstruct_prefix, entry.python_binding.name) + Naming.vtabstruct_prefix, entry.name) type.vtabptr_cname = self.mangle( - Naming.vtabptr_prefix, entry.python_binding.name) + Naming.vtabptr_prefix, entry.name) def check_c_classes_pxd(self): # Performs post-analysis checking and finishing up of extension types @@ -1425,16 +1403,16 @@ class ModuleScope(Scope): # Check defined if not entry.type.scope: error(entry.pos, "C class '%s' is declared but not defined" - % entry.python_binding.name) + % entry.name) def check_c_class(self, entry): type = entry.type - name = entry.python_binding.name + name = entry.name # Check defined if not type.scope: error(entry.pos, "C class '%s' is declared but not defined" % name) # Generate typeobj_cname - if not entry.c_source.extern and not type.typeobj_cname: + if not entry.extern and not type.typeobj_cname: type.typeobj_cname = self.mangle(Naming.typeobj_prefix, name) ## Generate typeptr_cname #type.typeptr_cname = self.mangle(Naming.typeptr_prefix, name) @@ -1443,12 +1421,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.python_binding.name) + method_entry.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.python_binding.name) + Naming.vtable_prefix, entry.name) def check_c_classes(self): # Performs post-analysis checking and finishing up of extension types @@ -1469,12 +1447,12 @@ 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.python_binding.name, entry)) + print("...entry %s %s" % (entry.name, entry)) print("......type = ", entry.type) - print("......extern = ", entry.c_source.extern) - print("......c_binding.visibility = ", - entry.c_binding.visibility) - print("......python_binding.visibility = ", + print("......extern = ", entry.extern) + print("......binding.c_visibility = ", + entry.c_visibility) + print("......binding.visibility = ", entry.python.binding.visibility) self.check_c_class(entry) @@ -1485,7 +1463,7 @@ class ModuleScope(Scope): if entry.is_cfunction: if (entry.defined_in_pxd and entry.scope is self - and not entry.c_source.extern + and not entry.extern and not entry.in_cinclude and not entry.is_implemented): error(entry.pos, "Non-extern C function '%s' declared but not defined" % name) @@ -1498,7 +1476,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.python_binding.name, + var_entry = Entry(name = entry.name, type = Builtin.type_type, pos = entry.pos, cname = "((PyObject*)%s)" % entry.type.typeptr_cname) @@ -1525,36 +1503,36 @@ class LocalScope(Scope): return prefix + name def declare_arg(self, name, type, pos): - c_source,c_binding,python_binding = self._WTK_setup(name, None, 'private') - c_binding.name = self.mangle(Naming.var_prefix, python_binding.name) + binding = self._WTK_setup(name, None, 'private') + binding.c_name = self.mangle(Naming.var_prefix, binding.name) return self.WTK_declare_arg( - c_source, c_binding, python_binding, type, pos = pos) + binding, type, pos = pos) - def WTK_declare_arg(self, c_source, c_binding, python_binding, type, pos = None): + def WTK_declare_arg(self, binding, type, pos = None): # Add an entry for an argument of a function. - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos = pos) + entry = self.WTK_declare(binding, type, pos = pos) entry.is_variable = 1 if type.is_pyobject: entry.init = "0" entry.is_arg = 1 #entry.borrowed = 1 # Not using borrowed arg refs for now self.arg_entries.append(entry) - self.control_flow.set_state((), (python_binding.name, 'source'), 'arg') + self.control_flow.set_state((), (binding.name, 'source'), 'arg') return entry def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = 0): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, pos = pos) + binding, type, is_cdef, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, pos = None): # Add an entry for a local variable. - if c_binding.visibility != 'private': #visibility in ('public', 'readonly'): - error(pos, "Local variable cannot be declared %s" % c_binding.visibility) + if binding.c_visibility != 'private': #visibility in ('public', 'readonly'): + error(pos, "Local variable cannot be declared %s" % binding.c_visibility) entry = Scope.WTK_declare_var( - self, c_source, c_binding, python_binding, type, is_cdef, + self, binding, type, is_cdef, pos = pos) if type.is_pyobject and not Options.init_local_none: entry.init = "0" @@ -1584,7 +1562,7 @@ class LocalScope(Scope): entry.in_closure = True # Would it be better to declare_var here? inner_entry = Entry( - entry.python_binding.name, entry.c_binding.name, + entry.name, entry.c_name, entry.type, entry.pos) inner_entry.scope = self inner_entry.is_variable = True @@ -1597,18 +1575,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.c_binding.name + cname = entry.outer_entry.c_name if self.is_passthrough: - entry.c_binding.name = cname + entry.c_name = cname else: if cname.startswith(Naming.cur_scope_cname): cname = cname[len(Naming.cur_scope_cname)+2:] - entry.c_binding.name = "%s->%s" % ( + entry.c_name = "%s->%s" % ( outer_scope_cname, cname) elif entry.in_closure: - entry.original_cname = entry.c_binding.name - entry.c_binding.name = "%s->%s" % ( - Naming.cur_scope_cname, entry.c_binding.name) + entry.original_cname = entry.c_name + entry.c_name = "%s->%s" % ( + Naming.cur_scope_cname, entry.c_name) class GeneratorExpressionScope(Scope): """Scope for generator expressions and comprehensions. As opposed @@ -1626,26 +1604,26 @@ class GeneratorExpressionScope(Scope): def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = True): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, pos = pos) + binding, type, is_cdef, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, pos = None): if type is unspecified_type: # if the outer scope defines a type for this variable, inherit it - outer_entry = self.outer_scope.lookup(python_binding.name) + outer_entry = self.outer_scope.lookup(binding.name) if outer_entry and outer_entry.is_variable: type = outer_entry.type # may still be 'unspecified_type' ! # the parent scope needs to generate code for the variable, but # this scope must hold its name exclusively - c_binding.name = '%s%s' % (self.genexp_prefix, self.parent_scope.mangle( - Naming.var_prefix, python_binding.name)) + binding.c_name = '%s%s' % (self.genexp_prefix, self.parent_scope.mangle( + Naming.var_prefix, binding.name)) entry = self.WTK_declare( - c_source, c_binding, python_binding, type, pos = pos) + binding, type, pos = pos) entry.is_variable = 1 self.var_entries.append(entry) - self.entries[python_binding.name] = entry + self.entries[binding.name] = entry return entry @@ -1667,13 +1645,13 @@ class ClosureScope(LocalScope): # return "%s->%s" % (self.closure_cname, name) def declare_pyfunction(self, name, pos, allow_redefine=False): - c_source,c_binding,python_binding = self._WTK_setup(name, name, visibility='private') - return self.WTK_declare_pyfunction(c_source, c_binding, python_binding, allow_redefine, pos) + binding = self._WTK_setup(name, name, visibility='private') + return self.WTK_declare_pyfunction(binding, allow_redefine, pos) - def WTK_declare_pyfunction(self, c_source, c_binding, python_binding, + def WTK_declare_pyfunction(self, binding, allow_redefine=False, pos=None): return LocalScope.WTK_declare_pyfunction( - self, c_source, c_binding, python_binding, allow_redefine, pos) + self, binding, allow_redefine, pos) class StructOrUnionScope(Scope): # Namespace of a C struct or union. @@ -1683,20 +1661,20 @@ class StructOrUnionScope(Scope): def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = 0, allow_pyobject = 0): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, allow_pyobject, pos = pos) + binding, type, is_cdef, allow_pyobject, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, allow_pyobject = 0, pos = None): # Add an entry for an attribute. - if not c_binding.name: - c_binding.name = python_binding.name - if c_binding.visibility == 'private': - c_binding.name = c_safe_identifier(c_binding.name) + if not binding.c_name: + binding.c_name = binding.name + if binding.c_visibility == 'private': + binding.c_name = c_safe_identifier(binding.c_name) if type.is_cfunction: type = PyrexTypes.CPtrType(type) - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos) + entry = self.WTK_declare(binding, type, pos) entry.is_variable = 1 self.var_entries.append(entry) if type.is_pyobject and not allow_pyobject: @@ -1707,16 +1685,16 @@ class StructOrUnionScope(Scope): def declare_cfunction(self, name, type, pos, cname = None, visibility = 'private', defining = 0, api = 0, in_pxd = 0, modifiers = (), utility_code = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - c_binding.api = api + binding = self._WTK_setup(name, cname, visibility) + binding.api = api return self.WTK_declare_cfunction( - c_source, c_binding, python_binding, + binding, pos, type, defining, in_pxd, modifiers, utility_code) def WTK_declare_cfunction( - self, c_source, c_binding, python_binding, pos, type, defining = 0, + self, binding, pos, type, defining = 0, in_pxd = 0, modifiers = (), utility_code = None): - return self.WTK_declare_var(c_source, c_binding, python_binding, type, pos=pos) + return self.WTK_declare_var(binding, type, pos=pos) @@ -1763,17 +1741,17 @@ class PyClassScope(ClassScope): def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = 0): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, pos = pos) + binding, type, is_cdef, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, pos = None): if type is unspecified_type: type = py_object_type # Add an entry for a class attribute. entry = Scope.WTK_declare_var( - self, c_source, c_binding, python_binding, type, is_cdef, + self, binding, type, is_cdef, pos = pos) entry.is_pyglobal = 1 entry.is_pyclass_attr = 1 @@ -1820,13 +1798,13 @@ class CClassScope(ClassScope): def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = 0): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) if visibility == 'private': - python_binding.visibility = 'private' + binding.visibility = 'private' return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, pos = pos) + binding, type, is_cdef, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, pos = None): if is_cdef: # Add an entry for an attribute. @@ -1834,32 +1812,32 @@ class CClassScope(ClassScope): error(pos, "C attributes cannot be added in implementation part of" " extension type defined in a pxd") - if get_special_method_signature(python_binding.name): + if get_special_method_signature(binding.name): error(pos, "The name '%s' is reserved for a special method." - % python_binding.name) - if not c_binding.name: - c_binding.name = python_binding.name - if c_binding.visibility == 'private': - c_binding.name = c_safe_identifier(c_binding.name) - if type.is_cpp_class and not c_source.extern: + % binding.name) + if not binding.c_name: + binding.c_name = binding.name + if binding.c_visibility == 'private': + binding.c_name = c_safe_identifier(binding.c_name) + if type.is_cpp_class and not binding.extern: error(pos, "C++ classes not allowed as members of an extension type, use a pointer or reference instead") - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos) + entry = self.WTK_declare(binding, type, pos) entry.is_variable = 1 self.var_entries.append(entry) if type.is_pyobject: self.has_pyobject_attrs = 1 - if python_binding.visibility not in ('private', 'public', 'readonly'): + if binding.visibility not in ('private', 'public', 'readonly'): error(pos, "Attribute of extension type cannot be declared %s" % - python_binding.visibility) - if python_binding.visibility in ('public', 'readonly'): - if python_binding.name == "__weakref__": + binding.visibility) + if binding.visibility in ('public', 'readonly'): + if binding.name == "__weakref__": error(pos, "Special attribute __weakref__ cannot be exposed to Python") if not type.is_pyobject: - #print 'XXX', python_binding.name, c_source.extern, c_binding.visibility, python_binding.visibility, type.create_to_py_utility_code(self), type.__class__ ####### XXXXX BUG! (cimportfrom_T248) + #print 'XXX', binding.name, binding.extern, binding.c_visibility, binding.visibility, type.create_to_py_utility_code(self), type.__class__ ####### XXXXX BUG! (cimportfrom_T248) if not type.create_to_py_utility_code(self): - #print 'XXX', python_binding.name, c_source.extern, c_binding.visibility, python_binding.visibility ####### XXXXX BUG! (cimportfrom_T248) + #print 'XXX', binding.name, binding.extern, binding.c_visibility, binding.visibility ####### XXXXX BUG! (cimportfrom_T248) error(pos, "C attribute of type '%s' cannot be accessed from Python" % type) return entry @@ -1868,7 +1846,7 @@ class CClassScope(ClassScope): type = py_object_type # Add an entry for a class attribute. entry = Scope.WTK_declare_var( - self, c_source, c_binding, python_binding, type, is_cdef, pos = pos) + self, binding, type, is_cdef, pos = pos) entry.is_member = 1 entry.is_pyglobal = 1 # xxx: is_pyglobal changes behaviour in so many places that # I keep it in for now. is_member should be enough @@ -1877,25 +1855,25 @@ class CClassScope(ClassScope): return entry def declare_pyfunction(self, name, pos, allow_redefine=False): - c_source,c_binding,python_binding = self._WTK_setup(name, name, 'extern') - return self.WTK_declare_pyfunction(c_source, c_binding, python_binding, allow_redefine, pos) + binding = self._WTK_setup(name, name, 'extern') + return self.WTK_declare_pyfunction(binding, allow_redefine, pos) - def WTK_declare_pyfunction(self, c_source, c_binding, python_binding, + def WTK_declare_pyfunction(self, binding, allow_redefine = False, pos = None): # Add an entry for a method. - if python_binding.name in ('__eq__', '__ne__', '__lt__', '__gt__', + if binding.name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'): error(pos, "Special method %s must be implemented via __richcmp__" - % python_binding.name) - if python_binding.name == "__new__": + % binding.name) + if binding.name == "__new__": error(pos, "__new__ method of extension type will change semantics " "in a future version of Pyrex and Cython. Use __cinit__ instead.") - name = python_binding.name + name = binding.name entry = self.declare_var(name, py_object_type, pos, visibility='extern') special_sig = get_special_method_signature(name) #entry = self.WTK_declare_var( - # c_source, c_binding, python_binding, py_object_type, pos = pos) - #special_sig = get_special_method_signature(python_binding.name) + # binding, py_object_type, pos = pos) + #special_sig = get_special_method_signature(binding.name) if special_sig: # Special methods get put in the method table with a particular # signature declared in advance. @@ -1916,38 +1894,38 @@ class CClassScope(ClassScope): def declare_cfunction(self, name, type, pos, cname = None, visibility = 'private', defining = 0, api = 0, in_pxd = 0, modifiers = (), utility_code = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - c_binding.api = api + binding = self._WTK_setup(name, cname, visibility) + binding.api = api return self.WTK_declare_cfunction( - c_source, c_binding, python_binding, + binding, pos, type, defining, in_pxd, modifiers, utility_code) def WTK_declare_cfunction( - self, c_source, c_binding, python_binding, pos, type, defining = 0, + self, binding, pos, type, defining = 0, in_pxd = 0, modifiers = (), utility_code = None): - if get_special_method_signature(python_binding.name): + if get_special_method_signature(binding.name): error(pos, "Special methods must be declared with 'def', not 'cdef'") args = type.args if not args: error(pos, "C method has no self argument") elif not self.parent_type.assignable_from(args[0].type): error(pos, "Self argument (%s) of C method '%s' does not match parent type (%s)" % - (args[0].type, python_binding.name, self.parent_type)) - entry = self.lookup_here(python_binding.name) + (args[0].type, binding.name, self.parent_type)) + entry = self.lookup_here(binding.name) if entry: if not entry.is_cfunction: - warning(pos, "'%s' redeclared " % python_binding.name, 0) + warning(pos, "'%s' redeclared " % binding.name, 0) else: if defining and entry.func_cname: - error(pos, "'%s' already defined" % python_binding.name) + error(pos, "'%s' already defined" % binding.name) #print "CClassScope.declare_cfunction: checking signature" ### if type.same_c_signature_as(entry.type, as_cmethod = 1) and type.nogil == entry.type.nogil: pass elif type.compatible_signature_with(entry.type, as_cmethod = 1) and type.nogil == entry.type.nogil: - c_source.extern = 0 - c_binding.visibility = 'ignore' - python_binding.visibility = 'public' - entry = self.WTK_add_cfunction(c_source, c_binding, python_binding, pos, type, modifiers) + binding.extern = 0 + binding.c_visibility = 'ignore' + binding.visibility = 'public' + entry = self.WTK_add_cfunction(binding, pos, type, modifiers) defining = 1 else: error(pos, "Signature not compatible with previous declaration") @@ -1956,45 +1934,45 @@ class CClassScope(ClassScope): if self.defined: error(pos, "C method '%s' not previously declared in definition part of" - " extension type" % python_binding.name) - if not c_binding.name: - c_binding.name = python_binding.name - entry = self.WTK_add_cfunction(c_source, c_binding, python_binding, pos, type, modifiers) + " extension type" % binding.name) + if not binding.c_name: + binding.c_name = binding.name + entry = self.WTK_add_cfunction(binding, pos, type, modifiers) if defining: - entry.func_cname = self.mangle(Naming.func_prefix, python_binding.name) + entry.func_cname = self.mangle(Naming.func_prefix, binding.name) entry.utility_code = utility_code return entry def add_cfunction(self, name, type, pos, cname, visibility, modifiers): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - return self.WTK_add_cfunction(c_source, c_binding, python_binding, pos, type, modifiers) + binding = self._WTK_setup(name, cname, visibility) + return self.WTK_add_cfunction(binding, pos, type, modifiers) - def WTK_add_cfunction(self, c_source, c_binding, python_binding, pos, type, + def WTK_add_cfunction(self, binding, pos, type, modifiers = ()): # Add a C function entry without giving it a func_cname. - prev_entry = self.lookup_here(python_binding.name) - entry = ClassScope.WTK_add_cfunction(self, c_source, c_binding, python_binding, pos, type, modifiers) + prev_entry = self.lookup_here(binding.name) + entry = ClassScope.WTK_add_cfunction(self, binding, pos, type, modifiers) entry.is_cmethod = 1 entry.prev_entry = prev_entry return entry def declare_builtin_cfunction(self, name, type, cname, utility_code = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, 'extern') - return self.WTK_declare_builtin_cfunction(c_source, c_binding, python_binding, type, utility_code=utility_code) + binding = self._WTK_setup(name, cname, 'extern') + return self.WTK_declare_builtin_cfunction(binding, type, utility_code=utility_code) def WTK_declare_builtin_cfunction( - self, c_source, c_binding, python_binding, type, python_equiv = None, + self, binding, type, python_equiv = None, utility_code = None): # overridden methods of builtin types still have their Python # equivalent that must be accessible to support bound methods - python_binding.name = EncodedString(python_binding.name) - #entry = self.declare_cfunction(python_binding.name, type, None, c_binding.name, visibility='extern', + binding.name = EncodedString(binding.name) + #entry = self.declare_cfunction(binding.name, type, None, binding.c_name, visibility='extern', # utility_code = utility_code) entry = self.WTK_declare_cfunction( - c_source, c_binding, python_binding, pos=None, type=type, + binding, pos=None, type=type, utility_code = utility_code) # WTK: need all declare_cfunction-s wrapped - tmp_c_source,tmp_c_binding,tmp_python_binding = self._WTK_setup(python_binding.name, python_binding.name, 'private') - var_entry = WTK_Entry(tmp_c_source, tmp_c_binding, tmp_python_binding, py_object_type) + var_entry = WTK_Entry( + Binding(name=binding.name, c_name=binding.name), py_object_type) var_entry.is_variable = 1 var_entry.is_builtin = 1 var_entry.utility_code = utility_code @@ -2002,18 +1980,18 @@ class CClassScope(ClassScope): return entry def declare_property(self, name, doc, pos): - c_source,c_binding,python_binding = self._WTK_setup(name, name, 'private') - return self.WTK_declare_property(c_source, c_binding, python_binding, doc, pos = pos) + binding = self._WTK_setup(name, name, 'private') + return self.WTK_declare_property(binding, doc, pos = pos) def WTK_declare_property( - self, c_source, c_binding, python_binding, doc, pos = None): - entry = self.lookup_here(python_binding.name) + self, binding, doc, pos = None): + entry = self.lookup_here(binding.name) if entry is None: - entry = self.WTK_declare(c_source, c_binding, python_binding, py_object_type, pos = pos) + entry = self.WTK_declare(binding, py_object_type, pos = pos) entry.is_property = 1 entry.doc = doc # WTK: TODO: adjust PropertyScope attributes - entry.scope = PropertyScope(python_binding.name, + entry.scope = PropertyScope(binding.name, outer_scope = self.global_scope(), parent_scope = self) entry.scope.parent_type = self.parent_type self.property_entries.append(entry) @@ -2024,24 +2002,24 @@ 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.c_binding.name) + return "%s.%s" % (Naming.obj_base_cname, base_entry.c_name) for base_entry in \ base_scope.inherited_var_entries + base_scope.var_entries: entry = self.declare( - base_entry.python_binding.name, - adapt(base_entry.c_binding.name), + base_entry.name, + adapt(base_entry.c_name), base_entry.type, None, 'private') entry.is_variable = 1 self.inherited_var_entries.append(entry) for base_entry in base_scope.cfunc_entries: visibility = 'private' - if base_entry.c_source.extern: + if base_entry.extern: visibility = 'extern' - elif base_entry.c_binding.visibility != 'private': - visibility = base_entry.c_binding.visibility + elif base_entry.c_visibility != 'private': + visibility = base_entry.c_visibility entry = self.add_cfunction( - base_entry.python_binding.name, base_entry.type, - base_entry.pos, adapt(base_entry.c_binding.name), + base_entry.name, base_entry.type, + base_entry.pos, adapt(base_entry.c_name), visibility, base_entry.func_modifiers) entry.is_inherited = 1 @@ -2060,18 +2038,18 @@ class CppClassScope(Scope): def declare_var(self, name, type, pos, cname = None, visibility = 'extern', is_cdef = 0, allow_pyobject = 0): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) + binding = self._WTK_setup(name, cname, visibility) return self.WTK_declare_var( - c_source, c_binding, python_binding, type, is_cdef, allow_pyobject, pos = pos) + binding, type, is_cdef, allow_pyobject, pos = pos) - def WTK_declare_var(self, c_source, c_binding, python_binding, type, + def WTK_declare_var(self, binding, type, is_cdef = 0, allow_pyobject = 0, pos = None): # Add an entry for an attribute. - if not c_binding.name: - c_binding.name = python_binding.name + if not binding.c_name: + binding.c_name = binding.name if type.is_cfunction: type = PyrexTypes.CPtrType(type) - entry = self.WTK_declare(c_source, c_binding, python_binding, type, pos) + entry = self.WTK_declare(binding, type, pos) entry.is_variable = 1 self.var_entries.append(entry) if type.is_pyobject and not allow_pyobject: @@ -2109,21 +2087,21 @@ class CppClassScope(Scope): def declare_cfunction(self, name, type, pos, cname = None, visibility = 'extern', defining = 0, api = 0, in_pxd = 0, modifiers = (), utility_code = None): - c_source,c_binding,python_binding = self._WTK_setup(name, cname, visibility) - c_binding.api = api + binding = self._WTK_setup(name, cname, visibility) + binding.api = api return self.WTK_declare_cfunction( - c_source, c_binding, python_binding, + binding, pos, type, defining, in_pxd, modifiers, utility_code) def WTK_declare_cfunction( - self, c_source, c_binding, python_binding, pos, type, defining = 0, + self, binding, pos, type, defining = 0, in_pxd = 0, modifiers = (), utility_code = None): - if python_binding.name == self.name.split('::')[-1] and c_binding.name is None: + if binding.name == self.name.split('::')[-1] and binding.c_name is None: self.check_base_default_constructor(pos) - python_binding.name = '' + binding.name = '' type.return_type = self.lookup(self.name).type - prev_entry = self.lookup_here(python_binding.name) - entry = self.WTK_declare_var(c_source, c_binding, python_binding, type, pos = pos) + prev_entry = self.lookup_here(binding.name) + entry = self.WTK_declare_var(binding, type, pos = pos) if prev_entry: entry.overloaded_alternatives = prev_entry.all_alternatives() entry.utility_code = utility_code @@ -2136,25 +2114,25 @@ class CppClassScope(Scope): for base_entry in \ base_scope.inherited_var_entries + base_scope.var_entries: #contructor is not inherited - if base_entry.python_binding.name == "": + if base_entry.name == "": continue - #print base_entry.python_binding.name, self.entries - if base_entry.python_binding.name in self.entries: - base_entry.python_binding.name + #print base_entry.name, self.entries + if base_entry.name in self.entries: + base_entry.name entry = self.declare( - base_entry.python_binding.name, base_entry.c_binding.name, + base_entry.name, base_entry.c_name, base_entry.type, None, 'extern') entry.is_variable = 1 self.inherited_var_entries.append(entry) for base_entry in base_scope.cfunc_entries: visibility = 'private' - if base_entry.c_source.extern: + if base_entry.extern: visibility = 'extern' - elif base_entry.c_binding.visibility != 'private': - visibility = base_entry.c_binding.visibility + elif base_entry.c_visibility != 'private': + visibility = base_entry.c_visibility entry = self.declare_cfunction( - base_entry.python_binding.name, base_entry.type, - base_entry.pos, base_entry.c_binding.name, + base_entry.name, base_entry.type, + base_entry.pos, base_entry.c_name, visibility, base_entry.func_modifiers, utility_code = base_entry.utility_code) entry.is_inherited = 1 @@ -2163,16 +2141,22 @@ class CppClassScope(Scope): scope = CppClassScope(self.name, self.outer_scope) for entry in self.entries.values(): if entry.is_type: + binding = Binding() + binding.pull(entry) scope.WTK_declare_type( - entry.c_source, entry.c_binding, entry.python_binding, + binding, type = entry.type.specialize(values), pos = entry.pos) else: +# binding = Binding() +# binding.pull(entry) # scope.WTK_declare_var( -# entry.c_source, entry.c_binding, entry.python_binding, +# binding, # type = entry.type.specialize(values), pos = entry.pos) - for e in entry.all_alternatives(): + for e in entry.all_alternatives(): + binding = Binding() + binding.pull(e) scope.WTK_declare_cfunction( - e.c_source, e.c_binding, e.python_binding, + binding, type = e.type.specialize(values), utility_code = e.utility_code, pos = e.pos) return scope @@ -2189,15 +2173,15 @@ class PropertyScope(Scope): is_property_scope = 1 def declare_pyfunction(self, name, pos, allow_redefine=False): - c_source,c_binding,python_binding = self._WTK_setup(name, name, visibility='private') - return self.WTK_declare_pyfunction(c_source, c_binding, python_binding, allow_redefine, pos = pos) + binding = self._WTK_setup(name, name, visibility='private') + return self.WTK_declare_pyfunction(binding, allow_redefine, pos = pos) - def WTK_declare_pyfunction(self, c_source, c_binding, python_binding, + def WTK_declare_pyfunction(self, binding, allow_redefine=False, pos=None): # Add an entry for a method. - signature = get_property_accessor_signature(python_binding.name) + signature = get_property_accessor_signature(binding.name) if signature: - entry = self.WTK_declare(c_source, c_binding, python_binding, py_object_type, pos = pos) + entry = self.WTK_declare(binding, py_object_type, pos = pos) entry.is_special = 1 entry.signature = signature return entry diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index 7a96883e..834fbe1c 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -287,7 +287,7 @@ class GCDependentSlot(InternalMethodSlot): parent_type_scope = scope.parent_type.base_type.scope if scope.parent_scope is parent_type_scope.parent_scope: entry = scope.parent_scope.lookup_here(scope.parent_type.base_type.name) - if not entry.c_source.extern: + if not entry.extern: return self.slot_code(parent_type_scope) return InternalMethodSlot.slot_code(self, scope) @@ -309,7 +309,7 @@ class ConstructorSlot(InternalMethodSlot): parent_type_scope = scope.parent_type.base_type.scope if scope.parent_scope is parent_type_scope.parent_scope: entry = scope.parent_scope.lookup_here(scope.parent_type.base_type.name) - if not entry.c_source.extern: + if not entry.extern: return self.slot_code(parent_type_scope) return InternalMethodSlot.slot_code(self, scope) @@ -468,7 +468,7 @@ def get_base_slot_function(scope, slot): parent_slot = slot.slot_code(base_type.scope) if parent_slot != '0': entry = scope.parent_scope.lookup_here(scope.parent_type.base_type.name) - if not entry.c_source.extern: + if not entry.extern: return parent_slot return None -- 2.26.2