diff options
author | Björn Gustavsson <[email protected]> | 2017-01-16 16:47:58 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2017-02-06 12:49:26 +0100 |
commit | 8a7f914affce3102e4889c2973ea2d2e99ad633d (patch) | |
tree | dc346ad3a5a9f04f59046209fe042515a873f6da /lib/asn1/src/asn1ct_gen.erl | |
parent | 48137fa5034202e0fc4c5fbc0faf9bbb8bc2bb13 (diff) | |
download | otp-8a7f914affce3102e4889c2973ea2d2e99ad633d.tar.gz otp-8a7f914affce3102e4889c2973ea2d2e99ad633d.tar.bz2 otp-8a7f914affce3102e4889c2973ea2d2e99ad633d.zip |
Teach the ASN.1 compiler the 'maps' option
When the 'maps' option is given, the SEQUENCE and SET types are
represented as maps instead of as records. Optional and default values
must be not be given as asn1_NOVALUE or asn1_DEFAULT in a map passed
to the M:encode/2 function; they must be omitted from the
map. Similarly, when decoding missing values will be omitted from the
map.
No .hrl files will be generated when the 'maps' options is used.
That means values in an ASN.1 module must be retrieved by calling the
appropriate function in generated module.
Since we one day hope to get rid of the options 'compact_bit_string',
'legacy_bit_string', and 'legacy_erlang_types', we will not allow them
to be combined with the 'maps' option.
Diffstat (limited to 'lib/asn1/src/asn1ct_gen.erl')
-rw-r--r-- | lib/asn1/src/asn1ct_gen.erl | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl index a54cb0765e..4fa830d7d9 100644 --- a/lib/asn1/src/asn1ct_gen.erl +++ b/lib/asn1/src/asn1ct_gen.erl @@ -67,6 +67,7 @@ pgen(OutFile, #gen{options=Options}=Gen, Module, Contents) -> UnmatchedTypes}) end, put(outfile,OutFile), + put(currmod, Module), HrlGenerated = pgen_hrl(Gen, Module, Contents), asn1ct_name:start(), ErlFile = lists:concat([OutFile,".erl"]), @@ -650,7 +651,7 @@ gen_decode_constructed(Erules,Typename,InnerType,D) when is_record(D,typedef) -> pgen_exports(#gen{options=Options}=Gen, _Module, Contents) -> {Types,Values,_,_,Objects,ObjectSets} = Contents, - emit(["-export([encoding_rule/0,bit_string_format/0,",nl, + emit(["-export([encoding_rule/0,maps/0,bit_string_format/0,",nl, " legacy_erlang_types/0]).",nl]), emit(["-export([",{asis,?SUPPRESSION_FUNC},"/1]).",nl]), case Types of @@ -887,8 +888,14 @@ gen_info_functions(Gen) -> #gen{erule=per,aligned=false} -> uper; #gen{erule=per,aligned=true} -> per end, + Maps = case Gen of + #gen{pack=record} -> false; + #gen{pack=map} -> true + end, emit(["encoding_rule() -> ", {asis,Erule},".",nl,nl, + "maps() -> ", + {asis,Maps},".",nl,nl, "bit_string_format() -> ", {asis,asn1ct:get_bit_string_format()},".",nl,nl, "legacy_erlang_types() -> ", @@ -1093,8 +1100,7 @@ open_output_file(F) -> close_output_file() -> ok = file:close(erase(gen_file_out)). -pgen_hrl(Gen, Module, Contents) -> - put(currmod, Module), +pgen_hrl(#gen{pack=record}=Gen, Module, Contents) -> {Types,Values,Ptypes,_,_,_} = Contents, Ret = case pgen_hrltypes(Gen, Module, Ptypes++Types, 0) of @@ -1103,7 +1109,7 @@ pgen_hrl(Gen, Module, Contents) -> [] -> 0; _ -> - open_hrl(get(outfile),get(currmod)), + open_hrl(get(outfile), Module), pgen_macros(Gen, Module, Values), 1 end; @@ -1122,7 +1128,9 @@ pgen_hrl(Gen, Module, Contents) -> [{generated,lists:concat([get(outfile),".hrl"])}], Gen), Y - end. + end; +pgen_hrl(#gen{pack=map}, _, _) -> + 0. pgen_macros(_,_,[]) -> true; |