Skip to content
Browse files

added specific exceptions for unknown attributes

git-svn-id: http://svn.ulf.wiger.net/parse_trans/branches/0.2/parse_trans@23 ae7daa23-5771-0410-ae54-ec81a0701e84
  • Loading branch information...
1 parent 11201b9 commit df4c57405a7fb7b4c68699ad5e6e0bbd0a11f8be uwiger committed Jan 10, 2010
Showing with 30 additions and 15 deletions.
  1. +1 −1 doc/ct_expand.html
  2. +1 −1 doc/exprecs.html
  3. +1 −1 doc/overview-summary.html
  4. +1 −1 doc/parse_trans.html
  5. +23 −8 src/exprecs.erl
  6. +3 −3 src/parse_trans.erl
View
2 doc/ct_expand.html
@@ -25,6 +25,6 @@ <h3 class="function"><a name="parse_transform-2">parse_transform/2</a></h3>
<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Jan 7 2010, 18:38:41.</i></p>
+<p><i>Generated by EDoc, Jan 10 2010, 19:56:29.</i></p>
</body>
</html>
View
2 doc/exprecs.html
@@ -99,6 +99,6 @@ <h3 class="function"><a name="parse_transform-2">parse_transform/2</a></h3>
<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Jan 7 2010, 18:38:41.</i></p>
+<p><i>Generated by EDoc, Jan 10 2010, 19:56:29.</i></p>
</body>
</html>
View
2 doc/overview-summary.html
@@ -63,6 +63,6 @@
<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Jan 7 2010, 18:38:41.</i></p>
+<p><i>Generated by EDoc, Jan 10 2010, 19:56:29.</i></p>
</body>
</html>
View
2 doc/parse_trans.html
@@ -186,6 +186,6 @@ <h3 class="function"><a name="transform-4">transform/4</a></h3>
<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Jan 7 2010, 18:38:41.</i></p>
+<p><i>Generated by EDoc, Jan 10 2010, 19:56:29.</i></p>
</body>
</html>
View
31 src/exprecs.erl
@@ -133,10 +133,10 @@ parse_transform(Forms, Options) ->
parse_trans:top(fun do_transform/2, Forms, Options).
do_transform(Forms, Context) ->
- io:fwrite("in do_transform/2~n", []),
+%% io:fwrite("in do_transform/2~n", []),
Acc1 = versioned_records(
parse_trans:do_inspect(fun inspect_f/4, #pass1{}, Forms, Context)),
- io:fwrite("Acc1 = ~p~n", [Acc1]),
+%% io:fwrite("Acc1 = ~p~n", [Acc1]),
{Forms2, Acc2} =
parse_trans:do_transform(fun generate_f/4, Acc1, Forms, Context),
parse_trans:revert(verify_generated(Forms2, Acc2, Context)).
@@ -212,7 +212,7 @@ check_record_names(Es, L, #pass1{records = Rs}) ->
end.
versioned_records(#pass1{exports = Es, records = Rs} = Pass1) ->
- io:fwrite("versioned_records/1~n", []),
+%% io:fwrite("versioned_records/1~n", []),
case split_recnames(Rs) of
[] ->
Pass1#pass1{versions = []};
@@ -349,7 +349,8 @@ f_new_1(Rname, L) ->
}]}.
f_set_2(Rname, Flds, L) ->
- {function, L, fname(set, Rname), 2,
+ Fname = fname(set, Rname),
+ {function, L, Fname, 2,
[{clause, L, [{var, L, 'Vals'}, {var, L, 'Rec'}], [],
[{match, L, {var, L, 'F'},
{'fun', L,
@@ -372,11 +373,23 @@ f_set_2(Rname, Flds, L) ->
[{record_field, L,
{atom, L, Attr},
{var, L, 'V'}}]},
- {var, L, 'F1'}]}]} || Attr <- Flds]]}}},
+ {var, L, 'F1'}]}]} || Attr <- Flds]
+ ++ [{clause, L, [{var, L, 'Vs'}, {var,L,'R'},{var,L,'_'}],
+ [],
+ [bad_record_op(L, Fname, 'Vs', 'R')]}]
+ ]}}},
{call, L, {var, L, 'F'}, [{var, L, 'Vals'},
{var, L, 'Rec'},
{var, L, 'F'}]}]}]}.
+bad_record_op(L, Fname, Val, R) ->
+ {call, L, {remote, L, {atom,L,erlang}, {atom,L,error}},
+ [{atom,L,bad_record_op}, {cons, L, {atom, L, Fname},
+ {cons, L, {var, L, Val},
+ {cons, L, {var, L, R},
+ {nil, L}}}}]}.
+
+
f_fromlist_2(Rname, Flds, L) ->
Fname = fname(fromlist, Rname),
FldList = erl_parse:abstract(
@@ -432,7 +445,9 @@ f_get_2(Rname, Flds, L) ->
} |
[{clause, L, [{atom, L, Attr}, {var, L, 'R'}], [],
[{record_field, L, {var, L, 'R'}, Rname, {atom, L, Attr}}]} ||
- Attr <- Flds]]
+ Attr <- Flds]] ++
+ [{clause, L, [{var, L, 'Attr'}, {var, L, 'R'}], [],
+ [bad_record_op(L, FName, 'Attr', 'R')]}]
}.
@@ -493,8 +508,8 @@ f_info_3(Versions, L) ->
[],
[{call, L, {atom, L, fname(info,R,V)}, [{var, L, 'Info'}]}]} ||
{R,V} <- flat_versions(Versions)]},
- io:fwrite("Versions = ~p~n", [Versions]),
- io:fwrite("F = ~p~n", [F]),
+%% io:fwrite("Versions = ~p~n", [Versions]),
+%% io:fwrite("F = ~p~n", [F]),
F.
View
6 src/parse_trans.erl
@@ -201,9 +201,9 @@ function_exists(Fname, Arity, Forms) ->
#context{}.
initial_context(Forms, Options) ->
File = get_file(Forms),
- io:fwrite("File = ~p~n", [File]),
+%% io:fwrite("File = ~p~n", [File]),
Module = get_module(Forms),
- io:fwrite("Module = ~p~n", [Module]),
+%% io:fwrite("Module = ~p~n", [Module]),
#context{file = File,
module = Module,
options = Options}.
@@ -409,7 +409,7 @@ context(options, #context{options = O} ) -> O.
-spec do_inspect(insp_f(), term(), forms(), #context{}) ->
term().
do_inspect(F, Acc, Forms, Context) ->
- io:fwrite("do_inspect/4~n", []),
+%% io:fwrite("do_inspect/4~n", []),
F1 =
fun(Form, Acc0) ->
Type = type(Form),

0 comments on commit df4c574

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