blob: c215c3fc0518eb2bc864e8a287aec18711efbd59 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*
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 */
10typedef 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 */
26typedef 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 Walkinf15320b2004-06-03 03:38:44 +000034 A1TC_BITVECTOR, /* A plain collection of bits */
35 A1TC_OPAQUE, /* Opaque data encoded as a bitvector */
36 A1TC_EXTENSIBLE, /* An extension marker "..." */
Lev Walkin070a52d2004-08-22 03:19:54 +000037 A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */
Lev Walkinf15320b2004-06-03 03:38:44 +000038 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 Walkin070a52d2004-08-22 03:19:54 +000044
Lev Walkinf15320b2004-06-03 03:38:44 +000045 /*
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 Walkine422e682004-08-25 01:58:59 +000054
Lev Walkinf15320b2004-06-03 03:38:44 +000055 /*
56 * ASN.1 Basic types
57 */
58#define ASN_BASIC_MASK 0x20 /* Every basic type */
Lev Walkin609ccbb2004-09-04 04:49:21 +000059 ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */
60 ASN_BASIC_BOOLEAN,
Lev Walkinf15320b2004-06-03 03:38:44 +000061 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 Walkin070a52d2004-08-22 03:19:54 +000074
Lev Walkinf15320b2004-06-03 03:38:44 +000075 /*
76 * ASN.1 String types
77 */
Lev Walkine422e682004-08-25 01:58:59 +000078#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 Walkinf15320b2004-06-03 03:38:44 +000089 ASN_STRING_GeneralString,
90 ASN_STRING_GraphicString,
Lev Walkinf15320b2004-06-03 03:38:44 +000091 ASN_STRING_TeletexString,
92 ASN_STRING_T61String,
Lev Walkinf15320b2004-06-03 03:38:44 +000093 ASN_STRING_VideotexString,
Lev Walkinf15320b2004-06-03 03:38:44 +000094 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 Walkin070a52d2004-08-22 03:19:54 +0000101struct asn1p_module_s; /* Forward declaration */
102
Lev Walkinf15320b2004-06-03 03:38:44 +0000103/*
104 * A named collection of types.
105 */
106typedef 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 Walkinc8092cb2005-02-18 16:34:21 +0000124 * Referenced type, defined elsewhere.
Lev Walkinf15320b2004-06-03 03:38:44 +0000125 * (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 Walkinf59d0752004-08-18 04:59:12 +0000135 * 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 Walkinf15320b2004-06-03 03:38:44 +0000141 * 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 Walkind21c5052004-09-29 13:18:09 +0000172 asn1c_integer_t tag_value;
Lev Walkinf15320b2004-06-03 03:38:44 +0000173 } tag;
174
Lev Walkin5498f2d2004-09-15 11:59:30 +0000175 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 Walkinc8285712005-03-04 22:18:20 +0000181 EM_UNRECURSE = 0x08, /* 1000: Use safe naming */
Lev Walkin5498f2d2004-09-15 11:59:30 +0000182 } flags;
183 asn1p_value_t *default_value; /* For EM_DEFAULT case */
Lev Walkin6e8da2b2004-09-10 08:21:27 +0000184 } marker;
185 int unique; /* UNIQUE */
186
Lev Walkinf15320b2004-06-03 03:38:44 +0000187 /*
Lev Walkin21d00002005-03-04 08:48:53 +0000188 * Whether automatic tagging may be applied for subtypes.
Lev Walkinf15320b2004-06-03 03:38:44 +0000189 */
190 int auto_tags_OK;
191
Lev Walkinf15320b2004-06-03 03:38:44 +0000192 /*
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 Walkin1004aa92004-09-08 00:28:11 +0000202 struct asn1p_expr_s *parent_expr; /* optional */
203
204 struct asn1p_module_s *module; /* Defined in module */
205
Lev Walkinf15320b2004-06-03 03:38:44 +0000206 /*
207 * Line number where this structure is defined in the original
208 * grammar source.
209 */
210 int _lineno;
Lev Walkin070a52d2004-08-22 03:19:54 +0000211
Lev Walkinf15320b2004-06-03 03:38:44 +0000212 /*
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 */
219 } _mark;
220
Lev Walkin21d00002005-03-04 08:48:53 +0000221 /*
222 * Some tags used by the compiler.
223 */
224 int _anonymous_type; /* This type is unnamed */
225 int _type_unique_index; /* A per top-level-type unique index */
Lev Walkin070a52d2004-08-22 03:19:54 +0000226
Lev Walkinf15320b2004-06-03 03:38:44 +0000227 /*
228 * Opaque data may be attached to this structure,
229 * probably by compiler.
230 */
231 void *data;
232 void (*data_free)(void *data);
233} asn1p_expr_t;
234
235
236/*
237 * Constructor and destructor.
238 */
239asn1p_expr_t *asn1p_expr_new(int _lineno);
Lev Walkin070a52d2004-08-22 03:19:54 +0000240asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions);
Lev Walkin1004aa92004-09-08 00:28:11 +0000241void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what);
Lev Walkinf15320b2004-06-03 03:38:44 +0000242void asn1p_expr_free(asn1p_expr_t *expr);
243
244#endif /* ASN1_PARSER_EXPR_H */