📄 gen-dec.c
字号:
initialTagLevel = tagLevel; initialElmtLevel = elmtLevel; routineName = td->cTypeDefInfo->decodeRoutineName; if ((elmts == NULL) || LIST_EMPTY (elmts)) /* empty seq */ { fprintf (src," if (elmtLen%d == INDEFINITE_LEN)\n", elmtLevel); fprintf (src," {\n"); fprintf (src," %sDecEoc (b, &totalElmtsLen%d, env);\n", GetEncRulePrefix(), totalLevel); fprintf (src," }\n"); fprintf (src," else if (elmtLen%d != 0)\n", elmtLevel); fprintf (src," {\n"); fprintf (src," Asn1Error (\"Expected an empty SEQUENCE\\n\");\n"); fprintf (src," longjmp (env, %d);\n", (int)(*longJmpValG)--); fprintf (src," }\n");/* forget about extended types for now fprintf (src," tagId%d = %sDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel+1, GetEncRulePrefix(), totalLevel); fprintf (src," {\n"); fprintf (src," if (tagId%d == EOC_TAG_ID)\n", tagLevel+1); fprintf (src," %sDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", GetEncRulePrefix(), totalLevel); fprintf (src," else\n"); fprintf (src," BerDiscardElmt (b, &totalElmtsLen%d, env);\n\n",totalLevel); fprintf (src," }\n"); fprintf (src," else \n"); fprintf (src," {\n"); fprintf (src," BufSkip (b, elmtLen%d);\n", elmtLevel); fprintf (src," totalElmtsLen%d += elmtLen%d\n", totalLevel, elmtLevel); fprintf (src," }\n");*/ return; } /* * must set list curr since IsTailOptional checks from curr pt * onward */ AsnListFirst (elmts); inTailOptElmts = IsTailOptional (elmts); e = (NamedType*)FIRST_LIST_ELMT (elmts); tmpTypeId = GetBuiltinType (e->type); /* * print code to decode the first tag */ tagLevel++; if (!inTailOptElmts) { 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 = %sDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel, GetEncRulePrefix(), 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 = %sDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel, GetEncRulePrefix(), totalLevel); fprintf (src," if ((elmtLen%d == INDEFINITE_LEN) && (tagId%d == EOC_TAG_ID))\n", elmtLevel, tagLevel); fprintf (src, " {\n"); fprintf (src, " %sDEC_2ND_EOC_OCTET (b, &totalElmtsLen%d, env)\n", GetEncRulePrefix(), 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)) { if(e->type->extensionAddition) { fprintf (src, "<Extensibility not supported in c-library>\n"); fprintf (src, "<--Suggest removing extension marker and making all respective extension additions optional>\n"); } else { 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 = DetermineCode(tag, NULL, 0);//RWC;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, %s)) ||\n", tagLevel, classStr, Form2FormStr (PRIM), DetermineCode(tag, NULL, 1));//RWC;tag->code); fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, Form2FormStr (CONS), DetermineCode(tag, NULL, 1));//RWC;tag->code); } else fprintf (src,"(tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, formStr, DetermineCode(tag, NULL, 1));//RWC;tag->code); } if (!stoleChoiceTags) { fprintf (src,"))\n"); fprintf (src, " {\n"); fprintf (src," elmtLen%d = %sDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, GetEncRulePrefix(), totalLevel); } AsnListFirst (tags); AsnListNext (tags); FOR_REST_LIST_ELMT (tag, tags) { classStr = Class2ClassStr (tag->tclass); codeStr = DetermineCode(tag, NULL, 0);//RWC;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, %s))", tagLevel, classStr, Form2FormStr (PRIM), DetermineCode(tag, NULL, 1));//RWC;tag->code); fprintf (src,"||\n (tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, Form2FormStr (CONS), DetermineCode(tag, NULL, 1));//RWC;tag->code); } else fprintf (src," (tagId%d == MAKE_TAG_ID (%s, %s, %s))", tagLevel, classStr, formStr, DetermineCode(tag, NULL, 1));//RWC;tag->code); } } else { tagLevel = initialTagLevel + 2; fprintf (src, " tagId%d = %sDecTag (b, &totalElmtsLen%d, env);\n\n", tagLevel, GetEncRulePrefix(), 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, %s)) &&\n", tagLevel, classStr, Form2FormStr (PRIM), DetermineCode(tag, NULL, 1));//RWC;tag->code); fprintf (src," (tagId%d != MAKE_TAG_ID (%s, %s, %s)))\n", tagLevel, classStr, Form2FormStr (CONS), DetermineCode(tag, NULL, 1));//RWC;tag->code); } else fprintf (src," if (tagId%d != MAKE_TAG_ID (%s, %s, %s))\n", tagLevel, classStr, formStr, DetermineCode(tag, NULL, 1));//RWC;tag->code); } fprintf (src," {\n"); fprintf (src," Asn1Error (\"Unexpected Tag\\n\");\n"); fprintf (src," longjmp (env, %d);\n",(int)(*longJmpValG)--); fprintf (src," }\n\n"); fprintf (src," elmtLen%d = %sDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, GetEncRulePrefix(), totalLevel); } } /* end tag list for */ if (stoleChoiceTags) { fprintf (src,"))\n"); fprintf (src, " {\n"); fprintf (src, " elmtLen%d = %sDecLen (b, &totalElmtsLen%d, env);\n", ++elmtLevel, GetEncRulePrefix(), totalLevel); } } MakeVarPtrRef (genDecCRulesG, td, parent, e->type, varName, tmpVarName); /* * allocate mem for decoding result */ PrintElmtAllocCode (src, e->type, tmpVarName); PrintCElmtDecodeCode (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 = %sDecTag (b, &totalElmtsLen%d, env);\n", initialTagLevel+1, GetEncRulePrefix(), 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");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -