]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/c++-gen/gen-code.c
Security-54.1.3.tar.gz
[apple/security.git] / SecuritySNACCRuntime / compiler / back-ends / c++-gen / gen-code.c
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 /*
21 * compiler/back_ends/c++_gen/gen_code.c - routines for printing C++ code from type trees
22 *
23 * assumes that the type tree has already been run through the
24 * c++ type generator (c++_gen/types.c).
25 *
26 * This was hastily written - it has some huge routines in it.
27 * Needs a lot of cleaning up and modularization...
28 *
29 * Mike Sample
30 * 92
31 * Copyright (C) 1991, 1992 Michael Sample
32 * and the University of British Columbia
33 *
34 * This program is free software; you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License as published by
36 * the Free Software Foundation; either version 2 of the License, or
37 * (at your option) any later version.
38 *
39 * INSERT_VDA_COMMENTS
40 *
41 *
42 * $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/compiler/back-ends/c++-gen/gen-code.c,v 1.4 2002/03/21 05:38:53 dmitch Exp $
43 * $Log: gen-code.c,v $
44 * Revision 1.4 2002/03/21 05:38:53 dmitch
45 * Radar 2868524: no more setjmp/longjmp in SNACC-generated code.
46 *
47 * Revision 1.3.44.3 2002/03/20 20:56:39 dmitch
48 * Further refinements for Radar 2868524: no more BDecPdu or BEncPdu.
49 *
50 * Revision 1.3.44.2 2002/03/20 02:53:09 dmitch
51 * Avoid the unused and uninitialized jmp_buf var in BDecPdu.
52 *
53 * Revision 1.3.44.1 2002/03/20 00:36:59 dmitch
54 * Radar 2868524: SNACC-generated code now uses throw/catch instead of setjmp/longjmp.
55 *
56 * Revision 1.3 2001/06/27 23:51:42 dmitch
57 * Reimplement partial fix for Radar 2664258: Print() routines are now empty stubs in NDEBUG config.
58 *
59 * Revision 1.2 2001/06/27 23:07:00 dmitch
60 * Pusuant to Radar 2664258, Print() member functions are now conditional on #ifndef NDEBUG.
61 *
62 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
63 * Move from private repository to open source repository
64 *
65 * Revision 1.4 2001/05/05 00:59:27 rmurphy
66 * Adding darwin license headers
67 *
68 * Revision 1.3 1999/03/20 03:13:48 mb
69 * Generate Copy member functions.
70 *
71 * Revision 1.2 1999/03/17 01:54:54 aram
72 * Changed compiler so that the destructors and Clone methods are virtual.
73 *
74 * Revision 1.1.1.1 1999/03/16 18:06:39 aram
75 * Originals from SMIME Free Library.
76 *
77 * Revision 1.12 1997/02/28 13:39:53 wan
78 * Modifications collected for new version 1.3: Bug fixes, tk4.2.
79 *
80 * Revision 1.11 1997/02/16 15:14:06 rj
81 * made return *this after calling abort()'' a compile time option.
82 *
83 * Revision 1.10 1997/02/16 12:46:31 rj
84 * use the TIME_WITH_SYS_TIME flag (checked and generated by configure).
85 * return *this after calling abort() for compilers that don't know about this volatile function.
86 * comment out unused parameters, the compiler otherwise may complain.
87 *
88 * Revision 1.9 1995/09/07 20:47:32 rj
89 * deep copying assingment operators added.
90 *
91 * Revision 1.8 1995/09/07 19:25:27 rj
92 * PrintCxxCode(): boolean genMeta changed to enum type MetaNameStyle. used globally in printMetaG.
93 *
94 * set Tcl's errorCode variable.
95 *
96 * Revision 1.7 1995/08/17 15:00:06 rj
97 * the PDU flag belongs to the metacode, not only to the tcl interface. (type and variable named adjusted)
98 *
99 * Revision 1.6 1995/07/27 10:52:28 rj
100 * include config.h before using its #define's :-)
101 *
102 * file name has been shortened for redundant part: c++-gen/gen-c++-code -> c++-gen/gen-code.
103 *
104 * functions used only locally made static.
105 *
106 * #if TCL ... #endif wrapped into #if META ... #endif, both here and in generated files.
107 *
108 * code changes to allow for more than one PDU (meta code), e.g. generate -create() functions.
109 *
110 * generate additional TclUnsetVal() function to delete OPTIONAL members and SEQUENCE OF and SET OF list elements.
111 *
112 * _getref() gets an additional optional argument to faciliate the different member access semantics of TclGetVal() and TclSetVal().
113 *
114 * the list functions Append(), Prepend(), InsertBefore() and InsertAfter() now set the current element to the element just inserted.
115 *
116 * changed `_' to `-' in file names.
117 *
118 * Revision 1.5 1995/02/18 14:45:16 rj
119 * tried to make the print function's output a little more readable. [kho]
120 *
121 * Revision 1.4 1994/10/08 03:19:24 rj
122 * 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.
123 *
124 * turned the functions order upside down to get rid of those annoying declarations.
125 *
126 * turned character pointers into constant character arrays.
127 *
128 * code for meta structures added (provides information about the generated code itself).
129 *
130 * code for Tcl interface added (makes use of the above mentioned meta code).
131 *
132 * instead of being a no-op, the no-arg-constructors (that get used by Clone()) do something useful now, namely:
133 * - initialize the pointer in a choice union. (the destruktor may try to free the bogus pointer).
134 * - for the same reason: initialize pointers in sequences and sets.
135 *
136 * to complement the destructors, T::T (const T&) and T &T::operator = (const T &) have been added to override the defaults supplied by the compiler.
137 * reason: simple pointer duplication may lead to unreferenced objects and to objects referenced more than once (on which the destructors delete may choke).
138 *
139 * virtual inline functions (the destructor and the Clone() function) moved from inc/*.h to src/*.C because g++ turns every one of them into a static non-inline function in every file where the .h file gets included.
140 *
141 * made Print() const (and some other, mainly comparison functions).
142 *
143 * Revision 1.3 1994/09/01 00:16:29 rj
144 * change of IBM ENC integrated: large inlines turned into normal functions.
145 * more portable .h file inclusion.
146 *
147 * Revision 1.2 1994/08/31 09:49:05 rj
148 * for the C++ code generated: turned TRUE/FALSE into true/false;
149 * the keyword `struct' had to be removed before AsnListElmt, or gcc 2.6 wouldn't compile the generated code.
150 *
151 * Revision 1.1 1994/08/28 09:48:01 rj
152 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
153 *
154 */
155
156 #include "snacc.h"
157
158 #if TIME_WITH_SYS_TIME
159 # include <sys/time.h>
160 # include <time.h>
161 #else
162 # if HAVE_SYS_TIME_H
163 # include <sys/time.h>
164 # else
165 # include <time.h>
166 # endif
167 #endif
168
169 #if STDC_HEADERS || HAVE_STRING_H
170 #include <string.h>
171 #else
172 #include <strings.h>
173 #endif
174 #include <stdio.h>
175
176 #include "asn-incl.h"
177 #include "asn1module.h"
178 #include "define.h"
179 #include "mem.h"
180 #include "lib-types.h"
181 #include "rules.h"
182 #include "types.h"
183 #include "cond.h"
184 #include "str-util.h"
185 #include "snacc-util.h"
186 #include "print.h"
187 #include "tag-util.h" /* get GetTags/FreeTags/CountTags/TagByteLen */
188 #if META
189 #include "meta.h"
190 #endif
191 #include "gen-vals.h"
192 #include "gen-any.h"
193 #include "gen-code.h"
194
195 #ifdef VDADER_RULES
196 long VDA_ProcessSetOf(FILE *src,TypeDef *td,Type *lst,CxxRules *r);
197 #endif
198
199
200 static const char bufTypeNameG[] = "BUF_TYPE";
201 static const char lenTypeNameG[] = "AsnLen";
202 static const char tagTypeNameG[] = "AsnTag";
203 static const char envTypeNameG[] = "ENV_TYPE";
204 static long int longJmpValG = -100;
205 static const char baseClassesG[] = ": public AsnType";
206
207 static int printTypesG;
208 static int printEncodersG;
209 static int printDecodersG;
210 static int printPrintersG;
211 static int printFreeG;
212 #if META
213 static MetaNameStyle printMetaG;
214 static MetaPDU *meta_pdus_G;
215 #if TCL
216 static int printTclG;
217 #endif
218 #endif /* META */
219
220
221 static void
222 PrintHdrComment PARAMS ((hdr, m),
223 FILE *hdr _AND_
224 Module *m)
225 {
226 time_t now = time (NULL);
227
228 fprintf (hdr, "// NOTE: this is a machine generated file--editing not recommended\n");
229 fprintf (hdr, "//\n");
230 fprintf (hdr, "// %s - class definitions for ASN.1 module %s\n", m->cxxHdrFileName, m->modId->name);
231 fprintf (hdr, "//\n");
232 fprintf (hdr, "// This file was generated by snacc on %s", ctime (&now));
233 fprintf (hdr, "// UBC snacc by Mike Sample\n");
234 fprintf (hdr, "// A couple of enhancements made by IBM European Networking Center\n"); /* 20.8.93 Thomas Meyer */
235 fprintf (hdr, "\n");
236
237 } /* PrintHdrComment */
238
239 static void
240 PrintSrcComment PARAMS ((src, m),
241 FILE *src _AND_
242 Module *m)
243 {
244 time_t now = time (NULL);
245
246 fprintf (src, "// NOTE: this is a machine generated file--editing not recommended\n");
247 fprintf (src, "//\n");
248 fprintf (src, "// %s - class member functions for ASN.1 module %s\n", m->cxxSrcFileName, m->modId->name);
249 fprintf (src, "//\n");
250 fprintf (src, "// This file was generated by snacc on %s", ctime (&now));
251 fprintf (src, "// UBC snacc written by Mike Sample\n");
252 fprintf (src, "// A couple of enhancements made by IBM European Networking Center\n"); /* 20.8.93 Thomas Meyer */
253 fprintf (src, "\n");
254
255 } /* PrintSrcComment */
256
257
258 static void
259 PrintSrcIncludes PARAMS ((src, if_IBM_ENC (srcdb COMMA) mods, m),
260 FILE *src _AND_
261 if_IBM_ENC (FILE *srcdb _AND_)
262 ModuleList *mods _AND_
263 Module *m)
264 {
265 void *tmp;
266 Module *currMod;
267 #ifdef _IBM_ENC_
268 size_t length;
269 char *inclstring;
270 #endif /* _IBM_ENC_ */
271
272 fprintf (src, "#include \"asn-incl.h\"\n");
273
274 tmp = (void *)CURR_LIST_NODE (mods); /* remember curr loc */
275 FOR_EACH_LIST_ELMT (currMod, mods)
276 fprintf (src, "#include \"%s\"\n", currMod->cxxHdrFileName);
277 SET_CURR_LIST_NODE (mods, tmp);
278
279 #ifdef _IBM_ENC_
280 #include "./ibm_editor/print_src_includes.h"
281 #endif /* _IBM_ENC_ */
282 } /* PrintSrcIncludes */
283
284
285 static void
286 PrintTypeDecl PARAMS ((f, td),
287 FILE *f _AND_
288 TypeDef *td)
289 {
290 switch (td->type->basicType->choiceId)
291 {
292 case BASICTYPE_COMPONENTSOF:
293 case BASICTYPE_SELECTION:
294 case BASICTYPE_UNKNOWN:
295 case BASICTYPE_MACRODEF:
296 case BASICTYPE_MACROTYPE:
297 return; /* do nothing */
298
299 default:
300 if (IsNewType (td->type))
301 fprintf (f, "class %s;\n", td->cxxTypeDefInfo->className);
302 }
303
304 } /* PrintTypeDecl */
305
306
307 static void
308 PrintCxxType PARAMS ((hdr, mods, m, r, td, parent, t),
309 FILE *hdr _AND_
310 ModuleList *mods _AND_
311 Module *m _AND_
312 CxxRules *r _AND_
313 TypeDef *td _AND_
314 Type *parent _AND_
315 Type *t)
316 {
317 fprintf (hdr, "%s ", t->cxxTypeRefInfo->className);
318
319 if (t->cxxTypeRefInfo->isPtr)
320 fprintf (hdr, "*");
321
322 } /* PrintCxxType */
323
324
325 #ifdef _IBM_ENC_
326 static void
327 PrintCxxTypedb PARAMS ((srcdb, mods, m, r, td, parent, t),
328 FILE *srcdb _AND_
329 ModuleList *mods _AND_
330 Module *m _AND_
331 CxxRules *r _AND_
332 TypeDef *td _AND_
333 Type *parent _AND_
334 Type *t)
335 {
336 #include "./ibm_editor/print_cxx_type_db.h"
337 } /* PrintCxxTypedb */
338 #endif
339
340
341 /*
342 * Uses the Constructor that takes no args.
343 * Assumes file f is positioned inside a class definition.
344 * All Classes get this to support the ANY type.
345 */
346 static void
347 PrintCloneMethod PARAMS ((hdr, src, td),
348 FILE *hdr _AND_
349 FILE *src _AND_
350 TypeDef *td)
351 {
352 fprintf (hdr, " virtual AsnType *Clone() const;\n\n", td->cxxTypeDefInfo->className);
353
354 fprintf (src, "AsnType *%s::Clone() const\n", td->cxxTypeDefInfo->className);
355 fprintf (src, "{\n");
356 fprintf (src, " return new %s;\n", td->cxxTypeDefInfo->className);
357 fprintf (src, "}\n\n");
358
359 /* Print the Copy method as well. Use the copy constuctor. */
360 fprintf (hdr, " virtual AsnType *Copy() const;\n\n", td->cxxTypeDefInfo->className);
361
362 fprintf (src, "AsnType *%s::Copy() const\n", td->cxxTypeDefInfo->className);
363 fprintf (src, "{\n");
364 fprintf (src, " return new %s (*this);\n", td->cxxTypeDefInfo->className);
365 fprintf (src, "}\n\n");
366 } /* PrintCloneMethod */
367
368
369 /*
370 * prints inline definition of constructors if this class is
371 * derived from a library class.
372 * assumes FILE *f is positioned in the derived class definition (.h)
373 *
374 * 12/92 MS - added overloaded "=" ops for string types.
375 */
376 static void
377 PrintDerivedConstructors PARAMS ((f, r, td),
378 FILE *f _AND_
379 CxxRules *r _AND_
380 TypeDef *td)
381 {
382 enum BasicTypeChoiceId typeId;
383 char *derivedClassName;
384 char *baseClassName;
385
386 typeId = GetBuiltinType (td->type);
387 derivedClassName = td->cxxTypeDefInfo->className;
388 baseClassName = td->type->cxxTypeRefInfo->className;
389
390 /* every class gets the no-arg constructor */
391 #if TCL
392 if (printTclG && typeId == BASICTYPE_ENUMERATED)
393 {
394 fprintf (f, "#if TCL\n");
395 fprintf (f, " %s(): %s (_nmdescs[0].value) {}\n", derivedClassName, baseClassName);
396 fprintf (f, "#else\n");
397 }
398 #endif /* TCL */
399 fprintf (f, " %s(): %s() {}\n", derivedClassName, baseClassName);
400 #if TCL
401 if (printTclG && typeId == BASICTYPE_ENUMERATED)
402 fprintf (f, "#endif\n");
403 #endif /* TCL */
404
405 switch (typeId)
406 {
407 case BASICTYPE_BOOLEAN:
408 fprintf (f, " %s (bool b): %s (b) {}\n", derivedClassName, baseClassName);
409 break;
410
411 case BASICTYPE_ENUMERATED:
412 case BASICTYPE_INTEGER:
413 fprintf (f, " %s (int i): %s (i) {}\n", derivedClassName, baseClassName);
414 break;
415
416 case BASICTYPE_REAL:
417 fprintf (f, " %s (double d): %s (d) {}\n", derivedClassName, baseClassName);
418 break;
419
420 case BASICTYPE_OCTETSTRING:
421 fprintf (f, " %s (const char *str): %s (str) {}\n", derivedClassName, baseClassName);
422
423 fprintf (f, " %s (const char *str, const size_t len): %s (str, len) {}\n", derivedClassName, baseClassName);
424
425 fprintf (f, " %s (const %s &o): %s (o) {}\n", derivedClassName, baseClassName, baseClassName);
426
427 /* include overloading of = op. MS 12/92 */
428 fprintf (f, " %s &operator = (const %s &o) { ReSet (o); return *this; }\n", derivedClassName, derivedClassName);
429 fprintf (f, " %s &operator = (const char *str) { ReSet (str); return *this; }\n", derivedClassName);
430 break;
431
432 case BASICTYPE_BITSTRING:
433 fprintf (f, " %s (const size_t bits): %s (bits) {}\n", derivedClassName, baseClassName);
434
435 fprintf (f, " %s (const char *str, const size_t bitLen): %s (str, bitLen) {}\n", derivedClassName, baseClassName);
436
437 fprintf (f, " %s (const %s &b): %s (b) {}\n", derivedClassName, baseClassName, baseClassName);
438 break;
439
440 /* include overloading of = op. MS 12/92 */
441 fprintf (f, " %s &operator = (const %s &b) { ReSet (b); return *this; }\n", derivedClassName, derivedClassName);
442
443 case BASICTYPE_OID:
444 fprintf (f, " %s (const char *encOid, size_t len): %s (encOid, len) {}\n", derivedClassName, baseClassName);
445
446 fprintf (f, " %s (const %s &o): %s (o) {}\n", derivedClassName, baseClassName, baseClassName);
447
448 fprintf (f, " %s (unsigned long int a1, unsigned long int a2, long int a3=-1, long int a4=-1, long int a5=-1, long int a6=-1, long int a7=-1, long int a8=-1, long int a9=-1, long int a10=-1, long int a11=-1): %s (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) {}\n", baseClassName, derivedClassName, baseClassName);
449
450 /* include overloading of = op. MS 12/92 */
451 fprintf (f, " %s &operator = (const %s &o) { ReSet (o); return *this; }\n", derivedClassName, derivedClassName);
452
453 break;
454
455
456 default:
457 /* do nothing */
458 break;
459 }
460
461 } /* PrintDerivedConstructors */
462
463
464 static void
465 PrintMakeTag PARAMS ((f, tag),
466 FILE *f _AND_
467 Tag *tag)
468 {
469 char *classStr;
470 char *formStr;
471
472 classStr = Class2ClassStr (tag->tclass);
473
474 if (tag->form == ANY_FORM) /* default to PRIM for dual form tags */
475 formStr = Form2FormStr (PRIM);
476 else
477 formStr = Form2FormStr (tag->form);
478
479 fprintf (f, "MAKE_TAG_ID (%s, %s, ", classStr, formStr);
480 if (tag->tclass == UNIV)
481 fprintf (f, "%s)", Code2UnivCodeStr (tag->code));
482 else
483 fprintf (f, "%d)", tag->code);
484
485 } /* PrintMakeTag */
486
487 static void
488 PrintPduMemberFcns PARAMS ((src, hdr, r, cln),
489 FILE *src _AND_
490 FILE *hdr _AND_
491 CxxRules *r _AND_
492 char *cln)
493 {
494 #if SNACC_ENABLE_PDU
495 if (printEncodersG)
496 {
497 fprintf (hdr, " int B%s (%s b, %s &bytesEncoded);\n", r->encodePduBaseName, bufTypeNameG, lenTypeNameG);
498
499 fprintf (src, "int %s::B%s (%s b, %s &bytesEncoded)\n", cln, r->encodePduBaseName, bufTypeNameG, lenTypeNameG);
500 fprintf (src, "{\n");
501 fprintf (src, " bytesEncoded = B%s (b);\n", r->encodeBaseName);
502 fprintf (src, " return !b.WriteError();\n");
503 fprintf (src, "}\n\n");
504 }
505
506 if (printDecodersG)
507 {
508 fprintf (hdr, " int B%s (%s b, %s &bytesDecoded);\n", r->decodePduBaseName, bufTypeNameG, lenTypeNameG);
509
510 fprintf (src, "int %s::B%s (%s b, %s &bytesDecoded)\n", cln, r->decodePduBaseName, bufTypeNameG, lenTypeNameG);
511 fprintf (src, "{\n");
512 #if !SNACC_EXCEPTION_ENABLE
513 fprintf (src, " %s env;\n", envTypeNameG);
514 fprintf (src, " int val;\n\n");
515 #endif
516 fprintf (src, " bytesDecoded = 0;\n");
517 #if SNACC_EXCEPTION_ENABLE
518 fprintf (src, " try\n");
519 fprintf (src, " {\n");
520 fprintf (src, " BDec (b, bytesDecoded, 0);\n");
521 fprintf (src, " return !b.ReadError();\n");
522 fprintf (src, " }\n");
523 fprintf (src, " catch(...)\n");
524 fprintf (src, " {\n");
525 fprintf (src, " return false;\n");
526 fprintf (src, " }\n");
527 #else /* SNACC_EXCEPTION_ENABLE */
528 fprintf (src, " if ((val = setjmp (env)) == 0)\n");
529 fprintf (src, " {\n");
530 fprintf (src, " BDec (b, bytesDecoded, env);\n");
531 fprintf (src, " return !b.ReadError();\n");
532 fprintf (src, " }\n");
533 fprintf (src, " else\n");
534 fprintf (src, " return false;\n");
535 /*
536 fprintf (src, " { cerr << \"longjmp return value is \" << val << endl;\n");
537 fprintf (src, " return false; }\n");
538 */
539 #endif /* SNACC_EXCEPTION_ENABLE */
540 fprintf (src, "}\n\n");
541 }
542
543 fprintf (hdr, "\n");
544 #endif /* SNACC_ENABLE_PDU */
545 } /* PrintPduMemberFcns */
546
547
548 static void
549 PrintCxxEocEncoders PARAMS ((src, td, t, bufVarName),
550 FILE *src _AND_
551 TypeDef *td _AND_
552 Type *t _AND_
553 char *bufVarName)
554 {
555 TagList *tl;
556 Tag *tag;
557 int stoleChoiceTags;
558
559 /*
560 * get all the tags on this type
561 */
562 tl = (TagList*) GetTags (t, &stoleChoiceTags);
563
564 /*
565 * leave choice elmt tag enc to encoding routine
566 */
567 if (!stoleChoiceTags)
568 {
569 FOR_EACH_LIST_ELMT (tag, tl)
570 if (tag->form == CONS)
571 fprintf (src, " BEncEocIfNec (b);\n");
572 }
573
574 FreeTags (tl);
575
576 } /* PrintCxxEocEncoders */
577
578
579 static int
580 HasShortLen PARAMS ((t),
581 Type *t)
582 {
583 enum BasicTypeChoiceId typesType;
584 /*
585 * efficiency hack - use simple length (1 byte)
586 * encoded for type (almost) guaranteed to have
587 * encoded lengths of 0 <= len <= 127
588 */
589 typesType = GetBuiltinType (t);
590 return typesType == BASICTYPE_BOOLEAN || typesType == BASICTYPE_INTEGER || typesType == BASICTYPE_NULL || typesType == BASICTYPE_REAL || typesType == BASICTYPE_ENUMERATED;
591 } /* HasShortLen */
592
593
594 /*
595 * prints length encoding code. Primitives always use
596 * definite length and constructors get "ConsLen"
597 * which can be configured at compile to to be indefinite
598 * or definite. Primitives can also be "short" (isShort is true)
599 * in which case a fast macro is used to write the length.
600 * Types for which isShort apply are: boolean, null and
601 * (almost always) integer and reals
602 */
603 static void
604 PrintCxxLenEncodingCode PARAMS ((f, isCons, isShort, lenVarName, bufVarName),
605 FILE *f _AND_
606 int isCons _AND_
607 int isShort _AND_
608 char *lenVarName _AND_
609 char *bufVarName)
610 {
611 if (isCons)
612 fprintf (f, " %s += BEncConsLen (%s, %s);\n", lenVarName, bufVarName, lenVarName);
613 else
614 {
615 if (isShort)
616 {
617 fprintf (f, " BEncDefLenTo127 (%s, %s);\n", bufVarName, lenVarName);
618 fprintf (f, " %s++;\n", lenVarName);
619 }
620 else
621 fprintf (f, " %s += BEncDefLen (%s, %s);\n", lenVarName, bufVarName, lenVarName);
622 }
623 } /* PrintCxxLenEncodingCode */
624
625
626 /*
627 * prints last tag's encoding code first
628 */
629 static void
630 PrintCxxTagAndLenList PARAMS ((src, t, tagList, lenVarName, bufVarName),
631 FILE *src _AND_
632 Type *t _AND_
633 TagList *tagList _AND_
634 char *lenVarName _AND_
635 char *bufVarName)
636 {
637 char *classStr;
638 char *formStr;
639 char *codeStr;
640 Tag *tg;
641 Tag *last;
642 int tagLen;
643 enum BasicTypeChoiceId typesType;
644 int isShort;
645
646 if ((tagList == NULL) || LIST_EMPTY (tagList))
647 return;
648
649 /*
650 * efficiency hack - use simple length (1 byte)
651 * encoded for type (almost) guaranteed to have
652 * encoded lengths of 0 <= len <= 127
653 */
654 isShort = HasShortLen (t);
655
656 /*
657 * since encoding backward encode tags backwards
658 */
659 last = (Tag*)LAST_LIST_ELMT (tagList);
660 FOR_EACH_LIST_ELMT_RVS (tg, tagList)
661 {
662 classStr = Class2ClassStr (tg->tclass);
663
664 if (tg->form == CONS)
665 {
666 formStr = Form2FormStr (CONS);
667 PrintCxxLenEncodingCode (src, TRUE, isShort, lenVarName, bufVarName);
668 }
669 else /* PRIM or ANY_FORM */
670 {
671 formStr = Form2FormStr (PRIM);
672 PrintCxxLenEncodingCode (src, FALSE, isShort, lenVarName, bufVarName);
673 }
674
675 /* GetTags sets the form properly now
676 if (IsPrimitiveByDefOrRef (t) && (tg == last))
677 {
678 formStr = Form2FormStr (PRIM);
679 PrintCxxLenEncodingCode (src, FALSE, isShort, lenVarName, bufVarName);
680 }
681 else
682 {
683 formStr = Form2FormStr (CONS);
684 PrintCxxLenEncodingCode (src, TRUE, isShort, lenVarName, bufVarName);
685 }
686 */
687
688 fprintf (src, "\n");
689
690 tagLen = TagByteLen (tg->code);
691
692 if (tg->tclass == UNIV)
693 fprintf (src, " %s += BEncTag%d (%s, %s, %s, %s);\n", lenVarName, tagLen, bufVarName, classStr, formStr, Code2UnivCodeStr (tg->code));
694 else
695 fprintf (src, " %s += BEncTag%d (%s, %s, %s, %d);\n", lenVarName, tagLen, bufVarName, classStr, formStr, tg->code);
696 }
697
698 } /* PrintCxxTagAndLenList */
699
700
701 /*
702 * Recursively walks through tags, printing lower lvl tags
703 * first (since encoding is done backwards).
704 *
705 */
706 static void
707 PrintCxxTagAndLenEncodingCode PARAMS ((src, td, t, lenVarName, bufVarName),
708 FILE *src _AND_
709 TypeDef *td _AND_
710 Type *t _AND_
711 char *lenVarName _AND_
712 char *bufVarName)
713 {
714 TagList *tl;
715 int stoleChoiceTags;
716
717 /*
718 * get all the tags on this type
719 */
720 tl = (TagList*) GetTags (t, &stoleChoiceTags);
721
722 /*
723 * leave choice elmt tag enc to encoding routine
724 */
725 if (!stoleChoiceTags)
726 PrintCxxTagAndLenList (src, t, tl, lenVarName, bufVarName);
727
728 FreeTags (tl);
729
730 } /* PrintCxxTagAndLenEncodingCode */
731
732
733 /*
734 * used to figure out local variables to declare
735 * for decoding tags/len pairs on type t
736 */
737 static int
738 CxxCountVariableLevels PARAMS ((t),
739 Type *t)
740 {
741 if (GetBuiltinType (t) == BASICTYPE_CHOICE)
742 return CountTags (t) +1; /* since must decode 1 internal tag type */
743 else
744 return CountTags (t);
745 } /* CxxCountVariableLevels */
746
747
748 /*
749 * returns true if elmts curr following
750 * onward are all optional ow. false
751 */
752 static int
753 RestAreTailOptional PARAMS ((e),
754 NamedTypeList *e)
755 {
756 NamedType *elmt;
757 void *tmp;
758 int retVal;
759
760 if (e == NULL)
761 return TRUE;
762
763 tmp = (void*)CURR_LIST_NODE (e);
764 retVal = TRUE;
765 AsnListNext (e);
766 FOR_REST_LIST_ELMT (elmt, e)
767 {
768 if ((!elmt->type->optional) && (elmt->type->defaultVal == NULL))
769 {
770 retVal = FALSE;
771 break;
772 }
773 }
774 SET_CURR_LIST_NODE (e, tmp); /* reset list to orig loc */
775 return retVal;
776 }
777
778
779 /*
780 * prints typedef or new class given an ASN.1 type def of a primitive type
781 * or typeref. Uses inheritance to cover re-tagging and named elmts.
782 */
783 static void
784 PrintCxxSimpleDef PARAMS ((hdr, src, if_IBM_ENC (hdrdb COMMA srcdb COMMA) if_META (m COMMA) r, td),
785 FILE *hdr _AND_
786 FILE *src _AND_
787 if_IBM_ENC (FILE *hdrdb _AND_)
788 if_IBM_ENC (FILE *srcdb _AND_)
789 if_META (Module *m _AND_)
790 CxxRules *r _AND_
791 TypeDef *td)
792 {
793 Tag *tag;
794 TagList *tags;
795 char *formStr;
796 char *classStr;
797 int tagLen;
798 int i;
799 CNamedElmt *n;
800 int stoleChoiceTags;
801 int elmtLevel;
802 enum BasicTypeChoiceId typeId;
803
804 fprintf (hdr, "/* ");
805 SpecialPrintType (hdr, td, td->type);
806 fprintf (hdr, " */\n");
807
808 /* check if has been re-tagged
809 * eg Foo ::= [APPLICATION 2] IMPLICIT REAL
810 * or if it has named elmts in which case a new class must
811 * be defined
812 * eg Foo ::= INTEGER { one (1), two (2), three (3) }
813 */
814
815 if (IsNewType (td->type))
816 {
817 int hasNamedElmts;
818
819 #ifdef _IBM_ENC_
820 #include "./ibm_editor/print_cxx_simple_def.h"
821 #endif /* _IBM_ENC_ */
822
823 fprintf (hdr, "class %s: public %s\n", td->cxxTypeDefInfo->className, td->type->cxxTypeRefInfo->className);
824 fprintf (hdr, "{\n");
825 fprintf (hdr, "public:\n");
826
827 /*
828 * must explicitly call constructors for base class
829 */
830 PrintDerivedConstructors (hdr, r, td);
831
832 /* do named elmts enum if any */
833 /* for types with named elements, inherit from the base
834 * class and define and enum eg:
835 * Foo ::= INTEGER { one (1), two (2), five (5) }
836 * ->
837 * class Foo: public AsnInt
838 * {
839 * public:
840 * Foo(): AsnInt() {}
841 * Foo (int val): AsnInt (int val) {}
842 * enum { one = 1, two = 2, five = 5 };
843 * };
844 * or
845 * Foo2 ::= [APPLICATION 2] INTEGER
846 * -->
847 * class Foo: public AsnInt
848 * {
849 * public:
850 * Foo(): AsnInt() {}
851 * Foo (int val): AsnInt (int val) {}
852 * AsnLen BEnc { ....... } <-- holds new tag enc/dec
853 * void BDec { ....... } <--/
854 * int BEncPdu { ....... }
855 * int BDecPdu { ....... }
856 * };
857 * (must 'inherit' constructors explicitly)
858 */
859
860 if (hasNamedElmts = HasNamedElmts (td->type))
861 {
862 fprintf (hdr, " enum\n");
863 fprintf (hdr, " {\n");
864 FOR_EACH_LIST_ELMT (n, td->type->cxxTypeRefInfo->namedElmts)
865 {
866 fprintf (hdr, " %s = %d", n->name, n->value);
867 if (n != (CNamedElmt *)LAST_LIST_ELMT (td->type->cxxTypeRefInfo->namedElmts))
868 fprintf (hdr, ",\n");
869 else
870 fprintf (hdr, "\n");
871 }
872 fprintf (hdr, " };\n");
873 }
874 #if META
875 if (printMetaG)
876 {
877 const char *T, *t;
878 int a3;
879
880 fprintf (hdr, "\n");
881 fprintf (hdr, "#if META\n");
882 fprintf (src, "#if META\n\n");
883
884 fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);
885 fprintf (src, "{\n");
886 fprintf (src, " return new %s;\n", td->cxxTypeDefInfo->className);
887 fprintf (src, "}\n\n");
888
889 if (hasNamedElmts = HasNamedElmts (td->type))
890 {
891 fprintf (hdr, " static const AsnNameDesc _nmdescs[];\n");
892
893 fprintf (src, "const AsnNameDesc %s::_nmdescs[] =\n", td->cxxTypeDefInfo->className);
894 fprintf (src, "{\n");
895 FOR_EACH_LIST_ELMT (n, td->type->cxxTypeRefInfo->namedElmts)
896 #if 0 /* (no asn1 names available!) */
897 if (printMetaG == META_backend_names)
898 else /* META_asn1_names */
899 #endif
900 fprintf (src, " \"%s\", %s, // %d\n", n->name, n->name, n->value);
901 fprintf (src, " NULL, -1\n");
902 fprintf (src, "};\n\n");
903 }
904
905 switch (GetBuiltinType (td->type))
906 {
907 case BASICTYPE_BOOLEAN:
908 T = "BOOLEAN";
909 t = "Bool";
910 a3 = FALSE;
911 break;
912 case BASICTYPE_ENUMERATED:
913 T = "ENUMERATED";
914 t = "Enum";
915 a3 = TRUE;
916 break;
917 case BASICTYPE_INTEGER:
918 T = "INTEGER";
919 t = "Int";
920 a3 = TRUE;
921 break;
922 case BASICTYPE_REAL:
923 T = "REAL";
924 t = "Real";
925 a3 = FALSE;
926 break;
927 case BASICTYPE_OCTETSTRING:
928 T = "OCTET_STRING";
929 t = "Octs";
930 a3 = FALSE;
931 break;
932 case BASICTYPE_BITSTRING:
933 T = "BIT_STRING";
934 t = "Bits";
935 a3 = TRUE;
936 break;
937 case BASICTYPE_OID:
938 T = "OID";
939 t = "Oid";
940 a3 = FALSE;
941 default:
942 T =
943 t = "?";
944 a3 = FALSE;
945 }
946
947 fprintf (hdr, " static const Asn%sTypeDesc _desc;\n", t);
948 fprintf (hdr, " const AsnTypeDesc *_getdesc() const;\n");
949
950 fprintf (src, "const Asn%sTypeDesc %s::_desc\n", t, td->cxxTypeDefInfo->className);
951 fprintf (src, "(\n");
952 fprintf (src, " &%sModuleDesc,\n", m->cxxname);
953 if (printMetaG == META_backend_names)
954 fprintf (src, " \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);
955 else /* META_asn1_names */
956 fprintf (src, " \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);
957 fprintf (src, " %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");
958 fprintf (src, " AsnTypeDesc::%s,\n", T);
959 fprintf (src, " create%s", td->cxxTypeDefInfo->className);
960 if (a3)
961 fprintf (src, ",\n %s", hasNamedElmts ? "_nmdescs" : "NULL");
962 fprintf (src, "\n);\n\n");
963
964 fprintf (src, "const AsnTypeDesc *%s::_getdesc() const\n", td->cxxTypeDefInfo->className);
965 fprintf (src, "{\n");
966 fprintf (src, " return &_desc;\n");
967 fprintf (src, "}\n\n");
968
969 fprintf (hdr, "#endif // META\n");
970 fprintf (src, "#endif // META\n\n");
971
972 #if TCL
973 #endif
974 }
975 #endif /* META */
976
977 /*
978 * Re-do BerEncode, BerDeocode, BerDecodePdu and BerDecodePdu
979 * if this type has been re-tagged
980 */
981 if ((IsDefinedByLibraryType (td->type) && !HasDefaultTag (td->type))
982 || (IsTypeRef (td->type) && ((td->type->tags != NULL) && !LIST_EMPTY (td->type->tags))))
983 {
984 /* only BerEn/Decode BerEn/DecodePdu need to be re-done if tags are different */
985
986 /* print clone routine for ANY mgmt */
987 PrintCloneMethod (hdr, src, td);
988
989 tags = GetTags (td->type, &stoleChoiceTags);
990 typeId = GetBuiltinType (td->type);
991
992 /* do BerEncode function */
993 if (printEncodersG)
994 {
995 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeBaseName, bufTypeNameG);
996 fprintf (src, "%s %s::B%s (%s b)\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeBaseName, bufTypeNameG);
997 fprintf (src, "{\n");
998 fprintf (src, " %s l;\n", lenTypeNameG);
999
1000 PrintCxxEocEncoders (src, td, td->type, "b");
1001
1002 fprintf (src, " l = BEncContent (b);\n");
1003
1004 /* encode each tag/len pair if any */
1005 if (!stoleChoiceTags)
1006 {
1007 FOR_EACH_LIST_ELMT_RVS (tag, tags)
1008 {
1009 classStr = Class2ClassStr (tag->tclass);
1010
1011 if (tag->form == ANY_FORM)
1012 {
1013 formStr = Form2FormStr (PRIM);
1014 PrintCxxLenEncodingCode (src, FALSE, HasShortLen (td->type), "l", "b");
1015 }
1016 else
1017 {
1018 formStr = Form2FormStr (tag->form);
1019 PrintCxxLenEncodingCode (src, TRUE, HasShortLen (td->type), "l", "b");
1020 }
1021
1022 fprintf (src, "\n");
1023 tagLen = TagByteLen (tag->code);
1024
1025 if (tag->tclass == UNIV)
1026 fprintf (src, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen, classStr, formStr, Code2UnivCodeStr (tag->code));
1027 else
1028 fprintf (src, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen, classStr, formStr, tag->code);
1029 }
1030 }
1031 fprintf (src, " return l;\n");
1032 fprintf (src, "}\n\n");
1033 }
1034 /* end of BEnc function */
1035
1036 /* Do BDec function */
1037 if (printDecodersG)
1038 {
1039 fprintf (hdr, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
1040 fprintf (src, "void %s::B%s (%s b, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
1041 fprintf (src, "{\n");
1042 fprintf (src, " %s tag;\n", tagTypeNameG);
1043
1044 /* print extra locals for redundant lengths */
1045 for (i = 1; (tags != NULL) && (i <= LIST_COUNT (tags)); i++)
1046 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
1047 if (typeId == BASICTYPE_CHOICE)
1048 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i++);
1049 fprintf (src, "\n");
1050
1051 /* decode tag/length pair (s) */
1052 elmtLevel = 0;
1053 if (!stoleChoiceTags)
1054 {
1055 FOR_EACH_LIST_ELMT (tag, tags)
1056 {
1057 classStr = Class2ClassStr (tag->tclass);
1058
1059 if (tag->form == ANY_FORM)
1060 formStr = Form2FormStr (PRIM);
1061 else
1062 formStr = Form2FormStr (tag->form);
1063
1064 fprintf (src, " if (((tag = BDecTag (b, bytesDecoded, env)) != ");
1065
1066 if (tag->tclass == UNIV)
1067 {
1068 fprintf (src, "MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, Code2UnivCodeStr (tag->code));
1069 if (tag->form == ANY_FORM)
1070 fprintf (src, "\n && (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), Code2UnivCodeStr (tag->code));
1071 else
1072 fprintf (src, ")\n");
1073 }
1074 else
1075 {
1076 fprintf (src, "MAKE_TAG_ID (%s, %s, %d))", classStr, formStr, tag->code);
1077 if (tag->form == ANY_FORM)
1078 fprintf (src, "\n && (tag != MAKE_TAG_ID (%s, %s, %d)))\n", classStr, Form2FormStr (CONS), tag->code);
1079 else
1080 fprintf (src, ")\n");
1081 }
1082 fprintf (src, " {\n");
1083 fprintf (src, " Asn1Error << \"%s::B%s: ERROR - wrong tag\" << endl;\n", td->cxxTypeDefInfo->className, r->decodeBaseName);
1084 #if SNACC_EXCEPTION_ENABLE
1085 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
1086 #else
1087 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
1088 #endif /* SNACC_EXCEPTION_ENABLE */
1089 fprintf (src, " }\n");
1090
1091 fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
1092 }
1093 }
1094
1095 /* decode first tag from CHOICE's content */
1096 if (typeId == BASICTYPE_CHOICE)
1097 {
1098 fprintf (src, " tag = BDecTag (b, bytesDecoded, env);\n");
1099 fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
1100 }
1101
1102 fprintf (src, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r->decodeContentBaseName, i-1);
1103
1104 /* grab any EOCs that match redundant, indef lengths */
1105 for (i = elmtLevel-1; i > 0; i--)
1106 {
1107 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
1108 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
1109 }
1110
1111 fprintf (src, "}\n\n");
1112 }
1113 /* end of BDec function */
1114
1115 PrintPduMemberFcns (src, hdr, r, td->cxxTypeDefInfo->className);
1116
1117 FreeTags (tags);
1118 }
1119 /* close class def */
1120 fprintf (hdr, "};\n\n\n");
1121
1122 }
1123 else /* isomorphic with referenced type, so just to a typedef */
1124 {
1125 #ifdef _IBM_ENC_
1126 #include "./ibm_editor/print_cxx_simple_def1.h"
1127 #endif /* _IBM_ENC_ */
1128
1129 #if META
1130 if (printMetaG)
1131 {
1132 fprintf (hdr, "#if META\n");
1133 fprintf (src, "#if META\n\n");
1134
1135 fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);
1136 fprintf (src, "{\n");
1137 fprintf (src, " return new %s;\n", td->cxxTypeDefInfo->className);
1138 fprintf (src, "}\n\n");
1139
1140 fprintf (hdr, "struct %s: public %s\n", td->cxxTypeDefInfo->className, td->type->cxxTypeRefInfo->className);
1141 fprintf (hdr, "{\n");
1142
1143 PrintDerivedConstructors (hdr, r, td);
1144
1145 PrintCloneMethod (hdr, src, td);
1146
1147 fprintf (hdr, " static const AsnAliasTypeDesc _desc;\n");
1148 fprintf (hdr, " const AsnTypeDesc *_getdesc() const;\n");
1149
1150 fprintf (src, "const AsnAliasTypeDesc %s::_desc\n", td->cxxTypeDefInfo->className);
1151 fprintf (src, "(\n");
1152 fprintf (src, " &%sModuleDesc,\n", m->cxxname);
1153 if (printMetaG == META_backend_names)
1154 fprintf (src, " \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);
1155 else /* META_asn1_names */
1156 fprintf (src, " \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);
1157 fprintf (src, " %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");
1158 fprintf (src, " AsnTypeDesc::ALIAS,\n");
1159 fprintf (src, " create%s,\n", td->cxxTypeDefInfo->className);
1160 fprintf (src, " &%s::_desc\n);\n\n", td->type->cxxTypeRefInfo->className);
1161
1162 fprintf (src, "const AsnTypeDesc *%s::_getdesc() const\n", td->cxxTypeDefInfo->className);
1163 fprintf (src, "{\n");
1164 fprintf (src, " return &_desc;\n");
1165 fprintf (src, "}\n\n");
1166
1167 fprintf (hdr, "};\n\n");
1168
1169 fprintf (hdr, "#else // META\n\n");
1170 fprintf (src, "#endif // META\n\n");
1171 }
1172 #endif /* META */
1173
1174 fprintf (hdr, "typedef %s %s;\n\n", td->type->cxxTypeRefInfo->className, td->cxxTypeDefInfo->className);
1175
1176 #if META
1177 if (printMetaG)
1178 fprintf (hdr, "#endif // META\n\n");
1179 #endif /* META */
1180 }
1181 } /* PrintCxxSimpleDef */
1182
1183 static void
1184 PrintCxxChoiceDefCode PARAMS ((src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, parent, choice, novolatilefuncs),
1185 FILE *src _AND_
1186 FILE *hdr _AND_
1187 if_IBM_ENC (FILE *srcdb _AND_)
1188 if_IBM_ENC (FILE *hdrdb _AND_)
1189 ModuleList *mods _AND_
1190 Module *m _AND_
1191 CxxRules *r _AND_
1192 TypeDef *td _AND_
1193 Type *parent _AND_
1194 Type *choice _AND_
1195 int novolatilefuncs)
1196 {
1197 NamedType *e;
1198 char *classStr;
1199 char *formStr;
1200 char *codeStr;
1201 int tagLen, i;
1202 Tag *tag;
1203 TagList *tags;
1204 char *varName;
1205 CxxTRI *cxxtri;
1206 int elmtLevel;
1207 int varCount, tmpVarCount;
1208 int stoleChoiceTags;
1209 enum BasicTypeChoiceId tmpTypeId;
1210 NamedType *defByNamedType;
1211
1212 #ifdef _IBM_ENC_
1213 #include "./ibm_editor/print_cxx_choice_def_code.h"
1214 #endif /* _IBM_ENC_ */
1215
1216 /* put class spec in hdr file */
1217
1218 fprintf (hdr, "class %s%s\n", td->cxxTypeDefInfo->className, baseClassesG);
1219 fprintf (hdr, "{\n");
1220 fprintf (hdr, "public:\n");
1221
1222 /* write out choiceId enum type */
1223
1224 fprintf (hdr, " enum %s\n", r->choiceIdEnumName);
1225 fprintf (hdr, " {\n");
1226 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1227 {
1228 fprintf (hdr, " %s = %d", e->type->cxxTypeRefInfo->choiceIdSymbol, e->type->cxxTypeRefInfo->choiceIdValue);
1229 if (e != (NamedType*)LAST_LIST_ELMT (choice->basicType->a.choice))
1230 fprintf (hdr, ",\n");
1231 else
1232 fprintf (hdr, "\n");
1233 }
1234 fprintf (hdr, " };\n\n");
1235
1236 /* write out the choice Id field */
1237 /* fprintf (hdr, "protected:\n"); */
1238 fprintf (hdr, " enum %s %s;\n", r->choiceIdEnumName, r->choiceIdFieldName);
1239
1240 /* write out the choice element anonymous union */
1241 fprintf (hdr, " union\n");
1242 fprintf (hdr, " {\n");
1243 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1244 {
1245 fprintf (hdr, " ");
1246 PrintCxxType (hdr, mods, m, r, td, choice, e->type);
1247 fprintf (hdr, "%s;\n", e->type->cxxTypeRefInfo->fieldName);
1248 }
1249 fprintf (hdr, " };\n\n");
1250
1251 #if META
1252 if (printMetaG)
1253 {
1254 fprintf (hdr, "#if META\n");
1255 fprintf (src, "#if META\n\n");
1256
1257 fprintf (hdr, " static const AsnChoiceTypeDesc _desc;\n");
1258 fprintf (hdr, " static const AsnChoiceMemberDesc _mdescs[];\n\n");
1259 fprintf (hdr, " const AsnTypeDesc *_getdesc() const;\n");
1260 fprintf (hdr, " AsnType *_getref (const char *membername, bool create = false);\n\n");
1261
1262 fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);
1263 fprintf (src, "{\n");
1264 fprintf (src, " return new %s;\n", td->cxxTypeDefInfo->className);
1265 fprintf (src, "}\n\n");
1266
1267 fprintf (src, "const AsnChoiceMemberDesc %s::_mdescs[] =\n", td->cxxTypeDefInfo->className);
1268 fprintf (src, "{\n");
1269 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1270 if (printMetaG == META_backend_names)
1271 fprintf (src, " AsnChoiceMemberDesc (\"%s\", &%s::_desc), // `%s'\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className, e->fieldName ? e->fieldName : "");
1272 else /* META_asn1_names */
1273 fprintf (src, " AsnChoiceMemberDesc (\"%s\", &%s::_desc), // `%s'\n", e->fieldName ? e->fieldName : e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className, e->type->cxxTypeRefInfo->fieldName);
1274 fprintf (src, " AsnChoiceMemberDesc()\n");
1275 fprintf (src, "};\n\n");
1276
1277 fprintf (src, "const AsnChoiceTypeDesc %s::_desc\n", td->cxxTypeDefInfo->className);
1278 fprintf (src, "(\n");
1279 fprintf (src, " &%sModuleDesc,\n", m->cxxname);
1280 if (printMetaG == META_backend_names)
1281 fprintf (src, " \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);
1282 else /* META_asn1_names */
1283 fprintf (src, " \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);
1284 fprintf (src, " %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");
1285 fprintf (src, " AsnTypeDesc::CHOICE,\n");
1286 fprintf (src, " create%s,\n", td->cxxTypeDefInfo->className);
1287 fprintf (src, " _mdescs\n");
1288 fprintf (src, ");\n\n");
1289
1290 fprintf (src, "const AsnTypeDesc *%s::_getdesc() const\n", td->cxxTypeDefInfo->className);
1291 fprintf (src, "{\n");
1292 fprintf (src, " return &_desc;\n");
1293 fprintf (src, "}\n\n");
1294
1295 fprintf (src, "AsnType *%s::_getref (const char *membername, bool create)\n", td->cxxTypeDefInfo->className);
1296 fprintf (src, "{\n");
1297 fprintf (src, " ChoiceIdEnum newCid = (ChoiceIdEnum)_desc.choicebyname (membername);\n");
1298 fprintf (src, " if (newCid == -1)\n");
1299 fprintf (src, " return NULL;\n");
1300 fprintf (src, " if (newCid == choiceId)\n");
1301 fprintf (src, " {\n");
1302 fprintf (src, " switch (choiceId)\n");
1303 fprintf (src, " {\n");
1304 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1305 {
1306 fprintf (src, " case %sCid:\n", e->type->cxxTypeRefInfo->fieldName);
1307 fprintf (src, " return %s;\n", e->type->cxxTypeRefInfo->fieldName);
1308 }
1309 fprintf (src, " default:\n");
1310 fprintf (src, " return NULL;\n");
1311 fprintf (src, " }\n");
1312 fprintf (src, " }\n");
1313 fprintf (src, " else\n");
1314 fprintf (src, " {\n");
1315 fprintf (src, " if (create)\n");
1316 fprintf (src, " {\n");
1317 fprintf (src, "// switch (choiceId)\n");
1318 fprintf (src, "// {\n");
1319 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1320 {
1321 fprintf (src, "// case %sCid:\n", e->type->cxxTypeRefInfo->fieldName);
1322 fprintf (src, "// delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
1323 fprintf (src, "// %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
1324 fprintf (src, "// break;\n");
1325 }
1326 fprintf (src, "// default:\n");
1327 fprintf (src, "// return NULL;\n");
1328 fprintf (src, "// }\n");
1329 e = FIRST_LIST_ELMT (choice->basicType->a.choice);
1330 fprintf (src, " // simply delete any member, the virtual function table takes care of the rest:\n");
1331 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
1332 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
1333 fprintf (src, " switch (choiceId = newCid)\n");
1334 fprintf (src, " {\n");
1335 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1336 {
1337 fprintf (src, " case %sCid:\n", e->type->cxxTypeRefInfo->fieldName);
1338 fprintf (src, " return %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
1339 }
1340 fprintf (src, " default: // internal error!\n");
1341 fprintf (src, " return NULL;\n");
1342 fprintf (src, " }\n");
1343 fprintf (src, " }\n");
1344 fprintf (src, " else\n");
1345 fprintf (src, " return NULL;\n");
1346 fprintf (src, " }\n");
1347 fprintf (src, "}\n\n");
1348
1349 #if TCL
1350 if (printTclG)
1351 {
1352 fprintf (hdr, "#if TCL\n");
1353 fprintf (src, "#if TCL\n\n");
1354
1355 fprintf (hdr, " int TclGetDesc (Tcl_DString *) const;\n");
1356 fprintf (hdr, " int TclGetVal (Tcl_Interp *) const;\n");
1357 fprintf (hdr, " int TclSetVal (Tcl_Interp *, const char *valstr);\n\n");
1358
1359 fprintf (src, "int %s::TclGetDesc (Tcl_DString *valstr) const\n", td->cxxTypeDefInfo->className);
1360 fprintf (src, "{\n");
1361 fprintf (src, " Tcl_DStringAppendElement (valstr, (char*)_desc.choicebyvalue (choiceId));\n");
1362 fprintf (src, " // hack: since all members are pointers, we don't have to check for its type via choiceId, because all we want to know is whether it's NULL or not:\n");
1363 e = FIRST_LIST_ELMT (choice->basicType->a.choice);
1364 fprintf (src, " Tcl_DStringAppendElement (valstr, %s ? \"valid\" : \"void\");\n", e->type->cxxTypeRefInfo->fieldName);
1365 fprintf (src, " return TCL_OK;\n");
1366 fprintf (src, "}\n\n");
1367
1368 fprintf (src, "int %s::TclGetVal (Tcl_Interp *interp) const\n", td->cxxTypeDefInfo->className);
1369 fprintf (src, "{\n");
1370 fprintf (src, " switch (choiceId)\n");
1371 fprintf (src, " {\n");
1372 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1373 {
1374 fprintf (src, " case %sCid:\n", e->type->cxxTypeRefInfo->fieldName);
1375 fprintf (src, " if (%s)\n", e->type->cxxTypeRefInfo->fieldName);
1376 fprintf (src, " if (%s->TclGetVal (interp) != TCL_OK)\n", e->type->cxxTypeRefInfo->fieldName);
1377 fprintf (src, " return TCL_ERROR;\n");
1378 fprintf (src, " break;\n");
1379 }
1380 fprintf (src, " default:\n");
1381 fprintf (src, " Tcl_SetResult (interp, \"illegal choiceId in %s\", TCL_STATIC);\n", td->cxxTypeDefInfo->className);
1382 fprintf (src, " Tcl_SetErrorCode (interp, \"SNACC\", \"ILLCHOICE\", NULL);\n");
1383 fprintf (src, " return TCL_ERROR;\n");
1384 fprintf (src, " }\n");
1385 fprintf (src, " Tcl_DString valstr;\n");
1386 fprintf (src, " Tcl_DStringInit (&valstr);\n");
1387 fprintf (src, " Tcl_DStringAppendElement (&valstr, (char*)_desc.choicebyvalue (choiceId));\n");
1388 fprintf (src, " Tcl_DStringAppendElement (&valstr, interp->result);\n");
1389 fprintf (src, " Tcl_ResetResult (interp);\n");
1390 fprintf (src, " Tcl_DStringResult (interp, &valstr);\n");
1391 fprintf (src, " return TCL_OK;\n");
1392 fprintf (src, "}\n\n");
1393
1394 fprintf (src, "int %s::TclSetVal (Tcl_Interp *interp, const char *valstr)\n", td->cxxTypeDefInfo->className);
1395 fprintf (src, "{\n");
1396 fprintf (src, " Args elem;\n");
1397 fprintf (src, " if (Tcl_SplitList (interp, (char*)valstr, &elem.c, &elem.v) != TCL_OK)\n");
1398 fprintf (src, " return TCL_ERROR;\n");
1399 fprintf (src, " if (elem.c != 2)\n");
1400 fprintf (src, " {\n");
1401 fprintf (src, " sprintf (interp->result, \"syntax error: expected a pair, but it's got %%d element(s)\", elem.c);\n");
1402 fprintf (src, " return TCL_ERROR;\n");
1403 fprintf (src, " }\n");
1404 fprintf (src, " AsnType *member = _getref (elem.v[0], true);\n");
1405 fprintf (src, " if (!member)\n");
1406 fprintf (src, " {\n");
1407 fprintf (src, " Tcl_AppendResult (interp, \"illegal choice \", elem.v[0], \" for %s\", NULL);\n", td->cxxTypeDefInfo->className);
1408 fprintf (src, " Tcl_SetErrorCode (interp, \"SNACC\", \"ILLCHOICE\", NULL);\n");
1409 fprintf (src, " return TCL_ERROR;\n");
1410 fprintf (src, " }\n");
1411 fprintf (src, " return member->TclSetVal (interp, elem.v[1]);\n");
1412 fprintf (src, "}\n\n");
1413
1414 fprintf (hdr, "#endif // TCL\n");
1415 fprintf (src, "#endif // TCL\n\n");
1416 }
1417 #endif /* TCL */
1418
1419 fprintf (hdr, "#endif // META\n");
1420 fprintf (src, "#endif // META\n\n");
1421 }
1422 #endif /* META */
1423
1424 fprintf (hdr, "\n");
1425
1426 /* constructors and destructor */
1427
1428 fprintf (hdr, " %s();\n", td->cxxTypeDefInfo->className);
1429
1430 fprintf (src, "%s::%s()\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1431 fprintf (src, "{\n");
1432 e = FIRST_LIST_ELMT (choice->basicType->a.choice);
1433 fprintf (src, " choiceId = %sCid;\n", e->type->cxxTypeRefInfo->fieldName);
1434 fprintf (src, "#if TCL\n");
1435 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
1436 fprintf (src, "#else\n");
1437 fprintf (src, " %s = NULL; // incomplete initialization of mandatory element!\n", e->type->cxxTypeRefInfo->fieldName);
1438 fprintf (src, "#endif // TCL\n");
1439 fprintf (src, "}\n\n");
1440
1441 fprintf (hdr, " %s (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1442
1443 fprintf (src, "%s::%s (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1444 fprintf (src, "{\n");
1445 fprintf (src, " Asn1Error << \"use of incompletely defined %s::%s (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1446 fprintf (src, " abort();\n");
1447 fprintf (src, "}\n\n");
1448
1449 fprintf (hdr, " virtual ~%s();\n\n", td->cxxTypeDefInfo->className);
1450
1451 fprintf (src, "%s::~%s()\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1452 fprintf (src, "{\n");
1453 fprintf (src, " switch (choiceId)\n");
1454 fprintf (src, " {\n");
1455 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1456 {
1457 fprintf (src, " case %s:\n", e->type->cxxTypeRefInfo->choiceIdSymbol);
1458 if (e->type->cxxTypeRefInfo->isPtr)
1459 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
1460 fprintf (src, " break;\n");
1461 }
1462 fprintf (src, " } // end of switch\n");
1463 fprintf (src, "} // end of destructor\n");
1464 fprintf (src, "\n");
1465
1466 /* print clone routine for ANY mgmt */
1467 PrintCloneMethod (hdr, src, td);
1468
1469 fprintf (hdr, " %s &operator = (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1470
1471 fprintf (src, "#if SNACC_DEEP_COPY\n");
1472 fprintf (src, "%s &%s::operator = (const %s &that)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1473 fprintf (src, "#else // SNACC_DEEP_COPY\n");
1474 fprintf (src, "%s &%s::operator = (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1475 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
1476 fprintf (src, "{\n");
1477 fprintf (src, "#if SNACC_DEEP_COPY\n");
1478 fprintf (src, " if (this != &that)\n");
1479 fprintf (src, " {\n");
1480 fprintf (src, " switch (choiceId)\n");
1481 fprintf (src, " {\n");
1482 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1483 {
1484 if (e->type->cxxTypeRefInfo->isPtr)
1485 {
1486 fprintf (src, " case %s:\n", e->type->cxxTypeRefInfo->choiceIdSymbol);
1487 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
1488 fprintf (src, " break;\n");
1489 }
1490 }
1491 fprintf (src, " }\n");
1492 fprintf (src, " switch (choiceId = that.choiceId)\n");
1493 fprintf (src, " {\n");
1494 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1495 {
1496 fprintf (src, " case %s:\n", e->type->cxxTypeRefInfo->choiceIdSymbol);
1497 if (e->type->cxxTypeRefInfo->isPtr)
1498 {
1499 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
1500 fprintf (src, " *%s = *that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName);
1501 }
1502 else
1503 fprintf (src, " %s = that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName);
1504 fprintf (src, " break;\n");
1505 }
1506 fprintf (src, " }\n");
1507 fprintf (src, " }\n");
1508 fprintf (src, "\n");
1509 fprintf (src, " return *this;\n");
1510 fprintf (src, "#else // SNACC_DEEP_COPY\n");
1511 fprintf (src, " Asn1Error << \"use of incompletely defined %s &%s::operator = (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
1512 fprintf (src, " abort();\n");
1513 fprintf (src, " // if your compiler complains here, check the -novolat option\n");
1514 if (novolatilefuncs)
1515 {
1516 fprintf (src, " return *this;\n");
1517 }
1518 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
1519 fprintf (src, "}\n\n");
1520
1521 /* BerEncodeContent */
1522 if (printEncodersG)
1523 {
1524 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeContentBaseName, bufTypeNameG);
1525
1526 fprintf (src, "%s\n", lenTypeNameG);
1527 fprintf (src, "%s::B%s (%s b)\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName, bufTypeNameG);
1528 fprintf (src, "{\n");
1529
1530 /* print local vars */
1531 fprintf (src, " %s l;\n", lenTypeNameG);
1532
1533 fprintf (src, " switch (%s)\n", r->choiceIdFieldName);
1534 fprintf (src, " {\n");
1535 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1536 {
1537 cxxtri = e->type->cxxTypeRefInfo;
1538 fprintf (src, " case %s:\n", cxxtri->choiceIdSymbol);
1539
1540 varName = cxxtri->fieldName;
1541
1542 /* encode Eoc (s) if nec */
1543 PrintCxxEocEncoders (src, td, e->type, "b");
1544
1545 /* encode content */
1546 tmpTypeId = GetBuiltinType (e->type);
1547 if (tmpTypeId == BASICTYPE_ANYDEFINEDBY)
1548 {
1549 fprintf (src, " %s", varName);
1550 if (cxxtri->isPtr)
1551 fprintf (src, "->");
1552 else
1553 fprintf (src, ".");
1554
1555 defByNamedType = e->type->basicType->a.anyDefinedBy->link;
1556 if (GetBuiltinType (defByNamedType->type) == BASICTYPE_OID)
1557 {
1558 fprintf (src, "SetTypeByOid (");
1559 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
1560 fprintf (src, " *");
1561 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
1562 }
1563 else
1564 {
1565 fprintf (src, "SetTypeByInt (");
1566 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
1567 fprintf (src, " *");
1568 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
1569 }
1570
1571 fprintf (src, " l = %s", varName);
1572 if (cxxtri->isPtr)
1573 fprintf (src, "->");
1574 else
1575 fprintf (src, ".");
1576 fprintf (src, "B%s (b);\n", r->encodeBaseName);
1577 }
1578 else if (tmpTypeId == BASICTYPE_ANY)
1579 {
1580 #ifdef VDADER_RULES
1581 if (! gVDADER_RULES)
1582 {
1583 #endif
1584 fprintf (src, " %s", varName);
1585 if (cxxtri->isPtr)
1586 fprintf (src, "->");
1587 else
1588 fprintf (src, ".");
1589 fprintf (src, "SetTypeBy???(???);\n");
1590
1591 fprintf (src, " l = %s", varName);
1592 if (cxxtri->isPtr)
1593 fprintf (src, "->");
1594 else
1595 fprintf (src, ".");
1596 fprintf (src, "B%s (b);\n", r->encodeBaseName);
1597
1598 #ifdef VDADER_RULES
1599 }
1600 else
1601 {
1602 fprintf (src, " ENC_LOAD_ANYBUF(");
1603 if (!cxxtri->isPtr)
1604 fprintf (src, "&");
1605 fprintf (src, "%s, b, l);\n", varName);
1606 }
1607 #endif
1608 }
1609 else
1610 {
1611 fprintf (src, " l = %s", varName);
1612 if (cxxtri->isPtr)
1613 fprintf (src, "->");
1614 else
1615 fprintf (src, ".");
1616
1617 fprintf (src, "B%s (b);\n", r->encodeContentBaseName);
1618 }
1619
1620
1621 /* encode tag (s) & len (s) */
1622 PrintCxxTagAndLenEncodingCode (src, td, e->type, "l", "b");
1623
1624
1625 fprintf (src, " break;\n\n");
1626 }
1627 fprintf (src, " } // end switch\n");
1628
1629 fprintf (src, " return l;\n");
1630 fprintf (src, "} // %s::B%s\n\n\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName);
1631 }
1632 /* end of BerEncodeContent method */
1633
1634 /* BerDecodeContent */
1635 if (printDecodersG)
1636 {
1637 fprintf (hdr, " void B%s (%s b, %s tag, %s elmtLen, %s &bytesDecoded, %s env);\n", r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG);
1638
1639 fprintf (src, "void %s::B%s (%s b, %s tag, %s elmtLen0, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG);
1640
1641 fprintf (src, "{\n");
1642
1643 /* print local vars */
1644 /* count max number of extra length var nec
1645 * by counting tag/len pairs on components of the CHOICE
1646 */
1647 varCount = 0;
1648 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1649 {
1650 tmpVarCount = CxxCountVariableLevels (e->type);
1651 if (tmpVarCount > varCount)
1652 varCount = tmpVarCount;
1653 }
1654 /* write extra length vars - remeber choice content
1655 * decoders are passed the 'key' tag so need one less
1656 * than max var count.
1657 */
1658 for (i = 1; i < varCount; i++)
1659 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
1660
1661 /* switch on given tag - choices always have the key tag decoded */
1662 fprintf (src, " switch (tag)\n");
1663 fprintf (src, " {\n");
1664 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
1665 {
1666 cxxtri = e->type->cxxTypeRefInfo;
1667
1668 tags = GetTags (e->type, &stoleChoiceTags);
1669
1670 if (LIST_EMPTY (tags))
1671 {
1672 fprintf (src, " // ANY Type?\n");
1673 fprintf (src, " case MAKE_TAG_ID (?, ?, ?):\n");
1674 }
1675 else
1676 {
1677 tag = (Tag*)FIRST_LIST_ELMT (tags);
1678 classStr = Class2ClassStr (tag->tclass);
1679 codeStr = Code2UnivCodeStr (tag->code);
1680 formStr = Form2FormStr (tag->form);
1681
1682 if (tag->tclass == UNIV)
1683 {
1684 if (tag->form == ANY_FORM)
1685 {
1686 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr);
1687 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr);
1688 }
1689 else
1690 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, formStr, codeStr);
1691 }
1692 else
1693 {
1694 if (tag->form == ANY_FORM)
1695 {
1696 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (PRIM), tag->code);
1697 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (CONS), tag->code);
1698 }
1699 else
1700 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, formStr, tag->code);
1701 }
1702
1703 /* now decode extra tags/length pairs */
1704 AsnListFirst (tags);
1705 AsnListNext (tags);
1706 elmtLevel = 0;
1707 if (stoleChoiceTags)
1708 {
1709 FOR_REST_LIST_ELMT (tag, tags)
1710 {
1711 classStr = Class2ClassStr (tag->tclass);
1712 codeStr = Code2UnivCodeStr (tag->code);
1713 formStr = Form2FormStr (tag->form);
1714
1715 if (tag->tclass == UNIV)
1716 {
1717 if (tag->form == ANY_FORM)
1718 {
1719 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr);
1720 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr);
1721 }
1722 else
1723 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, formStr, codeStr);
1724 }
1725 else
1726 {
1727 if (tag->form == ANY_FORM)
1728 {
1729 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (PRIM), tag->code);
1730 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (CONS), tag->code);
1731 }
1732 else
1733 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, formStr, tag->code);
1734 }
1735 }
1736 }
1737 else /* didn't steal nested choice's tags */
1738 {
1739 FOR_REST_LIST_ELMT (tag, tags)
1740 {
1741 classStr = Class2ClassStr (tag->tclass);
1742 codeStr = Code2UnivCodeStr (tag->code);
1743 formStr = Form2FormStr (tag->form);
1744
1745 fprintf (src, " tag = BDecTag (b, bytesDecoded, env);\n");
1746 if (tag->form == ANY_FORM)
1747 {
1748 if (tag->tclass == UNIV)
1749 {
1750 fprintf (src, " if ((tag != MAKE_TAG_ID (%s, %s, %s))\n", classStr, Form2FormStr (PRIM), codeStr);
1751 fprintf (src, " && (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), codeStr);
1752 }
1753 else
1754 {
1755 fprintf (src, " if ((tag != MAKE_TAG_ID (%s, %s, %d))\n", classStr, Form2FormStr (PRIM), tag->code);
1756 fprintf (src, " && (tag != MAKE_TAG_ID (%s, %s, %d)))\n", classStr, Form2FormStr (CONS), tag->code);
1757 }
1758
1759 }
1760 else
1761 {
1762 if (tag->tclass == UNIV)
1763 fprintf (src, " if (tag != MAKE_TAG_ID (%s, %s, %s))\n", classStr, formStr, codeStr);
1764 else
1765 fprintf (src, " if (tag != MAKE_TAG_ID (%s, %s, %d))\n", classStr, formStr, tag->code);
1766 }
1767
1768 fprintf (src, " {\n");
1769 fprintf (src, " Asn1Error << \"Unexpected Tag\" << endl;\n");
1770 #if SNACC_EXCEPTION_ENABLE
1771 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
1772 #else
1773 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
1774 #endif /* SNACC_EXCEPTION_ENABLE */
1775 fprintf (src, " }\n\n");
1776
1777 fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
1778 }
1779 }
1780 }
1781 /*
1782 * if the choices element is another choice &&
1783 * we didn't steal its tags then we must grab
1784 * the key tag out of the contained CHOICE
1785 */
1786 if (!stoleChoiceTags && (GetBuiltinType (e->type) == BASICTYPE_CHOICE))
1787 {
1788 fprintf (src, " tag = BDecTag (b, bytesDecoded, env);\n");
1789 fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
1790 }
1791
1792 varName = cxxtri->fieldName;
1793
1794 /* set choice id for to this elment */
1795 fprintf (src, " %s = %s;\n", r->choiceIdFieldName, cxxtri->choiceIdSymbol);
1796
1797 /* alloc elmt if nec */
1798 if (cxxtri->isPtr)
1799 fprintf (src, " %s = new %s;\n", varName, cxxtri->className);
1800
1801 /* decode content */
1802 tmpTypeId = GetBuiltinType (e->type);
1803 if (tmpTypeId == BASICTYPE_ANYDEFINEDBY)
1804 {
1805 /*
1806 * must check for another EOC for ANYs
1807 * since the any decode routines decode
1808 * their own first tag/len pair
1809 */
1810 elmtLevel++;
1811
1812 fprintf (src, " %s", varName);
1813 if (cxxtri->isPtr)
1814 fprintf (src, "->");
1815 else
1816 fprintf (src, ".");
1817
1818 defByNamedType = e->type->basicType->a.anyDefinedBy->link;
1819 if (GetBuiltinType (defByNamedType->type) == BASICTYPE_OID)
1820 {
1821 fprintf (src, "SetTypeByOid (");
1822 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
1823 fprintf (src, " *");
1824 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
1825 }
1826 else
1827 {
1828 fprintf (src, "SetTypeByInt (");
1829 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
1830 fprintf (src, " *");
1831 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
1832 }
1833
1834 fprintf (src, " %s", varName);
1835 if (cxxtri->isPtr)
1836 fprintf (src, "->");
1837 else
1838 fprintf (src, ".");
1839 fprintf (src, "B%s (b, bytesDecoded, env);\n", r->decodeBaseName);
1840 }
1841 else if (tmpTypeId == BASICTYPE_ANY)
1842 {
1843 /*
1844 * must check for another EOC for ANYs
1845 * since the any decode routines decode
1846 * their own first tag/len pair
1847 */
1848 elmtLevel++;
1849
1850 #ifdef VDADER_RULES
1851 if (! gVDADER_RULES )
1852 {
1853 #endif
1854 fprintf (src, " %s", varName);
1855 if (cxxtri->isPtr)
1856 fprintf (src, "->");
1857 else
1858 fprintf (src, ".");
1859 fprintf (src, "SetTypeBy???(???);\n");
1860
1861 fprintf (src, " %s", varName);
1862 if (cxxtri->isPtr)
1863 fprintf (src, "->");
1864 else
1865 fprintf (src, ".");
1866 fprintf (src, "B%s (b, bytesDecoded, env);\n", r->decodeBaseName);
1867
1868 #ifdef VDADER_RULES
1869 }
1870 else
1871 {
1872 fprintf (src, " DEC_LOAD_ANYBUF(");
1873 if (!cxxtri->isPtr)
1874 fprintf (src, "&");
1875 fprintf (src, "%s, b, bytesDecoded, env);\n", varName);
1876 }
1877 #endif
1878 }
1879 else
1880 {
1881 fprintf (src, " %s", varName);
1882 if (cxxtri->isPtr)
1883 fprintf (src, "->");
1884 else
1885 fprintf (src, ".");
1886
1887 fprintf (src, "B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r->decodeContentBaseName, elmtLevel);
1888 }
1889
1890 /* decode Eoc (s) */
1891 for (i = elmtLevel-1; i >= 0; i--)
1892 {
1893 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
1894 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
1895 }
1896
1897 fprintf (src, " break;\n\n");
1898 FreeTags (tags);
1899 }
1900
1901 fprintf (src, " default:\n");
1902 fprintf (src, " Asn1Error << \"ERROR - unexpected tag in CHOICE\" << endl;\n");
1903 #if SNACC_EXCEPTION_ENABLE
1904 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
1905 #else
1906 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
1907 #endif /* SNACC_EXCEPTION_ENABLE */
1908 fprintf (src, " break;\n");
1909
1910 fprintf (src, " } // end switch\n");
1911 fprintf (src, "} // %s::B%s\n\n\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName);
1912 }
1913 /* end of code for printing BDecodeContent method */
1914
1915 /* do BEnc function */
1916 if (printEncodersG)
1917 {
1918 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeBaseName, bufTypeNameG);
1919 fprintf (src, "%s %s::B%s (%s b)\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeBaseName, bufTypeNameG);
1920 fprintf (src, "{\n");
1921 fprintf (src, " %s l;\n", lenTypeNameG);
1922 fprintf (src, " l = B%s (b);\n", r->encodeContentBaseName);
1923
1924 /* encode each tag/len pair if any */
1925 FOR_EACH_LIST_ELMT_RVS (tag, choice->tags)
1926 {
1927 classStr = Class2ClassStr (tag->tclass);
1928 formStr = Form2FormStr (CONS); /* choices are constructed */
1929 tagLen = TagByteLen (tag->code);
1930
1931 fprintf (src, " l += BEncConsLen (b, l);\n");
1932
1933 if (tag->tclass == UNIV)
1934 fprintf (src, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen, classStr, formStr, Code2UnivCodeStr (tag->code));
1935 else
1936 fprintf (src, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen, classStr, formStr, tag->code);
1937 }
1938 fprintf (src, " return l;\n");
1939 fprintf (src, "}\n\n");
1940 }
1941 /* end of BEnc function */
1942
1943 /* Do BDec function */
1944 if (printDecodersG)
1945 {
1946 fprintf (hdr, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
1947
1948 fprintf (src, "void %s::B%s (%s b, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
1949 fprintf (src, "{\n");
1950 fprintf (src, " %s elmtLen;\n", lenTypeNameG);
1951 fprintf (src, " %s tag;\n", tagTypeNameG);
1952
1953 /* print extra locals for redundant lengths */
1954 for (i = 1; (choice->tags != NULL) && (i <= LIST_COUNT (choice->tags)); i++)
1955 {
1956 fprintf (src, " %s extraLen%d;\n", lenTypeNameG, i);
1957 }
1958 fprintf (src, "\n");
1959
1960 /* decode tag/length pair (s) */
1961 elmtLevel = 0;
1962 FOR_EACH_LIST_ELMT (tag, choice->tags)
1963 {
1964 classStr = Class2ClassStr (tag->tclass);
1965 formStr = Form2FormStr (CONS); /* choices are constructed */
1966
1967 fprintf (src, " if (BDecTag (b, bytesDecoded, env) != ");
1968 if (tag->tclass == UNIV)
1969 fprintf (src, "MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, Code2UnivCodeStr (tag->code));
1970 else
1971 fprintf (src, "MAKE_TAG_ID (%s, %s, %d))", classStr, formStr, tag->code);
1972 fprintf (src, " {\n");
1973 fprintf (src, " Asn1Error << \"%s::B%s: ERROR - wrong tag\" << endl;\n", td->cxxTypeDefInfo->className, r->decodeBaseName);
1974 #if SNACC_EXCEPTION_ENABLE
1975 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
1976 #else
1977 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
1978 #endif /* SNACC_EXCEPTION_ENABLE */
1979 fprintf (src, " }\n");
1980 fprintf (src, " extraLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
1981 }
1982
1983 /* decode identifying tag from choice body */
1984 fprintf (src, " /* CHOICEs are a special case - grab identifying tag */\n");
1985 fprintf (src, " /* this allows easier handling of nested CHOICEs */\n");
1986 fprintf (src, " tag = BDecTag (b, bytesDecoded, env);\n");
1987 fprintf (src, " elmtLen = BDecLen (b, bytesDecoded, env);\n");
1988 fprintf (src, " B%s (b, tag, elmtLen, bytesDecoded, env);\n", r->decodeContentBaseName);
1989
1990 /* grab any EOCs that match redundant, indef lengths */
1991 for (i = elmtLevel; i > 0; i--)
1992 {
1993 fprintf (src, " if (extraLen%d == INDEFINITE_LEN)\n", i);
1994 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
1995 }
1996
1997 fprintf (src, "}\n\n");
1998 }
1999 /* end of BDec function */
2000
2001 PrintPduMemberFcns (src, hdr, r, td->cxxTypeDefInfo->className);
2002
2003 /* ostream printing routine */
2004 if (printPrintersG)
2005 {
2006 fprintf (hdr, " void Print (ostream &os) const;\n", td->cxxTypeDefInfo->className);
2007
2008 fprintf (src, "void %s::Print (ostream &os) const\n", td->cxxTypeDefInfo->className);
2009 fprintf (src, "{\n");
2010 #ifdef __APPLE__
2011 fprintf (src, "#ifndef NDEBUG\n");
2012 #endif
2013 /* fprintf (src, " os << \"{\" << endl;\n") */
2014 fprintf (src, " switch (choiceId)\n");
2015 fprintf (src, " {\n");
2016 FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
2017 {
2018 fprintf (src, " case %s:\n", e->type->cxxTypeRefInfo->choiceIdSymbol);
2019
2020 /* value notation so print the choice elmts field name */
2021 if (e->fieldName != NULL)
2022 fprintf (src, " os << \"%s \";\n", e->fieldName);
2023
2024 if (e->type->cxxTypeRefInfo->isPtr)
2025 {
2026 fprintf (src, " if (%s)\n", e->type->cxxTypeRefInfo->fieldName);
2027 fprintf (src, " os << *%s;\n", e->type->cxxTypeRefInfo->fieldName);
2028 fprintf (src, " else\n");
2029 #ifdef KHO
2030 fprintf (src, " os << \"-- void3 --\\n\";\n", e->type->cxxTypeRefInfo->fieldName);
2031 #else
2032 fprintf (src, " os << \"-- void --\";\n", e->type->cxxTypeRefInfo->fieldName);
2033 #endif
2034 }
2035 else
2036 fprintf (src, " os << %s;\n", e->type->cxxTypeRefInfo->fieldName);
2037
2038 fprintf (src, " break;\n\n");
2039 }
2040 fprintf (src, " } // end of switch\n");
2041
2042 #ifdef __APPLE__
2043 fprintf (src, "#endif /* NDEBUG */\n");
2044 #endif
2045 /* fprintf (src, " os << \"}\" << endl;\n") */
2046 fprintf (src, "} // %s::Print\n\n", td->cxxTypeDefInfo->className);
2047 }
2048 /* end of Print Method code */
2049
2050 /* close class definition */
2051 fprintf (hdr, "};\n\n\n");
2052
2053 } /* PrintCxxChoiceDefCode */
2054
2055
2056
2057 static void
2058 PrintCxxSeqDefCode PARAMS ((src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, parent, seq, novolatilefuncs),
2059 FILE *src _AND_
2060 FILE *hdr _AND_
2061 if_IBM_ENC (FILE *srcdb _AND_)
2062 if_IBM_ENC (FILE *hdrdb _AND_)
2063 ModuleList *mods _AND_
2064 Module *m _AND_
2065 CxxRules *r _AND_
2066 TypeDef *td _AND_
2067 Type *parent _AND_
2068 Type *seq _AND_
2069 int novolatilefuncs)
2070 {
2071 NamedType *e;
2072 char *classStr;
2073 char *formStr;
2074 char *codeStr;
2075 int tagLen, i;
2076 Tag *tag;
2077 TagList *tags;
2078 char *varName;
2079 CxxTRI *cxxtri;
2080 int elmtLevel;
2081 int varCount, tmpVarCount;
2082 int stoleChoiceTags;
2083 int inTailOptElmts;
2084 enum BasicTypeChoiceId tmpTypeId;
2085 NamedType *defByNamedType;
2086 NamedType *tmpElmt;
2087 int allOpt;
2088
2089 #ifdef _IBM_ENC_
2090 #include "./ibm_editor/print_cxx_seq_def_code.h"
2091 #endif /* _IBM_ENC_ */
2092
2093 /* put class spec in hdr file */
2094
2095 fprintf (hdr, "class %s%s\n", td->cxxTypeDefInfo->className, baseClassesG);
2096 fprintf (hdr, "{\n");
2097 fprintf (hdr, "public:\n");
2098
2099 /* write out the sequence elmts */
2100 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2101 {
2102 fprintf (hdr, " ");
2103 PrintCxxType (hdr, mods, m, r, td, seq, e->type);
2104 fprintf (hdr, "%s;\n", e->type->cxxTypeRefInfo->fieldName);
2105 }
2106
2107 fprintf (hdr, "\n");
2108
2109 #if META
2110 if (printMetaG)
2111 {
2112 fprintf (hdr, "#if META\n");
2113 fprintf (src, "#if META\n\n");
2114
2115 fprintf (hdr, " static const AsnSequenceTypeDesc _desc;\n");
2116 fprintf (hdr, " static const AsnSequenceMemberDesc _mdescs[];\n");
2117 fprintf (hdr, " const AsnTypeDesc *_getdesc() const;\n");
2118 fprintf (hdr, " AsnType *_getref (const char *membername, bool create = false);\n\n");
2119
2120 fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);
2121 fprintf (src, "{\n");
2122 fprintf (src, " return new %s;\n", td->cxxTypeDefInfo->className);
2123 fprintf (src, "}\n\n");
2124
2125 fprintf (src, "const AsnSequenceMemberDesc %s::_mdescs[] =\n", td->cxxTypeDefInfo->className);
2126 fprintf (src, "{\n");
2127 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2128 if (printMetaG == META_backend_names)
2129 fprintf (src, " AsnSequenceMemberDesc (\"%s\", &%s::_desc, %s), // `%s'\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className, e->type->optional || e->type->defaultVal ? "true" : "false", e->fieldName ? e->fieldName : "");
2130 else /* META_asn1_names */
2131 fprintf (src, " AsnSequenceMemberDesc (\"%s\", &%s::_desc, %s), // `%s'\n", e->fieldName ? e->fieldName : e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className, e->type->optional || e->type->defaultVal ? "true" : "false", e->type->cxxTypeRefInfo->fieldName);
2132 fprintf (src, " AsnSequenceMemberDesc()\n");
2133 fprintf (src, "};\n\n");
2134
2135 fprintf (src, "const AsnSequenceTypeDesc %s::_desc\n", td->cxxTypeDefInfo->className);
2136 fprintf (src, "(\n");
2137 fprintf (src, " &%sModuleDesc,\n", m->cxxname);
2138 if (printMetaG == META_backend_names)
2139 fprintf (src, " \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);
2140 else /* META_asn1_names */
2141 fprintf (src, " \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);
2142 fprintf (src, " %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");
2143 fprintf (src, " AsnTypeDesc::SEQUENCE,\n");
2144 fprintf (src, " create%s,\n", td->cxxTypeDefInfo->className);
2145 fprintf (src, " _mdescs\n");
2146 fprintf (src, ");\n\n");
2147
2148 fprintf (src, "const AsnTypeDesc *%s::_getdesc() const\n", td->cxxTypeDefInfo->className);
2149 fprintf (src, "{\n");
2150 fprintf (src, " return &_desc;\n");
2151 fprintf (src, "}\n\n");
2152
2153 fprintf (src, "AsnType *%s::_getref (const char *membername, bool create)\n", td->cxxTypeDefInfo->className);
2154 fprintf (src, "{\n");
2155 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2156 {
2157 fprintf (src, " if (!strcmp (membername, \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
2158 if (e->type->cxxTypeRefInfo->isPtr)
2159 {
2160 fprintf (src, " {\n");
2161 fprintf (src, " if (!%s && create)\n", e->type->cxxTypeRefInfo->fieldName);
2162 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
2163 fprintf (src, " return %s;\n", e->type->cxxTypeRefInfo->fieldName);
2164 fprintf (src, " }\n");
2165 }
2166 else
2167 fprintf (src, " return &%s;\n", e->type->cxxTypeRefInfo->fieldName);
2168 }
2169 fprintf (src, " return NULL;\n");
2170 fprintf (src, "}\n\n");
2171
2172 #if TCL
2173 if (printTclG)
2174 {
2175 fprintf (hdr, "#if TCL\n");
2176 fprintf (src, "#if TCL\n\n");
2177
2178 fprintf (hdr, " int TclGetDesc (Tcl_DString *) const;\n");
2179 fprintf (hdr, " int TclGetVal (Tcl_Interp *) const;\n");
2180 fprintf (hdr, " int TclSetVal (Tcl_Interp *, const char *valstr);\n");
2181 fprintf (hdr, " int TclUnsetVal (Tcl_Interp *, const char *membname);\n\n");
2182
2183 fprintf (src, "int %s::TclGetDesc (Tcl_DString *valstr) const\n", td->cxxTypeDefInfo->className);
2184 fprintf (src, "{\n");
2185 fprintf (src, " Tcl_DStringStartSublist (valstr);\n\n");
2186 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2187 {
2188 fprintf (src, " Tcl_DStringStartSublist (valstr);\n");
2189 fprintf (src, " Tcl_DStringAppendElement (valstr, \"%s\");\n", e->type->cxxTypeRefInfo->fieldName);
2190 if (e->type->cxxTypeRefInfo->isPtr)
2191 fprintf (src, " Tcl_DStringAppendElement (valstr, %s ? \"valid\" : \"void\");\n", e->type->cxxTypeRefInfo->fieldName);
2192 else
2193 fprintf (src, " Tcl_DStringAppendElement (valstr, \"valid\");\n", e->type->cxxTypeRefInfo->fieldName);
2194 fprintf (src, " Tcl_DStringEndSublist (valstr);\n\n");
2195 }
2196 fprintf (src, " Tcl_DStringEndSublist (valstr);\n\n");
2197 fprintf (src, " return TCL_OK;\n");
2198 fprintf (src, "}\n\n");
2199
2200 fprintf (src, "int %s::TclGetVal (Tcl_Interp *interp) const\n", td->cxxTypeDefInfo->className);
2201 fprintf (src, "{\n");
2202 fprintf (src, " Tcl_DString valstr;\n\n");
2203 fprintf (src, " Tcl_DStringInit (&valstr);\n\n");
2204 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2205 {
2206 if (e->type->cxxTypeRefInfo->isPtr)
2207 {
2208 fprintf (src, " if (%s)\n", e->type->cxxTypeRefInfo->fieldName);
2209 fprintf (src, " {\n");
2210 fprintf (src, " Tcl_DStringStartSublist (&valstr);\n");
2211 fprintf (src, " Tcl_DStringAppendElement (&valstr, \"%s\");\n", e->type->cxxTypeRefInfo->fieldName);
2212 fprintf (src, " if (%s->TclGetVal (interp) != TCL_OK)\n", e->type->cxxTypeRefInfo->fieldName);
2213 fprintf (src, " goto Error;\n");
2214 fprintf (src, " Tcl_DStringAppendElement (&valstr, interp->result);\n");
2215 fprintf (src, " Tcl_ResetResult (interp);\n");
2216 fprintf (src, " Tcl_DStringEndSublist (&valstr);\n");
2217 fprintf (src, " }\n\n");
2218 }
2219 else
2220 {
2221 fprintf (src, " Tcl_DStringStartSublist (&valstr);\n");
2222 fprintf (src, " Tcl_DStringAppendElement (&valstr, \"%s\");\n", e->type->cxxTypeRefInfo->fieldName);
2223 fprintf (src, " if (%s.TclGetVal (interp) != TCL_OK)\n", e->type->cxxTypeRefInfo->fieldName);
2224 fprintf (src, " goto Error;\n");
2225 fprintf (src, " Tcl_DStringAppendElement (&valstr, interp->result);\n");
2226 fprintf (src, " Tcl_ResetResult (interp);\n");
2227 fprintf (src, " Tcl_DStringEndSublist (&valstr);\n\n");
2228 }
2229 }
2230 fprintf (src, " Tcl_DStringResult (interp, &valstr);\n");
2231 fprintf (src, " return TCL_OK;\n\n");
2232 fprintf (src, "Error:\n");
2233 fprintf (src, " Tcl_DStringFree (&valstr);\n");
2234 fprintf (src, " return TCL_ERROR;\n");
2235 fprintf (src, "}\n\n");
2236
2237 fprintf (src, "int %s::TclSetVal (Tcl_Interp *interp, const char *valstr)\n", td->cxxTypeDefInfo->className);
2238 fprintf (src, "{\n");
2239 fprintf (src, " int i;\n");
2240 fprintf (src, " Args elems;\n");
2241 fprintf (src, " if (Tcl_SplitList (interp, (char*)valstr, &elems.c, &elems.v) != TCL_OK)\n");
2242 fprintf (src, " return TCL_ERROR;\n");
2243 fprintf (src, " Args* elempairs = new Args[elems.c];\n");
2244 fprintf (src, " for (i=0; i<elems.c; i++)\n");
2245 fprintf (src, " {\n");
2246 fprintf (src, " if (Tcl_SplitList (interp, elems.v[i], &elempairs[i].c, &elempairs[i].v) != TCL_OK)\n");
2247 fprintf (src, " {\n");
2248 fprintf (src, " delete elempairs;\n");
2249 fprintf (src, " return TCL_ERROR;\n");
2250 fprintf (src, " }\n");
2251 fprintf (src, " if (elempairs[i].c != 2)\n");
2252 fprintf (src, " {\n");
2253 fprintf (src, " sprintf (interp->result, \"syntax error in element #%%d: expected a pair, but it's got %%d element(s)\", i, elempairs[i].c);\n");
2254 fprintf (src, " delete elempairs;\n");
2255 fprintf (src, " return TCL_ERROR;\n");
2256 fprintf (src, " }\n");
2257 fprintf (src, " }\n");
2258 fprintf (src, "\n");
2259 fprintf (src, " for (const AsnSequenceMemberDesc *m=_mdescs; m->name; m++)\n");
2260 fprintf (src, " {\n");
2261 fprintf (src, " int count = 0;\n");
2262 fprintf (src, " for (i=0; i<elems.c; i++)\n");
2263 fprintf (src, " if (!strcmp (elempairs[i].v[0], m->name))\n");
2264 fprintf (src, " count++;\n");
2265 fprintf (src, " if (count > 1)\n");
2266 fprintf (src, " {\n");
2267 fprintf (src, " sprintf (interp->result, \"duplicate value for member \\\"%%s\\\" in list\", m->name);\n");
2268 fprintf (src, " Tcl_SetErrorCode (interp, \"SNACC\", \"DUPMEMB\", NULL);\n");
2269 fprintf (src, " delete elempairs;\n");
2270 fprintf (src, " return TCL_ERROR;\n");
2271 fprintf (src, " }\n");
2272 fprintf (src, " if (!m->optional && count < 1)\n");
2273 fprintf (src, " {\n");
2274 fprintf (src, " sprintf (interp->result, \"mandatory member \\\"%%s\\\" is missing in list\", m->name);\n");
2275 fprintf (src, " Tcl_SetErrorCode (interp, \"SNACC\", \"MISSMAND\", NULL);\n");
2276 fprintf (src, " delete elempairs;\n");
2277 fprintf (src, " return TCL_ERROR;\n");
2278 fprintf (src, " }\n");
2279 fprintf (src, " \n");
2280 fprintf (src, " }\n");
2281 fprintf (src, "\n");
2282 fprintf (src, " for (i=0; i<elems.c; i++)\n");
2283 fprintf (src, " {\n");
2284 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2285 {
2286 fprintf (src, " if (!strcmp (elempairs[i].v[0], \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
2287 fprintf (src, " {\n");
2288 if (e->type->cxxTypeRefInfo->isPtr)
2289 {
2290 fprintf (src, " if (!%s)\n", e->type->cxxTypeRefInfo->fieldName);
2291 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
2292 fprintf (src, " if (%s->TclSetVal (interp, elempairs[i].v[1]))\n", e->type->cxxTypeRefInfo->fieldName);
2293 fprintf (src, " {\n");
2294 fprintf (src, " delete elempairs;\n");
2295 fprintf (src, " return TCL_ERROR;\n");
2296 fprintf (src, " }\n");
2297 }
2298 else
2299 {
2300 fprintf (src, " if (%s.TclSetVal (interp, elempairs[i].v[1]))\n", e->type->cxxTypeRefInfo->fieldName);
2301 fprintf (src, " {\n");
2302 fprintf (src, " delete elempairs;\n");
2303 fprintf (src, " return TCL_ERROR;\n");
2304 fprintf (src, " }\n");
2305 }
2306 fprintf (src, " }\n");
2307 }
2308 fprintf (src, " }\n");
2309 fprintf (src, "\n");
2310 fprintf (src, " // look for unmentioned optional members and delete them:\n");
2311 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2312 {
2313 if (e->type->optional || e->type->defaultVal)
2314 {
2315 fprintf (src, " {\n");
2316 fprintf (src, " bool present = false;\n");
2317 fprintf (src, " for (i=0; i<elems.c; i++)\n");
2318 fprintf (src, " if (!strcmp (elempairs[i].v[0], \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
2319 fprintf (src, " present = true;\n");
2320 fprintf (src, " if (!present)\n");
2321 fprintf (src, " {\n");
2322 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
2323 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
2324 fprintf (src, " }\n");
2325 fprintf (src, " }\n");
2326 }
2327 }
2328 fprintf (src, "\n");
2329 fprintf (src, " delete elempairs;\n");
2330 fprintf (src, " return TCL_OK;\n");
2331 fprintf (src, "}\n\n");
2332
2333 fprintf (src, "int %s::TclUnsetVal (Tcl_Interp *interp, const char *membernames)\n", td->cxxTypeDefInfo->className);
2334 fprintf (src, "{\n");
2335 fprintf (src, " Args elems;\n");
2336 fprintf (src, " if (Tcl_SplitList (interp, (char*)membernames, &elems.c, &elems.v) != TCL_OK)\n");
2337 fprintf (src, " return TCL_ERROR;\n");
2338 fprintf (src, "\n");
2339 fprintf (src, " for (int i=0; i<elems.c; i++)\n");
2340 fprintf (src, " {\n");
2341 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2342 {
2343 fprintf (src, " if (!strcmp (elems.v[i], \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
2344 fprintf (src, " {\n");
2345 if (e->type->optional || e->type->defaultVal)
2346 {
2347 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
2348 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
2349 }
2350 else
2351 {
2352 fprintf (src, " return _desc.mandatmemberr (interp, elems.v[i]);\n");
2353 }
2354 fprintf (src, " }\n");
2355 }
2356 fprintf (src, " }\n");
2357 fprintf (src, " return TCL_OK;\n");
2358 fprintf (src, "}\n\n");
2359
2360 fprintf (hdr, "#endif // TCL\n");
2361 fprintf (src, "#endif // TCL\n\n");
2362 }
2363 #endif /* TCL */
2364
2365 fprintf (hdr, "#endif // META\n\n");
2366 fprintf (src, "#endif // META\n\n");
2367 }
2368 #endif /* META */
2369
2370 /* constructors and destructor: */
2371
2372 fprintf (hdr, " %s();\n", td->cxxTypeDefInfo->className);
2373
2374 fprintf (src, "%s::%s()\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2375 fprintf (src, "{\n");
2376 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2377 {
2378 if (e->type->cxxTypeRefInfo->isPtr)
2379 if (e->type->optional || e->type->defaultVal)
2380 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
2381 else
2382 {
2383 fprintf (src, "#if TCL\n");
2384 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
2385 fprintf (src, "#else\n");
2386 fprintf (src, " %s = NULL; // incomplete initialization of mandatory element!\n", e->type->cxxTypeRefInfo->fieldName);
2387 fprintf (src, "#endif // TCL\n");
2388 }
2389 }
2390 fprintf (src, "}\n\n");
2391
2392 fprintf (hdr, " %s (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2393
2394 fprintf (src, "%s::%s (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2395 fprintf (src, "{\n");
2396 fprintf (src, " Asn1Error << \"use of incompletely defined %s::%s (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2397 fprintf (src, " abort();\n");
2398 fprintf (src, "}\n\n");
2399
2400 fprintf (hdr, " virtual ~%s();\n", td->cxxTypeDefInfo->className);
2401
2402 fprintf (src, "%s::~%s()\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2403 fprintf (src, "{\n");
2404 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2405 if (e->type->cxxTypeRefInfo->isPtr)
2406 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
2407 fprintf (src, "}\n\n");
2408
2409 /* print clone routine for ANY mgmt */
2410 PrintCloneMethod (hdr, src, td);
2411
2412 fprintf (hdr, " %s &operator = (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2413
2414 fprintf (src, "#if SNACC_DEEP_COPY\n");
2415 fprintf (src, "%s &%s::operator = (const %s &that)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2416 fprintf (src, "#else // SNACC_DEEP_COPY\n");
2417 fprintf (src, "%s &%s::operator = (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2418 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
2419 fprintf (src, "{\n");
2420 fprintf (src, "#if SNACC_DEEP_COPY\n");
2421 fprintf (src, " if (this != &that)\n");
2422 fprintf (src, " {\n");
2423 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2424 {
2425 if (e->type->cxxTypeRefInfo->isPtr)
2426 {
2427 fprintf (src, " if (that.%s)\n", e->type->cxxTypeRefInfo->fieldName);
2428 fprintf (src, " {\n");
2429 fprintf (src, " if (!%s)\n", e->type->cxxTypeRefInfo->fieldName);
2430 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
2431 fprintf (src, " *%s = *that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName);
2432 fprintf (src, " }\n");
2433 fprintf (src, " else\n");
2434 fprintf (src, " {\n");
2435 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
2436 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
2437 fprintf (src, " }\n");
2438 }
2439 else
2440 fprintf (src, " %s = that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName);
2441 }
2442 fprintf (src, " }\n");
2443 fprintf (src, "\n");
2444 fprintf (src, " return *this;\n");
2445 fprintf (src, "#else // SNACC_DEEP_COPY\n");
2446 fprintf (src, " Asn1Error << \"use of incompletely defined %s &%s::operator = (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
2447 fprintf (src, " abort();\n");
2448 fprintf (src, " // if your compiler complains here, check the -novolat option\n");
2449 if (novolatilefuncs)
2450 {
2451 fprintf (src, " return *this;\n");
2452 }
2453 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
2454 fprintf (src, "}\n\n");
2455
2456 /* BerEncodeContent method */
2457 if (printEncodersG)
2458 {
2459 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeContentBaseName, bufTypeNameG);
2460
2461 fprintf (src, "%s\n", lenTypeNameG);
2462 fprintf (src, "%s::B%s (%s b)\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName, bufTypeNameG);
2463
2464 fprintf (src, "{\n");
2465
2466 /* print local vars */
2467 fprintf (src, " %s totalLen = 0;\n", lenTypeNameG);
2468 fprintf (src, " %s l;\n\n", lenTypeNameG);
2469
2470 FOR_EACH_LIST_ELMT_RVS (e, seq->basicType->a.sequence)
2471 {
2472 cxxtri = e->type->cxxTypeRefInfo;
2473
2474 varName = cxxtri->fieldName;
2475
2476 /* print optional test if nec */
2477 if (e->type->optional || (e->type->defaultVal != NULL))
2478 {
2479 fprintf (src, " if (%s (%s))\n", cxxtri->optTestRoutineName, varName);
2480 fprintf (src, " {\n");
2481 }
2482
2483 /* encode Eoc (s) if nec */
2484 PrintCxxEocEncoders (src, td, e->type, "b");
2485
2486 /* encode content */
2487 tmpTypeId = GetBuiltinType (e->type);
2488 if (tmpTypeId == BASICTYPE_ANYDEFINEDBY)
2489 {
2490 fprintf (src, " %s", varName);
2491 if (cxxtri->isPtr)
2492 fprintf (src, "->");
2493 else
2494 fprintf (src, ".");
2495
2496 defByNamedType = e->type->basicType->a.anyDefinedBy->link;
2497 if (GetBuiltinType (defByNamedType->type) == BASICTYPE_OID)
2498 {
2499 fprintf (src, "SetTypeByOid (");
2500 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
2501 fprintf (src, " *");
2502 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
2503 }
2504 else
2505 {
2506 fprintf (src, "SetTypeByInt (");
2507 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
2508 fprintf (src, " *");
2509 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
2510 }
2511
2512 fprintf (src, " l = %s", varName);
2513 if (cxxtri->isPtr)
2514 fprintf (src, "->");
2515 else
2516 fprintf (src, ".");
2517 fprintf (src, "B%s (b);\n", r->encodeBaseName);
2518 }
2519 else if (tmpTypeId == BASICTYPE_ANY)
2520 {
2521 #ifdef VDADER_RULES
2522 if (! gVDADER_RULES)
2523 {
2524 #endif
2525 fprintf (src, " %s", varName);
2526 if (cxxtri->isPtr)
2527 fprintf (src, "->");
2528 else
2529 fprintf (src, ".");
2530 fprintf (src, "SetTypeBy???(???);\n");
2531
2532 fprintf (src, " l = %s", varName);
2533 if (cxxtri->isPtr)
2534 fprintf (src, "->");
2535 else
2536 fprintf (src, ".");
2537 fprintf (src, "B%s (b);\n", r->encodeBaseName);
2538
2539 #ifdef VDADER_RULES
2540 }
2541 else
2542 {
2543 fprintf (src, " ENC_LOAD_ANYBUF(");
2544 if (!cxxtri->isPtr)
2545 fprintf (src, "&");
2546 fprintf (src, "%s, b, l);\n", varName);
2547 }
2548 #endif
2549 }
2550 else
2551 {
2552 fprintf (src, " l = %s", varName);
2553 if (cxxtri->isPtr)
2554 fprintf (src, "->");
2555 else
2556 fprintf (src, ".");
2557
2558 fprintf (src, "B%s (b);\n", r->encodeContentBaseName);
2559 }
2560
2561
2562 /* encode tag (s) & len (s) */
2563 PrintCxxTagAndLenEncodingCode (src, td, e->type, "l", "b");
2564
2565
2566 fprintf (src, " totalLen += l;\n");
2567
2568 /* close optional test if nec */
2569 if (e->type->optional || (e->type->defaultVal != NULL))
2570 fprintf (src, " }\n\n");
2571 else
2572 fprintf (src, "\n");
2573 }
2574 fprintf (src, " return totalLen;\n");
2575 fprintf (src, "} // %s::B%s\n\n\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName);
2576 }
2577 /* end of BerEncodeContent method printing code */
2578
2579 /* write BerDecodeContent to src */
2580 if (printDecodersG)
2581 {
2582 fprintf (hdr, " void B%s (%s b, %s tag, %s elmtLen, %s &bytesDecoded, %s env);\n\n", r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG);
2583
2584 fprintf (src, "void %s::B%s (%s b, %s /*tag0*/, %s elmtLen0, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG);
2585
2586 fprintf (src, "{\n");
2587
2588 /* print local vars */
2589 fprintf (src, " %s tag1;\n", tagTypeNameG);
2590 fprintf (src, " %s seqBytesDecoded = 0;\n", lenTypeNameG);
2591 /* count max number of extra length var nec */
2592 varCount = 0;
2593 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2594 {
2595 tmpVarCount = CxxCountVariableLevels (e->type);
2596
2597 if (tmpVarCount > varCount)
2598 varCount = tmpVarCount;
2599 }
2600 /* write extra length vars */
2601 for (i = 1; i <= varCount; i++)
2602 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
2603
2604 /* handle empty seq */
2605 if ((seq->basicType->a.sequence == NULL) || LIST_EMPTY (seq->basicType->a.sequence))
2606 {
2607 fprintf (src, " if (elmtLen0 == INDEFINITE_LEN)\n");
2608 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
2609 fprintf (src, " else if (elmtLen0 != 0)\n");
2610 fprintf (src, " {\n");
2611 fprintf (src, " Asn1Error << \"Expected an empty sequence\" << endl;\n");
2612 #if SNACC_EXCEPTION_ENABLE
2613 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
2614 #else
2615 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
2616 #endif /* SNACC_EXCEPTION_ENABLE */
2617 fprintf (src, " }\n");
2618
2619 /*
2620 forget about posssible extensions to the type
2621 fprintf (src, " {\n");
2622 fprintf (src, " tag1 = BDecTag (b, bytesDecoded, env);\n\n");
2623 fprintf (src, " if (tag1 == EOC_TAG_ID)\n");
2624 fprintf (src, " BDEC_2ND_EOC_OCTET (b, bytesDecoded, env)\n");
2625 fprintf (src, " else\n");
2626
2627 fprintf (src, " BerDiscardElmt (b, bytesDecoded, env);\n\n");
2628 fprintf (src, " }\n");
2629 fprintf (src, " else\n");
2630 fprintf (src, " {\n");
2631 fprintf (src, " BufSkip (b, elmtLen0);\n");
2632 fprintf (src, " bytesDecoded%d += elmtLen0;\n");
2633 fprintf (src, " }\n");
2634 */
2635 }
2636 else
2637 {
2638 /* check if all elmts are optional */
2639 AsnListFirst (seq->basicType->a.sequence);
2640 inTailOptElmts = IsTailOptional (seq->basicType->a.sequence);
2641 e = (NamedType*)FIRST_LIST_ELMT (seq->basicType->a.sequence);
2642
2643 tmpTypeId = GetBuiltinType (e->type);
2644
2645 if (!inTailOptElmts)
2646 {
2647 if (((tmpTypeId == BASICTYPE_ANY) || (tmpTypeId == BASICTYPE_ANYDEFINEDBY)) && (CountTags (e->type) == 0))
2648 {
2649 if ((e->type->optional) && (e != (NamedType*)LAST_LIST_ELMT (seq->basicType->a.sequence)))
2650 fprintf (src, "<untagged optional ANY - you must fix this>\n");
2651 }
2652 else
2653 fprintf (src, " tag1 = BDecTag (b, seqBytesDecoded, env);\n\n");
2654 }
2655 else
2656 {
2657 fprintf (src, " if (elmtLen0 == 0)\n");
2658 fprintf (src, " return;\n");
2659 fprintf (src, " else\n");
2660 fprintf (src, " {\n");
2661 if (((tmpTypeId == BASICTYPE_ANY) || (tmpTypeId == BASICTYPE_ANYDEFINEDBY)) && (CountTags (e->type) == 0))
2662 {
2663 if ((e->type->optional) && (e != (NamedType*)LAST_LIST_ELMT (seq->basicType->a.sequence)))
2664 fprintf (src, "<untagged optional ANY - you must fix this>\n");
2665 }
2666 else
2667 fprintf (src, " tag1 = BDecTag (b, seqBytesDecoded, env);\n\n");
2668 fprintf (src, " if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))\n");
2669 fprintf (src, " {\n");
2670 fprintf (src, " BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)\n");
2671 fprintf (src, " bytesDecoded += seqBytesDecoded;\n");
2672 fprintf (src, " return;\n");
2673 fprintf (src, " }\n");
2674 fprintf (src, " }\n\n");
2675 }
2676
2677
2678 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
2679 {
2680 cxxtri = e->type->cxxTypeRefInfo;
2681 elmtLevel = 0;
2682
2683 tags = GetTags (e->type, &stoleChoiceTags);
2684
2685 /* if (inTailOptElmts)
2686 fprintf (src, " (!seqDone) && ");
2687 */
2688 if (LIST_EMPTY (tags))
2689 fprintf (src, " // ANY type\n");
2690 else
2691 {
2692 tag = (Tag*)FIRST_LIST_ELMT (tags);
2693 classStr = Class2ClassStr (tag->tclass);
2694 codeStr = Code2UnivCodeStr (tag->code);
2695 formStr = Form2FormStr (tag->form);
2696
2697 fprintf (src, " if (");
2698 if (tag->tclass == UNIV)
2699 {
2700 if (tag->form == ANY_FORM)
2701 {
2702 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %s))\n", classStr, Form2FormStr (PRIM), codeStr);
2703 fprintf (src, " || (tag1 == MAKE_TAG_ID (%s, %s, %s))", classStr, Form2FormStr (CONS), codeStr);
2704 }
2705 else
2706 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, codeStr);
2707 }
2708 else
2709 {
2710 if (tag->form == ANY_FORM)
2711 {
2712 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %d))\n", classStr, Form2FormStr (PRIM), tag->code);
2713 fprintf (src, " || (tag1 == MAKE_TAG_ID (%s, %s, %d))", classStr, Form2FormStr (CONS), tag->code);
2714 }
2715 else
2716 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %d))", classStr, formStr, tag->code);
2717 }
2718
2719
2720 /* now decode extra tags/length pairs */
2721 AsnListFirst (tags);
2722 AsnListNext (tags);
2723 if (stoleChoiceTags)
2724 {
2725 FOR_REST_LIST_ELMT (tag, tags)
2726 {
2727 fprintf (src, "\n || ");
2728 classStr = Class2ClassStr (tag->tclass);
2729 codeStr = Code2UnivCodeStr (tag->code);
2730 formStr = Form2FormStr (tag->form);
2731
2732 if (tag->tclass == UNIV)
2733 {
2734 if (tag->form == ANY_FORM)
2735 {
2736 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %s))\n", classStr, Form2FormStr (PRIM), codeStr);
2737 fprintf (src, " || (tag1 == MAKE_TAG_ID (%s, %s, %s))", classStr, Form2FormStr (CONS), codeStr);
2738 }
2739 else
2740 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, codeStr);
2741 }
2742 else
2743 {
2744 if (tag->form == ANY_FORM)
2745 {
2746 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %d))\n", classStr, Form2FormStr (PRIM), tag->code);
2747 fprintf (src, " || (tag1 == MAKE_TAG_ID (%s, %s, %d))", classStr, Form2FormStr (CONS), tag->code);
2748 }
2749 else
2750 fprintf (src, "(tag1 == MAKE_TAG_ID (%s, %s, %d))", classStr, formStr, tag->code);
2751 }
2752 }
2753 fprintf (src, ")\n");
2754 fprintf (src, " {\n");
2755 fprintf (src, " elmtLen%d = BDecLen (b, seqBytesDecoded, env);\n", ++elmtLevel);
2756 }
2757
2758 else /* didn't steal nested choice's tags */
2759 {
2760 fprintf (src, ")\n");
2761 fprintf (src, " {\n");
2762 fprintf (src, " elmtLen%d = BDecLen (b, seqBytesDecoded, env);\n", ++elmtLevel);
2763
2764 FOR_REST_LIST_ELMT (tag, tags)
2765 {
2766 classStr = Class2ClassStr (tag->tclass);
2767 codeStr = Code2UnivCodeStr (tag->code);
2768 formStr = Form2FormStr (tag->form);
2769
2770 fprintf (src, " tag1 = BDecTag (b, seqBytesDecoded, env);\n\n");
2771 if (tag->tclass == UNIV)
2772 {
2773 if (tag->form == ANY_FORM)
2774 {
2775 fprintf (src, " if ((tag1 != MAKE_TAG_ID (%s, %s, %s))\n", classStr, Form2FormStr (PRIM), codeStr);
2776 fprintf (src, " && (tag1 != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), codeStr);
2777 }
2778 else
2779 fprintf (src, " if (tag1 != MAKE_TAG_ID (%s, %s, %s))\n", classStr, formStr, codeStr);
2780 }
2781 else
2782 {
2783 if (tag->form == ANY_FORM)
2784 {
2785 fprintf (src, " if ((tag1 != MAKE_TAG_ID (%s, %s, %d))\n", classStr, Form2FormStr (PRIM), tag->code);
2786 fprintf (src, " && (tag1 != MAKE_TAG_ID (%s, %s, %d)))\n", classStr, Form2FormStr (CONS), tag->code);
2787 }
2788 else
2789 fprintf (src, " if (tag1 != MAKE_TAG_ID (%s, %s, %d))\n", classStr, formStr, tag->code);
2790 }
2791
2792 fprintf (src, " {\n");
2793 fprintf (src, " Asn1Error << \"Unexpected Tag\" << endl;\n");
2794 #if SNACC_EXCEPTION_ENABLE
2795 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
2796 #else
2797 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
2798 #endif /* SNACC_EXCEPTION_ENABLE */
2799 fprintf (src, " }\n\n");
2800 fprintf (src, " elmtLen%d = BDecLen (b, seqBytesDecoded, env);\n", ++elmtLevel);
2801 }
2802 }
2803 }
2804 /*
2805 * if this seq element is CHOICE &&
2806 * we didn't steal its tags then we must grab
2807 * the key tag out of the contained CHOICE
2808 */
2809 if (!stoleChoiceTags && (GetBuiltinType (e->type) == BASICTYPE_CHOICE))
2810 {
2811 fprintf (src, " tag1 = BDecTag (b, seqBytesDecoded, env);\n");
2812 fprintf (src, " elmtLen%d = BDecLen (b, seqBytesDecoded, env);\n", ++elmtLevel);
2813 }
2814
2815
2816
2817 varName = cxxtri->fieldName;
2818
2819 /* decode content */
2820 if (cxxtri->isPtr)
2821 fprintf (src, " %s = new %s;\n", varName, cxxtri->className);
2822
2823
2824 /* decode content */
2825 tmpTypeId = GetBuiltinType (e->type);
2826 if (tmpTypeId == BASICTYPE_ANYDEFINEDBY)
2827 {
2828 /*
2829 * must check for another EOC for ANYs
2830 * since the any decode routines decode
2831 * their own first tag/len pair
2832 */
2833 elmtLevel++;
2834 fprintf (src, " %s", varName);
2835 if (cxxtri->isPtr)
2836 fprintf (src, "->");
2837 else
2838 fprintf (src, ".");
2839
2840 defByNamedType = e->type->basicType->a.anyDefinedBy->link;
2841 if (GetBuiltinType (defByNamedType->type) == BASICTYPE_OID)
2842 {
2843 fprintf (src, "SetTypeByOid (");
2844 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
2845 fprintf (src, " *");
2846 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
2847 }
2848 else
2849 {
2850 fprintf (src, "SetTypeByInt (");
2851 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
2852 fprintf (src, " *");
2853 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
2854 }
2855
2856 fprintf (src, " %s", varName);
2857 if (cxxtri->isPtr)
2858 fprintf (src, "->");
2859 else
2860 fprintf (src, ".");
2861 fprintf (src, "B%s (b, seqBytesDecoded, env);\n", r->decodeBaseName);
2862 }
2863 else if (tmpTypeId == BASICTYPE_ANY)
2864 {
2865 /*
2866 * must check for another EOC for ANYs
2867 * since the any decode routines decode
2868 * their own first tag/len pair
2869 */
2870 elmtLevel++;
2871
2872 #ifdef VDADER_RULES
2873 if (! gVDADER_RULES)
2874 {
2875 #endif
2876 fprintf (src, " %s", varName);
2877 if (cxxtri->isPtr)
2878 fprintf (src, "->");
2879 else
2880 fprintf (src, ".");
2881 fprintf (src, "SetTypeBy???(???);\n");
2882
2883 fprintf (src, " %s", varName);
2884 if (cxxtri->isPtr)
2885 fprintf (src, "->");
2886 else
2887 fprintf (src, ".");
2888 fprintf (src, "B%s (b, seqBytesDecoded, env);\n", r->decodeBaseName);
2889
2890 #ifdef VDADER_RULES
2891 }
2892 else
2893 {
2894 fprintf (src, " DEC_LOAD_ANYBUF(");
2895 if (!cxxtri->isPtr)
2896 fprintf (src, "&");
2897 fprintf (src, "%s, b, seqBytesDecoded, env);\n", varName);
2898 }
2899 #endif
2900 }
2901 else
2902 {
2903 fprintf (src, " %s", varName);
2904 if (cxxtri->isPtr)
2905 fprintf (src, "->");
2906 else
2907 fprintf (src, ".");
2908
2909 fprintf (src, "B%s (b, tag1, elmtLen%d, seqBytesDecoded, env);\n", r->decodeContentBaseName, elmtLevel);
2910 }
2911
2912 /* decode Eoc (s) */
2913 for (i = elmtLevel-1; i > 0; i--)
2914 {
2915 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
2916 fprintf (src, " BDecEoc (b, seqBytesDecoded, env);\n\n");
2917 }
2918
2919 /*
2920 * print code for getting the next tag
2921 */
2922 inTailOptElmts = RestAreTailOptional (seq->basicType->a.sequence);
2923 if (e != (NamedType*)LAST_LIST_ELMT (seq->basicType->a.sequence))
2924 {
2925 tmpElmt = (NamedType*)NEXT_LIST_ELMT (seq->basicType->a.sequence);
2926 tmpTypeId = GetBuiltinType (tmpElmt->type);
2927 if (!inTailOptElmts)
2928 {
2929 if ((tmpTypeId == BASICTYPE_ANY || tmpTypeId == BASICTYPE_ANYDEFINEDBY) && CountTags (tmpElmt->type) == 0)
2930 {
2931 /* don't get a tag since ANY's decode their own */
2932 if (e->type->optional || (tmpElmt->type->optional && tmpElmt != (NamedType*)LAST_LIST_ELMT (seq->basicType->a.sequence)))
2933 /* let this cause a compile error in the generated code */
2934 fprintf (src, " <problems with untagged ANY that is optional or follows an optional sequence element - you must fix this>\n");
2935 }
2936 else
2937 fprintf (src, " tag1 = BDecTag (b, seqBytesDecoded, env);\n");
2938 }
2939 else
2940 {
2941 fprintf (src, " if (seqBytesDecoded == elmtLen0)\n");
2942 fprintf (src, " {\n");
2943 fprintf (src, " bytesDecoded += seqBytesDecoded;\n");
2944 fprintf (src, " return;\n");
2945 fprintf (src, " }\n");
2946 fprintf (src, " else\n");
2947 fprintf (src, " {\n");
2948
2949 if ((tmpTypeId == BASICTYPE_ANY || tmpTypeId == BASICTYPE_ANYDEFINEDBY) && !CountTags (tmpElmt->type))
2950 {
2951 /* don't get a tag since ANY's decode their own */
2952 if (e->type->optional || (tmpElmt->type->optional && tmpElmt != (NamedType *)LAST_LIST_ELMT (seq->basicType->a.sequence)))
2953 {
2954 /*
2955 * let this cause a compile error in the generated code
2956 */
2957 fprintf (src, " <problems with untagged ANY that is optional or follows an optional sequence element - you must fix this>\n");
2958 }
2959 fprintf (src, " tag1 = b.PeekByte();\n\n");
2960 fprintf (src, " if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))\n");
2961 fprintf (src, " {\n");
2962 fprintf (src, " BDecEoc (b, seqBytesDecoded, env);\n\n");
2963 fprintf (src, " bytesDecoded += seqBytesDecoded;\n");
2964 fprintf (src, " return;\n");
2965 fprintf (src, " }\n");
2966
2967 }
2968 else
2969 {
2970 fprintf (src, " tag1 = BDecTag (b, seqBytesDecoded, env);\n\n");
2971 fprintf (src, " if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))\n");
2972 fprintf (src, " {\n");
2973 fprintf (src, " BDEC_2ND_EOC_OCTET (b, seqBytesDecoded, env)\n");
2974 fprintf (src, " bytesDecoded += seqBytesDecoded;\n");
2975 fprintf (src, " return;\n");
2976 fprintf (src, " }\n");
2977 }
2978 fprintf (src, " }\n");
2979
2980 }
2981 }
2982
2983
2984 /*
2985 * close tag check if (if there is one) and
2986 * print else clause to handle missing non-optional elmt
2987 * errors
2988 */
2989 tmpTypeId = GetBuiltinType (e->type);
2990 if ((tmpTypeId == BASICTYPE_ANYDEFINEDBY || tmpTypeId == BASICTYPE_ANY) && !CountTags (e->type))
2991 {
2992 /* do nothing - no tag check if stmt to close */
2993 fprintf (src, "\n\n");
2994 }
2995 else if (!e->type->optional && !e->type->defaultVal)
2996 {
2997 fprintf (src, " }\n"); /* end of tag check if */
2998 fprintf (src, " else\n");
2999 fprintf (src, " {\n");
3000 fprintf (src, " Asn1Error << \"ERROR - SEQUENCE is missing non-optional elmt.\" << endl;\n");
3001 #if SNACC_EXCEPTION_ENABLE
3002 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
3003 #else
3004 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
3005 #endif /* SNACC_EXCEPTION_ENABLE */
3006 fprintf (src, " }\n\n");
3007 }
3008 else
3009 fprintf (src, " }\n\n"); /* end of tag check if */
3010
3011 FreeTags (tags);
3012 }
3013
3014 /* for last elmt only */
3015 fprintf (src, " bytesDecoded += seqBytesDecoded;\n");
3016 fprintf (src, " if (elmtLen0 == INDEFINITE_LEN)\n");
3017 fprintf (src, " {\n");
3018 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
3019 fprintf (src, " return;\n");
3020 fprintf (src, " }\n");
3021 fprintf (src, " else if (seqBytesDecoded != elmtLen0)\n");
3022 fprintf (src, " {\n");
3023 fprintf (src, " Asn1Error << \"ERROR - Length discrepancy on sequence.\" << endl;\n");
3024 #if SNACC_EXCEPTION_ENABLE
3025 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
3026 #else
3027 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
3028 #endif /* SNACC_EXCEPTION_ENABLE */
3029 fprintf (src, " }\n");
3030 fprintf (src, " else\n");
3031 fprintf (src, " return;\n");
3032
3033 } /* end of non-empty set else clause */
3034
3035 fprintf (src, "} // %s::B%s\n\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName);
3036 }
3037 /* end of code for printing ber decode content method */
3038
3039 /* do BEnc function */
3040 if (printEncodersG)
3041 {
3042 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeBaseName, bufTypeNameG);
3043
3044 fprintf (src, "%s %s::B%s (%s b)\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeBaseName, bufTypeNameG);
3045 fprintf (src, "{\n");
3046 fprintf (src, " %s l;\n", lenTypeNameG);
3047 fprintf (src, " l = B%s (b);\n", r->encodeContentBaseName);
3048
3049 /* encode each tag/len pair if any */
3050 FOR_EACH_LIST_ELMT_RVS (tag, seq->tags)
3051 {
3052 classStr = Class2ClassStr (tag->tclass);
3053 formStr = Form2FormStr (CONS); /* seq's are constructed */
3054 tagLen = TagByteLen (tag->code);
3055
3056 fprintf (src, " l += BEncConsLen (b, l);\n");
3057
3058 if (tag->tclass == UNIV)
3059 fprintf (src, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen, classStr, formStr, Code2UnivCodeStr (tag->code));
3060 else
3061 fprintf (src, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen, classStr, formStr, tag->code);
3062 }
3063 fprintf (src, " return l;\n");
3064 fprintf (src, "}\n\n");
3065 }
3066 /* end of BEnc function */
3067
3068 /* Do BDec function */
3069 if (printDecodersG)
3070 {
3071 fprintf (hdr, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
3072
3073 fprintf (src, "void %s::B%s (%s b, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
3074 fprintf (src, "{\n");
3075 fprintf (src, " %s tag;\n", tagTypeNameG);
3076
3077 /* print extra locals for redundant lengths */
3078 for (i = 1; (seq->tags != NULL) && (i <= LIST_COUNT (seq->tags)); i++)
3079 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
3080 fprintf (src, "\n");
3081
3082 /* decode tag/length pair (s) */
3083 elmtLevel = 0;
3084 FOR_EACH_LIST_ELMT (tag, seq->tags)
3085 {
3086 classStr = Class2ClassStr (tag->tclass);
3087 formStr = Form2FormStr (CONS); /* seqs are constructed */
3088
3089 fprintf (src, " if ((tag = BDecTag (b, bytesDecoded, env)) != ");
3090
3091 if (tag->tclass == UNIV)
3092 fprintf (src, "MAKE_TAG_ID (%s, %s, %s))\n", classStr, formStr, Code2UnivCodeStr (tag->code));
3093 else
3094 fprintf (src, "MAKE_TAG_ID (%s, %s, %d))\n", classStr, formStr, tag->code);
3095 fprintf (src, " {\n");
3096 fprintf (src, " Asn1Error << \"%s::B%s: ERROR - wrong tag\" << endl;\n", td->cxxTypeDefInfo->className, r->decodeBaseName);
3097 #if SNACC_EXCEPTION_ENABLE
3098 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
3099 #else
3100 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
3101 #endif /* SNACC_EXCEPTION_ENABLE */
3102 fprintf (src, " }\n");
3103
3104 fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
3105 }
3106
3107 fprintf (src, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r->decodeContentBaseName, elmtLevel);
3108
3109 /* grab any EOCs that match redundant, indef lengths */
3110 for (i = elmtLevel-1; i > 0; i--)
3111 {
3112 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
3113 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
3114 }
3115
3116 fprintf (src, "}\n\n");
3117 }
3118 /* end of BDec function */
3119
3120 PrintPduMemberFcns (src, hdr, r, td->cxxTypeDefInfo->className);
3121
3122 /* write code for printing */
3123 if (printPrintersG)
3124 {
3125 fprintf (hdr, " void Print (ostream &os) const;\n");
3126
3127 fprintf (src, "void %s::Print (ostream &os) const\n", td->cxxTypeDefInfo->className);
3128 fprintf (src, "{\n");
3129 #ifdef __APPLE__
3130 fprintf (src, "#ifndef NDEBUG\n");
3131 #endif
3132 allOpt = AllElmtsOptional (seq->basicType->a.sequence);
3133 if (allOpt)
3134 fprintf (src, " int nonePrinted = true;\n");
3135 fprintf (src, " os << \"{ -- SEQUENCE --\" << endl;\n");
3136 fprintf (src, " indentG += stdIndentG;\n\n");
3137
3138 FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
3139 {
3140 inTailOptElmts = IsTailOptional (seq->basicType->a.sequence);
3141
3142 if (e->type->cxxTypeRefInfo->isPtr)
3143 fprintf (src, " if (%s (%s))\n", cxxtri->optTestRoutineName, e->type->cxxTypeRefInfo->fieldName);
3144
3145 fprintf (src, " {\n");
3146
3147 if (allOpt)
3148 {
3149 if (e != FIRST_LIST_ELMT (seq->basicType->a.sequence))
3150 {
3151 fprintf (src, " if (!nonePrinted)\n");
3152 fprintf (src, " os << \",\" << endl;\n");
3153 }
3154 fprintf (src, " nonePrinted = false;\n", i);
3155 }
3156 else if (inTailOptElmts) /* cannot be first elmt ow allOpt is true */
3157 fprintf (src, " os << \",\"<< endl;\n");
3158
3159 fprintf (src, " Indent (os, indentG);\n");
3160
3161 if (e->fieldName != NULL)
3162 fprintf (src, " os << \"%s \";\n", e->fieldName);
3163
3164 if (e->type->cxxTypeRefInfo->isPtr)
3165 fprintf (src, " os << *%s;\n", e->type->cxxTypeRefInfo->fieldName);
3166 else
3167 fprintf (src, " os << %s;\n", e->type->cxxTypeRefInfo->fieldName);
3168
3169 #ifdef KHO
3170 if (e != LAST_LIST_ELMT (seq->basicType->a.sequence)&&(!e->type->cxxTypeRefInfo->isPtr) )
3171 fprintf (src, " os << \",\" << endl;\n");
3172 #else
3173 if (e != LAST_LIST_ELMT (seq->basicType->a.sequence) && !inTailOptElmts && !NextIsTailOptional (seq->basicType->a.sequence))
3174 fprintf (src, " os << \",\" << endl;\n");
3175 #endif
3176
3177 fprintf (src, " }\n");
3178
3179 if (e->type->cxxTypeRefInfo->isPtr)
3180 {
3181 fprintf (src, " else\n");
3182 #ifdef KHO
3183 fprintf (src, " {\n");
3184 fprintf (src, " Indent (os, indentG);\n");
3185 if (e->fieldName != NULL)
3186 fprintf (src, " os << \"%s \";\n", e->fieldName);
3187 fprintf (src, " os << \"-- void --\";\n");
3188 if (e != LAST_LIST_ELMT (seq->basicType->a.sequence))
3189 fprintf (src, " os << \",\" << endl;\n");
3190 else
3191 fprintf (src, " os << endl;\n");
3192 fprintf (src, " }\n");
3193 #else
3194 fprintf (src, " os << \"-- void --\";\n");
3195 #endif
3196 }
3197
3198 fprintf (src, "\n");
3199
3200 if (e == LAST_LIST_ELMT (seq->basicType->a.sequence))
3201 fprintf (src, " os << endl;\n");
3202 }
3203
3204 fprintf (src, " indentG -= stdIndentG;\n");
3205 fprintf (src, " Indent (os, indentG);\n");
3206 fprintf (src, " os << \"}\";\n");
3207 #ifdef __APPLE__
3208 fprintf (src, "#endif /* NDEBUG */\n");
3209 #endif
3210 fprintf (src, "} // %s::Print\n\n\n", td->cxxTypeDefInfo->className);
3211 }
3212 /* end of print method code printer */
3213
3214 /* close class definition */
3215 fprintf (hdr, "};\n\n\n");
3216
3217 } /* PrintCxxSeqDefCode */
3218
3219
3220 static void
3221 PrintCxxSetDefCode PARAMS ((src, hdr, mods, m, r, td, parent, set, novolatilefuncs),
3222 FILE *src _AND_
3223 FILE *hdr _AND_
3224 ModuleList *mods _AND_
3225 Module *m _AND_
3226 CxxRules *r _AND_
3227 TypeDef *td _AND_
3228 Type *parent _AND_
3229 Type *set _AND_
3230 int novolatilefuncs)
3231 {
3232 NamedType *e;
3233 char *classStr;
3234 char *formStr;
3235 char *codeStr;
3236 int tagLen, i;
3237 Tag *tag;
3238 TagList *tags;
3239 char *varName;
3240 CxxTRI *cxxtri;
3241 int elmtLevel;
3242 int varCount, tmpVarCount;
3243 int stoleChoiceTags;
3244 int inTailOptElmts;
3245 int mandatoryElmtCount;
3246 enum BasicTypeChoiceId tmpTypeId;
3247 NamedType *defByNamedType;
3248 int allOpt;
3249
3250 /* put class spec in hdr file */
3251
3252 fprintf (hdr, "class %s%s\n", td->cxxTypeDefInfo->className, baseClassesG);
3253 fprintf (hdr, "{\n");
3254 fprintf (hdr, "public:\n");
3255
3256 /* write out the set elmts */
3257 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3258 {
3259 fprintf (hdr, " ");
3260 PrintCxxType (hdr, mods, m, r, td, set, e->type);
3261 fprintf (hdr, "%s;\n", e->type->cxxTypeRefInfo->fieldName);
3262 }
3263
3264 fprintf (hdr, "\n");
3265
3266 #if META
3267 if (printMetaG)
3268 {
3269 fprintf (hdr, "#if META\n");
3270 fprintf (src, "#if META\n\n");
3271
3272 fprintf (hdr, " static const AsnSetTypeDesc _desc;\n");
3273 fprintf (hdr, " static const AsnSetMemberDesc _mdescs[];\n");
3274 fprintf (hdr, " const AsnTypeDesc *_getdesc() const;\n");
3275 fprintf (hdr, " AsnType *_getref (const char *membername, bool create = false);\n\n");
3276
3277 fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);
3278 fprintf (src, "{\n");
3279 fprintf (src, " return new %s;\n", td->cxxTypeDefInfo->className);
3280 fprintf (src, "}\n\n");
3281
3282 fprintf (src, "const AsnSetMemberDesc %s::_mdescs[] =\n", td->cxxTypeDefInfo->className);
3283 fprintf (src, "{\n");
3284 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3285 if (printMetaG == META_backend_names)
3286 fprintf (src, " AsnSetMemberDesc (\"%s\", &%s::_desc, %s), // `%s'\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className, e->type->optional || e->type->defaultVal ? "true" : "false", e->fieldName ? e->fieldName : "");
3287 else /* META_asn1_names */
3288 fprintf (src, " AsnSetMemberDesc (\"%s\", &%s::_desc, %s), // `%s'\n", e->fieldName ? e->fieldName : e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className, e->type->optional || e->type->defaultVal ? "true" : "false", e->type->cxxTypeRefInfo->fieldName);
3289 fprintf (src, " AsnSetMemberDesc()\n");
3290 fprintf (src, "};\n\n");
3291
3292 fprintf (src, "const AsnSetTypeDesc %s::_desc\n", td->cxxTypeDefInfo->className);
3293 fprintf (src, "(\n");
3294 fprintf (src, " &%sModuleDesc,\n", m->cxxname);
3295 if (printMetaG == META_backend_names)
3296 fprintf (src, " \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);
3297 else /* META_asn1_names */
3298 fprintf (src, " \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);
3299 fprintf (src, " %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");
3300 fprintf (src, " AsnTypeDesc::SET,\n");
3301 fprintf (src, " create%s,\n", td->cxxTypeDefInfo->className);
3302 fprintf (src, " _mdescs\n");
3303 fprintf (src, ");\n\n");
3304
3305 fprintf (src, "const AsnTypeDesc *%s::_getdesc() const\n", td->cxxTypeDefInfo->className);
3306 fprintf (src, "{\n");
3307 fprintf (src, " return &_desc;\n");
3308 fprintf (src, "}\n\n");
3309
3310 fprintf (src, "AsnType *%s::_getref (const char *membername, bool create)\n", td->cxxTypeDefInfo->className);
3311 fprintf (src, "{\n");
3312 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3313 {
3314 fprintf (src, " if (!strcmp (membername, \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
3315 if (e->type->cxxTypeRefInfo->isPtr)
3316 {
3317 fprintf (src, " {\n");
3318 fprintf (src, " if (!%s && create)\n", e->type->cxxTypeRefInfo->fieldName);
3319 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
3320 fprintf (src, " return %s;\n", e->type->cxxTypeRefInfo->fieldName);
3321 fprintf (src, " }\n");
3322 }
3323 else
3324 fprintf (src, " return &%s;\n", e->type->cxxTypeRefInfo->fieldName);
3325 }
3326 fprintf (src, " return NULL;\n");
3327 fprintf (src, "}\n\n");
3328
3329 #if TCL
3330 if (printTclG)
3331 {
3332 fprintf (hdr, "#if TCL\n");
3333 fprintf (src, "#if TCL\n\n");
3334
3335 fprintf (hdr, " int TclGetDesc (Tcl_DString *) const;\n");
3336 fprintf (hdr, " int TclGetVal (Tcl_Interp *) const;\n");
3337 fprintf (hdr, " int TclSetVal (Tcl_Interp *, const char *valstr);\n");
3338 fprintf (hdr, " int TclUnsetVal (Tcl_Interp *, const char *membernames);\n\n");
3339
3340 fprintf (src, "int %s::TclGetDesc (Tcl_DString *valstr) const\n", td->cxxTypeDefInfo->className);
3341 fprintf (src, "{\n");
3342 fprintf (src, " Tcl_DStringStartSublist (valstr);\n\n");
3343 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3344 {
3345 fprintf (src, " Tcl_DStringStartSublist (valstr);\n");
3346 fprintf (src, " Tcl_DStringAppendElement (valstr, \"%s\");\n", e->type->cxxTypeRefInfo->fieldName);
3347 if (e->type->cxxTypeRefInfo->isPtr)
3348 fprintf (src, " Tcl_DStringAppendElement (valstr, %s ? \"valid\" : \"void\");\n", e->type->cxxTypeRefInfo->fieldName);
3349 else
3350 fprintf (src, " Tcl_DStringAppendElement (valstr, \"valid\");\n", e->type->cxxTypeRefInfo->fieldName);
3351 fprintf (src, " Tcl_DStringEndSublist (valstr);\n\n");
3352 }
3353 fprintf (src, " Tcl_DStringEndSublist (valstr);\n\n");
3354 fprintf (src, " return TCL_OK;\n");
3355 fprintf (src, "}\n\n");
3356
3357 fprintf (src, "int %s::TclGetVal (Tcl_Interp *interp) const\n", td->cxxTypeDefInfo->className);
3358 fprintf (src, "{\n");
3359 fprintf (src, " Tcl_DString valstr;\n\n");
3360 fprintf (src, " Tcl_DStringInit (&valstr);\n\n");
3361 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3362 {
3363 if (e->type->cxxTypeRefInfo->isPtr)
3364 {
3365 fprintf (src, " if (%s)\n", e->type->cxxTypeRefInfo->fieldName);
3366 fprintf (src, " {\n");
3367 fprintf (src, " Tcl_DStringStartSublist (&valstr);\n");
3368 fprintf (src, " Tcl_DStringAppendElement (&valstr, \"%s\");\n", e->type->cxxTypeRefInfo->fieldName);
3369 fprintf (src, " if (%s->TclGetVal (interp) != TCL_OK)\n", e->type->cxxTypeRefInfo->fieldName);
3370 fprintf (src, " goto Error;\n");
3371 fprintf (src, " Tcl_DStringAppendElement (&valstr, interp->result);\n");
3372 fprintf (src, " Tcl_ResetResult (interp);\n");
3373 fprintf (src, " Tcl_DStringEndSublist (&valstr);\n");
3374 fprintf (src, " }\n\n");
3375 }
3376 else
3377 {
3378 fprintf (src, " Tcl_DStringStartSublist (&valstr);\n");
3379 fprintf (src, " Tcl_DStringAppendElement (&valstr, \"%s\");\n", e->type->cxxTypeRefInfo->fieldName);
3380 fprintf (src, " if (%s.TclGetVal (interp) != TCL_OK)\n", e->type->cxxTypeRefInfo->fieldName);
3381 fprintf (src, " goto Error;\n");
3382 fprintf (src, " Tcl_DStringAppendElement (&valstr, interp->result);\n");
3383 fprintf (src, " Tcl_ResetResult (interp);\n");
3384 fprintf (src, " Tcl_DStringEndSublist (&valstr);\n\n");
3385 }
3386 }
3387 fprintf (src, " Tcl_DStringResult (interp, &valstr);\n");
3388 fprintf (src, " return TCL_OK;\n\n");
3389 fprintf (src, "Error:\n");
3390 fprintf (src, " Tcl_DStringFree (&valstr);\n");
3391 fprintf (src, " return TCL_ERROR;\n");
3392 fprintf (src, "}\n\n");
3393
3394 fprintf (src, "int %s::TclSetVal (Tcl_Interp *interp, const char *valstr)\n", td->cxxTypeDefInfo->className);
3395 fprintf (src, "{\n");
3396 fprintf (src, " int i;\n");
3397 fprintf (src, " Args elems;\n");
3398 fprintf (src, " if (Tcl_SplitList (interp, (char*)valstr, &elems.c, &elems.v) != TCL_OK)\n");
3399 fprintf (src, " return TCL_ERROR;\n");
3400 fprintf (src, " Args* elempairs = new Args[elems.c];\n");
3401 fprintf (src, " for (i=0; i<elems.c; i++)\n");
3402 fprintf (src, " {\n");
3403 fprintf (src, " if (Tcl_SplitList (interp, elems.v[i], &elempairs[i].c, &elempairs[i].v) != TCL_OK)\n");
3404 fprintf (src, " {\n");
3405 fprintf (src, " delete elempairs;\n");
3406 fprintf (src, " return TCL_ERROR;\n");
3407 fprintf (src, " }\n");
3408 fprintf (src, " if (elempairs[i].c != 2)\n");
3409 fprintf (src, " {\n");
3410 fprintf (src, " sprintf (interp->result, \"syntax error in element #%%d: expected a pair, but it's got %%d element(s)\", i, elempairs[i].c);\n");
3411 fprintf (src, " delete elempairs;\n");
3412 fprintf (src, " return TCL_ERROR;\n");
3413 fprintf (src, " }\n");
3414 fprintf (src, " }\n");
3415 fprintf (src, "\n");
3416 fprintf (src, " for (const AsnSetMemberDesc *m=_mdescs; m->name; m++)\n");
3417 fprintf (src, " {\n");
3418 fprintf (src, " int count = 0;\n");
3419 fprintf (src, " for (i=0; i<elems.c; i++)\n");
3420 fprintf (src, " if (!strcmp (elempairs[i].v[0], m->name))\n");
3421 fprintf (src, " count++;\n");
3422 fprintf (src, " if (count > 1)\n");
3423 fprintf (src, " {\n");
3424 fprintf (src, " sprintf (interp->result, \"duplicate value for member \\\"%%s\\\" in list\", m->name);\n");
3425 fprintf (src, " Tcl_SetErrorCode (interp, \"SNACC\", \"DUPMEMB\", NULL);\n");
3426 fprintf (src, " delete elempairs;\n");
3427 fprintf (src, " return TCL_ERROR;\n");
3428 fprintf (src, " }\n");
3429 fprintf (src, " if (!m->optional && count < 1)\n");
3430 fprintf (src, " {\n");
3431 fprintf (src, " sprintf (interp->result, \"mandatory member \\\"%%s\\\" is missing in list\", m->name);\n");
3432 fprintf (src, " Tcl_SetErrorCode (interp, \"SNACC\", \"MISSMAND\", NULL);\n");
3433 fprintf (src, " delete elempairs;\n");
3434 fprintf (src, " return TCL_ERROR;\n");
3435 fprintf (src, " }\n");
3436 fprintf (src, " \n");
3437 fprintf (src, " }\n");
3438 fprintf (src, "\n");
3439 fprintf (src, " for (i=0; i<elems.c; i++)\n");
3440 fprintf (src, " {\n");
3441 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3442 {
3443 fprintf (src, " if (!strcmp (elempairs[i].v[0], \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
3444 fprintf (src, " {\n");
3445 if (e->type->cxxTypeRefInfo->isPtr)
3446 {
3447 fprintf (src, " if (!%s)\n", e->type->cxxTypeRefInfo->fieldName);
3448 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
3449 fprintf (src, " if (%s->TclSetVal (interp, elempairs[i].v[1]))\n", e->type->cxxTypeRefInfo->fieldName);
3450 fprintf (src, " {\n");
3451 fprintf (src, " delete elempairs;\n");
3452 fprintf (src, " return TCL_ERROR;\n");
3453 fprintf (src, " }\n");
3454 }
3455 else
3456 {
3457 fprintf (src, " if (%s.TclSetVal (interp, elempairs[i].v[1]))\n", e->type->cxxTypeRefInfo->fieldName);
3458 fprintf (src, " {\n");
3459 fprintf (src, " return TCL_ERROR;\n");
3460 fprintf (src, " delete elempairs;\n");
3461 fprintf (src, " }\n");
3462 }
3463 fprintf (src, " }\n");
3464 }
3465 fprintf (src, " }\n");
3466 fprintf (src, "\n");
3467 fprintf (src, " // look for unmentioned optional members and delete them:\n");
3468 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3469 {
3470 if (e->type->optional || e->type->defaultVal)
3471 {
3472 fprintf (src, " {\n");
3473 fprintf (src, " bool present = false;\n");
3474 fprintf (src, " for (i=0; i<elems.c; i++)\n");
3475 fprintf (src, " if (!strcmp (elempairs[i].v[0], \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
3476 fprintf (src, " present = true;\n");
3477 fprintf (src, " if (!present)\n");
3478 fprintf (src, " {\n");
3479 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
3480 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
3481 fprintf (src, " }\n");
3482 fprintf (src, " }\n");
3483 }
3484 }
3485 fprintf (src, "\n");
3486 fprintf (src, " delete elempairs;\n");
3487 fprintf (src, " return TCL_OK;\n");
3488 fprintf (src, "}\n\n");
3489
3490 fprintf (src, "int %s::TclUnsetVal (Tcl_Interp *interp, const char *membernames)\n", td->cxxTypeDefInfo->className);
3491 fprintf (src, "{\n");
3492 fprintf (src, " Args elems;\n");
3493 fprintf (src, " if (Tcl_SplitList (interp, (char*)membernames, &elems.c, &elems.v) != TCL_OK)\n");
3494 fprintf (src, " return TCL_ERROR;\n");
3495 fprintf (src, "\n");
3496 fprintf (src, " for (int i=0; i<elems.c; i++)\n");
3497 fprintf (src, " {\n");
3498 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3499 {
3500 fprintf (src, " if (!strcmp (elems.v[i], \"%s\"))\n", e->type->cxxTypeRefInfo->fieldName);
3501 fprintf (src, " {\n");
3502 if (e->type->optional || e->type->defaultVal)
3503 {
3504 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
3505 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
3506 }
3507 else
3508 {
3509 fprintf (src, " return _desc.mandatmemberr (interp, elems.v[i]);\n");
3510 }
3511 fprintf (src, " }\n");
3512 }
3513 fprintf (src, " }\n");
3514 fprintf (src, " return TCL_OK;\n");
3515 fprintf (src, "}\n\n");
3516
3517 fprintf (hdr, "#endif // TCL\n");
3518 fprintf (src, "#endif // TCL\n\n");
3519 }
3520 #endif /* TCL */
3521
3522 fprintf (hdr, "#endif // META\n\n");
3523 fprintf (src, "#endif // META\n\n");
3524 }
3525 #endif /* META */
3526
3527 /* constructors and destructor: */
3528
3529 fprintf (hdr, " %s();\n", td->cxxTypeDefInfo->className);
3530
3531 fprintf (src, "%s::%s()\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3532 fprintf (src, "{\n");
3533 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3534 {
3535 if (e->type->cxxTypeRefInfo->isPtr)
3536 if (e->type->optional || e->type->defaultVal)
3537 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
3538 else
3539 {
3540 fprintf (src, "#if TCL\n");
3541 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
3542 fprintf (src, "#else\n");
3543 fprintf (src, " %s = NULL; // incomplete initialization of mandatory element!\n", e->type->cxxTypeRefInfo->fieldName);
3544 fprintf (src, "#endif // TCL\n");
3545 }
3546 }
3547 fprintf (src, "}\n\n");
3548
3549 fprintf (hdr, " %s (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3550
3551 fprintf (src, "%s::%s (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3552 fprintf (src, "{\n");
3553 fprintf (src, " Asn1Error << \"use of incompletely defined %s::%s (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3554 fprintf (src, " abort();\n");
3555 fprintf (src, "}\n\n");
3556
3557 fprintf (hdr, " virtual ~%s();\n", td->cxxTypeDefInfo->className);
3558
3559 fprintf (src, "%s::~%s()\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3560 fprintf (src, "{\n");
3561 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3562 if (e->type->cxxTypeRefInfo->isPtr)
3563 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
3564 fprintf (src, "}\n\n");
3565
3566 /* print clone routine for ANY mgmt */
3567 PrintCloneMethod (hdr, src, td);
3568
3569 fprintf (hdr, " %s &operator = (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3570
3571 fprintf (src, "#if SNACC_DEEP_COPY\n");
3572 fprintf (src, "%s &%s::operator = (const %s &that)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3573 fprintf (src, "#else // SNACC_DEEP_COPY\n");
3574 fprintf (src, "%s &%s::operator = (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3575 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
3576 fprintf (src, "{\n");
3577 fprintf (src, "#if SNACC_DEEP_COPY\n");
3578 fprintf (src, " if (this != &that)\n");
3579 fprintf (src, " {\n");
3580 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3581 {
3582 if (e->type->cxxTypeRefInfo->isPtr)
3583 {
3584 fprintf (src, " if (that.%s)\n", e->type->cxxTypeRefInfo->fieldName);
3585 fprintf (src, " {\n");
3586 fprintf (src, " if (!%s)\n", e->type->cxxTypeRefInfo->fieldName);
3587 fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className);
3588 fprintf (src, " *%s = *that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName);
3589 fprintf (src, " }\n");
3590 fprintf (src, " else\n");
3591 fprintf (src, " {\n");
3592 fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName);
3593 fprintf (src, " %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);
3594 fprintf (src, " }\n");
3595 }
3596 else
3597 fprintf (src, " %s = that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName);
3598 }
3599 fprintf (src, " }\n");
3600 fprintf (src, "\n");
3601 fprintf (src, " return *this;\n");
3602 fprintf (src, "#else // SNACC_DEEP_COPY\n");
3603 fprintf (src, " Asn1Error << \"use of incompletely defined %s &%s::operator = (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
3604 fprintf (src, " abort();\n");
3605 fprintf (src, " // if your compiler complains here, check the -novolat option\n");
3606 if (novolatilefuncs)
3607 {
3608 fprintf (src, " return *this;\n");
3609 }
3610 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
3611 fprintf (src, "}\n\n");
3612
3613 /* BerEncode */
3614 if (printEncodersG)
3615 {
3616 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeContentBaseName, bufTypeNameG);
3617
3618 fprintf (src, "%s %s::B%s (%s b)\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeContentBaseName, bufTypeNameG);
3619 fprintf (src, "{\n");
3620
3621 /* print local vars */
3622 fprintf (src, " %s totalLen = 0;\n", lenTypeNameG);
3623 fprintf (src, " %s l;\n\n", lenTypeNameG);
3624
3625 #ifdef VDADER_RULES
3626 {
3627 if (gVDADER_RULES)
3628 { int tmpCount=0;
3629 FOR_EACH_LIST_ELMT_RVS (e, set->basicType->a.set)
3630 tmpCount++;
3631 fprintf (src, " AsnBuf outputBuf;\n int iii=0, tmpCount=0;\n");
3632 fprintf (src, " char *lpszBuf = (char *)calloc(1, 1024);\n");
3633 fprintf (src, " outputBuf.Init(lpszBuf, 1024);\n");
3634 fprintf (src, " outputBuf.ResetInWriteRvsMode();\n");
3635
3636 fprintf (src, " CSM_Buffer *tmpEnc[%d];\n", tmpCount);
3637 /** allocate enough tmp CSM_Buffer(s) to sort SET.
3638 NOT ALL MAY BE filled, there may be OPTIONAL SET
3639 elements!! */
3640 }
3641 #endif
3642
3643 FOR_EACH_LIST_ELMT_RVS (e, set->basicType->a.set)
3644 {
3645 cxxtri = e->type->cxxTypeRefInfo;
3646
3647 varName = cxxtri->fieldName;
3648
3649 /* print optional test if nec*/
3650 if (e->type->optional || (e->type->defaultVal != NULL))
3651 {
3652 fprintf (src, " if (%s (%s))\n", cxxtri->optTestRoutineName, varName);
3653 fprintf (src, " {\n");
3654 }
3655
3656 /* encode Eoc (s) if nec */
3657 #ifdef VDADER_RULES
3658 if (gVDADER_RULES)
3659 PrintCxxEocEncoders (src, td, e->type, "outputBuf");
3660 else
3661 #endif
3662 PrintCxxEocEncoders (src, td, e->type, "b");
3663
3664 /* encode content */
3665 tmpTypeId = GetBuiltinType (e->type);
3666 if (tmpTypeId == BASICTYPE_ANYDEFINEDBY)
3667 {
3668 fprintf (src, " %s", varName);
3669 if (cxxtri->isPtr)
3670 fprintf (src, "->");
3671 else
3672 fprintf (src, ".");
3673
3674 defByNamedType = e->type->basicType->a.anyDefinedBy->link;
3675 if (GetBuiltinType (defByNamedType->type) == BASICTYPE_OID)
3676 {
3677 fprintf (src, "SetTypeByOid (");
3678 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
3679 fprintf (src, " *");
3680 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
3681 }
3682 else
3683 {
3684 fprintf (src, "SetTypeByInt (");
3685 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
3686 fprintf (src, " *");
3687 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
3688 }
3689
3690 fprintf (src, " l = %s", varName);
3691 if (cxxtri->isPtr)
3692 fprintf (src, "->");
3693 else
3694 fprintf (src, ".");
3695 #ifdef VDADER_RULES
3696 if (gVDADER_RULES)
3697 fprintf (src, "B%s (outputBuf);\n", r->encodeBaseName);
3698 else
3699 #endif
3700 fprintf (src, "B%s (b);\n", r->encodeBaseName);
3701 }
3702 else if (tmpTypeId == BASICTYPE_ANY)
3703 {
3704
3705 #ifdef VDADER_RULES
3706 if (! gVDADER_RULES)
3707 {
3708 #endif
3709 fprintf (src, " %s", varName);
3710 if (cxxtri->isPtr)
3711 fprintf (src, "->");
3712 else
3713 fprintf (src, ".");
3714 fprintf (src, "SetTypeBy???(???);\n");
3715
3716 fprintf (src, " l = %s", varName);
3717 if (cxxtri->isPtr)
3718 fprintf (src, "->");
3719 else
3720 fprintf (src, ".");
3721 fprintf (src, "B%s (b);\n", r->encodeBaseName);
3722
3723 #ifdef VDADER_RULES
3724 }
3725 else
3726 {
3727 fprintf (src, " ENC_LOAD_ANYBUF(");
3728 if (!cxxtri->isPtr)
3729 fprintf (src, "&");
3730 fprintf (src, "%s, outputBuf, l);\n", varName);
3731 }
3732 #endif
3733 }
3734 else
3735 {
3736 fprintf (src, " l = %s", varName);
3737 if (cxxtri->isPtr)
3738 fprintf (src, "->");
3739 else
3740 fprintf (src, ".");
3741
3742 #ifdef VDADER_RULES
3743 if (gVDADER_RULES)
3744 fprintf (src, "B%s (outputBuf);\n", r->encodeContentBaseName);
3745 else
3746 #endif
3747 fprintf (src, "B%s (b);\n", r->encodeContentBaseName);
3748 }
3749
3750 /* encode tag (s) & len (s) */
3751
3752 #ifdef VDADER_RULES
3753 if (gVDADER_RULES)
3754 PrintCxxTagAndLenEncodingCode (src, td, e->type, "l", "outputBuf");
3755 else
3756 #endif
3757 PrintCxxTagAndLenEncodingCode (src, td, e->type, "l", "b");
3758
3759 fprintf (src, " totalLen += l;\n");
3760
3761 #ifdef VDADER_RULES
3762 if (gVDADER_RULES) /** NOW, encode for SET DER rule ordering.*/
3763 { /** RWC; Buffers handle files or memory. **/
3764 fprintf (src, " SNACC_BUFRESET_READ(&outputBuf);\n");
3765 fprintf (src, " SM_ReadFromAsnBuf(tmpEnc[iii], outputBuf,outputBuf.DataLen(),NULL);\n");
3766 fprintf (src, " SNACC_BUFRESET_WRITE(&outputBuf);\n");
3767 fprintf (src, " iii++;\n");
3768 }
3769 #endif
3770
3771 /* close optional test if nec */
3772 if (e->type->optional || (e->type->defaultVal != NULL))
3773 fprintf (src, " }\n\n");
3774 else
3775 fprintf (src, "\n");
3776 }
3777 #ifdef VDADER_RULES
3778 if (gVDADER_RULES) /** LAST, Order for SET DER rule ordering.*/
3779 { /** re-order all elements, add to "b".*/
3780 fprintf (src, " vdasnacc_sortSet(tmpEnc, iii);\n");
3781 /** These "SET" components are now ordered in ascending order,
3782 ** ready to be loaded into the output buffer. (RWC; TBD; make output
3783 ** buffers accept these allocated buffers directly, no copy).
3784 **/
3785 fprintf (src, " tmpCount = iii; /** REMEMBER how many we have**/\n");
3786 fprintf (src, " for (iii=0; iii < tmpCount; iii++)\n");
3787 fprintf (src, " SM_WriteToAsnBuf(tmpEnc[iii], b);\n");
3788
3789 fprintf (src, " for (iii=0; iii < tmpCount; iii++) delete tmpEnc[iii];\n");
3790 fprintf (src, " free(lpszBuf);\n");
3791
3792 }
3793 } /** internal definition bracket for "tmpCount".**/
3794 #endif
3795 fprintf (src, " return totalLen;\n");
3796 fprintf (src, "} // %s::B%s\n\n\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName);
3797 }
3798 /* end of BerEncodeContent */
3799
3800 /* write BerDecodeContent */
3801 if (printDecodersG)
3802 {
3803 fprintf (hdr, " void B%s (%s b, %s tag, %s elmtLen, %s &bytesDecoded, %s env);\n\n", r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG);
3804
3805 fprintf (src, "void %s::B%s (%s b, %s /*tag0*/, %s elmtLen0, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG);
3806 fprintf (src, "{\n");
3807
3808 /* print local vars */
3809 fprintf (src, " %s tag1;\n", tagTypeNameG);
3810 fprintf (src, " %s setBytesDecoded = 0;\n", lenTypeNameG);
3811 fprintf (src, " unsigned int mandatoryElmtsDecoded = 0;\n");
3812 /* count max number of extra length var nec */
3813 varCount = 0;
3814 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3815 {
3816 tmpVarCount = CxxCountVariableLevels (e->type);
3817 if (tmpVarCount > varCount)
3818 varCount = tmpVarCount;
3819 }
3820 /* write extra length vars */
3821 for (i = 1; i <= varCount; i++)
3822 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
3823 fprintf (src, "\n");
3824
3825 /* handle empty set */
3826 if ((set->basicType->a.set == NULL) || LIST_EMPTY (set->basicType->a.set))
3827 {
3828 fprintf (src, " if (elmtLen0 == INDEFINITE_LEN)\n");
3829 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
3830 fprintf (src, " else if (elmtLen0 != 0)\n");
3831 fprintf (src, " {\n");
3832 fprintf (src, " Asn1Error << \"Expected an empty sequence\" << endl;\n");
3833 #if SNACC_EXCEPTION_ENABLE
3834 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
3835 #else
3836 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
3837 #endif /* SNACC_EXCEPTION_ENABLE */
3838 fprintf (src, " }\n");
3839
3840 /* forget about potential extension types for now
3841 fprintf (src, " if (elmtLen0 == INDEFINITE_LEN)\n");
3842 fprintf (src, " {\n");
3843 fprintf (src, " tag1 = BDecTag (b, bytesDecoded, env);\n\n");
3844 fprintf (src, " if (tag1 == EOC_TAG_ID)\n");
3845 fprintf (src, " BDEC_2ND_EOC_OCTET (b, bytesDecoded, env)\n");
3846 fprintf (src, " else\n");
3847 fprintf (src, " BerDiscardElmt (b, bytesDecoded, env);\n\n");
3848 fprintf (src, " }\n");
3849 fprintf (src, " else\n");
3850 fprintf (src, " {\n");
3851 fprintf (src, " BufSkip (b, elmtLen0);\n");
3852 fprintf (src, " bytesDecoded += elmtLen0;\n");
3853 fprintf (src, " }\n");
3854 */
3855 }
3856 else
3857 {
3858 fprintf (src, " for (; (setBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN); )\n");
3859 fprintf (src, " {\n");
3860 fprintf (src, " tag1 = BDecTag (b, setBytesDecoded, env);\n\n");
3861 fprintf (src, " if ((elmtLen0 == INDEFINITE_LEN) && (tag1 == EOC_TAG_ID))\n");
3862 fprintf (src, " {\n");
3863 fprintf (src, " BDEC_2ND_EOC_OCTET (b, setBytesDecoded, env)\n");
3864 fprintf (src, " break; /* exit for loop */\n");
3865 fprintf (src, " }\n");
3866
3867 fprintf (src, " elmtLen1 = BDecLen (b, setBytesDecoded, env);\n");
3868 fprintf (src, " switch (tag1)\n");
3869 fprintf (src, " {\n");
3870 mandatoryElmtCount = 0;
3871 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
3872 {
3873 cxxtri = e->type->cxxTypeRefInfo;
3874
3875 tags = GetTags (e->type, &stoleChoiceTags);
3876
3877 if (LIST_EMPTY (tags))
3878 {
3879 fprintf (src, " // ANY Type ?\n");
3880 fprintf (src, " case MAKE_TAG_ID (?, ?, ?):\n");
3881 }
3882 else
3883 {
3884 tag = (Tag*)FIRST_LIST_ELMT (tags);
3885 classStr = Class2ClassStr (tag->tclass);
3886 codeStr = Code2UnivCodeStr (tag->code);
3887 formStr = Form2FormStr (tag->form);
3888
3889 if (tag->tclass == UNIV)
3890 {
3891 if (tag->form == ANY_FORM)
3892 {
3893 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr);
3894 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr);
3895 }
3896 else
3897 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, formStr, codeStr);
3898 }
3899 else
3900 {
3901 if (tag->form == ANY_FORM)
3902 {
3903 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (PRIM), tag->code);
3904 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (CONS), tag->code);
3905 }
3906 else
3907 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, formStr, tag->code);
3908 }
3909
3910 /* now decode extra tags/length pairs */
3911 AsnListFirst (tags);
3912 AsnListNext (tags);
3913 elmtLevel = 1;
3914 if (stoleChoiceTags)
3915 {
3916 FOR_REST_LIST_ELMT (tag, tags)
3917 {
3918 classStr = Class2ClassStr (tag->tclass);
3919 codeStr = Code2UnivCodeStr (tag->code);
3920 formStr = Form2FormStr (tag->form);
3921
3922 if (tag->tclass == UNIV)
3923 {
3924 if (tag->form == ANY_FORM)
3925 {
3926 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr);
3927 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr);
3928 }
3929 else
3930 fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, formStr, codeStr);
3931 }
3932 else
3933 {
3934 if (tag->form == ANY_FORM)
3935 {
3936 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (PRIM), tag->code);
3937 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (CONS), tag->code);
3938 }
3939 else
3940 fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, formStr, tag->code);
3941 }
3942 }
3943 }
3944 else /* didn't steal nested choice's tags */
3945 {
3946 FOR_REST_LIST_ELMT (tag, tags)
3947 {
3948 classStr = Class2ClassStr (tag->tclass);
3949 codeStr = Code2UnivCodeStr (tag->code);
3950 formStr = Form2FormStr (tag->form);
3951
3952 fprintf (src, " tag1 = BDecTag (b, setBytesDecoded, env);\n");
3953 if (tag->form == ANY_FORM)
3954 {
3955 if (tag->tclass == UNIV)
3956 {
3957 fprintf (src, " if ((tag1 != MAKE_TAG_ID (%s, %s, %s))\n", classStr, Form2FormStr (PRIM), codeStr);
3958 fprintf (src, " && (tag1 != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), codeStr);
3959 }
3960 else
3961 {
3962 fprintf (src, " if ((tag1 != MAKE_TAG_ID (%s, %s, %d))\n", classStr, Form2FormStr (PRIM), tag->code);
3963 fprintf (src, " && (tag1 != MAKE_TAG_ID (%s, %s, %d)))\n", classStr, Form2FormStr (CONS), tag->code);
3964 }
3965
3966 }
3967 else
3968 {
3969 if (tag->tclass == UNIV)
3970 fprintf (src, " if (tag1 != MAKE_TAG_ID (%s, %s, %s))\n", classStr, formStr, codeStr);
3971 else
3972 fprintf (src, " if (tag1 != MAKE_TAG_ID (%s, %s, %d))\n", classStr, formStr, tag->code);
3973 }
3974
3975 fprintf (src, " {\n");
3976 fprintf (src, " Asn1Error << \"Unexpected Tag\" << endl;\n");
3977 #if SNACC_EXCEPTION_ENABLE
3978 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
3979 #else
3980 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
3981 #endif /* SNACC_EXCEPTION_ENABLE */
3982 fprintf (src, " }\n\n");
3983
3984 fprintf (src, " elmtLen%d = BDecLen (b, setBytesDecoded, env);\n", ++elmtLevel);
3985 }
3986 }
3987 }
3988 /*
3989 * if the choices element is another choice &&
3990 * we didn't steal its tags then we must grab
3991 * the key tag out of the contained CHOICE
3992 */
3993 if (!stoleChoiceTags && (GetBuiltinType (e->type) == BASICTYPE_CHOICE))
3994 {
3995 fprintf (src, " tag1 = BDecTag (b, setBytesDecoded, env);\n");
3996 fprintf (src, " elmtLen%d = BDecLen (b, setBytesDecoded, env);\n", ++elmtLevel);
3997 }
3998
3999 varName = cxxtri->fieldName;
4000
4001 /* decode content */
4002 if (cxxtri->isPtr)
4003 fprintf (src, " %s = new %s;\n", varName, cxxtri->className);
4004
4005 /* decode content */
4006 tmpTypeId = GetBuiltinType (e->type);
4007 if (tmpTypeId == BASICTYPE_ANYDEFINEDBY)
4008 {
4009 /*
4010 * must check for another EOC for ANYs
4011 * since the any decode routines decode
4012 * their own first tag/len pair
4013 */
4014 elmtLevel++;
4015
4016 fprintf (src, " %s", varName);
4017 if (cxxtri->isPtr)
4018 fprintf (src, "->");
4019 else
4020 fprintf (src, ".");
4021
4022 defByNamedType = e->type->basicType->a.anyDefinedBy->link;
4023 if (GetBuiltinType (defByNamedType->type) == BASICTYPE_OID)
4024 {
4025 fprintf (src, "SetTypeByOid (");
4026 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
4027 fprintf (src, " *");
4028 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
4029 }
4030 else
4031 {
4032 fprintf (src, "SetTypeByInt (");
4033 if (defByNamedType->type->cxxTypeRefInfo->isPtr)
4034 fprintf (src, " *");
4035 fprintf (src, "%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName);
4036 }
4037
4038 fprintf (src, " %s", varName);
4039 if (cxxtri->isPtr)
4040 fprintf (src, "->");
4041 else
4042 fprintf (src, ".");
4043 fprintf (src, "B%s (b, setBytesDecoded, env);\n", r->decodeBaseName);
4044 }
4045 else if (tmpTypeId == BASICTYPE_ANY)
4046 {
4047 /*
4048 * must check for another EOC for ANYs
4049 * since the any decode routines decode
4050 * their own first tag/len pair
4051 */
4052 elmtLevel++;
4053
4054 #ifdef VDADER_RULES
4055 if (!gVDADER_RULES)
4056 {
4057 #endif
4058 fprintf (src, " %s", varName);
4059 if (cxxtri->isPtr)
4060 fprintf (src, "->");
4061 else
4062 fprintf (src, ".");
4063 fprintf (src, "SetTypeBy???(???);\n");
4064
4065 fprintf (src, " %s", varName);
4066 if (cxxtri->isPtr)
4067 fprintf (src, "->");
4068 else
4069 fprintf (src, ".");
4070 fprintf (src, "B%s (b, setBytesDecoded, env);\n", r->decodeBaseName);
4071
4072 #ifdef VDADER_RULES
4073 }
4074 else
4075 {
4076 fprintf (src, " DEC_LOAD_ANYBUF(");
4077 if (!cxxtri->isPtr)
4078 fprintf (src, "&");
4079 fprintf (src, "%s, b, setBytesDecoded, env);\n", varName);
4080 }
4081 #endif
4082 }
4083 else
4084 {
4085 fprintf (src, " %s", varName);
4086 if (cxxtri->isPtr)
4087 fprintf (src, "->");
4088 else
4089 fprintf (src, ".");
4090
4091 fprintf (src, "B%s (b, tag1, elmtLen%d, setBytesDecoded, env);\n", r->decodeContentBaseName, elmtLevel);
4092 }
4093
4094 /* decode Eoc (s) */
4095 for (i = elmtLevel-1; i >= 1; i--)
4096 {
4097 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
4098 fprintf (src, " BDecEoc (b, setBytesDecoded, env);\n\n");
4099 }
4100
4101 /* keep track of decoded non-optional elmts */
4102 if (!e->type->optional && (e->type->defaultVal == NULL))
4103 {
4104 mandatoryElmtCount++;
4105 fprintf (src, " mandatoryElmtsDecoded++;\n");
4106 }
4107 fprintf (src, " break;\n\n");
4108
4109 FreeTags (tags);
4110 } /* for each elmt */
4111 fprintf (src, " default:\n");
4112 fprintf (src, " Asn1Error << \"Unexpected Tag on SET elmt.\" << endl;\n");
4113 #if SNACC_EXCEPTION_ENABLE
4114 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
4115 #else
4116 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
4117 #endif /* SNACC_EXCEPTION_ENABLE */
4118 fprintf (src, " } // end switch\n");
4119 fprintf (src, " } // end for loop\n");
4120 fprintf (src, " bytesDecoded += setBytesDecoded;\n");
4121 fprintf (src, " if (mandatoryElmtsDecoded != %d)\n", mandatoryElmtCount);
4122 fprintf (src, " {\n");
4123 fprintf (src, " Asn1Error << \"ERROR - non-optional SET element missing.\" << endl;\n");
4124 #if SNACC_EXCEPTION_ENABLE
4125 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
4126 #else
4127 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
4128 #endif /* SNACC_EXCEPTION_ENABLE */
4129 fprintf (src, " }\n");
4130
4131 } /* if not empty set clause */
4132
4133 fprintf (src, "} // %s::B%s\n\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName);
4134 }
4135 /* end of decode content method code */
4136
4137 /* BerEncode */
4138 if (printEncodersG)
4139 {
4140 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeBaseName, bufTypeNameG);
4141
4142 fprintf (src, "%s\n", lenTypeNameG);
4143 fprintf (src, "%s::B%s (%s b)\n", td->cxxTypeDefInfo->className, r->encodeBaseName, bufTypeNameG);
4144 fprintf (src, "{\n");
4145 fprintf (src, " %s l;\n", lenTypeNameG);
4146 fprintf (src, " l = B%s (b);\n", r->encodeContentBaseName);
4147
4148 /* encode each tag/len pair if any */
4149 FOR_EACH_LIST_ELMT_RVS (tag, set->tags)
4150 {
4151 classStr = Class2ClassStr (tag->tclass);
4152 formStr = Form2FormStr (CONS); /* set's are constructed */
4153 tagLen = TagByteLen (tag->code);
4154
4155 fprintf (src, " l += BEncConsLen (b, l);\n");
4156
4157 if (tag->tclass == UNIV)
4158 fprintf (src, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen, classStr, formStr, Code2UnivCodeStr (tag->code));
4159 else
4160 fprintf (src, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen, classStr, formStr, tag->code);
4161 }
4162 fprintf (src, " return l;\n");
4163 fprintf (src, "}\n\n");
4164 }
4165 /* end of BerEncode */
4166
4167 /* BerDecode */
4168 if (printDecodersG)
4169 {
4170 fprintf (hdr, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
4171
4172 fprintf (src, "void %s::B%s (%s b, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
4173 fprintf (src, "{\n");
4174 fprintf (src, " %s tag;\n", tagTypeNameG);
4175
4176 /* print extra locals for redundant lengths */
4177 for (i = 1; (set->tags != NULL) && (i <= LIST_COUNT (set->tags)); i++)
4178 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
4179 fprintf (src, "\n");
4180
4181 /* decode tag/length pair (s) */
4182 elmtLevel = 0;
4183 FOR_EACH_LIST_ELMT (tag, set->tags)
4184 {
4185 classStr = Class2ClassStr (tag->tclass);
4186 formStr = Form2FormStr (CONS); /* sets are constructed */
4187
4188 fprintf (src, " if ((tag = BDecTag (b, bytesDecoded, env)) != ");
4189
4190 if (tag->tclass == UNIV)
4191 fprintf (src, "MAKE_TAG_ID (%s, %s, %s))\n", classStr, formStr, Code2UnivCodeStr (tag->code));
4192 else
4193 fprintf (src, "MAKE_TAG_ID (%s, %s, %d))\n", classStr, formStr, tag->code);
4194 fprintf (src, " {\n");
4195 fprintf (src, " Asn1Error << \"%s::B%s: ERROR - wrong tag\" << endl;\n", td->cxxTypeDefInfo->className, r->decodeBaseName);
4196 #if SNACC_EXCEPTION_ENABLE
4197 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
4198 #else
4199 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
4200 #endif /* SNACC_EXCEPTION_ENABLE */
4201 fprintf (src, " }\n");
4202
4203 fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
4204 }
4205
4206 fprintf (src, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r->decodeContentBaseName, i-1);
4207
4208 /* grab any EOCs that match redundant, indef lengths */
4209 for (i = elmtLevel-1; i > 0; i--)
4210 {
4211 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
4212 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
4213 }
4214
4215 fprintf (src, "}\n\n");
4216 }
4217 /* end of BerDecode */
4218
4219 PrintPduMemberFcns (src, hdr, r, td->cxxTypeDefInfo->className);
4220
4221 /* write code for printing */
4222 if (printPrintersG)
4223 {
4224 fprintf (hdr, " void Print (ostream &os) const;\n");
4225
4226 fprintf (src, "void %s::Print (ostream &os) const\n", td->cxxTypeDefInfo->className);
4227 fprintf (src, "{\n");
4228 #ifdef __APPLE__
4229 fprintf (src, "#ifndef NDEBUG\n");
4230 #endif
4231 allOpt = AllElmtsOptional (set->basicType->a.set);
4232 if (allOpt)
4233 fprintf (src, " int nonePrinted = true;\n");
4234
4235 fprintf (src, " os << \"{ -- SET --\" << endl;\n");
4236 fprintf (src, " indentG += stdIndentG;\n\n");
4237
4238 FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
4239 {
4240 inTailOptElmts = IsTailOptional (set->basicType->a.set);
4241
4242 if (e->type->cxxTypeRefInfo->isPtr)
4243 fprintf (src, " if (%s (%s))\n", cxxtri->optTestRoutineName, e->type->cxxTypeRefInfo->fieldName);
4244
4245 fprintf (src, " {\n");
4246
4247 if (allOpt)
4248 {
4249 if (e != FIRST_LIST_ELMT (set->basicType->a.set))
4250 {
4251 fprintf (src, " if (!nonePrinted)\n");
4252 fprintf (src, " os << \",\" << endl;\n");
4253 }
4254 fprintf (src, " nonePrinted = false;\n", i);
4255 }
4256 else if (inTailOptElmts) /* cannot be first elmt ow allOpt is true */
4257 fprintf (src, " os << \",\"<< endl;\n");
4258
4259 fprintf (src, " Indent (os, indentG);\n");
4260
4261 if (e->fieldName != NULL)
4262 fprintf (src, " os << \"%s \";\n", e->fieldName);
4263
4264 if (e->type->cxxTypeRefInfo->isPtr)
4265 fprintf (src, " os << *%s;\n", e->type->cxxTypeRefInfo->fieldName);
4266 else
4267 fprintf (src, " os << %s;\n", e->type->cxxTypeRefInfo->fieldName);
4268
4269 if (e != LAST_LIST_ELMT (set->basicType->a.set) && !inTailOptElmts && !NextIsTailOptional (set->basicType->a.set))
4270 fprintf (src, " os << \",\" << endl;\n");
4271
4272 fprintf (src, " }\n");
4273
4274 if (e->type->cxxTypeRefInfo->isPtr)
4275 {
4276 fprintf (src, " else\n");
4277 #ifdef KHO
4278 fprintf (src, " os << \"-- void2 --\\n\";\n");
4279 #else
4280 fprintf (src, " os << \"-- void --\";\n");
4281 #endif
4282 }
4283
4284 fprintf (src, "\n");
4285
4286 if (e == LAST_LIST_ELMT (set->basicType->a.set))
4287 fprintf (src, " os << endl;\n");
4288 }
4289 fprintf (src, " indentG -= stdIndentG;\n");
4290 fprintf (src, " Indent (os, indentG);\n");
4291 fprintf (src, " os << \"}\";\n");
4292 #ifdef __APPLE__
4293 fprintf (src, "#endif /* NDEBUG */\n");
4294 #endif __APPLE__
4295 fprintf (src, "} // %s - operator <<\n\n\n", td->cxxTypeDefInfo->className);
4296 }
4297 /* end of print method code */
4298
4299 /* close class definition */
4300 fprintf (hdr, "};\n\n\n");
4301
4302 } /* PrintCxxSetDefCode */
4303
4304
4305 /*
4306 * This major Bogosity results from gcc2.2.2 inability to handle
4307 * template properly
4308 */
4309 static void
4310 PrintCxxListClass PARAMS ((src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, parent, lst),
4311 FILE *src _AND_
4312 FILE *hdr _AND_
4313 if_IBM_ENC (FILE *srcdb _AND_)
4314 if_IBM_ENC (FILE *hdrdb _AND_)
4315 ModuleList *mods _AND_
4316 Module *m _AND_
4317 CxxRules *r _AND_
4318 TypeDef *td _AND_
4319 Type *parent _AND_
4320 Type *lst)
4321 {
4322 char *lcn; /* list class name */
4323 char *ecn; /* (list) elmt class name */
4324 char *classStr;
4325 char *formStr;
4326 int tagLen;
4327 Tag *tag;
4328 int i, elmtLevel;
4329
4330 lcn = td->cxxTypeDefInfo->className;
4331 ecn = lst->basicType->a.setOf->cxxTypeRefInfo->className;
4332
4333 #ifdef _IBM_ENC_
4334 #include "./ibm_editor/print_cxx_list_class.h"
4335 #endif /* _IBM_ENC_ */
4336
4337 fprintf (hdr, "class %s%s\n", lcn, baseClassesG);
4338 fprintf (hdr, "{\n");
4339 fprintf (hdr, "protected:\n");
4340
4341 fprintf (hdr, " unsigned long int count;\n");
4342 fprintf (hdr, " struct AsnListElmt\n");
4343 fprintf (hdr, " {\n");
4344 fprintf (hdr, " AsnListElmt *next;\n");
4345 fprintf (hdr, " AsnListElmt *prev;\n");
4346 #ifdef _IBM_ENC_
4347 fprintf (hdr, " void *operator new (size_t t) { return mem_mgr_ptr->Get (t); } // Guido Grassel 12.8.93\n");
4348 fprintf (hdr, " void operator delete (void *p) { mem_mgr_ptr->Put (p); } // Guido Grassel 12.8.93\n");
4349 #endif /* _IBM_ENC_ */
4350 fprintf (hdr, " %s *elmt;\n", ecn);
4351 fprintf (hdr, " } *first, *curr, *last;\n\n");
4352
4353 fprintf (hdr, "public:\n");
4354
4355 #if META
4356 if (printMetaG)
4357 {
4358 const char *emtn = "?";
4359 switch (lst->basicType->choiceId)
4360 {
4361 case BASICTYPE_SEQUENCEOF:
4362 emtn = "SEQUENCE_OF";
4363 break;
4364 case BASICTYPE_SETOF:
4365 emtn = "SET_OF";
4366 break;
4367 }
4368
4369 fprintf (hdr, "#if META\n");
4370 fprintf (src, "#if META\n\n");
4371
4372 fprintf (hdr, " static const AsnListTypeDesc _desc;\n");
4373 fprintf (hdr, " const AsnTypeDesc *_getdesc() const;\n");
4374 fprintf (hdr, " AsnType *_getref (const char *index, bool create = false);\n\n");
4375
4376 fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);
4377 fprintf (src, "{\n");
4378 fprintf (src, " return new %s;\n", td->cxxTypeDefInfo->className);
4379 fprintf (src, "}\n\n");
4380
4381 fprintf (src, "const AsnListTypeDesc %s::_desc\n", td->cxxTypeDefInfo->className);
4382 fprintf (src, "(\n");
4383 fprintf (src, " &%sModuleDesc,\n", m->cxxname);
4384 if (printMetaG == META_backend_names)
4385 fprintf (src, " \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);
4386 else /* META_asn1_names */
4387 fprintf (src, " \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);
4388 fprintf (src, " %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");
4389 fprintf (src, " AsnTypeDesc::%s,\n", emtn);
4390 fprintf (src, " create%s,\n", td->cxxTypeDefInfo->className);
4391 fprintf (src, " &%s::_desc\n", ecn);
4392 fprintf (src, ");\n\n");
4393
4394 fprintf (src, "const AsnTypeDesc *%s::_getdesc() const\n", td->cxxTypeDefInfo->className);
4395 fprintf (src, "{\n");
4396 fprintf (src, " return &_desc;\n");
4397 fprintf (src, "}\n\n");
4398
4399 fprintf (src, "AsnType *%s::_getref (const char *strindex, bool create)\n", td->cxxTypeDefInfo->className);
4400 fprintf (src, "{\n");
4401 fprintf (src, " bool insert;\n");
4402 fprintf (src, " unsigned long index;\n");
4403 fprintf (src, " char c;\n");
4404 fprintf (src, " if (sscanf (strindex, \"insert %%lu%%c\", &index, &c) == 1)\n");
4405 fprintf (src, " {\n");
4406 fprintf (src, " insert = true;\n");
4407 fprintf (src, " }\n");
4408 fprintf (src, " else if (sscanf (strindex, \"%%lu%%c\", &index, &c) == 1)\n");
4409 fprintf (src, " {\n");
4410 fprintf (src, " insert = false;\n");
4411 fprintf (src, " }\n");
4412 fprintf (src, " else\n");
4413 fprintf (src, " return NULL;\n");
4414 fprintf (src, " if (insert && index == Count())\n");
4415 fprintf (src, " return Append();\n");
4416 fprintf (src, " if (index >= Count())\n");
4417 fprintf (src, " return NULL;\n");
4418 fprintf (src, " SetCurrElmt (index);\n");
4419 fprintf (src, " return insert ? InsertBefore() : Curr();\n");
4420 fprintf (src, "}\n\n");
4421
4422 #if TCL
4423 if (printTclG)
4424 {
4425 fprintf (hdr, "#if TCL\n");
4426 fprintf (src, "#if TCL\n\n");
4427
4428 fprintf (hdr, " int TclGetDesc (Tcl_DString *) const;\n");
4429 fprintf (hdr, " int TclGetVal (Tcl_Interp *) const;\n");
4430 fprintf (hdr, " int TclSetVal (Tcl_Interp *, const char *valstr);\n");
4431 fprintf (hdr, " int TclUnsetVal (Tcl_Interp *, const char *indexstr);\n");
4432
4433 fprintf (src, "int %s::TclGetDesc (Tcl_DString *valstr) const\n", td->cxxTypeDefInfo->className);
4434 fprintf (src, "{\n");
4435 fprintf (src, " char countstr[80];\n");
4436 fprintf (src, " sprintf (countstr, \"%%lu\", count);\n");
4437 fprintf (src, " Tcl_DStringAppendElement (valstr, countstr);\n");
4438 fprintf (src, " return TCL_OK;\n");
4439 fprintf (src, " return _desc.base->AsnTypeDesc::TclGetDesc (valstr);\n");
4440 fprintf (src, "}\n\n");
4441
4442 fprintf (src, "int %s::TclGetVal (Tcl_Interp *interp) const\n", td->cxxTypeDefInfo->className);
4443 fprintf (src, "{\n");
4444 fprintf (src, " Tcl_DString valstr;\n");
4445 fprintf (src, " Tcl_DStringInit (&valstr);\n");
4446 fprintf (src, " //for (SetCurrToFirst(); Curr(); GoNext())\n");
4447 fprintf (src, " for (const AsnListElmt *run=first; run; run=run->next)\n");
4448 fprintf (src, " {\n");
4449 fprintf (src, " if (run->elmt->TclGetVal (interp) != TCL_OK)\n");
4450 fprintf (src, " {\n");
4451 fprintf (src, " Tcl_DStringFree (&valstr);\n");
4452 fprintf (src, " return TCL_ERROR;\n");
4453 fprintf (src, " }\n");
4454 fprintf (src, " Tcl_DStringAppendElement (&valstr, interp->result);\n");
4455 fprintf (src, " }\n");
4456 fprintf (src, " Tcl_ResetResult (interp);\n");
4457 fprintf (src, " Tcl_DStringResult (interp, &valstr);\n");
4458 fprintf (src, " return TCL_OK;\n");
4459 fprintf (src, "}\n\n");
4460
4461 fprintf (src, "int %s::TclSetVal (Tcl_Interp *interp, const char *valstr)\n", td->cxxTypeDefInfo->className);
4462 fprintf (src, "{\n");
4463 fprintf (src, " Args elem;\n");
4464 fprintf (src, " if (Tcl_SplitList (interp, (char*)valstr, &elem.c, &elem.v) != TCL_OK)\n");
4465 fprintf (src, " return TCL_ERROR;\n");
4466 fprintf (src, "\n");
4467 fprintf (src, " while (First())\n");
4468 fprintf (src, " RemoveCurrFromList();\n");
4469 fprintf (src, "\n");
4470 fprintf (src, " for (int i=0; i<elem.c; i++)\n");
4471 fprintf (src, " {\n");
4472 fprintf (src, " if (Append()->TclSetVal (interp, elem.v[i]) != TCL_OK)\n");
4473 fprintf (src, " return TCL_ERROR;\n");
4474 fprintf (src, " }\n");
4475 fprintf (src, " return TCL_OK;\n");
4476 fprintf (src, "}\n\n");
4477
4478 fprintf (src, "int %s::TclUnsetVal (Tcl_Interp *interp, const char *indexstr)\n", td->cxxTypeDefInfo->className);
4479 fprintf (src, "{\n");
4480 fprintf (src, " int index;\n");
4481 fprintf (src, " if (Tcl_GetInt (interp, (char*)indexstr, &index) != TCL_OK)\n");
4482 fprintf (src, " return TCL_ERROR;\n");
4483 fprintf (src, " if (index >= Count())\n");
4484 fprintf (src, " {\n");
4485 fprintf (src, " sprintf (interp->result, \"error: list: index %%d out of range (0-%%d)\", index, Count()-1);\n");
4486 fprintf (src, " return NULL;\n");
4487 fprintf (src, " }\n");
4488 fprintf (src, " SetCurrElmt (index);\n");
4489 fprintf (src, " RemoveCurrFromList();\n");
4490 fprintf (src, " return TCL_OK;\n");
4491 fprintf (src, "}\n\n");
4492
4493 fprintf (hdr, "#endif // TCL\n");
4494 fprintf (src, "#endif // TCL\n\n");
4495 }
4496 #endif /* TCL */
4497
4498 fprintf (hdr, "#endif // META\n\n");
4499 fprintf (src, "#endif // META\n\n");
4500 }
4501 #endif /* META */
4502
4503
4504 fprintf (hdr, " %s() { count = 0; first = curr = last = NULL; }\n", lcn);
4505
4506 fprintf (hdr, " %s (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4507
4508 fprintf (hdr, " virtual ~%s();\n", td->cxxTypeDefInfo->className);
4509
4510 /* print clone routine for ANY mgmt */
4511 PrintCloneMethod (hdr, src, td);
4512
4513 fprintf (hdr, " %s &operator = (const %s &);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4514
4515 fprintf (hdr, " void SetCurrElmt (unsigned long int index);\n");
4516 fprintf (hdr, " unsigned long int GetCurrElmtIndex();\n");
4517 fprintf (hdr, " void SetCurrToFirst() { curr = first; }\n");
4518 fprintf (hdr, " void SetCurrToLast() { curr = last; }\n");
4519
4520 fprintf (hdr, " // reading member fcns\n");
4521 fprintf (hdr, " int Count() const { return count; }\n");
4522 fprintf (hdr, " // NOTE: if your compiler complains about these NULLs, its definition of NULL is broken (and you better change it there!)\n");
4523 fprintf (hdr, " %s *First() const { return count > 0 ? first->elmt : NULL; }\n", ecn);
4524 fprintf (hdr, " %s *Last() const { return count > 0 ? last->elmt : NULL; }\n", ecn);
4525 fprintf (hdr, " %s *Curr() const { return curr ? curr->elmt : NULL; }\n", ecn);
4526 fprintf (hdr, " %s *Next() const { return curr && curr->next ? curr->next->elmt : NULL; }\n", ecn);
4527 fprintf (hdr, " %s *Prev() const { return curr && curr->prev ? curr->prev->elmt : NULL; }\n\n", ecn);
4528
4529 fprintf (hdr, " // routines that move the curr elmt\n");
4530 fprintf (hdr, " %s *GoNext() { if (curr) curr = curr->next; return Curr(); }\n", ecn);
4531 fprintf (hdr, " %s *GoPrev() { if (curr) curr = curr->prev; return Curr(); }\n\n", ecn);
4532
4533 fprintf (hdr, " // write & alloc fcns - returns new elmt\n");
4534 fprintf (hdr, " %s *Append(); // add elmt to end of list\n", ecn);
4535 fprintf (hdr, " %s *Prepend(); // add elmt to beginning of list\n", ecn);
4536 fprintf (hdr, " %s *InsertBefore(); //insert elmt before current elmt\n", ecn);
4537 fprintf (hdr, " %s *InsertAfter(); //insert elmt after current elmt\n\n", ecn);
4538
4539 fprintf (hdr, " // write & alloc & copy - returns list after copying elmt\n");
4540 fprintf (hdr, " %s &AppendCopy (%s &elmt); // add elmt to end of list\n", lcn, ecn);
4541 fprintf (hdr, " %s &PrependCopy (%s &elmt); // add elmt to beginning of list\n", lcn, ecn);
4542 fprintf (hdr, " %s &InsertBeforeAndCopy (%s &elmt); //insert elmt before current elmt\n", lcn, ecn);
4543 fprintf (hdr, " %s &InsertAfterAndCopy (%s &elmt); //insert elmt after current elmt\n\n", lcn, ecn);
4544
4545 fprintf (hdr, " // removing the current elmt from the list\n");
4546 fprintf (hdr, " void RemoveCurrFromList();\n\n");
4547
4548 fprintf (hdr, " // encode and decode routines \n");
4549
4550 /* print PDU oriented encode routine */
4551 if (printEncodersG)
4552 {
4553 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeBaseName, bufTypeNameG);
4554
4555 fprintf (src, "%s %s::B%s (%s b)\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeBaseName, bufTypeNameG);
4556 fprintf (src, "{\n");
4557 fprintf (src, " %s l;\n", lenTypeNameG);
4558
4559 /* encode the list content */
4560 fprintf (src, " l = B%s (b);\n", r->encodeContentBaseName);
4561
4562 /* encode each tag/len pair if any */
4563 FOR_EACH_LIST_ELMT_RVS (tag, lst->tags)
4564 {
4565 classStr = Class2ClassStr (tag->tclass);
4566 formStr = Form2FormStr (CONS); /* choices are constructed */
4567 tagLen = TagByteLen (tag->code);
4568
4569 /* always constructed lengths for list */
4570 fprintf (src, " l += BEncConsLen (b, l);\n");
4571
4572 if (tag->tclass == UNIV)
4573 fprintf (src, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen, classStr, formStr, Code2UnivCodeStr (tag->code));
4574 else
4575 fprintf (src, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen, classStr, formStr, tag->code);
4576 }
4577 fprintf (src, " return l;\n");
4578 fprintf (src, "}\n\n");
4579 }
4580 /* end of ber encode function */
4581
4582 /* do BerDecode function */
4583 if (printDecodersG)
4584 {
4585 fprintf (hdr, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
4586
4587 fprintf (src, "void %s::B%s (%s b, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);
4588 fprintf (src, "{\n");
4589 fprintf (src, " %s tag;\n", tagTypeNameG);
4590
4591 /* print extra locals for redundant lengths */
4592 for (i = 1; (lst->tags != NULL) && (i <= LIST_COUNT (lst->tags)); i++)
4593 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
4594 fprintf (src, "\n");
4595
4596 /* decode tag/length pair (s) */
4597 elmtLevel = 0;
4598 FOR_EACH_LIST_ELMT (tag, lst->tags)
4599 {
4600 classStr = Class2ClassStr (tag->tclass);
4601 formStr = Form2FormStr (CONS); /* lists are constructed */
4602
4603 fprintf (src, " if ((tag = BDecTag (b, bytesDecoded, env)) != ");
4604
4605 if (tag->tclass == UNIV)
4606 fprintf (src, "MAKE_TAG_ID (%s, %s, %s))\n", classStr, formStr, Code2UnivCodeStr (tag->code));
4607 else
4608 fprintf (src, "MAKE_TAG_ID (%s, %s, %d))\n", classStr, formStr, tag->code);
4609 fprintf (src, " {\n");
4610 fprintf (src, " Asn1Error << \"%s::B%s: ERROR - wrong tag\" << endl;\n", td->cxxTypeDefInfo->className, r->decodeBaseName);
4611 #if SNACC_EXCEPTION_ENABLE
4612 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
4613 #else
4614 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
4615 #endif /* SNACC_EXCEPTION_ENABLE */
4616 fprintf (src, " }\n");
4617
4618 fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);
4619 }
4620
4621 fprintf (src, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r->decodeContentBaseName, elmtLevel);
4622
4623 /* grab any EOCs that match redundant, indef lengths */
4624 for (i = elmtLevel-1; i > 0; i--)
4625 {
4626 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
4627 fprintf (src, " BDecEoc (b, bytesDecoded, env);\n");
4628 }
4629
4630 fprintf (src, "}\n\n");
4631 }
4632 /* end of BDec function */
4633
4634
4635 if (printEncodersG)
4636 fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeContentBaseName, bufTypeNameG);
4637
4638 if (printDecodersG)
4639 fprintf (hdr, " void B%s (%s b, %s tag, %s elmtLen, %s &bytesDecoded, %s env);\n\n", r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG);
4640
4641 fprintf (hdr, " PDU_MEMBER_MACROS\n");
4642
4643 if (printPrintersG) {
4644 fprintf (hdr, " void Print (ostream &os) const;\n");
4645 }
4646 fprintf (hdr, "};\n\n\n");
4647
4648 } /* PrintCxxListClass */
4649
4650
4651 /*
4652 * Prints code to decode and check tags and lengths for a
4653 * SEQ OF/SET OF element.
4654 *
4655 * as usual, assumes:
4656 * b for buf var name
4657 * elmtLen for elmts len var name
4658 * env for environment var name
4659 * listBytesDecoded for the runing total bytes decoded
4660 * tag1 for tag
4661 *
4662 * Assumes first tag has been decoded and is in 'tag1' var
4663 */
4664 static void
4665 PrintCxxListTagAndLenDecCode PARAMS ((src, td, t),
4666 FILE *src _AND_
4667 TypeDef *td _AND_
4668 Type *t)
4669 {
4670 TagList *tags;
4671 Tag *tag;
4672 int elmtLevel;
4673 int stoleChoiceTags;
4674
4675 elmtLevel = 0;
4676
4677 tags = GetTags (t, &stoleChoiceTags);
4678 if (stoleChoiceTags)
4679 {
4680 fprintf (src, " if (!(");
4681 FOR_EACH_LIST_ELMT (tag, tags)
4682 {
4683 fprintf (src, "(tag1 == ");
4684 PrintMakeTag (src, tag);
4685 if (tag->form == ANY_FORM)
4686 {
4687 fprintf (src, ")\n || (tag1 == ");
4688 tag->form = CONS;
4689 PrintMakeTag (src, tag);
4690 fprintf (src, ")\n");
4691 }
4692 else
4693 fprintf (src, ")");
4694
4695 if (tag != (Tag *)LAST_LIST_ELMT (tags))
4696 fprintf (src, "\n || ");
4697 }
4698 fprintf (src, "))\n");
4699 fprintf (src, " {\n");
4700 fprintf (src, " Asn1Error << \"Unexpected Tag\" << endl;\n");
4701 #if SNACC_EXCEPTION_ENABLE
4702 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
4703 #else
4704 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
4705 #endif /* SNACC_EXCEPTION_ENABLE */
4706 fprintf (src, " }\n\n");
4707 fprintf (src, " elmtLen%d = BDecLen (b, listBytesDecoded, env);\n", ++elmtLevel);
4708 }
4709
4710 else /* didn't steal nested choice's tags */
4711 {
4712 AsnListFirst (tags);
4713
4714 FOR_EACH_LIST_ELMT (tag, tags)
4715 {
4716
4717 fprintf (src, " if ((tag1 != ");
4718 PrintMakeTag (src, tag);
4719 if (tag->form == ANY_FORM)
4720 {
4721 fprintf (src, ")\n && (tag1 != ");
4722 tag->form = CONS;
4723 PrintMakeTag (src, tag);
4724 fprintf (src, "))\n");
4725 }
4726 else
4727 fprintf (src, "))\n");
4728
4729 fprintf (src, " {\n");
4730 fprintf (src, " Asn1Error << \"Unexpected Tag\" << endl;\n");
4731 #if SNACC_EXCEPTION_ENABLE
4732 fprintf (src, " SnaccExcep::throwMe(%d);\n", longJmpValG--);
4733 #else
4734 fprintf (src, " longjmp (env, %d);\n", longJmpValG--);
4735 #endif /* SNACC_EXCEPTION_ENABLE */
4736 fprintf (src, " }\n\n");
4737 fprintf (src, " elmtLen%d = BDecLen (b, listBytesDecoded, env);\n", ++elmtLevel);
4738
4739 if (tag != (Tag*)LAST_LIST_ELMT (tags))
4740 fprintf (src, " tag1 = BDecTag (b, listBytesDecoded, env);\n\n");
4741
4742 }
4743
4744 /*
4745 * if this seq element is CHOICE &&
4746 * we didn't steal its tags then we must grab
4747 * the key tag out of the contained CHOICE
4748 */
4749 if (GetBuiltinType (t) == BASICTYPE_CHOICE)
4750 {
4751 fprintf (src, " tag1 = BDecTag (b, listBytesDecoded, env);\n");
4752 fprintf (src, " elmtLen%d = BDecLen (b, listBytesDecoded, env);\n", ++elmtLevel);
4753 }
4754 }
4755 FreeTags (tags);
4756 } /* PrintCxxListTagAndLenDecCode */
4757
4758 /*
4759 * This major Bogosity results from gcc2.2.2 inability to handle
4760 * templates properly
4761 */
4762 static void
4763 PrintCxxListMethods PARAMS ((src, hdr, mods, m, r, td, parent, lst, novolatilefuncs),
4764 FILE *src _AND_
4765 FILE *hdr _AND_
4766 ModuleList *mods _AND_
4767 Module *m _AND_
4768 CxxRules *r _AND_
4769 TypeDef *td _AND_
4770 Type *parent _AND_
4771 Type *lst _AND_
4772 int novolatilefuncs)
4773 {
4774 char *lcn; /* list class name */
4775 char *ecn; /* (list) elmt class name */
4776 int elmtLevel;
4777 int i;
4778 enum BasicTypeChoiceId tmpTypeId;
4779 Tag *tag;
4780 char *classStr;
4781 char *formStr;
4782 int tagLen;
4783
4784 lcn = td->cxxTypeDefInfo->className;
4785 ecn = lst->basicType->a.setOf->cxxTypeRefInfo->className;
4786
4787 fprintf (src, "%s::%s (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4788 fprintf (src, "{\n");
4789 fprintf (src, " Asn1Error << \"use of incompletely defined %s::%s (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4790 fprintf (src, " abort();\n");
4791 fprintf (src, "}\n\n");
4792
4793 fprintf (src, "%s::~%s()\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4794 fprintf (src, "{\n");
4795 fprintf (src, " SetCurrToFirst();\n");
4796 fprintf (src, " for (; Curr() != NULL; RemoveCurrFromList())\n");
4797 fprintf (src, " ;\n");
4798 fprintf (src, "} // end of destructor\n\n");
4799
4800 fprintf (src, "#if SNACC_DEEP_COPY\n");
4801 fprintf (src, "%s &%s::operator = (const %s &that)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4802 fprintf (src, "#else // SNACC_DEEP_COPY\n");
4803 fprintf (src, "%s &%s::operator = (const %s &)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4804 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
4805 fprintf (src, "{\n");
4806 fprintf (src, "#if SNACC_DEEP_COPY\n");
4807 fprintf (src, " if (this != &that)\n");
4808 fprintf (src, " {\n");
4809 fprintf (src, " SetCurrToFirst();\n");
4810 fprintf (src, " for (; Curr(); RemoveCurrFromList())\n");
4811 fprintf (src, " ;\n");
4812 fprintf (src, "\n");
4813 fprintf (src, " //that.SetCurrToFirst();\n");
4814 fprintf (src, " //for (; that.Curr(); that.GoNext())\n");
4815 fprintf (src, " // AppendCopy (*that.Curr());\n");
4816 fprintf (src, " for (const AsnListElmt *run=that.first; run; run=run->next)\n");
4817 fprintf (src, " AppendCopy (*run->elmt);\n");
4818 fprintf (src, " }\n");
4819 fprintf (src, "\n");
4820 fprintf (src, " return *this;\n");
4821 fprintf (src, "#else // SNACC_DEEP_COPY\n");
4822 fprintf (src, " Asn1Error << \"use of incompletely defined %s &%s::operator = (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);
4823 fprintf (src, " abort();\n");
4824 fprintf (src, " // if your compiler complains here, check the -novolat option\n");
4825 if (novolatilefuncs)
4826 {
4827 fprintf (src, " return *this;\n");
4828 }
4829 fprintf (src, "#endif // SNACC_DEEP_COPY\n");
4830 fprintf (src, "}\n\n");
4831
4832 if (printPrintersG)
4833 {
4834 fprintf (src, "void %s::Print (ostream &os) const\n", td->cxxTypeDefInfo->className);
4835 fprintf (src, "{\n");
4836 #ifdef __APPLE__
4837 fprintf (src, "#ifndef NDEBUG\n");
4838 #endif
4839 fprintf (src, " os << \"{ -- SEQUENCE/SET OF -- \" << endl;\n");
4840 fprintf (src, " indentG += stdIndentG;\n");
4841
4842 fprintf (src, " //SetCurrToFirst();\n");
4843 fprintf (src, " //for (; Curr() != NULL; GoNext())\n");
4844 fprintf (src, " for (const AsnListElmt *run=first; run; run=run->next)\n");
4845 fprintf (src, " {\n");
4846 fprintf (src, " Indent (os, indentG);\n");
4847 fprintf (src, " //os << *Curr();\n");
4848 fprintf (src, " os << *run->elmt;\n");
4849 fprintf (src, " //if (Curr() != Last())\n");
4850 fprintf (src, " if (run != last)\n");
4851 fprintf (src, " os << \",\";\n");
4852 fprintf (src, " os << endl;\n");
4853 fprintf (src, " }\n");
4854
4855 fprintf (src, " indentG -= stdIndentG;\n");
4856 fprintf (src, " Indent (os, indentG);\n");
4857 #ifdef KHO
4858 fprintf (src, " os << \"}\\n\";\n");
4859 #else
4860 fprintf (src, " os << \"}\";\n");
4861 #endif
4862
4863 #ifdef __APPLE__
4864 fprintf (src, "#endif /* NDEBUG */\n\n\n");
4865 #endif
4866 fprintf (src, "} // Print\n\n\n");
4867 }
4868
4869 fprintf (src, "void %s::SetCurrElmt (unsigned long int index)\n", lcn);
4870 fprintf (src, "{\n");
4871 fprintf (src, " unsigned long int i;\n");
4872 fprintf (src, " curr = first;\n");
4873 fprintf (src, " if (count)\n");
4874 fprintf (src, " for (i = 0; (i < (count-1)) && (i < index); i++)\n");
4875 fprintf (src, " curr = curr->next;\n");
4876 fprintf (src, "} // %s::SetCurrElmt\n\n\n", lcn);
4877
4878
4879 fprintf (src, "unsigned long int %s::GetCurrElmtIndex()\n", lcn);
4880 fprintf (src, "{\n");
4881 fprintf (src, " unsigned long int i;\n");
4882 fprintf (src, " AsnListElmt *tmp;\n");
4883 fprintf (src, " if (curr != NULL)\n");
4884 fprintf (src, " {\n");
4885 fprintf (src, " for (i = 0, tmp = first; tmp != NULL; i++)\n");
4886 fprintf (src, " {\n");
4887 fprintf (src, " if (tmp == curr)\n");
4888 fprintf (src, " return i;\n");
4889 fprintf (src, " else\n");
4890 fprintf (src, " tmp = tmp->next;\n");
4891 fprintf (src, " }\n");
4892 fprintf (src, " }\n");
4893 fprintf (src, " return count;\n");
4894 fprintf (src, "} // %s::GetCurrElmtIndex\n\n\n", lcn);
4895
4896
4897 fprintf (src, "// alloc new list elmt, put at end of list\n");
4898 fprintf (src, "// and return the component type\n");
4899 fprintf (src, "%s *%s::Append()\n", ecn, lcn);
4900 fprintf (src, "{\n");
4901 fprintf (src, " AsnListElmt *newElmt;\n");
4902 fprintf (src, " newElmt = new AsnListElmt;\n");
4903 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
4904 fprintf (src, " newElmt->next = NULL;\n");
4905 fprintf (src, " if (last == NULL)\n");
4906 fprintf (src, " {\n");
4907 fprintf (src, " newElmt->prev = NULL;\n");
4908 fprintf (src, " first = last = newElmt;\n");
4909 fprintf (src, " }\n");
4910 fprintf (src, " else\n");
4911 fprintf (src, " {\n");
4912 fprintf (src, " newElmt->prev = last;\n");
4913 fprintf (src, " last->next = newElmt;\n");
4914 fprintf (src, " last = newElmt;\n");
4915 fprintf (src, " }\n");
4916 fprintf (src, " count++;\n");
4917 fprintf (src, " return (curr = newElmt)->elmt;\n");
4918 fprintf (src, "} // %s::Append\n\n\n", lcn);
4919
4920
4921 fprintf (src, "// alloc new list elmt, put at begining of list\n");
4922 fprintf (src, "// and return the component type\n");
4923 fprintf (src, "%s *%s::Prepend()\n", ecn, lcn);
4924 fprintf (src, "{\n");
4925 fprintf (src, " AsnListElmt *newElmt;\n");
4926 fprintf (src, " newElmt = new AsnListElmt;\n");
4927 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
4928 fprintf (src, " newElmt->prev = NULL;\n");
4929 fprintf (src, " if (first == NULL)\n");
4930 fprintf (src, " {\n");
4931 fprintf (src, " newElmt->next = NULL;\n");
4932 fprintf (src, " first = last = newElmt;\n");
4933 fprintf (src, " }\n");
4934 fprintf (src, " else\n");
4935 fprintf (src, " {\n");
4936 fprintf (src, " newElmt->next = first;\n");
4937 fprintf (src, " first->prev = newElmt;\n");
4938 fprintf (src, " first = newElmt;\n");
4939 fprintf (src, " }\n");
4940 fprintf (src, " count++;\n");
4941 fprintf (src, " return (curr = newElmt)->elmt;\n");
4942 fprintf (src, "} // %s::Prepend\n\n\n", lcn);
4943
4944
4945 fprintf (src, "// alloc new list elmt, insert it before the\n");
4946 fprintf (src, "// current element and return the component type\n");
4947 fprintf (src, "// if the current element is null, the new element\n");
4948 fprintf (src, "// is placed at the beginning of the list.\n");
4949 fprintf (src, "%s *%s::InsertBefore()\n", ecn, lcn);
4950 fprintf (src, "{\n");
4951 fprintf (src, " AsnListElmt *newElmt;\n");
4952 fprintf (src, " newElmt = new AsnListElmt;\n");
4953 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
4954 fprintf (src, " if (curr == NULL)\n");
4955 fprintf (src, " {\n");
4956 fprintf (src, " newElmt->next = first;\n");
4957 fprintf (src, " newElmt->prev = NULL;\n");
4958 fprintf (src, " first = newElmt;\n");
4959 fprintf (src, " if (last == NULL)\n");
4960 fprintf (src, " last = newElmt;\n");
4961 fprintf (src, " }\n");
4962 fprintf (src, " else\n");
4963 fprintf (src, " {\n");
4964 fprintf (src, " newElmt->next = curr;\n");
4965 fprintf (src, " newElmt->prev = curr->prev;\n");
4966 fprintf (src, " curr->prev = newElmt;\n");
4967 fprintf (src, " if (curr == first)\n");
4968 fprintf (src, " first = newElmt;\n");
4969 fprintf (src, " else\n");
4970 fprintf (src, " newElmt->prev->next = newElmt;\n");
4971 fprintf (src, " }\n");
4972 fprintf (src, " count++;\n");
4973 fprintf (src, " return (curr = newElmt)->elmt;\n");
4974 fprintf (src, "} // %s::InsertBefore\n\n\n", lcn);
4975
4976
4977 fprintf (src, "// alloc new list elmt, insert it after the\n");
4978 fprintf (src, "// current element and return the component type\n");
4979 fprintf (src, "// if the current element is null, the new element\n");
4980 fprintf (src, "// is placed at the end of the list.\n");
4981 fprintf (src, "%s *%s::InsertAfter()\n", ecn, lcn);
4982 fprintf (src, "{\n");
4983 fprintf (src, " AsnListElmt *newElmt;\n");
4984 fprintf (src, " newElmt = new AsnListElmt;\n");
4985 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
4986 fprintf (src, " if (curr == NULL)\n");
4987 fprintf (src, " {\n");
4988 fprintf (src, " newElmt->prev = last;\n");
4989 fprintf (src, " newElmt->next = NULL;\n");
4990 fprintf (src, " last = newElmt;\n");
4991 fprintf (src, " if (first == NULL)\n");
4992 fprintf (src, " first = newElmt;\n");
4993 fprintf (src, " }\n");
4994 fprintf (src, " else\n");
4995 fprintf (src, " {\n");
4996 fprintf (src, " newElmt->prev = curr;\n");
4997 fprintf (src, " newElmt->next = curr->next;\n");
4998 fprintf (src, " curr->next = newElmt;\n");
4999 fprintf (src, " if (curr == last)\n");
5000 fprintf (src, " last = newElmt;\n");
5001 fprintf (src, " else\n");
5002 fprintf (src, " newElmt->next->prev = newElmt;\n");
5003 fprintf (src, " }\n");
5004 fprintf (src, " count++;\n");
5005 fprintf (src, " return (curr = newElmt)->elmt;\n");
5006 fprintf (src, "} // %s::InsertAfter\n\n\n", lcn);
5007
5008
5009 fprintf (src, "%s &%s::AppendCopy (%s &elmt)\n", lcn, lcn, ecn);
5010 fprintf (src, "{\n");
5011 fprintf (src, " AsnListElmt *newElmt;\n");
5012 fprintf (src, " newElmt = new AsnListElmt;\n");
5013 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
5014 fprintf (src, " *newElmt->elmt = elmt;\n");
5015 fprintf (src, " newElmt->next = NULL;\n");
5016 fprintf (src, " if (last == NULL)\n");
5017 fprintf (src, " {\n");
5018 fprintf (src, " newElmt->prev = NULL;\n");
5019 fprintf (src, " first = last = newElmt;\n");
5020 fprintf (src, " }\n");
5021 fprintf (src, " else\n");
5022 fprintf (src, " {\n");
5023 fprintf (src, " newElmt->prev = last;\n");
5024 fprintf (src, " last->next = newElmt;\n");
5025 fprintf (src, " last = newElmt;\n");
5026 fprintf (src, " }\n");
5027 fprintf (src, " count++;\n");
5028 fprintf (src, " return *this;\n");
5029 fprintf (src, "} // AppendCopy\n\n\n");
5030
5031
5032 fprintf (src, "%s &%s::PrependCopy (%s &elmt)\n", lcn, lcn, ecn);
5033 fprintf (src, "{\n");
5034 fprintf (src, " AsnListElmt *newElmt;\n");
5035 fprintf (src, " newElmt = new AsnListElmt;\n");
5036 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
5037 fprintf (src, " *newElmt->elmt = elmt;\n");
5038 fprintf (src, " newElmt->prev = NULL;\n");
5039 fprintf (src, " if (first == NULL)\n");
5040 fprintf (src, " {\n");
5041 fprintf (src, " newElmt->next = NULL;\n");
5042 fprintf (src, " first = last = newElmt;\n");
5043 fprintf (src, " }\n");
5044 fprintf (src, " else\n");
5045 fprintf (src, " {\n");
5046 fprintf (src, " newElmt->next = first;\n");
5047 fprintf (src, " first->prev = newElmt;\n");
5048 fprintf (src, " first = newElmt;\n");
5049 fprintf (src, " }\n");
5050 fprintf (src, " count++;\n");
5051 fprintf (src, " return *this;\n");
5052 fprintf (src, "} // %s::PrependCopy\n\n\n", lcn);
5053
5054
5055 fprintf (src, "// alloc new list elmt, insert it before the\n");
5056 fprintf (src, "// current element, copy the given elmt into the new elmt\n");
5057 fprintf (src, "// and return the component type.\n");
5058 fprintf (src, "// if the current element is null, the new element\n");
5059 fprintf (src, "// is placed at the beginning of the list.\n");
5060 fprintf (src, "%s &%s::InsertBeforeAndCopy (%s &elmt)\n", lcn, lcn, ecn);
5061 fprintf (src, "{\n");
5062 fprintf (src, " AsnListElmt *newElmt;\n");
5063 fprintf (src, "\n");
5064 fprintf (src, " newElmt = new AsnListElmt;\n");
5065 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
5066 fprintf (src, " *newElmt->elmt = elmt;\n");
5067 fprintf (src, "\n");
5068 fprintf (src, " if (curr == NULL)\n");
5069 fprintf (src, " {\n");
5070 fprintf (src, " newElmt->next = first;\n");
5071 fprintf (src, " newElmt->prev = NULL;\n");
5072 fprintf (src, " first = newElmt;\n");
5073 fprintf (src, " if (last == NULL)\n");
5074 fprintf (src, " last = newElmt;\n");
5075 fprintf (src, " }\n");
5076 fprintf (src, " else\n");
5077 fprintf (src, " {\n");
5078 fprintf (src, " newElmt->next = curr;\n");
5079 fprintf (src, " newElmt->prev = curr->prev;\n");
5080 fprintf (src, " curr->prev = newElmt;\n");
5081 fprintf (src, " if (curr == first)\n");
5082 fprintf (src, " first = newElmt;\n");
5083 fprintf (src, " else\n");
5084 fprintf (src, " newElmt->prev->next = newElmt;\n");
5085 fprintf (src, " }\n");
5086 fprintf (src, " count++;\n");
5087 fprintf (src, " return *this;\n");
5088 fprintf (src, "} // %s::InsertBeforeAndCopy\n\n\n", lcn);
5089
5090
5091 fprintf (src, "// alloc new list elmt, insert it after the\n");
5092 fprintf (src, "// current element, copy given elmt in to new elmt\n");
5093 fprintf (src, "// and return the component type\n");
5094 fprintf (src, "// if the current element is null, the new element\n");
5095 fprintf (src, "// is placed at the end of the list.\n");
5096 fprintf (src, "%s &%s::InsertAfterAndCopy (%s &elmt)\n", lcn, lcn, ecn);
5097 fprintf (src, "{\n");
5098 fprintf (src, " AsnListElmt *newElmt;\n");
5099 fprintf (src, "\n");
5100 fprintf (src, " newElmt = new AsnListElmt;\n");
5101 fprintf (src, " newElmt->elmt = new %s;\n", ecn);
5102 fprintf (src, " *newElmt->elmt = elmt;\n");
5103 fprintf (src, " if (curr == NULL)\n");
5104 fprintf (src, " {\n");
5105 fprintf (src, " newElmt->prev = last;\n");
5106 fprintf (src, " newElmt->next = NULL;\n");
5107 fprintf (src, " last = newElmt;\n");
5108 fprintf (src, " if (first == NULL)\n");
5109 fprintf (src, " first = newElmt;\n");
5110 fprintf (src, " }\n");
5111 fprintf (src, " else\n");
5112 fprintf (src, " {\n");
5113 fprintf (src, " newElmt->prev = curr;\n");
5114 fprintf (src, " newElmt->next = curr->next;\n");
5115 fprintf (src, " curr->next = newElmt;\n");
5116 fprintf (src, " if (curr == last)\n");
5117 fprintf (src, " last = newElmt;\n");
5118 fprintf (src, " else\n");
5119 fprintf (src, " newElmt->next->prev = newElmt;\n");
5120 fprintf (src, " }\n");
5121 fprintf (src, " count++;\n");
5122 fprintf (src, " return *this;\n");
5123 fprintf (src, "} // %s::InsertAfterAndCopy\n\n\n", lcn);
5124
5125
5126 fprintf (src, "// remove current element from list if current element is not NULL \n");
5127 fprintf (src, "// The new current element will be the next element.\n");
5128 fprintf (src, "// If the current element is the last element in the list\n");
5129 fprintf (src, "// the second but last element will become the new current element.\n");
5130 fprintf (src, "void %s::RemoveCurrFromList()\n", lcn);
5131 fprintf (src, "{\n");
5132 fprintf (src, " AsnListElmt *del_elmt;\n");
5133 fprintf (src, "\n");
5134 fprintf (src, " if (curr != NULL)\n");
5135 fprintf (src, " {\n");
5136 fprintf (src, " del_elmt = curr;\n");
5137 fprintf (src, " count--;\n");
5138 fprintf (src, "\n");
5139 fprintf (src, " if (count == 0)\n");
5140 fprintf (src, " first = last = curr = NULL;\n");
5141 fprintf (src, " else if (curr == first)\n");
5142 fprintf (src, " {\n");
5143 fprintf (src, " curr = first= first->next;\n");
5144 fprintf (src, " first->prev = NULL;\n");
5145 fprintf (src, " }\n");
5146 fprintf (src, " else if (curr == last)\n");
5147 fprintf (src, " {\n");
5148 fprintf (src, " curr = last = last->prev;\n");
5149 fprintf (src, " last->next = NULL;\n");
5150 fprintf (src, " }\n");
5151 fprintf (src, " else\n");
5152 fprintf (src, " {\n");
5153 fprintf (src, " curr->prev->next = curr->next;\n");
5154 fprintf (src, " curr->next->prev = curr->prev;\n");
5155 fprintf (src, " }\n");
5156 fprintf (src, "\n");
5157 fprintf (src, " delete del_elmt->elmt;\n");
5158 fprintf (src, " delete del_elmt;\n");
5159 fprintf (src, " }\n");
5160 fprintf (src, "}\n\n\n");
5161
5162 if (printEncodersG)
5163 {
5164 fprintf (src, "%s %s::B%s (%s b)\n", lenTypeNameG, lcn, r->encodeContentBaseName, bufTypeNameG);
5165 fprintf (src, "{\n");
5166 fprintf (src, " AsnListElmt *currElmt;\n");
5167 fprintf (src, " %s elmtLen;\n", lenTypeNameG);
5168 fprintf (src, " %s totalLen = 0;\n", lenTypeNameG);
5169
5170 #ifdef VDADER_RULES
5171 if (gVDADER_RULES && lst->basicType->choiceId != BASICTYPE_SETOF)
5172 {
5173 #endif
5174 fprintf (src, " for (currElmt = last; currElmt != NULL; currElmt = currElmt->prev)\n");
5175 fprintf (src, " {\n");
5176 /* encode Eoc (s) if nec */
5177 PrintCxxEocEncoders (src, td, lst->basicType->a.setOf, "b");
5178
5179 tmpTypeId = GetBuiltinType (lst->basicType->a.setOf);
5180 /* list element types cannot by ANY DEFINED BY */
5181 if (tmpTypeId == BASICTYPE_ANY)
5182 {
5183 fprintf (src, " currElmt->elmt->SetTypeBy???(???);\n");
5184 fprintf (src, " elmtLen = currElmt->elmt->B%s (b);\n", r->encodeBaseName);
5185 }
5186 else
5187 {
5188 fprintf (src, " elmtLen = currElmt->elmt->B%s (b);\n", r->encodeContentBaseName);
5189 }
5190
5191 /* encode list elmt tag/len pairs here */
5192 PrintCxxTagAndLenEncodingCode (src, td, lst->basicType->a.setOf, "elmtLen", "b");
5193
5194 fprintf (src, " totalLen += elmtLen;\n");
5195 fprintf (src, " }\n");
5196
5197 #ifdef VDADER_RULES
5198 }
5199 /** handling of SET OF encoding
5200 **/
5201 else if (gVDADER_RULES && lst->basicType->choiceId == BASICTYPE_SETOF)
5202 VDA_ProcessSetOf(src, td, lst, r);
5203 #endif
5204
5205 fprintf (src, " return totalLen;\n");
5206 fprintf (src, "} // %s::B%s\n\n\n", lcn, r->encodeContentBaseName);
5207 } /** END IF for printDecodersG **/
5208
5209 if (printDecodersG)
5210 {
5211 fprintf (src, "void %s::B%s (%s b, %s /*tag0*/, %s elmtLen0,\n", lcn, r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG);
5212 fprintf (src, " %s &bytesDecoded, %s env)\n", lenTypeNameG, envTypeNameG);
5213 fprintf (src, "{\n");
5214 fprintf (src, " %s *listElmt;\n", ecn);
5215
5216 #ifdef VDADER_RULES
5217 tmpTypeId = GetBuiltinType (lst->basicType->a.setOf);
5218
5219 if ( tmpTypeId != BASICTYPE_ANY || ! gVDADER_RULES )
5220 fprintf (src, " %s tag1;\n", tagTypeNameG);
5221 #endif
5222
5223 fprintf (src, " %s listBytesDecoded = 0;\n", lenTypeNameG);
5224
5225 /* print local vars elmtLen for decoding list component */
5226 elmtLevel = CxxCountVariableLevels (lst->basicType->a.setOf);
5227
5228 for (i = 1; i <= elmtLevel; i++)
5229 fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i);
5230
5231 fprintf (src, "\n");
5232
5233
5234 fprintf (src, " while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))\n");
5235 fprintf (src, " {\n");
5236
5237 #ifdef VDADER_RULES
5238 /* decode content */
5239 /* note: cannot be ANY DEFINED BY as SET OF/SEQ OF ELMT */
5240 if ( tmpTypeId != BASICTYPE_ANY || ! gVDADER_RULES) /** RWC; 4/98 **/
5241 {
5242 #endif
5243
5244
5245 fprintf (src, " tag1 = BDecTag (b, listBytesDecoded, env);\n");
5246
5247 fprintf (src, " if ((tag1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN))\n");
5248 fprintf (src, " {\n");
5249 fprintf (src, " BDEC_2ND_EOC_OCTET (b, listBytesDecoded, env);\n");
5250 fprintf (src, " break;\n");
5251 fprintf (src, " }\n");
5252
5253 PrintCxxListTagAndLenDecCode (src, td, lst->basicType->a.setOf);
5254
5255 fprintf (src, " listElmt = Append();\n");
5256
5257 #ifdef VDADER_RULES
5258 fprintf (src, " listElmt->B%s (b, tag1, elmtLen%d, listBytesDecoded, env);\n", r->decodeContentBaseName, elmtLevel);
5259
5260 }
5261 else
5262 {
5263 fprintf (src, " listElmt = Append();\n");
5264 #else
5265 /* decode content */
5266 tmpTypeId = GetBuiltinType (lst->basicType->a.setOf);
5267 /* note: cannot be ANY DEFINED BY as SET OF/SEQ OF ELMT */
5268 if (tmpTypeId == BASICTYPE_ANY)
5269 {
5270 #endif
5271
5272 #ifdef VDADER_RULES
5273 if (!gVDADER_RULES)
5274 {
5275 #endif
5276 fprintf (src, " listElmt->SetTypeBy???(???);\n");
5277
5278 fprintf (src, " listElmt->B%s (b, listBytesDecoded, env);\n", r->decodeBaseName, elmtLevel);
5279
5280 #ifdef VDADER_RULES
5281 }
5282 else
5283 {
5284 fprintf (src, " DEC_LOAD_ANYBUF(");
5285 fprintf (src, "listElmt, b, listBytesDecoded, env);\n");
5286 }
5287 } /* end of else */
5288 #else
5289 } /* end of if BASIC_ANY_TYPE */
5290 else
5291 fprintf (src, " listElmt->B%s (b, tag1, elmtLen%d, listBytesDecoded, env);\n", r->decodeContentBaseName, elmtLevel);
5292 #endif
5293 /* grab any EOCs that match redundant, indef lengths */
5294 for (i = elmtLevel-1; i > 0; i--)
5295 {
5296 fprintf (src, " if (elmtLen%d == INDEFINITE_LEN)\n", i);
5297 fprintf (src, " BDecEoc (b, listBytesDecoded, env);\n");
5298 }
5299
5300
5301 fprintf (src, " }\n\n"); /* end of while */
5302
5303 fprintf (src, " bytesDecoded += listBytesDecoded;\n");
5304
5305 fprintf (src, "} // %s::B%s\n\n\n", lcn, r->decodeContentBaseName);
5306 }
5307
5308 } /* PrintCxxListMethods */
5309
5310 static void
5311 PrintCxxSetOfDefCode PARAMS ((src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, parent, setOf, novolatilefuncs),
5312 FILE *src _AND_
5313 FILE *hdr _AND_
5314 if_IBM_ENC (FILE *srcdb _AND_)
5315 if_IBM_ENC (FILE *hdrdb _AND_)
5316 ModuleList *mods _AND_
5317 Module *m _AND_
5318 CxxRules *r _AND_
5319 TypeDef *td _AND_
5320 Type *parent _AND_
5321 Type *setOf _AND_
5322 int novolatilefuncs)
5323 {
5324 /* do class */
5325 PrintCxxListClass (src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, parent, setOf);
5326
5327 /* do methods */
5328 PrintCxxListMethods (src, hdr, mods, m, r, td, parent, setOf, novolatilefuncs);
5329
5330 } /* PrintCxxSetOfDefCode */
5331
5332
5333 static void
5334 PrintCxxAnyDefCode PARAMS ((src, hdr, mods, m, r, td, parent, any),
5335 FILE *src _AND_
5336 FILE *hdr _AND_
5337 ModuleList *mods _AND_
5338 Module *m _AND_
5339 CxxRules *r _AND_
5340 TypeDef *td _AND_
5341 Type *parent _AND_
5342 Type *any)
5343 {
5344 fprintf (hdr, "/* ");
5345 SpecialPrintType (hdr, td, td->type);
5346 fprintf (hdr, " */\n");
5347 fprintf (hdr, "typedef %s %s;\n\n", td->type->cxxTypeRefInfo->className, td->cxxTypeDefInfo->className);
5348 } /* PrintCxxAnyDefCode */
5349
5350
5351 static void
5352 PrintCxxTypeDefCode PARAMS ((src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, novolatilefuncs),
5353 FILE *src _AND_
5354 FILE *hdr _AND_
5355 if_IBM_ENC (FILE *srcdb _AND_)
5356 if_IBM_ENC (FILE *hdrdb _AND_)
5357 ModuleList *mods _AND_
5358 Module *m _AND_
5359 CxxRules *r _AND_
5360 TypeDef *td _AND_
5361 int novolatilefuncs)
5362 {
5363 CNamedElmt *n;
5364
5365 switch (td->type->basicType->choiceId)
5366 {
5367 case BASICTYPE_BOOLEAN: /* library type */
5368 case BASICTYPE_REAL: /* library type */
5369 case BASICTYPE_OCTETSTRING: /* library type */
5370 case BASICTYPE_NULL: /* library type */
5371 case BASICTYPE_OID: /* library type */
5372 case BASICTYPE_INTEGER: /* library type */
5373 case BASICTYPE_BITSTRING: /* library type */
5374 case BASICTYPE_ENUMERATED: /* library type */
5375 PrintCxxSimpleDef (hdr, src, if_IBM_ENC (hdrdb COMMA srcdb COMMA) if_META (m COMMA) r, td);
5376 break;
5377
5378 case BASICTYPE_SEQUENCEOF: /* list types */
5379 case BASICTYPE_SETOF:
5380 PrintCxxSetOfDefCode (src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, NULL, td->type, novolatilefuncs);
5381 break;
5382
5383 case BASICTYPE_IMPORTTYPEREF: /* type references */
5384 case BASICTYPE_LOCALTYPEREF:
5385 /*
5386 * if this type has been re-tagged then
5387 * must create new class instead of using a typedef
5388 */
5389 PrintCxxSimpleDef (hdr, src, if_IBM_ENC (hdrdb COMMA srcdb COMMA) if_META (m COMMA) r, td);
5390 break;
5391
5392 case BASICTYPE_ANYDEFINEDBY: /* ANY types */
5393 case BASICTYPE_ANY:
5394 /*
5395 fprintf (stderr, " ANY types require modification. ");
5396 fprintf (stderr, " The source files will have a \" ANY - Fix Me! \" comment before related code.\n\n");
5397 */
5398 PrintCxxAnyDefCode (src, hdr, mods, m, r, td, NULL, td->type);
5399 break;
5400
5401 case BASICTYPE_CHOICE:
5402 PrintCxxChoiceDefCode (src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, NULL, td->type, novolatilefuncs);
5403 break;
5404
5405 case BASICTYPE_SET:
5406 PrintCxxSetDefCode (src, hdr, mods, m, r, td, NULL, td->type, novolatilefuncs);
5407 break;
5408
5409 case BASICTYPE_SEQUENCE:
5410 PrintCxxSeqDefCode (src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, NULL, td->type, novolatilefuncs);
5411 break;
5412
5413 case BASICTYPE_COMPONENTSOF:
5414 case BASICTYPE_SELECTION:
5415 case BASICTYPE_UNKNOWN:
5416 case BASICTYPE_MACRODEF:
5417 case BASICTYPE_MACROTYPE:
5418 /* do nothing */
5419 break;
5420 }
5421 } /* PrintCxxTypeDefCode */
5422
5423 void
5424 PrintCxxCode PARAMS ((src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) if_META (printMeta COMMA meta COMMA meta_pdus COMMA) mods, m, r, longJmpVal, printTypes, printValues, printEncoders, printDecoders, printPrinters, printFree if_TCL (COMMA printTcl), novolatilefuncs),
5425 FILE *src _AND_
5426 FILE *hdr _AND_
5427 if_IBM_ENC (FILE *srcdb _AND_)
5428 if_IBM_ENC (FILE *hdrdb _AND_)
5429 if_META (MetaNameStyle printMeta _AND_)
5430 if_META (const Meta *meta _AND_)
5431 if_META (MetaPDU *meta_pdus _AND_)
5432 ModuleList *mods _AND_
5433 Module *m _AND_
5434 CxxRules *r _AND_
5435 long int longJmpVal _AND_
5436 int printTypes _AND_
5437 int printValues _AND_
5438 int printEncoders _AND_
5439 int printDecoders _AND_
5440 int printPrinters _AND_
5441 int printFree
5442 if_TCL (_AND_ int printTcl) _AND_
5443 int novolatilefuncs)
5444 {
5445 TypeDef *td;
5446 ValueDef *vd;
5447 #ifdef _IBM_ENC_
5448 char mm_name[40];
5449 #endif /* _IBM_ENC_ */
5450
5451 longJmpValG = longJmpVal;
5452 printTypesG = printTypes;
5453 printEncodersG = printEncoders;
5454 printDecodersG = printDecoders;
5455 printPrintersG = printPrinters;
5456 printFreeG = printFree;
5457 #if META
5458 printMetaG = printMeta;
5459 meta_pdus_G = meta_pdus;
5460 #if TCL
5461 printTclG = printTcl;
5462 #endif /* TCL */
5463 #endif /* META */
5464
5465 PrintSrcComment (src, m);
5466 PrintHdrComment (hdr, m);
5467 #ifdef _IBM_ENC_
5468 PrintSrcComment (srcdb, m); /* 20.8.93 IBM-ENC */
5469 PrintHdrComment (hdrdb, m); /* 20.8.93 IBM-ENC */
5470
5471 strcpy (mm_name, m->cxxHdrFileName);
5472 #endif /* _IBM_ENC_ */
5473
5474 PrintConditionalIncludeOpen (hdr, m->cxxHdrFileName);
5475
5476 #ifdef _IBM_ENC_
5477 mm_name[strlen (mm_name)-2]='\0';
5478 fprintf (hdrdb, "#ifndef _%sdb_h_\n", mm_name);
5479 fprintf(hdrdb, "#define _%sdb_h_\n", mm_name);
5480 #endif /* _IBM_ENC_ */
5481
5482 #if META
5483 if (printMetaG)
5484 {
5485 fprintf (src, "\n");
5486 fprintf (src, "#ifndef META\n");
5487 fprintf (src, "#define META 1\n");
5488 fprintf (src, "#endif\n");
5489 #if TCL
5490 if (printTclG)
5491 {
5492 fprintf (src, "#ifndef TCL\n");
5493 fprintf (src, "#define TCL META\n");
5494 fprintf (src, "#endif\n");
5495 }
5496 #endif /* TCL */
5497 }
5498 #endif /* META */
5499
5500 fprintf (src, "\n");
5501
5502 PrintSrcIncludes (src, if_IBM_ENC (srcdb COMMA) mods, m);
5503
5504 fprintf (src, "\n");
5505
5506 fprintf (hdr, "//------------------------------------------------------------------------------\n");
5507 fprintf (hdr, "// class declarations:\n\n");
5508 FOR_EACH_LIST_ELMT (td, m->typeDefs)
5509 PrintTypeDecl (hdr, td);
5510 fprintf (hdr, "\n");
5511
5512 #if META
5513 if (printMeta)
5514 {
5515 fprintf (hdr, "#if META\n");
5516 fprintf (src, "#if META\n\n");
5517
5518 fprintf (hdr, "//------------------------------------------------------------------------------\n");
5519 fprintf (hdr, "extern const AsnModuleDesc %sModuleDesc;\n", m->cxxname);
5520
5521 fprintf (src, "//------------------------------------------------------------------------------\n");
5522 fprintf (src, "static const AsnTypeDesc *%sModuleTypes[] =\n", m->cxxname);
5523 fprintf (src, "{\n");
5524 FOR_EACH_LIST_ELMT (td, m->typeDefs)
5525 fprintf (src, " &%s::_desc,\n", td->cxxTypeDefInfo->className);
5526 fprintf (src, " NULL\n");
5527 fprintf (src, "};\n\n");
5528 #if 0 /* yet unused: */
5529 if (printMetaG == META_backend_names)
5530 else /* META_asn1_names */
5531 #endif
5532 fprintf (src, "const AsnModuleDesc %sModuleDesc = { \"%s\", %sModuleTypes };\n\n", m->cxxname, m->modId->name, m->cxxname);
5533
5534 fprintf (hdr, "#endif // META\n\n");
5535 fprintf (src, "#endif // META\n\n");
5536 }
5537 #endif /* META */
5538
5539 if (printValues)
5540 {
5541 fprintf (src, "//------------------------------------------------------------------------------\n");
5542 fprintf (src, "// value defs\n\n");
5543 FOR_EACH_LIST_ELMT (vd, m->valueDefs)
5544 PrintCxxValueDef (src, r, vd);
5545 fprintf (src, "\n");
5546 }
5547
5548 fprintf (hdr, "//------------------------------------------------------------------------------\n");
5549 fprintf (hdr, "// class definitions:\n\n");
5550 fprintf (src, "//------------------------------------------------------------------------------\n");
5551 fprintf (src, "// class member definitions:\n\n");
5552
5553 PrintCxxAnyCode (src, hdr, r, mods, m);
5554
5555 FOR_EACH_LIST_ELMT (td, m->typeDefs)
5556 PrintCxxTypeDefCode (src, hdr, if_IBM_ENC (srcdb COMMA hdrdb COMMA) mods, m, r, td, novolatilefuncs);
5557
5558 if (printValues)
5559 {
5560 fprintf (hdr, "//------------------------------------------------------------------------------\n");
5561 fprintf (hdr, "// externs for value defs\n\n");
5562 FOR_EACH_LIST_ELMT (vd, m->valueDefs)
5563 PrintCxxValueExtern (hdr, r, vd);
5564 }
5565
5566 fprintf (hdr, "//------------------------------------------------------------------------------\n");
5567 PrintConditionalIncludeClose (hdr, m->cxxHdrFileName);
5568
5569 #ifdef _IBM_ENC_
5570 fprintf (hdrdb, "#endif\n");
5571 #endif /* _IBM_ENC_ */
5572 } /* PrintCxxCode */
5573
5574
5575 #ifdef VDADER_RULES
5576
5577 /* this routine will generate code which will encode a SET OF in using DER
5578 * rules.
5579 */
5580 long VDA_ProcessSetOf(FILE *src,
5581 TypeDef *td,
5582 Type *lst,
5583 CxxRules *r)
5584 {
5585 enum BasicTypeChoiceId tmpTypeId;
5586
5587
5588 fprintf (src, " {\n");
5589 fprintf (src, " int iii,icount;\n CSM_Buffer **tmpEnc=NULL;\n");
5590 fprintf (src, " for (currElmt = last,icount=0; currElmt != NULL; currElmt = currElmt->prev, icount++);\n");
5591 fprintf (src, " tmpEnc = (CSM_Buffer **) calloc(sizeof(CSM_Buffer *), icount);\n");
5592 fprintf (src, " for (currElmt = last, iii=0; currElmt != NULL; currElmt = currElmt->prev,iii++,elmtLen=0)\n");
5593 fprintf (src, " {\n");
5594 /* encode Eoc (s) if nec */
5595 PrintCxxEocEncoders (src, td, lst->basicType->a.setOf, "b");
5596
5597 tmpTypeId = GetBuiltinType (lst->basicType->a.setOf);
5598
5599 /* list element types cannot by ANY DEFINED BY */
5600 if (tmpTypeId == BASICTYPE_ANY)
5601 {
5602 fprintf (src, " tmpEnc[iii] = (CSM_Buffer *)currElmt->elmt->value;\n");
5603 }
5604 else
5605 { /** SEE "smimesnacc.h" for a description of these ODD macros, to
5606 ** save space.
5607 **/
5608 fprintf (src, " ENCODE_BUF1(currElmt->elmt->B%s, elmtLen);\n", r->encodeContentBaseName);
5609
5610 /** encode content only into buffer.
5611 **/
5612 PrintCxxTagAndLenEncodingCode (src, td, lst->basicType->a.setOf,
5613 "elmtLen", "outputBuf");
5614
5615 /** set tag and length in "outputBuf" buffer (DEFINED IN MACRO).
5616 **/
5617 fprintf (src, " ENCODE_BUF2(tmpEnc[iii]);\n");
5618
5619 /** extract buffer to "Str_struct *".
5620 **/
5621 }
5622 fprintf (src, " }\n");
5623
5624 /* encode list elmt tag/len pairs here */
5625
5626 /** NOW, we have a list of icount "CSM_Buffer"s, which are the ASN.1
5627 ** encoded results of all of the specified "SET OF" components here.
5628 ** THESE MUST be re-ordered in ascending order for proper DER
5629 ** Encoding Rule encoding.
5630 **/
5631
5632 fprintf (src, " vdasnacc_sortSetOf(tmpEnc, icount);\n");
5633 /** These "SET OF" components are now ordered in ascending order,
5634 ** ready to be loaded into the output buffer. (RWC; TBD; make output
5635 ** buffers accept these allocated buffers directly, no copy).
5636 **/
5637
5638 fprintf (src, " for (iii=0,elmtLen=0; iii < icount; elmtLen+=tmpEnc[iii++]->Length())\n");
5639 fprintf (src, " SM_WriteToAsnBuf(tmpEnc[iii], b);\n");
5640 /**fprintf (src, " b.PutSegRvs((char *)tmpEnc[iii]->str, tmpEnc[iii]->lgth);\n");**/
5641 if (tmpTypeId != BASICTYPE_ANY) /** FREE resources loaded here. **/
5642 fprintf (src, " for (iii=0; iii < icount; iii++) delete tmpEnc[iii];\n");
5643 fprintf (src, " free(tmpEnc);\n");
5644 fprintf (src, " }\n");
5645 fprintf (src, " totalLen += elmtLen;\n");
5646
5647 return(0);
5648 } /** END else BASICTYPE_SETOF, RWC; only for VDADER_RULES define **/
5649
5650 #endif