⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen-code.c

📁 asn to c编译器 源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
                if (!stoleChoiceTags && (GetBuiltinType (e->type) == BASICTYPE_CHOICE))                {                    fprintf (src, "      tag = BDecTag (_b, bytesDecoded);\n");                    fprintf (src, "      elmtLen%d = BDecLen (_b, bytesDecoded);\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;                    PrintCxxSetTypeByCode(defByNamedType, cxxtri, src);                    fprintf (src, "      %s", varName);                    if (cxxtri->isPtr)                        fprintf (src, "->");                    else                        fprintf (src, ".");                    fprintf (src, "B%s (_b, bytesDecoded);\n",  r->decodeBaseName);                }                else if (tmpTypeId == BASICTYPE_ANY)                {                    elmtLevel++;                    fprintf (src, "        %s", varName);                    if (cxxtri->isPtr)                       fprintf (src, "->");                    else                       fprintf (src, ".");                    fprintf (src, "B%s (_b, bytesDecoded);\n",  r->decodeBaseName);                }                else if ( (tmpTypeId == BASICTYPE_OCTETCONTAINING) ||							     (tmpTypeId == BASICTYPE_BITCONTAINING) )                {                   PrintCxxDecodeContaining(e->type, r, src);                }                else                {                    fprintf (src, "        %s", varName);                    if (cxxtri->isPtr)                        fprintf (src, "->");                    else                        fprintf (src, ".");                    fprintf (src, "B%s (_b, tag, elmtLen%d, bytesDecoded);\n",  r->decodeContentBaseName, elmtLevel);                }                /* decode Eoc (s) */                for (i = elmtLevel-1; i >= 0; i--)                {                    fprintf (src, "      if (elmtLen%d == INDEFINITE_LEN)\n", i);                    fprintf (src, "        BDecEoc (_b, bytesDecoded);\n");                }                fprintf (src, "      break;\n\n");                FreeTags (tags);            }        }        fprintf (src, "    default:\n");        fprintf (src, "    {");        if(extensionsExist)        {            fprintf (src, "     AsnAny extAny;\n");            fprintf (src, "     extension = new AsnExtension;\n");            fprintf (src, "     choiceId = extensionCid;\n");            fprintf (src, "     extAny.BDecContent(_b, tag, elmtLen0, bytesDecoded);\n");            fprintf (src, "     extension->extList.insert( extension->extList.end(), extAny );\n");        }        else        {            fprintf (src, "        throw InvalidTagException(typeName(), tag, STACK_ENTRY);\n");        }        fprintf (src, "      break;\n");        fprintf (src, "    }\n");        fprintf (src, "  } // end switch\n");        fprintf (src, "} // %s::B%s\n\n\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName);    }    /* end of code for printing BDecodeContent method */    /* do BEnc function */    if (printEncodersG)    {        fprintf (hdr, "  %s		B%s (%s &_b) const;\n", lenTypeNameG, r->encodeBaseName, bufTypeNameG);        fprintf (src, "%s %s::B%s (%s &_b) const\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeBaseName, bufTypeNameG);        fprintf (src, "{\n");        fprintf (src, "    %s l=0;\n", lenTypeNameG);        fprintf (src, "    l = B%s (_b);\n", r->encodeContentBaseName);        /* encode each tag/len pair if any */        FOR_EACH_LIST_ELMT_RVS (tag, choice->tags)        {            classStr = Class2ClassStr (tag->tclass);            formStr = Form2FormStr (CONS);  /* choices are constructed */            //RWC;tagLen = TagByteLen (tag->code);            fprintf (src, "    l += BEncConsLen (_b, l);\n");            if (tag->tclass == UNIV)            {                const char* ptr = DetermineCode(tag, &tagLen, 1);                fprintf (src, "    l += BEncTag%d (_b, %s, %s, %s);\n", tagLen, classStr, formStr, ptr);//RWC;Code2UnivCodeStr (tag->code));            }            else            {                const char* ptr = DetermineCode(tag, &tagLen, 1);                fprintf (src, "    l += BEncTag%d (_b, %s, %s, %s);\n", tagLen, classStr, formStr, ptr);//RWC;tag->code);            }        }        fprintf (src, "    return l;\n");        fprintf (src, "}\n\n");    }    /* end of BEnc function */    /* Do BDec function */    if (printDecodersG)    {        fprintf (hdr, "  void			B%s (const %s &_b, %s &bytesDecoded);\n", r->decodeBaseName, bufTypeNameG, lenTypeNameG);        fprintf (src, "void %s::B%s (const %s &_b, %s &bytesDecoded)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG);//, envTypeNameG);        fprintf (src, "{\n");        if (choice->tags->count > 0)           fprintf (src, "    FUNC(\"%s::B%s\")\n", td->cxxTypeDefInfo->className, r->decodeBaseName);        fprintf (src, "    %s elmtLen = 0;\n", lenTypeNameG);        fprintf (src, "    %s tag;\n", tagTypeNameG);        /* print extra locals for redundant lengths */        for (i = 1; (choice->tags != NULL) && (i <= LIST_COUNT (choice->tags)); i++)        {            fprintf (src, "    %s extraLen%d = 0;\n", lenTypeNameG, i);        }        fprintf (src, "\n");        /*  decode tag/length pair (s) */        elmtLevel = 0;        FOR_EACH_LIST_ELMT (tag, choice->tags)        {            classStr = Class2ClassStr (tag->tclass);            formStr = Form2FormStr (CONS);  /* choices are constructed */            fprintf (src, "    AsnTag tagId = BDecTag (_b, bytesDecoded);\n");            fprintf (src, "    if (tagId != ");            if (tag->tclass == UNIV)            {                fprintf (src, "MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, DetermineCode(tag, NULL, 0));//RWC;Code2UnivCodeStr (tag->code));            }            else            {                fprintf (src, "MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, DetermineCode(tag, NULL, 1));//RWC;tag->code);            }            fprintf (src, "    {\n");            fprintf (src, "          throw InvalidTagException(typeName(), tagId, STACK_ENTRY);\n");            fprintf (src, "    }\n");            fprintf (src, "    extraLen%d = BDecLen (_b, bytesDecoded);\n", ++elmtLevel);        }        /* decode identifying tag from choice body */        fprintf (src, "    /*  CHOICEs are a special case - grab identifying tag */\n");        fprintf (src, "    /*  this allows easier handling of nested CHOICEs */\n");        fprintf (src, "    tag = BDecTag (_b, bytesDecoded);\n");        fprintf (src, "    elmtLen = BDecLen (_b, bytesDecoded);\n");        fprintf (src, "    B%s (_b, tag, elmtLen, bytesDecoded);\n", r->decodeContentBaseName);        /* grab any EOCs that match redundant, indef lengths */        for (i = elmtLevel; i > 0; i--)        {            fprintf (src, "    if (extraLen%d == INDEFINITE_LEN)\n", i);            fprintf (src, "        BDecEoc (_b, bytesDecoded);\n");        }        fprintf (src, "}\n\n");    }    /* end of BDec function */   if(genPERCode)   {    /* do PER Encode, PEnc function */    if (printEncodersG)    {        /****************************/        /*** FIRST, handle index encoding for PER Choice.  Taking advantage of            * the AsnInt class with constraints for the detailed encoding            * details.  Declare outside scope of source method for PEnc/PDec. */        fprintf (src, "class AsnIntChoice_%s: public AsnInt  {\n", td->cxxTypeDefInfo->className);        fprintf (src, "  public:\n");        fprintf (src, "  AsnIntChoice_%s(AsnIntType val=0):AsnInt(val){ }\n",                          td->cxxTypeDefInfo->className);        fprintf (src, "  ValueRange* ValueRanges(int &sizeVRList)\n");        fprintf (src, "  {\n");        fprintf (src, "  	static ValueRange INT1_ValueRangeList[] = \n");        fprintf (src, "  		{{ 0, %d, 1 }};\n",                 choice->basicType->a.choice->count);  /* CONSTANT value for this CHOICE. */        fprintf (src, "  	sizeVRList = 1;\n");        fprintf (src, "  	return INT1_ValueRangeList;\n");        fprintf (src, "  }\n");        fprintf (src, "};\n\n");		//RWC;fprintf (hdr, "  AsnLen		PEnc(AsnBufBits &_b, bool bAlign = false) const {AsnLen len; len = 1;return len;};\n");        fprintf (hdr, "  %s		P%s (AsnBufBits &_b) const;\n", lenTypeNameG, r->encodeBaseName);        fprintf (src, "%s %s::P%s (AsnBufBits &_b) const\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeBaseName);        fprintf (src, "{\n");        fprintf (src, "    %s l=0;\n", lenTypeNameG);        fprintf (src, "    FUNC(\"%s::P%s (AsnBufBits &_b)\");\n", td->cxxTypeDefInfo->className, r->encodeBaseName);        /****************************/        /*** PERFORM sorting of Choice elements for proper index setting. */        PrintCxxDefCode_PERSort(&ppElementNamedType, &pElementTag, choice->basicType->a.choice);        fprintf (src, "  AsnIntChoice_%s TmpAsnIntChoice(%d);\n",                  td->cxxTypeDefInfo->className,                  choice->basicType->a.choice->count);  /* CONSTANT value for this CHOICE. */        for (ii=0; ii < choice->basicType->a.choice->count; ii++)        {            fprintf (src, "   if (%s == %s::%s)\n", r->choiceIdFieldName,                   td->cxxTypeDefInfo->className,                   ppElementNamedType[ii]->type->cxxTypeRefInfo->choiceIdSymbol);            fprintf (src, "      TmpAsnIntChoice.Set(%d); // SORTED index value.\n", ii);        }       // END FOR ii        free(ppElementNamedType);        free(pElementTag);        /*** SETUP specific sorted index value. */        fprintf (src, "  l = TmpAsnIntChoice.PEnc(_b); // LOAD PER encoded, constrained Choice index value.\n");        /****************************/        /*** NOW, setup each individual Choice element.*/        //RWC;fprintf (src, "    l = P%s (_b);\n", r->encodeContentBaseName);        /* print local vars */        //RWC;fprintf (src, "  %s l=0;\n", lenTypeNameG);        /* encode tag (s) & len (s) */        //PrintCxxTagAndLenEncodingCode (src, td, e->type, "l", "_b");        // RWC; TAGS already encoded if necessary above (non-UNIV).        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 content */            tmpTypeId = GetBuiltinType (e->type);            if (tmpTypeId == BASICTYPE_ANYDEFINEDBY)            {               defByNamedType = e->type->basicType->a.anyDefinedBy->link;               PrintCxxSetTypeByCode(defByNamedType, cxxtri, src);            }            else if (tmpTypeId == BASICTYPE_ANY)            {                fprintf (src, "    l += %s", varName);                if (cxxtri->isPtr)                    fprintf (src, "->");                else                    fprintf (src, ".");                fprintf (src, "P%s (_b);\n", r->encodeBaseName);            }            else if ( (tmpTypeId == BASICTYPE_OCTETCONTAINING) ||                      (tmpTypeId == BASICTYPE_BITCONTAINING))            {               PrintCxxPEREncodeContaining(e->type, r, src);            }            else            {                fprintf (src, "      l += %s", varName);                if (cxxtri->isPtr)                    fprintf (src, "->");                else                    fprintf (src, ".");                fprintf (src, "P%s (_b);\n", r->encodeBaseName);            }            fprintf (src, "      break;\n\n");        }        fprintf (src, "      default:\n");		  fprintf (src, "         throw EXCEPT(\"Choice is empty\", ENCODE_ERROR);\n");        fprintf (src, "  } // end switch\n");        /****************************/        fprintf (src, "    return l;\n");        fprintf (src, "}    //%s::P%s(...)\n\n", td->cxxTypeDefInfo->className, r->encodeBaseName);    }       /* END IF printEncodersG */    /* end of PEnc function */    /* Do PDec function */    if (printDecodersG)    {        fprintf (hdr, "  void			P%s (AsnBufBits &_b, %s &bitsDecoded);\n", r->decodeBaseName, lenTypeNameG);        fprintf (src, "void %s::P%s (AsnBufBits &_b, %s &bitsDecoded)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, lenTypeNameG);//, envTypeNameG);        fprintf (src, "{\n");        fprintf (src, "\tClear();\n");        /* print extra locals for redundant lengths */        for (i = 1; (choice->tags != NULL) && (i <= LIST_COUNT (choice->tags)); i++)        {            //fprintf (src, "    %s extraLen%d = 0; \n", lenTypeNameG, i);        }        fprintf (src, "\n");        /*  decode tag/length pair (s) */        elmtLevel = 0;        /****************************/        fprintf (src, "  AsnIntChoice_%s TmpAsnIntChoice;\n", td->cxxTypeDefInfo->className);        /*** SETUP specific sorted index value. */        fprintf (src, "  TmpAsnIntChoice.PDec(_b, bitsDecoded); // LOAD PER decoded, constrained Choice index value.\n");        /* decode identifying tag from choice body */        fprintf (src, "    /*  CHOICEs are a special case - grab identifying tag */\n");        fprintf (src, "    /*  this allows easier handling of nested CHOICEs */\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;        }         /*** PERFORM sorting of Choice elements for proper index setting, then              determine actual Choice chosen by the user. */        PrintCxxDefCode_PERSort(&ppElementNamedType, &pElementTag, choice->basicType->a.choice);        for (ii=0; ii < choice->basicType->a.choice->count; ii++)        {            fprintf (src, "   if (TmpAsnIntChoice == %d)\n", ii);            fprintf (src, "   {\n");             fprintf (src, "      %s = %s::%s;\n", r->choiceIdFieldName,                   td->cxxTypeDefInfo->className,                   ppElementNamedType[ii]->type->cxxTypeRefInfo->choiceIdSymbol);            /* Process specific tag - choices always have the key tag decoded */                e = ppElementNamedType[ii];                cxxtri

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -