]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-any.c
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/c-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 encoding/decoding etc routines.
26 * Also prints an enum to identify each ANY mapping.
28 * if the given module has no ANY or ANY DEFINED BY types
32 * Copyright (C) 1991, 1992 Michael Sample
33 * and the University of British Columbia
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
40 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-any.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
42 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
43 * Move from private repository to open source repository
45 * Revision 1.2 2001/05/05 00:59:27 rmurphy
46 * Adding darwin license headers
48 * Revision 1.1 2000/05/10 21:35:01 rmurphy
49 * Adding back in base code files which had been moved to "2" versions.
51 * Revision 1.1.1.1 1999/03/16 18:06:41 aram
52 * Originals from SMIME Free Library.
54 * Revision 1.3 1995/07/25 18:33:43 rj
55 * file name has been shortened for redundant part: c-gen/gen-c-any -> c-gen/gen-any.
57 * changed `_' to `-' in file names.
59 * Revision 1.2 1994/09/01 00:21:15 rj
60 * snacc_config.h removed.
62 * Revision 1.1 1994/08/28 09:48:15 rj
63 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
71 #include "asn1module.h"
76 #include "lib-types.h"
82 void PrintCAnyEnum
PROTO ((FILE *hdr
, Module
*m
, CRules
*r
));
84 void PrintCAnyHashInitRoutine
PROTO ((FILE *src
, FILE *hdr
, ModuleList
*mods
, Module
*m
, CRules
*r
));
90 PrintCAnyCode
PARAMS ((src
, hdr
, r
, mods
, m
),
94 ModuleList
*mods _AND_
101 PrintCAnyEnum (hdr
, m
, r
);
102 PrintCAnyHashInitRoutine (src
, hdr
, mods
, m
, r
);
109 PrintCAnyEnum
PARAMS ((hdr
, m
, r
),
118 int firstPrinted
= TRUE
;
121 modName
= Asn1TypeName2CTypeName (m
->modId
->name
);
123 fprintf (hdr
,"typedef enum %sAnyId\n", modName
);
126 /* do any lib types */
127 for (i
= BASICTYPE_BOOLEAN
; i
< BASICTYPE_MACRODEF
; i
++)
129 arl
= LIBTYPE_GET_ANY_REFS (i
);
132 FOR_EACH_LIST_ELMT (ar
, arl
)
136 fprintf (hdr
," %s = %d", ar
->anyIdName
, anyEnumValG
++);
137 firstPrinted
= FALSE
;
142 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
144 if (td
->anyRefs
!= NULL
)
146 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
150 fprintf (hdr
," %s = %d", ar
->anyIdName
, anyEnumValG
++);
151 firstPrinted
= FALSE
;
155 if (firstPrinted
) /* none have been printed */
156 fprintf (hdr
,"/* NO INTEGER or OBJECT IDENTIFIER to ANY type relationships were defined (via MACROs or other mechanism) */\n???\n");
158 fprintf (hdr
,"} %sAnyId;\n\n\n", modName
);
165 PrintCAnyHashInitRoutine
PARAMS ((src
, hdr
, mods
, m
, r
),
168 ModuleList
*mods _AND_
178 enum BasicTypeChoiceId typeId
;
179 char *encRoutineName
;
180 char *decRoutineName
;
181 char *freeRoutineName
;
182 char *printRoutineName
;
183 int installedSomeHashes
= FALSE
;
185 /* print proto in hdr file */
186 modName
= Asn1TypeName2CTypeName (m
->modId
->name
);
187 fprintf (hdr
,"void InitAny%s();\n\n", modName
);
189 /* print routine to src file */
190 fprintf (src
,"void\nInitAny%s()\n", modName
);
193 /* first print value for OID's */
194 /* do any lib types first */
196 for (j
= BASICTYPE_BOOLEAN
; j
< BASICTYPE_MACRODEF
; j
++)
198 arl
= LIBTYPE_GET_ANY_REFS (j
);
201 FOR_EACH_LIST_ELMT (ar
, arl
)
203 installedSomeHashes
= TRUE
;
204 if (ar
->id
->choiceId
== OIDORINT_OID
)
206 fprintf (src
," %s oid%d =", r
->typeConvTbl
[BASICTYPE_OID
].cTypeName
, i
++);
207 PrintCOidValue (src
, r
, ar
->id
->a
.oid
);
214 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
216 if (td
->anyRefs
!= NULL
)
218 ctdi
= td
->cTypeDefInfo
;
219 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
221 installedSomeHashes
= TRUE
;
222 if (ar
->id
->choiceId
== OIDORINT_OID
)
224 fprintf (src
," %s oid%d =", r
->typeConvTbl
[BASICTYPE_OID
].cTypeName
, i
++);
225 PrintCOidValue (src
, r
, ar
->id
->a
.oid
);
232 fprintf (src
,"\n\n");
234 /* now print hash init calls */
237 /* do lib types first */
238 for (j
= BASICTYPE_BOOLEAN
; j
< BASICTYPE_MACRODEF
; j
++)
240 arl
= LIBTYPE_GET_ANY_REFS (j
);
243 FOR_EACH_LIST_ELMT (ar
, arl
)
246 encRoutineName
= r
->typeConvTbl
[j
].encodeRoutineName
;
247 decRoutineName
= r
->typeConvTbl
[j
].decodeRoutineName
;
248 printRoutineName
= r
->typeConvTbl
[j
].printRoutineName
;
251 * use NULL free routine for types that
252 * have empyt macros for their free routines
253 * (since the any hash tbl needs the addr of the routine)
257 case BASICTYPE_BOOLEAN
:
258 case BASICTYPE_INTEGER
:
261 case BASICTYPE_ENUMERATED
:
262 freeRoutineName
= "NULL";
265 freeRoutineName
= r
->typeConvTbl
[j
].freeRoutineName
;
268 if (ar
->id
->choiceId
== OIDORINT_OID
)
269 fprintf (src
," InstallAnyByOid (%s, &oid%d, sizeof (%s), (EncodeFcn) B%s, (DecodeFcn)B%s, (FreeFcn)%s, (PrintFcn)%s);\n\n", ar
->anyIdName
, i
++, r
->typeConvTbl
[j
].cTypeName
, encRoutineName
, decRoutineName
, freeRoutineName
, printRoutineName
);
271 fprintf (src
," InstallAnyByInt (%s, %d, sizeof (%s), (EncodeFcn) B%s, (DecodeFcn)B%s, (FreeFcn)%s, (PrintFcn)%s);\n\n", ar
->anyIdName
, ar
->id
->a
.intId
, r
->typeConvTbl
[j
].cTypeName
, encRoutineName
, decRoutineName
, freeRoutineName
, printRoutineName
);
276 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
278 if (td
->anyRefs
!= NULL
)
280 ctdi
= td
->cTypeDefInfo
;
281 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
283 typeId
= GetBuiltinType (td
->type
);
285 encRoutineName
= ctdi
->encodeRoutineName
;
286 decRoutineName
= ctdi
->decodeRoutineName
;
287 printRoutineName
= ctdi
->printRoutineName
;
290 * use NULL free routine for types that
291 * have empyt macros for their free routines
292 * (since the any hash tbl needs the addr of the routine)
296 case BASICTYPE_BOOLEAN
:
297 case BASICTYPE_INTEGER
:
300 case BASICTYPE_ENUMERATED
:
301 freeRoutineName
= "NULL";
304 freeRoutineName
= ctdi
->freeRoutineName
;
307 if (ar
->id
->choiceId
== OIDORINT_OID
)
308 fprintf (src
," InstallAnyByOid (%s, &oid%d, sizeof (%s), (EncodeFcn) B%s, (DecodeFcn)B%s, (FreeFcn)%s, (PrintFcn)%s);\n\n", ar
->anyIdName
, i
++, ctdi
->cTypeName
, encRoutineName
, decRoutineName
, freeRoutineName
, printRoutineName
);
310 fprintf (src
," InstallAnyByInt (%s, %d, sizeof (%s), (EncodeFcn) B%s, (DecodeFcn)B%s, (FreeFcn)%s, (PrintFcn)%s);\n\n", ar
->anyIdName
, ar
->id
->a
.intId
, ctdi
->cTypeName
, encRoutineName
, decRoutineName
, freeRoutineName
, printRoutineName
);
316 if (!installedSomeHashes
)
318 fprintf (src
," /* Since no INTEGER/OID to ANY type relations were defined\n");
319 fprintf (src
," * (usually done via MACROs) you must manually do the code\n");
320 fprintf (src
," * to fill the hash tbl.\n");
321 fprintf (src
," * if the ids are INTEGER use the following:\n");
322 fprintf (src
," * InstallAnyByInt (??_ANY_ID, intVal, sizeof (Foo), (EncodeFcn) BEncFoo, (DecodeFcn)BDecFoo, (FreeFcn)FreeFoo, (PrintFcn)PrintFoo);\n");
323 fprintf (src
," * if the ids are OBJECT IDENTIFIERs use the following:\n");
324 fprintf (src
," * InstallAnyByOid (??_ANY_ID, oidVal, sizeof (Foo), (EncodeFcn) BEncFoo, (DecodeFcn)BDecFoo, (FreeFcn)FreeFoo, (PrintFcn)PrintFoo);\n");
325 fprintf (src
," * put the ??_ANY_IDs in the AnyId enum.\n\n");
326 fprintf (src
," * For example if you have some thing like\n");
327 fprintf (src
," * T1 ::= SEQUENCE { id INTEGER, ANY DEFINED BY id }\n");
328 fprintf (src
," * and the id 1 maps to the type BOOLEAN use the following:\n");
329 fprintf (src
," * InstallAnyByInt (SOMEBOOL_ANY_ID, 1, sizeof (AsnBool), (EncodeFcn) BEncAsnBool, (DecodeFcn)BDecAsnBool, (FreeFcn)NULL, (PrintFcn)PrintAsnBool);;\n");
330 fprintf (src
," */\n ???????\n"); /* generate compile error */
334 fprintf (src
,"} /* InitAny%s */\n\n\n", modName
);
338 } /* PrintAnyHashInitRoutine */