Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit a612e99fb5aaa934fe5a8591db0f083d7fa0b20a 1 parent 054b4fd
Kostis Sagonas authored February 05, 2010 bjorng committed February 10, 2010
50  lib/compiler/src/sys_pre_expand.erl
@@ -114,7 +114,7 @@ expand_pmod(Fs0, St0) ->
114 114
 	    St1 = St0#expand{exports=Xs, defined=Ds},
115 115
 	    {Fs2,St2} = add_instance(Ps, Fs1, St1),
116 116
 	    {Fs3,St3} = ensure_new(Base, Ps0, Fs2, St2),
117  
-            {Fs3,St3#expand{attributes = [{abstract, [true]}
  117
+            {Fs3,St3#expand{attributes = [{abstract, 0, [true]}
118 118
 					  | St3#expand.attributes]}}
119 119
     end.
120 120
 
@@ -173,7 +173,7 @@ define_functions(Forms, #expand{defined=Predef}=St) ->
173 173
     St#expand{defined=ordsets:from_list(Fs)}.
174 174
 
175 175
 module_attrs(St) ->
176  
-    {[{attribute,0,Name,Val} || {Name,Val} <- St#expand.attributes],St}.
  176
+    {[{attribute,Line,Name,Val} || {Name,Line,Val} <- St#expand.attributes],St}.
177 177
 
178 178
 module_predef_funcs(St) ->
179 179
     PreDef = [{module_info,0},{module_info,1}],
@@ -197,8 +197,8 @@ module_predef_funcs(St) ->
197 197
 forms([{attribute,_,file,_File}=F|Fs0], St0) ->
198 198
     {Fs,St1} = forms(Fs0, St0),
199 199
     {[F|Fs],St1};
200  
-forms([{attribute,_,Name,Val}|Fs0], St0) ->
201  
-    St1 = attribute(Name, Val, St0),
  200
+forms([{attribute,Line,Name,Val}|Fs0], St0) ->
  201
+    St1 = attribute(Name, Val, Line, St0),
202 202
     forms(Fs0, St1);
203 203
 forms([{function,L,N,A,Cs}|Fs0], St0) ->
204 204
     {Ff,St1} = function(L, N, A, Cs, St0),
@@ -207,30 +207,30 @@ forms([{function,L,N,A,Cs}|Fs0], St0) ->
207 207
 forms([_|Fs], St) -> forms(Fs, St);
208 208
 forms([], St) -> {[],St}.
209 209
 
210  
-%% attribute(Attribute, Value, State) -> State'.
  210
+%% attribute(Attribute, Value, Line, State) -> State'.
211 211
 %%  Process an attribute, this just affects the state.
212 212
 
213  
-attribute(module, {Module, As}, St) ->
  213
+attribute(module, {Module, As}, _L, St) ->
214 214
     M = package_to_string(Module),
215 215
     St#expand{module=list_to_atom(M),
216  
-              package = packages:strip_last(M),
  216
+              package=packages:strip_last(M),
217 217
               parameters=As};
218  
-attribute(module, Module, St) ->
  218
+attribute(module, Module, _L, St) ->
219 219
     M = package_to_string(Module),
220 220
     St#expand{module=list_to_atom(M),
221  
-              package = packages:strip_last(M)};
222  
-attribute(export, Es, St) ->
  221
+              package=packages:strip_last(M)};
  222
+attribute(export, Es, _L, St) ->
223 223
     St#expand{exports=union(from_list(Es), St#expand.exports)};
224  
-attribute(import, Is, St) ->
  224
+attribute(import, Is, _L, St) ->
225 225
     import(Is, St);
226  
-attribute(compile, C, St) when is_list(C) ->
  226
+attribute(compile, C, _L, St) when is_list(C) ->
227 227
     St#expand{compile=St#expand.compile ++ C};
228  
-attribute(compile, C, St) ->
  228
+attribute(compile, C, _L, St) ->
229 229
     St#expand{compile=St#expand.compile ++ [C]};
230  
-attribute(Name, Val, St) when is_list(Val) ->
231  
-    St#expand{attributes=St#expand.attributes ++ [{Name,Val}]};
232  
-attribute(Name, Val, St) ->
233  
-    St#expand{attributes=St#expand.attributes ++ [{Name,[Val]}]}.
  230
+attribute(Name, Val, Line, St) when is_list(Val) ->
  231
+    St#expand{attributes=St#expand.attributes ++ [{Name,Line,Val}]};
  232
+attribute(Name, Val, Line, St) ->
  233
+    St#expand{attributes=St#expand.attributes ++ [{Name,Line,[Val]}]}.
234 234
 
235 235
 function(L, N, A, Cs0, St0) ->
236 236
     {Cs,St} = clauses(Cs0, St0#expand{func=N,arity=A,fcount=0}),
@@ -299,10 +299,10 @@ pattern({match,Line,Pat1, Pat2}, St0) ->
299 299
     {TT,St2} = pattern(Pat1, St1),
300 300
     {{match,Line,TT,TH},St2};
301 301
 %% Compile-time pattern expressions, including unary operators.
302  
-pattern({op,Line,Op,A}, St) ->
303  
-    {erl_eval:partial_eval({op,Line,Op,A}),St};
304  
-pattern({op,Line,Op,L,R}, St) ->
305  
-    {erl_eval:partial_eval({op,Line,Op,L,R}),St}.
  302
+pattern({op,_Line,_Op,_A}=Op, St) ->
  303
+    {erl_eval:partial_eval(Op),St};
  304
+pattern({op,_Line,_Op,_L,_R}=Op, St) ->
  305
+    {erl_eval:partial_eval(Op),St}.
306 306
 
307 307
 pattern_list([P0|Ps0], St0) ->
308 308
     {P,St1} = pattern(P0, St0),
@@ -400,18 +400,18 @@ expr({'receive',Line,Cs0,To0,ToEs0}, St0) ->
400 400
     {{'receive',Line,Cs,To,ToEs},St3};
401 401
 expr({'fun',Line,Body}, St) ->
402 402
     fun_tq(Line, Body, St);
403  
-expr({call,Line,{atom,La,N},As0}, St0) ->
  403
+expr({call,Line,{atom,La,N}=Atom,As0}, St0) ->
404 404
     {As,St1} = expr_list(As0, St0),
405 405
     Ar = length(As),
406 406
     case erl_internal:bif(N, Ar) of
407 407
         true ->
408  
-            {{call,Line,{remote,La,{atom,La,erlang},{atom,La,N}},As},St1};
  408
+            {{call,Line,{remote,La,{atom,La,erlang},Atom},As},St1};
409 409
         false ->
410 410
             case imported(N, Ar, St1) of
411 411
                 {yes,Mod} ->
412  
-                    {{call,Line,{remote,La,{atom,La,Mod},{atom,La,N}},As},St1};
  412
+                    {{call,Line,{remote,La,{atom,La,Mod},Atom},As},St1};
413 413
                 no ->
414  
-                    {{call,Line,{atom,La,N},As},St1}
  414
+                    {{call,Line,Atom,As},St1}
415 415
             end
416 416
     end;
417 417
 expr({call,Line,{record_field,_,_,_}=M,As0}, St0) ->
4  lib/compiler/src/v3_core.erl
@@ -164,8 +164,8 @@ form({attribute,_,file,{File,_Line}}, {Fs,As,Es,Ws,_}, _Opts) ->
164 164
 form({attribute,_,_,_}=F, {Fs,As,Es,Ws,File}, _Opts) ->
165 165
     {Fs,[attribute(F)|As],Es,Ws,File}.
166 166
 
167  
-attribute({attribute,_,Name,Val}) ->
168  
-    {#c_literal{val=Name},#c_literal{val=Val}}.
  167
+attribute({attribute,Line,Name,Val}) ->
  168
+    {#c_literal{val=Name, anno=[Line]}, #c_literal{val=Val, anno=[Line]}}.
169 169
 
170 170
 function({function,_,Name,Arity,Cs0}, Es0, Ws0, File, Opts) ->
171 171
     %%ok = io:fwrite("~p - ", [{Name,Arity}]),

0 notes on commit a612e99

Please sign in to comment.
Something went wrong with that request. Please try again.