~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/asn1/src/asn1ct_gen.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
%% ``The contents of this file are subject to the Erlang Public License,
 
1
%%<copyright>
 
2
%% <year>1997-2008</year>
 
3
%% <holder>Ericsson AB, All Rights Reserved</holder>
 
4
%%</copyright>
 
5
%%<legalnotice>
 
6
%% The contents of this file are subject to the Erlang Public License,
2
7
%% Version 1.1, (the "License"); you may not use this file except in
3
8
%% compliance with the License. You should have received a copy of the
4
9
%% Erlang Public License along with this software. If not, it can be
5
 
%% retrieved via the world wide web at http://www.erlang.org/.
6
 
%% 
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
7
12
%% Software distributed under the License is distributed on an "AS IS"
8
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
14
%% the License for the specific language governing rights and limitations
10
15
%% under the License.
11
 
%% 
12
 
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
 
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
 
%% AB. All Rights Reserved.''
15
 
%% 
16
 
%%     $Id$
 
16
%%
 
17
%% The Initial Developer of the Original Code is Ericsson AB.
 
18
%%</legalnotice>
17
19
%%
18
20
-module(asn1ct_gen).
19
21
 
607
609
        #'Externaltypereference'{type=T} ->
608
610
            emit([{asis,ensure_atom(list2name([T,check]))},"(DV,V),",nl]);
609
611
        'ASN1_OPEN_TYPE' ->
 
612
            emit(["DV = V,",nl]);
 
613
        _ ->
610
614
            emit(["DV = V,",nl])
611
615
    end,
612
616
    emit({"   ",{asis,NewName},"(DVs,Vs).",nl,nl}).
663
667
                  "      ",DefVal," == ",Val," -> true;",nl,
664
668
                  "      true -> throw({error,{asn1_open_type}})",nl,
665
669
                  "   end",nl]);
 
670
        {constructed,bif} ->
 
671
            emit(["   ",{asis,ensure_atom(list2name([N,Name]))},"(",DefVal,",",Val,")"]);
666
672
        _ ->
667
 
            emit(["   ",{asis,ensure_atom(list2name([N,Name]))},"(",DefVal,",",Val,")"])
 
673
            emit(["   if",nl,
 
674
                  "      ",DefVal," == ",Val," -> true;",nl,
 
675
                  "      true -> throw({error,{asn1_open_type}})",nl,
 
676
                  "   end",nl])
668
677
    end.
669
678
                  
670
679
    
887
896
    emit(["-export([encode/2,decode/2,encode_disp/2,decode_disp/2]).",nl,nl]),
888
897
    emit(["encoding_rule() ->",nl]),
889
898
    emit(["   ",{asis,Erules},".",nl,nl]),
 
899
    NoFinalPadding = lists:member(no_final_padding,get(encoding_options)),
890
900
    Call = case Erules of
891
901
               per -> "?RT_PER:complete(encode_disp(Type,Data))";
892
902
               per_bin -> "?RT_PER:complete(encode_disp(Type,Data))";
893
903
               ber -> "encode_disp(Type,Data)";
894
904
               ber_bin -> "encode_disp(Type,Data)";
895
 
               ber_bin_v2 -> "encode_disp(Type,Data)"
 
905
               ber_bin_v2 -> "encode_disp(Type,Data)";
 
906
               uper_bin when NoFinalPadding == true -> 
 
907
                   "?RT_PER:complete_NFP(encode_disp(Type,Data))";
 
908
               uper_bin -> "?RT_PER:complete(encode_disp(Type,Data))"
896
909
           end,
897
910
    EncWrap = case Erules of
898
911
               ber -> "wrap_encode(Bytes)";
995
1008
                  "    {ok,X,Rest};",nl,
996
1009
                  "  {X,Rest,_Len} ->",nl,
997
1010
                  "    {ok,X,Rest}",nl]);
 
1011
        {uper_bin,true} ->
 
1012
            emit(["  {X,{_,Rest}} ->",nl,
 
1013
                  "    {ok,X,Rest};",nl,
 
1014
                  "  {X,{_,Rest},_Len} ->",nl,
 
1015
                  "    {ok,X,Rest};",nl,
 
1016
                  "  {X,Rest} ->",nl,
 
1017
                  "    {ok,X,Rest};",nl,
 
1018
                  "  {X,Rest,_Len} ->",nl,
 
1019
                  "    {ok,X,Rest}",nl]);
998
1020
        _ ->
999
1021
            emit(["  {X,Rest} ->",nl,
1000
1022
                  "    {ok,X,Rest};",nl,
1349
1371
              Set when record(Set,'SET') ->
1350
1372
                  case Set#'SET'.pname of
1351
1373
                      false ->
1352
 
                          {record,Set#'SET'.components};
 
1374
                          {record,to_textual_order(Set#'SET'.components)};
1353
1375
                      _Pname when TorPtype == type ->
1354
1376
                          false;
1355
1377
                      _ ->
1356
 
                          {record,Set#'SET'.components}
 
1378
                          {record,to_textual_order(Set#'SET'.components)}
1357
1379
                  end;
1358
1380
%             {'SET',{_,_CompList}} -> 
1359
1381
%                 {record,_CompList}; 
1401
1423
                        emit(["%% with extensions",nl]),
1402
1424
                        gen_record2(Name,'SEQUENCE',Extl,"",ext),
1403
1425
                        case Extl of
1404
 
                            [] -> true;
1405
 
                            _ -> emit([",",nl])
 
1426
                            [_H|_] when Rootl2 /= [] -> emit([",",nl]);
 
1427
                            _ -> ok
1406
1428
                        end,
1407
1429
                        emit(["%% end of extensions",nl]),
1408
1430
                        gen_record2(Name,'SEQUENCE',Rootl2,"",noext),
1450
1472
                            emit({"%% Generated by the Erlang ASN.1 BER_V2-"
1451
1473
                                  "compiler version, utilizing bit-syntax:",
1452
1474
                                  asn1ct:vsn(),nl}),
1453
 
                            {"RT_BER","asn1rt_ber_bin_v2"}
 
1475
                            {"RT_BER","asn1rt_ber_bin_v2"};
 
1476
                        uper_bin ->
 
1477
                            emit(["%% Generated by the Erlang ASN.1 UNALIGNED"
 
1478
                                  " PER-compiler version, utilizing"
 
1479
                                  " bit-syntax:",
 
1480
                                  asn1ct:vsn(),nl]),
 
1481
                            {"RT_PER","asn1rt_uper_bin"}
1454
1482
    end,
1455
1483
    emit({"%% Purpose: encoder and decoder to the types in mod ",Mod,nl,nl}),
1456
1484
    emit({"-module('",Mod,"').",nl}),
1500
1528
gen_record_default(_, _) ->
1501
1529
    true.
1502
1530
 
 
1531
%% May only be a list or a two-tuple.
 
1532
to_textual_order({Root,Ext}) ->
 
1533
    {to_textual_order(Root),Ext};
 
1534
to_textual_order(Cs={_R1,_Ext,_R2}) ->
 
1535
    Cs;
 
1536
to_textual_order(Cs=[#'ComponentType'{textual_order=undefined}|_]) ->
 
1537
    Cs;
 
1538
to_textual_order(Cs) when is_list(Cs) ->
 
1539
    lists:keysort(#'ComponentType'.textual_order,Cs).
 
1540
    
 
1541
 
1503
1542
gen_check_call(TopType,Cname,Type,InnerType,WhatKind,DefaultValue,Element) ->
1504
1543
    case WhatKind of
1505
1544
        {primitive,bif} ->
1526
1565
            %% Must look for check functions in InnerType,
1527
1566
            %% that may be referenced  or internal defined 
1528
1567
            %% constructed types not used elsewhere.
1529
 
            lookahead_innertype(NameList,InnerType,Type)
 
1568
            lookahead_innertype(NameList,InnerType,Type);
 
1569
        _ ->
 
1570
            %% Generate Dummy function call i.e. anything is accepted
 
1571
            emit(["fun() -> true end ()"])
1530
1572
    end.
1531
1573
 
1532
1574
gen_prim_check_call(PrimType,DefaultValue,Element,Type) ->
1555
1597
        'OBJECT IDENTIFIER' ->
1556
1598
            emit({"asn1rt_check:check_objectidentifier(",DefaultValue,
1557
1599
                  ", ",Element,")"});
 
1600
        'RELATIVE-OID' ->
 
1601
            emit({"asn1rt_check:check_objectidentifier(",DefaultValue,
 
1602
                  ", ",Element,")"});
1558
1603
        'ObjectDescriptor' ->
1559
1604
            emit({"asn1rt_check:check_objectdescriptor(",DefaultValue,
1560
1605
                  ", ",Element,")"});
1662
1707
    end.
1663
1708
 
1664
1709
insert_once(Table,Object) ->
 
1710
    _Info = ets:info(Table),
1665
1711
    case ets:lookup(Table,element(1,Object)) of
1666
1712
        [] ->
1667
1713
            ets:insert(Table,Object); %returns true
1676
1722
            restrictedstring;
1677
1723
        'TeletexString' ->
1678
1724
            restrictedstring;
 
1725
        'T61String' ->
 
1726
            restrictedstring;
1679
1727
        'VideotexString' ->
1680
1728
            restrictedstring;
1681
1729
        'IA5String' ->
1773
1821
                    'ENUMERATED',
1774
1822
                    'REAL',
1775
1823
                    'OBJECT IDENTIFIER',
 
1824
                    'RELATIVE-OID',
1776
1825
                    'ANY',
1777
1826
                    'NULL',
1778
1827
                    'BIT STRING' ,
1780
1829
                    'ObjectDescriptor',
1781
1830
                    'NumericString',
1782
1831
                    'TeletexString',
 
1832
                    'T61String',
1783
1833
                    'VideotexString',
1784
1834
                    'UTCTime',
1785
1835
                    'GeneralizedTime',
1931
1981
erule(per) ->
1932
1982
    per;
1933
1983
erule(per_bin) ->
 
1984
    per;
 
1985
erule(uper_bin) ->
1934
1986
    per.
1935
1987
 
1936
1988
wrap_ber(ber) ->