Commit c96fc2de authored by Robert Bradshaw's avatar Robert Bradshaw

Use existing Python not operator for !.

parent f97b7dc0
......@@ -6939,7 +6939,20 @@ class NotNode(ExprNode):
def analyse_types(self, env):
self.operand.analyse_types(env)
self.operand = self.operand.coerce_to_boolean(env)
if self.operand.type.is_cpp_class:
type = self.operand.type
function = type.scope.lookup("operator!")
if not function:
error(self.pos, "'!' operator not defined for %s"
% (type))
self.type = PyrexTypes.error_type
return
func_type = function.type
if func_type.is_ptr:
func_type = func_type.base_type
self.type = func_type.return_type
else:
self.operand = self.operand.coerce_to_boolean(env)
def calculate_result_code(self):
return "(!%s)" % self.operand.result()
......@@ -7021,20 +7034,6 @@ class CUnopNode(UnopNode):
def is_py_operation(self):
return False
class BangNode(CUnopNode):
# unary ! operator
operator = '!'
def analyse_c_operation(self, env):
if self.operand.type.is_ptr or self.operand.type.is_numeric:
self.type = PyrexTypes.c_bint_type
else:
self.type_error()
def calculate_result_code(self):
return "(!%s)" % self.operand.result()
class DereferenceNode(CUnopNode):
# unary * operator
......
......@@ -614,7 +614,6 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
'typeof': ExprNodes.TypeofNode,
'operator.address': ExprNodes.AmpersandNode,
'operator.bang': ExprNodes.BangNode,
'operator.dereference': ExprNodes.DereferenceNode,
'operator.preincrement' : ExprNodes.inc_dec_constructor(True, '++'),
'operator.predecrement' : ExprNodes.inc_dec_constructor(True, '--'),
......
......@@ -333,8 +333,6 @@ a special module ``cython.operator``. The functions provided are:
* ``cython.operator.dereference`` for dereferencing. ``dereference(foo)``
will produce the C++ code ``*(foo)``
* ``cython.operator.bang`` for not. ``bang(foo)``
will produce the C++ code ``!(foo)``
* ``cython.operator.preincrement`` for pre-incrementation. ``preincrement(foo)``
will produce the C++ code ``++(foo)``
* ...
......
......@@ -58,7 +58,7 @@ def test_unops():
out(-t[0])
out(~t[0])
out(deref(t[0]))
out(cython.operator.bang(t[0]))
out(not t[0])
del t
def test_incdec():
......
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