1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
|
/*
* compiler/back_ends/idl_gen/gen_idl_code.c - routines for printing CORBA IDL code from type trees
*
* assumes that the type tree has already been run through the
* IDL type generator (idl_gen/types.c).
*
* Mike Sample
* 92
* Copyright (C) 1991, 1992 Michael Sample
* and the University of British Columbia
*
* Copyright 1995 Robert Joop
*
* 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: /baseline/SNACC/compiler/back-ends/idl-gen/gen-code.c,v 1.9 2004/03/25 19:20:16 gronej Exp $
* $Log: gen-code.c,v $
* Revision 1.9 2004/03/25 19:20:16 gronej
* fixed some linux warnings
*
* Revision 1.8 2004/01/14 19:07:53 gronej
* Updated Compiler to accept and process relative-oid's
*
* Revision 1.7 2003/07/17 15:16:28 nicholar
* Fixed bugs related to removing headers.
*
* Revision 1.6 2003/07/07 14:51:57 nicholar
* Eliminated headers and cleaned up include references
*
* Revision 1.5 2002/10/21 17:15:34 mcphersc
* fixed long int
*
* Revision 1.4 2002/09/16 17:53:46 mcphersc
* iFixed warnings
*
* Revision 1.3 2002/09/04 18:02:28 vracarl
* got rid of c++ comments
*
* Revision 1.2 2000/10/24 14:54:48 rwc
* Updated to remove high-level warnings (level 4 on MSVC++) for an easier build.
* SOME warnings persist due to difficulty in modifying the SNACC compiler to
* properly build clean source; also some files are built by Lex/Yacc.
*
* Revision 1.1.1.1 2000/08/21 20:36:04 leonberp
* First CVS Version of SNACC.
*
* Revision 1.2 1997/03/13 09:15:21 wan
* Improved dependency generation for stupid makedepends.
* Corrected PeekTag to peek into buffer only as far as necessary.
* Added installable error handler.
* Fixed small glitch in idl-code generator (Markku Savela <msa@msa.tte.vtt.fi>).
*
* Revision 1.1 1997/01/01 20:25:34 rj
* first draft
*
*/
#include "snacc.h"
#if STDC_HEADERS || HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#include <time.h>
#include "asn-incl.h"
#include "asn1module.h"
#include "rules.h"
#include "snacc-util.h"
#include "print.h"
/* Function Prototypes */
void PrintConditionalIncludeOpen PROTO ((FILE *f, char *fileName));
void PrintConditionalIncludeClose PROTO ((FILE *f, char *fileName));
void PrintIDLValueDef PROTO ((FILE *idl, IDLRules *r, ValueDef *v));
void PrintIDLValueDefsName PROTO ((FILE *f, IDLRules *r, ValueDef *v));
static long longJmpValG = -100;
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintComment PARAMS ((idl, m),
FILE *idl _AND_
Module *m)
{
time_t t;
t = time (0);
fprintf (idl, "// NOTE: this is a machine generated file -- editing not recommended\n");
fprintf (idl, "//\n");
fprintf (idl, "// %s -- IDL for ASN.1 module %s\n", m->idlFileName, m->modId->name);
fprintf (idl, "//\n");
fprintf (idl, "// This file was generated by snacc on %s", ctime (&t));
fprintf (idl, "// UBC snacc written by Mike Sample\n");
fprintf (idl, "// IDL generator written by Robert Joop\n");
fprintf (idl, "\n");
} /* PrintComment */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintIncludes PARAMS ((idl, mods, m),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m)
{
void *tmp;
Module *currMod;
fprintf (idl, "#include \"ASN1Types.idl\"\n");
fprintf (idl, "#include \"BitString.idl\"\n");
tmp = (void *)CURR_LIST_NODE (mods); /* remember curr loc */
FOR_EACH_LIST_ELMT (currMod, mods)
fprintf (idl, "#include \"%s\"\n", currMod->idlFileName);
SET_CURR_LIST_NODE (mods, tmp);
m=m; /*AVOIDS warning.*/
} /* PrintIncludes */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintTypeDecl PARAMS ((f, td),
FILE *f _AND_
TypeDef *td)
{
switch (td->type->basicType->choiceId)
{
case BASICTYPE_COMPONENTSOF:
case BASICTYPE_SELECTION:
case BASICTYPE_UNKNOWN:
case BASICTYPE_MACRODEF:
case BASICTYPE_MACROTYPE:
return; /* do nothing */
case BASICTYPE_ENUMERATED:
if (IsNewType (td->type))
fprintf (f, " enum %s;\n", td->idlTypeDefInfo->typeName);
break;
default:
if (IsNewType (td->type))
fprintf (f, " struct %s;\n", td->idlTypeDefInfo->typeName);
}
} /* PrintTypeDecl */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintIDLTypeAndName PARAMS ((idl, mods, m, r, td, parent, t),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
TypeDef *td _AND_
Type *parent _AND_
Type *t)
{
if (t->optional)
fprintf (idl, "union %sOptional switch (boolean) { case True: %s %s; };\n", t->idlTypeRefInfo->typeName, t->idlTypeRefInfo->typeName, t->idlTypeRefInfo->fieldName);
else
fprintf (idl, "%s %s;\n", t->idlTypeRefInfo->typeName, t->idlTypeRefInfo->fieldName);
#if 0
if (t->idlTypeRefInfo->isPtr)
fprintf (idl, "*");
#endif
parent=parent;td=td;r=r;m=m;mods=mods; /*AVOIDS warning.*/
} /* PrintIDLTypeAndName */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
/*
* prints typedef or new class given an ASN.1 type def of a primitive type
* or typeref. Uses inheritance to cover re-tagging and named elmts.
*/
static void
PrintIDLSimpleDef PARAMS ((idl, r, td),
FILE *idl _AND_
IDLRules *r _AND_
TypeDef *td)
{
int hasNamedElmts;
CNamedElmt *n;
fprintf (idl, " /* ");
SpecialPrintType (idl, td, td->type);
fprintf (idl, " */\n");
if ((hasNamedElmts = HasNamedElmts (td->type)) != FALSE)
{
int tlen = strlen (td->idlTypeDefInfo->typeName) - strlen (r->typeSuffix);
switch (GetBuiltinType (td->type))
{
case BASICTYPE_INTEGER:
fprintf (idl, " typedef %s %s;\n", td->type->idlTypeRefInfo->typeName, td->idlTypeDefInfo->typeName);
FOR_EACH_LIST_ELMT (n, td->type->idlTypeRefInfo->namedElmts)
fprintf (idl, " const %s %.*s_%s = %d;\n", td->idlTypeDefInfo->typeName, tlen, td->idlTypeDefInfo->typeName, n->name, n->value);
break;
case BASICTYPE_ENUMERATED:
fprintf (idl, " enum %s\n", td->idlTypeDefInfo->typeName);
fprintf (idl, " {\n");
FOR_EACH_LIST_ELMT (n, td->type->idlTypeRefInfo->namedElmts)
{
char comma = (char)((n != (CNamedElmt *)LAST_LIST_ELMT (td->type->idlTypeRefInfo->namedElmts)) ? ',' : ' ');
fprintf (idl, " %s%c // (original value = %d)\n", n->name, comma, n->value);
}
fprintf (idl, " };\n");
break;
case BASICTYPE_BITSTRING:
fprintf (idl, " typedef %s %s;\n", td->type->idlTypeRefInfo->typeName, td->idlTypeDefInfo->typeName);
FOR_EACH_LIST_ELMT (n, td->type->idlTypeRefInfo->namedElmts)
fprintf (idl, " const unsigned long %.*s_%s = %d;\n", tlen, td->idlTypeDefInfo->typeName, n->name, n->value);
break;
default:
fprintf (idl, " \?\?\?!\n");
}
}
else
fprintf (idl, " typedef %s %s;\n\n", td->type->idlTypeRefInfo->typeName, td->idlTypeDefInfo->typeName);
} /* PrintIDLSimpleDef */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintIDLChoiceDefCode PARAMS ((idl, mods, m, r, td, parent, choice),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
TypeDef *td _AND_
Type *parent _AND_
Type *choice)
{
NamedType *e;
/* put class spec in idl file */
/* write out choiceId enum type */
fprintf (idl, " enum %s%s\n", td->idlTypeDefInfo->typeName, r->choiceEnumSuffix);
fprintf (idl, " {\n");
FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
{
fprintf (idl, " %s", e->type->idlTypeRefInfo->choiceIdSymbol);
if (e != (NamedType *)LAST_LIST_ELMT (choice->basicType->a.choice))
fprintf (idl, ",\n");
else
fprintf (idl, "\n");
}
fprintf (idl, " };\n\n");
/* write out the choice element anonymous union */
fprintf (idl, " union %s switch (%s%s)\n", td->idlTypeDefInfo->typeName, td->idlTypeDefInfo->typeName, r->choiceEnumSuffix);
fprintf (idl, " {\n");
FOR_EACH_LIST_ELMT (e, choice->basicType->a.choice)
{
#if 0
fprintf (idl, " case %s: %s %s;\n", e->type->idlTypeRefInfo->choiceIdSymbol, e->type->idlTypeRefInfo->typeName, e->type->idlTypeRefInfo->fieldName);
#else
fprintf (idl, " case %s: ", e->type->idlTypeRefInfo->choiceIdSymbol);
PrintIDLTypeAndName (idl, mods, m, r, td, choice, e->type);
#endif
}
fprintf (idl, " };\n\n");
parent=parent; /*AVOIDS warning.*/
} /* PrintIDLChoiceDefCode */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintIDLSeqDefCode PARAMS ((idl, mods, m, r, td, parent, seq),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
TypeDef *td _AND_
Type *parent _AND_
Type *seq)
{
NamedType *e;
/* put class spec in idl file */
fprintf (idl, " struct %s\n", td->idlTypeDefInfo->typeName);
fprintf (idl, " {\n");
/* write out the sequence elmts */
FOR_EACH_LIST_ELMT (e, seq->basicType->a.sequence)
{
fprintf (idl, " ");
PrintIDLTypeAndName (idl, mods, m, r, td, seq, e->type);
}
/* close struct definition */
fprintf (idl, " };\n\n\n");
parent=parent; /*AVOIDS warning.*/
} /* PrintIDLSeqDefCode */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintIDLSetDefCode PARAMS ((idl, mods, m, r, td, parent, set),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
TypeDef *td _AND_
Type *parent _AND_
Type *set)
{
NamedType *e;
/* put class spec in idl file */
fprintf (idl, " struct %s\n", td->idlTypeDefInfo->typeName);
fprintf (idl, " {\n");
/* write out the set elmts */
FOR_EACH_LIST_ELMT (e, set->basicType->a.set)
{
fprintf (idl, " ");
PrintIDLTypeAndName (idl, mods, m, r, td, set, e->type);
}
fprintf (idl, " };\n\n");
parent=parent; /*AVOIDS warning.*/
} /* PrintIDLSetDefCode */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintCxxSetOfDefCode PARAMS ((idl, mods, m, r, td, parent, setOf),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
TypeDef *td _AND_
Type *parent _AND_
Type *setOf)
{
char *lcn; /* list class name */
char *ecn; /* (list) elmt class name */
lcn = td->idlTypeDefInfo->typeName;
ecn = setOf->basicType->a.setOf->idlTypeRefInfo->typeName;
fprintf (idl, " typedef sequence<%s> %s;\n", ecn, lcn);
parent=parent;r=r;m=m;mods=mods; /*AVOIDS warning.*/
} /* PrintCxxSetOfDefCode */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintCxxAnyDefCode PARAMS ((idl, mods, m, r, td, parent, any),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
TypeDef *td _AND_
Type *parent _AND_
Type *any)
{
fprintf (idl, " /* ");
SpecialPrintType (idl, td, td->type);
fprintf (idl, " */\n");
fprintf (idl, " typedef %s %s;\n\n", td->type->idlTypeRefInfo->typeName, td->idlTypeDefInfo->typeName);
any=any;parent=parent;r=r;m=m;mods=mods; /*AVOIDS warning.*/
} /* PrintCxxAnyDefCode */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
static void
PrintIDLTypeDefCode PARAMS ((idl, mods, m, r, td),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
TypeDef *td)
{
switch (td->type->basicType->choiceId)
{
case BASICTYPE_BOOLEAN: /* library type */
case BASICTYPE_REAL: /* library type */
case BASICTYPE_OCTETSTRING: /* library type */
case BASICTYPE_NULL: /* library type */
case BASICTYPE_OID: /* library type */
case BASICTYPE_RELATIVE_OID:
case BASICTYPE_INTEGER: /* library type */
case BASICTYPE_BITSTRING: /* library type */
case BASICTYPE_ENUMERATED: /* library type */
PrintIDLSimpleDef (idl, r, td);
break;
case BASICTYPE_SEQUENCEOF: /* list types */
case BASICTYPE_SETOF:
PrintCxxSetOfDefCode (idl, mods, m, r, td, NULL, td->type);
break;
case BASICTYPE_IMPORTTYPEREF: /* type references */
case BASICTYPE_LOCALTYPEREF:
/*
* if this type has been re-tagged then
* must create new class instead of using a typedef
*/
PrintIDLSimpleDef (idl, r, td);
break;
case BASICTYPE_ANYDEFINEDBY: /* ANY types */
case BASICTYPE_ANY:
/*
fprintf (errFileG, " ANY types require modification. ");
fprintf (errFileG, " The source files will have a \" ANY - Fix Me! \" comment before related code.\n\n");
*/
PrintCxxAnyDefCode (idl, mods, m, r, td, NULL, td->type);
break;
case BASICTYPE_CHOICE:
PrintIDLChoiceDefCode (idl, mods, m, r, td, NULL, td->type);
break;
case BASICTYPE_SET:
PrintIDLSetDefCode (idl, mods, m, r, td, NULL, td->type);
break;
case BASICTYPE_SEQUENCE:
PrintIDLSeqDefCode (idl, mods, m, r, td, NULL, td->type);
break;
case BASICTYPE_COMPONENTSOF:
case BASICTYPE_SELECTION:
case BASICTYPE_UNKNOWN:
case BASICTYPE_MACRODEF:
case BASICTYPE_MACROTYPE:
/* do nothing */
break;
default:
break;
}
} /* PrintIDLTypeDefCode */
/*\[sep]--------------------------------------------------------------------------------------------------------------------------*/
void
PrintIDLCode PARAMS ((idl, mods, m, r, longJmpVal),
FILE *idl _AND_
ModuleList *mods _AND_
Module *m _AND_
IDLRules *r _AND_
long longJmpVal _AND_
int printValues)
{
TypeDef *td;
ValueDef *vd;
longJmpValG = longJmpVal;
PrintComment (idl, m);
PrintConditionalIncludeOpen (idl, m->idlFileName);
PrintIncludes (idl, mods, m);
fprintf (idl, "\n");
fprintf (idl, "module %s\n{\n\n", m->idlname);
fprintf (idl, " //----------------------------------------------------------------------------\n");
fprintf (idl, " // type declarations:\n\n");
FOR_EACH_LIST_ELMT (td, m->typeDefs)
PrintTypeDecl (idl, td);
fprintf (idl, "\n");
if (printValues)
{
fprintf (idl, " //----------------------------------------------------------------------------\n");
fprintf (idl, " // value definitions:\n\n");
FOR_EACH_LIST_ELMT (vd, m->valueDefs)
PrintIDLValueDef (idl, r, vd);
fprintf (idl, "\n");
}
fprintf (idl, " //----------------------------------------------------------------------------\n");
fprintf (idl, " // type definitions:\n\n");
#if 0
PrintIDLAnyCode (idl, r, mods, m);
#endif
FOR_EACH_LIST_ELMT (td, m->typeDefs)
{
PrintIDLTypeDefCode (idl, mods, m, r, td);
fputc ('\n', idl);
}
fprintf (idl, "}; // end of module %s\n", m->idlname);
PrintConditionalIncludeClose (idl, m->idlFileName);
} /* PrintIDLCode */
/*\[banner "EOF"]-----------------------------------------------------------------------------------------------------------------*/
|