aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2012-08-14 15:30:03 +0200
committerFredrik Gustafsson <[email protected]>2012-08-14 15:30:03 +0200
commit160bf5da0e03f39b468ebba5d39d1658c8a370e6 (patch)
treee0d7bcbde2f11b6b8def23ad8de6bc6abc3c2290 /lib
parentce6691c02f5bea8ecb0478edd68a555067de37d2 (diff)
parent9492bf7abbf5e43a9bdada5b0ace0432ce1f4223 (diff)
downloadotp-160bf5da0e03f39b468ebba5d39d1658c8a370e6.tar.gz
otp-160bf5da0e03f39b468ebba5d39d1658c8a370e6.tar.bz2
otp-160bf5da0e03f39b468ebba5d39d1658c8a370e6.zip
Merge branch 'maint', remote-tracking branch 'upstream'
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler/doc/src/compile.xml5
-rw-r--r--lib/compiler/src/compile.erl25
-rw-r--r--lib/compiler/src/sys_pre_expand.erl2
-rw-r--r--lib/compiler/test/error_SUITE.erl15
-rw-r--r--lib/stdlib/doc/src/epp.xml2
-rw-r--r--lib/stdlib/src/epp.erl44
-rw-r--r--lib/stdlib/src/erl_scan.erl2
7 files changed, 78 insertions, 17 deletions
diff --git a/lib/compiler/doc/src/compile.xml b/lib/compiler/doc/src/compile.xml
index be9eb1cd75..b87e32a3d9 100644
--- a/lib/compiler/doc/src/compile.xml
+++ b/lib/compiler/doc/src/compile.xml
@@ -108,6 +108,11 @@
See the <em>Efficiency Guide</em> for further information.</p>
</item>
+ <tag><c>column</c></tag>
+ <item>
+ <p>The compiler will keep the column numbers while parsing.</p>
+ </item>
+
<tag><c>compressed</c></tag>
<item>
<p>The compiler will compress the generated object code,
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index 7365706b94..fbaacc08da 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()}
@@ -363,7 +363,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]).
@@ -773,7 +783,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}};
@@ -1423,7 +1434,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]) ->
@@ -1479,6 +1490,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.
diff --git a/lib/compiler/src/sys_pre_expand.erl b/lib/compiler/src/sys_pre_expand.erl
index 68bc83433e..6cea783090 100644
--- a/lib/compiler/src/sys_pre_expand.erl
+++ b/lib/compiler/src/sys_pre_expand.erl
@@ -119,7 +119,7 @@ expand_pmod(Fs0, St0) ->
get_base(As) ->
case lists:keyfind(extends, 1, As) of
- {extends,[Base]} when is_atom(Base) ->
+ {extends,_,[Base]} when is_atom(Base) ->
Base;
_ ->
[]
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) ->
diff --git a/lib/stdlib/doc/src/epp.xml b/lib/stdlib/doc/src/epp.xml
index 488499581f..a57c7084fa 100644
--- a/lib/stdlib/doc/src/epp.xml
+++ b/lib/stdlib/doc/src/epp.xml
@@ -51,6 +51,7 @@
<func>
<name name="open" arity="2"/>
<name name="open" arity="3"/>
+ <name name="open" arity="4"/>
<fsummary>Open a file for preprocessing</fsummary>
<desc>
<p>Opens a file for preprocessing.</p>
@@ -75,6 +76,7 @@
</func>
<func>
<name name="parse_file" arity="3"/>
+ <name name="parse_file" arity="4"/>
<fsummary>Preprocess and parse an Erlang source file</fsummary>
<desc>
<p>Preprocesses and parses an Erlang source file.
diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl
index ccc14610d7..d958b0af2a 100644
--- a/lib/stdlib/src/epp.erl
+++ b/lib/stdlib/src/epp.erl
@@ -20,9 +20,9 @@
%% An Erlang code preprocessor.
--export([open/2,open/3,open/5,close/1,format_error/1]).
+-export([open/2,open/3,open/4, open/5,close/1,format_error/1]).
-export([scan_erl_form/1,parse_erl_form/1,macro_defs/1]).
--export([parse_file/1, parse_file/3]).
+-export([parse_file/1, parse_file/3, parse_file/4]).
-export([interpret_file_attribute/1]).
-export([normalize_typed_record_fields/1,restore_typed_record_fields/1]).
@@ -54,12 +54,14 @@
%% open(FileName, IncludePath)
%% open(FileName, IncludePath, PreDefMacros)
+%% open(FileName, StartLocation, IncludePath, PredefMacros)
%% open(FileName, IoDevice, StartLocation, IncludePath, PreDefMacros)
%% close(Epp)
%% scan_erl_form(Epp)
%% parse_erl_form(Epp)
%% parse_file(Epp)
%% parse_file(FileName, IncludePath, PreDefMacros)
+%% parse_file(FileName, StartLocation, IncludePath, PreDefMacros)
%% macro_defs(Epp)
-spec open(FileName, IncludePath) ->
@@ -81,8 +83,20 @@ open(Name, Path) ->
ErrorDescriptor :: term().
open(Name, Path, Pdm) ->
+ open(Name, 1, Path, Pdm).
+
+-spec open(FileName, StartLocation, IncludePath, PredefMacros) ->
+ {'ok', Epp} | {'error', ErrorDescriptor} when
+ FileName :: file:name(),
+ StartLocation :: erl_scan:location(),
+ IncludePath :: [DirectoryName :: file:name()],
+ PredefMacros :: macros(),
+ Epp :: epp_handle(),
+ ErrorDescriptor :: term().
+
+open(Name, StartLocation, Path, Pdm) ->
Self = self(),
- Epp = spawn(fun() -> server(Self, Name, Path, Pdm) end),
+ Epp = spawn(fun() -> server(Self, Name, StartLocation, Path, Pdm) end),
epp_request(Epp).
open(Name, File, StartLocation, Path, Pdm) ->
@@ -178,7 +192,21 @@ format_error(E) -> file:format_error(E).
OpenError :: file:posix() | badarg | system_limit.
parse_file(Ifile, Path, Predefs) ->
- case open(Ifile, Path, Predefs) of
+ parse_file(Ifile, 1, Path, Predefs).
+
+-spec parse_file(FileName, StartLocation, IncludePath, PredefMacros) ->
+ {'ok', [Form]} | {error, OpenError} when
+ FileName :: file:name(),
+ StartLocation :: erl_scan:location(),
+ IncludePath :: [DirectoryName :: file:name()],
+ Form :: erl_parse:abstract_form() | {'error', ErrorInfo} | {'eof',Line},
+ PredefMacros :: macros(),
+ Line :: erl_scan:line(),
+ ErrorInfo :: erl_scan:error_info() | erl_parse:error_info(),
+ OpenError :: file:posix() | badarg | system_limit.
+
+parse_file(Ifile, StartLocation, Path, Predefs) ->
+ case open(Ifile, StartLocation, Path, Predefs) of
{ok,Epp} ->
Forms = parse_file(Epp),
close(Epp),
@@ -245,14 +273,12 @@ restore_typed_record_fields([{attribute,La,type,{{record,Record},Fields,[]}}|
restore_typed_record_fields([Form|Forms]) ->
[Form|restore_typed_record_fields(Forms)].
-%% server(StarterPid, FileName, Path, PreDefMacros)
-
-server(Pid, Name, Path, Pdm) ->
+%% server(StarterPid, FileName, Location, Path, PreDefMacros)
+server(Pid, Name, AtLocation, Path, Pdm) ->
process_flag(trap_exit, true),
case file:open(Name, [read]) of
{ok,File} ->
- Location = 1,
- init_server(Pid, Name, File, Location, Path, Pdm, false);
+ init_server(Pid, Name, File, AtLocation, Path, Pdm, false);
{error,E} ->
epp_reply(Pid, {error,E})
end.
diff --git a/lib/stdlib/src/erl_scan.erl b/lib/stdlib/src/erl_scan.erl
index 10b2ed2e49..be64b428b1 100644
--- a/lib/stdlib/src/erl_scan.erl
+++ b/lib/stdlib/src/erl_scan.erl
@@ -55,7 +55,7 @@
token_info/1,token_info/2,
attributes_info/1,attributes_info/2,set_attribute/3]).
--export_type([error_info/0, line/0, tokens_result/0]).
+-export_type([error_info/0, line/0, location/0, tokens_result/0]).
%%%
%%% Defines and type definitions