mirror of
https://github.com/valitydev/parse_trans.git
synced 2024-11-06 08:35:17 +00:00
fix record conversions + add example
This commit is contained in:
parent
e9d307f1fc
commit
5b2201f39f
23
examples/test_exprecs_vsns.erl
Normal file
23
examples/test_exprecs_vsns.erl
Normal file
@ -0,0 +1,23 @@
|
||||
-module(test_exprecs_vsns).
|
||||
|
||||
-export([f/0]).
|
||||
-export_records([r]).
|
||||
|
||||
-compile({parse_transform, exprecs}).
|
||||
|
||||
-record(r, {a,b,c}).
|
||||
-record(r__1_2, {a,b}).
|
||||
-record(r__1_1, {a,b,c,d}).
|
||||
|
||||
|
||||
f() ->
|
||||
io:fwrite("'#info-r'(fields) -> ~p~n", ['#info-r'(fields)]),
|
||||
io:fwrite("'#info-r__1_1'(fields)' -> ~p (not exported)~n",
|
||||
['#info-r__1_1'(fields)]),
|
||||
io:fwrite("'#info-r__1_2'(fields)' -> ~p (not exported)~n",
|
||||
['#info-r__1_2'(fields)]),
|
||||
io:fwrite("'#convert-'(\"1_1\", {r,1,2,3,4}) -> ~p~n",
|
||||
['#convert-'("1_1", {r,1,2,3,4})]),
|
||||
io:fwrite("'#convert-'(\"1_1\", {r,1,2,3,4}) -> ~p~n",
|
||||
['#convert-'("1_2", {r,1,2})]).
|
||||
|
@ -627,7 +627,7 @@ get_flds(Rname, #pass1{records = Rs}) ->
|
||||
fname_prefix(Op, #pass1{prefix = Pat}) ->
|
||||
lists:flatten(
|
||||
lists:map(fun(operation) -> str(Op);
|
||||
(X) -> X
|
||||
(X) -> str(X)
|
||||
end, Pat)).
|
||||
%% fname_prefix(Op, #pass1{} = Acc) ->
|
||||
%% case Op of
|
||||
@ -659,10 +659,10 @@ fname(Op, Rname, #pass1{fname = FPat} = Acc) ->
|
||||
Prefix = fname_prefix(Op, Acc),
|
||||
list_to_atom(
|
||||
lists:flatten(
|
||||
lists:map(fun(prefix) -> Prefix;
|
||||
lists:map(fun(prefix) -> str(Prefix);
|
||||
(record) -> str(Rname);
|
||||
(operation) -> str(Op);
|
||||
(X) -> X
|
||||
(X) -> str(X)
|
||||
end, FPat))).
|
||||
%% list_to_atom(fname_prefix(Op, Rname, Acc)).
|
||||
|
||||
@ -672,8 +672,9 @@ fname(Op, Rname, V, #pass1{vfname = VPat} = Acc) ->
|
||||
lists:map(fun(prefix) -> fname_prefix(Op, Acc);
|
||||
(operation) -> str(Op);
|
||||
(record) -> str(Rname);
|
||||
(version) -> V;
|
||||
(fname) -> fname(Op, Rname, Acc)
|
||||
(version) -> str(V);
|
||||
(fname) -> str(fname(Op, Rname, Acc));
|
||||
(X) -> str(X)
|
||||
end, VPat))).
|
||||
%% list_to_atom(fname_prefix(Op, Rname, Acc) ++ "__" ++ V).
|
||||
|
||||
@ -1120,19 +1121,13 @@ f_convert(_Vsns, L, Acc) ->
|
||||
{call, L, {atom, L, size},
|
||||
[{var, L, 'Rec'}]}},
|
||||
%%
|
||||
{match, L, {var, L, 'Old_fields'},
|
||||
{call, L, {atom,L,fname(info, Acc)},
|
||||
[{var,L,'Rname'},{atom,L,fields},{var,L,'FromVsn'}]}},
|
||||
%% {match, L, {var, L, 'Old_fields'},
|
||||
%% {call, L, {atom,L,fname(info, Acc)},
|
||||
%% [{var,L,'Rname'},{atom,L,fields},{var,L,'FromVsn'}]}},
|
||||
{match, L, {var, L, 'New_fields'},
|
||||
{call, L, {atom,L,fname(info, Acc)},
|
||||
[{var,L,'Rname'},{atom,L,fields}]}},
|
||||
{match, L, {var, L, 'Common_fields'},
|
||||
{op, L, '--',
|
||||
{var, L, 'Old_fields'},
|
||||
{op, L, '--',
|
||||
{var, L, 'Old_fields'},
|
||||
{var, L, 'New_fields'}}}},
|
||||
%%
|
||||
|
||||
{match, L, {var, L, 'Values'},
|
||||
{call, L, {remote, L, {atom, L, lists}, {atom, L, zip}},
|
||||
[{call, L, {atom,L,fname(info, Acc)},
|
||||
|
Loading…
Reference in New Issue
Block a user