aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTomas Abrahamsson <[email protected]>2011-09-15 19:38:23 +0200
committerHenrik Nord <[email protected]>2011-09-16 11:09:05 +0200
commit9c132d619bb3b88201019a39d064f2852a067fb0 (patch)
treeaab53bc942d75894ac1fd1b9ff593cbebbcdb81a /lib
parent68c96ca855821adb42a25ced5b69446ae7ccc635 (diff)
downloadotp-9c132d619bb3b88201019a39d064f2852a067fb0.tar.gz
otp-9c132d619bb3b88201019a39d064f2852a067fb0.tar.bz2
otp-9c132d619bb3b88201019a39d064f2852a067fb0.zip
Quote atoms if necessary in types
Atoms in some occurrences were not correctly quoted when formatted to strings, for instance by the typer program. Example: -module(tb). -export(['UPPERCASE-FUNCTION-NAME'/0, f1/0, f2/0, f3/0]). -record('UPPERCASE-RECORD-NAME', {x}). -record(r2, {'UPPERCASE-FIELD-NAME'}). -type 'UPPERCASE-TYPE-NAME'() :: integer(). 'UPPERCASE-FUNCTION-NAME'() -> ok. f1() -> #'UPPERCASE-RECORD-NAME'{x=1}. f2() -> #r2{'UPPERCASE-FIELD-NAME'=1}. -spec f3() -> 'UPPERCASE-TYPE-NAME'(). f3() -> 1. Given the program above, the output from typer --plt some.plt tb.erl resulted in the following specs being printed: -spec UPPERCASE-FUNCTION-NAME() -> 'ok'. -spec f1() -> #UPPERCASE-RECORD-NAME{x::1}. -spec f2() -> #r2{UPPERCASE-FIELD-NAME::1}. -spec f3() -> UPPERCASE-TYPE-NAME(). This commit changes the output to become the following: -spec 'UPPERCASE-FUNCTION-NAME'() -> 'ok'. -spec f1() -> #'UPPERCASE-RECORD-NAME'{x::1}. -spec f2() -> #r2{'UPPERCASE-FIELD-NAME'::1}. -spec f3() -> 'UPPERCASE-TYPE-NAME'().
Diffstat (limited to 'lib')
-rw-r--r--lib/hipe/cerl/erl_types.erl16
-rw-r--r--lib/typer/src/typer.erl2
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/hipe/cerl/erl_types.erl b/lib/hipe/cerl/erl_types.erl
index 1748c1cc16..7ff170776e 100644
--- a/lib/hipe/cerl/erl_types.erl
+++ b/lib/hipe/cerl/erl_types.erl
@@ -211,7 +211,8 @@
record_field_diffs_to_string/2,
subst_all_vars_to_any/1,
lift_list_to_pos_empty/1,
- is_erl_type/1
+ is_erl_type/1,
+ atom_to_string/1
]).
%%-define(DO_ERL_TYPES_TEST, true).
@@ -3360,14 +3361,14 @@ t_to_string(?var(Id), _RecDict) when is_integer(Id) ->
record_to_string(Tag, [_|Fields], FieldNames, RecDict) ->
FieldStrings = record_fields_to_string(Fields, FieldNames, RecDict, []),
- "#" ++ atom_to_list(Tag) ++ "{" ++ string:join(FieldStrings, ",") ++ "}".
+ "#" ++ atom_to_string(Tag) ++ "{" ++ string:join(FieldStrings, ",") ++ "}".
record_fields_to_string([F|Fs], [{FName, _DefType}|FDefs], RecDict, Acc) ->
NewAcc =
case t_is_any(F) orelse t_is_atom('undefined', F) of
true -> Acc;
false ->
- StrFV = atom_to_list(FName) ++ "::" ++ t_to_string(F, RecDict),
+ StrFV = atom_to_string(FName) ++ "::" ++ t_to_string(F, RecDict),
%% ActualDefType = t_subtract(DefType, t_atom('undefined')),
%% Str = case t_is_any(ActualDefType) of
%% true -> StrFV;
@@ -3393,7 +3394,7 @@ field_diffs([F|Fs], [{FName, DefType}|FDefs], RecDict, Acc) ->
case t_is_subtype(F, DefType) of
true -> Acc;
false ->
- Str = atom_to_list(FName) ++ "::" ++ t_to_string(DefType, RecDict),
+ Str = atom_to_string(FName) ++ "::" ++ t_to_string(DefType, RecDict),
[Str|Acc]
end,
field_diffs(Fs, FDefs, RecDict, NewAcc);
@@ -3906,7 +3907,7 @@ t_form_to_string({type, _L, union, Args}) ->
string:join(t_form_to_string_list(Args), " | ");
t_form_to_string({type, _L, Name, []} = T) ->
try t_to_string(t_from_form(T))
- catch throw:{error, _} -> atom_to_list(Name) ++ "()"
+ catch throw:{error, _} -> atom_to_string(Name) ++ "()"
end;
t_form_to_string({type, _L, Name, List}) ->
io_lib:format("~w(~s)",
@@ -3920,6 +3921,11 @@ t_form_to_string_list([H|T], Acc) ->
t_form_to_string_list([], Acc) ->
lists:reverse(Acc).
+-spec atom_to_string(atom()) -> string().
+
+atom_to_string(Atom) ->
+ lists:flatten(io_lib:format("~w", [Atom])).
+
%%=============================================================================
%%
%% Utilities
diff --git a/lib/typer/src/typer.erl b/lib/typer/src/typer.erl
index e40c4f39cd..fd906c8c46 100644
--- a/lib/typer/src/typer.erl
+++ b/lib/typer/src/typer.erl
@@ -539,7 +539,7 @@ get_type_string(F, A, Info, Mode) ->
case {Mode, Type} of
{file, {contract, _}} -> "";
_ ->
- Prefix = lists:concat(["-spec ", F]),
+ Prefix = lists:concat(["-spec ", erl_types:atom_to_string(F)]),
lists:concat([Prefix, TypeStr, "."])
end;
true ->