aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-06-05 06:47:11 +0200
committerBjörn Gustavsson <[email protected]>2013-08-30 10:13:16 +0200
commit72713a28d5e1bcc22e4be3650504b7ea9dd90b29 (patch)
tree9d21acb5f99e41eddfb14004abaa34e3c160a9a8 /lib
parent060bd359237cdb629abba03620323c0ed8084910 (diff)
downloadotp-72713a28d5e1bcc22e4be3650504b7ea9dd90b29.tar.gz
otp-72713a28d5e1bcc22e4be3650504b7ea9dd90b29.tar.bz2
otp-72713a28d5e1bcc22e4be3650504b7ea9dd90b29.zip
Clean up handling of extension addition groups
Break out the code to a separate function to make it more readable. Also avoid hard-coding the name of the value to use as "Val1" as it may not be true in the future. Instead of using a list comprenhension like this: case [X || X <- [element(5, Val),element(6, Val)], X =/= asn1_NOVALUE] of [] -> ...; _ -> ... end use an orelse chain: case element(5, Val) =/= asn1_NOVALUE orelse element(5, Val) =/= asn1_NOVALUE of false -> ...; true -> ... end
Diffstat (limited to 'lib')
-rw-r--r--lib/asn1/src/asn1ct_constructed_per.erl54
1 files changed, 29 insertions, 25 deletions
diff --git a/lib/asn1/src/asn1ct_constructed_per.erl b/lib/asn1/src/asn1ct_constructed_per.erl
index 8eb6b91d01..463de965d7 100644
--- a/lib/asn1/src/asn1ct_constructed_per.erl
+++ b/lib/asn1/src/asn1ct_constructed_per.erl
@@ -97,31 +97,7 @@ gen_encode_constructed(Erule,Typename,D) when is_record(D,type) ->
Ext = extensible_enc(CompList),
case Ext of
{ext,_,NumExt} when NumExt > 0 ->
- case extgroup_pos_and_length(CompList) of
- {extgrouppos,[]} -> % no extenstionAdditionGroup
- ok;
- {extgrouppos,ExtGroupPosLenList} ->
- ExtGroupFun =
- fun({ExtActualGroupPos,ExtGroupVirtualPos,ExtGroupLen}) ->
- Elements =
- make_elements(ExtGroupVirtualPos+1,
- "Val1",
- lists:seq(1,ExtGroupLen)),
- emit([
- {next,val}," = case [X || X <- [",Elements,
- "],X =/= asn1_NOVALUE] of",nl,
- "[] -> setelement(",
- {asis,ExtActualGroupPos+1},",",
- {curr,val},",",
- "asn1_NOVALUE);",nl,
- "_ -> setelement(",{asis,ExtActualGroupPos+1},",",
- {curr,val},",",
- "{extaddgroup,", Elements,"})",nl,
- "end,",nl]),
- asn1ct_name:new(val)
- end,
- lists:foreach(ExtGroupFun,ExtGroupPosLenList)
- end,
+ gen_encode_extaddgroup(CompList),
asn1ct_name:new(tmpval),
emit(["Extensions = ",
{call,Erule,fixextensions,[{asis,Ext},{curr,val}]},
@@ -194,6 +170,34 @@ gen_encode_constructed(Erule,Typename,D) when is_record(D,type) ->
gen_enc_components_call(Erule,Typename,CompList,MaybeComma2,EncObj,Ext),
emit({"].",nl}).
+gen_encode_extaddgroup(CompList) ->
+ case extgroup_pos_and_length(CompList) of
+ {extgrouppos,[]} ->
+ ok;
+ {extgrouppos,ExtGroupPosLenList} ->
+ _ = [do_gen_encode_extaddgroup(G) || G <- ExtGroupPosLenList],
+ ok
+ end.
+
+do_gen_encode_extaddgroup({ActualGroupPos,GroupVirtualPos,GroupLen}) ->
+ Val = asn1ct_gen:mk_var(asn1ct_name:curr(val)),
+ Elements = make_elements(GroupVirtualPos+1,
+ Val,
+ lists:seq(1, GroupLen)),
+ Expr = any_non_value(GroupVirtualPos+1, Val, GroupLen, ""),
+ emit([{next,val}," = case ",Expr," of",nl,
+ "false -> setelement(",{asis,ActualGroupPos+1},", ",
+ {curr,val},", asn1_NOVALUE);",nl,
+ "true -> setelement(",{asis,ActualGroupPos+1},", ",
+ {curr,val},", {extaddgroup,", Elements,"})",nl,
+ "end,",nl]),
+ asn1ct_name:new(val).
+
+any_non_value(_, _, 0, _) ->
+ [];
+any_non_value(Pos, Val, N, Sep) ->
+ Sep ++ [make_element(Pos, Val)," =/= asn1_NOVALUE"] ++
+ any_non_value(Pos+1, Val, N-1, [" orelse",nl]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% generate decode function for SEQUENCE and SET