diff options
author | Kenneth Lundin <[email protected]> | 2012-06-08 13:26:41 +0200 |
---|---|---|
committer | Kenneth Lundin <[email protected]> | 2012-06-08 13:27:40 +0200 |
commit | b4b4c6299d3926e55b042ea45f55adaeec41cb6f (patch) | |
tree | 23fb9c48a109397a4aa9bd68b70a07a6cd9cf086 /lib/asn1/src | |
parent | 9cfeeb9b7e66a3345cbc0e5b4b634cb5965635fc (diff) | |
parent | be01ab6d2cad9d5b139b36c79b1c7addd57d5265 (diff) | |
download | otp-b4b4c6299d3926e55b042ea45f55adaeec41cb6f.tar.gz otp-b4b4c6299d3926e55b042ea45f55adaeec41cb6f.tar.bz2 otp-b4b4c6299d3926e55b042ea45f55adaeec41cb6f.zip |
Merge branch 'kenneth/asn1/multiple_extaddgroup/OTP-10058' into maint
* kenneth/asn1/multiple_extaddgroup/OTP-10058:
Add support for multiple ExtensionAdditionGroups
Diffstat (limited to 'lib/asn1/src')
-rw-r--r-- | lib/asn1/src/asn1ct_check.erl | 20 | ||||
-rw-r--r-- | lib/asn1/src/asn1ct_constructed_per.erl | 156 | ||||
-rw-r--r-- | lib/asn1/src/asn1ct_gen_per.erl | 24 | ||||
-rw-r--r-- | lib/asn1/src/asn1ct_gen_per_rt2ct.erl | 24 | ||||
-rw-r--r-- | lib/asn1/src/asn1ct_parser2.erl | 6 |
5 files changed, 131 insertions, 99 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index 187339fb53..494a2eddd9 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -5991,17 +5991,25 @@ generate_automatic_tags1([H|T],[TagNo|TagNos]) when is_record(H,'ComponentType') type={default,'IMPLICIT'}, form= 0 }]}, % PRIMITIVE [H#'ComponentType'{typespec=NewTs}|generate_automatic_tags1(T,[TagNo+1|TagNos])]; -generate_automatic_tags1([ExtMark|T],[_TagNo|TagNos]) -> % EXTENSIONMARK +generate_automatic_tags1([ExtMark = #'EXTENSIONMARK'{}|T],[_TagNo|TagNos]) -> [ExtMark | generate_automatic_tags1(T,TagNos)]; +generate_automatic_tags1([H|T],TagList) -> % ExtensionAdditionGroup etc are just ignored + [H | generate_automatic_tags1(T,TagList)]; generate_automatic_tags1([],_) -> []. -any_manual_tag([#'ComponentType'{typespec=#type{tag=[]}}|Rest]) -> - any_manual_tag(Rest); -any_manual_tag([#'EXTENSIONMARK'{}|Rest]) -> - any_manual_tag(Rest); -any_manual_tag([_|_Rest]) -> +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Returns true if there is at least one ComponentType with a manually +%% specified tag. No manual tag is indicated by typespec=#type{tag=[]} +%% so we check if we find a tag =/= [] and return true in that case +%% all other things in the componentlist like (EXTENSIONMARK, +%% ExtensionAdditionGroup,...) except ComponentType is simply +%% ignored/skipped +any_manual_tag([#'ComponentType'{typespec=#type{tag=Tag}}|_Rest]) + when Tag =/= []-> true; +any_manual_tag([_|Rest]) -> + any_manual_tag(Rest); any_manual_tag([]) -> false. diff --git a/lib/asn1/src/asn1ct_constructed_per.erl b/lib/asn1/src/asn1ct_constructed_per.erl index e07680f10b..5f5138ef23 100644 --- a/lib/asn1/src/asn1ct_constructed_per.erl +++ b/lib/asn1/src/asn1ct_constructed_per.erl @@ -100,18 +100,26 @@ gen_encode_constructed(Erule,Typename,D) when is_record(D,type) -> case Ext of {ext,_,NumExt} when NumExt > 0 -> case extgroup_pos_and_length(CompList) of - {extgrouppos,ExtGroupPos,ExtGroupLen} -> - Elements = make_elements(ExtGroupPos+1, - "Val1",lists:seq(1,ExtGroupLen)), - emit([ - {next,val}," = case [X || X <- [",Elements, - "],X =/= asn1_NOVALUE] of",nl, - "[] -> ",{curr,val},";",nl, - "_ -> setelement(",{asis,ExtGroupPos+1},",", - {curr,val},",", - "{extaddgroup,", Elements,"})",nl, - "end,",nl]), - asn1ct_name:new(val); + {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, + "[] -> ",{curr,val},";",nl, + "_ -> setelement(",{asis,ExtActualGroupPos+1},",", + {curr,val},",", + "{extaddgroup,", Elements,"})",nl, + "end,",nl]), + asn1ct_name:new(val) + end, + lists:foreach(ExtGroupFun,ExtGroupPosLenList); _ -> % no extensionAdditionGroup ok end, @@ -279,9 +287,9 @@ gen_decode_constructed(Erules,Typename,D) when is_record(D,type) -> {false,false,false} end end, - NewCompList = wrap_compList(CompList), +%% NewCompList = wrap_compList(CompList), {AccTerm,AccBytes} = - gen_dec_components_call(Erules,Typename,NewCompList,MaybeComma2,DecObjInf,Ext,length(Optionals)), + gen_dec_components_call(Erules,Typename,CompList,MaybeComma2,DecObjInf,Ext,length(Optionals)), case asn1ct_name:all(term) of [] -> emit(MaybeComma2); % no components at all _ -> emit({com,nl}) @@ -689,24 +697,28 @@ ext_length([],_,Acc) -> Acc. extgroup_pos_and_length(CompList) when is_list(CompList) -> - noextgroup; + {extgrouppos,[]}; extgroup_pos_and_length({RootList,ExtList}) -> - extgrouppos(ExtList,length(RootList)+1); -extgroup_pos_and_length({Rl1,Ext,_Rl2}) -> - extgrouppos(Ext,length(Rl1)+1). - -extgrouppos([{'ExtensionAdditionGroup',_Num}|T],Pos) -> - extgrouppos(T,Pos,0); -extgrouppos([_|T],Pos) -> - extgrouppos(T,Pos+1); -extgrouppos([],_) -> - noextgroup. - -extgrouppos(['ExtensionAdditionGroupEnd'|_T],Pos,Len) -> - {extgrouppos,Pos,Len}; -extgrouppos([_|T],Pos,Len) -> - extgrouppos(T,Pos,Len+1). - + ActualPos = length(RootList) +1, + %% position to get and deliver data in the record to the user + VirtualPos = ActualPos, + %% position to encode/decode the extaddgroup as an opentype sequence + extgrouppos(ExtList,ActualPos,VirtualPos,[]); +extgroup_pos_and_length({RootList,ExtList,_Rl2}) -> + extgroup_pos_and_length({RootList,ExtList}). + +extgrouppos([{'ExtensionAdditionGroup',_Num}|T],ActualPos,VirtualPos,Acc) -> + extgrouppos(T,ActualPos,VirtualPos,0,Acc); +extgrouppos([_|T],ActualPos,VirtualPos,Acc) -> + extgrouppos(T,ActualPos+1,VirtualPos+1,Acc); +extgrouppos([],_,_,Acc) -> + {extgrouppos,lists:reverse(Acc)}. + +extgrouppos(['ExtensionAdditionGroupEnd'|T],ActualPos,VirtualPos,Len,Acc) -> + extgrouppos(T,ActualPos+1,VirtualPos+Len,[{ActualPos,VirtualPos,Len}|Acc]); +extgrouppos([_|T],ActualPos,VirtualPos,Len,Acc) -> + extgrouppos(T,ActualPos,VirtualPos,Len+1,Acc). + gen_dec_extension_value(_) -> @@ -817,19 +829,21 @@ add_textual_order1(Cs,NumIn) -> end, NumIn,Cs). -gen_enc_components_call(Erule,TopType,{Root1,ExtList,Root2},MaybeComma,DynamicEnc,Ext) -> - gen_enc_components_call(Erule,TopType,{Root1++Root2,ExtList},MaybeComma,DynamicEnc,Ext); -gen_enc_components_call(Erule,TopType,{CompList,ExtList},MaybeComma,DynamicEnc,Ext) -> +gen_enc_components_call(Erule,TopType,{Root,ExtList},MaybeComma,DynamicEnc,Ext) -> + gen_enc_components_call(Erule,TopType,{Root,ExtList,[]},MaybeComma,DynamicEnc,Ext); +gen_enc_components_call(Erule,TopType,CL={Root,ExtList,Root2},MaybeComma,DynamicEnc,Ext) -> %% The type has extensionmarker - Rpos = gen_enc_components_call1(Erule,TopType,CompList,1,MaybeComma,DynamicEnc,noext), + Rpos = gen_enc_components_call1(Erule,TopType,Root++Root2,1,MaybeComma,DynamicEnc,noext), case Ext of {ext,_,ExtNum} when ExtNum > 0 -> emit([nl, ",Extensions",nl]); + _ -> true end, %handle extensions - NewExtList = wrap_extensionAdditionGroups(ExtList), + {extgrouppos,ExtGroupPosLen} = extgroup_pos_and_length(CL), + NewExtList = wrap_extensionAdditionGroups(ExtList,ExtGroupPosLen), gen_enc_components_call1(Erule,TopType,NewExtList,Rpos,MaybeComma,DynamicEnc,Ext); gen_enc_components_call(Erule,TopType, CompList, MaybeComma, DynamicEnc, Ext) -> %% The type has no extensionmarker @@ -938,7 +952,7 @@ gen_enc_line(Erule,TopType,Cname,Type,Element, _Pos,DynamicEnc,Ext) -> Atype = case Type of #type{def=#'ObjectClassFieldType'{type=InnerType}} -> - InnerType; + InnerType; _ -> asn1ct_gen:get_inner(Type#type.def) end, @@ -948,6 +962,7 @@ gen_enc_line(Erule,TopType,Cname,Type,Element, _Pos,DynamicEnc,Ext) -> emit(["?RT_PER:encode_open_type(dummy,?RT_PER:complete("]); _ -> true end, + case Atype of {typefield,_} -> case DynamicEnc of @@ -1023,20 +1038,22 @@ gen_enc_line(Erule,TopType,Cname,Type,Element, _Pos,DynamicEnc,Ext) -> emit("))"); _ -> true end. -gen_dec_components_call(Erule,TopType,{Root1,ExtList,Root2},MaybeComma,DecInfObj,Ext,NumberOfOptionals) -> - gen_dec_components_call(Erule,TopType,{Root1++Root2,ExtList},MaybeComma,DecInfObj,Ext,NumberOfOptionals); -gen_dec_components_call(Erule,TopType,{CompList,ExtList},MaybeComma, +gen_dec_components_call(Erule,TopType,{Root,ExtList},MaybeComma, DecInfObj,Ext,NumberOfOptionals) -> + gen_dec_components_call(Erule,TopType,{Root,ExtList,[]},MaybeComma,DecInfObj,Ext,NumberOfOptionals); +gen_dec_components_call(Erule,TopType,CL={Root1,ExtList,Root2},MaybeComma,DecInfObj,Ext,NumberOfOptionals) -> %% The type has extensionmarker - OptTable = create_optionality_table(CompList), + + OptTable = create_optionality_table(Root1++Root2), {Rpos,AccTerm,AccBytes} = - gen_dec_components_call1(Erule,TopType, CompList, 1, OptTable, + gen_dec_components_call1(Erule,TopType, Root1++Root2, 1, OptTable, MaybeComma,DecInfObj,noext,[],[], NumberOfOptionals), emit([",",nl,"{Extensions,",{next,bytes},"} = "]), emit(["?RT_PER:getextension(Ext,",{curr,bytes},"),",nl]), asn1ct_name:new(bytes), - NewExtList = wrap_extensionAdditionGroups(ExtList), + {extgrouppos,ExtGroupPosLen} = extgroup_pos_and_length(CL), + NewExtList = wrap_extensionAdditionGroups(ExtList,ExtGroupPosLen), {_Epos,AccTermE,AccBytesE} = gen_dec_components_call1(Erule,TopType,NewExtList,Rpos, OptTable, "",DecInfObj,Ext,[],[],NumberOfOptionals), @@ -1233,8 +1250,7 @@ gen_dec_line(Erule,TopType,Cname,Type,Pos,DecInfObj,Ext,Prop) -> "} = ?RT_PER:decode_open_type(",{curr,bytes}, ", []),",nl]), emit([indent(2),"case (catch ObjFun(", - {asis,Name}, - ",",{curr,tmpterm},",telltype,", + {asis,Name},",",{curr,tmpterm},",telltype,", {asis,RestFieldNames},")) of", nl]), emit([indent(4),"{'EXIT',",{curr,reason},"} ->",nl]), emit([indent(6),"exit({'Type not ", @@ -1596,42 +1612,44 @@ flat_complist({Rl1,El,Rl2}) -> Rl1 ++ El ++ Rl2; flat_complist({Rl,El}) -> Rl ++ El; flat_complist(CompList) -> CompList. -wrap_compList({Root1,Ext,Root2}) -> - {Root1,wrap_extensionAdditionGroups(Ext),Root2}; -wrap_compList({Root1,Ext}) -> - {Root1,wrap_extensionAdditionGroups(Ext)}; -wrap_compList(CompList) -> - CompList. +%%wrap_compList({Root1,Ext,Root2}) -> +%% {Root1,wrap_extensionAdditionGroups(Ext),Root2}; +%%wrap_compList({Root1,Ext}) -> +%% {Root1,wrap_extensionAdditionGroups(Ext)}; +%%wrap_compList(CompList) -> +%% CompList. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Will convert all componentTypes following 'ExtensionAdditionGroup' %% up to the matching 'ExtensionAdditionGroupEnd' into one componentType %% of type SEQUENCE with the componentTypes as components %% -wrap_extensionAdditionGroups(ExtCompList) -> - wrap_extensionAdditionGroups(ExtCompList,[],0). +wrap_extensionAdditionGroups(ExtCompList,ExtGroupPosLen) -> + wrap_extensionAdditionGroups(ExtCompList,ExtGroupPosLen,[],0,0). -wrap_extensionAdditionGroups([{'ExtensionAdditionGroup',_Number}|Rest],Acc,0) -> - {ExtGroupCompList= - [#'ComponentType'{textual_order=TextPos}|_], - ['ExtensionAdditionGroupEnd'|Rest2]} = +wrap_extensionAdditionGroups([{'ExtensionAdditionGroup',_Number}|Rest], + [{ActualPos,_,_}|ExtGroupPosLenRest],Acc,_ExtAddGroupDiff,ExtGroupNum) -> + {ExtGroupCompList,['ExtensionAdditionGroupEnd'|Rest2]} = lists:splitwith(fun(#'ComponentType'{}) -> true; (_) -> false end, Rest), - wrap_extensionAdditionGroups(Rest2, + wrap_extensionAdditionGroups(Rest2,ExtGroupPosLenRest, [#'ComponentType'{ - name='ExtAddGroup', % FIXME: handles ony one ExtAddGroup - typespec=#type{def=#'SEQUENCE'{ - extaddgroup=1,% FIXME: handles only one + name=list_to_atom("ExtAddGroup"++ + integer_to_list(ExtGroupNum+1)), + typespec=#type{def=#'SEQUENCE'{ + extaddgroup=ExtGroupNum+1, components=ExtGroupCompList}}, - textual_order = TextPos, - prop='OPTIONAL'}|Acc],length(ExtGroupCompList)-1); -wrap_extensionAdditionGroups([H=#'ComponentType'{textual_order=Tord}|T],Acc,ExtAddGroupDiff) when is_integer(Tord) -> - wrap_extensionAdditionGroups(T,[H#'ComponentType'{ - textual_order=Tord - ExtAddGroupDiff}|Acc],ExtAddGroupDiff); -wrap_extensionAdditionGroups([H|T],Acc,ExtAddGroupDiff) -> - wrap_extensionAdditionGroups(T,[H|Acc],ExtAddGroupDiff); -wrap_extensionAdditionGroups([],Acc,_) -> + textual_order = ActualPos, + prop='OPTIONAL'}|Acc],length(ExtGroupCompList)-1, + ExtGroupNum+1); +wrap_extensionAdditionGroups([H=#'ComponentType'{textual_order=Tord}|T], + ExtAddGrpLenPos,Acc,ExtAddGroupDiff,ExtGroupNum) when is_integer(Tord) -> + wrap_extensionAdditionGroups(T,ExtAddGrpLenPos,[H#'ComponentType'{ + textual_order=Tord - ExtAddGroupDiff}|Acc],ExtAddGroupDiff,ExtGroupNum); +wrap_extensionAdditionGroups([H|T],ExtAddGrpLenPos,Acc,ExtAddGroupDiff,ExtGroupNum) -> + wrap_extensionAdditionGroups(T,ExtAddGrpLenPos,[H|Acc],ExtAddGroupDiff,ExtGroupNum); +wrap_extensionAdditionGroups([],_,Acc,_,_) -> lists:reverse(Acc). diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl index 59b4b3d261..5f42eacbdc 100644 --- a/lib/asn1/src/asn1ct_gen_per.erl +++ b/lib/asn1/src/asn1ct_gen_per.erl @@ -1405,19 +1405,21 @@ get_object_field(Name,ObjectFields) -> %% have been specified within a SEQUENCE, therefore we construct a fake sequence type here %% so that we can generate code for it extaddgroup2sequence(ExtList) -> - extaddgroup2sequence(ExtList,[]). + extaddgroup2sequence(ExtList,0,[]). -extaddgroup2sequence([{'ExtensionAdditionGroup',Number0}|T],Acc) -> +extaddgroup2sequence([{'ExtensionAdditionGroup',Number0}|T],ExtNum,Acc) -> Number = case Number0 of undefined -> 1; _ -> Number0 end, {ExtGroupComps,['ExtensionAdditionGroupEnd'|T2]} = lists:splitwith(fun(Elem) -> is_record(Elem,'ComponentType') end,T), - extaddgroup2sequence(T2,[#'ComponentType'{ - name='ExtAddGroup', - typespec=#type{def=#'SEQUENCE'{ - extaddgroup=Number, - components=ExtGroupComps}}, - prop='OPTIONAL'}|Acc]); -extaddgroup2sequence([C|T],Acc) -> - extaddgroup2sequence(T,[C|Acc]); -extaddgroup2sequence([],Acc) -> + extaddgroup2sequence(T2,ExtNum+1, + [#'ComponentType'{ + name=list_to_atom("ExtAddGroup"++ + integer_to_list(ExtNum+1)), + typespec=#type{def=#'SEQUENCE'{ + extaddgroup=Number, + components=ExtGroupComps}}, + prop='OPTIONAL'}|Acc]); +extaddgroup2sequence([C|T],ExtNum,Acc) -> + extaddgroup2sequence(T,ExtNum,[C|Acc]); +extaddgroup2sequence([],_,Acc) -> lists:reverse(Acc). diff --git a/lib/asn1/src/asn1ct_gen_per_rt2ct.erl b/lib/asn1/src/asn1ct_gen_per_rt2ct.erl index 4add659d79..eda0faad3c 100644 --- a/lib/asn1/src/asn1ct_gen_per_rt2ct.erl +++ b/lib/asn1/src/asn1ct_gen_per_rt2ct.erl @@ -1808,19 +1808,21 @@ dec_enumerated_cases([],_,_) -> %% have been specified within a SEQUENCE, therefore we construct a fake sequence type here %% so that we can generate code for it extaddgroup2sequence(ExtList) -> - extaddgroup2sequence(ExtList,[]). + extaddgroup2sequence(ExtList,0,[]). -extaddgroup2sequence([{'ExtensionAdditionGroup',Number0}|T],Acc) -> +extaddgroup2sequence([{'ExtensionAdditionGroup',Number0}|T],ExtNum,Acc) -> Number = case Number0 of undefined -> 1; _ -> Number0 end, {ExtGroupComps,['ExtensionAdditionGroupEnd'|T2]} = lists:splitwith(fun(Elem) -> is_record(Elem,'ComponentType') end,T), - extaddgroup2sequence(T2,[#'ComponentType'{ - name='ExtAddGroup', - typespec=#type{def=#'SEQUENCE'{ - extaddgroup=Number, - components=ExtGroupComps}}, - prop='OPTIONAL'}|Acc]); -extaddgroup2sequence([C|T],Acc) -> - extaddgroup2sequence(T,[C|Acc]); -extaddgroup2sequence([],Acc) -> + extaddgroup2sequence(T2,ExtNum+1, + [#'ComponentType'{ + name=list_to_atom("ExtAddGroup"++ + integer_to_list(ExtNum+1)), + typespec=#type{def=#'SEQUENCE'{ + extaddgroup=Number, + components=ExtGroupComps}}, + prop='OPTIONAL'}|Acc]); +extaddgroup2sequence([C|T],ExtNum,Acc) -> + extaddgroup2sequence(T,ExtNum,[C|Acc]); +extaddgroup2sequence([],_,Acc) -> lists:reverse(Acc). diff --git a/lib/asn1/src/asn1ct_parser2.erl b/lib/asn1/src/asn1ct_parser2.erl index 007d390a1b..7301f49085 100644 --- a/lib/asn1/src/asn1ct_parser2.erl +++ b/lib/asn1/src/asn1ct_parser2.erl @@ -769,9 +769,11 @@ resolve_module(_Type, Current, undefined) -> Current; resolve_module(Type, Current, Imports) -> case [Mod || #'SymbolsFromModule'{symbols = S, module = Mod} <- Imports, - #'Externaltypereference'{type = T} <- S, + #'Externaltypereference'{type = T} <- S, Type == T] of - [#'Externaltypereference'{type = Mod}] -> Mod; + [#'Externaltypereference'{type = Mod}|_] -> Mod; + %% This allows the same symbol to be imported several times + %% which ought to be checked elsewhere and flagged as an error [] -> Current end. |