📄 gen-code.c
字号:
{ enum BasicTypeChoiceId typeId; char *derivedClassName; char *baseClassName; typeId = GetBuiltinType (td->type); derivedClassName = td->cxxTypeDefInfo->className; baseClassName = td->type->cxxTypeRefInfo->className; /* every class gets the no-arg constructor */ #if TCL if (printTclG && typeId == BASICTYPE_ENUMERATED) { fprintf (f, "#if TCL\n"); fprintf (f, " %s(): %s (_nmdescs[0].value) {}\n", derivedClassName, baseClassName); fprintf (f, "#else\n"); } if (printTclG && typeId == BASICTYPE_ENUMERATED) fprintf (f, "#endif\n"); #endif /* TCL */ switch (typeId) { case BASICTYPE_BOOLEAN: fprintf (f, " %s(): %s() {}\n", derivedClassName, baseClassName); fprintf (f, " %s (bool _b): %s (_b) {}\n", derivedClassName, baseClassName); break; case BASICTYPE_ENUMERATED: case BASICTYPE_INTEGER: fprintf (f, " %s(): %s() {}\n", derivedClassName, baseClassName); fprintf (f, " %s (int i): %s (i) {}\n", derivedClassName, baseClassName); break; case BASICTYPE_REAL: fprintf (f, " %s(): %s() {}\n", derivedClassName, baseClassName); fprintf (f, " %s (double d): %s (d) {}\n", derivedClassName, baseClassName); break; case BASICTYPE_OCTETSTRING: fprintf (f, " %s(): %s() {}\n", derivedClassName, baseClassName); fprintf (f, " %s (const char *str): %s (str) {}\n", derivedClassName, baseClassName); fprintf (f, " %s (const char *str, const size_t len): %s (str, len) {}\n", derivedClassName, baseClassName); fprintf (f, " %s (const %s &o): %s (o) {}\n", derivedClassName, derivedClassName, baseClassName); /* include overloading of = op. MS 12/92 */ fprintf (f, " %s &operator = (const %s &o) { AsnOcts::operator=(o); return *this; }\n", derivedClassName, derivedClassName); fprintf (f, " %s &operator = (const char *str) { AsnOcts::operator=(str); return *this; }\n", derivedClassName); break; case BASICTYPE_BITSTRING: { const char *nblStr = "nblFlag = false;"; if (HasNamedElmts (td->type)) nblStr = "nblFlag = true;"; fprintf(f, "\t%s() : %s()\t\t\t{ %s }\n", derivedClassName, baseClassName, nblStr); fprintf(f, "\t%s(size_t bits) : %s(bits)\t{ %s }\n", derivedClassName, baseClassName, nblStr); fprintf(f, "\t%s(const unsigned char* str, const size_t bitLen) :\n", derivedClassName); fprintf(f, "\t\t%s(str, bitLen)\t\t\t\t{ %s }\n", baseClassName, nblStr); // Copy constructor not needed // fprintf(f, "\t%s (const %s &o) : %s(o)\n", // derivedClassName, baseClassName, baseClassName); } break; case BASICTYPE_OID: /* TBD: Fix this code -PIERCE fprintf (f, " %s(): %s() {}\n", derivedClassName, baseClassName); 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 a1, unsigned long a2, long a3=-1, long a4=-1, long a5=-1, long a6=-1, long a7=-1, long a8=-1, long a9=-1, long a10=-1, long a11=-1): %s (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) {}\n", baseClassName, derivedClassName, baseClassName); fprintf (f, " %s &operator = (const %s &o) { ReSet (o); return *this; }\n", derivedClassName, derivedClassName); */ printf("TBD: Attempt was made to generate code for a tagged OID outside of a SEQ or SET\n"); break; default: break; } r = r; /*AVOIDS warning.*/} /* PrintDerivedConstructors */#if DEPRECATEDstatic 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); FreeTags (tl); bufVarName=bufVarName;td=td; /*AVOIDS warning.*/} /* PrintCxxEocEncoders */#endifstatic 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); /*RWC;8/9/01;REMOVED when INTEGER made AsnOcts;return typesType == BASICTYPE_BOOLEAN || typesType == BASICTYPE_INTEGER || typesType == BASICTYPE_NULL || typesType == BASICTYPE_REAL || typesType == BASICTYPE_ENUMERATED; */ return typesType == BASICTYPE_BOOLEAN || 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; Tag *tg; Tag *last; int tagLen; 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); } fprintf (src, "\n"); //RWC;tagLen = TagByteLen (tg->code); if (tg->tclass == UNIV) { const char* ptr = DetermineCode(tg, &tagLen, 0); fprintf (src, " %s += BEncTag%d (%s, %s, %s, %s);\n", lenVarName, tagLen, bufVarName, classStr, formStr, ptr); } //RWC;Code2UnivCodeStr (tg->code)); else { const char* ptr = DetermineCode(tg, &tagLen, 1); fprintf (src, " %s += BEncTag%d (%s, %s, %s, %s);\n", lenVarName, tagLen, bufVarName, classStr, formStr, ptr); } //RWC;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); td=td; /*AVOIDS warning.*/} /* 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)&&(!elmt->type->extensionAddition)) { 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, m, r, td), FILE *hdr _AND_ FILE *src _AND_ Module *m _AND_ CxxRules *r _AND_ TypeDef *td){ Tag *tag; TagList *tags; char *formStr; char *classStr; int tagLen; int i; CNamedElmt *n; int stoleChoiceTags; int elmtLevel; enum BasicTypeChoiceId typeId; m = m; 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; char *ptr=""; /* NOT DLL Exported, or ignored on Unix. */ if (bVDAGlobalDLLExport) ptr = bVDAGlobalDLLExport; fprintf (hdr, "class %s %s: public %s\n", ptr, 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -