2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * compiler/back-ends/c-gen/gen-dec.c - routines for printing C decoders from type trees
22 * The type tree has already been run through the c type generator
23 * (type-info.c). Types that the type generator didn't know how
24 * to handle (or didn't want/need to handle eg macros) get the
25 * C_NO_TYPE label and are ignored for code generation.
27 * NOTE: this is a real rats nest - it sort of evolved. It was
28 * written assuming SETs/SEQ/CHOICE etc could be nested
29 * hence all the crap about 'levels'.
33 * Copyright (C) 1991, 1992 Michael Sample
34 * and the University of British Columbia
36 * This program is free software; you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation; either version 2 of the License, or
39 * (at your option) any later version.
41 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/compiler/back-ends/c-gen/gen-dec.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
43 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
44 * Move from private repository to open source repository
46 * Revision 1.2 2001/05/05 00:59:28 rmurphy
47 * Adding darwin license headers
49 * Revision 1.1.1.1 1999/03/16 18:06:41 aram
50 * Originals from SMIME Free Library.
52 * Revision 1.4 1997/02/28 13:39:54 wan
53 * Modifications collected for new version 1.3: Bug fixes, tk4.2.
55 * Revision 1.3 1995/07/25 18:41:01 rj
56 * file name has been shortened for redundant part: c-gen/gen-c-dec -> c-gen/gen-dec.
58 * changed `_' to `-' in file names.
60 * Revision 1.2 1994/09/01 00:22:06 rj
61 * snacc_config.h and other superfluous .h files removed.
63 * Revision 1.1 1994/08/28 09:48:20 rj
64 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
71 #include "asn1module.h"
74 #include "lib-types.h"
76 #include "type-info.h"
78 #include "snacc-util.h"
84 static CRules
*genDecCRulesG
;
85 char *valueArgNameG
= "v";
86 static long int *longJmpValG
;
87 static char *decodedLenVarNameG
= "totalElmtsLen";
88 static char *itemLenVarNameG
= "elmtLen";
89 static char *mecVarNameG
= "mandatoryElmtCount";
90 static char *tagIdVarNameG
= "tagId";
91 char *bufTypeNameG
= "BUF_TYPE";
92 char *lenTypeNameG
= "AsnLen";
93 char *tagTypeNameG
= "AsnTag";
94 char *envTypeNameG
= "ENV_TYPE";
98 /* non-exported prototypes */
100 static void PrintCBerDecoderPrototype
PROTO ((FILE *hdr
, TypeDef
*td
));
101 static void PrintCBerDecoderDeclaration
PROTO ((FILE *src
, TypeDef
*td
));
102 static void PrintCBerDecoderDefine
PROTO ((FILE *src
, TypeDef
*td
));
104 static int RecCountVariableLevels
PROTO ((Type
*t
));
105 static int CountVariableLevels
PROTO ((Type
*t
));
106 static void PrintCBerDecoderLocals
PROTO ((FILE *src
, TypeDef
*td
));
107 static void PrintCBerListDecoderLocals
PROTO ((FILE *src
));
109 static void PrintCBerSetDecodeCode
PROTO ((FILE *src
, TypeDef
*td
, Type
*parent
, NamedTypeList
*e
, int elmtLevel
, int totalLevel
, int tagLevel
, char *varName
));
111 static void PrintCBerSeqDecodeCode
PROTO ((FILE *src
, TypeDef
*td
, Type
*parent
, NamedTypeList
*e
, int elmtLevel
, int totalLevel
, int tagLevel
, char *varName
));
113 static void PrintCBerListDecoderCode
PROTO ((FILE *src
, TypeDef
*td
, Type
*t
, int elmtLevel
, int totalLevel
, int tagLevel
, char *varName
));
115 static void PrintCBerChoiceDecodeCode
PROTO ((FILE *src
, TypeDef
*td
, Type
*t
, int elmtLevel
, int totalLevel
, int tagLevel
, char *varName
));
117 static void PrintCLenDecodingCode
PROTO ((FILE *f
));
119 static void PrintCBerDecoderIncludes
PROTO ((FILE *src
, Module
*m
, ModuleList
*mods
));
121 static void PrintCBerElmtDecodeCode
PROTO ((FILE *src
, TypeDef
*td
, Type
*parent
, Type
*t
, int elmtLevel
, int totalLevel
, int tagLevel
, char *parnetVarName
, char *elmtVarName
, int stoleChoiceTags
));
125 PrintCBerDecoder
PARAMS ((src
, hdr
, r
, m
, td
, longJmpVal
),
131 long int *longJmpVal
)
134 enum BasicTypeChoiceId typeId
;
143 ctdi
= td
->cTypeDefInfo
;
144 if (!ctdi
->genDecodeRoutine
)
148 * if is type that refs another pdu type or lib type
149 * without generating a new type via tagging or named elmts
150 * print define to the hdr file
151 * (a type is a pdu by default if it is ref'd by an ANY)
153 if (!IsNewType (td
->type
) &&
154 (!IsTypeRef (td
->type
) ||
155 (IsTypeRef (td
->type
) &&
156 (td
->type
->basicType
->a
.localTypeRef
->link
->cTypeDefInfo
->isPdu
||
157 ((td
->type
->basicType
->a
.localTypeRef
->link
->anyRefs
!= NULL
) &&
158 !LIST_EMPTY (td
->type
->basicType
->a
.localTypeRef
->link
->anyRefs
))))))
160 fprintf(hdr
,"#define B%s B%s\n", td
->cTypeDefInfo
->decodeRoutineName
, td
->type
->cTypeRefInfo
->decodeRoutineName
);
162 fprintf(hdr,"#define B%s(b, v, bytesDecoded, env) B%s(b, v, bytesDecoded, env)\n", td->cTypeDefInfo->decodeRoutineName, td->type->cTypeRefInfo->decodeRoutineName);
169 typeId
= GetBuiltinType (td
->type
);
171 /* print proto type to hdr file */
172 fprintf (hdr
, "void B%s PROTO ((%s b, %s *result, %s *bytesDecoded, %s env));\n", ctdi
->decodeRoutineName
, bufTypeNameG
, ctdi
->cTypeName
, lenTypeNameG
, envTypeNameG
);
174 /* print routine in src */
175 fprintf (src
,"void B%s PARAMS ((b, result, bytesDecoded, env),\n", ctdi
->decodeRoutineName
);
176 fprintf (src
,"%s b _AND_\n", bufTypeNameG
);
177 fprintf (src
,"%s *result _AND_\n", ctdi
->cTypeName
);
178 fprintf (src
,"%s *bytesDecoded _AND_\n", lenTypeNameG
);
179 fprintf (src
,"%s env)\n", envTypeNameG
);
181 fprintf (src
," %s tag;\n", tagTypeNameG
);
183 /* print extra locals for redundant lengths */
184 tags
= GetTags (td
->type
, &stoleChoiceTags
);
185 for (i
= 1; !stoleChoiceTags
&& (i
<= LIST_COUNT (tags
)); i
++)
186 fprintf (src
," %s elmtLen%d;\n", lenTypeNameG
, i
);
188 /* add extra len for choice */
189 if (typeId
== BASICTYPE_CHOICE
)
190 fprintf (src
," %s elmtLen%d;\n", lenTypeNameG
, i
);
194 /* decode tag/length pairs */
196 if (!stoleChoiceTags
)
198 FOR_EACH_LIST_ELMT (tag
, tags
)
200 classStr
= Class2ClassStr (tag
->tclass
);
201 if (tag
->form
== ANY_FORM
)
202 formStr
= Form2FormStr (PRIM
);
204 formStr
= Form2FormStr (tag
->form
);
206 fprintf (src
," if (((tag = BDecTag (b, bytesDecoded, env)) != \n");
208 if (tag
->tclass
== UNIV
)
210 fprintf (src
,"MAKE_TAG_ID (%s, %s, %s))", classStr
, formStr
, Code2UnivCodeStr (tag
->code
));
211 if (tag
->form
== ANY_FORM
)
212 fprintf (src
,"&&\n (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr
, Form2FormStr (CONS
), Code2UnivCodeStr (tag
->code
));
218 fprintf (src
,"MAKE_TAG_ID (%s, %s, %d))", classStr
, formStr
, tag
->code
);
219 if (tag
->form
== ANY_FORM
)
220 fprintf (src
,"&&\n (tag != MAKE_TAG_ID (%s, %s, %d)))\n", classStr
, Form2FormStr (CONS
), tag
->code
);
225 fprintf (src
," {\n");
226 fprintf (src
," Asn1Error (\"B%s: ERROR - wrong tag\\n\");\n", ctdi
->decodeRoutineName
);
227 fprintf (src
," longjmp (env, %d);\n", (*longJmpVal
)--);
228 fprintf (src
," }\n");
230 fprintf (src
," elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
234 /* for choices always decode first tag of the choice's content */
235 if (typeId
== BASICTYPE_CHOICE
)
237 fprintf (src
," tag = BDecTag (b, bytesDecoded, env);\n");
238 fprintf (src
," elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel
);
241 if ((typeId
!= BASICTYPE_ANY
) && (typeId
!= BASICTYPE_ANYDEFINEDBY
))
242 fprintf (src
," B%sContent (b, tag, elmtLen%d, result, bytesDecoded, env);\n", ctdi
->decodeRoutineName
, elmtLevel
);
244 fprintf (src
," B%s (b, result, bytesDecoded, env);\n", ctdi
->decodeRoutineName
, elmtLevel
);
247 /* grab any EOCs that match redundant, indef lengths */
248 for (i
= elmtLevel
-1; i
> 0; i
--)
250 fprintf (src
," if (elmtLen%d == INDEFINITE_LEN)\n", i
);
251 fprintf (src
," BDecEoc (b, bytesDecoded, env);\n");
255 fprintf (src
,"} /* B%s */\n\n", ctdi
->decodeRoutineName
);
258 } /* PrintCBerDecoder */
262 PrintCBerContentDecoder
PARAMS ((src
, hdr
, r
, m
, td
, longJmpVal
),
268 long int *longJmpVal
)
272 CTypeId rhsTypeId
; /* cTypeId of the type that defined this typedef */
276 longJmpValG
= longJmpVal
;
280 ctdi
= td
->cTypeDefInfo
;
281 if ((ctdi
== NULL
) || (td
->type
->cTypeRefInfo
== NULL
))
283 fprintf (stderr
,"PrintCBerDecoder: ERROR - no type info\n");
287 if (!ctdi
->genDecodeRoutine
)
290 rhsTypeId
= td
->type
->cTypeRefInfo
->cTypeId
;
294 * type refs or primitive types are
295 * defined as calls to the referenced type
298 fprintf (hdr
, "/* ANY - Fix Me! */\n");
300 fprintf(hdr
, "#define B%s B%s\n", td
->cTypeDefInfo
->decodeRoutineName
, td
->type
->cTypeRefInfo
->decodeRoutineName
);
303 fprintf(hdr, "#define B%s( b, tagId, elmtLen, v, bytesDecoded, env) ", td->cTypeDefInfo->decodeRoutineName);
304 fprintf (hdr, "B%s (b, tagId, elmtLen, v, bytesDecoded, env)", td->type->cTypeRefInfo->decodeRoutineName);
306 fprintf (hdr
,"\n\n");
311 PrintCBerDecoderDefine (hdr
, td
);
312 fprintf (hdr
,"\n\n");
317 PrintCBerDecoderPrototype (hdr
, td
);
318 fprintf (hdr
,"\n\n");
319 PrintCBerDecoderDeclaration (src
, td
);
321 PrintCBerDecoderLocals (src
, td
);
322 fprintf (src
,"\n\n");
323 PrintCBerChoiceDecodeCode (src
, td
, td
->type
, FIRST_LEVEL
-1, FIRST_LEVEL
,FIRST_LEVEL
-1, valueArgNameG
);
325 fprintf (src
, " (*bytesDecoded) += totalElmtsLen1;\n");
326 fprintf (src
,"} /* B%sContent */",td
->cTypeDefInfo
->decodeRoutineName
);
327 fprintf (src
,"\n\n");
331 PrintCBerDecoderPrototype (hdr
, td
);
332 fprintf (hdr
,"\n\n");
333 PrintCBerDecoderDeclaration (src
, td
);
335 PrintCBerDecoderLocals (src
, td
);
336 fprintf (src
,"\n\n");
337 if (td
->type
->basicType
->choiceId
== BASICTYPE_SET
)
338 PrintCBerSetDecodeCode (src
, td
, td
->type
, td
->type
->basicType
->a
.set
, FIRST_LEVEL
-1, FIRST_LEVEL
, FIRST_LEVEL
-1, valueArgNameG
);
340 PrintCBerSeqDecodeCode (src
, td
, td
->type
, td
->type
->basicType
->a
.sequence
, FIRST_LEVEL
-1, FIRST_LEVEL
, FIRST_LEVEL
-1, valueArgNameG
);
342 fprintf (src
, " (*bytesDecoded) += totalElmtsLen1;\n");
343 fprintf (src
,"} /* B%sContent */",td
->cTypeDefInfo
->decodeRoutineName
);
344 fprintf (src
,"\n\n");
349 PrintCBerDecoderPrototype (hdr
, td
);
350 fprintf (hdr
,"\n\n");
352 PrintCBerDecoderDeclaration (src
, td
);
354 PrintCBerDecoderLocals (src
, td
);
355 fprintf (src
,"\n\n");
356 PrintCBerListDecoderCode (src
, td
, td
->type
, FIRST_LEVEL
-1, FIRST_LEVEL
, FIRST_LEVEL
-1, valueArgNameG
);
358 fprintf (src
, " (*bytesDecoded) += totalElmtsLen1;\n");
359 fprintf (src
,"} /* B%sContent */",td
->cTypeDefInfo
->decodeRoutineName
);
360 fprintf (src
,"\n\n");
364 /* fprintf (src,"< sorry, unsupported type >\n\n"); */
365 return; /* dont' print newlines */
369 fprintf (stderr
,"PrintCBerContentDecoder: ERROR - unknown c type id\n");
374 } /* PrintCBerContentDecoder */
380 * Prints prototype for decode routine in hdr file
384 PrintCBerDecoderPrototype
PARAMS ((hdr
, td
),
390 ctdi
= td
->cTypeDefInfo
;
391 fprintf (hdr
,"void B%sContent PROTO ((%s b, %s tagId%d, %s elmtLen%d, %s *v, %s *bytesDecoded, %s env));\n", ctdi
->decodeRoutineName
, bufTypeNameG
, tagTypeNameG
, FIRST_LEVEL
-1, lenTypeNameG
, FIRST_LEVEL
-1, ctdi
->cTypeName
,lenTypeNameG
, envTypeNameG
);
393 } /* PrintCBerDecoderPrototype */
398 * Prints declarations of decode routine for the given type def
401 PrintCBerDecoderDeclaration
PARAMS ((src
,td
),
407 ctdi
= td
->cTypeDefInfo
;
408 fprintf (src
,"void\n");
409 fprintf (src
,"B%sContent PARAMS ((b, tagId%d, elmtLen%d, v, bytesDecoded, env),\n", ctdi
->decodeRoutineName
, FIRST_LEVEL
-1, FIRST_LEVEL
-1);
410 fprintf (src
,"%s b _AND_\n", bufTypeNameG
);
411 fprintf (src
,"%s tagId%d _AND_\n", tagTypeNameG
, FIRST_LEVEL
-1);
412 fprintf (src
,"%s elmtLen%d _AND_\n", lenTypeNameG
, FIRST_LEVEL
-1);
413 fprintf (src
,"%s *v _AND_\n", ctdi
->cTypeName
);
414 fprintf (src
,"%s *bytesDecoded _AND_\n", lenTypeNameG
);
415 fprintf (src
,"%s env)\n", envTypeNameG
);
417 } /* PrintCBerDecoderDeclaration */
422 * makes a define for type refs or primitive type renaming
424 * TypeX ::= INTEGER --> #define BerDecodeTypeX(b,v) BerDecodeInteger(b,v)
425 * TypeX ::= TypeY --> #define BerDecodeTypeX(b,v) BerDecodeTypeY(b,v)
428 PrintCBerDecoderDefine
PARAMS ((hdr
, td
),
432 fprintf(hdr
, "#define B%sContent B%sContent", td
->cTypeDefInfo
->decodeRoutineName
, td
->type
->cTypeRefInfo
->decodeRoutineName
);
435 fprintf(hdr, "#define B%sContent( b, tagId, elmtLen, v, bytesDecoded, env) ", td->cTypeDefInfo->decodeRoutineName);
436 fprintf (hdr, "B%sContent (b, tagId, elmtLen, v, bytesDecoded, env)", td->type->cTypeRefInfo->decodeRoutineName);
438 } /* PrintCBerDecoderDefine */
443 * used to figure out local variables to declare
446 RecCountVariableLevels
PARAMS ((t
),
456 enum BasicTypeChoiceId typeId
;
458 ctri
= t
->cTypeRefInfo
;
459 typeId
= GetBuiltinType (t
);
461 /* embedded struct/choices aren't really an issue any more */
462 if ((ctri
->cTypeId
== C_STRUCT
) ||
463 (ctri
->cTypeId
== C_CHOICE
))
467 tagCount
= CountTags (t
);
469 tmp
= (void*)CURR_LIST_NODE (t
->basicType
->a
.set
);
470 FOR_EACH_LIST_ELMT (e
, t
->basicType
->a
.set
)
472 if ((e
->type
== NULL
) || (e
->type
->cTypeRefInfo
== NULL
))
475 typeCount
= RecCountVariableLevels (e
->type
);
477 if (typeCount
> maxLevels
)
478 maxLevels
= typeCount
;
480 SET_CURR_LIST_NODE (t
->basicType
->a
.set
, tmp
);
481 return maxLevels
+ tagCount
;
483 else if (ctri
->cTypeId
== C_LIST
)
485 return CountTags (t
) +RecCountVariableLevels (t
->basicType
->a
.setOf
);
487 else if (typeId
== BASICTYPE_CHOICE
)
488 return CountTags (t
) +1;
489 else if ((typeId
== BASICTYPE_ANY
) || (typeId
== BASICTYPE_ANYDEFINEDBY
))
490 return CountTags (t
) +1;
492 return CountTags (t
);
494 } /* RecCountVariableLevels */
499 * returns the number of variable contexts needed for
500 * decoding the contents of this type. Does not consider tags on this type.
503 CountVariableLevels
PARAMS ((t
),
514 ctri
= t
->cTypeRefInfo
;
516 if ((ctri
->cTypeId
== C_STRUCT
) ||
517 (ctri
->cTypeId
== C_CHOICE
))
520 tmp
= (void*)CURR_LIST_NODE (t
->basicType
->a
.set
);
521 FOR_EACH_LIST_ELMT (e
, t
->basicType
->a
.set
)
523 if ((e
->type
== NULL
) || (e
->type
->cTypeRefInfo
== NULL
))
526 typeCount
= RecCountVariableLevels (e
->type
);
528 /* add extra level since must decode key tag in choice */
529 if (GetBuiltinType (e
->type
) == BASICTYPE_CHOICE
)
532 if (typeCount
> maxLevels
)
533 maxLevels
= typeCount
;
535 SET_CURR_LIST_NODE (t
->basicType
->a
.set
, tmp
);
538 else if (ctri
->cTypeId
== C_LIST
)
539 return RecCountVariableLevels (t
->basicType
->a
.setOf
);
540 else if ((ctri
->cTypeId
== C_ANY
) ||
541 (ctri
->cTypeId
== C_ANYDEFINEDBY
))
545 } /* CountVariableLevels */
550 * prints local vars for constructed types (set/seq/choice)
553 PrintCBerDecoderLocals
PARAMS ((src
,td
),
560 levels
= CountVariableLevels (td
->type
);
562 fprintf (src
, " int seqDone = FALSE;\n");
564 for (i
= 0; i
< levels
; i
++)
566 fprintf (src
, " %s totalElmtsLen%d = 0;\n", lenTypeNameG
, i
+ FIRST_LEVEL
);
567 fprintf (src
, " %s elmtLen%d;\n", lenTypeNameG
, i
+ FIRST_LEVEL
);
568 fprintf (src
, " %s tagId%d;\n", tagTypeNameG
, i
+ FIRST_LEVEL
);
570 fprintf (src
, " int mandatoryElmtCount%d = 0;\n", i
+ FIRST_LEVEL
);
573 } /* PrintCBerDecoderLocals */
577 * given the Type *(t) of an elmt in a set/seq/choice/list,
578 * prints decoding code.
579 * elmtVarName is string ptr ref to field being decoded
580 * eg "(&personnelRecord.name)"
581 * stoleChoiceTags is as returned by GetTags
583 * elmtLevel - last elmtLen# var that is valid/used (has a len)
584 * totalLevel - totalElmtsLen# to be used for running total of dec bytes
585 * tagIdLevel - last tagId# var that is valid/used (contains a tag)
588 PrintCBerElmtDecodeCode
PARAMS ((src
, td
, parent
, t
, elmtLevel
, totalLevel
, tagLevel
, parentVarName
, elmtVarName
, stoleChoiceTags
),
596 char *parentVarName _AND_
597 char *elmtVarName _AND_
602 char idVarRef
[MAX_VAR_REF
];
603 NamedType
*idNamedType
;
604 enum BasicTypeChoiceId tmpTypeId
;
606 ctri
= t
->cTypeRefInfo
;
608 /* check if meant to be encoded */
612 tmpType
= GetType (t
);
614 if (tmpType
->basicType
->choiceId
== BASICTYPE_ANY
)
616 fprintf (src
,"/* ANY - Fix Me ! */\n");
617 fprintf (src
," SetAnyTypeBy???(%s, ???);\n", elmtVarName
);
618 fprintf (src
," B%s (b, %s, &%s%d, env);\n", ctri
->decodeRoutineName
, elmtVarName
, decodedLenVarNameG
, totalLevel
);
620 else if (tmpType
->basicType
->choiceId
== BASICTYPE_ANYDEFINEDBY
)
622 /* get type of 'defining' field (int/enum/oid)*/
623 idNamedType
= t
->basicType
->a
.anyDefinedBy
->link
;
624 tmpTypeId
= GetBuiltinType (idNamedType
->type
);
626 if (tmpTypeId
== BASICTYPE_OID
)
628 MakeVarPtrRef (genDecCRulesG
, td
, parent
, idNamedType
->type
, parentVarName
, idVarRef
);
629 fprintf (src
, " SetAnyTypeByOid (%s, %s);\n", elmtVarName
, idVarRef
);
633 /* want to ref int by value not ptr */
634 MakeVarValueRef (genDecCRulesG
, td
, parent
, idNamedType
->type
, parentVarName
, idVarRef
);
635 fprintf (src
, " SetAnyTypeByInt (%s, %s);\n", elmtVarName
, idVarRef
);
637 fprintf (src
," B%s (b, %s, &%s%d, env);\n", ctri
->decodeRoutineName
, elmtVarName
, decodedLenVarNameG
, totalLevel
);
639 else switch (ctri
->cTypeId
)
644 * choices and octet/bit str types need tagId argument
646 if ((tmpType
->basicType
->choiceId
== BASICTYPE_CHOICE
) &&
650 * strip off top tag of choice in not already done
651 * since choice decoders assume you are passing in
654 fprintf (src
, " %s%d = BDecTag (b, &%s%d, env);\n", tagIdVarNameG
, ++tagLevel
, decodedLenVarNameG
, totalLevel
);
655 fprintf (src
, " %s%d = BDecLen (b, &%s%d, env);\n", itemLenVarNameG
, ++elmtLevel
, decodedLenVarNameG
, totalLevel
);
657 fprintf (src
," B%sContent (b, %s%d, %s%d, %s, &%s%d, env);\n", ctri
->decodeRoutineName
, tagIdVarNameG
, tagLevel
, itemLenVarNameG
, elmtLevel
, elmtVarName
, decodedLenVarNameG
, totalLevel
);
659 /* From ftp://ftp.cs.ubc.ca/pub/local/src/snacc/bugs-in-1.1 */
660 if ((tmpType
->basicType
->choiceId
== BASICTYPE_CHOICE
)
663 fprintf(src
," if (elmtLen%d == INDEFINITE_LEN)\n", elmtLevel
-1);
664 fprintf(src
," BDecEoc(b, &totalElmtsLen%d, env);\n", totalLevel
);
671 * NOTE: the CHOICE, STRUCT and LIST switch clauses won't
672 * fire due to the current 'normalization'
678 * strip off top tag of choice in not already done
679 * since choice decoders assume you are passing in
682 if (!stoleChoiceTags
)
684 fprintf (src
, " %s%d = BDecTag (b, &%s%d, env);\n\n", tagIdVarNameG
, ++tagLevel
, decodedLenVarNameG
, totalLevel
);
686 fprintf (src
, " %s%d = BDecLen (b, &%s%d, env);\n", itemLenVarNameG
, ++elmtLevel
, decodedLenVarNameG
, totalLevel
);
688 PrintCBerChoiceDecodeCode (src
, td
, t
, elmtLevel
, totalLevel
+1, tagLevel
, elmtVarName
);
693 if (t
->basicType
->choiceId
== BASICTYPE_SET
)
694 PrintCBerSetDecodeCode (src
, td
, t
, t
->basicType
->a
.set
, elmtLevel
, totalLevel
+1, tagLevel
, elmtVarName
);
697 PrintCBerSeqDecodeCode (src
, td
, t
, t
->basicType
->a
.sequence
, elmtLevel
,totalLevel
+1, tagLevel
, elmtVarName
);
698 fprintf (src
," seqDone = FALSE;\n");
700 fprintf (src
," %s%d += %s%d;\n", decodedLenVarNameG
, totalLevel
, decodedLenVarNameG
, totalLevel
+1);
705 PrintCBerListDecoderCode (src
, td
, t
, elmtLevel
, totalLevel
+1, tagLevel
, elmtVarName
);
706 fprintf (src
,"\n\n");
707 fprintf (src
," %s%d += %s%d;\n", decodedLenVarNameG
, totalLevel
, decodedLenVarNameG
, totalLevel
+1);
715 fprintf (stderr
,"PrintCBerElmtDecodeCode: ERROR - unknown c type id\n");
719 } /* PrintCBerElmtDecodeCode */
723 * Prints code for decoding the elmts of SET
726 PrintCBerSetDecodeCode
PARAMS ((src
, td
, parent
, elmts
, elmtLevel
, totalLevel
, tagLevel
, varName
),
730 NamedTypeList
*elmts _AND_
741 enum BasicTypeChoiceId builtinType
;
745 int mandatoryCount
= 0;
747 char tmpVarName
[MAX_VAR_REF
];
751 int initialElmtLevel
;
754 initialTagLevel
= tagLevel
;
755 initialElmtLevel
= elmtLevel
;
758 routineName
= td
->cTypeDefInfo
->decodeRoutineName
;
760 if ((elmts
== NULL
) || LIST_EMPTY (elmts
)) /* empty set */
762 fprintf (src
," if (elmtLen%d == INDEFINITE_LEN)\n", elmtLevel
);
763 fprintf (src
," {\n");
764 fprintf (src
," BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel
);
765 fprintf (src
," }\n");
766 fprintf (src
," else if (elmtLen%d != 0)\n", elmtLevel
);
767 fprintf (src
," {\n");
768 fprintf (src
," Asn1Error (\"Expected an empty SET\\n\");\n");
769 fprintf (src
," longjmp (env, %d);\n",(*longJmpValG
)--);
771 fprintf (src
," }\n");
773 /* forget about possible extension types for now
774 fprintf (src," if (elmtLen%d == INDEFINITE_LEN)\n", elmtLevel);
775 fprintf (src," {\n");
776 fprintf (src," tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", ++tagLevel, totalLevel);
778 fprintf (src," if (tagId%d == EOC_TAG_ID)\n", tagLevel);
779 fprintf (src," BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel);
780 fprintf (src," else\n");
781 fprintf (src," BerDiscardElmt (b, &totalElmtsLen%d, env);\n\n",totalLevel);
782 fprintf (src," }\n");
783 fprintf (src," else\n");
784 fprintf (src," {\n");
785 fprintf (src," BufSkip (b, elmtLen%d);\n", elmtLevel);
786 fprintf (src," totalElmtsLen%d += elmtLen%d;\n", totalLevel, elmtLevel);
787 fprintf (src," }\n");
793 fprintf (src
, "for ( ; (totalElmtsLen%d < elmtLen%d) || (elmtLen%d == INDEFINITE_LEN);)\n", totalLevel
, elmtLevel
, elmtLevel
);
794 fprintf (src
, "{\n");
795 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", ++tagLevel
, totalLevel
);
796 fprintf (src
, " if ((tagId%d == EOC_TAG_ID) && (elmtLen%d == INDEFINITE_LEN))\n", tagLevel
, elmtLevel
);
797 fprintf (src
, " {\n");
798 fprintf (src
, " BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel
);
799 fprintf (src
, " break; /* got EOC so can exit this SET's for loop*/\n");
800 fprintf (src
, " }\n");
802 fprintf (src
, " elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
804 fprintf (src
, " switch (tagId%d)\n", tagLevel
);
805 fprintf (src
, " {\n");
807 FOR_EACH_LIST_ELMT (e
, elmts
)
810 elmtLevel
= initialElmtLevel
+1;
811 tagLevel
= initialTagLevel
+1;
812 if ((e
->type
== NULL
) || (e
->type
->cTypeRefInfo
== NULL
))
814 fprintf (src
, "< ERROR - no c type information - prob unsuported type>\n");
818 ctri
= e
->type
->cTypeRefInfo
;
820 /* check if meant to be encoded */
824 tags
= GetTags (e
->type
, &stoleChoiceTags
);
825 builtinType
= GetBuiltinType (e
->type
);
827 if ((tags
== NULL
) || LIST_EMPTY (tags
))
829 if ((builtinType
!= BASICTYPE_ANY
) &&
830 (builtinType
!= BASICTYPE_ANYDEFINEDBY
))
831 fprintf (src
, "<What? no tag on a SetElmt?>\n");
834 fprintf (src
," /* ANY - Fix Me ! */\n");
835 fprintf (src
," case MAKE_TAG_ID (?,?,?):\n");
840 tag
= (Tag
*)FIRST_LIST_ELMT (tags
);
841 classStr
= Class2ClassStr (tag
->tclass
);
842 codeStr
= Code2UnivCodeStr (tag
->code
);
843 formStr
= Form2FormStr (tag
->form
);
845 if (tag
->tclass
== UNIV
)
847 if (tag
->form
== ANY_FORM
)
849 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, Form2FormStr (CONS
), codeStr
);
850 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, Form2FormStr (PRIM
), codeStr
);
853 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
857 if (tag
->form
== ANY_FORM
)
859 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (CONS
), tag
->code
);
861 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (PRIM
), tag
->code
);
864 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
868 AsnListNext (tags
); /* set curr to 2nd tag */
869 FOR_REST_LIST_ELMT (tag
, tags
)
872 codeStr
= Code2UnivCodeStr (tag
->code
);
873 classStr
= Class2ClassStr (tag
->tclass
);
874 formStr
= Form2FormStr (tag
->form
);
878 if (tag
->tclass
== UNIV
)
880 if (tag
->form
== ANY_FORM
)
882 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (CONS
), tag
->code
);
884 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (PRIM
), tag
->code
);
886 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
890 if (tag
->form
== ANY_FORM
)
892 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (CONS
), tag
->code
);
894 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (PRIM
), tag
->code
);
896 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
901 tagLevel
= initialTagLevel
+2;
902 if (tag
->form
== ANY_FORM
)
904 fprintf (src
," tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n", tagLevel
, totalLevel
);
905 if (tag
->tclass
== UNIV
)
907 fprintf (src
,"if ((tagId%d != MAKE_TAG_ID (%s, %s, %s)) &&\n", tagLevel
, classStr
, Form2FormStr (PRIM
), codeStr
);
908 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %s)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), codeStr
);
912 fprintf (src
,"if ((tagId%d != MAKE_TAG_ID (%s, %s, %d)) &&\n", tagLevel
, classStr
, Form2FormStr (PRIM
), tag
->code
);
913 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %d)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), tag
->code
);
919 if (tag
->tclass
== UNIV
)
920 fprintf (src
,"if (BDecTag (b, &totalElmtsLen%d, env) != MAKE_TAG_ID (%s, %s, %s))\n", totalLevel
, classStr
, formStr
, codeStr
);
922 fprintf (src
,"if (BDecTag (b, &totalElmtsLen%d, env) != MAKE_TAG_ID (%s, %s, %d))\n", totalLevel
, classStr
, formStr
, tag
->code
);
925 fprintf (src
," {\n");
926 fprintf (src
," Asn1Error (\"Unexpected Tag\\n\");\n");
927 fprintf (src
," longjmp (env, %d);\n", (*longJmpValG
)--);
928 fprintf (src
," }\n\n");
929 fprintf (src
,"elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
934 MakeVarPtrRef (genDecCRulesG
, td
, parent
, e
->type
, varName
, tmpVarName
);
937 * allocate mem for decoding result
939 PrintElmtAllocCode (src
, e
->type
, tmpVarName
);
941 PrintCBerElmtDecodeCode (src
, td
, parent
, e
->type
, elmtLevel
, totalLevel
, tagLevel
, varName
, tmpVarName
, stoleChoiceTags
);
944 * must check for another EOC for ANYs
945 * Since the any decode routines
946 * decode their own first tag/len pair
948 if ((builtinType
== BASICTYPE_ANY
) ||
949 (builtinType
== BASICTYPE_ANYDEFINEDBY
))
950 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
952 * must check for another EOC for tagged CHOICEs
953 * since the choice decoder routines do not check
954 * for an EOC on the choice's overall length -
955 * they are only passed the tag/len of the choice's
958 else if ((builtinType
== BASICTYPE_CHOICE
) && !(stoleChoiceTags
) &&
959 ((tags
!= NULL
) && !LIST_EMPTY (tags
)))
960 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
963 PrintEocDecoders (src
, elmtLevel
-1, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
965 if ((!e
->type
->optional
) && (e
->type
->defaultVal
== NULL
))
968 fprintf (src
, " mandatoryElmtCount%d++;\n", totalLevel
);
973 fprintf (src
," break;\n\n");
976 fprintf (src
, " default:\n");
977 fprintf (src
, " Asn1Error (\"B%sContent: ERROR - Unexpected tag in SET\\n\");\n", routineName
);
978 fprintf (src
, " longjmp (env, %d);\n",(*longJmpValG
)--);
979 fprintf (src
, " break;\n");
982 fprintf (src, " Asn1Warning (\"B%sContent: Warning - unexpected tag in SET, discarding elmt\\n\");\n", routineName);
983 fprintf (src, " BerDiscardElmt (b, &totalElmtsLen%d, env);\n\n", totalLevel);
986 fprintf (src
, " } /* end switch */\n");
987 fprintf (src
, " } /* end for */\n");
989 fprintf (src
, " if (mandatoryElmtCount%d != %d)\n", totalLevel
, mandatoryCount
);
991 fprintf (src
, " {\n");
992 fprintf (src
, " Asn1Error (\"B%sContent: ERROR - non-optional elmt missing from SET\\n\");\n", routineName
);
993 fprintf (src
, " longjmp (env, %d);\n",(*longJmpValG
)--);
994 fprintf (src
, " }\n");
996 } /* PrintCBerSetDecodeCode */
1002 * Prints code for decoding the elmts of a SEQUENCE
1005 PrintCBerSeqDecodeCode
PARAMS ((src
, td
, parent
, elmts
, elmtLevel
, totalLevel
, tagLevel
, varName
),
1009 NamedTypeList
*elmts _AND_
1011 int totalLevel _AND_
1023 enum BasicTypeChoiceId builtinType
;
1024 enum BasicTypeChoiceId tmpTypeId
;
1030 char tmpVarName
[MAX_VAR_REF
];
1031 int stoleChoiceTags
;
1033 int inTailOptElmts
= FALSE
;
1034 int initialElmtLevel
;
1035 int initialTagLevel
;
1038 initialTagLevel
= tagLevel
;
1039 initialElmtLevel
= elmtLevel
;
1042 routineName
= td
->cTypeDefInfo
->decodeRoutineName
;
1044 if ((elmts
== NULL
) || LIST_EMPTY (elmts
)) /* empty seq */
1046 fprintf (src
," if (elmtLen%d == INDEFINITE_LEN)\n", elmtLevel
);
1047 fprintf (src
," {\n");
1048 fprintf (src
," BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel
);
1049 fprintf (src
," }\n");
1050 fprintf (src
," else if (elmtLen%d != 0)\n", elmtLevel
);
1051 fprintf (src
," {\n");
1052 fprintf (src
," Asn1Error (\"Expected an empty SEQUENCE\\n\");\n");
1053 fprintf (src
," longjmp (env, %d);\n",(*longJmpValG
)--);
1055 fprintf (src
," }\n");
1058 forget about extended types for now
1059 fprintf (src," tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel+1, totalLevel);
1060 fprintf (src," {\n");
1061 fprintf (src," if (tagId%d == EOC_TAG_ID)\n", tagLevel+1);
1062 fprintf (src," BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel);
1063 fprintf (src," else\n");
1064 fprintf (src," BerDiscardElmt (b, &totalElmtsLen%d, env);\n\n",totalLevel);
1065 fprintf (src," }\n");
1066 fprintf (src," else \n");
1067 fprintf (src," {\n");
1068 fprintf (src," BufSkip (b, elmtLen%d);\n", elmtLevel);
1069 fprintf (src," totalElmtsLen%d += elmtLen%d\n", totalLevel, elmtLevel);
1070 fprintf (src," }\n");
1076 * must set list curr since IsTailOptional checks from curr pt
1079 AsnListFirst (elmts
);
1080 inTailOptElmts
= IsTailOptional (elmts
);
1081 e
= (NamedType
*)FIRST_LIST_ELMT (elmts
);
1082 tmpTypeId
= GetBuiltinType (e
->type
);
1085 * print code to decode the first tag
1088 if (!inTailOptElmts
)
1090 if (((tmpTypeId
== BASICTYPE_ANY
) ||
1091 (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)) &&
1092 (CountTags (e
->type
) == 0))
1094 if ((e
->type
->optional
) && (e
!= (NamedType
*)LAST_LIST_ELMT (elmts
)))
1096 /* let this cause a compile error in the generated code */
1097 fprintf (src
,"<untagged optional ANY - you must fix this>\n");
1101 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel
, totalLevel
);
1105 fprintf (src
, " if ((elmtLen%d != INDEFINITE_LEN) && (totalElmtsLen%d == elmtLen%d))\n", elmtLevel
, totalLevel
, elmtLevel
);
1106 fprintf (src
, " seqDone = TRUE;\n");
1107 fprintf (src
, " else\n");
1108 fprintf (src
, " {\n");
1110 if (((tmpTypeId
== BASICTYPE_ANY
) ||
1111 (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)) &&
1112 (CountTags (e
->type
) == 0))
1114 if ((e
->type
->optional
) && (e
!= (NamedType
*)LAST_LIST_ELMT (elmts
)))
1116 /* let this cause a compile error in the generated code */
1117 fprintf (src
,"<untagged optional ANY - you must fix this>\n");
1121 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel
, totalLevel
);
1122 fprintf (src
," if ((elmtLen%d == INDEFINITE_LEN) && (tagId%d == EOC_TAG_ID))\n", elmtLevel
, tagLevel
);
1123 fprintf (src
, " {\n");
1124 fprintf (src
, " BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel
);
1125 fprintf (src
, " seqDone = TRUE;\n");
1126 fprintf (src
, " }\n");
1127 fprintf (src
, " }\n\n");
1130 last
= (NamedType
*)LAST_LIST_ELMT (elmts
);
1131 FOR_EACH_LIST_ELMT (e
, elmts
)
1133 elmtLevel
= initialElmtLevel
;
1134 tagLevel
= initialTagLevel
+1;
1136 if ((e
->type
== NULL
) || (e
->type
->cTypeRefInfo
== NULL
))
1138 fprintf (src
, "< ERROR - no c type information - prob unsuported type>\n");
1142 ctri
= e
->type
->cTypeRefInfo
;
1144 /* check if meant to be encoded */
1145 if (!ctri
->isEncDec
)
1148 tags
= GetTags (e
->type
, &stoleChoiceTags
);
1149 builtinType
= GetBuiltinType (e
->type
);
1152 if ((tags
== NULL
) || LIST_EMPTY (tags
))
1154 if ((builtinType
!= BASICTYPE_ANY
) &&
1155 (builtinType
!= BASICTYPE_ANYDEFINEDBY
))
1156 fprintf (src
, "<What? no tag on a SetElmt?>\n");
1160 fprintf (src
," if (!seqDone)");
1162 /* always enclose elmt decoder in block */
1163 fprintf (src
," {\n");
1168 fprintf (src," if (tagId%d == MAKE_TAG_ID (?, ?, ?))\n", tagLevel);
1169 fprintf (src," {\n");
1175 tag
= (Tag
*)FIRST_LIST_ELMT (tags
);
1177 classStr
= Class2ClassStr (tag
->tclass
);
1178 codeStr
= Code2UnivCodeStr (tag
->code
);
1179 formStr
= Form2FormStr (tag
->form
);
1184 fprintf (src
," if ((!seqDone) && (");
1186 fprintf (src
," if ((");
1188 if (tag
->tclass
== UNIV
)
1190 if (tag
->form
== ANY_FORM
)
1192 fprintf (src
,"(tagId%d == MAKE_TAG_ID (%s, %s, %s)) ||\n", tagLevel
, classStr
, Form2FormStr (PRIM
), codeStr
);
1193 fprintf (src
,"(tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel
, classStr
, Form2FormStr (CONS
), codeStr
);
1196 fprintf (src
,"(tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel
, classStr
, formStr
, codeStr
);
1200 if (tag
->form
== ANY_FORM
)
1202 fprintf (src
,"(tagId%d == MAKE_TAG_ID (%s, %s, %d)) ||\n", tagLevel
, classStr
, Form2FormStr (PRIM
), tag
->code
);
1203 fprintf (src
,"(tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel
, classStr
, Form2FormStr (CONS
), tag
->code
);
1206 fprintf (src
,"(tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel
, classStr
, formStr
, tag
->code
);
1209 if (!stoleChoiceTags
)
1211 fprintf (src
,"))\n");
1212 fprintf (src
, " {\n");
1213 fprintf (src
," elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
1216 AsnListFirst (tags
);
1219 FOR_REST_LIST_ELMT (tag
, tags
)
1221 classStr
= Class2ClassStr (tag
->tclass
);
1222 codeStr
= Code2UnivCodeStr (tag
->code
);
1223 formStr
= Form2FormStr (tag
->form
);
1226 if (stoleChoiceTags
)
1228 fprintf (src
," ||\n");
1229 if (tag
->tclass
== UNIV
)
1231 if (tag
->form
== ANY_FORM
)
1233 fprintf (src
," (tagId%d ==MAKE_TAG_ID (%s, %s, %s))", tagLevel
, classStr
, Form2FormStr (PRIM
), codeStr
);
1234 fprintf (src
,"||\n (tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel
, classStr
, Form2FormStr (CONS
), codeStr
);
1237 fprintf (src
," (tagId%d ==MAKE_TAG_ID (%s, %s, %s))", tagLevel
, classStr
, formStr
, codeStr
);
1241 if (tag
->form
== ANY_FORM
)
1243 fprintf (src
," (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel
, classStr
, Form2FormStr (PRIM
), tag
->code
);
1244 fprintf (src
,"||\n (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel
, classStr
, Form2FormStr (CONS
), tag
->code
);
1247 fprintf (src
," (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel
, classStr
, formStr
, tag
->code
);
1253 tagLevel
= initialTagLevel
+ 2;
1254 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel
, totalLevel
);
1255 if (tag
->tclass
== UNIV
)
1257 if (tag
->form
== ANY_FORM
)
1259 fprintf (src
," if ((tagId%d != MAKE_TAG_ID (%s, %s, %s)) &&\n", tagLevel
, classStr
, Form2FormStr (PRIM
), codeStr
);
1260 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %s)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), codeStr
);
1263 fprintf (src
," if (tagId%d != MAKE_TAG_ID (%s, %s, %s))\n", tagLevel
, classStr
, formStr
, codeStr
);
1267 if (tag
->form
== ANY_FORM
)
1269 fprintf (src
," if ((tagId%d != MAKE_TAG_ID (%s, %s, %d)) &&\n", tagLevel
, classStr
, Form2FormStr (PRIM
), tag
->code
);
1270 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %d)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), tag
->code
);
1273 fprintf (src
," if (tagId%d != MAKE_TAG_ID (%s, %s, %d))\n", tagLevel
, classStr
, formStr
, tag
->code
);
1277 fprintf (src
," {\n");
1278 fprintf (src
," Asn1Error (\"Unexpected Tag\\n\");\n");
1279 fprintf (src
," longjmp (env, %d);\n",(*longJmpValG
)--);
1280 fprintf (src
," }\n\n");
1281 fprintf (src
," elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
1283 } /* end tag list for */
1285 if (stoleChoiceTags
)
1287 fprintf (src
,"))\n");
1288 fprintf (src
, " {\n");
1289 fprintf (src
, " elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
1294 MakeVarPtrRef (genDecCRulesG
, td
, parent
, e
->type
, varName
, tmpVarName
);
1297 * allocate mem for decoding result
1299 PrintElmtAllocCode (src
, e
->type
, tmpVarName
);
1301 PrintCBerElmtDecodeCode (src
, td
, parent
, e
->type
, elmtLevel
, totalLevel
, tagLevel
, varName
, tmpVarName
, stoleChoiceTags
);
1304 * must check for another EOC for ANYs
1305 * Since the any decode routines
1306 * decode their own first tag/len pair
1308 if ((builtinType
== BASICTYPE_ANY
) ||
1309 (builtinType
== BASICTYPE_ANYDEFINEDBY
))
1310 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1312 * must check for another EOC for tagged CHOICEs
1313 * since the choice decoder routines do not check
1314 * for an EOC on the choice's overall length -
1315 * they are only passed the tag/len of the choice's
1318 else if ((builtinType
== BASICTYPE_CHOICE
) && (!stoleChoiceTags
) &&
1319 ((tags
!= NULL
) && !LIST_EMPTY (tags
)))
1320 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1323 PrintEocDecoders (src
, elmtLevel
-1, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1326 /* could check cons len vs decode len here */
1328 if (!inTailOptElmts
)
1331 * determine whether next elmt in Seq is start
1332 * of tailing optionals
1334 AsnListNext (elmts
);
1335 inTailOptElmts
= IsTailOptional (elmts
);
1336 AsnListPrev (elmts
);
1340 * print code for getting the next tag
1342 tmpTypeId
= GetBuiltinType (e
->type
);
1346 tmpElmt
= (NamedType
*)NEXT_LIST_ELMT (elmts
);
1347 tmpTypeId
= GetBuiltinType (tmpElmt
->type
);
1348 if (!inTailOptElmts
)
1350 if (((tmpTypeId
== BASICTYPE_ANY
) ||
1351 (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)) &&
1352 (CountTags (tmpElmt
->type
) == 0))
1354 if ((e
->type
->optional
) ||
1355 ((tmpElmt
->type
->optional
) && (tmpElmt
!= last
)))
1357 /* let this cause a compile error in the gen'd code */
1358 fprintf (src
," <problems with untagged ANY that is optional or follows an optional sequence element - you must fix this>\n");
1360 /* don't get a tag since ANY's decode their own */
1363 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n", initialTagLevel
+1, totalLevel
);
1367 fprintf (src
, " if ((elmtLen%d != INDEFINITE_LEN) && (totalElmtsLen%d == elmtLen%d))\n", initialElmtLevel
, totalLevel
, initialElmtLevel
);
1368 fprintf (src
, " seqDone = TRUE;\n");
1369 fprintf (src
, " else\n");
1370 fprintf (src
, " {\n");
1371 if (((tmpTypeId
== BASICTYPE_ANY
) ||
1372 (tmpTypeId
== BASICTYPE_ANYDEFINEDBY
)) &&
1373 (CountTags (tmpElmt
->type
) == 0))
1375 if ((e
->type
->optional
) ||
1376 ((tmpElmt
->type
->optional
) && (tmpElmt
!= last
)))
1378 /* let this cause a compile error in the gen'd code */
1379 fprintf (src
," <problems with untagged ANY that is optional or follows an optional sequence element - you must fix this>\n");
1383 /* peek ahead for first octet of eoc */
1384 fprintf (src
," tagId%d = BufPeekByte (b);\n", initialTagLevel
+1);
1385 fprintf (src
," if ((elmtLen%d == INDEFINITE_LEN) && (tagId%d == EOC_TAG_ID))\n", initialElmtLevel
, initialTagLevel
+1);
1386 fprintf (src
, " {\n");
1387 fprintf (src
, " BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel
);
1388 fprintf (src
, " seqDone = TRUE;\n");
1389 fprintf (src
, " }\n");
1393 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", initialTagLevel
+1, totalLevel
);
1394 fprintf (src
," if ((elmtLen%d == INDEFINITE_LEN) && (tagId%d == EOC_TAG_ID))\n", initialElmtLevel
, initialTagLevel
+1);
1395 fprintf (src
, " {\n");
1396 fprintf (src
, " BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel
);
1397 fprintf (src
, " seqDone = TRUE;\n");
1398 fprintf (src
, " }\n");
1400 fprintf (src
, " }\n");
1403 else /* for last elmt only */
1405 fprintf (src
," seqDone = TRUE;\n");
1406 fprintf (src
," if (elmtLen%d == INDEFINITE_LEN)\n", initialElmtLevel
);
1407 fprintf (src
," BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel
);
1408 fprintf (src
," else if (totalElmtsLen%d != elmtLen%d)\n", totalLevel
, initialElmtLevel
);
1409 fprintf (src
," longjmp (env, %d);\n",(*longJmpValG
)--);
1413 * close (tag check/seqDone test) if block and
1414 * print else clause to handle missing non-optional elmt
1417 tmpTypeId
= GetBuiltinType (e
->type
);
1418 if (((tmpTypeId
== BASICTYPE_ANYDEFINEDBY
) ||
1419 (tmpTypeId
== BASICTYPE_ANY
)) &&
1420 (CountTags (e
->type
) == 0))
1422 /* close if stmt block */
1423 fprintf (src
," }\n");
1425 else if (!e
->type
->optional
&& (e
->type
->defaultVal
== NULL
))
1428 fprintf (src
, " }\n"); /* end of tag check if */
1429 fprintf (src
, " else\n");
1430 fprintf (src
, " longjmp (env, %d);\n", (*longJmpValG
)--);
1434 fprintf (src
, " }\n"); /* end of tag check if */
1437 fprintf (src
,"\n\n");
1443 * print code to make sure that truly finished with sequence
1446 fprintf (src
," if (!seqDone)\n");
1447 fprintf (src
, " longjmp (env, %d);\n\n", (*longJmpValG
)--);
1449 } /* PrintCBerSeqDecodeCode */
1453 * Generates code for internally defined lists
1455 * TypeX = SET { foo INTEGER, bar SEQUENCE OF INTEGER } -->
1456 * BerDecodeTypeX (b, len, v, bytesDecoded, env)
1459 * listLen1 = BerDecodeLen (b, &totalElmtsLen, env);
1460 * retVal->bar = NewList();
1461 * for ( ; totalElmtsLen1 < listLen1 || listLen1== INDEFINITE_LEN;)
1463 * tagId1 = BerDecodeTag (b, &totalElmtsLen1, env);
1465 * elmtLen1 = BerDecodeLen (b, &totalElmtsLen1, env)
1466 * tmpInt = Asn1Alloc (sizeof (int));
1467 * BerDecodeInteger (b, elmtLen1, tmpInt, &totalElmtsLen1, env);
1468 * AppendList (retVal->bar, tmpInt);
1470 * totalElmtsLen += totalElmtsLen1;
1475 PrintCBerListDecoderCode
PARAMS ((src
, td
, list
, elmtLevel
, totalLevel
, tagLevel
, varName
),
1480 int totalLevel _AND_
1488 enum BasicTypeChoiceId builtinType
;
1493 int mandatoryCount
= 0;
1495 char tmpVarName
[MAX_VAR_REF
];
1496 int stoleChoiceTags
;
1498 int initialTagLevel
;
1499 int initialElmtLevel
;
1502 initialTagLevel
= tagLevel
;
1503 initialElmtLevel
= elmtLevel
;
1506 routineName
= td
->cTypeDefInfo
->decodeRoutineName
;
1507 ctri
= list
->basicType
->a
.setOf
->cTypeRefInfo
;
1508 tags
= GetTags (list
->basicType
->a
.setOf
, &stoleChoiceTags
);
1509 builtinType
= GetBuiltinType (list
->basicType
->a
.setOf
);
1511 taglessAny
= (((tags
== NULL
) || LIST_EMPTY (tags
)) &&
1512 ((builtinType
== BASICTYPE_ANY
) ||
1513 (builtinType
== BASICTYPE_ANYDEFINEDBY
)));
1515 fprintf (src
, " for (totalElmtsLen%d = 0; (totalElmtsLen%d < elmtLen%d) || (elmtLen%d == INDEFINITE_LEN);)\n", totalLevel
, totalLevel
, elmtLevel
, elmtLevel
);
1516 fprintf (src
, " {\n");
1517 fprintf (src
," %s **tmpVar;\n", ctri
->cTypeName
);
1521 fprintf (src
, " tagId%d = BufPeekByte (b);\n\n", ++tagLevel
);
1522 fprintf (src
, " if ((tagId%d == EOC_TAG_ID) && (elmtLen%d == INDEFINITE_LEN))\n", tagLevel
, elmtLevel
);
1523 fprintf (src
, " {\n");
1524 fprintf (src
, " BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel
);
1525 fprintf (src
, " break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/\n");
1526 fprintf (src
, " }\n");
1530 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", ++tagLevel
, totalLevel
);
1531 fprintf (src
, " if ((tagId%d == EOC_TAG_ID) && (elmtLen%d == INDEFINITE_LEN))\n", tagLevel
, elmtLevel
);
1532 fprintf (src
, " {\n");
1533 fprintf (src
, " BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel
);
1534 fprintf (src
, " break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/\n");
1535 fprintf (src
, " }\n");
1539 if ((tags
== NULL
) || LIST_EMPTY (tags
))
1542 fprintf (src
, "<What? no tag on a SET OF/SEQ OF Elmt?>\n");
1546 fprintf (src," if (tagId%d == MAKE_TAG_ID (?, ?, ?))",tagLevel);
1547 fprintf (src," {\n");
1552 else if (!stoleChoiceTags
) /* choice decoder will check tag */
1554 tag
= (Tag
*)FIRST_LIST_ELMT (tags
);
1555 classStr
= Class2ClassStr (tag
->tclass
);
1556 codeStr
= Code2UnivCodeStr (tag
->code
);
1557 formStr
= Form2FormStr (tag
->form
);
1559 if (tag
->tclass
== UNIV
)
1561 if (tag
->form
== ANY_FORM
)
1563 fprintf (src
," if ((tagId%d == MAKE_TAG_ID (%s, %s, %s)) ||", tagLevel
, classStr
, Form2FormStr (PRIM
), codeStr
);
1565 fprintf (src
," (tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel
, classStr
, Form2FormStr (CONS
), codeStr
);
1568 fprintf (src
," if ((tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel
, classStr
, formStr
, codeStr
);
1572 if (tag
->form
== ANY_FORM
)
1574 fprintf (src
," if ((tagId%d == MAKE_TAG_ID (%s, %s, %d)) ||\n", tagLevel
, classStr
, Form2FormStr (PRIM
), tag
->code
);
1575 fprintf (src
," (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel
, classStr
, Form2FormStr (CONS
), tag
->code
);
1578 fprintf (src
," if ((tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel
, classStr
, formStr
, tag
->code
);
1581 fprintf (src
,")\n");
1582 fprintf (src
, " {\n");
1583 fprintf (src
, " elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
1585 AsnListFirst (tags
);
1587 FOR_REST_LIST_ELMT (tag
, tags
)
1589 tagLevel
= initialTagLevel
+2;
1590 fprintf (src
, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel
, totalLevel
);
1591 classStr
= Class2ClassStr (tag
->tclass
);
1592 codeStr
= Code2UnivCodeStr (tag
->code
);
1593 formStr
= Form2FormStr (tag
->form
);
1595 if (tag
->tclass
== UNIV
)
1597 if (tag
->form
== ANY_FORM
)
1599 fprintf (src
," if ((tagId%d != MAKE_TAG_ID (%s, %s, %s)) ||\n", tagLevel
, classStr
, Form2FormStr (PRIM
), codeStr
);
1600 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %s)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), codeStr
);
1603 fprintf (src
," if (tagId%d != MAKE_TAG_ID (%s, %s, %s))\n", tagLevel
, classStr
, formStr
, codeStr
);
1607 if (tag
->form
== ANY_FORM
)
1609 fprintf (src
," if ((tagId%d != MAKE_TAG_ID (%s, %s, %d)) ||\n", tagLevel
, classStr
, Form2FormStr (PRIM
), tag
->code
);
1610 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %d)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), tag
->code
);
1614 fprintf (src
," if (tagId%d != MAKE_TAG_ID (%s, %s, %d))\n", tagLevel
, classStr
, formStr
, tag
->code
);
1618 fprintf (src
," {\n");
1619 fprintf (src
," Asn1Error (\"Unexpected Tag\\n\");\n");
1620 fprintf (src
," longjmp (env, %d);\n", (*longJmpValG
)--);
1621 fprintf (src
," }\n\n");
1622 fprintf (src
," elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
1625 if (stoleChoiceTags
)
1627 fprintf (src
, " elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
1632 strcpy (tmpVarName
, "(*tmpVar)");
1633 fprintf (src
," tmpVar = (%s**) AsnListAppend (%s);\n", ctri
->cTypeName
, varName
);
1634 fprintf (src
, " %s = (%s*) Asn1Alloc (sizeof (%s));\n", tmpVarName
, ctri
->cTypeName
, ctri
->cTypeName
);
1636 fprintf (src
," CheckAsn1Alloc (%s, env);\n", tmpVarName
);
1637 PrintCBerElmtDecodeCode (src
, td
, list
, list
->basicType
->a
.setOf
, elmtLevel
, totalLevel
, tagLevel
, varName
, tmpVarName
, stoleChoiceTags
);
1640 * must check for another EOC for ANYs
1641 * Since the any decode routines
1642 * decode their own first tag/len pair
1644 if ((builtinType
== BASICTYPE_ANY
) ||
1645 (builtinType
== BASICTYPE_ANYDEFINEDBY
))
1646 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1648 * must check for another EOC for tagged CHOICEs
1649 * since the choice decoder routines do not check
1650 * for an EOC on the choice's overall length -
1651 * they are only passed the tag/len of the choice's
1654 else if ((builtinType
== BASICTYPE_CHOICE
) && (!stoleChoiceTags
) &&
1655 ((tags
!= NULL
) && !LIST_EMPTY (tags
)))
1656 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1659 PrintEocDecoders (src
, elmtLevel
-1, initialElmtLevel
, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1662 if ((!stoleChoiceTags
) && (!taglessAny
))
1664 fprintf (src
, " } /* end of tag check if */\n");
1665 fprintf (src
, " else /* wrong tag */\n");
1666 fprintf (src
," {\n");
1667 fprintf (src
," Asn1Error (\"Unexpected Tag\\n\");\n");
1668 fprintf (src
," longjmp (env, %d);\n", (*longJmpValG
)--);
1669 fprintf (src
," }\n");
1671 fprintf (src
, " } /* end of for */\n\n");
1675 } /* PrintCBerListDecodeCode */
1680 * t is the choice type pointer
1683 PrintCBerChoiceDecodeCode
PARAMS ((src
, td
, t
, elmtLevel
, totalLevel
, tagLevel
, varName
),
1688 int totalLevel _AND_
1697 enum BasicTypeChoiceId builtinType
;
1702 int mandatoryCount
= 0;
1704 char tmpVarName
[MAX_VAR_REF
];
1705 char choiceIdVarName
[MAX_VAR_REF
];
1707 int stoleChoiceTags
;
1709 int initialTagLevel
;
1710 int initialElmtLevel
;
1712 initialTagLevel
= tagLevel
;
1713 initialElmtLevel
= elmtLevel
;
1715 parentCtri
= t
->cTypeRefInfo
;
1718 fprintf (src
, " switch (tagId%d)\n", tagLevel
);
1719 fprintf (src
, " {\n");
1722 FOR_EACH_LIST_ELMT (e
, t
->basicType
->a
.choice
)
1724 /* hack ! remember curr loc cause called routine hacks it */
1725 tmp
= (void*)CURR_LIST_NODE (t
->basicType
->a
.choice
);
1727 tagLevel
= initialTagLevel
;
1728 elmtLevel
= initialElmtLevel
;
1730 if ((e
->type
== NULL
) || (e
->type
->cTypeRefInfo
== NULL
))
1732 fprintf (src
, "< ERROR - no c type information - prob unsuported type>\n");
1736 ctri
= e
->type
->cTypeRefInfo
;
1738 tags
= GetTags (e
->type
, &stoleChoiceTags
);
1739 builtinType
= GetBuiltinType (e
->type
);
1741 if ((tags
== NULL
) || LIST_EMPTY (tags
))
1743 if ((builtinType
!= BASICTYPE_ANY
) &&
1744 (builtinType
!= BASICTYPE_ANYDEFINEDBY
))
1745 fprintf (src
, "<What? no tag on a CHOICE elmt?>\n");
1748 fprintf (src
, " /* You must hand code ANY type refs */\n");
1749 fprintf (src
," case MAKE_TAG_ID (?, ?, ?):\n");
1756 tag
= (Tag
*)FIRST_LIST_ELMT (tags
);
1757 classStr
= Class2ClassStr (tag
->tclass
);
1758 codeStr
= Code2UnivCodeStr (tag
->code
);
1759 formStr
= Form2FormStr (tag
->form
);
1761 if (tag
->tclass
== UNIV
)
1763 if (tag
->form
== ANY_FORM
)
1765 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, Form2FormStr (PRIM
), codeStr
);
1766 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, Form2FormStr (CONS
), codeStr
);
1769 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
1773 if (tag
->form
== ANY_FORM
)
1775 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (PRIM
), tag
->code
);
1776 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (CONS
), tag
->code
);
1779 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
1783 AsnListFirst (tags
);
1784 AsnListNext (tags
); /* set curr ptr to 2nd elmt */
1785 FOR_REST_LIST_ELMT (tag
, tags
)
1787 classStr
= Class2ClassStr (tag
->tclass
);
1788 codeStr
= Code2UnivCodeStr (tag
->code
);
1789 formStr
= Form2FormStr (tag
->form
);
1792 if (stoleChoiceTags
)
1794 if (tag
->tclass
== UNIV
)
1796 if (tag
->form
== ANY_FORM
)
1798 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, Form2FormStr (PRIM
), codeStr
);
1799 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, Form2FormStr (CONS
), codeStr
);
1802 fprintf (src
," case MAKE_TAG_ID (%s, %s, %s):\n", classStr
, formStr
, codeStr
);
1806 if (tag
->form
== ANY_FORM
)
1808 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (PRIM
), tag
->code
);
1809 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, Form2FormStr (CONS
), tag
->code
);
1812 fprintf (src
," case MAKE_TAG_ID (%s, %s, %d):\n", classStr
, formStr
, tag
->code
);
1817 tagLevel
= initialTagLevel
+1;
1818 if (tag
->form
== ANY_FORM
)
1820 fprintf (src
," tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n", tagLevel
, totalLevel
);
1821 if (tag
->tclass
== UNIV
)
1823 fprintf (src
,"if ((tagId%d != MAKE_TAG_ID (%s, %s, %s)) &&\n", tagLevel
, classStr
, Form2FormStr (PRIM
), codeStr
);
1824 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %s)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), codeStr
);
1828 fprintf (src
,"if ((tagId%d != MAKE_TAG_ID (%s, %s, %d)) &&\n", tagLevel
, classStr
, Form2FormStr (PRIM
), tag
->code
);
1829 fprintf (src
," (tagId%d != MAKE_TAG_ID (%s, %s, %d)))\n", tagLevel
, classStr
, Form2FormStr (CONS
), tag
->code
);
1835 if (tag
->tclass
== UNIV
)
1836 fprintf (src
,"if (BDecTag (b, &totalElmtsLen%d, env) != MAKE_TAG_ID (%s, %s, %s))\n", totalLevel
, classStr
, formStr
, codeStr
);
1838 fprintf (src
,"if (BDecTag (b, &totalElmtsLen%d, env) != MAKE_TAG_ID (%s, %s, %d))\n", totalLevel
, classStr
, formStr
, tag
->code
);
1841 fprintf (src
," {\n");
1842 fprintf (src
," Asn1Error (\"Unexpected Tag\\n\");\n");
1843 fprintf (src
," longjmp (env, %d);\n", (*longJmpValG
)--);
1844 fprintf (src
," }\n\n");
1845 fprintf (src
," elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel
, totalLevel
);
1851 MakeChoiceIdValueRef (genDecCRulesG
, td
, t
, e
->type
, varName
, choiceIdVarName
);
1852 fprintf (src
, " %s = %s;\n", choiceIdVarName
, ctri
->choiceIdSymbol
);
1854 MakeVarPtrRef (genDecCRulesG
, td
, t
, e
->type
, varName
, tmpVarName
);
1856 PrintElmtAllocCode (src
, e
->type
, tmpVarName
);
1858 PrintCBerElmtDecodeCode (src
, td
, t
, e
->type
, elmtLevel
, totalLevel
, tagLevel
, varName
, tmpVarName
, stoleChoiceTags
);
1861 * this is slightly diff from set/seq since
1862 * no loop checking for eoc (set) and no next elmt (seq)
1863 * so should check elmtLen0 for EOC if nec
1864 * (therefore (initialElmtLevel-1) instead of initialElmtLevel)
1866 * must check for another EOC for ANYs
1867 * Since the any decode routines
1868 * decode their own first tag/len pair
1870 if ((builtinType
== BASICTYPE_ANY
) ||
1871 (builtinType
== BASICTYPE_ANYDEFINEDBY
))
1872 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
-1, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1874 * must check for another EOC for tagged CHOICEs
1875 * since the choice decoder routines do not check
1876 * for an EOC on the choice's overall length -
1877 * they are only passed the tag/len of the choice's
1880 else if ((builtinType
== BASICTYPE_CHOICE
) && (!stoleChoiceTags
) &&
1881 ((tags
!= NULL
) && !LIST_EMPTY (tags
)))
1882 PrintEocDecoders (src
, elmtLevel
, initialElmtLevel
-1, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1885 PrintEocDecoders (src
, elmtLevel
-1, initialElmtLevel
-1, itemLenVarNameG
, totalLevel
, decodedLenVarNameG
);
1890 fprintf (src
," break;\n\n");
1892 /* reset curr list node to value remember at beg of loop */
1893 SET_CURR_LIST_NODE (t
->basicType
->a
.choice
, tmp
);
1896 fprintf (src
," default:\n");
1897 fprintf (src
," Asn1Error (\"ERROR - unexpected tag in CHOICE\\n\");\n");
1898 fprintf (src
," longjmp (env, %d);\n",(*longJmpValG
)--);
1899 fprintf (src
," break;\n");
1901 fprintf (src
, " } /* end switch */\n");
1903 } /* PrintCBerChoiceDecodeCode */
1908 PrintCLenDecodingCode
PARAMS ((f
),
1911 fprintf (f
, " itemLen += BDecDefLen (b, itemLen);");
1912 } /* PrintCLenDecodingCode */