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 ///////////////////////////////////////////////////////////////////////////////
9 #include "../common/memory.h"
10 #include "functionref.h"
16 void defFunctionrefClass(const funcref_def
*fdef
, output_struct
*output
)
18 char *def
= NULL
, *src
= NULL
;
19 const char *name
= fdef
->name
;
20 const char *dispname
= fdef
->dispname
;
22 const char *return_type
, *fat_string
;
24 if (fdef
->return_type
!= NULL
) return_type
= fdef
->return_type
;
25 else return_type
= "void";
29 fat_string
= "function";
32 fat_string
= "altstep";
35 fat_string
= "testcase";
39 FATAL_ERROR("defFunctionrefClass(): invalid type");
42 /* class declaration code */
43 output
->header
.class_decls
= mputprintf(output
->header
.class_decls
,
46 /* class definition */
49 "// written by %s in " __FILE__
" at %d\n"
51 "class %s : public Base_Type {\n"
54 , __FUNCTION__
, __LINE__
60 def
= mputstr(def
, "typedef ");
61 /* work-around for GCC versions earlier than 3.4:
62 * parse error occurs within the typedef if the return type is the same
63 * as the function type itself */
64 if (!strcmp(name
, return_type
)) def
= mputstr(def
, "class ");
65 def
= mputprintf(def
, "%s (*function_pointer)(%s);\n"
66 "typedef void (*start_pointer)(const COMPONENT& "
67 "component_reference", return_type
, fdef
->formal_par_list
);
68 if (fdef
->formal_par_list
[0] != '\0') def
= mputstr(def
, ", ");
69 def
= mputprintf(def
, "%s);\n", fdef
->formal_par_list
);
72 def
= mputprintf(def
, "typedef void (*standalone_pointer)(%s);\n"
73 "typedef Default_Base* (*activate_pointer)(%s);\n"
74 "typedef alt_status (*function_pointer)(%s);\n", fdef
->formal_par_list
,
75 fdef
->formal_par_list
, fdef
->formal_par_list
);
78 def
= mputprintf(def
, "typedef verdicttype (*function_pointer)(%s);\n",
79 fdef
->formal_par_list
);
85 "friend class %s_template;\n"
86 "friend boolean operator==(%s::function_pointer value, "
87 "const %s& other_value);\n"
88 "function_pointer referred_function;\n"
91 /* default constructor */
92 def
= mputprintf(def
,"public:\n"
94 src
= mputprintf(src
,"%s::%s()\n"
96 "referred_function = NULL;\n"
99 def
= mputprintf(def
,"%s(function_pointer other_value);\n", name
);
100 src
= mputprintf(src
,"%s::%s(function_pointer other_value)\n"
102 "referred_function = other_value;\n"
103 "}\n\n", name
, name
);
105 /* copy constructor */
106 def
= mputprintf(def
,"%s(const %s& other_value);\n", name
, name
);
107 src
= mputprintf(src
,"%s::%s(const %s& other_value)\n"
108 ": Base_Type()" /* call the *default* constructor as before */
110 "other_value.must_bound(\"Copying an unbound %s value.\");\n"
111 "referred_function = other_value.referred_function;\n"
112 "}\n\n", name
, name
, name
, dispname
);
115 def
=mputprintf(def
,"%s& operator=(function_pointer other_value);\n", name
);
116 src
=mputprintf(src
,"%s& %s::operator=(function_pointer other_value)\n"
118 "referred_function = other_value;\n"
120 "}\n\n", name
, name
);
122 def
= mputprintf(def
,"%s& operator=(const %s& other_value);\n",
124 src
= mputprintf(src
,"%s& %s::operator=(const %s& other_value)\n"
126 "other_value.must_bound(\"Assignment of an unbound value.\");\n"
127 "referred_function = other_value.referred_function;\n"
129 "}\n\n", name
, name
, name
);
132 def
= mputstr(def
,"boolean operator==(function_pointer other_value) "
134 src
= mputprintf(src
,"boolean %s::operator==(function_pointer other_value) "
137 "must_bound(\"Unbound left operand of %s comparison.\");\n"
138 "return referred_function == other_value;\n"
139 "}\n\n", name
, dispname
);
140 def
= mputprintf(def
,"boolean operator==(const %s& other_value) const;\n"
142 src
= mputprintf(src
,"boolean %s::operator==(const %s& other_value) const\n"
144 "must_bound(\"Unbound left operand of %s comparison.\");\n"
145 "other_value.must_bound(\"Unbound right operand of %s comparison.\");\n"
146 "return referred_function == other_value.referred_function;\n"
147 "}\n\n", name
, name
, dispname
, dispname
);
150 def
= mputprintf(def
,"inline boolean operator!=(function_pointer other_value)"
152 "{ return !(*this == other_value); }\n"
153 "inline boolean operator!=(const %s& other_value) const\n"
154 "{ return !(*this == other_value); }\n\n", name
);
158 def
= mputprintf(def
,"%s invoke(%s) const;\n"
159 , return_type
, fdef
->formal_par_list
);
160 src
= mputprintf(src
,"%s %s::invoke(%s) const\n"
162 "must_bound(\"Call of unbound function.\");\n"
163 "if(referred_function == "
164 "(%s::function_pointer)Module_List::get_fat_null())\n"
165 "TTCN_error(\"null reference cannot be invoked.\");\n"
166 "%sreferred_function(%s);\n"
167 "}\n\n", return_type
, name
, fdef
->formal_par_list
, name
168 , fdef
->return_type
!= NULL
? "return ": "", fdef
->actual_par_list
);
169 if(fdef
->is_startable
) {
170 def
= mputprintf(def
,"void start(const COMPONENT& component_reference%s"
171 "%s) const;\n", strcmp(fdef
->formal_par_list
,"")?", ":""
172 , fdef
->formal_par_list
);
173 src
= mputprintf(src
,"void %s::start(const COMPONENT& "
174 "component_reference%s%s) const\n{\n"
175 "((%s::start_pointer)Module_List::lookup_start_by_function_address"
176 "((genericfunc_t)referred_function))(component_reference%s%s);\n"
177 "}\n\n", name
, strcmp(fdef
->formal_par_list
,"")?", ":""
178 , fdef
->formal_par_list
, name
, strcmp(fdef
->formal_par_list
,"")?", ":""
179 , fdef
->actual_par_list
);
183 def
= mputprintf(def
,"void invoke_standalone(%s) const;\n",
184 fdef
->formal_par_list
);
185 src
= mputprintf(src
,"void %s::invoke_standalone(%s) const\n"
187 "((%s::standalone_pointer)"
188 "Module_List::lookup_standalone_address_by_altstep_address("
189 "(genericfunc_t)referred_function))(%s);\n"
190 "}\n\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
192 def
= mputprintf(def
,"Default_Base *activate(%s) const;\n"
193 , fdef
->formal_par_list
);
194 src
= mputprintf(src
,"Default_Base *%s::activate(%s) const\n"
196 "return ((%s::activate_pointer)"
197 "Module_List::lookup_activate_address_by_altstep_address("
198 "(genericfunc_t)referred_function))(%s);\n"
199 "}\n\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
201 def
= mputprintf(def
,"alt_status invoke(%s) const;\n"
202 , fdef
->formal_par_list
);
203 src
= mputprintf(src
,"alt_status %s::invoke(%s) const\n"
205 "must_bound(\"Call of an unbound altstep.\");\n"
206 "if(referred_function == "
207 "(%s::function_pointer)Module_List::get_fat_null())\n"
208 "TTCN_error(\"null reference cannot be invoked.\");\n"
209 "return referred_function(%s);\n"
210 "}\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
214 def
= mputprintf(def
,"verdicttype execute(%s) const;\n",
215 fdef
->formal_par_list
);
216 src
= mputprintf(src
,"verdicttype %s::execute(%s) const\n"
218 "must_bound(\"Call of unbound testcase.\");\n"
219 "if(referred_function == "
220 "(%s::function_pointer)Module_List::get_fat_null())\n"
221 "TTCN_error(\"null reference cannot be executed.\");\n"
222 "return referred_function(%s);\n"
223 "}\n\n", name
, fdef
->formal_par_list
, name
, fdef
->actual_par_list
);
228 def
= mputstr(def
,"inline boolean is_bound() "
229 "const { return referred_function != NULL; }\n");
231 def
= mputstr(def
,"inline boolean is_value() "
232 "const { return referred_function != NULL; }\n");
233 def
= mputstr(def
,"inline void clean_up() "
234 "{ referred_function = NULL; }\n");
235 def
= mputstr(def
,"inline void must_bound(const char *err_msg) const\n"
236 "{ if (referred_function == NULL) TTCN_error(\"%s\", err_msg); }\n\n");
242 /* functions in alternative runtime */
244 "boolean is_equal(const Base_Type* other_value) const;\n"
245 "void set_value(const Base_Type* other_value);\n"
246 "Base_Type* clone() const;\n"
247 "const TTCN_Typedescriptor_t* get_descriptor() const;\n");
248 src
= mputprintf(src
,
249 "boolean %s::is_equal(const Base_Type* other_value) const "
250 "{ return *this == *(static_cast<const %s*>(other_value)); }\n"
251 "void %s::set_value(const Base_Type* other_value) "
252 "{ *this = *(static_cast<const %s*>(other_value)); }\n"
253 "Base_Type* %s::clone() const { return new %s(*this); }\n"
254 "const TTCN_Typedescriptor_t* %s::get_descriptor() const "
255 "{ return &%s_descr_; }\n",
262 "inline boolean is_present() const { return is_bound(); }\n");
266 def
= mputstr(def
,"void log() const;\n");
267 src
= mputprintf(src
,"void %s::log() const\n"
269 "Module_List::log_%s((genericfunc_t)referred_function);\n"
270 "}\n\n",name
, fat_string
);
273 def
= mputstr(def
,"void set_param(Module_Param& param);\n");
274 src
= mputprintf(src
,"void %s::set_param(Module_Param& param)\n"
276 " param.error(\"Not supported.\");\n"
280 def
= mputstr(def
,"Module_Param* get_param(Module_Param_Name& param_name) const;\n");
281 src
= mputprintf(src
,"Module_Param* %s::get_param(Module_Param_Name& /* param_name */) const\n"
286 /* encode_text / decode_text */
287 def
= mputstr(def
,"void encode_text(Text_Buf& text_buf) const;\n");
288 src
= mputprintf(src
,"void %s::encode_text(Text_Buf&", name
);
289 if (fdef
->runs_on_self
) {
290 src
= mputprintf(src
, ") const\n"
292 "TTCN_error(\"Values of type %s cannot be sent to "
293 "other test components.\");\n", dispname
);
295 src
= mputprintf(src
, " text_buf) const\n"
297 "Module_List::encode_%s(text_buf,"
298 "(genericfunc_t)referred_function);\n", fat_string
);
300 src
= mputstr(src
,"}\n\n");
301 def
= mputstr(def
,"void decode_text(Text_Buf& text_buf);\n");
302 src
= mputprintf(src
,"void %s::decode_text(Text_Buf&", name
);
303 if (fdef
->runs_on_self
) {
304 src
= mputprintf(src
, ")\n"
306 "TTCN_error(\"Values of type %s cannot be received "
307 "from other test components.\");\n", dispname
);
309 src
= mputprintf(src
, " text_buf)\n"
311 "Module_List::decode_%s(text_buf,"
312 "(genericfunc_t*)&referred_function);\n", fat_string
);
314 src
= mputstr(src
,"}\n\n");
315 def
= mputstr(def
, "};\n\n");
317 def
= mputprintf(def
,"extern boolean operator==(%s::function_pointer value,"
318 " const %s& other_value);\n", name
, name
);
319 src
= mputprintf(src
,"boolean operator==(%s::function_pointer value, "
320 "const %s& other_value)\n"
322 "other_value.must_bound(\"Unbound right operand of %s comparison.\");\n"
323 "return value == other_value.referred_function;\n"
324 "}\n\n", name
, name
, dispname
);
325 def
= mputprintf(def
,"inline boolean operator!=(%s::function_pointer value,"
326 " const %s& other_value)\n"
327 "{ return !(value == other_value); } \n\n", name
, name
);
329 output
->header
.class_defs
= mputstr(output
->header
.class_defs
, def
);
332 output
->source
.methods
= mputstr(output
->source
.methods
, src
);
336 void defFunctionrefTemplate(const funcref_def
*fdef
, output_struct
*output
)
338 char *def
= NULL
, *src
= NULL
;
339 const char *name
= fdef
->name
;
340 const char *dispname
= fdef
->dispname
;
341 char *fat_string
= NULL
;
345 fat_string
= mputstr(fat_string
, "function");
348 fat_string
= mputstr(fat_string
, "altstep");
351 fat_string
= mputstr(fat_string
, "testcase");
355 /* class declaration */
356 output
->header
.class_decls
= mputprintf(output
->header
.class_decls
,
357 "class %s_template;\n", name
);
359 /* class definition */
360 def
= mputprintf(def
,"class %s_template : public Base_Template {\n"
362 "%s::function_pointer single_value;\n"
364 "unsigned int n_values;\n"
365 "%s_template *list_value;\n"
367 "};\n\n", name
, name
, name
);
370 def
= mputprintf(def
," void copy_template(const %s_template& other_value);\n"
372 src
= mputprintf(src
,"void %s_template::copy_template(const %s_template& "
375 "switch(other_value.template_selection) {\n"
376 "case SPECIFIC_VALUE:\n"
377 "single_value = other_value.single_value;\n"
381 "case ANY_OR_OMIT:\n"
384 "case COMPLEMENTED_LIST:\n"
385 "value_list.n_values = other_value.value_list.n_values;\n"
386 "value_list.list_value = new %s_template[value_list.n_values];\n"
387 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
388 "value_list.list_value[i] = other_value.value_list.list_value[i];\n"
391 "TTCN_error(\"Copying an unitialized/unsupported %s template.\");\n"
393 "set_selection(other_value);\n"
394 "}\n\n", name
, name
, name
, dispname
);
397 def
= mputprintf(def
,"public:\n"
398 "%s_template();\n", name
);
399 src
= mputprintf(src
,"%s_template::%s_template()\n"
400 "{\n}\n\n", name
, name
);
401 def
= mputprintf(def
,"%s_template(template_sel other_value);\n", name
);
402 src
= mputprintf(src
,"%s_template::%s_template(template_sel other_value)\n"
403 " : Base_Template(other_value)\n"
405 "check_single_selection(other_value);\n"
406 "}\n\n", name
, name
);
407 def
= mputprintf(def
,"%s_template(%s::function_pointer other_value);\n"
409 src
= mputprintf(src
,"%s_template::%s_template(%s::function_pointer "
411 " : Base_Template(SPECIFIC_VALUE)\n"
413 "single_value = other_value;\n"
414 "}\n\n", name
, name
, name
);
415 def
= mputprintf(def
,"%s_template(const %s& other_value);\n", name
, name
);
416 src
= mputprintf(src
,"%s_template::%s_template(const %s& other_value)\n"
417 " :Base_Template(SPECIFIC_VALUE)\n"
419 "other_value.must_bound(\"Creating a template from an unbound %s value."
421 "single_value = other_value.referred_function;\n"
422 "}\n\n", name
, name
, name
, dispname
);
423 def
= mputprintf(def
,"%s_template(const OPTIONAL<%s>& other_value);\n"
425 src
= mputprintf(src
,"%s_template::%s_template(const OPTIONAL<%s>& "
428 "if(other_value.ispresent()) {\n"
429 "set_selection(SPECIFIC_VALUE);\n"
430 "single_value = ((const %s&)other_value()).referred_function;\n"
431 "} else set_selection(OMIT_VALUE);\n"
432 "}\n\n", name
, name
, name
, name
);
433 def
= mputprintf(def
,"%s_template(const %s_template& other_value);\n"
435 src
= mputprintf(src
,"%s_template::%s_template(const %s_template& "
437 " :Base_Template()\n" /* yes, the default constructor */
439 "copy_template(other_value);\n"
440 "}\n\n", name
, name
, name
);
443 def
= mputprintf(def
,"~%s_template();\n", name
);
444 src
= mputprintf(src
,"%s_template::~%s_template()\n"
447 "}\n\n", name
, name
);
450 def
= mputstr(def
,"void clean_up();\n");
451 src
= mputprintf(src
,"void %s_template::clean_up()"
453 "if(template_selection == VALUE_LIST ||\n"
454 "template_selection == COMPLEMENTED_LIST)\n"
455 "delete[] value_list.list_value;\n"
456 "template_selection = UNINITIALIZED_TEMPLATE;\n"
460 def
= mputprintf(def
,"%s_template& operator=(template_sel other_value);\n"
462 src
= mputprintf(src
,"%s_template& %s_template::operator=(template_sel "
465 "check_single_selection(other_value);\n"
467 "set_selection(other_value);\n"
469 "}\n\n", name
, name
);
470 def
= mputprintf(def
,"%s_template& operator=(%s::function_pointer "
471 "other_value);\n", name
, name
);
472 src
= mputprintf(src
,"%s_template& %s_template::operator="
473 "(%s::function_pointer other_value)\n"
476 "set_selection(SPECIFIC_VALUE);\n"
477 "single_value = other_value;\n"
479 "}\n\n", name
, name
, name
);
480 def
= mputprintf(def
,"%s_template& operator=(const %s& other_value);\n"
482 src
= mputprintf(src
,"%s_template& %s_template::operator="
483 "(const %s& other_value)\n"
485 "other_value.must_bound(\"Assignment of an unbound %s value to a "
488 "set_selection(SPECIFIC_VALUE);\n"
489 "single_value = other_value.referred_function;\n"
491 "}\n\n", name
, name
, name
, dispname
);
492 def
= mputprintf(def
,"%s_template& operator=(const OPTIONAL<%s>& "
493 "other_value);\n", name
, name
);
494 src
= mputprintf(src
,"%s_template& %s_template::operator=(const "
495 "OPTIONAL<%s>& other_value)\n"
498 "if(other_value.ispresent()) { \n"
499 "set_selection(SPECIFIC_VALUE);\n"
500 "single_value = ((const %s&)other_value()).referred_function;\n"
501 "} else set_selection(OMIT_VALUE);\n"
503 "}\n\n", name
, name
, name
, name
);
504 def
= mputprintf(def
,"%s_template& operator=(const %s_template& "
505 "other_value);\n", name
, name
);
506 src
= mputprintf(src
,"%s_template& %s_template::operator=(const %s_template& "
509 "if(&other_value != this) {\n"
511 "copy_template(other_value);\n"
514 "}\n\n", name
,name
, name
);
516 /* match functions */
517 def
= mputprintf(def
,"boolean match(%s::function_pointer "
518 "other_value, boolean legacy = FALSE) const;\n", name
);
519 src
= mputprintf(src
,"boolean %s_template::match(%s::function_pointer "
520 "other_value, boolean) const\n"
522 "switch(template_selection) {\n"
523 "case SPECIFIC_VALUE:\n"
524 "return single_value == other_value;\n"
528 "case ANY_OR_OMIT:\n"
531 "case COMPLEMENTED_LIST:\n"
532 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
533 "if(value_list.list_value[i].match(other_value))\n"
534 "return template_selection == VALUE_LIST;\n"
535 "return template_selection == COMPLEMENTED_LIST;\n"
537 "TTCN_error(\"Matching with an unitialized/unsupported %s template."
541 "}\n\n", name
, name
, dispname
);
542 def
= mputprintf(def
,"boolean match(const %s& other_value, boolean legacy "
543 "= FALSE) const;\n", name
);
544 src
= mputprintf(src
,"boolean %s_template::match(const %s& other_value, "
547 " if (!other_value.is_bound()) return FALSE;\n"
548 "return match(other_value.referred_function);\n"
549 "}\n\n", name
, name
);
551 /* value of function */
552 def
= mputprintf(def
,"%s valueof() const;\n", name
);
553 src
= mputprintf(src
,"%s %s_template::valueof() const\n"
555 "if(template_selection != SPECIFIC_VALUE || is_ifpresent)\n"
556 "TTCN_error(\"Performing a valueof or send operation on a "
557 "non-specific %s template.\");\n"
558 "return single_value;\n}\n\n", name
, name
, dispname
);
561 def
= mputstr(def
,"void set_type(template_sel template_type, "
562 "unsigned int list_length);\n");
563 src
= mputprintf(src
,"void %s_template::set_type(template_sel template_type, "
564 "unsigned int list_length)\n"
566 "if(template_type != VALUE_LIST && "
567 "template_type != COMPLEMENTED_LIST)\n"
568 "TTCN_error(\"Setting an invalid type for an %s template.\");\n"
570 "set_selection(template_type);\n"
571 "value_list.n_values = list_length;\n"
572 "value_list.list_value = new %s_template[list_length];\n"
573 "}\n\n", name
, dispname
, name
);
576 def
= mputprintf(def
,"%s_template& list_item(unsigned int list_index) "
578 src
= mputprintf(src
,"%s_template& %s_template::list_item("
579 "unsigned int list_index) const\n"
581 "if(template_selection != VALUE_LIST && "
582 "template_selection != COMPLEMENTED_LIST)\n"
583 "TTCN_error(\"Accessing a list element of a non-list template of "
585 "if(list_index >= value_list.n_values)\n"
586 "TTCN_error(\"Index overflow in a value list template of type %s."
588 "return value_list.list_value[list_index];\n"
589 "}\n\n", name
, name
, dispname
, dispname
);
592 /* functions in alternative runtime */
594 "void valueofv(Base_Type* value) const;\n"
595 "void set_value(template_sel other_value);\n"
596 "void copy_value(const Base_Type* other_value);\n"
597 "Base_Template* clone() const;\n"
598 "const TTCN_Typedescriptor_t* get_descriptor() const;\n"
599 "boolean matchv(const Base_Type* other_value, boolean legacy) const;\n"
600 "void log_matchv(const Base_Type* match_value, boolean legacy) const;\n");
601 src
= mputprintf(src
,
602 "void %s_template::valueofv(Base_Type* value) const "
603 "{ *(static_cast<%s*>(value)) = valueof(); }\n"
604 "void %s_template::set_value(template_sel other_value) "
605 "{ *this = other_value; }\n"
606 "void %s_template::copy_value(const Base_Type* other_value) "
607 "{ *this = *(static_cast<const %s*>(other_value)); }\n"
608 "Base_Template* %s_template::clone() const "
609 "{ return new %s_template(*this); }\n"
610 "const TTCN_Typedescriptor_t* %s_template::get_descriptor() const "
611 "{ return &%s_descr_; }\n"
612 "boolean %s_template::matchv(const Base_Type* other_value, "
613 "boolean legacy) const "
614 "{ return match(*(static_cast<const %s*>(other_value)), legacy); }\n"
615 "void %s_template::log_matchv(const Base_Type* match_value, "
616 "boolean legacy) const "
617 " { log_match(*(static_cast<const %s*>(match_value)), legacy); }\n",
628 def
= mputstr(def
,"void log() const;\n");
629 src
= mputprintf(src
,"void %s_template::log() const\n"
631 "switch(template_selection) {\n"
632 "case SPECIFIC_VALUE:\n"
633 "Module_List::log_%s((genericfunc_t)single_value);\n"
635 "case COMPLEMENTED_LIST:\n"
636 "TTCN_Logger::log_event_str(\"complement \");\n"
638 "TTCN_Logger::log_char('(');\n"
639 "for(unsigned int i = 0; i < value_list.n_values; i++) {\n"
640 "if(i > 0) TTCN_Logger::log_event_str(\", \");\n"
641 "value_list.list_value[i].log();\n"
643 "TTCN_Logger::log_char(')');\n"
649 "}\n\n", name
, fat_string
);
651 /* log_match function */
652 def
= mputprintf(def
,"void log_match(const %s& match_value, "
653 "boolean legacy = FALSE) const;\n", name
);
654 src
= mputprintf(src
,"void %s_template::log_match(const %s& match_value, "
655 "boolean legacy) const\n"
658 "TTCN_Logger::log_event_str(\" with \");\n"
659 "match_value.log();\n"
660 "if(match(match_value, legacy)) TTCN_Logger::log_event_str(\" matched\");\n"
661 "else TTCN_Logger::log_event_str(\" unmatched\");\n"
662 "}\n\n", name
, name
);
664 /* encode_text / decode_text */
665 def
= mputstr(def
,"void encode_text(Text_Buf& text_buf) const;\n");
666 src
= mputprintf(src
,"void %s_template::encode_text(Text_Buf&", name
);
667 if (fdef
->runs_on_self
) {
668 src
= mputprintf(src
, ") const\n"
670 "TTCN_error(\"Templates of type %s cannot be sent to "
671 "other test components.\");\n", dispname
);
673 src
= mputprintf(src
, " text_buf) const\n"
675 "encode_text_base(text_buf);\n"
676 "switch(template_selection) {\n"
679 "case ANY_OR_OMIT:\n"
681 "case SPECIFIC_VALUE:\n"
682 "Module_List::encode_%s(text_buf, (genericfunc_t)single_value);\n"
685 "case COMPLEMENTED_LIST:\n"
686 "text_buf.push_int(value_list.n_values);\n"
687 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
688 "value_list.list_value[i].encode_text(text_buf);\n"
691 "TTCN_error(\"Text encoder: Encoding an uninitialized/unsupported template "
693 "}\n", fat_string
, dispname
);
695 src
= mputstr(src
,"}\n\n");
696 def
= mputstr(def
,"void decode_text(Text_Buf& text_buf);\n");
697 src
= mputprintf(src
,"void %s_template::decode_text(Text_Buf&", name
);
698 if (fdef
->runs_on_self
) {
699 src
= mputprintf(src
, ")\n"
701 "TTCN_error(\"Templates of type %s cannot be received "
702 "from other test components.\");\n", dispname
);
704 src
= mputprintf(src
, " text_buf)\n"
707 "decode_text_base(text_buf);\n"
708 "switch(template_selection) {\n"
711 "case ANY_OR_OMIT:\n"
713 "case SPECIFIC_VALUE:\n"
714 "Module_List::decode_%s(text_buf,(genericfunc_t*)&single_value);\n"
717 "case COMPLEMENTED_LIST:\n"
718 "value_list.n_values = text_buf.pull_int().get_val();\n"
719 "value_list.list_value = new %s_template[value_list.n_values];\n"
720 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
721 "value_list.list_value[i].decode_text(text_buf);\n"
723 "TTCN_error(\"Text decoder: An unknown/unsupported selection was received "
724 "in a template of type %s.\");\n"
725 "}\n", fat_string
, name
, dispname
);
727 src
= mputstr(src
,"}\n\n");
729 /* TTCN-3 ispresent() function */
730 def
= mputstr(def
, "boolean is_present(boolean legacy = FALSE) const;\n");
731 src
= mputprintf(src
,
732 "boolean %s_template::is_present(boolean legacy) const\n"
734 "if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;\n"
735 "return !match_omit(legacy);\n"
739 def
= mputstr(def
, "boolean match_omit(boolean legacy = FALSE) const;\n");
740 src
= mputprintf(src
,
741 "boolean %s_template::match_omit(boolean legacy) const\n"
743 "if (is_ifpresent) return TRUE;\n"
744 "switch (template_selection) {\n"
746 "case ANY_OR_OMIT:\n"
749 "case COMPLEMENTED_LIST:\n"
751 "for (unsigned int i=0; i<value_list.n_values; i++)\n"
752 "if (value_list.list_value[i].match_omit())\n"
753 "return template_selection==VALUE_LIST;\n"
754 "return template_selection==COMPLEMENTED_LIST;\n"
755 "} // else fall through\n"
763 def
= mputstr(def
,"void set_param(Module_Param& param);\n");
764 src
= mputprintf(src
,"void %s_template::set_param(Module_Param& param)\n"
766 " param.error(\"Not supported.\");\n"
770 def
= mputstr(def
,"Module_Param* get_param(Module_Param_Name& param_name) const;\n");
771 src
= mputprintf(src
,"Module_Param* %s_template::get_param(Module_Param_Name& /* param_name */) const\n"
776 if (!use_runtime_2
) {
777 /* check template restriction */
778 def
= mputstr(def
, "void check_restriction(template_res t_res, "
779 "const char* t_name=NULL, boolean legacy = FALSE) const;\n");
780 src
= mputprintf(src
,
781 "void %s_template::check_restriction"
782 "(template_res t_res, const char* t_name, boolean legacy) const\n"
784 "if (template_selection==UNINITIALIZED_TEMPLATE) return;\n"
785 "switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {\n"
787 "if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;\n"
790 "if (!is_ifpresent && (template_selection==OMIT_VALUE || "
791 "template_selection==SPECIFIC_VALUE)) return;\n"
794 "if (!match_omit(legacy)) return;\n"
799 "TTCN_error(\"Restriction `%%s' on template of type %%s violated.\", "
800 "get_res_name(t_res), t_name ? t_name : \"%s\");\n"
801 "}\n\n", name
, dispname
);
804 def
= mputstr(def
,"};\n\n");
808 output
->header
.class_defs
= mputstr(output
->header
.class_defs
, def
);
811 output
->source
.methods
= mputstr(output
->source
.methods
, src
);
This page took 0.07885 seconds and 5 git commands to generate.