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

📄 gen-code.c

📁 asn.1 compiler
💻 C
📖 第 1 页 / 共 5 页
字号:
            /* include overloading of = op. MS 12/92 */            fprintf (f, "  %s		&operator = (const %s &o)	{ ReSet (o); return *this; }\n", derivedClassName, derivedClassName);            fprintf (f, "  %s		&operator = (const char *str)	{ ReSet (str); return *this; }\n", derivedClassName);            break;        case BASICTYPE_BITSTRING:            fprintf (f, "			%s (const size_t bits): %s (bits) {}\n", derivedClassName, baseClassName);            fprintf (f, "			%s (const char *str, const size_t bitLen): %s (str, bitLen) {}\n", derivedClassName, baseClassName);            fprintf (f, "			%s (const %s &b): %s (b) {}\n",  derivedClassName, baseClassName, baseClassName);            break;            /* include overloading of = op. MS 12/92 */            fprintf (f, "  %s		&operator = (const %s &b)	{ ReSet (b); return *this; }\n", derivedClassName, derivedClassName);        case BASICTYPE_OID:            fprintf (f, "			%s (const char *encOid, size_t len): %s (encOid, len) {}\n", derivedClassName, baseClassName);            fprintf (f, "			%s (const %s &o): %s (o) {}\n", derivedClassName, baseClassName, baseClassName);            fprintf (f, "			%s (unsigned long int a1, unsigned long int a2, long int a3=-1, long int a4=-1, long int a5=-1, long int a6=-1, long int a7=-1, long int a8=-1, long int a9=-1, long int a10=-1, long int a11=-1): %s (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) {}\n", baseClassName, derivedClassName, baseClassName);            /* include overloading of = op. MS 12/92 */            fprintf (f, "  %s		&operator = (const %s &o)	{ ReSet (o); return *this; }\n", derivedClassName, derivedClassName);            break;        default:            /* do nothing */            break;    }} /* PrintDerivedConstructors */static voidPrintMakeTag PARAMS ((f, tag),    FILE *f _AND_    Tag *tag){    char *classStr;    char *formStr;    classStr = Class2ClassStr (tag->tclass);    if (tag->form == ANY_FORM)  /* default to PRIM for dual form tags */        formStr = Form2FormStr (PRIM);    else        formStr = Form2FormStr (tag->form);    fprintf (f, "MAKE_TAG_ID (%s, %s, ", classStr, formStr);    if (tag->tclass == UNIV)        fprintf (f, "%s)", Code2UnivCodeStr (tag->code));    else        fprintf (f, "%d)", tag->code);} /* PrintMakeTag */static voidPrintPduMemberFcns PARAMS ((src, hdr, r, cln),    FILE *src _AND_    FILE *hdr _AND_    CxxRules *r _AND_    char *cln){    if (printEncodersG)    {        fprintf (hdr, "  int			B%s (%s b, %s &bytesEncoded);\n", r->encodePduBaseName, bufTypeNameG, lenTypeNameG);        fprintf (src, "int %s::B%s (%s b, %s &bytesEncoded)\n", cln, r->encodePduBaseName, bufTypeNameG, lenTypeNameG);        fprintf (src, "{\n");        fprintf (src, "    bytesEncoded = B%s (b);\n", r->encodeBaseName);        fprintf (src, "    return !b.WriteError();\n");        fprintf (src, "}\n\n");    }    if (printDecodersG)    {        fprintf (hdr, "  int			B%s (%s b, %s &bytesDecoded);\n", r->decodePduBaseName, bufTypeNameG, lenTypeNameG);        fprintf (src, "int %s::B%s (%s b, %s &bytesDecoded)\n", cln, r->decodePduBaseName, bufTypeNameG, lenTypeNameG);	fprintf (src, "{\n");        fprintf (src, "    %s env;\n", envTypeNameG);        fprintf (src, "    int val;\n\n");        fprintf (src, "    bytesDecoded = 0;\n");        fprintf (src, "    if ((val = setjmp (env)) == 0)\n");        fprintf (src, "    {\n");        fprintf (src, "         BDec (b, bytesDecoded, env);\n");        fprintf (src, "         return !b.ReadError();\n");        fprintf (src, "    }\n");        fprintf (src, "    else\n");        fprintf (src, "        return false;\n");/*        fprintf (src, "    { cerr << \"longjmp return value is \" << val << endl;\n");        fprintf (src, "        return false; }\n");*/        fprintf (src, "}\n\n");    }    fprintf (hdr, "\n");} /* PrintPduMemberFcns */static voidPrintCxxEocEncoders PARAMS ((src, td, t, bufVarName),    FILE *src _AND_    TypeDef *td _AND_    Type *t _AND_    char *bufVarName){    TagList *tl;    Tag *tag;    int stoleChoiceTags;    /*     * get all the tags on this type     */    tl = (TagList*) GetTags (t, &stoleChoiceTags);    /*     * leave choice elmt tag enc to encoding routine     */    if (!stoleChoiceTags)    {        FOR_EACH_LIST_ELMT (tag, tl)            if (tag->form == CONS)                fprintf (src, "      BEncEocIfNec (b);\n");    }    FreeTags (tl);} /* PrintCxxEocEncoders */static intHasShortLen PARAMS ((t),    Type *t){    enum BasicTypeChoiceId typesType;    /*     * efficiency hack - use simple length (1 byte)     * encoded for type (almost) guaranteed to have     * encoded lengths of 0 <= len <= 127     */    typesType = GetBuiltinType (t);    return typesType == BASICTYPE_BOOLEAN || typesType == BASICTYPE_INTEGER || typesType == BASICTYPE_NULL || typesType == BASICTYPE_REAL || typesType == BASICTYPE_ENUMERATED;} /* HasShortLen *//* * prints length encoding code.  Primitives always use * definite length and constructors get "ConsLen" * which can be configured at compile to to be indefinite * or definite.  Primitives can also be "short" (isShort is true) * in which case a fast macro is used to write the length. * Types for which isShort apply are: boolean, null and * (almost always) integer and reals */static voidPrintCxxLenEncodingCode PARAMS ((f, isCons, isShort, lenVarName, bufVarName),    FILE *f _AND_    int isCons _AND_    int isShort _AND_    char *lenVarName _AND_    char *bufVarName){    if (isCons)        fprintf (f, "    %s += BEncConsLen (%s, %s);\n", lenVarName, bufVarName, lenVarName);    else    {        if (isShort)        {            fprintf (f, "    BEncDefLenTo127 (%s, %s);\n", bufVarName, lenVarName);            fprintf (f, "    %s++;\n", lenVarName);        }        else            fprintf (f, "    %s += BEncDefLen (%s, %s);\n", lenVarName, bufVarName, lenVarName);    }} /* PrintCxxLenEncodingCode *//* * prints last tag's encoding code first */static voidPrintCxxTagAndLenList PARAMS ((src, t, tagList, lenVarName, bufVarName),    FILE *src _AND_    Type *t _AND_    TagList *tagList _AND_    char *lenVarName _AND_    char *bufVarName){    char *classStr;    char *formStr;    char *codeStr;    Tag *tg;    Tag *last;    int tagLen;    enum BasicTypeChoiceId typesType;    int isShort;    if ((tagList == NULL) || LIST_EMPTY (tagList))        return;    /*     * efficiency hack - use simple length (1 byte)     * encoded for type (almost) guaranteed to have     * encoded lengths of 0 <= len <= 127     */    isShort = HasShortLen (t);    /*     * since encoding backward encode tags backwards     */    last = (Tag*)LAST_LIST_ELMT (tagList);    FOR_EACH_LIST_ELMT_RVS (tg, tagList)    {        classStr = Class2ClassStr (tg->tclass);        if (tg->form == CONS)        {            formStr = Form2FormStr (CONS);            PrintCxxLenEncodingCode (src, TRUE, isShort, lenVarName, bufVarName);        }        else /* PRIM or ANY_FORM */        {            formStr = Form2FormStr (PRIM);            PrintCxxLenEncodingCode (src, FALSE, isShort, lenVarName, bufVarName);        }/*      GetTags sets the form properly now        if (IsPrimitiveByDefOrRef (t) && (tg == last))        {            formStr = Form2FormStr (PRIM);            PrintCxxLenEncodingCode (src, FALSE, isShort, lenVarName, bufVarName);        }        else        {            formStr = Form2FormStr (CONS);            PrintCxxLenEncodingCode (src, TRUE, isShort, lenVarName, bufVarName);        }*/        fprintf (src, "\n");        tagLen = TagByteLen (tg->code);        if (tg->tclass == UNIV)            fprintf (src, "    %s += BEncTag%d (%s, %s, %s, %s);\n", lenVarName, tagLen, bufVarName, classStr, formStr, Code2UnivCodeStr (tg->code));        else            fprintf (src, "    %s += BEncTag%d (%s, %s, %s, %d);\n", lenVarName, tagLen, bufVarName, classStr, formStr, tg->code);    }} /* PrintCxxTagAndLenList *//* *  Recursively walks through tags, printing lower lvl tags *  first (since encoding is done backwards). * */static voidPrintCxxTagAndLenEncodingCode PARAMS ((src, td, t, lenVarName, bufVarName),    FILE *src _AND_    TypeDef *td _AND_    Type *t _AND_    char *lenVarName _AND_    char *bufVarName){    TagList *tl;    int stoleChoiceTags;    /*     * get all the tags on this type     */    tl = (TagList*) GetTags (t, &stoleChoiceTags);    /*     * leave choice elmt tag enc to encoding routine     */    if (!stoleChoiceTags)        PrintCxxTagAndLenList (src, t, tl, lenVarName, bufVarName);    FreeTags (tl);} /* PrintCxxTagAndLenEncodingCode *//* * used to figure out local variables to declare * for decoding tags/len pairs on type t */static intCxxCountVariableLevels PARAMS ((t),    Type *t){    if (GetBuiltinType (t) == BASICTYPE_CHOICE)        return CountTags (t) +1; /* since must decode 1 internal tag type */    else        return CountTags (t);} /* CxxCountVariableLevels *//* * returns true if elmts curr following *  onward are all optional ow. false */static intRestAreTailOptional PARAMS ((e),    NamedTypeList *e){    NamedType *elmt;    void *tmp;    int retVal;    if (e == NULL)        return TRUE;    tmp = (void*)CURR_LIST_NODE (e);    retVal = TRUE;    AsnListNext (e);    FOR_REST_LIST_ELMT (elmt, e)    {        if ((!elmt->type->optional) && (elmt->type->defaultVal == NULL))        {            retVal = FALSE;            break;        }    }    SET_CURR_LIST_NODE (e, tmp); /* reset list to orig loc */    return retVal;}/* * prints typedef or new class given an ASN.1  type def of a primitive type * or typeref.  Uses inheritance to cover re-tagging and named elmts. */static voidPrintCxxSimpleDef PARAMS ((hdr, src, if_IBM_ENC (hdrdb COMMA srcdb COMMA) if_META (m COMMA) r, td),    FILE *hdr _AND_    FILE *src _AND_    if_IBM_ENC (FILE *hdrdb _AND_)    if_IBM_ENC (FILE *srcdb _AND_)    if_META (Module *m _AND_)    CxxRules *r _AND_    TypeDef *td){    Tag *tag;    TagList *tags;    char *formStr;    char *classStr;    int tagLen;

⌨️ 快捷键说明

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