From: Robert Bradshaw Date: Wed, 3 Feb 2010 22:45:28 +0000 (-0800) Subject: Use cython.operator for operators. X-Git-Tag: 0.13.beta0~353^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=437447118d47035c3680403e7bdec35952faae1e;p=cython.git Use cython.operator for operators. --- diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 16ee6de8..bcd18cb6 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -325,12 +325,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): """ unop_method_nodes = { 'typeof': TypeofNode, + + 'operator.address': AmpersandNode, + 'operator.dereference': DereferenceNode, + 'operator.preincrement' : inc_dec_constructor(True, '++'), + 'operator.predecrement' : inc_dec_constructor(True, '--'), + 'operator.postincrement': inc_dec_constructor(False, '++'), + 'operator.postdecrement': inc_dec_constructor(False, '--'), + + # For backwards compatability. 'address': AmpersandNode, - 'dereference': DereferenceNode, - 'preincrement' : inc_dec_constructor(True, '++'), - 'predecrement' : inc_dec_constructor(True, '--'), - 'postincrement': inc_dec_constructor(False, '++'), - 'postdecrement': inc_dec_constructor(False, '--'), } special_methods = set(['declare', 'union', 'struct', 'typedef', 'sizeof', 'cast', 'pointer', 'compiled', 'NULL'] @@ -379,10 +383,9 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): self.cython_module_names.add(modname) elif node.module_name.startswith(u"cython."): if node.as_name: - modname = node.as_name + self.directive_names[node.as_name] = node.module_name[7:] else: - modname = u"cython" - self.directive_names[modname] = node.module_name[7:] + self.cython_module_names.add(u"cython") else: return node @@ -393,6 +396,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): elif node.module_name == u"cython": is_cython_module = True submodule = u"" + else: + is_cython_module = False if is_cython_module: newimp = [] for pos, name, as_name, kind in node.imported_names: @@ -420,6 +425,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): elif node.module.module_name.value == u"cython": is_cython_module = True submodule = u"" + else: + is_cython_module = False if is_cython_module: newimp = [] for name, name_node in node.items: diff --git a/tests/run/cpp_operators.pyx b/tests/run/cpp_operators.pyx index cdce50e8..f3713e3d 100644 --- a/tests/run/cpp_operators.pyx +++ b/tests/run/cpp_operators.pyx @@ -1,5 +1,5 @@ -cimport cython -from cython cimport dereference as deref +cimport cython.operator +from cython.operator cimport dereference as deref cdef extern from "cpp_operators_helper.h": cdef cppclass TestOps: @@ -61,10 +61,10 @@ def test_incdec(): post -- """ cdef TestOps* t = new TestOps() - print cython.preincrement(t[0]) - print cython.predecrement(t[0]) - print cython.postincrement(t[0]) - print cython.postdecrement(t[0]) + print cython.operator.preincrement(t[0]) + print cython.operator.predecrement(t[0]) + print cython.operator.postincrement(t[0]) + print cython.operator.postdecrement(t[0]) del t def test_binop(): diff --git a/tests/run/cpp_templates.pyx b/tests/run/cpp_templates.pyx index 6b723983..118dfa08 100644 --- a/tests/run/cpp_templates.pyx +++ b/tests/run/cpp_templates.pyx @@ -1,4 +1,4 @@ -from cython import dereference as deref +from cython.operator import dereference as deref cdef extern from "cpp_templates_helper.h": cdef cppclass Wrap[T]: