📄 gen-dec.c
字号:
{ if ((e->type->optional) && (e != (NamedType*)LAST_LIST_ELMT (elmts))) { /* let this cause a compile error in the generated code */ fprintf (src,"<untagged optional ANY - you must fix this>\n"); } } else fprintf (src, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel, totalLevel); } else { fprintf (src, " if ((elmtLen%d != INDEFINITE_LEN) && (totalElmtsLen%d == elmtLen%d))\n", elmtLevel, totalLevel, elmtLevel); fprintf (src, " seqDone = TRUE;\n"); fprintf (src, " else\n"); fprintf (src, " {\n"); if (((tmpTypeId == BASICTYPE_ANY) || (tmpTypeId == BASICTYPE_ANYDEFINEDBY)) && (CountTags (e->type) == 0)) { if ((e->type->optional) && (e != (NamedType*)LAST_LIST_ELMT (elmts))) { /* let this cause a compile error in the generated code */ fprintf (src,"<untagged optional ANY - you must fix this>\n"); } } else fprintf (src, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel, totalLevel); fprintf (src," if ((elmtLen%d == INDEFINITE_LEN) && (tagId%d == EOC_TAG_ID))\n", elmtLevel, tagLevel); fprintf (src, " {\n"); fprintf (src, " BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel); fprintf (src, " seqDone = TRUE;\n"); fprintf (src, " }\n"); fprintf (src, " }\n\n"); } last = (NamedType*)LAST_LIST_ELMT (elmts); FOR_EACH_LIST_ELMT (e, elmts) { elmtLevel = initialElmtLevel; tagLevel = initialTagLevel+1; if ((e->type == NULL) || (e->type->cTypeRefInfo == NULL)) { fprintf (src, "< ERROR - no c type information - prob unsuported type>\n"); continue; } ctri = e->type->cTypeRefInfo; /* check if meant to be encoded */ if (!ctri->isEncDec) continue; tags = GetTags (e->type, &stoleChoiceTags); builtinType = GetBuiltinType (e->type); if ((tags == NULL) || LIST_EMPTY (tags)) { if ((builtinType != BASICTYPE_ANY) && (builtinType != BASICTYPE_ANYDEFINEDBY)) fprintf (src, "<What? no tag on a SetElmt?>\n"); if (inTailOptElmts) { fprintf (src," if (!seqDone)"); } /* always enclose elmt decoder in block */ fprintf (src," {\n");/* else { fprintf (src," if (tagId%d == MAKE_TAG_ID (?, ?, ?))\n", tagLevel); fprintf (src," {\n"); }*/ } else /* has tags */ { tag = (Tag*)FIRST_LIST_ELMT (tags); classStr = Class2ClassStr (tag->tclass); codeStr = Code2UnivCodeStr (tag->code); formStr = Form2FormStr (tag->form); if (inTailOptElmts) fprintf (src," if ((!seqDone) && ("); else fprintf (src," if (("); if (tag->tclass == UNIV) { if (tag->form == ANY_FORM) { fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %s)) ||\n", tagLevel, classStr, Form2FormStr (PRIM), codeStr); fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, Form2FormStr (CONS), codeStr); } else fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, formStr, codeStr); } else { if (tag->form == ANY_FORM) { fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %d)) ||\n", tagLevel, classStr, Form2FormStr (PRIM), tag->code); fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel, classStr, Form2FormStr (CONS), tag->code); } else fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel, classStr, formStr, tag->code); } if (!stoleChoiceTags) { fprintf (src,"))\n"); fprintf (src, " {\n"); fprintf (src," elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, totalLevel); } AsnListFirst (tags); AsnListNext (tags); FOR_REST_LIST_ELMT (tag, tags) { classStr = Class2ClassStr (tag->tclass); codeStr = Code2UnivCodeStr (tag->code); formStr = Form2FormStr (tag->form); if (stoleChoiceTags) { fprintf (src," ||\n"); if (tag->tclass == UNIV) { if (tag->form == ANY_FORM) { fprintf (src," (tagId%d ==MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, Form2FormStr (PRIM), codeStr); fprintf (src,"||\n (tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, Form2FormStr (CONS), codeStr); } else fprintf (src," (tagId%d ==MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, formStr, codeStr); } else { if (tag->form == ANY_FORM) { fprintf (src," (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel, classStr, Form2FormStr (PRIM), tag->code); fprintf (src,"||\n (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel, classStr, Form2FormStr (CONS), tag->code); } else fprintf (src," (tagId%d == MAKE_TAG_ID (%s, %s, %d))", tagLevel, classStr, formStr, tag->code); } } else { tagLevel = initialTagLevel + 2; fprintf (src, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel, totalLevel); if (tag->tclass == UNIV) { if (tag->form == ANY_FORM) { fprintf (src," if ((tagId%d != MAKE_TAG_ID (%s, %s, %s)) &&\n", tagLevel, classStr, Form2FormStr (PRIM), codeStr); fprintf (src," (tagId%d != MAKE_TAG_ID (%s, %s, %s)))\n", tagLevel, classStr, Form2FormStr (CONS), codeStr); } else fprintf (src," if (tagId%d != MAKE_TAG_ID (%s, %s, %s))\n", tagLevel, classStr, formStr, codeStr); } else { if (tag->form == ANY_FORM) { fprintf (src," if ((tagId%d != MAKE_TAG_ID (%s, %s, %d)) &&\n", tagLevel, classStr, Form2FormStr (PRIM), tag->code); fprintf (src," (tagId%d != MAKE_TAG_ID (%s, %s, %d)))\n", tagLevel, classStr, Form2FormStr (CONS), tag->code); } else fprintf (src," if (tagId%d != MAKE_TAG_ID (%s, %s, %d))\n", tagLevel, classStr, formStr, tag->code); } fprintf (src," {\n"); fprintf (src," Asn1Error (\"Unexpected Tag\\n\");\n"); fprintf (src," longjmp (env, %d);\n",(*longJmpValG)--); fprintf (src," }\n\n"); fprintf (src," elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, totalLevel); } } /* end tag list for */ if (stoleChoiceTags) { fprintf (src,"))\n"); fprintf (src, " {\n"); fprintf (src, " elmtLen%d = BDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, totalLevel); } } MakeVarPtrRef (genDecCRulesG, td, parent, e->type, varName, tmpVarName); /* * allocate mem for decoding result */ PrintElmtAllocCode (src, e->type, tmpVarName); PrintCBerElmtDecodeCode (src, td, parent, e->type, elmtLevel, totalLevel, tagLevel, varName, tmpVarName, stoleChoiceTags); /* * must check for another EOC for ANYs * Since the any decode routines * decode their own first tag/len pair */ if ((builtinType == BASICTYPE_ANY) || (builtinType == BASICTYPE_ANYDEFINEDBY)) PrintEocDecoders (src, elmtLevel, initialElmtLevel, itemLenVarNameG, totalLevel, decodedLenVarNameG); /* * must check for another EOC for tagged CHOICEs * since the choice decoder routines do not check * for an EOC on the choice's overall length - * they are only passed the tag/len of the choice's * component. */ else if ((builtinType == BASICTYPE_CHOICE) && (!stoleChoiceTags) && ((tags != NULL) && !LIST_EMPTY (tags))) PrintEocDecoders (src, elmtLevel, initialElmtLevel, itemLenVarNameG, totalLevel, decodedLenVarNameG); else PrintEocDecoders (src, elmtLevel-1, initialElmtLevel, itemLenVarNameG, totalLevel, decodedLenVarNameG); /* could check cons len vs decode len here */ if (!inTailOptElmts) { /* * determine whether next elmt in Seq is start * of tailing optionals */ AsnListNext (elmts); inTailOptElmts = IsTailOptional (elmts); AsnListPrev (elmts); } /* * print code for getting the next tag */ tmpTypeId = GetBuiltinType (e->type); if (e != last) { tmpElmt = (NamedType*)NEXT_LIST_ELMT (elmts); tmpTypeId = GetBuiltinType (tmpElmt->type); if (!inTailOptElmts) { if (((tmpTypeId == BASICTYPE_ANY) || (tmpTypeId == BASICTYPE_ANYDEFINEDBY)) && (CountTags (tmpElmt->type) == 0)) { if ((e->type->optional) || ((tmpElmt->type->optional) && (tmpElmt != last))) { /* let this cause a compile error in the gen'd code */ fprintf (src," <problems with untagged ANY that is optional or follows an optional sequence element - you must fix this>\n"); } /* don't get a tag since ANY's decode their own */ } else fprintf (src, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n", initialTagLevel+1, totalLevel); } else { fprintf (src, " if ((elmtLen%d != INDEFINITE_LEN) && (totalElmtsLen%d == elmtLen%d))\n", initialElmtLevel, totalLevel, initialElmtLevel); fprintf (src, " seqDone = TRUE;\n"); fprintf (src, " else\n"); fprintf (src, " {\n"); if (((tmpTypeId == BASICTYPE_ANY) || (tmpTypeId == BASICTYPE_ANYDEFINEDBY)) && (CountTags (tmpElmt->type) == 0)) { if ((e->type->optional) || ((tmpElmt->type->optional) && (tmpElmt != last))) { /* let this cause a compile error in the gen'd code */ fprintf (src," <problems with untagged ANY that is optional or follows an optional sequence element - you must fix this>\n"); } /* peek ahead for first octet of eoc */ fprintf (src," tagId%d = BufPeekByte (b);\n", initialTagLevel+1); fprintf (src," if ((elmtLen%d == INDEFINITE_LEN) && (tagId%d == EOC_TAG_ID))\n", initialElmtLevel, initialTagLevel+1); fprintf (src, " {\n"); fprintf (src, " BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel); fprintf (src, " seqDone = TRUE;\n"); fprintf (src, " }\n"); } else { fprintf (src, " tagId%d = BDecTag (b, &totalElmtsLen%d, env);\n\n", initialTagLevel+1, totalLevel); fprintf (src," if ((elmtLen%d == INDEFINITE_LEN) && (tagId%d == EOC_TAG_ID))\n", initialElmtLevel, initialTagLevel+1); fprintf (src, " {\n"); fprintf (src, " BDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", totalLevel); fprintf (src, " seqDone = TRUE;\n"); fprintf (src, " }\n"); } fprintf (src, " }\n"); } } else /* for last elmt only */ { fprintf (src," seqDone = TRUE;\n"); fprintf (src," if (elmtLen%d == INDEFINITE_LEN)\n", initialElmtLevel); fprintf (src," BDecEoc (b, &totalElmtsLen%d, env);\n", totalLevel); fprintf (src," else if (totalElmtsLen%d != elmtLen%d)\n", totalLevel, initialElmtLevel); fprintf (src," longjmp (env, %d);\n",(*longJmpValG)--); } /* * close (tag check/seqDone test) if block and * print else clause to handle missing non-optional elmt * errors */ tmpTypeId = GetBuiltinType (e->type); if (((tmpTypeId == BASICTYPE_ANYDEFINEDBY) || (tmpTypeId == BASICTYPE_ANY)) && (CountTags (e->type) == 0)) { /* close if stmt block */ fprintf (src," }\n"); } else if (!e->type->optional && (e->type->defaultVal == NULL)) { fprintf (src, " }\n"); /* end of tag check if */ fprintf (src, " else\n"); fprintf (src, " longjmp (env, %d);\n", (*longJmpValG)--); } else { fprintf (src, " }\n"); /* end of tag check if */ } fprintf (src,"\n\n"); FreeTags (tags); } /* * print code to make sure that truly finished with sequence */ fprintf (src," if (!seqDone)\n"); fprintf (src, " longjmp (env, %d);\n\n", (*longJmpValG)--);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -