diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index 581729e7619f..b9bea8e84348 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -2490,11 +2490,11 @@ check_ptype(S,Type,Ts) when is_record(Ts,type) -> NewDef= case Def of Seq when is_record(Seq,'SEQUENCE') -> - Components = prepare_components(S,Seq#'SEQUENCE'.components), + Components = expand_components(S,Seq#'SEQUENCE'.components), #newt{type=Seq#'SEQUENCE'{pname=get_datastr_name(Type), components = Components}}; Set when is_record(Set,'SET') -> - Components = prepare_components(S,Set#'SET'.components), + Components = expand_components(S,Set#'SET'.components), #newt{type=Set#'SET'{pname=get_datastr_name(Type), components = Components}}; _Other -> @@ -4395,38 +4395,12 @@ check_sequence(S,Type,Comps) -> NewComps3 = textual_order(CompListWithTblInf), NewComps4 = simplify_comps(NewComps3), - CompListTuple = complist_as_tuple(NewComps4), + CompListTuple = asn1ct_gen:complist_as_tuple(NewComps4), {CRelInf,CompListTuple}; Dupl -> asn1_error(S, {duplicate_identifier, error_value(hd(Dupl))}) end. -complist_as_tuple(CompList) -> - complist_as_tuple(CompList, [], [], [], root). - -complist_as_tuple([#'EXTENSIONMARK'{}|T], Acc, Ext, Acc2, root) -> - complist_as_tuple(T, Acc, Ext, Acc2, ext); -complist_as_tuple([#'EXTENSIONMARK'{}|T], Acc, Ext, Acc2, ext) -> - complist_as_tuple(T, Acc, Ext, Acc2, root2); -complist_as_tuple([C|T], Acc, Ext, Acc2, root) -> - complist_as_tuple(T, [C|Acc], Ext, Acc2, root); -complist_as_tuple([C|T], Acc, Ext, Acc2, ext) -> - complist_as_tuple(T, Acc, [C|Ext], Acc2, ext); -complist_as_tuple([C|T], Acc, Ext, Acc2, root2) -> - complist_as_tuple(T, Acc, Ext, [C|Acc2], root2); -complist_as_tuple([], Acc, _Ext, _Acc2, root) -> - lists:reverse(Acc); -complist_as_tuple([], Acc, Ext, _Acc2, ext) -> - {lists:reverse(Acc),lists:reverse(Ext)}; -complist_as_tuple([], Acc, Ext, Acc2, root2) -> - {lists:reverse(Acc),lists:reverse(Ext),lists:reverse(Acc2)}. - -prepare_components(_S, Components) when is_tuple(Components) -> - Components; -prepare_components(S, Components) -> - Cl = expand_components(S, Components), - complist_as_tuple(Cl). - expand_components(S, [{'COMPONENTS OF',Type}|T]) -> CompList = expand_components2(S,get_referenced_type(S,Type#type.def)), expand_components(S,CompList) ++ expand_components(S,T); @@ -4475,7 +4449,7 @@ take_only_rootset([H|T]) -> [H|take_only_rootset(T)]. check_unique_sequence_tags(S,CompList) -> - TagComps = case complist_as_tuple(CompList) of + TagComps = case asn1ct_gen:complist_as_tuple(CompList) of {R1,Ext,R2} -> R1 ++ [C#'ComponentType'{prop='OPTIONAL'}|| C = #'ComponentType'{} <- Ext]++R2; @@ -4738,7 +4712,7 @@ check_choice(S,Type,Components) when is_list(Components) -> end,NewComps), NewComps3 = simplify_comps(NewComps2), check_unique_tags(S, NewComps3), - complist_as_tuple(NewComps3); + asn1ct_gen:complist_as_tuple(NewComps3); Dupl -> asn1_error(S, {duplicate_identifier,error_value(hd(Dupl))}) end; diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl index bb8ef7f5ea6e..1a27eb0b023f 100644 --- a/lib/asn1/src/asn1ct_gen.erl +++ b/lib/asn1/src/asn1ct_gen.erl @@ -35,7 +35,8 @@ index2suffix/1, get_record_name_prefix/1, conform_value/2, - named_bitstring_value/2]). + named_bitstring_value/2, + complist_as_tuple/1]). -export([pgen/3, mk_var/1, un_hyphen_var/1]). @@ -1252,19 +1253,24 @@ gen_record(Gen, TorPtype, Name, #type{}=Type, Num) -> gen_record(_, _, _, _, NumRecords) -> % skip CLASS etc for now. NumRecords. +do_gen_record(Gen, Name, CL0) when is_list(CL0) -> + do_gen_record_0(Gen, Name, complist_as_tuple(CL0)); do_gen_record(Gen, Name, CL0) -> + do_gen_record_0(Gen, Name, CL0). + +do_gen_record_0(Gen, Name, CL0) -> CL = case CL0 of {Root,[]} -> Root ++ [{comment,"with extension mark"}]; {Root,Ext} -> - Root ++ [{comment,"with exensions"}] ++ + Root ++ [{comment,"with extensions"}] ++ only_components(Ext); {Root1,Ext,Root2} -> - Root1 ++ [{comment,"with exensions"}] ++ + Root1 ++ [{comment,"with extensions"}] ++ only_components(Ext) ++ [{comment,"end of extensions"}] ++ Root2; _ when is_list(CL0) -> - CL0 + only_components(CL0) end, Prefix = get_record_name_prefix(Gen), emit(["-record('",Prefix,list2name(Name),"', {"] ++ @@ -1593,6 +1599,27 @@ list2rname1([H|_T]) -> list2rname1([]) -> []. +%% +%% convert a complist to a [Components] or a {Root,Ext} or a {Root,Ext,Ext2} +complist_as_tuple(CompList) -> + complist_as_tuple(CompList, [], [], [], root). + +complist_as_tuple([#'EXTENSIONMARK'{}|T], Acc, Ext, Acc2, root) -> + complist_as_tuple(T, Acc, Ext, Acc2, ext); +complist_as_tuple([#'EXTENSIONMARK'{}|T], Acc, Ext, Acc2, ext) -> + complist_as_tuple(T, Acc, Ext, Acc2, root2); +complist_as_tuple([C|T], Acc, Ext, Acc2, root) -> + complist_as_tuple(T, [C|Acc], Ext, Acc2, root); +complist_as_tuple([C|T], Acc, Ext, Acc2, ext) -> + complist_as_tuple(T, Acc, [C|Ext], Acc2, ext); +complist_as_tuple([C|T], Acc, Ext, Acc2, root2) -> + complist_as_tuple(T, Acc, Ext, [C|Acc2], root2); +complist_as_tuple([], Acc, _Ext, _Acc2, root) -> + lists:reverse(Acc); +complist_as_tuple([], Acc, Ext, _Acc2, ext) -> + {lists:reverse(Acc),lists:reverse(Ext)}; +complist_as_tuple([], Acc, Ext, Acc2, root2) -> + {lists:reverse(Acc),lists:reverse(Ext),lists:reverse(Acc2)}. constructed_suffix(_,#'SEQUENCE'{pname=Ptypename}) when Ptypename =/= false -> diff --git a/lib/asn1/test/asn1_SUITE_data/CAP.asn1 b/lib/asn1/test/asn1_SUITE_data/CAP.asn1 index 69d8486d3bc1..a70423908774 100644 --- a/lib/asn1/test/asn1_SUITE_data/CAP.asn1 +++ b/lib/asn1/test/asn1_SUITE_data/CAP.asn1 @@ -37,5 +37,14 @@ CriticalityType ::= ENUMERATED { Code ::= CHOICE {local INTEGER, global OBJECT IDENTIFIER} +Digits {PARAMETERS-BOUND : bound} ::= OCTET STRING (SIZE( + bound.&minDigitsLength .. bound.&maxDigitsLength)) + +BasicGapCriteria {PARAMETERS-BOUND : bound} ::= CHOICE { + calledAddressAndService [29] SEQUENCE { + calledAddressValue [0] Digits {bound}, + ... + } + } END