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

📄 gen-any.c

📁 asn.1 compiler
💻 C
字号:
/* * compiler/back_ends/idl_gen/gen_any.c * *     prints Routine to initialize the ANY Hash table.  The *     ANY Hash table maps the OBJECT IDENTIFIERS or INTEGERS *     to the correct decoding routines. * *     Also prints an enum to identify each ANY mapping. * * MS 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/gen-any.c,v 1.1 1997/01/01 20:25:32 rj Exp $ * $Log: gen-any.c,v $ * Revision 1.1  1997/01/01 20:25:32  rj * first draft * */#include <stdio.h>#include "asn-incl.h"#include "mem.h"#include "asn1module.h"#include "define.h"#include "str-util.h"#include "rules.h"#include "gen-vals.h"#include "lib-types.h"#include "gen-any.h"static int anyEnumValG = 0;void PrintIDLAnyEnum PROTO ((FILE *idl, Module *m, IDLRules *r));void PrintIDLAnyHashInitRoutine PROTO ((FILE *idl, ModuleList *mods, Module *m, IDLRules *r));voidPrintIDLAnyCode PARAMS ((idl, r, mods, m),    FILE *idl _AND_    IDLRules *r _AND_    ModuleList *mods _AND_    Module *m){    if (!m->hasAnys)        return;    PrintIDLAnyEnum (idl, m, r);#if 0    PrintIDLAnyHashInitRoutine (idl, mods, m, r);#endif}  /* PrintAnyCode */voidPrintIDLAnyEnum PARAMS ((idl, m, r),    FILE *idl _AND_    Module *m _AND_    IDLRules *r){    TypeDef *td;    AnyRef *ar;    AnyRefList *arl;    int firstPrinted = TRUE;    int i;    char *modName;    modName = Asn1TypeName2CTypeName (m->modId->name);    fprintf (idl,"typedef enum %sAnyId\n", modName);    fprintf (idl,"{\n");    /* do any lib types */    for (i = BASICTYPE_BOOLEAN; i < BASICTYPE_MACRODEF; i++)    {        arl = LIBTYPE_GET_ANY_REFS (i);        if (arl != NULL)        {            FOR_EACH_LIST_ELMT (ar, arl)            {                if (!firstPrinted)                    fprintf (idl,",\n");                fprintf (idl,"    %s = %d", ar->anyIdName, anyEnumValG++);                firstPrinted = FALSE;            }        }    }    FOR_EACH_LIST_ELMT (td, m->typeDefs)    {        if (td->anyRefs != NULL)        {            FOR_EACH_LIST_ELMT (ar, td->anyRefs)            {                if (!firstPrinted)                    fprintf (idl,",\n");                fprintf (idl,"    %s = %d", ar->anyIdName, anyEnumValG++);                firstPrinted = FALSE;            }        }    }    if (firstPrinted) /* none have been printed */        fprintf (idl,"/* NO INTEGER or OBJECT IDENTIFIER to ANY type relationships were defined (via MACROs or other mechanism) */\n ??? \n");    fprintf (idl,"\n} %sAnyId;\n\n\n", modName);    Free (modName);}  /* PrintAnyEnum */#if 0voidPrintIDLAnyHashInitRoutine PARAMS ((idl, mods, m, r),    FILE *idl _AND_    ModuleList *mods _AND_    Module *m _AND_    IDLRules *r){    TypeDef *td;    AnyRefList *arl;    AnyRef *ar;    IDLTDI *idltdi;    int i;    int j;    enum BasicTypeChoiceId typeId;    int installedSomeHashes = FALSE;    /* print InitAny class src file */    fprintf (src,"// this class will automatically intialize the any hash tbl\n");    fprintf (src,"class InitAny\n");    fprintf (src,"{\n");    fprintf (src,"  public:\n");    fprintf (src,"    InitAny();\n");    fprintf (src,"};\n\n");    fprintf (src,"static InitAny anyInitalizer;\n");    /* print constructor method that build hash tbl to src file*/    fprintf (src,"InitAny::InitAny()\n");    fprintf (src,"{\n");    /* first print value for OID's */    /* do any lib types first */    i = 0;    for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++)    {        arl = LIBTYPE_GET_ANY_REFS (j);        if (arl != NULL)        {            FOR_EACH_LIST_ELMT (ar, arl)            {                installedSomeHashes = TRUE;                if (ar->id->choiceId == OIDORINT_OID)                {                    fprintf (src,"    %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++);                    PrintIDLOidValue (src, r, ar->id->a.oid);                    fprintf (src,";\n");                }                else if (ar->id->choiceId == OIDORINT_INTID)                {                    fprintf (src,"    %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++);                    PrintIDLIntValue (src, r, ar->id->a.intId);                    fprintf (src,";\n");                }            }        }    }    FOR_EACH_LIST_ELMT (td, m->typeDefs)    {        if (td->anyRefs != NULL)        {            idltdi = td->idlTypeDefInfo;            FOR_EACH_LIST_ELMT (ar, td->anyRefs)            {                installedSomeHashes = TRUE;                if (ar->id->choiceId == OIDORINT_OID)                {                    fprintf (src,"    %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++);                    PrintIDLOidValue (src, r, ar->id->a.oid);                    fprintf (src,";\n");                }                else if (ar->id->choiceId == OIDORINT_INTID)                {                    fprintf (src,"    %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++);                    PrintIDLIntValue (src, r, ar->id->a.intId);                    fprintf (src,";\n");                }            }        }    }    /* now print hash init calls */    i = 0;    for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++)    {        arl = LIBTYPE_GET_ANY_REFS (j);        if (arl != NULL)        {            FOR_EACH_LIST_ELMT (ar, arl)            {                if (ar->id->choiceId == OIDORINT_OID)                    fprintf (src,"    AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, r->typeConvTbl[j].className);                else                    fprintf (src,"    AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, r->typeConvTbl[j].className);            }        }    }    FOR_EACH_LIST_ELMT (td, m->typeDefs)    {        if (td->anyRefs != NULL)        {            FOR_EACH_LIST_ELMT (ar, td->anyRefs)            {                idltdi = td->idlTypeDefInfo;                if (ar->id->choiceId == OIDORINT_OID)                    fprintf (src,"    AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, idltdi->className);                else                    fprintf (src,"    AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, idltdi->className);            }        }    }    if (!installedSomeHashes)    {        fprintf (src,"    /* Since no INTEGER/OID to ANY type relations were defined\n");        fprintf (src,"     * (usually done via MACROs) you must manually do the code\n");        fprintf (src,"     * to fill the hash tbl.\n");        fprintf (src,"     * if the ids are INTEGER use the following:\n");        fprintf (src,"     * AsnAny::InstallAnyByInt (3, ??_ANY_ID, new <className>);\n");        fprintf (src,"     * if the ids are OBJECT IDENTIFIERs use the following:\n");        fprintf (src,"     * AsnAny::InstallAnyByOid (OidValue, ??_ANY_ID, new <className>);\n");        fprintf (src,"     * put the ??_ANY_IDs in the AnyId enum.\n\n");        fprintf (src,"     * For example if you have some thing like\n");        fprintf (src,"     * T1 ::= SEQUENCE { id INTEGER, ANY DEFINED BY id }\n");        fprintf (src,"     * and the id 1 maps to the type BOOLEAN use the following:\n");        fprintf (src,"     * AsnAny::InstallAnyByInt (1, SOMEBOOL_ANY_ID, new AsnBool);\n");        fprintf (src,"     */\n ???????\n");  /* generate compile error */    }    fprintf (src,"}  /* InitAny::InitAny */\n\n\n");}  /* PrintAnyHashInitRoutine */#endif

⌨️ 快捷键说明

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