Commit 43744711 authored by Robert Bradshaw's avatar Robert Bradshaw

Use cython.operator for operators.

parent 1d5d18ff
...@@ -325,12 +325,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -325,12 +325,16 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
""" """
unop_method_nodes = { unop_method_nodes = {
'typeof': TypeofNode, '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, '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'] special_methods = set(['declare', 'union', 'struct', 'typedef', 'sizeof', 'cast', 'pointer', 'compiled', 'NULL']
...@@ -379,10 +383,9 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -379,10 +383,9 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
self.cython_module_names.add(modname) self.cython_module_names.add(modname)
elif node.module_name.startswith(u"cython."): elif node.module_name.startswith(u"cython."):
if node.as_name: if node.as_name:
modname = node.as_name self.directive_names[node.as_name] = node.module_name[7:]
else: else:
modname = u"cython" self.cython_module_names.add(u"cython")
self.directive_names[modname] = node.module_name[7:]
else: else:
return node return node
...@@ -393,6 +396,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -393,6 +396,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
elif node.module_name == u"cython": elif node.module_name == u"cython":
is_cython_module = True is_cython_module = True
submodule = u"" submodule = u""
else:
is_cython_module = False
if is_cython_module: if is_cython_module:
newimp = [] newimp = []
for pos, name, as_name, kind in node.imported_names: for pos, name, as_name, kind in node.imported_names:
...@@ -420,6 +425,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -420,6 +425,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
elif node.module.module_name.value == u"cython": elif node.module.module_name.value == u"cython":
is_cython_module = True is_cython_module = True
submodule = u"" submodule = u""
else:
is_cython_module = False
if is_cython_module: if is_cython_module:
newimp = [] newimp = []
for name, name_node in node.items: for name, name_node in node.items:
......
cimport cython cimport cython.operator
from cython cimport dereference as deref from cython.operator cimport dereference as deref
cdef extern from "cpp_operators_helper.h": cdef extern from "cpp_operators_helper.h":
cdef cppclass TestOps: cdef cppclass TestOps:
...@@ -61,10 +61,10 @@ def test_incdec(): ...@@ -61,10 +61,10 @@ def test_incdec():
post -- post --
""" """
cdef TestOps* t = new TestOps() cdef TestOps* t = new TestOps()
print cython.preincrement(t[0]) print cython.operator.preincrement(t[0])
print cython.predecrement(t[0]) print cython.operator.predecrement(t[0])
print cython.postincrement(t[0]) print cython.operator.postincrement(t[0])
print cython.postdecrement(t[0]) print cython.operator.postdecrement(t[0])
del t del t
def test_binop(): def test_binop():
......
from cython import dereference as deref from cython.operator import dereference as deref
cdef extern from "cpp_templates_helper.h": cdef extern from "cpp_templates_helper.h":
cdef cppclass Wrap[T]: cdef cppclass Wrap[T]:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment