]>
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-code.c - generate C hdr and src files | |
21 | * | |
22 | * Assumes you have called FillCTypeInfo | |
23 | * | |
24 | * MS 92 | |
25 | * Copyright (C) 1991, 1992 Michael Sample | |
26 | * and the University of British Columbia | |
27 | * | |
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. | |
32 | * | |
a66d0d4a | 33 | * $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/Attic/gen-code2.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $ |
bac41a7b A |
34 | * $Log: gen-code2.c,v $ |
35 | * Revision 1.1.1.1 2001/05/18 23:14:09 mb | |
36 | * Move from private repository to open source repository | |
37 | * | |
38 | * Revision 1.2 2001/05/05 00:59:28 rmurphy | |
39 | * Adding darwin license headers | |
40 | * | |
41 | * Revision 1.1.1.1 1999/03/16 18:06:41 aram | |
42 | * Originals from SMIME Free Library. | |
43 | * | |
44 | * Revision 1.4 1995/07/25 18:39:46 rj | |
45 | * file name has been shortened for redundant part: c-gen/gen-c-code -> c-gen/gen-code. | |
46 | * | |
47 | * PrintConditionalIncludeOpen() and PrintConditionalIncludeClose() moved to back-ends/cond.c | |
48 | * | |
49 | * changed `_' to `-' in file names. | |
50 | * | |
51 | * Revision 1.3 1995/02/18 12:50:53 rj | |
52 | * typo fixed. | |
53 | * | |
54 | * Revision 1.2 1994/09/01 00:21:54 rj | |
55 | * snacc_config.h and other superfluous .h files removed. | |
56 | * | |
57 | * Revision 1.1 1994/08/28 09:48:17 rj | |
58 | * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. | |
59 | * | |
60 | */ | |
61 | ||
62 | #include <stdio.h> | |
63 | ||
64 | #include "asn-incl.h" | |
65 | #include "asn1module.h" | |
66 | #include "mem.h" | |
67 | #include "print.h" | |
68 | #include "rules.h" | |
69 | #include "type-info.h" | |
70 | #include "util.h" | |
71 | #include "cond.h" | |
72 | #include "gen-type.h" | |
73 | #include "gen-enc.h" | |
74 | #include "gen-dec.h" | |
75 | #include "gen-vals.h" | |
76 | #include "gen-free.h" | |
77 | #include "gen-print.h" | |
78 | #include "gen-any.h" | |
79 | #include "gen-code.h" | |
80 | ||
81 | /* unexported prototypes */ | |
82 | static void PrintCSrcComment PROTO ((FILE *src, Module *m)); | |
83 | static void PrintCSrcIncludes PROTO ((FILE *src, Module *m, ModuleList *mods)); | |
84 | static void PrintCHdrComment PROTO ((FILE *hdr, Module *m)); | |
85 | ||
86 | /* | |
87 | * Fills the hdr file with the C type and encode/decode prototypes | |
88 | * Fills the src file with the encoded/decode routine definitions | |
89 | */ | |
90 | void | |
91 | PrintCCode PARAMS ((src, hdr, mods, m, r, longJmpVal, printTypes, printValues, printEncoders, printDecoders, printPrinters, printFree), | |
92 | FILE *src _AND_ | |
93 | FILE *hdr _AND_ | |
94 | ModuleList *mods _AND_ | |
95 | Module *m _AND_ | |
96 | CRules *r _AND_ | |
97 | long int longJmpVal _AND_ | |
98 | int printTypes _AND_ | |
99 | int printValues _AND_ | |
100 | int printEncoders _AND_ | |
101 | int printDecoders _AND_ | |
102 | int printPrinters _AND_ | |
103 | int printFree) | |
104 | { | |
105 | TypeDef *td; | |
106 | ValueDef *vd; | |
107 | ||
108 | PrintCSrcComment (src, m); | |
109 | PrintCSrcIncludes (src, m, mods); | |
110 | ||
111 | PrintCHdrComment (hdr, m); | |
112 | PrintConditionalIncludeOpen (hdr, m->cHdrFileName); | |
113 | ||
114 | fprintf (hdr,"\n\n"); | |
115 | fprintf (src,"\n\n"); | |
116 | ||
117 | ||
118 | if (printValues) | |
119 | { | |
120 | /* put value defs at beginning of .c file */ | |
121 | FOR_EACH_LIST_ELMT (vd, m->valueDefs) | |
122 | { | |
123 | PrintCValueDef (src, r, vd); | |
124 | } | |
125 | } | |
126 | ||
127 | PrintCAnyCode (src, hdr, r, mods, m); | |
128 | ||
129 | FOR_EACH_LIST_ELMT (td, m->typeDefs) | |
130 | { | |
131 | if (printTypes) | |
132 | PrintCTypeDef (hdr, r, m, td); | |
133 | ||
134 | /* for PDU type or types ref'd with ANY/ANY DEF BY */ | |
135 | if (printEncoders && | |
136 | ((td->anyRefs != NULL) || td->cTypeDefInfo->isPdu)) | |
137 | PrintCBerEncoder (src, hdr, r, m, td); | |
138 | ||
139 | /* for PDU type or types ref'd with ANY/ANY DEF BY */ | |
140 | if (printDecoders && | |
141 | ((td->anyRefs != NULL) || td->cTypeDefInfo->isPdu)) | |
142 | PrintCBerDecoder (src, hdr, r, m, td, &longJmpVal); | |
143 | ||
144 | if (printEncoders) | |
145 | PrintCBerContentEncoder (src, hdr, r, m, td); | |
146 | ||
147 | if (printDecoders) | |
148 | PrintCBerContentDecoder (src, hdr, r, m, td, &longJmpVal); | |
149 | ||
150 | ||
151 | if (printPrinters) | |
152 | PrintCPrinter (src, hdr, r, mods, m, td); | |
153 | ||
154 | if (printFree) | |
155 | PrintCFree (src, hdr, r, mods, m, td); | |
156 | ||
157 | /* only print new lines for normal types */ | |
158 | switch (td->type->basicType->choiceId) | |
159 | { | |
160 | case BASICTYPE_SEQUENCEOF: /* list types */ | |
161 | case BASICTYPE_SETOF: | |
162 | case BASICTYPE_CHOICE: | |
163 | case BASICTYPE_SET: | |
164 | case BASICTYPE_SEQUENCE: | |
165 | fprintf (src, "\n\n\n"); | |
166 | /* fall through */ | |
167 | ||
168 | case BASICTYPE_IMPORTTYPEREF: /* type references */ | |
169 | case BASICTYPE_LOCALTYPEREF: | |
170 | case BASICTYPE_BOOLEAN: /* library type */ | |
171 | case BASICTYPE_REAL: /* library type */ | |
172 | case BASICTYPE_OCTETSTRING: /* library type */ | |
173 | case BASICTYPE_NULL: /* library type */ | |
174 | case BASICTYPE_OID: /* library type */ | |
175 | case BASICTYPE_INTEGER: /* library type */ | |
176 | case BASICTYPE_BITSTRING: /* library type */ | |
177 | case BASICTYPE_ENUMERATED: /* library type */ | |
178 | case BASICTYPE_ANYDEFINEDBY: /* ANY types */ | |
179 | case BASICTYPE_ANY: | |
180 | fprintf (hdr, "\n\n\n"); | |
181 | break; | |
182 | } | |
183 | ||
184 | } | |
185 | ||
186 | if (printValues) | |
187 | { | |
188 | /* put value externs at end of .h file */ | |
189 | FOR_EACH_LIST_ELMT (vd, m->valueDefs) | |
190 | { | |
191 | PrintCValueExtern (hdr, r, vd); | |
192 | } | |
193 | } | |
194 | ||
195 | PrintConditionalIncludeClose (hdr, m->cHdrFileName); | |
196 | ||
197 | } /* PrintCCode */ | |
198 | ||
199 | ||
200 | static void | |
201 | PrintCSrcComment PARAMS ((src, m), | |
202 | FILE *src _AND_ | |
203 | Module *m) | |
204 | { | |
205 | long int t; | |
206 | ||
207 | t = time (0); | |
208 | fprintf (src, "/*\n"); | |
209 | fprintf (src, " * %s\n *\n", m->cSrcFileName); | |
210 | fprintf (src, " * \"%s\" ASN.1 module encode/decode/print/free C src.\n *\n", m->modId->name); | |
211 | fprintf (src, " * This file was generated by snacc on %s *\n", ctime (&t)); | |
212 | fprintf (src, " * UBC snacc written by Mike Sample\n *\n"); | |
213 | fprintf (src, " * NOTE: This is a machine generated file - editing not recommended\n"); | |
214 | fprintf (src, " */\n\n\n"); | |
215 | ||
216 | } /* PrintSrcComment */ | |
217 | ||
218 | ||
219 | ||
220 | static void | |
221 | PrintCSrcIncludes PARAMS ((src, m, mods), | |
222 | FILE *src _AND_ | |
223 | Module *m _AND_ | |
224 | ModuleList *mods) | |
225 | { | |
226 | void *tmp; | |
227 | Module *impMod; | |
228 | ||
229 | /* | |
230 | * include snacc runtime library related hdrs | |
231 | */ | |
232 | fprintf (src, "\n#include \"asn-incl.h\"\n"); | |
233 | ||
234 | /* | |
235 | * print out include files in same order of the module | |
236 | * list. every module in the list includes the others and it's | |
237 | * own .h | |
238 | */ | |
239 | tmp = (void*)CURR_LIST_NODE (mods); | |
240 | FOR_EACH_LIST_ELMT (impMod, mods) | |
241 | { | |
242 | fprintf (src, "#include \"%s\"\n", impMod->cHdrFileName); | |
243 | } | |
244 | SET_CURR_LIST_NODE (mods, tmp); | |
245 | ||
246 | } /* PrintCSrcIncludes */ | |
247 | ||
248 | ||
249 | static void | |
250 | PrintCHdrComment PARAMS ((f, m), | |
251 | FILE *f _AND_ | |
252 | Module *m) | |
253 | { | |
254 | long int t; | |
255 | ||
256 | t = time (0); | |
257 | fprintf (f, "/*\n"); | |
258 | fprintf (f, " * %s\n *\n", m->cHdrFileName); | |
259 | fprintf (f, " * \"%s\" ASN.1 module C type definitions and prototypes\n *\n", m->modId->name); | |
260 | fprintf (f, " * This .h file was generated by snacc on %s *\n", ctime (&t)); | |
261 | fprintf (f, " * UBC snacc written compiler by Mike Sample\n *\n"); | |
262 | fprintf (f, " * NOTE: This is a machine generated file--editing not recommended\n"); | |
263 | fprintf (f, " */\n\n\n"); | |
264 | } /* PrintCHdrComment */ |