]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/core/link-values.c
Security-54.1.7.tar.gz
[apple/security.git] / SecuritySNACCRuntime / compiler / core / link-values.c
1 /*
2 * compiler/core/link.c
3 *
4 * first links value refs in the import list then
5 * links value references in value defs and types' default values
6 *
7 *
8 * Mike Sample
9 * 91/09/04
10 * Completely Rewritten for new ModuleList data structure (ASN.1 based)
11 *
12 * Copyright (C) 1991, 1992 Michael Sample
13 * and the University of British Columbia
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * $Header: /cvs/root/Security/SecuritySNACCRuntime/compiler/core/Attic/link-values.c,v 1.1 2001/06/20 21:27:57 dmitch Exp $
21 * $Log: link-values.c,v $
22 * Revision 1.1 2001/06/20 21:27:57 dmitch
23 * Adding missing snacc compiler files.
24 *
25 * Revision 1.1.1.1 1999/03/16 18:06:49 aram
26 * Originals from SMIME Free Library.
27 *
28 * Revision 1.3 1995/07/25 19:41:38 rj
29 * changed `_' to `-' in file names.
30 *
31 * Revision 1.2 1994/09/01 00:38:43 rj
32 * snacc_config.h removed.
33 *
34 * Revision 1.1 1994/08/28 09:49:19 rj
35 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
36 *
37 */
38
39 #include <ctype.h>
40 #include <stdio.h>
41
42 #include "asn-incl.h"
43 #include "asn1module.h"
44 #include "mem.h"
45 #include "snacc-util.h"
46 #include "link-values.h"
47
48 extern Module *usefulTypeModG;
49
50 /* non-exported fcn prototypes */
51
52
53 void ValueLinkImportLists PROTO ((ModuleList *m));
54
55 void ValueLinkTypeDef PROTO ((ModuleList *m, Module *currMod, TypeDef *head));
56
57 void ValueLinkElmtTypes PROTO ((ModuleList *m, Module *currMod, TypeDef *head, NamedTypeList *e));
58
59 void ValueLinkElmtType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, NamedType *n));
60
61 void ValueLinkType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *currType));
62
63 void ValueLinkBasicType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *type, BasicType *bt));
64
65 void ValueLinkSubtypes PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *currType, Subtype *s));
66
67 void ValueLinkSubtypeValue PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *currType, SubtypeValue *s));
68
69 void ValueLinkNamedElmts PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, ValueDefList *v));
70
71
72 void ValueLinkValueDef PROTO ((ModuleList *m, Module *currMod, ValueDef *v));
73
74
75 void ValueLinkValue PROTO ((ModuleList *m, Module *currMod, ValueDef *head, Type *valuesType, Value *v));
76
77 void ValueLinkBasicValue PROTO ((ModuleList *m, Module *currMod, ValueDef *head, Type *valuesType, Value *v, BasicValue *bv));
78
79 void ValueLinkOid PROTO ((ModuleList *m, Module *currMod, ValueDef *head, Value *v, OID *oid));
80
81 void ValueLinkRosOperationMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, RosOperationMacroType *op));
82
83 void ValueLinkRosErrorMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, RosErrorMacroType *err));
84
85
86 void ValueLinkRosBindMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, RosBindMacroType *bind));
87
88 void ValueLinkRosAseMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, RosAseMacroType *ase));
89
90 void ValueLinkRosAcMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, RosAcMacroType *ac));
91
92 void ValueLinkMtsasExtensionsMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, MtsasExtensionsMacroType *exts));
93
94 void ValueLinkMtsasExtensionMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, MtsasExtensionMacroType *ext));
95
96 void ValueLinkMtsasExtensionAttributeMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, MtsasExtensionAttributeMacroType *ext));
97
98 void ValueLinkMtsasTokenMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, MtsasTokenMacroType *tok));
99
100 void ValueLinkMtsasTokenDataMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, MtsasTokenDataMacroType *tok));
101
102 void ValueLinkMtsasSecurityCategoryMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, MtsasSecurityCategoryMacroType *sec));
103
104 void ValueLinkAsnObjectMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, AsnObjectMacroType *obj));
105
106 void ValueLinkAsnPortMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, AsnPortMacroType *p));
107
108 void ValueLinkAsnAbstractBindMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, AsnAbstractBindMacroType *bind));
109
110 void ValueLinkSnmpObjectTypeMacroType PROTO ((ModuleList *m, Module *currMod, TypeDef *head, Type *t, BasicType *bt, SnmpObjectTypeMacroType *ot));
111
112
113 /* end of prototypes */
114
115
116
117
118 static char *asn1SrcFileNameG;
119 static int linkOidCallDepthG = 0; /* big hack!! */
120
121 /*
122 * returns 0 if no link error occured
123 * otherwise returns a value < 0.
124 * processing should not continue is an error is returned
125 */
126 int
127 LinkValueRefs PARAMS ((m),
128 ModuleList *m)
129 {
130 Module *currMod;
131 TypeDef *td;
132 ValueDef *vd;
133 int linkErr = 0;
134
135 /*
136 * link imported types/values to there definition if
137 * the defining module is in the modulelist
138 */
139 ValueLinkImportLists (m);
140
141
142 /* link useful module, in case there are value defs there */
143 if (usefulTypeModG != NULL)
144 {
145 currMod = usefulTypeModG;
146 asn1SrcFileNameG = currMod->asn1SrcFileName;
147
148 /*
149 * link this modules object identifier value
150 */
151 ValueLinkOid (m, currMod, NULL, NULL, currMod->modId->oid);
152
153
154 /*
155 * go through each type in typeList and link as nec
156 */
157 FOR_EACH_LIST_ELMT (td, currMod->typeDefs)
158 {
159 ValueLinkTypeDef (m, currMod, td);
160 }
161
162
163 /*
164 * go through each value in valueList and link as nec
165 */
166 FOR_EACH_LIST_ELMT (vd, currMod->valueDefs)
167 {
168 ValueLinkValueDef (m, currMod, vd);
169 }
170
171 if (currMod->status != MOD_ERROR)
172 currMod->status = MOD_OK;
173 else
174 linkErr = -1;
175 }
176
177 /*
178 * go through types, values & macros of each parsed module
179 */
180
181 FOR_EACH_LIST_ELMT (currMod, m)
182 {
183
184 asn1SrcFileNameG = currMod->asn1SrcFileName;
185
186 /*
187 * link this modules object identifier value
188 */
189 ValueLinkOid (m, currMod, NULL, NULL, currMod->modId->oid);
190
191
192 /*
193 * go through each type in typeList and link as nec
194 */
195 FOR_EACH_LIST_ELMT (td, currMod->typeDefs)
196 {
197 ValueLinkTypeDef (m, currMod, td);
198 }
199
200 /*
201 * go through each value in valueList and link as nec
202 */
203 FOR_EACH_LIST_ELMT (vd, currMod->valueDefs)
204 {
205 ValueLinkValueDef (m, currMod, vd);
206 }
207
208 if (currMod->status != MOD_ERROR)
209 currMod->status = MOD_OK;
210 else
211 linkErr = -1;
212 }
213
214 return linkErr;
215
216 } /* ValueLinkRefs */
217
218
219 /*
220 * go through each modules import lists and link
221 * any values as nec. values'symbols start with a
222 * lowercase letter
223 */
224 void
225 ValueLinkImportLists PARAMS ((m),
226 ModuleList *m)
227 {
228 Module *currMod;
229 TypeDef *t;
230 ValueDef *v;
231 ImportModule *currImpList;
232 ImportElmt *currImpElmt;
233 Module *impRefMod;
234
235
236 /* link imports of each module in the list */
237 FOR_EACH_LIST_ELMT (currMod, m)
238 {
239 /* for each import list in the current module */
240 FOR_EACH_LIST_ELMT (currImpList, currMod->imports)
241 {
242 /* see if the referenced module is in the list */
243 impRefMod = LookupModule (m, currImpList->modId->name, currImpList->modId->oid);
244
245 if (impRefMod == NULL)
246 {
247 /* the type linker will have reported this error */
248 continue;
249 }
250
251 /*
252 * link each value referencing import elmt in
253 * the current import list
254 */
255 FOR_EACH_LIST_ELMT (currImpElmt, currImpList->importElmts)
256 {
257 /*
258 * only link values (all vals have lowercase first letter)
259 */
260 if (!islower (currImpElmt->name[0]))
261 continue;
262
263 v = LookupValue (impRefMod->valueDefs, currImpElmt->name);
264 if (v != NULL)
265 {
266 if (!v->exported)
267 {
268 currMod->status = MOD_ERROR;
269 PrintErrLoc (currMod->asn1SrcFileName, currImpElmt->lineNo);
270 fprintf (stderr,"ERROR - \"%s\" module imports value \"%s\", which is not exported from module \"%s\".\n", currMod->modId->name, currImpElmt->name, impRefMod->modId->name);
271 }
272 /* resolve value */
273 currImpElmt->resolvedRef =
274 (ImportElmtChoice*)Malloc (sizeof (ImportElmtChoice));
275 currImpElmt->resolvedRef->choiceId = IMPORTELMTCHOICE_VALUE;
276 currImpElmt->resolvedRef->a.value = v;
277 }
278 else /* value not found in ref'd module */
279 {
280 currMod->status = MOD_ERROR;
281 PrintErrLoc (currMod->asn1SrcFileName, currImpElmt->lineNo);
282 fprintf (stderr,"ERROR - \"%s\" is imported from module \"%s\" by module \"%s\", but is not defined in the referenced module\n", currImpElmt->name, impRefMod->modId->name, currMod->modId->name);
283 }
284
285 }
286 }
287 }
288 } /* ValueLinkImportLists */
289
290
291
292 void
293 ValueLinkTypeDef PARAMS ((m, currMod, head),
294 ModuleList *m _AND_
295 Module *currMod _AND_
296 TypeDef *head)
297 {
298
299 if (head == NULL)
300 return;
301
302 ValueLinkType (m, currMod, head, head->type);
303
304 } /* ValueLinkTypeDef */
305
306
307
308 void
309 ValueLinkType PARAMS ((m, currMod, head, t),
310 ModuleList *m _AND_
311 Module *currMod _AND_
312 TypeDef *head _AND_
313 Type *t)
314 {
315
316 if (t == NULL)
317 return;
318
319 ValueLinkBasicType (m, currMod, head, t, t->basicType);
320
321 ValueLinkSubtypes (m, currMod, head, t, t->subtypes);
322
323 if (t->defaultVal != NULL)
324 ValueLinkValue (m, currMod, NULL, t, t->defaultVal->value);
325
326 } /* ValueLinkType */
327
328
329
330 void
331 ValueLinkElmtTypes PARAMS ((m, currMod, head, e),
332 ModuleList *m _AND_
333 Module *currMod _AND_
334 TypeDef *head _AND_
335 NamedTypeList *e)
336 {
337 NamedType *n;
338 FOR_EACH_LIST_ELMT (n, e)
339 {
340 ValueLinkElmtType (m, currMod, head, n);
341 }
342 } /* ValueLinkElmtTypes */
343
344
345 void
346 ValueLinkElmtType PARAMS ((m, currMod, head, n),
347 ModuleList *m _AND_
348 Module *currMod _AND_
349 TypeDef *head _AND_
350 NamedType *n)
351 {
352 if (n != NULL)
353 ValueLinkType (m, currMod, head, n->type);
354 }
355
356
357 void
358 ValueLinkBasicType PARAMS ((m, currMod, head, type, bt),
359 ModuleList *m _AND_
360 Module *currMod _AND_
361 TypeDef *head _AND_
362 Type *type _AND_
363 BasicType *bt)
364 {
365 TypeDef *tmpTypeDef;
366 TypeDefList *tmpTypeDefs;
367 Type *tmpType;
368 Module *tmpMod;
369 NamedType *tmpElmtType;
370 ImportElmt *impElmt;
371 ImportModule *impMod;
372 int implicitRef;
373
374 if (bt == NULL)
375 return;
376
377 switch (bt->choiceId)
378 {
379
380 case BASICTYPE_SEQUENCE:
381 case BASICTYPE_SET:
382 case BASICTYPE_CHOICE:
383 ValueLinkElmtTypes (m, currMod, head, bt->a.set);
384 break;
385
386
387
388 case BASICTYPE_SEQUENCEOF:
389 case BASICTYPE_SETOF:
390 ValueLinkType (m, currMod, head, bt->a.setOf);
391 break;
392
393
394
395 case BASICTYPE_SELECTION:
396 case BASICTYPE_COMPONENTSOF:
397 case BASICTYPE_ANYDEFINEDBY:
398 case BASICTYPE_LOCALTYPEREF:
399 case BASICTYPE_IMPORTTYPEREF:
400 break;
401
402 /*
403 * these types may optionally have named elmts
404 */
405 case BASICTYPE_INTEGER:
406 case BASICTYPE_BITSTRING:
407 case BASICTYPE_ENUMERATED:
408 ValueLinkNamedElmts (m, currMod, head, type, bt->a.integer);
409 break;
410
411
412
413 /*
414 * these types have no extra info and cause no linking action
415 */
416 case BASICTYPE_UNKNOWN:
417 case BASICTYPE_BOOLEAN:
418 case BASICTYPE_OCTETSTRING:
419 case BASICTYPE_NULL:
420 case BASICTYPE_OID:
421 case BASICTYPE_REAL:
422 case BASICTYPE_ANY:
423 case BASICTYPE_MACRODEF:
424 /*
425 * these have no more info - only the choiceId is used
426 */
427 break;
428
429 case BASICTYPE_MACROTYPE:
430 switch (bt->a.macroType->choiceId)
431 {
432 case MACROTYPE_ROSOPERATION:
433 case MACROTYPE_ASNABSTRACTOPERATION:
434
435 ValueLinkRosOperationMacroType (m, currMod, head, type, bt, bt->a.macroType->a.rosOperation);
436 break;
437
438 case MACROTYPE_ROSERROR:
439 case MACROTYPE_ASNABSTRACTERROR:
440 ValueLinkRosErrorMacroType (m, currMod, head, type, bt, bt->a.macroType->a.rosError);
441 break;
442
443 case MACROTYPE_ROSBIND:
444 case MACROTYPE_ROSUNBIND:
445 ValueLinkRosBindMacroType (m, currMod, head, type, bt, bt->a.macroType->a.rosBind);
446 break;
447
448 case MACROTYPE_ROSASE:
449 ValueLinkRosAseMacroType (m, currMod, head, type, bt, bt->a.macroType->a.rosAse);
450 break;
451
452 case MACROTYPE_MTSASEXTENSIONS:
453 ValueLinkMtsasExtensionsMacroType (m, currMod, head, type, bt, bt->a.macroType->a.mtsasExtensions);
454 break;
455
456 case MACROTYPE_MTSASEXTENSION:
457 ValueLinkMtsasExtensionMacroType (m, currMod, head, type, bt, bt->a.macroType->a.mtsasExtension);
458 break;
459
460 case MACROTYPE_MTSASEXTENSIONATTRIBUTE:
461 ValueLinkMtsasExtensionAttributeMacroType (m, currMod, head, type, bt, bt->a.macroType->a.mtsasExtensionAttribute);
462 break;
463
464 case MACROTYPE_MTSASTOKEN:
465 ValueLinkMtsasTokenMacroType (m, currMod, head, type, bt, bt->a.macroType->a.mtsasToken);
466 break;
467
468 case MACROTYPE_MTSASTOKENDATA:
469 ValueLinkMtsasTokenDataMacroType (m, currMod, head, type, bt, bt->a.macroType->a.mtsasTokenData);
470 break;
471
472 case MACROTYPE_MTSASSECURITYCATEGORY:
473 ValueLinkMtsasSecurityCategoryMacroType (m, currMod, head, type, bt, bt->a.macroType->a.mtsasSecurityCategory);
474 break;
475
476 case MACROTYPE_ASNOBJECT:
477 ValueLinkAsnObjectMacroType (m, currMod, head, type, bt, bt->a.macroType->a.asnObject);
478 break;
479
480 case MACROTYPE_ASNPORT:
481 ValueLinkAsnPortMacroType (m, currMod, head, type, bt, bt->a.macroType->a.asnPort);
482 break;
483
484 case MACROTYPE_ASNABSTRACTBIND:
485 case MACROTYPE_ASNABSTRACTUNBIND:
486 ValueLinkAsnAbstractBindMacroType (m, currMod, head, type, bt, bt->a.macroType->a.asnAbstractBind);
487 break;
488
489 case MACROTYPE_AFALGORITHM:
490 case MACROTYPE_AFENCRYPTED:
491 case MACROTYPE_AFPROTECTED:
492 case MACROTYPE_AFSIGNATURE:
493 case MACROTYPE_AFSIGNED:
494 ValueLinkType (m, currMod, head, bt->a.macroType->a.afAlgorithm);
495 break;
496
497 case MACROTYPE_SNMPOBJECTTYPE:
498 ValueLinkSnmpObjectTypeMacroType (m, currMod, head, type, bt, bt->a.macroType->a.snmpObjectType);
499 break;
500
501 default:
502 fprintf (stderr, "ValueLinkBasicType: ERROR - unknown macro type id!\n");
503 break;
504 }
505 break;
506
507 default:
508 fprintf (stderr, "ValueLinkBasicType: ERROR - unknown basic type id!\n");
509
510 }
511 } /* ValueLinkBasicType */
512
513
514
515
516 /*
517 * resolve any type/value refs in the subtypes (if any)
518 */
519 void
520 ValueLinkSubtypes PARAMS ((m, currMod, head, currType, s),
521 ModuleList *m _AND_
522 Module *currMod _AND_
523 TypeDef *head _AND_
524 Type *currType _AND_
525 Subtype *s)
526 {
527 Subtype *sElmt;
528
529 if (s == NULL)
530 return;
531
532 switch (s->choiceId)
533 {
534 case SUBTYPE_SINGLE:
535 ValueLinkSubtypeValue (m, currMod, head, currType, s->a.single);
536 break;
537
538 case SUBTYPE_AND:
539 case SUBTYPE_OR:
540 case SUBTYPE_NOT:
541 FOR_EACH_LIST_ELMT (sElmt, s->a.and)
542 {
543 ValueLinkSubtypes (m, currMod, head, currType, sElmt);
544 }
545 break;
546
547 default:
548 fprintf (stderr, "ValueLinkSubtypes: ERROR - unknown Subtype id\n");
549 break;
550 }
551 } /* ValueLinkSubtypes */
552
553
554
555
556
557 void
558 ValueLinkSubtypeValue PARAMS ((m, currMod, head, currType, s),
559 ModuleList *m _AND_
560 Module *currMod _AND_
561 TypeDef *head _AND_
562 Type *currType _AND_
563 SubtypeValue *s)
564 {
565 Constraint *constraint;
566
567 if (s == NULL)
568 return;
569
570 switch (s->choiceId)
571 {
572 case SUBTYPEVALUE_SINGLEVALUE:
573 ValueLinkValue (m, currMod, NULL, currType, s->a.singleValue);
574 break;
575
576 case SUBTYPEVALUE_CONTAINED:
577 ValueLinkType (m, currMod, head, s->a.contained);
578 break;
579
580 case SUBTYPEVALUE_VALUERANGE:
581 ValueLinkValue (m, currMod, NULL, currType, s->a.valueRange->lowerEndValue);
582 ValueLinkValue (m, currMod, NULL, currType, s->a.valueRange->upperEndValue);
583 break;
584
585 case SUBTYPEVALUE_PERMITTEDALPHABET:
586 ValueLinkSubtypes (m, currMod, head, currType, s->a.permittedAlphabet);
587 break;
588
589 case SUBTYPEVALUE_SIZECONSTRAINT:
590 ValueLinkSubtypes (m, currMod, head, currType, s->a.sizeConstraint);
591 break;
592
593 case SUBTYPEVALUE_INNERSUBTYPE:
594 FOR_EACH_LIST_ELMT (constraint, s->a.innerSubtype->constraints)
595 {
596 ValueLinkSubtypes (m, currMod, head, currType, constraint->valueConstraints);
597 }
598 break;
599
600 default:
601 fprintf (stderr,"ValueLinkSubtype: ERROR - unknown subtype choiceId\n");
602 }
603
604 } /* ValueLinkSubtype */
605
606
607
608
609 void
610 ValueLinkNamedElmts PARAMS ((m, currMod, head, t, v),
611 ModuleList *m _AND_
612 Module *currMod _AND_
613 TypeDef *head _AND_
614 Type *t _AND_
615 ValueDefList *v)
616 {
617 ValueDef *vd;
618 FOR_EACH_LIST_ELMT (vd, v)
619 {
620 ValueLinkValue (m, currMod, vd, vd->value->type, vd->value);
621 }
622
623 } /* ValueLinkNamedElmts */
624
625
626
627
628 void
629 ValueLinkValueDef PARAMS ((m, currMod, v),
630 ModuleList *m _AND_
631 Module *currMod _AND_
632 ValueDef *v)
633 {
634 if (v == NULL)
635 return;
636
637 ValueLinkType (m, currMod, NULL, v->value->type);
638 ValueLinkValue (m, currMod, v, v->value->type, v->value);
639
640 } /* ValueLinkValueDef */
641
642
643
644
645 void
646 ValueLinkValue PARAMS ((m, currMod, head, valuesType, v),
647 ModuleList *m _AND_
648 Module *currMod _AND_
649 ValueDef *head _AND_
650 Type *valuesType _AND_
651 Value *v)
652 {
653
654 if (v == NULL)
655 return;
656
657 ValueLinkBasicValue (m, currMod, head, valuesType, v, v->basicValue);
658
659 } /* ValueLinkValue */
660
661
662
663 void
664 ValueLinkBasicValue PARAMS ((m, currMod, head, valuesType, v, bv),
665 ModuleList *m _AND_
666 Module *currMod _AND_
667 ValueDef *head _AND_
668 Type *valuesType _AND_
669 Value *v _AND_
670 BasicValue *bv)
671 {
672 ValueDef *tmpValueDef;
673 Module *tmpMod;
674 ImportElmt *impElmt;
675 ImportModule *impMod;
676 ValueDef *n;
677 ValueDefList *namedElmtList;
678
679
680 if (v == NULL)
681 return;
682
683
684 switch (bv->choiceId)
685 {
686 case BASICVALUE_UNKNOWN:
687 case BASICVALUE_EMPTY:
688 case BASICVALUE_INTEGER:
689 case BASICVALUE_SPECIALINTEGER:
690 case BASICVALUE_BOOLEAN:
691 case BASICVALUE_REAL:
692 case BASICVALUE_SPECIALREAL:
693 case BASICVALUE_ASCIITEXT:
694 case BASICVALUE_ASCIIHEX:
695 case BASICVALUE_ASCIIBITSTRING:
696 case BASICVALUE_BERVALUE:
697 case BASICVALUE_PERVALUE:
698 case BASICVALUE_NAMEDVALUE:
699 case BASICVALUE_NULL:
700 case BASICVALUE_VALUENOTATION:
701 case BASICVALUE_OID:
702 break;
703
704
705 case BASICVALUE_LOCALVALUEREF:
706
707 /*
708 * parser sets all value refs to "Local" so must
709 * check if local, then if import ....
710 */
711
712 /*
713 * first check in named elmts of the given type
714 */
715 namedElmtList = GetAllNamedElmts (valuesType);
716 if (namedElmtList != NULL)
717 {
718 n = LookupValue (namedElmtList, bv->a.localValueRef->valueName);
719
720 if (n != NULL)
721 {
722 bv->a.localValueRef->link = n;
723 bv->a.localValueRef->module = currMod;
724
725 /* now free list structure (not data elmts) */
726 AsnListFree (namedElmtList);
727
728 break; /* exit switch since done here. */
729 }
730 }
731
732 /*
733 * second, look for values defined in this module
734 */
735 tmpValueDef = LookupValue (currMod->valueDefs, bv->a.localValueRef->valueName);
736
737 if (tmpValueDef != NULL)
738 {
739 bv->a.localValueRef->link = tmpValueDef;
740 break; /* exit switch since done here. */
741 }
742
743 else
744 bv->choiceId = BASICVALUE_IMPORTVALUEREF;
745 /*!!!!!!!!!! fall through from else clause */
746
747
748 case BASICVALUE_IMPORTVALUEREF:
749 /* This handles "modname.value" value refs. */
750 if (bv->a.importValueRef->moduleName != NULL)
751 {
752 /*
753 * Lookup the import list maintained in this module
754 * from the named module. (the parser generates
755 * an import list from Foo module for "Foo.Bar" style
756 * import refs)
757 */
758 impMod = LookupImportModule (currMod, bv->a.importValueRef->moduleName);
759
760 if (impMod == NULL) /* whoa, compiler error */
761 {
762 currMod->status = MOD_ERROR;
763 fprintf (stderr,"Compiler Error: \"%s.%s\" valueref - no import list defined from module \"%s\".\n", bv->a.importValueRef->moduleName, bv->a.importValueRef->valueName, bv->a.importValueRef->moduleName);
764
765 return;
766 }
767 impElmt = LookupImportElmtInImportElmtList (impMod->importElmts, bv->a.importValueRef->valueName);
768
769 if (impElmt == NULL) /* whoa, compiler error again */
770 {
771 currMod->status = MOD_ERROR;
772 fprintf (stderr,"Compiler Error: \"%s.%s\" valueref - no import element defined for value \"%s\".\n", bv->a.importValueRef->moduleName, bv->a.importValueRef->valueName, bv->a.importValueRef->valueName);
773
774
775 }
776 else if (impElmt->resolvedRef != NULL)
777 {
778 if (impElmt->resolvedRef->choiceId !=
779 IMPORTELMTCHOICE_VALUE)
780 fprintf (stderr,"Linker Warning: import VALUE ref \"%s\" resolves with an imported TYPE\n", impElmt->name);
781
782 bv->a.importValueRef->link = impElmt->resolvedRef->a.value;
783 bv->a.importValueRef->module = impMod->moduleRef;
784 }
785 else
786 {
787 PrintErrLoc (currMod->asn1SrcFileName, v->lineNo);
788 fprintf (stderr,"reference to unresolved imported value \"%s\"\n", impElmt->name);
789 }
790 }
791 else
792 {
793 impElmt = LookupImportElmtInModule (currMod, bv->a.importValueRef->valueName, &impMod);
794 if ((impElmt != NULL) && (!impElmt->privateScope))
795 {
796 /*
797 * if import elmt is resolved then
798 * set up link
799 */
800
801 if (impElmt->resolvedRef != NULL)
802 {
803 if (impElmt->resolvedRef->choiceId !=
804 IMPORTELMTCHOICE_VALUE)
805 fprintf (stderr,"Linker Warning: import VALUE ref \"%s\" resolves with an imported TYPE\n", impElmt->name);
806
807 bv->a.importValueRef->link = impElmt->resolvedRef->a.value;
808 bv->a.importValueRef->module = impMod->moduleRef;
809 }
810 else
811 {
812 PrintErrLoc (currMod->asn1SrcFileName, v->lineNo);
813 fprintf (stderr,"reference to unresolved imported value \"%s\"\n", impElmt->name);
814 }
815 }
816
817 /*
818 * third, look for values defined in the useful module
819 */
820 else if ((usefulTypeModG != NULL) &&
821 ((tmpValueDef = LookupValue (usefulTypeModG->valueDefs, bv->a.localValueRef->valueName)) != NULL))
822 {
823 bv->a.localValueRef->link = tmpValueDef;
824 bv->a.localValueRef->module = usefulTypeModG;
825 }
826 else
827 {
828 /*
829 * value not defined locally, nor imported nor
830 * defined in useful types module
831 */
832 currMod->status = MOD_ERROR;
833 PrintErrLoc (currMod->asn1SrcFileName, v->lineNo);
834 fprintf (stderr,"ERROR - value \"%s\" is referenced but not defined or imported.\n", bv->a.importValueRef->valueName);
835 }
836 }
837 break;
838
839 case BASICVALUE_LINKEDOID:
840 ValueLinkOid (m, currMod, head, v, bv->a.linkedOid);
841 break;
842
843 default:
844 fprintf (stderr,"ValueLinkBasicValue: ERROR - unknown value type\n");
845 }
846
847 } /* ValueLinkBasicValue */
848
849
850 /*
851 * link the value refs from an object identifier
852 *
853 *
854 * eg
855 * for { ccitt foo (1) bar bell (bunt) 2 } the format is
856 *
857 * ccitt
858 * arcnum is set to number from oid table (oid.c)
859 * foo (1)
860 * - arc num is set to 1
861 * - sets up a new value def foo defined as 1
862 * - makes oid valueref a value ref to foo (doesn't link it tho)
863 * bar
864 * - makes oid valueref a value ref to bar (doesn't link it tho)
865 * bell (bunt)
866 * - sets up a new value def bell defined as a val ref to bunt
867 * - makes oid valueref a value ref to bell (doesn't link it tho)
868 * 2
869 * -arc num is set to 2
870 *
871 */
872 void
873 ValueLinkOid PARAMS ((m, currMod, head, v, oid),
874 ModuleList *m _AND_
875 Module *currMod _AND_
876 ValueDef *head _AND_
877 Value *v _AND_
878 OID *oid)
879 {
880 ValueDef *tmpValueDef;
881 ImportElmt *impElmt;
882 ImportModule *impMod;
883 int lineNo;
884 OID *firstElmt;
885 Value *val;
886
887 /*
888 * WARNING: for cyclic oid value definintions like.
889 * foo OID ::= { bar 1 3 }
890 * bar OID ::= { foo 1 3 }
891 * infinite recursion is prevented by
892 * a hack (linkOidCallDepth)
893 */
894 if (linkOidCallDepthG > 100)
895 {
896 currMod->status = MOD_ERROR;
897 PrintErrLoc (currMod->asn1SrcFileName, v->lineNo);
898 fprintf (stderr,"ERROR - OBJECT IDENTIFIER value \"%s\" appears to be defined recursively\n", head->definedName);
899 linkOidCallDepthG = 0;
900 return;
901 }
902 else
903 linkOidCallDepthG++;
904
905 for (firstElmt = oid; oid != NULL; oid = oid->next)
906 {
907 if (oid->valueRef != NULL)
908 {
909 ValueLinkValue (m, currMod, head, NULL, oid->valueRef);
910
911 if ((oid->valueRef->basicValue->choiceId !=
912 BASICVALUE_LOCALVALUEREF) &&
913 (oid->valueRef->basicValue->choiceId !=
914 BASICVALUE_IMPORTVALUEREF))
915 {
916 fprintf (stderr,"Internal error: Oid valueref is not a ref\n");
917 break; /* exit for */
918 }
919
920 /*
921 * leave simplification (replacement of value refs with values)
922 * of oid values to normalize.c
923 */
924 }
925 }
926
927 linkOidCallDepthG--;
928
929 } /* ValueLinkOid */
930
931
932 void
933 ValueLinkRosOperationMacroType PARAMS ((m, currMod, head, t, bt, op),
934 ModuleList *m _AND_
935 Module *currMod _AND_
936 TypeDef *head _AND_
937 Type *t _AND_
938 BasicType *bt _AND_
939 RosOperationMacroType *op)
940 {
941 TypeOrValue *tOrV;
942
943 if (op->arguments != NULL)
944 ValueLinkType (m, currMod, head, op->arguments->type);
945
946 if (op->result != NULL)
947 ValueLinkType (m, currMod, head, op->result->type);
948
949 /*
950 * go through errors (if any) and link types/values
951 */
952 FOR_EACH_LIST_ELMT (tOrV, op->errors)
953 {
954 if (tOrV->choiceId == TYPEORVALUE_TYPE)
955 ValueLinkType (m, currMod, head, tOrV->a.type);
956 else
957 ValueLinkValue (m, currMod, NULL, t, tOrV->a.value);
958 }
959
960 /*
961 * go through linked operations (if any) and
962 * link types/values
963 */
964 FOR_EACH_LIST_ELMT (tOrV, op->linkedOps)
965 {
966 if (tOrV->choiceId == TYPEORVALUE_TYPE)
967 ValueLinkType (m, currMod, head, tOrV->a.type);
968 else
969 ValueLinkValue (m, currMod, NULL, t, tOrV->a.value);
970 }
971 } /* ValueLinkRosOperationMacroType */
972
973
974 void
975 ValueLinkRosErrorMacroType PARAMS ((m, currMod, head, t, bt, err),
976 ModuleList *m _AND_
977 Module *currMod _AND_
978 TypeDef *head _AND_
979 Type *t _AND_
980 BasicType *bt _AND_
981 RosErrorMacroType *err)
982 {
983 if ((err != NULL) && (err->parameter != NULL))
984 {
985 ValueLinkType (m, currMod, head, err->parameter->type);
986 }
987 } /* ValueLinkRosErrorMacroType */
988
989
990 void
991 ValueLinkRosBindMacroType PARAMS ((m, currMod, head, t, bt, bind),
992 ModuleList *m _AND_
993 Module *currMod _AND_
994 TypeDef *head _AND_
995 Type *t _AND_
996 BasicType *bt _AND_
997 RosBindMacroType *bind)
998 {
999 if (bind != NULL)
1000 {
1001 ValueLinkElmtType (m, currMod, head, bind->argument);
1002 ValueLinkElmtType (m, currMod, head, bind->result);
1003 ValueLinkElmtType (m, currMod, head, bind->error);
1004 }
1005 } /* ValueLinkRosBindMacroType */
1006
1007
1008 void
1009 ValueLinkRosAseMacroType PARAMS ((m, currMod, head, t, bt, ase),
1010 ModuleList *m _AND_
1011 Module *currMod _AND_
1012 TypeDef *head _AND_
1013 Type *t _AND_
1014 BasicType *bt _AND_
1015 RosAseMacroType *ase)
1016 {
1017 Value *v;
1018
1019 FOR_EACH_LIST_ELMT (v, ase->operations)
1020 ValueLinkValue (m, currMod, NULL, t, v);
1021
1022
1023 FOR_EACH_LIST_ELMT (v, ase->consumerInvokes)
1024 ValueLinkValue (m, currMod, NULL, t, v);
1025
1026
1027 FOR_EACH_LIST_ELMT (v, ase->supplierInvokes)
1028 ValueLinkValue (m, currMod, NULL, t, v);
1029
1030 } /* ValueLinkRosAseMacroType */
1031
1032
1033
1034 void
1035 ValueLinkRosAcMacroType PARAMS ((m, currMod, head, t, bt, ac),
1036 ModuleList *m _AND_
1037 Module *currMod _AND_
1038 TypeDef *head _AND_
1039 Type *t _AND_
1040 BasicType *bt _AND_
1041 RosAcMacroType *ac)
1042 {
1043 Value *v;
1044 OID *oid;
1045
1046 FOR_EACH_LIST_ELMT (v, ac->nonRoElements)
1047 ValueLinkValue (m, currMod, NULL, t, v);
1048
1049
1050 ValueLinkType (m, currMod, head, ac->bindMacroType);
1051 ValueLinkType (m, currMod, head, ac->unbindMacroType);
1052
1053 FOR_EACH_LIST_ELMT (v, ac->operationsOf)
1054 ValueLinkValue (m, currMod, NULL, t, v);
1055
1056
1057 FOR_EACH_LIST_ELMT (v, ac->initiatorConsumerOf)
1058 ValueLinkValue (m, currMod, NULL, t, v);
1059
1060
1061 FOR_EACH_LIST_ELMT (v, ac->responderConsumerOf)
1062 ValueLinkValue (m, currMod, NULL, t, v);
1063
1064
1065 FOR_EACH_LIST_ELMT (oid, ac->abstractSyntaxes)
1066 ValueLinkOid (m, currMod, NULL, NULL, oid);
1067
1068 } /* ValueLinkRosAcMacroType */
1069
1070
1071
1072 void
1073 ValueLinkMtsasExtensionsMacroType PARAMS ((m, currMod, head, t, bt, exts),
1074 ModuleList *m _AND_
1075 Module *currMod _AND_
1076 TypeDef *head _AND_
1077 Type *t _AND_
1078 BasicType *bt _AND_
1079 MtsasExtensionsMacroType *exts)
1080 {
1081 Value *v;
1082
1083 FOR_EACH_LIST_ELMT (v, exts->extensions)
1084 ValueLinkValue (m, currMod, NULL, t, v);
1085
1086 } /* ValueLinkMtsasExtensionsMacroType */
1087
1088
1089 void
1090 ValueLinkMtsasExtensionMacroType PARAMS ((m, currMod, head, t, bt, ext),
1091 ModuleList *m _AND_
1092 Module *currMod _AND_
1093 TypeDef *head _AND_
1094 Type *t _AND_
1095 BasicType *bt _AND_
1096 MtsasExtensionMacroType *ext)
1097 {
1098 ValueLinkElmtType (m, currMod, head, ext->elmtType);
1099 ValueLinkValue (m, currMod, NULL, t, ext->defaultValue);
1100
1101 } /* ValueLinkMtsasExtensionMacroType */
1102
1103
1104 void
1105 ValueLinkMtsasExtensionAttributeMacroType PARAMS ((m, currMod, head, t,bt, ext),
1106 ModuleList *m _AND_
1107 Module *currMod _AND_
1108 TypeDef *head _AND_
1109 Type *t _AND_
1110 BasicType *bt _AND_
1111 MtsasExtensionAttributeMacroType *ext)
1112 {
1113
1114 if (ext != NULL)
1115 ValueLinkType (m, currMod, head, ext->type);
1116
1117 } /* ValueLinkMtsasExtensionAttributeMacroType */
1118
1119
1120 void
1121 ValueLinkMtsasTokenMacroType PARAMS ((m, currMod, head, t, bt, tok),
1122 ModuleList *m _AND_
1123 Module *currMod _AND_
1124 TypeDef *head _AND_
1125 Type *t _AND_
1126 BasicType *bt _AND_
1127 MtsasTokenMacroType *tok)
1128 {
1129 if (tok != NULL)
1130 ValueLinkType (m, currMod, head, tok->type);
1131
1132 } /* ValueLinkMtsasTokenMacroType */
1133
1134
1135 void
1136 ValueLinkMtsasTokenDataMacroType PARAMS ((m, currMod, head, t, bt, tok),
1137 ModuleList *m _AND_
1138 Module *currMod _AND_
1139 TypeDef *head _AND_
1140 Type *t _AND_
1141 BasicType *bt _AND_
1142 MtsasTokenDataMacroType *tok)
1143 {
1144 if (tok != NULL)
1145 ValueLinkType (m, currMod, head, tok->type);
1146
1147 } /* ValueLinkMtsasTokenDataMacroType */
1148
1149 void
1150 ValueLinkMtsasSecurityCategoryMacroType PARAMS ((m, currMod, head, t, bt, sec),
1151 ModuleList *m _AND_
1152 Module *currMod _AND_
1153 TypeDef *head _AND_
1154 Type *t _AND_
1155 BasicType *bt _AND_
1156 MtsasSecurityCategoryMacroType *sec)
1157 {
1158
1159 if (sec != NULL)
1160 ValueLinkType (m, currMod, head, sec->type);
1161
1162 } /* ValueLinkMtsasSecurityCategoryMacroType */
1163
1164
1165
1166 void
1167 ValueLinkAsnObjectMacroType PARAMS ((m, currMod, head, t, bt, obj),
1168 ModuleList *m _AND_
1169 Module *currMod _AND_
1170 TypeDef *head _AND_
1171 Type *t _AND_
1172 BasicType *bt _AND_
1173 AsnObjectMacroType *obj)
1174 {
1175 AsnPort *ap;
1176
1177 FOR_EACH_LIST_ELMT (ap, obj->ports)
1178 ValueLinkValue (m, currMod, NULL, t, ap->portValue);
1179
1180 } /* ValueLinkAsnObjectMacroType */
1181
1182
1183 void
1184 ValueLinkAsnPortMacroType PARAMS ((m, currMod, head, t, bt, p),
1185 ModuleList *m _AND_
1186 Module *currMod _AND_
1187 TypeDef *head _AND_
1188 Type *t _AND_
1189 BasicType *bt _AND_
1190 AsnPortMacroType *p)
1191 {
1192 TypeOrValue *tOrV;
1193
1194 FOR_EACH_LIST_ELMT (tOrV, p->abstractOps)
1195 {
1196 if (tOrV->choiceId == TYPEORVALUE_TYPE)
1197 ValueLinkType (m, currMod, head, tOrV->a.type);
1198 else
1199 ValueLinkValue (m, currMod, NULL, t, tOrV->a.value);
1200 }
1201
1202
1203 FOR_EACH_LIST_ELMT (tOrV, p->supplierInvokes)
1204 {
1205 if (tOrV->choiceId == TYPEORVALUE_TYPE)
1206 ValueLinkType (m, currMod, head, tOrV->a.type);
1207 else
1208 ValueLinkValue (m, currMod, NULL, t, tOrV->a.value);
1209 }
1210
1211
1212 FOR_EACH_LIST_ELMT (tOrV, p->consumerInvokes)
1213 {
1214 if (tOrV->choiceId == TYPEORVALUE_TYPE)
1215 ValueLinkType (m, currMod, head, tOrV->a.type);
1216 else
1217 ValueLinkValue (m, currMod, NULL, t, tOrV->a.value);
1218 }
1219
1220 } /* ValueLinkAsnPortMacroType */
1221
1222
1223
1224 void
1225 ValueLinkAsnAbstractBindMacroType PARAMS ((m, currMod, head, t, bt, bind),
1226 ModuleList *m _AND_
1227 Module *currMod _AND_
1228 TypeDef *head _AND_
1229 Type *t _AND_
1230 BasicType *bt _AND_
1231 AsnAbstractBindMacroType *bind)
1232 {
1233 AsnPort *ap;
1234
1235 FOR_EACH_LIST_ELMT (ap, bind->ports)
1236 ValueLinkValue (m, currMod, NULL, t, ap->portValue);
1237
1238 } /* ValueLinkAsnBindMacroType */
1239
1240
1241
1242 void
1243 ValueLinkSnmpObjectTypeMacroType PARAMS ((m, currMod, head, t, bt, ot),
1244 ModuleList *m _AND_
1245 Module *currMod _AND_
1246 TypeDef *head _AND_
1247 Type *t _AND_
1248 BasicType *bt _AND_
1249 SnmpObjectTypeMacroType *ot)
1250 {
1251 TypeOrValue *tOrV;
1252
1253 ValueLinkType (m, currMod, head, ot->syntax);
1254 ValueLinkValue (m, currMod, NULL, t, ot->description);
1255 ValueLinkValue (m, currMod, NULL, t, ot->reference);
1256 ValueLinkValue (m, currMod, NULL, t, ot->defVal);
1257
1258 FOR_EACH_LIST_ELMT (tOrV, ot->index)
1259 {
1260 if (tOrV->choiceId == TYPEORVALUE_TYPE)
1261 ValueLinkType (m, currMod, head, tOrV->a.type);
1262 else
1263 ValueLinkValue (m, currMod, NULL, t, tOrV->a.value);
1264 }
1265
1266 } /* ValueLinkSnmpObjectTypeMacroType */