]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-any2.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/root/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/Attic/gen-any2.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
41 * $Log: gen-any2.c,v $
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:28 rmurphy
46 * Adding darwin license headers
48 * Revision 1.1.1.1 1999/03/16 18:06:41 aram
49 * Originals from SMIME Free Library.
51 * Revision 1.3 1995/07/25 18:33:43 rj
52 * file name has been shortened for redundant part: c-gen/gen-c-any -> c-gen/gen-any.
54 * changed `_' to `-' in file names.
56 * Revision 1.2 1994/09/01 00:21:15 rj
57 * snacc_config.h removed.
59 * Revision 1.1 1994/08/28 09:48:15 rj
60 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
68 #include "asn1module.h"
73 #include "lib-types.h"
79 void PrintCAnyEnum
PROTO ((FILE *hdr
, Module
*m
, CRules
*r
));
81 void PrintCAnyHashInitRoutine
PROTO ((FILE *src
, FILE *hdr
, ModuleList
*mods
, Module
*m
, CRules
*r
));
87 PrintCAnyCode
PARAMS ((src
, hdr
, r
, mods
, m
),
91 ModuleList
*mods _AND_
98 PrintCAnyEnum (hdr
, m
, r
);
99 PrintCAnyHashInitRoutine (src
, hdr
, mods
, m
, r
);
106 PrintCAnyEnum
PARAMS ((hdr
, m
, r
),
115 int firstPrinted
= TRUE
;
118 modName
= Asn1TypeName2CTypeName (m
->modId
->name
);
120 fprintf (hdr
,"typedef enum %sAnyId\n", modName
);
123 /* do any lib types */
124 for (i
= BASICTYPE_BOOLEAN
; i
< BASICTYPE_MACRODEF
; i
++)
126 arl
= LIBTYPE_GET_ANY_REFS (i
);
129 FOR_EACH_LIST_ELMT (ar
, arl
)
133 fprintf (hdr
," %s = %d", ar
->anyIdName
, anyEnumValG
++);
134 firstPrinted
= FALSE
;
139 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
141 if (td
->anyRefs
!= NULL
)
143 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
147 fprintf (hdr
," %s = %d", ar
->anyIdName
, anyEnumValG
++);
148 firstPrinted
= FALSE
;
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");
155 fprintf (hdr
,"} %sAnyId;\n\n\n", modName
);
162 PrintCAnyHashInitRoutine
PARAMS ((src
, hdr
, mods
, m
, r
),
165 ModuleList
*mods _AND_
175 enum BasicTypeChoiceId typeId
;
176 char *encRoutineName
;
177 char *decRoutineName
;
178 char *freeRoutineName
;
179 char *printRoutineName
;
180 int installedSomeHashes
= FALSE
;
182 /* print proto in hdr file */
183 modName
= Asn1TypeName2CTypeName (m
->modId
->name
);
184 fprintf (hdr
,"void InitAny%s();\n\n", modName
);
186 /* print routine to src file */
187 fprintf (src
,"void\nInitAny%s()\n", modName
);
190 /* first print value for OID's */
191 /* do any lib types first */
193 for (j
= BASICTYPE_BOOLEAN
; j
< BASICTYPE_MACRODEF
; j
++)
195 arl
= LIBTYPE_GET_ANY_REFS (j
);
198 FOR_EACH_LIST_ELMT (ar
, arl
)
200 installedSomeHashes
= TRUE
;
201 if (ar
->id
->choiceId
== OIDORINT_OID
)
203 fprintf (src
," %s oid%d =", r
->typeConvTbl
[BASICTYPE_OID
].cTypeName
, i
++);
204 PrintCOidValue (src
, r
, ar
->id
->a
.oid
);
211 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
213 if (td
->anyRefs
!= NULL
)
215 ctdi
= td
->cTypeDefInfo
;
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
].cTypeName
, i
++);
222 PrintCOidValue (src
, r
, ar
->id
->a
.oid
);
229 fprintf (src
,"\n\n");
231 /* now print hash init calls */
234 /* do lib types first */
235 for (j
= BASICTYPE_BOOLEAN
; j
< BASICTYPE_MACRODEF
; j
++)
237 arl
= LIBTYPE_GET_ANY_REFS (j
);
240 FOR_EACH_LIST_ELMT (ar
, arl
)
243 encRoutineName
= r
->typeConvTbl
[j
].encodeRoutineName
;
244 decRoutineName
= r
->typeConvTbl
[j
].decodeRoutineName
;
245 printRoutineName
= r
->typeConvTbl
[j
].printRoutineName
;
248 * use NULL free routine for types that
249 * have empyt macros for their free routines
250 * (since the any hash tbl needs the addr of the routine)
254 case BASICTYPE_BOOLEAN
:
255 case BASICTYPE_INTEGER
:
258 case BASICTYPE_ENUMERATED
:
259 freeRoutineName
= "NULL";
262 freeRoutineName
= r
->typeConvTbl
[j
].freeRoutineName
;
265 if (ar
->id
->choiceId
== OIDORINT_OID
)
266 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
);
268 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
);
273 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
275 if (td
->anyRefs
!= NULL
)
277 ctdi
= td
->cTypeDefInfo
;
278 FOR_EACH_LIST_ELMT (ar
, td
->anyRefs
)
280 typeId
= GetBuiltinType (td
->type
);
282 encRoutineName
= ctdi
->encodeRoutineName
;
283 decRoutineName
= ctdi
->decodeRoutineName
;
284 printRoutineName
= ctdi
->printRoutineName
;
287 * use NULL free routine for types that
288 * have empyt macros for their free routines
289 * (since the any hash tbl needs the addr of the routine)
293 case BASICTYPE_BOOLEAN
:
294 case BASICTYPE_INTEGER
:
297 case BASICTYPE_ENUMERATED
:
298 freeRoutineName
= "NULL";
301 freeRoutineName
= ctdi
->freeRoutineName
;
304 if (ar
->id
->choiceId
== OIDORINT_OID
)
305 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
);
307 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
);
313 if (!installedSomeHashes
)
315 fprintf (src
," /* Since no INTEGER/OID to ANY type relations were defined\n");
316 fprintf (src
," * (usually done via MACROs) you must manually do the code\n");
317 fprintf (src
," * to fill the hash tbl.\n");
318 fprintf (src
," * if the ids are INTEGER use the following:\n");
319 fprintf (src
," * InstallAnyByInt (??_ANY_ID, intVal, sizeof (Foo), (EncodeFcn) BEncFoo, (DecodeFcn)BDecFoo, (FreeFcn)FreeFoo, (PrintFcn)PrintFoo);\n");
320 fprintf (src
," * if the ids are OBJECT IDENTIFIERs use the following:\n");
321 fprintf (src
," * InstallAnyByOid (??_ANY_ID, oidVal, sizeof (Foo), (EncodeFcn) BEncFoo, (DecodeFcn)BDecFoo, (FreeFcn)FreeFoo, (PrintFcn)PrintFoo);\n");
322 fprintf (src
," * put the ??_ANY_IDs in the AnyId enum.\n\n");
323 fprintf (src
," * For example if you have some thing like\n");
324 fprintf (src
," * T1 ::= SEQUENCE { id INTEGER, ANY DEFINED BY id }\n");
325 fprintf (src
," * and the id 1 maps to the type BOOLEAN use the following:\n");
326 fprintf (src
," * InstallAnyByInt (SOMEBOOL_ANY_ID, 1, sizeof (AsnBool), (EncodeFcn) BEncAsnBool, (DecodeFcn)BDecAsnBool, (FreeFcn)NULL, (PrintFcn)PrintAsnBool);;\n");
327 fprintf (src
," */\n ???????\n"); /* generate compile error */
331 fprintf (src
,"} /* InitAny%s */\n\n\n", modName
);
335 } /* PrintAnyHashInitRoutine */