1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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"
279 /* encode_text / decode_text */
280 def
= mputstr(def
,"void encode_text(Text_Buf& text_buf) const;\n");
281 src
= mputprintf(src
,"void %s::encode_text(Text_Buf&", name
);
282 if (fdef
->runs_on_self
) {
283 src
= mputprintf(src
, ") const\n"
285 "TTCN_error(\"Values of type %s cannot be sent to "
286 "other test components.\");\n", dispname
);
288 src
= mputprintf(src
, " text_buf) const\n"
290 "Module_List::encode_%s(text_buf,"
291 "(genericfunc_t)referred_function);\n", fat_string
);
293 src
= mputstr(src
,"}\n\n");
294 def
= mputstr(def
,"void decode_text(Text_Buf& text_buf);\n");
295 src
= mputprintf(src
,"void %s::decode_text(Text_Buf&", name
);
296 if (fdef
->runs_on_self
) {
297 src
= mputprintf(src
, ")\n"
299 "TTCN_error(\"Values of type %s cannot be received "
300 "from other test components.\");\n", dispname
);
302 src
= mputprintf(src
, " text_buf)\n"
304 "Module_List::decode_%s(text_buf,"
305 "(genericfunc_t*)&referred_function);\n", fat_string
);
307 src
= mputstr(src
,"}\n\n");
308 def
= mputstr(def
, "};\n\n");
310 def
= mputprintf(def
,"extern boolean operator==(%s::function_pointer value,"
311 " const %s& other_value);\n", name
, name
);
312 src
= mputprintf(src
,"boolean operator==(%s::function_pointer value, "
313 "const %s& other_value)\n"
315 "other_value.must_bound(\"Unbound right operand of %s comparison.\");\n"
316 "return value == other_value.referred_function;\n"
317 "}\n\n", name
, name
, dispname
);
318 def
= mputprintf(def
,"inline boolean operator!=(%s::function_pointer value,"
319 " const %s& other_value)\n"
320 "{ return !(value == other_value); } \n\n", name
, name
);
322 output
->header
.class_defs
= mputstr(output
->header
.class_defs
, def
);
325 output
->source
.methods
= mputstr(output
->source
.methods
, src
);
329 void defFunctionrefTemplate(const funcref_def
*fdef
, output_struct
*output
)
331 char *def
= NULL
, *src
= NULL
;
332 const char *name
= fdef
->name
;
333 const char *dispname
= fdef
->dispname
;
334 char *fat_string
= NULL
;
338 fat_string
= mputstr(fat_string
, "function");
341 fat_string
= mputstr(fat_string
, "altstep");
344 fat_string
= mputstr(fat_string
, "testcase");
348 /* class declaration */
349 output
->header
.class_decls
= mputprintf(output
->header
.class_decls
,
350 "class %s_template;\n", name
);
352 /* class definition */
353 def
= mputprintf(def
,"class %s_template : public Base_Template {\n"
355 "%s::function_pointer single_value;\n"
357 "unsigned int n_values;\n"
358 "%s_template *list_value;\n"
360 "};\n\n", name
, name
, name
);
363 def
= mputprintf(def
," void copy_template(const %s_template& other_value);\n"
365 src
= mputprintf(src
,"void %s_template::copy_template(const %s_template& "
368 "switch(other_value.template_selection) {\n"
369 "case SPECIFIC_VALUE:\n"
370 "single_value = other_value.single_value;\n"
374 "case ANY_OR_OMIT:\n"
377 "case COMPLEMENTED_LIST:\n"
378 "value_list.n_values = other_value.value_list.n_values;\n"
379 "value_list.list_value = new %s_template[value_list.n_values];\n"
380 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
381 "value_list.list_value[i] = other_value.value_list.list_value[i];\n"
384 "TTCN_error(\"Copying an unitialized/unsupported %s template.\");\n"
386 "set_selection(other_value);\n"
387 "}\n\n", name
, name
, name
, dispname
);
390 def
= mputprintf(def
,"public:\n"
391 "%s_template();\n", name
);
392 src
= mputprintf(src
,"%s_template::%s_template()\n"
393 "{\n}\n\n", name
, name
);
394 def
= mputprintf(def
,"%s_template(template_sel other_value);\n", name
);
395 src
= mputprintf(src
,"%s_template::%s_template(template_sel other_value)\n"
396 " : Base_Template(other_value)\n"
398 "check_single_selection(other_value);\n"
399 "}\n\n", name
, name
);
400 def
= mputprintf(def
,"%s_template(%s::function_pointer other_value);\n"
402 src
= mputprintf(src
,"%s_template::%s_template(%s::function_pointer "
404 " : Base_Template(SPECIFIC_VALUE)\n"
406 "single_value = other_value;\n"
407 "}\n\n", name
, name
, name
);
408 def
= mputprintf(def
,"%s_template(const %s& other_value);\n", name
, name
);
409 src
= mputprintf(src
,"%s_template::%s_template(const %s& other_value)\n"
410 " :Base_Template(SPECIFIC_VALUE)\n"
412 "other_value.must_bound(\"Creating a template from an unbound %s value."
414 "single_value = other_value.referred_function;\n"
415 "}\n\n", name
, name
, name
, dispname
);
416 def
= mputprintf(def
,"%s_template(const OPTIONAL<%s>& other_value);\n"
418 src
= mputprintf(src
,"%s_template::%s_template(const OPTIONAL<%s>& "
421 "if(other_value.ispresent()) {\n"
422 "set_selection(SPECIFIC_VALUE);\n"
423 "single_value = ((const %s&)other_value()).referred_function;\n"
424 "} else set_selection(OMIT_VALUE);\n"
425 "}\n\n", name
, name
, name
, name
);
426 def
= mputprintf(def
,"%s_template(const %s_template& other_value);\n"
428 src
= mputprintf(src
,"%s_template::%s_template(const %s_template& "
430 " :Base_Template()\n" /* yes, the default constructor */
432 "copy_template(other_value);\n"
433 "}\n\n", name
, name
, name
);
436 def
= mputprintf(def
,"~%s_template();\n", name
);
437 src
= mputprintf(src
,"%s_template::~%s_template()\n"
440 "}\n\n", name
, name
);
443 def
= mputstr(def
,"void clean_up();\n");
444 src
= mputprintf(src
,"void %s_template::clean_up()"
446 "if(template_selection == VALUE_LIST ||\n"
447 "template_selection == COMPLEMENTED_LIST)\n"
448 "delete[] value_list.list_value;\n"
449 "template_selection = UNINITIALIZED_TEMPLATE;\n"
453 def
= mputprintf(def
,"%s_template& operator=(template_sel other_value);\n"
455 src
= mputprintf(src
,"%s_template& %s_template::operator=(template_sel "
458 "check_single_selection(other_value);\n"
460 "set_selection(other_value);\n"
462 "}\n\n", name
, name
);
463 def
= mputprintf(def
,"%s_template& operator=(%s::function_pointer "
464 "other_value);\n", name
, name
);
465 src
= mputprintf(src
,"%s_template& %s_template::operator="
466 "(%s::function_pointer other_value)\n"
469 "set_selection(SPECIFIC_VALUE);\n"
470 "single_value = other_value;\n"
472 "}\n\n", name
, name
, name
);
473 def
= mputprintf(def
,"%s_template& operator=(const %s& other_value);\n"
475 src
= mputprintf(src
,"%s_template& %s_template::operator="
476 "(const %s& other_value)\n"
478 "other_value.must_bound(\"Assignment of an unbound %s value to a "
481 "set_selection(SPECIFIC_VALUE);\n"
482 "single_value = other_value.referred_function;\n"
484 "}\n\n", name
, name
, name
, dispname
);
485 def
= mputprintf(def
,"%s_template& operator=(const OPTIONAL<%s>& "
486 "other_value);\n", name
, name
);
487 src
= mputprintf(src
,"%s_template& %s_template::operator=(const "
488 "OPTIONAL<%s>& other_value)\n"
491 "if(other_value.ispresent()) { \n"
492 "set_selection(SPECIFIC_VALUE);\n"
493 "single_value = ((const %s&)other_value()).referred_function;\n"
494 "} else set_selection(OMIT_VALUE);\n"
496 "}\n\n", name
, name
, name
, name
);
497 def
= mputprintf(def
,"%s_template& operator=(const %s_template& "
498 "other_value);\n", name
, name
);
499 src
= mputprintf(src
,"%s_template& %s_template::operator=(const %s_template& "
502 "if(&other_value != this) {\n"
504 "copy_template(other_value);\n"
507 "}\n\n", name
,name
, name
);
509 /* match functions */
510 def
= mputprintf(def
,"boolean match(%s::function_pointer "
511 "other_value) const;\n", name
);
512 src
= mputprintf(src
,"boolean %s_template::match(%s::function_pointer "
513 "other_value) const\n"
515 "switch(template_selection) {\n"
516 "case SPECIFIC_VALUE:\n"
517 "return single_value == other_value;\n"
521 "case ANY_OR_OMIT:\n"
524 "case COMPLEMENTED_LIST:\n"
525 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
526 "if(value_list.list_value[i].match(other_value))\n"
527 "return template_selection == VALUE_LIST;\n"
528 "return template_selection == COMPLEMENTED_LIST;\n"
530 "TTCN_error(\"Matching with an unitialized/unsupported %s template."
534 "}\n\n", name
, name
, dispname
);
535 def
= mputprintf(def
,"boolean match(const %s& other_value) const;\n", name
);
536 src
= mputprintf(src
,"boolean %s_template::match(const %s& other_value) "
539 " if (!other_value.is_bound()) return FALSE;\n"
540 "return match(other_value.referred_function);\n"
541 "}\n\n", name
, name
);
543 /* value of function */
544 def
= mputprintf(def
,"%s valueof() const;\n", name
);
545 src
= mputprintf(src
,"%s %s_template::valueof() const\n"
547 "if(template_selection != SPECIFIC_VALUE || is_ifpresent)\n"
548 "TTCN_error(\"Performing a valueof or send operation on a "
549 "non-specific %s template.\");\n"
550 "return single_value;\n}\n\n", name
, name
, dispname
);
553 def
= mputstr(def
,"void set_type(template_sel template_type, "
554 "unsigned int list_length);\n");
555 src
= mputprintf(src
,"void %s_template::set_type(template_sel template_type, "
556 "unsigned int list_length)\n"
558 "if(template_type != VALUE_LIST && "
559 "template_type != COMPLEMENTED_LIST)\n"
560 "TTCN_error(\"Setting an invalid type for an %s template.\");\n"
562 "set_selection(template_type);\n"
563 "value_list.n_values = list_length;\n"
564 "value_list.list_value = new %s_template[list_length];\n"
565 "}\n\n", name
, dispname
, name
);
568 def
= mputprintf(def
,"%s_template& list_item(unsigned int list_index) "
570 src
= mputprintf(src
,"%s_template& %s_template::list_item("
571 "unsigned int list_index) const\n"
573 "if(template_selection != VALUE_LIST && "
574 "template_selection != COMPLEMENTED_LIST)\n"
575 "TTCN_error(\"Accessing a list element of a non-list template of "
577 "if(list_index >= value_list.n_values)\n"
578 "TTCN_error(\"Index overflow in a value list template of type %s."
580 "return value_list.list_value[list_index];\n"
581 "}\n\n", name
, name
, dispname
, dispname
);
584 /* functions in alternative runtime */
586 "void valueofv(Base_Type* value) const;\n"
587 "void set_value(template_sel other_value);\n"
588 "void copy_value(const Base_Type* other_value);\n"
589 "Base_Template* clone() const;\n"
590 "const TTCN_Typedescriptor_t* get_descriptor() const;\n"
591 "boolean matchv(const Base_Type* other_value) const;\n"
592 "void log_matchv(const Base_Type* match_value) const;\n");
593 src
= mputprintf(src
,
594 "void %s_template::valueofv(Base_Type* value) const "
595 "{ *(static_cast<%s*>(value)) = valueof(); }\n"
596 "void %s_template::set_value(template_sel other_value) "
597 "{ *this = other_value; }\n"
598 "void %s_template::copy_value(const Base_Type* other_value) "
599 "{ *this = *(static_cast<const %s*>(other_value)); }\n"
600 "Base_Template* %s_template::clone() const "
601 "{ return new %s_template(*this); }\n"
602 "const TTCN_Typedescriptor_t* %s_template::get_descriptor() const "
603 "{ return &%s_descr_; }\n"
604 "boolean %s_template::matchv(const Base_Type* other_value) const "
605 "{ return match(*(static_cast<const %s*>(other_value))); }\n"
606 "void %s_template::log_matchv(const Base_Type* match_value) const "
607 " { log_match(*(static_cast<const %s*>(match_value))); }\n",
618 def
= mputstr(def
,"void log() const;\n");
619 src
= mputprintf(src
,"void %s_template::log() const\n"
621 "switch(template_selection) {\n"
622 "case SPECIFIC_VALUE:\n"
623 "Module_List::log_%s((genericfunc_t)single_value);\n"
625 "case COMPLEMENTED_LIST:\n"
626 "TTCN_Logger::log_event_str(\"complement \");\n"
628 "TTCN_Logger::log_char('(');\n"
629 "for(unsigned int i = 0; i < value_list.n_values; i++) {\n"
630 "if(i > 0) TTCN_Logger::log_event_str(\", \");\n"
631 "value_list.list_value[i].log();\n"
633 "TTCN_Logger::log_char(')');\n"
639 "}\n\n", name
, fat_string
);
641 /* log_match function */
642 def
= mputprintf(def
,"void log_match(const %s& match_value) const;\n", name
);
643 src
= mputprintf(src
,"void %s_template::log_match(const %s& match_value) "
647 "TTCN_Logger::log_event_str(\" with \");\n"
648 "match_value.log();\n"
649 "if(match(match_value)) TTCN_Logger::log_event_str(\" matched\");\n"
650 "else TTCN_Logger::log_event_str(\" unmatched\");\n"
651 "}\n\n", name
, name
);
653 /* encode_text / decode_text */
654 def
= mputstr(def
,"void encode_text(Text_Buf& text_buf) const;\n");
655 src
= mputprintf(src
,"void %s_template::encode_text(Text_Buf&", name
);
656 if (fdef
->runs_on_self
) {
657 src
= mputprintf(src
, ") const\n"
659 "TTCN_error(\"Templates of type %s cannot be sent to "
660 "other test components.\");\n", dispname
);
662 src
= mputprintf(src
, " text_buf) const\n"
664 "encode_text_base(text_buf);\n"
665 "switch(template_selection) {\n"
668 "case ANY_OR_OMIT:\n"
670 "case SPECIFIC_VALUE:\n"
671 "Module_List::encode_%s(text_buf, (genericfunc_t)single_value);\n"
674 "case COMPLEMENTED_LIST:\n"
675 "text_buf.push_int(value_list.n_values);\n"
676 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
677 "value_list.list_value[i].encode_text(text_buf);\n"
680 "TTCN_error(\"Text encoder: Encoding an uninitialized/unsupported template "
682 "}\n", fat_string
, dispname
);
684 src
= mputstr(src
,"}\n\n");
685 def
= mputstr(def
,"void decode_text(Text_Buf& text_buf);\n");
686 src
= mputprintf(src
,"void %s_template::decode_text(Text_Buf&", name
);
687 if (fdef
->runs_on_self
) {
688 src
= mputprintf(src
, ")\n"
690 "TTCN_error(\"Templates of type %s cannot be received "
691 "from other test components.\");\n", dispname
);
693 src
= mputprintf(src
, " text_buf)\n"
696 "decode_text_base(text_buf);\n"
697 "switch(template_selection) {\n"
700 "case ANY_OR_OMIT:\n"
702 "case SPECIFIC_VALUE:\n"
703 "Module_List::decode_%s(text_buf,(genericfunc_t*)&single_value);\n"
706 "case COMPLEMENTED_LIST:\n"
707 "value_list.n_values = text_buf.pull_int().get_val();\n"
708 "value_list.list_value = new %s_template[value_list.n_values];\n"
709 "for(unsigned int i = 0; i < value_list.n_values; i++)\n"
710 "value_list.list_value[i].decode_text(text_buf);\n"
712 "TTCN_error(\"Text decoder: An unknown/unsupported selection was received "
713 "in a template of type %s.\");\n"
714 "}\n", fat_string
, name
, dispname
);
716 src
= mputstr(src
,"}\n\n");
718 /* TTCN-3 ispresent() function */
719 def
= mputstr(def
, "boolean is_present() const;\n");
720 src
= mputprintf(src
,
721 "boolean %s_template::is_present() const\n"
723 "if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;\n"
724 "return !match_omit();\n"
728 def
= mputstr(def
, "boolean match_omit() const;\n");
729 src
= mputprintf(src
,
730 "boolean %s_template::match_omit() const\n"
732 "if (is_ifpresent) return TRUE;\n"
733 "switch (template_selection) {\n"
735 "case ANY_OR_OMIT:\n"
738 "case COMPLEMENTED_LIST:\n"
739 "for (unsigned int i=0; i<value_list.n_values; i++)\n"
740 "if (value_list.list_value[i].match_omit())\n"
741 "return template_selection==VALUE_LIST;\n"
742 "return template_selection==COMPLEMENTED_LIST;\n"
750 def
= mputstr(def
,"void set_param(Module_Param& param);\n");
751 src
= mputprintf(src
,"void %s_template::set_param(Module_Param& param)\n"
753 " param.error(\"Not supported.\");\n"
756 if (!use_runtime_2
) {
757 /* check template restriction */
758 def
= mputstr(def
, "void check_restriction(template_res t_res, "
759 "const char* t_name=NULL) const;\n");
760 src
= mputprintf(src
,
761 "void %s_template::check_restriction"
762 "(template_res t_res, const char* t_name) const\n"
764 "if (template_selection==UNINITIALIZED_TEMPLATE) return;\n"
765 "switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {\n"
767 "if (!is_ifpresent && template_selection==SPECIFIC_VALUE) return;\n"
770 "if (!is_ifpresent && (template_selection==OMIT_VALUE || "
771 "template_selection==SPECIFIC_VALUE)) return;\n"
774 "if (!match_omit()) return;\n"
779 "TTCN_error(\"Restriction `%%s' on template of type %%s violated.\", "
780 "get_res_name(t_res), t_name ? t_name : \"%s\");\n"
781 "}\n\n", name
, dispname
);
784 def
= mputstr(def
,"};\n\n");
788 output
->header
.class_defs
= mputstr(output
->header
.class_defs
, def
);
791 output
->source
.methods
= mputstr(output
->source
.methods
, src
);
This page took 0.052768 seconds and 6 git commands to generate.