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

📄 gen-code.c

📁 asn to c编译器 源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
         * {         * 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)) != 0)        {               int count = 0;            fprintf (hdr, "\n\tenum\n");            fprintf (hdr, "\t{\n");            FOR_EACH_LIST_ELMT (n, td->type->cxxTypeRefInfo->namedElmts)            {                fprintf (hdr, "\t\t%s = %d", n->name, n->value);                if (n != (CNamedElmt *)LAST_LIST_ELMT (td->type->cxxTypeRefInfo->namedElmts))                    fprintf (hdr, ",\n");                else                    fprintf (hdr, "\n");                count++;            }            fprintf (hdr, "\t};\n");            if(td->type->basicType->choiceId == BASICTYPE_ENUMERATED)            {                fprintf (hdr, "  AsnLen PEnc(AsnBufBits &_b)const{\n");                fprintf (hdr, "     long enumList[] = {");                FOR_EACH_LIST_ELMT (n, td->type->cxxTypeRefInfo->namedElmts)                {                    fprintf (hdr, "%d", n->value);                    if (n != (CNamedElmt *)LAST_LIST_ELMT (td->type->cxxTypeRefInfo->namedElmts))                        fprintf (hdr, ", ");                }                fprintf (hdr, " };\n");                fprintf (hdr, "       AsnInt index = IndexedVal(enumList, %d);\n", count);                fprintf (hdr, "       AsnLen len = index.PEncFullyConstrained(_b, 0, %d);\n", count - 1);                fprintf (hdr, "       return len;}\n");                                  fprintf (hdr, "  void PDec(AsnBufBits &_b, AsnLen &bitsDecoded){\n");                fprintf (hdr, "     long enumList[] = {");                FOR_EACH_LIST_ELMT (n, td->type->cxxTypeRefInfo->namedElmts)                {                    fprintf (hdr, "%d", n->value);                    if (n != (CNamedElmt *)LAST_LIST_ELMT (td->type->cxxTypeRefInfo->namedElmts))                        fprintf (hdr, ", ");                }                fprintf (hdr, " };\n");                fprintf (hdr, "     AsnInt index;\n");                fprintf (hdr, "     index.PDecFullyConstrained(_b, 0, %d, bitsDecoded);\n", count - 1);                fprintf (hdr, "     SetIndex(enumList, %d, index);}\n", count);                              }        }        #if META	        if (printMetaG)	        {	            PrintCxxSimpleDefMeta_1(hdr, src, td, hasNamedElmts, n, m);	        }        #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) 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 = 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");                        //RWC;tagLen = TagByteLen (tag->code);                        if (tag->tclass == UNIV)                        {                            const char* ptr = DetermineCode(tag, &tagLen, 0);                            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);// envTypeNameG);                fprintf (src, "void %s::B%s (const %s &_b, %s &bytesDecoded)\n", td->cxxTypeDefInfo->className, r->decodeBaseName, bufTypeNameG, lenTypeNameG);//, envTypeNameG);                fprintf (src, "{\n");                fprintf (src, "    FUNC(\"%s::B%s\");\n", td->cxxTypeDefInfo->className, r->decodeBaseName);                 fprintf (src, "    %s tag;\n", tagTypeNameG);                /* PL: removed to avoid unused variable warning                  fprintf (src, "    AsnBufLoc readLoc = _b.GetReadLoc();\n");                 */                /* 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)) != ");                        if (tag->tclass == UNIV)                        {                            fprintf (src, "MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, DetermineCode(tag, NULL, 0));//RWC;Code2UnivCodeStr (tag->code));                            if (tag->form == ANY_FORM)                                fprintf (src, "\n        && (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), DetermineCode(tag, NULL, 0));//RWC;Code2UnivCodeStr (tag->code));                            else                                fprintf (src, ")\n");                        }                        else                        {                            fprintf (src, "MAKE_TAG_ID (%s, %s, %s))", classStr, formStr, DetermineCode(tag, NULL, 1));//RWC;tag->code);                            if (tag->form == ANY_FORM)                                fprintf (src, "\n        && (tag != MAKE_TAG_ID (%s, %s, %s)))\n", classStr, Form2FormStr (CONS), DetermineCode(tag, NULL, 1));//RWC;tag->code);                            else                                fprintf (src, ")\n");                        }                        fprintf (src, "    {\n");                        fprintf (src, "        throw InvalidTagException(typeName(), tag, STACK_ENTRY);\n");                        fprintf (src, "    }\n");                        fprintf (src, "    elmtLen%d = BDecLen (_b, bytesDecoded);\n", ++elmtLevel);                    }                }                /* decode first tag from CHOICE's content */                if (typeId == BASICTYPE_CHOICE)                {                    fprintf (src, "    tag = BDecTag (_b, bytesDecoded);\n");                    fprintf (src, "    elmtLen%d = BDecLen (_b, bytesDecoded);\n", ++elmtLevel);                }                fprintf (src, "    B%s (_b, tag, elmtLen%d, bytesDecoded);\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);\n");                }                fprintf (src, "}\n\n");            }            /* end of BDec function */            FreeTags (tags);        }        /* close class def */        fprintf (hdr, "};\n\n\n");    }    else  /* isomorphic with referenced type, so just to a typedef */    {        #if META	        if (printMetaG)	        {                PrintCxxSimpleDefMeta_2(hdr, src, td, hasNamedElmts, n, m, r);	        }        #endif /* META */		/* JKG 7/31/03 */		/* The following code enclosed in this if/else statement */		/* is constructed for constraint handling capability     */		/* for primitives found outside of                       */		/* sequences or sets                                     */        if (td->type->subtypes != NULL)		{			switch (td->type->subtypes->choiceId)            {			    case SUBTYPE_AND:			    case SUBTYPE_OR:                case SUBTYPE_SINGLE:				    {   				    struct NamedType temp;				    NamedType* tmp;				    tmp=&temp;				    tmp->type=td->type;				    tmp->type->cxxTypeRefInfo->fieldName=td->definedName;				    tmp->fieldName=td->definedName;				    if (!PrintCxxMultiConstraintOrHandler(hdr, src, NULL, tmp, 0))					    PrintTypeDefDefault(hdr, src, td);				    break;				    }			    default:                {				    PrintTypeDefDefault(hdr, src, td);			   								    break;                }			}		}		else		{			PrintTypeDefDefault(hdr, src, td);		}        #if META		        if (printMetaG)			        fprintf (hdr, "#endif // META\n\n");        #endif /* META */	}} /* PrintCxxSimpleDef */static voidPrintCxxChoiceDefCode (FILE *src, FILE *hdr, ModuleList *mods, Module *m, CxxRules *r ,    TypeDef *td,Type *parent, Type *choice, int novolatilefuncs){    NamedType *e;    char *classStr;    char *formStr;    char *codeStr;    int tagLen=0, i;    Tag *tag;    TagList *tags;    char *varName;    CxxTRI *cxxtri;    int elmtLevel=0;    int varCount, tmpVarCount;    int stoleChoiceTags;    enum BasicTypeChoiceId tmpTypeId;    NamedType *defByNamedType;    NamedType **ppElementNamedType;    int *pElementTag;    int ii;    char *ptr="";   /* NOT DLL Exported, or ignored on Unix. */    int extensionsExist = FALSE;    /* put class spec in hdr file */        if (bVDAGlobalDLLExport != NULL)        ptr = bVDAGlobalDLLExport;    fprintf (hdr, "class %s %s%s\n", ptr, td->cxxTypeDefInfo->className, baseClassesG);    fprintf (hdr, "{\n");    fprintf (hdr, "public:\n");    /* write out choiceId enum type */        FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)        {            if(e->type->subtypes != NULL)            {    switch(e->type->subtypes->choiceId)                {                       case SUBTYPE_AND:                    case SUBTYPE_OR:                    case SUBTYPE_SINGLE:                        {                            PrintCxxMultiConstraintOrHandler(hdr, src, td->cxxTypeDefInfo->className, e, 3);                            break;                        }                    default:                        {                            break;                        }                }            }        }       fprintf (hdr, "  enum %s\n", r->choiceIdEnumName);    fprintf (hdr, "  {\n");    FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)    {        fprintf (hdr, "     %s = %d", e->type->cxxTypeRefInfo->choiceIdSymbol, e->type->cxxTypeRefInfo->choiceIdValue);        if (e != (NamedType*)LAST_LIST_ELMT (choice->basicType->a.choice))            fprintf (hdr, ",\n");        else            fprintf (hdr, "\n");    }    fprintf (hdr, "  };\n\n");    /* write out the choice Id field */    fprintf (hdr, "  enum %s	%s;\n", r->choiceIdEnumName, r->choiceIdFieldName);    /* write out the choice element anonymous union */    fprintf (hdr, "  union\n");    fprintf (hdr, "  {\n");

⌨️ 快捷键说明

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