Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * A collection of data members of unspecified types. |
| 3 | */ |
| 4 | #ifndef ASN1_PARSER_EXPR_H |
| 5 | #define ASN1_PARSER_EXPR_H |
| 6 | |
| 7 | /* |
| 8 | * Meta type of the ASN expression. |
| 9 | */ |
| 10 | typedef enum asn1p_expr_meta { |
| 11 | AMT_INVALID, |
| 12 | AMT_TYPE, /* Type1 ::= INTEGER */ |
| 13 | AMT_TYPEREF, /* Type2 ::= Type1 */ |
| 14 | AMT_PARAMTYPE, /* Type3{Parameter} ::= SET { ... } */ |
| 15 | AMT_VALUE, /* value1 Type1 ::= 1 */ |
| 16 | AMT_VALUESET, /* ValueSet Type1 ::= { value1 } */ |
| 17 | AMT_OBJECT, /* FUNCTION ::= CLASS {...} */ |
| 18 | AMT_OBJECTSET, /* Functions FUNCTION ::= {...} */ |
| 19 | AMT_OBJECTFIELD, /* ... */ |
| 20 | AMT_EXPR_META_MAX |
| 21 | } asn1p_expr_meta_e; |
| 22 | |
| 23 | /* |
| 24 | * ASN type of the expression. |
| 25 | */ |
| 26 | typedef enum asn1p_expr_type { |
| 27 | /* |
| 28 | * Internal types. |
| 29 | */ |
| 30 | A1TC_INVALID, /* Invalid type */ |
| 31 | A1TC_REFERENCE, /* Reference to the type defined elsewhere */ |
| 32 | A1TC_EXPORTVAR, /* We're exporting this definition */ |
| 33 | A1TC_UNIVERVAL, /* A value of an ENUMERATED, INTEGER or BS */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 34 | A1TC_BITVECTOR, /* A plain collection of bits */ |
| 35 | A1TC_OPAQUE, /* Opaque data encoded as a bitvector */ |
| 36 | A1TC_EXTENSIBLE, /* An extension marker "..." */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 37 | A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 38 | A1TC_PARAMETRIZED, /* A parametrized type declaration */ |
| 39 | A1TC_VALUESET, /* Value set definition */ |
| 40 | A1TC_CLASSDEF, /* Information Object Class */ |
| 41 | A1TC_CLASSFIELD, /* Information Object Class field */ |
| 42 | A1TC_INSTANCE, /* Instance of Object Class */ |
| 43 | A1TC_TYPEID, /* Type identifier */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 44 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 45 | /* |
| 46 | * ASN.1 Constructed types |
| 47 | */ |
| 48 | #define ASN_CONSTR_MASK 0x10 /* Every constructed type */ |
| 49 | ASN_CONSTR_SEQUENCE = ASN_CONSTR_MASK, /* SEQUENCE */ |
| 50 | ASN_CONSTR_CHOICE, /* CHOICE */ |
| 51 | ASN_CONSTR_SET, /* SET */ |
| 52 | ASN_CONSTR_SEQUENCE_OF, /* SEQUENCE OF */ |
| 53 | ASN_CONSTR_SET_OF, /* SET OF */ |
Lev Walkin | e422e68 | 2004-08-25 01:58:59 +0000 | [diff] [blame] | 54 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 55 | /* |
| 56 | * ASN.1 Basic types |
| 57 | */ |
| 58 | #define ASN_BASIC_MASK 0x20 /* Every basic type */ |
Lev Walkin | 609ccbb | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 59 | ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */ |
| 60 | ASN_BASIC_BOOLEAN, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 61 | ASN_BASIC_NULL, |
| 62 | ASN_BASIC_INTEGER, |
| 63 | ASN_BASIC_REAL, |
| 64 | ASN_BASIC_ENUMERATED, |
| 65 | ASN_BASIC_BIT_STRING, |
| 66 | ASN_BASIC_OCTET_STRING, |
| 67 | ASN_BASIC_OBJECT_IDENTIFIER, |
| 68 | ASN_BASIC_RELATIVE_OID, |
| 69 | ASN_BASIC_EXTERNAL, |
| 70 | ASN_BASIC_EMBEDDED_PDV, |
| 71 | ASN_BASIC_CHARACTER_STRING, |
| 72 | ASN_BASIC_UTCTime, |
| 73 | ASN_BASIC_GeneralizedTime, |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 74 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 75 | /* |
| 76 | * ASN.1 String types |
| 77 | */ |
Lev Walkin | e422e68 | 2004-08-25 01:58:59 +0000 | [diff] [blame] | 78 | #define ASN_STRING_KM_MASK 0x40 /* Known multiplier */ |
| 79 | #define ASN_STRING_NKM_MASK 0x80 /* Not a known multiplier */ |
| 80 | #define ASN_STRING_MASK 0xC0 /* Every restricted string type */ |
| 81 | ASN_STRING_IA5String = ASN_STRING_KM_MASK, |
| 82 | ASN_STRING_PrintableString, |
| 83 | ASN_STRING_VisibleString, |
| 84 | ASN_STRING_ISO646String, /* aka VisibleString */ |
| 85 | ASN_STRING_NumericString, |
| 86 | ASN_STRING_UniversalString, |
| 87 | ASN_STRING_BMPString, |
| 88 | ASN_STRING_UTF8String = ASN_STRING_NKM_MASK, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 89 | ASN_STRING_GeneralString, |
| 90 | ASN_STRING_GraphicString, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 91 | ASN_STRING_TeletexString, |
| 92 | ASN_STRING_T61String, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | ASN_STRING_VideotexString, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 94 | ASN_STRING_ObjectDescriptor, |
| 95 | ASN_EXPR_TYPE_MAX |
| 96 | } asn1p_expr_type_e; |
| 97 | |
| 98 | #include "asn1p_expr_str.h" |
| 99 | #include "asn1p_expr2uclass.h" |
| 100 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 101 | struct asn1p_module_s; /* Forward declaration */ |
| 102 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 103 | /* |
| 104 | * A named collection of types. |
| 105 | */ |
| 106 | typedef struct asn1p_expr_s { |
| 107 | |
| 108 | /* |
| 109 | * Human readable name. |
| 110 | */ |
| 111 | char *Identifier; |
| 112 | |
| 113 | /* |
| 114 | * Meta type of the expression (type, value, value set, etc). |
| 115 | */ |
| 116 | asn1p_expr_meta_e meta_type; |
| 117 | |
| 118 | /* |
| 119 | * ASN type of the expression. |
| 120 | */ |
| 121 | asn1p_expr_type_e expr_type; |
| 122 | |
| 123 | /* |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 124 | * Referenced type, defined elsewhere. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 125 | * (If expr_type == A1TC_REFERENCE) |
| 126 | */ |
| 127 | asn1p_ref_t *reference; |
| 128 | |
| 129 | /* |
| 130 | * Constraints for the type. |
| 131 | */ |
| 132 | asn1p_constraint_t *constraints; |
| 133 | |
| 134 | /* |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 135 | * This field is holding the transformed constraints, with all the |
| 136 | * parent constraints taken into account. |
| 137 | */ |
| 138 | asn1p_constraint_t *combined_constraints; |
| 139 | |
| 140 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 141 | * A list of parameters for parametrized type declaration |
| 142 | * (AMT_PARAMTYPE). |
| 143 | */ |
| 144 | asn1p_paramlist_t *params; |
| 145 | |
| 146 | /* |
| 147 | * The actual value (DefinedValue or inlined value). |
| 148 | */ |
| 149 | asn1p_value_t *value; |
| 150 | |
| 151 | /* |
| 152 | * The WITH SYHTAX clause. |
| 153 | */ |
| 154 | asn1p_wsyntx_t *with_syntax; |
| 155 | |
| 156 | /* |
| 157 | * A tag. |
| 158 | */ |
| 159 | struct asn1p_type_tag_s { |
| 160 | enum { |
| 161 | TC_NOCLASS, |
| 162 | TC_UNIVERSAL, |
| 163 | TC_APPLICATION, |
| 164 | TC_CONTEXT_SPECIFIC, |
| 165 | TC_PRIVATE, |
| 166 | } tag_class; |
| 167 | enum { |
| 168 | TM_DEFAULT, |
| 169 | TM_IMPLICIT, |
| 170 | TM_EXPLICIT, |
| 171 | } tag_mode; |
Lev Walkin | d21c505 | 2004-09-29 13:18:09 +0000 | [diff] [blame] | 172 | asn1c_integer_t tag_value; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 173 | } tag; |
| 174 | |
Lev Walkin | 5498f2d | 2004-09-15 11:59:30 +0000 | [diff] [blame] | 175 | struct asn1p_expr_marker_s { |
| 176 | enum asn1p_expr_marker_e { |
| 177 | EM_NOMARK, |
| 178 | EM_INDIRECT = 0x01, /* 0001: Represent as pointer */ |
| 179 | EM_OPTIONAL = 0x03, /* 0011: Optional member */ |
| 180 | EM_DEFAULT = 0x07, /* 0111: default_value */ |
Lev Walkin | c828571 | 2005-03-04 22:18:20 +0000 | [diff] [blame] | 181 | EM_UNRECURSE = 0x08, /* 1000: Use safe naming */ |
Lev Walkin | 5498f2d | 2004-09-15 11:59:30 +0000 | [diff] [blame] | 182 | } flags; |
| 183 | asn1p_value_t *default_value; /* For EM_DEFAULT case */ |
Lev Walkin | 6e8da2b | 2004-09-10 08:21:27 +0000 | [diff] [blame] | 184 | } marker; |
| 185 | int unique; /* UNIQUE */ |
| 186 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 187 | /* |
Lev Walkin | 21d0000 | 2005-03-04 08:48:53 +0000 | [diff] [blame] | 188 | * Whether automatic tagging may be applied for subtypes. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 189 | */ |
| 190 | int auto_tags_OK; |
| 191 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 192 | /* |
| 193 | * Members of the constructed type. |
| 194 | */ |
| 195 | TQ_HEAD(struct asn1p_expr_s) members; |
| 196 | |
| 197 | /* |
| 198 | * Next expression in the list. |
| 199 | */ |
| 200 | TQ_ENTRY(struct asn1p_expr_s) next; |
| 201 | |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 202 | struct asn1p_expr_s *parent_expr; /* optional */ |
| 203 | |
| 204 | struct asn1p_module_s *module; /* Defined in module */ |
| 205 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 206 | /* |
| 207 | * Line number where this structure is defined in the original |
| 208 | * grammar source. |
| 209 | */ |
| 210 | int _lineno; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 211 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 212 | /* |
| 213 | * Marks are used for various purposes. |
| 214 | * Here are some predefined ones. |
| 215 | */ |
| 216 | enum { |
| 217 | TM_NOMARK, |
| 218 | TM_RECURSION, /* Used to break recursion */ |
Lev Walkin | 81c5fc5 | 2005-03-18 05:26:15 +0000 | [diff] [blame] | 219 | TM_BROKEN, /* A warning was already issued */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 220 | } _mark; |
| 221 | |
Lev Walkin | 21d0000 | 2005-03-04 08:48:53 +0000 | [diff] [blame] | 222 | /* |
| 223 | * Some tags used by the compiler. |
| 224 | */ |
| 225 | int _anonymous_type; /* This type is unnamed */ |
| 226 | int _type_unique_index; /* A per top-level-type unique index */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 227 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 228 | /* |
| 229 | * Opaque data may be attached to this structure, |
| 230 | * probably by compiler. |
| 231 | */ |
| 232 | void *data; |
| 233 | void (*data_free)(void *data); |
| 234 | } asn1p_expr_t; |
| 235 | |
| 236 | |
| 237 | /* |
| 238 | * Constructor and destructor. |
| 239 | */ |
| 240 | asn1p_expr_t *asn1p_expr_new(int _lineno); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 241 | asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 242 | void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 243 | void asn1p_expr_free(asn1p_expr_t *expr); |
| 244 | |
| 245 | #endif /* ASN1_PARSER_EXPR_H */ |