NativeEnumerated.c vars NULL init and check
[com/asn1c.git] / tests / tests-asn1c-compiler / 126-per-extensions-OK.asn1.-Pgen-PER
1
2 /*** <<< INCLUDES [PDU] >>> ***/
3
4 #include <IA5String.h>
5 #include "Singleton.h"
6 #include <constr_SEQUENCE.h>
7
8 /*** <<< FWD-DECLS [PDU] >>> ***/
9
10 struct PDU_2;
11 struct Singleton;
12
13 /*** <<< TYPE-DECLS [PDU] >>> ***/
14
15 typedef struct PDU {
16         /*
17          * This type is extensible,
18          * possible extensions are below.
19          */
20         IA5String_t     *str_o; /* OPTIONAL */
21         IA5String_t     *str_m;
22         struct Singleton        *singl;
23         struct PDU_2    *pdu_2; /* OPTIONAL */
24         
25         /* Context for parsing across buffer boundaries */
26         asn_struct_ctx_t _asn_ctx;
27 } PDU_t;
28
29 /*** <<< FUNC-DECLS [PDU] >>> ***/
30
31 extern asn_TYPE_descriptor_t asn_DEF_PDU;
32
33 /*** <<< POST-INCLUDE [PDU] >>> ***/
34
35 #include "PDU-2.h"
36
37 /*** <<< STAT-DEFS [PDU] >>> ***/
38
39 static asn_TYPE_member_t asn_MBR_PDU_1[] = {
40         { ATF_POINTER, 4, offsetof(struct PDU, str_o),
41                 .tag = (ASN_TAG_CLASS_CONTEXT | (0 << 2)),
42                 .tag_mode = -1, /* IMPLICIT tag at current level */
43                 .type = &asn_DEF_IA5String,
44                 .type_selector = 0,
45                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
46                 0, 0, /* No default value */
47                 .name = "str-o"
48                 },
49         { ATF_POINTER, 3, offsetof(struct PDU, str_m),
50                 .tag = (ASN_TAG_CLASS_CONTEXT | (1 << 2)),
51                 .tag_mode = -1, /* IMPLICIT tag at current level */
52                 .type = &asn_DEF_IA5String,
53                 .type_selector = 0,
54                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
55                 0, 0, /* No default value */
56                 .name = "str-m"
57                 },
58         { ATF_POINTER, 2, offsetof(struct PDU, singl),
59                 .tag = (ASN_TAG_CLASS_CONTEXT | (2 << 2)),
60                 .tag_mode = -1, /* IMPLICIT tag at current level */
61                 .type = &asn_DEF_Singleton,
62                 .type_selector = 0,
63                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
64                 0, 0, /* No default value */
65                 .name = "singl"
66                 },
67         { ATF_POINTER, 1, offsetof(struct PDU, pdu_2),
68                 .tag = (ASN_TAG_CLASS_CONTEXT | (3 << 2)),
69                 .tag_mode = +1, /* EXPLICIT tag at current level */
70                 .type = &asn_DEF_PDU_2,
71                 .type_selector = 0,
72                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
73                 0, 0, /* No default value */
74                 .name = "pdu-2"
75                 },
76 };
77 static const int asn_MAP_PDU_oms_1[] = { 0, 1, 2, 3 };
78 static const ber_tlv_tag_t asn_DEF_PDU_tags_1[] = {
79         (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
80 };
81 static const asn_TYPE_tag2member_t asn_MAP_PDU_tag2el_1[] = {
82     { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* str-o */
83     { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* str-m */
84     { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 }, /* singl */
85     { (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 3, 0, 0 } /* pdu-2 */
86 };
87 static asn_SEQUENCE_specifics_t asn_SPC_PDU_specs_1 = {
88         sizeof(struct PDU),
89         offsetof(struct PDU, _asn_ctx),
90         .tag2el = asn_MAP_PDU_tag2el_1,
91         .tag2el_count = 4,      /* Count of tags in the map */
92         asn_MAP_PDU_oms_1,      /* Optional members */
93         0, 4,   /* Root/Additions */
94         0,      /* First extension addition */
95 };
96 asn_TYPE_descriptor_t asn_DEF_PDU = {
97         "PDU",
98         "PDU",
99         &asn_OP_SEQUENCE,
100         asn_DEF_PDU_tags_1,
101         sizeof(asn_DEF_PDU_tags_1)
102                 /sizeof(asn_DEF_PDU_tags_1[0]), /* 1 */
103         asn_DEF_PDU_tags_1,     /* Same as above */
104         sizeof(asn_DEF_PDU_tags_1)
105                 /sizeof(asn_DEF_PDU_tags_1[0]), /* 1 */
106         { 0, 0, SEQUENCE_constraint },
107         asn_MBR_PDU_1,
108         4,      /* Elements count */
109         &asn_SPC_PDU_specs_1    /* Additional specs */
110 };
111
112
113 /*** <<< INCLUDES [Singleton] >>> ***/
114
115 #include <IA5String.h>
116 #include <constr_SEQUENCE.h>
117
118 /*** <<< TYPE-DECLS [Singleton] >>> ***/
119
120 typedef struct Singleton {
121         IA5String_t     *opt_z; /* DEFAULT z */
122         
123         /* Context for parsing across buffer boundaries */
124         asn_struct_ctx_t _asn_ctx;
125 } Singleton_t;
126
127 /*** <<< FUNC-DECLS [Singleton] >>> ***/
128
129 extern asn_TYPE_descriptor_t asn_DEF_Singleton;
130 extern asn_SEQUENCE_specifics_t asn_SPC_Singleton_specs_1;
131 extern asn_TYPE_member_t asn_MBR_Singleton_1[1];
132
133 /*** <<< STAT-DEFS [Singleton] >>> ***/
134
135 static int asn_DFL_2_cmp(const void *sptr) {
136         static const uint8_t defv[] = "z";
137         const IA5String_t *st = sptr;
138         
139         if(!st) {
140                 return -1; /* No value is not a default value */
141         }
142         
143         if(st->size == (sizeof(defv) - 1)
144         && memcmp(st->buf, &defv, sizeof(defv) - 1) == 0)
145                 return 0;
146         return 1;
147 }
148 static int asn_DFL_2_set(void **sptr) {
149         static const uint8_t defv[] = "z";
150         IA5String_t *st = *sptr;
151         uint8_t *nstr = MALLOC(sizeof(defv));
152         
153         if(!nstr) return -1;
154         memcpy(nstr, defv, sizeof(defv));
155         
156         if(st) {
157                 FREEMEM(st->buf);
158         } else {
159                 st = (*sptr = CALLOC(1, sizeof(*st)));
160                 if(!st) { FREEMEM(nstr); return -1; }
161         }
162         st->buf = nstr;
163         st->size = sizeof(defv) - 1;
164         
165         return 0;
166 }
167 asn_TYPE_member_t asn_MBR_Singleton_1[] = {
168         { ATF_POINTER, 1, offsetof(struct Singleton, opt_z),
169                 .tag = (ASN_TAG_CLASS_CONTEXT | (0 << 2)),
170                 .tag_mode = -1, /* IMPLICIT tag at current level */
171                 .type = &asn_DEF_IA5String,
172                 .type_selector = 0,
173                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
174                 .default_value_cmp = &asn_DFL_2_cmp,    /* Compare DEFAULT "z" */
175                 .default_value_set = &asn_DFL_2_set,    /* Set DEFAULT "z" */
176                 .name = "opt-z"
177                 },
178 };
179 static const int asn_MAP_Singleton_oms_1[] = { 0 };
180 static const ber_tlv_tag_t asn_DEF_Singleton_tags_1[] = {
181         (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
182 };
183 static const asn_TYPE_tag2member_t asn_MAP_Singleton_tag2el_1[] = {
184     { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* opt-z */
185 };
186 asn_SEQUENCE_specifics_t asn_SPC_Singleton_specs_1 = {
187         sizeof(struct Singleton),
188         offsetof(struct Singleton, _asn_ctx),
189         .tag2el = asn_MAP_Singleton_tag2el_1,
190         .tag2el_count = 1,      /* Count of tags in the map */
191         asn_MAP_Singleton_oms_1,        /* Optional members */
192         1, 0,   /* Root/Additions */
193         -1,     /* First extension addition */
194 };
195 asn_TYPE_descriptor_t asn_DEF_Singleton = {
196         "Singleton",
197         "Singleton",
198         &asn_OP_SEQUENCE,
199         asn_DEF_Singleton_tags_1,
200         sizeof(asn_DEF_Singleton_tags_1)
201                 /sizeof(asn_DEF_Singleton_tags_1[0]), /* 1 */
202         asn_DEF_Singleton_tags_1,       /* Same as above */
203         sizeof(asn_DEF_Singleton_tags_1)
204                 /sizeof(asn_DEF_Singleton_tags_1[0]), /* 1 */
205         { 0, 0, SEQUENCE_constraint },
206         asn_MBR_Singleton_1,
207         1,      /* Elements count */
208         &asn_SPC_Singleton_specs_1      /* Additional specs */
209 };
210
211
212 /*** <<< INCLUDES [PDU-2] >>> ***/
213
214 #include <NativeInteger.h>
215 #include <constr_CHOICE.h>
216
217 /*** <<< DEPS [PDU-2] >>> ***/
218
219 typedef enum PDU_2_PR {
220         PDU_2_PR_NOTHING,       /* No components present */
221         PDU_2_PR_main,
222         /* Extensions may appear below */
223         PDU_2_PR_ext1,
224         PDU_2_PR_ext0
225 } PDU_2_PR;
226
227 /*** <<< TYPE-DECLS [PDU-2] >>> ***/
228
229 typedef struct PDU_2 {
230         PDU_2_PR present;
231         union PDU_2_u {
232                 long     main;
233                 /*
234                  * This type is extensible,
235                  * possible extensions are below.
236                  */
237                 long     ext1;
238                 long     ext0;
239         } choice;
240         
241         /* Context for parsing across buffer boundaries */
242         asn_struct_ctx_t _asn_ctx;
243 } PDU_2_t;
244
245 /*** <<< FUNC-DECLS [PDU-2] >>> ***/
246
247 extern asn_TYPE_descriptor_t asn_DEF_PDU_2;
248 extern asn_CHOICE_specifics_t asn_SPC_PDU_2_specs_1;
249 extern asn_TYPE_member_t asn_MBR_PDU_2_1[3];
250 extern asn_per_constraints_t asn_PER_type_PDU_2_constr_1;
251
252 /*** <<< CTDEFS [PDU-2] >>> ***/
253
254 asn_per_constraints_t asn_PER_type_PDU_2_constr_1 CC_NOTUSED = {
255         { APC_CONSTRAINED | APC_EXTENSIBLE,  0,  0,  0,  0 }    /* (0..0,...) */,
256         { APC_UNCONSTRAINED,    -1, -1,  0,  0 },
257         0, 0    /* No PER value map */
258 };
259
260 /*** <<< STAT-DEFS [PDU-2] >>> ***/
261
262 asn_TYPE_member_t asn_MBR_PDU_2_1[] = {
263         { ATF_NOFLAGS, 0, offsetof(struct PDU_2, choice.main),
264                 .tag = (ASN_TAG_CLASS_CONTEXT | (3 << 2)),
265                 .tag_mode = -1, /* IMPLICIT tag at current level */
266                 .type = &asn_DEF_NativeInteger,
267                 .type_selector = 0,
268                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
269                 0, 0, /* No default value */
270                 .name = "main"
271                 },
272         { ATF_NOFLAGS, 0, offsetof(struct PDU_2, choice.ext1),
273                 .tag = (ASN_TAG_CLASS_CONTEXT | (1 << 2)),
274                 .tag_mode = -1, /* IMPLICIT tag at current level */
275                 .type = &asn_DEF_NativeInteger,
276                 .type_selector = 0,
277                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
278                 0, 0, /* No default value */
279                 .name = "ext1"
280                 },
281         { ATF_NOFLAGS, 0, offsetof(struct PDU_2, choice.ext0),
282                 .tag = (ASN_TAG_CLASS_CONTEXT | (0 << 2)),
283                 .tag_mode = -1, /* IMPLICIT tag at current level */
284                 .type = &asn_DEF_NativeInteger,
285                 .type_selector = 0,
286                 { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
287                 0, 0, /* No default value */
288                 .name = "ext0"
289                 },
290 };
291 static const unsigned asn_MAP_PDU_2_to_canonical_1[] = { 0, 2, 1 };
292 static const unsigned asn_MAP_PDU_2_from_canonical_1[] = { 0, 2, 1 };
293 static const asn_TYPE_tag2member_t asn_MAP_PDU_2_tag2el_1[] = {
294     { (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 2, 0, 0 }, /* ext0 */
295     { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* ext1 */
296     { (ASN_TAG_CLASS_CONTEXT | (3 << 2)), 0, 0, 0 } /* main */
297 };
298 asn_CHOICE_specifics_t asn_SPC_PDU_2_specs_1 = {
299         sizeof(struct PDU_2),
300         offsetof(struct PDU_2, _asn_ctx),
301         offsetof(struct PDU_2, present),
302         sizeof(((struct PDU_2 *)0)->present),
303         .tag2el = asn_MAP_PDU_2_tag2el_1,
304         .tag2el_count = 3,      /* Count of tags in the map */
305         .to_canonical_order = asn_MAP_PDU_2_to_canonical_1,
306         .from_canonical_order = asn_MAP_PDU_2_from_canonical_1,
307         .first_extension = 1    /* Extensions start */
308 };
309 asn_TYPE_descriptor_t asn_DEF_PDU_2 = {
310         "PDU-2",
311         "PDU-2",
312         &asn_OP_CHOICE,
313         0,      /* No effective tags (pointer) */
314         0,      /* No effective tags (count) */
315         0,      /* No tags (pointer) */
316         0,      /* No tags (count) */
317         { 0, &asn_PER_type_PDU_2_constr_1, CHOICE_constraint },
318         asn_MBR_PDU_2_1,
319         3,      /* Elements count */
320         &asn_SPC_PDU_2_specs_1  /* Additional specs */
321 };
322