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

📄 gen-code.c

📁 asn to c编译器 源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)    {        fprintf (hdr, "  ");        PrintCxxType (hdr, mods, m, r, td, choice, e->type);	    fprintf (hdr, "%s;\n\n", e->type->cxxTypeRefInfo->fieldName);    }    fprintf (hdr, "  };\n\n");    #if META        if (printMetaG)        {            PrintCxxChoiceDefCodeMeta_1(hdr, src, td, choice, m, e);        }    #endif /* META */    fprintf (hdr, "\n");    /* constructors and destructor */    fprintf (hdr, "   %s() {Init();}\n", td->cxxTypeDefInfo->className);    /* PIERCE 8-22-2001 */    PrintCopyConstructor(hdr, src, td->cxxTypeDefInfo->className);	PrintSimpleMeta(hdr,td->cxxTypeDefInfo->className,0);	/* Init() member function*/    fprintf (hdr, "   void Init(void);\n");    fprintf (src, "void %s::Init(void)\n", td->cxxTypeDefInfo->className);    fprintf (src, "{\n");    fprintf (src, "   // initialize choice to no choiceId to first choice and set pointer to NULL\n");    e = FIRST_LIST_ELMT (choice->basicType->a.choice);    fprintf (src, "  choiceId = %sCid;\n", e->type->cxxTypeRefInfo->fieldName);    fprintf (src, "  %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);    fprintf (src, "}\n\n");    fprintf (hdr, "\n   virtual int checkConstraints(ConstraintFailList* pConstraintFails)const;\n\n");	fprintf(src, "\nint %s::checkConstraints(ConstraintFailList* pConstraintFails) const\n{\n",		td->cxxTypeDefInfo->className);	FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)	{		if (e->type->cxxTypeRefInfo->isPtr)		{			fprintf(src, "\tif (%s != NULL)\n",				e->type->cxxTypeRefInfo->fieldName);			fprintf(src, "\t\t%s->checkConstraints(pConstraintFails);\n\n",				e->type->cxxTypeRefInfo->fieldName);		}		else		{			fprintf(src, "\t%s.checkConstraints(pConstraintFails);\n\n",				e->type->cxxTypeRefInfo->fieldName);		}	}	fprintf(src, "\treturn 0;\n");	fprintf(src, "}\n\n\n");    /* virtual destructor*/    fprintf (hdr, "   virtual ~%s() {Clear();}\n\n", td->cxxTypeDefInfo->className);    /* Clear() member*/    fprintf (hdr, "   void Clear();\n\n");    fprintf (src, "void %s::Clear()\n", td->cxxTypeDefInfo->className);    fprintf (src, "{\n");    fprintf (src, "  switch (choiceId)\n");    fprintf (src, "  {\n");    FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)    {        tmpTypeId = GetBuiltinType (e->type);	    fprintf (src, "    case %s:\n", e->type->cxxTypeRefInfo->choiceIdSymbol);	    if (e->type->cxxTypeRefInfo->isPtr)       {	      fprintf (src, "      delete %s;\n", e->type->cxxTypeRefInfo->fieldName);          fprintf (src, "      %s = NULL;\n", e->type->cxxTypeRefInfo->fieldName);       }        else if(!e->type->cxxTypeRefInfo->isPtr &&             ((tmpTypeId == BASICTYPE_CHOICE) ||                (tmpTypeId == BASICTYPE_SET) ||                (tmpTypeId == BASICTYPE_SEQUENCE)) )        {            fprintf (src, "  %s.Clear();\n", e->type->cxxTypeRefInfo->fieldName);        }	    fprintf (src, "      break;\n");    }    fprintf (src, "  } // end of switch\n");    fprintf (src, "} // end of Clear()\n");    fprintf (src, "\n");    /* print clone routine for ANY mgmt */    PrintCloneMethod (hdr, src, td);    fprintf (hdr, "  %s		&operator = (const %s &that);\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);    fprintf (src, "%s &%s::operator = (const %s &that)\n", td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className, td->cxxTypeDefInfo->className);    fprintf (src, "{\n");    fprintf (src, "  if (this != &that)\n");    fprintf (src, "  {\n");    fprintf (src, "    Clear();\n");       e = FIRST_LIST_ELMT (choice->basicType->a.choice);    fprintf (src, "    // Check first type in choice to determine if choice is empty\n");    fprintf (src, "    if (that.%s != NULL)\n", e->type->cxxTypeRefInfo->fieldName);    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(*that.%s);\n", e->type->cxxTypeRefInfo->fieldName, e->type->cxxTypeRefInfo->className,                    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, "       }// end of switch\n");    fprintf (src, "     }// end of if\n");    fprintf (src, "  }\n");    fprintf (src, "\n");    fprintf (src, "  return *this;\n");    fprintf (src, "}\n\n");    /* BerEncodeContent */    if (printEncodersG)    {        fprintf (hdr, "  %s		B%s (%s &_b) const;\n", lenTypeNameG, r->encodeContentBaseName, bufTypeNameG);        fprintf (src, "%s\n", lenTypeNameG);        fprintf (src, "%s::B%s (%s &_b) const\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName, bufTypeNameG);        fprintf (src, "{\n");        fprintf (src, "    FUNC(\"%s::B%s (%s &_b)\");\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName, bufTypeNameG);        /* print local vars */        fprintf (src, "  %s l=0;\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;            /* eSNACC 1.5 does not encode indefinite length             *             * PrintCxxEocEncoders (src, td, e->type, "_b");             */            /* 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, "B%s (_b);\n", r->encodeBaseName);            }            else if ( (tmpTypeId == BASICTYPE_OCTETCONTAINING) ||                      (tmpTypeId == BASICTYPE_BITCONTAINING))            {               PrintCxxEncodeContaining(e->type, r, src);            }            else if ( tmpTypeId == BASICTYPE_EXTENSION )            {                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, "      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::B%s\n\n\n", td->cxxTypeDefInfo->className, r->encodeContentBaseName);    }    /* end of BerEncodeContent method */    /* BerDecodeContent */    if (printDecodersG)    {        fprintf (hdr, "  void			B%s (const %s &_b, %s tag, %s elmtLen, %s &bytesDecoded /*, s env*/);\n", r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG);//, envTypeNameG);        fprintf (src, "void %s::B%s (const %s &_b, %s tag, %s elmtLen0, %s &bytesDecoded /*, s env*/)\n", td->cxxTypeDefInfo->className, r->decodeContentBaseName, bufTypeNameG, tagTypeNameG, lenTypeNameG, lenTypeNameG);//, envTypeNameG);        fprintf (src, "{\n");        fprintf (src, "   FUNC(\"%s::B%s()\");\n",td->cxxTypeDefInfo->className, r->decodeContentBaseName);         fprintf (src, "   Clear();\n");        //fprintf (src, "   Init();\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 - remember 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 = 0;\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)        {            if( e->type->basicType->choiceId == BASICTYPE_EXTENSION )            {                extensionsExist = TRUE;            }            else            {                            cxxtri =  e->type->cxxTypeRefInfo;                tags = GetTags (e->type, &stoleChoiceTags);                if (LIST_EMPTY (tags))                {                    fprintf (src, "    // ANY Type?\n");                    fprintf (src, "    case MAKE_TAG_ID (?, ?, ?):\n");                }                else                {                    tag = (Tag*)FIRST_LIST_ELMT (tags);                    classStr = Class2ClassStr (tag->tclass);                    formStr = Form2FormStr (tag->form);                    if (tag->tclass == UNIV)                    {                        codeStr = DetermineCode(tag, NULL, 0);//RWC;Code2UnivCodeStr (tag->code);                    }                    else                    {                        codeStr = DetermineCode(tag, NULL, 1);                    }                    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);                    }                    /* now decode extra tags/length pairs */                    AsnListFirst (tags);                    AsnListNext (tags);                    elmtLevel = 0;                    if (stoleChoiceTags)                    {                        FOR_REST_LIST_ELMT (tag, tags)                        {                            classStr = Class2ClassStr (tag->tclass);                            formStr = Form2FormStr (tag->form);                            if (tag->tclass == UNIV)                                codeStr = DetermineCode(tag, NULL, 0);//RWC;Code2UnivCodeStr (tag->code);                            else                                codeStr = DetermineCode(tag, NULL, 1);                            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 /* didn't steal nested choice's tags */                    {                        FOR_REST_LIST_ELMT (tag, tags)                        {                            classStr = Class2ClassStr (tag->tclass);                            codeStr = DetermineCode(tag, NULL, 0);//RWC;Code2UnivCodeStr (tag->code);                            formStr = Form2FormStr (tag->form);                            fprintf (src, "      tag = BDecTag (_b, bytesDecoded);\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, %s))\n", classStr, Form2FormStr (PRIM), DetermineCode(tag, NULL, 1));//RWC;tag->code);                                    fprintf (src, "          && (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), DetermineCode(tag, NULL, 1));//RWC;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, %s))\n", classStr, formStr, DetermineCode(tag, NULL, 1));//RWC;tag->code);                            }                            fprintf (src, "      {\n");                                                    fprintf (src, "        throw InvalidTagException(typeName(), tag, STACK_ENTRY);\n");                            fprintf (src, "      }\n\n");                            fprintf (src, "      elmtLen%d = BDecLen (_b, bytesDecoded);\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                 */

⌨️ 快捷键说明

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