]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c-gen/util.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/util.c - utilities for generating C encoders and decoders
23 * Copyright (C) 1991, 1992 Michael Sample
24 * and the University of British Columbia
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/util.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
33 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
34 * Move from private repository to open source repository
36 * Revision 1.2 2001/05/05 00:59:28 rmurphy
37 * Adding darwin license headers
39 * Revision 1.1.1.1 1999/03/16 18:06:44 aram
40 * Originals from SMIME Free Library.
42 * Revision 1.3 1995/07/25 18:48:38 rj
43 * changed `_' to `-' in file names.
45 * Revision 1.2 1994/09/01 00:26:52 rj
46 * snacc_config.h removed.
48 * Revision 1.1 1994/08/28 09:48:44 rj
49 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
56 #include "asn1module.h"
58 #include "snacc-util.h"
63 MakeVarPtrRef
PARAMS ((r
, td
, parent
, fieldType
, parentVarName
, newVarName
),
68 char *parentVarName _AND_
73 ctri
= fieldType
->cTypeRefInfo
;
75 /* always put in brackets to save future referencing hassles */
76 strcpy (newVarName
, "(");
78 /* make ref'd field into a ptr by taking it's addr if nec */
80 strcat (newVarName
, "&");
82 /* start with ref to parent */
83 strcat (newVarName
, parentVarName
);
86 if ((td
->type
== parent
) || (parent
->cTypeRefInfo
->isPtr
))
87 strcat (newVarName
, "->");
89 strcat (newVarName
, ".");
91 /* ref choice union field if nec */
92 if (parent
->basicType
->choiceId
== BASICTYPE_CHOICE
)
94 strcat (newVarName
, r
->choiceUnionFieldName
);
95 strcat (newVarName
, ".");
98 strcat (newVarName
, ctri
->cFieldName
);
99 strcat (newVarName
, ")");
101 } /* MakeVarPtrRef */
107 MakeVarValueRef
PARAMS ((r
, td
, parent
, fieldType
, parentVarName
, newVarName
),
111 Type
*fieldType _AND_
112 char *parentVarName _AND_
117 ctri
= fieldType
->cTypeRefInfo
;
119 /* always put in brackets to save future referencing hassles */
120 strcpy (newVarName
, "(");
122 /* make ref'd field into a value by de-referencing if nec */
124 strcat (newVarName
, "*");
126 /* start with ref to parent */
127 strcat (newVarName
, parentVarName
);
130 if ((td
->type
== parent
) || (parent
->cTypeRefInfo
->isPtr
))
131 strcat (newVarName
, "->");
133 strcat (newVarName
, ".");
135 /* ref choice union field if nec */
136 if (parent
->basicType
->choiceId
== BASICTYPE_CHOICE
)
138 strcat (newVarName
, r
->choiceUnionFieldName
);
139 strcat (newVarName
, ".");
142 strcat (newVarName
, ctri
->cFieldName
);
143 strcat (newVarName
, ")");
145 } /* MakeVarValueRef */
148 MakeChoiceIdValueRef
PARAMS ((r
, td
, parent
, fieldType
, parentVarName
, newVarName
),
152 Type
*fieldType _AND_
153 char *parentVarName _AND_
158 ctri
= fieldType
->cTypeRefInfo
;
160 /* always put in brackets to save future referencing hassles */
161 strcpy (newVarName
, "(");
163 /* start with ref to parent */
164 strcat (newVarName
, parentVarName
);
167 if ((td
->type
== parent
) || (parent
->cTypeRefInfo
->isPtr
))
168 strcat (newVarName
, "->");
170 strcat (newVarName
, ".");
172 strcat (newVarName
, parent
->cTypeRefInfo
->choiceIdEnumFieldName
);
173 strcat (newVarName
, ")");
175 } /* MakeChoiceIdValueRef */
179 PrintElmtAllocCode
PARAMS ((src
, type
, varRefPtrName
),
189 ctri1
= type
->cTypeRefInfo
;
190 ctri2
= t
->cTypeRefInfo
;
193 if (ctri2
->cTypeId
== C_LIST
)
194 fprintf (src
, " %s = AsnListNew (sizeof (char*));\n", varRefPtrName
);
196 fprintf (src
, " %s = (%s*) Asn1Alloc (sizeof (%s));\n", varRefPtrName
, ctri1
->cTypeName
, ctri1
->cTypeName
);
197 fprintf (src
," CheckAsn1Alloc (%s, env);\n", varRefPtrName
);
200 } /* PrintElmtAllocCode */
204 * prints code to decode EOCs for the lengths that go with extra tagging
205 * maxLenLevel - the highest used length variable (ie 2 for elmtLen2)
206 * minLenLevel - the lowest valid length variable (ie 0 for elmtLen0)
207 * lenBaseVarName - len var name sans number (ie elmtLen for elmtLen2)
208 * totalLevel - current level for the running total
209 * totalBaseName - total var name sans number
210 * (ie totalElmtLen for totalElmtLen1)
213 PrintEocDecoders
PARAMS ((f
, maxLenLevel
, minLenLevel
, lenBaseVarName
, totalLevel
, totalBaseVarName
),
215 int maxLenLevel _AND_
216 int minLenLevel _AND_
217 char *lenBaseVarName _AND_
219 char *totalBaseVarName
)
222 for (i
= maxLenLevel
; i
> minLenLevel
; i
--)
224 fprintf (f
," if (%s%d == INDEFINITE_LEN)\n", lenBaseVarName
, i
);
225 fprintf (f
," BDecEoc (b, &%s%d, env);\n", totalBaseVarName
, totalLevel
);
227 } /* PrintEocDeocoders */