aboutsummaryrefslogtreecommitdiffstats
path: root/lib/parsetools
diff options
context:
space:
mode:
authorTuncer Ayaz <[email protected]>2011-08-02 16:40:57 +0200
committerTuncer Ayaz <[email protected]>2011-09-08 14:02:16 +0200
commit089df2b89969353229093ac56665f1b52d87ce09 (patch)
tree35637d9a782b2e493f6e7f4716c45d077e7a31c0 /lib/parsetools
parent48de2c2182e703c07d67471db3e2f154cc5df99e (diff)
downloadotp-089df2b89969353229093ac56665f1b52d87ce09.tar.gz
otp-089df2b89969353229093ac56665f1b52d87ce09.tar.bz2
otp-089df2b89969353229093ac56665f1b52d87ce09.zip
leex: log warnings as errors if -Werror is enabled
Diffstat (limited to 'lib/parsetools')
-rw-r--r--lib/parsetools/src/leex.erl33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/parsetools/src/leex.erl b/lib/parsetools/src/leex.erl
index e3e10eb204..ca010e09f0 100644
--- a/lib/parsetools/src/leex.erl
+++ b/lib/parsetools/src/leex.erl
@@ -307,15 +307,24 @@ report_errors(St) ->
end, report_errors, St#leex.opts).
report_warnings(St) ->
- when_opt(fun () ->
- foreach(fun({File,{none,Mod,W}}) ->
- io:fwrite("~s: Warning: ~s\n",
- [File,Mod:format_error(W)]);
- ({File,{Line,Mod,W}}) ->
- io:fwrite("~s:~w: Warning: ~s\n",
- [File,Line,Mod:format_error(W)])
- end, sort(St#leex.warnings))
- end, report_warnings, St#leex.opts).
+ Werr = member(warnings_as_errors, St#leex.opts),
+ Prefix = case Werr of
+ true -> "";
+ false -> "Warning: "
+ end,
+ ReportWerr = Werr andalso member(report_errors, St#leex.opts),
+ ShouldReport = member(report_warnings, St#leex.opts) orelse ReportWerr,
+ when_bool(fun () ->
+ foreach(fun({File,{none,Mod,W}}) ->
+ io:fwrite("~s: ~s~s\n",
+ [File,Prefix,
+ Mod:format_error(W)]);
+ ({File,{Line,Mod,W}}) ->
+ io:fwrite("~s:~w: ~s~s\n",
+ [File,Line,Prefix,
+ Mod:format_error(W)])
+ end, sort(St#leex.warnings))
+ end, ShouldReport).
-spec add_error(_, #leex{}) -> no_return().
add_error(E, St) ->
@@ -363,6 +372,12 @@ when_opt(Do, Opt, Opts) ->
false -> ok
end.
+when_bool(Do, Bool) ->
+ case Bool of
+ true -> Do();
+ false -> ok
+ end.
+
verbose_print(St, Format, Args) ->
when_opt(fun () -> io:fwrite(Format, Args) end, verbose, St#leex.opts).