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

📄 type-info.c

📁 asn to c编译器 源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (r->typeConvTbl[basicTypeId].cTypeId == C_TYPEREF)    {        /*         * don't do this anymore - it cause problems since FillTypeDef         * changes name ie ORName -> ORName1 and other type use new name         *         * don't define type or print/enc/dec/free routines         * if typedef name is the same as the defining type ref name         * in P2: ORName ::= P1.ORName        if ((parentTypeId == C_TYPEDEF) &&            (strcmp (head->definedName, t->basicType->a.localTypeRef->typeName)             == 0))        {            tmpCtdi = head->cTypeDefInfo;            tmpCtdi->genPrintRoutine = FALSE;            tmpCtdi->genEncodeRoutine = FALSE;            tmpCtdi->genDecodeRoutine = FALSE;            tmpCtdi->genFreeRoutine = FALSE;            tmpCtdi->genTypeDef = FALSE;        }         */        /*         * grab type name from link (link is the def of the         * the ref'd type)         */        if (t->basicType->a.localTypeRef->link != NULL)        {            /* inherit attributes from referenced type */            tmpCtdi=  t->basicType->a.localTypeRef->link->cTypeDefInfo;            ctri->cTypeName = tmpCtdi->cTypeName;            ctri->printRoutineName  = tmpCtdi->printRoutineName;            ctri->encodeRoutineName = tmpCtdi->encodeRoutineName;            ctri->decodeRoutineName = tmpCtdi->decodeRoutineName;            ctri->freeRoutineName = tmpCtdi->freeRoutineName;            ctri->isEncDec = tmpCtdi->isEncDec;            ctri->optTestRoutineName = tmpCtdi->optTestRoutineName;        }        else        {            /*             * guess type and routine names             */            fprintf (errFileG, "Assuming C Type and Routine names for unresolved type ref \"%s\"\n",				t->basicType->a.localTypeRef->typeName);            ctri->cTypeName = Asn1TypeName2CTypeName (t->basicType->a.localTypeRef->typeName);            ctri->printRoutineName = Malloc (strlen (r->printRoutineBaseName) + strlen (ctri->cTypeName) + 1);            strcpy (ctri->printRoutineName, r->printRoutineBaseName);            strcat (ctri->printRoutineName, ctri->cTypeName);            ctri->encodeRoutineName = Malloc (strlen (r->encodeRoutineBaseName)+ strlen (ctri->cTypeName) +  1);            strcpy (ctri->encodeRoutineName, r->encodeRoutineBaseName);            strcat (ctri->encodeRoutineName, ctri->cTypeName);            ctri->decodeRoutineName = Malloc (strlen (r->decodeRoutineBaseName)+ strlen (ctri->cTypeName) + 1);            strcpy (ctri->decodeRoutineName, r->decodeRoutineBaseName);            strcat (ctri->decodeRoutineName, ctri->cTypeName);            ctri->freeRoutineName = Malloc (strlen (ctri->cTypeName) + strlen (r->freeRoutineBaseName) + 1);            strcpy (ctri->freeRoutineName, r->freeRoutineBaseName);            strcat (ctri->freeRoutineName, ctri->cTypeName);        }    }	// Deepak: 05/Feb/2003#ifdef DEEPAK    else if (r->typeConvTbl[basicTypeId].cTypeId == C_OBJECTCLASSFIELDTYPE)    {        /*         * grab type name from link (link is the def of the         * the ref'd type)         */        if (t->basicType->a.localTypeRef->namedTypeLink != NULL)        {            /* inherit attributes from referenced type */          /*  tmpCtdi=  t->basicType->a.localTypeRef->namedTypeLink->type->cTypeRefInfo;            ctri->cTypeName = tmpCtdi->cTypeName;            ctri->printRoutineName  = tmpCtdi->printRoutineName;            ctri->encodeRoutineName = tmpCtdi->encodeRoutineName;            ctri->decodeRoutineName = tmpCtdi->decodeRoutineName;            ctri->freeRoutineName = tmpCtdi->freeRoutineName;            ctri->isEncDec = tmpCtdi->isEncDec;            ctri->optTestRoutineName = tmpCtdi->optTestRoutineName;		  */        }        else        {            /*             * guess type and routine names             */            fprintf (errFileG, "Assuming C Type and Routine names for unresolved type ref \"%s\"\n",				t->basicType->a.localTypeRef->typeName);            ctri->cTypeName = Asn1TypeName2CTypeName (t->basicType->a.localTypeRef->typeName);            ctri->printRoutineName = Malloc (strlen (r->printRoutineBaseName) + strlen (ctri->cTypeName) + 1);            strcpy (ctri->printRoutineName, r->printRoutineBaseName);            strcat (ctri->printRoutineName, ctri->cTypeName);            ctri->encodeRoutineName = Malloc (strlen (r->encodeRoutineBaseName)+ strlen (ctri->cTypeName) +  1);            strcpy (ctri->encodeRoutineName, r->encodeRoutineBaseName);            strcat (ctri->encodeRoutineName, ctri->cTypeName);            ctri->decodeRoutineName = Malloc (strlen (r->decodeRoutineBaseName)+ strlen (ctri->cTypeName) + 1);            strcpy (ctri->decodeRoutineName, r->decodeRoutineBaseName);            strcat (ctri->decodeRoutineName, ctri->cTypeName);            ctri->freeRoutineName = Malloc (strlen (ctri->cTypeName) + strlen (r->freeRoutineBaseName) + 1);            strcpy (ctri->freeRoutineName, r->freeRoutineBaseName);            strcat (ctri->freeRoutineName, ctri->cTypeName);        }    }#endif	// DEEPAK	else if (r->typeConvTbl[basicTypeId].cTypeId == C_OBJECTCLASS)	{	// Deepak: 11/Mar/2003		//FillCTypeRefInfo (r, m, head, t->basicType->a.objectclass->classdef, C_LIST);        unionName = Malloc (strlen (head->cTypeDefInfo->cTypeName) +1);        strcpy (unionName, head->cTypeDefInfo->cTypeName);        ctri->cTypeName = unionName;        FillCStructElmts (r, m, head, t->basicType->a.objectclass->classdef);		// Deepak: All the elements in this structure are filled here.        FillCFieldNames (r, t->basicType->a.objectclass->classdef);	// Deepak: All the identifiers are stored over here.	}    else if (r->typeConvTbl[basicTypeId].cTypeId == C_LIST)    {        /*         * List  types (SET OF/ SEQ OF)         * fill in component type         */        FillCTypeRefInfo (r, m, head, t->basicType->a.setOf, C_LIST);    }    else if (r->typeConvTbl[basicTypeId].cTypeId == C_CHOICE)    {        /*         * Choice - set up choice Id elmt names, choiceid enum name         * choiceid enum fieldName, choice union name.         * this will only be the first type in the typedef         * ie will not be embedded (those are turned into type         * refs in nomalize.c)         */        /*         * make union name (tag) from enclosing typedefs name plus "Choice"         * put in the cTypeName part. (the typeDef name is already unique         * but make sure union tag/name does not conflict with other types)         */        len = strlen (head->cTypeDefInfo->cTypeName);        unionName = (char*) Malloc (len + strlen (r->choiceUnionDefSuffix) + r->maxDigitsToAppend + 1);        strcpy (unionName, head->cTypeDefInfo->cTypeName);        strcat (unionName, r->choiceUnionDefSuffix);        MakeCStrUnique (definedNamesG, unionName,  r->maxDigitsToAppend, 1);        DefineObj (&definedNamesG, unionName);        ctri->cTypeName = unionName;        ctri->choiceIdEnumName = Malloc (len + strlen (r->choiceIdEnumSuffix) + r->maxDigitsToAppend + 1);        strcpy (ctri->choiceIdEnumName, head->cTypeDefInfo->cTypeName);        strcat (ctri->choiceIdEnumName, r->choiceIdEnumSuffix);        MakeCStrUnique (definedNamesG, ctri->choiceIdEnumName,  r->maxDigitsToAppend, 1);        DefineObj (&definedNamesG, ctri->choiceIdEnumName);        ctri->choiceIdEnumFieldName = r->choiceIdFieldName; /* "choiceId" */        ctri->cFieldName = r->choiceUnionFieldName;         /* "a" */        /*         * must fill field names BEFORE filling choice elmts         * (allows better naming for choice ids         */        FillCFieldNames (r, t->basicType->a.choice);        FillCChoiceElmts (r, m, head, t->basicType->a.choice);    }    else if (r->typeConvTbl[basicTypeId].cTypeId == C_STRUCT)    {        /*         * SETs and SEQUENCEs         */        /*         * make struct name (tag) (the typeDef name is already unique)         * the same as the enclosing typeDef         */        unionName = Malloc (strlen (head->cTypeDefInfo->cTypeName) +1);        strcpy (unionName, head->cTypeDefInfo->cTypeName);        ctri->cTypeName = unionName;        FillCStructElmts (r, m, head, t->basicType->a.set);		// Deepak: All the elements in this structure are filled here.        FillCFieldNames (r, t->basicType->a.set);	// Deepak: All the identifiers are stored over here.    }    else if (r->typeConvTbl[basicTypeId].cTypeId == C_MACROTYPE)    {		// Deepak: 17/Apr/2003        /*         * Macro Types         */        /*         * make struct name (tag) (the typeDef name is already unique)         * the same as the enclosing typeDef         */        unionName = Malloc (strlen (head->cTypeDefInfo->cTypeName) +1);        strcpy (unionName, head->cTypeDefInfo->cTypeName);        ctri->cTypeName = unionName;		switch(t->basicType->a.macroType->choiceId)		{        case MACROTYPE_ASNABSTRACTOPERATION:        case MACROTYPE_ROSOPERATION:			if(t->basicType->a.macroType->a.rosOperation->arguments != NULL)				FillCTypeRefInfo (r, m, head, t->basicType->a.macroType->a.rosOperation->arguments->type, C_MACROTYPE);			if(t->basicType->a.macroType->a.rosOperation->result != NULL)				FillCTypeRefInfo (r, m, head, t->basicType->a.macroType->a.rosOperation->result->type, C_MACROTYPE);			break;		default:		  break;		}    }    /*     * figure out whether this is a ptr based on the enclosing     * type (if any) and optionality/default     */    ctri->isPtr = (unsigned char)IsCPtr (r, head, t, parentTypeId);		// ????? check for C_MACROTYPE    /* let user overide any defaults with the --snacc attributes */    ParseTypeRefAttribs (ctri, t->attrList);    /* Check for bigint conversion */  /*  if (strcmp(ctri->cTypeName, "AsnBigInt") == 0) {      t->basicType->choiceId = BASICTYPE_BIGINT;    } */}  /* FillCTypeRefInfo */static voidFillCStructElmts PARAMS ((r, m, head, elmts),    CRules *r _AND_    Module *m _AND_    TypeDef *head _AND_    NamedTypeList *elmts){    NamedType *et;    FOR_EACH_LIST_ELMT (et, elmts)		// Take struct elements one by one.    {        FillCTypeRefInfo (r, m, head, et->type, C_STRUCT);    }}  /* FillCStructElmts *//* *  Figures out non-conflicting enum names for the *  choice id's */static voidFillCChoiceElmts PARAMS ((r, m, head, elmts),    CRules *r _AND_    Module *m _AND_    TypeDef *head _AND_    NamedTypeList *elmts){    NamedType *et;    int idCount = 0;    CTRI *ctri;    char *firstName;    char *secondName;    int   len;    /*     * fill in type info for elmt types first     */    FOR_EACH_LIST_ELMT (et, elmts)        FillCTypeRefInfo (r, m, head, et->type, C_CHOICE);    /*     * set choiceId Symbol & value     * eg     *  Car ::= CHOICE {          typedef struct Car {     *     chev ChevCar,   ->         enum CarChoiceId {     *     ford FordCar                  CAR_CHEV,  <- typename_fieldName     *     toyota ToyotaCar              CAR_FORD,     *     }                             CAR_TOYOTA } choiceId;     *                                union CarChoiceUnion {     *                                      ChevCar *chev;     *                                      FordCar *ford;     *                                      ToyotaCar *toyota; } a;     *                               }     */    FOR_EACH_LIST_ELMT (et, elmts)    {        ctri =  et->type->cTypeRefInfo;        if (ctri == NULL)            continue; /* wierd type */        ctri->choiceIdValue = idCount++;        firstName = Asn1TypeName2CTypeName (head->cTypeDefInfo->cTypeName);        secondName = ctri->cFieldName;        ctri->choiceIdSymbol = Malloc (strlen (firstName) + strlen (secondName) + 2 + r->maxDigitsToAppend);        strcpy (ctri->choiceIdSymbol, firstName);        strcat (ctri->choiceIdSymbol, "_");        strcat (ctri->choiceIdSymbol, secondName);        Free (firstName);        len = strlen (ctri->choiceIdSymbol);        if (r->capitalizeNamedElmts)            Str2UCase (ctri->choiceIdSymbol, len);        MakeCStrUnique (definedNamesG, ctri->choiceIdSymbol, r->maxDigitsToAppend, 0);        DefineObj (&definedNamesG, ctri->choiceIdSymbol);    }}  /* FillCChoiceElmts *//* * takes a list of "sibling" (eg same level in a structure) * ElmtTypes and fills sets up the c field names in * the CTypeRefInfo struct */static voidFillCFieldNames PARAMS ((r, elmts),    CRules *r _AND_    NamedTypeList *elmts){    NamedType  *et;    CTRI *ctri;    DefinedObj *fieldNames;    char      *tmpName;    char      *asn1FieldName;    char      *cFieldName;    fieldNames = NewObjList();    /*     * Initialize fieldname data     * allocate (if nec) and fill in CTRI fieldname if poss     * from asn1 field name.  leave blank otherwise     */    FOR_EACH_LIST_ELMT (et, elmts)    {        ctri =  et->type->cTypeRefInfo;        if (ctri == NULL)        {            ctri = MT (CTRI);            et->type->cTypeRefInfo = ctri;        }        if (et->fieldName != NULL)        {            asn1FieldName = et->fieldName;            ctri->cFieldName = Asn1FieldName2CFieldName (asn1FieldName);            DefineObj (&fieldNames, ctri->cFieldName);        }    }    FOR_EACH_LIST_ELMT (et, elmts)    {        ctri =  et->type->cTypeRefInfo;        /*         * generate field names for those without them         */

⌨️ 快捷键说明

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