2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
21 * compiler/back_ends/c++_gen/gen_code.c - routines for printing C++ code from type trees
23 * assumes that the type tree has already been run through the
24 * c++ type generator (c++_gen/types.c).
26 * This was hastily written - it has some huge routines in it.
27 * Needs a lot of cleaning up and modularization...
31 * Copyright (C) 1991, 1992 Michael Sample
32 * and the University of British Columbia
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.
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.
47 * Revision 1.3.44.3 2002/03/20 20:56:39 dmitch
48 * Further refinements for Radar 2868524: no more BDecPdu or BEncPdu.
50 * Revision 1.3.44.2 2002/03/20 02:53:09 dmitch
51 * Avoid the unused and uninitialized jmp_buf var in BDecPdu.
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.
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.
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.
62 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
63 * Move from private repository to open source repository
65 * Revision 1.4 2001/05/05 00:59:27 rmurphy
66 * Adding darwin license headers
68 * Revision 1.3 1999/03/20 03:13:48 mb
69 * Generate Copy member functions.
71 * Revision 1.2 1999/03/17 01:54:54 aram
72 * Changed compiler so that the destructors and Clone methods are virtual.
74 * Revision 1.1.1.1 1999/03/16 18:06:39 aram
75 * Originals from SMIME Free Library.
77 * Revision 1.12 1997/02/28 13:39:53 wan
78 * Modifications collected for new version 1.3: Bug fixes, tk4.2.
80 * Revision 1.11 1997/02/16 15:14:06 rj
81 * made return *this after calling abort()'' a compile time option.
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.
88 * Revision 1.9 1995/09/07 20:47:32 rj
89 * deep copying assingment operators added.
91 * Revision 1.8 1995/09/07 19:25:27 rj
92 * PrintCxxCode(): boolean genMeta changed to enum type MetaNameStyle. used globally in printMetaG.
94 * set Tcl's errorCode variable.
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)
99 * Revision 1.6 1995/07/27 10:52:28 rj
100 * include config.h before using its #define's :-)
102 * file name has been shortened for redundant part: c++-gen/gen-c++-code -> c++-gen/gen-code.
104 * functions used only locally made static.
106 * #if TCL ... #endif wrapped into #if META ... #endif, both here and in generated files.
108 * code changes to allow for more than one PDU (meta code), e.g. generate -create() functions.
110 * generate additional TclUnsetVal() function to delete OPTIONAL members and SEQUENCE OF and SET OF list elements.
112 * _getref() gets an additional optional argument to faciliate the different member access semantics of TclGetVal() and TclSetVal().
114 * the list functions Append(), Prepend(), InsertBefore() and InsertAfter() now set the current element to the element just inserted.
116 * changed `_' to `-' in file names.
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]
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.
124 * turned the functions order upside down to get rid of those annoying declarations.
126 * turned character pointers into constant character arrays.
128 * code for meta structures added (provides information about the generated code itself).
130 * code for Tcl interface added (makes use of the above mentioned meta code).
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.
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).
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.
141 * made Print() const (and some other, mainly comparison functions).
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.
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.
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.
158 #if TIME_WITH_SYS_TIME
159 # include <sys/time.h>
163 # include <sys/time.h>
169 #if STDC_HEADERS || HAVE_STRING_H
176 #include "asn-incl.h"
177 #include "asn1module.h"
180 #include "lib-types.h"
184 #include "str-util.h"
185 #include "snacc-util.h"
187 #include "tag-util.h" /* get GetTags/FreeTags/CountTags/TagByteLen */
191 #include "gen-vals.h"
193 #include "gen-code.h"
196 long VDA_ProcessSetOf(FILE *src
,TypeDef
*td
,Type
*lst
,CxxRules
*r
);
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";
207 static int printTypesG
;
208 static int printEncodersG
;
209 static int printDecodersG
;
210 static int printPrintersG
;
211 static int printFreeG
;
213 static MetaNameStyle printMetaG
;
214 static MetaPDU
*meta_pdus_G
;
216 static int printTclG
;
222 PrintHdrComment
PARAMS ((hdr
, m
),
226 time_t now
= time (NULL
);
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 */
237 } /* PrintHdrComment */
240 PrintSrcComment
PARAMS ((src
, m
),
244 time_t now
= time (NULL
);
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 */
255 } /* PrintSrcComment */
259 PrintSrcIncludes
PARAMS ((src
, if_IBM_ENC (srcdb COMMA
) mods
, m
),
261 if_IBM_ENC (FILE *srcdb _AND_
)
262 ModuleList
*mods _AND_
270 #endif /* _IBM_ENC_ */
272 fprintf (src
, "#include \"asn-incl.h\"\n");
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
);
280 #include "./ibm_editor/print_src_includes.h"
281 #endif /* _IBM_ENC_ */
282 } /* PrintSrcIncludes */
286 PrintTypeDecl
PARAMS ((f
, td
),
290 switch (td
->type
->basicType
->choiceId
)
292 case BASICTYPE_COMPONENTSOF
:
293 case BASICTYPE_SELECTION
:
294 case BASICTYPE_UNKNOWN
:
295 case BASICTYPE_MACRODEF
:
296 case BASICTYPE_MACROTYPE
:
297 return; /* do nothing */
300 if (IsNewType (td
->type
))
301 fprintf (f
, "class %s;\n", td
->cxxTypeDefInfo
->className
);
304 } /* PrintTypeDecl */
308 PrintCxxType
PARAMS ((hdr
, mods
, m
, r
, td
, parent
, t
),
310 ModuleList
*mods _AND_
317 fprintf (hdr
, "%s ", t
->cxxTypeRefInfo
->className
);
319 if (t
->cxxTypeRefInfo
->isPtr
)
327 PrintCxxTypedb
PARAMS ((srcdb
, mods
, m
, r
, td
, parent
, t
),
329 ModuleList
*mods _AND_
336 #include "./ibm_editor/print_cxx_type_db.h"
337 } /* PrintCxxTypedb */
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.
347 PrintCloneMethod
PARAMS ((hdr
, src
, td
),
352 fprintf (hdr
, " virtual AsnType *Clone() const;\n\n", td
->cxxTypeDefInfo
->className
);
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");
359 /* Print the Copy method as well. Use the copy constuctor. */
360 fprintf (hdr
, " virtual AsnType *Copy() const;\n\n", td
->cxxTypeDefInfo
->className
);
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 */
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)
374 * 12/92 MS - added overloaded "=" ops for string types.
377 PrintDerivedConstructors
PARAMS ((f
, r
, td
),
382 enum BasicTypeChoiceId typeId
;
383 char *derivedClassName
;
386 typeId
= GetBuiltinType (td
->type
);
387 derivedClassName
= td
->cxxTypeDefInfo
->className
;
388 baseClassName
= td
->type
->cxxTypeRefInfo
->className
;
390 /* every class gets the no-arg constructor */
392 if (printTclG
&& typeId
== BASICTYPE_ENUMERATED
)
394 fprintf (f
, "#if TCL\n");
395 fprintf (f
, " %s(): %s (_nmdescs[0].value) {}\n", derivedClassName
, baseClassName
);
396 fprintf (f
, "#else\n");
399 fprintf (f
, " %s(): %s() {}\n", derivedClassName
, baseClassName
);
401 if (printTclG
&& typeId
== BASICTYPE_ENUMERATED
)
402 fprintf (f
, "#endif\n");
407 case BASICTYPE_BOOLEAN
:
408 fprintf (f
, " %s (bool b): %s (b) {}\n", derivedClassName
, baseClassName
);
411 case BASICTYPE_ENUMERATED
:
412 case BASICTYPE_INTEGER
:
413 fprintf (f
, " %s (int i): %s (i) {}\n", derivedClassName
, baseClassName
);
417 fprintf (f
, " %s (double d): %s (d) {}\n", derivedClassName
, baseClassName
);
420 case BASICTYPE_OCTETSTRING
:
421 fprintf (f
, " %s (const char *str): %s (str) {}\n", derivedClassName
, baseClassName
);
423 fprintf (f
, " %s (const char *str, const size_t len): %s (str, len) {}\n", derivedClassName
, baseClassName
);
425 fprintf (f
, " %s (const %s &o): %s (o) {}\n", derivedClassName
, baseClassName
, baseClassName
);
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
);
432 case BASICTYPE_BITSTRING
:
433 fprintf (f
, " %s (const size_t bits): %s (bits) {}\n", derivedClassName
, baseClassName
);
435 fprintf (f
, " %s (const char *str, const size_t bitLen): %s (str, bitLen) {}\n", derivedClassName
, baseClassName
);
437 fprintf (f
, " %s (const %s &b): %s (b) {}\n", derivedClassName
, baseClassName
, baseClassName
);
440 /* include overloading of = op. MS 12/92 */
441 fprintf (f
, " %s &operator = (const %s &b) { ReSet (b); return *this; }\n", derivedClassName
, derivedClassName
);
444 fprintf (f
, " %s (const char *encOid, size_t len): %s (encOid, len) {}\n", derivedClassName
, baseClassName
);
446 fprintf (f
, " %s (const %s &o): %s (o) {}\n", derivedClassName
, baseClassName
, baseClassName
);
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
);
450 /* include overloading of = op. MS 12/92 */
451 fprintf (f
, " %s &operator = (const %s &o) { ReSet (o); return *this; }\n", derivedClassName
, derivedClassName
);
461 } /* PrintDerivedConstructors */
465 PrintMakeTag
PARAMS ((f
, tag
),
472 classStr
= Class2ClassStr (tag
->tclass
);
474 if (tag
->form
== ANY_FORM
) /* default to PRIM for dual form tags */
475 formStr
= Form2FormStr (PRIM
);
477 formStr
= Form2FormStr (tag
->form
);
479 fprintf (f
, "MAKE_TAG_ID (%s, %s, ", classStr
, formStr
);
480 if (tag
->tclass
== UNIV
)
481 fprintf (f
, "%s)", Code2UnivCodeStr (tag
->code
));
483 fprintf (f
, "%d)", tag
->code
);
488 PrintPduMemberFcns
PARAMS ((src
, hdr
, r
, cln
),
497 fprintf (hdr
, " int B%s (%s b, %s &bytesEncoded);\n", r
->encodePduBaseName
, bufTypeNameG
, lenTypeNameG
);
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");
508 fprintf (hdr
, " int B%s (%s b, %s &bytesDecoded);\n", r
->decodePduBaseName
, bufTypeNameG
, lenTypeNameG
);
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");
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");
536 fprintf (src, " { cerr << \"longjmp return value is \" << val << endl;\n");
537 fprintf (src, " return false; }\n");
539 #endif /* SNACC_EXCEPTION_ENABLE */
540 fprintf (src
, "}\n\n");
544 #endif /* SNACC_ENABLE_PDU */
545 } /* PrintPduMemberFcns */
549 PrintCxxEocEncoders
PARAMS ((src
, td
, t
, bufVarName
),
560 * get all the tags on this type
562 tl
= (TagList
*) GetTags (t
, &stoleChoiceTags
);
565 * leave choice elmt tag enc to encoding routine
567 if (!stoleChoiceTags
)
569 FOR_EACH_LIST_ELMT (tag
, tl
)
570 if (tag
->form
== CONS
)
571 fprintf (src
, " BEncEocIfNec (b);\n");
576 } /* PrintCxxEocEncoders */
580 HasShortLen
PARAMS ((t
),
583 enum BasicTypeChoiceId typesType
;
585 * efficiency hack - use simple length (1 byte)
586 * encoded for type (almost) guaranteed to have
587 * encoded lengths of 0 <= len <= 127
589 typesType
= GetBuiltinType (t
);
590 return typesType
== BASICTYPE_BOOLEAN
|| typesType
== BASICTYPE_INTEGER
|| typesType
== BASICTYPE_NULL
|| typesType
== BASICTYPE_REAL
|| typesType
== BASICTYPE_ENUMERATED
;
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
604 PrintCxxLenEncodingCode
PARAMS ((f
, isCons
, isShort
, lenVarName
, bufVarName
),
608 char *lenVarName _AND_
612 fprintf (f
, " %s += BEncConsLen (%s, %s);\n", lenVarName
, bufVarName
, lenVarName
);
617 fprintf (f
, " BEncDefLenTo127 (%s, %s);\n", bufVarName
, lenVarName
);
618 fprintf (f
, " %s++;\n", lenVarName
);
621 fprintf (f
, " %s += BEncDefLen (%s, %s);\n", lenVarName
, bufVarName
, lenVarName
);
623 } /* PrintCxxLenEncodingCode */
627 * prints last tag's encoding code first
630 PrintCxxTagAndLenList
PARAMS ((src
, t
, tagList
, lenVarName
, bufVarName
),
633 TagList
*tagList _AND_
634 char *lenVarName _AND_
643 enum BasicTypeChoiceId typesType
;
646 if ((tagList
== NULL
) || LIST_EMPTY (tagList
))
650 * efficiency hack - use simple length (1 byte)
651 * encoded for type (almost) guaranteed to have
652 * encoded lengths of 0 <= len <= 127
654 isShort
= HasShortLen (t
);
657 * since encoding backward encode tags backwards
659 last
= (Tag
*)LAST_LIST_ELMT (tagList
);
660 FOR_EACH_LIST_ELMT_RVS (tg
, tagList
)
662 classStr
= Class2ClassStr (tg
->tclass
);
664 if (tg
->form
== CONS
)
666 formStr
= Form2FormStr (CONS
);
667 PrintCxxLenEncodingCode (src
, TRUE
, isShort
, lenVarName
, bufVarName
);
669 else /* PRIM or ANY_FORM */
671 formStr
= Form2FormStr (PRIM
);
672 PrintCxxLenEncodingCode (src
, FALSE
, isShort
, lenVarName
, bufVarName
);
675 /* GetTags sets the form properly now
676 if (IsPrimitiveByDefOrRef (t) && (tg == last))
678 formStr = Form2FormStr (PRIM);
679 PrintCxxLenEncodingCode (src, FALSE, isShort, lenVarName, bufVarName);
683 formStr = Form2FormStr (CONS);
684 PrintCxxLenEncodingCode (src, TRUE, isShort, lenVarName, bufVarName);
690 tagLen
= TagByteLen (tg
->code
);
692 if (tg
->tclass
== UNIV
)
693 fprintf (src
, " %s += BEncTag%d (%s, %s, %s, %s);\n", lenVarName
, tagLen
, bufVarName
, classStr
, formStr
, Code2UnivCodeStr (tg
->code
));
695 fprintf (src
, " %s += BEncTag%d (%s, %s, %s, %d);\n", lenVarName
, tagLen
, bufVarName
, classStr
, formStr
, tg
->code
);
698 } /* PrintCxxTagAndLenList */
702 * Recursively walks through tags, printing lower lvl tags
703 * first (since encoding is done backwards).
707 PrintCxxTagAndLenEncodingCode
PARAMS ((src
, td
, t
, lenVarName
, bufVarName
),
711 char *lenVarName _AND_
718 * get all the tags on this type
720 tl
= (TagList
*) GetTags (t
, &stoleChoiceTags
);
723 * leave choice elmt tag enc to encoding routine
725 if (!stoleChoiceTags
)
726 PrintCxxTagAndLenList (src
, t
, tl
, lenVarName
, bufVarName
);
730 } /* PrintCxxTagAndLenEncodingCode */
734 * used to figure out local variables to declare
735 * for decoding tags/len pairs on type t
738 CxxCountVariableLevels
PARAMS ((t
),
741 if (GetBuiltinType (t
) == BASICTYPE_CHOICE
)
742 return CountTags (t
) +1; /* since must decode 1 internal tag type */
744 return CountTags (t
);
745 } /* CxxCountVariableLevels */
749 * returns true if elmts curr following
750 * onward are all optional ow. false
753 RestAreTailOptional
PARAMS ((e
),
763 tmp
= (void*)CURR_LIST_NODE (e
);
766 FOR_REST_LIST_ELMT (elmt
, e
)
768 if ((!elmt
->type
->optional
) && (elmt
->type
->defaultVal
== NULL
))
774 SET_CURR_LIST_NODE (e
, tmp
); /* reset list to orig loc */
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.
784 PrintCxxSimpleDef
PARAMS ((hdr
, src
, if_IBM_ENC (hdrdb COMMA srcdb COMMA
) if_META (m COMMA
) r
, td
),
787 if_IBM_ENC (FILE *hdrdb _AND_
)
788 if_IBM_ENC (FILE *srcdb _AND_
)
789 if_META (Module
*m _AND_
)
802 enum BasicTypeChoiceId typeId
;
804 fprintf (hdr
, "/* ");
805 SpecialPrintType (hdr
, td
, td
->type
);
806 fprintf (hdr
, " */\n");
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
812 * eg Foo ::= INTEGER { one (1), two (2), three (3) }
815 if (IsNewType (td
->type
))
820 #include "./ibm_editor/print_cxx_simple_def.h"
821 #endif /* _IBM_ENC_ */
823 fprintf (hdr
, "class %s: public %s\n", td
->cxxTypeDefInfo
->className
, td
->type
->cxxTypeRefInfo
->className
);
824 fprintf (hdr
, "{\n");
825 fprintf (hdr
, "public:\n");
828 * must explicitly call constructors for base class
830 PrintDerivedConstructors (hdr
, r
, td
);
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) }
837 * class Foo: public AsnInt
841 * Foo (int val): AsnInt (int val) {}
842 * enum { one = 1, two = 2, five = 5 };
845 * Foo2 ::= [APPLICATION 2] INTEGER
847 * class Foo: public 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 { ....... }
857 * (must 'inherit' constructors explicitly)
860 if (hasNamedElmts
= HasNamedElmts (td
->type
))
862 fprintf (hdr
, " enum\n");
863 fprintf (hdr
, " {\n");
864 FOR_EACH_LIST_ELMT (n
, td
->type
->cxxTypeRefInfo
->namedElmts
)
866 fprintf (hdr
, " %s = %d", n
->name
, n
->value
);
867 if (n
!= (CNamedElmt
*)LAST_LIST_ELMT (td
->type
->cxxTypeRefInfo
->namedElmts
))
868 fprintf (hdr
, ",\n");
872 fprintf (hdr
, " };\n");
881 fprintf (hdr
, "#if META\n");
882 fprintf (src
, "#if META\n\n");
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");
889 if (hasNamedElmts
= HasNamedElmts (td
->type
))
891 fprintf (hdr
, " static const AsnNameDesc _nmdescs[];\n");
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 */
900 fprintf (src
, " \"%s\", %s, // %d\n", n
->name
, n
->name
, n
->value
);
901 fprintf (src
, " NULL, -1\n");
902 fprintf (src
, "};\n\n");
905 switch (GetBuiltinType (td
->type
))
907 case BASICTYPE_BOOLEAN
:
912 case BASICTYPE_ENUMERATED
:
917 case BASICTYPE_INTEGER
:
927 case BASICTYPE_OCTETSTRING
:
932 case BASICTYPE_BITSTRING
:
947 fprintf (hdr
, " static const Asn%sTypeDesc _desc;\n", t
);
948 fprintf (hdr
, " const AsnTypeDesc *_getdesc() const;\n");
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
);
961 fprintf (src
, ",\n %s", hasNamedElmts
? "_nmdescs" : "NULL");
962 fprintf (src
, "\n);\n\n");
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");
969 fprintf (hdr
, "#endif // META\n");
970 fprintf (src
, "#endif // META\n\n");
978 * Re-do BerEncode, BerDeocode, BerDecodePdu and BerDecodePdu
979 * if this type has been re-tagged
981 if ((IsDefinedByLibraryType (td
->type
) && !HasDefaultTag (td
->type
))
982 || (IsTypeRef (td
->type
) && ((td
->type
->tags
!= NULL
) && !LIST_EMPTY (td
->type
->tags
))))
984 /* only BerEn/Decode BerEn/DecodePdu need to be re-done if tags are different */
986 /* print clone routine for ANY mgmt */
987 PrintCloneMethod (hdr
, src
, td
);
989 tags
= GetTags (td
->type
, &stoleChoiceTags
);
990 typeId
= GetBuiltinType (td
->type
);
992 /* do BerEncode function */
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
);
1000 PrintCxxEocEncoders (src
, td
, td
->type
, "b");
1002 fprintf (src
, " l = BEncContent (b);\n");
1004 /* encode each tag/len pair if any */
1005 if (!stoleChoiceTags
)
1007 FOR_EACH_LIST_ELMT_RVS (tag
, tags
)
1009 classStr
= Class2ClassStr (tag
->tclass
);
1011 if (tag
->form
== ANY_FORM
)
1013 formStr
= Form2FormStr (PRIM
);
1014 PrintCxxLenEncodingCode (src
, FALSE
, HasShortLen (td
->type
), "l", "b");
1018 formStr
= Form2FormStr (tag
->form
);
1019 PrintCxxLenEncodingCode (src
, TRUE
, HasShortLen (td
->type
), "l", "b");
1022 fprintf (src
, "\n");
1023 tagLen
= TagByteLen (tag
->code
);
1025 if (tag
->tclass
== UNIV
)
1026 fprintf (src
, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen
, classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
1028 fprintf (src
, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen
, classStr
, formStr
, tag
->code
);
1031 fprintf (src
, " return l;\n");
1032 fprintf (src
, "}\n\n");
1034 /* end of BEnc function */
1036 /* Do BDec function */
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
);
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");
1051 /* decode tag/length pair (s) */
1053 if (!stoleChoiceTags
)
1055 FOR_EACH_LIST_ELMT (tag
, tags
)
1057 classStr
= Class2ClassStr (tag
->tclass
);
1059 if (tag
->form
== ANY_FORM
)
1060 formStr
= Form2FormStr (PRIM
);
1062 formStr
= Form2FormStr (tag
->form
);
1064 fprintf (src
, " if (((tag = BDecTag (b, bytesDecoded, env)) != ");
1066 if (tag
->tclass
== UNIV
)
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
));
1072 fprintf (src
, ")\n");
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
);
1080 fprintf (src
, ")\n");
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
--);
1087 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
1088 #endif /* SNACC_EXCEPTION_ENABLE */
1089 fprintf (src
, " }\n");
1091 fprintf (src
, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
1095 /* decode first tag from CHOICE's content */
1096 if (typeId
== BASICTYPE_CHOICE
)
1098 fprintf (src
, " tag = BDecTag (b, bytesDecoded, env);\n");
1099 fprintf (src
, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
1102 fprintf (src
, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r
->decodeContentBaseName
, i
-1);
1104 /* grab any EOCs that match redundant, indef lengths */
1105 for (i
= elmtLevel
-1; i
> 0; i
--)
1107 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
1108 fprintf (src
, " BDecEoc (b, bytesDecoded, env);\n");
1111 fprintf (src
, "}\n\n");
1113 /* end of BDec function */
1115 PrintPduMemberFcns (src
, hdr
, r
, td
->cxxTypeDefInfo
->className
);
1119 /* close class def */
1120 fprintf (hdr
, "};\n\n\n");
1123 else /* isomorphic with referenced type, so just to a typedef */
1126 #include "./ibm_editor/print_cxx_simple_def1.h"
1127 #endif /* _IBM_ENC_ */
1132 fprintf (hdr
, "#if META\n");
1133 fprintf (src
, "#if META\n\n");
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");
1140 fprintf (hdr
, "struct %s: public %s\n", td
->cxxTypeDefInfo
->className
, td
->type
->cxxTypeRefInfo
->className
);
1141 fprintf (hdr
, "{\n");
1143 PrintDerivedConstructors (hdr
, r
, td
);
1145 PrintCloneMethod (hdr
, src
, td
);
1147 fprintf (hdr
, " static const AsnAliasTypeDesc _desc;\n");
1148 fprintf (hdr
, " const AsnTypeDesc *_getdesc() const;\n");
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
);
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");
1167 fprintf (hdr
, "};\n\n");
1169 fprintf (hdr
, "#else // META\n\n");
1170 fprintf (src
, "#endif // META\n\n");
1174 fprintf (hdr
, "typedef %s %s;\n\n", td
->type
->cxxTypeRefInfo
->className
, td
->cxxTypeDefInfo
->className
);
1178 fprintf (hdr
, "#endif // META\n\n");
1181 } /* PrintCxxSimpleDef */
1184 PrintCxxChoiceDefCode
PARAMS ((src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, parent
, choice
, novolatilefuncs
),
1187 if_IBM_ENC (FILE *srcdb _AND_
)
1188 if_IBM_ENC (FILE *hdrdb _AND_
)
1189 ModuleList
*mods _AND_
1195 int novolatilefuncs
)
1207 int varCount
, tmpVarCount
;
1208 int stoleChoiceTags
;
1209 enum BasicTypeChoiceId tmpTypeId
;
1210 NamedType
*defByNamedType
;
1213 #include "./ibm_editor/print_cxx_choice_def_code.h"
1214 #endif /* _IBM_ENC_ */
1216 /* put class spec in hdr file */
1218 fprintf (hdr
, "class %s%s\n", td
->cxxTypeDefInfo
->className
, baseClassesG
);
1219 fprintf (hdr
, "{\n");
1220 fprintf (hdr
, "public:\n");
1222 /* write out choiceId enum type */
1224 fprintf (hdr
, " enum %s\n", r
->choiceIdEnumName
);
1225 fprintf (hdr
, " {\n");
1226 FOR_EACH_LIST_ELMT (e
, choice
->basicType
->a
.choice
)
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");
1232 fprintf (hdr
, "\n");
1234 fprintf (hdr
, " };\n\n");
1236 /* write out the choice Id field */
1237 /* fprintf (hdr, "protected:\n"); */
1238 fprintf (hdr
, " enum %s %s;\n", r
->choiceIdEnumName
, r
->choiceIdFieldName
);
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
)
1246 PrintCxxType (hdr
, mods
, m
, r
, td
, choice
, e
->type
);
1247 fprintf (hdr
, "%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
1249 fprintf (hdr
, " };\n\n");
1254 fprintf (hdr
, "#if META\n");
1255 fprintf (src
, "#if META\n\n");
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");
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");
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");
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");
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");
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
)
1306 fprintf (src
, " case %sCid:\n", e
->type
->cxxTypeRefInfo
->fieldName
);
1307 fprintf (src
, " return %s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
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
)
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");
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
)
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
);
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");
1352 fprintf (hdr
, "#if TCL\n");
1353 fprintf (src
, "#if TCL\n\n");
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");
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");
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
)
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");
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");
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");
1414 fprintf (hdr
, "#endif // TCL\n");
1415 fprintf (src
, "#endif // TCL\n\n");
1419 fprintf (hdr
, "#endif // META\n");
1420 fprintf (src
, "#endif // META\n\n");
1424 fprintf (hdr
, "\n");
1426 /* constructors and destructor */
1428 fprintf (hdr
, " %s();\n", td
->cxxTypeDefInfo
->className
);
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");
1441 fprintf (hdr
, " %s (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
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");
1449 fprintf (hdr
, " virtual ~%s();\n\n", td
->cxxTypeDefInfo
->className
);
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
)
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");
1462 fprintf (src
, " } // end of switch\n");
1463 fprintf (src
, "} // end of destructor\n");
1464 fprintf (src
, "\n");
1466 /* print clone routine for ANY mgmt */
1467 PrintCloneMethod (hdr
, src
, td
);
1469 fprintf (hdr
, " %s &operator = (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
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
)
1484 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
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
)
1496 fprintf (src
, " case %s:\n", e
->type
->cxxTypeRefInfo
->choiceIdSymbol
);
1497 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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
);
1503 fprintf (src
, " %s = that.%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
, e
->type
->cxxTypeRefInfo
->fieldName
);
1504 fprintf (src
, " break;\n");
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
)
1516 fprintf (src
, " return *this;\n");
1518 fprintf (src
, "#endif // SNACC_DEEP_COPY\n");
1519 fprintf (src
, "}\n\n");
1521 /* BerEncodeContent */
1524 fprintf (hdr
, " %s B%s (%s b);\n", lenTypeNameG
, r
->encodeContentBaseName
, bufTypeNameG
);
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");
1530 /* print local vars */
1531 fprintf (src
, " %s l;\n", lenTypeNameG
);
1533 fprintf (src
, " switch (%s)\n", r
->choiceIdFieldName
);
1534 fprintf (src
, " {\n");
1535 FOR_EACH_LIST_ELMT (e
, choice
->basicType
->a
.choice
)
1537 cxxtri
= e
->type
->cxxTypeRefInfo
;
1538 fprintf (src
, " case %s:\n", cxxtri
->choiceIdSymbol
);
1540 varName
= cxxtri
->fieldName
;
1542 /* encode Eoc (s) if nec */
1543 PrintCxxEocEncoders (src
, td
, e
->type
, "b");
1545 /* encode content */
1546 tmpTypeId
= GetBuiltinType (e
->type
);
1547 if (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)
1549 fprintf (src
, " %s", varName
);
1551 fprintf (src
, "->");
1555 defByNamedType
= e
->type
->basicType
->a
.anyDefinedBy
->link
;
1556 if (GetBuiltinType (defByNamedType
->type
) == BASICTYPE_OID
)
1558 fprintf (src
, "SetTypeByOid (");
1559 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
1560 fprintf (src
, " *");
1561 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
1565 fprintf (src
, "SetTypeByInt (");
1566 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
1567 fprintf (src
, " *");
1568 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
1571 fprintf (src
, " l = %s", varName
);
1573 fprintf (src
, "->");
1576 fprintf (src
, "B%s (b);\n", r
->encodeBaseName
);
1578 else if (tmpTypeId
== BASICTYPE_ANY
)
1581 if (! gVDADER_RULES
)
1584 fprintf (src
, " %s", varName
);
1586 fprintf (src
, "->");
1589 fprintf (src
, "SetTypeBy???(???);\n");
1591 fprintf (src
, " l = %s", varName
);
1593 fprintf (src
, "->");
1596 fprintf (src
, "B%s (b);\n", r
->encodeBaseName
);
1602 fprintf (src
, " ENC_LOAD_ANYBUF(");
1605 fprintf (src
, "%s, b, l);\n", varName
);
1611 fprintf (src
, " l = %s", varName
);
1613 fprintf (src
, "->");
1617 fprintf (src
, "B%s (b);\n", r
->encodeContentBaseName
);
1621 /* encode tag (s) & len (s) */
1622 PrintCxxTagAndLenEncodingCode (src
, td
, e
->type
, "l", "b");
1625 fprintf (src
, " break;\n\n");
1627 fprintf (src
, " } // end switch\n");
1629 fprintf (src
, " return l;\n");
1630 fprintf (src
, "} // %s::B%s\n\n\n", td
->cxxTypeDefInfo
->className
, r
->encodeContentBaseName
);
1632 /* end of BerEncodeContent method */
1634 /* BerDecodeContent */
1637 fprintf (hdr
, " void B%s (%s b, %s tag, %s elmtLen, %s &bytesDecoded, %s env);\n", r
->decodeContentBaseName
, bufTypeNameG
, tagTypeNameG
, lenTypeNameG
, lenTypeNameG
, envTypeNameG
);
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
);
1641 fprintf (src
, "{\n");
1643 /* print local vars */
1644 /* count max number of extra length var nec
1645 * by counting tag/len pairs on components of the CHOICE
1648 FOR_EACH_LIST_ELMT (e
, choice
->basicType
->a
.choice
)
1650 tmpVarCount
= CxxCountVariableLevels (e
->type
);
1651 if (tmpVarCount
> varCount
)
1652 varCount
= tmpVarCount
;
1654 /* write extra length vars - remeber choice content
1655 * decoders are passed the 'key' tag so need one less
1656 * than max var count.
1658 for (i
= 1; i
< varCount
; i
++)
1659 fprintf (src
, " %s elmtLen%d;\n", lenTypeNameG
, i
);
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
)
1666 cxxtri
= e
->type
->cxxTypeRefInfo
;
1668 tags
= GetTags (e
->type
, &stoleChoiceTags
);
1670 if (LIST_EMPTY (tags
))
1672 fprintf (src
, " // ANY Type?\n");
1673 fprintf (src
, " case MAKE_TAG_ID (?, ?, ?):\n");
1677 tag
= (Tag
*)FIRST_LIST_ELMT (tags
);
1678 classStr
= Class2ClassStr (tag
->tclass
);
1679 codeStr
= Code2UnivCodeStr (tag
->code
);
1680 formStr
= Form2FormStr (tag
->form
);
1682 if (tag
->tclass
== UNIV
)
1684 if (tag
->form
== ANY_FORM
)
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
);
1690 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
1694 if (tag
->form
== ANY_FORM
)
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
);
1700 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
1703 /* now decode extra tags/length pairs */
1704 AsnListFirst (tags
);
1707 if (stoleChoiceTags
)
1709 FOR_REST_LIST_ELMT (tag
, tags
)
1711 classStr
= Class2ClassStr (tag
->tclass
);
1712 codeStr
= Code2UnivCodeStr (tag
->code
);
1713 formStr
= Form2FormStr (tag
->form
);
1715 if (tag
->tclass
== UNIV
)
1717 if (tag
->form
== ANY_FORM
)
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
);
1723 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
1727 if (tag
->form
== ANY_FORM
)
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
);
1733 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
1737 else /* didn't steal nested choice's tags */
1739 FOR_REST_LIST_ELMT (tag
, tags
)
1741 classStr
= Class2ClassStr (tag
->tclass
);
1742 codeStr
= Code2UnivCodeStr (tag
->code
);
1743 formStr
= Form2FormStr (tag
->form
);
1745 fprintf (src
, " tag = BDecTag (b, bytesDecoded, env);\n");
1746 if (tag
->form
== ANY_FORM
)
1748 if (tag
->tclass
== UNIV
)
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
);
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
);
1762 if (tag
->tclass
== UNIV
)
1763 fprintf (src
, " if (tag != MAKE_TAG_ID (%s, %s, %s))\n", classStr
, formStr
, codeStr
);
1765 fprintf (src
, " if (tag != MAKE_TAG_ID (%s, %s, %d))\n", classStr
, formStr
, tag
->code
);
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
--);
1773 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
1774 #endif /* SNACC_EXCEPTION_ENABLE */
1775 fprintf (src
, " }\n\n");
1777 fprintf (src
, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
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
1786 if (!stoleChoiceTags
&& (GetBuiltinType (e
->type
) == BASICTYPE_CHOICE
))
1788 fprintf (src
, " tag = BDecTag (b, bytesDecoded, env);\n");
1789 fprintf (src
, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
1792 varName
= cxxtri
->fieldName
;
1794 /* set choice id for to this elment */
1795 fprintf (src
, " %s = %s;\n", r
->choiceIdFieldName
, cxxtri
->choiceIdSymbol
);
1797 /* alloc elmt if nec */
1799 fprintf (src
, " %s = new %s;\n", varName
, cxxtri
->className
);
1801 /* decode content */
1802 tmpTypeId
= GetBuiltinType (e
->type
);
1803 if (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)
1806 * must check for another EOC for ANYs
1807 * since the any decode routines decode
1808 * their own first tag/len pair
1812 fprintf (src
, " %s", varName
);
1814 fprintf (src
, "->");
1818 defByNamedType
= e
->type
->basicType
->a
.anyDefinedBy
->link
;
1819 if (GetBuiltinType (defByNamedType
->type
) == BASICTYPE_OID
)
1821 fprintf (src
, "SetTypeByOid (");
1822 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
1823 fprintf (src
, " *");
1824 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
1828 fprintf (src
, "SetTypeByInt (");
1829 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
1830 fprintf (src
, " *");
1831 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
1834 fprintf (src
, " %s", varName
);
1836 fprintf (src
, "->");
1839 fprintf (src
, "B%s (b, bytesDecoded, env);\n", r
->decodeBaseName
);
1841 else if (tmpTypeId
== BASICTYPE_ANY
)
1844 * must check for another EOC for ANYs
1845 * since the any decode routines decode
1846 * their own first tag/len pair
1851 if (! gVDADER_RULES
)
1854 fprintf (src
, " %s", varName
);
1856 fprintf (src
, "->");
1859 fprintf (src
, "SetTypeBy???(???);\n");
1861 fprintf (src
, " %s", varName
);
1863 fprintf (src
, "->");
1866 fprintf (src
, "B%s (b, bytesDecoded, env);\n", r
->decodeBaseName
);
1872 fprintf (src
, " DEC_LOAD_ANYBUF(");
1875 fprintf (src
, "%s, b, bytesDecoded, env);\n", varName
);
1881 fprintf (src
, " %s", varName
);
1883 fprintf (src
, "->");
1887 fprintf (src
, "B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r
->decodeContentBaseName
, elmtLevel
);
1890 /* decode Eoc (s) */
1891 for (i
= elmtLevel
-1; i
>= 0; i
--)
1893 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
1894 fprintf (src
, " BDecEoc (b, bytesDecoded, env);\n");
1897 fprintf (src
, " break;\n\n");
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
--);
1906 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
1907 #endif /* SNACC_EXCEPTION_ENABLE */
1908 fprintf (src
, " break;\n");
1910 fprintf (src
, " } // end switch\n");
1911 fprintf (src
, "} // %s::B%s\n\n\n", td
->cxxTypeDefInfo
->className
, r
->decodeContentBaseName
);
1913 /* end of code for printing BDecodeContent method */
1915 /* do BEnc function */
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
);
1924 /* encode each tag/len pair if any */
1925 FOR_EACH_LIST_ELMT_RVS (tag
, choice
->tags
)
1927 classStr
= Class2ClassStr (tag
->tclass
);
1928 formStr
= Form2FormStr (CONS
); /* choices are constructed */
1929 tagLen
= TagByteLen (tag
->code
);
1931 fprintf (src
, " l += BEncConsLen (b, l);\n");
1933 if (tag
->tclass
== UNIV
)
1934 fprintf (src
, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen
, classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
1936 fprintf (src
, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen
, classStr
, formStr
, tag
->code
);
1938 fprintf (src
, " return l;\n");
1939 fprintf (src
, "}\n\n");
1941 /* end of BEnc function */
1943 /* Do BDec function */
1946 fprintf (hdr
, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r
->decodeBaseName
, bufTypeNameG
, lenTypeNameG
, envTypeNameG
);
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
);
1953 /* print extra locals for redundant lengths */
1954 for (i
= 1; (choice
->tags
!= NULL
) && (i
<= LIST_COUNT (choice
->tags
)); i
++)
1956 fprintf (src
, " %s extraLen%d;\n", lenTypeNameG
, i
);
1958 fprintf (src
, "\n");
1960 /* decode tag/length pair (s) */
1962 FOR_EACH_LIST_ELMT (tag
, choice
->tags
)
1964 classStr
= Class2ClassStr (tag
->tclass
);
1965 formStr
= Form2FormStr (CONS
); /* choices are constructed */
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
));
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
--);
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
);
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
);
1990 /* grab any EOCs that match redundant, indef lengths */
1991 for (i
= elmtLevel
; i
> 0; i
--)
1993 fprintf (src
, " if (extraLen%d == INDEFINITE_LEN)\n", i
);
1994 fprintf (src
, " BDecEoc (b, bytesDecoded, env);\n");
1997 fprintf (src
, "}\n\n");
1999 /* end of BDec function */
2001 PrintPduMemberFcns (src
, hdr
, r
, td
->cxxTypeDefInfo
->className
);
2003 /* ostream printing routine */
2006 fprintf (hdr
, " void Print (ostream &os) const;\n", td
->cxxTypeDefInfo
->className
);
2008 fprintf (src
, "void %s::Print (ostream &os) const\n", td
->cxxTypeDefInfo
->className
);
2009 fprintf (src
, "{\n");
2011 fprintf (src
, "#ifndef NDEBUG\n");
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
)
2018 fprintf (src
, " case %s:\n", e
->type
->cxxTypeRefInfo
->choiceIdSymbol
);
2020 /* value notation so print the choice elmts field name */
2021 if (e
->fieldName
!= NULL
)
2022 fprintf (src
, " os << \"%s \";\n", e
->fieldName
);
2024 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
2030 fprintf (src
, " os << \"-- void3 --\\n\";\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2032 fprintf (src
, " os << \"-- void --\";\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2036 fprintf (src
, " os << %s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2038 fprintf (src
, " break;\n\n");
2040 fprintf (src
, " } // end of switch\n");
2043 fprintf (src
, "#endif /* NDEBUG */\n");
2045 /* fprintf (src, " os << \"}\" << endl;\n") */
2046 fprintf (src
, "} // %s::Print\n\n", td
->cxxTypeDefInfo
->className
);
2048 /* end of Print Method code */
2050 /* close class definition */
2051 fprintf (hdr
, "};\n\n\n");
2053 } /* PrintCxxChoiceDefCode */
2058 PrintCxxSeqDefCode
PARAMS ((src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, parent
, seq
, novolatilefuncs
),
2061 if_IBM_ENC (FILE *srcdb _AND_
)
2062 if_IBM_ENC (FILE *hdrdb _AND_
)
2063 ModuleList
*mods _AND_
2069 int novolatilefuncs
)
2081 int varCount
, tmpVarCount
;
2082 int stoleChoiceTags
;
2084 enum BasicTypeChoiceId tmpTypeId
;
2085 NamedType
*defByNamedType
;
2090 #include "./ibm_editor/print_cxx_seq_def_code.h"
2091 #endif /* _IBM_ENC_ */
2093 /* put class spec in hdr file */
2095 fprintf (hdr
, "class %s%s\n", td
->cxxTypeDefInfo
->className
, baseClassesG
);
2096 fprintf (hdr
, "{\n");
2097 fprintf (hdr
, "public:\n");
2099 /* write out the sequence elmts */
2100 FOR_EACH_LIST_ELMT (e
, seq
->basicType
->a
.sequence
)
2103 PrintCxxType (hdr
, mods
, m
, r
, td
, seq
, e
->type
);
2104 fprintf (hdr
, "%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2107 fprintf (hdr
, "\n");
2112 fprintf (hdr
, "#if META\n");
2113 fprintf (src
, "#if META\n\n");
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");
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");
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");
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");
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");
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
)
2157 fprintf (src
, " if (!strcmp (membername, \"%s\"))\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2158 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
2167 fprintf (src
, " return &%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2169 fprintf (src
, " return NULL;\n");
2170 fprintf (src
, "}\n\n");
2175 fprintf (hdr
, "#if TCL\n");
2176 fprintf (src
, "#if TCL\n\n");
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");
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
)
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
);
2193 fprintf (src
, " Tcl_DStringAppendElement (valstr, \"valid\");\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2194 fprintf (src
, " Tcl_DStringEndSublist (valstr);\n\n");
2196 fprintf (src
, " Tcl_DStringEndSublist (valstr);\n\n");
2197 fprintf (src
, " return TCL_OK;\n");
2198 fprintf (src
, "}\n\n");
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
)
2206 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
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");
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");
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
)
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
)
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");
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");
2306 fprintf (src
, " }\n");
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
)
2313 if (e
->type
->optional
|| e
->type
->defaultVal
)
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");
2328 fprintf (src
, "\n");
2329 fprintf (src
, " delete elempairs;\n");
2330 fprintf (src
, " return TCL_OK;\n");
2331 fprintf (src
, "}\n\n");
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
)
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
)
2347 fprintf (src
, " delete %s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2348 fprintf (src
, " %s = NULL;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
2352 fprintf (src
, " return _desc.mandatmemberr (interp, elems.v[i]);\n");
2354 fprintf (src
, " }\n");
2356 fprintf (src
, " }\n");
2357 fprintf (src
, " return TCL_OK;\n");
2358 fprintf (src
, "}\n\n");
2360 fprintf (hdr
, "#endif // TCL\n");
2361 fprintf (src
, "#endif // TCL\n\n");
2365 fprintf (hdr
, "#endif // META\n\n");
2366 fprintf (src
, "#endif // META\n\n");
2370 /* constructors and destructor: */
2372 fprintf (hdr
, " %s();\n", td
->cxxTypeDefInfo
->className
);
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
)
2378 if (e
->type
->cxxTypeRefInfo
->isPtr
)
2379 if (e
->type
->optional
|| e
->type
->defaultVal
)
2380 fprintf (src
, " %s = NULL;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
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");
2390 fprintf (src
, "}\n\n");
2392 fprintf (hdr
, " %s (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
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");
2400 fprintf (hdr
, " virtual ~%s();\n", td
->cxxTypeDefInfo
->className
);
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");
2409 /* print clone routine for ANY mgmt */
2410 PrintCloneMethod (hdr
, src
, td
);
2412 fprintf (hdr
, " %s &operator = (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
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
)
2425 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
2440 fprintf (src
, " %s = that.%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
, e
->type
->cxxTypeRefInfo
->fieldName
);
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
)
2451 fprintf (src
, " return *this;\n");
2453 fprintf (src
, "#endif // SNACC_DEEP_COPY\n");
2454 fprintf (src
, "}\n\n");
2456 /* BerEncodeContent method */
2459 fprintf (hdr
, " %s B%s (%s b);\n", lenTypeNameG
, r
->encodeContentBaseName
, bufTypeNameG
);
2461 fprintf (src
, "%s\n", lenTypeNameG
);
2462 fprintf (src
, "%s::B%s (%s b)\n", td
->cxxTypeDefInfo
->className
, r
->encodeContentBaseName
, bufTypeNameG
);
2464 fprintf (src
, "{\n");
2466 /* print local vars */
2467 fprintf (src
, " %s totalLen = 0;\n", lenTypeNameG
);
2468 fprintf (src
, " %s l;\n\n", lenTypeNameG
);
2470 FOR_EACH_LIST_ELMT_RVS (e
, seq
->basicType
->a
.sequence
)
2472 cxxtri
= e
->type
->cxxTypeRefInfo
;
2474 varName
= cxxtri
->fieldName
;
2476 /* print optional test if nec */
2477 if (e
->type
->optional
|| (e
->type
->defaultVal
!= NULL
))
2479 fprintf (src
, " if (%s (%s))\n", cxxtri
->optTestRoutineName
, varName
);
2480 fprintf (src
, " {\n");
2483 /* encode Eoc (s) if nec */
2484 PrintCxxEocEncoders (src
, td
, e
->type
, "b");
2486 /* encode content */
2487 tmpTypeId
= GetBuiltinType (e
->type
);
2488 if (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)
2490 fprintf (src
, " %s", varName
);
2492 fprintf (src
, "->");
2496 defByNamedType
= e
->type
->basicType
->a
.anyDefinedBy
->link
;
2497 if (GetBuiltinType (defByNamedType
->type
) == BASICTYPE_OID
)
2499 fprintf (src
, "SetTypeByOid (");
2500 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
2501 fprintf (src
, " *");
2502 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
2506 fprintf (src
, "SetTypeByInt (");
2507 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
2508 fprintf (src
, " *");
2509 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
2512 fprintf (src
, " l = %s", varName
);
2514 fprintf (src
, "->");
2517 fprintf (src
, "B%s (b);\n", r
->encodeBaseName
);
2519 else if (tmpTypeId
== BASICTYPE_ANY
)
2522 if (! gVDADER_RULES
)
2525 fprintf (src
, " %s", varName
);
2527 fprintf (src
, "->");
2530 fprintf (src
, "SetTypeBy???(???);\n");
2532 fprintf (src
, " l = %s", varName
);
2534 fprintf (src
, "->");
2537 fprintf (src
, "B%s (b);\n", r
->encodeBaseName
);
2543 fprintf (src
, " ENC_LOAD_ANYBUF(");
2546 fprintf (src
, "%s, b, l);\n", varName
);
2552 fprintf (src
, " l = %s", varName
);
2554 fprintf (src
, "->");
2558 fprintf (src
, "B%s (b);\n", r
->encodeContentBaseName
);
2562 /* encode tag (s) & len (s) */
2563 PrintCxxTagAndLenEncodingCode (src
, td
, e
->type
, "l", "b");
2566 fprintf (src
, " totalLen += l;\n");
2568 /* close optional test if nec */
2569 if (e
->type
->optional
|| (e
->type
->defaultVal
!= NULL
))
2570 fprintf (src
, " }\n\n");
2572 fprintf (src
, "\n");
2574 fprintf (src
, " return totalLen;\n");
2575 fprintf (src
, "} // %s::B%s\n\n\n", td
->cxxTypeDefInfo
->className
, r
->encodeContentBaseName
);
2577 /* end of BerEncodeContent method printing code */
2579 /* write BerDecodeContent to src */
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
);
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
);
2586 fprintf (src
, "{\n");
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 */
2593 FOR_EACH_LIST_ELMT (e
, seq
->basicType
->a
.sequence
)
2595 tmpVarCount
= CxxCountVariableLevels (e
->type
);
2597 if (tmpVarCount
> varCount
)
2598 varCount
= tmpVarCount
;
2600 /* write extra length vars */
2601 for (i
= 1; i
<= varCount
; i
++)
2602 fprintf (src
, " %s elmtLen%d;\n", lenTypeNameG
, i
);
2604 /* handle empty seq */
2605 if ((seq
->basicType
->a
.sequence
== NULL
) || LIST_EMPTY (seq
->basicType
->a
.sequence
))
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
--);
2615 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
2616 #endif /* SNACC_EXCEPTION_ENABLE */
2617 fprintf (src
, " }\n");
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");
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");
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
);
2643 tmpTypeId
= GetBuiltinType (e
->type
);
2645 if (!inTailOptElmts
)
2647 if (((tmpTypeId
== BASICTYPE_ANY
) || (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)) && (CountTags (e
->type
) == 0))
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");
2653 fprintf (src
, " tag1 = BDecTag (b, seqBytesDecoded, env);\n\n");
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))
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");
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");
2678 FOR_EACH_LIST_ELMT (e
, seq
->basicType
->a
.sequence
)
2680 cxxtri
= e
->type
->cxxTypeRefInfo
;
2683 tags
= GetTags (e
->type
, &stoleChoiceTags
);
2685 /* if (inTailOptElmts)
2686 fprintf (src, " (!seqDone) && ");
2688 if (LIST_EMPTY (tags
))
2689 fprintf (src
, " // ANY type\n");
2692 tag
= (Tag
*)FIRST_LIST_ELMT (tags
);
2693 classStr
= Class2ClassStr (tag
->tclass
);
2694 codeStr
= Code2UnivCodeStr (tag
->code
);
2695 formStr
= Form2FormStr (tag
->form
);
2697 fprintf (src
, " if (");
2698 if (tag
->tclass
== UNIV
)
2700 if (tag
->form
== ANY_FORM
)
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
);
2706 fprintf (src
, "(tag1 == MAKE_TAG_ID (%s, %s, %s))", classStr
, formStr
, codeStr
);
2710 if (tag
->form
== ANY_FORM
)
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
);
2716 fprintf (src
, "(tag1 == MAKE_TAG_ID (%s, %s, %d))", classStr
, formStr
, tag
->code
);
2720 /* now decode extra tags/length pairs */
2721 AsnListFirst (tags
);
2723 if (stoleChoiceTags
)
2725 FOR_REST_LIST_ELMT (tag
, tags
)
2727 fprintf (src
, "\n || ");
2728 classStr
= Class2ClassStr (tag
->tclass
);
2729 codeStr
= Code2UnivCodeStr (tag
->code
);
2730 formStr
= Form2FormStr (tag
->form
);
2732 if (tag
->tclass
== UNIV
)
2734 if (tag
->form
== ANY_FORM
)
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
);
2740 fprintf (src
, "(tag1 == MAKE_TAG_ID (%s, %s, %s))", classStr
, formStr
, codeStr
);
2744 if (tag
->form
== ANY_FORM
)
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
);
2750 fprintf (src
, "(tag1 == MAKE_TAG_ID (%s, %s, %d))", classStr
, formStr
, tag
->code
);
2753 fprintf (src
, ")\n");
2754 fprintf (src
, " {\n");
2755 fprintf (src
, " elmtLen%d = BDecLen (b, seqBytesDecoded, env);\n", ++elmtLevel
);
2758 else /* didn't steal nested choice's tags */
2760 fprintf (src
, ")\n");
2761 fprintf (src
, " {\n");
2762 fprintf (src
, " elmtLen%d = BDecLen (b, seqBytesDecoded, env);\n", ++elmtLevel
);
2764 FOR_REST_LIST_ELMT (tag
, tags
)
2766 classStr
= Class2ClassStr (tag
->tclass
);
2767 codeStr
= Code2UnivCodeStr (tag
->code
);
2768 formStr
= Form2FormStr (tag
->form
);
2770 fprintf (src
, " tag1 = BDecTag (b, seqBytesDecoded, env);\n\n");
2771 if (tag
->tclass
== UNIV
)
2773 if (tag
->form
== ANY_FORM
)
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
);
2779 fprintf (src
, " if (tag1 != MAKE_TAG_ID (%s, %s, %s))\n", classStr
, formStr
, codeStr
);
2783 if (tag
->form
== ANY_FORM
)
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
);
2789 fprintf (src
, " if (tag1 != MAKE_TAG_ID (%s, %s, %d))\n", classStr
, formStr
, tag
->code
);
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
--);
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
);
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
2809 if (!stoleChoiceTags
&& (GetBuiltinType (e
->type
) == BASICTYPE_CHOICE
))
2811 fprintf (src
, " tag1 = BDecTag (b, seqBytesDecoded, env);\n");
2812 fprintf (src
, " elmtLen%d = BDecLen (b, seqBytesDecoded, env);\n", ++elmtLevel
);
2817 varName
= cxxtri
->fieldName
;
2819 /* decode content */
2821 fprintf (src
, " %s = new %s;\n", varName
, cxxtri
->className
);
2824 /* decode content */
2825 tmpTypeId
= GetBuiltinType (e
->type
);
2826 if (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)
2829 * must check for another EOC for ANYs
2830 * since the any decode routines decode
2831 * their own first tag/len pair
2834 fprintf (src
, " %s", varName
);
2836 fprintf (src
, "->");
2840 defByNamedType
= e
->type
->basicType
->a
.anyDefinedBy
->link
;
2841 if (GetBuiltinType (defByNamedType
->type
) == BASICTYPE_OID
)
2843 fprintf (src
, "SetTypeByOid (");
2844 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
2845 fprintf (src
, " *");
2846 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
2850 fprintf (src
, "SetTypeByInt (");
2851 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
2852 fprintf (src
, " *");
2853 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
2856 fprintf (src
, " %s", varName
);
2858 fprintf (src
, "->");
2861 fprintf (src
, "B%s (b, seqBytesDecoded, env);\n", r
->decodeBaseName
);
2863 else if (tmpTypeId
== BASICTYPE_ANY
)
2866 * must check for another EOC for ANYs
2867 * since the any decode routines decode
2868 * their own first tag/len pair
2873 if (! gVDADER_RULES
)
2876 fprintf (src
, " %s", varName
);
2878 fprintf (src
, "->");
2881 fprintf (src
, "SetTypeBy???(???);\n");
2883 fprintf (src
, " %s", varName
);
2885 fprintf (src
, "->");
2888 fprintf (src
, "B%s (b, seqBytesDecoded, env);\n", r
->decodeBaseName
);
2894 fprintf (src
, " DEC_LOAD_ANYBUF(");
2897 fprintf (src
, "%s, b, seqBytesDecoded, env);\n", varName
);
2903 fprintf (src
, " %s", varName
);
2905 fprintf (src
, "->");
2909 fprintf (src
, "B%s (b, tag1, elmtLen%d, seqBytesDecoded, env);\n", r
->decodeContentBaseName
, elmtLevel
);
2912 /* decode Eoc (s) */
2913 for (i
= elmtLevel
-1; i
> 0; i
--)
2915 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
2916 fprintf (src
, " BDecEoc (b, seqBytesDecoded, env);\n\n");
2920 * print code for getting the next tag
2922 inTailOptElmts
= RestAreTailOptional (seq
->basicType
->a
.sequence
);
2923 if (e
!= (NamedType
*)LAST_LIST_ELMT (seq
->basicType
->a
.sequence
))
2925 tmpElmt
= (NamedType
*)NEXT_LIST_ELMT (seq
->basicType
->a
.sequence
);
2926 tmpTypeId
= GetBuiltinType (tmpElmt
->type
);
2927 if (!inTailOptElmts
)
2929 if ((tmpTypeId
== BASICTYPE_ANY
|| tmpTypeId
== BASICTYPE_ANYDEFINEDBY
) && CountTags (tmpElmt
->type
) == 0)
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");
2937 fprintf (src
, " tag1 = BDecTag (b, seqBytesDecoded, env);\n");
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");
2949 if ((tmpTypeId
== BASICTYPE_ANY
|| tmpTypeId
== BASICTYPE_ANYDEFINEDBY
) && !CountTags (tmpElmt
->type
))
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
)))
2955 * let this cause a compile error in the generated code
2957 fprintf (src
, " <problems with untagged ANY that is optional or follows an optional sequence element - you must fix this>\n");
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");
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");
2978 fprintf (src
, " }\n");
2985 * close tag check if (if there is one) and
2986 * print else clause to handle missing non-optional elmt
2989 tmpTypeId
= GetBuiltinType (e
->type
);
2990 if ((tmpTypeId
== BASICTYPE_ANYDEFINEDBY
|| tmpTypeId
== BASICTYPE_ANY
) && !CountTags (e
->type
))
2992 /* do nothing - no tag check if stmt to close */
2993 fprintf (src
, "\n\n");
2995 else if (!e
->type
->optional
&& !e
->type
->defaultVal
)
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
--);
3004 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
3005 #endif /* SNACC_EXCEPTION_ENABLE */
3006 fprintf (src
, " }\n\n");
3009 fprintf (src
, " }\n\n"); /* end of tag check if */
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
--);
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");
3033 } /* end of non-empty set else clause */
3035 fprintf (src
, "} // %s::B%s\n\n", td
->cxxTypeDefInfo
->className
, r
->decodeContentBaseName
);
3037 /* end of code for printing ber decode content method */
3039 /* do BEnc function */
3042 fprintf (hdr
, " %s B%s (%s b);\n", lenTypeNameG
, r
->encodeBaseName
, bufTypeNameG
);
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
);
3049 /* encode each tag/len pair if any */
3050 FOR_EACH_LIST_ELMT_RVS (tag
, seq
->tags
)
3052 classStr
= Class2ClassStr (tag
->tclass
);
3053 formStr
= Form2FormStr (CONS
); /* seq's are constructed */
3054 tagLen
= TagByteLen (tag
->code
);
3056 fprintf (src
, " l += BEncConsLen (b, l);\n");
3058 if (tag
->tclass
== UNIV
)
3059 fprintf (src
, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen
, classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
3061 fprintf (src
, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen
, classStr
, formStr
, tag
->code
);
3063 fprintf (src
, " return l;\n");
3064 fprintf (src
, "}\n\n");
3066 /* end of BEnc function */
3068 /* Do BDec function */
3071 fprintf (hdr
, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r
->decodeBaseName
, bufTypeNameG
, lenTypeNameG
, envTypeNameG
);
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
);
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");
3082 /* decode tag/length pair (s) */
3084 FOR_EACH_LIST_ELMT (tag
, seq
->tags
)
3086 classStr
= Class2ClassStr (tag
->tclass
);
3087 formStr
= Form2FormStr (CONS
); /* seqs are constructed */
3089 fprintf (src
, " if ((tag = BDecTag (b, bytesDecoded, env)) != ");
3091 if (tag
->tclass
== UNIV
)
3092 fprintf (src
, "MAKE_TAG_ID (%s, %s, %s))\n", classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
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
--);
3100 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
3101 #endif /* SNACC_EXCEPTION_ENABLE */
3102 fprintf (src
, " }\n");
3104 fprintf (src
, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
3107 fprintf (src
, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r
->decodeContentBaseName
, elmtLevel
);
3109 /* grab any EOCs that match redundant, indef lengths */
3110 for (i
= elmtLevel
-1; i
> 0; i
--)
3112 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
3113 fprintf (src
, " BDecEoc (b, bytesDecoded, env);\n");
3116 fprintf (src
, "}\n\n");
3118 /* end of BDec function */
3120 PrintPduMemberFcns (src
, hdr
, r
, td
->cxxTypeDefInfo
->className
);
3122 /* write code for printing */
3125 fprintf (hdr
, " void Print (ostream &os) const;\n");
3127 fprintf (src
, "void %s::Print (ostream &os) const\n", td
->cxxTypeDefInfo
->className
);
3128 fprintf (src
, "{\n");
3130 fprintf (src
, "#ifndef NDEBUG\n");
3132 allOpt
= AllElmtsOptional (seq
->basicType
->a
.sequence
);
3134 fprintf (src
, " int nonePrinted = true;\n");
3135 fprintf (src
, " os << \"{ -- SEQUENCE --\" << endl;\n");
3136 fprintf (src
, " indentG += stdIndentG;\n\n");
3138 FOR_EACH_LIST_ELMT (e
, seq
->basicType
->a
.sequence
)
3140 inTailOptElmts
= IsTailOptional (seq
->basicType
->a
.sequence
);
3142 if (e
->type
->cxxTypeRefInfo
->isPtr
)
3143 fprintf (src
, " if (%s (%s))\n", cxxtri
->optTestRoutineName
, e
->type
->cxxTypeRefInfo
->fieldName
);
3145 fprintf (src
, " {\n");
3149 if (e
!= FIRST_LIST_ELMT (seq
->basicType
->a
.sequence
))
3151 fprintf (src
, " if (!nonePrinted)\n");
3152 fprintf (src
, " os << \",\" << endl;\n");
3154 fprintf (src
, " nonePrinted = false;\n", i
);
3156 else if (inTailOptElmts
) /* cannot be first elmt ow allOpt is true */
3157 fprintf (src
, " os << \",\"<< endl;\n");
3159 fprintf (src
, " Indent (os, indentG);\n");
3161 if (e
->fieldName
!= NULL
)
3162 fprintf (src
, " os << \"%s \";\n", e
->fieldName
);
3164 if (e
->type
->cxxTypeRefInfo
->isPtr
)
3165 fprintf (src
, " os << *%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3167 fprintf (src
, " os << %s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3170 if (e
!= LAST_LIST_ELMT (seq
->basicType
->a
.sequence
)&&(!e
->type
->cxxTypeRefInfo
->isPtr
) )
3171 fprintf (src
, " os << \",\" << endl;\n");
3173 if (e
!= LAST_LIST_ELMT (seq
->basicType
->a
.sequence
) && !inTailOptElmts
&& !NextIsTailOptional (seq
->basicType
->a
.sequence
))
3174 fprintf (src
, " os << \",\" << endl;\n");
3177 fprintf (src
, " }\n");
3179 if (e
->type
->cxxTypeRefInfo
->isPtr
)
3181 fprintf (src
, " else\n");
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");
3191 fprintf (src
, " os << endl;\n");
3192 fprintf (src
, " }\n");
3194 fprintf (src
, " os << \"-- void --\";\n");
3198 fprintf (src
, "\n");
3200 if (e
== LAST_LIST_ELMT (seq
->basicType
->a
.sequence
))
3201 fprintf (src
, " os << endl;\n");
3204 fprintf (src
, " indentG -= stdIndentG;\n");
3205 fprintf (src
, " Indent (os, indentG);\n");
3206 fprintf (src
, " os << \"}\";\n");
3208 fprintf (src
, "#endif /* NDEBUG */\n");
3210 fprintf (src
, "} // %s::Print\n\n\n", td
->cxxTypeDefInfo
->className
);
3212 /* end of print method code printer */
3214 /* close class definition */
3215 fprintf (hdr
, "};\n\n\n");
3217 } /* PrintCxxSeqDefCode */
3221 PrintCxxSetDefCode
PARAMS ((src
, hdr
, mods
, m
, r
, td
, parent
, set
, novolatilefuncs
),
3224 ModuleList
*mods _AND_
3230 int novolatilefuncs
)
3242 int varCount
, tmpVarCount
;
3243 int stoleChoiceTags
;
3245 int mandatoryElmtCount
;
3246 enum BasicTypeChoiceId tmpTypeId
;
3247 NamedType
*defByNamedType
;
3250 /* put class spec in hdr file */
3252 fprintf (hdr
, "class %s%s\n", td
->cxxTypeDefInfo
->className
, baseClassesG
);
3253 fprintf (hdr
, "{\n");
3254 fprintf (hdr
, "public:\n");
3256 /* write out the set elmts */
3257 FOR_EACH_LIST_ELMT (e
, set
->basicType
->a
.set
)
3260 PrintCxxType (hdr
, mods
, m
, r
, td
, set
, e
->type
);
3261 fprintf (hdr
, "%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3264 fprintf (hdr
, "\n");
3269 fprintf (hdr
, "#if META\n");
3270 fprintf (src
, "#if META\n\n");
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");
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");
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");
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");
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");
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
)
3314 fprintf (src
, " if (!strcmp (membername, \"%s\"))\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3315 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
3324 fprintf (src
, " return &%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3326 fprintf (src
, " return NULL;\n");
3327 fprintf (src
, "}\n\n");
3332 fprintf (hdr
, "#if TCL\n");
3333 fprintf (src
, "#if TCL\n\n");
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");
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
)
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
);
3350 fprintf (src
, " Tcl_DStringAppendElement (valstr, \"valid\");\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3351 fprintf (src
, " Tcl_DStringEndSublist (valstr);\n\n");
3353 fprintf (src
, " Tcl_DStringEndSublist (valstr);\n\n");
3354 fprintf (src
, " return TCL_OK;\n");
3355 fprintf (src
, "}\n\n");
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
)
3363 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
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");
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");
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
)
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
)
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");
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");
3463 fprintf (src
, " }\n");
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
)
3470 if (e
->type
->optional
|| e
->type
->defaultVal
)
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");
3485 fprintf (src
, "\n");
3486 fprintf (src
, " delete elempairs;\n");
3487 fprintf (src
, " return TCL_OK;\n");
3488 fprintf (src
, "}\n\n");
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
)
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
)
3504 fprintf (src
, " delete %s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3505 fprintf (src
, " %s = NULL;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
3509 fprintf (src
, " return _desc.mandatmemberr (interp, elems.v[i]);\n");
3511 fprintf (src
, " }\n");
3513 fprintf (src
, " }\n");
3514 fprintf (src
, " return TCL_OK;\n");
3515 fprintf (src
, "}\n\n");
3517 fprintf (hdr
, "#endif // TCL\n");
3518 fprintf (src
, "#endif // TCL\n\n");
3522 fprintf (hdr
, "#endif // META\n\n");
3523 fprintf (src
, "#endif // META\n\n");
3527 /* constructors and destructor: */
3529 fprintf (hdr
, " %s();\n", td
->cxxTypeDefInfo
->className
);
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
)
3535 if (e
->type
->cxxTypeRefInfo
->isPtr
)
3536 if (e
->type
->optional
|| e
->type
->defaultVal
)
3537 fprintf (src
, " %s = NULL;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
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");
3547 fprintf (src
, "}\n\n");
3549 fprintf (hdr
, " %s (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
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");
3557 fprintf (hdr
, " virtual ~%s();\n", td
->cxxTypeDefInfo
->className
);
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");
3566 /* print clone routine for ANY mgmt */
3567 PrintCloneMethod (hdr
, src
, td
);
3569 fprintf (hdr
, " %s &operator = (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
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
)
3582 if (e
->type
->cxxTypeRefInfo
->isPtr
)
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");
3597 fprintf (src
, " %s = that.%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
, e
->type
->cxxTypeRefInfo
->fieldName
);
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
)
3608 fprintf (src
, " return *this;\n");
3610 fprintf (src
, "#endif // SNACC_DEEP_COPY\n");
3611 fprintf (src
, "}\n\n");
3616 fprintf (hdr
, " %s B%s (%s b);\n", lenTypeNameG
, r
->encodeContentBaseName
, bufTypeNameG
);
3618 fprintf (src
, "%s %s::B%s (%s b)\n", lenTypeNameG
, td
->cxxTypeDefInfo
->className
, r
->encodeContentBaseName
, bufTypeNameG
);
3619 fprintf (src
, "{\n");
3621 /* print local vars */
3622 fprintf (src
, " %s totalLen = 0;\n", lenTypeNameG
);
3623 fprintf (src
, " %s l;\n\n", lenTypeNameG
);
3629 FOR_EACH_LIST_ELMT_RVS (e
, set
->basicType
->a
.set
)
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");
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
3643 FOR_EACH_LIST_ELMT_RVS (e
, set
->basicType
->a
.set
)
3645 cxxtri
= e
->type
->cxxTypeRefInfo
;
3647 varName
= cxxtri
->fieldName
;
3649 /* print optional test if nec*/
3650 if (e
->type
->optional
|| (e
->type
->defaultVal
!= NULL
))
3652 fprintf (src
, " if (%s (%s))\n", cxxtri
->optTestRoutineName
, varName
);
3653 fprintf (src
, " {\n");
3656 /* encode Eoc (s) if nec */
3659 PrintCxxEocEncoders (src
, td
, e
->type
, "outputBuf");
3662 PrintCxxEocEncoders (src
, td
, e
->type
, "b");
3664 /* encode content */
3665 tmpTypeId
= GetBuiltinType (e
->type
);
3666 if (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)
3668 fprintf (src
, " %s", varName
);
3670 fprintf (src
, "->");
3674 defByNamedType
= e
->type
->basicType
->a
.anyDefinedBy
->link
;
3675 if (GetBuiltinType (defByNamedType
->type
) == BASICTYPE_OID
)
3677 fprintf (src
, "SetTypeByOid (");
3678 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
3679 fprintf (src
, " *");
3680 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
3684 fprintf (src
, "SetTypeByInt (");
3685 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
3686 fprintf (src
, " *");
3687 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
3690 fprintf (src
, " l = %s", varName
);
3692 fprintf (src
, "->");
3697 fprintf (src
, "B%s (outputBuf);\n", r
->encodeBaseName
);
3700 fprintf (src
, "B%s (b);\n", r
->encodeBaseName
);
3702 else if (tmpTypeId
== BASICTYPE_ANY
)
3706 if (! gVDADER_RULES
)
3709 fprintf (src
, " %s", varName
);
3711 fprintf (src
, "->");
3714 fprintf (src
, "SetTypeBy???(???);\n");
3716 fprintf (src
, " l = %s", varName
);
3718 fprintf (src
, "->");
3721 fprintf (src
, "B%s (b);\n", r
->encodeBaseName
);
3727 fprintf (src
, " ENC_LOAD_ANYBUF(");
3730 fprintf (src
, "%s, outputBuf, l);\n", varName
);
3736 fprintf (src
, " l = %s", varName
);
3738 fprintf (src
, "->");
3744 fprintf (src
, "B%s (outputBuf);\n", r
->encodeContentBaseName
);
3747 fprintf (src
, "B%s (b);\n", r
->encodeContentBaseName
);
3750 /* encode tag (s) & len (s) */
3754 PrintCxxTagAndLenEncodingCode (src
, td
, e
->type
, "l", "outputBuf");
3757 PrintCxxTagAndLenEncodingCode (src
, td
, e
->type
, "l", "b");
3759 fprintf (src
, " totalLen += l;\n");
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");
3771 /* close optional test if nec */
3772 if (e
->type
->optional
|| (e
->type
->defaultVal
!= NULL
))
3773 fprintf (src
, " }\n\n");
3775 fprintf (src
, "\n");
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).
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");
3789 fprintf (src
, " for (iii=0; iii < tmpCount; iii++) delete tmpEnc[iii];\n");
3790 fprintf (src
, " free(lpszBuf);\n");
3793 } /** internal definition bracket for "tmpCount".**/
3795 fprintf (src
, " return totalLen;\n");
3796 fprintf (src
, "} // %s::B%s\n\n\n", td
->cxxTypeDefInfo
->className
, r
->encodeContentBaseName
);
3798 /* end of BerEncodeContent */
3800 /* write BerDecodeContent */
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
);
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");
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 */
3814 FOR_EACH_LIST_ELMT (e
, set
->basicType
->a
.set
)
3816 tmpVarCount
= CxxCountVariableLevels (e
->type
);
3817 if (tmpVarCount
> varCount
)
3818 varCount
= tmpVarCount
;
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");
3825 /* handle empty set */
3826 if ((set
->basicType
->a
.set
== NULL
) || LIST_EMPTY (set
->basicType
->a
.set
))
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
--);
3836 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
3837 #endif /* SNACC_EXCEPTION_ENABLE */
3838 fprintf (src
, " }\n");
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");
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");
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
)
3873 cxxtri
= e
->type
->cxxTypeRefInfo
;
3875 tags
= GetTags (e
->type
, &stoleChoiceTags
);
3877 if (LIST_EMPTY (tags
))
3879 fprintf (src
, " // ANY Type ?\n");
3880 fprintf (src
, " case MAKE_TAG_ID (?, ?, ?):\n");
3884 tag
= (Tag
*)FIRST_LIST_ELMT (tags
);
3885 classStr
= Class2ClassStr (tag
->tclass
);
3886 codeStr
= Code2UnivCodeStr (tag
->code
);
3887 formStr
= Form2FormStr (tag
->form
);
3889 if (tag
->tclass
== UNIV
)
3891 if (tag
->form
== ANY_FORM
)
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
);
3897 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
3901 if (tag
->form
== ANY_FORM
)
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
);
3907 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
3910 /* now decode extra tags/length pairs */
3911 AsnListFirst (tags
);
3914 if (stoleChoiceTags
)
3916 FOR_REST_LIST_ELMT (tag
, tags
)
3918 classStr
= Class2ClassStr (tag
->tclass
);
3919 codeStr
= Code2UnivCodeStr (tag
->code
);
3920 formStr
= Form2FormStr (tag
->form
);
3922 if (tag
->tclass
== UNIV
)
3924 if (tag
->form
== ANY_FORM
)
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
);
3930 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
3934 if (tag
->form
== ANY_FORM
)
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
);
3940 fprintf (src
, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
3944 else /* didn't steal nested choice's tags */
3946 FOR_REST_LIST_ELMT (tag
, tags
)
3948 classStr
= Class2ClassStr (tag
->tclass
);
3949 codeStr
= Code2UnivCodeStr (tag
->code
);
3950 formStr
= Form2FormStr (tag
->form
);
3952 fprintf (src
, " tag1 = BDecTag (b, setBytesDecoded, env);\n");
3953 if (tag
->form
== ANY_FORM
)
3955 if (tag
->tclass
== UNIV
)
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
);
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
);
3969 if (tag
->tclass
== UNIV
)
3970 fprintf (src
, " if (tag1 != MAKE_TAG_ID (%s, %s, %s))\n", classStr
, formStr
, codeStr
);
3972 fprintf (src
, " if (tag1 != MAKE_TAG_ID (%s, %s, %d))\n", classStr
, formStr
, tag
->code
);
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
--);
3980 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
3981 #endif /* SNACC_EXCEPTION_ENABLE */
3982 fprintf (src
, " }\n\n");
3984 fprintf (src
, " elmtLen%d = BDecLen (b, setBytesDecoded, env);\n", ++elmtLevel
);
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
3993 if (!stoleChoiceTags
&& (GetBuiltinType (e
->type
) == BASICTYPE_CHOICE
))
3995 fprintf (src
, " tag1 = BDecTag (b, setBytesDecoded, env);\n");
3996 fprintf (src
, " elmtLen%d = BDecLen (b, setBytesDecoded, env);\n", ++elmtLevel
);
3999 varName
= cxxtri
->fieldName
;
4001 /* decode content */
4003 fprintf (src
, " %s = new %s;\n", varName
, cxxtri
->className
);
4005 /* decode content */
4006 tmpTypeId
= GetBuiltinType (e
->type
);
4007 if (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)
4010 * must check for another EOC for ANYs
4011 * since the any decode routines decode
4012 * their own first tag/len pair
4016 fprintf (src
, " %s", varName
);
4018 fprintf (src
, "->");
4022 defByNamedType
= e
->type
->basicType
->a
.anyDefinedBy
->link
;
4023 if (GetBuiltinType (defByNamedType
->type
) == BASICTYPE_OID
)
4025 fprintf (src
, "SetTypeByOid (");
4026 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
4027 fprintf (src
, " *");
4028 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
4032 fprintf (src
, "SetTypeByInt (");
4033 if (defByNamedType
->type
->cxxTypeRefInfo
->isPtr
)
4034 fprintf (src
, " *");
4035 fprintf (src
, "%s);\n", defByNamedType
->type
->cxxTypeRefInfo
->fieldName
);
4038 fprintf (src
, " %s", varName
);
4040 fprintf (src
, "->");
4043 fprintf (src
, "B%s (b, setBytesDecoded, env);\n", r
->decodeBaseName
);
4045 else if (tmpTypeId
== BASICTYPE_ANY
)
4048 * must check for another EOC for ANYs
4049 * since the any decode routines decode
4050 * their own first tag/len pair
4058 fprintf (src
, " %s", varName
);
4060 fprintf (src
, "->");
4063 fprintf (src
, "SetTypeBy???(???);\n");
4065 fprintf (src
, " %s", varName
);
4067 fprintf (src
, "->");
4070 fprintf (src
, "B%s (b, setBytesDecoded, env);\n", r
->decodeBaseName
);
4076 fprintf (src
, " DEC_LOAD_ANYBUF(");
4079 fprintf (src
, "%s, b, setBytesDecoded, env);\n", varName
);
4085 fprintf (src
, " %s", varName
);
4087 fprintf (src
, "->");
4091 fprintf (src
, "B%s (b, tag1, elmtLen%d, setBytesDecoded, env);\n", r
->decodeContentBaseName
, elmtLevel
);
4094 /* decode Eoc (s) */
4095 for (i
= elmtLevel
-1; i
>= 1; i
--)
4097 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
4098 fprintf (src
, " BDecEoc (b, setBytesDecoded, env);\n\n");
4101 /* keep track of decoded non-optional elmts */
4102 if (!e
->type
->optional
&& (e
->type
->defaultVal
== NULL
))
4104 mandatoryElmtCount
++;
4105 fprintf (src
, " mandatoryElmtsDecoded++;\n");
4107 fprintf (src
, " break;\n\n");
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
--);
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
--);
4127 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
4128 #endif /* SNACC_EXCEPTION_ENABLE */
4129 fprintf (src
, " }\n");
4131 } /* if not empty set clause */
4133 fprintf (src
, "} // %s::B%s\n\n", td
->cxxTypeDefInfo
->className
, r
->decodeContentBaseName
);
4135 /* end of decode content method code */
4140 fprintf (hdr
, " %s B%s (%s b);\n", lenTypeNameG
, r
->encodeBaseName
, bufTypeNameG
);
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
);
4148 /* encode each tag/len pair if any */
4149 FOR_EACH_LIST_ELMT_RVS (tag
, set
->tags
)
4151 classStr
= Class2ClassStr (tag
->tclass
);
4152 formStr
= Form2FormStr (CONS
); /* set's are constructed */
4153 tagLen
= TagByteLen (tag
->code
);
4155 fprintf (src
, " l += BEncConsLen (b, l);\n");
4157 if (tag
->tclass
== UNIV
)
4158 fprintf (src
, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen
, classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
4160 fprintf (src
, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen
, classStr
, formStr
, tag
->code
);
4162 fprintf (src
, " return l;\n");
4163 fprintf (src
, "}\n\n");
4165 /* end of BerEncode */
4170 fprintf (hdr
, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r
->decodeBaseName
, bufTypeNameG
, lenTypeNameG
, envTypeNameG
);
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
);
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");
4181 /* decode tag/length pair (s) */
4183 FOR_EACH_LIST_ELMT (tag
, set
->tags
)
4185 classStr
= Class2ClassStr (tag
->tclass
);
4186 formStr
= Form2FormStr (CONS
); /* sets are constructed */
4188 fprintf (src
, " if ((tag = BDecTag (b, bytesDecoded, env)) != ");
4190 if (tag
->tclass
== UNIV
)
4191 fprintf (src
, "MAKE_TAG_ID (%s, %s, %s))\n", classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
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
--);
4199 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
4200 #endif /* SNACC_EXCEPTION_ENABLE */
4201 fprintf (src
, " }\n");
4203 fprintf (src
, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
4206 fprintf (src
, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r
->decodeContentBaseName
, i
-1);
4208 /* grab any EOCs that match redundant, indef lengths */
4209 for (i
= elmtLevel
-1; i
> 0; i
--)
4211 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
4212 fprintf (src
, " BDecEoc (b, bytesDecoded, env);\n");
4215 fprintf (src
, "}\n\n");
4217 /* end of BerDecode */
4219 PrintPduMemberFcns (src
, hdr
, r
, td
->cxxTypeDefInfo
->className
);
4221 /* write code for printing */
4224 fprintf (hdr
, " void Print (ostream &os) const;\n");
4226 fprintf (src
, "void %s::Print (ostream &os) const\n", td
->cxxTypeDefInfo
->className
);
4227 fprintf (src
, "{\n");
4229 fprintf (src
, "#ifndef NDEBUG\n");
4231 allOpt
= AllElmtsOptional (set
->basicType
->a
.set
);
4233 fprintf (src
, " int nonePrinted = true;\n");
4235 fprintf (src
, " os << \"{ -- SET --\" << endl;\n");
4236 fprintf (src
, " indentG += stdIndentG;\n\n");
4238 FOR_EACH_LIST_ELMT (e
, set
->basicType
->a
.set
)
4240 inTailOptElmts
= IsTailOptional (set
->basicType
->a
.set
);
4242 if (e
->type
->cxxTypeRefInfo
->isPtr
)
4243 fprintf (src
, " if (%s (%s))\n", cxxtri
->optTestRoutineName
, e
->type
->cxxTypeRefInfo
->fieldName
);
4245 fprintf (src
, " {\n");
4249 if (e
!= FIRST_LIST_ELMT (set
->basicType
->a
.set
))
4251 fprintf (src
, " if (!nonePrinted)\n");
4252 fprintf (src
, " os << \",\" << endl;\n");
4254 fprintf (src
, " nonePrinted = false;\n", i
);
4256 else if (inTailOptElmts
) /* cannot be first elmt ow allOpt is true */
4257 fprintf (src
, " os << \",\"<< endl;\n");
4259 fprintf (src
, " Indent (os, indentG);\n");
4261 if (e
->fieldName
!= NULL
)
4262 fprintf (src
, " os << \"%s \";\n", e
->fieldName
);
4264 if (e
->type
->cxxTypeRefInfo
->isPtr
)
4265 fprintf (src
, " os << *%s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
4267 fprintf (src
, " os << %s;\n", e
->type
->cxxTypeRefInfo
->fieldName
);
4269 if (e
!= LAST_LIST_ELMT (set
->basicType
->a
.set
) && !inTailOptElmts
&& !NextIsTailOptional (set
->basicType
->a
.set
))
4270 fprintf (src
, " os << \",\" << endl;\n");
4272 fprintf (src
, " }\n");
4274 if (e
->type
->cxxTypeRefInfo
->isPtr
)
4276 fprintf (src
, " else\n");
4278 fprintf (src
, " os << \"-- void2 --\\n\";\n");
4280 fprintf (src
, " os << \"-- void --\";\n");
4284 fprintf (src
, "\n");
4286 if (e
== LAST_LIST_ELMT (set
->basicType
->a
.set
))
4287 fprintf (src
, " os << endl;\n");
4289 fprintf (src
, " indentG -= stdIndentG;\n");
4290 fprintf (src
, " Indent (os, indentG);\n");
4291 fprintf (src
, " os << \"}\";\n");
4293 fprintf (src
, "#endif /* NDEBUG */\n");
4295 fprintf (src
, "} // %s - operator <<\n\n\n", td
->cxxTypeDefInfo
->className
);
4297 /* end of print method code */
4299 /* close class definition */
4300 fprintf (hdr
, "};\n\n\n");
4302 } /* PrintCxxSetDefCode */
4306 * This major Bogosity results from gcc2.2.2 inability to handle
4310 PrintCxxListClass
PARAMS ((src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, parent
, lst
),
4313 if_IBM_ENC (FILE *srcdb _AND_
)
4314 if_IBM_ENC (FILE *hdrdb _AND_
)
4315 ModuleList
*mods _AND_
4322 char *lcn
; /* list class name */
4323 char *ecn
; /* (list) elmt class name */
4330 lcn
= td
->cxxTypeDefInfo
->className
;
4331 ecn
= lst
->basicType
->a
.setOf
->cxxTypeRefInfo
->className
;
4334 #include "./ibm_editor/print_cxx_list_class.h"
4335 #endif /* _IBM_ENC_ */
4337 fprintf (hdr
, "class %s%s\n", lcn
, baseClassesG
);
4338 fprintf (hdr
, "{\n");
4339 fprintf (hdr
, "protected:\n");
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");
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");
4353 fprintf (hdr
, "public:\n");
4358 const char *emtn
= "?";
4359 switch (lst
->basicType
->choiceId
)
4361 case BASICTYPE_SEQUENCEOF
:
4362 emtn
= "SEQUENCE_OF";
4364 case BASICTYPE_SETOF
:
4369 fprintf (hdr
, "#if META\n");
4370 fprintf (src
, "#if META\n\n");
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");
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");
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");
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");
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");
4425 fprintf (hdr
, "#if TCL\n");
4426 fprintf (src
, "#if TCL\n\n");
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");
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");
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");
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");
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");
4493 fprintf (hdr
, "#endif // TCL\n");
4494 fprintf (src
, "#endif // TCL\n\n");
4498 fprintf (hdr
, "#endif // META\n\n");
4499 fprintf (src
, "#endif // META\n\n");
4504 fprintf (hdr
, " %s() { count = 0; first = curr = last = NULL; }\n", lcn
);
4506 fprintf (hdr
, " %s (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
4508 fprintf (hdr
, " virtual ~%s();\n", td
->cxxTypeDefInfo
->className
);
4510 /* print clone routine for ANY mgmt */
4511 PrintCloneMethod (hdr
, src
, td
);
4513 fprintf (hdr
, " %s &operator = (const %s &);\n", td
->cxxTypeDefInfo
->className
, td
->cxxTypeDefInfo
->className
);
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");
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
);
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
);
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
);
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
);
4545 fprintf (hdr
, " // removing the current elmt from the list\n");
4546 fprintf (hdr
, " void RemoveCurrFromList();\n\n");
4548 fprintf (hdr
, " // encode and decode routines \n");
4550 /* print PDU oriented encode routine */
4553 fprintf (hdr
, " %s B%s (%s b);\n", lenTypeNameG
, r
->encodeBaseName
, bufTypeNameG
);
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
);
4559 /* encode the list content */
4560 fprintf (src
, " l = B%s (b);\n", r
->encodeContentBaseName
);
4562 /* encode each tag/len pair if any */
4563 FOR_EACH_LIST_ELMT_RVS (tag
, lst
->tags
)
4565 classStr
= Class2ClassStr (tag
->tclass
);
4566 formStr
= Form2FormStr (CONS
); /* choices are constructed */
4567 tagLen
= TagByteLen (tag
->code
);
4569 /* always constructed lengths for list */
4570 fprintf (src
, " l += BEncConsLen (b, l);\n");
4572 if (tag
->tclass
== UNIV
)
4573 fprintf (src
, " l += BEncTag%d (b, %s, %s, %s);\n", tagLen
, classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
4575 fprintf (src
, " l += BEncTag%d (b, %s, %s, %d);\n", tagLen
, classStr
, formStr
, tag
->code
);
4577 fprintf (src
, " return l;\n");
4578 fprintf (src
, "}\n\n");
4580 /* end of ber encode function */
4582 /* do BerDecode function */
4585 fprintf (hdr
, " void B%s (%s b, %s &bytesDecoded, %s env);\n", r
->decodeBaseName
, bufTypeNameG
, lenTypeNameG
, envTypeNameG
);
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
);
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");
4596 /* decode tag/length pair (s) */
4598 FOR_EACH_LIST_ELMT (tag
, lst
->tags
)
4600 classStr
= Class2ClassStr (tag
->tclass
);
4601 formStr
= Form2FormStr (CONS
); /* lists are constructed */
4603 fprintf (src
, " if ((tag = BDecTag (b, bytesDecoded, env)) != ");
4605 if (tag
->tclass
== UNIV
)
4606 fprintf (src
, "MAKE_TAG_ID (%s, %s, %s))\n", classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
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
--);
4614 fprintf (src
, " longjmp (env, %d);\n", longJmpValG
--);
4615 #endif /* SNACC_EXCEPTION_ENABLE */
4616 fprintf (src
, " }\n");
4618 fprintf (src
, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
4621 fprintf (src
, " B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r
->decodeContentBaseName
, elmtLevel
);
4623 /* grab any EOCs that match redundant, indef lengths */
4624 for (i
= elmtLevel
-1; i
> 0; i
--)
4626 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
4627 fprintf (src
, " BDecEoc (b, bytesDecoded, env);\n");
4630 fprintf (src
, "}\n\n");
4632 /* end of BDec function */
4636 fprintf (hdr
, " %s B%s (%s b);\n", lenTypeNameG
, r
->encodeContentBaseName
, bufTypeNameG
);
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
);
4641 fprintf (hdr
, " PDU_MEMBER_MACROS\n");
4643 if (printPrintersG
) {
4644 fprintf (hdr
, " void Print (ostream &os) const;\n");
4646 fprintf (hdr
, "};\n\n\n");
4648 } /* PrintCxxListClass */
4652 * Prints code to decode and check tags and lengths for a
4653 * SEQ OF/SET OF element.
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
4662 * Assumes first tag has been decoded and is in 'tag1' var
4665 PrintCxxListTagAndLenDecCode
PARAMS ((src
, td
, t
),
4673 int stoleChoiceTags
;
4677 tags
= GetTags (t
, &stoleChoiceTags
);
4678 if (stoleChoiceTags
)
4680 fprintf (src
, " if (!(");
4681 FOR_EACH_LIST_ELMT (tag
, tags
)
4683 fprintf (src
, "(tag1 == ");
4684 PrintMakeTag (src
, tag
);
4685 if (tag
->form
== ANY_FORM
)
4687 fprintf (src
, ")\n || (tag1 == ");
4689 PrintMakeTag (src
, tag
);
4690 fprintf (src
, ")\n");
4695 if (tag
!= (Tag
*)LAST_LIST_ELMT (tags
))
4696 fprintf (src
, "\n || ");
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
--);
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
);
4710 else /* didn't steal nested choice's tags */
4712 AsnListFirst (tags
);
4714 FOR_EACH_LIST_ELMT (tag
, tags
)
4717 fprintf (src
, " if ((tag1 != ");
4718 PrintMakeTag (src
, tag
);
4719 if (tag
->form
== ANY_FORM
)
4721 fprintf (src
, ")\n && (tag1 != ");
4723 PrintMakeTag (src
, tag
);
4724 fprintf (src
, "))\n");
4727 fprintf (src
, "))\n");
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
--);
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
);
4739 if (tag
!= (Tag
*)LAST_LIST_ELMT (tags
))
4740 fprintf (src
, " tag1 = BDecTag (b, listBytesDecoded, env);\n\n");
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
4749 if (GetBuiltinType (t
) == BASICTYPE_CHOICE
)
4751 fprintf (src
, " tag1 = BDecTag (b, listBytesDecoded, env);\n");
4752 fprintf (src
, " elmtLen%d = BDecLen (b, listBytesDecoded, env);\n", ++elmtLevel
);
4756 } /* PrintCxxListTagAndLenDecCode */
4759 * This major Bogosity results from gcc2.2.2 inability to handle
4760 * templates properly
4763 PrintCxxListMethods
PARAMS ((src
, hdr
, mods
, m
, r
, td
, parent
, lst
, novolatilefuncs
),
4766 ModuleList
*mods _AND_
4772 int novolatilefuncs
)
4774 char *lcn
; /* list class name */
4775 char *ecn
; /* (list) elmt class name */
4778 enum BasicTypeChoiceId tmpTypeId
;
4784 lcn
= td
->cxxTypeDefInfo
->className
;
4785 ecn
= lst
->basicType
->a
.setOf
->cxxTypeRefInfo
->className
;
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");
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");
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
)
4827 fprintf (src
, " return *this;\n");
4829 fprintf (src
, "#endif // SNACC_DEEP_COPY\n");
4830 fprintf (src
, "}\n\n");
4834 fprintf (src
, "void %s::Print (ostream &os) const\n", td
->cxxTypeDefInfo
->className
);
4835 fprintf (src
, "{\n");
4837 fprintf (src
, "#ifndef NDEBUG\n");
4839 fprintf (src
, " os << \"{ -- SEQUENCE/SET OF -- \" << endl;\n");
4840 fprintf (src
, " indentG += stdIndentG;\n");
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");
4855 fprintf (src
, " indentG -= stdIndentG;\n");
4856 fprintf (src
, " Indent (os, indentG);\n");
4858 fprintf (src
, " os << \"}\\n\";\n");
4860 fprintf (src
, " os << \"}\";\n");
4864 fprintf (src
, "#endif /* NDEBUG */\n\n\n");
4866 fprintf (src
, "} // Print\n\n\n");
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
);
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
);
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
);
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
);
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
);
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
);
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");
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
);
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
);
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
);
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");
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
);
5171 if (gVDADER_RULES
&& lst
->basicType
->choiceId
!= BASICTYPE_SETOF
)
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");
5179 tmpTypeId
= GetBuiltinType (lst
->basicType
->a
.setOf
);
5180 /* list element types cannot by ANY DEFINED BY */
5181 if (tmpTypeId
== BASICTYPE_ANY
)
5183 fprintf (src
, " currElmt->elmt->SetTypeBy???(???);\n");
5184 fprintf (src
, " elmtLen = currElmt->elmt->B%s (b);\n", r
->encodeBaseName
);
5188 fprintf (src
, " elmtLen = currElmt->elmt->B%s (b);\n", r
->encodeContentBaseName
);
5191 /* encode list elmt tag/len pairs here */
5192 PrintCxxTagAndLenEncodingCode (src
, td
, lst
->basicType
->a
.setOf
, "elmtLen", "b");
5194 fprintf (src
, " totalLen += elmtLen;\n");
5195 fprintf (src
, " }\n");
5199 /** handling of SET OF encoding
5201 else if (gVDADER_RULES
&& lst
->basicType
->choiceId
== BASICTYPE_SETOF
)
5202 VDA_ProcessSetOf(src
, td
, lst
, r
);
5205 fprintf (src
, " return totalLen;\n");
5206 fprintf (src
, "} // %s::B%s\n\n\n", lcn
, r
->encodeContentBaseName
);
5207 } /** END IF for printDecodersG **/
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
);
5217 tmpTypeId
= GetBuiltinType (lst
->basicType
->a
.setOf
);
5219 if ( tmpTypeId
!= BASICTYPE_ANY
|| ! gVDADER_RULES
)
5220 fprintf (src
, " %s tag1;\n", tagTypeNameG
);
5223 fprintf (src
, " %s listBytesDecoded = 0;\n", lenTypeNameG
);
5225 /* print local vars elmtLen for decoding list component */
5226 elmtLevel
= CxxCountVariableLevels (lst
->basicType
->a
.setOf
);
5228 for (i
= 1; i
<= elmtLevel
; i
++)
5229 fprintf (src
, " %s elmtLen%d;\n", lenTypeNameG
, i
);
5231 fprintf (src
, "\n");
5234 fprintf (src
, " while ((listBytesDecoded < elmtLen0) || (elmtLen0 == INDEFINITE_LEN))\n");
5235 fprintf (src
, " {\n");
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 **/
5245 fprintf (src
, " tag1 = BDecTag (b, listBytesDecoded, env);\n");
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");
5253 PrintCxxListTagAndLenDecCode (src
, td
, lst
->basicType
->a
.setOf
);
5255 fprintf (src
, " listElmt = Append();\n");
5258 fprintf (src
, " listElmt->B%s (b, tag1, elmtLen%d, listBytesDecoded, env);\n", r
->decodeContentBaseName
, elmtLevel
);
5263 fprintf (src
, " listElmt = Append();\n");
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
)
5276 fprintf (src
, " listElmt->SetTypeBy???(???);\n");
5278 fprintf (src
, " listElmt->B%s (b, listBytesDecoded, env);\n", r
->decodeBaseName
, elmtLevel
);
5284 fprintf (src
, " DEC_LOAD_ANYBUF(");
5285 fprintf (src
, "listElmt, b, listBytesDecoded, env);\n");
5289 } /* end of if BASIC_ANY_TYPE */
5291 fprintf (src
, " listElmt->B%s (b, tag1, elmtLen%d, listBytesDecoded, env);\n", r
->decodeContentBaseName
, elmtLevel
);
5293 /* grab any EOCs that match redundant, indef lengths */
5294 for (i
= elmtLevel
-1; i
> 0; i
--)
5296 fprintf (src
, " if (elmtLen%d == INDEFINITE_LEN)\n", i
);
5297 fprintf (src
, " BDecEoc (b, listBytesDecoded, env);\n");
5301 fprintf (src
, " }\n\n"); /* end of while */
5303 fprintf (src
, " bytesDecoded += listBytesDecoded;\n");
5305 fprintf (src
, "} // %s::B%s\n\n\n", lcn
, r
->decodeContentBaseName
);
5308 } /* PrintCxxListMethods */
5311 PrintCxxSetOfDefCode
PARAMS ((src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, parent
, setOf
, novolatilefuncs
),
5314 if_IBM_ENC (FILE *srcdb _AND_
)
5315 if_IBM_ENC (FILE *hdrdb _AND_
)
5316 ModuleList
*mods _AND_
5322 int novolatilefuncs
)
5325 PrintCxxListClass (src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, parent
, setOf
);
5328 PrintCxxListMethods (src
, hdr
, mods
, m
, r
, td
, parent
, setOf
, novolatilefuncs
);
5330 } /* PrintCxxSetOfDefCode */
5334 PrintCxxAnyDefCode
PARAMS ((src
, hdr
, mods
, m
, r
, td
, parent
, any
),
5337 ModuleList
*mods _AND_
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 */
5352 PrintCxxTypeDefCode
PARAMS ((src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, novolatilefuncs
),
5355 if_IBM_ENC (FILE *srcdb _AND_
)
5356 if_IBM_ENC (FILE *hdrdb _AND_
)
5357 ModuleList
*mods _AND_
5361 int novolatilefuncs
)
5365 switch (td
->type
->basicType
->choiceId
)
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
);
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
);
5383 case BASICTYPE_IMPORTTYPEREF
: /* type references */
5384 case BASICTYPE_LOCALTYPEREF
:
5386 * if this type has been re-tagged then
5387 * must create new class instead of using a typedef
5389 PrintCxxSimpleDef (hdr
, src
, if_IBM_ENC (hdrdb COMMA srcdb COMMA
) if_META (m COMMA
) r
, td
);
5392 case BASICTYPE_ANYDEFINEDBY
: /* ANY types */
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");
5398 PrintCxxAnyDefCode (src
, hdr
, mods
, m
, r
, td
, NULL
, td
->type
);
5401 case BASICTYPE_CHOICE
:
5402 PrintCxxChoiceDefCode (src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, NULL
, td
->type
, novolatilefuncs
);
5406 PrintCxxSetDefCode (src
, hdr
, mods
, m
, r
, td
, NULL
, td
->type
, novolatilefuncs
);
5409 case BASICTYPE_SEQUENCE
:
5410 PrintCxxSeqDefCode (src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, NULL
, td
->type
, novolatilefuncs
);
5413 case BASICTYPE_COMPONENTSOF
:
5414 case BASICTYPE_SELECTION
:
5415 case BASICTYPE_UNKNOWN
:
5416 case BASICTYPE_MACRODEF
:
5417 case BASICTYPE_MACROTYPE
:
5421 } /* PrintCxxTypeDefCode */
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
),
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_
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_
5442 if_TCL (_AND_
int printTcl
) _AND_
5443 int novolatilefuncs
)
5449 #endif /* _IBM_ENC_ */
5451 longJmpValG
= longJmpVal
;
5452 printTypesG
= printTypes
;
5453 printEncodersG
= printEncoders
;
5454 printDecodersG
= printDecoders
;
5455 printPrintersG
= printPrinters
;
5456 printFreeG
= printFree
;
5458 printMetaG
= printMeta
;
5459 meta_pdus_G
= meta_pdus
;
5461 printTclG
= printTcl
;
5465 PrintSrcComment (src
, m
);
5466 PrintHdrComment (hdr
, m
);
5468 PrintSrcComment (srcdb
, m
); /* 20.8.93 IBM-ENC */
5469 PrintHdrComment (hdrdb
, m
); /* 20.8.93 IBM-ENC */
5471 strcpy (mm_name
, m
->cxxHdrFileName
);
5472 #endif /* _IBM_ENC_ */
5474 PrintConditionalIncludeOpen (hdr
, m
->cxxHdrFileName
);
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_ */
5485 fprintf (src
, "\n");
5486 fprintf (src
, "#ifndef META\n");
5487 fprintf (src
, "#define META 1\n");
5488 fprintf (src
, "#endif\n");
5492 fprintf (src
, "#ifndef TCL\n");
5493 fprintf (src
, "#define TCL META\n");
5494 fprintf (src
, "#endif\n");
5500 fprintf (src
, "\n");
5502 PrintSrcIncludes (src
, if_IBM_ENC (srcdb COMMA
) mods
, m
);
5504 fprintf (src
, "\n");
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");
5515 fprintf (hdr
, "#if META\n");
5516 fprintf (src
, "#if META\n\n");
5518 fprintf (hdr
, "//------------------------------------------------------------------------------\n");
5519 fprintf (hdr
, "extern const AsnModuleDesc %sModuleDesc;\n", m
->cxxname
);
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 */
5532 fprintf (src
, "const AsnModuleDesc %sModuleDesc = { \"%s\", %sModuleTypes };\n\n", m
->cxxname
, m
->modId
->name
, m
->cxxname
);
5534 fprintf (hdr
, "#endif // META\n\n");
5535 fprintf (src
, "#endif // META\n\n");
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");
5548 fprintf (hdr
, "//------------------------------------------------------------------------------\n");
5549 fprintf (hdr
, "// class definitions:\n\n");
5550 fprintf (src
, "//------------------------------------------------------------------------------\n");
5551 fprintf (src
, "// class member definitions:\n\n");
5553 PrintCxxAnyCode (src
, hdr
, r
, mods
, m
);
5555 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
5556 PrintCxxTypeDefCode (src
, hdr
, if_IBM_ENC (srcdb COMMA hdrdb COMMA
) mods
, m
, r
, td
, novolatilefuncs
);
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
);
5566 fprintf (hdr
, "//------------------------------------------------------------------------------\n");
5567 PrintConditionalIncludeClose (hdr
, m
->cxxHdrFileName
);
5570 fprintf (hdrdb
, "#endif\n");
5571 #endif /* _IBM_ENC_ */
5572 } /* PrintCxxCode */
5577 /* this routine will generate code which will encode a SET OF in using DER
5580 long VDA_ProcessSetOf(FILE *src
,
5585 enum BasicTypeChoiceId tmpTypeId
;
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");
5597 tmpTypeId
= GetBuiltinType (lst
->basicType
->a
.setOf
);
5599 /* list element types cannot by ANY DEFINED BY */
5600 if (tmpTypeId
== BASICTYPE_ANY
)
5602 fprintf (src
, " tmpEnc[iii] = (CSM_Buffer *)currElmt->elmt->value;\n");
5605 { /** SEE "smimesnacc.h" for a description of these ODD macros, to
5608 fprintf (src
, " ENCODE_BUF1(currElmt->elmt->B%s, elmtLen);\n", r
->encodeContentBaseName
);
5610 /** encode content only into buffer.
5612 PrintCxxTagAndLenEncodingCode (src
, td
, lst
->basicType
->a
.setOf
,
5613 "elmtLen", "outputBuf");
5615 /** set tag and length in "outputBuf" buffer (DEFINED IN MACRO).
5617 fprintf (src
, " ENCODE_BUF2(tmpEnc[iii]);\n");
5619 /** extract buffer to "Str_struct *".
5622 fprintf (src
, " }\n");
5624 /* encode list elmt tag/len pairs here */
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.
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).
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");
5648 } /** END else BASICTYPE_SETOF, RWC; only for VDADER_RULES define **/