From f6dc9c00459cba32e06d5eb7a0b9f2c6785a4e4d Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 2 Jun 2012 18:37:53 +0200 Subject: Create a new "column" option in compile If set, compile will call epp with a full location {1, 1} instead of 1, thus making it keep the column numbers in the parsed AST. --- lib/compiler/doc/src/compile.xml | 5 +++++ lib/compiler/src/compile.erl | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'lib/compiler') diff --git a/lib/compiler/doc/src/compile.xml b/lib/compiler/doc/src/compile.xml index 84e9922847..2e783d82a0 100644 --- a/lib/compiler/doc/src/compile.xml +++ b/lib/compiler/doc/src/compile.xml @@ -108,6 +108,11 @@ See the Efficiency Guide for further information.

+ column + +

The compiler will keep the column numbers while parsing.

+
+ compressed

The compiler will compress the generated object code, diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index 9b505ad15c..c443f9f788 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -769,7 +769,8 @@ parse_module(St) -> Opts = St#compile.options, Cwd = ".", IncludePath = [Cwd, St#compile.dir|inc_paths(Opts)], - R = epp:parse_file(St#compile.ifile, IncludePath, pre_defs(Opts)), + AtPos = initial_position(Opts), + R = epp:parse_file(St#compile.ifile, AtPos, IncludePath, pre_defs(Opts)), case R of {ok,Forms} -> {ok,St#compile{code=Forms}}; @@ -1475,6 +1476,12 @@ objfile(Base, St) -> tmpfile(Ofile) -> reverse([$#|tl(reverse(Ofile))]). +initial_position(Opts) -> + case lists:member(column, Opts) of + true -> {1, 1}; + false -> 1 + end. + %% pre_defs(Options) %% inc_paths(Options) %% Extract the predefined macros and include paths from the option list. -- cgit v1.2.3 From 5af6bd403862b10693035bebfd88d326541ca4bb Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 3 Jun 2012 10:42:45 +0200 Subject: Fix printing of errors with column numbers There was a colon missing after the column number, it must be an error as it's not missing in list_errors/2. --- lib/compiler/src/compile.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/compiler') diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index c443f9f788..31c8f6c280 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -1420,7 +1420,7 @@ report_warnings(#compile{options=Opts,warnings=Ws0}) -> end. format_message(F, P, [{{Line,Column}=Loc,Mod,E}|Es]) -> - M = {{F,Loc},io_lib:format("~s:~w:~w ~s~s\n", + M = {{F,Loc},io_lib:format("~s:~w:~w: ~s~s\n", [F,Line,Column,P,Mod:format_error(E)])}, [M|format_message(F, P, Es)]; format_message(F, P, [{Line,Mod,E}|Es]) -> -- cgit v1.2.3 From c98bc0eb21aae3011b09c37c0efd4dd5316b6d30 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 3 Jun 2012 14:27:21 +0200 Subject: Test column number reporting in error_SUITE --- lib/compiler/test/error_SUITE.erl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/compiler') diff --git a/lib/compiler/test/error_SUITE.erl b/lib/compiler/test/error_SUITE.erl index eb5e50818e..47698ecdb7 100644 --- a/lib/compiler/test/error_SUITE.erl +++ b/lib/compiler/test/error_SUITE.erl @@ -22,13 +22,15 @@ -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, - head_mismatch_line/1,warnings_as_errors/1, bif_clashes/1]). + head_mismatch_line/1,warnings_as_errors/1, bif_clashes/1, + column_number/1 + ]). suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> test_lib:recompile(?MODULE), - [head_mismatch_line, warnings_as_errors, bif_clashes]. + [head_mismatch_line, warnings_as_errors, bif_clashes, column_number]. groups() -> []. @@ -166,6 +168,15 @@ bif_clashes(Config) when is_list(Config) -> +%% Tests that messages are correctly reported with column numbers +%% if the column option is set. +column_number(Config) when is_list(Config) -> + Ts1 = [{column_number_warning, + <<"\nt(X) -> ok.">>, + [return_warnings, export_all, column], + {warning, [{{2, 3}, erl_lint, {unused_var, 'X'}}]}}], + ?line [] = run(Config, Ts1), + ok. %% Tests that a head mismatch is reported on the correct line (OTP-2125). head_mismatch_line(Config) when is_list(Config) -> -- cgit v1.2.3 From 198ef4b41ce0b22898b7642354ea5062bc3cc896 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 6 Jun 2012 13:31:10 +0200 Subject: Fix type compile:err_info/0 --- lib/compiler/src/compile.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/compiler') diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index 31c8f6c280..8062ca59fa 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -41,7 +41,7 @@ -type option() :: atom() | {atom(), term()} | {'d', atom(), term()}. --type err_info() :: {erl_scan:line(), module(), term()}. %% ErrorDescriptor +-type err_info() :: erl_scan:error_info(). %% ErrorDescriptor -type errors() :: [{file:filename(), [err_info()]}]. -type warnings() :: [{file:filename(), [err_info()]}]. -type mod_ret() :: {'ok', module()} -- cgit v1.2.3 From d932ad582676f1593d917f222b1d8dec71fe88b3 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 10 Jun 2012 13:01:50 +0200 Subject: Fix messages ordering with column numbers With L1, L2, C1, C2 integers such as L1 < L2 and C1 < C2, locations are ordered like this: L1 < {L1, C1} < {L1, C2} < L2 --- lib/compiler/src/compile.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/compiler') diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index 8062ca59fa..d4d84e02fb 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -359,7 +359,17 @@ messages_per_file(Ms) -> (_) -> false end, A) end, T, PrioMs), - Prio = lists:sort(fun({_,{L1,_,_}}, {_,{L2,_,_}}) -> L1 =< L2 end, + Prio = lists:sort(fun({_,{As1,_,_}}, {_,{As2,_,_}}) -> + {location, Loc1} = + erl_scan:attributes_info(As1, location), + {location, Loc2} = + erl_scan:attributes_info(As2, location), + case {Loc1, Loc2} of + {{L1, _}, L2} when is_integer(L2) -> L1 < L2; + {L1, {L2, _}} when is_integer(L1) -> L1 =< L2; + {_, _} -> Loc1 =< Loc2 + end + end, lists:append(Prio0)), flatmap(fun mpf/1, [Prio, Rest]). -- cgit v1.2.3