1
1
%% -*- erlang-indent-level: 2 -*-
2
2
%%-----------------------------------------------------------------------
3
%% ``The contents of this file are subject to the Erlang Public License,
5
%% Copyright Ericsson AB 2006-2009. All Rights Reserved.
7
%% The contents of this file are subject to the Erlang Public License,
4
8
%% Version 1.1, (the "License"); you may not use this file except in
5
9
%% compliance with the License. You should have received a copy of the
6
10
%% Erlang Public License along with this software. If not, it can be
7
%% retrieved via the world wide web at http://www.erlang.org/.
11
%% retrieved online at http://www.erlang.org/.
9
13
%% Software distributed under the License is distributed on an "AS IS"
10
14
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11
15
%% the License for the specific language governing rights and limitations
12
16
%% under the License.
14
%% Copyright 2006, 2007 Tobias Lindahl and Kostis Sagonas
19
21
%%%----------------------------------------------------------------------
61
65
Opts1 = check_output_plt(Opts),
62
66
adapt_get_warnings(Opts1).
64
check_output_plt(Opts = #options{analysis_type=Mode}) ->
68
check_output_plt(Opts = #options{analysis_type = Mode, from = From,
69
output_plt = OutPLT}) ->
65
70
case is_plt_mode(Mode) of
67
case Opts#options.from =:= byte_code of
72
case From =:= byte_code of
70
75
Msg = "Byte code compiled with debug_info is needed to build the PLT",
71
76
throw({dialyzer_error, Msg})
74
case Opts#options.output_plt =:= none of
79
case OutPLT =:= none of
77
Msg = io_lib:format("Output plt cannot be specified "
82
Msg = io_lib:format("Output PLT cannot be specified "
78
83
"in analysis mode ~w", [Mode]),
79
84
throw({dialyzer_error, lists:flatten(Msg)})
83
adapt_get_warnings(Opts = #options{analysis_type=Mode}) ->
88
adapt_get_warnings(Opts = #options{analysis_type = Mode,
89
get_warnings = Warns}) ->
84
90
%% Warnings are off by default in plt mode, and on by default in
85
91
%% success typings mode. User defined warning mode overrides the
87
93
case is_plt_mode(Mode) of
89
case Opts#options.get_warnings =:= maybe of
90
true -> Opts#options{get_warnings=false};
95
case Warns =:= maybe of
96
true -> Opts#options{get_warnings = false};
94
case Opts#options.get_warnings =:= maybe of
95
true -> Opts#options{get_warnings=true};
100
case Warns =:= maybe of
101
true -> Opts#options{get_warnings = true};
100
-spec bad_option(string(), _) -> no_return().
106
-spec bad_option(string(), term()) -> no_return().
102
108
bad_option(String, Term) ->
103
Msg = io_lib:format("~s: ~P\n", [String,Term,25]),
109
Msg = io_lib:format("~s: ~P", [String, Term, 25]),
104
110
throw({dialyzer_options_error, lists:flatten(Msg)}).
107
112
build_options([{OptName, undefined}|Rest], Options) when is_atom(OptName) ->
108
113
build_options(Rest, Options);
109
build_options([Term = {OptionName, Value}|Rest], Options) ->
114
build_options([{OptionName, Value} = Term|Rest], Options) ->
110
115
case OptionName of
112
117
assert_filenames(Term, Value),
113
build_options(Rest, Options#options{files=Value});
118
build_options(Rest, Options#options{files = Value});
115
120
assert_filenames(Term, Value),
116
build_options(Rest, Options#options{files_rec=Value});
121
build_options(Rest, Options#options{files_rec = Value});
120
succ_typings -> Options#options{analysis_type=Value};
121
plt_add -> Options#options{analysis_type=Value};
122
plt_build -> Options#options{analysis_type=Value};
123
plt_check -> Options#options{analysis_type=Value};
124
plt_remove -> Options#options{analysis_type=Value};
125
succ_typings -> Options#options{analysis_type = Value};
126
plt_add -> Options#options{analysis_type = Value};
127
plt_build -> Options#options{analysis_type = Value};
128
plt_check -> Options#options{analysis_type = Value};
129
plt_remove -> Options#options{analysis_type = Value};
125
130
dataflow -> bad_option("Analysis type is no longer supported", Term);
126
131
old_style -> bad_option("Analysis type is no longer supported", Term);
127
132
Other -> bad_option("Unknown analysis type", Other)
129
134
assert_plt_op(Options, NewOptions),
130
135
build_options(Rest, NewOptions);
131
136
check_plt when is_boolean(Value) ->
132
build_options(Rest, Options#options{check_plt=Value});
137
build_options(Rest, Options#options{check_plt = Value});
134
139
assert_defines(Term, Value),
135
140
OldVal = Options#options.defines,
136
141
NewVal = ordsets:union(ordsets:from_list(Value), OldVal),
137
build_options(Rest, Options#options{defines=NewVal});
142
build_options(Rest, Options#options{defines = NewVal});
138
143
from when Value =:= byte_code; Value =:= src_code ->
139
build_options(Rest, Options#options{from=Value});
144
build_options(Rest, Options#options{from = Value});
141
build_options(Rest, Options#options{get_warnings=Value});
146
build_options(Rest, Options#options{get_warnings = Value});
143
148
assert_filenames([Term], [Value]),
144
build_options(Rest, Options#options{init_plt=Value});
149
build_options(Rest, Options#options{init_plt = Value});
146
151
assert_filenames(Term, Value),
147
152
OldVal = Options#options.include_dirs,
148
153
NewVal = ordsets:union(ordsets:from_list(Value), OldVal),
149
build_options(Rest, Options#options{include_dirs=NewVal});
154
build_options(Rest, Options#options{include_dirs = NewVal});
151
build_options(Rest, Options#options{use_contracts=Value});
156
build_options(Rest, Options#options{use_contracts = Value});
153
158
bad_option("Analysis type is no longer supported", old_style);
155
assert_filenames([Term], [Value]),
156
build_options(Rest, Options#options{output_file=Value});
160
assert_filename(Value),
161
build_options(Rest, Options#options{output_file = Value});
158
163
assert_output_format(Value),
159
build_options(Rest, Options#options{output_format=Value});
164
build_options(Rest, Options#options{output_format = Value});
161
assert_filenames([Term], [Value]),
162
build_options(Rest, Options#options{output_plt=Value});
166
assert_filename(Value),
167
build_options(Rest, Options#options{output_plt = Value});
164
build_options(Rest, Options#options{report_mode=Value});
169
build_options(Rest, Options#options{report_mode = Value});
166
build_options(Rest, Options#options{erlang_mode=true});
171
build_options(Rest, Options#options{erlang_mode = true});
168
173
NewWarnings = build_warnings(Value, Options#options.legal_warnings),
169
build_options(Rest, Options#options{legal_warnings=NewWarnings});
174
build_options(Rest, Options#options{legal_warnings = NewWarnings});
176
assert_filename(Value),
177
build_options(Rest, Options#options{callgraph_file = Value});
171
179
bad_option("Unknown dialyzer command line option", Term)
176
184
assert_filenames(Term, [FileName|Left]) when length(FileName) >= 0 ->
185
case filelib:is_file(FileName) orelse filelib:is_dir(FileName) of
187
false -> bad_option("No such file or directory", FileName)
177
189
assert_filenames(Term, Left);
178
190
assert_filenames(_Term, []) ->
180
192
assert_filenames(Term, [_|_]) ->
181
193
bad_option("Malformed or non-existing filename", Term).
183
assert_defines(Term, [{Macro, _Value}|Left]) when is_atom(Macro) ->
184
assert_defines(Term, Left);
195
assert_filename(FileName) when length(FileName) >= 0 ->
197
assert_filename(FileName) ->
198
bad_option("Malformed or non-existing filename", FileName).
200
assert_defines(Term, [{Macro, _Value}|Defs]) when is_atom(Macro) ->
201
assert_defines(Term, Defs);
185
202
assert_defines(_Term, []) ->
187
204
assert_defines(Term, [_|_]) ->