]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/idl-gen/gen-any.c
Security-54.tar.gz
[apple/security.git] / SecuritySNACCRuntime / compiler / back-ends / idl-gen / gen-any.c
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 /*
20 * compiler/back_ends/idl_gen/gen_any.c
21 *
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.
25 *
26 * Also prints an enum to identify each ANY mapping.
27 *
28 * MS 92
29 * Copyright (C) 1991, 1992 Michael Sample
30 * and the University of British Columbia
31 *
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.
36 *
37 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/compiler/back-ends/idl-gen/gen-any.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
38 * $Log: gen-any.c,v $
39 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
40 * Move from private repository to open source repository
41 *
42 * Revision 1.2 2001/05/05 00:59:28 rmurphy
43 * Adding darwin license headers
44 *
45 * Revision 1.1.1.1 1999/03/16 18:06:45 aram
46 * Originals from SMIME Free Library.
47 *
48 * Revision 1.1 1997/01/01 20:25:32 rj
49 * first draft
50 *
51 */
52
53 #include <stdio.h>
54
55 #include "asn-incl.h"
56 #include "mem.h"
57 #include "asn1module.h"
58 #include "define.h"
59 #include "str-util.h"
60 #include "rules.h"
61 #include "gen-vals.h"
62 #include "lib-types.h"
63 #include "gen-any.h"
64
65 static int anyEnumValG = 0;
66
67
68 void PrintIDLAnyEnum PROTO ((FILE *idl, Module *m, IDLRules *r));
69
70 void PrintIDLAnyHashInitRoutine PROTO ((FILE *idl, ModuleList *mods, Module *m, IDLRules *r));
71
72
73 void
74 PrintIDLAnyCode PARAMS ((idl, r, mods, m),
75 FILE *idl _AND_
76 IDLRules *r _AND_
77 ModuleList *mods _AND_
78 Module *m)
79 {
80
81 if (!m->hasAnys)
82 return;
83
84 PrintIDLAnyEnum (idl, m, r);
85 #if 0
86 PrintIDLAnyHashInitRoutine (idl, mods, m, r);
87 #endif
88
89 } /* PrintAnyCode */
90
91
92
93 void
94 PrintIDLAnyEnum PARAMS ((idl, m, r),
95 FILE *idl _AND_
96 Module *m _AND_
97 IDLRules *r)
98 {
99 TypeDef *td;
100 AnyRef *ar;
101 AnyRefList *arl;
102 int firstPrinted = TRUE;
103 int i;
104 char *modName;
105
106 modName = Asn1TypeName2CTypeName (m->modId->name);
107
108 fprintf (idl,"typedef enum %sAnyId\n", modName);
109 fprintf (idl,"{\n");
110
111 /* do any lib types */
112 for (i = BASICTYPE_BOOLEAN; i < BASICTYPE_MACRODEF; i++)
113 {
114 arl = LIBTYPE_GET_ANY_REFS (i);
115 if (arl != NULL)
116 {
117 FOR_EACH_LIST_ELMT (ar, arl)
118 {
119 if (!firstPrinted)
120 fprintf (idl,",\n");
121 fprintf (idl," %s = %d", ar->anyIdName, anyEnumValG++);
122 firstPrinted = FALSE;
123 }
124 }
125 }
126
127 FOR_EACH_LIST_ELMT (td, m->typeDefs)
128 {
129 if (td->anyRefs != NULL)
130 {
131 FOR_EACH_LIST_ELMT (ar, td->anyRefs)
132 {
133 if (!firstPrinted)
134 fprintf (idl,",\n");
135 fprintf (idl," %s = %d", ar->anyIdName, anyEnumValG++);
136 firstPrinted = FALSE;
137 }
138 }
139 }
140
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");
143
144 fprintf (idl,"\n} %sAnyId;\n\n\n", modName);
145 Free (modName);
146
147 } /* PrintAnyEnum */
148
149
150 #if 0
151 void
152 PrintIDLAnyHashInitRoutine PARAMS ((idl, mods, m, r),
153 FILE *idl _AND_
154 ModuleList *mods _AND_
155 Module *m _AND_
156 IDLRules *r)
157 {
158 TypeDef *td;
159 AnyRefList *arl;
160 AnyRef *ar;
161 IDLTDI *idltdi;
162 int i;
163 int j;
164 enum BasicTypeChoiceId typeId;
165 int installedSomeHashes = FALSE;
166
167
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");
171 fprintf (src,"{\n");
172 fprintf (src," public:\n");
173 fprintf (src," InitAny();\n");
174 fprintf (src,"};\n\n");
175
176 fprintf (src,"static InitAny anyInitalizer;\n");
177
178 /* print constructor method that build hash tbl to src file*/
179 fprintf (src,"InitAny::InitAny()\n");
180 fprintf (src,"{\n");
181
182 /* first print value for OID's */
183
184 /* do any lib types first */
185 i = 0;
186 for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++)
187 {
188 arl = LIBTYPE_GET_ANY_REFS (j);
189 if (arl != NULL)
190 {
191 FOR_EACH_LIST_ELMT (ar, arl)
192 {
193 installedSomeHashes = TRUE;
194 if (ar->id->choiceId == OIDORINT_OID)
195 {
196 fprintf (src," %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++);
197 PrintIDLOidValue (src, r, ar->id->a.oid);
198 fprintf (src,";\n");
199 }
200 else if (ar->id->choiceId == OIDORINT_INTID)
201 {
202 fprintf (src," %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++);
203 PrintIDLIntValue (src, r, ar->id->a.intId);
204 fprintf (src,";\n");
205 }
206 }
207 }
208 }
209
210
211 FOR_EACH_LIST_ELMT (td, m->typeDefs)
212 {
213 if (td->anyRefs != NULL)
214 {
215 idltdi = td->idlTypeDefInfo;
216 FOR_EACH_LIST_ELMT (ar, td->anyRefs)
217 {
218 installedSomeHashes = TRUE;
219 if (ar->id->choiceId == OIDORINT_OID)
220 {
221 fprintf (src," %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++);
222 PrintIDLOidValue (src, r, ar->id->a.oid);
223 fprintf (src,";\n");
224 }
225 else if (ar->id->choiceId == OIDORINT_INTID)
226 {
227 fprintf (src," %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++);
228 PrintIDLIntValue (src, r, ar->id->a.intId);
229 fprintf (src,";\n");
230 }
231 }
232 }
233 }
234
235
236 /* now print hash init calls */
237 i = 0;
238 for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++)
239 {
240 arl = LIBTYPE_GET_ANY_REFS (j);
241 if (arl != NULL)
242 {
243 FOR_EACH_LIST_ELMT (ar, arl)
244 {
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);
247
248 else
249 fprintf (src," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, r->typeConvTbl[j].className);
250
251 }
252 }
253 }
254
255 FOR_EACH_LIST_ELMT (td, m->typeDefs)
256 {
257 if (td->anyRefs != NULL)
258 {
259 FOR_EACH_LIST_ELMT (ar, td->anyRefs)
260 {
261 idltdi = td->idlTypeDefInfo;
262
263 if (ar->id->choiceId == OIDORINT_OID)
264 fprintf (src," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, idltdi->className);
265
266 else
267 fprintf (src," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, idltdi->className);
268
269 }
270 }
271 }
272
273 if (!installedSomeHashes)
274 {
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 */
288 }
289
290
291 fprintf (src,"} /* InitAny::InitAny */\n\n\n");
292
293 } /* PrintAnyHashInitRoutine */
294 #endif