#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 PrintCxxAnyEnum PROTO ((FILE *hdr, Module *m, CxxRules *r));
void PrintCxxAnyHashInitRoutine PROTO ((FILE *src, FILE *hdr, ModuleList *mods, Module *m, CxxRules *r));
void
PrintCxxAnyCode PARAMS ((src, hdr, r, mods, m),
FILE *src _AND_
FILE *hdr _AND_
CxxRules *r _AND_
ModuleList *mods _AND_
Module *m)
{
if (!m->hasAnys)
return;
PrintCxxAnyEnum (hdr, m, r);
PrintCxxAnyHashInitRoutine (src, hdr, mods, m, r);
}
void
PrintCxxAnyEnum PARAMS ((hdr, m, r),
FILE *hdr _AND_
Module *m _AND_
CxxRules *r)
{
TypeDef *td;
AnyRef *ar;
AnyRefList *arl;
int firstPrinted = TRUE;
int i;
char *modName;
modName = Asn1TypeName2CTypeName (m->modId->name);
fprintf (hdr,"typedef enum %sAnyId\n", modName);
fprintf (hdr,"{\n");
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 (hdr,",\n");
fprintf (hdr," %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 (hdr,",\n");
fprintf (hdr," %s = %d", ar->anyIdName, anyEnumValG++);
firstPrinted = FALSE;
}
}
}
#ifndef VDADER_RULES
if (firstPrinted)
fprintf (hdr,"/* NO INTEGER or OBJECT IDENTIFIER to ANY type relationships were defined (via MACROs or other mechanism) */\n ??? \n");
#endif
fprintf (hdr,"\n} %sAnyId;\n\n\n", modName);
Free (modName);
}
void
PrintCxxAnyHashInitRoutine PARAMS ((src, hdr, mods, m, r),
FILE *src _AND_
FILE *hdr _AND_
ModuleList *mods _AND_
Module *m _AND_
CxxRules *r)
{
TypeDef *td;
AnyRefList *arl;
AnyRef *ar;
CxxTDI *cxxtdi;
int i;
int j;
enum BasicTypeChoiceId typeId;
int installedSomeHashes = FALSE;
#ifndef VDADER_RULES
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");
fprintf (src,"InitAny::InitAny()\n");
fprintf (src,"{\n");
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++);
PrintCxxOidValue (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++);
PrintCxxIntValue (src, r, ar->id->a.intId);
fprintf (src,";\n");
}
}
}
}
FOR_EACH_LIST_ELMT (td, m->typeDefs)
{
if (td->anyRefs != NULL)
{
cxxtdi = td->cxxTypeDefInfo;
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++);
PrintCxxOidValue (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++);
PrintCxxIntValue (src, r, ar->id->a.intId);
fprintf (src,";\n");
}
}
}
}
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)
{
cxxtdi = td->cxxTypeDefInfo;
if (ar->id->choiceId == OIDORINT_OID)
fprintf (src," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, cxxtdi->className);
else
fprintf (src," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, cxxtdi->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");
fprintf (src," /* VDADER_RULES is selected UPDATE THIS COMMENT\n");
fprintf (src," */\n");
}
fprintf (src,"} /* InitAny::InitAny */\n\n\n");
#endif
}