1 /******************************************************************************
2 * Copyright (c) 2000-2016 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
16 * Szabo, Janos Zoltan – initial implementation
18 ******************************************************************************/
20 #include "../common/memory.h"
21 #include "functionref.h"
27 void defFunctionrefClass(const funcref_def
*fdef
, output_struct
*output
)
29 char *def
= NULL
, *src
= NULL
;
30 const char *name
= fdef
->name
;
31 const char *dispname
= fdef
->dispname
;
33 const char *return_type
, *fat_string
;
35 if (fdef
->return_type
!= NULL
) return_type
= fdef
->return_type
;
36 else return_type
= "void";
40 fat_string
= "function";
43 fat_string
= "altstep";
46 fat_string
= "testcase";
50 FATAL_ERROR("defFunctionrefClass(): invalid type");
53 /* class declaration code */
54 output
->header
.class_decls
= mputprintf(output
->header
.class_decls
,
57 /* class definition */
60 "// written by %s in " __FILE__
" at %d\n"
62 "class %s : public Base_Type {\n"
65 , __FUNCTION__
, __LINE__
71 def
= mputstr(def
, "typedef ");
72 /* work-around for GCC versions earlier than 3.4:
73 * parse error occurs within the typedef if the return type is the same
74 * as the function type itself */
75 if (!strcmp(name
, return_type
)) def
= mputstr(def
, "class ");
76 def
= mputprintf(def
, "%s (*function_pointer)(%s);\n"
77 "typedef void (*start_pointer)(const COMPONENT& "
78 "component_reference", return_type
, fdef
->formal_par_list
);
79 if (fdef
->formal_par_list
[0] != '\0') def
= mputstr(def
, ", ");
80 def
= mputprintf(def
, "%s);\n", fdef
->formal_par_list
);
83 def
= mputprintf(def
, "typedef void (*standalone_pointer)(%s);\n"
84 "typedef Default_Base* (*activate_pointer)(%s);\n"
85 "typedef alt_status (*function_pointer)(%s);\n", fdef
->formal_par_list
,
86 fdef
->formal_par_list
, fdef
->formal_par_list
);
89 def
= mputprintf(def
, "typedef verdicttype (*function_pointer)(%s);\n",
90 fdef
->formal_par_list
);
96 "friend class %s_template;\n"
97 "friend boolean operator==(%s::function_pointer value, "
98 "const %s& other_value);\n"
99 "function_pointer referred_function;\n"
102 /* default constructor */
103 def
= mputprintf(def
,"public:\n"
105 src
= mputprintf(src
,"%s::%s()\n"
107 "referred_function = NULL;\n"
108 "}\n\n", name
, name
);
110 def
= mputprintf(def
,"%s(function_pointer other_value);\n", name
);
111 src
= mputprintf(src
,"%s::%s(function_pointer other_value)\n"
113 "referred_function = other_value;\n"
114 "}\n\n", name
, name
);
116 /* copy constructor */
117 def
= mputprintf(def
,"%s(const %s& other_value);\n", name
, name
);
118 src
= mputprintf(src
,"%s::%s(const %s& other_value)\n"
119 ": Base_Type()" /* call the *default* constructor as before */
121 "other_value.must_bound(\"Copying an unbound %s value.\");\n"
122 "referred_function = other_value.referred_function;\n"
123 "}\n\n", name
, name
, name
, dispname
);
126 def
=mputprintf(def
,"%s& operator=(function_pointer other_value);\n", name
);
127 src
=mputprintf(src
,"%s& %s::operator=(function_pointer other_value)\n"
129 "referred_function = other_value;\n"
131 "}\n\n", name
, name
);
133 def
= mputprintf(def
,"%s& operator=(const %s& other_value);\n",
135 src
= mputprintf(src
,"%s& %s::operator=(const %s& other_value)\n"
137 "other_value.must_bound(\"Assignment of an unbound value.\");\n"
138 "referred_function = other_value.referred_function;\n"
140 "}\n\n", name
, name
, name
);
143 def
= mputstr(def
,"boolean operator==(function_pointer other_value) "
145 src
= mputprintf(src
,"boolean %s::operator==(function_pointer other_value) "
148 "must_bound(\"Unbound left operand of %s comparison.\");\n"
149 "return referred_function == other_value;\n"
150 "}\n\n", name
, dispname
);
151 def
= mputprintf(def
,"boolean operator==(const %s& other_value) const;\n"
153 src
= mputprintf(src
,"boolean %s::operator==(const %s& other_value) const\n"
155 "must_bound(\"Unbound left operand of %s comparison.\");\n"
156 "other_value.must_bound(\"Unbound right operand of %s comparison.\");\n"
157 "return referred_function == other_value.referred_function;\n"
158 "}\n\n", name
, name
, dispname
, dispname
);
161 def
= mputprintf(def
,"inline boolean operator!=(function_pointer other_value)"
163 "{ return !(*this == other_value); }\n"
164 "inline boolean operator!=(const %s& other_value) const\n"
165 "{ return !(*this == other_value); }\n\n", name
);
169 def
= mputprintf(def
,"%s invoke(%s) const;\n"
170 , return_type
, fdef
->formal_par_list
);
171 src
= mputprintf(src
,"%s %s::invoke(%s) const\n"
173 "must_bound(\"Call of unbound function.\");\n"
174 "if(referred_function == "
175 "(%s::function_pointer)Module_List::get_fat_null())\n"
176 "TTCN_error(\"null reference cannot be invoked.\");\n"
177 "%sreferred_function(%s);\n"
178 "}\n\n", return_type
, name
, fdef
->formal_par_list
, name
179 , fdef
->return_type
!= NULL
? "return ": "", fdef
->actual_par_list
);
180 if(fdef
->is_startable
) {
181 def
= mputprintf(def
,"void start(const COMPONENT& component_reference%s"
182 "%s) const;\n", strcmp(fdef
->formal_par_list
,"")?", ":""
183 , fdef
->formal_par_list
);
184 src
= mputprintf(src
,"void %s::start(const COMPONENT& "
185 "component_reference%s%s) const\n{\n"
186 "((%s::start_pointer)Module_List::lookup_start_by_function_address"
187 "((genericfunc_t)referred_function))(component_reference%s%s);\n"
188 "}\n\n", name
, strcmp(fdef
->formal_par_list
,"")?", ":""
189 , fdef
->formal_par_list
, name
, strcmp(fdef
->formal_par_list
,"")?", ":""
190 , fdef
->actual_par_list
);
194 def
= mputprintf(def
,"void invoke_standalone(%s) const;\n",
195 fdef
->formal_par_list
);
196 src
= mputprintf(src
,"void %s::invoke_standalone(%s) const\n"
198 "((%s::standalone_pointer)"
199 "Module_List::lookup_standalone_address_by_altstep_address("
200 "(genericfunc_t)referred_function))(%s);\n"
201 "}\n\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
203 def
= mputprintf(def
,"Default_Base *activate(%s) const;\n"
204 , fdef
->formal_par_list
);
205 src
= mputprintf(src
,"Default_Base *%s::activate(%s) const\n"
207 "return ((%s::activate_pointer)"
208 "Module_List::lookup_activate_address_by_altstep_address("
209 "(genericfunc_t)referred_function))(%s);\n"
210 "}\n\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
212 def
= mputprintf(def
,"alt_status invoke(%s) const;\n"
213 , fdef
->formal_par_list
);
214 src
= mputprintf(src
,"alt_status %s::invoke(%s) const\n"
216 "must_bound(\"Call of an unbound altstep.\");\n"
217 "if(referred_function == "
218 "(%s::function_pointer)Module_List::get_fat_null())\n"
219 "TTCN_error(\"null reference cannot be invoked.\");\n"
220 "return referred_function(%s);\n"
221 "}\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
225 def
= mputprintf(def
,"verdicttype execute(%s) const;\n",
226 fdef
->formal_par_list
);
227 src
= mputprintf(src
,"verdicttype %s::execute(%s) const\n"
229 "must_bound(\"Call of unbound testcase.\");\n"
230 "if(referred_function == "
231 "(%s::function_pointer)Module_List::get_fat_null())\n"
232 "TTCN_error(\"null reference cannot be executed.\");\n"
233 "return referred_function(%s);\n"
234 "}\n\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
239 def
= mputstr(def
,"inline boolean is_bound() "
240 "const { return referred_function != NULL; }\n");
242 def
= mputstr(def
,"inline boolean is_value() "
243 "const { return referred_function != NULL; }\n");
244 def
= mputstr(def
,"inline void clean_up() "
245 "{ referred_function = NULL; }\n");
246 def
= mputstr(def
,"inline void must_bound(const char *err_msg) const\n"
247 "{ if (referred_function == NULL) TTCN_error(\"%s\", err_msg); }\n\n");
253 /* functions in alternative runtime */
255 "boolean is_equal(const Base_Type* other_value) const;\n"
256 "void set_value(const Base_Type* other_value);\n"
257 "Base_Type* clone() const;\n"
258 "const TTCN_Typedescriptor_t* get_descriptor() const;\n");
259 src
= mputprintf(src
,
260 "boolean %s::is_equal(const Base_Type* other_value) const "
261 "{ return *this == *(static_cast<const %s*>(other_value)); }\n"
262 "void %s::set_value(const Base_Type* other_value) "
263 "{ *this = *(static_cast<const %s*>(other_value)); }\n"
264 "Base_Type* %s::clone() const { return new %s(*this); }\n"
265 "const TTCN_Typedescriptor_t* %s::get_descriptor() const "
266 "{ return &%s_descr_; }\n",
273 "inline boolean is_present() const { return is_bound(); }\n");
277 def
= mputstr(def
,"void log() const;\n");
278 src
= mputprintf(src
,"void %s::log() const\n"
280 "Module_List::log_%s((genericfunc_t)referred_function);\n"
281 "}\n\n",name
, fat_string
);
284 def
= mputstr(def
,"void set_param(Module_Param& param);\n");
285 src
= mputprintf(src
,"void %s::set_param(Module_Param& param)\n"
287 " param.error(\"Not supported.\");\n"
291 def
= mputstr(def
,"Module_Param* get_param(Module_Param_Name& param_name) const;\n");
292 src
= mputprintf(src
,"Module_Param* %s::get_param(Module_Param_Name& /* param_name */) const\n"
297 /* encode_text / decode_text */
298 def
= mputstr(def
,"void encode_text(Text_Buf& text_buf) const;\n");
299 src
= mputprintf(src
,"void %s::encode_text(Text_Buf&", name
);
300 if (fdef
->runs_on_self
) {
301 src
= mputprintf(src
, ") const\n"
303 "TTCN_error(\"Values of type %s cannot be sent to "
304 "other test components.\");\n", dispname
);
306 src
= mputprintf(src
, " text_buf) const\n"
308 "Module_List::encode_%s(text_buf,"
309 "(genericfunc_t)referred_function);\n", fat_string
);
311 src
= mputstr(src
,"}\n\n");
312 def
= mputstr(def
,"void decode_text(Text_Buf& text_buf);\n");
313 src
= mputprintf(src
,"void %s::decode_text(Text_Buf&", name
);
314 if (fdef
->runs_on_self
) {
315 src
= mputprintf(src
, ")\n"
317 "TTCN_error(\"Values of type %s cannot be received "
318 "from other test components.\");\n", dispname
);
320 src
= mputprintf(src
, " text_buf)\n"
322 "Module_List::decode_%s(text_buf,"
323 "(genericfunc_t*)&referred_function);\n", fat_string
);
325 src
= mputstr(src
,"}\n\n");
326 def
= mputstr(def
, "};\n\n");
328 def
= mputprintf(def
,"extern boolean operator==(%s::function_pointer value,"
329 " const %s& other_value);\n", name
, name
);
330 src
= mputprintf(src
,"boolean operator==(%s::function_pointer value, "
331 "const %s& other_value)\n"
333 "other_value.must_bound(\"Unbound right operand of %s comparison.\");\n"
334 "return value == other_value.referred_function;\n"
335 "}\n\n", name
, name
, dispname
);
336 def
= mputprintf(def
,"inline boolean operator!=(%s::function_pointer value,"
337 " const %s& other_value)\n"
338 "{ return !(value == other_value); } \n\n", name
, name
);
340 output
->header
.class_defs
= mputstr(output
->header
.class_defs
, def
);
343 output
->source
.methods
= mputstr(output
->source
.methods
, src
);
347 void defFunctionrefTemplate(const funcref_def
*fdef
, output_struct
*output
)
349 char *def
= NULL
, *src
= NULL
;
350 const char *name
= fdef
->name
;
351 const char *dispname
= fdef
->dispname
;
352 char *fat_string
= NULL
;
356 fat_string
= mputstr(fat_string
, "function");
359 fat_string
= mputstr(fat_string
, "altstep");
362 fat_string
= mputstr(fat_string
, "testcase");
366 /* class declaration */
367 output
->header
.class_decls
= mputprintf(output
->header
.class_decls
,
368 "class %s_template;\n", name
);
370 /* class definition */
371 def
= mputprintf(def
,"class %s_template : public Base_Template {\n"
373 "%s::function_pointer single_value;\n"
375 "unsigned int n_values;\n"
376 "%s_template *list_value;\n"
378 "};\n\n", name
, name
, name
);
381 def
= mputprintf(def
," void copy_template(const %s_template& other_value);\n"
383 src
= mputprintf(src
,"void %s_template::copy_template(const %s_template& "
386 "switch(other_value.template_selection) {\n"
387 "case SPECIFIC_VALUE:\n"
388 "single_value = other_value.single_value;\n"
392 "case ANY_OR_OMIT:\n"
395 "case COMPLEMENTED_LIST:\n"
396 "value_list.n_values = other_value.value_list.n_values;\n"
397 "value_list.list_value = new %s_template[value_list.n_values];\n"
398 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
399 "value_list.list_value[i] = other_value.value_list.list_value[i];\n"
402 "TTCN_error(\"Copying an unitialized/unsupported %s template.\");\n"
404 "set_selection(other_value);\n"
405 "}\n\n", name
, name
, name
, dispname
);
408 def
= mputprintf(def
,"public:\n"
409 "%s_template();\n", name
);
410 src
= mputprintf(src
,"%s_template::%s_template()\n"
411 "{\n}\n\n", name
, name
);
412 def
= mputprintf(def
,"%s_template(template_sel other_value);\n", name
);
413 src
= mputprintf(src
,"%s_template::%s_template(template_sel other_value)\n"
414 " : Base_Template(other_value)\n"
416 "check_single_selection(other_value);\n"
417 "}\n\n", name
, name
);
418 def
= mputprintf(def
,"%s_template(%s::function_pointer other_value);\n"
420 src
= mputprintf(src
,"%s_template::%s_template(%s::function_pointer "
422 " : Base_Template(SPECIFIC_VALUE)\n"
424 "single_value = other_value;\n"
425 "}\n\n", name
, name
, name
);
426 def
= mputprintf(def
,"%s_template(const %s& other_value);\n", name
, name
);
427 src
= mputprintf(src
,"%s_template::%s_template(const %s& other_value)\n"
428 " :Base_Template(SPECIFIC_VALUE)\n"
430 "other_value.must_bound(\"Creating a template from an unbound %s value."
432 "single_value = other_value.referred_function;\n"
433 "}\n\n", name
, name
, name
, dispname
);
434 def
= mputprintf(def
,"%s_template(const OPTIONAL<%s>& other_value);\n"
436 src
= mputprintf(src
,"%s_template::%s_template(const OPTIONAL<%s>& "
439 "if(other_value.ispresent()) {\n"
440 "set_selection(SPECIFIC_VALUE);\n"
441 "single_value = ((const %s&)other_value()).referred_function;\n"
442 "} else set_selection(OMIT_VALUE);\n"
443 "}\n\n", name
, name
, name
, name
);
444 def
= mputprintf(def
,"%s_template(const %s_template& other_value);\n"
446 src
= mputprintf(src
,"%s_template::%s_template(const %s_template& "
448 " :Base_Template()\n" /* yes, the default constructor */
450 "copy_template(other_value);\n"
451 "}\n\n", name
, name
, name
);
454 def
= mputprintf(def
,"~%s_template();\n", name
);
455 src
= mputprintf(src
,"%s_template::~%s_template()\n"
458 "}\n\n", name
, name
);
461 def
= mputstr(def
,"void clean_up();\n");
462 src
= mputprintf(src
,"void %s_template::clean_up()"
464 "if(template_selection == VALUE_LIST ||\n"
465 "template_selection == COMPLEMENTED_LIST)\n"
466 "delete[] value_list.list_value;\n"
467 "template_selection = UNINITIALIZED_TEMPLATE;\n"
471 def
= mputprintf(def
,"%s_template& operator=(template_sel other_value);\n"
473 src
= mputprintf(src
,"%s_template& %s_template::operator=(template_sel "
476 "check_single_selection(other_value);\n"
478 "set_selection(other_value);\n"
480 "}\n\n", name
, name
);
481 def
= mputprintf(def
,"%s_template& operator=(%s::function_pointer "
482 "other_value);\n", name
, name
);
483 src
= mputprintf(src
,"%s_template& %s_template::operator="
484 "(%s::function_pointer other_value)\n"
487 "set_selection(SPECIFIC_VALUE);\n"
488 "single_value = other_value;\n"
490 "}\n\n", name
, name
, name
);
491 def
= mputprintf(def
,"%s_template& operator=(const %s& other_value);\n"
493 src
= mputprintf(src
,"%s_template& %s_template::operator="
494 "(const %s& other_value)\n"
496 "other_value.must_bound(\"Assignment of an unbound %s value to a "
499 "set_selection(SPECIFIC_VALUE);\n"
500 "single_value = other_value.referred_function;\n"
502 "}\n\n", name
, name
, name
, dispname
);
503 def
= mputprintf(def
,"%s_template& operator=(const OPTIONAL<%s>& "
504 "other_value);\n", name
, name
);
505 src
= mputprintf(src
,"%s_template& %s_template::operator=(const "
506 "OPTIONAL<%s>& other_value)\n"
509 "if(other_value.ispresent()) { \n"
510 "set_selection(SPECIFIC_VALUE);\n"
511 "single_value = ((const %s&)other_value()).referred_function;\n"
512 "} else set_selection(OMIT_VALUE);\n"
514 "}\n\n", name
, name
, name
, name
);
515 def
= mputprintf(def
,"%s_template& operator=(const %s_template& "
516 "other_value);\n", name
, name
);
517 src
= mputprintf(src
,"%s_template& %s_template::operator=(const %s_template& "
520 "if(&other_value != this) {\n"
522 "copy_template(other_value);\n"
525 "}\n\n", name
,name
, name
);
527 /* match functions */
528 def
= mputprintf(def
,"boolean match(%s::function_pointer "
529 "other_value, boolean legacy = FALSE) const;\n", name
);
530 src
= mputprintf(src
,"boolean %s_template::match(%s::function_pointer "
531 "other_value, boolean) const\n"
533 "switch(template_selection) {\n"
534 "case SPECIFIC_VALUE:\n"
535 "return single_value == other_value;\n"
539 "case ANY_OR_OMIT:\n"
542 "case COMPLEMENTED_LIST:\n"
543 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
544 "if(value_list.list_value[i].match(other_value))\n"
545 "return template_selection == VALUE_LIST;\n"
546 "return template_selection == COMPLEMENTED_LIST;\n"
548 "TTCN_error(\"Matching with an unitialized/unsupported %s template."
552 "}\n\n", name
, name
, dispname
);
553 def
= mputprintf(def
,"boolean match(const %s& other_value, boolean legacy "
554 "= FALSE) const;\n", name
);
555 src
= mputprintf(src
,"boolean %s_template::match(const %s& other_value, "
558 " if (!other_value.is_bound()) return FALSE;\n"
559 "return match(other_value.referred_function);\n"
560 "}\n\n", name
, name
);
562 /* value of function */
563 def
= mputprintf(def
,"%s valueof() const;\n", name
);
564 src
= mputprintf(src
,"%s %s_template::valueof() const\n"
566 "if(template_selection != SPECIFIC_VALUE || is_ifpresent)\n"
567 "TTCN_error(\"Performing a valueof or send operation on a "
568 "non-specific %s template.\");\n"
569 "return single_value;\n}\n\n", name
, name
, dispname
);
572 def
= mputstr(def
,"void set_type(template_sel template_type, "
573 "unsigned int list_length);\n");
574 src
= mputprintf(src
,"void %s_template::set_type(template_sel template_type, "
575 "unsigned int list_length)\n"
577 "if(template_type != VALUE_LIST && "
578 "template_type != COMPLEMENTED_LIST)\n"
579 "TTCN_error(\"Setting an invalid type for an %s template.\");\n"
581 "set_selection(template_type);\n"
582 "value_list.n_values = list_length;\n"
583 "value_list.list_value = new %s_template[list_length];\n"
584 "}\n\n", name
, dispname
, name
);
587 def
= mputprintf(def
,"%s_template& list_item(unsigned int list_index) "
589 src
= mputprintf(src
,"%s_template& %s_template::list_item("
590 "unsigned int list_index) const\n"
592 "if(template_selection != VALUE_LIST && "
593 "template_selection != COMPLEMENTED_LIST)\n"
594 "TTCN_error(\"Accessing a list element of a non-list template of "
596 "if(list_index >= value_list.n_values)\n"
597 "TTCN_error(\"Index overflow in a value list template of type %s."
599 "return value_list.list_value[list_index];\n"
600 "}\n\n", name
, name
, dispname
, dispname
);
603 /* functions in alternative runtime */
605 "void valueofv(Base_Type* value) const;\n"
606 "void set_value(template_sel other_value);\n"
607 "void copy_value(const Base_Type* other_value);\n"
608 "Base_Template* clone() const;\n"
609 "const TTCN_Typedescriptor_t* get_descriptor() const;\n"
610 "boolean matchv(const Base_Type* other_value, boolean legacy) const;\n"
611 "void log_matchv(const Base_Type* match_value, boolean legacy) const;\n");
612 src
= mputprintf(src
,
613 "void %s_template::valueofv(Base_Type* value) const "
614 "{ *(static_cast<%s*>(value)) = valueof(); }\n"
615 "void %s_template::set_value(template_sel other_value) "
616 "{ *this = other_value; }\n"
617 "void %s_template::copy_value(const Base_Type* other_value) "
618 "{ *this = *(static_cast<const %s*>(other_value)); }\n"
619 "Base_Template* %s_template::clone() const "
620 "{ return new %s_template(*this); }\n"
621 "const TTCN_Typedescriptor_t* %s_template::get_descriptor() const "
622 "{ return &%s_descr_; }\n"
623 "boolean %s_template::matchv(const Base_Type* other_value, "
624 "boolean legacy) const "
625 "{ return match(*(static_cast<const %s*>(other_value)), legacy); }\n"
626 "void %s_template::log_matchv(const Base_Type* match_value, "
627 "boolean legacy) const "
628 " { log_match(*(static_cast<const %s*>(match_value)), legacy); }\n",
639 def
= mputstr(def
,"void log() const;\n");
640 src
= mputprintf(src
,"void %s_template::log() const\n"
642 "switch(template_selection) {\n"
643 "case SPECIFIC_VALUE:\n"
644 "Module_List::log_%s((genericfunc_t)single_value);\n"
646 "case COMPLEMENTED_LIST:\n"
647 "TTCN_Logger::log_event_str(\"complement \");\n"
649 "TTCN_Logger::log_char('(');\n"
650 "for(unsigned int i = 0; i < value_list.n_values; i++) {\n"
651 "if(i > 0) TTCN_Logger::log_event_str(\", \");\n"
652 "value_list.list_value[i].log();\n"
654 "TTCN_Logger::log_char(')');\n"
660 "}\n\n", name
, fat_string
);
662 /* log_match function */
663 def
= mputprintf(def
,"void log_match(const %s& match_value, "
664 "boolean legacy = FALSE) const;\n", name
);
665 src
= mputprintf(src
,"void %s_template::log_match(const %s& match_value, "
666 "boolean legacy) const\n"
669 "TTCN_Logger::log_event_str(\" with \");\n"
670 "match_value.log();\n"
671 "if(match(match_value, legacy)) TTCN_Logger::log_event_str(\" matched\");\n"
672 "else TTCN_Logger::log_event_str(\" unmatched\");\n"
673 "}\n\n", name
, name
);
675 /* encode_text / decode_text */
676 def
= mputstr(def
,"void encode_text(Text_Buf& text_buf) const;\n");
677 src
= mputprintf(src
,"void %s_template::encode_text(Text_Buf&", name
);
678 if (fdef
->runs_on_self
) {
679 src
= mputprintf(src
, ") const\n"
681 "TTCN_error(\"Templates of type %s cannot be sent to "
682 "other test components.\");\n", dispname
);
684 src
= mputprintf(src
, " text_buf) const\n"
686 "encode_text_base(text_buf);\n"
687 "switch(template_selection) {\n"
690 "case ANY_OR_OMIT:\n"
692 "case SPECIFIC_VALUE:\n"
693 "Module_List::encode_%s(text_buf, (genericfunc_t)single_value);\n"
696 "case COMPLEMENTED_LIST:\n"
697 "text_buf.push_int(value_list.n_values);\n"
698 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
699 "value_list.list_value[i].encode_text(text_buf);\n"
702 "TTCN_error(\"Text encoder: Encoding an uninitialized/unsupported template "
704 "}\n", fat_string
, dispname
);
706 src
= mputstr(src
,"}\n\n");
707 def
= mputstr(def
,"void decode_text(Text_Buf& text_buf);\n");
708 src
= mputprintf(src
,"void %s_template::decode_text(Text_Buf&", name
);
709 if (fdef
->runs_on_self
) {
710 src
= mputprintf(src
, ")\n"
712 "TTCN_error(\"Templates of type %s cannot be received "
713 "from other test components.\");\n", dispname
);
715 src
= mputprintf(src
, " text_buf)\n"
718 "decode_text_base(text_buf);\n"
719 "switch(template_selection) {\n"
722 "case ANY_OR_OMIT:\n"
724 "case SPECIFIC_VALUE:\n"
725 "Module_List::decode_%s(text_buf,(genericfunc_t*)&single_value);\n"
728 "case COMPLEMENTED_LIST:\n"
729 "value_list.n_values = text_buf.pull_int().get_val();\n"
730 "value_list.list_value = new %s_template[value_list.n_values];\n"
731 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
732 "value_list.list_value[i].decode_text(text_buf);\n"
734 "TTCN_error(\"Text decoder: An unknown/unsupported selection was received "
735 "in a template of type %s.\");\n"
736 "}\n", fat_string
, name
, dispname
);
738 src
= mputstr(src
,"}\n\n");
740 /* TTCN-3 ispresent() function */
741 def
= mputstr(def
, "boolean is_present(boolean legacy = FALSE) const;\n");
742 src
= mputprintf(src
,
743 "boolean %s_template::is_present(boolean legacy) const\n"
745 "if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;\n"
746 "return !match_omit(legacy);\n"
750 def
= mputstr(def
, "boolean match_omit(boolean legacy = FALSE) const;\n");
751 src
= mputprintf(src
,
752 "boolean %s_template::match_omit(boolean legacy) const\n"
754 "if (is_ifpresent) return TRUE;\n"
755 "switch (template_selection) {\n"
757 "case ANY_OR_OMIT:\n"
760 "case COMPLEMENTED_LIST:\n"
762 "for (unsigned int i=0; i<value_list.n_values; i++)\n"
763 "if (value_list.list_value[i].match_omit())\n"
764 "return template_selection==VALUE_LIST;\n"
765 "return template_selection==COMPLEMENTED_LIST;\n"
766 "} // else fall through\n"
774 def
= mputstr(def
,"void set_param(Module_Param& param);\n");
775 src
= mputprintf(src
,"void %s_template::set_param(Module_Param& param)\n"
777 " param.error(\"Not supported.\");\n"
781 def
= mputstr(def
,"Module_Param* get_param(Module_Param_Name& param_name) const;\n");
782 src
= mputprintf(src
,"Module_Param* %s_template::get_param(Module_Param_Name& /* param_name */) const\n"
787 if (!use_runtime_2
) {
788 /* check template restriction */
789 def
= mputstr(def
, "void check_restriction(template_res t_res, "
790 "const char* t_name=NULL, boolean legacy = FALSE) const;\n");
791 src
= mputprintf(src
,
792 "void %s_template::check_restriction"
793 "(template_res t_res, const char* t_name, boolean legacy) const\n"
795 "if (template_selection==UNINITIALIZED_TEMPLATE) return;\n"
796 "switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {\n"
798 "if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;\n"
801 "if (!is_ifpresent && (template_selection==OMIT_VALUE || "
802 "template_selection==SPECIFIC_VALUE)) return;\n"
805 "if (!match_omit(legacy)) return;\n"
810 "TTCN_error(\"Restriction `%%s' on template of type %%s violated.\", "
811 "get_res_name(t_res), t_name ? t_name : \"%s\");\n"
812 "}\n\n", name
, dispname
);
815 def
= mputstr(def
,"};\n\n");
819 output
->header
.class_defs
= mputstr(output
->header
.class_defs
, def
);
822 output
->source
.methods
= mputstr(output
->source
.methods
, src
);
This page took 0.059229 seconds and 5 git commands to generate.