diff options
author | Hans Bolinder <[email protected]> | 2014-06-30 13:42:06 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2014-06-30 13:42:06 +0200 |
commit | a884f78ee7609b3140f5a9fb524599be4ea816d7 (patch) | |
tree | 7bc0690dae4881831308cd14b40365e9e717584b /lib | |
parent | e54518231ac28096dec8f0a63afe527916ff1343 (diff) | |
parent | d78df206f9356629d82891e5853f7ff53c9f9749 (diff) | |
download | otp-a884f78ee7609b3140f5a9fb524599be4ea816d7.tar.gz otp-a884f78ee7609b3140f5a9fb524599be4ea816d7.tar.bz2 otp-a884f78ee7609b3140f5a9fb524599be4ea816d7.zip |
Merge branch 'hb/hipe/pretty_bitstring/OTP-12015' into maint
* hb/hipe/pretty_bitstring/OTP-12015:
hipe: Correct pretty-printing of bitstrings
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dialyzer/test/small_SUITE_data/results/pretty_bitstring | 3 | ||||
-rw-r--r-- | lib/dialyzer/test/small_SUITE_data/src/pretty_bitstring.erl | 8 | ||||
-rw-r--r-- | lib/hipe/cerl/cerl_prettypr.erl | 17 |
3 files changed, 23 insertions, 5 deletions
diff --git a/lib/dialyzer/test/small_SUITE_data/results/pretty_bitstring b/lib/dialyzer/test/small_SUITE_data/results/pretty_bitstring new file mode 100644 index 0000000000..0ad6eee766 --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/results/pretty_bitstring @@ -0,0 +1,3 @@ + +pretty_bitstring.erl:7: Function t/0 has no local return +pretty_bitstring.erl:8: The call binary:copy(#{#<1>(8, 1, 'integer', ['unsigned', 'big']), #<2>(8, 1, 'integer', ['unsigned', 'big']), #<3>(3, 1, 'integer', ['unsigned', 'big'])}#,2) breaks the contract (Subject,N) -> binary() when is_subtype(Subject,binary()), is_subtype(N,non_neg_integer()) diff --git a/lib/dialyzer/test/small_SUITE_data/src/pretty_bitstring.erl b/lib/dialyzer/test/small_SUITE_data/src/pretty_bitstring.erl new file mode 100644 index 0000000000..3dbf5ab7a7 --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/pretty_bitstring.erl @@ -0,0 +1,8 @@ +%% Prettyprint bitstrings. + +-module(pretty_bitstring). + +-export([t/0]). + +t() -> + binary:copy(<<1,2,3:3>>,2). diff --git a/lib/hipe/cerl/cerl_prettypr.erl b/lib/hipe/cerl/cerl_prettypr.erl index 9a3873f46d..f4a67439d6 100644 --- a/lib/hipe/cerl/cerl_prettypr.erl +++ b/lib/hipe/cerl/cerl_prettypr.erl @@ -1,7 +1,7 @@ %% ===================================================================== %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2014. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -476,13 +476,20 @@ lay_literal(Node, Ctxt) -> %% that could represent printable characters - we %% always print an integer. text(int_lit(Node)); - V when is_binary(V) -> - lay_binary(c_binary([c_bitstr(abstract(B), - abstract(8), + V when is_bitstring(V) -> + Val = fun(I) when is_integer(I) -> I; + (B) when is_bitstring(B) -> + BZ = bit_size(B), <<BV:BZ>> = B, BV + end, + Sz = fun(I) when is_integer(I) -> 8; + (B) when is_bitstring(B) -> bit_size(B) + end, + lay_binary(c_binary([c_bitstr(abstract(Val(B)), + abstract(Sz(B)), abstract(1), abstract(integer), abstract([unsigned, big])) - || B <- binary_to_list(V)]), + || B <- bitstring_to_list(V)]), Ctxt); [] -> text("[]"); |