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

📄 gen-code.c

📁 asn.1 compiler
💻 C
📖 第 1 页 / 共 5 页
字号:
    int i;    CNamedElmt *n;    int stoleChoiceTags;    int elmtLevel;    enum BasicTypeChoiceId typeId;    fprintf (hdr, "/* ");    SpecialPrintType (hdr, td, td->type);    fprintf (hdr, " */\n");    /* check if has been re-tagged     *   eg Foo ::= [APPLICATION 2] IMPLICIT REAL     * or if it has named elmts in which case a new class must     * be defined     *  eg Foo ::= INTEGER { one (1), two (2), three (3) }     */    if (IsNewType (td->type))    {	int	hasNamedElmts;#ifdef _IBM_ENC_#include "./ibm_editor/print_cxx_simple_def.h"#endif /* _IBM_ENC_ */        fprintf (hdr, "class %s: public %s\n", td->cxxTypeDefInfo->className, td->type->cxxTypeRefInfo->className);        fprintf (hdr, "{\n");        fprintf (hdr, "public:\n");        /*         * must explicitly call constructors for base class         */        PrintDerivedConstructors (hdr, r, td);        /* do named elmts enum if any */        /* for types with named elements, inherit from the base         * class and define and enum eg:         * Foo ::= INTEGER { one (1), two (2), five (5) }         *  ->         * class Foo: public AsnInt         * {         * public:         *		Foo(): AsnInt() {}         *		Foo (int val): AsnInt (int val) {}         *    enum { one = 1, two = 2, five = 5 };         * };         * or         * Foo2 ::= [APPLICATION 2] INTEGER         * -->         * class Foo: public AsnInt         * {         * public:         *		Foo(): AsnInt() {}         *		Foo (int val): AsnInt (int val) {}         *     AsnLen	BEnc { ....... } <-- holds new tag enc/dec         *     void	BDec { ....... }   <--/         *     int	BEncPdu { ....... }         *     int	BDecPdu { ....... }         * };         * (must 'inherit' constructors explicitly)         */        if (hasNamedElmts = HasNamedElmts (td->type))        {            fprintf (hdr, "  enum\n");            fprintf (hdr, "  {\n");            FOR_EACH_LIST_ELMT (n, td->type->cxxTypeRefInfo->namedElmts)            {                fprintf (hdr, "    %s = %d", n->name, n->value);                if (n != (CNamedElmt *)LAST_LIST_ELMT (td->type->cxxTypeRefInfo->namedElmts))                    fprintf (hdr, ",\n");                else                    fprintf (hdr, "\n");            }            fprintf (hdr, "  };\n");        }#if META	if (printMetaG)	{	    const char	*T, *t;	    int a3;	    fprintf (hdr, "\n");	    fprintf (hdr, "#if META\n");	    fprintf (src, "#if META\n\n");	    fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);	    fprintf (src, "{\n");	    fprintf (src, "  return new %s;\n", td->cxxTypeDefInfo->className);	    fprintf (src, "}\n\n");	    if (hasNamedElmts = HasNamedElmts (td->type))	    {		fprintf (hdr, "  static const AsnNameDesc	_nmdescs[];\n");		fprintf (src, "const AsnNameDesc %s::_nmdescs[] =\n", td->cxxTypeDefInfo->className);		fprintf (src, "{\n");		FOR_EACH_LIST_ELMT (n, td->type->cxxTypeRefInfo->namedElmts)#if 0 /* (no asn1 names available!) */		    if (printMetaG == META_backend_names)		    else /* META_asn1_names */#endif			fprintf (src, "  \"%s\", %s, // %d\n", n->name, n->name, n->value);		fprintf (src, "  NULL, -1\n");		fprintf (src, "};\n\n");	    }	    switch (GetBuiltinType (td->type))	    {		case BASICTYPE_BOOLEAN:		    T = "BOOLEAN";		    t = "Bool";		    a3 = FALSE;		    break;		case BASICTYPE_ENUMERATED:		    T = "ENUMERATED";		    t = "Enum";		    a3 = TRUE;		    break;		case BASICTYPE_INTEGER:		    T = "INTEGER";		    t = "Int";		    a3 = TRUE;		    break;		case BASICTYPE_REAL:		    T = "REAL";		    t = "Real";		    a3 = FALSE;		    break;		case BASICTYPE_OCTETSTRING:		    T = "OCTET_STRING";		    t = "Octs";		    a3 = FALSE;		    break;		case BASICTYPE_BITSTRING:		    T = "BIT_STRING";		    t = "Bits";		    a3 = TRUE;		    break;		case BASICTYPE_OID:		    T = "OID";		    t = "Oid";		    a3 = FALSE;	    	default:		    T =		    t = "?";		    a3 = FALSE;	    }	    fprintf (hdr, "  static const Asn%sTypeDesc	_desc;\n", t);	    fprintf (hdr, "  const AsnTypeDesc	*_getdesc() const;\n");	    fprintf (src, "const Asn%sTypeDesc %s::_desc\n", t, td->cxxTypeDefInfo->className);	    fprintf (src, "(\n");	    fprintf (src, "  &%sModuleDesc,\n", m->cxxname);	    if (printMetaG == META_backend_names)		fprintf (src, "  \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);	    else /* META_asn1_names */		fprintf (src, "  \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);	    fprintf (src, "  %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");	    fprintf (src, "  AsnTypeDesc::%s,\n", T);	    fprintf (src, "  create%s", td->cxxTypeDefInfo->className);	    if (a3)		fprintf (src, ",\n  %s", hasNamedElmts ? "_nmdescs" : "NULL");	    fprintf (src, "\n);\n\n");	    fprintf (src, "const AsnTypeDesc *%s::_getdesc() const\n", td->cxxTypeDefInfo->className);	    fprintf (src, "{\n");	    fprintf (src, "  return &_desc;\n");	    fprintf (src, "}\n\n");	    fprintf (hdr, "#endif // META\n");	    fprintf (src, "#endif // META\n\n");#if TCL#endif	}#endif /* META */        /*         * Re-do BerEncode, BerDeocode, BerDecodePdu and BerDecodePdu         * if this type has been re-tagged         */        if ((IsDefinedByLibraryType (td->type) && !HasDefaultTag (td->type))	  || (IsTypeRef (td->type) && ((td->type->tags != NULL) && !LIST_EMPTY (td->type->tags))))        {            /* only BerEn/Decode BerEn/DecodePdu need to be re-done if tags are different */            /* print clone routine for ANY mgmt */            PrintCloneMethod (hdr, src, td);            tags = GetTags (td->type, &stoleChoiceTags);            typeId = GetBuiltinType (td->type);            /* do BerEncode function */            if (printEncodersG)            {                fprintf (hdr, "  %s		B%s (%s b);\n", lenTypeNameG, r->encodeBaseName, bufTypeNameG);                fprintf (src, "%s %s::B%s (%s b)\n", lenTypeNameG, td->cxxTypeDefInfo->className, r->encodeBaseName, bufTypeNameG);                fprintf (src, "{\n");                fprintf (src, "    %s l;\n", lenTypeNameG);                PrintCxxEocEncoders (src, td, td->type, "b");                fprintf (src, "    l = BEncContent (b);\n");                /* encode each tag/len pair if any */                if (!stoleChoiceTags)                {                    FOR_EACH_LIST_ELMT_RVS (tag, tags)                    {                        classStr = Class2ClassStr (tag->tclass);                        if (tag->form == ANY_FORM)                        {                            formStr = Form2FormStr (PRIM);                            PrintCxxLenEncodingCode (src, FALSE, HasShortLen (td->type), "l", "b");                        }                        else                        {                            formStr = Form2FormStr (tag->form);                            PrintCxxLenEncodingCode (src, TRUE, HasShortLen (td->type), "l", "b");                        }                        fprintf (src, "\n");                        tagLen = TagByteLen (tag->code);                        if (tag->tclass == UNIV)                            fprintf (src, "    l += BEncTag%d (b, %s, %s, %s);\n", tagLen, classStr, formStr, Code2UnivCodeStr (tag->code));                        else                            fprintf (src, "    l += BEncTag%d (b, %s, %s, %d);\n", tagLen, classStr, formStr, 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 (%s b, %s &bytesDecoded, %s env);\n", r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);                fprintf (src, "void %s::B%s (%s b, %s &bytesDecoded, %s env)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG, envTypeNameG);                fprintf (src, "{\n");                fprintf (src, "    %s tag;\n", tagTypeNameG);                /* print extra locals for redundant lengths */                for (i = 1; (tags != NULL) && (i <= LIST_COUNT (tags)); i++)                    fprintf (src, "    %s elmtLen%d;\n", lenTypeNameG, i);                if (typeId == BASICTYPE_CHOICE)                    fprintf (src, "    %s elmtLen%d;\n", lenTypeNameG, i++);                fprintf (src, "\n");                /*  decode tag/length pair (s) */                elmtLevel = 0;                if (!stoleChoiceTags)                {                    FOR_EACH_LIST_ELMT (tag, tags)                    {                        classStr = Class2ClassStr (tag->tclass);                        if (tag->form == ANY_FORM)                            formStr = Form2FormStr (PRIM);                        else                            formStr = Form2FormStr (tag->form);                        fprintf (src, "    if (((tag = BDecTag (b, bytesDecoded, env)) != ");                        if (tag->tclass == UNIV)                        {                            fprintf (src, "MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, Code2UnivCodeStr (tag->code));                            if (tag->form == ANY_FORM)                                fprintf (src, "\n        && (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), Code2UnivCodeStr (tag->code));                            else                                fprintf (src, ")\n");                        }                        else                        {                            fprintf (src, "MAKE_TAG_ID (%s, %s, %d))", classStr, formStr, tag->code);                            if (tag->form == ANY_FORM)                                fprintf (src, "\n        && (tag != MAKE_TAG_ID (%s, %s, %d)))\n", classStr, Form2FormStr (CONS), tag->code);                            else                                fprintf (src, ")\n");                        }                        fprintf (src, "    {\n");            		fprintf (src, "        Asn1Error << \"%s::B%s: ERROR - wrong tag\" << endl;\n", td->cxxTypeDefInfo->className, r->decodeBaseName);                        fprintf (src, "        longjmp (env, %d);\n", longJmpValG--);                        fprintf (src, "    }\n");                        fprintf (src, "    elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);                    }                }                /* decode first tag from CHOICE's content */                if (typeId == BASICTYPE_CHOICE)                {                    fprintf (src, "    tag = BDecTag (b, bytesDecoded, env);\n");                    fprintf (src, "    elmtLen%d = BDecLen (b, bytesDecoded, env);\n", ++elmtLevel);                }                fprintf (src, "    B%s (b, tag, elmtLen%d, bytesDecoded, env);\n", r->decodeContentBaseName, i-1);                /* grab any EOCs that match redundant, indef lengths */                for (i = elmtLevel-1; i > 0; i--)                {                    fprintf (src, "    if (elmtLen%d == INDEFINITE_LEN)\n", i);                    fprintf (src, "        BDecEoc (b, bytesDecoded, env);\n");                }                fprintf (src, "}\n\n");            }            /* end of BDec function */            PrintPduMemberFcns (src, hdr, r, td->cxxTypeDefInfo->className);            FreeTags (tags);        }        /* close class def */        fprintf (hdr, "};\n\n\n");    }    else  /* isomorphic with referenced type, so just to a typedef */    {#ifdef _IBM_ENC_#include "./ibm_editor/print_cxx_simple_def1.h"#endif /* _IBM_ENC_ */#if META	if (printMetaG)	{	    fprintf (hdr, "#if META\n");	    fprintf (src, "#if META\n\n");	    fprintf (src, "static AsnType *create%s()\n", td->cxxTypeDefInfo->className);	    fprintf (src, "{\n");	    fprintf (src, "  return new %s;\n", td->cxxTypeDefInfo->className);	    fprintf (src, "}\n\n");	    fprintf (hdr, "struct %s: public %s\n", td->cxxTypeDefInfo->className, td->type->cxxTypeRefInfo->className);	    fprintf (hdr, "{\n");	    PrintDerivedConstructors (hdr, r, td);            PrintCloneMethod (hdr, src, td);	    fprintf (hdr, "  static const AsnAliasTypeDesc	_desc;\n");	    fprintf (hdr, "  const AsnTypeDesc	*_getdesc() const;\n");	    fprintf (src, "const AsnAliasTypeDesc %s::_desc\n", td->cxxTypeDefInfo->className);	    fprintf (src, "(\n");	    fprintf (src, "  &%sModuleDesc,\n", m->cxxname);	    if (printMetaG == META_backend_names)		fprintf (src, "  \"%s\", // `%s'\n", td->cxxTypeDefInfo->className, td->definedName);	    else /* META_asn1_names */		fprintf (src, "  \"%s\", // `%s'\n", td->definedName, td->cxxTypeDefInfo->className);	    fprintf (src, "  %s,\n", isMetaPDU (m->modId->name, td->definedName, meta_pdus_G) ? "true" : "false");	    fprintf (src, "  AsnTypeDesc::ALIAS,\n");	    fprintf (src, "  create%s,\n", td->cxxTypeDefInfo->className);

⌨️ 快捷键说明

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