Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'gustav/asn1/enumerated_n2n/OTP-10144' into maint

* gustav/asn1/enumerated_n2n/OTP-10144:
  Add support for extensible enumeration types in n2n generated functions.
  Make n2n option work for enumerated types without extension markers.
  Add test enumeration types for testing n2n option when using the name2num
  and num2name functions on an enumeration value not in the extension root
  of an enumeration type with extension marker.
  • Loading branch information...
commit f3c830eddc68d7269d4f48b13ddae40893929573 2 parents d7b1657 + cf6ecce
Gustav Simonsson authored August 15, 2012
31  lib/asn1/src/asn1ct_gen.erl
@@ -129,28 +129,39 @@ pgen_types(Rtmod,Erules,N2nConvEnums,Module,[H|T]) ->
129 129
     end,
130 130
     pgen_types(Rtmod,Erules,N2nConvEnums,Module,T).
131 131
 
  132
+%% Enumerated type with extension marker
132 133
 pgen_n2nconversion(_Erules,#typedef{name=TypeName,typespec=#type{def={'ENUMERATED',{NN1,NN2}}}}) ->
133 134
     NN = NN1 ++ NN2,
134  
-    pgen_name2numfunc(TypeName,NN),
135  
-    pgen_num2namefunc(TypeName,NN);
  135
+    pgen_name2numfunc(TypeName,NN, extension_marker),
  136
+    pgen_num2namefunc(TypeName,NN, extension_marker);
  137
+%% Without extension marker
  138
+pgen_n2nconversion(_Erules,#typedef{name=TypeName,typespec=#type{def={'ENUMERATED',NN}}}) ->
  139
+    pgen_name2numfunc(TypeName,NN, no_extension_marker),
  140
+    pgen_num2namefunc(TypeName,NN, no_extension_marker);
136 141
 pgen_n2nconversion(_Erules,_) ->
137 142
     true.
138 143
 
139  
-pgen_name2numfunc(_TypeName,[]) ->
  144
+pgen_name2numfunc(_TypeName,[], _) ->
140 145
     true;
141  
-pgen_name2numfunc(TypeName,[{Atom,Number}]) ->
  146
+pgen_name2numfunc(TypeName,[{Atom,Number}], extension_marker) ->
  147
+    emit(["name2num_",TypeName,"(",{asis,Atom},") ->",Number,";",nl]),
  148
+    emit(["name2num_",TypeName,"({asn1_enum, Num}) -> Num.",nl,nl]);
  149
+pgen_name2numfunc(TypeName,[{Atom,Number}], _) ->
142 150
     emit(["name2num_",TypeName,"(",{asis,Atom},") ->",Number,".",nl,nl]);
143  
-pgen_name2numfunc(TypeName,[{Atom,Number}|NNRest]) ->
  151
+pgen_name2numfunc(TypeName,[{Atom,Number}|NNRest], EM) ->
144 152
     emit(["name2num_",TypeName,"(",{asis,Atom},") ->",Number,";",nl]),
145  
-    pgen_name2numfunc(TypeName,NNRest).
  153
+    pgen_name2numfunc(TypeName,NNRest, EM).
146 154
 
147  
-pgen_num2namefunc(_TypeName,[]) ->
  155
+pgen_num2namefunc(_TypeName,[], _) ->
148 156
     true;
149  
-pgen_num2namefunc(TypeName,[{Atom,Number}]) ->
  157
+pgen_num2namefunc(TypeName,[{Atom,Number}], extension_marker) ->
  158
+    emit(["num2name_",TypeName,"(",Number,") ->",{asis,Atom},";",nl]),
  159
+    emit(["num2name_",TypeName,"(ExtensionNum) -> {asn1_enum, ExtensionNum}.",nl,nl]);
  160
+pgen_num2namefunc(TypeName,[{Atom,Number}], _) ->
150 161
     emit(["num2name_",TypeName,"(",Number,") ->",{asis,Atom},".",nl,nl]);
151  
-pgen_num2namefunc(TypeName,[{Atom,Number}|NNRest]) ->
  162
+pgen_num2namefunc(TypeName,[{Atom,Number}|NNRest], EM) ->
152 163
     emit(["num2name_",TypeName,"(",Number,") ->",{asis,Atom},";",nl]),
153  
-    pgen_num2namefunc(TypeName,NNRest).
  164
+    pgen_num2namefunc(TypeName,NNRest, EM).
154 165
 
155 166
 pgen_objects(_,_,_,[]) ->
156 167
     true;
21  lib/asn1/test/asn1_SUITE.erl
@@ -1237,6 +1237,27 @@ testName2Number(Config) ->
1237 1237
 
1238 1238
     0 = 'S1AP-IEs':name2num_CauseMisc('control-processing-overload'),
1239 1239
     'unknown-PLMN' = 'S1AP-IEs':num2name_CauseMisc(5),
  1240
+
  1241
+    %% OTP-10144
  1242
+    %% Test that n2n option generates name2num and num2name functions supporting
  1243
+    %% values not within the extension root if the enumeration type has an
  1244
+    %% extension marker.
  1245
+    N2NOptionsExt = [{n2n, 'NoExt'}, {n2n, 'Ext'}, {n2n, 'Ext2'}],
  1246
+    asn1_test_lib:compile("EnumN2N", Config, N2NOptionsExt),
  1247
+    %% Previously, name2num and num2name was not generated if the type didn't
  1248
+    %% have an extension marker:
  1249
+    0 = 'EnumN2N':name2num_NoExt('blue'),
  1250
+    2 = 'EnumN2N':name2num_NoExt('green'),
  1251
+    blue = 'EnumN2N':num2name_NoExt(0),
  1252
+    green = 'EnumN2N':num2name_NoExt(2),
  1253
+
  1254
+    %% Test enumeration extension:
  1255
+    7 = 'EnumN2N':name2num_Ext2('orange'),
  1256
+    orange = 'EnumN2N':num2name_Ext2(7),
  1257
+    %% 7 is not defined in Ext, only in Ext2.
  1258
+    {asn1_enum, 7} = 'EnumN2N':num2name_Ext(7),
  1259
+    7 = 'EnumN2N':name2num_Ext({asn1_enum, 7}),
  1260
+    42 = 'EnumN2N':name2num_Ext2({asn1_enum, 42}),
1240 1261
     ok.
1241 1262
 
1242 1263
 ticket_7407(Config) ->
25  lib/asn1/test/asn1_SUITE_data/EnumN2N.asn1
... ...
@@ -0,0 +1,25 @@
  1
+EnumN2N DEFINITIONS AUTOMATIC TAGS ::=
  2
+BEGIN
  3
+
  4
+NoExt ::= ENUMERATED {
  5
+	blue(0),
  6
+	red(1),
  7
+	green(2)
  8
+}
  9
+
  10
+Ext ::= ENUMERATED {
  11
+	blue(0),
  12
+	red(1),
  13
+	green(2),
  14
+	...
  15
+}
  16
+
  17
+Ext2 ::= ENUMERATED {
  18
+	blue(0),
  19
+	red(1),
  20
+	green(2),
  21
+	...,
  22
+	orange(7)
  23
+}
  24
+
  25
+END

0 notes on commit f3c830e

Please sign in to comment.
Something went wrong with that request. Please try again.