]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-code.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-code.c - generate C hdr and src files
22 * Assumes you have called FillCTypeInfo
25 * Copyright (C) 1991, 1992 Michael Sample
26 * and the University of British Columbia
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version.
33 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-code.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
34 * $Log: gen-code.c,v $
35 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
36 * Move from private repository to open source repository
38 * Revision 1.2 2001/05/05 00:59:28 rmurphy
39 * Adding darwin license headers
41 * Revision 1.1 2000/05/10 21:35:01 rmurphy
42 * Adding back in base code files which had been moved to "2" versions.
44 * Revision 1.1.1.1 1999/03/16 18:06:41 aram
45 * Originals from SMIME Free Library.
47 * Revision 1.4 1995/07/25 18:39:46 rj
48 * file name has been shortened for redundant part: c-gen/gen-c-code -> c-gen/gen-code.
50 * PrintConditionalIncludeOpen() and PrintConditionalIncludeClose() moved to back-ends/cond.c
52 * changed `_' to `-' in file names.
54 * Revision 1.3 1995/02/18 12:50:53 rj
57 * Revision 1.2 1994/09/01 00:21:54 rj
58 * snacc_config.h and other superfluous .h files removed.
60 * Revision 1.1 1994/08/28 09:48:17 rj
61 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
68 #include "asn1module.h"
72 #include "type-info.h"
80 #include "gen-print.h"
84 /* unexported prototypes */
85 static void PrintCSrcComment
PROTO ((FILE *src
, Module
*m
));
86 static void PrintCSrcIncludes
PROTO ((FILE *src
, Module
*m
, ModuleList
*mods
));
87 static void PrintCHdrComment
PROTO ((FILE *hdr
, Module
*m
));
90 * Fills the hdr file with the C type and encode/decode prototypes
91 * Fills the src file with the encoded/decode routine definitions
94 PrintCCode
PARAMS ((src
, hdr
, mods
, m
, r
, longJmpVal
, printTypes
, printValues
, printEncoders
, printDecoders
, printPrinters
, printFree
),
97 ModuleList
*mods _AND_
100 long int longJmpVal _AND_
102 int printValues _AND_
103 int printEncoders _AND_
104 int printDecoders _AND_
105 int printPrinters _AND_
111 PrintCSrcComment (src
, m
);
112 PrintCSrcIncludes (src
, m
, mods
);
114 PrintCHdrComment (hdr
, m
);
115 PrintConditionalIncludeOpen (hdr
, m
->cHdrFileName
);
117 fprintf (hdr
,"\n\n");
118 fprintf (src
,"\n\n");
123 /* put value defs at beginning of .c file */
124 FOR_EACH_LIST_ELMT (vd
, m
->valueDefs
)
126 PrintCValueDef (src
, r
, vd
);
130 PrintCAnyCode (src
, hdr
, r
, mods
, m
);
132 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
135 PrintCTypeDef (hdr
, r
, m
, td
);
137 /* for PDU type or types ref'd with ANY/ANY DEF BY */
139 ((td
->anyRefs
!= NULL
) || td
->cTypeDefInfo
->isPdu
))
140 PrintCBerEncoder (src
, hdr
, r
, m
, td
);
142 /* for PDU type or types ref'd with ANY/ANY DEF BY */
144 ((td
->anyRefs
!= NULL
) || td
->cTypeDefInfo
->isPdu
))
145 PrintCBerDecoder (src
, hdr
, r
, m
, td
, &longJmpVal
);
148 PrintCBerContentEncoder (src
, hdr
, r
, m
, td
);
151 PrintCBerContentDecoder (src
, hdr
, r
, m
, td
, &longJmpVal
);
155 PrintCPrinter (src
, hdr
, r
, mods
, m
, td
);
158 PrintCFree (src
, hdr
, r
, mods
, m
, td
);
160 /* only print new lines for normal types */
161 switch (td
->type
->basicType
->choiceId
)
163 case BASICTYPE_SEQUENCEOF
: /* list types */
164 case BASICTYPE_SETOF
:
165 case BASICTYPE_CHOICE
:
167 case BASICTYPE_SEQUENCE
:
168 fprintf (src
, "\n\n\n");
171 case BASICTYPE_IMPORTTYPEREF
: /* type references */
172 case BASICTYPE_LOCALTYPEREF
:
173 case BASICTYPE_BOOLEAN
: /* library type */
174 case BASICTYPE_REAL
: /* library type */
175 case BASICTYPE_OCTETSTRING
: /* library type */
176 case BASICTYPE_NULL
: /* library type */
177 case BASICTYPE_OID
: /* library type */
178 case BASICTYPE_INTEGER
: /* library type */
179 case BASICTYPE_BITSTRING
: /* library type */
180 case BASICTYPE_ENUMERATED
: /* library type */
181 case BASICTYPE_ANYDEFINEDBY
: /* ANY types */
183 fprintf (hdr
, "\n\n\n");
191 /* put value externs at end of .h file */
192 FOR_EACH_LIST_ELMT (vd
, m
->valueDefs
)
194 PrintCValueExtern (hdr
, r
, vd
);
198 PrintConditionalIncludeClose (hdr
, m
->cHdrFileName
);
204 PrintCSrcComment
PARAMS ((src
, m
),
211 fprintf (src
, "/*\n");
212 fprintf (src
, " * %s\n *\n", m
->cSrcFileName
);
213 fprintf (src
, " * \"%s\" ASN.1 module encode/decode/print/free C src.\n *\n", m
->modId
->name
);
214 fprintf (src
, " * This file was generated by snacc on %s *\n", ctime (&t
));
215 fprintf (src
, " * UBC snacc written by Mike Sample\n *\n");
216 fprintf (src
, " * NOTE: This is a machine generated file - editing not recommended\n");
217 fprintf (src
, " */\n\n\n");
219 } /* PrintSrcComment */
224 PrintCSrcIncludes
PARAMS ((src
, m
, mods
),
233 * include snacc runtime library related hdrs
235 fprintf (src
, "\n#include \"asn-incl.h\"\n");
238 * print out include files in same order of the module
239 * list. every module in the list includes the others and it's
242 tmp
= (void*)CURR_LIST_NODE (mods
);
243 FOR_EACH_LIST_ELMT (impMod
, mods
)
245 fprintf (src
, "#include \"%s\"\n", impMod
->cHdrFileName
);
247 SET_CURR_LIST_NODE (mods
, tmp
);
249 } /* PrintCSrcIncludes */
253 PrintCHdrComment
PARAMS ((f
, m
),
261 fprintf (f
, " * %s\n *\n", m
->cHdrFileName
);
262 fprintf (f
, " * \"%s\" ASN.1 module C type definitions and prototypes\n *\n", m
->modId
->name
);
263 fprintf (f
, " * This .h file was generated by snacc on %s *\n", ctime (&t
));
264 fprintf (f
, " * UBC snacc written compiler by Mike Sample\n *\n");
265 fprintf (f
, " * NOTE: This is a machine generated file--editing not recommended\n");
266 fprintf (f
, " */\n\n\n");
267 } /* PrintCHdrComment */