69
69
implementation_md5=[] :: [{atom(), _}]
72
-spec(new/0 :: () -> #dialyzer_plt{}).
72
-spec new() -> #dialyzer_plt{}.
75
75
#dialyzer_plt{info=table_new(), contracts=table_new()}.
77
-spec(delete_module/2 :: (#dialyzer_plt{}, atom()) -> #dialyzer_plt{}).
77
-spec delete_module(#dialyzer_plt{}, atom()) -> #dialyzer_plt{}.
79
79
delete_module(#dialyzer_plt{info=Info, contracts=Contracts}, Mod) ->
80
80
#dialyzer_plt{info=table_delete_module(Info, Mod),
81
81
contracts=table_delete_module(Contracts, Mod)}.
83
-spec(delete_list/2 :: (#dialyzer_plt{}, [_]) -> #dialyzer_plt{}).
83
-spec delete_list(#dialyzer_plt{}, [_]) -> #dialyzer_plt{}.
85
85
delete_list(#dialyzer_plt{info=Info, contracts=Contracts}, List) ->
86
86
#dialyzer_plt{info=table_delete_list(Info, List),
87
87
contracts=table_delete_list(Contracts, List)}.
89
-spec(insert_contract_list/2 ::
90
(#dialyzer_plt{}, [{mfa(), #contract{}}]) -> #dialyzer_plt{}).
89
-spec insert_contract_list(#dialyzer_plt{}, [{mfa(), #contract{}}]) -> #dialyzer_plt{}.
92
91
insert_contract_list(Plt = #dialyzer_plt{contracts=Contracts}, List) ->
93
92
Plt#dialyzer_plt{contracts=table_insert_list(Contracts, List)}.
95
-spec(lookup_contract/2 ::
96
(#dialyzer_plt{}, mfa()) -> 'none' | {'value', #contract{}}).
94
-spec lookup_contract(#dialyzer_plt{}, mfa()) -> 'none' | {'value',#contract{}}.
98
96
lookup_contract(#dialyzer_plt{contracts=Contracts},
99
97
MFA={M, F, A}) when is_atom(M), is_atom(F), is_integer(A),
100
98
0 =< A, A =< 255 ->
101
99
table_lookup(Contracts, MFA).
103
-spec(delete_contract_list/2 :: (#dialyzer_plt{}, [mfa()]) -> #dialyzer_plt{}).
101
-spec delete_contract_list(#dialyzer_plt{}, [mfa()]) -> #dialyzer_plt{}.
105
103
delete_contract_list(Plt = #dialyzer_plt{contracts=Contracts}, List) ->
106
104
Plt#dialyzer_plt{contracts=table_delete_list(Contracts, List)}.
109
%% -spec(insert/3 :: (#dialyzer_plt{}, mfa() | integer(), {_, _}) ->
107
%% -spec insert(#dialyzer_plt{}, mfa() | integer(), {_, _}) -> #dialyzer_plt{}.
112
109
%% insert(Plt = #dialyzer_plt{info=Info}, Id, Types) ->
113
110
%% Plt#dialyzer_plt{info=table_insert(Info, Id, Types)}.
115
-spec(insert_list/2 :: (#dialyzer_plt{}, [{mfa() | integer(), {_, _}}]) ->
112
-spec insert_list(#dialyzer_plt{}, [{mfa() | integer(), {_, _}}]) -> #dialyzer_plt{}.
118
114
insert_list(Plt = #dialyzer_plt{info=Info}, List) ->
119
115
Plt#dialyzer_plt{info=table_insert_list(Info, List)}.
121
-spec(lookup/2 :: (#dialyzer_plt{}, integer() | mfa()) ->
122
'none' | {'value', {_, _}}).
117
-spec lookup(#dialyzer_plt{}, integer() | mfa()) -> 'none' | {'value', {_, _}}.
124
119
lookup(#dialyzer_plt{info=Info}, MFA={M, F, A}) when is_atom(M),
129
124
lookup(#dialyzer_plt{info=Info}, Label) when is_integer(Label) ->
130
125
table_lookup(Info, Label).
132
-spec(lookup_module/2 ::
133
(#dialyzer_plt{}, atom()) -> 'none' | {'value', [{_, _}]}).
127
-spec lookup_module(#dialyzer_plt{}, atom()) -> 'none' | {'value', [{mfa(), _, _}]}.
135
129
lookup_module(#dialyzer_plt{info=Info}, M) when is_atom(M) ->
136
130
table_lookup_module(Info, M).
138
-spec(contains_module/2 :: (#dialyzer_plt{}, atom()) -> bool()).
132
-spec contains_module(#dialyzer_plt{}, atom()) -> bool().
140
134
contains_module(#dialyzer_plt{info=Info, contracts=Cs}, M) when is_atom(M) ->
141
135
table_contains_module(Info, M) orelse table_contains_module(Cs, M).
143
-spec(contains_mfa/2 :: (#dialyzer_plt{}, mfa()) -> bool()).
137
-spec contains_mfa(#dialyzer_plt{}, mfa()) -> bool().
145
139
contains_mfa(#dialyzer_plt{info=Info, contracts=Contracts}, MFA) ->
146
140
(table_lookup(Info, MFA) =/= none)
147
141
orelse (table_lookup(Contracts, MFA) =/= none).
149
-spec(get_default_plt/0 :: () -> string()).
143
-spec get_default_plt() -> string().
151
145
get_default_plt() ->
152
146
case os:getenv("DIALYZER_PLT") of
154
148
case os:getenv("HOME") of
155
false -> error("Please specify which plt to use");
150
error("The HOME environment variable needs to be set " ++
151
"so that Dialyzer knows where to find the default PLT");
156
152
HomeDir -> filename:join(HomeDir, ".dialyzer_plt")
158
154
UserSpecPlt -> UserSpecPlt
161
-spec(plt_and_info_from_file/1 :: (string()) -> {#dialyzer_plt{}, {_, _}}).
157
-spec plt_and_info_from_file(string()) -> {#dialyzer_plt{}, {_, _}}.
163
159
plt_and_info_from_file(FileName) ->
164
160
from_file(FileName, true).
166
-spec(from_file/1 :: (string()) -> #dialyzer_plt{}).
162
-spec from_file(string()) -> #dialyzer_plt{}.
168
164
from_file(FileName) ->
169
165
from_file(FileName, false).
226
221
{error, read_error}
229
-spec(merge_plts/1 :: ([#dialyzer_plt{}]) -> #dialyzer_plt{}).
224
-spec merge_plts([#dialyzer_plt{}]) -> #dialyzer_plt{}.
231
226
merge_plts(List) ->
232
InfoList = lists:map(fun(#dialyzer_plt{info=Info}) -> Info end, List),
233
ContractsList = lists:map(fun(#dialyzer_plt{contracts=Contracts}) ->
227
InfoList = [Info || #dialyzer_plt{info=Info} <- List],
228
ContractsList = [Contracts || #dialyzer_plt{contracts=Contracts} <- List],
236
229
#dialyzer_plt{info=table_merge(InfoList),
237
230
contracts=table_merge(ContractsList)}.
239
-spec(to_file/4 :: (string(), #dialyzer_plt{}, dict(), {md5(), dict()}) -> 'ok').
232
-spec to_file(string(), #dialyzer_plt{}, dict(), {md5(), dict()}) -> 'ok'.
241
234
to_file(FileName, #dialyzer_plt{info=Info, contracts=Contracts},
242
235
ModDeps, {MD5, OldModDeps}) ->
260
253
throw({dialyzer_error, Msg})
263
-type(md5_diff() :: [{'differ',atom()} | {'removed',atom()}]).
264
-type(check_error() :: 'not_valid' | 'no_such_file' | 'read_error' |
265
{'no_file_to_remove', string()}).
256
-type md5_diff() :: [{'differ',atom()} | {'removed',atom()}].
257
-type check_error() :: 'not_valid' | 'no_such_file' | 'read_error'
258
| {'no_file_to_remove', string()}.
268
(string(), [string()], [string()]) ->
260
-spec check_plt(string(), [string()], [string()]) ->
270
262
| {'error', check_error()}
271
263
| {'differ', md5(), md5_diff(), mod_deps()}
272
| {'old_version', md5()}).
264
| {'old_version', md5()}.
274
266
check_plt(FileName, RemoveFiles, AddFiles) ->
275
267
case get_record_from_file(FileName) of
404
396
beam_file_to_module(Filename) ->
405
397
list_to_atom(filename:basename(Filename, ".beam")).
407
-spec(to_edoc/4 :: (#dialyzer_plt{}, atom(), atom(), byte()) -> string()).
399
-spec to_edoc(#dialyzer_plt{}, atom(), atom(), byte()) -> string().
409
401
to_edoc(PLT, M, F, A) when is_atom(M), is_atom(F) ->
410
402
{value, Val} = lookup(PLT, {M, F, A}),