📄 types.c
字号:
case BASICTYPE_CHOICE: /* * must fill field names BEFORE filling choice elmts * (allows better naming for choice ids) */ FillCxxFieldNames (r, t->basicType->a.choice); FillCxxChoiceElmts (r, m, head, t, t->basicType->a.choice); break; case BASICTYPE_SET: case BASICTYPE_SEQUENCE: FillCxxStructElmts (r, m, head, t, t->basicType->a.set); FillCxxFieldNames (r, t->basicType->a.set); break; case BASICTYPE_COMPONENTSOF: case BASICTYPE_SELECTION: fprintf (stderr,"Compiler error - COMPONENTS OF or SELECTION type slipped through normalizing phase.\n"); break; case BASICTYPE_UNKNOWN: case BASICTYPE_MACRODEF: case BASICTYPE_MACROTYPE: /* do nothing */ break; } /* * figure out whether this is a ptr based on the enclosing * type (if any) and optionality/default */ cxxtri->isPtr = IsCxxPtr (r, head, parent, t); /* let user overide any defaults with the --snacc attributes */ /* undefined for C++ ParseTypeRefAttribs (ctri, t->attrList); */} /* FillCxxTypeRefInfo */static voidFillCxxStructElmts PARAMS ((r, m, head, parent, elmts), CxxRules *r _AND_ Module *m _AND_ TypeDef *head _AND_ Type *parent _AND_ NamedTypeList *elmts){ NamedType *et; FOR_EACH_LIST_ELMT (et, elmts) { FillCxxTypeRefInfo (r, m, head, parent, et->type); }} /* FillCxxStructElmts *//* * Figures out non-conflicting enum names for the * choice id's */static voidFillCxxChoiceElmts PARAMS ((r, m, head, parent, elmts), CxxRules *r _AND_ Module *m _AND_ TypeDef *head _AND_ Type *parent _AND_ NamedTypeList *elmts){ NamedType *et; int idCount = 0; CxxTRI *cxxtri; int len; /* * fill in type info for elmt types first */ FOR_EACH_LIST_ELMT (et, elmts) FillCxxTypeRefInfo (r, m, head, parent, et->type); /* * set choiceId Symbol & value * eg * Car ::= CHOICE { class Car { * chev ChevCar, -> enum ChoiceIdEnum { * ford FordCar chevCid, * toyota ToyotaCar fordCid, * } toyotaCid } choiceId; * union CarChoiceUnion { * ChevCar *chev; * FordCar *ford; * ToyotaCar *toyota; }; * ... * } * NOTE that the union is anonymous */ FOR_EACH_LIST_ELMT (et, elmts) { cxxtri = et->type->cxxTypeRefInfo; if (cxxtri == NULL) continue; /* wierd type */ cxxtri->choiceIdValue = idCount++; len = strlen (cxxtri->fieldName); cxxtri->choiceIdSymbol = Malloc (len + 4); strcpy (cxxtri->choiceIdSymbol, cxxtri->fieldName); strcat (cxxtri->choiceIdSymbol, "Cid"); if (r->capitalizeNamedElmts) Str2UCase (cxxtri->choiceIdSymbol, len); }} /* FillCxxChoiceElmts *//* * takes a list of "sibling" (eg same level in a structure) * ElmtTypes and fills sets up the c field names in * the CxxTRI struct */static voidFillCxxFieldNames PARAMS ((r, elmts), CxxRules *r _AND_ NamedTypeList *elmts){ NamedType *et; CxxTRI *cxxtri; DefinedObj *fieldNames; int len, num, digit, i, tmpLen; char *tmpName; char *asn1FieldName; char *cFieldName; /* * Initialize fieldname data * allocate (if nec) and fill in CTRI fieldname if poss * from asn1 field name. leave blank otherwise */ fieldNames = NewObjList(); FOR_EACH_LIST_ELMT (et, elmts) { cxxtri = et->type->cxxTypeRefInfo; if (cxxtri == NULL) { cxxtri = MT (CxxTRI); et->type->cxxTypeRefInfo = cxxtri; } if (et->fieldName != NULL) { /* * can assume that the field names are * distinct because they have passed the * error checking step. * However, still call MakeCxxStrUnique * to change any field names that * conflict with C++ keywords */ asn1FieldName = et->fieldName; tmpName = Asn1FieldName2CFieldName (asn1FieldName); cxxtri->fieldName = Malloc (strlen (tmpName) + 1 + r->maxDigitsToAppend); strcpy (cxxtri->fieldName, tmpName); Free (tmpName);/* old cxxtri->fieldName = Asn1FieldName2CFieldName (asn1FieldName); */ MakeCxxStrUnique (fieldNames, cxxtri->fieldName, r->maxDigitsToAppend, 1); DefineObj (&fieldNames, cxxtri->fieldName); } } FOR_EACH_LIST_ELMT (et, elmts) { cxxtri = et->type->cxxTypeRefInfo; /* * generate field names for those without them */ if (cxxtri->fieldName == NULL) { if ((et->type->basicType->choiceId == BASICTYPE_LOCALTYPEREF) || (et->type->basicType->choiceId == BASICTYPE_IMPORTTYPEREF)) { /* * take ref'd type name as field name * convert first let to lower case */ tmpName = et->type->basicType->a.localTypeRef->link->cxxTypeDefInfo->className; tmpName = Asn1TypeName2CTypeName (tmpName); cFieldName = Malloc (strlen (tmpName) + r->maxDigitsToAppend +1); strcpy (cFieldName, tmpName); Free (tmpName); if (isupper (cFieldName[0])) cFieldName[0] = tolower (cFieldName[0]); } else { /* * get default field name for this type */ tmpName = r->typeConvTbl[et->type->basicType->choiceId].defaultFieldName; cFieldName = Malloc (strlen (tmpName) + r->maxDigitsToAppend +1); strcpy (cFieldName, tmpName); if (isupper (cFieldName[0])) cFieldName[0] = tolower (cFieldName[0]); } len = strlen (cFieldName); /* * try to use just the type name (with lower case first char). * if that is already used in this type or a C++ keyword, * append ascii digits to field name until unique * in this type */ MakeCxxStrUnique (fieldNames, cFieldName, r->maxDigitsToAppend, 1); DefineObj (&fieldNames, cFieldName); cxxtri->fieldName = cFieldName; } } FreeDefinedObjs (&fieldNames);} /* FillCxxFieldNames *//* * returns true if this c type for this type should be * be ref'd as a ptr */static intIsCxxPtr PARAMS ((r, td, parent, t), CxxRules *r _AND_ TypeDef *td _AND_ Type *parent _AND_ Type *t){ CxxTDI *cxxtdi; int retVal = FALSE; /* * inherit ptr attriubutes from ref'd type if any * otherwise grab lib c type def from the CxxRules */ if ((t->basicType->choiceId == BASICTYPE_LOCALTYPEREF) || (t->basicType->choiceId == BASICTYPE_IMPORTTYPEREF)) { cxxtdi = t->basicType->a.localTypeRef->link->cxxTypeDefInfo; } else cxxtdi = &r->typeConvTbl[GetBuiltinType (t)]; /* no parent means t is the root of a typedef */ if ((parent == NULL) && (cxxtdi->isPtrForTypeDef)) retVal = TRUE; else if ((parent != NULL) && ((parent->basicType->choiceId == BASICTYPE_SET) || (parent->basicType->choiceId == BASICTYPE_SEQUENCE)) && (cxxtdi->isPtrInSetAndSeq)) retVal = TRUE; else if ((parent != NULL) && ((parent->basicType->choiceId == BASICTYPE_SETOF) || (parent->basicType->choiceId == BASICTYPE_SEQUENCEOF)) && (cxxtdi->isPtrInList)) retVal = TRUE; else if ((parent != NULL) && (parent->basicType->choiceId == BASICTYPE_CHOICE) && (cxxtdi->isPtrInChoice)) retVal = TRUE; else if (((t->optional) || (t->defaultVal != NULL)) && (cxxtdi->isPtrForOpt)) retVal = TRUE; return retVal;} /* IsCxxPtr *//* fill given cxxtdi with defaults from table for given typedef */voidFillCxxTDIDefaults PARAMS ((r, cxxtdi, td), CxxRules *r _AND_ CxxTDI *cxxtdi _AND_ TypeDef *td){ CxxTDI *tblCxxtdi; int typeIndex; char *tmpName; typeIndex = GetBuiltinType (td->type); if (typeIndex < 0) return; tblCxxtdi = &r->typeConvTbl[typeIndex]; memcpy (cxxtdi, tblCxxtdi, sizeof (CxxTDI)); /* make sure class name is unique wrt to previously defined classes */ tmpName = Asn1TypeName2CTypeName (td->definedName); cxxtdi->className = Malloc (strlen (tmpName) + r->maxDigitsToAppend +1); strcpy (cxxtdi->className, tmpName); Free (tmpName); MakeCxxStrUnique (definedNamesG, cxxtdi->className, r->maxDigitsToAppend, 1); DefineObj (&definedNamesG, cxxtdi->className);} /* FillCxxTDIDefaults */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -