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

📄 types.c

📁 asn.1 compiler
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * compiler/back_ends/idl_gen/types.c  - fills in IDL type information * * MS 91/92 * Copyright (C) 1991, 1992 Michael Sample *           and the University of British Columbia * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * $Header: /usr/app/odstb/CVS/snacc/compiler/back-ends/idl-gen/types.c,v 1.1 1997/01/01 20:25:40 rj Exp $ * $Log: types.c,v $ * Revision 1.1  1997/01/01 20:25:40  rj * first draft * */#include <ctype.h>#include <stdio.h>#include "asn-incl.h"#include "define.h"#include "asn1module.h"#include "mem.h"#include "snacc-util.h"#include "str-util.h"#include "rules.h"#include "c++-gen/kwd.h"#include "types.h"extern Module		*usefulTypeModG;static DefinedObj	*definedNamesG;/* unexported prototypes */void FillIDLTypeDefInfo PROTO ((IDLRules *r, Module *m, TypeDef *td));static void FillIDLFieldNames PROTO ((IDLRules *r, NamedTypeList *firstSibling));static void FillIDLTypeRefInfo PROTO ((IDLRules *r, Module *m, TypeDef *td, Type *parent, Type *t));static void FillIDLStructElmts PROTO ((IDLRules *r, Module *m, TypeDef *td, Type *parent, NamedTypeList *t));static void FillIDLChoiceElmts PROTO ((IDLRules *r, Module *m, TypeDef *td, Type *parent, NamedTypeList *first));static int IsIDLPtr PROTO ((IDLRules *r, TypeDef *td, Type *parent, Type *t));void FillIDLTDIDefaults PROTO ((IDLRules *r, IDLTDI *ctdi, TypeDef *td));/* *  allocates and fills all the idlTypeInfos *  in the type trees for every module in the list */voidFillIDLTypeInfo PARAMS ((r, modList),    IDLRules *r _AND_    ModuleList *modList){    TypeDef *td;    Module *m;    /*     * go through each module's type defs and fill     * in the C type and enc/dec routines etc     */    definedNamesG = NULL;    /* do useful types first */    if (usefulTypeModG != NULL)    {        FOR_EACH_LIST_ELMT (td, usefulTypeModG->typeDefs)            FillIDLTypeDefInfo (r, usefulTypeModG, td);    }    FOR_EACH_LIST_ELMT (m, modList)    {        FOR_EACH_LIST_ELMT (td, m->typeDefs)            FillIDLTypeDefInfo (r, m, td);    }    /*     * now that type def info is filled in     * set up set/seq/list/choice elements that ref     * those definitions     */    /* do useful types first */    if (usefulTypeModG != NULL)    {        FOR_EACH_LIST_ELMT (td, usefulTypeModG->typeDefs)            FillIDLTypeRefInfo (r, usefulTypeModG, td, NULL, td->type);    }    FOR_EACH_LIST_ELMT (m, modList)    {        FOR_EACH_LIST_ELMT (td, m->typeDefs)            FillIDLTypeRefInfo (r, m, td, NULL, td->type);    }    /*     * modules compiled together (ie one call to snacc with     * multiple args) likely to be C compiled together so     * need a unique routines/types/defines/enum values     * since assuming they share same name space.     *  All Typedefs, union, struct & enum Tags, and defined values     * (enum consts), #define names     *  are assumed to share the same name space     */    /* done with checking for name conflicts */    FreeDefinedObjs (&definedNamesG);}  /* FillIDLTypeInfo *//* *  allocates and fills structure holding C type definition information *  fo the given ASN.1 type definition.  Does not fill CTRI for contained *  types etc. */voidFillIDLTypeDefInfo PARAMS ((r, m, td),    IDLRules *r _AND_    Module *m _AND_    TypeDef *td){    int digit;    int len;    char *tmpName;    IDLTDI *idltdi;    /*     * if IDLTDI is present this type def has already been 'filled'     */    if (td->idlTypeDefInfo != NULL)        return;    idltdi = MT (IDLTDI);    td->idlTypeDefInfo = idltdi;    /* get default type def attributes from table for type on rhs of ::= */    FillIDLTDIDefaults (r, idltdi, td);    /*     * if defined by a ref to another type definition fill in that type     * def's IDLTDI so can inherit (actully completly replace default     * attributes) from it     */    if ((td->type->basicType->choiceId == BASICTYPE_LOCALTYPEREF) ||        (td->type->basicType->choiceId == BASICTYPE_IMPORTTYPEREF))    {        /*         * Fill in IDLTDI for defining type if nec.         * this works for importTypeRef as well since both a.localTypeRef         * and a.importTypeRef are of type TypeRef         */        FillIDLTypeDefInfo (r, td->type->basicType->a.localTypeRef->module, td->type->basicType->a.localTypeRef->link);        tmpName = idltdi->typeName; /* save typeName */        /* copy all type def info and restore name related stuff - hack*/        *idltdi = *td->type->basicType->a.localTypeRef->link->idlTypeDefInfo;        idltdi->typeName = tmpName; /* restore typeName */    }    /*     * check for any "--snacc" attributes that overide the current     * idltdi fields     * UNDEFINED FOR C++    ParseTypeDefAttribs (idltdi, td->attrList);     */}  /* FillIDLTypeDefInfo */static voidFillIDLTypeRefInfo PARAMS ((r, m, td, parent, t),    IDLRules	*r _AND_    Module	*m _AND_    TypeDef	*td _AND_    Type	*parent _AND_    Type	*t){    IDLTRI	*idltri;    IDLTDI	*tmpidltdi;    ValueDef	*namedElmt;    CNamedElmt	*cne;    CNamedElmt	**cneHndl;    char	*elmtName;    char	*listName;    char	*choiceName;    char	*unionName;    Type	*tmpT;    int		len, digit;    enum BasicTypeChoiceId		basicTypeId;    /*     * you must check for cycles yourself before calling this     */    if (t->idlTypeRefInfo == NULL)    {        idltri = MT (IDLTRI);        t->idlTypeRefInfo = idltri;    }    else        idltri = t->idlTypeRefInfo;    basicTypeId = t->basicType->choiceId;    tmpidltdi = &r->typeConvTbl[basicTypeId];    /* get base type def info from the conversion table in the rules */    idltri->isEnc = tmpidltdi->isEnc;    idltri->typeName = tmpidltdi->typeName;    idltri->optTestRoutineName = tmpidltdi->optTestRoutineName;    /*     * convert named elmts to IDL names.     * check for name conflict with other defined Types/Names/Values     */    if ((basicTypeId == BASICTYPE_INTEGER || basicTypeId == BASICTYPE_ENUMERATED || basicTypeId == BASICTYPE_BITSTRING) && !(LIST_EMPTY (t->basicType->a.integer)))    {        idltri->namedElmts = AsnListNew (sizeof (void *));        FOR_EACH_LIST_ELMT (namedElmt, t->basicType->a.integer)        {            cneHndl = (CNamedElmt **)AsnListAppend (idltri->namedElmts);            cne = *cneHndl = MT (CNamedElmt);            elmtName = Asn1ValueName2CValueName (namedElmt->definedName);#if 0	    if (basicTypeId == BASICTYPE_BITSTRING)#endif	    {		len = strlen (elmtName);		cne->name = Malloc (len + 1 + r->maxDigitsToAppend);		strcpy (cne->name, elmtName);	    }#if 0	    else	    {		len = strlen (idltri->typeName) + 7 + strlen (elmtName);		cne->name = Malloc (len + 1 + r->maxDigitsToAppend);		strcpy (cne->name, idltri->typeName);		strcat (cne->name, "Choice_");		strcat (cne->name, elmtName);	    }#endif            Free (elmtName); /* not very efficient */            if (namedElmt->value->basicValue->choiceId == BASICVALUE_INTEGER)                cne->value = namedElmt->value->basicValue->a.integer;            else            {                fprintf (stderr, "Warning: unlinked defined value. Using -9999999\n");                cne->value = -9999999;            }            if (r->capitalizeNamedElmts)                Str2UCase (cne->name, len);            /*             * append digits if enum value name is a keyword             */            MakeCxxStrUnique (definedNamesG, cne->name, r->maxDigitsToAppend, 1);            DefineObj (&definedNamesG, cne->name);        }    }    /* fill in rest of type info depending on the type */    switch (basicTypeId)    {        case BASICTYPE_BOOLEAN:  /* library types */        case BASICTYPE_INTEGER:        case BASICTYPE_BITSTRING:        case BASICTYPE_OCTETSTRING:        case BASICTYPE_NULL:        case BASICTYPE_OID:        case BASICTYPE_REAL:        case BASICTYPE_ENUMERATED:            /* don't need to do anything else */            break;        case BASICTYPE_SEQUENCEOF:  /* list types */        case BASICTYPE_SETOF:            /* fill in component type */            FillIDLTypeRefInfo (r, m, td, t, t->basicType->a.setOf);            break;        case BASICTYPE_IMPORTTYPEREF:  /* type references */        case BASICTYPE_LOCALTYPEREF:            /*             * grab class 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 */                tmpidltdi=  t->basicType->a.localTypeRef->link->idlTypeDefInfo;                idltri->typeName = tmpidltdi->typeName;                idltri->isEnc = tmpidltdi->isEnc;                idltri->optTestRoutineName = tmpidltdi->optTestRoutineName;            }            break;        case BASICTYPE_ANYDEFINEDBY:  /* ANY types */            break;  /* these are handled now */        case BASICTYPE_ANY:#if 0            PrintErrLoc (m->asn1SrcFileName, t->lineNo);            fprintf (stderr, "Warning - generated code for the \"ANY\" type in type \"%s\" will need modification by YOU.", td->definedName);            fprintf (stderr, "  The source files will have a \"/* ANY - Fix Me! */\" comment before related code.\n\n");#endif            break;

⌨️ 快捷键说明

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