blob: 461f42da5d625cfd41fbe0959106a70afed897cb [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 */
34 A1TC_BOOLBITPOS, /* A bit position in a BIT STRING */
35 A1TC_BITVECTOR, /* A plain collection of bits */
36 A1TC_OPAQUE, /* Opaque data encoded as a bitvector */
37 A1TC_EXTENSIBLE, /* An extension marker "..." */
Lev Walkin070a52d2004-08-22 03:19:54 +000038 A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */
Lev Walkinf15320b2004-06-03 03:38:44 +000039 A1TC_PARAMETRIZED, /* A parametrized type declaration */
40 A1TC_VALUESET, /* Value set definition */
41 A1TC_CLASSDEF, /* Information Object Class */
42 A1TC_CLASSFIELD, /* Information Object Class field */
43 A1TC_INSTANCE, /* Instance of Object Class */
44 A1TC_TYPEID, /* Type identifier */
Lev Walkin070a52d2004-08-22 03:19:54 +000045
Lev Walkinf15320b2004-06-03 03:38:44 +000046 /*
47 * ASN.1 Constructed types
48 */
49#define ASN_CONSTR_MASK 0x10 /* Every constructed type */
50 ASN_CONSTR_SEQUENCE = ASN_CONSTR_MASK, /* SEQUENCE */
51 ASN_CONSTR_CHOICE, /* CHOICE */
52 ASN_CONSTR_SET, /* SET */
53 ASN_CONSTR_SEQUENCE_OF, /* SEQUENCE OF */
54 ASN_CONSTR_SET_OF, /* SET OF */
Lev Walkine422e682004-08-25 01:58:59 +000055
Lev Walkinf15320b2004-06-03 03:38:44 +000056 /*
57 * ASN.1 Basic types
58 */
59#define ASN_BASIC_MASK 0x20 /* Every basic type */
Lev Walkin609ccbb2004-09-04 04:49:21 +000060 ASN_TYPE_ANY = ASN_BASIC_MASK, /* ANY (deprecated) */
61 ASN_BASIC_BOOLEAN,
Lev Walkinf15320b2004-06-03 03:38:44 +000062 ASN_BASIC_NULL,
63 ASN_BASIC_INTEGER,
64 ASN_BASIC_REAL,
65 ASN_BASIC_ENUMERATED,
66 ASN_BASIC_BIT_STRING,
67 ASN_BASIC_OCTET_STRING,
68 ASN_BASIC_OBJECT_IDENTIFIER,
69 ASN_BASIC_RELATIVE_OID,
70 ASN_BASIC_EXTERNAL,
71 ASN_BASIC_EMBEDDED_PDV,
72 ASN_BASIC_CHARACTER_STRING,
73 ASN_BASIC_UTCTime,
74 ASN_BASIC_GeneralizedTime,
Lev Walkin070a52d2004-08-22 03:19:54 +000075
Lev Walkinf15320b2004-06-03 03:38:44 +000076 /*
77 * ASN.1 String types
78 */
Lev Walkine422e682004-08-25 01:58:59 +000079#define ASN_STRING_KM_MASK 0x40 /* Known multiplier */
80#define ASN_STRING_NKM_MASK 0x80 /* Not a known multiplier */
81#define ASN_STRING_MASK 0xC0 /* Every restricted string type */
82 ASN_STRING_IA5String = ASN_STRING_KM_MASK,
83 ASN_STRING_PrintableString,
84 ASN_STRING_VisibleString,
85 ASN_STRING_ISO646String, /* aka VisibleString */
86 ASN_STRING_NumericString,
87 ASN_STRING_UniversalString,
88 ASN_STRING_BMPString,
89 ASN_STRING_UTF8String = ASN_STRING_NKM_MASK,
Lev Walkinf15320b2004-06-03 03:38:44 +000090 ASN_STRING_GeneralString,
91 ASN_STRING_GraphicString,
Lev Walkinf15320b2004-06-03 03:38:44 +000092 ASN_STRING_TeletexString,
93 ASN_STRING_T61String,
Lev Walkinf15320b2004-06-03 03:38:44 +000094 ASN_STRING_VideotexString,
Lev Walkinf15320b2004-06-03 03:38:44 +000095 ASN_STRING_ObjectDescriptor,
96 ASN_EXPR_TYPE_MAX
97} asn1p_expr_type_e;
98
99#include "asn1p_expr_str.h"
100#include "asn1p_expr2uclass.h"
101
Lev Walkin070a52d2004-08-22 03:19:54 +0000102struct asn1p_module_s; /* Forward declaration */
103
Lev Walkinf15320b2004-06-03 03:38:44 +0000104/*
105 * A named collection of types.
106 */
107typedef struct asn1p_expr_s {
108
109 /*
110 * Human readable name.
111 */
112 char *Identifier;
113
114 /*
115 * Meta type of the expression (type, value, value set, etc).
116 */
117 asn1p_expr_meta_e meta_type;
118
119 /*
120 * ASN type of the expression.
121 */
122 asn1p_expr_type_e expr_type;
123
124 /*
125 * Referenced type, if defined elsewhere.
126 * (If expr_type == A1TC_REFERENCE)
127 */
128 asn1p_ref_t *reference;
129
130 /*
131 * Constraints for the type.
132 */
133 asn1p_constraint_t *constraints;
134
135 /*
Lev Walkinf59d0752004-08-18 04:59:12 +0000136 * This field is holding the transformed constraints, with all the
137 * parent constraints taken into account.
138 */
139 asn1p_constraint_t *combined_constraints;
140
141 /*
Lev Walkinf15320b2004-06-03 03:38:44 +0000142 * A list of parameters for parametrized type declaration
143 * (AMT_PARAMTYPE).
144 */
145 asn1p_paramlist_t *params;
146
147 /*
148 * The actual value (DefinedValue or inlined value).
149 */
150 asn1p_value_t *value;
151
152 /*
153 * The WITH SYHTAX clause.
154 */
155 asn1p_wsyntx_t *with_syntax;
156
157 /*
158 * A tag.
159 */
160 struct asn1p_type_tag_s {
161 enum {
162 TC_NOCLASS,
163 TC_UNIVERSAL,
164 TC_APPLICATION,
165 TC_CONTEXT_SPECIFIC,
166 TC_PRIVATE,
167 } tag_class;
168 enum {
169 TM_DEFAULT,
170 TM_IMPLICIT,
171 TM_EXPLICIT,
172 } tag_mode;
173 asn1_integer_t tag_value;
174 } tag;
175
176 /*
177 * Whether automatic tagging is applicable for subtypes.
178 */
179 int auto_tags_OK;
180
181 enum asn1p_expr_marker_e {
182 EM_NOMARK,
183 EM_OPTIONAL,
184 EM_DEFAULT, /* FIXME: store the value somewhere. */
185 } marker;
186 int unique; /* UNIQUE */
187
188 /*
189 * Members of the constructed type.
190 */
191 TQ_HEAD(struct asn1p_expr_s) members;
192
193 /*
194 * Next expression in the list.
195 */
196 TQ_ENTRY(struct asn1p_expr_s) next;
197
Lev Walkin1004aa92004-09-08 00:28:11 +0000198 struct asn1p_expr_s *parent_expr; /* optional */
199
200 struct asn1p_module_s *module; /* Defined in module */
201
Lev Walkinf15320b2004-06-03 03:38:44 +0000202 /*
203 * Line number where this structure is defined in the original
204 * grammar source.
205 */
206 int _lineno;
Lev Walkin070a52d2004-08-22 03:19:54 +0000207
Lev Walkinf15320b2004-06-03 03:38:44 +0000208 /*
209 * Marks are used for various purposes.
210 * Here are some predefined ones.
211 */
212 enum {
213 TM_NOMARK,
214 TM_RECURSION, /* Used to break recursion */
215 } _mark;
216
Lev Walkin070a52d2004-08-22 03:19:54 +0000217 int _anonymous_type; /* Used by the compiler */
218
Lev Walkinf15320b2004-06-03 03:38:44 +0000219 /*
220 * Opaque data may be attached to this structure,
221 * probably by compiler.
222 */
223 void *data;
224 void (*data_free)(void *data);
225} asn1p_expr_t;
226
227
228/*
229 * Constructor and destructor.
230 */
231asn1p_expr_t *asn1p_expr_new(int _lineno);
Lev Walkin070a52d2004-08-22 03:19:54 +0000232asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions);
Lev Walkin1004aa92004-09-08 00:28:11 +0000233void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what);
Lev Walkinf15320b2004-06-03 03:38:44 +0000234void asn1p_expr_free(asn1p_expr_t *expr);
235
236#endif /* ASN1_PARSER_EXPR_H */