aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-01-18 15:33:56 +0100
committerBjörn Gustavsson <[email protected]>2017-02-03 13:34:23 +0100
commitce431409d0daba5630e36173dcb751f0ab65e5bb (patch)
treebd5003cc65432db7752ac80d23cc1c9c540e36fe /lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl
parent5fa478d4550d8a55b3c89f8f6a7deef5b6fd9b0e (diff)
downloadotp-ce431409d0daba5630e36173dcb751f0ab65e5bb.tar.gz
otp-ce431409d0daba5630e36173dcb751f0ab65e5bb.tar.bz2
otp-ce431409d0daba5630e36173dcb751f0ab65e5bb.zip
Refactor code generation options
Most options to the code generation pass are passed through the process dictionary. At the same time, an Erule or Erules argument is passed to most code generation functions. The Erule argument is only an atom indicating the encoding rules ('ber', 'per', or 'uper'). Introduce a new record #gen{} to contain code generation options and parameters. Pass it as the Erule argument (renaming it to Gen in functions that we will have to touch anyway). In this commit, eliminate the use of the variable 'encoding_options' in the process dictionary.
Diffstat (limited to 'lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl')
-rw-r--r--lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl39
1 files changed, 18 insertions, 21 deletions
diff --git a/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl b/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl
index 325bea5879..cc1196c5cb 100644
--- a/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl
+++ b/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl
@@ -32,7 +32,7 @@
-include("asn1_records.hrl").
--import(asn1ct_gen, [emit/1,demit/1,get_record_name_prefix/0]).
+-import(asn1ct_gen, [emit/1,demit/1,get_record_name_prefix/1]).
-define(ASN1CT_GEN_BER,asn1ct_gen_ber_bin_v2).
@@ -225,7 +225,7 @@ gen_decode_sequence(Erules,Typename,D) when is_record(D,type) ->
_ ->
{false,false}
end,
- RecordName = lists:concat([get_record_name_prefix(),
+ RecordName = lists:concat([get_record_name_prefix(Erules),
asn1ct_gen:list2rname(Typename)]),
case gen_dec_sequence_call(Erules,Typename,CompList2,Ext,DecObjInf) of
no_terms -> % an empty sequence
@@ -405,7 +405,7 @@ gen_decode_set(Erules,Typename,D) when is_record(D,type) ->
asn1ct_name:new(tlv)
end,
- RecordName = lists:concat([get_record_name_prefix(),
+ RecordName = lists:concat([get_record_name_prefix(Erules),
asn1ct_gen:list2rname(Typename)]),
case gen_dec_sequence_call(Erules,Typename,CompList,Ext,DecObjInf) of
no_terms -> % an empty sequence
@@ -504,10 +504,8 @@ gen_decode_sof(Erules,TypeName,_InnerTypeName,D) when is_record(D,type) ->
emit([" || ",{curr,v}," <- ",{curr,tlv},"].",nl,nl,nl]).
-gen_encode_sof_components(Erules,Typename,SeqOrSetOf,Cont)
- when is_record(Cont,type)->
-
- {Objfun,Objfun_novar,EncObj} =
+gen_encode_sof_components(Gen, Typename, SeqOrSetOf, #type{}=Cont) ->
+ {Objfun,Objfun_novar,EncObj} =
case Cont#type.tablecinf of
[{objfun,_}|_R] ->
{", ObjFun",", _",{no_attr,"ObjFun"}};
@@ -517,20 +515,19 @@ gen_encode_sof_components(Erules,Typename,SeqOrSetOf,Cont)
emit(["'enc_",asn1ct_gen:list2name(Typename),
"_components'([]",Objfun_novar,", AccBytes, AccLen) -> ",nl]),
- case catch lists:member(der,get(encoding_options)) of
- true when SeqOrSetOf=='SET OF'->
+ case {Gen,SeqOrSetOf} of
+ {#gen{der=true},'SET OF'} ->
asn1ct_func:need({ber,dynamicsort_SETOF,1}),
emit([indent(3),
"{dynamicsort_SETOF(AccBytes),AccLen};",nl,nl]);
- _ ->
+ {_,_} ->
emit([indent(3),"{lists:reverse(AccBytes),AccLen};",nl,nl])
end,
emit(["'enc_",asn1ct_gen:list2name(Typename),
"_components'([H|T]",Objfun,",AccBytes, AccLen) ->",nl]),
TypeNameSuffix = asn1ct_gen:constructed_suffix(SeqOrSetOf,Cont#type.def),
- gen_enc_line(Erules,Typename,TypeNameSuffix,Cont,"H",3,
-% mandatory,"{EncBytes,EncLen} = ",EncObj),
- mandatory,EncObj),
+ gen_enc_line(Gen, Typename, TypeNameSuffix, Cont, "H", 3,
+ mandatory, EncObj),
emit([",",nl]),
emit([indent(3),"'enc_",asn1ct_gen:list2name(Typename),
"_components'(T",Objfun,","]),
@@ -1035,26 +1032,26 @@ gen_optormand_case('OPTIONAL', Erules, _TopType, _Cname, _Type, Element) ->
emit([indent(9),"asn1_NOVALUE -> {",
empty_lb(Erules),",0};",nl]),
emit([indent(9),"_ ->",nl,indent(12)]);
-gen_optormand_case({'DEFAULT',DefaultValue}, Erules, _TopType,
+gen_optormand_case({'DEFAULT',DefaultValue}, Gen, _TopType,
_Cname, Type, Element) ->
CurrMod = get(currmod),
- case catch lists:member(der,get(encoding_options)) of
- true ->
+ case Gen of
+ #gen{erule=ber,der=true} ->
asn1ct_gen_check:emit(Type, DefaultValue, Element);
- _ ->
+ #gen{erule=ber,der=false} ->
emit([" case ",Element," of",nl]),
emit([indent(9),"asn1_DEFAULT -> {",
- empty_lb(Erules),
+ empty_lb(Gen),
",0};",nl]),
case DefaultValue of
#'Externalvaluereference'{module=CurrMod,
value=V} ->
emit([indent(9),"?",{asis,V}," -> {",
- empty_lb(Erules),",0};",nl]);
+ empty_lb(Gen),",0};",nl]);
_ ->
emit([indent(9),{asis,
DefaultValue}," -> {",
- empty_lb(Erules),",0};",nl])
+ empty_lb(Gen),",0};",nl])
end,
emit([indent(9),"_ ->",nl,indent(12)])
end.
@@ -1429,7 +1426,7 @@ mkfuncname(TopType,Cname,WhatKind,Prefix,Suffix) ->
{F, "?MODULE", F}
end.
-empty_lb(ber) ->
+empty_lb(#gen{erule=ber}) ->
"<<>>".
value_match(Index,Value) when is_atom(Value) ->