Files
mercury/tests/hard_coded/read_min_int.exp2
Peter Wang 6a267a8f07 Make base_string_to_int check overflow/underflow for all bases.
Make base_string_to_int check for overflow and underflow when converting
from strings in all bases, not only base 10.  Fixes bug #376.

Previously it was stated that "numbers not in base 10 are assumed to
denote bit patterns and are not checked for overflow."  Though not a
safe assumption in general, in Mercury source files it is useful to be
able to write values with the high bit set, e.g. 0x80000000 on 32-bit
machines, that would be greater than max_int if interpreted as a
positive integer.

The changed behaviour of base_string_to_int would reject such literals
from Mercury sources, so additional changes are required to maintain
that usage.  However, unlike before, the compiler will report an
error if some non-zero bits of the literal would be discarded.

library/string.m:
	Enable overflow/underflow checking for base_string_to_int for
	any base.

	Update documentation.

library/lexer.m:
	Allow `big_integer' token functor to represent non-base 10
	literals as well.

	Add `integer_base' type.

library/term.m:
	Add `big_integer' term functor.

	Add `integer_base' type.

library/term_io.m:
	Add private helper functions `integer_base_int' and
	`integer_base_prefix'.

	Conform to changes.

library/parser.m:
	Pass through `big_integer' tokens as `big_integer' terms.

	Conform to changes.

compiler/prog_util.m:
	Add predicate to convert integer terms to ints with the
	aforementioned concession for bit patterns.

	`make_functor_cons_id' can now fail due to integer tokens
	exceeding the range of `int'.

compiler/superhomogeneous.m:
	Make `unravel_var_functor_unification' convert `big_integer'
	tokens on the RHS to a simple `int' with the aforementioned
	concession for bit patterns, or add an error message if any
	significant bits would be discarded.

compiler/fact_table.m:
compiler/mercury_to_mercury.m:
compiler/module_imports.m:
compiler/prog_io_util.m:
	Conform to changes.

compiler/make.util.m:
	Delete unused predicate.

tests/general/test_string_to_int_overflow.m:
tests/general/test_string_to_int_overflow.exp:
tests/general/test_string_to_int_overflow.exp2:
tests/general/test_string_to_int_overflow.exp3:
        Rewrite test case.

tests/hard_coded/lexer_bigint.exp:
tests/hard_coded/lexer_bigint.exp2:
tests/hard_coded/read_min_int.exp:
tests/hard_coded/read_min_int.exp2:
	Update expected outputs due to the lexer and term module changes.

tests/invalid/Mmakefile:
tests/invalid/invalid_int.err_exp:
tests/invalid/invalid_int.err_exp2:
tests/invalid/invalid_int.m:
	Add new test case.

NEWS:
	Announce the changes.
2015-02-17 12:14:16 +11:00

14 lines
303 B
Plaintext

foo(-2147483648)
foo(2147483647)
foo(2147483648)
foo(-9223372036854775808)
foo(9223372036854775807)
io.read: the term read did not have the right type
foo(-2147483648)
foo(2147483647)
foo(2147483648)
foo(-9223372036854775808)
foo(9223372036854775807)
io.read: the term read did not have the right type