aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/cerl
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2014-05-26 11:04:45 +0200
committerBjörn-Egil Dahlberg <[email protected]>2014-05-26 11:04:45 +0200
commit3c95f2613cc7030576f28dae73129dffc1962b96 (patch)
tree431d93211bb98b2b845c4828880ea59c33351e3a /lib/hipe/cerl
parent40052e19a6bbebdf1af89d19245a7abb1d32d1f8 (diff)
parent839f8fea41003883681188dfb09eebbfbd351094 (diff)
downloadotp-3c95f2613cc7030576f28dae73129dffc1962b96.tar.gz
otp-3c95f2613cc7030576f28dae73129dffc1962b96.tar.bz2
otp-3c95f2613cc7030576f28dae73129dffc1962b96.zip
Merge branch 'egil/fix-maps-pretty-layout/OTP-11947' into maint
* egil/fix-maps-pretty-layout/OTP-11947: dialyzer: Add Maps type mismatch test hipe,compiler: Fix Map literals pretty printing
Diffstat (limited to 'lib/hipe/cerl')
-rw-r--r--lib/hipe/cerl/cerl_prettypr.erl24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/hipe/cerl/cerl_prettypr.erl b/lib/hipe/cerl/cerl_prettypr.erl
index 22f5b8945a..9a3873f46d 100644
--- a/lib/hipe/cerl/cerl_prettypr.erl
+++ b/lib/hipe/cerl/cerl_prettypr.erl
@@ -63,7 +63,8 @@
seq_arg/1, seq_body/1, string_lit/1, try_arg/1,
try_body/1, try_vars/1, try_evars/1, try_handler/1,
tuple_es/1, type/1, values_es/1, var_name/1,
- map_es/1, map_pair_key/1, map_pair_val/1, map_pair_op/1
+ c_map/1, map_arg/1, map_es/1, is_c_map_empty/1,
+ c_map_pair/2, map_pair_key/1, map_pair_val/1, map_pair_op/1
]).
-define(PAPER, 76).
@@ -489,7 +490,13 @@ lay_literal(Node, Ctxt) ->
%% `lay_cons' will check for strings.
lay_cons(Node, Ctxt);
V when is_tuple(V) ->
- lay_tuple(Node, Ctxt)
+ lay_tuple(Node, Ctxt);
+ M when is_map(M), map_size(M) =:= 0 ->
+ text("~{}~");
+ M when is_map(M) ->
+ lay_map(c_map([c_map_pair(abstract(K),abstract(V))
+ || {K,V} <- maps:to_list(M)]),
+ Ctxt)
end.
lay_var(Node, Ctxt) ->
@@ -596,10 +603,17 @@ lay_tuple(Node, Ctxt) ->
floating(text("}")))).
lay_map(Node, Ctxt) ->
+ Arg = map_arg(Node),
+ After = case is_c_map_empty(Arg) of
+ true -> floating(text("}~"));
+ false ->
+ beside(floating(text(" | ")),
+ beside(lay(Arg,Ctxt),
+ floating(text("}~"))))
+ end,
beside(floating(text("~{")),
- beside(par(seq(map_es(Node), floating(text(",")),
- Ctxt, fun lay/2)),
- floating(text("}~")))).
+ beside(par(seq(map_es(Node), floating(text(",")), Ctxt, fun lay/2)),
+ After)).
lay_map_pair(Node, Ctxt) ->
K = map_pair_key(Node),