diff options
author | Björn Gustavsson <[email protected]> | 2012-01-03 13:44:17 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2012-03-14 11:04:45 +0100 |
commit | 982ce043282cfa9f118f13ce8b3abd989fa0c0f8 (patch) | |
tree | b26d42c5fc60225fec3c3a2323aef68034443b2e /lib | |
parent | 084b34086f8f2cf6bc7aa0075f82a487d161cc72 (diff) | |
download | otp-982ce043282cfa9f118f13ce8b3abd989fa0c0f8.tar.gz otp-982ce043282cfa9f118f13ce8b3abd989fa0c0f8.tar.bz2 otp-982ce043282cfa9f118f13ce8b3abd989fa0c0f8.zip |
v3_core: Don't put negative line numbers in annotations
In Core Erlang and later passes, compiler-generated code can be
indicated in two different ways: by negative line numbers and by
a 'compiler_generated' annotation.
Simplify the code and improve coverage by turning negative line
numbers positive and adding a 'compiler_generated' annotation in
the v3_core pass. That means that Core Erlang and latter passes
do not have deal with negative line numbers.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compiler/src/sys_core_fold.erl | 35 | ||||
-rw-r--r-- | lib/compiler/src/v3_codegen.erl | 2 | ||||
-rw-r--r-- | lib/compiler/src/v3_core.erl | 7 | ||||
-rw-r--r-- | lib/compiler/src/v3_kernel.erl | 17 |
4 files changed, 31 insertions, 30 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index 6a8fd8980c..4e67639805 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -2741,22 +2741,20 @@ add_bin_opt_info(Core, Term) -> end. add_warning(Core, Term) -> - Anno = core_lib:get_anno(Core), - case lists:member(compiler_generated, Anno) of - true -> ok; + case is_compiler_generated(Core) of + true -> + ok; false -> - case get_line(Anno) of - Line when Line >= 0 -> %Must be positive. - File = get_file(Anno), - Key = {?MODULE,warnings}, - case get(Key) of - [{File,[{Line,?MODULE,Term}]}|_] -> - ok; %We already have + Anno = core_lib:get_anno(Core), + Line = get_line(Anno), + File = get_file(Anno), + Key = {?MODULE,warnings}, + case get(Key) of + [{File,[{Line,?MODULE,Term}]}|_] -> + ok; %We already have %an identical warning. - Ws -> - put(Key, [{File,[{Line,?MODULE,Term}]}|Ws]) - end; - _ -> ok %Compiler-generated code. + Ws -> + put(Key, [{File,[{Line,?MODULE,Term}]}|Ws]) end end. @@ -2770,14 +2768,7 @@ get_file([]) -> "no_file". % should not happen is_compiler_generated(Core) -> Anno = core_lib:get_anno(Core), - case lists:member(compiler_generated, Anno) of - true -> true; - false -> - case get_line(Anno) of - Line when Line >= 0 -> false; - _ -> true - end - end. + member(compiler_generated, Anno). get_warnings() -> ordsets:from_list((erase({?MODULE,warnings}))). diff --git a/lib/compiler/src/v3_codegen.erl b/lib/compiler/src/v3_codegen.erl index 0b81cb33c9..36d35a8122 100644 --- a/lib/compiler/src/v3_codegen.erl +++ b/lib/compiler/src/v3_codegen.erl @@ -2054,7 +2054,7 @@ line_1(_, 0) -> %% Missing line number or line number 0. {line,[]}; line_1(Name, Line) -> - {line,[{location,Name,abs(Line)}]}. + {line,[{location,Name,Line}]}. find_loc([Line|T], File, _) when is_integer(Line) -> find_loc(T, File, Line); diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl index 6885405ae0..ad0a8a7654 100644 --- a/lib/compiler/src/v3_core.erl +++ b/lib/compiler/src/v3_core.erl @@ -2085,7 +2085,12 @@ bitstr_vars(Segs, Vs) -> lineno_anno(L, St) -> {line, Line} = erl_parse:get_attribute(L, line), - [Line] ++ St#core.file. + if + Line < 0 -> + [-Line] ++ St#core.file ++ [compiler_generated]; + true -> + [Line] ++ St#core.file + end. get_ianno(Ce) -> case get_anno(Ce) of diff --git a/lib/compiler/src/v3_kernel.erl b/lib/compiler/src/v3_kernel.erl index 9d1839708f..abe94ad991 100644 --- a/lib/compiler/src/v3_kernel.erl +++ b/lib/compiler/src/v3_kernel.erl @@ -926,9 +926,11 @@ maybe_add_warning([C|_], MatchAnno, St) -> maybe_add_warning([], _MatchAnno, St) -> St; maybe_add_warning(fail, _MatchAnno, St) -> St; maybe_add_warning(Ke, MatchAnno, St) -> - case get_kanno(Ke) of - [compiler_generated|_] -> St; - Anno -> + case is_compiler_generated(Ke) of + true -> + St; + false -> + Anno = get_kanno(Ke), Line = get_line(Anno), MatchLine = get_line(MatchAnno), Warn = case MatchLine of @@ -1830,7 +1832,10 @@ format_error(bad_call) -> add_warning(none, Term, Anno, #kern{ws=Ws}=St) -> File = get_file(Anno), St#kern{ws=[{File,[{?MODULE,Term}]}|Ws]}; -add_warning(Line, Term, Anno, #kern{ws=Ws}=St) when Line >= 0 -> +add_warning(Line, Term, Anno, #kern{ws=Ws}=St) -> File = get_file(Anno), - St#kern{ws=[{File,[{Line,?MODULE,Term}]}|Ws]}; -add_warning(_, _, _, St) -> St. + St#kern{ws=[{File,[{Line,?MODULE,Term}]}|Ws]}. + +is_compiler_generated(Ke) -> + Anno = get_kanno(Ke), + member(compiler_generated, Anno). |