Debian Codegraph @

compiler/back-ends/c++-gen/gen-vals.c

raw symbols SCIP
1 /*
2 * compiler/back_ends/c++_gen/gen_vals.c - prints ASN.1 values in c++ format
3 *
4 * MS 92
5 * Copyright (C) 1991, 1992 Michael Sample
6 * and the University of British Columbia
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * $Header: /baseline/SNACC/compiler/back-ends/c++-gen/gen-vals.c,v 1.8 2004/04/06 15:13:41 gronej Exp $
14 * $Log: gen-vals.c,v $
15 * Revision 1.8 2004/04/06 15:13:41 gronej
16 * *** empty log message ***
17 *
18 * Revision 1.7 2003/12/19 20:55:49 leonberp
19 * added parameter to PrintCxxOidValue() to allow printing of paren or quote to be specified.
20 *
21 * Revision 1.6 2003/07/07 14:52:35 nicholar
22 * Eliminated headers and cleaned up include references
23 *
24 * Revision 1.5 2002/10/21 17:18:52 mcphersc
25 * fixed long int
26 *
27 * Revision 1.4 2002/05/15 14:53:11 leonberp
28 * added support for new basicTypes to compiler
29 *
30 * Revision 1.3 2001/08/30 17:25:38 rwc
31 * Updated AsnOid constructor, automatic build of constants to now load strings, not
32 * the 10 parameter constructor choice (which was removed by Pierce eariler).
33 *
34 * Revision 1.2 2000/10/24 14:54:46 rwc
35 * Updated to remove high-level warnings (level 4 on MSVC++) for an easier build.
36 * SOME warnings persist due to difficulty in modifying the SNACC compiler to
37 * properly build clean source; also some files are built by Lex/Yacc.
38 *
39 * Revision 1.1.1.1 2000/08/21 20:36:06 leonberp
40 * First CVS Version of SNACC.
41 *
42 * Revision 1.4 1995/07/25 18:20:05 rj
43 * use true/false instead of AsnBool::true/false.
44 *
45 * changed `_' to `-' in file names.
46 *
47 * Revision 1.3 1994/10/08 03:47:57 rj
48 * since i was still irritated by cpp standing for c++ and not the C preprocessor, i renamed them to cxx (which is one known suffix for C++ source files). since the standard #define is __cplusplus, cplusplus would have been the more obvious choice, but it is a little too long.
49 *
50 * Revision 1.2 1994/09/01 00:17:22 rj
51 * snacc_config.h removed.
52 *
53 * Revision 1.1 1994/08/28 09:48:05 rj
54 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
55 *
56 */
57
58 #include "asn-incl.h"
59 #include "asn1module.h"
60 #include "str-util.h"
61 #include "rules.h"
62
63
64 extern char *bVDAGlobalDLLExport;
65
66
67 void PrintCxxValuesClass PROTO ((FILE *f, CxxRules *r, Value *v));
68 void PrintCxxValueInstantiation PROTO ((FILE *f, CxxRules *r, Value *v));
69 void PrintCxxOidValue PROTO ((FILE *f, CxxRules *r, AsnOid *oid, int parenOrQuote));
70 void PrintCxxIntValue PROTO ((FILE *f, CxxRules *r, AsnInt oid));
71 static void PrintCxxValueDefsName PROTO ((FILE *f, CxxRules *r, ValueDef *v));
72
73
74
75
76 void
77 PrintCxxValueDef PARAMS ((src, r, v),
78 FILE *src _AND_
79 CxxRules *r _AND_
80 ValueDef *v)
81 {
82 /* just do oid's, ints and bools for now */
83 if ((v->value->basicValue->choiceId != BASICVALUE_OID) &&
84 (v->value->basicValue->choiceId != BASICVALUE_INTEGER) &&
85 (v->value->basicValue->choiceId != BASICVALUE_BOOLEAN))
86 return;
87
88 if (v->value->basicValue->choiceId == BASICVALUE_OID)
89 {
90 fprintf(src, "const char *");
91 PrintCxxValueDefsName (src, r, v);
92 fprintf(src, " =""");
93 PrintCxxOidValue (src, r, v->value->basicValue->a.oid, 2);
94 fprintf(src, """;\n\n");
95 }
96 else
97 {
98 /*
99 * put instantiation in src file
100 */
101 fprintf (src, "const ");
102 PrintCxxValuesClass (src, r, v->value);
103 fprintf (src, " ");
104 PrintCxxValueDefsName (src, r, v);
105 fprintf (src, " ");
106 PrintCxxValueInstantiation (src, r, v->value);
107 fprintf (src, ";\n\n");
108 }
109
110
111 } /* PrintCxxValueDef */
112
113 void
114 PrintCxxValueExtern PARAMS ((hdr, r, v),
115 FILE *hdr _AND_
116 CxxRules *r _AND_
117 ValueDef *v)
118 {
119 /* just do oid's, ints and bools for now */
120 if ((v->value->basicValue->choiceId != BASICVALUE_OID) &&
121 (v->value->basicValue->choiceId != BASICVALUE_INTEGER) &&
122 (v->value->basicValue->choiceId != BASICVALUE_BOOLEAN))
123 return;
124
125 /*
126 * put extern declaration in hdr file
127 */
128 if (bVDAGlobalDLLExport != NULL)
129 fprintf (hdr, "extern const %s ", bVDAGlobalDLLExport);
130 else
131 fprintf (hdr, "extern const ");
132
133 if (v->value->basicValue->choiceId == BASICVALUE_OID)
134 {
135 fprintf(hdr, "char *");
136 PrintCxxValueDefsName (hdr, r, v);
137 fprintf(hdr, ";\n");
138 }
139 else
140 {
141 PrintCxxValuesClass (hdr, r, v->value);
142 fprintf (hdr, " ");
143 PrintCxxValueDefsName (hdr, r, v);
144 fprintf (hdr, ";\n");
145 }
146
147 } /* PrintCxxValueExtern */
148
149
150 static void
151 PrintCxxValueDefsName PARAMS ((f, r, v),
152 FILE *f _AND_
153 CxxRules *r _AND_
154 ValueDef *v)
155 {
156 char *cName;
157 cName = Asn1ValueName2CValueName (v->definedName);
158 fprintf (f, "%s", cName);
159 Free (cName);
160 r=r; /*AVOIDS warning.*/
161 }
162
163 void
164 PrintCxxValuesClass PARAMS ((f, r, v),
165 FILE *f _AND_
166 CxxRules *r _AND_
167 Value *v)
168 {
169 /* needs work - just do ints bools and oid's for now */
170 switch (v->basicValue->choiceId)
171 {
172 case BASICVALUE_OID:
173 fprintf (f, "%s", r->typeConvTbl[BASICTYPE_OID].className);
174 break;
175
176 case BASICVALUE_INTEGER:
177 fprintf (f, "%s", r->typeConvTbl[BASICTYPE_INTEGER].className);
178 break;
179
180 case BASICVALUE_BOOLEAN:
181 fprintf (f, "%s", r->typeConvTbl[BASICTYPE_BOOLEAN].className);
182 break;
183
184 default:
185 break;
186 }
187 }
188
189
190 void
191 PrintCxxValueInstantiation PARAMS ((f, r, v),
192 FILE *f _AND_
193 CxxRules *r _AND_
194 Value *v)
195 {
196 /* needs work - just do oids, ints and bools for now */
197 switch (v->basicValue->choiceId)
198 {
199 case BASICVALUE_OID:
200 PrintCxxOidValue (f, r, v->basicValue->a.oid, 1);
201 break;
202
203 case BASICVALUE_INTEGER:
204 PrintCxxIntValue (f, r, v->basicValue->a.integer);
205 break;
206
207 case BASICVALUE_BOOLEAN:
208 fprintf (f, "(%s)", v->basicValue->a.boolean ? "true" : "false");
209 break;
210
211 default:
212 break;
213 }
214 }
215
216
217
218 /*
219 * given an AOID, c++ AOID constructors params are produced.
220 * This is used for turning ASN.1 OBJECT ID values
221 * into usable c++ values.
222 *
223 * eg for the oid { 0 1 2 } (in AOID format)
224 * (0,1,2)
225 * is produced.
226 *
227 * To wrap the dotted notation in parens pass in a parenOrQuote value of 1
228 *
229 * To wrap the dotted notation in quotes pass in a parenOrQuote value of 2
230 */
231 void
232 PrintCxxOidValue (FILE *f, CxxRules *r, AsnOid *v, int parenOrQuote)
233 {
234 unsigned short int firstArcNum;
235 unsigned long arcNum;
236 int i;
237
238 if (parenOrQuote == 1)
239 fprintf (f, "(\"");
240 else
241 fprintf (f, "\"");
242
243 /* un-munge first two arc numbers */
244 for (arcNum = 0, i=0; (i < (int)v->octetLen) && (v->octs[i] & 0x80);i++)
245 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
246
247 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
248 i++;
249 firstArcNum = (unsigned short)(arcNum/40);
250 if (firstArcNum > 2)
251 firstArcNum = 2;
252
253 #ifdef NOW_CONST_OIDS_ARE_STRINGS
254 fprintf (f, "%u, %u", firstArcNum, arcNum - (firstArcNum * 40));
255 #else
256 fprintf (f, "%u.%lu", firstArcNum, arcNum - (firstArcNum * 40));
257 #endif
258 for (; i < (int)v->octetLen; )
259 {
260 for (arcNum = 0; (i < (int)v->octetLen) && (v->octs[i] & 0x80);i++)
261 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
262
263 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
264 i++;
265
266 #ifdef NOW_CONST_OIDS_ARE_STRINGS
267 fprintf (f, ", %u", arcNum);
268 #else
269 fprintf (f, ".%lu", arcNum);
270 #endif
271 }
272
273 if (parenOrQuote == 1)
274 fprintf (f, "\")");
275 else
276 fprintf (f, "\"");
277
278 r=r; /*AVOIDS warning.*/
279 } /* PrintCxxOidValue */
280
281
282
283 void
284 PrintCxxIntValue PARAMS ((f, r, v),
285 FILE *f _AND_
286 CxxRules *r _AND_
287 AsnInt v)
288 {
289 fprintf (f, "(%d)", v);
290 r=r; /*AVOIDS warning.*/
291 } /* PrintCxxIntValue */