2 * compiler/core/do_macros.c
4 * Runs through type and value def lists and does any processing nec.
5 * for any macro encountered.
7 * Processing could consist of making stubs for OPERATION macro etc.
8 * What is done is very environment dependent.
10 * You should change this file to match your environment.
12 * Any Type Defs hidden in a MACRO Type are popped into the normal
13 * type def list and REFERENCED from the macro (instead of being
16 * SNMP Objectype macro fills the ANY Ref lists so the id to ANY
17 * type hash table is filled.
22 * Copyright (C) 1991, 1992 Michael Sample
23 * and the University of British Columbia
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
30 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/compiler/core/do-macros.c,v 1.1 2001/06/20 21:27:56 dmitch Exp $
31 * $Log: do-macros.c,v $
32 * Revision 1.1 2001/06/20 21:27:56 dmitch
33 * Adding missing snacc compiler files.
35 * Revision 1.1.1.1 1999/03/16 18:06:47 aram
36 * Originals from SMIME Free Library.
38 * Revision 1.3 1995/07/25 19:41:23 rj
39 * changed `_' to `-' in file names.
41 * Revision 1.2 1994/09/01 00:32:28 rj
42 * snacc_config.h removed; do_macros.h includet.
44 * Revision 1.1 1994/08/28 09:49:03 rj
45 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
50 #include <ctype.h> /* for islower/toupper */
54 #include "asn1module.h"
57 #include "normalize.h"
58 #include "snacc-util.h"
59 #include "do-macros.h"
61 void AddAnyRefByOid
PROTO ((AnyRefList
**arl
, char *enumIdName
, AsnOid
*oid
));
63 void AddAnyRefByInt
PROTO ((AnyRefList
**arl
, char *enumIdName
, AsnInt intId
));
66 void ProcessMacrosInTypeDef
PROTO ((Module
*m
, TypeDef
*td
));
68 void ProcessMacrosInValueDef
PROTO ((Module
*m
, ValueDef
*vd
));
70 void ProcessMacrosInType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, ValueDef
*v
));
72 void ProcessMacrosInElmtTypes
PROTO ((Module
*m
, TypeDef
*td
, NamedTypeList
*e
, ValueDef
*v
));
74 void ProcessMacrosInBasicType
PROTO ((Module
*m
, TypeDef
*td
, Type
*type
, BasicType
*bt
, ValueDef
*v
));
76 void DefineType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, char *name
));
78 void ProcessRosOperationMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, RosOperationMacroType
*op
, ValueDef
*v
));
80 void ProcessRosErrorMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, RosErrorMacroType
*err
, ValueDef
*v
));
82 void ProcessRosBindMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, RosBindMacroType
*bind
, ValueDef
*v
));
84 void ProcessRosAseMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, RosAseMacroType
*ase
, ValueDef
*v
));
86 void ProcessRosAcMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, RosAcMacroType
*ac
, ValueDef
*v
));
88 void ProcessMtsasExtensionsMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, MtsasExtensionsMacroType
*exts
, ValueDef
*v
));
90 void ProcessMtsasExtensionMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, MtsasExtensionMacroType
*ext
, ValueDef
*v
));
92 void ProcessMtsasExtensionAttributeMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, MtsasExtensionAttributeMacroType
*ext
, ValueDef
*v
));
94 void ProcessMtsasTokenMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, MtsasTokenMacroType
*tok
, ValueDef
*v
));
96 void ProcessMtsasTokenDataMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, MtsasTokenDataMacroType
*tok
, ValueDef
*v
));
98 void ProcessMtsasSecurityCategoryMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, MtsasSecurityCategoryMacroType
*sec
, ValueDef
*v
));
100 void ProcessAsnObjectMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, AsnObjectMacroType
*obj
, ValueDef
*v
));
102 void ProcessAsnPortMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, AsnPortMacroType
*p
, ValueDef
*v
));
104 void ProcessAsnAbstractBindMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, AsnAbstractBindMacroType
*bind
, ValueDef
*v
));
106 void ProcessSnmpObjectTypeMacroType
PROTO ((Module
*m
, TypeDef
*td
, Type
*t
, BasicType
*bt
, SnmpObjectTypeMacroType
*bind
, ValueDef
*v
));
109 static TypeDef *snmpObjectSyntaxesG = NULL;
113 * Hunts for macros in TypeDefs or ValueDefs and
114 * might do something with them.
117 ProcessMacros
PARAMS ((m
),
121 TypeDef
**tmpTypeDefHndl
;
125 * go through each type in typeList
127 FOR_EACH_LIST_ELMT (td
, m
->typeDefs
)
129 ProcessMacrosInTypeDef (m
, td
);
133 * go through each value in valueList and link
135 FOR_EACH_LIST_ELMT (vd
, m
->valueDefs
)
137 ProcessMacrosInValueDef (m
, vd
);
140 /* add snmp object syntaxes choice to typedef list */
142 tmpTypeDefHndl = (TypeDef**) AsnListAppend (m->typeDefs);
143 *tmpTypeDefHndl = snmpObjectSyntaxesG;
144 snmpObjectSyntaxesG = NULL;
148 } /* ProcessMacros */
151 * Given an AnyRefList, char string for an enum Id,
152 * and an OBJECT IDENTIFIER,
153 * this routine puts the id and oid into the AnyRefList.
154 * When the code is generated, the AnyInit routine for
155 * the module to which the typeDef that owns the given AnyRefList
156 * belongs, calls a routine that will cause the given oid to
157 * hash to the TypeDef that owns the AnyRefList.
158 * The enumId value at runtime is used for simple determination of
159 * the ANY type by the user.
162 AddAnyRefByOid
PARAMS ((arl
, enumId
, oid
),
163 AnyRefList
**arl _AND_
170 *arl
= AsnListNew (sizeof (void*));
172 anyRefHndl
= (AnyRef
**)AsnListAppend (*arl
);
173 *anyRefHndl
= MT (AnyRef
);
175 (*anyRefHndl
)->anyIdName
= Malloc (strlen (enumId
)+1);
176 strcpy ((*anyRefHndl
)->anyIdName
, enumId
);
178 (*anyRefHndl
)->id
= MT (OidOrInt
);
179 (*anyRefHndl
)->id
->choiceId
= OIDORINT_OID
;
180 (*anyRefHndl
)->id
->a
.oid
= MT (AsnOid
);
181 (*anyRefHndl
)->id
->a
.oid
->octs
= Malloc (oid
->octetLen
);
182 memcpy ((*anyRefHndl
)->id
->a
.oid
->octs
, oid
->octs
, oid
->octetLen
);
183 (*anyRefHndl
)->id
->a
.oid
->octetLen
= oid
->octetLen
;
185 } /* AddAnyRefByOid */
188 * Like AddAnyRefByOid except that an int maps to the type def
189 * instead of an OBJECT IDENTIFIER
192 AddAnyRefByInt
PARAMS ((arl
, enumId
, intId
),
193 AnyRefList
**arl _AND_
200 *arl
= AsnListNew (sizeof (void*));
202 anyRefHndl
= (AnyRef
**)AsnListAppend (*arl
);
203 *anyRefHndl
= MT (AnyRef
);
205 (*anyRefHndl
)->anyIdName
= Malloc (strlen (enumId
)+1);
206 strcpy ((*anyRefHndl
)->anyIdName
, enumId
);
207 (*anyRefHndl
)->id
= MT (OidOrInt
);
208 (*anyRefHndl
)->id
->choiceId
= OIDORINT_INTID
;
209 (*anyRefHndl
)->id
->a
.intId
= intId
;
211 } /* AddAnyRefByInt */
215 ProcessMacrosInValueDef
PARAMS ((m
, vd
),
222 /* turn linked oid's into encoded oids */
223 if (vd
->value
->basicValue
->choiceId
== BASICVALUE_LINKEDOID
)
224 NormalizeValue (m
, vd
, vd
->value
, FALSE
);
226 ProcessMacrosInType (m
, NULL
, vd
->value
->type
, vd
);
228 } /* ProcessMacrosInValueDef */
233 ProcessMacrosInTypeDef
PARAMS ((m
,td
),
240 ProcessMacrosInType (m
, td
, td
->type
, NULL
);
242 } /* ProcessMacrosInTypeDef */
247 ProcessMacrosInType
PARAMS ((m
, td
,t
, v
),
256 ProcessMacrosInBasicType (m
, td
, t
, t
->basicType
, v
);
258 } /* ProcessMacrosInTypeDef */
263 ProcessMacrosInElmtTypes
PARAMS ((m
, td
, e
, v
),
266 NamedTypeList
*e _AND_
270 FOR_EACH_LIST_ELMT (nt
, e
)
272 ProcessMacrosInType (m
, td
, nt
->type
, v
);
274 } /* ProcessElmtTypes */
279 ProcessMacrosInBasicType
PARAMS ((m
,td
,type
,bt
, v
),
290 switch (bt
->choiceId
)
293 case BASICTYPE_SEQUENCE
:
295 case BASICTYPE_CHOICE
:
296 ProcessMacrosInElmtTypes (m
, td
, bt
->a
.set
,v
);
301 case BASICTYPE_SEQUENCEOF
:
302 case BASICTYPE_SETOF
:
303 ProcessMacrosInType (m
, td
, bt
->a
.setOf
, v
);
308 case BASICTYPE_MACROTYPE
:
309 switch (bt
->a
.macroType
->choiceId
)
311 case MACROTYPE_ASNABSTRACTOPERATION
:
312 case MACROTYPE_ROSOPERATION
:
314 ProcessRosOperationMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.rosOperation
, v
);
317 case MACROTYPE_ROSERROR
:
318 case MACROTYPE_ASNABSTRACTERROR
:
319 ProcessRosErrorMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.rosError
, v
);
322 case MACROTYPE_ROSBIND
:
323 case MACROTYPE_ROSUNBIND
:
324 ProcessRosBindMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.rosBind
,v
);
327 case MACROTYPE_ROSASE
:
328 ProcessRosAseMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.rosAse
,v
);
331 case MACROTYPE_MTSASEXTENSIONS
:
332 ProcessMtsasExtensionsMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.mtsasExtensions
,v
);
335 case MACROTYPE_MTSASEXTENSION
:
336 ProcessMtsasExtensionMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.mtsasExtension
,v
);
339 case MACROTYPE_MTSASEXTENSIONATTRIBUTE
:
340 ProcessMtsasExtensionAttributeMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.mtsasExtensionAttribute
,v
);
343 case MACROTYPE_MTSASTOKEN
:
344 ProcessMtsasTokenMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.mtsasToken
,v
);
347 case MACROTYPE_MTSASTOKENDATA
:
348 ProcessMtsasTokenDataMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.mtsasTokenData
,v
);
351 case MACROTYPE_MTSASSECURITYCATEGORY
:
352 ProcessMtsasSecurityCategoryMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.mtsasSecurityCategory
,v
);
355 case MACROTYPE_ASNOBJECT
:
356 ProcessAsnObjectMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.asnObject
,v
);
359 case MACROTYPE_ASNPORT
:
360 ProcessAsnPortMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.asnPort
,v
);
363 case MACROTYPE_ASNABSTRACTBIND
:
364 case MACROTYPE_ASNABSTRACTUNBIND
:
365 ProcessAsnAbstractBindMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.asnAbstractBind
,v
);
368 case MACROTYPE_AFALGORITHM
:
369 case MACROTYPE_AFENCRYPTED
:
370 case MACROTYPE_AFPROTECTED
:
371 case MACROTYPE_AFSIGNATURE
:
372 case MACROTYPE_AFSIGNED
:
375 case MACROTYPE_SNMPOBJECTTYPE
:
376 ProcessSnmpObjectTypeMacroType (m
, td
, type
, bt
, bt
->a
.macroType
->a
.snmpObjectType
,v
);
380 /* ignore any others */
385 /* the rest do not need processing */
389 } /* ProcessMacrosInBasicType */
393 * Given a Type referenced in a macro, makes up a name and defines
394 * the type iff the type is not a simple type ref or library type.
395 * Returns the typedef of the type given type. (may be new may
396 * be from the typeref if t was a local or import type ref)
399 DefineType
PARAMS ((m
, td
, t
, name
),
407 TypeDef
**tmpTypeDefHndl
;
413 newDef
= (TypeDef
*)Malloc (sizeof (TypeDef
));
414 newDef
->exported
= FALSE
;
415 newDef
->type
= (Type
*)Malloc (sizeof (Type
));
416 memcpy (newDef
->type
, t
, sizeof (Type
));
419 newDef
->definedName
= Malloc (strlen (name
)+4);
420 strcpy (newDef
->definedName
, name
);
422 if (islower (newDef
->definedName
[0]))
423 newDef
->definedName
[0] =
424 toupper (newDef
->definedName
[0]);
427 /* set up unique type name for new type */
429 (LookupType (m
->typeDefs
, newDef
->definedName
) != NULL
);
431 AppendDigit (newDef
->definedName
, digit
);
434 * now put new typedef at head of list
436 tmpTypeDefHndl
= (TypeDef
**)AsnListPrepend (m
->typeDefs
);
437 *tmpTypeDefHndl
= newDef
;
439 /* convert macro's type def into a ref */
441 SetupType (&tmpType
, BASICTYPE_LOCALTYPEREF
, 0);
442 memcpy (t
, tmpType
, sizeof (Type
));
445 t
->basicType
->a
.localTypeRef
= (TypeRef
*)Malloc (sizeof (TypeRef
));
446 t
->basicType
->a
.localTypeRef
->link
= newDef
;
447 t
->basicType
->a
.localTypeRef
->module = m
;
448 t
->basicType
->a
.localTypeRef
->typeName
=
456 ProcessRosOperationMacroType
PARAMS ((m
, td
, t
, bt
, op
, v
),
461 RosOperationMacroType
*op _AND_
465 if (op
->arguments
!= NULL
)
466 DefineType (m
, td
, op
->arguments
->type
, v
->definedName
);
468 if (op
->result
!= NULL
)
469 DefineType (m
, td
, op
->result
->type
, v
->definedName
);
471 } /* ProcessRosOperationMacroType */
476 ProcessRosErrorMacroType
PARAMS ((m
, td
, t
, bt
, err
, v
),
481 RosErrorMacroType
*err _AND_
484 if ((err
!= NULL
) && (err
->parameter
!= NULL
))
485 DefineType (m
, td
, err
->parameter
->type
, v
->definedName
);
487 } /* ProcessRosErrorMacroType */
491 ProcessRosBindMacroType
PARAMS ((m
, td
, t
, bt
, bind
, v
),
496 RosBindMacroType
*bind _AND_
501 DefineType (m
, td
, bind
->argument
->type
, v
->definedName
);
502 DefineType (m
, td
, bind
->result
->type
, v
->definedName
);
503 DefineType (m
, td
, bind
->error
->type
, v
->definedName
);
505 } /* ProcessRosBindMacroType */
509 ProcessRosAseMacroType
PARAMS ((m
, td
, t
, bt
, ase
, v
),
514 RosAseMacroType
*ase _AND_
518 } /* ProcessRosAseMacroType */
523 ProcessRosAcMacroType
PARAMS ((m
, td
, t
, bt
, ac
, v
),
528 RosAcMacroType
*ac _AND_
532 } /* ProcessRosAcMacroType */
537 ProcessMtsasExtensionsMacroType
PARAMS ((m
, td
, t
, bt
, exts
, v
),
542 MtsasExtensionsMacroType
*exts _AND_
546 } /* ProcessMtsasExtensionsMacroType */
550 ProcessMtsasExtensionMacroType
PARAMS ((m
, td
, t
, bt
, ext
, v
),
555 MtsasExtensionMacroType
*ext _AND_
559 } /* ProcessMtsasExtensionMacroType */
563 ProcessMtsasExtensionAttributeMacroType
PARAMS ((m
, td
, t
, bt
, ext
, v
),
568 MtsasExtensionAttributeMacroType
*ext _AND_
572 } /* ProcessMtsasExtensionAttributeMacroType */
576 ProcessMtsasTokenMacroType
PARAMS ((m
, td
, t
, bt
, tok
, v
),
581 MtsasTokenMacroType
*tok _AND_
585 } /* ProcessMtsasTokenMacroType */
589 ProcessMtsasTokenDataMacroType
PARAMS ((m
, td
, t
, bt
, tok
, v
),
594 MtsasTokenDataMacroType
*tok _AND_
599 } /* ProcessMtsasTokenDataMacroType */
603 ProcessMtsasSecurityCategoryMacroType
PARAMS ((m
, td
, t
, bt
, sec
, v
),
608 MtsasSecurityCategoryMacroType
*sec _AND_
612 } /* ProcessMtsasSecurityCategoryMacroType */
617 ProcessAsnObjectMacroType
PARAMS ((m
, td
, t
, bt
, obj
, v
),
622 AsnObjectMacroType
*obj _AND_
626 } /* ProcessAsnObjectMacroType */
630 ProcessAsnPortMacroType
PARAMS ((m
, td
, t
, bt
, p
, v
),
635 AsnPortMacroType
*p _AND_
639 } /* ProcessAsnPortMacroType */
644 ProcessAsnAbstractBindMacroType
PARAMS ((m
, td
, t
, bt
, bind
, v
),
649 AsnAbstractBindMacroType
*bind _AND_
653 } /* ProcessAsnBindMacroType */
657 ProcessSnmpObjectTypeMacroType
PARAMS ((m
, td
, t
, bt
, ot
, v
),
662 SnmpObjectTypeMacroType
*ot _AND_
666 NamedType
**tmpNtHndl
;
668 AnyRefList
**arlHndl
;
670 if ((ot
!= NULL
) && (ot
->syntax
!= NULL
))
671 DefineType (m
, td
, ot
->syntax
, v
->definedName
);
674 * add ANY ref stuff to type ref'd by this macro so it is
675 * included in the ANY hash table.
679 * do this since the SNMP spec doesn't have an ANY type
680 * but uses the mechanism. (SNMP uses an OCTET STRING
681 * where the 'ANY' value is
685 strcpy (anyId
, v
->definedName
);
686 /* Str2UCase (anyId, strlen (anyId)); */
687 strcat (anyId
, "_ANY_ID");
689 arlHndl
= GetAnyRefListHndl (ot
->syntax
);
692 if (v
->value
->basicValue
->choiceId
== BASICVALUE_OID
)
693 AddAnyRefByOid (arlHndl
, anyId
, v
->value
->basicValue
->a
.oid
);
695 /* integer types are not allowed, but relax constraints anyway */
697 AddAnyRefByInt (arlHndl
, anyId
, v
->value
->basicValue
->a
.integer
);
701 /* make a choice with all the object type elmts */
702 /* USING THE ANY HASH TABLE NOW
703 if (snmpObjectSyntaxesG == NULL)
705 snmpObjectSyntaxesG = (TypeDef*) Malloc (sizeof (TypeDef));
706 SetupType (&snmpObjectSyntaxesG->type, BASICTYPE_CHOICE, 0);
707 snmpObjectSyntaxesG->type->basicType->a.choice =
708 AsnListNew (sizeof (void*));
709 snmpObjectSyntaxesG->definedName = "SnmpOpaqueTypes";
715 * make each field in the choice the same as the object
716 * types SYNTAX field type (adjusted by Define type)
717 * make choice field name same as OBJ-TYPE value Defs name
719 * NOTE - using ptrs to type/fieldname, not duplicating them
720 * this may cause freeing probs
724 nt->fieldName = v->definedName;
725 nt->type = ot->syntax;
727 tmpNtHndl = (NamedType**)
728 AsnListAppend (snmpObjectSyntaxesG->type->basicType->a.choice);
732 } /* ProcessSnmpObjectTypeMacro */