else:
return "%s(%s)" % (self.operand.type.unary_op('-'), self.operand.result())
+ def get_constant_c_result_code(self):
+ value = self.operand.get_constant_c_result_code()
+ if value:
+ return "(-%s)" % (value)
+
class TildeNode(UnopNode):
# unary '~' operator
opnd = self.operand
return self.type.cast_code(opnd.result())
+ def get_constant_c_result_code(self):
+ operand_result = self.operand.get_constant_c_result_code()
+ if operand_result:
+ return self.type.cast_code(operand_result)
+
def result_as(self, type):
if self.type.is_pyobject and not self.is_temp:
# Optimise away some unnecessary casting
else:
if self.exception_value:
self.exception_value.analyse_const_expression(env)
- exc_val = self.exception_value.get_constant_c_result_code()
if self.exception_check == '+':
exc_val_type = self.exception_value.type
if not exc_val_type.is_error and \
error(self.exception_value.pos,
"Exception value must be a Python exception or cdef function with no arguments.")
else:
+ exc_val = self.exception_value.get_constant_c_result_code()
if not return_type.assignable_from(self.exception_value.type):
error(self.exception_value.pos,
"Exception value incompatible with function return type")
arg_reprs = map(repr, self.args)
if self.has_varargs:
arg_reprs.append("...")
- return "<CFuncType %s %s[%s]>" % (
+ if self.exception_value:
+ except_clause = " %r" % self.exception_value
+ else:
+ except_clause = ""
+ if self.exception_check:
+ except_clause += "?"
+ return "<CFuncType %s %s[%s]%s>" % (
repr(self.return_type),
self.calling_convention_prefix(),
- ",".join(arg_reprs))
+ ",".join(arg_reprs),
+ except_clause)
def calling_convention_prefix(self):
cc = self.calling_convention
def foo(a):
cdef int i = obj2int(a)
CHKERR(i)
+
+cdef int* except_expr(bint fire) except <int*>-1:
+ if fire:
+ raise RuntimeError
+
+def test_except_expr(bint fire):
+ """
+ >>> test_except_expr(False)
+ >>> test_except_expr(True)
+ Traceback (most recent call last):
+ ...
+ RuntimeError
+ """
+ except_expr(fire)