Sync with 5.4.0
[deliverable/titan.core.git] / compiler2 / union.c
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 #include <string.h>
9
10 #include "../common/memory.h"
11 #include "datatypes.h"
12 #include "union.h"
13 #include "encdec.h"
14
15 #include "main.hh"
16 #include "ttcn3/compiler.h"
17
18 /** used in the RAW_decode functions generation to store information
19 * about the temporal variables
20 * type is the type of the variable
21 * typedescr is the type's descriptor
22 * start_pos is where the decoding should begin
23 * it is >= 0 if known at compile time, otherwise -1
24 * use_counter stores how many times this type will be used
25 * if it is >1 than we create the variable "globally" so that that
26 * we don't need to create it again in the next component's decode try
27 * if it is ==1 than it is a local variable only referred at one place
28 * we create it only where it is needed, so if at runtime the decoding
29 * comes to a conclusion before the use of this variable, then its
30 * overhead won't slow down the decoding
31 * decoded_for_element is the index of the element in the union for which
32 * this variable was last used for
33 * if it is -1 if the variable hasn't been decoded yet
34 * only in this case it is needed to generate the code to do the decoding
35 * if it is >=0 than we use it generate the conditions
36 * if it doesn't equal to the actual component's index, then we have to
37 * generate the condition and the decoding... parts to it.
38 * if it equals the actual component's index, then we only add its test
39 * to the actual condition
40 */
41 typedef struct{
42 const char* type;
43 const char* typedescr;
44 int start_pos;
45 int use_counter;
46 int decoded_for_element;
47 }temporal_variable;
48
49 void defUnionClass(struct_def const *sdef, output_struct *output)
50 {
51 size_t i;
52 const char *name = sdef->name, *dispname = sdef->dispname;
53 const char *at_field = sdef->kind==ANYTYPE ? "AT_" : "";
54 /* at_field is used to prefix the name of accessor member functions
55 * for the anytype, otherwise the generated "INTEGER()" will look like
56 * a constructor, upsetting the C++ compiler. AT_INTEGER() is ok. */
57 char *def = NULL, *src = NULL;
58 boolean ber_needed = sdef->isASN1 && enable_ber();
59 boolean raw_needed = sdef->hasRaw && enable_raw();
60 boolean text_needed = sdef->hasText && enable_text();
61 boolean xer_needed = sdef->hasXer && enable_xer();
62 boolean json_needed = sdef->hasJson && enable_json();
63
64 char *selection_type, *unbound_value, *selection_prefix;
65 selection_type = mcopystr("union_selection_type");
66 unbound_value = mcopystr("UNBOUND_VALUE");
67 selection_prefix = mcopystr("ALT");
68
69
70 /* class declaration */
71 output->header.class_decls = mputprintf(output->header.class_decls,
72 "class %s;\n", name);
73
74 /* class definition and source code */
75
76 /* class header and data fields*/
77 def = mputprintf(def,
78 #ifndef NDEBUG
79 "// written by defUnionClass in " __FILE__ " at %d\n"
80 #endif
81 "class %s : public Base_Type {\n"
82 #ifndef NDEBUG
83 , __LINE__
84 #endif
85 , name);
86 /* selection type (enum) definition */
87 def = mputstr(def, "public:\n"
88 "enum union_selection_type { UNBOUND_VALUE = 0");
89 for (i = 0; i < sdef->nElements; i++) {
90 def = mputprintf(def, ", ALT_%s = %lu", sdef->elements[i].name,
91 (unsigned long) (i + 1));
92 }
93 def = mputstr(def, " };\n"
94 "private:\n");
95
96 def = mputprintf(def, "%s union_selection;\n"
97 "union {\n", selection_type);
98 for (i = 0; i < sdef->nElements; i++) {
99 def = mputprintf(def, "%s *field_%s;\n", sdef->elements[i].type,
100 sdef->elements[i].name);
101 }
102 def = mputstr(def, "};\n");
103
104 if(ber_needed && sdef->ot) {
105 def=mputstr(def, "ASN_BER_TLV_t tlv_opentype;\n");
106 }
107
108 if (use_runtime_2) {
109 def=mputstr(def, "Erroneous_descriptor_t* err_descr;\n");
110 }
111
112 /* copy_value function */
113 def = mputprintf(def, "void copy_value(const %s& other_value);\n", name);
114 src = mputprintf(src, "void %s::copy_value(const %s& other_value)\n"
115 "{\n"
116 "switch (other_value.union_selection) {\n", name, name);
117 for (i = 0; i < sdef->nElements; i++) {
118 src = mputprintf(src, "case %s_%s:\n"
119 "field_%s = new %s(*other_value.field_%s);\n"
120 "break;\n", selection_prefix, sdef->elements[i].name,
121 sdef->elements[i].name, sdef->elements[i].type, sdef->elements[i].name);
122 }
123 src = mputprintf(src, "default:\n"
124 "TTCN_error(\"Assignment of an unbound union value of type %s.\");\n"
125 "}\n"
126 "union_selection = other_value.union_selection;\n", dispname);
127
128 if (use_runtime_2) {
129 src = mputstr(src, "err_descr = other_value.err_descr;\n");
130 }
131
132 src = mputstr(src, "}\n\n");
133
134 /* default constructor */
135 def = mputprintf(def, "\npublic:\n"
136 "%s();\n", name);
137 src = mputprintf(src, "%s::%s()%s\n"
138 "{\n"
139 "union_selection = %s;\n"
140 "}\n\n", name, name,
141 use_runtime_2 ? ": err_descr(NULL)" : "",
142 unbound_value);
143
144 /* copy constructor */
145 def = mputprintf(def, "%s(const %s& other_value);\n", name, name);
146 src = mputprintf(src, "%s::%s(const %s& other_value)\n"
147 ": Base_Type()" /* call the *default* constructor as before */
148 "{\n"
149 "copy_value(other_value);\n"
150 "}\n\n", name, name, name);
151
152 /* destructor */
153 def = mputprintf(def, "~%s();\n", name);
154 src = mputprintf(src, "%s::~%s()\n"
155 "{\n"
156 "clean_up();\n"
157 "}\n\n", name, name);
158
159 /* assignment operator */
160 def = mputprintf(def, "%s& operator=(const %s& other_value);\n", name, name);
161 src = mputprintf(src, "%s& %s::operator=(const %s& other_value)\n"
162 "{\n"
163 "if (this != &other_value) {\n"
164 "clean_up();\n"
165 "copy_value(other_value);\n"
166 "}\n"
167 "return *this;\n"
168 "}\n\n", name, name, name);
169
170 /* comparison operator */
171 def = mputprintf(def, "boolean operator==(const %s& other_value) const;\n",
172 name);
173 src = mputprintf(src, "boolean %s::operator==(const %s& other_value) const\n"
174 "{\n"
175 "if (union_selection == %s) TTCN_error(\"The left operand of comparison "
176 "is an unbound value of union type %s.\");\n"
177 "if (other_value.union_selection == %s) TTCN_error(\"The right operand of "
178 "comparison is an unbound value of union type %s.\");\n"
179 "if (union_selection != other_value.union_selection) return FALSE;\n"
180 "switch (union_selection) {\n", name, name, unbound_value, dispname,
181 unbound_value, dispname);
182 for (i = 0; i < sdef->nElements; i++) {
183 src = mputprintf(src, "case %s_%s:\n"
184 "return *field_%s == *other_value.field_%s;\n", selection_prefix,
185 sdef->elements[i].name, sdef->elements[i].name, sdef->elements[i].name);
186 }
187 src = mputstr(src, "default:\n"
188 "return FALSE;\n"
189 "}\n"
190 "}\n\n");
191
192 /* != and () operator */
193 def = mputprintf(def, "inline boolean operator!=(const %s& other_value) "
194 "const { return !(*this == other_value); }\n", name);
195
196 /* field access functions */
197 for (i = 0; i < sdef->nElements; i++) {
198 def = mputprintf(def, "%s& %s%s();\n", sdef->elements[i].type,
199 at_field, sdef->elements[i].name);
200 src = mputprintf(src, "%s& %s::%s%s()\n"
201 "{\n"
202 "if (union_selection != %s_%s) {\n"
203 "clean_up();\n"
204 "field_%s = new %s;\n"
205 "union_selection = %s_%s;\n"
206 "}\n"
207 "return *field_%s;\n"
208 "}\n\n", sdef->elements[i].type, name, at_field, sdef->elements[i].name,
209 selection_prefix, sdef->elements[i].name, sdef->elements[i].name,
210 sdef->elements[i].type, selection_prefix, sdef->elements[i].name,
211 sdef->elements[i].name);
212
213 def = mputprintf(def, "const %s& %s%s() const;\n", sdef->elements[i].type,
214 at_field, sdef->elements[i].name);
215 src = mputprintf(src, "const %s& %s::%s%s() const\n"
216 "{\n"
217 "if (union_selection != %s_%s) TTCN_error(\"Using non-selected field "
218 "%s in a value of union type %s.\");\n"
219 "return *field_%s;\n"
220 "}\n\n",
221 sdef->elements[i].type, name, at_field, sdef->elements[i].name, selection_prefix,
222 sdef->elements[i].name, sdef->elements[i].dispname, dispname,
223 sdef->elements[i].name);
224 }
225
226 /* get_selection function */
227 def = mputprintf(def, "inline %s get_selection() const "
228 "{ return union_selection; }\n", selection_type);
229
230 /* ischosen function */
231 def = mputprintf(def, "boolean ischosen(%s checked_selection) const;\n",
232 selection_type);
233 src = mputprintf(src, "boolean %s::ischosen(%s checked_selection) const\n"
234 "{\n"
235 "if (checked_selection == %s) TTCN_error(\"Internal error: Performing "
236 "ischosen() operation on an invalid field of union type %s.\");\n"
237 "if (union_selection == %s) TTCN_error(\"Performing ischosen() operation "
238 "on an unbound value of union type %s.\");\n"
239 "return union_selection == checked_selection;\n"
240 "}\n\n", name, selection_type, unbound_value, dispname, unbound_value,
241 dispname);
242
243 /* is_bound function */
244 def = mputstr (def, "boolean is_bound() const;\n");
245 src = mputprintf(src, "boolean %s::is_bound() const\n"
246 "{\n"
247 " return union_selection != %s;\n"
248 "}\n\n", name, unbound_value);
249
250 /* is_value function */
251 def = mputstr (def, "boolean is_value() const;\n");
252 src = mputprintf(src, "boolean %s::is_value() const\n"
253 "{\n"
254 "switch (union_selection) {\n"
255 "case %s: return FALSE;\n",
256 name, unbound_value);
257 for (i = 0; i < sdef->nElements; ++i) {
258 src = mputprintf(src, "case %s_%s: return field_%s->is_value();\n",
259 selection_prefix, sdef->elements[i].name, sdef->elements[i].name);
260 }
261 src = mputstr(src, "default: TTCN_error(\"Invalid selection in union is_bound\");"
262 "}\n"
263 "}\n\n");
264
265 /* clean_up function */
266 def = mputstr (def, "void clean_up();\n");
267 src = mputprintf(src, "void %s::clean_up()\n"
268 "{\n"
269 "switch (union_selection) {\n",
270 name);
271 for (i = 0; i < sdef->nElements; ++i) {
272 src = mputprintf(src, "case %s_%s:\n"
273 " delete field_%s;\n"
274 " break;\n",
275 selection_prefix, sdef->elements[i].name, sdef->elements[i].name);
276 }
277 src = mputprintf(src, "default:\n"
278 " break;\n"
279 "}\n"
280 "union_selection = %s;\n"
281 "}\n\n", unbound_value);
282
283 if (use_runtime_2) {
284 def = mputstr(def,
285 "boolean is_equal(const Base_Type* other_value) const;\n"
286 "void set_value(const Base_Type* other_value);\n"
287 "Base_Type* clone() const;\n"
288 "const TTCN_Typedescriptor_t* get_descriptor() const;\n"
289 "void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }\n"
290 "Erroneous_descriptor_t* get_err_descr() const { return err_descr; }\n");
291 src = mputprintf(src,
292 "boolean %s::is_equal(const Base_Type* other_value) const "
293 "{ return *this == *(static_cast<const %s*>(other_value)); }\n"
294 "void %s::set_value(const Base_Type* other_value) "
295 "{ *this = *(static_cast<const %s*>(other_value)); }\n"
296 "Base_Type* %s::clone() const { return new %s(*this); }\n"
297 "const TTCN_Typedescriptor_t* %s::get_descriptor() const "
298 "{ return &%s_descr_; }\n",
299 name, name,
300 name, name,
301 name, name,
302 name, name);
303 } else {
304 def = mputstr(def,
305 "inline boolean is_present() const { return is_bound(); }\n");
306 }
307
308 /* log function */
309 def = mputstr(def, "void log() const;\n");
310 src = mputprintf(src, "void %s::log() const\n"
311 "{\n"
312 "switch (union_selection) {\n", name);
313 for (i = 0; i < sdef->nElements; i++) {
314 src = mputprintf(src, "case %s_%s:\n"
315 "TTCN_Logger::log_event_str(\"{ %s := \");\n"
316 "field_%s->log();\n"
317 "TTCN_Logger::log_event_str(\" }\");\n"
318 "break;\n", selection_prefix, sdef->elements[i].name,
319 sdef->elements[i].dispname, sdef->elements[i].name);
320 }
321 src = mputstr(src, "default:\n"
322 "TTCN_Logger::log_event_unbound();\n"
323 "}\n");
324 if (use_runtime_2) {
325 src = mputstr(src, "if (err_descr) err_descr->log();\n");
326 }
327 src = mputstr(src, "}\n\n");
328
329 /* set_param function */
330 def = mputstr(def, "void set_param(Module_Param& param);\n");
331 src = mputprintf(src, "void %s::set_param(Module_Param& param)\n"
332 "{\n"
333 " if (dynamic_cast<Module_Param_Name*>(param.get_id()) != NULL &&\n"
334 " param.get_id()->next_name()) {\n"
335 // Haven't reached the end of the module parameter name
336 // => the name refers to one of the fields, not to the whole union
337 " char* param_field = param.get_id()->get_current_name();\n"
338 " if (param_field[0] >= '0' && param_field[0] <= '9') {\n"
339 " param.error(\"Unexpected array index in module parameter, expected a valid field\"\n"
340 " \" name for union type `%s'\");\n"
341 " }\n"
342 " ", name, dispname);
343 for (i = 0; i < sdef->nElements; i++) {
344 src = mputprintf(src,
345 "if (strcmp(\"%s\", param_field) == 0) {\n"
346 " %s%s().set_param(param);\n"
347 " return;\n"
348 " } else ",
349 sdef->elements[i].dispname, at_field, sdef->elements[i].name);
350 }
351 src = mputprintf(src,
352 "param.error(\"Field `%%s' not found in union type `%s'\", param_field);\n"
353 " }\n"
354 " param.basic_check(Module_Param::BC_VALUE, \"union value\");\n"
355 " Module_Param_Ptr mp = &param;\n"
356 " if (param.get_type() == Module_Param::MP_Reference) {\n"
357 " mp = param.get_referenced_param();\n"
358 " }\n"
359 " if (mp->get_type()==Module_Param::MP_Value_List && mp->get_size()==0) return;\n"
360 " if (mp->get_type()!=Module_Param::MP_Assignment_List) {\n"
361 " param.error(\"union value with field name was expected\");\n"
362 " }\n"
363 " Module_Param* mp_last = mp->get_elem(mp->get_size()-1);\n", dispname);
364
365 for (i = 0; i < sdef->nElements; i++) {
366 src = mputprintf(src,
367 " if (!strcmp(mp_last->get_id()->get_name(), \"%s\")) {\n"
368 " %s%s().set_param(*mp_last);\n"
369 " return;\n"
370 " }\n", sdef->elements[i].dispname, at_field, sdef->elements[i].name);
371 }
372 src = mputprintf(src,
373 " mp_last->error(\"Field %%s does not exist in type %s.\", mp_last->get_id()->get_name());\n"
374 "}\n\n", dispname);
375
376 /* get param function */
377 def = mputstr(def, "Module_Param* get_param(Module_Param_Name& param_name) const;\n");
378 src = mputprintf(src,
379 "Module_Param* %s::get_param(Module_Param_Name& param_name) const\n"
380 "{\n"
381 " if (!is_bound()) {\n"
382 " return new Module_Param_Unbound();\n"
383 " }\n"
384 " if (param_name.next_name()) {\n"
385 // Haven't reached the end of the module parameter name
386 // => the name refers to one of the fields, not to the whole union
387 " char* param_field = param_name.get_current_name();\n"
388 " if (param_field[0] >= '0' && param_field[0] <= '9') {\n"
389 " TTCN_error(\"Unexpected array index in module parameter reference, \"\n"
390 " \"expected a valid field name for union type `%s'\");\n"
391 " }\n"
392 " ", name, dispname);
393 for (i = 0; i < sdef->nElements; i++) {
394 src = mputprintf(src,
395 "if (strcmp(\"%s\", param_field) == 0) {\n"
396 " return %s%s().get_param(param_name);\n"
397 " } else ",
398 sdef->elements[i].dispname, at_field, sdef->elements[i].name);
399 }
400 src = mputprintf(src,
401 "TTCN_error(\"Field `%%s' not found in union type `%s'\", param_field);\n"
402 " }\n"
403 " Module_Param* mp_field = NULL;\n"
404 " switch(union_selection) {\n"
405 , name);
406 for (i = 0; i < sdef->nElements; ++i) {
407 src = mputprintf(src,
408 " case %s_%s:\n"
409 " mp_field = field_%s->get_param(param_name);\n"
410 " mp_field->set_id(new Module_Param_FieldName(mcopystr(\"%s\")));\n"
411 " break;\n"
412 , selection_prefix, sdef->elements[i].name
413 , sdef->elements[i].name, sdef->elements[i].dispname);
414 }
415 src = mputstr(src,
416 " default:\n"
417 " break;\n"
418 " }\n"
419 " Module_Param_Assignment_List* mp = new Module_Param_Assignment_List();\n"
420 " mp->add_elem(mp_field);\n"
421 " return mp;\n"
422 "}\n\n");
423
424 /* set implicit omit function, recursive */
425 def = mputstr(def, " void set_implicit_omit();\n");
426 src = mputprintf(src,
427 "void %s::set_implicit_omit()\n{\n"
428 "switch (union_selection) {\n", name);
429 for (i = 0; i < sdef->nElements; i++) {
430 src = mputprintf(src,
431 "case %s_%s:\n"
432 "field_%s->set_implicit_omit(); break;\n",
433 selection_prefix, sdef->elements[i].name, sdef->elements[i].name);
434 }
435 src = mputstr(src, "default: break;\n}\n}\n\n");
436
437 /* encode_text function */
438 def = mputstr(def, "void encode_text(Text_Buf& text_buf) const;\n");
439 src = mputprintf(src, "void %s::encode_text(Text_Buf& text_buf) const\n"
440 "{\n"
441 "text_buf.push_int(union_selection);\n"
442 "switch (union_selection) {\n", name);
443 for (i = 0; i < sdef->nElements; i++) {
444 src = mputprintf(src, "case %s_%s:\n"
445 "field_%s->encode_text(text_buf);\n"
446 "break;\n", selection_prefix, sdef->elements[i].name,
447 sdef->elements[i].name);
448 }
449 src = mputprintf(src, "default:\n"
450 "TTCN_error(\"Text encoder: Encoding an unbound value of union type "
451 "%s.\");\n"
452 "}\n"
453 "}\n\n", dispname);
454
455 /* decode_text function */
456 def = mputstr(def, "void decode_text(Text_Buf& text_buf);\n");
457 src = mputprintf(src, "void %s::decode_text(Text_Buf& text_buf)\n"
458 "{\n"
459 "switch ((%s)text_buf.pull_int().get_val()) {\n", name, selection_type);
460 for (i = 0; i < sdef->nElements; i++) {
461 src = mputprintf(src, "case %s_%s:\n"
462 "%s%s().decode_text(text_buf);\n"
463 "break;\n", selection_prefix, sdef->elements[i].name,
464 at_field, sdef->elements[i].name);
465 }
466 src = mputprintf(src, "default:\n"
467 "TTCN_error(\"Text decoder: Unrecognized union selector was received "
468 "for type %s.\");\n"
469 "}\n"
470 "}\n\n", dispname);
471
472 if(ber_needed || raw_needed || text_needed || xer_needed || json_needed)
473 def_encdec(name, &def, &src, ber_needed, raw_needed, text_needed,
474 xer_needed, json_needed, TRUE);
475
476 /* BER functions */
477 if(ber_needed) {
478 def = mputstr(def, "private:\n"
479 "boolean BER_decode_set_selection(const ASN_BER_TLV_t& p_tlv);\n"
480 "public:\n"
481 "boolean BER_decode_isMyMsg(const TTCN_Typedescriptor_t& p_td, "
482 "const ASN_BER_TLV_t& p_tlv);\n");
483
484 /* BER_encode_TLV() */
485 src = mputprintf(src,
486 #ifndef NDEBUG
487 "// written by %s in " __FILE__ " at %d\n"
488 #endif
489 "ASN_BER_TLV_t *%s::BER_encode_TLV("
490 "const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const\n"
491 "{\n"
492 #ifndef NDEBUG
493 , __FUNCTION__, __LINE__
494 #endif
495 , name);
496 if (use_runtime_2) {
497 src = mputstr(src,
498 " if (err_descr) return BER_encode_TLV_negtest(err_descr, p_td, p_coding);\n");
499 }
500 src = mputstr(src,
501 " BER_chk_descr(p_td);\n"
502 " ASN_BER_TLV_t *new_tlv;\n"
503 " TTCN_EncDec_ErrorContext ec_0(\"Alternative '\");\n"
504 " TTCN_EncDec_ErrorContext ec_1;\n"
505 " switch (union_selection) {\n");
506 for (i = 0; i < sdef->nElements; i++) {
507 src = mputprintf(src, " case %s_%s:\n"
508 " ec_1.set_msg(\"%s': \");\n"
509 " new_tlv = field_%s->BER_encode_TLV(%s_descr_, p_coding);\n"
510 " break;\n", selection_prefix, sdef->elements[i].name,
511 sdef->elements[i].dispname,
512 sdef->elements[i].name, sdef->elements[i].typedescrname);
513 } /* for i */
514 src = mputprintf(src, " case %s:\n"
515 " new_tlv = BER_encode_chk_bound(FALSE);\n"
516 " break;\n"
517 " default:\n"
518 " TTCN_EncDec_ErrorContext::error_internal(\"Unknown selection.\");\n"
519 " new_tlv = NULL;\n"
520 " }\n" /* switch */
521 " return ASN_BER_V2TLV(new_tlv, p_td, p_coding);\n"
522 "}\n\n", unbound_value);
523
524 if (use_runtime_2) { /* BER_encode_TLV_negtest() */
525 def = mputstr(def,
526 "ASN_BER_TLV_t* BER_encode_TLV_negtest(const Erroneous_descriptor_t* p_err_descr, const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const;\n");
527 src = mputprintf(src,
528 "ASN_BER_TLV_t *%s::BER_encode_TLV_negtest(const Erroneous_descriptor_t* p_err_descr, "
529 "const TTCN_Typedescriptor_t& p_td, unsigned p_coding) const\n"
530 "{\n"
531 " BER_chk_descr(p_td);\n"
532 " ASN_BER_TLV_t *new_tlv = NULL;\n"
533 " TTCN_EncDec_ErrorContext ec_0(\"Alternative '\");\n"
534 " TTCN_EncDec_ErrorContext ec_1;\n"
535 " const Erroneous_values_t* err_vals = NULL;\n"
536 " const Erroneous_descriptor_t* emb_descr = NULL;\n"
537 " switch (union_selection) {\n", name);
538 for (i = 0; i < sdef->nElements; i++) {
539 src = mputprintf(src, " case %s_%s:\n"
540 " err_vals = p_err_descr->get_field_err_values(%d);\n"
541 " emb_descr = p_err_descr->get_field_emb_descr(%d);\n"
542 " if (err_vals && err_vals->value) {\n"
543 " if (err_vals->value->errval) {\n"
544 " ec_1.set_msg(\"%s'(erroneous value): \");\n"
545 " if (err_vals->value->raw) {\n"
546 " new_tlv = err_vals->value->errval->BER_encode_negtest_raw();\n"
547 " } else {\n"
548 " if (err_vals->value->type_descr==NULL) TTCN_error(\"internal error: erroneous value typedescriptor missing\");\n"
549 " new_tlv = err_vals->value->errval->BER_encode_TLV(*err_vals->value->type_descr, p_coding);\n"
550 " }\n"
551 " }\n"
552 " } else {\n"
553 " ec_1.set_msg(\"%s': \");\n"
554 " if (emb_descr) new_tlv = field_%s->BER_encode_TLV_negtest(emb_descr, %s_descr_, p_coding);\n"
555 " else new_tlv = field_%s->BER_encode_TLV(%s_descr_, p_coding);\n"
556 " }\n"
557 " break;\n", selection_prefix, sdef->elements[i].name,
558 (int)i, (int)i, sdef->elements[i].dispname, sdef->elements[i].dispname,
559 sdef->elements[i].name, sdef->elements[i].typedescrname,
560 sdef->elements[i].name, sdef->elements[i].typedescrname);
561 } /* for i */
562 src = mputprintf(src, " case %s:\n"
563 " new_tlv = BER_encode_chk_bound(FALSE);\n"
564 " break;\n"
565 " default:\n"
566 " TTCN_EncDec_ErrorContext::error_internal(\"Unknown selection.\");\n"
567 " new_tlv = NULL;\n"
568 " }\n" /* switch */
569 " if (new_tlv==NULL) new_tlv=ASN_BER_TLV_t::construct(NULL);\n"
570 " return ASN_BER_V2TLV(new_tlv, p_td, p_coding);\n"
571 "}\n\n", unbound_value);
572 }
573
574 /* BER_decode_set_selection() */
575 src = mputprintf(src, "boolean %s::BER_decode_set_selection("
576 "const ASN_BER_TLV_t& p_tlv)\n"
577 "{\n"
578 " clean_up();\n", name);
579 for (i = 0; i < sdef->nElements; i++) {
580 src = mputprintf(src, " field_%s = new %s;\n"
581 " union_selection = %s_%s;\n"
582 " if (field_%s->BER_decode_isMyMsg(%s_descr_, p_tlv)) return TRUE;\n"
583 " delete field_%s;\n", sdef->elements[i].name, sdef->elements[i].type,
584 selection_prefix, sdef->elements[i].name, sdef->elements[i].name,
585 sdef->elements[i].typedescrname, sdef->elements[i].name);
586 } /* for i */
587 src = mputprintf(src, " union_selection = %s;\n"
588 " return FALSE;\n"
589 "}\n\n", unbound_value);
590
591 /* BER_decode_isMyMsg() */
592 src = mputprintf(src, "boolean %s::BER_decode_isMyMsg("
593 "const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv)\n"
594 "{\n"
595 " if (p_td.ber->n_tags == 0) {\n"
596 " %s tmp_type;\n"
597 " return tmp_type.BER_decode_set_selection(p_tlv);\n"
598 " } else return Base_Type::BER_decode_isMyMsg(p_td, p_tlv);\n"
599 "}\n\n", name, name);
600
601 /* BER_decode_TLV() */
602 src = mputprintf(src, "boolean %s::BER_decode_TLV("
603 "const TTCN_Typedescriptor_t& p_td, const ASN_BER_TLV_t& p_tlv, "
604 "unsigned L_form)\n"
605 "{\n"
606 " BER_chk_descr(p_td);\n"
607 " ASN_BER_TLV_t stripped_tlv;\n"
608 " BER_decode_strip_tags(*p_td.ber, p_tlv, L_form, stripped_tlv);\n"
609 " TTCN_EncDec_ErrorContext ec_0(\"While decoding '%s' type: \");\n",
610 name, dispname);
611 if (sdef->ot) {
612 src = mputprintf(src, " if (!BER_decode_TLV_CHOICE(*p_td.ber, "
613 "stripped_tlv, L_form, tlv_opentype)) {\n"
614 " tlv_opentype.Tlen = 0;\n"
615 " return FALSE;\n"
616 " }\n"
617 " clean_up();\n"
618 " union_selection = %s;\n", unbound_value);
619 } else {
620 src = mputstr(src, " ASN_BER_TLV_t tmp_tlv;\n"
621 " if (!BER_decode_TLV_CHOICE(*p_td.ber, stripped_tlv, L_form, "
622 "tmp_tlv) || "
623 "!BER_decode_CHOICE_selection(BER_decode_set_selection(tmp_tlv), "
624 "tmp_tlv)) return FALSE;\n"
625 " TTCN_EncDec_ErrorContext ec_1(\"Alternative '\");\n"
626 " TTCN_EncDec_ErrorContext ec_2;\n"
627 " switch (union_selection) {\n");
628 for(i = 0; i < sdef->nElements; i++) {
629 src = mputprintf(src, " case %s_%s:\n"
630 " ec_2.set_msg(\"%s': \");\n"
631 " field_%s->BER_decode_TLV(%s_descr_, tmp_tlv, L_form);\n"
632 " break;\n", selection_prefix, sdef->elements[i].name,
633 sdef->elements[i].dispname,
634 sdef->elements[i].name, sdef->elements[i].typedescrname);
635 } /* for i */
636 src = mputstr(src, " default:\n"
637 " return FALSE;\n"
638 " }\n");
639 if (sdef->opentype_outermost) {
640 src = mputstr(src,
641 " TTCN_EncDec_ErrorContext ec_1(\"While decoding opentypes: \");\n"
642 " TTCN_Type_list p_typelist;\n"
643 " BER_decode_opentypes(p_typelist, L_form);\n");
644 } /* if sdef->opentype_outermost */
645 }
646 src = mputstr(src, " return TRUE;\n"
647 "}\n\n");
648
649 if (sdef->ot || sdef->has_opentypes) { /* theoretically, these are
650 mutually exlusive */
651 /* BER_decode_opentypes() */
652 def = mputstr(def, "void BER_decode_opentypes("
653 "TTCN_Type_list& p_typelist, unsigned L_form);\n");
654 src = mputprintf(src, "void %s::BER_decode_opentypes("
655 "TTCN_Type_list& p_typelist, unsigned L_form)\n"
656 "{\n", name);
657 if (sdef->ot) {
658 AtNotationList_t *anl = &sdef->ot->anl;
659 OpentypeAlternativeList_t *oal = &sdef->ot->oal;
660 src = mputprintf(src,
661 " if (union_selection != %s) return;\n"
662 " TTCN_EncDec_ErrorContext ec_0(\"While decoding open type '%s': "
663 "\");\n", unbound_value, dispname);
664 if (oal->nElements > 0) {
665 size_t oal_i, anl_i;
666 char *s2;
667 /* variable declarations - the referenced components */
668 for (anl_i = 0; anl_i < anl->nElements; anl_i++) {
669 AtNotation_t *an = anl->elements + anl_i;
670 src = mputprintf(src, " const %s& f_%lu = static_cast<const %s*>"
671 "(p_typelist.get_nth(%lu))->%s;\n", an->type_name,
672 (unsigned long) (anl_i + 1), an->parent_typename,
673 (unsigned long) an->parent_level, an->sourcecode);
674 } /* for anl_i */
675 src = mputstr(src, " {\n"
676 " TTCN_EncDec_ErrorContext ec_1(\"Alternative '\");\n"
677 " TTCN_EncDec_ErrorContext ec_2;\n");
678 s2 = mprintf("%*s", (int)(anl->nElements + 2) * 2, "");
679 for (oal_i = 0; oal_i < oal->nElements; oal_i++) {
680 size_t if_level;
681 OpentypeAlternative_t *oa = oal->elements + oal_i;
682 if (oal_i > 0) {
683 for (if_level = 0; if_level < anl->nElements; if_level++)
684 if (oa->const_valuenames[if_level]) break;
685 for (i = anl->nElements; i > if_level; i--)
686 src = mputprintf(src, "%*s}\n", (int)(i + 1) * 2, "");
687 } /* if oal_i */
688 else if_level = 0;
689 for (anl_i = if_level; anl_i < anl->nElements; anl_i++) {
690 src = mputprintf(src, "%*s%sif (f_%lu == %s) {\n",
691 (int)(anl_i + 2) * 2, "",
692 oal_i && anl_i <= if_level ? "else " : "",
693 (unsigned long) (anl_i + 1), oa->const_valuenames[anl_i]);
694 } /* for anl_i */
695 src = mputprintf(src, "%sunion_selection = %s_%s;\n"
696 "%sfield_%s = new %s;\n"
697 "%sec_2.set_msg(\"%s': \");\n"
698 "%sfield_%s->BER_decode_TLV(%s_descr_, tlv_opentype, L_form);\n",
699 s2, selection_prefix, oa->alt, s2, oa->alt, oa->alt_typename, s2,
700 oa->alt_dispname, s2, oa->alt, oa->alt_typedescrname);
701 } /* for oal_i */
702 Free(s2);
703 if (oal->nElements > 0)
704 for (i = anl->nElements; i > 0; i--)
705 src = mputprintf(src, "%*s}\n", (int)(i+1)*2, "");
706 src = mputprintf(src, " }\n"
707 " if (union_selection == %s) {\n"
708 " ec_0.error(TTCN_EncDec::ET_DEC_OPENTYPE, \"Cannot decode "
709 "open type: broken component relation constraint.\");\n"
710 " if (TTCN_EncDec::get_error_behavior("
711 "TTCN_EncDec::ET_DEC_OPENTYPE) != TTCN_EncDec::EB_IGNORE) {\n"
712 " TTCN_Logger::log_str(TTCN_WARNING, \"The value%s of"
713 " constraining component%s:\");\n", unbound_value,
714 anl->nElements > 1 ? "s" : "", anl->nElements > 1 ? "s" : "");
715 for (anl_i = 0; anl_i < anl->nElements; anl_i++) {
716 AtNotation_t *an = anl->elements + anl_i;
717 src = mputprintf(src,
718 " TTCN_Logger::begin_event(TTCN_WARNING);\n"
719 " TTCN_Logger::log_event_str(\"Component '%s': \");\n"
720 " f_%lu.log();\n"
721 " TTCN_Logger::end_event();\n", an->dispname,
722 (unsigned long) (anl_i + 1));
723 } /* for anl_i */
724 src = mputstr(src, " }\n"
725 " }\n");
726 } /* if oal->nElements>0 */
727 else {
728 src = mputstr(src, " ec_0.error(TTCN_EncDec::ET_DEC_OPENTYPE, "
729 "\"Cannot decode open type: the constraining object set is "
730 "empty.\");\n");
731 } /* oal->nElements==0 */
732 } /* if sdef->ot */
733 else { /* if !sdef->ot (but has_opentypes) */
734 src = mputstr(src,
735 " p_typelist.push(this);\n"
736 " TTCN_EncDec_ErrorContext ec_0(\"Alternative '\");\n"
737 " TTCN_EncDec_ErrorContext ec_1;\n"
738 " switch (union_selection) {\n");
739 for (i = 0; i < sdef->nElements; i++) {
740 src = mputprintf(src, " case %s_%s:\n"
741 " ec_1.set_msg(\"%s': \");\n"
742 " field_%s->BER_decode_opentypes(p_typelist, L_form);\n"
743 " break;\n", selection_prefix, sdef->elements[i].name,
744 sdef->elements[i].dispname, sdef->elements[i].name);
745 } /* for i */
746 src = mputstr(src, " default:\n"
747 " break;\n"
748 " }\n"
749 " p_typelist.pop();\n");
750 } /* if has opentypes */
751 src = mputstr(src, "}\n"
752 "\n");
753 } /* if sdef->ot || sdef->has_opentypes */
754 } /* if ber_needed */
755
756 if (raw_needed) {
757 size_t nTemp_variables = 0;
758 temporal_variable* temp_variable_list = NULL;
759 int* tag_type = (int*) Malloc(sdef->nElements*sizeof(int));
760 memset(tag_type, 0, sdef->nElements * sizeof(int));
761 if (sdef->hasRaw) { /* fill tag_type. 0-No tag, >0 index of the tag + 1 */
762 for (i = 0; i < sdef->raw.taglist.nElements; i++) {
763 if (sdef->raw.taglist.list[i].nElements) {
764 boolean found = FALSE;
765 size_t v;
766 for (v = 0; v < sdef->raw.taglist.list[i].nElements; v++) {
767 if (sdef->raw.taglist.list[i].fields[v].start_pos >= 0) {
768 found = TRUE;
769 break;
770 }
771 }
772 if (found)
773 tag_type[sdef->raw.taglist.list[i].fieldnum] = i + 1;
774 else
775 tag_type[sdef->raw.taglist.list[i].fieldnum] = -i - 1;
776 }
777 }
778 }
779 src = mputprintf(src, "int %s::RAW_decode(\n"
780 "const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, int limit, \n"
781 "raw_order_t top_bit_ord, boolean no_err, int sel_field, boolean)\n"
782 "{\n"
783 " int prepaddlength=p_buf.increase_pos_padd(p_td.raw->prepadding);\n"
784 " limit-=prepaddlength;\n"
785 " int decoded_length=0;\n"
786 " int starting_pos=p_buf.get_pos_bit();\n"
787 " if(sel_field!=-1){\n"
788 " switch(sel_field){\n", name);
789 for (i = 0; i < sdef->nElements; i++) {
790 src = mputprintf(src,
791 " case %lu:\n"
792 " decoded_length = %s().RAW_decode(%s_descr_, p_buf, limit, "
793 "top_bit_ord, no_err);\n"
794 " break;\n", (unsigned long) i, sdef->elements[i].name,
795 sdef->elements[i].typedescrname);
796 }
797 src = mputstr(src, " default: break;\n"
798 " }\n"
799 " return decoded_length + p_buf.increase_pos_padd(p_td.raw->padding) + "
800 "prepaddlength;\n"
801 " } else {\n");
802 /* only generate this variable if it will be used */
803 for (i = 0; i < sdef->nElements; i++) {
804 if ((tag_type[i] > 0)
805 && (sdef->raw.taglist.list + tag_type[i] - 1)->nElements) {
806 src = mputstr(src, " boolean already_failed = FALSE;\n"
807 " raw_order_t local_top_order;\n");
808 break;
809 }
810 }
811
812 /* precalculate what we know about the temporal variables*/
813 for (i = 0; i < sdef->nElements; i++) {
814 if ((tag_type[i] > 0)
815 && (sdef->raw.taglist.list + tag_type[i] - 1)->nElements) {
816 rawAST_coding_taglist* cur_choice = sdef->raw.taglist.list + tag_type[i] - 1;
817 size_t j;
818 for (j = 0; j < cur_choice->nElements; j++) {
819 rawAST_coding_field_list *fieldlist = cur_choice->fields + j;
820 if (fieldlist->start_pos >= 0) {
821 size_t k;
822 boolean found = FALSE;
823 for (k = 0; k < nTemp_variables; k++) {
824 if (temp_variable_list[k].start_pos == fieldlist->start_pos
825 && !strcmp(temp_variable_list[k].typedescr,
826 fieldlist->fields[fieldlist->nElements - 1].typedescr)) {
827 temp_variable_list[k].use_counter++;
828 fieldlist->temporal_variable_index = k;
829 found = TRUE;
830 break;
831 }
832 }
833 if (!found) {
834 temp_variable_list
835 = (temporal_variable*) Realloc(temp_variable_list,
836 (nTemp_variables + 1) * sizeof(*temp_variable_list));
837 temp_variable_list[nTemp_variables].type
838 = fieldlist->fields[fieldlist->nElements - 1].type;
839 temp_variable_list[nTemp_variables].typedescr
840 = fieldlist->fields[fieldlist->nElements - 1].typedescr;
841 temp_variable_list[nTemp_variables].start_pos
842 = fieldlist->start_pos;
843 temp_variable_list[nTemp_variables].use_counter = 1;
844 temp_variable_list[nTemp_variables].decoded_for_element
845 = -1;
846 fieldlist->temporal_variable_index = nTemp_variables;
847 nTemp_variables++;
848 }
849 }
850 }
851 }
852 }
853
854 for (i = 0; i < nTemp_variables; i++) {
855 if (temp_variable_list[i].use_counter > 1) {
856 src = mputprintf(src, " %s temporal_%lu;\n"
857 " int decoded_%lu_length;\n", temp_variable_list[i].type,
858 (unsigned long) i, (unsigned long) i);
859 }
860 }
861
862 for (i = 0; i < sdef->nElements; i++) { /* fields with tag */
863 if ((tag_type[i] > 0)
864 && (sdef->raw.taglist.list + tag_type[i] - 1)->nElements) {
865 rawAST_coding_taglist* cur_choice = sdef->raw.taglist.list
866 + tag_type[i] - 1;
867 size_t j;
868 src = mputstr(src, " already_failed = FALSE;\n");
869 /* first check the fields we can precode
870 * try to decode those key variables whose position we know
871 * this way we might be able to step over bad values faster
872 */
873 for (j = 0; j < cur_choice->nElements; j++) {
874 rawAST_coding_field_list *cur_field_list = cur_choice->fields + j;
875 if (cur_field_list->start_pos >= 0) {
876 size_t k;
877 size_t variable_index = cur_field_list->temporal_variable_index;
878 if (temp_variable_list[variable_index].decoded_for_element == i) continue;
879 src = mputstr(src, " if (!already_failed) {\n");
880 if (temp_variable_list[variable_index].use_counter == 1) {
881 src = mputprintf(src, " %s temporal_%lu;\n"
882 " int decoded_%lu_length;\n",
883 temp_variable_list[variable_index].type,
884 (unsigned long) variable_index, (unsigned long) variable_index);
885 }
886 if (temp_variable_list[variable_index].decoded_for_element
887 == -1) {
888 src = mputstr(src, " ");
889 for (k = cur_field_list->nElements - 1; k > 0; k--) {
890 src = mputprintf(src,
891 " if(%s_descr_.raw->top_bit_order==TOP_BIT_RIGHT)"
892 "local_top_order=ORDER_MSB;\n"
893 " else if(%s_descr_.raw->top_bit_order==TOP_BIT_LEFT)"
894 "local_top_order=ORDER_LSB;\n"
895 " else", cur_field_list->fields[k - 1].typedescr,
896 cur_field_list->fields[k - 1].typedescr);
897 }
898 src = mputprintf(src, " local_top_order=top_bit_ord;\n"
899 " p_buf.set_pos_bit(starting_pos + %d);\n"
900 " decoded_%lu_length = temporal_%lu.RAW_decode("
901 "%s_descr_, p_buf, limit, top_bit_ord, TRUE);\n",
902 cur_field_list->start_pos, (unsigned long) variable_index,
903 (unsigned long) variable_index,
904 temp_variable_list[variable_index].typedescr);
905 }
906 temp_variable_list[variable_index].decoded_for_element = i;
907 src = mputprintf(src, " if (decoded_%lu_length > 0) {\n"
908 " if (temporal_%lu == %s", (unsigned long) variable_index,
909 (unsigned long) variable_index, cur_field_list->value);
910 for (k = j + 1; k < cur_choice->nElements; k++) {
911 if (cur_choice->fields[k].temporal_variable_index
912 == variable_index) {
913 src = mputprintf(src, " || temporal_%lu == %s",
914 (unsigned long) variable_index, cur_choice->fields[k].value);
915 }
916 }
917 src = mputprintf(src, ") {\n"
918 " p_buf.set_pos_bit(starting_pos);\n"
919 " decoded_length = %s().RAW_decode(%s_descr_, p_buf, "
920 "limit, top_bit_ord, TRUE);\n"
921 " if (decoded_length > 0) {\n", sdef->elements[i].name,
922 sdef->elements[i].typedescrname);
923 src = mputstr(src, " if (");
924 src = genRawFieldChecker(src, cur_choice, TRUE);
925 src = mputstr(src, ") {\n"
926 " return decoded_length + "
927 "p_buf.increase_pos_padd(p_td.raw->padding) + prepaddlength;\n"
928 " }else already_failed = TRUE;\n"
929 " }\n"
930 " }\n"
931 " }\n"
932 " }\n");
933 }
934 }
935 /* if there is one tag key whose position we don't know
936 * and we couldn't decide yet if the element can be decoded or not
937 * than we have to decode it.
938 * note that this is not actually a cycle because of the break
939 */
940 for (j = 0; j < cur_choice->nElements; j++) {
941 if (cur_choice->fields[j].start_pos < 0) {
942 src = mputprintf(src, " if (already_failed) {\n"
943 " p_buf.set_pos_bit(starting_pos);\n"
944 " decoded_length = %s().RAW_decode(%s_descr_, p_buf, limit, "
945 "top_bit_ord, TRUE);\n"
946 " if (decoded_length > 0) {\n", sdef->elements[i].name,
947 sdef->elements[i].typedescrname);
948 src = mputstr(src, " if (");
949 src = genRawFieldChecker(src, cur_choice, TRUE);
950 src = mputstr(src, ") {\n"
951 " return decoded_length + "
952 "p_buf.increase_pos_padd(p_td.raw->padding) + prepaddlength;\n"
953 " }\n"
954 " }\n"
955 " }\n");
956 break;
957 }
958 }
959 }
960 }
961 Free(temp_variable_list);
962 for (i = 0; i < sdef->nElements; i++) { /* fields with only variable tag */
963 if ((tag_type[i] < 0)
964 && (sdef->raw.taglist.list - tag_type[i] - 1)->nElements) {
965 rawAST_coding_taglist* cur_choice = sdef->raw.taglist.list
966 - tag_type[i] - 1;
967 src = mputprintf(src, " p_buf.set_pos_bit(starting_pos);\n"
968 " decoded_length = %s().RAW_decode(%s_descr_, p_buf, limit, "
969 "top_bit_ord, TRUE);\n"
970 " if (decoded_length >= 0) {\n", sdef->elements[i].name,
971 sdef->elements[i].typedescrname);
972 src = mputstr(src, " if (");
973 src = genRawFieldChecker(src, cur_choice, TRUE);
974 src = mputstr(src, ") {\n"
975 " return decoded_length + "
976 "p_buf.increase_pos_padd(p_td.raw->padding) + prepaddlength;\n"
977 " }\n"
978 " }\n");
979 }
980 }/**/
981 for (i = 0; i < sdef->nElements; i++) { /* fields without tag */
982 if (!tag_type[i]) {
983 src = mputprintf(src, " p_buf.set_pos_bit(starting_pos);\n"
984 " decoded_length = %s().RAW_decode(%s_descr_, p_buf, limit, "
985 "top_bit_ord, TRUE);\n"
986 " if (decoded_length >= 0) {\n", sdef->elements[i].name,
987 sdef->elements[i].typedescrname);
988 src = mputstr(src, " return decoded_length + "
989 "p_buf.increase_pos_padd(p_td.raw->padding) + prepaddlength;\n"
990 " }\n");
991 }
992 }/**/
993 src = mputstr(src, " }\n"
994 " clean_up();\n"
995 " return -1;\n"
996 "}\n\n");
997 /* encoder */
998 src = mputprintf(src, "int %s::RAW_encode("
999 "const TTCN_Typedescriptor_t&%s, RAW_enc_tree& myleaf) const\n"
1000 "{\n", name, use_runtime_2 ? " p_td" : "");
1001 if (use_runtime_2) {
1002 src = mputstr(src, " if (err_descr) return RAW_encode_negtest(err_descr, p_td, myleaf);\n");
1003 }
1004 src = mputprintf(src,
1005 " int encoded_length = 0;\n"
1006 " myleaf.isleaf = FALSE;\n"
1007 " myleaf.body.node.num_of_nodes = %lu;"
1008 " myleaf.body.node.nodes = init_nodes_of_enc_tree(%lu);\n"
1009 " memset(myleaf.body.node.nodes, 0, %lu * sizeof(RAW_enc_tree *));\n"
1010 " switch (union_selection) {\n", (unsigned long)sdef->nElements,
1011 (unsigned long)sdef->nElements, (unsigned long)sdef->nElements);
1012 for (i = 0; i < sdef->nElements; i++) {
1013 int t_type = tag_type[i] > 0 ? tag_type[i] : -tag_type[i];
1014 src = mputprintf(src, " case %s_%s:\n"
1015 " myleaf.body.node.nodes[%lu] = new RAW_enc_tree(TRUE, &myleaf, "
1016 "&myleaf.curr_pos, %lu, %s_descr_.raw);\n"
1017 " encoded_length = field_%s->RAW_encode(%s_descr_, "
1018 "*myleaf.body.node.nodes[%lu]);\n"
1019 " myleaf.body.node.nodes[%lu]->coding_descr = &%s_descr_;\n",
1020 selection_prefix, sdef->elements[i].name, (unsigned long) i,
1021 (unsigned long) i, sdef->elements[i].typedescrname,
1022 sdef->elements[i].name, sdef->elements[i].typedescrname,
1023 (unsigned long) i, (unsigned long) i, sdef->elements[i].typedescrname);
1024 if (t_type && (sdef->raw.taglist.list + t_type - 1)->nElements) {
1025 rawAST_coding_taglist* cur_choice = sdef->raw.taglist.list + t_type - 1;
1026 src = mputstr(src, " if (");
1027 src = genRawFieldChecker(src, cur_choice, FALSE);
1028 src = mputstr(src, ") {\n");
1029 src = genRawTagChecker(src, cur_choice);
1030 src = mputstr(src, " }\n");
1031 }
1032 src = mputstr(src, " break;\n");
1033 }
1034 src = mputstr(src, " default:\n"
1035 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "
1036 "\"Encoding an unbound value.\");\n"
1037 " }\n"
1038 " return encoded_length;\n"
1039 "}\n\n");
1040 if (use_runtime_2) {
1041 def = mputstr(def, "int RAW_encode_negtest(const Erroneous_descriptor_t *, "
1042 "const TTCN_Typedescriptor_t&, RAW_enc_tree&) const;\n");
1043 src = mputprintf(src, "int %s::RAW_encode_negtest(const Erroneous_descriptor_t *p_err_descr, "
1044 "const TTCN_Typedescriptor_t& /*p_td*/, RAW_enc_tree& myleaf) const\n"
1045 "{\n"
1046 " const Erroneous_values_t *err_vals = NULL;\n"
1047 " const Erroneous_descriptor_t *emb_descr = NULL;\n"
1048 " int encoded_length = 0;\n"
1049 " myleaf.isleaf = FALSE;\n"
1050 " myleaf.body.node.num_of_nodes = %lu;\n"
1051 " myleaf.body.node.nodes = init_nodes_of_enc_tree(%lu);\n"
1052 " memset(myleaf.body.node.nodes, 0, %lu * sizeof(RAW_enc_tree *));\n"
1053 " switch (union_selection) {\n", name, (unsigned long)sdef->nElements,
1054 (unsigned long)sdef->nElements, (unsigned long)sdef->nElements);
1055 for (i = 0; i < sdef->nElements; i++) {
1056 int t_type = tag_type[i] > 0 ? tag_type[i] : -tag_type[i];
1057 src = mputprintf(src,
1058 " case %s_%s: {\n",
1059 selection_prefix, sdef->elements[i].name);
1060 if (t_type && (sdef->raw.taglist.list + t_type - 1)->nElements) {
1061 src = mputstr(src, " bool negtest_confl_tag = false;\n");
1062 }
1063 src = mputprintf(src,
1064 " err_vals = p_err_descr->get_field_err_values(%d);\n"
1065 " emb_descr = p_err_descr->get_field_emb_descr(%d);\n"
1066 " if (err_vals && err_vals->value) {\n"
1067 " if (err_vals->value->raw) {\n"
1068 " myleaf.body.node.nodes[%lu] =\n"
1069 " new RAW_enc_tree(TRUE, &myleaf, &myleaf.curr_pos, %lu, "
1070 "err_vals->value->errval->get_descriptor()->raw);\n"
1071 " encoded_length = err_vals->value->errval->RAW_encode_negtest_raw(*myleaf.body.node.nodes[%lu]);\n"
1072 " myleaf.body.node.nodes[%lu]->coding_descr = err_vals->value->errval->get_descriptor();\n"
1073 " } else {\n"
1074 " if (err_vals->value->errval) {\n"
1075 " if (err_vals->value->type_descr == NULL)\n"
1076 " TTCN_error(\"internal error: erroneous value typedescriptor missing\");\n"
1077 " myleaf.body.node.nodes[%lu] = new RAW_enc_tree(TRUE, &myleaf, &myleaf.curr_pos, %lu, err_vals->value->type_descr->raw);\n"
1078 " encoded_length = err_vals->value->errval->RAW_encode(*err_vals->value->type_descr, *myleaf.body.node.nodes[%lu]);\n"
1079 " myleaf.body.node.nodes[%lu]->coding_descr = err_vals->value->type_descr;\n"
1080 " }\n"
1081 " }\n",
1082 (int)i, (int)i,
1083 (unsigned long)i, (unsigned long)i,
1084 (unsigned long)i, (unsigned long)i, (unsigned long)i,
1085 (unsigned long)i, (unsigned long)i, (unsigned long)i);
1086 if (t_type && (sdef->raw.taglist.list + t_type - 1)->nElements) {
1087 /* Avoid TAGs. */
1088 src = mputprintf(src, " negtest_confl_tag = true;\n");
1089 }
1090 src = mputprintf(src,
1091 " } else {\n"
1092 " myleaf.body.node.nodes[%lu] = new RAW_enc_tree(TRUE, "
1093 "&myleaf, &myleaf.curr_pos, %lu, %s_descr_.raw);\n"
1094 " if (emb_descr) {\n",
1095 (unsigned long)i, (unsigned long)i, sdef->elements[i].typedescrname);
1096 if (t_type && (sdef->raw.taglist.list + t_type - 1)->nElements) {
1097 /* Avoid TAGs. */
1098 src = mputprintf(src, " negtest_confl_tag = true;\n");
1099 }
1100 src = mputprintf(src,
1101 " encoded_length = field_%s->RAW_encode_negtest(emb_descr, %s_descr_, *myleaf.body.node.nodes[%lu]);\n"
1102 " } else encoded_length = field_%s->RAW_encode(%s_descr_, *myleaf.body.node.nodes[%lu]);\n"
1103 " myleaf.body.node.nodes[%lu]->coding_descr = &%s_descr_;\n"
1104 " }\n",
1105 sdef->elements[i].name, sdef->elements[i].typedescrname,
1106 (unsigned long)i, sdef->elements[i].name,
1107 sdef->elements[i].typedescrname, (unsigned long)i, (unsigned long)i,
1108 sdef->elements[i].typedescrname);
1109 if (t_type && (sdef->raw.taglist.list + t_type - 1)->nElements) {
1110 rawAST_coding_taglist *cur_choice = sdef->raw.taglist.list + t_type - 1;
1111 src = mputprintf(src,
1112 " if (negtest_confl_tag) {\n"
1113 " TTCN_EncDec_ErrorContext e_c;\n"
1114 " e_c.set_msg(\"Field '%s': \");\n"
1115 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_NEGTEST_CONFL,\n"
1116 " \"Conflicting negative testing attributes, TAG attribute "
1117 "will be ignored\");\n"
1118 " }\n"
1119 " if (!negtest_confl_tag && (", sdef->elements[i].name);
1120 src = genRawFieldChecker(src, cur_choice, FALSE);
1121 src = mputstr(src, ")) {\n");
1122 src = genRawTagChecker(src, cur_choice);
1123 src = mputstr(src, " }\n");
1124 }
1125 src = mputstr(src, " break; }\n");
1126 }
1127 src = mputstr(src, " default:\n"
1128 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "
1129 "\"Encoding an unbound value.\");\n"
1130 " }\n"
1131 " return encoded_length;\n"
1132 "}\n\n");
1133 }
1134 Free(tag_type);
1135 } /* if raw_needed */
1136
1137 if (text_needed) {
1138 src = mputprintf(src, "int %s::TEXT_encode("
1139 "const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf) const\n"
1140 "{\n", name);
1141 if (use_runtime_2) {
1142 src = mputstr(src, " if (err_descr) return TEXT_encode_negtest(err_descr, p_td, p_buf);\n");
1143 }
1144 src = mputstr(src, " int encoded_length=0;\n"
1145 " if (p_td.text->begin_encode) {\n"
1146 " p_buf.put_cs(*p_td.text->begin_encode);\n"
1147 " encoded_length += p_td.text->begin_encode->lengthof();\n"
1148 " }\n"
1149 " switch(union_selection){\n");
1150 for (i = 0; i < sdef->nElements; i++) {
1151 src = mputprintf(src, " case %s_%s:\n"
1152 " encoded_length += field_%s->TEXT_encode(%s_descr_,p_buf);\n"
1153 " break;\n", selection_prefix, sdef->elements[i].name,
1154 sdef->elements[i].name, sdef->elements[i].typedescrname);
1155 }
1156 src = mputstr(src, " default:\n"
1157 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "
1158 "\"Encoding an unbound value.\");\n"
1159 " break;\n"
1160 " }\n"
1161 " if (p_td.text->end_encode) {\n"
1162 " p_buf.put_cs(*p_td.text->end_encode);\n"
1163 " encoded_length += p_td.text->end_encode->lengthof();\n"
1164 " }\n"
1165 " return encoded_length;\n"
1166 "}\n\n");
1167 if (use_runtime_2) {/*TEXT_encde_negtest()*/
1168 def = mputstr(def,
1169 "int TEXT_encode_negtest(const Erroneous_descriptor_t* p_err_descr, const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf) const;\n");
1170 src = mputprintf(src, "int %s::TEXT_encode_negtest("
1171 "const Erroneous_descriptor_t* p_err_descr, const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf) const\n"
1172 "{\n"
1173 " int encoded_length=0;\n"
1174 " const Erroneous_values_t* err_vals = NULL;\n"
1175 " const Erroneous_descriptor_t* emb_descr = NULL;\n"
1176 " if (p_td.text->begin_encode) {\n"
1177 " p_buf.put_cs(*p_td.text->begin_encode);\n"
1178 " encoded_length += p_td.text->begin_encode->lengthof();\n"
1179 " }\n"
1180 " switch(union_selection){\n", name);
1181 for (i = 0; i < sdef->nElements; i++) {
1182 src = mputprintf(src, " case %s_%s:\n"
1183 " err_vals = p_err_descr->get_field_err_values(%d);\n"
1184 " emb_descr = p_err_descr->get_field_emb_descr(%d);\n"
1185 " if (err_vals && err_vals->value){\n"
1186 " if (err_vals->value->errval) {\n"
1187 " if(err_vals->value->raw){\n"
1188 " encoded_length += err_vals->value->errval->encode_raw(p_buf);\n"
1189 " }else{\n"
1190 " if (err_vals->value->type_descr==NULL) TTCN_error(\"internal error: erroneous value typedescriptor missing\");\n"
1191 " encoded_length += err_vals->value->errval->TEXT_encode(*err_vals->value->type_descr,p_buf);\n"
1192 " }\n"
1193 " }\n"
1194 " }else{\n"
1195 " if (emb_descr) encoded_length += field_%s->TEXT_encode_negtest(emb_descr,%s_descr_,p_buf);\n"
1196 " else field_%s->TEXT_encode(%s_descr_,p_buf);\n"
1197 " }\n"
1198 " break;\n", selection_prefix, sdef->elements[i].name,(int)i,(int)i,
1199 sdef->elements[i].name, sdef->elements[i].typedescrname, sdef->elements[i].name, sdef->elements[i].typedescrname);
1200 }
1201 src = mputstr(src, " default:\n"
1202 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, "
1203 "\"Encoding an unbound value.\");\n"
1204 " break;\n"
1205 " }\n"
1206 " if (p_td.text->end_encode) {\n"
1207 " p_buf.put_cs(*p_td.text->end_encode);\n"
1208 " encoded_length += p_td.text->end_encode->lengthof();\n"
1209 " }\n"
1210 " return encoded_length;\n"
1211 "}\n\n");
1212 }
1213
1214 src = mputprintf(src, "int %s::TEXT_decode("
1215 "const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, "
1216 "Limit_Token_List& limit, boolean no_err, boolean)\n"
1217 "{\n"
1218 " int decoded_length = 0;\n"
1219 " if(p_td.text->begin_decode){\n"
1220 " int tl = p_td.text->begin_decode->match_begin(p_buf);\n"
1221 " if (tl >= 0) {\n"
1222 " decoded_length += tl;\n"
1223 " p_buf.increase_pos(tl);\n"
1224 " } else {\n"
1225 " if (no_err) return -1;\n"
1226 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_TOKEN_ERR, "
1227 "\"The specified token '%%s' not found for '%%s': \", "
1228 "(const char*)(*p_td.text->begin_decode), p_td.name);\n"
1229 " return 0;\n"
1230 " }\n"
1231 " }\n"
1232 " if (p_buf.get_read_len() < 1 && no_err) return -1;\n"
1233 "%s"
1234 " int ml = 0;\n"
1235 " boolean found = FALSE;\n"
1236 " if (p_td.text->end_decode) {\n"
1237 " limit.add_token(p_td.text->end_decode);\n"
1238 " ml++;\n"
1239 " }\n", name, sdef->nElements > 1 ? " size_t pos = p_buf.get_pos();\n" : "");
1240 if (sdef->nElements > 0) {
1241 src = mputprintf(src,
1242 " int str_len = %s().TEXT_decode(%s_descr_, p_buf, limit, true);\n"
1243 " if (str_len >= 0) found = TRUE;\n", sdef->elements[0].name,
1244 sdef->elements[0].typedescrname);
1245 }
1246 for (i = 1; i < sdef->nElements; i++) {
1247 src = mputprintf(src, " if (!found) {\n"
1248 " p_buf.set_pos(pos);\n"
1249 " str_len = %s().TEXT_decode(%s_descr_, p_buf, limit, true);\n"
1250 " if (str_len >= 0) found = TRUE;\n"
1251 " }\n", sdef->elements[i].name, sdef->elements[i].typedescrname);
1252 }
1253 src = mputstr(src, " limit.remove_tokens(ml);\n"
1254 " if (found) {\n"
1255 " decoded_length += str_len;\n"
1256 " if (p_td.text->end_decode) {\n"
1257 " int tl = p_td.text->end_decode->match_begin(p_buf);\n"
1258 " if (tl >= 0){\n"
1259 " decoded_length += tl;\n"
1260 " p_buf.increase_pos(tl);\n"
1261 " } else {\n"
1262 " if (no_err) return -1;\n"
1263 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_TOKEN_ERR, "
1264 "\"The specified token '%s' not found for '%s': \", "
1265 "(const char*)(*p_td.text->end_decode), p_td.name);\n"
1266 " }\n"
1267 " }\n"
1268 " } else {\n"
1269 " if (no_err) return -1;\n"
1270 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_TOKEN_ERR, "
1271 "\"No union member found for '%s': \", p_td.name);\n"
1272 " clean_up();\n"
1273 " }\n"
1274 " return decoded_length;\n"
1275 "}\n");
1276 }
1277
1278 if (xer_needed) { /* XERSTUFF encoder functions for union */
1279 def = mputstr(def,
1280 "char **collect_ns(const XERdescriptor_t& p_td, size_t& num, bool& def_ns) const;\n");
1281
1282 src=mputprintf(src,
1283 "boolean %s::can_start(const char *name, const char *uri,"
1284 " const XERdescriptor_t& xd, unsigned int flavor) {\n"
1285 " boolean exer = is_exer(flavor);\n"
1286 " if (!exer || (!(xd.xer_bits & UNTAGGED) && !(flavor & (USE_NIL|(exer ? XER_LIST : XER_RECOF))))) "
1287 /* If the union has no own tag, there is nothing to check. */
1288 "return check_name(name, xd, exer)" /* if false, return immediately */
1289 " && (!exer || (flavor & USE_TYPE_ATTR) || check_namespace(uri, xd));\n"
1290 /* else check the ns, unless Basic XER (which has no namespaces, ever)
1291 * or USE_TYPE (where we only have a name from the type id attribute) */
1292 , name
1293 );
1294 src = mputstr(src, " flavor &= ~XER_RECOF;\n");
1295
1296 /* An untagged union can start with the start tag of any alternative */
1297 for (i = 0; i < sdef->nElements; i++) {
1298 src=mputprintf(src,
1299 " if (%s::can_start(name, uri, %s_xer_, flavor)) return true;\n"
1300 , sdef->elements[i].type, sdef->elements[i].typegen
1301 );
1302 }
1303 src = mputstr(src, " return false;\n}\n\n");
1304
1305 src = mputprintf(src,
1306 "char ** %s::collect_ns(const XERdescriptor_t& p_td, size_t& num, bool& def_ns) const {\n"
1307 " size_t num_collected;\n"
1308 " char **collected_ns = Base_Type::collect_ns(p_td, num_collected, def_ns);\n"
1309 /* Two-level new memory allocated */
1310 " char **new_ns;\n"
1311 " size_t num_new;\n"
1312 " boolean need_type = FALSE;\n"
1313 " try {\n"
1314 " bool def_ns_1 = false;\n"
1315 " switch (union_selection) {\n"
1316 , name
1317 );
1318 for (i = 0; i < sdef->nElements; i++) {
1319 src = mputprintf(src,
1320 " case %s_%s:\n"
1321 " new_ns = field_%s->collect_ns(%s_xer_, num_new, def_ns_1);\n"
1322 " def_ns = def_ns || def_ns_1;\n" /* alas, no ||= */
1323 " merge_ns(collected_ns, num_collected, new_ns, num_new);\n"
1324 /* merge_ns() deallocated new_ns and duplicated strings,
1325 * copied the new ones into the expanded new_ns */
1326 , selection_prefix, sdef->elements[i].name
1327 , sdef->elements[i].name
1328 , sdef->elements[i].typegen
1329 );
1330 /* Type id attribute not needed for the first field in case of USE-TYPE */
1331 if (sdef->xerUseUnion || i > 0) src = mputprintf(src,
1332 " need_type = (%s_xer_.namelens[1] > 2);\n"
1333 , sdef->elements[i].typegen);
1334 src = mputstr(src, " break;\n");
1335 }
1336
1337 src = mputstr(src,
1338 " default: break;\n"
1339 " }\n" /* switch */
1340 " if ((p_td.xer_bits & USE_TYPE_ATTR) && !(p_td.xer_bits & XER_ATTRIBUTE) && need_type) {\n"
1341 /* control ns for type attribute */
1342 " collected_ns = (char**)Realloc(collected_ns, sizeof(char*) * ++num_collected);\n"
1343 " const namespace_t *c_ns = p_td.my_module->get_controlns();\n"
1344 " collected_ns[num_collected-1] = mprintf(\" xmlns:%s='%s'\", c_ns->px, c_ns->ns);\n"
1345 " }\n"
1346 " }\n"
1347 " catch (...) {\n"
1348 /* Probably a TC_Error thrown from field_%s->collect_ns() if e.g.
1349 * encoding an unbound value. */
1350 " while (num_collected > 0) Free(collected_ns[--num_collected]);\n"
1351 " Free(collected_ns);\n"
1352 " throw;\n"
1353 " }\n"
1354 " num = num_collected;\n"
1355 " return collected_ns;\n"
1356 "}\n\n"
1357 );
1358
1359 src = mputprintf(src, /* XERSTUFF XER_encode for union */
1360 "int %s::XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, "
1361 "unsigned int p_flavor, int p_indent, embed_values_enc_struct_t*) const\n"
1362 "{\n"
1363 "%s"
1364 " if (%s==union_selection) {\n"
1365 " TTCN_error(\"Attempt to XER-encode an unbound union value.\");\n"
1366 " return 0;\n"
1367 " }\n"
1368 " TTCN_EncDec_ErrorContext ec_0(\"Alternative '\");\n"
1369 " TTCN_EncDec_ErrorContext ec_1;\n"
1370 " int encoded_length=(int)p_buf.get_len();\n"
1371 , name
1372 , (use_runtime_2 ? " if (err_descr) return XER_encode_negtest"
1373 "(err_descr, p_td, p_buf, p_flavor, p_indent, 0);\n" : "")
1374 , unbound_value
1375 );
1376
1377 if (sdef->xerUseTypeAttr) {
1378 src = mputstr(src,
1379 " const boolean e_xer = is_exer(p_flavor);\n"
1380 " char *type_atr = NULL;\n"
1381 " unsigned short name_len = 0;\n"
1382 " if (e_xer && (p_td.xer_bits & USE_TYPE_ATTR)) {\n"
1383 " const char *type_name = 0;\n"
1384 " const namespace_t *control_ns;\n"
1385 " switch (union_selection) {\n");
1386 /* In case of USE-TYPE the first field won't need the type attribute */
1387 int start_at = sdef->xerUseUnion ? 0 : 1;
1388 for (i = start_at; i < sdef->nElements; i++) {
1389 src = mputprintf(src,
1390 " case %s_%s:\n"
1391 " type_name = %s_xer_.names[1];\n"
1392 " name_len = %s_xer_.namelens[1] - 2;\n"
1393 " %s\n"
1394 , selection_prefix, sdef->elements[i].name
1395 , sdef->elements[i].typegen
1396 , sdef->elements[i].typegen
1397 , i < sdef->nElements - 1 ? "goto write_atr;" : "" /* no break */
1398 );
1399 }
1400 src = mputprintf(src,
1401 "%s" /* label only if more than two elements total */
1402 " if (name_len > 0) {\n" /* 38.3.8, no atr if NAME AS "" */
1403 " control_ns = p_td.my_module->get_controlns();\n"
1404 " type_atr = mcopystr(\" \");\n"
1405 " type_atr = mputstr (type_atr, control_ns->px);\n"
1406 " type_atr = mputstr (type_atr, \":type='\");\n"
1407 " type_atr = mputstrn(type_atr, type_name, name_len);\n"
1408 " type_atr = mputc (type_atr, '\\'');\n"
1409 " }\n"
1410 " break;\n"
1411 " default: break;\n"
1412 " }\n" /* switch */
1413 " p_flavor &= ~XER_RECOF;\n"
1414 " }\n" /* if e_xer */
1415 , (sdef->nElements > start_at + 1 ? "write_atr:\n" : "")
1416
1417
1418 );
1419 } /* if UseTypeAttr */
1420 src = mputprintf(src,
1421 " unsigned int flavor_1 = p_flavor;\n"
1422 " if (is_exer(p_flavor)) flavor_1 &= ~XER_RECOF;\n"
1423 " bool omit_tag = begin_xml(p_td, p_buf, flavor_1, p_indent, false, "
1424 "(collector_fn)&%s::collect_ns%s);\n"
1425 , sdef->name
1426 , sdef->xerUseTypeAttr ? ", type_atr" : "");
1427 src = mputprintf(src,
1428 " unsigned int flavor_0 = (p_flavor & XER_MASK)%s;\n"
1429 " switch (union_selection) {\n"
1430 , sdef->xerUseTypeAttr ? " | USE_TYPE_ATTR" : "");
1431 for (i = 0; i < sdef->nElements; i++) {
1432 src = mputprintf(src, " case %s_%s:\n"
1433 " ec_1.set_msg(\"%s': \");\n"
1434 " field_%s->XER_encode(%s_xer_, p_buf, flavor_0, "
1435 "p_indent + (!p_indent || !omit_tag), 0);\n"
1436 " break;\n",
1437 selection_prefix, sdef->elements[i].name,
1438 sdef->elements[i].dispname,
1439 sdef->elements[i].name, sdef->elements[i].typegen);
1440 }
1441 src = mputprintf(src, " case %s:\n"
1442 " (void)flavor_0;\n" /* warning reduction for empty union */
1443 " break;\n"
1444 " } //switch\n"
1445 , unbound_value);
1446 if (sdef->xerUseTypeAttr) {
1447 src = mputstr(src, " if (p_buf.get_data()[p_buf.get_len()-1] != '\\n') flavor_1 |= SIMPLE_TYPE;\n");
1448 }
1449 src = mputstr(src,
1450 " end_xml(p_td, p_buf, flavor_1, p_indent, 0);\n"
1451 " return (int)p_buf.get_len() - encoded_length;\n"
1452 "}\n\n");
1453
1454 if (use_runtime_2) {
1455 def = mputstr(def,
1456 "int XER_encode_negtest(const Erroneous_descriptor_t* p_err_descr, "
1457 "const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, "
1458 "unsigned int p_flavor, int p_indent, embed_values_enc_struct_t*) const;\n");
1459 src = mputprintf(src, /* XERSTUFF XER_encode for union */
1460 "int %s::XER_encode_negtest(const Erroneous_descriptor_t* p_err_descr, "
1461 "const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, "
1462 "unsigned int p_flavor, int p_indent, embed_values_enc_struct_t*) const\n"
1463 "{\n"
1464 " if (%s==union_selection) {\n"
1465 " TTCN_error(\"Attempt to XER-encode an unbound union value.\");\n"
1466 " return 0;\n"
1467 " }\n"
1468 " TTCN_EncDec_ErrorContext ec_0(\"Alternative '\");\n"
1469 " TTCN_EncDec_ErrorContext ec_1;\n"
1470 " int encoded_length=(int)p_buf.get_len();\n"
1471 , name
1472 , unbound_value
1473 );
1474 if (sdef->xerUseTypeAttr) {
1475 src = mputstr(src,
1476 " const boolean e_xer = is_exer(p_flavor);\n"
1477 " char *type_atr = NULL;\n"
1478 " unsigned short name_len = 0;\n"
1479 " if (e_xer && (p_td.xer_bits & USE_TYPE_ATTR)) {\n"
1480 " const char *type_name = 0;\n"
1481 " const namespace_t *control_ns;\n"
1482 " switch (union_selection) {\n");
1483 int start_at = sdef->xerUseUnion ? 0 : 1;
1484 for (i = start_at; i < sdef->nElements; i++) {
1485 src = mputprintf(src,
1486 " case %s_%s:\n"
1487 " type_name = %s_xer_.names[1];\n"
1488 " name_len = %s_xer_.namelens[1] - 2;\n"
1489 " %s\n"
1490 , selection_prefix, sdef->elements[i].name
1491 , sdef->elements[i].typegen
1492 , sdef->elements[i].typegen
1493 , i < sdef->nElements - 1 ? "goto write_atr;" : "" /* no break */
1494 );
1495 }
1496 src = mputprintf(src,
1497 "%s" /* label only if more than two elements total */
1498 " if (name_len > 0) {\n" /* 38.3.8, no atr if NAME AS "" */
1499 " control_ns = p_td.my_module->get_controlns();\n"
1500 " type_atr = mcopystr(\" \");\n"
1501 " type_atr = mputstr (type_atr, control_ns->px);\n"
1502 " type_atr = mputstr (type_atr, \":type='\");\n"
1503 " type_atr = mputstrn(type_atr, type_name, name_len);\n"
1504 " type_atr = mputc (type_atr, '\\'');\n"
1505 " }\n"
1506 " break;\n"
1507 " default: break;\n"
1508 " }\n" /* switch */
1509 " p_flavor &= ~XER_RECOF;\n"
1510 " }\n" /* if e_xer */
1511 , (sdef->nElements > start_at + 1 ? "write_atr:\n" : "")
1512 );
1513 } /* if UseTypeAttr */
1514
1515 src = mputprintf(src,
1516 " bool omit_tag = begin_xml(p_td, p_buf, p_flavor, p_indent, false, "
1517 "(collector_fn)&%s::collect_ns%s);\n"
1518 , sdef->name
1519 , sdef->xerUseTypeAttr ? ", type_atr" : "");
1520 /* begin_xml will Free type_atr */
1521 src = mputprintf(src,
1522 " unsigned int flavor_0 = (p_flavor & XER_MASK)%s;\n"
1523 " const Erroneous_values_t* err_vals = NULL;\n"
1524 " const Erroneous_descriptor_t* emb_descr = NULL;\n"
1525 " switch (union_selection) {\n"
1526 , sdef->xerUseTypeAttr ? " | USE_TYPE_ATTR" : "");
1527 for (i = 0; i < sdef->nElements; i++) {
1528 src = mputprintf(src, " case %s_%s:\n"
1529 " err_vals = p_err_descr->get_field_err_values(%lu);\n"
1530 " emb_descr = p_err_descr->get_field_emb_descr(%lu);\n"
1531 " if (err_vals && err_vals->value) {\n"
1532 " if (err_vals->value->errval) {\n"
1533 " ec_1.set_msg(\"%s'(erroneous value): \");\n"
1534 " if (err_vals->value->raw) {\n"
1535 " err_vals->value->errval->encode_raw(p_buf);\n"
1536 " } else {\n"
1537 " if (err_vals->value->type_descr==NULL) TTCN_error"
1538 "(\"internal error: erroneous value typedescriptor missing\");\n"
1539 " else err_vals->value->errval->XER_encode("
1540 "*err_vals->value->type_descr->xer, p_buf, flavor_0, "
1541 "p_indent + (!p_indent || !omit_tag), 0);\n"
1542 " }\n"
1543 " }\n"
1544 " } else {\n"
1545 " ec_1.set_msg(\"%s': \");\n"
1546 " if (emb_descr) field_%s->XER_encode_negtest(emb_descr, "
1547 "%s_xer_, p_buf, flavor_0, p_indent + (!p_indent || !omit_tag), 0);\n"
1548 " else field_%s->XER_encode(%s_xer_, p_buf, flavor_0, "
1549 "p_indent + (!p_indent || !omit_tag), 0);\n"
1550 " }\n"
1551 " break;\n",
1552 selection_prefix, sdef->elements[i].name, /* case label */
1553 (unsigned long)i, (unsigned long)i,
1554 sdef->elements[i].dispname, /* set_msg (erroneous) */
1555 sdef->elements[i].dispname, /* set_msg */
1556 sdef->elements[i].name, sdef->elements[i].typegen,
1557 sdef->elements[i].name, sdef->elements[i].typegen /* field_%s, %s_descr */
1558 );
1559 }
1560 src = mputprintf(src, " case %s:\n"
1561 " (void)flavor_0;\n" /* warning reduction for empty union */
1562 " break;\n"
1563 " } //switch\n"
1564 " end_xml(p_td, p_buf, p_flavor, p_indent, 0);\n"
1565 " return (int)p_buf.get_len() - encoded_length;\n"
1566 "}\n\n"
1567 , unbound_value);
1568 }
1569
1570 #ifndef NDEBUG
1571 src = mputprintf(src, "// %s has%s%s%s%s%s%s%s%s%s\n"
1572 "// written by %s in " __FILE__ " at %d\n"
1573 , name
1574 , (sdef->xerUntagged ? " UNTAGGED" : "")
1575 , (sdef->xerUntaggedOne ? "1" : "")
1576 , (sdef->xerUseNilPossible ? " USE_NIL?" : "")
1577 , (sdef->xerUseOrderPossible ? " USE_ORDER?" : "")
1578 , (sdef->xerUseQName ? " USE_QNAME" : "")
1579 , (sdef->xerUseTypeAttr ? " USE_TYPE_ATTR" : "")
1580 , (sdef->xerUseUnion ? " USE-UNION" : "")
1581 , (sdef->xerHasNamespaces ? " namespace" : "")
1582 , (sdef->xerEmbedValuesPossible ? " EMBED?" : "")
1583 , __FUNCTION__, __LINE__
1584 );
1585 #endif
1586 src = mputprintf(src, /* XERSTUFF decoder functions for union */
1587 "int %s::XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& p_reader,"
1588 " unsigned int p_flavor, embed_values_dec_struct_t*)\n"
1589 "{\n"
1590 " int e_xer = is_exer(p_flavor);\n"
1591 " int type = 0;\n" /* None */
1592 " int rd_ok=1, xml_depth=-1;\n"
1593 "%s%s"
1594 " int xerbits = p_td.xer_bits;\n"
1595 " if (p_flavor & XER_TOPLEVEL) xerbits &= ~UNTAGGED;\n"
1596 " if (xerbits & USE_TYPE_ATTR) p_flavor &= ~XER_RECOF;\n"
1597 " boolean own_tag = !(e_xer && ((xerbits & (ANY_ELEMENT | UNTAGGED)) "
1598 "|| (p_flavor & (USE_NIL|(e_xer ? XER_LIST : XER_RECOF)))));\n"
1599 " if ((e_xer || !is_record_of(p_flavor)) && own_tag)\n"
1600 /* Loop until the start tag */
1601 " %sfor (rd_ok = p_reader.Ok(); rd_ok == 1; rd_ok = p_reader.Read()) {\n"
1602 " type = p_reader.NodeType();\n"
1603 " if (type == XML_READER_TYPE_ELEMENT) {\n"
1604 " verify_name(p_reader, p_td, e_xer);\n"
1605 " xml_depth = p_reader.Depth();\n"
1606 , name
1607 , sdef->xerUseTypeAttr ? " char * typeatr = 0;\n" : ""
1608 , sdef->xerUseUnion ? " boolean attribute = (p_td.xer_bits & XER_ATTRIBUTE) ? true : false;\n" : ""
1609 , sdef->xerUseUnion ? "if (!attribute) " : ""
1610 );
1611 if (sdef->xerUseTypeAttr) {
1612 src = mputprintf(src,
1613 " int other_attributes = 0;\n"
1614 " if (e_xer) {\n"
1615 " for (rd_ok = p_reader.MoveToFirstAttribute(); rd_ok == 1;"
1616 " rd_ok = p_reader.MoveToNextAttribute()) {\n"
1617 " if (p_reader.IsNamespaceDecl()) continue;\n"
1618 " const char *attr_name = (const char*)p_reader.Name();\n"
1619 " if (!strcmp(attr_name, \"%s:type\"))\n"
1620 " {\n"
1621 " typeatr = mcopystr((const char*)p_reader.Value());\n"
1622 " }\n"
1623 " else ++other_attributes;\n"
1624 " }\n" /* for */
1625 " rd_ok = p_reader.MoveToElement() | 1;\n"
1626 , sdef->control_ns_prefix);
1627 if (!sdef->xerUseUnion) {
1628 /* USE-TYPE: No type attribute means the first alternative */
1629 src = mputprintf(src,
1630 " if (typeatr == NULL) {\n"
1631 " typeatr = mcopystr(%s_xer_.names[1]);\n"
1632 " typeatr = mtruncstr(typeatr, %s_xer_.namelens[1] - 2);\n"
1633 " }\n"
1634 , sdef->elements[0].typegen
1635 , sdef->elements[0].typegen);
1636 }
1637 src = mputstr(src,
1638 " }\n" /* if exer */);
1639 }
1640
1641 src = mputprintf(src,
1642 " if (!(e_xer && (p_td.xer_bits & USE_TYPE_ATTR)%s)\n"
1643 " && !p_reader.IsEmptyElement()) rd_ok = p_reader.Read();\n"
1644 " break;\n"
1645 " }\n"
1646 " }\n"
1647 " unsigned int flavor_1 = (p_flavor & XER_MASK);\n" /* also, not toplevel */
1648 /* Loop until the content. Normally an element, unless UNTAGGED
1649 * USE-UNION or some other shenanigans. */
1650 " %s%sfor (rd_ok = p_reader.Ok(); rd_ok == 1; rd_ok = p_reader.Read()) {\n"
1651 " type = p_reader.NodeType();\n"
1652 " %sif (type == XML_READER_TYPE_ELEMENT) break;\n"
1653 " else if (type == XML_READER_TYPE_END_ELEMENT) break;\n"
1654 " }\n"
1655 " if (rd_ok) {\n"
1656 " TTCN_EncDec_ErrorContext ec_1(\"Alternative '\");\n"
1657 " TTCN_EncDec_ErrorContext ec_2;\n"
1658 " const char *elem_name;\n"
1659 " const char *ns_uri = 0;\n"
1660 , sdef->xerUseTypeAttr ? " && other_attributes > 0" : ""
1661 , sdef->xerUseTypeAttr ? "if (!e_xer) " : ""
1662 , sdef->xerUseUnion ? "if (!attribute) " : ""
1663 , sdef->xerUseTypeAttr ?
1664 "if (e_xer) { if (type == XML_READER_TYPE_TEXT) break; }\n"
1665 " else " : ""
1666 );
1667
1668 if (sdef->xerUseTypeAttr) {
1669 src = mputstr(src,
1670 " if (e_xer) {\n" /* USE-TYPE => no XML element, use typeatr */
1671 " elem_name = typeatr;\n"
1672 " flavor_1 |= USE_TYPE_ATTR;\n"
1673 " }\n"
1674 " else" /* no newline, gobbles up the next {} */);
1675 }
1676 src = mputstr(src,
1677 " {\n"
1678 " elem_name = (const char*)p_reader.LocalName();\n"
1679 " ns_uri = (const char*)p_reader.NamespaceUri();\n"
1680 " }\n");
1681
1682 if (sdef->xerUseUnion) {
1683 src = mputstr(src,
1684 " int matched = -1;\n"
1685 " if (typeatr == NULL) flavor_1 |= EXIT_ON_ERROR;\n"
1686 " for (;;) {\n");
1687 /* TODO unify the two alternatives */
1688 for (i = 0; i < sdef->nElements; i++) {
1689 src = mputprintf(src,
1690 /* If decoding EXER, there is no tag to apply check_name
1691 *
1692 */
1693 " if ((e_xer && (typeatr == NULL || !(p_td.xer_bits & USE_TYPE_ATTR))) "
1694 "|| can_start(elem_name, ns_uri, %s_xer_, flavor_1)) {\n"
1695 " ec_2.set_msg(\"%s': \");\n"
1696 " if (%s==union_selection) {\n"
1697 " matched = %d;\n"
1698 " %s().XER_decode(%s_xer_, p_reader, flavor_1, 0);\n"
1699 " }\n"
1700 " if (field_%s->is_bound()) break; else clean_up();\n"
1701 " }\n",
1702 sdef->elements[i].typegen,
1703 sdef->elements[i].dispname,
1704 unbound_value, (int)i,
1705 sdef->elements[i].name, sdef->elements[i].typegen,
1706 sdef->elements[i].name);
1707 }
1708 src = mputstr(src,
1709 " if (typeatr == NULL) {\n"
1710 /* No type attribute found and none of the fields managed to decode the value (USE-UNION only) */
1711 " ec_1.set_msg(\" \");\n"
1712 " ec_2.set_msg(\" \");\n"
1713 " const char* value = (const char*)p_reader.Value();\n"
1714 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG,\n"
1715 " \"'%s' could not be decoded by any of the union's fields.\", value);\n"
1716 " } else if (matched >= 0) {\n"
1717 /* Alternative found, but it couldn't be decoded */
1718 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG,\n"
1719 " \"Failed to decode field.\");\n"
1720 " } else {\n"
1721 /* Type attribute found, but it didn't match any of the fields */
1722 " ec_1.set_msg(\" \");\n"
1723 " ec_2.set_msg(\" \");\n"
1724 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG,\n"
1725 " \"'%s' does not match any alternative.\", elem_name);\n"
1726 " }\n"
1727 " if (xml_depth >= 0) for (; rd_ok == 1 "
1728 "&& p_reader.Depth() > xml_depth; rd_ok = p_reader.Read()) ;\n"
1729 " break;\n"
1730 " }\n"); /* for ever */
1731 }
1732 else /* not USE-UNION */
1733 {
1734 if (sdef->exerMaybeEmptyIndex >= 0) {
1735 /* There is a field which can be empty XML. Add code to detect this
1736 * and jump to the appropriate field which can decode "nothing". */
1737 src = mputstr(src,
1738 " if (type!=XML_READER_TYPE_ELEMENT || "
1739 "(own_tag && p_reader.IsEmptyElement())) goto empty_xml;\n");
1740 /* If the choice itself is untagged, then an empty element belongs to
1741 * one of the fields and does not mean that the choice is empty */
1742 }
1743 /* FIXME some hashing should be implemented */
1744 /* The field which can be empty should be checked last, otherwise we create an infinity loop with memory bomb.
1745 * So move that field to the last elseif branch*/
1746 for (i = 0; i < sdef->nElements; i++) {
1747 if(sdef->exerMaybeEmptyIndex != i){
1748 src = mputprintf(src,
1749 " %sif (%s::can_start(elem_name, ns_uri, %s_xer_, flavor_1) || (%s_xer_.xer_bits & ANY_ELEMENT)) {\n"
1750 " ec_2.set_msg(\"%s': \");\n"
1751 " %s%s().XER_decode(%s_xer_, p_reader, flavor_1, 0);\n"
1752 " if (!%s%s().is_bound()) {\n"
1753 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG, \"Failed to decode field.\");\n"
1754 " }\n"
1755 " }\n",
1756 i && !(i==1 && sdef->exerMaybeEmptyIndex==0) ? "else " : "", /* print "if(" if generate code for the first field or if the first field is the MaybeEmpty field and we generate the code for the second one*/
1757 sdef->elements[i].type, sdef->elements[i].typegen, sdef->elements[i].typegen,
1758 sdef->elements[i].dispname,
1759 at_field, sdef->elements[i].name, sdef->elements[i].typegen,
1760 at_field, sdef->elements[i].name);
1761 }
1762 }
1763 if(sdef->exerMaybeEmptyIndex>=0 ){
1764 i=sdef->exerMaybeEmptyIndex;
1765 src = mputprintf(src,
1766 " %sif ((e_xer && (type==XML_READER_TYPE_END_ELEMENT || !own_tag)) || %s::can_start(elem_name, ns_uri, %s_xer_, flavor_1) || (%s_xer_.xer_bits & ANY_ELEMENT)) {\n"
1767 "empty_xml: ec_2.set_msg(\"%s': \");\n"
1768 " %s%s().XER_decode(%s_xer_, p_reader, flavor_1, 0);\n"
1769 " if (!%s%s().is_bound()) {\n"
1770 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG, \"Failed to decode field.\");\n"
1771 " }\n"
1772 " }\n",
1773 sdef->nElements>0 ? "else " : "",
1774 sdef->elements[i].type, sdef->elements[i].typegen, sdef->elements[i].typegen,
1775 sdef->elements[i].dispname,
1776 at_field, sdef->elements[i].name, sdef->elements[i].typegen,
1777 at_field, sdef->elements[i].name);
1778 }
1779 if (!sdef->isOptional) {
1780 src = mputstr(src,
1781 " else {\n"
1782 " ec_1.set_msg(\" \");\n"
1783 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_INVAL_MSG, "
1784 "\"'%s' does not match any alternative\", elem_name);\n"
1785 " if (xml_depth >= 0) for (; rd_ok == 1 "
1786 "&& p_reader.Depth() > xml_depth; rd_ok = p_reader.Read()) ;\n"
1787 " }\n"
1788 );
1789 }
1790 }
1791
1792 src = mputprintf(src,
1793 " }\n" /* end if(rd_ok) */
1794 " if (%s(e_xer || !is_record_of(p_flavor)) && own_tag)\n"
1795 " for (; rd_ok == 1; rd_ok = p_reader.Read()) {\n"
1796 " type = p_reader.NodeType();\n"
1797 " if (type == XML_READER_TYPE_END_ELEMENT) {\n"
1798 " verify_end(p_reader, p_td, xml_depth, e_xer);\n"
1799 " rd_ok = p_reader.Read(); // one last time\n"
1800 " break;\n"
1801 " }\n"
1802 " }\n"
1803 "%s"
1804 " return 1;\n"
1805 "}\n\n", sdef->xerUseUnion ? "!attribute && " : "",
1806 sdef->xerUseTypeAttr ? " Free(typeatr);\n" : "");
1807 }
1808 if (json_needed) {
1809 // JSON encode
1810 src = mputprintf(src,
1811 "int %s::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok) const\n"
1812 "{\n", name);
1813 if (!sdef->jsonAsValue) {
1814 src = mputstr(src, " int enc_len = p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);\n\n");
1815 } else {
1816 src = mputstr(src, " int enc_len = 0;\n\n");
1817 }
1818 src = mputstr(src, " switch(union_selection) {\n");
1819
1820 for (i = 0; i < sdef->nElements; ++i) {
1821 src = mputprintf(src, " case %s_%s:\n", selection_prefix, sdef->elements[i].name);
1822 if (!sdef->jsonAsValue) {
1823 src = mputprintf(src, " enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, \"%s\");\n"
1824 , sdef->elements[i].jsonAlias ? sdef->elements[i].jsonAlias : sdef->elements[i].dispname);
1825 }
1826 src = mputprintf(src,
1827 " enc_len += field_%s->JSON_encode(%s_descr_, p_tok);\n"
1828 " break;\n"
1829 , sdef->elements[i].name, sdef->elements[i].typedescrname);
1830 }
1831 src = mputprintf(src,
1832 " default:\n"
1833 " TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND, \n"
1834 " \"Encoding an unbound value of type %s.\");\n"
1835 " return -1;\n"
1836 " }\n\n"
1837 , dispname);
1838 if (!sdef->jsonAsValue) {
1839 src = mputstr(src, " enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_END, NULL);\n");
1840 }
1841 src = mputstr(src,
1842 " return enc_len;\n"
1843 "}\n\n");
1844
1845 // JSON decode
1846 src = mputprintf(src,
1847 "int %s::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_silent)\n"
1848 "{\n"
1849 " json_token_t j_token = JSON_TOKEN_NONE;\n"
1850 , name);
1851 if (sdef->jsonAsValue) {
1852 src = mputstr(src,
1853 " size_t buf_pos = p_tok.get_buf_pos();\n"
1854 " p_tok.get_next_token(&j_token, NULL, NULL);\n"
1855 " int ret_val = 0;\n"
1856 " switch(j_token) {\n"
1857 " case JSON_TOKEN_NUMBER: {\n");
1858 for (i = 0; i < sdef->nElements; ++i) {
1859 if (JSON_NUMBER & sdef->elements[i].jsonValueType) {
1860 src = mputprintf(src,
1861 " p_tok.set_buf_pos(buf_pos);\n"
1862 " ret_val = %s%s().JSON_decode(%s_descr_, p_tok, true);\n"
1863 " if (0 <= ret_val) {\n"
1864 " return ret_val;\n"
1865 " }\n"
1866 , at_field, sdef->elements[i].name, sdef->elements[i].typedescrname);
1867 }
1868 }
1869 src = mputstr(src,
1870 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_AS_VALUE_ERROR, \"number\");\n"
1871 " clean_up();\n"
1872 " return JSON_ERROR_FATAL;\n"
1873 " }\n"
1874 " case JSON_TOKEN_STRING: {\n");
1875 for (i = 0; i < sdef->nElements; ++i) {
1876 if (JSON_STRING & sdef->elements[i].jsonValueType) {
1877 src = mputprintf(src,
1878 " p_tok.set_buf_pos(buf_pos);\n"
1879 " ret_val = %s%s().JSON_decode(%s_descr_, p_tok, true);\n"
1880 " if (0 <= ret_val) {\n"
1881 " return ret_val;\n"
1882 " }\n"
1883 , at_field, sdef->elements[i].name, sdef->elements[i].typedescrname);
1884 }
1885 }
1886 src = mputstr(src,
1887 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_AS_VALUE_ERROR, \"string\");\n"
1888 " clean_up();\n"
1889 " return JSON_ERROR_FATAL;\n"
1890 " }\n"
1891 " case JSON_TOKEN_LITERAL_TRUE:\n"
1892 " case JSON_TOKEN_LITERAL_FALSE: {\n");
1893 for (i = 0; i < sdef->nElements; ++i) {
1894 if (JSON_BOOLEAN & sdef->elements[i].jsonValueType) {
1895 src = mputprintf(src,
1896 " p_tok.set_buf_pos(buf_pos);\n"
1897 " ret_val = %s%s().JSON_decode(%s_descr_, p_tok, true);\n"
1898 " if (0 <= ret_val) {\n"
1899 " return ret_val;\n"
1900 " }\n"
1901 , at_field, sdef->elements[i].name, sdef->elements[i].typedescrname);
1902 }
1903 }
1904 src = mputstr(src,
1905 " char* literal_str = mprintf(\"literal (%s)\",\n"
1906 " (JSON_TOKEN_LITERAL_TRUE == j_token) ? \"true\" : \"false\");\n"
1907 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_AS_VALUE_ERROR, literal_str);\n"
1908 " Free(literal_str);\n"
1909 " clean_up();\n"
1910 " return JSON_ERROR_FATAL;\n"
1911 " }\n"
1912 " case JSON_TOKEN_ARRAY_START: {\n");
1913 for (i = 0; i < sdef->nElements; ++i) {
1914 if (JSON_ARRAY & sdef->elements[i].jsonValueType) {
1915 src = mputprintf(src,
1916 " p_tok.set_buf_pos(buf_pos);\n"
1917 " ret_val = %s%s().JSON_decode(%s_descr_, p_tok, true);\n"
1918 " if (0 <= ret_val) {\n"
1919 " return ret_val;\n"
1920 " }\n"
1921 , at_field, sdef->elements[i].name, sdef->elements[i].typedescrname);
1922 }
1923 }
1924 src = mputstr(src,
1925 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_AS_VALUE_ERROR, \"array\");\n"
1926 " clean_up();\n"
1927 " return JSON_ERROR_FATAL;\n"
1928 " }\n"
1929 " case JSON_TOKEN_OBJECT_START: {\n");
1930 for (i = 0; i < sdef->nElements; ++i) {
1931 if (JSON_OBJECT & sdef->elements[i].jsonValueType) {
1932 src = mputprintf(src,
1933 " p_tok.set_buf_pos(buf_pos);\n"
1934 " ret_val = %s%s().JSON_decode(%s_descr_, p_tok, true);\n"
1935 " if (0 <= ret_val) {\n"
1936 " return ret_val;\n"
1937 " }\n"
1938 , at_field, sdef->elements[i].name, sdef->elements[i].typedescrname);
1939 }
1940 }
1941 src = mputstr(src,
1942 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_AS_VALUE_ERROR, \"object\");\n"
1943 " clean_up();\n"
1944 " return JSON_ERROR_FATAL;\n"
1945 " }\n"
1946 " case JSON_TOKEN_LITERAL_NULL: {\n");
1947 for (i = 0; i < sdef->nElements; ++i) {
1948 if (JSON_NULL & sdef->elements[i].jsonValueType) {
1949 src = mputprintf(src,
1950 " p_tok.set_buf_pos(buf_pos);\n"
1951 " ret_val = %s%s().JSON_decode(%s_descr_, p_tok, true);\n"
1952 " if (0 <= ret_val) {\n"
1953 " return ret_val;\n"
1954 " }\n"
1955 , at_field, sdef->elements[i].name, sdef->elements[i].typedescrname);
1956 }
1957 }
1958 src = mputstr(src,
1959 " clean_up();\n"
1960 // the caller might be able to decode the null value if it's an optional field
1961 // only return an invalid token error, not a fatal error
1962 " return JSON_ERROR_INVALID_TOKEN;\n"
1963 " }\n"
1964 " case JSON_TOKEN_ERROR:\n"
1965 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, \"\");\n"
1966 " return JSON_ERROR_FATAL;\n"
1967 " default:\n"
1968 " return JSON_ERROR_INVALID_TOKEN;\n"
1969 " }\n"
1970 " return 0;\n"
1971 "}\n\n");
1972 } else { // not "as value"
1973 src = mputprintf(src,
1974 " int dec_len = p_tok.get_next_token(&j_token, NULL, NULL);\n"
1975 " if (JSON_TOKEN_ERROR == j_token) {\n"
1976 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, \"\");\n"
1977 " return JSON_ERROR_FATAL;\n"
1978 " }\n"
1979 " else if (JSON_TOKEN_OBJECT_START != j_token) {\n"
1980 " return JSON_ERROR_INVALID_TOKEN;\n"
1981 " }\n\n"
1982 " char* fld_name = 0;\n"
1983 " size_t name_len = 0;"
1984 " dec_len += p_tok.get_next_token(&j_token, &fld_name, &name_len);\n"
1985 " if (JSON_TOKEN_NAME != j_token) {\n"
1986 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_NAME_TOKEN_ERROR);\n"
1987 " return JSON_ERROR_FATAL;\n"
1988 " } else {\n"
1989 " union_selection = %s;\n "
1990 , unbound_value);
1991 for (i = 0; i < sdef->nElements; ++i) {
1992 src = mputprintf(src,
1993 "if (0 == strncmp(fld_name, \"%s\", name_len)) {\n"
1994 " int ret_val = %s%s().JSON_decode(%s_descr_, p_tok, p_silent);\n"
1995 " if (0 > ret_val) {\n"
1996 " if (JSON_ERROR_INVALID_TOKEN) {\n"
1997 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FIELD_TOKEN_ERROR, \"%s\");\n"
1998 " }\n"
1999 " return JSON_ERROR_FATAL;\n"
2000 " } else {\n"
2001 " dec_len += ret_val;\n"
2002 " }\n"
2003 " } else "
2004 , sdef->elements[i].jsonAlias ? sdef->elements[i].jsonAlias : sdef->elements[i].dispname
2005 , at_field, sdef->elements[i].name, sdef->elements[i].typedescrname
2006 , sdef->elements[i].dispname);
2007 }
2008 src = mputstr(src,
2009 "{\n"
2010 " char* fld_name2 = mcopystrn(fld_name, name_len);\n"
2011 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_INVALID_NAME_ERROR, fld_name2);\n"
2012 " Free(fld_name2);\n"
2013 " return JSON_ERROR_FATAL;\n"
2014 " }\n"
2015 " }\n\n"
2016 " dec_len += p_tok.get_next_token(&j_token, NULL, NULL);\n"
2017 " if (JSON_TOKEN_OBJECT_END != j_token) {\n"
2018 " JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_STATIC_OBJECT_END_TOKEN_ERROR, \"\");\n"
2019 " return JSON_ERROR_FATAL;\n"
2020 " }\n\n"
2021 " return dec_len;\n"
2022 "}\n\n");
2023 }
2024 }
2025
2026 /* end of class definition */
2027 def = mputstr(def, "};\n\n");
2028
2029 output->header.class_defs = mputstr(output->header.class_defs, def);
2030 Free(def);
2031
2032 output->source.methods = mputstr(output->source.methods, src);
2033 Free(src);
2034
2035 Free(selection_type);
2036 Free(unbound_value);
2037 Free(selection_prefix);
2038 }
2039
2040
2041 void defUnionTemplate(const struct_def *sdef, output_struct *output)
2042 {
2043 int i;
2044 const char *name = sdef->name, *dispname = sdef->dispname;
2045 const char *at_field = sdef->kind==ANYTYPE ? "AT_" : "";
2046 char *def = NULL, *src = NULL;
2047
2048 char *selection_type, *unbound_value, *selection_prefix;
2049 selection_type = mprintf("%s::union_selection_type", name);
2050 unbound_value = mprintf("%s::UNBOUND_VALUE", name);
2051 selection_prefix = mprintf("%s::ALT", name);
2052
2053 /* template class */
2054
2055 output->header.class_decls = mputprintf(output->header.class_decls,
2056 "class %s_template;\n", name);
2057
2058 /* template class header and data members */
2059 def = mputprintf(def, "class %s_template : public Base_Template {\n"
2060 "union {\n"
2061 "struct {\n"
2062 "%s union_selection;\n"
2063 "union {\n", name, selection_type);
2064 for (i = 0; i < sdef->nElements; i++) {
2065 def = mputprintf(def, "%s_template *field_%s;\n",
2066 sdef->elements[i].type, sdef->elements[i].name);
2067 }
2068 def = mputprintf(def, "};\n"
2069 "} single_value;\n"
2070 "struct {\n"
2071 "unsigned int n_values;\n"
2072 "%s_template *list_value;\n"
2073 "} value_list;\n"
2074 "};\n", name);
2075 if (use_runtime_2) {
2076 def = mputstr(def,
2077 "Erroneous_descriptor_t* err_descr;\n");
2078 }
2079
2080 /* copy_value function */
2081 def = mputprintf(def, "void copy_value(const %s& other_value);\n\n", name);
2082 src = mputprintf(src, "void %s_template::copy_value(const %s& other_value)\n"
2083 "{\n"
2084 "single_value.union_selection = other_value.get_selection();\n"
2085 "switch (single_value.union_selection) {\n", name, name);
2086 for (i = 0; i<sdef->nElements; i++) {
2087 src = mputprintf(src, "case %s_%s:\n"
2088 "single_value.field_%s = new %s_template(other_value.%s%s());\n"
2089 "break;\n", selection_prefix, sdef->elements[i].name,
2090 sdef->elements[i].name, sdef->elements[i].type,
2091 at_field, sdef->elements[i].name);
2092 }
2093 src = mputprintf(src, "default:\n"
2094 "TTCN_error(\"Initializing a template with an unbound value of type "
2095 "%s.\");\n"
2096 "}\n"
2097 "set_selection(SPECIFIC_VALUE);\n"
2098 "%s"
2099 "}\n\n", dispname,
2100 use_runtime_2 ? "err_descr = other_value.get_err_descr();\n" : "");
2101
2102 /* copy_template function */
2103 def = mputprintf(def, "void copy_template(const %s_template& "
2104 "other_value);\n", name);
2105 src = mputprintf(src, "void %s_template::copy_template(const "
2106 "%s_template& other_value)\n"
2107 "{\n"
2108 "switch (other_value.template_selection) {\n"
2109 "case SPECIFIC_VALUE:\n"
2110 "single_value.union_selection = "
2111 "other_value.single_value.union_selection;\n"
2112 "switch (single_value.union_selection) {\n", name, name);
2113 for (i = 0; i < sdef->nElements; i++) {
2114 src = mputprintf(src, "case %s_%s:\n"
2115 "single_value.field_%s = "
2116 "new %s_template(*other_value.single_value.field_%s);\n"
2117 "break;\n", selection_prefix, sdef->elements[i].name,
2118 sdef->elements[i].name, sdef->elements[i].type, sdef->elements[i].name);
2119 }
2120 src = mputprintf(src, "default:\n"
2121 "TTCN_error(\"Internal error: Invalid union selector in a specific value "
2122 "when copying a template of type %s.\");\n"
2123 "}\n"
2124 "case OMIT_VALUE:\n"
2125 "case ANY_VALUE:\n"
2126 "case ANY_OR_OMIT:\n"
2127 "break;\n"
2128 "case VALUE_LIST:\n"
2129 "case COMPLEMENTED_LIST:\n"
2130 "value_list.n_values = other_value.value_list.n_values;\n"
2131 "value_list.list_value = new %s_template[value_list.n_values];\n"
2132 "for (unsigned int list_count = 0; list_count < value_list.n_values; "
2133 "list_count++)\n"
2134 "value_list.list_value[list_count].copy_template("
2135 "other_value.value_list.list_value[list_count]);\n"
2136 "break;\n"
2137 "default:\n"
2138 "TTCN_error(\"Copying an uninitialized template of union type %s.\");\n"
2139 "}\n"
2140 "set_selection(other_value);\n"
2141 "%s"
2142 "}\n\n", dispname, name, dispname,
2143 use_runtime_2 ? "err_descr = other_value.err_descr;\n" : "");
2144
2145 /* default constructor */
2146 def = mputprintf(def, "\npublic:\n"
2147 "%s_template();\n", name);
2148 src = mputprintf(src, "%s_template::%s_template()%s\n"
2149 "{\n"
2150 "}\n\n", name, name,
2151 use_runtime_2 ? ": err_descr(NULL)" : "");
2152
2153 /* constructor (template_sel) */
2154 def = mputprintf(def, "%s_template(template_sel other_value);\n", name);
2155 src = mputprintf(src, "%s_template::%s_template(template_sel other_value)\n"
2156 " : Base_Template(other_value)%s\n"
2157 "{\n"
2158 "check_single_selection(other_value);\n"
2159 "}\n\n", name, name,
2160 use_runtime_2 ? ", err_descr(NULL)" : "");
2161
2162 /* constructor (value) */
2163 def = mputprintf(def, "%s_template(const %s& other_value);\n", name, name);
2164 src = mputprintf(src, "%s_template::%s_template(const %s& other_value)\n"
2165 "{\n"
2166 "copy_value(other_value);\n"
2167 "}\n\n", name, name, name);
2168
2169 /* constructor (optional value) */
2170 def = mputprintf(def, "%s_template(const OPTIONAL<%s>& other_value);\n", name,
2171 name);
2172 src = mputprintf(src, "%s_template::%s_template(const OPTIONAL<%s>& "
2173 "other_value)\n"
2174 "{\n"
2175 "switch (other_value.get_selection()) {\n"
2176 "case OPTIONAL_PRESENT:\n"
2177 "copy_value((const %s&)other_value);\n"
2178 "break;\n"
2179 "case OPTIONAL_OMIT:\n"
2180 "set_selection(OMIT_VALUE);\n"
2181 "%s"
2182 "break;\n"
2183 "default:\n"
2184 "TTCN_error(\"Creating a template of union type %s from an unbound "
2185 "optional field.\");\n"
2186 "}\n"
2187 "}\n\n", name, name, name, name,
2188 use_runtime_2 ? "err_descr = NULL;\n" : "",
2189 dispname);
2190
2191 /* copy constructor */
2192 def = mputprintf(def, "%s_template(const %s_template& other_value);\n", name,
2193 name);
2194 src = mputprintf(src, "%s_template::%s_template(const %s_template& "
2195 "other_value)\n"
2196 ": Base_Template()" /* yes, the base class _default_ constructor */
2197 "{\n"
2198 "copy_template(other_value);\n"
2199 "}\n\n", name, name, name);
2200
2201 /* destructor */
2202 def = mputprintf(def, "~%s_template();\n", name);
2203 src = mputprintf(src, "%s_template::~%s_template()\n"
2204 "{\n"
2205 "clean_up();\n"
2206 "}\n\n", name, name);
2207
2208 /* clean_up function */
2209 def = mputstr(def, "void clean_up();\n");
2210 src = mputprintf(src, "void %s_template::clean_up()\n"
2211 "{\n"
2212 "switch (template_selection) {\n"
2213 "case SPECIFIC_VALUE:\n"
2214 "switch (single_value.union_selection) {\n", name);
2215 for (i = 0; i < sdef->nElements; i++) {
2216 src = mputprintf(src, "case %s_%s:\n"
2217 "delete single_value.field_%s;\n",
2218 selection_prefix, sdef->elements[i].name, sdef->elements[i].name);
2219 if (i < sdef->nElements - 1) src = mputstr(src, "break;\n");
2220 }
2221 src = mputstr(src, "default:\n"
2222 "break;\n"
2223 "}\n"
2224 "break;\n"
2225 "case VALUE_LIST:\n"
2226 "case COMPLEMENTED_LIST:\n"
2227 "delete [] value_list.list_value;\n"
2228 "default:\n"
2229 "break;\n"
2230 "}\n"
2231 "template_selection = UNINITIALIZED_TEMPLATE;\n"
2232 "}\n\n");
2233
2234 /* assignment operator (template_sel) */
2235 def = mputprintf(def, "%s_template& operator=(template_sel other_value);\n",
2236 name);
2237 src = mputprintf(src,
2238 "%s_template& %s_template::operator=(template_sel "
2239 "other_value)\n"
2240 "{\n"
2241 "check_single_selection(other_value);\n"
2242 "clean_up();\n"
2243 "set_selection(other_value);\n"
2244 "%s"
2245 "return *this;\n"
2246 "}\n\n", name, name, use_runtime_2 ? "err_descr = NULL;\n" : "");
2247
2248 /* assignment operator (value) */
2249 def = mputprintf(def, "%s_template& operator=(const %s& other_value);\n",
2250 name, name);
2251 src = mputprintf(src, "%s_template& %s_template::operator=(const %s& "
2252 "other_value)\n"
2253 "{\n"
2254 "clean_up();\n"
2255 "copy_value(other_value);\n"
2256 "return *this;\n"
2257 "}\n\n", name, name, name);
2258
2259 /* assignment operator <- optional value */
2260 def = mputprintf(def, "%s_template& operator=(const OPTIONAL<%s>& "
2261 "other_value);\n", name, name);
2262 src = mputprintf(src,
2263 "%s_template& %s_template::operator=(const OPTIONAL<%s>& other_value)\n"
2264 "{\n"
2265 "clean_up();\n"
2266 "switch (other_value.get_selection()) {\n"
2267 "case OPTIONAL_PRESENT:\n"
2268 "copy_value((const %s&)other_value);\n"
2269 "break;\n"
2270 "case OPTIONAL_OMIT:\n"
2271 "set_selection(OMIT_VALUE);\n"
2272 "%s"
2273 "break;\n"
2274 "default:\n"
2275 "TTCN_error(\"Assignment of an unbound optional field to a template of "
2276 "union type %s.\");\n"
2277 "}\n"
2278 "return *this;\n"
2279 "}\n\n", name, name, name, name,
2280 use_runtime_2 ? "err_descr = NULL;\n" : "", dispname);
2281
2282 /* assignment operator (template) */
2283 def = mputprintf(def, "%s_template& operator=(const %s_template& "
2284 "other_value);\n", name, name);
2285 src = mputprintf(src,
2286 "%s_template& %s_template::operator=(const %s_template& other_value)\n"
2287 "{\n"
2288 "if (&other_value != this) {\n"
2289 "clean_up();\n"
2290 "copy_template(other_value);\n"
2291 "}\n"
2292 "return *this;\n"
2293 "}\n\n", name, name, name);
2294
2295 /* match function */
2296 def = mputprintf(def, "boolean match(const %s& other_value, boolean legacy "
2297 "= FALSE) const;\n", name);
2298 src = mputprintf(src, "boolean %s_template::match(const %s& other_value, "
2299 "boolean legacy) const\n"
2300 "{\n"
2301 "if (!other_value.is_bound()) return FALSE;\n"
2302 "switch (template_selection) {\n"
2303 "case ANY_VALUE:\n"
2304 "case ANY_OR_OMIT:\n"
2305 "return TRUE;\n"
2306 "case OMIT_VALUE:\n"
2307 "return FALSE;\n"
2308 "case SPECIFIC_VALUE:\n"
2309 "{\n"
2310 "%s value_selection = other_value.get_selection();\n"
2311 "if (value_selection == %s) return FALSE;\n"
2312 "if (value_selection != single_value.union_selection) return FALSE;\n"
2313 "switch (value_selection) {\n", name, name, selection_type, unbound_value);
2314 for (i = 0; i < sdef->nElements; i++) {
2315 src = mputprintf(src, "case %s_%s:\n"
2316 "return single_value.field_%s->match(other_value.%s%s(), legacy);\n",
2317 selection_prefix, sdef->elements[i].name, sdef->elements[i].name,
2318 at_field, sdef->elements[i].name);
2319 }
2320 src = mputprintf(src, "default:\n"
2321 "TTCN_error(\"Internal error: Invalid selector in a specific value when "
2322 "matching a template of union type %s.\");\n"
2323 "}\n"
2324 "}\n"
2325 "case VALUE_LIST:\n"
2326 "case COMPLEMENTED_LIST:\n"
2327 "for (unsigned int list_count = 0; list_count < value_list.n_values; "
2328 "list_count++)\n"
2329 "if (value_list.list_value[list_count].match(other_value, legacy)) "
2330 "return template_selection == VALUE_LIST;\n"
2331 "return template_selection == COMPLEMENTED_LIST;\n"
2332 "default:\n"
2333 "TTCN_error (\"Matching an uninitialized template of union type %s.\");\n"
2334 "}\n"
2335 "return FALSE;\n"
2336 "}\n\n", dispname, dispname);
2337
2338 /* isvalue */
2339 def = mputstr(def, "boolean is_value() const;");
2340 src = mputprintf(src, "boolean %s_template::is_value() const\n"
2341 "{\n"
2342 "if (template_selection != SPECIFIC_VALUE || is_ifpresent) return false;\n"
2343 "switch (single_value.union_selection) {\n"
2344 , name);
2345 for (i = 0; i < sdef->nElements; i++) {
2346 src = mputprintf(src, "case %s_%s:\n"
2347 "return single_value.field_%s->is_value();\n", selection_prefix,
2348 sdef->elements[i].name, sdef->elements[i].name);
2349 }
2350 src = mputprintf(src, "default:\n"
2351 "TTCN_error(\"Internal error: Invalid selector in a specific value when "
2352 "performing is_value operation on a template of union type %s.\");\n"
2353 "}\n"
2354 "}\n\n", dispname);
2355
2356 /* valueof member function */
2357 def = mputprintf(def, "%s valueof() const;\n", name);
2358 src = mputprintf(src, "%s %s_template::valueof() const\n"
2359 "{\n"
2360 "if (template_selection != SPECIFIC_VALUE || is_ifpresent)\n"
2361 "TTCN_error(\"Performing valueof or send operation on a non-specific "
2362 "template of union type %s.\");\n"
2363 "%s ret_val;\n"
2364 "switch (single_value.union_selection) {\n", name, name, dispname, name);
2365 for (i = 0; i < sdef->nElements; i++) {
2366 src = mputprintf(src, "case %s_%s:\n"
2367 "ret_val.%s%s() = single_value.field_%s->valueof();\n"
2368 "break;\n", selection_prefix, sdef->elements[i].name,
2369 at_field, sdef->elements[i].name, sdef->elements[i].name);
2370 }
2371 src = mputprintf(src, "default:\n"
2372 "TTCN_error(\"Internal error: Invalid selector in a specific value when "
2373 "performing valueof operation on a template of union type %s.\");\n"
2374 "}\n"
2375 "%s"
2376 "return ret_val;\n"
2377 "}\n\n", dispname,
2378 use_runtime_2 ? "ret_val.set_err_descr(err_descr);\n" : "");
2379
2380 /* list_item(int) function */
2381 def = mputprintf(def, "%s_template& list_item(unsigned int list_index) "
2382 "const;\n", name);
2383 src = mputprintf(src,
2384 "%s_template& %s_template::list_item(unsigned int list_index) const\n"
2385 "{\n"
2386 "if (template_selection != VALUE_LIST && "
2387 "template_selection != COMPLEMENTED_LIST) TTCN_error(\"Internal error: "
2388 "Accessing a list element of a non-list template of union type %s.\");\n"
2389 "if (list_index >= value_list.n_values) "
2390 "TTCN_error(\"Internal error: Index overflow in a value list template "
2391 "of union type %s.\");\n"
2392 "return value_list.list_value[list_index];\n"
2393 "}\n", name, name, dispname, dispname);
2394
2395 /* void set_type(template_sel, int) function */
2396 def = mputstr(def, "void set_type(template_sel template_type, "
2397 "unsigned int list_length);\n");
2398 src = mputprintf(src,
2399 "void %s_template::set_type(template_sel template_type, "
2400 "unsigned int list_length)\n"
2401 "{\n"
2402 "if (template_type != VALUE_LIST && template_type != COMPLEMENTED_LIST) "
2403 "TTCN_error (\"Internal error: Setting an invalid list for a template "
2404 "of union type %s.\");\n"
2405 "clean_up();\n"
2406 "set_selection(template_type);\n"
2407 "value_list.n_values = list_length;\n"
2408 "value_list.list_value = new %s_template[list_length];\n"
2409 "}\n\n", name, dispname, name);
2410
2411 /* field access functions */
2412 for (i = 0; i < sdef->nElements; i++) {
2413 def = mputprintf(def, "%s_template& %s%s();\n", sdef->elements[i].type,
2414 at_field, sdef->elements[i].name);
2415 src = mputprintf(src, "%s_template& %s_template::%s%s()\n"
2416 "{\n"
2417 "if (template_selection != SPECIFIC_VALUE || "
2418 "single_value.union_selection != %s_%s) {\n"
2419 "template_sel old_selection = template_selection;\n"
2420 "clean_up();\n"
2421 "if (old_selection == ANY_VALUE || old_selection == ANY_OR_OMIT) "
2422 "single_value.field_%s = new %s_template(ANY_VALUE);\n"
2423 "else single_value.field_%s = new %s_template;\n"
2424 "single_value.union_selection = %s_%s;\n"
2425 "set_selection(SPECIFIC_VALUE);\n"
2426 "}\n"
2427 "return *single_value.field_%s;\n"
2428 "}\n\n", sdef->elements[i].type, name, at_field, sdef->elements[i].name,
2429 selection_prefix, sdef->elements[i].name, sdef->elements[i].name,
2430 sdef->elements[i].type, sdef->elements[i].name, sdef->elements[i].type,
2431 selection_prefix, sdef->elements[i].name, sdef->elements[i].name);
2432
2433 def = mputprintf(def, "const %s_template& %s%s() const;\n",
2434 sdef->elements[i].type, at_field, sdef->elements[i].name);
2435 src = mputprintf(src, "const %s_template& %s_template::%s%s() const\n"
2436 "{\n"
2437 "if (template_selection != SPECIFIC_VALUE) TTCN_error(\"Accessing field "
2438 "%s in a non-specific template of union type %s.\");\n"
2439 "if (single_value.union_selection != %s_%s) "
2440 "TTCN_error(\"Accessing non-selected field %s in a template of union "
2441 "type %s.\");\n"
2442 "return *single_value.field_%s;\n"
2443 "}\n\n", sdef->elements[i].type, name, at_field, sdef->elements[i].name,
2444 sdef->elements[i].dispname, dispname, selection_prefix,
2445 sdef->elements[i].name, sdef->elements[i].dispname, dispname,
2446 sdef->elements[i].name);
2447 }
2448
2449 /* ischosen function */
2450 def = mputprintf(def, "boolean ischosen(%s checked_selection) const;\n",
2451 selection_type);
2452 src = mputprintf(src, "boolean %s_template::ischosen(%s checked_selection) "
2453 "const\n"
2454 "{\n"
2455 "if (checked_selection == %s) TTCN_error(\"Internal error: Performing "
2456 "ischosen() operation on an invalid field of union type %s.\");\n"
2457 "switch (template_selection) {\n"
2458 "case SPECIFIC_VALUE:\n"
2459 "if (single_value.union_selection == %s) TTCN_error(\"Internal error: "
2460 "Invalid selector in a specific value when performing ischosen() "
2461 "operation on a template of union type %s.\");\n"
2462 "return single_value.union_selection == checked_selection;\n"
2463 "case VALUE_LIST:\n"
2464 "{\n"
2465 "if (value_list.n_values < 1)\n"
2466 "TTCN_error(\"Internal error: Performing ischosen() operation on a "
2467 "template of union type %s containing an empty list.\");\n"
2468 "boolean ret_val = "
2469 "value_list.list_value[0].ischosen(checked_selection);\n"
2470 "boolean all_same = TRUE;\n"
2471 "for (unsigned int list_count = 1; list_count < value_list.n_values; "
2472 "list_count++) {\n"
2473 "if (value_list.list_value[list_count].ischosen(checked_selection) != "
2474 "ret_val) {\n"
2475 "all_same = FALSE;\n"
2476 "break;\n"
2477 "}\n"
2478 "}\n"
2479 "if (all_same) return ret_val;\n"
2480 "}\n"
2481 "case ANY_VALUE:\n"
2482 "case ANY_OR_OMIT:\n"
2483 "case OMIT_VALUE:\n"
2484 "case COMPLEMENTED_LIST:\n"
2485 "TTCN_error(\"Performing ischosen() operation on a template of union type "
2486 "%s, which does not determine unambiguously the chosen field of the "
2487 "matching values.\");\n"
2488 "default:\n"
2489 "TTCN_error(\"Performing ischosen() operation on an uninitialized "
2490 "template of union type %s\");\n"
2491 "}\n"
2492 "return FALSE;\n"
2493 "}\n\n", name, selection_type, unbound_value, dispname, unbound_value,
2494 dispname, dispname, dispname, dispname);
2495
2496 if (use_runtime_2) {
2497 def = mputstr(def,
2498 "void set_err_descr(Erroneous_descriptor_t* p_err_descr) { err_descr=p_err_descr; }\n");
2499 /** virtual stuff */
2500 def = mputstr(def,
2501 "void valueofv(Base_Type* value) const;\n"
2502 "void set_value(template_sel other_value);\n"
2503 "void copy_value(const Base_Type* other_value);\n"
2504 "Base_Template* clone() const;\n"
2505 "const TTCN_Typedescriptor_t* get_descriptor() const;\n"
2506 "boolean matchv(const Base_Type* other_value, boolean legacy) const;\n"
2507 "void log_matchv(const Base_Type* match_value, boolean legacy) const;\n");
2508 src = mputprintf(src,
2509 "void %s_template::valueofv(Base_Type* value) const "
2510 "{ *(static_cast<%s*>(value)) = valueof(); }\n"
2511 "void %s_template::set_value(template_sel other_value) "
2512 "{ *this = other_value; }\n"
2513 "void %s_template::copy_value(const Base_Type* other_value) "
2514 "{ *this = *(static_cast<const %s*>(other_value)); }\n"
2515 "Base_Template* %s_template::clone() const "
2516 "{ return new %s_template(*this); }\n"
2517 "const TTCN_Typedescriptor_t* %s_template::get_descriptor() const "
2518 "{ return &%s_descr_; }\n"
2519 "boolean %s_template::matchv(const Base_Type* other_value, "
2520 "boolean legacy) const "
2521 "{ return match(*(static_cast<const %s*>(other_value)), legacy); }\n"
2522 "void %s_template::log_matchv(const Base_Type* match_value, "
2523 "boolean legacy) const "
2524 " { log_match(*(static_cast<const %s*>(match_value)), legacy); }\n",
2525 name, name,
2526 name,
2527 name, name,
2528 name, name,
2529 name, name,
2530 name, name,
2531 name, name);
2532 }
2533
2534 /* log function */
2535 def = mputstr(def, "void log() const;\n");
2536 src = mputprintf(src,"void %s_template::log() const\n"
2537 "{\n"
2538 "switch (template_selection) {\n"
2539 "case SPECIFIC_VALUE:\n"
2540 "switch (single_value.union_selection) {\n", name);
2541 for (i = 0; i < sdef->nElements; i++) {
2542 src = mputprintf(src, "case %s_%s:\n"
2543 "TTCN_Logger::log_event_str(\"{ %s := \");\n"
2544 "single_value.field_%s->log();\n"
2545 "TTCN_Logger::log_event_str(\" }\");\n"
2546 "break;\n", selection_prefix, sdef->elements[i].name,
2547 sdef->elements[i].dispname, sdef->elements[i].name);
2548 }
2549 src = mputstr(src, "default:\n"
2550 "TTCN_Logger::log_event_str(\"<invalid selector>\");\n"
2551 "}\n"
2552 "break;\n"
2553 "case COMPLEMENTED_LIST:\n"
2554 "TTCN_Logger::log_event_str(\"complement \");\n"
2555 "case VALUE_LIST:\n"
2556 "TTCN_Logger::log_char('(');\n"
2557 "for (unsigned int list_count = 0; list_count < value_list.n_values; "
2558 "list_count++) {\n"
2559 "if (list_count > 0) TTCN_Logger::log_event_str(\", \");\n"
2560 "value_list.list_value[list_count].log();\n"
2561 "}\n"
2562 "TTCN_Logger::log_char(')');\n"
2563 "break;\n"
2564 "default:\n"
2565 "log_generic();\n"
2566 "}\n"
2567 "log_ifpresent();\n");
2568 if (use_runtime_2) {
2569 src = mputstr(src, "if (err_descr) err_descr->log();\n");
2570 }
2571 src = mputstr(src, "}\n\n");
2572
2573 /* log_match function */
2574 def = mputprintf(def, "void log_match(const %s& match_value, "
2575 "boolean legacy = FALSE) const;\n", name);
2576 src = mputprintf(src,
2577 "void %s_template::log_match(const %s& match_value, boolean legacy) const\n"
2578 "{\n"
2579 "if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity() "
2580 "&& match(match_value, legacy)){\n"
2581 "TTCN_Logger::print_logmatch_buffer();\n"
2582 "TTCN_Logger::log_event_str(\" matched\");\n"
2583 "return;\n"
2584 "}\n"
2585 "if (template_selection == SPECIFIC_VALUE && "
2586 "single_value.union_selection == match_value.get_selection()) {\n"
2587 "switch (single_value.union_selection) {\n", name, name);
2588 for (i = 0; i < sdef->nElements; i++) {
2589 src = mputprintf(src, "case %s_%s:\n"
2590 "if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){\n"
2591 "TTCN_Logger::log_logmatch_info(\".%s\");\n"
2592 "single_value.field_%s->log_match(match_value.%s%s(), legacy);\n"
2593 "} else {\n"
2594 "TTCN_Logger::log_event_str(\"{ %s := \");\n"
2595 "single_value.field_%s->log_match(match_value.%s%s(), legacy);\n"
2596 "TTCN_Logger::log_event_str(\" }\");\n"
2597 "}\n"
2598 "break;\n", selection_prefix, sdef->elements[i].name,
2599 sdef->elements[i].dispname,
2600 sdef->elements[i].name, at_field, sdef->elements[i].name,
2601 sdef->elements[i].dispname, sdef->elements[i].name,
2602 at_field, sdef->elements[i].name);
2603 }
2604 src = mputstr(src, "default:\n"
2605 "TTCN_Logger::print_logmatch_buffer();\n"
2606 "TTCN_Logger::log_event_str(\"<invalid selector>\");\n"
2607 "}\n"
2608 "} else {\n"
2609 "TTCN_Logger::print_logmatch_buffer();\n"
2610 "match_value.log();\n"
2611 "TTCN_Logger::log_event_str(\" with \");\n"
2612 "log();\n"
2613 "if (match(match_value, legacy)) TTCN_Logger::log_event_str(\" matched\");\n"
2614 "else TTCN_Logger::log_event_str(\" unmatched\");\n"
2615 "}\n"
2616 "}\n\n");
2617
2618 /* encode_text function */
2619 def = mputstr(def, "void encode_text(Text_Buf& text_buf) const;\n");
2620 src = mputprintf(src,
2621 "void %s_template::encode_text(Text_Buf& text_buf) const\n"
2622 "{\n"
2623 "encode_text_base(text_buf);\n"
2624 "switch (template_selection) {\n"
2625 "case SPECIFIC_VALUE:\n"
2626 "text_buf.push_int(single_value.union_selection);\n"
2627 "switch (single_value.union_selection) {\n", name);
2628 for (i = 0; i < sdef->nElements; i++) {
2629 src = mputprintf(src, "case %s_%s:\n"
2630 "single_value.field_%s->encode_text(text_buf);\n"
2631 "break;\n", selection_prefix, sdef->elements[i].name,
2632 sdef->elements[i].name);
2633 }
2634 src = mputprintf(src, "default:\n"
2635 "TTCN_error(\"Internal error: Invalid selector in a specific value when "
2636 "encoding a template of union type %s.\");\n"
2637 "}\n"
2638 "case OMIT_VALUE:\n"
2639 "case ANY_VALUE:\n"
2640 "case ANY_OR_OMIT:\n"
2641 "break;\n"
2642 "case VALUE_LIST:\n"
2643 "case COMPLEMENTED_LIST:\n"
2644 "text_buf.push_int(value_list.n_values);\n"
2645 "for (unsigned int list_count = 0; list_count < value_list.n_values; "
2646 "list_count++)\n"
2647 "value_list.list_value[list_count].encode_text(text_buf);\n"
2648 "break;\n"
2649 "default:\n"
2650 "TTCN_error(\"Text encoder: Encoding an uninitialized template of type "
2651 "%s.\");\n"
2652 "}\n"
2653 "}\n\n", dispname, dispname);
2654
2655 /* decode_text function */
2656 def = mputstr(def, "void decode_text(Text_Buf& text_buf);\n");
2657 src = mputprintf(src, "void %s_template::decode_text(Text_Buf& text_buf)\n"
2658 "{\n"
2659 "clean_up();\n"
2660 "decode_text_base(text_buf);\n"
2661 "switch (template_selection) {\n"
2662 "case SPECIFIC_VALUE:\n"
2663 "{\n"
2664 "single_value.union_selection = %s;\n"
2665 "%s new_selection = (%s)text_buf.pull_int().get_val();\n"
2666 "switch (new_selection) {\n", name, unbound_value, selection_type,
2667 selection_type);
2668 for (i = 0; i < sdef->nElements; i++) {
2669 src = mputprintf(src, "case %s_%s:\n"
2670 "single_value.field_%s = new %s_template;\n"
2671 "single_value.field_%s->decode_text(text_buf);\n"
2672 "break;\n", selection_prefix, sdef->elements[i].name,
2673 sdef->elements[i].name, sdef->elements[i].type, sdef->elements[i].name);
2674 }
2675 src = mputprintf(src, "default:\n"
2676 "TTCN_error(\"Text decoder: Unrecognized union selector was received for "
2677 "a template of type %s.\");\n"
2678 "}\n"
2679 "single_value.union_selection = new_selection;\n"
2680 "}\n"
2681 "case OMIT_VALUE:\n"
2682 "case ANY_VALUE:\n"
2683 "case ANY_OR_OMIT:\n"
2684 "break;\n"
2685 "case VALUE_LIST:\n"
2686 "case COMPLEMENTED_LIST:\n"
2687 "value_list.n_values = text_buf.pull_int().get_val();\n"
2688 "value_list.list_value = new %s_template[value_list.n_values];\n"
2689 "for (unsigned int list_count = 0; list_count < value_list.n_values; "
2690 "list_count++)\n"
2691 "value_list.list_value[list_count].decode_text(text_buf);\n"
2692 "break;\n"
2693 "default:\n"
2694 "TTCN_error(\"Text decoder: Unrecognized selector was received in a "
2695 "template of type %s.\");\n"
2696 "}\n"
2697 "}\n\n", dispname, name, dispname);
2698
2699 /* TTCN-3 ispresent() function */
2700 def = mputstr(def, "boolean is_present(boolean legacy = FALSE) const;\n");
2701 src = mputprintf(src,
2702 "boolean %s_template::is_present(boolean legacy) const\n"
2703 "{\n"
2704 "if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;\n"
2705 "return !match_omit(legacy);\n"
2706 "}\n\n", name);
2707
2708 /* match_omit() */
2709 def = mputstr(def, "boolean match_omit(boolean legacy = FALSE) const;\n");
2710 src = mputprintf(src,
2711 "boolean %s_template::match_omit(boolean legacy) const\n"
2712 "{\n"
2713 "if (is_ifpresent) return TRUE;\n"
2714 "switch (template_selection) {\n"
2715 "case OMIT_VALUE:\n"
2716 "case ANY_OR_OMIT:\n"
2717 "return TRUE;\n"
2718 "case VALUE_LIST:\n"
2719 "case COMPLEMENTED_LIST:\n"
2720 "if (legacy) {\n"
2721 "for (unsigned int v_idx=0; v_idx<value_list.n_values; v_idx++)\n"
2722 "if (value_list.list_value[v_idx].match_omit())\n"
2723 "return template_selection==VALUE_LIST;\n"
2724 "return template_selection==COMPLEMENTED_LIST;\n"
2725 "} // else fall through\n"
2726 "default:\n"
2727 "return FALSE;\n"
2728 "}\n"
2729 "return FALSE;\n"
2730 "}\n\n", name);
2731
2732 /* set_param() */
2733 def = mputstr(def, "void set_param(Module_Param& param);\n");
2734 src = mputprintf(src,
2735 "void %s_template::set_param(Module_Param& param)\n"
2736 "{\n"
2737 " if (dynamic_cast<Module_Param_Name*>(param.get_id()) != NULL &&\n"
2738 " param.get_id()->next_name()) {\n"
2739 // Haven't reached the end of the module parameter name
2740 // => the name refers to one of the fields, not to the whole union
2741 " char* param_field = param.get_id()->get_current_name();\n"
2742 " if (param_field[0] >= '0' && param_field[0] <= '9') {\n"
2743 " param.error(\"Unexpected array index in module parameter, expected a valid field\"\n"
2744 " \" name for union template type `%s'\");\n"
2745 " }\n"
2746 " ", name, dispname);
2747 for (i = 0; i < sdef->nElements; i++) {
2748 src = mputprintf(src,
2749 "if (strcmp(\"%s\", param_field) == 0) {\n"
2750 " %s%s().set_param(param);\n"
2751 " return;\n"
2752 " } else ",
2753 sdef->elements[i].dispname, at_field, sdef->elements[i].name);
2754 }
2755 src = mputprintf(src,
2756 "param.error(\"Field `%%s' not found in union template type `%s'\", param_field);\n"
2757 " }\n"
2758 " param.basic_check(Module_Param::BC_TEMPLATE, \"union template\");\n"
2759 " Module_Param_Ptr mp = &param;\n"
2760 " if (param.get_type() == Module_Param::MP_Reference) {\n"
2761 " mp = param.get_referenced_param();\n"
2762 " }\n"
2763 " switch (mp->get_type()) {\n"
2764 " case Module_Param::MP_Omit:\n"
2765 " *this = OMIT_VALUE;\n"
2766 " break;\n"
2767 " case Module_Param::MP_Any:\n"
2768 " *this = ANY_VALUE;\n"
2769 " break;\n"
2770 " case Module_Param::MP_AnyOrNone:\n"
2771 " *this = ANY_OR_OMIT;\n"
2772 " break;\n"
2773 " case Module_Param::MP_List_Template:\n"
2774 " case Module_Param::MP_ComplementList_Template: {\n"
2775 " %s_template temp;\n"
2776 " temp.set_type(mp->get_type()==Module_Param::MP_List_Template ? "
2777 "VALUE_LIST : COMPLEMENTED_LIST, mp->get_size());\n"
2778 " for (size_t p_i=0; p_i<mp->get_size(); p_i++) {\n"
2779 " temp.list_item(p_i).set_param(*mp->get_elem(p_i));\n"
2780 " }\n"
2781 " *this = temp;\n"
2782 " break; }\n"
2783 " case Module_Param::MP_Value_List:\n"
2784 " if (mp->get_size()==0) break;\n" /* for backward compatibility */
2785 " param.type_error(\"union template\", \"%s\");\n"
2786 " break;\n"
2787 " case Module_Param::MP_Assignment_List: {\n"
2788 " Module_Param* mp_last = mp->get_elem(mp->get_size()-1);\n",
2789 dispname, name, dispname);
2790 for (i = 0; i < sdef->nElements; i++) {
2791 src = mputprintf(src,
2792 " if (!strcmp(mp_last->get_id()->get_name(), \"%s\")) {\n"
2793 " %s%s().set_param(*mp_last);\n"
2794 " break;\n"
2795 " }\n", sdef->elements[i].dispname, at_field, sdef->elements[i].name);
2796 }
2797 src = mputprintf(src,
2798 " mp_last->error(\"Field %%s does not exist in type %s.\", mp_last->get_id()->get_name());\n"
2799 " } break;\n"
2800 " default:\n"
2801 " param.type_error(\"union template\", \"%s\");\n"
2802 " }\n"
2803 " is_ifpresent = param.get_ifpresent() || mp->get_ifpresent();\n"
2804 "}\n\n", dispname, dispname);
2805
2806 /* get_param() */
2807 def = mputstr(def, "Module_Param* get_param(Module_Param_Name& param_name) const;\n");
2808 src = mputprintf(src,
2809 "Module_Param* %s_template::get_param(Module_Param_Name& param_name) const\n"
2810 "{\n"
2811 " if (param_name.next_name()) {\n"
2812 // Haven't reached the end of the module parameter name
2813 // => the name refers to one of the fields, not to the whole union
2814 " char* param_field = param_name.get_current_name();\n"
2815 " if (param_field[0] >= '0' && param_field[0] <= '9') {\n"
2816 " TTCN_error(\"Unexpected array index in module parameter reference, \"\n"
2817 " \"expected a valid field name for union template type `%s'\");\n"
2818 " }\n"
2819 " ", name, dispname);
2820 for (i = 0; i < sdef->nElements; i++) {
2821 src = mputprintf(src,
2822 "if (strcmp(\"%s\", param_field) == 0) {\n"
2823 " return %s%s().get_param(param_name);\n"
2824 " } else ",
2825 sdef->elements[i].dispname, at_field, sdef->elements[i].name);
2826 }
2827 src = mputprintf(src,
2828 "TTCN_error(\"Field `%%s' not found in union type `%s'\", param_field);\n"
2829 " }\n"
2830 " Module_Param* mp = NULL;\n"
2831 " switch (template_selection) {\n"
2832 " case UNINITIALIZED_TEMPLATE:\n"
2833 " mp = new Module_Param_Unbound();\n"
2834 " break;\n"
2835 " case OMIT_VALUE:\n"
2836 " mp = new Module_Param_Omit();\n"
2837 " break;\n"
2838 " case ANY_VALUE:\n"
2839 " mp = new Module_Param_Any();\n"
2840 " break;\n"
2841 " case ANY_OR_OMIT:\n"
2842 " mp = new Module_Param_AnyOrNone();\n"
2843 " break;\n"
2844 " case SPECIFIC_VALUE: {\n"
2845 " Module_Param* mp_field = NULL;\n"
2846 " switch(single_value.union_selection) {\n"
2847 , name);
2848 for (i = 0; i < sdef->nElements; ++i) {
2849 src = mputprintf(src,
2850 " case %s_%s:\n"
2851 " mp_field = single_value.field_%s->get_param(param_name);\n"
2852 " mp_field->set_id(new Module_Param_FieldName(mcopystr(\"%s\")));\n"
2853 " break;\n"
2854 , selection_prefix, sdef->elements[i].name
2855 , sdef->elements[i].name, sdef->elements[i].dispname);
2856 }
2857 src = mputstr(src,
2858 " default:\n"
2859 " break;\n"
2860 " }\n"
2861 " mp = new Module_Param_Assignment_List();\n"
2862 " mp->add_elem(mp_field);\n"
2863 " break; }\n"
2864 " case VALUE_LIST:\n"
2865 " case COMPLEMENTED_LIST: {\n"
2866 " if (template_selection == VALUE_LIST) {\n"
2867 " mp = new Module_Param_List_Template();\n"
2868 " }\n"
2869 " else {\n"
2870 " mp = new Module_Param_ComplementList_Template();\n"
2871 " }\n"
2872 " for (size_t i = 0; i < value_list.n_values; ++i) {\n"
2873 " mp->add_elem(value_list.list_value[i].get_param(param_name));\n"
2874 " }\n"
2875 " break; }\n"
2876 " default:\n"
2877 " break;\n"
2878 " }\n"
2879 " if (is_ifpresent) {\n"
2880 " mp->set_ifpresent();\n"
2881 " }\n"
2882 " return mp;\n"
2883 "}\n\n");
2884
2885 /* check template restriction */
2886 def = mputstr(def, "void check_restriction(template_res t_res, "
2887 "const char* t_name=NULL, boolean legacy = FALSE) const;\n");
2888 src = mputprintf(src,
2889 "void %s_template::check_restriction("
2890 "template_res t_res, const char* t_name, boolean legacy) const\n"
2891 "{\n"
2892 "if (template_selection==UNINITIALIZED_TEMPLATE) return;\n"
2893 "switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {\n"
2894 "case TR_OMIT:\n"
2895 "if (template_selection==OMIT_VALUE) return;\n"
2896 "case TR_VALUE:\n"
2897 "if (template_selection!=SPECIFIC_VALUE || is_ifpresent) break;\n"
2898 "switch (single_value.union_selection) {\n"
2899 , name);
2900 for (i = 0; i < sdef->nElements; i++) {
2901 src = mputprintf(src, "case %s_%s:\n"
2902 "single_value.field_%s->check_restriction("
2903 "t_res, t_name ? t_name : \"%s\");\n"
2904 "return;\n",
2905 selection_prefix, sdef->elements[i].name,
2906 sdef->elements[i].name, dispname);
2907 }
2908 src = mputprintf(src, "default:\n"
2909 "TTCN_error(\"Internal error: Invalid selector in a specific value when "
2910 "performing check_restriction operation on a template of union type %s.\");\n"
2911 "}\n"
2912 "case TR_PRESENT:\n"
2913 "if (!match_omit(legacy)) return;\n"
2914 "break;\n"
2915 "default:\n"
2916 "return;\n"
2917 "}\n"
2918 "TTCN_error(\"Restriction `%%s' on template of type %%s violated.\", "
2919 "get_res_name(t_res), t_name ? t_name : \"%s\");\n"
2920 "}\n\n", dispname, dispname);
2921
2922 def = mputstr(def, "};\n\n");
2923
2924 output->header.class_defs = mputstr(output->header.class_defs, def);
2925 Free(def);
2926
2927 output->source.methods = mputstr(output->source.methods, src);
2928 Free(src);
2929
2930 Free(selection_type);
2931 Free(unbound_value);
2932 Free(selection_prefix);
2933 }
This page took 0.177025 seconds and 6 git commands to generate.