📄 gen-code.c
字号:
FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice) { if (e->type->cxxTypeRefInfo->isPtr) { fprintf (src, " case %s:\n", e->type->cxxTypeRefInfo->choiceIdSymbol); fprintf (src, " delete %s;\n", e->type->cxxTypeRefInfo->fieldName); fprintf (src, " break;\n"); } } fprintf (src, " }\n"); fprintf (src, " switch (choiceId = that.choiceId)\n"); fprintf (src, " {\n"); FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice) { fprintf (src, " case %s:\n", e->type->cxxTypeRefInfo->choiceIdSymbol); if (e->type->cxxTypeRefInfo->isPtr) { fprintf (src, " %s = new %s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className); fprintf (src, " *%s = *that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName); } else fprintf (src, " %s = that.%s;\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->fieldName); fprintf (src, " break;\n"); } fprintf (src, " }\n"); fprintf (src, " }\n"); fprintf (src, "\n"); fprintf (src, " return *this;\n"); fprintf (src, "#else // SNACC_DEEP_COPY\n"); fprintf (src, " Asn1Error << \"use of incompletely defined %s &%s::operator = (const %s &)\" << endl;\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className); fprintf (src, " abort();\n"); fprintf (src, " // if your compiler complains here, check the -novolat option\n"); if (novolatilefuncs) { fprintf (src, " return *this;\n"); } fprintf (src, "#endif // SNACC_DEEP_COPY\n"); fprintf (src, "}\n\n"); /* BerEncodeContent */ if (printEncodersG) { fprintf (hdr, " %s B%s (%s b);\n", lenTypeNameG, r->encodeContentBaseName, bufTypeNameG); fprintf (src, "%s\n", lenTypeNameG); fprintf (src, "%s::B%s (%s b)\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName, bufTypeNameG); fprintf (src, "{\n"); /* print local vars */ fprintf (src, " %s l;\n", lenTypeNameG); fprintf (src, " switch (%s)\n", r->choiceIdFieldName); fprintf (src, " {\n"); FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice) { cxxtri = e->type->cxxTypeRefInfo; fprintf (src, " case %s:\n", cxxtri->choiceIdSymbol); varName = cxxtri->fieldName; /* encode Eoc (s) if nec */ PrintCxxEocEncoders (src, td, e->type, "b"); /* encode content */ tmpTypeId = GetBuiltinType (e->type); if (tmpTypeId == BASICTYPE_ANYDEFINEDBY) { defByNamedType = e->type->basicType->a.anyDefinedBy->link; /*dafe Now I will try to write code for BASICTYPE_CHOICE */ if (GetBuiltinType (defByNamedType->type) == BASICTYPE_CHOICE) { fprintf (src, " if ( %s->choiceId == ActionTypeId::globalFormCid ) \n", defByNamedType->type->cxxTypeRefInfo->fieldName); fprintf (src, " {\n"); fprintf (src, " %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); fprintf (src, "SetTypeByOid( *( %s->globalForm, Global_%s));\n", defByNamedType->type->cxxTypeRefInfo->fieldName, td->cxxTypeDefInfo->className); fprintf (src, " } else\n"); fprintf (src, " {\n"); fprintf (src, " %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); /* to global mark with class name */ fprintf (src, "SetTypeByInt( *( %s->localForm), Global_%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName, td->cxxTypeDefInfo->className); fprintf (src, " }\n"); } else { fprintf (src, " %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); if (GetBuiltinType (defByNamedType->type) == BASICTYPE_OID) { fprintf (src, "SetTypeByOid ("); if (defByNamedType->type->cxxTypeRefInfo->isPtr) fprintf (src, " *"); fprintf (src, "%s, Global_%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName, td->cxxTypeDefInfo->className); } else { fprintf (src, "SetTypeByInt ("); if (defByNamedType->type->cxxTypeRefInfo->isPtr) fprintf (src, " *"); /* to global mark with class name */ fprintf (src, "%s, , Global_%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName, td->cxxTypeDefInfo->className); } } fprintf (src, " l = %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); fprintf (src, "B%s (b);\n", r->encodeBaseName); } else if (tmpTypeId == BASICTYPE_ANY) { /* dafe not to generate ??? - later repair fprintf (src, " %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); fprintf (src, "SetTypeBy???(???);\n");*/ fprintf (src, " l = %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); fprintf (src, "B%s (b);\n", r->encodeBaseName); } else { fprintf (src, " l = %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); fprintf (src, "B%s (b);\n", r->encodeContentBaseName); } /* encode tag (s) & len (s) */ PrintCxxTagAndLenEncodingCode (src, td, e->type, "l", "b"); fprintf (src, " break;\n\n"); } fprintf (src, " } // end switch\n"); fprintf (src, " return l;\n"); fprintf (src, "} // %s::B%s\n\n\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName); } /* end of BerEncodeContent method */ /* BerDecodeContent */ if (printDecodersG) { fprintf (hdr, " void B%s (%s b, %s tag, %s elmtLen, %s &bytesDecoded, %s env);\n", r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG, envTypeNameG); 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); fprintf (src, "{\n"); /* print local vars */ /* count max number of extra length var nec * by counting tag/len pairs on components of the CHOICE */ varCount = 0; FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice) { tmpVarCount = CxxCountVariableLevels (e->type); if (tmpVarCount > varCount) varCount = tmpVarCount; } /* write extra length vars - remeber choice content * decoders are passed the 'key' tag so need one less * than max var count. */ for (i = 1; i < varCount; i++) fprintf (src, " %s elmtLen%d;\n", lenTypeNameG, i); /* switch on given tag - choices always have the key tag decoded */ fprintf (src, " switch (tag)\n"); fprintf (src, " {\n"); FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice) { cxxtri = e->type->cxxTypeRefInfo; tags = GetTags (e->type, &stoleChoiceTags); if (LIST_EMPTY (tags)) { fprintf (src, " // ANY Type riadok 1655\n"); } else { tag = (Tag*)FIRST_LIST_ELMT (tags); classStr = Class2ClassStr (tag->tclass); codeStr = Code2UnivCodeStr (tag->code); formStr = Form2FormStr (tag->form); if (tag->tclass == UNIV) { if (tag->form == ANY_FORM) { fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr); fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr); } else fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, formStr, codeStr); } else { if (tag->form == ANY_FORM) { fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (PRIM), tag->code); fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (CONS), tag->code); } else fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, formStr, tag->code); } /* now decode extra tags/length pairs */ AsnListFirst (tags); AsnListNext (tags); elmtLevel = 0; if (stoleChoiceTags) { FOR_REST_LIST_ELMT (tag, tags) { classStr = Class2ClassStr (tag->tclass); codeStr = Code2UnivCodeStr (tag->code); formStr = Form2FormStr (tag->form); if (tag->tclass == UNIV) { if (tag->form == ANY_FORM) { fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (PRIM), codeStr); fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, Form2FormStr (CONS), codeStr); } else fprintf (src, " case MAKE_TAG_ID (%s, %s, %s):\n", classStr, formStr, codeStr); } else { if (tag->form == ANY_FORM) { fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (PRIM), tag->code); fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, Form2FormStr (CONS), tag->code); } else fprintf (src, " case MAKE_TAG_ID (%s, %s, %d):\n", classStr, formStr, tag->code); } } } else /* didn't steal nested choice's tags */ { FOR_REST_LIST_ELMT (tag, tags) { classStr = Class2ClassStr (tag->tclass); codeStr = Code2UnivCodeStr (tag->code); formStr = Form2FormStr (tag->form); fprintf (src, " tag = BDecTag (b, bytesDecoded, env);\n"); if (tag->form == ANY_FORM) { if (tag->tclass == UNIV) { fprintf (src, " if ((tag != MAKE_TAG_ID (%s, %s, %s))\n", classStr, Form2FormStr (PRIM), codeStr); fprintf (src, " && (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), codeStr); } else { fprintf (src, " if ((tag != MAKE_TAG_ID (%s, %s, %d))\n", classStr, Form2FormStr (PRIM), tag->code); fprintf (src, " && (tag != MAKE_TAG_ID (%s, %s, %d)))\n", classStr, Form2FormStr (CONS), tag->code); } } else { if (tag->tclass == UNIV) fprintf (src, " if (tag != MAKE_TAG_ID (%s, %s, %s))\n", classStr, formStr, codeStr); else fprintf (src, " if (tag != MAKE_TAG_ID (%s, %s, %d))\n", classStr, formStr, tag->code); } fprintf (src, " {\n"); fprintf (src, " Asn1Error << \"Unexpected Tag\" << endl;\n"); fprintf (src, " longjmp (env, %d);\n", longJmpValG--); fprintf (src, " }\n\n"); fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel); } } } /* * if the choices element is another choice && * we didn't steal its tags then we must grab * the key tag out of the contained CHOICE */ if (!stoleChoiceTags && (GetBuiltinType (e->type) == BASICTYPE_CHOICE)) { fprintf (src, " tag = BDecTag (b, bytesDecoded, env);\n"); fprintf (src, " elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel); } varName = cxxtri->fieldName; /* set choice id for to this elment */ fprintf (src, " %s = %s;\n", r->choiceIdFieldName, cxxtri->choiceIdSymbol); /* alloc elmt if nec */ if (cxxtri->isPtr) fprintf (src, " %s = new %s;\n", varName, cxxtri->className); /* decode content */ tmpTypeId = GetBuiltinType (e->type); if (tmpTypeId == BASICTYPE_ANYDEFINEDBY) { /* * must check for another EOC for ANYs * since the any decode routines decode * their own first tag/len pair */ elmtLevel++; defByNamedType = e->type->basicType->a.anyDefinedBy->link; /*dafe Now I will try to write code for BASICTYPE_CHOICE */ if (GetBuiltinType (defByNamedType->type) == BASICTYPE_CHOICE) { fprintf (src, " if ( %s->choiceId == ActionTypeId::globalFormCid ) \n", defByNamedType->type->cxxTypeRefInfo->fieldName); fprintf (src, " {\n"); fprintf (src, " %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, "."); fprintf (src, "SetTypeByOid( *( %s->globalForm), Global_%s);\n", defByNamedType->type->cxxTypeRefInfo->fieldName, td->cxxTypeDefInfo->className); fprintf (src, " } else\n"); fprintf (src, " {\n"); fprintf (src, " %s", varName); if (cxxtri->isPtr) fprintf (src, "->"); else fprintf (src, ".");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -