diff options
author | Kostis Sagonas <[email protected]> | 2010-02-05 16:43:30 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-02-10 10:43:10 +0100 |
commit | a612e99fb5aaa934fe5a8591db0f083d7fa0b20a (patch) | |
tree | 51c9139b885bff3fed3d104263a18930e16dd734 /lib | |
parent | 054b4fdf69fbbdf4e47b555b4c73f524fc3eeec2 (diff) | |
download | otp-a612e99fb5aaa934fe5a8591db0f083d7fa0b20a.tar.gz otp-a612e99fb5aaa934fe5a8591db0f083d7fa0b20a.tar.bz2 otp-a612e99fb5aaa934fe5a8591db0f083d7fa0b20a.zip |
compiler: keep line numbers for attributes
In the future, we might want to generate warnings
for attributes, referring to them with line numbers.
sys_pre_expand used to replace line number for attributes
with 0. Change sys_pre_expand to retain the real line
number.
v3_core used to throw away the line numbers. Change
v3_core so that it retains the line numbers in annotations.
While at it, do some tidying as suggested by tidier.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compiler/src/sys_pre_expand.erl | 50 | ||||
-rw-r--r-- | lib/compiler/src/v3_core.erl | 4 |
2 files changed, 27 insertions, 27 deletions
diff --git a/lib/compiler/src/sys_pre_expand.erl b/lib/compiler/src/sys_pre_expand.erl index 78dd73e0a2..04c45a8c5d 100644 --- a/lib/compiler/src/sys_pre_expand.erl +++ b/lib/compiler/src/sys_pre_expand.erl @@ -114,7 +114,7 @@ expand_pmod(Fs0, St0) -> St1 = St0#expand{exports=Xs, defined=Ds}, {Fs2,St2} = add_instance(Ps, Fs1, St1), {Fs3,St3} = ensure_new(Base, Ps0, Fs2, St2), - {Fs3,St3#expand{attributes = [{abstract, [true]} + {Fs3,St3#expand{attributes = [{abstract, 0, [true]} | St3#expand.attributes]}} end. @@ -173,7 +173,7 @@ define_functions(Forms, #expand{defined=Predef}=St) -> St#expand{defined=ordsets:from_list(Fs)}. module_attrs(St) -> - {[{attribute,0,Name,Val} || {Name,Val} <- St#expand.attributes],St}. + {[{attribute,Line,Name,Val} || {Name,Line,Val} <- St#expand.attributes],St}. module_predef_funcs(St) -> PreDef = [{module_info,0},{module_info,1}], @@ -197,8 +197,8 @@ module_predef_funcs(St) -> forms([{attribute,_,file,_File}=F|Fs0], St0) -> {Fs,St1} = forms(Fs0, St0), {[F|Fs],St1}; -forms([{attribute,_,Name,Val}|Fs0], St0) -> - St1 = attribute(Name, Val, St0), +forms([{attribute,Line,Name,Val}|Fs0], St0) -> + St1 = attribute(Name, Val, Line, St0), forms(Fs0, St1); forms([{function,L,N,A,Cs}|Fs0], St0) -> {Ff,St1} = function(L, N, A, Cs, St0), @@ -207,30 +207,30 @@ forms([{function,L,N,A,Cs}|Fs0], St0) -> forms([_|Fs], St) -> forms(Fs, St); forms([], St) -> {[],St}. -%% attribute(Attribute, Value, State) -> State'. +%% attribute(Attribute, Value, Line, State) -> State'. %% Process an attribute, this just affects the state. -attribute(module, {Module, As}, St) -> +attribute(module, {Module, As}, _L, St) -> M = package_to_string(Module), St#expand{module=list_to_atom(M), - package = packages:strip_last(M), + package=packages:strip_last(M), parameters=As}; -attribute(module, Module, St) -> +attribute(module, Module, _L, St) -> M = package_to_string(Module), St#expand{module=list_to_atom(M), - package = packages:strip_last(M)}; -attribute(export, Es, St) -> + package=packages:strip_last(M)}; +attribute(export, Es, _L, St) -> St#expand{exports=union(from_list(Es), St#expand.exports)}; -attribute(import, Is, St) -> +attribute(import, Is, _L, St) -> import(Is, St); -attribute(compile, C, St) when is_list(C) -> +attribute(compile, C, _L, St) when is_list(C) -> St#expand{compile=St#expand.compile ++ C}; -attribute(compile, C, St) -> +attribute(compile, C, _L, St) -> St#expand{compile=St#expand.compile ++ [C]}; -attribute(Name, Val, St) when is_list(Val) -> - St#expand{attributes=St#expand.attributes ++ [{Name,Val}]}; -attribute(Name, Val, St) -> - St#expand{attributes=St#expand.attributes ++ [{Name,[Val]}]}. +attribute(Name, Val, Line, St) when is_list(Val) -> + St#expand{attributes=St#expand.attributes ++ [{Name,Line,Val}]}; +attribute(Name, Val, Line, St) -> + St#expand{attributes=St#expand.attributes ++ [{Name,Line,[Val]}]}. function(L, N, A, Cs0, St0) -> {Cs,St} = clauses(Cs0, St0#expand{func=N,arity=A,fcount=0}), @@ -299,10 +299,10 @@ pattern({match,Line,Pat1, Pat2}, St0) -> {TT,St2} = pattern(Pat1, St1), {{match,Line,TT,TH},St2}; %% Compile-time pattern expressions, including unary operators. -pattern({op,Line,Op,A}, St) -> - {erl_eval:partial_eval({op,Line,Op,A}),St}; -pattern({op,Line,Op,L,R}, St) -> - {erl_eval:partial_eval({op,Line,Op,L,R}),St}. +pattern({op,_Line,_Op,_A}=Op, St) -> + {erl_eval:partial_eval(Op),St}; +pattern({op,_Line,_Op,_L,_R}=Op, St) -> + {erl_eval:partial_eval(Op),St}. pattern_list([P0|Ps0], St0) -> {P,St1} = pattern(P0, St0), @@ -400,18 +400,18 @@ expr({'receive',Line,Cs0,To0,ToEs0}, St0) -> {{'receive',Line,Cs,To,ToEs},St3}; expr({'fun',Line,Body}, St) -> fun_tq(Line, Body, St); -expr({call,Line,{atom,La,N},As0}, St0) -> +expr({call,Line,{atom,La,N}=Atom,As0}, St0) -> {As,St1} = expr_list(As0, St0), Ar = length(As), case erl_internal:bif(N, Ar) of true -> - {{call,Line,{remote,La,{atom,La,erlang},{atom,La,N}},As},St1}; + {{call,Line,{remote,La,{atom,La,erlang},Atom},As},St1}; false -> case imported(N, Ar, St1) of {yes,Mod} -> - {{call,Line,{remote,La,{atom,La,Mod},{atom,La,N}},As},St1}; + {{call,Line,{remote,La,{atom,La,Mod},Atom},As},St1}; no -> - {{call,Line,{atom,La,N},As},St1} + {{call,Line,Atom,As},St1} end end; expr({call,Line,{record_field,_,_,_}=M,As0}, St0) -> diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl index a39a3c538f..746fce7578 100644 --- a/lib/compiler/src/v3_core.erl +++ b/lib/compiler/src/v3_core.erl @@ -164,8 +164,8 @@ form({attribute,_,file,{File,_Line}}, {Fs,As,Es,Ws,_}, _Opts) -> form({attribute,_,_,_}=F, {Fs,As,Es,Ws,File}, _Opts) -> {Fs,[attribute(F)|As],Es,Ws,File}. -attribute({attribute,_,Name,Val}) -> - {#c_literal{val=Name},#c_literal{val=Val}}. +attribute({attribute,Line,Name,Val}) -> + {#c_literal{val=Name, anno=[Line]}, #c_literal{val=Val, anno=[Line]}}. function({function,_,Name,Arity,Cs0}, Es0, Ws0, File, Opts) -> %%ok = io:fwrite("~p - ", [{Name,Arity}]), |