diff options
author | Björn Gustavsson <[email protected]> | 2013-02-21 11:11:41 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-05-31 14:52:14 +0200 |
commit | 23a99bfc9cde454b91e75f9cb1801666581b7051 (patch) | |
tree | 027a6c0da95d7c09e07c2fccf8ce185974f2eb44 /lib | |
parent | c42ce67e3fa3b2a43964761dc7d1d3177e259f72 (diff) | |
download | otp-23a99bfc9cde454b91e75f9cb1801666581b7051.tar.gz otp-23a99bfc9cde454b91e75f9cb1801666581b7051.tar.bz2 otp-23a99bfc9cde454b91e75f9cb1801666581b7051.zip |
Refactor decoding of items in SEQUENCEs and CHOICEs
We will need more explicit control of decoding of open types for
CHOICEs, so refactor the gen_dec_line() and gen_dec_line_imm()
to break out the decoding of the open types.
Note that gen_dec_line_special() will not generate correct code
if Ext =/= noext; thus, we can eliminate the Ext parameter.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asn1/src/asn1ct_constructed_per.erl | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/asn1/src/asn1ct_constructed_per.erl b/lib/asn1/src/asn1ct_constructed_per.erl index 9808d12811..7fc904ec16 100644 --- a/lib/asn1/src/asn1ct_constructed_per.erl +++ b/lib/asn1/src/asn1ct_constructed_per.erl @@ -1254,7 +1254,7 @@ gen_dec_comp_call(Comp, Erule, TopType, Tpos, OptTable, DecInfObj, St end end, - Lines = gen_dec_line_imm(Erule, TopType, Comp, Tpos, DecInfObj, Ext), + Lines = gen_dec_seq_line_imm(Erule, TopType, Comp, Tpos, DecInfObj, Ext), Postamble = case {Ext,Prop} of {noext,mandatory} -> @@ -1322,13 +1322,18 @@ gen_dec_component_no_val({ext,_,_},mandatory) -> emit({"asn1_NOVALUE"}). -gen_dec_line(Erule, TopType, Comp, Pos, Ext) -> - Imm0 = gen_dec_line_imm(Erule, TopType, Comp, Pos, false, Ext), +gen_dec_choice_line(Erule, TopType, Comp, Pos, Ext) -> + Pre = gen_dec_line_open_type(Erule, Ext, Pos), + Imm0 = gen_dec_line_imm(Erule, TopType, Comp, false, Pre), Init = {ignore,fun(_) -> {[],[]} end}, Imm = [{group,[Init|Imm0]}], emit_gen_dec_imm(Imm). -gen_dec_line_imm(Erule, TopType, Comp, Pos, DecInfObj, Ext) -> +gen_dec_seq_line_imm(Erule, TopType, Comp, Pos, DecInfObj, Ext) -> + Pre = gen_dec_line_open_type(Erule, Ext, Pos), + gen_dec_line_imm(Erule, TopType, Comp, DecInfObj, Pre). + +gen_dec_line_imm(Erule, TopType, Comp, DecInfObj, Pre) -> #'ComponentType'{name=Cname,typespec=Type} = Comp, Atype = case Type of @@ -1337,9 +1342,7 @@ gen_dec_line_imm(Erule, TopType, Comp, Pos, DecInfObj, Ext) -> _ -> asn1ct_gen:get_inner(Type#type.def) end, - - Pre = gen_dec_line_open_type(Erule, Ext, Pos), - Decode = gen_dec_line_special(Erule, Atype, TopType, Comp, DecInfObj, Ext), + Decode = gen_dec_line_special(Erule, Atype, TopType, Comp, DecInfObj), Post = fun({SaveBytes,Finish}) -> {AccTerm,AccBytes} = Finish(), @@ -1383,7 +1386,7 @@ gen_dec_line_open_type(_, _, _) -> end}. gen_dec_line_special(Erule, {typefield,_}, _TopType, Comp, - DecInfObj, Ext) -> + DecInfObj) -> #'ComponentType'{name=Cname,typespec=Type,prop=Prop} = Comp, fun({_BytesVar,PrevSt}) -> case DecInfObj of @@ -1415,7 +1418,7 @@ gen_dec_line_special(Erule, {typefield,_}, _TopType, Comp, %% objfun though arguments on function %% invocation. if - Ext == noext andalso Prop == mandatory -> + Prop =:= mandatory -> ok; true -> asn1ct_name:new(tmpterm), @@ -1429,7 +1432,7 @@ gen_dec_line_special(Erule, {typefield,_}, _TopType, Comp, asn1ct_imm:dec_code_gen(Imm, BytesVar), emit([com,nl]), if - Ext == noext andalso Prop == mandatory -> + Prop =:= mandatory -> emit([{curr,term}," =",nl," "]); true -> emit([" {"]) @@ -1446,7 +1449,7 @@ gen_dec_line_special(Erule, {typefield,_}, _TopType, Comp, emit([indent(6),{curr,tmpterm},nl]), emit([indent(2),"end"]), if - Ext == noext andalso Prop == mandatory -> + Prop =:= mandatory -> ok; true -> emit([",",nl,{curr,tmpbytes},"}"]) @@ -1466,7 +1469,7 @@ gen_dec_line_special(Erule, {typefield,_}, _TopType, Comp, end end; gen_dec_line_special(Erule, {objectfield,PrimFieldName1,PFNList}, _TopType, - Comp, _DecInfObj, _Ext) -> + Comp, _DecInfObj) -> fun({_BytesVar,PrevSt}) -> Imm = asn1ct_imm:per_dec_open_type(is_aligned(Erule)), BytesVar = asn1ct_gen:mk_var(asn1ct_name:curr(bytes)), @@ -1478,7 +1481,7 @@ gen_dec_line_special(Erule, {objectfield,PrimFieldName1,PFNList}, _TopType, Prop}], {SaveBytes,PrevSt} end; -gen_dec_line_special(Erule, Atype, TopType, Comp, DecInfObj, _Ext) -> +gen_dec_line_special(Erule, Atype, TopType, Comp, DecInfObj) -> case gen_dec_line_other(Erule, Atype, TopType, Comp) of Fun when is_function(Fun, 1) -> fun({BytesVar,PrevSt}) -> @@ -1683,10 +1686,10 @@ gen_dec_choice2(Erule, TopType, [H0|T], Pos, Sep0, Ext) -> case Type#type.def of #'ObjectClassFieldType'{type={typefield,_}} -> emit([Sep0,Pos," ->",nl]), - gen_dec_line(Erule, TopType, H, Pos+1, Ext); + gen_dec_choice_line(Erule, TopType, H, Pos+1, Ext); _ -> emit([Sep0,Pos," -> {",{asis,Cname},",",nl]), - gen_dec_line(Erule, TopType, H, Pos+1, Ext), + gen_dec_choice_line(Erule, TopType, H, Pos+1, Ext), emit("}") end, Sep = [";",nl], |