]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
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/c++_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 | * INSERT_VDA_COMMENTS | |
38 | * | |
a66d0d4a | 39 | * $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/back-ends/c++-gen/Attic/gen-any.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $ |
bac41a7b A |
40 | * $Log: gen-any.c,v $ |
41 | * Revision 1.1.1.1 2001/05/18 23:14:09 mb | |
42 | * Move from private repository to open source repository | |
43 | * | |
44 | * Revision 1.2 2001/05/05 00:59:27 rmurphy | |
45 | * Adding darwin license headers | |
46 | * | |
47 | * Revision 1.1.1.1 1999/03/16 18:06:39 aram | |
48 | * Originals from SMIME Free Library. | |
49 | * | |
50 | * Revision 1.4 1995/07/25 18:19:11 rj | |
51 | * changed `_' to `-' in file names. | |
52 | * | |
53 | * Revision 1.3 1994/10/08 03:47:53 rj | |
54 | * since i was still irritated by cpp standing for c++ and not the C preprocessor, i renamed them to cxx (which is one known suffix for C++ source files). since the standard #define is __cplusplus, cplusplus would have been the more obvious choice, but it is a little too long. | |
55 | * | |
56 | * Revision 1.2 1994/09/01 01:06:31 rj | |
57 | * snacc_config.h removed. | |
58 | * | |
59 | * Revision 1.1 1994/08/28 09:47:58 rj | |
60 | * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. | |
61 | * | |
62 | */ | |
63 | ||
64 | #include <stdio.h> | |
65 | ||
66 | #include "asn-incl.h" | |
67 | #include "mem.h" | |
68 | #include "asn1module.h" | |
69 | #include "define.h" | |
70 | #include "str-util.h" | |
71 | #include "rules.h" | |
72 | #include "gen-vals.h" | |
73 | #include "lib-types.h" | |
74 | #include "gen-any.h" | |
75 | ||
76 | static int anyEnumValG = 0; | |
77 | ||
78 | ||
79 | void PrintCxxAnyEnum PROTO ((FILE *hdr, Module *m, CxxRules *r)); | |
80 | ||
81 | void PrintCxxAnyHashInitRoutine PROTO ((FILE *src, FILE *hdr, ModuleList *mods, Module *m, CxxRules *r)); | |
82 | ||
83 | ||
84 | void | |
85 | PrintCxxAnyCode PARAMS ((src, hdr, r, mods, m), | |
86 | FILE *src _AND_ | |
87 | FILE *hdr _AND_ | |
88 | CxxRules *r _AND_ | |
89 | ModuleList *mods _AND_ | |
90 | Module *m) | |
91 | { | |
92 | ||
93 | if (!m->hasAnys) | |
94 | return; | |
95 | ||
96 | PrintCxxAnyEnum (hdr, m, r); | |
97 | PrintCxxAnyHashInitRoutine (src, hdr, mods, m, r); | |
98 | ||
99 | } /* PrintAnyCode */ | |
100 | ||
101 | ||
102 | ||
103 | void | |
104 | PrintCxxAnyEnum PARAMS ((hdr, m, r), | |
105 | FILE *hdr _AND_ | |
106 | Module *m _AND_ | |
107 | CxxRules *r) | |
108 | { | |
109 | TypeDef *td; | |
110 | AnyRef *ar; | |
111 | AnyRefList *arl; | |
112 | int firstPrinted = TRUE; | |
113 | int i; | |
114 | char *modName; | |
115 | ||
116 | modName = Asn1TypeName2CTypeName (m->modId->name); | |
117 | ||
118 | fprintf (hdr,"typedef enum %sAnyId\n", modName); | |
119 | fprintf (hdr,"{\n"); | |
120 | ||
121 | /* do any lib types */ | |
122 | for (i = BASICTYPE_BOOLEAN; i < BASICTYPE_MACRODEF; i++) | |
123 | { | |
124 | arl = LIBTYPE_GET_ANY_REFS (i); | |
125 | if (arl != NULL) | |
126 | { | |
127 | FOR_EACH_LIST_ELMT (ar, arl) | |
128 | { | |
129 | if (!firstPrinted) | |
130 | fprintf (hdr,",\n"); | |
131 | fprintf (hdr," %s = %d", ar->anyIdName, anyEnumValG++); | |
132 | firstPrinted = FALSE; | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
137 | FOR_EACH_LIST_ELMT (td, m->typeDefs) | |
138 | { | |
139 | if (td->anyRefs != NULL) | |
140 | { | |
141 | FOR_EACH_LIST_ELMT (ar, td->anyRefs) | |
142 | { | |
143 | if (!firstPrinted) | |
144 | fprintf (hdr,",\n"); | |
145 | fprintf (hdr," %s = %d", ar->anyIdName, anyEnumValG++); | |
146 | firstPrinted = FALSE; | |
147 | } | |
148 | } | |
149 | } | |
150 | ||
151 | #ifndef VDADER_RULES | |
152 | if (firstPrinted) /* none have been printed */ | |
153 | fprintf (hdr,"/* NO INTEGER or OBJECT IDENTIFIER to ANY type relationships were defined (via MACROs or other mechanism) */\n ??? \n"); | |
154 | #endif | |
155 | ||
156 | fprintf (hdr,"\n} %sAnyId;\n\n\n", modName); | |
157 | Free (modName); | |
158 | ||
159 | } /* PrintAnyEnum */ | |
160 | ||
161 | ||
162 | void | |
163 | PrintCxxAnyHashInitRoutine PARAMS ((src, hdr, mods, m, r), | |
164 | FILE *src _AND_ | |
165 | FILE *hdr _AND_ | |
166 | ModuleList *mods _AND_ | |
167 | Module *m _AND_ | |
168 | CxxRules *r) | |
169 | { | |
170 | TypeDef *td; | |
171 | AnyRefList *arl; | |
172 | AnyRef *ar; | |
173 | CxxTDI *cxxtdi; | |
174 | int i; | |
175 | int j; | |
176 | enum BasicTypeChoiceId typeId; | |
177 | int installedSomeHashes = FALSE; | |
178 | ||
179 | ||
180 | #ifndef VDADER_RULES | |
181 | /* print InitAny class src file */ | |
182 | fprintf (src,"// this class will automatically intialize the any hash tbl\n"); | |
183 | fprintf (src,"class InitAny\n"); | |
184 | fprintf (src,"{\n"); | |
185 | fprintf (src," public:\n"); | |
186 | fprintf (src," InitAny();\n"); | |
187 | fprintf (src,"};\n\n"); | |
188 | ||
189 | fprintf (src,"static InitAny anyInitalizer;\n"); | |
190 | ||
191 | /* print constructor method that build hash tbl to src file*/ | |
192 | fprintf (src,"InitAny::InitAny()\n"); | |
193 | fprintf (src,"{\n"); | |
194 | ||
195 | /* first print value for OID's */ | |
196 | ||
197 | /* do any lib types first */ | |
198 | i = 0; | |
199 | for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++) | |
200 | { | |
201 | arl = LIBTYPE_GET_ANY_REFS (j); | |
202 | if (arl != NULL) | |
203 | { | |
204 | FOR_EACH_LIST_ELMT (ar, arl) | |
205 | { | |
206 | installedSomeHashes = TRUE; | |
207 | if (ar->id->choiceId == OIDORINT_OID) | |
208 | { | |
209 | fprintf (src," %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++); | |
210 | PrintCxxOidValue (src, r, ar->id->a.oid); | |
211 | fprintf (src,";\n"); | |
212 | } | |
213 | else if (ar->id->choiceId == OIDORINT_INTID) | |
214 | { | |
215 | fprintf (src," %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++); | |
216 | PrintCxxIntValue (src, r, ar->id->a.intId); | |
217 | fprintf (src,";\n"); | |
218 | } | |
219 | } | |
220 | } | |
221 | } | |
222 | ||
223 | ||
224 | FOR_EACH_LIST_ELMT (td, m->typeDefs) | |
225 | { | |
226 | if (td->anyRefs != NULL) | |
227 | { | |
228 | cxxtdi = td->cxxTypeDefInfo; | |
229 | FOR_EACH_LIST_ELMT (ar, td->anyRefs) | |
230 | { | |
231 | installedSomeHashes = TRUE; | |
232 | if (ar->id->choiceId == OIDORINT_OID) | |
233 | { | |
234 | fprintf (src," %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++); | |
235 | PrintCxxOidValue (src, r, ar->id->a.oid); | |
236 | fprintf (src,";\n"); | |
237 | } | |
238 | else if (ar->id->choiceId == OIDORINT_INTID) | |
239 | { | |
240 | fprintf (src," %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++); | |
241 | PrintCxxIntValue (src, r, ar->id->a.intId); | |
242 | fprintf (src,";\n"); | |
243 | } | |
244 | } | |
245 | } | |
246 | } | |
247 | ||
248 | ||
249 | /* now print hash init calls */ | |
250 | i = 0; | |
251 | for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++) | |
252 | { | |
253 | arl = LIBTYPE_GET_ANY_REFS (j); | |
254 | if (arl != NULL) | |
255 | { | |
256 | FOR_EACH_LIST_ELMT (ar, arl) | |
257 | { | |
258 | if (ar->id->choiceId == OIDORINT_OID) | |
259 | fprintf (src," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, r->typeConvTbl[j].className); | |
260 | ||
261 | else | |
262 | fprintf (src," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, r->typeConvTbl[j].className); | |
263 | ||
264 | } | |
265 | } | |
266 | } | |
267 | ||
268 | FOR_EACH_LIST_ELMT (td, m->typeDefs) | |
269 | { | |
270 | if (td->anyRefs != NULL) | |
271 | { | |
272 | FOR_EACH_LIST_ELMT (ar, td->anyRefs) | |
273 | { | |
274 | cxxtdi = td->cxxTypeDefInfo; | |
275 | ||
276 | if (ar->id->choiceId == OIDORINT_OID) | |
277 | fprintf (src," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, cxxtdi->className); | |
278 | ||
279 | else | |
280 | fprintf (src," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, cxxtdi->className); | |
281 | ||
282 | } | |
283 | } | |
284 | } | |
285 | ||
286 | if (!installedSomeHashes) | |
287 | { | |
288 | fprintf (src," /* Since no INTEGER/OID to ANY type relations were defined\n"); | |
289 | fprintf (src," * (usually done via MACROs) you must manually do the code\n"); | |
290 | fprintf (src," * to fill the hash tbl.\n"); | |
291 | fprintf (src," * if the ids are INTEGER use the following:\n"); | |
292 | fprintf (src," * AsnAny::InstallAnyByInt (3, ??_ANY_ID, new <className>);\n"); | |
293 | fprintf (src," * if the ids are OBJECT IDENTIFIERs use the following:\n"); | |
294 | fprintf (src," * AsnAny::InstallAnyByOid (OidValue, ??_ANY_ID, new <className>);\n"); | |
295 | fprintf (src," * put the ??_ANY_IDs in the AnyId enum.\n\n"); | |
296 | fprintf (src," * For example if you have some thing like\n"); | |
297 | fprintf (src," * T1 ::= SEQUENCE { id INTEGER, ANY DEFINED BY id }\n"); | |
298 | fprintf (src," * and the id 1 maps to the type BOOLEAN use the following:\n"); | |
299 | fprintf (src," * AsnAny::InstallAnyByInt (1, SOMEBOOL_ANY_ID, new AsnBool);\n"); | |
300 | fprintf (src," */\n ???????\n"); /* generate compile error */ | |
301 | fprintf (src," /* VDADER_RULES is selected UPDATE THIS COMMENT\n"); | |
302 | fprintf (src," */\n"); | |
303 | } | |
304 | ||
305 | ||
306 | fprintf (src,"} /* InitAny::InitAny */\n\n\n"); | |
307 | #endif | |
308 | ||
309 | } /* PrintAnyHashInitRoutine */ |