2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * compiler/back_ends/idl_gen/gen_any.c
22 * prints Routine to initialize the ANY Hash table. The
23 * ANY Hash table maps the OBJECT IDENTIFIERS or INTEGERS
24 * to the correct decoding routines.
26 * Also prints an enum to identify each ANY mapping.
29 * Copyright (C) 1991, 1992 Michael Sample
30 * and the University of British Columbia
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/back-ends/idl-gen/Attic/gen-any.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
39 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
40 * Move from private repository to open source repository
42 * Revision 1.2 2001/05/05 00:59:28 rmurphy
43 * Adding darwin license headers
45 * Revision 1.1.1.1 1999/03/16 18:06:45 aram
46 * Originals from SMIME Free Library.
48 * Revision 1.1 1997/01/01 20:25:32 rj
57 #include "asn1module.h"
62 #include "lib-types.h"
65 static int anyEnumValG
= 0;
68 void PrintIDLAnyEnum
PROTO ((FILE *idl
, Module
*m
, IDLRules
*r
));
70 void PrintIDLAnyHashInitRoutine
PROTO ((FILE *idl
, ModuleList
*mods
, Module
*m
, IDLRules
*r
));
74 PrintIDLAnyCode
PARAMS ((idl
, r
, mods
, m
),
77 ModuleList
*mods _AND_
84 PrintIDLAnyEnum (idl
, m
, r
);
86 PrintIDLAnyHashInitRoutine (idl
, mods
, m
, r
);
94 PrintIDLAnyEnum
PARAMS ((idl
, m
, r
),
102 int firstPrinted
= TRUE
;
106 modName
= Asn1TypeName2CTypeName (m
->modId
->name
);
108 fprintf (idl
,"typedef enum %sAnyId\n", modName
);
111 /* do any lib types */
112 for (i
= BASICTYPE_BOOLEAN
; i
< BASICTYPE_MACRODEF
; i
++)
114 arl
= LIBTYPE_GET_ANY_REFS (i
);
117 FOR_EACH_LIST_ELMT (ar
, arl
)
121 fprintf (idl
," %s = %d", ar
->anyIdName
, anyEnumValG
++);
122 firstPrinted
= FALSE
;
127 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
129 if (td
->anyRefs
!= NULL
)
131 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
135 fprintf (idl
," %s = %d", ar
->anyIdName
, anyEnumValG
++);
136 firstPrinted
= FALSE
;
141 if (firstPrinted
) /* none have been printed */
142 fprintf (idl
,"/* NO INTEGER or OBJECT IDENTIFIER to ANY type relationships were defined (via MACROs or other mechanism) */\n ??? \n");
144 fprintf (idl
,"\n} %sAnyId;\n\n\n", modName
);
152 PrintIDLAnyHashInitRoutine
PARAMS ((idl
, mods
, m
, r
),
154 ModuleList
*mods _AND_
164 enum BasicTypeChoiceId typeId
;
165 int installedSomeHashes
= FALSE
;
168 /* print InitAny class src file */
169 fprintf (src
,"// this class will automatically intialize the any hash tbl\n");
170 fprintf (src
,"class InitAny\n");
172 fprintf (src
," public:\n");
173 fprintf (src
," InitAny();\n");
174 fprintf (src
,"};\n\n");
176 fprintf (src
,"static InitAny anyInitalizer;\n");
178 /* print constructor method that build hash tbl to src file*/
179 fprintf (src
,"InitAny::InitAny()\n");
182 /* first print value for OID's */
184 /* do any lib types first */
186 for (j
= BASICTYPE_BOOLEAN
; j
< BASICTYPE_MACRODEF
; j
++)
188 arl
= LIBTYPE_GET_ANY_REFS (j
);
191 FOR_EACH_LIST_ELMT (ar
, arl
)
193 installedSomeHashes
= TRUE
;
194 if (ar
->id
->choiceId
== OIDORINT_OID
)
196 fprintf (src
," %s oid%d", r
->typeConvTbl
[BASICTYPE_OID
].className
, i
++);
197 PrintIDLOidValue (src
, r
, ar
->id
->a
.oid
);
200 else if (ar
->id
->choiceId
== OIDORINT_INTID
)
202 fprintf (src
," %s int%d", r
->typeConvTbl
[BASICTYPE_INTEGER
].className
, i
++);
203 PrintIDLIntValue (src
, r
, ar
->id
->a
.intId
);
211 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
213 if (td
->anyRefs
!= NULL
)
215 idltdi
= td
->idlTypeDefInfo
;
216 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
218 installedSomeHashes
= TRUE
;
219 if (ar
->id
->choiceId
== OIDORINT_OID
)
221 fprintf (src
," %s oid%d", r
->typeConvTbl
[BASICTYPE_OID
].className
, i
++);
222 PrintIDLOidValue (src
, r
, ar
->id
->a
.oid
);
225 else if (ar
->id
->choiceId
== OIDORINT_INTID
)
227 fprintf (src
," %s int%d", r
->typeConvTbl
[BASICTYPE_INTEGER
].className
, i
++);
228 PrintIDLIntValue (src
, r
, ar
->id
->a
.intId
);
236 /* now print hash init calls */
238 for (j
= BASICTYPE_BOOLEAN
; j
< BASICTYPE_MACRODEF
; j
++)
240 arl
= LIBTYPE_GET_ANY_REFS (j
);
243 FOR_EACH_LIST_ELMT (ar
, arl
)
245 if (ar
->id
->choiceId
== OIDORINT_OID
)
246 fprintf (src
," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i
++, ar
->anyIdName
, r
->typeConvTbl
[j
].className
);
249 fprintf (src
," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i
++, ar
->anyIdName
, r
->typeConvTbl
[j
].className
);
255 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
257 if (td
->anyRefs
!= NULL
)
259 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
261 idltdi
= td
->idlTypeDefInfo
;
263 if (ar
->id
->choiceId
== OIDORINT_OID
)
264 fprintf (src
," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i
++, ar
->anyIdName
, idltdi
->className
);
267 fprintf (src
," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i
++, ar
->anyIdName
, idltdi
->className
);
273 if (!installedSomeHashes
)
275 fprintf (src
," /* Since no INTEGER/OID to ANY type relations were defined\n");
276 fprintf (src
," * (usually done via MACROs) you must manually do the code\n");
277 fprintf (src
," * to fill the hash tbl.\n");
278 fprintf (src
," * if the ids are INTEGER use the following:\n");
279 fprintf (src
," * AsnAny::InstallAnyByInt (3, ??_ANY_ID, new <className>);\n");
280 fprintf (src
," * if the ids are OBJECT IDENTIFIERs use the following:\n");
281 fprintf (src
," * AsnAny::InstallAnyByOid (OidValue, ??_ANY_ID, new <className>);\n");
282 fprintf (src
," * put the ??_ANY_IDs in the AnyId enum.\n\n");
283 fprintf (src
," * For example if you have some thing like\n");
284 fprintf (src
," * T1 ::= SEQUENCE { id INTEGER, ANY DEFINED BY id }\n");
285 fprintf (src
," * and the id 1 maps to the type BOOLEAN use the following:\n");
286 fprintf (src
," * AsnAny::InstallAnyByInt (1, SOMEBOOL_ANY_ID, new AsnBool);\n");
287 fprintf (src
," */\n ???????\n"); /* generate compile error */
291 fprintf (src
,"} /* InitAny::InitAny */\n\n\n");
293 } /* PrintAnyHashInitRoutine */