Commit 23c084c9 authored by Stefan Behnel's avatar Stefan Behnel

keep longness when folding negative integer constants

parent fc08e8bf
...@@ -7317,7 +7317,8 @@ def unop_node(pos, operator, operand): ...@@ -7317,7 +7317,8 @@ def unop_node(pos, operator, operand):
# Construct unnop node of appropriate class for # Construct unnop node of appropriate class for
# given operator. # given operator.
if isinstance(operand, IntNode) and operator == '-': if isinstance(operand, IntNode) and operator == '-':
return IntNode(pos = operand.pos, value = str(-Utils.str_to_number(operand.value))) return IntNode(pos = operand.pos, value = str(-Utils.str_to_number(operand.value)),
longness=operand.longness, unsigned=operand.unsigned)
elif isinstance(operand, UnopNode) and operand.operator == operator in '+-': elif isinstance(operand, UnopNode) and operand.operator == operator in '+-':
warning(pos, "Python has no increment/decrement operator: %s%sx == %s(%sx) == x" % ((operator,)*4), 5) warning(pos, "Python has no increment/decrement operator: %s%sx == %s(%sx) == x" % ((operator,)*4), 5)
return unop_node_classes[operator](pos, return unop_node_classes[operator](pos,
......
__doc__ = u""" __doc__ = u"""
>>> c_longs() >>> c_longs()
(1, 1L, -1L, 18446744073709551615L) (1, 1L, -1L, 18446744073709551615L)
>>> negative_c_longs()
(-1, -9223285636854775809L)
>>> py_longs() >>> py_longs()
(1, 1L, 100000000000000000000000000000000L, -100000000000000000000000000000000L) (1, 1L, 100000000000000000000000000000000L, -100000000000000000000000000000000L)
...@@ -18,14 +20,28 @@ import sys ...@@ -18,14 +20,28 @@ import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u'L', u'') __doc__ = __doc__.replace(u'L', u'')
@cython.test_assert_path_exists(
'//IntNode[@longness = "LL"]',
'//IntNode[@longness = "L"]',
)
@cython.test_fail_if_path_exists('//IntNode[@longness = ""]')
def c_longs(): def c_longs():
cdef long a = 1L cdef long a = 1L
cdef unsigned long ua = 1UL cdef unsigned long ua = 1UL
cdef long long aa = 0xFFFFFFFFFFFFFFFFLL cdef long long aa = 0xFFFFFFFFFFFFFFFFLL
cdef unsigned long long uaa = 0xFFFFFFFFFFFFFFFFULL cdef unsigned long long uaa = 0xFFFFFFFFFFFFFFFFULL
return a, ua, aa, uaa return a, ua, aa, uaa
@cython.test_assert_path_exists(
'//IntNode[@longness = "LL"]',
'//IntNode[@longness = "L"]',
)
@cython.test_fail_if_path_exists('//IntNode[@longness = ""]')
def negative_c_longs():
cdef long a = -1L
cdef long long aa = -9223285636854775809LL
return a, aa
def py_longs(): def py_longs():
return 1, 1L, 100000000000000000000000000000000, -100000000000000000000000000000000 return 1, 1L, 100000000000000000000000000000000, -100000000000000000000000000000000
......
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