]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-code2.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-code2.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
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
38 * Revision 1.2 2001/05/05 00:59:28 rmurphy
39 * Adding darwin license headers
41 * Revision 1.1.1.1 1999/03/16 18:06:41 aram
42 * Originals from SMIME Free Library.
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.
47 * PrintConditionalIncludeOpen() and PrintConditionalIncludeClose() moved to back-ends/cond.c
49 * changed `_' to `-' in file names.
51 * Revision 1.3 1995/02/18 12:50:53 rj
54 * Revision 1.2 1994/09/01 00:21:54 rj
55 * snacc_config.h and other superfluous .h files removed.
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.
65 #include "asn1module.h"
69 #include "type-info.h"
77 #include "gen-print.h"
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
));
87 * Fills the hdr file with the C type and encode/decode prototypes
88 * Fills the src file with the encoded/decode routine definitions
91 PrintCCode
PARAMS ((src
, hdr
, mods
, m
, r
, longJmpVal
, printTypes
, printValues
, printEncoders
, printDecoders
, printPrinters
, printFree
),
94 ModuleList
*mods _AND_
97 long int longJmpVal _AND_
100 int printEncoders _AND_
101 int printDecoders _AND_
102 int printPrinters _AND_
108 PrintCSrcComment (src
, m
);
109 PrintCSrcIncludes (src
, m
, mods
);
111 PrintCHdrComment (hdr
, m
);
112 PrintConditionalIncludeOpen (hdr
, m
->cHdrFileName
);
114 fprintf (hdr
,"\n\n");
115 fprintf (src
,"\n\n");
120 /* put value defs at beginning of .c file */
121 FOR_EACH_LIST_ELMT (vd
, m
->valueDefs
)
123 PrintCValueDef (src
, r
, vd
);
127 PrintCAnyCode (src
, hdr
, r
, mods
, m
);
129 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
132 PrintCTypeDef (hdr
, r
, m
, td
);
134 /* for PDU type or types ref'd with ANY/ANY DEF BY */
136 ((td
->anyRefs
!= NULL
) || td
->cTypeDefInfo
->isPdu
))
137 PrintCBerEncoder (src
, hdr
, r
, m
, td
);
139 /* for PDU type or types ref'd with ANY/ANY DEF BY */
141 ((td
->anyRefs
!= NULL
) || td
->cTypeDefInfo
->isPdu
))
142 PrintCBerDecoder (src
, hdr
, r
, m
, td
, &longJmpVal
);
145 PrintCBerContentEncoder (src
, hdr
, r
, m
, td
);
148 PrintCBerContentDecoder (src
, hdr
, r
, m
, td
, &longJmpVal
);
152 PrintCPrinter (src
, hdr
, r
, mods
, m
, td
);
155 PrintCFree (src
, hdr
, r
, mods
, m
, td
);
157 /* only print new lines for normal types */
158 switch (td
->type
->basicType
->choiceId
)
160 case BASICTYPE_SEQUENCEOF
: /* list types */
161 case BASICTYPE_SETOF
:
162 case BASICTYPE_CHOICE
:
164 case BASICTYPE_SEQUENCE
:
165 fprintf (src
, "\n\n\n");
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 */
180 fprintf (hdr
, "\n\n\n");
188 /* put value externs at end of .h file */
189 FOR_EACH_LIST_ELMT (vd
, m
->valueDefs
)
191 PrintCValueExtern (hdr
, r
, vd
);
195 PrintConditionalIncludeClose (hdr
, m
->cHdrFileName
);
201 PrintCSrcComment
PARAMS ((src
, m
),
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");
216 } /* PrintSrcComment */
221 PrintCSrcIncludes
PARAMS ((src
, m
, mods
),
230 * include snacc runtime library related hdrs
232 fprintf (src
, "\n#include \"asn-incl.h\"\n");
235 * print out include files in same order of the module
236 * list. every module in the list includes the others and it's
239 tmp
= (void*)CURR_LIST_NODE (mods
);
240 FOR_EACH_LIST_ELMT (impMod
, mods
)
242 fprintf (src
, "#include \"%s\"\n", impMod
->cHdrFileName
);
244 SET_CURR_LIST_NODE (mods
, tmp
);
246 } /* PrintCSrcIncludes */
250 PrintCHdrComment
PARAMS ((f
, m
),
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 */