Skip to content

Commit

Permalink
support extensionmark in nested SEQUENCE in parameterized type
Browse files Browse the repository at this point in the history
erlangGH-4902 OTP-17522
  • Loading branch information
KennethL committed Jul 14, 2021
1 parent 3002f55 commit 252ca6e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
36 changes: 5 additions & 31 deletions lib/asn1/src/asn1ct_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 31 additions & 4 deletions lib/asn1/src/asn1ct_gen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -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),"', {"] ++
Expand Down Expand Up @@ -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 ->
Expand Down
9 changes: 9 additions & 0 deletions lib/asn1/test/asn1_SUITE_data/CAP.asn1
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 252ca6e

Please sign in to comment.