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
18 * Zalanyi, Balazs Andor
21 ******************************************************************************/
22 #include "../../common/dbgnew.hh"
23 #include "AST_ttcn3.hh"
24 #include "../Identifier.hh"
25 #include "../CompilerError.hh"
26 #include "../Setting.hh"
28 #include "../CompField.hh"
29 #include "../CompType.hh"
30 #include "../TypeCompat.hh"
31 #include "../Valuestuff.hh"
32 #include "../Value.hh"
33 #include "Ttcnstuff.hh"
34 #include "TtcnTemplate.hh"
35 #include "Templatestuff.hh"
36 #include "ArrayDimensions.hh"
39 #include "Statement.hh"
41 #include "Attributes.hh"
42 #include "PatternString.hh"
43 #include "../../common/version_internal.h"
44 #include "../CodeGenHelper.hh"
45 #include "../../common/JSON_Tokenizer.hh"
46 #include "../DebuggerStuff.hh"
49 // implemented in coding_attrib_p.y
50 extern Ttcn::ExtensionAttributes
* parse_extattributes(
51 Ttcn::WithAttribPath
*w_attrib_path
);
53 // implemented in compiler.y
54 extern Ttcn::ErroneousAttributeSpec
* ttcn3_parse_erroneous_attr_spec_string(
55 const char* p_str
, const Common::Location
& str_loc
);
58 extern void init_coding_attrib_lex(const Ttcn::AttributeSpec
& attrib
);
59 extern int coding_attrib_parse();
60 extern void cleanup_coding_attrib_lex();
61 extern Ttcn::ExtensionAttributes
*extatrs
;
63 /** Create a field name in the anytype
65 * The output of this function will be used to create an identifier
66 * to be used as the field name in the anytype.
67 * The type_name may be a built-in type (e.g. "integer") or a user-defined
70 * If the name has multiple components (a fullname?), it keeps just the last
71 * component without any dots. *
72 * Also, the space in "universal charstring" needs to be replaced
73 * with an underscore to make it an identifier.
75 * Note: Prefixing with "AT_" is not done here, but in defUnionClass().
77 * @param type_name string
78 * @return string to be used as the identifier.
80 string
anytype_field(const string
& type_name
)
82 string
retval(type_name
);
84 // keep just the last part of the name
85 // TODO check if there's a way to get just the last component (note that fetching the string is done outside of this function)
86 size_t dot
= retval
.rfind('.');
87 if (dot
>= retval
.size()) dot
= 0;
89 retval
.replace(0, dot
, "");
94 extern Common::Modules
*modules
; // in main.cc
97 static const string
_T_("_T_");
102 using namespace Common
;
104 // =================================
105 // ===== FieldOrArrayRef
106 // =================================
108 FieldOrArrayRef::FieldOrArrayRef(const FieldOrArrayRef
& p
)
109 : Node(p
), Location(p
), ref_type(p
.ref_type
)
111 switch (p
.ref_type
) {
113 u
.id
= p
.u
.id
->clone();
116 u
.arp
= p
.u
.arp
->clone();
119 FATAL_ERROR("FieldOrArrayRef::FieldOrArrayRef()");
123 FieldOrArrayRef::FieldOrArrayRef(Identifier
*p_id
)
124 : Node(), Location(), ref_type(FIELD_REF
)
126 if (!p_id
) FATAL_ERROR("FieldOrArrayRef::FieldOrArrayRef()");
130 FieldOrArrayRef::FieldOrArrayRef(Value
*p_arp
)
131 : Node(), Location(), ref_type(ARRAY_REF
)
133 if (!p_arp
) FATAL_ERROR("FieldOrArrayRef::FieldOrArrayRef()");
137 FieldOrArrayRef::~FieldOrArrayRef()
147 FATAL_ERROR("FieldOrArrayRef::~FieldOrArrayRef()");
151 FieldOrArrayRef
*FieldOrArrayRef::clone() const
153 return new FieldOrArrayRef(*this);
156 void FieldOrArrayRef::set_fullname(const string
& p_fullname
)
158 Node::set_fullname(p_fullname
);
159 if (ref_type
== ARRAY_REF
)
160 u
.arp
->set_fullname(p_fullname
+ ".<array_index>");
163 void FieldOrArrayRef::set_my_scope(Scope
*p_scope
)
165 if (ref_type
== ARRAY_REF
) u
.arp
->set_my_scope(p_scope
);
168 const Identifier
* FieldOrArrayRef::get_id() const
170 if (ref_type
!= FIELD_REF
) FATAL_ERROR("FieldOrArrayRef::get_id()");
174 Value
*FieldOrArrayRef::get_val() const
176 if (ref_type
!= ARRAY_REF
) FATAL_ERROR("FieldOrArrayRef::get_val()");
180 void FieldOrArrayRef::append_stringRepr(string
& str
) const
185 str
+= u
.id
->get_dispname();
189 str
+= u
.arp
->get_stringRepr();
193 str
+= "<unknown sub-reference>";
197 void FieldOrArrayRef::set_field_name_to_lowercase()
199 if (ref_type
!= FIELD_REF
) FATAL_ERROR("FieldOrArrayRef::set_field_name_to_lowercase()");
200 string new_name
= u
.id
->get_name();
201 if (isupper(new_name
[0])) {
202 new_name
[0] = tolower(new_name
[0]);
203 if (new_name
[new_name
.size() - 1] == '_') {
204 // an underscore is inserted at the end of the field name if it's
205 // a basic type's name (since it would conflict with the class generated
207 // remove the underscore, it won't conflict with anything if its name
208 // starts with a lowercase letter
209 new_name
.replace(new_name
.size() - 1, 1, "");
212 u
.id
= new Identifier(Identifier::ID_NAME
, new_name
);
216 // =================================
217 // ===== FieldOrArrayRefs
218 // =================================
220 FieldOrArrayRefs::FieldOrArrayRefs(const FieldOrArrayRefs
& p
)
221 : Node(p
), refs_str_element(false)
223 for (size_t i
= 0; i
< p
.refs
.size(); i
++) refs
.add(p
.refs
[i
]->clone());
226 FieldOrArrayRefs::~FieldOrArrayRefs()
228 for (size_t i
= 0; i
< refs
.size(); i
++) delete refs
[i
];
232 FieldOrArrayRefs
*FieldOrArrayRefs::clone() const
234 return new FieldOrArrayRefs(*this);
237 void FieldOrArrayRefs::set_fullname(const string
& p_fullname
)
239 Node::set_fullname(p_fullname
);
240 for (size_t i
= 0; i
< refs
.size(); i
++)
241 refs
[i
]->set_fullname(p_fullname
+
242 ".<sub_reference" + Int2string(i
+ 1) + ">");
245 void FieldOrArrayRefs::set_my_scope(Scope
*p_scope
)
247 for (size_t i
= 0; i
< refs
.size(); i
++) refs
[i
]->set_my_scope(p_scope
);
250 bool FieldOrArrayRefs::has_unfoldable_index() const
252 for (size_t i
= 0; i
< refs
.size(); i
++) {
253 FieldOrArrayRef
*ref
= refs
[i
];
254 if (ref
->get_type() == FieldOrArrayRef::ARRAY_REF
) {
255 Value
*v
= ref
->get_val();
256 v
->set_lowerid_to_ref();
257 if (v
->is_unfoldable()) return true;
263 void FieldOrArrayRefs::remove_refs(size_t n
)
265 for (size_t i
= 0; i
< n
; i
++) delete refs
[i
];
266 refs
.replace(0, n
, NULL
);
267 set_fullname(get_fullname());
270 /* remove_last_field is used when unfolding references for
271 ischosen and ispresent function operands.
272 In this case it is NOT sure the last field exists.
273 Calling remove_last_field previously
274 will avoid getting the "variable...Has no member called..." error message.
275 The last field component will be checked as a separate step.
276 Warning: the removed Identifier has to be deleted later */
278 Identifier
* FieldOrArrayRefs::remove_last_field()
280 if (refs
.size() == 0) return 0;
281 size_t last_elem_ind
= refs
.size() - 1;
282 FieldOrArrayRef
* last_elem
= refs
[last_elem_ind
];
283 if (last_elem
->get_type() == FieldOrArrayRef::FIELD_REF
) {
284 Identifier
*ret_val
= last_elem
->get_id()->clone();
286 refs
.replace(last_elem_ind
, 1, NULL
);
291 void FieldOrArrayRefs::generate_code(expression_struct
*expr
,
292 Common::Assignment
*ass
, size_t nof_subrefs
/* = UINT_MAX*/)
295 bool is_template
= false;
296 switch (ass
->get_asstype()) {
297 case Common::Assignment::A_CONST
: // a Def_Const
298 case Common::Assignment::A_EXT_CONST
: // a Def_ExtConst
299 case Common::Assignment::A_MODULEPAR
: // a Def_Modulepar
300 case Common::Assignment::A_VAR
: // a Def_Var
301 case Common::Assignment::A_FUNCTION_RVAL
: // a Def_Function
302 case Common::Assignment::A_EXT_FUNCTION_RVAL
: // a Def_ExtFunction
303 case Common::Assignment::A_PAR_VAL_IN
: // a FormalPar
304 case Common::Assignment::A_PAR_VAL_OUT
: // a FormalPar
305 case Common::Assignment::A_PAR_VAL_INOUT
: // a FormalPar
306 // The type is important since the referred entities are value objects.
307 type
= ass
->get_Type();
309 case Common::Assignment::A_MODULEPAR_TEMP
: // a Def_Modulepar_Template
310 case Common::Assignment::A_TEMPLATE
: // a Def_Template
311 case Common::Assignment::A_VAR_TEMPLATE
: // a Def_Var_Template
312 case Common::Assignment::A_PAR_TEMPL_IN
: // a FormalPar
313 case Common::Assignment::A_PAR_TEMPL_OUT
: // a FormalPar
314 case Common::Assignment::A_PAR_TEMPL_INOUT
: // a FormalPar
315 // The type is semi-important because fields of anytype templates
317 type
= ass
->get_Type();
320 case Common::Assignment::A_TIMER
: // a Def_Timer
321 case Common::Assignment::A_PORT
: // a Def_Port
322 case Common::Assignment::A_FUNCTION_RTEMP
: // a Def_Function
323 case Common::Assignment::A_EXT_FUNCTION_RTEMP
: // a Def_ExtFunction
324 case Common::Assignment::A_PAR_TIMER
: // a FormalPar
325 case Common::Assignment::A_PAR_PORT
: // a FormalPar
326 // The type is not relevant (i.e. the optional fields do not require
327 // special handling).
331 // Reference to other definitions cannot occur during code generation.
332 FATAL_ERROR("FieldOrArrayRefs::generate_code()");
335 size_t n_refs
= (nof_subrefs
!= UINT_MAX
) ? nof_subrefs
: refs
.size();
336 for (size_t i
= 0; i
< n_refs
; i
++) {
337 if (type
) type
= type
->get_type_refd_last();
338 // type changes inside the loop; need to recompute "last" every time.
339 FieldOrArrayRef
*ref
= refs
[i
];
340 if (ref
->get_type() == FieldOrArrayRef::FIELD_REF
) {
341 // Write a call to the field accessor method.
342 // Fields of the anytype get a special prefix; see also:
343 // Template::generate_code_init_se, TypeConv::gen_conv_func_choice_anytype,
344 // defUnionClass and defUnionTemplate.
345 const Identifier
& id
= *ref
->get_id();
346 expr
->expr
= mputprintf(expr
->expr
, ".%s%s()",
347 ((type
!=0 && type
->get_typetype()==Type::T_ANYTYPE
) ? "AT_" : ""),
348 id
.get_name().c_str());
350 CompField
*cf
= type
->get_comp_byName(id
);
351 // If the field is optional, the return type of the accessor is an
352 // OPTIONAL<T>. Write a call to OPTIONAL<T>::operator(),
353 // which "reaches into" the OPTIONAL to get the contained type T.
354 // Don't do this at the end of the reference chain.
355 // Accessor methods for a foo_template return a bar_template
356 // and OPTIONAL<> is not involved, hence no "()".
357 if (!is_template
&& i
< n_refs
- 1 && cf
->get_is_optional())
358 expr
->expr
= mputstr(expr
->expr
, "()");
359 // Follow the field type.
360 type
= cf
->get_type();
363 // Generate code for array reference.
364 expr
->expr
= mputc(expr
->expr
, '[');
365 ref
->get_val()->generate_code_expr(expr
);
366 expr
->expr
= mputc(expr
->expr
, ']');
368 // Follow the embedded type.
369 switch (type
->get_typetype()) {
373 type
= type
->get_ofType();
376 // The index points to a string element.
377 // There are no further sub-references.
381 } // if (ref->get_type)
385 void FieldOrArrayRefs::append_stringRepr(string
& str
) const
387 for (size_t i
= 0; i
< refs
.size(); i
++) refs
[i
]->append_stringRepr(str
);
390 // =================================
392 // =================================
394 Ref_base::Ref_base(const Ref_base
& p
)
395 : Ref_simple(p
), subrefs(p
.subrefs
)
397 modid
= p
.modid
? p
.modid
->clone() : 0;
398 id
= p
.id
? p
.id
->clone() : 0;
399 params_checked
= p
.is_erroneous
;
402 Ref_base::Ref_base(Identifier
*p_modid
, Identifier
*p_id
)
403 : Ref_simple(), modid(p_modid
), id(p_id
), params_checked(false)
404 , usedInIsbound(false)
407 FATAL_ERROR("NULL parameter: Ttcn::Ref_base::Ref_base()");
410 Ref_base::~Ref_base()
416 void Ref_base::set_fullname(const string
& p_fullname
)
418 Ref_simple::set_fullname(p_fullname
);
419 subrefs
.set_fullname(p_fullname
);
422 void Ref_base::set_my_scope(Scope
*p_scope
)
424 Ref_simple::set_my_scope(p_scope
);
425 subrefs
.set_my_scope(p_scope
);
428 /* returns the referenced variable's base type or value */
429 Setting
* Ref_base::get_refd_setting()
431 Common::Assignment
*ass
= get_refd_assignment();
432 if (ass
) return ass
->get_Setting();
436 FieldOrArrayRefs
*Ref_base::get_subrefs()
438 if (!id
) get_modid();
439 if (subrefs
.get_nof_refs() == 0) return 0;
440 else return &subrefs
;
443 bool Ref_base::has_single_expr()
445 Common::Assignment
*ass
= get_refd_assignment();
446 if (!ass
) FATAL_ERROR("Ref_base::has_single_expr()");
447 for (size_t i
= 0; i
< subrefs
.get_nof_refs(); i
++) {
448 FieldOrArrayRef
*ref
= subrefs
.get_ref(i
);
449 if (ref
->get_type() == FieldOrArrayRef::ARRAY_REF
&&
450 !ref
->get_val()->has_single_expr()) return false;
455 void Ref_base::set_code_section(
456 GovernedSimple::code_section_t p_code_section
)
458 for (size_t i
= 0; i
< subrefs
.get_nof_refs(); i
++) {
459 FieldOrArrayRef
*ref
= subrefs
.get_ref(i
);
460 if (ref
->get_type() == FieldOrArrayRef::ARRAY_REF
)
461 ref
->get_val()->set_code_section(p_code_section
);
465 void Ref_base::generate_code_const_ref(expression_struct_t */
*expr*/
)
467 FATAL_ERROR("Ref_base::generate_code_const_ref()");
470 // =================================
472 // =================================
474 Reference::Reference(Identifier
*p_id
)
475 : Ref_base(), parlist(0)
477 subrefs
.add(new FieldOrArrayRef(p_id
));
480 Reference::~Reference()
488 * Common::PortTypeBody::PortTypeBody
490 * Common::TypeMappingTarget::TypeMappingTarget
491 * Common::PatternString::ps_elem_t::chk_ref */
492 Reference
*Reference::clone() const
494 return new Reference(*this);
497 string
Reference::get_dispname()
502 ret_val
+= modid
->get_dispname();
505 ret_val
+= id
->get_dispname();
506 subrefs
.append_stringRepr(ret_val
);
508 subrefs
.append_stringRepr(ret_val
);
509 // cut the leading dot
510 if (!ret_val
.empty() && ret_val
[0] == '.')
511 ret_val
.replace(0, 1, "");
516 Common::Assignment
* Reference::get_refd_assignment(bool check_parlist
)
518 Common::Assignment
*ass
= Ref_base::get_refd_assignment(check_parlist
);
519 // In fact calls Ref_simple::get_refd_assignment
520 if (ass
&& check_parlist
&& !params_checked
) {
521 params_checked
= true;
522 FormalParList
*fplist
= ass
->get_FormalParList();
524 if (fplist
->has_only_default_values()
525 && Common::Assignment::A_TEMPLATE
== ass
->get_asstype()) {
526 Ttcn::ParsedActualParameters params
;
527 Error_Context
cntxt(¶ms
, "In actual parameter list of %s",
528 ass
->get_description().c_str());
529 parlist
= new ActualParList();
530 is_erroneous
= fplist
->fold_named_and_chk(¶ms
, parlist
);
531 parlist
->set_fullname(get_fullname());
532 parlist
->set_my_scope(my_scope
);
534 error("Reference to parameterized definition `%s' without "
535 "actual parameter list", ass
->get_id().get_dispname().c_str());
542 const Identifier
* Reference::get_modid()
544 if (!id
) detect_modid();
548 const Identifier
* Reference::get_id()
550 if (!id
) detect_modid();
554 Type
*Reference::chk_variable_ref()
556 Common::Assignment
*t_ass
= get_refd_assignment();
557 if (!t_ass
) return 0;
558 switch (t_ass
->get_asstype()) {
559 case Common::Assignment::A_PAR_VAL_IN
:
560 t_ass
->use_as_lvalue(*this);
562 case Common::Assignment::A_VAR
:
563 case Common::Assignment::A_PAR_VAL_OUT
:
564 case Common::Assignment::A_PAR_VAL_INOUT
:
567 error("Reference to a variable or value parameter was "
568 "expected instead of %s", t_ass
->get_description().c_str());
571 FieldOrArrayRefs
*t_subrefs
= get_subrefs();
572 Type
*ret_val
= t_ass
->get_Type()->get_field_type(t_subrefs
,
573 Type::EXPECTED_DYNAMIC_VALUE
);
574 if (ret_val
&& t_subrefs
&& t_subrefs
->refers_to_string_element()) {
575 error("Reference to a string element of type `%s' cannot be used in "
576 "this context", ret_val
->get_typename().c_str());
581 Type
*Reference::chk_comptype_ref()
583 Common::Assignment
*ass
= get_refd_assignment();
585 if (ass
->get_asstype() == Common::Assignment::A_TYPE
) {
586 Type
*t
= ass
->get_Type()->get_type_refd_last();
587 switch (t
->get_typetype()) {
591 case Type::T_COMPONENT
:
594 error("Reference `%s' does not refer to a component type",
595 get_dispname().c_str());
598 error("Reference `%s' does not refer to a type",
599 get_dispname().c_str());
605 bool Reference::has_single_expr()
607 if (!Ref_base::has_single_expr()) {
610 if (parlist
!= NULL
) {
611 for (size_t i
= 0; i
< parlist
->get_nof_pars(); i
++) {
612 if (!parlist
->get_par(i
)->has_single_expr()) {
620 void Reference::ref_usage_found()
622 Common::Assignment
*ass
= get_refd_assignment();
623 if (!ass
) FATAL_ERROR("Reference::ref_usage_found()");
624 switch (ass
->get_asstype()) {
625 case Common::Assignment::A_PAR_VAL_OUT
:
626 case Common::Assignment::A_PAR_TEMPL_OUT
:
627 case Common::Assignment::A_PAR_VAL
:
628 case Common::Assignment::A_PAR_VAL_IN
:
629 case Common::Assignment::A_PAR_VAL_INOUT
:
630 case Common::Assignment::A_PAR_TEMPL_IN
:
631 case Common::Assignment::A_PAR_TEMPL_INOUT
:
632 case Common::Assignment::A_PAR_PORT
:
633 case Common::Assignment::A_PAR_TIMER
: {
634 FormalPar
*fpar
= dynamic_cast<FormalPar
*>(ass
);
636 FATAL_ERROR("Reference::ref_usage_found()");
638 fpar
->set_usage_found();
640 case Common::Assignment::A_EXT_CONST
: {
641 Def_ExtConst
* def
= dynamic_cast<Def_ExtConst
*>(ass
);
643 FATAL_ERROR("Reference::ref_usage_found()");
645 def
->set_usage_found();
652 void Reference::generate_code(expression_struct_t
*expr
)
655 Common::Assignment
*ass
= get_refd_assignment();
656 if (!ass
) FATAL_ERROR("Reference::generate_code()");
658 // reference without parameters to a template that has only default formal parameters.
659 // if @lazy: nothing to do, it's a C++ function call just like in case of Ref_pard::generate_code()
660 expr
->expr
= mputprintf(expr
->expr
, "%s(",
661 ass
->get_genname_from_scope(my_scope
).c_str());
662 parlist
->generate_code_alias(expr
, ass
->get_FormalParList(),
663 ass
->get_RunsOnType(), false);
664 expr
->expr
= mputc(expr
->expr
, ')');
666 expr
->expr
= mputstr(expr
->expr
,
667 LazyParamData::in_lazy() ?
668 LazyParamData::add_ref_genname(ass
, my_scope
).c_str() :
669 ass
->get_genname_from_scope(my_scope
).c_str());
671 if (subrefs
.get_nof_refs() > 0) subrefs
.generate_code(expr
, ass
);
674 void Reference::generate_code_const_ref(expression_struct_t
*expr
)
676 FieldOrArrayRefs
*t_subrefs
= get_subrefs();
677 if (!t_subrefs
|| t_subrefs
->get_nof_refs() == 0) {
683 Common::Assignment
*ass
= get_refd_assignment();
684 if (!ass
) FATAL_ERROR("Reference::generate_code_const_ref()");
687 switch (ass
->get_asstype()) {
688 case Common::Assignment::A_MODULEPAR
:
689 case Common::Assignment::A_VAR
:
690 case Common::Assignment::A_FUNCTION_RVAL
:
691 case Common::Assignment::A_EXT_FUNCTION_RVAL
:
692 case Common::Assignment::A_PAR_VAL_IN
:
693 case Common::Assignment::A_PAR_VAL_OUT
:
694 case Common::Assignment::A_PAR_VAL_INOUT
: {
697 case Common::Assignment::A_MODULEPAR_TEMP
:
698 case Common::Assignment::A_TEMPLATE
:
699 case Common::Assignment::A_VAR_TEMPLATE
:
700 case Common::Assignment::A_PAR_TEMPL_IN
:
701 case Common::Assignment::A_PAR_TEMPL_OUT
:
702 case Common::Assignment::A_PAR_TEMPL_INOUT
: {
705 case Common::Assignment::A_CONST
:
706 case Common::Assignment::A_EXT_CONST
:
712 Type
*refd_gov
= ass
->get_Type();
714 expr
->expr
= mputprintf(expr
->expr
, "const_cast< const %s&>(",
715 refd_gov
->get_genname_template(get_my_scope()).c_str() );
717 expr
->expr
= mputprintf(expr
->expr
, "const_cast< const %s&>(",
718 refd_gov
->get_genname_value(get_my_scope()).c_str());
721 // reference without parameters to a template that has only default formal parameters.
722 // if @lazy: nothing to do, it's a C++ function call just like in case of Ref_pard::generate_code()
723 expr
->expr
= mputprintf(expr
->expr
, "%s(",
724 ass
->get_genname_from_scope(my_scope
).c_str());
725 parlist
->generate_code_alias(expr
, ass
->get_FormalParList(),
726 ass
->get_RunsOnType(), false);
727 expr
->expr
= mputc(expr
->expr
, ')');
729 expr
->expr
= mputstr(expr
->expr
,
730 LazyParamData::in_lazy() ?
731 LazyParamData::add_ref_genname(ass
, my_scope
).c_str() :
732 ass
->get_genname_from_scope(my_scope
).c_str());
734 expr
->expr
= mputstr(expr
->expr
, ")");
736 if (t_subrefs
&& t_subrefs
->get_nof_refs() > 0)
737 t_subrefs
->generate_code(expr
, ass
);
740 void Reference::generate_code_portref(expression_struct_t
*expr
,
744 Common::Assignment
*ass
= get_refd_assignment();
745 if (!ass
) FATAL_ERROR("Reference::generate_code_portref()");
746 expr
->expr
= mputstr(expr
->expr
,
747 ass
->get_genname_from_scope(p_scope
).c_str());
748 if (subrefs
.get_nof_refs() > 0) subrefs
.generate_code(expr
, ass
);
752 void Reference::generate_code_ispresentbound(expression_struct_t
*expr
,
753 bool is_template
, const bool isbound
)
756 Common::Assignment
*ass
= get_refd_assignment();
757 const string
& ass_id
= ass
->get_genname_from_scope(my_scope
);
758 const char *ass_id_str
= ass_id
.c_str();
760 if (subrefs
.get_nof_refs() > 0) {
761 const string
& tmp_generalid
= my_scope
->get_scope_mod_gen()
762 ->get_temporary_id();
763 const char *tmp_generalid_str
= tmp_generalid
.c_str();
765 expression_struct isbound_expr
;
766 Code::init_expr(&isbound_expr
);
767 isbound_expr
.preamble
= mputprintf(isbound_expr
.preamble
,
768 "boolean %s = %s.is_bound();\n", tmp_generalid_str
,
770 ass
->get_Type()->generate_code_ispresentbound(&isbound_expr
, &subrefs
, my_scope
->get_scope_mod_gen(),
771 tmp_generalid
, ass_id
, is_template
, isbound
);
773 expr
->preamble
= mputstr(expr
->preamble
, isbound_expr
.preamble
);
774 expr
->preamble
= mputstr(expr
->preamble
, isbound_expr
.expr
);
775 Code::free_expr(&isbound_expr
);
777 expr
->expr
= mputprintf(expr
->expr
, "%s", tmp_generalid_str
);
779 expr
->expr
= mputprintf(expr
->expr
, "%s.%s(%s)", ass_id_str
,
780 isbound
? "is_bound":"is_present",
781 (!isbound
&& is_template
&& omit_in_value_list
) ? "TRUE" : "");
785 void Reference::detect_modid()
787 // do nothing if detection is already performed
789 // the first element of subrefs must be an <id>
790 const Identifier
*first_id
= subrefs
.get_ref(0)->get_id(), *second_id
= 0;
791 if (subrefs
.get_nof_refs() > 1) {
792 FieldOrArrayRef
*second_ref
= subrefs
.get_ref(1);
793 if (second_ref
->get_type() == FieldOrArrayRef::FIELD_REF
) {
794 // the reference begins with <id>.<id> (most complicated case)
795 // there are 3 possible situations:
796 // 1. first_id points to a local definition (this has the priority)
797 // modid: 0, id: first_id
798 // 2. first_id points to an imported module (trivial case)
799 // modid: first_id, id: second_id
800 // 3. none of the above (first_id might be an imported symbol)
801 // modid: 0, id: first_id
802 // Note: Rule 1 has the priority because it can be overridden using
803 // the notation <id>.objid { ... }.<id> (modid and id are set in the
804 // constructor), but there is no work-around in the reverse way.
805 if (!my_scope
->has_ass_withId(*first_id
)
806 && my_scope
->is_valid_moduleid(*first_id
)) {
807 // rule 1 is not fulfilled, but rule 2 is fulfilled
808 second_id
= second_ref
->get_id();
810 } // else: the reference begins with <id>[<arrayref>] -> there is no modid
811 } // else: the reference consists of a single <id> -> there is no modid
813 modid
= first_id
->clone();
814 id
= second_id
->clone();
815 subrefs
.remove_refs(2);
818 id
= first_id
->clone();
819 subrefs
.remove_refs(1);
823 // =================================
825 // =================================
827 Ref_pard::Ref_pard(const Ref_pard
& p
)
828 : Ref_base(p
), parlist(p
.parlist
), expr_cache(0)
830 params
= p
.params
? p
.params
->clone() : 0;
833 Ref_pard::Ref_pard(Identifier
*p_modid
, Identifier
*p_id
,
834 ParsedActualParameters
*p_params
)
835 : Ref_base(p_modid
, p_id
), parlist(), params(p_params
), expr_cache(0)
838 FATAL_ERROR("Ttcn::Ref_pard::Ref_pard(): NULL parameter");
841 Ref_pard::~Ref_pard()
847 Ref_pard
*Ref_pard::clone() const
849 return new Ref_pard(*this);
852 void Ref_pard::set_fullname(const string
& p_fullname
)
854 Ref_base::set_fullname(p_fullname
);
855 parlist
.set_fullname(p_fullname
);
856 if (params
) params
->set_fullname(p_fullname
);
859 void Ref_pard::set_my_scope(Scope
*p_scope
)
861 Ref_base::set_my_scope(p_scope
);
862 parlist
.set_my_scope(p_scope
);
863 if (params
) params
->set_my_scope(p_scope
);
866 string
Ref_pard::get_dispname()
868 if (is_erroneous
) return string("erroneous");
871 ret_val
+= modid
->get_dispname();
874 ret_val
+= id
->get_dispname();
876 if (params_checked
) {
877 // used after semantic analysis
878 for (size_t i
= 0; i
< parlist
.get_nof_pars(); i
++) {
879 if (i
> 0) ret_val
+= ", ";
880 parlist
.get_par(i
)->append_stringRepr(ret_val
);
883 // used before semantic analysis
884 for (size_t i
= 0; i
< params
->get_nof_tis(); i
++) {
885 if (i
> 0) ret_val
+= ", ";
886 params
->get_ti_byIndex(i
)->append_stringRepr(ret_val
);
890 subrefs
.append_stringRepr(ret_val
);
894 Common::Assignment
* Ref_pard::get_refd_assignment(bool check_parlist
)
896 Common::Assignment
*ass
= Ref_base::get_refd_assignment(check_parlist
);
897 if (ass
&& check_parlist
&& !params_checked
) {
898 params_checked
= true;
899 FormalParList
*fplist
= ass
->get_FormalParList();
901 Error_Context
cntxt(params
, "In actual parameter list of %s",
902 ass
->get_description().c_str());
903 is_erroneous
= fplist
->fold_named_and_chk(params
, &parlist
);
904 parlist
.set_fullname(get_fullname());
905 parlist
.set_my_scope(my_scope
);
906 // the parsed parameter list is no longer needed
910 params
->error("The referenced %s cannot have actual parameters",
911 ass
->get_description().c_str());
917 const Identifier
* Ref_pard::get_modid()
922 const Identifier
* Ref_pard::get_id()
927 ActualParList
*Ref_pard::get_parlist()
929 if (!params_checked
) FATAL_ERROR("Ref_pard::get_parlist()");
933 bool Ref_pard::chk_activate_argument()
935 Common::Assignment
*t_ass
= get_refd_assignment();
936 if (!t_ass
) return false;
937 if (t_ass
->get_asstype() != Common::Assignment::A_ALTSTEP
) {
938 error("Reference to an altstep was expected in the argument instead of "
939 "%s", t_ass
->get_description().c_str());
942 my_scope
->chk_runs_on_clause(t_ass
, *this, "activate");
943 // the altstep reference cannot have sub-references
944 if (get_subrefs()) FATAL_ERROR("Ref_pard::chk_activate_argument()");
945 FormalParList
*fp_list
= t_ass
->get_FormalParList();
946 // the altstep must have formal parameter list
947 if (!fp_list
) FATAL_ERROR("Ref_pard::chk_activate_argument()");
948 return fp_list
->chk_activate_argument(&parlist
,
949 t_ass
->get_description().c_str());
952 bool Ref_pard::has_single_expr()
954 if (!Ref_base::has_single_expr()) return false;
955 for (size_t i
= 0; i
< parlist
.get_nof_pars(); i
++)
956 if (!parlist
.get_par(i
)->has_single_expr()) return false;
957 // if any formal parameter has lazy evaluation
958 Common::Assignment
*ass
= get_refd_assignment();
960 const FormalParList
*fplist
= ass
->get_FormalParList();
962 size_t num_formal
= fplist
->get_nof_fps();
963 for (size_t i
=0; i
<num_formal
; ++i
) {
964 const FormalPar
*fp
= fplist
->get_fp_byIndex(i
);
965 if (fp
->get_lazy_eval()) return false;
972 void Ref_pard::set_code_section(
973 GovernedSimple::code_section_t p_code_section
)
975 Ref_base::set_code_section(p_code_section
);
976 for (size_t i
= 0; i
< parlist
.get_nof_pars(); i
++)
977 parlist
.get_par(i
)->set_code_section(p_code_section
);
980 void Ref_pard::generate_code(expression_struct_t
*expr
)
982 Common::Assignment
*ass
= get_refd_assignment();
983 // C++ function reference with actual parameter list
984 expr
->expr
= mputprintf(expr
->expr
, "%s(",
985 ass
->get_genname_from_scope(my_scope
).c_str());
986 parlist
.generate_code_alias(expr
, ass
->get_FormalParList(),
987 ass
->get_RunsOnType(),false);
988 expr
->expr
= mputc(expr
->expr
, ')');
990 if (subrefs
.get_nof_refs() > 0) subrefs
.generate_code(expr
, ass
);
993 void Ref_pard::generate_code_cached(expression_struct_t
*expr
)
996 expr
->expr
= mputstr(expr
->expr
, expr_cache
);
1000 expr_cache
= mputstr(expr_cache
, expr
->expr
);
1004 void Ref_pard::generate_code_const_ref(expression_struct_t
*expr
)
1006 FieldOrArrayRefs
*t_subrefs
= get_subrefs();
1007 if (!t_subrefs
|| t_subrefs
->get_nof_refs() == 0) {
1008 generate_code(expr
);
1012 Common::Assignment
*ass
= get_refd_assignment();
1013 if (!ass
) FATAL_ERROR("Ref_pard::generate_code_const_ref()");
1016 switch (ass
->get_asstype()) {
1017 case Common::Assignment::A_TEMPLATE
:
1018 if (NULL
== ass
->get_FormalParList()) {
1019 // not a parameterized template
1023 // else fall through
1024 case Common::Assignment::A_CONST
:
1025 case Common::Assignment::A_EXT_CONST
:
1026 case Common::Assignment::A_ALTSTEP
:
1027 case Common::Assignment::A_TESTCASE
:
1028 case Common::Assignment::A_FUNCTION
:
1029 case Common::Assignment::A_EXT_FUNCTION
:
1030 case Common::Assignment::A_FUNCTION_RVAL
:
1031 case Common::Assignment::A_EXT_FUNCTION_RVAL
:
1032 case Common::Assignment::A_FUNCTION_RTEMP
:
1033 case Common::Assignment::A_EXT_FUNCTION_RTEMP
:
1034 generate_code(expr
);
1036 case Common::Assignment::A_MODULEPAR
:
1037 case Common::Assignment::A_VAR
:
1038 case Common::Assignment::A_PAR_VAL_IN
:
1039 case Common::Assignment::A_PAR_VAL_OUT
:
1040 case Common::Assignment::A_PAR_VAL_INOUT
: {
1041 is_template
= false;
1043 case Common::Assignment::A_MODULEPAR_TEMP
:
1044 case Common::Assignment::A_VAR_TEMPLATE
:
1045 case Common::Assignment::A_PAR_TEMPL_IN
:
1046 case Common::Assignment::A_PAR_TEMPL_OUT
:
1047 case Common::Assignment::A_PAR_TEMPL_INOUT
: {
1051 is_template
= false;
1055 Type
*refd_gov
= ass
->get_Type();
1057 generate_code(expr
);
1062 expr
->expr
= mputprintf(expr
->expr
, "const_cast< const %s&>(",
1063 refd_gov
->get_genname_template(get_my_scope()).c_str() );
1065 expr
->expr
= mputprintf(expr
->expr
, "const_cast< const %s%s&>(",
1066 refd_gov
->get_genname_value(get_my_scope()).c_str(),
1067 is_template
? "_template":"");
1070 expr
->expr
= mputprintf(expr
->expr
, "%s(",
1071 ass
->get_genname_from_scope(my_scope
).c_str());
1072 parlist
.generate_code_alias(expr
, ass
->get_FormalParList(),
1073 ass
->get_RunsOnType(), false);
1074 expr
->expr
= mputstr(expr
->expr
, "))");
1076 t_subrefs
->generate_code(expr
, ass
);
1079 // =================================
1080 // ===== NameBridgingScope
1081 // =================================
1082 string
NameBridgingScope::get_scopeMacro_name() const
1084 if (scopeMacro_name
.empty()) FATAL_ERROR("NameBridgingScope::get_scopeMacro_name()");
1085 return scopeMacro_name
;
1088 NameBridgingScope
*NameBridgingScope::clone() const
1090 FATAL_ERROR("NameBridgingScope::clone");
1093 Common::Assignment
* NameBridgingScope::get_ass_bySRef(Ref_simple
*p_ref
)
1095 return get_parent_scope()->get_ass_bySRef(p_ref
);
1098 // =================================
1099 // ===== RunsOnScope
1100 // =================================
1102 RunsOnScope::RunsOnScope(Type
*p_comptype
)
1103 : Scope(), component_type(p_comptype
)
1105 if (!p_comptype
|| p_comptype
->get_typetype() != Type::T_COMPONENT
)
1106 FATAL_ERROR("RunsOnScope::RunsOnScope()");
1107 component_type
->set_ownertype(Type::OT_RUNSON_SCOPE
, this);
1108 component_defs
= p_comptype
->get_CompBody();
1109 set_scope_name("runs on `" + p_comptype
->get_fullname() + "'");
1112 RunsOnScope
*RunsOnScope::clone() const
1114 FATAL_ERROR("RunsOnScope::clone()");
1117 void RunsOnScope::chk_uniq()
1119 // do not perform this check if the component type is defined in the same
1120 // module as the 'runs on' clause
1121 if (parent_scope
->get_scope_mod() == component_defs
->get_scope_mod())
1123 size_t nof_defs
= component_defs
->get_nof_asss();
1124 for (size_t i
= 0; i
< nof_defs
; i
++) {
1125 Common::Assignment
*comp_def
= component_defs
->get_ass_byIndex(i
);
1126 const Identifier
& id
= comp_def
->get_id();
1127 if (parent_scope
->has_ass_withId(id
)) {
1128 comp_def
->warning("Imported component element definition `%s' hides a "
1129 "definition at module scope", comp_def
->get_fullname().c_str());
1130 Reference
ref(0, id
.clone());
1131 Common::Assignment
*hidden_ass
= parent_scope
->get_ass_bySRef(&ref
);
1132 hidden_ass
->warning("Hidden definition `%s' is here",
1133 hidden_ass
->get_fullname().c_str());
1139 RunsOnScope
*RunsOnScope::get_scope_runs_on()
1144 Common::Assignment
*RunsOnScope::get_ass_bySRef(Ref_simple
*p_ref
)
1146 if (!p_ref
) FATAL_ERROR("Ttcn::RunsOnScope::get_ass_bySRef()");
1147 if (p_ref
->get_modid()) return parent_scope
->get_ass_bySRef(p_ref
);
1149 const Identifier
& id
= *p_ref
->get_id();
1150 if (component_defs
->has_local_ass_withId(id
)) {
1151 Common::Assignment
* ass
= component_defs
->get_local_ass_byId(id
);
1152 if (!ass
) FATAL_ERROR("Ttcn::RunsOnScope::get_ass_bySRef()");
1154 if (component_defs
->is_own_assignment(ass
)) return ass
;
1155 else if (ass
->get_visibility() == PUBLIC
) {
1159 p_ref
->error("The member definition `%s' in component type `%s'"
1160 " is not visible in this scope", id
.get_dispname().c_str(),
1161 component_defs
->get_id()->get_dispname().c_str());
1163 } else return parent_scope
->get_ass_bySRef(p_ref
);
1167 bool RunsOnScope::has_ass_withId(const Identifier
& p_id
)
1169 return component_defs
->has_ass_withId(p_id
)
1170 || parent_scope
->has_ass_withId(p_id
);
1173 // =================================
1175 // =================================
1177 FriendMod::FriendMod(Identifier
*p_modid
)
1178 : Node(), modid(p_modid
), w_attrib_path(0), parentgroup(0), checked(false)
1180 if (!p_modid
) FATAL_ERROR("NULL parameter: Ttcn::FriendMod::FriendMod()");
1181 set_fullname("<friends>."+modid
->get_dispname());
1184 FriendMod::~FriendMod()
1188 delete w_attrib_path
;
1191 FriendMod
*FriendMod::clone() const
1193 FATAL_ERROR("Ttcn::FriendMod::clone()");
1196 void FriendMod::set_fullname(const string
& p_fullname
)
1198 if(w_attrib_path
) w_attrib_path
->set_fullname(p_fullname
+ ".<attribpath>");
1201 void FriendMod::chk()
1203 if (checked
) return;
1205 Error_Context
cntxt(this, "In friend module declaration");
1207 if (w_attrib_path
) {
1208 w_attrib_path
->chk_global_attrib();
1209 w_attrib_path
->chk_no_qualif();
1215 void FriendMod::set_with_attr(MultiWithAttrib
* p_attrib
)
1217 if (w_attrib_path
) FATAL_ERROR("FriendMod::set_with_attr()");
1218 w_attrib_path
= new WithAttribPath();
1219 if (p_attrib
&& p_attrib
->get_nof_elements() > 0) {
1220 w_attrib_path
->set_with_attr(p_attrib
);
1224 WithAttribPath
* FriendMod::get_attrib_path()
1226 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
1227 return w_attrib_path
;
1230 void FriendMod::set_parent_path(WithAttribPath
* p_path
)
1232 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
1233 w_attrib_path
->set_parent(p_path
);
1236 void FriendMod::set_parent_group(Group
* p_group
)
1238 if(parentgroup
) FATAL_ERROR("FriendMod::set_parent_group");
1239 parentgroup
= p_group
;
1242 // =================================
1244 // =================================
1246 ImpMod::ImpMod(Identifier
*p_modid
)
1247 : Node(), mod(0), my_mod(0), imptype(I_UNDEF
), modid(p_modid
),
1248 language_spec(0), is_recursive(false),
1249 w_attrib_path(0), parentgroup(0), visibility(PRIVATE
)
1251 if (!p_modid
) FATAL_ERROR("NULL parameter: Ttcn::ImpMod::ImpMod()");
1252 set_fullname("<imports>." + modid
->get_dispname());
1258 delete language_spec
;
1260 delete w_attrib_path
;
1263 ImpMod
*ImpMod::clone() const
1265 FATAL_ERROR("No clone for you!");
1268 void ImpMod::set_fullname(const string
& p_fullname
)
1270 if(w_attrib_path
) w_attrib_path
->set_fullname(p_fullname
+ ".<attribpath>");
1275 if (w_attrib_path
) {
1276 w_attrib_path
->chk_global_attrib();
1277 w_attrib_path
->chk_no_qualif();
1281 void ImpMod::chk_imp(ReferenceChain
& refch
, vector
<Common::Module
>& moduleStack
)
1283 Error_Context
cntxt(this, "In import definition");
1285 if (!modules
->has_mod_withId(*modid
)) {
1286 error("There is no module with identifier `%s'",
1287 modid
->get_dispname().c_str());
1291 Common::Module
*m
= modules
->get_mod_byId(*modid
);
1297 error("A module cannot import from itself");
1305 if (refch
.exists(my_mod
->get_fullname())) {
1306 if(my_mod
->get_moduletype()!=Common::Module::MOD_ASN
){ // Do not warning for circular import in ASN.1 module. It is legal
1307 my_mod
->warning("Circular import chain is not recommended: %s",
1308 refch
.get_dispstr(my_mod
->get_fullname()).c_str());
1313 refch
.add(my_mod
->get_fullname());
1315 if (ImpMod::I_IMPORTIMPORT
== imptype
){
1316 Ttcn::Module
* ttcnmodule
=static_cast<Ttcn::Module
*>(m
);
1317 const Imports
& imp
= ttcnmodule
->get_imports();
1319 for (size_t t
= 0; t
< imp
.impmods_v
.size(); t
++) {
1320 const ImpMod
*im
= imp
.impmods_v
[t
];
1321 const Identifier
& im_id
= im
->get_modid();
1322 Common::Module
*cm
= modules
->get_mod_byId(im_id
); // never NULL
1325 if (PRIVATE
!= im
->get_visibility()) {
1326 if (refch
.exists(m
->get_fullname())) {
1327 if(m
->get_moduletype()!=Common::Module::MOD_ASN
){ // Do not warning for circular import in ASN.1 module. It is legal
1328 m
->warning("Circular import chain is not recommended: %s",
1329 refch
.get_dispstr(m
->get_fullname()).c_str());
1334 refch
.add(m
->get_fullname());
1335 cm
->chk_imp(refch
, moduleStack
);
1341 //refch.mark_state();
1342 m
->chk_imp(refch
, moduleStack
);
1343 //refch.prev_state();
1348 size_t state
=moduleStack
.size();
1349 moduleStack
.replace(state
, moduleStack
.size() - state
);
1352 bool ImpMod::has_imported_def(const Identifier
& p_source_modid
,
1353 const Identifier
& p_id
, const Location
*loc
) const
1355 if (!mod
) return false;
1361 Common::Assignment
* return_assignment
= mod
->importAssignment(p_source_modid
, p_id
);
1362 if (return_assignment
!= NULL
) {
1369 case I_IMPORTIMPORT
:
1371 Ttcn::Module
*tm
= static_cast<Ttcn::Module
*>(mod
); // B
1373 const Imports
& imps
= tm
->get_imports();
1375 vector
<ImpMod
> tempusedImpMods
;
1376 for (size_t i
= 0, num
= imps
.impmods_v
.size(); i
< num
; ++i
) {
1377 ReferenceChain
* referencechain
= new ReferenceChain(this, "NEW IMPORT REFERNCECHAIN");
1378 Common::Assignment
* return_assignment
= imps
.impmods_v
[i
]->
1379 get_imported_def(p_source_modid
, p_id
, loc
, referencechain
, tempusedImpMods
); // C
1380 referencechain
->reset();
1381 delete referencechain
;
1383 if (return_assignment
!= NULL
) {
1389 //satisfy destructor
1390 tempusedImpMods
.clear();
1395 FATAL_ERROR("ImpMod::get_imported_def");
1401 Common::Assignment
*ImpMod::get_imported_def(
1402 const Identifier
& p_source_modid
, const Identifier
& p_id
,
1403 const Location
*loc
, ReferenceChain
* refch
,
1404 vector
<ImpMod
>& usedImpMods
) const
1409 Common::Assignment
* result
= NULL
;
1414 result
= mod
->importAssignment(p_source_modid
, p_id
);
1415 if (result
!= NULL
) {
1416 usedImpMods
.add(const_cast<Ttcn::ImpMod
*>(this));
1420 case I_IMPORTIMPORT
:
1422 Ttcn::Module
*tm
= static_cast<Ttcn::Module
*>(mod
);
1424 const Imports
& imps
= tm
->get_imports();
1425 Common::Assignment
* t_ass
= NULL
;
1427 for (size_t i
= 0, num
= imps
.impmods_v
.size(); i
< num
; ++i
) {
1428 vector
<ImpMod
> tempusedImpMods
;
1430 refch
->mark_state();
1431 if (imps
.impmods_v
[i
]->get_visibility() == PUBLIC
) {
1432 t_ass
= imps
.impmods_v
[i
]->get_imported_def(p_source_modid
, p_id
, loc
, refch
, tempusedImpMods
);
1434 else if (imps
.impmods_v
[i
]->get_visibility() == FRIEND
) {
1435 t_ass
= imps
.impmods_v
[i
]->get_imported_def(p_source_modid
, p_id
, loc
, refch
, tempusedImpMods
);
1437 tempusedImpMods
.add(imps
.impmods_v
[i
]);
1440 refch
->prev_state();
1442 if (t_ass
!= NULL
) {
1443 bool visible
= true;
1444 for (size_t j
= 0; j
< tempusedImpMods
.size(); j
++) {
1445 ImpMod
* impmod_l
= tempusedImpMods
[j
];
1446 //check whether the module is TTCN
1447 if (impmod_l
->get_mod()->get_moduletype() == Common::Module::MOD_TTCN
) {
1448 // cast to ttcn module
1449 Ttcn::Module
*ttcn_m
= static_cast<Ttcn::Module
*>(impmod_l
->get_mod());
1450 if (!ttcn_m
->is_visible(mod
->get_modid(), impmod_l
->get_visibility())) {
1456 for (size_t t
= 0; i
< tempusedImpMods
.size(); i
++) {
1457 usedImpMods
.add(tempusedImpMods
[t
]);
1462 } else if(result
!= t_ass
) {
1467 "It is not possible to resolve the reference unambiguously"
1468 ", as it can be resolved to `%s' and to `%s'",
1469 result
->get_fullname().c_str(), t_ass
->get_fullname().c_str());
1475 tempusedImpMods
.clear();
1478 if (result
!= NULL
) {
1479 usedImpMods
.add(const_cast<Ttcn::ImpMod
*>(this));
1485 FATAL_ERROR("ImpMod::get_imported_def");
1490 void ImpMod::set_language_spec(const char *p_language_spec
)
1492 if (language_spec
) FATAL_ERROR("ImpMod::set_language_spec()");
1493 if (p_language_spec
) language_spec
= new string(p_language_spec
);
1496 void ImpMod::generate_code(output_struct
*target
)
1498 const char *module_name
= modid
->get_name().c_str();
1500 target
->header
.includes
= mputprintf(target
->header
.includes
,
1501 "#include \"%s.hh\"\n",
1502 duplicate_underscores
? module_name
: modid
->get_ttcnname().c_str());
1504 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
1505 "%s%s.pre_init_module();\n", module_name
,
1508 if (mod
->get_moduletype() == Common::Module::MOD_TTCN
) {
1509 target
->functions
.post_init
= mputprintf(target
->functions
.post_init
,
1510 "%s%s.post_init_module();\n", module_name
,
1516 void ImpMod::dump(unsigned level
) const
1518 DEBUG(level
, "Import from module %s", modid
->get_dispname().c_str());
1519 if (w_attrib_path
) {
1520 MultiWithAttrib
*attrib
= w_attrib_path
->get_with_attr();
1522 DEBUG(level
+ 1, "Attributes:");
1523 attrib
->dump(level
+ 2);
1528 void ImpMod::set_with_attr(MultiWithAttrib
* p_attrib
)
1530 if (w_attrib_path
) FATAL_ERROR("ImpMod::set_with_attr()");
1531 w_attrib_path
= new WithAttribPath();
1532 if (p_attrib
&& p_attrib
->get_nof_elements() > 0) {
1533 w_attrib_path
->set_with_attr(p_attrib
);
1537 WithAttribPath
* ImpMod::get_attrib_path()
1539 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
1540 return w_attrib_path
;
1543 void ImpMod::set_parent_path(WithAttribPath
* p_path
)
1545 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
1546 w_attrib_path
->set_parent(p_path
);
1549 void ImpMod::set_parent_group(Group
* p_group
)
1551 if(parentgroup
) FATAL_ERROR("ImpMod::set_parent_group");
1552 parentgroup
= p_group
;
1555 // =================================
1557 // =================================
1561 for (size_t i
= 0; i
< impmods_v
.size(); i
++)
1562 delete impmods_v
[i
];
1566 Imports
*Imports::clone() const
1568 FATAL_ERROR("Ttcn::Imports::clone()");
1571 void Imports::add_impmod(ImpMod
*p_impmod
)
1573 if (!p_impmod
) FATAL_ERROR("Ttcn::Imports::add_impmod()");
1574 impmods_v
.add(p_impmod
);
1575 p_impmod
->set_my_mod(my_mod
);
1578 void Imports::set_my_mod(Module
*p_mod
)
1581 for(size_t i
= 0; i
< impmods_v
.size(); i
++)
1582 impmods_v
[i
]->set_my_mod(my_mod
);
1585 bool Imports::has_impmod_withId(const Identifier
& p_id
) const
1587 for (size_t i
= 0, size
= impmods_v
.size(); i
< size
; ++i
) {
1588 const ImpMod
* im
= impmods_v
[i
];
1589 const Identifier
& im_id
= im
->get_modid();
1590 const string
& im_name
= im_id
.get_name();
1591 if (p_id
.get_name() == im_name
) {
1592 // The identifier represents a module imported in the current module
1599 void Imports::chk_imp(ReferenceChain
& refch
, vector
<Common::Module
>& moduleStack
)
1601 if (impmods_v
.size() <= 0) return;
1603 if (!my_mod
) FATAL_ERROR("Ttcn::Imports::chk_imp()");
1608 for(size_t n
= 0; n
< impmods_v
.size(); n
++)
1610 impmods_v
[n
]->chk();
1613 //TODO this whole thing should be moved into impmod::chk
1614 Identifier
address_id(Identifier::ID_TTCN
, string("address"));
1615 for (size_t n
= 0; n
< impmods_v
.size(); n
++) {
1616 ImpMod
*im
= impmods_v
[n
];
1617 im
->chk_imp(refch
, moduleStack
);
1619 const Identifier
& im_id
= im
->get_modid();
1620 Common::Module
*m
= modules
->get_mod_byId(im_id
);
1623 if (m
->get_gen_code()) my_mod
->set_gen_code();
1624 } // next assignment
1627 bool Imports::has_imported_def(const Identifier
& p_id
, const Location
*loc
) const
1629 for (size_t n
= 0; n
< impmods_v
.size(); n
++) {
1630 ImpMod
*im
= impmods_v
[n
];
1631 bool return_bool
= im
->has_imported_def(my_mod
->get_modid(), p_id
, loc
);
1632 if (return_bool
) return true;
1637 Common::Assignment
*Imports::get_imported_def(
1638 const Identifier
& p_source_modid
, const Identifier
& p_id
,
1639 const Location
*loc
, ReferenceChain
* refch
)
1641 vector
<ImpMod
> tempusedImpMods
;
1642 Common::Assignment
* result
= NULL
;
1643 for (size_t n
= 0; n
< impmods_v
.size(); n
++) {
1644 ImpMod
*im
= impmods_v
[n
];
1645 refch
->mark_state();
1646 Common::Assignment
* ass
= im
->get_imported_def(
1647 p_source_modid
, p_id
, loc
, refch
, tempusedImpMods
);
1648 tempusedImpMods
.clear();
1649 refch
->prev_state();
1654 } else if(result
!= ass
&& loc
) {
1659 "It is not possible to resolve the reference unambiguously"
1660 ", as it can be resolved to `%s' and to `%s'",
1661 result
->get_fullname().c_str(), ass
->get_fullname().c_str());
1669 void Imports::get_imported_mods(Module::module_set_t
& p_imported_mods
) const
1671 for (size_t i
= 0; i
< impmods_v
.size(); i
++) {
1672 ImpMod
*im
= impmods_v
[i
];
1673 Common::Module
*m
= im
->get_mod();
1675 if (!p_imported_mods
.has_key(m
)) {
1676 p_imported_mods
.add(m
, 0);
1677 m
->get_visible_mods(p_imported_mods
);
1682 void Imports::generate_code(output_struct
*target
)
1684 target
->header
.includes
= mputstr(target
->header
.includes
,
1685 "#include <TTCN3.hh>\n");
1686 for (size_t i
= 0; i
< impmods_v
.size(); i
++) {
1687 ImpMod
*im
= impmods_v
[i
];
1688 Common::Module
*m
= im
->get_mod();
1689 // inclusion of m's header file can be eliminated if we find another
1690 // imported module that imports m
1691 bool covered
= false;
1692 for (size_t j
= 0; j
< impmods_v
.size(); j
++) {
1693 // skip over the same import definition
1694 if (j
== i
) continue;
1695 ImpMod
*im2
= impmods_v
[j
];
1696 Common::Module
*m2
= im2
->get_mod();
1697 // a module that is equivalent to the current module due to
1698 // circular imports cannot be used to cover anything
1699 if (m2
->is_visible(my_mod
)) continue;
1700 if (m2
->is_visible(m
) && !m
->is_visible(m2
)) {
1701 // m2 covers m (i.e. m is visible from m2)
1702 // and they are not in the same import loop
1707 // do not generate the #include if a covering module is found
1708 if (!covered
) im
->generate_code(target
);
1712 void Imports::generate_code(CodeGenHelper
& cgh
) {
1713 generate_code(cgh
.get_current_outputstruct());
1716 void Imports::dump(unsigned level
) const
1718 DEBUG(level
, "Imports (%lu pcs.)", (unsigned long) impmods_v
.size());
1719 for (size_t i
= 0; i
< impmods_v
.size(); i
++)
1720 impmods_v
[i
]->dump(level
+ 1);
1723 // =================================
1724 // ===== Definitions
1725 // =================================
1727 Definitions::~Definitions()
1729 for(size_t i
= 0; i
< ass_v
.size(); i
++) delete ass_v
[i
];
1734 Definitions
*Definitions::clone() const
1736 FATAL_ERROR("Definitions::clone");
1739 void Definitions::add_ass(Definition
*p_ass
)
1741 // it is too late to add a new one after it has been checked.
1742 if (checked
|| !p_ass
) FATAL_ERROR("Ttcn::OtherDefinitions::add_ass()");
1744 p_ass
->set_my_scope(this);
1747 void Definitions::set_fullname(const string
& p_fullname
)
1749 Common::Assignments::set_fullname(p_fullname
);
1750 for(size_t i
= 0; i
< ass_v
.size(); i
++) {
1751 Definition
*ass
= ass_v
[i
];
1752 ass
->set_fullname(p_fullname
+ "." + ass
->get_id().get_dispname());
1756 bool Definitions::has_local_ass_withId(const Identifier
& p_id
)
1758 if (!checked
) chk_uniq();
1759 return ass_m
.has_key(p_id
.get_name());
1762 Common::Assignment
* Definitions::get_local_ass_byId(const Identifier
& p_id
)
1764 if (!checked
) chk_uniq();
1765 return ass_m
[p_id
.get_name()];
1768 size_t Definitions::get_nof_asss()
1770 if (!checked
) chk_uniq();
1771 return ass_m
.size();
1774 size_t Definitions::get_nof_raw_asss()
1776 return ass_v
.size();
1779 Common::Assignment
* Definitions::get_ass_byIndex(size_t p_i
)
1781 if (!checked
) chk_uniq();
1782 return ass_m
.get_nth_elem(p_i
);
1785 Ttcn::Definition
* Definitions::get_raw_ass_byIndex(size_t p_i
) {
1789 void Definitions::chk_uniq()
1791 if (checked
) return;
1793 for (size_t i
= 0; i
< ass_v
.size(); i
++) {
1794 Definition
*ass
= ass_v
[i
];
1795 const Identifier
& id
= ass
->get_id();
1796 const string
& name
= id
.get_name();
1797 if (ass_m
.has_key(name
)) {
1798 const char *dispname_str
= id
.get_dispname().c_str();
1799 ass
->error("Duplicate definition with name `%s'", dispname_str
);
1800 ass_m
[name
]->note("Previous definition of `%s' is here", dispname_str
);
1802 ass_m
.add(name
, ass
);
1803 if (parent_scope
->is_valid_moduleid(id
)) {
1804 ass
->warning("Definition with name `%s' hides a module identifier",
1805 id
.get_dispname().c_str());
1812 void Definitions::chk()
1814 for (size_t i
= 0; i
< ass_v
.size(); i
++) ass_v
[i
]->chk();
1817 void Definitions::chk_for()
1819 if (checked
) return;
1822 // all checks are done in one iteration because
1823 // forward referencing is not allowed between the definitions
1824 for (size_t i
= 0; i
< ass_v
.size(); i
++) {
1825 Definition
*def
= ass_v
[i
];
1826 const Identifier
& id
= def
->get_id();
1827 const string
& name
= id
.get_name();
1828 if (ass_m
.has_key(name
)) {
1829 const char *dispname_str
= id
.get_dispname().c_str();
1830 def
->error("Duplicate definition with name `%s'", dispname_str
);
1831 ass_m
[name
]->note("Previous definition of `%s' is here", dispname_str
);
1833 ass_m
.add(name
, def
);
1835 if (parent_scope
->has_ass_withId(id
)) {
1836 const char *dispname_str
= id
.get_dispname().c_str();
1837 def
->error("Definition with identifier `%s' is not unique in the "
1838 "scope hierarchy", dispname_str
);
1839 Reference
ref(0, id
.clone());
1840 Common::Assignment
*ass
= parent_scope
->get_ass_bySRef(&ref
);
1841 if (!ass
) FATAL_ERROR("OtherDefinitions::chk_for()");
1842 ass
->note("Previous definition with identifier `%s' in higher "
1843 "scope unit is here", dispname_str
);
1844 } else if (parent_scope
->is_valid_moduleid(id
)) {
1845 def
->warning("Definition with name `%s' hides a module identifier",
1846 id
.get_dispname().c_str());
1854 void Definitions::set_genname(const string
& prefix
)
1856 for (size_t i
= 0; i
< ass_v
.size(); i
++) {
1857 Definition
*def
= ass_v
[i
];
1858 def
->set_genname(prefix
+ def
->get_id().get_name());
1862 void Definitions::generate_code(output_struct
* target
)
1864 for(size_t i
= 0; i
< ass_v
.size(); i
++) ass_v
[i
]->generate_code(target
);
1867 void Definitions::generate_code(CodeGenHelper
& cgh
) {
1869 for(size_t i
= 0; i
< ass_v
.size(); i
++) ass_v
[i
]->generate_code(cgh
);
1872 char* Definitions::generate_code_str(char *str
)
1874 for(size_t i
=0; i
<ass_v
.size(); i
++) {
1875 str
= ass_v
[i
]->update_location_object(str
);
1876 str
=ass_v
[i
]->generate_code_str(str
);
1881 void Definitions::ilt_generate_code(ILT
*ilt
)
1883 for(size_t i
=0; i
<ass_v
.size(); i
++)
1884 ass_v
[i
]->ilt_generate_code(ilt
);
1888 void Definitions::dump(unsigned level
) const
1890 DEBUG(level
, "Definitions: (%lu pcs.)", (unsigned long) ass_v
.size());
1891 for(size_t i
= 0; i
< ass_v
.size(); i
++) ass_v
[i
]->dump(level
+ 1);
1894 // =================================
1896 // =================================
1898 Group::Group(Identifier
*p_id
)
1899 : Node(), Location(), parent_group(0), w_attrib_path(0), id(p_id
),
1902 if (!p_id
) FATAL_ERROR("Group::Group()");
1907 delete w_attrib_path
;
1910 for (size_t i
= 0; i
< group_v
.size(); i
++) delete group_v
[i
];
1914 friendmods_v
.clear();
1918 Group
* Group::clone() const
1920 FATAL_ERROR("Ttcn::Group::clone()");
1923 void Group::set_fullname(const string
& p_fullname
)
1925 Node::set_fullname(p_fullname
);
1926 for(size_t i
= 0; i
< group_v
.size() ; i
++)
1928 group_v
[i
]->set_fullname(p_fullname
+ ".<group " + Int2string(i
) + ">");
1930 if (w_attrib_path
) w_attrib_path
->set_fullname( p_fullname
1934 void Group::add_ass(Definition
* p_ass
)
1937 p_ass
->set_parent_group(this);
1940 void Group::add_group(Group
* p_group
)
1942 group_v
.add(p_group
);
1945 void Group::set_parent_group(Group
* p_parent_group
)
1947 if (parent_group
) FATAL_ERROR("Group::set_parent_group()");
1948 parent_group
= p_parent_group
;
1951 void Group::set_with_attr(MultiWithAttrib
* p_attrib
)
1953 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
1954 w_attrib_path
->set_with_attr(p_attrib
);
1957 WithAttribPath
* Group::get_attrib_path()
1959 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
1960 return w_attrib_path
;
1963 void Group::set_parent_path(WithAttribPath
* p_path
)
1965 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
1966 w_attrib_path
->set_parent(p_path
);
1969 void Group::chk_uniq()
1971 if (checked
) return;
1975 for (size_t i
= 0; i
< ass_v
.size(); i
++) {
1976 Definition
*ass
= ass_v
[i
];
1977 const string
& ass_name
= ass
->get_id().get_name();
1978 if (!ass_m
.has_key(ass_name
)) ass_m
.add(ass_name
, ass
);
1981 for(size_t i
= 0; i
< group_v
.size(); i
++) {
1982 Group
*group
= group_v
[i
];
1983 const Identifier
& group_id
= group
->get_id();
1984 const string
& group_name
= group_id
.get_name();
1985 if (ass_m
.has_key(group_name
)) {
1986 group
->error("Group name `%s' clashes with a definition",
1987 group_id
.get_dispname().c_str());
1988 ass_m
[group_name
]->note("Definition of `%s' is here",
1989 group_id
.get_dispname().c_str());
1991 if (group_m
.has_key(group_name
)) {
1992 group
->error("Duplicate group with name `%s'",
1993 group_id
.get_dispname().c_str());
1994 group_m
[group_name
]->note("Group `%s' is already defined here",
1995 group_id
.get_dispname().c_str());
1996 } else group_m
.add(group_name
, group
);
2003 Error_Context
cntxt(this, "In group `%s'", id
->get_dispname().c_str());
2007 if (w_attrib_path
) {
2008 w_attrib_path
->chk_global_attrib();
2009 w_attrib_path
->chk_no_qualif();
2012 for(size_t i
= 0; i
< group_v
.size(); i
++) group_v
[i
]->chk();
2015 void Group::add_impmod(ImpMod
*p_impmod
)
2017 impmods_v
.add(p_impmod
);
2018 p_impmod
->set_parent_group(this);
2021 void Group::add_friendmod(FriendMod
*p_friendmod
)
2023 friendmods_v
.add(p_friendmod
);
2024 p_friendmod
->set_parent_group(this);
2027 void Group::dump(unsigned level
) const
2029 DEBUG(level
, "Group: %s", id
->get_dispname().c_str());
2030 DEBUG(level
+ 1, "Nested groups: (%lu pcs.)",
2031 (unsigned long) group_v
.size());
2032 for(size_t i
= 0; i
< group_v
.size(); i
++) group_v
[i
]->dump(level
+ 2);
2033 DEBUG(level
+ 1, "Nested definitions: (%lu pcs.)",
2034 (unsigned long) ass_v
.size());
2035 for(size_t i
= 0; i
< ass_v
.size(); i
++) ass_v
[i
]->dump(level
+ 2);
2036 DEBUG(level
+ 1, "Nested imports: (%lu pcs.)",
2037 (unsigned long) impmods_v
.size());
2038 for(size_t i
= 0; i
< impmods_v
.size(); i
++) impmods_v
[i
]->dump(level
+ 2);
2039 if (w_attrib_path
) {
2040 MultiWithAttrib
*attrib
= w_attrib_path
->get_with_attr();
2042 DEBUG(level
+ 1, "Group Attributes:");
2043 attrib
->dump(level
+ 2);
2048 // =================================
2049 // ===== ControlPart
2050 // =================================
2052 ControlPart::ControlPart(StatementBlock
* p_block
)
2053 : Node(), Location(), block(p_block
), w_attrib_path(0)
2055 if (!p_block
) FATAL_ERROR("ControlPart::ControlPart()");
2058 ControlPart::~ControlPart()
2061 delete w_attrib_path
;
2064 ControlPart
* ControlPart::clone() const
2066 FATAL_ERROR("ControlPart::clone");
2069 void ControlPart::set_fullname(const string
& p_fullname
)
2071 block
->set_fullname(p_fullname
);
2072 if(w_attrib_path
) w_attrib_path
->set_fullname(p_fullname
+ ".<attribpath>");
2075 void ControlPart::set_my_scope(Scope
*p_scope
)
2077 bridgeScope
.set_parent_scope(p_scope
);
2078 string
temp("control");
2079 bridgeScope
.set_scopeMacro_name(temp
);
2081 block
->set_my_scope(&bridgeScope
);
2084 void ControlPart::chk()
2086 Error_Context
cntxt(this, "In control part");
2088 if (!semantic_check_only
)
2089 block
->set_code_section(GovernedSimple::CS_INLINE
);
2090 if (w_attrib_path
) {
2091 w_attrib_path
->chk_global_attrib();
2092 w_attrib_path
->chk_no_qualif();
2096 void ControlPart::generate_code(output_struct
*target
, Module
*my_module
)
2098 const char *module_dispname
= my_module
->get_modid().get_dispname().c_str();
2099 target
->functions
.control
=
2100 create_location_object(target
->functions
.control
, "CONTROLPART",
2102 target
->functions
.control
= mputprintf(target
->functions
.control
,
2103 "TTCN_Runtime::begin_controlpart(\"%s\");\n", module_dispname
);
2104 if (debugger_active
) {
2105 target
->functions
.control
= mputprintf(target
->functions
.control
,
2106 "charstring_list no_params = NULL_VALUE;\n"
2107 "TTCN3_Debug_Function debug_scope(NULL, \"control\", \"%s\", no_params, no_params, NULL);\n"
2108 "debug_scope.initial_snapshot();\n", module_dispname
);
2110 target
->functions
.control
=
2111 block
->generate_code(target
->functions
.control
);
2112 target
->functions
.control
= mputstr(target
->functions
.control
,
2113 "TTCN_Runtime::end_controlpart();\n");
2116 void ControlPart::set_with_attr(MultiWithAttrib
* p_attrib
)
2118 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
2119 w_attrib_path
->set_with_attr(p_attrib
);
2122 WithAttribPath
* ControlPart::get_attrib_path()
2124 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
2125 return w_attrib_path
;
2128 void ControlPart::set_parent_path(WithAttribPath
* p_path
)
2130 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
2131 w_attrib_path
->set_parent(p_path
);
2132 block
->set_parent_path(w_attrib_path
);
2135 void ControlPart::dump(unsigned level
) const
2137 DEBUG(level
, "Control part");
2138 block
->dump(level
+ 1);
2139 if (w_attrib_path
) {
2140 MultiWithAttrib
*attrib
= w_attrib_path
->get_with_attr();
2142 DEBUG(level
+ 1, "Attributes:");
2143 attrib
->dump(level
+ 2);
2148 // =================================
2150 // =================================
2152 Module::Module(Identifier
*p_modid
)
2153 : Common::Module(MOD_TTCN
, p_modid
), language_spec(0), w_attrib_path(0),
2156 asss
= new Definitions();
2157 asss
->set_parent_scope(this);
2158 imp
= new Imports();
2159 imp
->set_my_mod(this);
2160 //modified_encodings = true; // Assume always true for TTCN modules
2165 delete language_spec
;
2167 for (size_t i
= 0; i
< group_v
.size(); i
++) delete group_v
[i
];
2171 for (size_t i
= 0; i
< friendmods_v
.size(); i
++) delete friendmods_v
[i
];
2172 friendmods_v
.clear();
2174 for (size_t i
= 0; i
< runs_on_scopes
.size(); i
++)
2175 delete runs_on_scopes
[i
];
2176 runs_on_scopes
.clear();
2177 delete w_attrib_path
;
2180 void Module::add_group(Group
* p_group
)
2182 group_v
.add(p_group
);
2185 void Module::add_friendmod(FriendMod
*p_friendmod
)
2187 friendmods_v
.add(p_friendmod
);
2188 p_friendmod
->set_my_mod(this);
2191 Module
*Module::clone() const
2193 FATAL_ERROR("Ttcn::Module::clone()");
2196 Common::Assignment
*Module::importAssignment(const Identifier
& p_modid
,
2197 const Identifier
& p_id
) const
2199 if (asss
->has_local_ass_withId(p_id
)) {
2200 Common::Assignment
* ass
= asss
->get_local_ass_byId(p_id
);
2201 if (!ass
) FATAL_ERROR("Ttcn::Module::importAssignment()");
2203 switch(ass
->get_visibility()) {
2205 for (size_t i
= 0; i
< friendmods_v
.size(); i
++) {
2206 if (friendmods_v
[i
]->get_modid() == p_modid
) return ass
;
2214 FATAL_ERROR("Ttcn::Module::importAssignment()");
2220 void Module::set_fullname(const string
& p_fullname
)
2222 Node::set_fullname(p_fullname
);
2223 asss
->set_fullname(p_fullname
);
2224 if (controlpart
) controlpart
->set_fullname(p_fullname
+ ".control");
2225 for(size_t i
= 0; i
< group_v
.size(); i
++)
2227 group_v
[i
]->set_fullname(p_fullname
+ ".<group " + Int2string(i
) + ">");
2229 if (w_attrib_path
) w_attrib_path
->set_fullname(p_fullname
2233 Common::Assignments
*Module::get_scope_asss()
2238 bool Module::has_imported_ass_withId(const Identifier
& p_id
)
2240 const Location
*loc
= NULL
;
2241 for (size_t i
= 0, num
= imp
->get_imports_size(); i
< num
; ++i
) {
2242 const ImpMod
* im
= imp
->get_impmod(i
);
2243 //TODO use a reference instead of an identifier
2244 if(im
->has_imported_def(*modid
, p_id
, loc
)) return true;
2249 Common::Assignment
* Module::get_ass_bySRef(Ref_simple
*p_ref
)
2251 const Identifier
*r_modid
= p_ref
->get_modid();
2252 const Identifier
*r_id
= p_ref
->get_id();
2254 // the reference contains a module name
2255 if (r_modid
->get_name() != modid
->get_name()) {
2256 // the reference points to another module
2257 bool has_impmod_with_name
= false;
2258 Common::Assignment
* result_ass
= NULL
;
2259 for (size_t i
= 0, num
= imp
->get_imports_size(); i
< num
; ++i
) {
2260 const ImpMod
* im
= imp
->get_impmod(i
);
2261 const Identifier
& im_id
= im
->get_modid();
2262 const string
& im_name
= im_id
.get_name();
2263 if (r_modid
->get_name() == im_name
) {
2264 has_impmod_with_name
= true;
2265 vector
<ImpMod
> tempusedImpMods
;
2266 ReferenceChain
* referencechain
= new ReferenceChain(this, "NEW IMPORT REFERNCECHAIN");
2267 Common::Assignment
*t_ass
= im
->get_imported_def(*modid
, *r_id
, p_ref
, referencechain
, tempusedImpMods
);
2268 referencechain
->reset();
2269 delete referencechain
;
2271 if (t_ass
!= NULL
) {
2272 Ttcn::Module
*ttcn_m
= static_cast<Ttcn::Module
*>(im
->get_mod());
2273 if (!ttcn_m
->is_visible(*modid
, t_ass
->get_visibility())) {
2277 if (t_ass
!= NULL
) {
2278 if (result_ass
== NULL
) {
2280 } else if(result_ass
!= t_ass
) {
2282 "It is not possible to resolve the reference unambiguously"
2283 ", as it can be resolved to `%s' and to `%s'",
2284 result_ass
->get_fullname().c_str(), t_ass
->get_fullname().c_str());
2288 tempusedImpMods
.clear();
2291 if (result_ass
) return result_ass
;
2293 if (has_impmod_with_name
) {
2294 p_ref
->error("There is no definition with name `%s' visible from "
2295 "module `%s'", r_id
->get_dispname().c_str(),
2296 r_modid
->get_dispname().c_str());
2298 if (modules
->has_mod_withId(*r_modid
)) {
2299 Common::Module
*m
= modules
->get_mod_byId(*r_modid
);
2300 if (m
->get_asss()->has_ass_withId(*r_id
)) {
2301 p_ref
->error("Definition with name `%s' is not imported from "
2302 "module `%s'", r_id
->get_dispname().c_str(),
2303 r_modid
->get_dispname().c_str());
2305 p_ref
->error("There is no definition with name `%s' in "
2306 "module `%s'", r_id
->get_dispname().c_str(),
2307 r_modid
->get_dispname().c_str());
2310 p_ref
->error("There is no module with name `%s'",
2311 r_modid
->get_dispname().c_str());
2316 // the reference points to the own module
2317 if (asss
->has_local_ass_withId(*r_id
)) {
2318 return asss
->get_local_ass_byId(*r_id
);
2320 p_ref
->error("There is no definition with name `%s' in "
2321 "module `%s'", r_id
->get_dispname().c_str(),
2322 r_modid
->get_dispname().c_str());
2326 // no module name is given in the reference
2327 if (asss
->has_local_ass_withId(*r_id
)) {
2328 return asss
->get_local_ass_byId(*r_id
);
2330 // the reference was not found locally -> look at the import list
2331 Common::Assignment
*t_result
= NULL
, *t_ass
= NULL
;
2332 for (size_t i
= 0, num
= imp
->get_imports_size(); i
< num
; ++i
) {
2333 const ImpMod
* im
= imp
->get_impmod(i
);
2335 vector
<ImpMod
> tempusedImpMods
;
2336 ReferenceChain
* referencechain
= new ReferenceChain(this, "NEW IMPORT REFERNCECHAIN");
2337 t_ass
= im
->get_imported_def(*modid
, *r_id
, p_ref
, referencechain
, tempusedImpMods
);
2338 referencechain
->reset();
2340 delete referencechain
;
2341 if (t_ass
!= NULL
) {
2342 Ttcn::Module
*ttcn_m
= static_cast<Ttcn::Module
*>(im
->get_mod());
2343 if (!ttcn_m
->is_visible(*modid
, t_ass
->get_visibility())) {
2347 if (t_ass
!= NULL
) {
2348 if (t_result
== NULL
) {
2350 } else if(t_result
!= t_ass
) {
2352 "It is not possible to resolve the reference unambiguously"
2353 ", as it can be resolved to `%s' and to `%s'",
2354 t_result
->get_fullname().c_str(), t_ass
->get_fullname().c_str());
2358 tempusedImpMods
.clear();
2361 if (t_result
) return t_result
;
2363 p_ref
->error("There is no local or imported definition with name `%s'"
2364 ,r_id
->get_dispname().c_str());
2370 bool Module::is_valid_moduleid(const Identifier
& p_id
)
2372 // The identifier represents the current module
2373 if (p_id
.get_name() == modid
->get_name()) return true;
2374 // The identifier represents a module imported in the current module
2375 if(imp
->has_impmod_withId(p_id
)) return true;
2379 Common::Assignments
*Module::get_asss()
2384 bool Module::exports_sym(const Identifier
&)
2386 FATAL_ERROR("Ttcn::Module::exports_sym()");
2390 Type
*Module::get_address_type()
2392 Identifier
address_id(Identifier::ID_TTCN
, string("address"));
2393 // return NULL if address type is not defined
2394 if (!asss
->has_local_ass_withId(address_id
)) return 0;
2395 Common::Assignment
*t_ass
= asss
->get_local_ass_byId(address_id
);
2396 if (t_ass
->get_asstype() != Common::Assignment::A_TYPE
)
2397 FATAL_ERROR("Module::get_address_type(): address is not a type");
2398 return t_ass
->get_Type();
2401 void Module::chk_imp(ReferenceChain
& refch
, vector
<Common::Module
>& moduleStack
)
2403 if (imp_checked
) return;
2404 const string
& module_name
= modid
->get_dispname();
2406 Error_Context backup
;
2407 Error_Context
cntxt(this, "In TTCN-3 module `%s'", module_name
.c_str());
2408 imp
->chk_imp(refch
, moduleStack
);
2411 collect_visible_mods();
2416 DEBUG(1, "Checking TTCN-3 module `%s'", modid
->get_dispname().c_str());
2417 Error_Context
cntxt(this, "In TTCN-3 module `%s'",
2418 modid
->get_dispname().c_str());
2419 if (w_attrib_path
) {
2420 w_attrib_path
->chk_global_attrib();
2421 w_attrib_path
->chk_no_qualif();
2423 // Check "extension" attributes in the module's "with" statement
2424 MultiWithAttrib
*multi
= w_attrib_path
->get_with_attr();
2425 if (multi
) for (size_t i
= 0; i
< multi
->get_nof_elements(); ++i
) {
2426 const SingleWithAttrib
*single
= multi
->get_element(i
);
2427 if (single
->get_attribKeyword() != SingleWithAttrib::AT_EXTENSION
) continue;
2428 // Parse the extension attribute
2429 // We circumvent parse_extattributes() in coding_attrib_p.y because
2430 // it processes all attributes in the "with" statement and
2431 // doesn't allow the removal on a case-by-case basis.
2433 init_coding_attrib_lex(single
->get_attribSpec());
2434 int result
= coding_attrib_parse();// 0=OK, 1=error, 2=out of memory
2435 cleanup_coding_attrib_lex();
2442 const size_t num_parsed
= extatrs
->size();
2443 for (size_t a
= 0; a
< num_parsed
; ++a
) {
2444 Ttcn::ExtensionAttribute
& ex
= extatrs
->get(0);
2446 switch (ex
.get_type()) {
2447 case Ttcn::ExtensionAttribute::VERSION_TEMPLATE
:
2448 case Ttcn::ExtensionAttribute::VERSION
: {
2449 char* act_product_number
;
2450 unsigned int act_suffix
, act_rel
, act_patch
, act_build
;
2452 (void)ex
.get_id(act_product_number
, act_suffix
, act_rel
, act_patch
, act_build
, extra_junk
);
2454 if (release
!= UINT_MAX
) {
2455 ex
.error("Duplicate 'version' attribute");
2458 product_number
= mcopystr(act_product_number
);
2459 suffix
= act_suffix
;
2463 extra
= mcopystr(extra_junk
);
2465 // Avoid propagating the attribute needlessly
2466 multi
->delete_element(i
--);
2470 case Ttcn::ExtensionAttribute::REQUIRES
: {
2471 // Imports have already been checked
2472 char* exp_product_number
;
2473 unsigned int exp_suffix
, exp_rel
, exp_patch
, exp_build
;
2475 Common::Identifier
*req_id
= ex
.get_id(exp_product_number
,
2476 exp_suffix
, exp_rel
, exp_patch
, exp_build
, exp_extra
);
2478 if (imp
->has_impmod_withId(*req_id
)) {
2479 Common::Module
* m
= modules
->get_mod_byId(*req_id
);
2480 if (m
->product_number
== NULL
&& exp_product_number
!= NULL
) {
2481 ex
.error("Module '%s' requires module '%s' of product %s"
2482 ", but it is not specified",
2483 this->modid
->get_dispname().c_str(), req_id
->get_dispname().c_str(),
2484 exp_product_number
);
2485 multi
->delete_element(i
--);
2488 } else if (exp_product_number
== NULL
&&
2489 m
->product_number
!= NULL
&& strcmp(m
->product_number
, "") > 0){
2490 ex
.warning("Module '%s' requires module '%s' of any product"
2491 ", while it specifies '%s'",
2492 this->modid
->get_dispname().c_str(),
2493 req_id
->get_dispname().c_str(), m
->product_number
);
2494 } else if (m
->product_number
!= NULL
&& exp_product_number
!= NULL
2495 && 0 != strcmp(m
->product_number
, exp_product_number
)) {
2496 char *req_product_identifier
=
2497 get_product_identifier(exp_product_number
,
2498 exp_suffix
, exp_rel
, exp_patch
, exp_build
);
2499 char *mod_product_identifier
=
2500 get_product_identifier(m
->product_number
,
2501 m
->suffix
, m
->release
, m
->patch
, m
->build
);
2503 ex
.error("Module '%s' requires version %s of module"
2504 " '%s', but only %s is available",
2505 this->modid
->get_dispname().c_str(), req_product_identifier
,
2506 req_id
->get_dispname().c_str(), mod_product_identifier
);
2507 Free(req_product_identifier
);
2508 Free(mod_product_identifier
);
2509 multi
->delete_element(i
--);
2513 // different suffixes are always incompatible
2514 // unless the special version number is used
2515 if (m
->suffix
!= exp_suffix
&& (m
->suffix
!= UINT_MAX
)) {
2516 char *req_product_identifier
=
2517 get_product_identifier(exp_product_number
,exp_suffix
, exp_rel
, exp_patch
, exp_build
);
2518 char *mod_product_identifier
=
2519 get_product_identifier(m
->product_number
,
2520 m
->suffix
, m
->release
, m
->patch
, m
->build
);
2522 ex
.error("Module '%s' requires version %s of module"
2523 " '%s', but only %s is available",
2524 this->modid
->get_dispname().c_str(), req_product_identifier
,
2525 req_id
->get_dispname().c_str(), mod_product_identifier
);
2526 Free(req_product_identifier
);
2527 Free(mod_product_identifier
);
2528 multi
->delete_element(i
--);
2532 if ( m
->release
< exp_rel
2533 ||(m
->release
== exp_rel
&& m
->patch
< exp_patch
)
2534 ||(m
->patch
== exp_patch
&& m
->build
< exp_build
)) {
2535 char *mod_bld_str
= buildstr(m
->build
);
2536 char *exp_bld_str
= buildstr(exp_build
);
2537 if (mod_bld_str
==0 || exp_bld_str
==0) FATAL_ERROR(
2538 "Ttcn::Module::chk() invalid build number");
2539 ex
.error("Module '%s' requires version R%u%c%s of module"
2540 " '%s', but only R%u%c%s is available",
2541 this->modid
->get_dispname().c_str(),
2542 exp_rel
, eri(exp_patch
), exp_bld_str
,
2543 req_id
->get_dispname().c_str(),
2544 m
->release
, eri(m
->patch
), mod_bld_str
);
2549 single
->error("No imported module named '%s'",
2550 req_id
->get_dispname().c_str());
2552 multi
->delete_element(i
--);
2556 case Ttcn::ExtensionAttribute::REQ_TITAN
: {
2557 char* exp_product_number
;
2558 unsigned int exp_suffix
, exp_minor
, exp_patch
, exp_build
;
2560 (void)ex
.get_id(exp_product_number
, exp_suffix
, exp_minor
, exp_patch
, exp_build
, exp_extra
);
2561 if (exp_product_number
!= NULL
&& strcmp(exp_product_number
,"CRL 113 200") != 0) {
2562 ex
.error("This module needs to be compiled with TITAN, but "
2563 " product number %s is not TITAN"
2564 , exp_product_number
);
2566 if (0 == exp_suffix
) {
2567 exp_suffix
= 1; // previous version number format did not list the suffix part
2569 // TTCN3_MAJOR is always 1
2570 int expected_version
= exp_suffix
* 1000000
2571 + exp_minor
* 10000 + exp_patch
* 100 + exp_build
;
2572 if (expected_version
> TTCN3_VERSION_MONOTONE
) {
2573 char *exp_product_identifier
=
2574 get_product_identifier(exp_product_number
, exp_suffix
, exp_minor
, exp_patch
, exp_build
);
2575 ex
.error("This module needs to be compiled with TITAN version"
2576 " %s or higher; version %s detected"
2577 , exp_product_identifier
, PRODUCT_NUMBER
);
2578 Free(exp_product_identifier
);
2580 multi
->delete_element(i
--);
2583 case Ttcn::ExtensionAttribute::PRINTING
: {
2584 ex
.error("Attribute 'printing' not allowed at module level");
2585 multi
->delete_element(i
--);
2591 // Let everything else propagate into the module.
2592 // Extension attributes in the module's "with" statement
2593 // may be impractical, but not outright erroneous.
2604 if (controlpart
) controlpart
->chk();
2605 if (control_ns
&& !*control_ns
) { // set but empty
2606 error("Invalid URI value for control namespace");
2608 if (control_ns_prefix
&& !*control_ns_prefix
) { // set but empty
2609 error("Empty NCName for the control namespace prefix is not allowed");
2611 // TODO proper URI and NCName validation
2614 void Module::chk_friends()
2616 map
<string
, FriendMod
> friends_m
;
2618 for(size_t i
= 0; i
< friendmods_v
.size(); i
++)
2620 FriendMod
* temp_friend
= friendmods_v
[i
];
2621 const Identifier
& friend_id
= temp_friend
->get_modid();
2622 const string
& friend_name
= friend_id
.get_name();
2623 if(friends_m
.has_key(friend_name
))
2625 temp_friend
->error("Duplicate friend module with name `%s'",
2626 friend_id
.get_dispname().c_str());
2627 friends_m
[friend_name
]->note("Friend module `%s' is already defined here",
2628 friend_id
.get_dispname().c_str());
2630 friends_m
.add(friend_name
, temp_friend
);
2633 friendmods_v
[i
]->chk();
2640 void Module::chk_groups()
2642 map
<string
,Common::Assignment
> ass_m
;
2644 for(size_t i
= 0; i
< asss
->get_nof_asss(); i
++)
2646 Common::Assignment
*temp_ass
= asss
->get_ass_byIndex(i
);
2647 if(!temp_ass
->get_parent_group())
2649 const string
& ass_name
= temp_ass
->get_id().get_name();
2650 if (!ass_m
.has_key(ass_name
)) ass_m
.add(ass_name
, temp_ass
);
2654 for(size_t i
= 0; i
< group_v
.size(); i
++)
2656 const Group
* group
= group_v
[i
];
2657 const Identifier
& group_id
= group
->get_id();
2658 const string
& group_name
= group_id
.get_name();
2659 if(ass_m
.has_key(group_name
))
2661 group
->error("Group name `%s' clashes with a definition",
2662 group_id
.get_dispname().c_str());
2663 ass_m
[group_name
]->note("Definition of `%s' is here",
2664 group_id
.get_dispname().c_str());
2666 if(group_m
.has_key(group_name
))
2668 group
->error("Duplicate group with name `%s'",
2669 group_id
.get_dispname().c_str());
2670 group_m
[group_name
]->note("Group `%s' is already defined here",
2671 group_id
.get_dispname().c_str());
2673 group_m
.add(group_name
,group_v
[i
]);
2679 for(size_t i
= 0; i
< group_v
.size(); i
++)
2685 void Module::get_imported_mods(module_set_t
& p_imported_mods
)
2687 imp
->get_imported_mods(p_imported_mods
);
2690 void Module::generate_code_internal(CodeGenHelper
& cgh
) {
2691 imp
->generate_code(cgh
);
2692 asss
->generate_code(cgh
);
2694 controlpart
->generate_code(cgh
.get_outputstruct(modid
->get_ttcnname()), this);
2697 RunsOnScope
*Module::get_runs_on_scope(Type
*comptype
)
2699 RunsOnScope
*ret_val
= new RunsOnScope(comptype
);
2700 runs_on_scopes
.add(ret_val
);
2701 ret_val
->set_parent_scope(asss
);
2702 ret_val
->chk_uniq();
2707 void Module::dump(unsigned level
) const
2709 DEBUG(level
, "TTCN-3 module: %s", modid
->get_dispname().c_str());
2711 if(imp
) imp
->dump(level
);
2712 if(asss
) asss
->dump(level
);
2714 for(size_t i
= 0; i
< group_v
.size(); i
++)
2716 group_v
[i
]->dump(level
);
2719 if(controlpart
) controlpart
->dump(level
);
2721 if (w_attrib_path
) {
2722 MultiWithAttrib
*attrib
= w_attrib_path
->get_with_attr();
2724 DEBUG(level
, "Module Attributes:");
2725 attrib
->dump(level
+ 1);
2730 void Module::set_language_spec(const char *p_language_spec
)
2732 if (language_spec
) FATAL_ERROR("Module::set_language_spec()");
2733 if (p_language_spec
) language_spec
= new string(p_language_spec
);
2736 void Module::add_ass(Definition
* p_ass
)
2738 asss
->add_ass(p_ass
);
2741 void Module::add_impmod(ImpMod
*p_impmod
)
2743 imp
->add_impmod(p_impmod
);
2746 void Module::add_controlpart(ControlPart
* p_controlpart
)
2748 if (!p_controlpart
|| controlpart
) FATAL_ERROR("Module::add_controlpart()");
2749 controlpart
= p_controlpart
;
2750 controlpart
->set_my_scope(asss
);
2753 void Module::set_with_attr(MultiWithAttrib
* p_attrib
)
2755 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
2756 w_attrib_path
->set_with_attr(p_attrib
);
2759 WithAttribPath
* Module::get_attrib_path()
2761 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
2762 return w_attrib_path
;
2765 void Module::set_parent_path(WithAttribPath
* p_path
)
2767 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
2768 w_attrib_path
->set_parent(p_path
);
2771 bool Module::is_visible(const Identifier
& id
, visibility_t visibility
){
2773 if (visibility
== PUBLIC
) {
2776 if (visibility
== FRIEND
) {
2777 for (size_t i
= 0; i
< friendmods_v
.size(); i
++) {
2778 if (friendmods_v
[i
]->get_modid() == id
) {
2786 void Module::generate_json_schema(JSON_Tokenizer
& json
, map
<Type
*, JSON_Tokenizer
>& json_refs
)
2788 // add a new property for this module
2789 json
.put_next_token(JSON_TOKEN_NAME
, modid
->get_ttcnname().c_str());
2791 // add type definitions into an object
2792 json
.put_next_token(JSON_TOKEN_OBJECT_START
);
2794 // cycle through each type, generate schema segment and reference when needed
2795 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
2796 Def_Type
* def
= dynamic_cast<Def_Type
*>(asss
->get_ass_byIndex(i
));
2798 Type
* t
= def
->get_Type();
2799 if (t
->has_encoding(Type::CT_JSON
)) {
2800 // insert type's schema segment
2801 t
->generate_json_schema(json
, false, false);
2803 if (json_refs_for_all_types
&& !json_refs
.has_key(t
)) {
2804 // create JSON schema reference for the type
2805 JSON_Tokenizer
* json_ref
= new JSON_Tokenizer
;
2806 json_refs
.add(t
, json_ref
);
2807 t
->generate_json_schema_ref(*json_ref
);
2813 // end of type definitions
2814 json
.put_next_token(JSON_TOKEN_OBJECT_END
);
2816 // insert function data
2817 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
2818 Def_ExtFunction
* def
= dynamic_cast<Def_ExtFunction
*>(asss
->get_ass_byIndex(i
));
2820 def
->generate_json_schema_ref(json_refs
);
2825 void Module::generate_debugger_init(output_struct
* output
)
2827 static boolean first
= TRUE
;
2828 // create the initializer function
2829 output
->source
.global_vars
= mputprintf(output
->source
.global_vars
,
2830 "\n/* Initializing the TTCN-3 debugger */\n"
2831 "void init_ttcn3_debugger()\n"
2833 "%s", first
? " ttcn3_debugger.activate();\n" : "");
2836 // initialize global scope and variables (including imported variables)
2837 char* str_glob
= generate_debugger_global_vars(NULL
, this);
2838 for (int i
= 0; i
< imp
->get_imports_size(); ++i
) {
2839 str_glob
= imp
->get_impmod(i
)->get_mod()->generate_debugger_global_vars(str_glob
, this);
2841 if (str_glob
!= NULL
) {
2842 // only add the global scope if it actually has variables
2843 output
->source
.global_vars
= mputprintf(output
->source
.global_vars
,
2844 " /* global variables */\n"
2845 " TTCN3_Debug_Scope* global_scope = ttcn3_debugger.add_global_scope(\"%s\");\n"
2847 get_modid().get_dispname().c_str(), str_glob
);
2851 // initialize components' scopes and their variables
2852 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
2853 Def_Type
* def
= dynamic_cast<Def_Type
*>(asss
->get_ass_byIndex(i
));
2855 Type
* comp_type
= def
->get_Type();
2856 if (comp_type
->get_typetype() == Type::T_COMPONENT
) {
2857 char* str_comp
= NULL
;
2858 ComponentTypeBody
* comp_body
= comp_type
->get_CompBody();
2859 for (size_t j
= 0; j
< comp_body
->get_nof_asss(); ++j
) {
2860 str_comp
= generate_code_debugger_add_var(str_comp
, comp_body
->get_ass_byIndex(j
),
2861 this, comp_type
->get_dispname().c_str());
2863 if (str_comp
!= NULL
) {
2864 // only add the component if it actually has variables
2865 output
->source
.global_vars
= mputprintf(output
->source
.global_vars
,
2866 " /* variables of component %s */\n"
2867 " TTCN3_Debug_Scope* %s_scope = ttcn3_debugger.add_component_scope(\"%s\");\n"
2869 , comp_type
->get_dispname().c_str(), comp_type
->get_dispname().c_str()
2870 , comp_type
->get_dispname().c_str(), str_comp
);
2877 // close the initializer function
2878 output
->source
.global_vars
= mputstr(output
->source
.global_vars
, "}\n");
2881 char* Module::generate_debugger_global_vars(char* str
, Common::Module
* current_mod
)
2883 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
2884 Common::Assignment
* ass
= asss
->get_ass_byIndex(i
);
2885 switch (ass
->get_asstype()) {
2886 case Common::Assignment::A_TEMPLATE
:
2887 if (ass
->get_FormalParList() != NULL
) {
2888 // don't add parameterized templates, since they are functions in C++
2891 // else fall through
2892 case Common::Assignment::A_CONST
:
2893 case Common::Assignment::A_MODULEPAR
:
2894 case Common::Assignment::A_MODULEPAR_TEMP
:
2895 str
= generate_code_debugger_add_var(str
, ass
, current_mod
, "global");
2897 case Common::Assignment::A_EXT_CONST
: {
2898 Def_ExtConst
* def
= dynamic_cast<Def_ExtConst
*>(ass
);
2900 FATAL_ERROR("Module::generate_debugger_global_vars");
2902 if (def
->is_used()) {
2903 str
= generate_code_debugger_add_var(str
, ass
, current_mod
, "global");
2913 void Module::generate_debugger_functions(output_struct
*output
)
2915 char* print_str
= NULL
;
2916 char* overwrite_str
= NULL
;
2917 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
2918 Def_Type
* def
= dynamic_cast<Def_Type
*>(asss
->get_ass_byIndex(i
));
2920 Type
* t
= def
->get_Type();
2921 if (!t
->is_ref() && t
->get_typetype() != Type::T_COMPONENT
) {
2922 // don't generate code for subtypes
2923 if (t
->get_typetype() != Type::T_SIGNATURE
) {
2924 print_str
= mputprintf(print_str
,
2925 " %sif (!strcmp(p_var.type_name, \"%s\")) {\n"
2926 " ((const %s*)ptr)->log();\n"
2928 , (print_str
!= NULL
) ? "else " : ""
2929 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str());
2930 if (t
->get_typetype() != Type::T_PORT
) {
2931 overwrite_str
= mputprintf(overwrite_str
,
2932 " %sif (!strcmp(p_var.type_name, \"%s\")) {\n"
2933 " ((%s*)p_var.value)->set_param(p_new_value);\n"
2935 , (overwrite_str
!= NULL
) ? "else " : ""
2936 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str());
2939 if (t
->get_typetype() != Type::T_PORT
) {
2940 print_str
= mputprintf(print_str
,
2941 " %sif (!strcmp(p_var.type_name, \"%s template\")) {\n"
2942 " ((const %s_template*)ptr)->log();\n"
2944 , (print_str
!= NULL
) ? "else " : ""
2945 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str());
2946 if (t
->get_typetype() != Type::T_SIGNATURE
) {
2947 overwrite_str
= mputprintf(overwrite_str
,
2948 " %sif (!strcmp(p_var.type_name, \"%s template\")) {\n"
2949 " ((%s_template*)p_var.value)->set_param(p_new_value);\n"
2951 , (overwrite_str
!= NULL
) ? "else " : ""
2952 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str());
2958 if (print_str
!= NULL
) {
2959 // don't generate an empty printing function
2960 output
->header
.class_defs
= mputprintf(output
->header
.class_defs
,
2961 "/* Debugger printing and overwriting functions for types declared in this module */\n\n"
2962 "extern CHARSTRING print_var_%s(const TTCN3_Debugger::variable_t& p_var);\n",
2963 get_modid().get_ttcnname().c_str());
2964 output
->source
.global_vars
= mputprintf(output
->source
.global_vars
,
2965 "\n/* Debugger printing function for types declared in this module */\n"
2966 "CHARSTRING print_var_%s(const TTCN3_Debugger::variable_t& p_var)\n"
2968 " const void* ptr = p_var.set_function != NULL ? p_var.value : p_var.cvalue;\n"
2969 " TTCN_Logger::begin_event_log2str();\n"
2972 " TTCN_Logger::log_event_str(\"<unrecognized value or template>\");\n"
2974 " return TTCN_Logger::end_event_log2str();\n"
2975 "}\n", get_modid().get_ttcnname().c_str(), print_str
);
2977 if (overwrite_str
!= NULL
) {
2978 // don't generate an empty overwriting function
2979 output
->header
.class_defs
= mputprintf(output
->header
.class_defs
,
2980 "extern boolean set_var_%s(TTCN3_Debugger::variable_t& p_var, Module_Param& p_new_value);\n",
2981 get_modid().get_ttcnname().c_str());
2982 output
->source
.global_vars
= mputprintf(output
->source
.global_vars
,
2983 "\n/* Debugger overwriting function for types declared in this module */\n"
2984 "boolean set_var_%s(TTCN3_Debugger::variable_t& p_var, Module_Param& p_new_value)\n"
2991 "}\n", get_modid().get_ttcnname().c_str(), overwrite_str
);
2995 // =================================
2997 // =================================
2999 string
Definition::get_genname() const
3001 if (!genname
.empty()) return genname
;
3002 else return id
->get_name();
3005 namedbool
Definition::has_implicit_omit_attr() const {
3006 if (w_attrib_path
) {
3007 const vector
<SingleWithAttrib
>& real_attribs
=
3008 w_attrib_path
->get_real_attrib();
3009 for (size_t in
= real_attribs
.size(); in
> 0; in
--) {
3010 if (SingleWithAttrib::AT_OPTIONAL
==
3011 real_attribs
[in
-1]->get_attribKeyword()) {
3012 if ("implicit omit" ==
3013 real_attribs
[in
-1]->get_attribSpec().get_spec()) {
3014 return IMPLICIT_OMIT
;
3015 } else if ("explicit omit" ==
3016 real_attribs
[in
-1]->get_attribSpec().get_spec()) {
3017 return NOT_IMPLICIT_OMIT
;
3018 } // error reporting for other values is in chk_global_attrib
3022 return NOT_IMPLICIT_OMIT
;
3025 Definition::~Definition()
3027 delete w_attrib_path
;
3028 delete erroneous_attrs
;
3031 void Definition::set_fullname(const string
& p_fullname
)
3033 Common::Assignment::set_fullname(p_fullname
);
3034 if (w_attrib_path
) w_attrib_path
->set_fullname(p_fullname
+ ".<attribpath>");
3035 if (erroneous_attrs
) erroneous_attrs
->set_fullname(p_fullname
+".<erroneous_attributes>");
3038 bool Definition::is_local() const
3040 if (!my_scope
) FATAL_ERROR("Definition::is_local()");
3041 for (Scope
*scope
= my_scope
; scope
; scope
= scope
->get_parent_scope()) {
3042 if (dynamic_cast<StatementBlock
*>(scope
)) return true;
3047 bool Definition::chk_identical(Definition
*)
3049 FATAL_ERROR("Definition::chk_identical()");
3053 void Definition::chk_erroneous_attr()
3055 if (!w_attrib_path
) return;
3056 const Ttcn::MultiWithAttrib
* attribs
= w_attrib_path
->get_local_attrib();
3057 if (!attribs
) return;
3058 for (size_t i
= 0; i
< attribs
->get_nof_elements(); i
++) {
3059 const Ttcn::SingleWithAttrib
* act_attr
= attribs
->get_element(i
);
3060 if (act_attr
->get_attribKeyword()==Ttcn::SingleWithAttrib::AT_ERRONEOUS
) {
3061 if (!use_runtime_2
) {
3062 error("`erroneous' attributes can be used only with the Function Test Runtime");
3063 note("If you need negative testing use the -R flag when generating the makefile");
3066 size_t nof_qualifiers
= act_attr
->get_attribQualifiers() ? act_attr
->get_attribQualifiers()->get_nof_qualifiers() : 0;
3067 dynamic_array
<Type
*> refd_type_array(nof_qualifiers
); // only the qualifiers pointing to existing fields will be added to erroneous_attrs objects
3068 if (nof_qualifiers
==0) {
3069 act_attr
->error("At least one qualifier must be specified for the `erroneous' attribute");
3071 // check if qualifiers point to existing fields
3072 for (size_t qi
=0; qi
<nof_qualifiers
; qi
++) {
3073 Qualifier
* act_qual
= const_cast<Qualifier
*>(act_attr
->get_attribQualifiers()->get_qualifier(qi
));
3074 act_qual
->set_my_scope(get_my_scope());
3075 Type
* field_type
= get_Type()->get_field_type(act_qual
, Type::EXPECTED_CONSTANT
);
3077 dynamic_array
<size_t> subrefs_array
;
3078 dynamic_array
<Type
*> type_array
;
3079 bool valid_indexes
= get_Type()->get_subrefs_as_array(act_qual
, subrefs_array
, type_array
);
3080 if (!valid_indexes
) field_type
= NULL
;
3081 if (act_qual
->refers_to_string_element()) {
3082 act_qual
->error("Reference to a string element cannot be used in this context");
3086 refd_type_array
.add(field_type
);
3089 // parse the attr. spec.
3090 ErroneousAttributeSpec
* err_attr_spec
= ttcn3_parse_erroneous_attr_spec_string(
3091 act_attr
->get_attribSpec().get_spec().c_str(), act_attr
->get_attribSpec());
3092 if (err_attr_spec
) {
3093 if (!erroneous_attrs
) erroneous_attrs
= new ErroneousAttributes(get_Type());
3094 // attr.spec will be owned by erroneous_attrs object
3095 erroneous_attrs
->add_spec(err_attr_spec
);
3096 err_attr_spec
->set_fullname(get_fullname());
3097 err_attr_spec
->set_my_scope(get_my_scope());
3098 err_attr_spec
->chk();
3099 // create qualifier - err.attr.spec. pairs
3100 for (size_t qi
=0; qi
<nof_qualifiers
; qi
++) {
3101 if (refd_type_array
[qi
] && (err_attr_spec
->get_indicator()!=ErroneousAttributeSpec::I_INVALID
)) {
3102 erroneous_attrs
->add_pair(act_attr
->get_attribQualifiers()->get_qualifier(qi
), err_attr_spec
);
3108 if (erroneous_attrs
) erroneous_attrs
->chk();
3111 char* Definition::generate_code_str(char *str
)
3113 FATAL_ERROR("Definition::generate_code_str()");
3117 void Definition::ilt_generate_code(ILT
*)
3119 FATAL_ERROR("Definition::ilt_generate_code()");
3122 char *Definition::generate_code_init_comp(char *str
, Definition
*)
3124 FATAL_ERROR("Definition::generate_code_init_comp()");
3128 void Definition::set_with_attr(MultiWithAttrib
* p_attrib
)
3130 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
3131 w_attrib_path
->set_with_attr(p_attrib
);
3134 WithAttribPath
* Definition::get_attrib_path()
3136 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
3137 return w_attrib_path
;
3140 void Definition::set_parent_path(WithAttribPath
* p_path
)
3142 if (!w_attrib_path
) w_attrib_path
= new WithAttribPath();
3143 w_attrib_path
->set_parent(p_path
);
3146 void Definition::set_parent_group(Group
* p_group
)
3148 if(parentgroup
) // there would be a leak!
3149 FATAL_ERROR("Definition::set_parent_group()");
3150 parentgroup
= p_group
;
3153 Group
* Definition::get_parent_group()
3158 void Definition::dump_internal(unsigned level
) const
3160 DEBUG(level
, "Move along, nothing to see here");
3163 void Definition::dump(unsigned level
) const
3165 dump_internal(level
);
3166 if (w_attrib_path
) {
3167 MultiWithAttrib
*attrib
= w_attrib_path
->get_with_attr();
3169 DEBUG(level
+ 1, "Definition Attributes:");
3170 attrib
->dump(level
+ 2);
3173 if (erroneous_attrs
) erroneous_attrs
->dump(level
+1);
3176 // =================================
3178 // =================================
3180 Def_Type::Def_Type(Identifier
*p_id
, Type
*p_type
)
3181 : Definition(A_TYPE
, p_id
), type(p_type
)
3183 if(!p_type
) FATAL_ERROR("Ttcn::Def_Type::Def_Type()");
3184 type
->set_ownertype(Type::OT_TYPE_DEF
, this);
3187 Def_Type::~Def_Type()
3192 Def_Type
*Def_Type::clone() const
3194 FATAL_ERROR("Def_Type::clone");
3197 void Def_Type::set_fullname(const string
& p_fullname
)
3199 Definition::set_fullname(p_fullname
);
3200 type
->set_fullname(p_fullname
);
3203 void Def_Type::set_my_scope(Scope
*p_scope
)
3205 bridgeScope
.set_parent_scope(p_scope
);
3206 bridgeScope
.set_scopeMacro_name(id
->get_dispname());
3208 Definition::set_my_scope(&bridgeScope
);
3209 type
->set_my_scope(&bridgeScope
);
3213 Setting
*Def_Type::get_Setting()
3218 Type
*Def_Type::get_Type()
3224 void Def_Type::chk()
3226 if (checked
) return;
3228 Error_Context
cntxt(this, "In %s definition `%s'",
3229 type
->get_typetype() == Type::T_SIGNATURE
? "signature" : "type",
3230 id
->get_dispname().c_str());
3231 type
->set_genname(get_genname());
3232 if (!semantic_check_only
&& type
->get_typetype() == Type::T_COMPONENT
) {
3233 // the prefix of embedded definitions must be set before the checking
3234 type
->get_CompBody()->set_genname(get_genname() + "_component_");
3237 while (w_attrib_path
) { // not a loop, but we can _break_ out of it
3238 w_attrib_path
->chk_global_attrib();
3239 w_attrib_path
->chk_no_qualif();
3240 if (type
->get_typetype() != Type::T_ANYTYPE
) break;
3241 // This is the anytype; it must be empty (we're about to add the fields)
3242 if (type
->get_nof_comps() > 0) FATAL_ERROR("Def_Type::chk");
3244 Ttcn::ExtensionAttributes
*extattrs
= parse_extattributes(w_attrib_path
);
3245 if (extattrs
== 0) break; // NULL means parsing error
3247 size_t num_atrs
= extattrs
->size();
3248 for (size_t k
= 0; k
< num_atrs
; ++k
) {
3249 ExtensionAttribute
&ea
= extattrs
->get(k
);
3250 switch (ea
.get_type()) {
3251 case ExtensionAttribute::ANYTYPELIST
: {
3252 Types
*anytypes
= ea
.get_types();
3253 // List of types to be converted into fields for the anytype.
3254 // Make sure scope is set on all types in the list.
3255 anytypes
->set_my_scope(get_my_scope());
3257 // Convert the list of types into field names for the anytype
3258 for (size_t i
=0; i
< anytypes
->get_nof_types(); ++i
) {
3259 Type
*t
= anytypes
->extract_type_byIndex(i
);
3260 // we are now the owner of the Type.
3261 if (t
->get_typetype()==Type::T_ERROR
) { // should we give up?
3267 const char* btn
= Type::get_typename_builtin(t
->get_typetype());
3271 else if (t
->get_typetype() == Type::T_REFD
) {
3272 // Extract the identifier
3273 Common::Reference
*ref
= t
->get_Reference();
3274 Ttcn::Reference
*tref
= dynamic_cast<Ttcn::Reference
*>(ref
);
3275 if (!tref
) FATAL_ERROR("Def_Type::chk, wrong kind of reference");
3276 const Common::Identifier
*modid
= tref
->get_modid();
3278 ea
.error("Qualified name '%s' cannot be added to the anytype",
3279 tref
->get_dispname().c_str());
3283 field_name
= tref
->get_id()->get_ttcnname();
3286 // Can't happen here
3287 FATAL_ERROR("Unexpected type %d", t
->get_typetype());
3290 const string
& at_field
= anytype_field(field_name
);
3291 Identifier
*field_id
= new Identifier(Identifier::ID_TTCN
, at_field
);
3292 CompField
*cf
= new CompField(field_id
, t
, false, 0);
3293 cf
->set_location(ea
);
3294 cf
->set_fullname(get_fullname());
3300 w_attrib_path
->get_with_attr()->error("Type def can only have anytype");
3306 break; // do not loop
3309 // Now we can check the type
3311 type
->chk_constructor_name(*id
);
3312 if (id
->get_ttcnname() == "address") type
->chk_address();
3313 ReferenceChain
refch(type
, "While checking embedded recursions");
3314 type
->chk_recursions(refch
);
3316 if (type
->get_typetype()==Type::T_FUNCTION
3317 ||type
->get_typetype()==Type::T_ALTSTEP
3318 ||type
->get_typetype()==Type::T_TESTCASE
) {
3319 // TR 922. This is a function/altstep/testcase reference.
3320 // Set this definition as the definition for the formal parameters.
3321 type
->get_fat_parameters()->set_my_def(this);
3325 void Def_Type::generate_code(output_struct
*target
, bool)
3327 type
->generate_code(target
);
3328 if (type
->get_typetype() == Type::T_COMPONENT
) {
3329 // the C++ equivalents of embedded component element definitions must be
3330 // generated from outside Type::generate_code() because the function can
3331 // call itself recursively and create invalid (overlapped) initializer
3333 type
->get_CompBody()->generate_code(target
);
3337 void Def_Type::generate_code(CodeGenHelper
& cgh
) {
3338 type
->generate_code(cgh
.get_outputstruct(get_Type()));
3339 if (type
->get_typetype() == Type::T_COMPONENT
) {
3340 // the C++ equivalents of embedded component element definitions must be
3341 // generated from outside Type::generate_code() because the function can
3342 // call itself recursively and create invalid (overlapped) initializer
3344 type
->get_CompBody()->generate_code(cgh
.get_current_outputstruct());
3346 cgh
.finalize_generation(get_Type());
3350 void Def_Type::dump_internal(unsigned level
) const
3352 DEBUG(level
, "Type def: %s @ %p", id
->get_dispname().c_str(), (const void*)this);
3353 type
->dump(level
+ 1);
3356 void Def_Type::set_with_attr(MultiWithAttrib
* p_attrib
)
3358 if (!w_attrib_path
) {
3359 w_attrib_path
= new WithAttribPath();
3360 type
->set_parent_path(w_attrib_path
);
3362 type
->set_with_attr(p_attrib
);
3365 WithAttribPath
* Def_Type::get_attrib_path()
3367 if (!w_attrib_path
) {
3368 w_attrib_path
= new WithAttribPath();
3369 type
->set_parent_path(w_attrib_path
);
3371 return w_attrib_path
;
3374 void Def_Type::set_parent_path(WithAttribPath
* p_path
)
3376 if (!w_attrib_path
) {
3377 w_attrib_path
= new WithAttribPath();
3378 type
->set_parent_path(w_attrib_path
);
3380 w_attrib_path
->set_parent(p_path
);
3383 // =================================
3385 // =================================
3387 Def_Const::Def_Const(Identifier
*p_id
, Type
*p_type
, Value
*p_value
)
3388 : Definition(A_CONST
, p_id
)
3390 if (!p_type
|| !p_value
) FATAL_ERROR("Ttcn::Def_Const::Def_Const()");
3392 type
->set_ownertype(Type::OT_CONST_DEF
, this);
3394 value_under_check
=false;
3397 Def_Const::~Def_Const()
3403 Def_Const
*Def_Const::clone() const
3405 FATAL_ERROR("Def_Const::clone");
3408 void Def_Const::set_fullname(const string
& p_fullname
)
3410 Definition::set_fullname(p_fullname
);
3411 type
->set_fullname(p_fullname
+ ".<type>");
3412 value
->set_fullname(p_fullname
);
3415 void Def_Const::set_my_scope(Scope
*p_scope
)
3417 Definition::set_my_scope(p_scope
);
3418 type
->set_my_scope(p_scope
);
3419 value
->set_my_scope(p_scope
);
3422 Setting
*Def_Const::get_Setting()
3427 Type
*Def_Const::get_Type()
3434 Value
*Def_Const::get_Value()
3440 void Def_Const::chk()
3443 if (value_under_check
) {
3444 error("Circular reference in constant definition `%s'",
3445 id
->get_dispname().c_str());
3446 value_under_check
= false; // only report the error once for this definition
3450 Error_Context
cntxt(this, "In constant definition `%s'",
3451 id
->get_dispname().c_str());
3452 type
->set_genname(_T_
, get_genname());
3454 value
->set_my_governor(type
);
3455 type
->chk_this_value_ref(value
);
3457 if (w_attrib_path
) {
3458 w_attrib_path
->chk_global_attrib(true);
3459 switch (type
->get_type_refd_last()->get_typetype_ttcn3()) {
3462 case Type::T_CHOICE_T
:
3463 // These types may have qualified attributes
3465 case Type::T_SEQOF
: case Type::T_SETOF
:
3468 w_attrib_path
->chk_no_qualif();
3472 Type
*t
= type
->get_type_refd_last();
3473 switch (t
->get_typetype()) {
3475 error("Constant cannot be defined for port type `%s'",
3476 t
->get_fullname().c_str());
3478 case Type::T_SIGNATURE
:
3479 error("Constant cannot be defined for signature `%s'",
3480 t
->get_fullname().c_str());
3483 value_under_check
= true;
3484 type
->chk_this_value(value
, 0, Type::EXPECTED_CONSTANT
, INCOMPLETE_ALLOWED
,
3485 OMIT_NOT_ALLOWED
, SUB_CHK
, has_implicit_omit_attr());
3486 value_under_check
= false;
3487 chk_erroneous_attr();
3488 if (erroneous_attrs
) value
->set_err_descr(erroneous_attrs
->get_err_descr());
3490 ReferenceChain
refch(type
, "While checking embedded recursions");
3491 value
->chk_recursions(refch
);
3495 if (!semantic_check_only
) {
3496 value
->set_genname_prefix("const_");
3497 value
->set_genname_recursive(get_genname());
3498 value
->set_code_section(GovernedSimple::CS_PRE_INIT
);
3502 bool Def_Const::chk_identical(Definition
*p_def
)
3506 if (p_def
->get_asstype() != A_CONST
) {
3507 const char *dispname_str
= id
->get_dispname().c_str();
3508 error("Local definition `%s' is a constant, but the definition "
3509 "inherited from component type `%s' is a %s", dispname_str
,
3510 p_def
->get_my_scope()->get_fullname().c_str(), p_def
->get_assname());
3511 p_def
->note("The inherited definition of `%s' is here", dispname_str
);
3514 Def_Const
*p_def_const
= dynamic_cast<Def_Const
*>(p_def
);
3515 if (!p_def_const
) FATAL_ERROR("Def_Const::chk_identical()");
3516 if (!type
->is_identical(p_def_const
->type
)) {
3517 const char *dispname_str
= id
->get_dispname().c_str();
3518 type
->error("Local constant `%s' has type `%s', but the constant "
3519 "inherited from component type `%s' has type `%s'", dispname_str
,
3520 type
->get_typename().c_str(),
3521 p_def_const
->get_my_scope()->get_fullname().c_str(),
3522 p_def_const
->type
->get_typename().c_str());
3523 p_def_const
->note("The inherited constant `%s' is here", dispname_str
);
3525 } else if (!(*value
== *p_def_const
->value
)) {
3526 const char *dispname_str
= id
->get_dispname().c_str();
3527 value
->error("Local constant `%s' and the constant inherited from "
3528 "component type `%s' have different values", dispname_str
,
3529 p_def_const
->get_my_scope()->get_fullname().c_str());
3530 p_def_const
->note("The inherited constant `%s' is here", dispname_str
);
3535 void Def_Const::generate_code(output_struct
*target
, bool)
3537 type
->generate_code(target
);
3539 Code::init_cdef(&cdef
);
3540 type
->generate_code_object(&cdef
, value
);
3541 cdef
.init
= update_location_object(cdef
.init
);
3542 cdef
.init
= value
->generate_code_init(cdef
.init
,
3543 value
->get_lhs_name().c_str());
3544 Code::merge_cdef(target
, &cdef
);
3545 Code::free_cdef(&cdef
);
3548 void Def_Const::generate_code(Common::CodeGenHelper
& cgh
) {
3549 // constant definitions always go to its containing module
3550 generate_code(cgh
.get_current_outputstruct());
3553 char *Def_Const::generate_code_str(char *str
)
3555 const string
& t_genname
= get_genname();
3556 const char *genname_str
= t_genname
.c_str();
3557 if (value
->has_single_expr()) {
3558 // the value can be represented by a single C++ expression
3559 // the object is initialized by the constructor
3560 str
= mputprintf(str
, "%s %s(%s);\n",
3561 type
->get_genname_value(my_scope
).c_str(), genname_str
,
3562 value
->get_single_expr().c_str());
3564 // use the default constructor
3565 str
= mputprintf(str
, "%s %s;\n",
3566 type
->get_genname_value(my_scope
).c_str(), genname_str
);
3567 // the value is assigned using subsequent statements
3568 str
= value
->generate_code_init(str
, genname_str
);
3570 if (debugger_active
) {
3571 str
= generate_code_debugger_add_var(str
, this);
3576 void Def_Const::ilt_generate_code(ILT
*ilt
)
3578 const string
& t_genname
= get_genname();
3579 const char *genname_str
= t_genname
.c_str();
3580 char*& def
=ilt
->get_out_def();
3581 char*& init
=ilt
->get_out_branches();
3582 def
= mputprintf(def
, "%s %s;\n", type
->get_genname_value(my_scope
).c_str(),
3584 init
= value
->generate_code_init(init
, genname_str
);
3587 char *Def_Const::generate_code_init_comp(char *str
, Definition
*)
3589 /* This function actually does nothing as \a this and \a base_defn are
3590 * exactly the same. */
3594 void Def_Const::dump_internal(unsigned level
) const
3596 DEBUG(level
, "Constant: %s @%p", id
->get_dispname().c_str(), (const void*)this);
3597 type
->dump(level
+ 1);
3598 value
->dump(level
+ 1);
3601 // =================================
3602 // ===== Def_ExtConst
3603 // =================================
3605 Def_ExtConst::Def_ExtConst(Identifier
*p_id
, Type
*p_type
)
3606 : Definition(A_EXT_CONST
, p_id
)
3608 if (!p_type
) FATAL_ERROR("Ttcn::Def_ExtConst::Def_ExtConst()");
3610 type
->set_ownertype(Type::OT_CONST_DEF
, this);
3611 usage_found
= false;
3614 Def_ExtConst::~Def_ExtConst()
3619 Def_ExtConst
*Def_ExtConst::clone() const
3621 FATAL_ERROR("Def_ExtConst::clone");
3624 void Def_ExtConst::set_fullname(const string
& p_fullname
)
3626 Definition::set_fullname(p_fullname
);
3627 type
->set_fullname(p_fullname
+ ".<type>");
3630 void Def_ExtConst::set_my_scope(Scope
*p_scope
)
3632 Definition::set_my_scope(p_scope
);
3633 type
->set_my_scope(p_scope
);
3636 Type
*Def_ExtConst::get_Type()
3642 void Def_ExtConst::chk()
3645 Error_Context
cntxt(this, "In external constant definition `%s'",
3646 id
->get_dispname().c_str());
3647 type
->set_genname(_T_
, get_genname());
3650 Type
*t
= type
->get_type_refd_last();
3651 switch (t
->get_typetype()) {
3653 error("External constant cannot be defined for port type `%s'",
3654 t
->get_fullname().c_str());
3656 case Type::T_SIGNATURE
:
3657 error("External constant cannot be defined for signature `%s'",
3658 t
->get_fullname().c_str());
3663 if (w_attrib_path
) {
3664 w_attrib_path
->chk_global_attrib();
3665 switch (type
->get_type_refd_last()->get_typetype()) {
3668 case Type::T_CHOICE_T
:
3669 // These types may have qualified attributes
3671 case Type::T_SEQOF
: case Type::T_SETOF
:
3674 w_attrib_path
->chk_no_qualif();
3680 void Def_ExtConst::generate_code(output_struct
*target
, bool)
3682 type
->generate_code(target
);
3683 target
->header
.global_vars
= mputprintf(target
->header
.global_vars
,
3684 "extern const %s& %s;\n", type
->get_genname_value(my_scope
).c_str(),
3685 get_genname().c_str());
3688 void Def_ExtConst::generate_code(Common::CodeGenHelper
& cgh
) {
3689 // constant definitions always go to its containing module
3690 generate_code(cgh
.get_current_outputstruct());
3693 void Def_ExtConst::dump_internal(unsigned level
) const
3695 DEBUG(level
, "External constant: %s @ %p", id
->get_dispname().c_str(), (const void*)this);
3696 type
->dump(level
+ 1);
3699 // =================================
3700 // ===== Def_Modulepar
3701 // =================================
3703 Def_Modulepar::Def_Modulepar(Identifier
*p_id
, Type
*p_type
, Value
*p_defval
)
3704 : Definition(A_MODULEPAR
, p_id
)
3706 if (!p_type
) FATAL_ERROR("Ttcn::Def_Modulepar::Def_Modulepar()");
3708 type
->set_ownertype(Type::OT_MODPAR_DEF
, this);
3709 def_value
= p_defval
;
3712 Def_Modulepar::~Def_Modulepar()
3718 Def_Modulepar
* Def_Modulepar::clone() const
3720 FATAL_ERROR("Def_Modulepar::clone");
3723 void Def_Modulepar::set_fullname(const string
& p_fullname
)
3725 Definition::set_fullname(p_fullname
);
3726 type
->set_fullname(p_fullname
+ ".<type>");
3727 if (def_value
) def_value
->set_fullname(p_fullname
+ ".<default_value>");
3730 void Def_Modulepar::set_my_scope(Scope
*p_scope
)
3732 Definition::set_my_scope(p_scope
);
3733 type
->set_my_scope(p_scope
);
3734 if (def_value
) def_value
->set_my_scope(p_scope
);
3737 Type
*Def_Modulepar::get_Type()
3743 void Def_Modulepar::chk()
3746 Error_Context
cntxt(this, "In module parameter definition `%s'",
3747 id
->get_dispname().c_str());
3748 type
->set_genname(_T_
, get_genname());
3750 if (w_attrib_path
) {
3751 w_attrib_path
->chk_global_attrib();
3752 switch (type
->get_type_refd_last()->get_typetype()) {
3755 case Type::T_CHOICE_T
:
3756 // These types may have qualified attributes
3758 case Type::T_SEQOF
: case Type::T_SETOF
:
3761 w_attrib_path
->chk_no_qualif();
3765 map
<Type
*,void> type_chain
;
3766 map
<Type::typetype_t
, void> not_allowed
;
3767 not_allowed
.add(Type::T_PORT
, 0);
3768 Type
*t
= type
->get_type_refd_last();
3769 // if the type is valid the original will be returned
3770 Type::typetype_t tt
= t
->search_for_not_allowed_type(type_chain
, not_allowed
);
3772 not_allowed
.clear();
3775 error("Type of module parameter cannot be or embed port type `%s'",
3776 t
->get_fullname().c_str());
3778 case Type::T_SIGNATURE
:
3779 error("Type of module parameter cannot be signature `%s'",
3780 t
->get_fullname().c_str());
3782 case Type::T_FUNCTION
:
3783 case Type::T_ALTSTEP
:
3784 case Type::T_TESTCASE
:
3785 if (t
->get_fat_runs_on_self()) {
3786 error("Type of module parameter cannot be of function reference type"
3787 " `%s' which has runs on self clause", t
->get_fullname().c_str());
3795 Error_Context
cntxt2(def_value
, "In default value");
3796 def_value
->set_my_governor(type
);
3797 type
->chk_this_value_ref(def_value
);
3799 type
->chk_this_value(def_value
, 0, Type::EXPECTED_CONSTANT
, INCOMPLETE_ALLOWED
,
3800 OMIT_NOT_ALLOWED
, SUB_CHK
, has_implicit_omit_attr());
3801 if (!semantic_check_only
) {
3802 def_value
->set_genname_prefix("modulepar_");
3803 def_value
->set_genname_recursive(get_genname());
3804 def_value
->set_code_section(GovernedSimple::CS_PRE_INIT
);
3806 } else checked
= true;
3812 void Def_Modulepar::generate_code(output_struct
*target
, bool)
3814 type
->generate_code(target
);
3816 Code::init_cdef(&cdef
);
3817 const string
& t_genname
= get_genname();
3818 const char *name
= t_genname
.c_str();
3819 type
->generate_code_object(&cdef
, my_scope
, t_genname
, "modulepar_", false);
3821 cdef
.init
= update_location_object(cdef
.init
);
3822 cdef
.init
= def_value
->generate_code_init(cdef
.init
, def_value
->get_lhs_name().c_str());
3824 Code::merge_cdef(target
, &cdef
);
3825 Code::free_cdef(&cdef
);
3827 if (has_implicit_omit_attr()) {
3828 target
->functions
.post_init
= mputprintf(target
->functions
.post_init
,
3829 "modulepar_%s.set_implicit_omit();\n", name
);
3832 const char *dispname
= id
->get_dispname().c_str();
3833 target
->functions
.set_param
= mputprintf(target
->functions
.set_param
,
3834 "if (!strcmp(par_name, \"%s\")) {\n"
3835 "modulepar_%s.set_param(param);\n"
3837 "} else ", dispname
, name
);
3838 target
->functions
.get_param
= mputprintf(target
->functions
.get_param
,
3839 "if (!strcmp(par_name, \"%s\")) {\n"
3840 "return modulepar_%s.get_param(param_name);\n"
3841 "} else ", dispname
, name
);
3843 if (target
->functions
.log_param
) {
3844 // this is not the first modulepar
3845 target
->functions
.log_param
= mputprintf(target
->functions
.log_param
,
3846 "TTCN_Logger::log_event_str(\", %s := \");\n", dispname
);
3848 // this is the first modulepar
3849 target
->functions
.log_param
= mputprintf(target
->functions
.log_param
,
3850 "TTCN_Logger::log_event_str(\"%s := \");\n", dispname
);
3852 target
->functions
.log_param
= mputprintf(target
->functions
.log_param
,
3853 "%s.log();\n", name
);
3856 void Def_Modulepar::generate_code(Common::CodeGenHelper
& cgh
) {
3857 // module parameter definitions always go to its containing module
3858 generate_code(cgh
.get_current_outputstruct());
3861 void Def_Modulepar::dump_internal(unsigned level
) const
3863 DEBUG(level
, "Module parameter: %s @ %p", id
->get_dispname().c_str(), (const void*)this);
3864 type
->dump(level
+ 1);
3865 if (def_value
) def_value
->dump(level
+ 1);
3866 else DEBUG(level
+ 1, "No default value");
3869 // =================================
3870 // ===== Def_Modulepar_Template
3871 // =================================
3873 Def_Modulepar_Template::Def_Modulepar_Template(Identifier
*p_id
, Type
*p_type
, Template
*p_deftmpl
)
3874 : Definition(A_MODULEPAR_TEMP
, p_id
)
3876 if (!p_type
) FATAL_ERROR("Ttcn::Def_Modulepar_Template::Def_Modulepar_Template()");
3878 type
->set_ownertype(Type::OT_MODPAR_DEF
, this);
3879 def_template
= p_deftmpl
;
3882 Def_Modulepar_Template::~Def_Modulepar_Template()
3885 delete def_template
;
3888 Def_Modulepar_Template
* Def_Modulepar_Template::clone() const
3890 FATAL_ERROR("Def_Modulepar_Template::clone");
3893 void Def_Modulepar_Template::set_fullname(const string
& p_fullname
)
3895 Definition::set_fullname(p_fullname
);
3896 type
->set_fullname(p_fullname
+ ".<type>");
3897 if (def_template
) def_template
->set_fullname(p_fullname
+ ".<default_template>");
3900 void Def_Modulepar_Template::set_my_scope(Scope
*p_scope
)
3902 Definition::set_my_scope(p_scope
);
3903 type
->set_my_scope(p_scope
);
3904 if (def_template
) def_template
->set_my_scope(p_scope
);
3907 Type
*Def_Modulepar_Template::get_Type()
3913 void Def_Modulepar_Template::chk()
3916 Error_Context
cntxt(this, "In template module parameter definition `%s'",
3917 id
->get_dispname().c_str());
3918 if (w_attrib_path
) {
3919 w_attrib_path
->chk_global_attrib();
3920 switch (type
->get_type_refd_last()->get_typetype()) {
3923 case Type::T_CHOICE_T
:
3924 // These types may have qualified attributes
3926 case Type::T_SEQOF
: case Type::T_SETOF
:
3929 w_attrib_path
->chk_no_qualif();
3933 type
->set_genname(_T_
, get_genname());
3935 Type
*t
= type
->get_type_refd_last();
3936 switch (t
->get_typetype()) {
3938 error("Type of template module parameter cannot be port type `%s'",
3939 t
->get_fullname().c_str());
3941 case Type::T_SIGNATURE
:
3942 error("Type of template module parameter cannot be signature `%s'",
3943 t
->get_fullname().c_str());
3945 case Type::T_FUNCTION
:
3946 case Type::T_ALTSTEP
:
3947 case Type::T_TESTCASE
:
3948 if (t
->get_fat_runs_on_self()) {
3949 error("Type of template module parameter cannot be of function reference type"
3950 " `%s' which has runs on self clause", t
->get_fullname().c_str());
3954 if (has_implicit_omit_attr()) {
3955 error("Implicit omit not supported for template module parameters");
3961 Error_Context
cntxt2(def_template
, "In default template");
3962 def_template
->set_my_governor(type
);
3963 def_template
->flatten(false);
3964 if (def_template
->get_templatetype() == Template::CSTR_PATTERN
&&
3965 type
->get_type_refd_last()->get_typetype() == Type::T_USTR
) {
3966 def_template
->set_templatetype(Template::USTR_PATTERN
);
3967 def_template
->get_ustr_pattern()->set_pattern_type(
3968 PatternString::USTR_PATTERN
);
3970 type
->chk_this_template_ref(def_template
);
3972 type
->chk_this_template_generic(def_template
, INCOMPLETE_ALLOWED
,
3973 OMIT_ALLOWED
, ANY_OR_OMIT_ALLOWED
, SUB_CHK
, has_implicit_omit_attr() ? IMPLICIT_OMIT
: NOT_IMPLICIT_OMIT
, 0);
3974 if (!semantic_check_only
) {
3975 def_template
->set_genname_prefix("modulepar_");
3976 def_template
->set_genname_recursive(get_genname());
3977 def_template
->set_code_section(GovernedSimple::CS_PRE_INIT
);
3979 } else checked
= true;
3985 void Def_Modulepar_Template::generate_code(output_struct
*target
, bool)
3987 type
->generate_code(target
);
3989 Code::init_cdef(&cdef
);
3990 const string
& t_genname
= get_genname();
3991 const char *name
= t_genname
.c_str();
3992 type
->generate_code_object(&cdef
, my_scope
, t_genname
, "modulepar_", true);
3994 cdef
.init
= update_location_object(cdef
.init
);
3995 cdef
.init
= def_template
->generate_code_init(cdef
.init
, def_template
->get_lhs_name().c_str());
3997 Code::merge_cdef(target
, &cdef
);
3998 Code::free_cdef(&cdef
);
4000 if (has_implicit_omit_attr()) {
4001 FATAL_ERROR("Def_Modulepar_Template::generate_code()");
4004 const char *dispname
= id
->get_dispname().c_str();
4005 target
->functions
.set_param
= mputprintf(target
->functions
.set_param
,
4006 "if (!strcmp(par_name, \"%s\")) {\n"
4007 "modulepar_%s.set_param(param);\n"
4009 "} else ", dispname
, name
);
4010 target
->functions
.get_param
= mputprintf(target
->functions
.get_param
,
4011 "if (!strcmp(par_name, \"%s\")) {\n"
4012 "return modulepar_%s.get_param(param_name);\n"
4013 "} else ", dispname
, name
);
4015 if (target
->functions
.log_param
) {
4016 // this is not the first modulepar
4017 target
->functions
.log_param
= mputprintf(target
->functions
.log_param
,
4018 "TTCN_Logger::log_event_str(\", %s := \");\n", dispname
);
4020 // this is the first modulepar
4021 target
->functions
.log_param
= mputprintf(target
->functions
.log_param
,
4022 "TTCN_Logger::log_event_str(\"%s := \");\n", dispname
);
4024 target
->functions
.log_param
= mputprintf(target
->functions
.log_param
,
4025 "%s.log();\n", name
);
4028 void Def_Modulepar_Template::generate_code(Common::CodeGenHelper
& cgh
) {
4029 // module parameter definitions always go to its containing module
4030 generate_code(cgh
.get_current_outputstruct());
4033 void Def_Modulepar_Template::dump_internal(unsigned level
) const
4035 DEBUG(level
, "Module parameter: %s @ %p", id
->get_dispname().c_str(), (const void*)this);
4036 type
->dump(level
+ 1);
4037 if (def_template
) def_template
->dump(level
+ 1);
4038 else DEBUG(level
+ 1, "No default template");
4041 // =================================
4042 // ===== Def_Template
4043 // =================================
4045 Def_Template::Def_Template(template_restriction_t p_template_restriction
,
4046 Identifier
*p_id
, Type
*p_type
, FormalParList
*p_fpl
,
4047 Reference
*p_derived_ref
, Template
*p_body
)
4048 : Definition(A_TEMPLATE
, p_id
), type(p_type
), fp_list(p_fpl
),
4049 derived_ref(p_derived_ref
), base_template(0), recurs_deriv_checked(false),
4050 body(p_body
), template_restriction(p_template_restriction
),
4051 gen_restriction_check(false)
4053 if (!p_type
|| !p_body
) FATAL_ERROR("Ttcn::Def_Template::Def_Template()");
4054 type
->set_ownertype(Type::OT_TEMPLATE_DEF
, this);
4055 if (fp_list
) fp_list
->set_my_def(this);
4058 Def_Template::~Def_Template()
4066 Def_Template
*Def_Template::clone() const
4068 FATAL_ERROR("Def_Template::clone");
4071 void Def_Template::set_fullname(const string
& p_fullname
)
4073 Definition::set_fullname(p_fullname
);
4074 type
->set_fullname(p_fullname
+ ".<type>");
4075 if (fp_list
) fp_list
->set_fullname(p_fullname
+ ".<formal_par_list>");
4077 derived_ref
->set_fullname(p_fullname
+ ".<derived_reference>");
4078 body
->set_fullname(p_fullname
);
4081 void Def_Template::set_my_scope(Scope
*p_scope
)
4083 bridgeScope
.set_parent_scope(p_scope
);
4084 bridgeScope
.set_scopeMacro_name(id
->get_dispname());
4086 Definition::set_my_scope(&bridgeScope
);
4087 type
->set_my_scope(&bridgeScope
);
4088 if (derived_ref
) derived_ref
->set_my_scope(&bridgeScope
);
4090 fp_list
->set_my_scope(&bridgeScope
);
4091 body
->set_my_scope(fp_list
);
4092 } else body
->set_my_scope(&bridgeScope
);
4095 Setting
*Def_Template::get_Setting()
4097 return get_Template();
4100 Type
*Def_Template::get_Type()
4102 if (!checked
) chk();
4106 Template
*Def_Template::get_Template()
4108 if (!checked
) chk();
4112 FormalParList
*Def_Template::get_FormalParList()
4114 if (!checked
) chk();
4118 void Def_Template::chk()
4120 if (checked
) return;
4121 Error_Context
cntxt(this, "In template definition `%s'",
4122 id
->get_dispname().c_str());
4123 const string
& t_genname
= get_genname();
4124 type
->set_genname(_T_
, t_genname
);
4126 if (w_attrib_path
) {
4127 w_attrib_path
->chk_global_attrib(true);
4128 switch (type
->get_type_refd_last()->get_typetype_ttcn3()) {
4131 case Type::T_CHOICE_T
:
4132 // These types may have qualified attributes
4134 case Type::T_SEQOF
: case Type::T_SETOF
:
4137 w_attrib_path
->chk_no_qualif();
4143 fp_list
->chk(asstype
);
4144 if (local_scope
) error("Parameterized local template `%s' not supported",
4145 id
->get_dispname().c_str());
4148 // Merge the elements of "all from" into the list
4149 body
->flatten(false);
4151 body
->set_my_governor(type
);
4153 if (body
->get_templatetype() == Template::CSTR_PATTERN
&&
4154 type
->get_type_refd_last()->get_typetype() == Type::T_USTR
) {
4155 body
->set_templatetype(Template::USTR_PATTERN
);
4156 body
->get_ustr_pattern()->set_pattern_type(PatternString::USTR_PATTERN
);
4159 type
->chk_this_template_ref(body
);
4161 Type
*t
= type
->get_type_refd_last();
4162 if (t
->get_typetype() == Type::T_PORT
) {
4163 error("Template cannot be defined for port type `%s'",
4164 t
->get_fullname().c_str());
4167 chk_recursive_derivation();
4168 type
->chk_this_template_generic(body
, INCOMPLETE_ALLOWED
, OMIT_ALLOWED
,
4169 ANY_OR_OMIT_ALLOWED
, SUB_CHK
,
4170 has_implicit_omit_attr() ? IMPLICIT_OMIT
: NOT_IMPLICIT_OMIT
, 0);
4172 chk_erroneous_attr();
4173 if (erroneous_attrs
) body
->set_err_descr(erroneous_attrs
->get_err_descr());
4176 ReferenceChain
refch(type
, "While checking embedded recursions");
4177 body
->chk_recursions(refch
);
4179 if (template_restriction
!=TR_NONE
) {
4180 Error_Context
ec(this, "While checking template restriction `%s'",
4181 Template::get_restriction_name(template_restriction
));
4182 gen_restriction_check
=
4183 body
->chk_restriction("template definition", template_restriction
, body
);
4184 if (fp_list
&& template_restriction
!=TR_PRESENT
) {
4185 size_t nof_fps
= fp_list
->get_nof_fps();
4186 for (size_t i
=0; i
<nof_fps
; i
++) {
4187 FormalPar
* fp
= fp_list
->get_fp_byIndex(i
);
4188 // if formal par is not template then skip restriction checking,
4189 // templates can have only `in' parameters
4190 if (fp
->get_asstype()!=A_PAR_TEMPL_IN
) continue;
4191 template_restriction_t fp_tr
= fp
->get_template_restriction();
4192 switch (template_restriction
) {
4201 fp
->error("Formal parameter with template restriction `%s' "
4202 "not allowed here", Template::get_restriction_name(fp_tr
));
4205 fp
->error("Formal parameter without template restriction "
4206 "not allowed here");
4209 FATAL_ERROR("Ttcn::Def_Template::chk()");
4213 FATAL_ERROR("Ttcn::Def_Template::chk()");
4218 if (!semantic_check_only
) {
4219 if (fp_list
) fp_list
->set_genname(t_genname
);
4220 body
->set_genname_prefix("template_");
4221 body
->set_genname_recursive(t_genname
);
4222 body
->set_code_section(fp_list
? GovernedSimple::CS_INLINE
:
4223 GovernedSimple::CS_POST_INIT
);
4228 void Def_Template::chk_default() const
4230 if (!fp_list
) FATAL_ERROR("Def_Template::chk_default()");
4232 if (fp_list
->has_notused_defval())
4233 fp_list
->error("Only modified templates are allowed to use the not "
4234 "used symbol (`-') as the default parameter");
4237 Common::Assignment
*ass
= derived_ref
->get_refd_assignment(false);
4238 if (!ass
|| ass
->get_asstype() != A_TEMPLATE
) return; // Work locally.
4239 Def_Template
*base
= dynamic_cast<Def_Template
*>(ass
);
4240 if (!base
) FATAL_ERROR("Def_Template::chk_default()");
4241 FormalParList
*base_fpl
= base
->get_FormalParList();
4242 size_t nof_base_fps
= base_fpl
? base_fpl
->get_nof_fps() : 0;
4243 size_t nof_local_fps
= fp_list
? fp_list
->get_nof_fps() : 0;
4244 size_t min_fps
= nof_base_fps
;
4245 if (nof_local_fps
< nof_base_fps
) min_fps
= nof_local_fps
;
4246 for (size_t i
= 0; i
< min_fps
; i
++) {
4247 FormalPar
*base_fp
= base_fpl
->get_fp_byIndex(i
);
4248 FormalPar
*local_fp
= fp_list
->get_fp_byIndex(i
);
4249 if (local_fp
->has_notused_defval()) {
4250 if (base_fp
->has_defval()) {
4251 local_fp
->set_defval(base_fp
->get_defval());
4253 local_fp
->error("Not used symbol (`-') doesn't have the "
4254 "corresponding default parameter in the "
4259 // Additional parameters in the derived template with using the not used
4260 // symbol. TODO: Merge the loops.
4261 for (size_t i
= nof_base_fps
; i
< nof_local_fps
; i
++) {
4262 FormalPar
*local_fp
= fp_list
->get_fp_byIndex(i
);
4263 if (local_fp
->has_notused_defval())
4264 local_fp
->error("Not used symbol (`-') doesn't have the "
4265 "corresponding default parameter in the "
4270 void Def_Template::chk_modified()
4272 if (!derived_ref
) return;
4273 // Do not check the (non-existent) actual parameter list of the derived
4274 // reference against the formal parameter list of the base template.
4275 // According to TTCN-3 syntax the derived reference cannot have parameters
4276 // even if the base template is parameterized.
4277 Common::Assignment
*ass
= derived_ref
->get_refd_assignment(false);
4278 // Checking the existence and type compatibility of the base template.
4280 if (ass
->get_asstype() != A_TEMPLATE
) {
4281 derived_ref
->error("Reference to a template was expected in the "
4282 "`modifies' definition instead of %s",
4283 ass
->get_description().c_str());
4286 base_template
= dynamic_cast<Def_Template
*>(ass
);
4287 if (!base_template
) FATAL_ERROR("Def_Template::chk_modified()");
4288 Type
*base_type
= base_template
->get_Type();
4289 TypeCompatInfo
info_base(my_scope
->get_scope_mod(), type
, base_type
, true,
4291 TypeChain l_chain_base
;
4292 TypeChain r_chain_base
;
4293 if (!type
->is_compatible(base_type
, &info_base
, &l_chain_base
,
4295 if (info_base
.is_subtype_error()) {
4296 type
->error("%s", info_base
.get_subtype_error().c_str());
4298 if (!info_base
.is_erroneous()) {
4299 type
->error("The modified template has different type than base "
4300 "template `%s': `%s' was expected instead of `%s'",
4301 ass
->get_fullname().c_str(),
4302 base_type
->get_typename().c_str(),
4303 type
->get_typename().c_str());
4305 // Always use the format string.
4306 type
->error("%s", info_base
.get_error_str_str().c_str());
4309 if (info_base
.needs_conversion())
4310 body
->set_needs_conversion();
4312 // Check for restriction.
4313 if (Template::is_less_restrictive(base_template
->get_template_restriction(),
4314 template_restriction
)) {
4315 error("The template restriction is not the same or more "
4316 "restrictive as of base template `%s'", ass
->get_fullname().c_str());
4318 // Checking formal parameter lists.
4319 FormalParList
*base_fpl
= base_template
->get_FormalParList();
4320 size_t nof_base_fps
= base_fpl
? base_fpl
->get_nof_fps() : 0;
4321 size_t nof_local_fps
= fp_list
? fp_list
->get_nof_fps() : 0;
4323 if (nof_local_fps
< nof_base_fps
) {
4324 error("The modified template has fewer formal parameters than base "
4325 "template `%s': at least %lu parameter%s expected instead of %lu",
4326 ass
->get_fullname().c_str(), (unsigned long)nof_base_fps
,
4327 nof_base_fps
> 1 ? "s were" : " was", (unsigned long)nof_local_fps
);
4328 min_fps
= nof_local_fps
;
4329 } else min_fps
= nof_base_fps
;
4331 for (size_t i
= 0; i
< min_fps
; i
++) {
4332 FormalPar
*base_fp
= base_fpl
->get_fp_byIndex(i
);
4333 FormalPar
*local_fp
= fp_list
->get_fp_byIndex(i
);
4334 Error_Context
cntxt(local_fp
, "In formal parameter #%lu",
4335 (unsigned long)(i
+ 1));
4336 // Check for parameter kind equivalence (value or template).
4337 if (base_fp
->get_asstype() != local_fp
->get_asstype())
4338 local_fp
->error("The kind of parameter is not the same as in base "
4339 "template `%s': %s was expected instead of %s",
4340 ass
->get_fullname().c_str(), base_fp
->get_assname(),
4341 local_fp
->get_assname());
4342 // Check for type compatibility.
4343 Type
*base_fp_type
= base_fp
->get_Type();
4344 Type
*local_fp_type
= local_fp
->get_Type();
4345 TypeCompatInfo
info_par(my_scope
->get_scope_mod(), base_fp_type
,
4346 local_fp_type
, true, false);
4347 TypeChain l_chain_par
;
4348 TypeChain r_chain_par
;
4349 if (!base_fp_type
->is_compatible(local_fp_type
, &info_par
, &l_chain_par
,
4351 if (info_par
.is_subtype_error()) {
4352 local_fp_type
->error("%s", info_par
.get_subtype_error().c_str());
4354 if (!info_par
.is_erroneous()) {
4355 local_fp_type
->error("The type of parameter is not the same as in "
4356 "base template `%s': `%s' was expected instead "
4358 ass
->get_fullname().c_str(),
4359 base_fp_type
->get_typename().c_str(),
4360 local_fp_type
->get_typename().c_str());
4362 local_fp_type
->error("%s", info_par
.get_error_str_str().c_str());
4365 if (info_par
.needs_conversion())
4366 body
->set_needs_conversion();
4368 // Check for name equivalence.
4369 const Identifier
& base_fp_id
= base_fp
->get_id();
4370 const Identifier
& local_fp_id
= local_fp
->get_id();
4371 if (!(base_fp_id
== local_fp_id
))
4372 local_fp
->error("The name of parameter is not the same as in base "
4373 "template `%s': `%s' was expected instead of `%s'",
4374 ass
->get_fullname().c_str(),
4375 base_fp_id
.get_dispname().c_str(),
4376 local_fp_id
.get_dispname().c_str());
4377 // Check for restrictions: the derived must be same or more restrictive.
4378 if (base_fp
->get_asstype()==local_fp
->get_asstype() &&
4379 Template::is_less_restrictive(base_fp
->get_template_restriction(),
4380 local_fp
->get_template_restriction())) {
4381 local_fp
->error("The restriction of parameter is not the same or more "
4382 "restrictive as in base template `%s'", ass
->get_fullname().c_str());
4385 // Set the pointer to the body of base template.
4386 body
->set_base_template(base_template
->get_Template());
4389 void Def_Template::chk_recursive_derivation()
4391 if (recurs_deriv_checked
) return;
4392 if (base_template
) {
4393 ReferenceChain
refch(this, "While checking the chain of base templates");
4394 refch
.add(get_fullname());
4395 for (Def_Template
*iter
= base_template
; iter
; iter
= iter
->base_template
)
4397 if (iter
->recurs_deriv_checked
) break;
4398 else if (refch
.add(iter
->get_fullname()))
4399 iter
->recurs_deriv_checked
= true;
4403 recurs_deriv_checked
= true;
4406 void Def_Template::generate_code(output_struct
*target
, bool)
4408 type
->generate_code(target
);
4410 // Parameterized template. Generate code for a function which returns
4411 // a $(genname)_template and has the appropriate parameters.
4412 const string
& t_genname
= get_genname();
4413 const char *template_name
= t_genname
.c_str();
4414 const char *template_dispname
= id
->get_dispname().c_str();
4415 const string
& type_genname
= type
->get_genname_template(my_scope
);
4416 const char *type_genname_str
= type_genname
.c_str();
4418 // assemble the function body first (this also determines which parameters
4420 size_t nof_base_pars
= 0;
4421 char* function_body
= create_location_object(memptystr(), "TEMPLATE",
4423 if (debugger_active
) {
4424 function_body
= generate_code_debugger_function_init(function_body
, this);
4426 if (base_template
) {
4427 // modified template
4428 function_body
= mputprintf(function_body
, "%s ret_val(%s",
4430 base_template
->get_genname_from_scope(my_scope
).c_str());
4431 if (base_template
->fp_list
) {
4432 // the base template is also parameterized
4433 function_body
= mputc(function_body
, '(');
4434 nof_base_pars
= base_template
->fp_list
->get_nof_fps();
4435 for (size_t i
= 0; i
< nof_base_pars
; i
++) {
4436 if (i
> 0) function_body
= mputstr(function_body
, ", ");
4437 function_body
= mputstr(function_body
,
4438 fp_list
->get_fp_byIndex(i
)->get_id().get_name().c_str());
4440 function_body
= mputc(function_body
, ')');
4442 function_body
= mputstr(function_body
, ");\n");
4445 function_body
= mputprintf(function_body
, "%s ret_val;\n",
4448 if (erroneous_attrs
&& erroneous_attrs
->get_err_descr()) {
4449 function_body
= erroneous_attrs
->get_err_descr()->
4450 generate_code_str(function_body
, string("ret_val"));
4452 function_body
= body
->generate_code_init(function_body
, "ret_val");
4453 if (template_restriction
!=TR_NONE
&& gen_restriction_check
)
4454 function_body
= Template::generate_restriction_check_code(function_body
,
4455 "ret_val", template_restriction
);
4456 if (debugger_active
) {
4457 function_body
= mputstr(function_body
,
4458 "ttcn3_debugger.set_return_value((TTCN_Logger::begin_event_log2str(), "
4459 "ret_val.log(), TTCN_Logger::end_event_log2str()));\n");
4461 function_body
= mputstr(function_body
, "return ret_val;\n");
4462 // if the template modifies a parameterized template, then the inherited
4463 // formal parameters must always be displayed, otherwise generate a smart
4464 // formal parameter list (where the names of unused parameters are omitted)
4465 char *formal_par_list
= fp_list
->generate_code(memptystr(), nof_base_pars
);
4466 fp_list
->generate_code_defval(target
);
4468 target
->header
.function_prototypes
=
4469 mputprintf(target
->header
.function_prototypes
,
4470 "extern %s %s(%s);\n",
4471 type_genname_str
, template_name
, formal_par_list
);
4472 target
->source
.function_bodies
= mputprintf(target
->source
.function_bodies
,
4476 "}\n\n", type_genname_str
, template_name
, formal_par_list
, function_body
);
4477 Free(formal_par_list
);
4478 Free(function_body
);
4480 // non-parameterized template
4482 Code::init_cdef(&cdef
);
4483 type
->generate_code_object(&cdef
, body
);
4484 cdef
.init
= update_location_object(cdef
.init
);
4485 if (base_template
) {
4486 // modified template
4487 if (base_template
->my_scope
->get_scope_mod_gen() ==
4488 my_scope
->get_scope_mod_gen()) {
4489 // if the base template is in the same module its body has to be
4490 // initialized first
4491 cdef
.init
= base_template
->body
->generate_code_init(cdef
.init
,
4492 base_template
->body
->get_lhs_name().c_str());
4494 if (use_runtime_2
&& body
->get_needs_conversion()) {
4495 Type
*body_type
= body
->get_my_governor()->get_type_refd_last();
4496 Type
*base_type
= base_template
->body
->get_my_governor()
4497 ->get_type_refd_last();
4498 if (!body_type
|| !base_type
)
4499 FATAL_ERROR("Def_Template::generate_code()");
4500 const string
& tmp_id
= body
->get_temporary_id();
4501 const char *tmp_id_str
= tmp_id
.c_str();
4502 // base template initialization
4503 cdef
.init
= mputprintf(cdef
.init
,
4505 "if (!%s(%s, %s)) TTCN_error(\"Values or templates of types `%s' "
4506 "and `%s' are not compatible at run-time\");\n"
4508 body_type
->get_genname_template(my_scope
).c_str(), tmp_id_str
,
4509 TypeConv::get_conv_func(base_type
, body_type
, my_scope
4510 ->get_scope_mod()).c_str(), tmp_id_str
, base_template
4511 ->get_genname_from_scope(my_scope
).c_str(), base_type
4512 ->get_typename().c_str(), body_type
->get_typename().c_str(),
4513 body
->get_lhs_name().c_str(), tmp_id_str
);
4515 cdef
.init
= mputprintf(cdef
.init
, "%s = %s;\n",
4516 body
->get_lhs_name().c_str(),
4517 base_template
->get_genname_from_scope(my_scope
).c_str());
4520 if (use_runtime_2
&& TypeConv::needs_conv_refd(body
))
4521 cdef
.init
= TypeConv::gen_conv_code_refd(cdef
.init
,
4522 body
->get_lhs_name().c_str(), body
);
4524 cdef
.init
= body
->generate_code_init(cdef
.init
,
4525 body
->get_lhs_name().c_str());
4526 if (template_restriction
!= TR_NONE
&& gen_restriction_check
)
4527 cdef
.init
= Template::generate_restriction_check_code(cdef
.init
,
4528 body
->get_lhs_name().c_str(), template_restriction
);
4529 target
->header
.global_vars
= mputstr(target
->header
.global_vars
,
4531 target
->source
.global_vars
= mputstr(target
->source
.global_vars
,
4533 target
->functions
.post_init
= mputstr(target
->functions
.post_init
,
4535 Code::free_cdef(&cdef
);
4539 void Def_Template::generate_code(Common::CodeGenHelper
& cgh
) {
4540 generate_code(cgh
.get_outputstruct(this));
4543 char *Def_Template::generate_code_str(char *str
)
4545 const string
& t_genname
= get_genname();
4546 const char *genname_str
= t_genname
.c_str();
4547 const string
& type_genname
= type
->get_genname_template(my_scope
);
4548 const char *type_genname_str
= type_genname
.c_str();
4550 const char *dispname_str
= id
->get_dispname().c_str();
4551 NOTSUPP("Code generation for parameterized local template `%s'",
4553 str
= mputprintf(str
, "/* NOT SUPPORTED: template %s */\n",
4556 if (base_template
) {
4557 // non-parameterized modified template
4558 if (use_runtime_2
&& body
->get_needs_conversion()) {
4559 Type
*body_type
= body
->get_my_governor()->get_type_refd_last();
4560 Type
*base_type
= base_template
->body
->get_my_governor()
4561 ->get_type_refd_last();
4562 if (!body_type
|| !base_type
)
4563 FATAL_ERROR("Def_Template::generate_code_str()");
4564 const string
& tmp_id
= body
->get_temporary_id();
4565 const char *tmp_id_str
= tmp_id
.c_str();
4566 str
= mputprintf(str
,
4568 "if (!%s(%s, %s)) TTCN_error(\"Values or templates of types `%s' "
4569 "and `%s' are not compatible at run-time\");\n"
4571 body_type
->get_genname_template(my_scope
).c_str(), tmp_id_str
,
4572 TypeConv::get_conv_func(base_type
, body_type
, my_scope
4573 ->get_scope_mod()).c_str(), tmp_id_str
, base_template
4574 ->get_genname_from_scope(my_scope
).c_str(), base_type
4575 ->get_typename().c_str(), body_type
->get_typename().c_str(),
4576 type_genname_str
, genname_str
, tmp_id_str
);
4578 // the object is initialized from the base template by the
4580 str
= mputprintf(str
, "%s %s(%s);\n", type_genname_str
, genname_str
,
4581 base_template
->get_genname_from_scope(my_scope
).c_str());
4583 // the modified body is assigned in the subsequent statements
4584 str
= body
->generate_code_init(str
, genname_str
);
4586 // non-parameterized non-modified template
4587 if (body
->has_single_expr()) {
4588 // the object is initialized by the constructor
4589 str
= mputprintf(str
, "%s %s(%s);\n", type_genname_str
,
4590 genname_str
, body
->get_single_expr(false).c_str());
4591 // make sure the template's code is not generated twice (TR: HU56425)
4592 body
->set_code_generated();
4594 // the default constructor is used
4595 str
= mputprintf(str
, "%s %s;\n", type_genname_str
, genname_str
);
4596 // the body is assigned in the subsequent statements
4597 str
= body
->generate_code_init(str
, genname_str
);
4600 if (template_restriction
!= TR_NONE
&& gen_restriction_check
)
4601 str
= Template::generate_restriction_check_code(str
, genname_str
,
4602 template_restriction
);
4604 if (debugger_active
) {
4605 str
= generate_code_debugger_add_var(str
, this);
4610 void Def_Template::ilt_generate_code(ILT
*ilt
)
4612 const string
& t_genname
= get_genname();
4613 const char *genname_str
= t_genname
.c_str();
4614 char*& def
=ilt
->get_out_def();
4615 char*& init
=ilt
->get_out_branches();
4617 const char *dispname_str
= id
->get_dispname().c_str();
4618 NOTSUPP("Code generation for parameterized local template `%s'",
4620 def
= mputprintf(def
, "/* NOT SUPPORTED: template %s */\n", dispname_str
);
4621 init
= mputprintf(init
, "/* NOT SUPPORTED: template %s */\n",
4624 // non-parameterized template
4625 // use the default constructor for initialization
4626 def
= mputprintf(def
, "%s %s;\n",
4627 type
->get_genname_template(my_scope
).c_str(), genname_str
);
4628 if (base_template
) {
4629 // copy the base template with an assignment
4630 init
= mputprintf(init
, "%s = %s;\n", genname_str
,
4631 base_template
->get_genname_from_scope(my_scope
).c_str());
4633 // finally assign the body
4634 init
= body
->generate_code_init(init
, genname_str
);
4635 if (template_restriction
!=TR_NONE
&& gen_restriction_check
)
4636 init
= Template::generate_restriction_check_code(init
, genname_str
,
4637 template_restriction
);
4641 void Def_Template::dump_internal(unsigned level
) const
4643 DEBUG(level
, "Template: %s", id
->get_dispname().c_str());
4644 if (fp_list
) fp_list
->dump(level
+ 1);
4646 DEBUG(level
+ 1, "modifies: %s", derived_ref
->get_dispname().c_str());
4647 if (template_restriction
!=TR_NONE
)
4648 DEBUG(level
+ 1, "restriction: %s",
4649 Template::get_restriction_name(template_restriction
));
4650 type
->dump(level
+ 1);
4651 body
->dump(level
+ 1);
4654 // =================================
4656 // =================================
4658 Def_Var::Def_Var(Identifier
*p_id
, Type
*p_type
, Value
*p_initial_value
)
4659 : Definition(A_VAR
, p_id
), type(p_type
), initial_value(p_initial_value
)
4661 if (!p_type
) FATAL_ERROR("Ttcn::Def_Var::Def_Var()");
4662 type
->set_ownertype(Type::OT_VAR_DEF
, this);
4668 delete initial_value
;
4671 Def_Var
*Def_Var::clone() const
4673 FATAL_ERROR("Def_Var::clone");
4676 void Def_Var::set_fullname(const string
& p_fullname
)
4678 Definition::set_fullname(p_fullname
);
4679 type
->set_fullname(p_fullname
+ ".<type>");
4681 initial_value
->set_fullname(p_fullname
+ ".<initial_value>");
4684 void Def_Var::set_my_scope(Scope
*p_scope
)
4686 Definition::set_my_scope(p_scope
);
4687 type
->set_my_scope(p_scope
);
4688 if (initial_value
) initial_value
->set_my_scope(p_scope
);
4691 Type
*Def_Var::get_Type()
4700 Error_Context
cntxt(this, "In variable definition `%s'",
4701 id
->get_dispname().c_str());
4702 type
->set_genname(_T_
, get_genname());
4705 Type
*t
= type
->get_type_refd_last();
4706 switch (t
->get_typetype()) {
4708 error("Variable cannot be defined for port type `%s'",
4709 t
->get_fullname().c_str());
4711 case Type::T_SIGNATURE
:
4712 error("Variable cannot be defined for signature `%s'",
4713 t
->get_fullname().c_str());
4716 if (initial_value
) {
4717 initial_value
->set_my_governor(type
);
4718 type
->chk_this_value_ref(initial_value
);
4719 type
->chk_this_value(initial_value
, this, is_local() ?
4720 Type::EXPECTED_DYNAMIC_VALUE
: Type::EXPECTED_STATIC_VALUE
,
4721 INCOMPLETE_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
4722 if (!semantic_check_only
) {
4723 initial_value
->set_genname_recursive(get_genname());
4724 initial_value
->set_code_section(GovernedSimple::CS_INLINE
);
4730 if (w_attrib_path
) {
4731 w_attrib_path
->chk_global_attrib();
4732 w_attrib_path
->chk_no_qualif();
4736 bool Def_Var::chk_identical(Definition
*p_def
)
4740 if (p_def
->get_asstype() != A_VAR
) {
4741 const char *dispname_str
= id
->get_dispname().c_str();
4742 error("Local definition `%s' is a variable, but the definition "
4743 "inherited from component type `%s' is a %s", dispname_str
,
4744 p_def
->get_my_scope()->get_fullname().c_str(), p_def
->get_assname());
4745 p_def
->note("The inherited definition of `%s' is here", dispname_str
);
4748 Def_Var
*p_def_var
= dynamic_cast<Def_Var
*>(p_def
);
4749 if (!p_def_var
) FATAL_ERROR("Def_Var::chk_identical()");
4750 if (!type
->is_identical(p_def_var
->type
)) {
4751 const char *dispname_str
= id
->get_dispname().c_str();
4752 type
->error("Local variable `%s' has type `%s', but the variable "
4753 "inherited from component type `%s' has type `%s'", dispname_str
,
4754 type
->get_typename().c_str(),
4755 p_def_var
->get_my_scope()->get_fullname().c_str(),
4756 p_def_var
->type
->get_typename().c_str());
4757 p_def_var
->note("The inherited variable `%s' is here", dispname_str
);
4760 if (initial_value
) {
4761 if (p_def_var
->initial_value
) {
4762 if (!initial_value
->is_unfoldable() &&
4763 !p_def_var
->initial_value
->is_unfoldable() &&
4764 !(*initial_value
== *p_def_var
->initial_value
)) {
4765 const char *dispname_str
= id
->get_dispname().c_str();
4766 initial_value
->warning("Local variable `%s' and the variable "
4767 "inherited from component type `%s' have different initial values",
4768 dispname_str
, p_def_var
->get_my_scope()->get_fullname().c_str());
4769 p_def_var
->note("The inherited variable `%s' is here", dispname_str
);
4772 const char *dispname_str
= id
->get_dispname().c_str();
4773 initial_value
->warning("Local variable `%s' has initial value, but "
4774 "the variable inherited from component type `%s' does not",
4775 dispname_str
, p_def_var
->get_my_scope()->get_fullname().c_str());
4776 p_def_var
->note("The inherited variable `%s' is here", dispname_str
);
4778 } else if (p_def_var
->initial_value
) {
4779 const char *dispname_str
= id
->get_dispname().c_str();
4780 warning("Local variable `%s' does not have initial value, but the "
4781 "variable inherited from component type `%s' has", dispname_str
,
4782 p_def_var
->get_my_scope()->get_fullname().c_str());
4783 p_def_var
->note("The inherited variable `%s' is here", dispname_str
);
4788 void Def_Var::generate_code(output_struct
*target
, bool clean_up
)
4790 type
->generate_code(target
);
4792 Code::init_cdef(&cdef
);
4793 type
->generate_code_object(&cdef
, my_scope
, get_genname(), 0, false);
4794 Code::merge_cdef(target
, &cdef
);
4795 Code::free_cdef(&cdef
);
4796 if (initial_value
) {
4797 target
->functions
.init_comp
=
4798 initial_value
->generate_code_init(target
->functions
.init_comp
,
4799 initial_value
->get_lhs_name().c_str());
4800 } else if (clean_up
) { // No initial value.
4801 target
->functions
.init_comp
= mputprintf(target
->functions
.init_comp
,
4802 "%s.clean_up();\n", get_genname().c_str());
4806 void Def_Var::generate_code(CodeGenHelper
& cgh
)
4808 generate_code(cgh
.get_outputstruct(this));
4811 char *Def_Var::generate_code_str(char *str
)
4813 const string
& t_genname
= get_genname();
4814 const char *genname_str
= t_genname
.c_str();
4815 if (initial_value
&& initial_value
->has_single_expr()) {
4816 // the initial value can be represented by a single C++ expression
4817 // the object is initialized by the constructor
4818 str
= mputprintf(str
, "%s %s(%s);\n",
4819 type
->get_genname_value(my_scope
).c_str(), genname_str
,
4820 initial_value
->get_single_expr().c_str());
4822 // use the default constructor
4823 str
= mputprintf(str
, "%s %s;\n",
4824 type
->get_genname_value(my_scope
).c_str(), genname_str
);
4825 if (initial_value
) {
4826 // the initial value is assigned using subsequent statements
4827 str
= initial_value
->generate_code_init(str
, genname_str
);
4830 if (debugger_active
) {
4831 str
= generate_code_debugger_add_var(str
, this);
4836 void Def_Var::ilt_generate_code(ILT
*ilt
)
4838 const string
& t_genname
= get_genname();
4839 const char *genname_str
= t_genname
.c_str();
4840 char*& def
=ilt
->get_out_def();
4841 char*& init
=ilt
->get_out_branches();
4842 def
= mputprintf(def
, "%s %s;\n", type
->get_genname_value(my_scope
).c_str(),
4845 init
= initial_value
->generate_code_init(init
, genname_str
);
4848 char *Def_Var::generate_code_init_comp(char *str
, Definition
*base_defn
)
4850 if (initial_value
) {
4851 str
= initial_value
->generate_code_init(str
,
4852 base_defn
->get_genname_from_scope(my_scope
).c_str());
4857 void Def_Var::dump_internal(unsigned level
) const
4859 DEBUG(level
, "Variable %s", id
->get_dispname().c_str());
4860 type
->dump(level
+ 1);
4861 if (initial_value
) initial_value
->dump(level
+ 1);
4864 // =================================
4865 // ===== Def_Var_Template
4866 // =================================
4868 Def_Var_Template::Def_Var_Template(Identifier
*p_id
, Type
*p_type
,
4869 Template
*p_initial_value
, template_restriction_t p_template_restriction
)
4870 : Definition(A_VAR_TEMPLATE
, p_id
), type(p_type
),
4871 initial_value(p_initial_value
), template_restriction(p_template_restriction
)
4873 if (!p_type
) FATAL_ERROR("Ttcn::Def_Var_Template::Def_Var_Template()");
4874 type
->set_ownertype(Type::OT_VARTMPL_DEF
, this);
4877 Def_Var_Template::~Def_Var_Template()
4880 delete initial_value
;
4883 Def_Var_Template
*Def_Var_Template::clone() const
4885 FATAL_ERROR("Def_Var_Template::clone");
4888 void Def_Var_Template::set_fullname(const string
& p_fullname
)
4890 Definition::set_fullname(p_fullname
);
4891 type
->set_fullname(p_fullname
+ ".<type>");
4893 initial_value
->set_fullname(p_fullname
+ ".<initial_value>");
4896 void Def_Var_Template::set_my_scope(Scope
*p_scope
)
4898 Definition::set_my_scope(p_scope
);
4899 type
->set_my_scope(p_scope
);
4900 if (initial_value
) initial_value
->set_my_scope(p_scope
);
4903 Type
*Def_Var_Template::get_Type()
4909 void Def_Var_Template::chk()
4912 Error_Context
cntxt(this, "In template variable definition `%s'",
4913 id
->get_dispname().c_str());
4914 type
->set_genname(_T_
, get_genname());
4917 Type
*t
= type
->get_type_refd_last();
4918 if (t
->get_typetype() == Type::T_PORT
) {
4919 error("Template variable cannot be defined for port type `%s'",
4920 t
->get_fullname().c_str());
4923 if (initial_value
) {
4924 initial_value
->set_my_governor(type
);
4925 initial_value
->flatten(false);
4927 if (initial_value
->get_templatetype() == Template::CSTR_PATTERN
&&
4928 type
->get_type_refd_last()->get_typetype() == Type::T_USTR
) {
4929 initial_value
->set_templatetype(Template::USTR_PATTERN
);
4930 initial_value
->get_ustr_pattern()->set_pattern_type(
4931 PatternString::USTR_PATTERN
);
4934 type
->chk_this_template_ref(initial_value
);
4935 // temporary hack: to allow incomplete body as initial value
4936 // checking as a modified template, but without a base template
4937 type
->chk_this_template_generic(initial_value
, INCOMPLETE_ALLOWED
,
4938 OMIT_ALLOWED
, ANY_OR_OMIT_ALLOWED
, SUB_CHK
, IMPLICIT_OMIT
, 0);
4939 gen_restriction_check
=
4940 initial_value
->chk_restriction("template variable definition",
4941 template_restriction
, initial_value
);
4942 if (!semantic_check_only
) {
4943 initial_value
->set_genname_recursive(get_genname());
4944 initial_value
->set_code_section(GovernedSimple::CS_INLINE
);
4947 if (w_attrib_path
) {
4948 w_attrib_path
->chk_global_attrib();
4949 w_attrib_path
->chk_no_qualif();
4953 bool Def_Var_Template::chk_identical(Definition
*p_def
)
4957 if (p_def
->get_asstype() != A_VAR_TEMPLATE
) {
4958 const char *dispname_str
= id
->get_dispname().c_str();
4959 error("Local definition `%s' is a template variable, but the definition "
4960 "inherited from component type `%s' is a %s", dispname_str
,
4961 p_def
->get_my_scope()->get_fullname().c_str(), p_def
->get_assname());
4962 p_def
->note("The inherited definition of `%s' is here", dispname_str
);
4965 Def_Var_Template
*p_def_var_template
=
4966 dynamic_cast<Def_Var_Template
*>(p_def
);
4967 if (!p_def_var_template
) FATAL_ERROR("Def_Var_Template::chk_identical()");
4968 if (!type
->is_identical(p_def_var_template
->type
)) {
4969 const char *dispname_str
= id
->get_dispname().c_str();
4970 type
->error("Local template variable `%s' has type `%s', but the "
4971 "template variable inherited from component type `%s' has type `%s'",
4972 dispname_str
, type
->get_typename().c_str(),
4973 p_def_var_template
->get_my_scope()->get_fullname().c_str(),
4974 p_def_var_template
->type
->get_typename().c_str());
4975 p_def_var_template
->note("The inherited template variable `%s' is here",
4979 if (initial_value
) {
4980 if (!p_def_var_template
->initial_value
) {
4981 const char *dispname_str
= id
->get_dispname().c_str();
4982 initial_value
->warning("Local template variable `%s' has initial "
4983 "value, but the template variable inherited from component type "
4984 "`%s' does not", dispname_str
,
4985 p_def_var_template
->get_my_scope()->get_fullname().c_str());
4986 p_def_var_template
->note("The inherited template variable `%s' is here",
4989 } else if (p_def_var_template
->initial_value
) {
4990 const char *dispname_str
= id
->get_dispname().c_str();
4991 warning("Local template variable `%s' does not have initial value, but "
4992 "the template variable inherited from component type `%s' has",
4994 p_def_var_template
->get_my_scope()->get_fullname().c_str());
4995 p_def_var_template
->note("The inherited template variable `%s' is here",
5001 void Def_Var_Template::generate_code(output_struct
*target
, bool clean_up
)
5003 type
->generate_code(target
);
5005 Code::init_cdef(&cdef
);
5006 type
->generate_code_object(&cdef
, my_scope
, get_genname(), 0, true);
5007 Code::merge_cdef(target
, &cdef
);
5008 Code::free_cdef(&cdef
);
5009 if (initial_value
) {
5010 if (Common::Type::T_SEQOF
== initial_value
->get_my_governor()->get_typetype() ||
5011 Common::Type::T_ARRAY
== initial_value
->get_my_governor()->get_typetype()) {
5012 target
->functions
.init_comp
= mputprintf(target
->functions
.init_comp
,
5013 "%s.remove_all_permutations();\n", initial_value
->get_lhs_name().c_str());
5015 target
->functions
.init_comp
=
5016 initial_value
->generate_code_init(target
->functions
.init_comp
,
5017 initial_value
->get_lhs_name().c_str());
5018 if (template_restriction
!=TR_NONE
&& gen_restriction_check
)
5019 target
->functions
.init_comp
= Template::generate_restriction_check_code(
5020 target
->functions
.init_comp
, initial_value
->get_lhs_name().c_str(),
5021 template_restriction
);
5022 } else if (clean_up
) { // No initial value.
5023 // Always reset component variables/variable templates on component
5024 // reinitialization. Fix for HM79493.
5025 target
->functions
.init_comp
= mputprintf(target
->functions
.init_comp
,
5026 "%s.clean_up();\n", get_genname().c_str());
5030 void Def_Var_Template::generate_code(CodeGenHelper
& cgh
)
5032 generate_code(cgh
.get_outputstruct(this));
5035 char *Def_Var_Template::generate_code_str(char *str
)
5037 const string
& t_genname
= get_genname();
5038 const char *genname_str
= t_genname
.c_str();
5039 if (initial_value
&& initial_value
->has_single_expr()) {
5040 // The initial value can be represented by a single C++ expression
5041 // the object is initialized by the constructor.
5042 str
= mputprintf(str
, "%s %s(%s);\n",
5043 type
->get_genname_template(my_scope
).c_str(), genname_str
,
5044 initial_value
->get_single_expr(false).c_str());
5046 // Use the default constructor.
5047 str
= mputprintf(str
, "%s %s;\n",
5048 type
->get_genname_template(my_scope
).c_str(), genname_str
);
5049 if (initial_value
) {
5050 // The initial value is assigned using subsequent statements.
5051 if (use_runtime_2
&& TypeConv::needs_conv_refd(initial_value
))
5052 str
= TypeConv::gen_conv_code_refd(str
, genname_str
, initial_value
);
5053 else str
= initial_value
->generate_code_init(str
, genname_str
);
5056 if (initial_value
&& template_restriction
!= TR_NONE
5057 && gen_restriction_check
)
5058 str
= Template::generate_restriction_check_code(str
, genname_str
,
5059 template_restriction
);
5060 if (debugger_active
) {
5061 str
= generate_code_debugger_add_var(str
, this);
5066 void Def_Var_Template::ilt_generate_code(ILT
*ilt
)
5068 const string
& t_genname
= get_genname();
5069 const char *genname_str
= t_genname
.c_str();
5070 char*& def
=ilt
->get_out_def();
5071 char*& init
=ilt
->get_out_branches();
5072 def
= mputprintf(def
, "%s %s;\n",
5073 type
->get_genname_template(my_scope
).c_str(), genname_str
);
5074 if (initial_value
) {
5075 init
= initial_value
->generate_code_init(init
, genname_str
);
5076 if (template_restriction
!=TR_NONE
&& gen_restriction_check
)
5077 init
= Template::generate_restriction_check_code(init
, genname_str
,
5078 template_restriction
);
5082 char *Def_Var_Template::generate_code_init_comp(char *str
,
5083 Definition
*base_defn
)
5085 if (initial_value
) {
5086 str
= initial_value
->generate_code_init(str
,
5087 base_defn
->get_genname_from_scope(my_scope
).c_str());
5088 if (template_restriction
!= TR_NONE
&& gen_restriction_check
)
5089 str
= Template::generate_restriction_check_code(str
,
5090 base_defn
->get_genname_from_scope(my_scope
).c_str(),
5091 template_restriction
);
5096 void Def_Var_Template::dump_internal(unsigned level
) const
5098 DEBUG(level
, "Template variable %s", id
->get_dispname().c_str());
5099 if (template_restriction
!=TR_NONE
)
5100 DEBUG(level
+ 1, "restriction: %s",
5101 Template::get_restriction_name(template_restriction
));
5102 type
->dump(level
+ 1);
5103 if (initial_value
) initial_value
->dump(level
+ 1);
5106 // =================================
5108 // =================================
5110 Def_Timer::~Def_Timer()
5113 delete default_duration
;
5116 Def_Timer
*Def_Timer::clone() const
5118 FATAL_ERROR("Def_Timer::clone");
5121 void Def_Timer::set_fullname(const string
& p_fullname
)
5123 Definition::set_fullname(p_fullname
);
5124 if (dimensions
) dimensions
->set_fullname(p_fullname
+ ".<dimensions>");
5125 if (default_duration
)
5126 default_duration
->set_fullname(p_fullname
+ ".<default_duration>");
5129 void Def_Timer::set_my_scope(Scope
*p_scope
)
5131 Definition::set_my_scope(p_scope
);
5132 if (dimensions
) dimensions
->set_my_scope(p_scope
);
5133 if (default_duration
) default_duration
->set_my_scope(p_scope
);
5136 ArrayDimensions
*Def_Timer::get_Dimensions()
5138 if (!checked
) chk();
5142 void Def_Timer::chk()
5145 Error_Context
cntxt(this, "In timer definition `%s'",
5146 id
->get_dispname().c_str());
5147 if (dimensions
) dimensions
->chk();
5148 if (default_duration
) {
5149 Error_Context
cntxt2(default_duration
, "In default duration");
5150 if (dimensions
) chk_array_duration(default_duration
);
5151 else chk_single_duration(default_duration
);
5152 if (!semantic_check_only
) {
5153 default_duration
->set_code_section(GovernedSimple::CS_POST_INIT
);
5157 if (w_attrib_path
) {
5158 w_attrib_path
->chk_global_attrib();
5159 w_attrib_path
->chk_no_qualif();
5163 bool Def_Timer::chk_identical(Definition
*p_def
)
5167 if (p_def
->get_asstype() != A_TIMER
) {
5168 const char *dispname_str
= id
->get_dispname().c_str();
5169 error("Local definition `%s' is a timer, but the definition inherited "
5170 "from component type `%s' is a %s", dispname_str
,
5171 p_def
->get_my_scope()->get_fullname().c_str(), p_def
->get_assname());
5172 p_def
->note("The inherited definition of `%s' is here", dispname_str
);
5175 Def_Timer
*p_def_timer
= dynamic_cast<Def_Timer
*>(p_def
);
5176 if (!p_def_timer
) FATAL_ERROR("Def_Timer::chk_identical()");
5178 if (p_def_timer
->dimensions
) {
5179 if (!dimensions
->is_identical(p_def_timer
->dimensions
)) {
5180 const char *dispname_str
= id
->get_dispname().c_str();
5181 error("Local timer `%s' and the timer inherited from component type "
5182 "`%s' have different array dimensions", dispname_str
,
5183 p_def_timer
->get_my_scope()->get_fullname().c_str());
5184 p_def_timer
->note("The inherited timer `%s' is here", dispname_str
);
5188 const char *dispname_str
= id
->get_dispname().c_str();
5189 error("Local definition `%s' is a timer array, but the definition "
5190 "inherited from component type `%s' is a single timer", dispname_str
,
5191 p_def_timer
->get_my_scope()->get_fullname().c_str());
5192 p_def_timer
->note("The inherited timer `%s' is here", dispname_str
);
5195 } else if (p_def_timer
->dimensions
) {
5196 const char *dispname_str
= id
->get_dispname().c_str();
5197 error("Local definition `%s' is a single timer, but the definition "
5198 "inherited from component type `%s' is a timer array", dispname_str
,
5199 p_def_timer
->get_my_scope()->get_fullname().c_str());
5200 p_def_timer
->note("The inherited timer `%s' is here", dispname_str
);
5203 if (default_duration
) {
5204 if (p_def_timer
->default_duration
) {
5205 if (!default_duration
->is_unfoldable() &&
5206 !p_def_timer
->default_duration
->is_unfoldable() &&
5207 !(*default_duration
== *p_def_timer
->default_duration
)) {
5208 const char *dispname_str
= id
->get_dispname().c_str();
5209 default_duration
->warning("Local timer `%s' and the timer inherited "
5210 "from component type `%s' have different default durations",
5211 dispname_str
, p_def_timer
->get_my_scope()->get_fullname().c_str());
5212 p_def_timer
->note("The inherited timer `%s' is here", dispname_str
);
5215 const char *dispname_str
= id
->get_dispname().c_str();
5216 default_duration
->error("Local timer `%s' has default duration, but "
5217 "the timer inherited from component type `%s' does not", dispname_str
,
5218 p_def_timer
->get_my_scope()->get_fullname().c_str());
5219 p_def_timer
->note("The inherited timer `%s' is here", dispname_str
);
5222 } else if (p_def_timer
->default_duration
) {
5223 const char *dispname_str
= id
->get_dispname().c_str();
5224 error("Local timer `%s' does not have default duration, but the timer "
5225 "inherited from component type `%s' has", dispname_str
,
5226 p_def_timer
->get_my_scope()->get_fullname().c_str());
5227 p_def_timer
->note("The inherited timer `%s' is here", dispname_str
);
5233 bool Def_Timer::has_default_duration(FieldOrArrayRefs
*p_subrefs
)
5235 // return true in case of any uncertainity
5236 if (!default_duration
) return false;
5237 else if (!dimensions
|| !p_subrefs
) return true;
5238 Value
*v
= default_duration
;
5239 size_t nof_dims
= dimensions
->get_nof_dims();
5240 size_t nof_refs
= p_subrefs
->get_nof_refs();
5241 size_t upper_limit
= nof_dims
< nof_refs
? nof_dims
: nof_refs
;
5242 for (size_t i
= 0; i
< upper_limit
; i
++) {
5243 v
= v
->get_value_refd_last();
5244 if (v
->get_valuetype() != Value::V_SEQOF
) break;
5245 FieldOrArrayRef
*ref
= p_subrefs
->get_ref(i
);
5246 if (ref
->get_type() != FieldOrArrayRef::ARRAY_REF
) return true;
5247 Value
*v_index
= ref
->get_val()->get_value_refd_last();
5248 if (v_index
->get_valuetype() != Value::V_INT
) return true;
5249 Int index
= v_index
->get_val_Int()->get_val()
5250 - dimensions
->get_dim_byIndex(i
)->get_offset();
5251 if (index
>= 0 && index
< static_cast<Int
>(v
->get_nof_comps()))
5252 v
= v
->get_comp_byIndex(index
);
5255 return v
->get_valuetype() != Value::V_NOTUSED
;
5258 void Def_Timer::chk_single_duration(Value
*dur
)
5260 dur
->chk_expr_float(is_local() ?
5261 Type::EXPECTED_DYNAMIC_VALUE
: Type::EXPECTED_STATIC_VALUE
);
5262 Value
*v
= dur
->get_value_refd_last();
5263 if (v
->get_valuetype() == Value::V_REAL
) {
5264 ttcn3float v_real
= v
->get_val_Real();
5265 if ( (v_real
<0.0) || isSpecialFloatValue(v_real
) ) {
5266 dur
->error("A non-negative float value was expected "
5267 "as timer duration instead of `%s'", Real2string(v_real
).c_str());
5272 void Def_Timer::chk_array_duration(Value
*dur
, size_t start_dim
)
5274 ArrayDimension
*dim
= dimensions
->get_dim_byIndex(start_dim
);
5275 bool array_size_known
= !dim
->get_has_error();
5276 size_t array_size
= 0;
5277 if (array_size_known
) array_size
= dim
->get_size();
5278 Value
*v
= dur
->get_value_refd_last();
5279 switch (v
->get_valuetype()) {
5280 case Value::V_ERROR
:
5282 case Value::V_SEQOF
: {
5283 size_t nof_vs
= v
->get_nof_comps();
5284 // Value-list notation.
5285 if (!v
->is_indexed()) {
5286 if (array_size_known
) {
5287 if (array_size
> nof_vs
) {
5288 dur
->error("Too few elements in the default duration of timer "
5289 "array: %lu was expected instead of %lu",
5290 (unsigned long)array_size
, (unsigned long)nof_vs
);
5291 } else if (array_size
< nof_vs
) {
5292 dur
->error("Too many elements in the default duration of timer "
5293 "array: %lu was expected instead of %lu",
5294 (unsigned long)array_size
, (unsigned long)nof_vs
);
5297 bool last_dimension
= start_dim
+ 1 >= dimensions
->get_nof_dims();
5298 for (size_t i
= 0; i
< nof_vs
; i
++) {
5299 Value
*array_v
= v
->get_comp_byIndex(i
);
5300 if (array_v
->get_valuetype() == Value::V_NOTUSED
) continue;
5301 if (last_dimension
) chk_single_duration(array_v
);
5302 else chk_array_duration(array_v
, start_dim
+ 1);
5305 // Indexed-notation.
5306 bool last_dimension
= start_dim
+ 1 >= dimensions
->get_nof_dims();
5307 map
<Int
, Int
> index_map
;
5308 for (size_t i
= 0; i
< nof_vs
; i
++) {
5309 Value
*array_v
= v
->get_comp_byIndex(i
);
5310 if (array_v
->get_valuetype() == Value::V_NOTUSED
) continue;
5311 if (last_dimension
) chk_single_duration(array_v
);
5312 else chk_array_duration(array_v
, start_dim
+ 1);
5313 Error_Context
cntxt(this, "In timer array element %lu",
5314 (unsigned long)(i
+ 1));
5315 Value
*index
= v
->get_index_byIndex(i
);
5316 dim
->chk_index(index
, Type::EXPECTED_DYNAMIC_VALUE
);
5317 if (index
->get_value_refd_last()->get_valuetype() == Value::V_INT
) {
5318 const int_val_t
*index_int
= index
->get_value_refd_last()
5320 if (*index_int
> INT_MAX
) {
5321 index
->error("An integer value less than `%d' was expected for "
5322 "indexing timer array instead of `%s'", INT_MAX
,
5323 (index_int
->t_str()).c_str());
5324 index
->set_valuetype(Value::V_ERROR
);
5326 Int index_val
= index_int
->get_val();
5327 if (index_map
.has_key(index_val
)) {
5328 index
->error("Duplicate index value `%s' for timer array "
5329 "elements `%s' and `%s'",
5330 Int2string(index_val
).c_str(),
5331 Int2string((Int
)i
+ 1).c_str(),
5332 Int2string(*index_map
[index_val
]).c_str());
5333 index
->set_valuetype(Value::V_ERROR
);
5335 index_map
.add(index_val
, new Int((Int
)i
+ 1));
5340 // It's not possible to have "index_map.size() > array_size", since we
5341 // add only correct constant-index values into the map. It's possible
5342 // to create partially initialized timer arrays.
5343 for (size_t i
= 0; i
< index_map
.size(); i
++)
5344 delete index_map
.get_nth_elem(i
);
5349 if (array_size_known
) {
5350 dur
->error("An array value (with %lu elements) was expected as "
5351 "default duration of timer array",
5352 (unsigned long)array_size
);
5354 dur
->error("An array value was expected as default duration of timer "
5357 dur
->set_valuetype(Value::V_ERROR
);
5362 void Def_Timer::generate_code(output_struct
*target
, bool)
5364 const string
& t_genname
= get_genname();
5365 const char *genname_str
= t_genname
.c_str();
5366 const string
& dispname
= id
->get_dispname();
5369 const string
& array_type
= dimensions
->get_timer_type();
5370 const char *array_type_str
= array_type
.c_str();
5371 target
->header
.global_vars
= mputprintf(target
->header
.global_vars
,
5372 "extern %s %s;\n", array_type_str
, genname_str
);
5373 target
->source
.global_vars
= mputprintf(target
->source
.global_vars
,
5374 "%s %s;\n", array_type_str
, genname_str
);
5375 target
->functions
.pre_init
= mputstr(target
->functions
.pre_init
, "{\n"
5376 "static const char * const timer_name = \"");
5377 target
->functions
.pre_init
= mputstr(target
->functions
.pre_init
,
5379 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
5381 "%s.set_name(timer_name);\n"
5382 "}\n", genname_str
);
5383 if (default_duration
) target
->functions
.post_init
=
5384 generate_code_array_duration(target
->functions
.post_init
, genname_str
,
5388 target
->header
.global_vars
= mputprintf(target
->header
.global_vars
,
5389 "extern TIMER %s;\n", genname_str
);
5390 if (default_duration
) {
5391 // has default duration
5392 Value
*v
= default_duration
->get_value_refd_last();
5393 if (v
->get_valuetype() == Value::V_REAL
) {
5394 // duration is known at compilation time -> set in the constructor
5395 target
->source
.global_vars
= mputprintf(target
->source
.global_vars
,
5396 "TIMER %s(\"%s\", %s);\n", genname_str
, dispname
.c_str(),
5397 v
->get_single_expr().c_str());
5399 // duration is known only at runtime -> set in post_init
5400 target
->source
.global_vars
= mputprintf(target
->source
.global_vars
,
5401 "TIMER %s(\"%s\");\n", genname_str
, dispname
.c_str());
5402 expression_struct expr
;
5403 Code::init_expr(&expr
);
5404 expr
.expr
= mputprintf(expr
.expr
, "%s.set_default_duration(",
5406 default_duration
->generate_code_expr(&expr
);
5407 expr
.expr
= mputc(expr
.expr
, ')');
5408 target
->functions
.post_init
=
5409 Code::merge_free_expr(target
->functions
.post_init
, &expr
);
5412 // does not have default duration
5413 target
->source
.global_vars
= mputprintf(target
->source
.global_vars
,
5414 "TIMER %s(\"%s\");\n", genname_str
, dispname
.c_str());
5419 void Def_Timer::generate_code(CodeGenHelper
& cgh
) {
5420 generate_code(cgh
.get_current_outputstruct());
5423 char *Def_Timer::generate_code_array_duration(char *str
,
5424 const char *object_name
, Value
*dur
, size_t start_dim
)
5426 ArrayDimension
*dim
= dimensions
->get_dim_byIndex(start_dim
);
5427 size_t dim_size
= dim
->get_size();
5428 Value
*v
= dur
->get_value_refd_last();
5429 if (v
->get_valuetype() != Value::V_SEQOF
5430 || (v
->get_nof_comps() != dim_size
&& !v
->is_indexed()))
5431 FATAL_ERROR("Def_Timer::generate_code_array_duration()");
5432 // Value-list notation.
5433 if (!v
->is_indexed()) {
5434 if (start_dim
+ 1 < dimensions
->get_nof_dims()) {
5435 // There are more dimensions, the elements of "v" are arrays a
5436 // temporary reference shall be introduced if the next dimension has
5437 // more than 1 elements.
5438 bool temp_ref_needed
=
5439 dimensions
->get_dim_byIndex(start_dim
+ 1)->get_size() > 1;
5440 for (size_t i
= 0; i
< dim_size
; i
++) {
5441 Value
*v_elem
= v
->get_comp_byIndex(i
);
5442 if (v_elem
->get_valuetype() == Value::V_NOTUSED
) continue;
5443 if (temp_ref_needed
) {
5444 const string
& tmp_id
= my_scope
->get_scope_mod_gen()
5445 ->get_temporary_id();
5446 const char *tmp_str
= tmp_id
.c_str();
5447 str
= mputprintf(str
, "{\n"
5448 "%s& %s = %s.array_element(%lu);\n",
5449 dimensions
->get_timer_type(start_dim
+ 1).c_str(),
5450 tmp_str
, object_name
, (unsigned long)i
);
5451 str
= generate_code_array_duration(str
, tmp_str
, v_elem
,
5453 str
= mputstr(str
, "}\n");
5455 char *tmp_str
= mprintf("%s.array_element(%lu)", object_name
,
5457 str
= generate_code_array_duration(str
, tmp_str
, v_elem
,
5463 // We are in the last dimension, the elements of "v" are floats.
5464 for (size_t i
= 0; i
< dim_size
; i
++) {
5465 Value
*v_elem
= v
->get_comp_byIndex(i
);
5466 if (v_elem
->get_valuetype() == Value::V_NOTUSED
) continue;
5467 expression_struct expr
;
5468 Code::init_expr(&expr
);
5469 expr
.expr
= mputprintf(expr
.expr
,
5470 "%s.array_element(%lu).set_default_duration(",
5471 object_name
, (unsigned long)i
);
5472 v_elem
->generate_code_expr(&expr
);
5473 expr
.expr
= mputc(expr
.expr
, ')');
5474 str
= Code::merge_free_expr(str
, &expr
);
5477 // Indexed-list notation.
5479 if (start_dim
+ 1 < dimensions
->get_nof_dims()) {
5480 bool temp_ref_needed
=
5481 dimensions
->get_dim_byIndex(start_dim
+ 1)->get_size() > 1;
5482 for (size_t i
= 0; i
< v
->get_nof_comps(); i
++) {
5483 Value
*v_elem
= v
->get_comp_byIndex(i
);
5484 if (v_elem
->get_valuetype() == Value::V_NOTUSED
) continue;
5485 if (temp_ref_needed
) {
5486 const string
& tmp_id
= my_scope
->get_scope_mod_gen()
5487 ->get_temporary_id();
5488 const string
& idx_id
= my_scope
->get_scope_mod_gen()
5489 ->get_temporary_id();
5490 const char *tmp_str
= tmp_id
.c_str();
5491 str
= mputstr(str
, "{\n");
5492 str
= mputprintf(str
, "int %s;\n", idx_id
.c_str());
5493 str
= v
->get_index_byIndex(i
)->generate_code_init(str
,
5495 str
= mputprintf(str
, "%s& %s = %s.array_element(%s);\n",
5496 dimensions
->get_timer_type(start_dim
+ 1).c_str(),
5497 tmp_str
, object_name
, idx_id
.c_str());
5498 str
= generate_code_array_duration(str
, tmp_str
, v_elem
,
5500 str
= mputstr(str
, "}\n");
5502 const string
& idx_id
= my_scope
->get_scope_mod_gen()
5503 ->get_temporary_id();
5504 str
= mputstr(str
, "{\n");
5505 str
= mputprintf(str
, "int %s;\n", idx_id
.c_str());
5506 str
= v
->get_index_byIndex(i
)->generate_code_init(str
,
5508 char *tmp_str
= mprintf("%s.array_element(%s)", object_name
,
5510 str
= generate_code_array_duration(str
, tmp_str
, v_elem
,
5512 str
= mputstr(str
, "}\n");
5517 for (size_t i
= 0; i
< v
->get_nof_comps(); i
++) {
5518 Value
*v_elem
= v
->get_comp_byIndex(i
);
5519 if (v_elem
->get_valuetype() == Value::V_NOTUSED
) continue;
5520 expression_struct expr
;
5521 Code::init_expr(&expr
);
5522 str
= mputstr(str
, "{\n");
5523 const string
& idx_id
= my_scope
->get_scope_mod_gen()
5524 ->get_temporary_id();
5525 str
= mputprintf(str
, "int %s;\n", idx_id
.c_str());
5526 str
= v
->get_index_byIndex(i
)->generate_code_init(str
,
5528 str
= mputprintf(str
,
5529 "%s.array_element(%s).set_default_duration(",
5530 object_name
, idx_id
.c_str());
5531 v_elem
->generate_code_expr(&expr
);
5532 expr
.expr
= mputc(expr
.expr
, ')');
5533 str
= Code::merge_free_expr(str
, &expr
);
5534 str
= mputstr(str
, "}\n");
5541 char *Def_Timer::generate_code_str(char *str
)
5543 const string
& t_genname
= get_genname();
5544 const char *genname_str
= t_genname
.c_str();
5545 const string
& dispname
= id
->get_dispname();
5548 const string
& array_type
= dimensions
->get_timer_type();
5549 const char *array_type_str
= array_type
.c_str();
5550 str
= mputprintf(str
, "%s %s;\n", array_type_str
, genname_str
);
5551 str
= mputstr(str
, "{\n"
5552 "static const char * const timer_name = \"");
5553 str
= mputstr(str
, dispname
.c_str());
5554 str
= mputprintf(str
, "\";\n"
5555 "%s.set_name(timer_name);\n"
5556 "}\n", genname_str
);
5557 if (default_duration
) str
= generate_code_array_duration(str
,
5558 genname_str
, default_duration
);
5561 if (default_duration
&& default_duration
->has_single_expr()) {
5562 // the default duration can be passed to the constructor
5563 str
= mputprintf(str
, "TIMER %s(\"%s\", %s);\n", genname_str
,
5564 dispname
.c_str(), default_duration
->get_single_expr().c_str());
5566 // only the name is passed to the constructor
5567 str
= mputprintf(str
, "TIMER %s(\"%s\");\n", genname_str
,
5569 if (default_duration
) {
5570 // the default duration is set explicitly
5571 expression_struct expr
;
5572 Code::init_expr(&expr
);
5573 expr
.expr
= mputprintf(expr
.expr
, "%s.set_default_duration(",
5575 default_duration
->generate_code_expr(&expr
);
5576 expr
.expr
= mputc(expr
.expr
, ')');
5577 str
= Code::merge_free_expr(str
, &expr
);
5581 if (debugger_active
) {
5582 str
= generate_code_debugger_add_var(str
, this);
5587 void Def_Timer::ilt_generate_code(ILT
*ilt
)
5589 const string
& t_genname
= get_genname();
5590 const char *genname_str
= t_genname
.c_str();
5591 const string
& dispname
= id
->get_dispname();
5593 char*& def
= ilt
->get_out_def();
5594 char*& init
= ilt
->get_out_branches();
5598 const string
& array_type
= dimensions
->get_timer_type();
5599 const char *array_type_str
= array_type
.c_str();
5600 def
= mputprintf(def
, "%s %s;\n", array_type_str
, genname_str
);
5601 def
= mputstr(def
, "{\n"
5602 "static const char * const timer_names[] = { ");
5603 def
= dimensions
->generate_element_names(def
, dispname
);
5604 def
= mputprintf(def
, " };\n"
5605 "%s.set_name(%lu, timer_names);\n"
5606 "}\n", genname_str
, (unsigned long) dimensions
->get_array_size());
5607 if (default_duration
) init
= generate_code_array_duration(init
,
5608 genname_str
, default_duration
);
5611 if (default_duration
) {
5612 // has default duration
5613 Value
*v
= default_duration
->get_value_refd_last();
5614 if (v
->get_valuetype() == Value::V_REAL
) {
5615 // duration is known at compilation time -> set in the constructor
5616 def
= mputprintf(def
, "TIMER %s(\"%s\", %s);\n", genname_str
,
5617 dispname
.c_str(), v
->get_single_expr().c_str());
5619 // duration is known only at runtime -> set when control reaches the
5621 def
= mputprintf(def
, "TIMER %s(\"%s\");\n", genname_str
,
5623 expression_struct expr
;
5624 Code::init_expr(&expr
);
5625 expr
.expr
= mputprintf(expr
.expr
, "%s.set_default_duration(",
5627 default_duration
->generate_code_expr(&expr
);
5628 expr
.expr
= mputc(expr
.expr
, ')');
5629 init
= Code::merge_free_expr(init
, &expr
);
5632 // does not have default duration
5633 def
= mputprintf(def
, "TIMER %s(\"%s\");\n", genname_str
,
5639 char *Def_Timer::generate_code_init_comp(char *str
, Definition
*base_defn
)
5641 if (default_duration
) {
5642 Def_Timer
*base_timer_defn
= dynamic_cast<Def_Timer
*>(base_defn
);
5643 if (!base_timer_defn
|| !base_timer_defn
->default_duration
)
5644 FATAL_ERROR("Def_Timer::generate_code_init_comp()");
5645 // initializer is not needed if the default durations are the same
5646 // constants in both timers
5647 if (default_duration
->is_unfoldable() ||
5648 base_timer_defn
->default_duration
->is_unfoldable() ||
5649 !(*default_duration
== *base_timer_defn
->default_duration
)) {
5651 str
= generate_code_array_duration(str
,
5652 base_timer_defn
->get_genname_from_scope(my_scope
).c_str(),
5655 expression_struct expr
;
5656 Code::init_expr(&expr
);
5657 expr
.expr
= mputprintf(expr
.expr
, "%s.set_default_duration(",
5658 base_timer_defn
->get_genname_from_scope(my_scope
).c_str());
5659 default_duration
->generate_code_expr(&expr
);
5660 expr
.expr
= mputc(expr
.expr
, ')');
5661 str
= Code::merge_free_expr(str
, &expr
);
5668 void Def_Timer::dump_internal(unsigned level
) const
5670 DEBUG(level
, "Timer: %s", id
->get_dispname().c_str());
5671 if (dimensions
) dimensions
->dump(level
+ 1);
5672 if (default_duration
) {
5673 DEBUG(level
+ 1, "Default duration:");
5674 default_duration
->dump(level
+ 1);
5678 // =================================
5680 // =================================
5682 Def_Port::Def_Port(Identifier
*p_id
, Reference
*p_tref
,
5683 ArrayDimensions
*p_dims
)
5684 : Definition(A_PORT
, p_id
), type_ref(p_tref
), port_type(0),
5687 if (!p_tref
) FATAL_ERROR("Def_Port::Def_Port()");
5690 Def_Port::~Def_Port()
5696 Def_Port
*Def_Port::clone() const
5698 FATAL_ERROR("Def_Port::clone");
5701 void Def_Port::set_fullname(const string
& p_fullname
)
5703 Definition::set_fullname(p_fullname
);
5704 type_ref
->set_fullname(p_fullname
+ ".<type_ref>");
5705 if (dimensions
) dimensions
->set_fullname(p_fullname
);
5708 void Def_Port::set_my_scope(Scope
*p_scope
)
5710 Definition::set_my_scope(p_scope
);
5711 type_ref
->set_my_scope(p_scope
);
5712 if (dimensions
) dimensions
->set_my_scope(p_scope
);
5715 Type
*Def_Port::get_Type()
5721 ArrayDimensions
*Def_Port::get_Dimensions()
5723 if (!checked
) chk();
5727 void Def_Port::chk()
5729 if (checked
) return;
5731 Error_Context
cntxt(this, "In port definition `%s'",
5732 id
->get_dispname().c_str());
5733 Common::Assignment
*ass
= type_ref
->get_refd_assignment();
5735 if (ass
->get_asstype() == A_TYPE
) {
5736 Type
*t
= ass
->get_Type()->get_type_refd_last();
5737 if (t
->get_typetype() == Type::T_PORT
) port_type
= t
;
5738 else type_ref
->error("Type reference `%s' does not refer to a "
5739 "port type", type_ref
->get_dispname().c_str());
5740 } else type_ref
->error("Reference `%s' does not refer to a "
5741 "type", type_ref
->get_dispname().c_str());
5743 if (dimensions
) dimensions
->chk();
5744 if (w_attrib_path
) {
5745 w_attrib_path
->chk_global_attrib();
5746 w_attrib_path
->chk_no_qualif();
5750 bool Def_Port::chk_identical(Definition
*p_def
)
5754 if (p_def
->get_asstype() != A_PORT
) {
5755 const char *dispname_str
= id
->get_dispname().c_str();
5756 error("Local definition `%s' is a port, but the definition inherited "
5757 "from component type `%s' is a %s", dispname_str
,
5758 p_def
->get_my_scope()->get_fullname().c_str(), p_def
->get_assname());
5759 p_def
->note("The inherited definition of `%s' is here", dispname_str
);
5762 Def_Port
*p_def_port
= dynamic_cast<Def_Port
*>(p_def
);
5763 if (!p_def_port
) FATAL_ERROR("Def_Port::chk_identical()");
5764 if (port_type
&& p_def_port
->port_type
&&
5765 port_type
!= p_def_port
->port_type
) {
5766 const char *dispname_str
= id
->get_dispname().c_str();
5767 type_ref
->error("Local port `%s' has type `%s', but the port inherited "
5768 "from component type `%s' has type `%s'", dispname_str
,
5769 port_type
->get_typename().c_str(),
5770 p_def_port
->get_my_scope()->get_fullname().c_str(),
5771 p_def_port
->port_type
->get_typename().c_str());
5772 p_def_port
->note("The inherited port `%s' is here", dispname_str
);
5776 if (p_def_port
->dimensions
) {
5777 if (!dimensions
->is_identical(p_def_port
->dimensions
)) {
5778 const char *dispname_str
= id
->get_dispname().c_str();
5779 error("Local port `%s' and the port inherited from component type "
5780 "`%s' have different array dimensions", dispname_str
,
5781 p_def_port
->get_my_scope()->get_fullname().c_str());
5782 p_def_port
->note("The inherited port `%s' is here", dispname_str
);
5786 const char *dispname_str
= id
->get_dispname().c_str();
5787 error("Local definition `%s' is a port array, but the definition "
5788 "inherited from component type `%s' is a single port", dispname_str
,
5789 p_def_port
->get_my_scope()->get_fullname().c_str());
5790 p_def_port
->note("The inherited port `%s' is here", dispname_str
);
5793 } else if (p_def_port
->dimensions
) {
5794 const char *dispname_str
= id
->get_dispname().c_str();
5795 error("Local definition `%s' is a single port, but the definition "
5796 "inherited from component type `%s' is a port array", dispname_str
,
5797 p_def_port
->get_my_scope()->get_fullname().c_str());
5798 p_def_port
->note("The inherited port `%s' is here", dispname_str
);
5804 void Def_Port::generate_code(output_struct
*target
, bool)
5806 const string
& t_genname
= get_genname();
5807 const char *genname_str
= t_genname
.c_str();
5808 const string
& type_genname
= port_type
->get_genname_value(my_scope
);
5809 const string
& dispname
= id
->get_dispname();
5812 const string
& array_type
= dimensions
->get_port_type(type_genname
);
5813 const char *array_type_str
= array_type
.c_str();
5814 target
->header
.global_vars
= mputprintf(target
->header
.global_vars
,
5815 "extern %s %s;\n", array_type_str
, genname_str
);
5816 target
->source
.global_vars
= mputprintf(target
->source
.global_vars
,
5817 "%s %s;\n", array_type_str
, genname_str
);
5818 target
->functions
.pre_init
= mputstr(target
->functions
.pre_init
, "{\n"
5819 "static const char * const port_name = \"");
5820 target
->functions
.pre_init
= mputstr(target
->functions
.pre_init
,
5822 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
5824 "%s.set_name(port_name);\n"
5825 "}\n", genname_str
);
5828 const char *type_genname_str
= type_genname
.c_str();
5829 target
->header
.global_vars
= mputprintf(target
->header
.global_vars
,
5830 "extern %s %s;\n", type_genname_str
, genname_str
);
5831 target
->source
.global_vars
= mputprintf(target
->source
.global_vars
,
5832 "%s %s(\"%s\");\n", type_genname_str
, genname_str
, dispname
.c_str());
5834 target
->functions
.init_comp
= mputprintf(target
->functions
.init_comp
,
5835 "%s.activate_port();\n", genname_str
);
5838 void Def_Port::generate_code(CodeGenHelper
& cgh
) {
5839 generate_code(cgh
.get_current_outputstruct());
5842 char *Def_Port::generate_code_init_comp(char *str
, Definition
*base_defn
)
5844 return mputprintf(str
, "%s.activate_port();\n",
5845 base_defn
->get_genname_from_scope(my_scope
).c_str());
5848 void Def_Port::dump_internal(unsigned level
) const
5850 DEBUG(level
, "Port: %s", id
->get_dispname().c_str());
5851 DEBUG(level
+ 1, "Port type:");
5852 type_ref
->dump(level
+ 2);
5853 if (dimensions
) dimensions
->dump(level
+ 1);
5856 // =================================
5857 // ===== Def_Function_Base
5858 // =================================
5860 Def_Function_Base::asstype_t
Def_Function_Base::determine_asstype(
5861 bool is_external
, bool has_return_type
, bool returns_template
)
5864 if (has_return_type
) {
5865 if (returns_template
) return A_EXT_FUNCTION_RTEMP
;
5866 else return A_EXT_FUNCTION_RVAL
;
5868 if (returns_template
)
5869 FATAL_ERROR("Def_Function_Base::determine_asstype()");
5870 return A_EXT_FUNCTION
;
5872 } else { // not an external function
5873 if (has_return_type
) {
5874 if (returns_template
) return A_FUNCTION_RTEMP
;
5875 else return A_FUNCTION_RVAL
;
5877 if (returns_template
)
5878 FATAL_ERROR("Def_Function_Base::determine_asstype()");
5884 Def_Function_Base::Def_Function_Base(const Def_Function_Base
& p
)
5885 : Definition(p
), prototype(PROTOTYPE_NONE
), input_type(0), output_type(0)
5887 fp_list
= p
.fp_list
->clone();
5888 fp_list
->set_my_def(this);
5889 return_type
= p
.return_type
? p
.return_type
->clone() : 0;
5890 template_restriction
= p
.template_restriction
;
5893 Def_Function_Base::Def_Function_Base(bool is_external
, Identifier
*p_id
,
5894 FormalParList
*p_fpl
, Type
*p_return_type
, bool returns_template
,
5895 template_restriction_t p_template_restriction
)
5896 : Definition(determine_asstype(is_external
, p_return_type
!= 0,
5897 returns_template
), p_id
), fp_list(p_fpl
), return_type(p_return_type
),
5898 prototype(PROTOTYPE_NONE
), input_type(0), output_type(0),
5899 template_restriction(p_template_restriction
)
5901 if (!p_fpl
) FATAL_ERROR("Def_Function_Base::Def_Function_Base()");
5902 fp_list
->set_my_def(this);
5903 if (return_type
) return_type
->set_ownertype(Type::OT_FUNCTION_DEF
, this);
5906 Def_Function_Base::~Def_Function_Base()
5912 void Def_Function_Base::set_fullname(const string
& p_fullname
)
5914 Definition::set_fullname(p_fullname
);
5915 fp_list
->set_fullname(p_fullname
+ ".<formal_par_list>");
5916 if (return_type
) return_type
->set_fullname(p_fullname
+ ".<return_type>");
5919 void Def_Function_Base::set_my_scope(Scope
*p_scope
)
5921 Definition::set_my_scope(p_scope
);
5922 fp_list
->set_my_scope(p_scope
);
5923 if (return_type
) return_type
->set_my_scope(p_scope
);
5926 Type
*Def_Function_Base::get_Type()
5928 if (!checked
) chk();
5932 FormalParList
*Def_Function_Base::get_FormalParList()
5934 if (!checked
) chk();
5938 const char *Def_Function_Base::get_prototype_name() const
5940 switch (prototype
) {
5941 case PROTOTYPE_NONE
:
5942 return "<no prototype>";
5943 case PROTOTYPE_CONVERT
:
5945 case PROTOTYPE_FAST
:
5947 case PROTOTYPE_BACKTRACK
:
5949 case PROTOTYPE_SLIDING
:
5952 return "<unknown prototype>";
5956 void Def_Function_Base::chk_prototype()
5958 switch (prototype
) {
5959 case PROTOTYPE_NONE
:
5960 // return immediately
5962 case PROTOTYPE_CONVERT
:
5963 case PROTOTYPE_FAST
:
5964 case PROTOTYPE_BACKTRACK
:
5965 case PROTOTYPE_SLIDING
:
5966 // perform the checks below
5969 FATAL_ERROR("Def_Function_Base::chk_prototype()");
5971 // checking the formal parameter list
5972 if (prototype
== PROTOTYPE_CONVERT
) {
5973 if (fp_list
->get_nof_fps() == 1) {
5974 FormalPar
*par
= fp_list
->get_fp_byIndex(0);
5975 if (par
->get_asstype() == A_PAR_VAL_IN
) {
5976 input_type
= par
->get_Type();
5978 par
->error("The parameter must be an `in' value parameter for "
5979 "attribute `prototype(%s)' instead of %s", get_prototype_name(),
5980 par
->get_assname());
5983 fp_list
->error("The function must have one parameter instead of %lu "
5984 "for attribute `prototype(%s)'", (unsigned long) fp_list
->get_nof_fps(),
5985 get_prototype_name());
5987 } else { // not PROTOTYPE_CONVERT
5988 if (fp_list
->get_nof_fps() == 2) {
5989 FormalPar
*first_par
= fp_list
->get_fp_byIndex(0);
5990 if (prototype
== PROTOTYPE_SLIDING
) {
5991 if (first_par
->get_asstype() == A_PAR_VAL_INOUT
) {
5992 Type
*first_par_type
= first_par
->get_Type();
5993 switch (first_par_type
->get_type_refd_last()
5994 ->get_typetype_ttcn3()) {
5999 input_type
= first_par_type
;
6002 first_par_type
->error("The type of the first parameter must be "
6003 "`octetstring' or `charstring' or `bitstring' for attribute "
6004 "`prototype(%s)' instead of `%s'", get_prototype_name(),
6005 first_par_type
->get_typename().c_str());
6008 first_par
->error("The first parameter must be an `inout' value "
6009 "parameter for attribute `prototype(%s)' instead of %s",
6010 get_prototype_name(), first_par
->get_assname());
6013 if (first_par
->get_asstype() == A_PAR_VAL_IN
) {
6014 input_type
= first_par
->get_Type();
6016 first_par
->error("The first parameter must be an `in' value "
6017 "parameter for attribute `prototype(%s)' instead of %s",
6018 get_prototype_name(), first_par
->get_assname());
6021 FormalPar
*second_par
= fp_list
->get_fp_byIndex(1);
6022 if (second_par
->get_asstype() == A_PAR_VAL_OUT
) {
6023 output_type
= second_par
->get_Type();
6025 second_par
->error("The second parameter must be an `out' value "
6026 "parameter for attribute `prototype(%s)' instead of %s",
6027 get_prototype_name(), second_par
->get_assname());
6030 fp_list
->error("The function must have two parameters for attribute "
6031 "`prototype(%s)' instead of %lu", get_prototype_name(),
6032 (unsigned long) fp_list
->get_nof_fps());
6035 // checking the return type
6036 if (prototype
== PROTOTYPE_FAST
) {
6038 return_type
->error("The function cannot have return type for "
6039 "attribute `prototype(%s)'", get_prototype_name());
6043 if (asstype
== A_FUNCTION_RTEMP
|| asstype
== A_EXT_FUNCTION_RTEMP
)
6044 return_type
->error("The function must return a value instead of a "
6045 "template for attribute `prototype(%s)'", get_prototype_name());
6046 if (prototype
== PROTOTYPE_CONVERT
) {
6047 output_type
= return_type
;
6049 switch (return_type
->get_type_refd_last()->get_typetype_ttcn3()) {
6054 return_type
->error("The return type of the function must be "
6055 "`integer' instead of `%s' for attribute `prototype(%s)'",
6056 return_type
->get_typename().c_str(), get_prototype_name());
6060 error("The function must have return type for attribute "
6061 "`prototype(%s)'", get_prototype_name());
6064 // checking the 'runs on' clause
6065 if (get_RunsOnType()) {
6066 error("The function cannot have `runs on' clause for attribute "
6067 "`prototype(%s)'", get_prototype_name());
6071 Type
*Def_Function_Base::get_input_type()
6073 if (!checked
) chk();
6077 Type
*Def_Function_Base::get_output_type()
6079 if (!checked
) chk();
6084 // =================================
6085 // ===== Def_Function
6086 // =================================
6088 Def_Function::Def_Function(Identifier
*p_id
, FormalParList
*p_fpl
,
6089 Reference
*p_runs_on_ref
, Type
*p_return_type
,
6090 bool returns_template
,
6091 template_restriction_t p_template_restriction
,
6092 StatementBlock
*p_block
)
6093 : Def_Function_Base(false, p_id
, p_fpl
, p_return_type
, returns_template
,
6094 p_template_restriction
),
6095 runs_on_ref(p_runs_on_ref
), runs_on_type(0), block(p_block
),
6096 is_startable(false), transparent(false)
6098 if (!p_block
) FATAL_ERROR("Def_Function::Def_Function()");
6099 block
->set_my_def(this);
6102 Def_Function::~Def_Function()
6108 Def_Function
*Def_Function::clone() const
6110 FATAL_ERROR("Def_Function::clone");
6113 void Def_Function::set_fullname(const string
& p_fullname
)
6115 Def_Function_Base::set_fullname(p_fullname
);
6116 if (runs_on_ref
) runs_on_ref
->set_fullname(p_fullname
+ ".<runs_on_type>");
6117 block
->set_fullname(p_fullname
+ ".<statement_block>");
6120 void Def_Function::set_my_scope(Scope
*p_scope
)
6122 bridgeScope
.set_parent_scope(p_scope
);
6123 bridgeScope
.set_scopeMacro_name(id
->get_dispname());
6125 Def_Function_Base::set_my_scope(&bridgeScope
);
6126 if (runs_on_ref
) runs_on_ref
->set_my_scope(&bridgeScope
);
6127 block
->set_my_scope(fp_list
);
6130 Type
*Def_Function::get_RunsOnType()
6132 if (!checked
) chk();
6133 return runs_on_type
;
6136 RunsOnScope
*Def_Function::get_runs_on_scope(Type
*comptype
)
6138 Module
*my_module
= dynamic_cast<Module
*>(my_scope
->get_scope_mod());
6139 if (!my_module
) FATAL_ERROR("Def_Function::get_runs_on_scope()");
6140 return my_module
->get_runs_on_scope(comptype
);
6143 void Def_Function::chk()
6145 if (checked
) return;
6147 Error_Context
cntxt(this, "In function definition `%s'",
6148 id
->get_dispname().c_str());
6149 // checking the `runs on' clause
6151 Error_Context
cntxt2(runs_on_ref
, "In `runs on' clause");
6152 runs_on_type
= runs_on_ref
->chk_comptype_ref();
6153 // override the scope of the formal parameter list
6155 Scope
*runs_on_scope
= get_runs_on_scope(runs_on_type
);
6156 runs_on_scope
->set_parent_scope(my_scope
);
6157 fp_list
->set_my_scope(runs_on_scope
);
6160 // checking the formal parameter list
6161 fp_list
->chk(asstype
);
6162 // checking of return type
6164 Error_Context
cntxt2(return_type
, "In return type");
6166 return_type
->chk_as_return_type(asstype
== A_FUNCTION_RVAL
,"function");
6168 // decision of startability
6169 is_startable
= runs_on_ref
!= 0;
6170 if (is_startable
&& !fp_list
->get_startability()) is_startable
= false;
6171 if (is_startable
&& return_type
&& return_type
->is_component_internal())
6172 is_startable
= false;
6173 // checking of statement block
6176 // checking the presence of return statements
6177 switch (block
->has_return()) {
6178 case StatementBlock::RS_NO
:
6179 error("The function has return type, but it does not have any return "
6182 case StatementBlock::RS_MAYBE
:
6183 error("The function has return type, but control might leave it "
6184 "without reaching a return statement");
6189 if (!semantic_check_only
) {
6190 fp_list
->set_genname(get_genname());
6191 block
->set_code_section(GovernedSimple::CS_INLINE
);
6193 if (w_attrib_path
) {
6194 w_attrib_path
->chk_global_attrib();
6195 w_attrib_path
->chk_no_qualif();
6196 Ttcn::ExtensionAttributes
* extattrs
= parse_extattributes(w_attrib_path
);
6197 if (extattrs
!= 0) { // NULL means parsing error
6198 size_t num_atrs
= extattrs
->size();
6199 for (size_t i
=0; i
< num_atrs
; ++i
) {
6200 ExtensionAttribute
&ea
= extattrs
->get(i
);
6201 switch (ea
.get_type()) {
6202 case ExtensionAttribute::PROTOTYPE
: {
6203 if (get_prototype() != Def_Function_Base::PROTOTYPE_NONE
) {
6204 ea
.error("Duplicate attribute `prototype'");
6206 Def_Function_Base::prototype_t proto
= ea
.get_proto();
6207 set_prototype(proto
);
6210 case ExtensionAttribute::ANYTYPELIST
: // ignore it
6211 case ExtensionAttribute::NONE
: // erroneous, do not issue an error
6214 case ExtensionAttribute::TRANSPARENT
:
6218 case ExtensionAttribute::ENCODE
:
6219 case ExtensionAttribute::DECODE
:
6220 case ExtensionAttribute::ERRORBEHAVIOR
:
6221 case ExtensionAttribute::PRINTING
:
6222 ea
.error("Extension attribute 'encode', 'decode', 'errorbehavior'"
6223 " or 'printing' can only be applied to external functions");
6226 default: // complain
6227 ea
.error("Function definition can only have the 'prototype'"
6228 " extension attribute");
6238 bool Def_Function::chk_startable()
6240 if (!checked
) chk();
6241 if (is_startable
) return true;
6242 if (!runs_on_ref
) error("Function `%s' cannot be started on a parallel "
6243 "test component because it does not have `runs on' clause",
6244 get_fullname().c_str());
6245 fp_list
->chk_startability("Function", get_fullname().c_str());
6246 if (return_type
&& return_type
->is_component_internal()) {
6247 map
<Type
*,void> type_chain
;
6248 char* err_str
= mprintf("the return type or embedded in the return type "
6249 "of function `%s' if it is started on a parallel test component",
6250 get_fullname().c_str());
6251 return_type
->chk_component_internal(type_chain
, err_str
);
6257 void Def_Function::generate_code(output_struct
*target
, bool)
6259 transparency_holder
glass(*this);
6260 const string
& t_genname
= get_genname();
6261 const char *genname_str
= t_genname
.c_str();
6262 const char *dispname_str
= id
->get_dispname().c_str();
6263 string return_type_name
;
6266 return_type_name
= "void";
6268 case A_FUNCTION_RVAL
:
6269 return_type_name
= return_type
->get_genname_value(my_scope
);
6271 case A_FUNCTION_RTEMP
:
6272 return_type_name
= return_type
->get_genname_template(my_scope
);
6275 FATAL_ERROR("Def_Function::generate_code()");
6277 const char *return_type_str
= return_type_name
.c_str();
6279 // assemble the function body first (this also determines which parameters
6281 char* body
= create_location_object(memptystr(), "FUNCTION", dispname_str
);
6282 if (!enable_set_bound_out_param
)
6283 body
= fp_list
->generate_code_set_unbound(body
); // conform the standard out parameter is unbound
6284 body
= fp_list
->generate_shadow_objects(body
);
6285 if (debugger_active
) {
6286 body
= generate_code_debugger_function_init(body
, this);
6288 body
= block
->generate_code(body
);
6289 // smart formal parameter list (names of unused parameters are omitted)
6290 char *formal_par_list
= fp_list
->generate_code(memptystr());
6291 fp_list
->generate_code_defval(target
);
6292 // function prototype
6293 target
->header
.function_prototypes
=
6294 mputprintf(target
->header
.function_prototypes
, "extern %s %s(%s);\n",
6295 return_type_str
, genname_str
, formal_par_list
);
6298 target
->source
.function_bodies
= mputprintf(target
->source
.function_bodies
,
6302 "}\n\n", return_type_str
, genname_str
, formal_par_list
, body
);
6303 Free(formal_par_list
);
6307 size_t nof_fps
= fp_list
->get_nof_fps();
6308 // use the full list of formal parameters here (since they are all logged)
6309 char *full_formal_par_list
= fp_list
->generate_code(memptystr(), nof_fps
);
6310 // starter function (stub)
6311 // function prototype
6312 target
->header
.function_prototypes
=
6313 mputprintf(target
->header
.function_prototypes
,
6314 "extern void start_%s(const COMPONENT& component_reference%s%s);\n",
6315 genname_str
, nof_fps
>0?", ":"", full_formal_par_list
);
6317 body
= mprintf("void start_%s(const COMPONENT& component_reference%s"
6320 "TTCN_Logger::begin_event(TTCN_Logger::PARALLEL_PTC);\n"
6321 "TTCN_Logger::log_event_str(\"Starting function %s(\");\n",
6322 genname_str
, nof_fps
>0?", ":"", full_formal_par_list
, dispname_str
);
6323 for (size_t i
= 0; i
< nof_fps
; i
++) {
6324 if (i
> 0) body
= mputstr(body
,
6325 "TTCN_Logger::log_event_str(\", \");\n");
6326 body
= mputprintf(body
, "%s.log();\n",
6327 fp_list
->get_fp_byIndex(i
)->get_reference_name(my_scope
).c_str());
6329 body
= mputprintf(body
,
6330 "TTCN_Logger::log_event_str(\") on component \");\n"
6331 "component_reference.log();\n"
6332 "TTCN_Logger::log_char('.');\n"
6333 "TTCN_Logger::end_event();\n"
6334 "Text_Buf text_buf;\n"
6335 "TTCN_Runtime::prepare_start_component(component_reference, "
6336 "\"%s\", \"%s\", text_buf);\n",
6337 my_scope
->get_scope_mod()->get_modid().get_dispname().c_str(),
6339 for (size_t i
= 0; i
< nof_fps
; i
++) {
6340 body
= mputprintf(body
, "%s.encode_text(text_buf);\n",
6341 fp_list
->get_fp_byIndex(i
)->get_reference_name(my_scope
).c_str());
6343 body
= mputstr(body
, "TTCN_Runtime::send_start_component(text_buf);\n"
6345 target
->source
.function_bodies
= mputstr(target
->source
.function_bodies
,
6349 // an entry in start_ptc_function
6350 body
= mprintf("if (!strcmp(function_name, \"%s\")) {\n",
6353 body
= fp_list
->generate_code_object(body
, "", ' ');
6354 for (size_t i
= 0; i
< nof_fps
; i
++) {
6355 body
= mputprintf(body
, "%s.decode_text(function_arguments);\n",
6356 fp_list
->get_fp_byIndex(i
)->get_reference_name(my_scope
).c_str());
6358 body
= mputprintf(body
,
6359 "TTCN_Logger::begin_event(TTCN_Logger::PARALLEL_PTC);\n"
6360 "TTCN_Logger::log_event_str(\"Starting function %s(\");\n",
6362 for (size_t i
= 0; i
< nof_fps
; i
++) {
6363 if (i
> 0) body
= mputstr(body
,
6364 "TTCN_Logger::log_event_str(\", \");\n");
6365 body
= mputprintf(body
, "%s.log();\n",
6366 fp_list
->get_fp_byIndex(i
)->get_reference_name(my_scope
).c_str());
6368 body
= mputstr(body
, "TTCN_Logger::log_event_str(\").\");\n"
6369 "TTCN_Logger::end_event();\n");
6371 body
= mputprintf(body
,
6372 "TTCN_Logger::log_str(TTCN_Logger::PARALLEL_PTC, \"Starting function "
6373 "%s().\");\n", dispname_str
);
6375 body
= mputstr(body
,
6376 "TTCN_Runtime::function_started(function_arguments);\n");
6377 char *actual_par_list
=
6378 fp_list
->generate_code_actual_parlist(memptystr(), "");
6379 bool return_value_kept
= false;
6380 if (asstype
== A_FUNCTION_RVAL
) {
6381 // the return value is kept only if the function returns a value
6382 // (rather than a template) and the return type has the "done"
6383 // extension attribute
6384 for (Type
*t
= return_type
; ; t
= t
->get_type_refd()) {
6385 if (t
->has_done_attribute()) {
6386 return_value_kept
= true;
6388 } else if (!t
->is_ref()) break;
6391 if (return_value_kept
) {
6392 const string
& return_type_dispname
= return_type
->get_typename();
6393 const char *return_type_dispname_str
= return_type_dispname
.c_str();
6394 body
= mputprintf(body
, "%s ret_val(%s(%s));\n"
6395 "TTCN_Logger::begin_event(TTCN_PARALLEL);\n"
6396 "TTCN_Logger::log_event_str(\"Function %s returned %s : \");\n"
6398 "Text_Buf text_buf;\n"
6399 "TTCN_Runtime::prepare_function_finished(\"%s\", text_buf);\n"
6400 "ret_val.encode_text(text_buf);\n"
6401 "TTCN_Runtime::send_function_finished(text_buf);\n",
6402 return_type_str
, genname_str
, actual_par_list
, dispname_str
,
6403 return_type_dispname_str
, return_type_dispname_str
);
6405 body
= mputprintf(body
, "%s(%s);\n"
6406 "TTCN_Runtime::function_finished(\"%s\");\n",
6407 genname_str
, actual_par_list
, dispname_str
);
6409 Free(actual_par_list
);
6410 body
= mputstr(body
, "return TRUE;\n"
6412 target
->functions
.start
= mputstr(target
->functions
.start
, body
);
6414 Free(full_formal_par_list
);
6417 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
6418 "%s.add_function(\"%s\", (genericfunc_t)&%s, ", get_module_object_name(),
6419 dispname_str
, genname_str
);
6421 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
6422 "(genericfunc_t)&start_%s);\n", genname_str
);
6424 target
->functions
.pre_init
= mputstr(target
->functions
.pre_init
,
6428 void Def_Function::generate_code(CodeGenHelper
& cgh
) {
6429 generate_code(cgh
.get_current_outputstruct());
6432 void Def_Function::dump_internal(unsigned level
) const
6434 DEBUG(level
, "Function: %s", id
->get_dispname().c_str());
6435 DEBUG(level
+ 1, "Parameters:");
6436 fp_list
->dump(level
+ 1);
6438 DEBUG(level
+ 1, "Runs on clause:");
6439 runs_on_ref
->dump(level
+ 2);
6442 DEBUG(level
+ 1, "Return type:");
6443 return_type
->dump(level
+ 2);
6444 if (asstype
== A_FUNCTION_RTEMP
) DEBUG(level
+ 1, "Returns template");
6446 if (prototype
!= PROTOTYPE_NONE
)
6447 DEBUG(level
+ 1, "Prototype: %s", get_prototype_name());
6448 //DEBUG(level + 1, "Statement block:");
6449 block
->dump(level
+ 1);
6452 void Def_Function::set_parent_path(WithAttribPath
* p_path
) {
6453 Def_Function_Base::set_parent_path(p_path
);
6454 block
->set_parent_path(w_attrib_path
);
6457 // =================================
6458 // ===== Def_ExtFunction
6459 // =================================
6461 Def_ExtFunction::~Def_ExtFunction()
6463 delete encoding_options
;
6465 if (NULL
!= json_printing
) {
6466 delete json_printing
;
6470 Def_ExtFunction
*Def_ExtFunction::clone() const
6472 FATAL_ERROR("Def_ExtFunction::clone");
6475 void Def_ExtFunction::set_fullname(const string
& p_fullname
)
6477 Def_Function_Base::set_fullname(p_fullname
);
6478 if (eb_list
) eb_list
->set_fullname(p_fullname
+ ".<errorbehavior_list>");
6481 void Def_ExtFunction::set_encode_parameters(Type::MessageEncodingType_t
6482 p_encoding_type
, string
*p_encoding_options
)
6484 function_type
= EXTFUNC_ENCODE
;
6485 encoding_type
= p_encoding_type
;
6486 delete encoding_options
;
6487 encoding_options
= p_encoding_options
;
6490 void Def_ExtFunction::set_decode_parameters(Type::MessageEncodingType_t
6491 p_encoding_type
, string
*p_encoding_options
)
6493 function_type
= EXTFUNC_DECODE
;
6494 encoding_type
= p_encoding_type
;
6495 delete encoding_options
;
6496 encoding_options
= p_encoding_options
;
6499 void Def_ExtFunction::add_eb_list(Ttcn::ErrorBehaviorList
*p_eb_list
)
6501 if (!p_eb_list
) FATAL_ERROR("Def_ExtFunction::add_eb_list()");
6503 eb_list
->steal_ebs(p_eb_list
);
6506 eb_list
= p_eb_list
;
6507 eb_list
->set_fullname(get_fullname() + ".<errorbehavior_list>");
6511 void Def_ExtFunction::chk_function_type()
6513 switch (function_type
) {
6514 case EXTFUNC_MANUAL
:
6516 eb_list
->error("Attribute `errorbehavior' can only be used together "
6517 "with `encode' or `decode'");
6521 case EXTFUNC_ENCODE
:
6522 switch (prototype
) {
6523 case PROTOTYPE_NONE
:
6524 error("Attribute `encode' cannot be used without `prototype'");
6526 case PROTOTYPE_BACKTRACK
:
6527 case PROTOTYPE_SLIDING
:
6528 error("Attribute `encode' cannot be used with `prototype(%s)'",
6529 get_prototype_name());
6530 default: /* CONVERT and FAST allowed */
6535 if (!input_type
->has_encoding(encoding_type
, encoding_options
)) {
6536 if (Common::Type::CT_CUSTOM
== encoding_type
) {
6537 input_type
->error("Input type `%s' does not support custom encoding '%s'",
6538 input_type
->get_typename().c_str(), encoding_options
->c_str());
6541 input_type
->error("Input type `%s' does not support %s encoding",
6542 input_type
->get_typename().c_str(),
6543 Type::get_encoding_name(encoding_type
));
6547 if (Common::Type::CT_XER
== encoding_type
6548 && input_type
->get_type_refd_last()->is_untagged()) {
6549 // "untagged" on the (toplevel) input type will have no effect.
6550 warning("UNTAGGED encoding attribute is ignored on top-level type");
6552 if (Common::Type::CT_CUSTOM
== encoding_type
) {
6553 if (PROTOTYPE_CONVERT
!= prototype
) {
6554 error("Only `prototype(convert)' is allowed for custom encoding functions");
6557 // let the input type know that this is its encoding function
6558 input_type
->get_type_refd()->set_coding_function(true,
6559 get_genname_from_scope(input_type
->get_type_refd()->get_my_scope()));
6560 // treat this as a manual external function during code generation
6561 function_type
= EXTFUNC_MANUAL
;
6567 if(encoding_type
== Common::Type::CT_TEXT
) { // TEXT encoding supports both octetstring and charstring stream types
6568 Type
*stream_type
= Type::get_stream_type(encoding_type
,0);
6569 Type
*stream_type2
= Type::get_stream_type(encoding_type
,1);
6570 if ( (!stream_type
->is_identical(output_type
)) && (!stream_type2
->is_identical(output_type
)) ) {
6571 output_type
->error("The output type of %s encoding should be `%s' or `%s' "
6572 "instead of `%s'", Type::get_encoding_name(encoding_type
),
6573 stream_type
->get_typename().c_str(),
6574 stream_type2
->get_typename().c_str(),
6575 output_type
->get_typename().c_str());
6578 Type
*stream_type
= Type::get_stream_type(encoding_type
);
6579 if (!stream_type
->is_identical(output_type
)) {
6580 output_type
->error("The output type of %s encoding should be `%s' "
6581 "instead of `%s'", Type::get_encoding_name(encoding_type
),
6582 stream_type
->get_typename().c_str(),
6583 output_type
->get_typename().c_str());
6587 if (eb_list
) eb_list
->chk();
6588 chk_allowed_encode();
6590 case EXTFUNC_DECODE
:
6591 if (prototype
== PROTOTYPE_NONE
) {
6592 error("Attribute `decode' cannot be used without `prototype'");
6595 if(encoding_type
== Common::Type::CT_TEXT
) { // TEXT encoding supports both octetstring and charstring stream types
6596 Type
*stream_type
= Type::get_stream_type(encoding_type
,0);
6597 Type
*stream_type2
= Type::get_stream_type(encoding_type
,1);
6598 if ( (!stream_type
->is_identical(input_type
)) && (!stream_type2
->is_identical(input_type
)) ) {
6599 input_type
->error("The input type of %s decoding should be `%s' or `%s' "
6600 "instead of `%s'", Type::get_encoding_name(encoding_type
),
6601 stream_type
->get_typename().c_str(),
6602 stream_type2
->get_typename().c_str(),
6603 input_type
->get_typename().c_str());
6606 Type
*stream_type
= Type::get_stream_type(encoding_type
);
6607 if (!stream_type
->is_identical(input_type
)) {
6608 input_type
->error("The input type of %s decoding should be `%s' "
6609 "instead of `%s'", Type::get_encoding_name(encoding_type
),
6610 stream_type
->get_typename().c_str(),
6611 input_type
->get_typename().c_str());
6616 if (output_type
&& !output_type
->has_encoding(encoding_type
, encoding_options
)) {
6617 if (Common::Type::CT_CUSTOM
== encoding_type
) {
6618 output_type
->error("Output type `%s' does not support custom encoding '%s'",
6619 output_type
->get_typename().c_str(), encoding_options
->c_str());
6622 output_type
->error("Output type `%s' does not support %s encoding",
6623 output_type
->get_typename().c_str(),
6624 Type::get_encoding_name(encoding_type
));
6628 if (Common::Type::CT_CUSTOM
== encoding_type
) {
6629 if (PROTOTYPE_SLIDING
!= prototype
) {
6630 error("Only `prototype(sliding)' is allowed for custom decoding functions");
6632 else if (output_type
) {
6633 // let the output type know that this is its decoding function
6634 output_type
->get_type_refd()->set_coding_function(false,
6635 get_genname_from_scope(output_type
->get_type_refd()->get_my_scope()));
6636 // treat this as a manual external function during code generation
6637 function_type
= EXTFUNC_MANUAL
;
6641 if (eb_list
) eb_list
->chk();
6642 chk_allowed_encode();
6645 FATAL_ERROR("Def_ExtFunction::chk()");
6649 void Def_ExtFunction::chk_allowed_encode()
6651 switch (encoding_type
) {
6653 if (enable_ber()) return; // ok
6656 if (enable_raw()) return; // ok
6659 if (enable_text()) return; // ok
6662 if (enable_xer()) return; // ok
6665 if (enable_per()) return; // ok?
6668 if (enable_json()) return;
6670 case Type::CT_CUSTOM
:
6671 return; // cannot be disabled
6673 FATAL_ERROR("Def_ExtFunction::chk_allowed_encode");
6677 error("%s encoding is disallowed by license or commandline options",
6678 Type::get_encoding_name(encoding_type
));
6681 void Def_ExtFunction::chk()
6683 if (checked
) return;
6685 Error_Context
cntxt(this, "In external function definition `%s'",
6686 id
->get_dispname().c_str());
6687 fp_list
->chk(asstype
);
6689 Error_Context
cntxt2(return_type
, "In return type");
6691 return_type
->chk_as_return_type(asstype
== A_EXT_FUNCTION_RVAL
,
6692 "external function");
6694 if (!semantic_check_only
) fp_list
->set_genname(get_genname());
6695 if (w_attrib_path
) {
6696 w_attrib_path
->chk_global_attrib();
6697 w_attrib_path
->chk_no_qualif();
6698 const Ttcn::ExtensionAttributes
* extattrs
= parse_extattributes(w_attrib_path
);
6699 if (extattrs
!= 0) {
6700 size_t num_atrs
= extattrs
->size();
6701 for (size_t i
=0; i
< num_atrs
; ++i
) {
6702 ExtensionAttribute
&ea
= extattrs
->get(i
);
6703 switch (ea
.get_type()) {
6704 case ExtensionAttribute::PROTOTYPE
: {
6705 if (get_prototype() != Def_Function_Base::PROTOTYPE_NONE
) {
6706 ea
.error("Duplicate attribute `prototype'");
6708 Def_Function_Base::prototype_t proto
= ea
.get_proto();
6709 set_prototype(proto
);
6712 case ExtensionAttribute::ENCODE
: {
6713 switch (get_function_type()) {
6714 case Def_ExtFunction::EXTFUNC_MANUAL
:
6716 case Def_ExtFunction::EXTFUNC_ENCODE
: {
6717 ea
.error("Duplicate attribute `encode'");
6719 case Def_ExtFunction::EXTFUNC_DECODE
: {
6720 ea
.error("Attributes `decode' and `encode' "
6721 "cannot be used at the same time");
6724 FATAL_ERROR("coding_attrib_parse(): invalid external function type");
6726 Type::MessageEncodingType_t et
;
6728 ea
.get_encdec_parameters(et
, opt
);
6729 set_encode_parameters(et
, opt
);
6732 case ExtensionAttribute::ERRORBEHAVIOR
: {
6733 add_eb_list(ea
.get_eb_list());
6736 case ExtensionAttribute::DECODE
: {
6737 switch (get_function_type()) {
6738 case Def_ExtFunction::EXTFUNC_MANUAL
:
6740 case Def_ExtFunction::EXTFUNC_ENCODE
: {
6741 ea
.error("Attributes `encode' and `decode' "
6742 "cannot be used at the same time");
6744 case Def_ExtFunction::EXTFUNC_DECODE
: {
6745 ea
.error("Duplicate attribute `decode'");
6748 FATAL_ERROR("coding_attrib_parse(): invalid external function type");
6750 Type::MessageEncodingType_t et
;
6752 ea
.get_encdec_parameters(et
, opt
);
6753 set_decode_parameters(et
, opt
);
6756 case ExtensionAttribute::PRINTING
: {
6757 json_printing
= ea
.get_printing();
6760 case ExtensionAttribute::ANYTYPELIST
:
6761 // ignore, because we can't distinguish between a local
6762 // "extension anytype" (which is bogus) and an inherited one
6763 // (which was meant for a type definition)
6766 case ExtensionAttribute::NONE
:
6767 // Ignore, do not issue "wrong type" error
6772 "Only the following extension attributes may be applied to "
6773 "external functions: 'prototype', 'encode', 'decode', 'errorbehavior'");
6781 chk_function_type();
6783 if (NULL
!= json_printing
&& (EXTFUNC_ENCODE
!= function_type
||
6784 Type::CT_JSON
!= encoding_type
)) {
6785 error("Attribute 'printing' is only allowed for JSON encoding functions.");
6789 char *Def_ExtFunction::generate_code_encode(char *str
)
6791 const char *function_name
= id
->get_dispname().c_str();
6792 const char *first_par_name
=
6793 fp_list
->get_fp_byIndex(0)->get_id().get_name().c_str();
6794 // producing debug printout of the input PDU
6795 str
= mputprintf(str
,
6797 "// written by %s in " __FILE__
" at %d\n"
6799 "if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC)) {\n"
6800 "TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);\n"
6801 "TTCN_Logger::log_event_str(\"%s(): Encoding %s: \");\n"
6803 "TTCN_Logger::end_event();\n"
6806 , __FUNCTION__
, __LINE__
6808 , function_name
, input_type
->get_typename().c_str(), first_par_name
);
6809 // setting error behavior
6810 if (eb_list
) str
= eb_list
->generate_code(str
);
6811 else str
= mputstr(str
, "TTCN_EncDec::set_error_behavior("
6812 "TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);\n");
6813 // encoding PDU into the buffer
6814 str
= mputstr(str
, "TTCN_Buffer ttcn_buffer;\n");
6815 str
= mputprintf(str
, "%s.encode(%s_descr_, ttcn_buffer, TTCN_EncDec::CT_%s",
6817 input_type
->get_genname_typedescriptor(my_scope
).c_str(),
6818 Type::get_encoding_name(encoding_type
));
6819 if (encoding_type
== Type::CT_JSON
) {
6820 if (json_printing
!= NULL
) {
6821 str
= json_printing
->generate_code(str
);
6823 str
= mputstr(str
, ", 0");
6826 if (encoding_options
) str
= mputprintf(str
, ", %s",
6827 encoding_options
->c_str());
6828 str
= mputstr(str
, ");\n");
6829 const char *result_name
;
6830 switch (prototype
) {
6831 case PROTOTYPE_CONVERT
:
6832 result_name
= "ret_val";
6833 // creating a local variable for the result stream
6834 str
= mputprintf(str
, "%s ret_val;\n",
6835 output_type
->get_genname_value(my_scope
).c_str());
6837 case PROTOTYPE_FAST
:
6838 result_name
= fp_list
->get_fp_byIndex(1)->get_id().get_name().c_str();
6841 FATAL_ERROR("Def_ExtFunction::generate_code_encode()");
6844 // taking the result from the buffer and producing debug printout
6845 str
= mputprintf(str
, "ttcn_buffer.get_string(%s);\n"
6846 "if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC)) {\n"
6847 "TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);\n"
6848 "TTCN_Logger::log_event_str(\"%s(): Stream after encoding: \");\n"
6850 "TTCN_Logger::end_event();\n"
6851 "}\n", result_name
, function_name
, result_name
);
6852 // returning the result stream if necessary
6853 if (prototype
== PROTOTYPE_CONVERT
) {
6854 if (debugger_active
) {
6856 "ttcn3_debugger.set_return_value((TTCN_Logger::begin_event_log2str(), "
6857 "ret_val.log(), TTCN_Logger::end_event_log2str()));\n");
6859 str
= mputstr(str
, "return ret_val;\n");
6864 char *Def_ExtFunction::generate_code_decode(char *str
)
6866 const char *function_name
= id
->get_dispname().c_str();
6867 const char *first_par_name
=
6868 fp_list
->get_fp_byIndex(0)->get_id().get_name().c_str();
6869 // producing debug printout of the input stream
6870 str
= mputprintf(str
,
6872 "// written by %s in " __FILE__
" at %d\n"
6874 "if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC)) {\n"
6875 "TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);\n"
6876 "TTCN_Logger::log_event_str(\"%s(): Stream before decoding: \");\n"
6878 "TTCN_Logger::end_event();\n"
6881 , __FUNCTION__
, __LINE__
6883 , function_name
, first_par_name
);
6884 // setting error behavior
6885 if (eb_list
) str
= eb_list
->generate_code(str
);
6886 else if (prototype
== PROTOTYPE_BACKTRACK
|| prototype
== PROTOTYPE_SLIDING
) {
6887 str
= mputstr(str
, "TTCN_EncDec::set_error_behavior("
6888 "TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_WARNING);\n");
6889 } else str
= mputstr(str
, "TTCN_EncDec::set_error_behavior("
6890 "TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);\n");
6891 // creating a buffer from the input stream
6892 str
= mputprintf(str
, "TTCN_EncDec::clear_error();\n"
6893 "TTCN_Buffer ttcn_buffer(%s);\n", first_par_name
);
6894 const char *result_name
;
6895 if (prototype
== PROTOTYPE_CONVERT
) {
6896 // creating a local variable for the result
6897 str
= mputprintf(str
, "%s ret_val;\n",
6898 output_type
->get_genname_value(my_scope
).c_str());
6899 result_name
= "ret_val";
6901 result_name
= fp_list
->get_fp_byIndex(1)->get_id().get_name().c_str();
6903 if(encoding_type
==Type::CT_TEXT
){
6904 str
= mputprintf(str
,
6905 "if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC)) {\n"
6906 " TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_LOG_MATCHING, TTCN_EncDec::EB_WARNING);\n"
6909 str
= mputprintf(str
, "%s.decode(%s_descr_, ttcn_buffer, "
6910 "TTCN_EncDec::CT_%s", result_name
,
6911 output_type
->get_genname_typedescriptor(my_scope
).c_str(),
6912 Type::get_encoding_name(encoding_type
));
6913 if (encoding_options
) str
= mputprintf(str
, ", %s",
6914 encoding_options
->c_str());
6915 str
= mputstr(str
, ");\n");
6916 // producing debug printout of the result PDU
6917 str
= mputprintf(str
,
6918 "if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC)) {\n"
6919 "TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);\n"
6920 "TTCN_Logger::log_event_str(\"%s(): Decoded %s: \");\n"
6922 "TTCN_Logger::end_event();\n"
6923 "}\n", function_name
, output_type
->get_typename().c_str(), result_name
);
6924 if (prototype
!= PROTOTYPE_SLIDING
) {
6925 // checking for remaining data in the buffer if decoding was successful
6926 str
= mputprintf(str
, "if (TTCN_EncDec::get_last_error_type() == "
6927 "TTCN_EncDec::ET_NONE) {\n"
6928 "if (ttcn_buffer.get_pos() < ttcn_buffer.get_len()-1 && "
6929 "TTCN_Logger::log_this_event(TTCN_WARNING)) {\n"
6930 "ttcn_buffer.cut();\n"
6931 "%s remaining_stream;\n"
6932 "ttcn_buffer.get_string(remaining_stream);\n"
6933 "TTCN_Logger::begin_event(TTCN_WARNING);\n"
6934 "TTCN_Logger::log_event_str(\"%s(): Warning: Data remained at the end "
6935 "of the stream after successful decoding: \");\n"
6936 "remaining_stream.log();\n"
6937 "TTCN_Logger::end_event();\n"
6938 "}\n", input_type
->get_genname_value(my_scope
).c_str(), function_name
);
6939 // closing the block and returning the appropriate result or status code
6940 if (prototype
== PROTOTYPE_BACKTRACK
) {
6941 if (debugger_active
) {
6942 str
= mputstr(str
, "ttcn3_debugger.set_return_value(\"0\");\n");
6947 if (debugger_active
) {
6948 str
= mputstr(str
, "ttcn3_debugger.set_return_value(\"1\");\n");
6954 str
= mputstr(str
, "}\n");
6955 if (prototype
== PROTOTYPE_CONVERT
) {
6956 if (debugger_active
) {
6958 "ttcn3_debugger.set_return_value((TTCN_Logger::begin_event_log2str(), "
6959 "ret_val.log(), TTCN_Logger::end_event_log2str()));\n");
6961 str
= mputstr(str
, "return ret_val;\n");
6965 // result handling and debug printout for sliding decoders
6966 str
= mputprintf(str
, "switch (TTCN_EncDec::get_last_error_type()) {\n"
6967 "case TTCN_EncDec::ET_NONE:\n"
6968 // TTCN_Buffer::get_string will call OCTETSTRING::clean_up()
6969 "ttcn_buffer.cut();\n"
6970 "ttcn_buffer.get_string(%s);\n"
6971 "if (TTCN_Logger::log_this_event(TTCN_Logger::DEBUG_ENCDEC)) {\n"
6972 "TTCN_Logger::begin_event(TTCN_Logger::DEBUG_ENCDEC);\n"
6973 "TTCN_Logger::log_event_str(\"%s(): Stream after decoding: \");\n"
6975 "TTCN_Logger::end_event();\n"
6978 "case TTCN_EncDec::ET_INCOMPL_MSG:\n"
6979 "case TTCN_EncDec::ET_LEN_ERR:\n"
6983 "}\n", first_par_name
, function_name
, first_par_name
,
6984 debugger_active
? "ttcn3_debugger.set_return_value(\"0\");\n" : "",
6985 debugger_active
? "ttcn3_debugger.set_return_value(\"2\");\n" : "",
6986 debugger_active
? "ttcn3_debugger.set_return_value(\"1\");\n" : "");
6991 void Def_ExtFunction::generate_code(output_struct
*target
, bool)
6993 const string
& t_genname
= get_genname();
6994 const char *genname_str
= t_genname
.c_str();
6995 string return_type_name
;
6997 case A_EXT_FUNCTION
:
6998 return_type_name
= "void";
7000 case A_EXT_FUNCTION_RVAL
:
7001 return_type_name
= return_type
->get_genname_value(my_scope
);
7003 case A_EXT_FUNCTION_RTEMP
:
7004 return_type_name
= return_type
->get_genname_template(my_scope
);
7007 FATAL_ERROR("Def_ExtFunction::generate_code()");
7009 const char *return_type_str
= return_type_name
.c_str();
7010 char *formal_par_list
= fp_list
->generate_code(memptystr(), fp_list
->get_nof_fps());
7011 fp_list
->generate_code_defval(target
);
7012 // function prototype
7013 target
->header
.function_prototypes
=
7014 mputprintf(target
->header
.function_prototypes
, "extern %s %s(%s);\n",
7015 return_type_str
, genname_str
, formal_par_list
);
7017 if (function_type
!= EXTFUNC_MANUAL
) {
7018 // function body written by the compiler
7021 body
= mprintf("// written by %s in " __FILE__
" at %d\n"
7022 , __FUNCTION__
, __LINE__
);
7024 body
= mputprintf(body
,
7027 , return_type_str
, genname_str
, formal_par_list
);
7028 if (debugger_active
) {
7029 body
= generate_code_debugger_function_init(body
, this);
7031 switch (function_type
) {
7032 case EXTFUNC_ENCODE
:
7033 body
= generate_code_encode(body
);
7035 case EXTFUNC_DECODE
:
7036 body
= generate_code_decode(body
);
7039 FATAL_ERROR("Def_ExtFunction::generate_code()");
7041 body
= mputstr(body
, "}\n\n");
7042 target
->source
.function_bodies
= mputstr(target
->source
.function_bodies
,
7047 Free(formal_par_list
);
7049 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
7050 "%s.add_function(\"%s\", (genericfunc_t)&%s, NULL);\n",
7051 get_module_object_name(), id
->get_dispname().c_str(), genname_str
);
7054 void Def_ExtFunction::generate_code(CodeGenHelper
& cgh
) {
7055 generate_code(cgh
.get_current_outputstruct());
7058 void Def_ExtFunction::dump_internal(unsigned level
) const
7060 DEBUG(level
, "External function: %s", id
->get_dispname().c_str());
7061 DEBUG(level
+ 1, "Parameters:");
7062 fp_list
->dump(level
+ 2);
7064 DEBUG(level
+ 1, "Return type:");
7065 return_type
->dump(level
+ 2);
7066 if(asstype
== A_EXT_FUNCTION_RTEMP
) DEBUG(level
+ 1, "Returns template");
7068 if (prototype
!= PROTOTYPE_NONE
)
7069 DEBUG(level
+ 1, "Prototype: %s", get_prototype_name());
7070 if (function_type
!= EXTFUNC_MANUAL
) {
7071 DEBUG(level
+ 1, "Automatically generated: %s",
7072 function_type
== EXTFUNC_ENCODE
? "encoder" : "decoder");
7073 DEBUG(level
+ 2, "Encoding type: %s",
7074 Type::get_encoding_name(encoding_type
));
7075 if (encoding_options
)
7076 DEBUG(level
+ 2, "Encoding options: %s", encoding_options
->c_str());
7078 if (eb_list
) eb_list
->dump(level
+ 1);
7081 void Def_ExtFunction::generate_json_schema_ref(map
<Type
*, JSON_Tokenizer
>& json_refs
)
7083 // only do anything if this is a JSON encoding or decoding function
7084 if (encoding_type
== Type::CT_JSON
&&
7085 (function_type
== EXTFUNC_ENCODE
|| function_type
== EXTFUNC_DECODE
)) {
7086 // retrieve the encoded type
7088 if (function_type
== EXTFUNC_ENCODE
) {
7089 // for encoding functions it's always the first parameter
7090 type
= fp_list
->get_fp_byIndex(0)->get_Type();
7092 // for decoding functions it depends on the prototype
7093 switch (prototype
) {
7094 case PROTOTYPE_CONVERT
:
7097 case PROTOTYPE_FAST
:
7098 case PROTOTYPE_BACKTRACK
:
7099 case PROTOTYPE_SLIDING
:
7100 type
= fp_list
->get_fp_byIndex(1)->get_Type();
7103 FATAL_ERROR("Def_ExtFunction::generate_json_schema_ref");
7107 // step over the type reference created for this function
7108 type
= type
->get_type_refd();
7110 JSON_Tokenizer
* json
= NULL
;
7111 if (json_refs
.has_key(type
)) {
7112 // the schema segment containing the type's reference already exists
7113 json
= json_refs
[type
];
7115 // the schema segment doesn't exist yet, create it and insert the reference
7116 json
= new JSON_Tokenizer
;
7117 json_refs
.add(type
, json
);
7118 type
->generate_json_schema_ref(*json
);
7121 // insert a property to specify which function this is (encoding or decoding)
7122 json
->put_next_token(JSON_TOKEN_NAME
, (function_type
== EXTFUNC_ENCODE
) ?
7123 "encoding" : "decoding");
7125 // place the function's info in an object
7126 json
->put_next_token(JSON_TOKEN_OBJECT_START
);
7128 // insert information related to the function's prototype in an array
7129 json
->put_next_token(JSON_TOKEN_NAME
, "prototype");
7130 json
->put_next_token(JSON_TOKEN_ARRAY_START
);
7132 // 1st element: external function prototype name (as string)
7134 case PROTOTYPE_CONVERT
:
7135 json
->put_next_token(JSON_TOKEN_STRING
, "\"convert\"");
7137 case PROTOTYPE_FAST
:
7138 json
->put_next_token(JSON_TOKEN_STRING
, "\"fast\"");
7140 case PROTOTYPE_BACKTRACK
:
7141 json
->put_next_token(JSON_TOKEN_STRING
, "\"backtrack\"");
7143 case PROTOTYPE_SLIDING
:
7144 json
->put_next_token(JSON_TOKEN_STRING
, "\"sliding\"");
7147 FATAL_ERROR("Def_ExtFunction::generate_json_schema_ref");
7150 // 2nd element: external function name
7151 char* func_name_str
= mprintf("\"%s\"", id
->get_dispname().c_str());
7152 json
->put_next_token(JSON_TOKEN_STRING
, func_name_str
);
7153 Free(func_name_str
);
7155 // the rest of the elements contain the names of the function's parameters (1 or 2)
7156 for (size_t i
= 0; i
< fp_list
->get_nof_fps(); ++i
) {
7157 char* param_str
= mprintf("\"%s\"",
7158 fp_list
->get_fp_byIndex(i
)->get_id().get_dispname().c_str());
7159 json
->put_next_token(JSON_TOKEN_STRING
, param_str
);
7163 // end of the prototype's array
7164 json
->put_next_token(JSON_TOKEN_ARRAY_END
);
7166 // insert error behavior data
7167 if (eb_list
!= NULL
) {
7168 json
->put_next_token(JSON_TOKEN_NAME
, "errorBehavior");
7169 json
->put_next_token(JSON_TOKEN_OBJECT_START
);
7171 // add each error behavior modification as a property
7172 for (size_t i
= 0; i
< eb_list
->get_nof_ebs(); ++i
) {
7173 ErrorBehaviorSetting
* eb
= eb_list
->get_ebs_byIndex(i
);
7174 json
->put_next_token(JSON_TOKEN_NAME
, eb
->get_error_type().c_str());
7175 char* handling_str
= mprintf("\"%s\"", eb
->get_error_handling().c_str());
7176 json
->put_next_token(JSON_TOKEN_STRING
, handling_str
);
7180 json
->put_next_token(JSON_TOKEN_OBJECT_END
);
7183 // insert printing type
7184 if (json_printing
!= NULL
) {
7185 json
->put_next_token(JSON_TOKEN_NAME
, "printing");
7186 json
->put_next_token(JSON_TOKEN_STRING
,
7187 (json_printing
->get_printing() == PrintingType::PT_PRETTY
) ?
7188 "\"pretty\"" : "\"compact\"");
7191 // end of this function's object
7192 json
->put_next_token(JSON_TOKEN_OBJECT_END
);
7196 // =================================
7197 // ===== Def_Altstep
7198 // =================================
7200 Def_Altstep::Def_Altstep(Identifier
*p_id
, FormalParList
*p_fpl
,
7201 Reference
*p_runs_on_ref
, StatementBlock
*p_sb
,
7203 : Definition(A_ALTSTEP
, p_id
), fp_list(p_fpl
), runs_on_ref(p_runs_on_ref
),
7204 runs_on_type(0), sb(p_sb
), ags(p_ags
)
7206 if (!p_fpl
|| !p_sb
|| !p_ags
)
7207 FATAL_ERROR("Def_Altstep::Def_Altstep()");
7208 fp_list
->set_my_def(this);
7209 sb
->set_my_def(this);
7210 ags
->set_my_def(this);
7211 ags
->set_my_sb(sb
, 0);
7214 Def_Altstep::~Def_Altstep()
7222 Def_Altstep
*Def_Altstep::clone() const
7224 FATAL_ERROR("Def_Altstep::clone");
7227 void Def_Altstep::set_fullname(const string
& p_fullname
)
7229 Definition::set_fullname(p_fullname
);
7230 fp_list
->set_fullname(p_fullname
+ ".<formal_par_list>");
7231 if (runs_on_ref
) runs_on_ref
->set_fullname(p_fullname
+ ".<runs_on_type>");
7232 sb
->set_fullname(p_fullname
+".<block>");
7233 ags
->set_fullname(p_fullname
+ ".<guards>");
7236 void Def_Altstep::set_my_scope(Scope
*p_scope
)
7238 bridgeScope
.set_parent_scope(p_scope
);
7239 bridgeScope
.set_scopeMacro_name(id
->get_dispname());
7241 Definition::set_my_scope(&bridgeScope
);
7242 // the scope of the parameter list is set during checking
7243 if (runs_on_ref
) runs_on_ref
->set_my_scope(&bridgeScope
);
7244 sb
->set_my_scope(fp_list
);
7245 ags
->set_my_scope(sb
);
7248 Type
*Def_Altstep::get_RunsOnType()
7250 if (!checked
) chk();
7251 return runs_on_type
;
7254 FormalParList
*Def_Altstep::get_FormalParList()
7256 if (!checked
) chk();
7260 RunsOnScope
*Def_Altstep::get_runs_on_scope(Type
*comptype
)
7262 Module
*my_module
= dynamic_cast<Module
*>(my_scope
->get_scope_mod());
7263 if (!my_module
) FATAL_ERROR("Def_Altstep::get_runs_on_scope()");
7264 return my_module
->get_runs_on_scope(comptype
);
7267 void Def_Altstep::chk()
7269 if (checked
) return;
7271 Error_Context
cntxt(this, "In altstep definition `%s'",
7272 id
->get_dispname().c_str());
7273 Scope
*parlist_scope
= my_scope
;
7275 Error_Context
cntxt2(runs_on_ref
, "In `runs on' clause");
7276 runs_on_type
= runs_on_ref
->chk_comptype_ref();
7278 Scope
*runs_on_scope
= get_runs_on_scope(runs_on_type
);
7279 runs_on_scope
->set_parent_scope(my_scope
);
7280 parlist_scope
= runs_on_scope
;
7283 fp_list
->set_my_scope(parlist_scope
);
7284 fp_list
->chk(asstype
);
7286 ags
->set_is_altstep();
7287 ags
->set_my_ags(ags
);
7288 ags
->set_my_laic_stmt(ags
, 0);
7290 if (!semantic_check_only
) {
7291 fp_list
->set_genname(get_genname());
7292 sb
->set_code_section(GovernedSimple::CS_INLINE
);
7293 ags
->set_code_section(GovernedSimple::CS_INLINE
);
7295 if (w_attrib_path
) {
7296 w_attrib_path
->chk_global_attrib();
7297 w_attrib_path
->chk_no_qualif();
7301 void Def_Altstep::generate_code(output_struct
*target
, bool)
7303 const string
& t_genname
= get_genname();
7304 const char *genname_str
= t_genname
.c_str();
7305 const char *dispname_str
= id
->get_dispname().c_str();
7307 // function for altstep instance:
7308 // assemble the function body first (this also determines which parameters
7310 char* body
= create_location_object(memptystr(), "ALTSTEP", dispname_str
);
7311 body
= fp_list
->generate_shadow_objects(body
);
7312 if (debugger_active
) {
7313 body
= generate_code_debugger_function_init(body
, this);
7315 body
= sb
->generate_code(body
);
7316 body
= ags
->generate_code_altstep(body
);
7317 // generate a smart formal parameter list (omits unused parameter names)
7318 char *formal_par_list
= fp_list
->generate_code(memptystr());
7319 fp_list
->generate_code_defval(target
);
7321 // function for altstep instance: prototype
7322 target
->header
.function_prototypes
=
7323 mputprintf(target
->header
.function_prototypes
,
7324 "extern alt_status %s_instance(%s);\n", genname_str
, formal_par_list
);
7326 // function for altstep instance: body
7327 target
->source
.function_bodies
= mputprintf(target
->source
.function_bodies
,
7328 "alt_status %s_instance(%s)\n"
7331 "}\n\n", genname_str
, formal_par_list
, body
);
7332 Free(formal_par_list
);
7335 char *actual_par_list
=
7336 fp_list
->generate_code_actual_parlist(memptystr(), "");
7338 // use a full formal parameter list for the rest of the functions
7339 char *full_formal_par_list
= fp_list
->generate_code(memptystr(),
7340 fp_list
->get_nof_fps());
7342 // wrapper function for stand-alone instantiation: prototype
7343 target
->header
.function_prototypes
=
7344 mputprintf(target
->header
.function_prototypes
,
7345 "extern void %s(%s);\n", genname_str
, full_formal_par_list
);
7347 // wrapper function for stand-alone instantiation: body
7348 target
->source
.function_bodies
=
7349 mputprintf(target
->source
.function_bodies
, "void %s(%s)\n"
7352 "boolean block_flag = FALSE;\n"
7353 "alt_status altstep_flag = ALT_UNCHECKED, "
7354 "default_flag = ALT_UNCHECKED;\n"
7356 "TTCN_Snapshot::take_new(block_flag);\n"
7357 "if (altstep_flag != ALT_NO) {\n"
7358 "altstep_flag = %s_instance(%s);\n"
7359 "if (altstep_flag == ALT_YES || altstep_flag == ALT_BREAK) return;\n"
7360 "else if (altstep_flag == ALT_REPEAT) goto altstep_begin;\n"
7362 "if (default_flag != ALT_NO) {\n"
7363 "default_flag = TTCN_Default::try_altsteps();\n"
7364 "if (default_flag == ALT_YES || default_flag == ALT_BREAK) return;\n"
7365 "else if (default_flag == ALT_REPEAT) goto altstep_begin;\n"
7367 "if (altstep_flag == ALT_NO && default_flag == ALT_NO) "
7368 "TTCN_error(\"None of the branches can be chosen in altstep %s.\");\n"
7369 "else block_flag = TRUE;\n"
7371 "}\n\n", genname_str
, full_formal_par_list
, genname_str
, actual_par_list
,
7374 // class for keeping the altstep in the default context
7375 // the class is for internal use, we do not need to publish it in the
7377 char* str
= mprintf("class %s_Default : public Default_Base {\n", genname_str
);
7378 str
= fp_list
->generate_code_object(str
, "par_");
7379 str
= mputprintf(str
, "public:\n"
7381 "alt_status call_altstep();\n"
7382 "};\n\n", genname_str
, full_formal_par_list
);
7383 target
->source
.class_defs
= mputstr(target
->source
.class_defs
, str
);
7385 // member functions of the class
7386 str
= mprintf("%s_Default::%s_Default(%s)\n"
7387 " : Default_Base(\"%s\")", genname_str
, genname_str
, full_formal_par_list
,
7389 for (size_t i
= 0; i
< fp_list
->get_nof_fps(); i
++) {
7390 const char *fp_name_str
=
7391 fp_list
->get_fp_byIndex(i
)->get_id().get_name().c_str();
7392 str
= mputprintf(str
, ", par_%s(%s)", fp_name_str
, fp_name_str
);
7394 str
= mputstr(str
, "\n{\n}\n\n");
7395 char *actual_par_list_prefixed
=
7396 fp_list
->generate_code_actual_parlist(memptystr(), "par_");
7397 str
= mputprintf(str
, "alt_status %s_Default::call_altstep()\n"
7399 "return %s_instance(%s);\n"
7400 "}\n\n", genname_str
, genname_str
, actual_par_list_prefixed
);
7401 Free(actual_par_list_prefixed
);
7402 target
->source
.methods
= mputstr(target
->source
.methods
, str
);
7405 // function for default activation: prototype
7406 target
->header
.function_prototypes
=
7407 mputprintf(target
->header
.function_prototypes
,
7408 "extern Default_Base *activate_%s(%s);\n", genname_str
,
7409 full_formal_par_list
);
7411 // function for default activation: body
7412 str
= mprintf("Default_Base *activate_%s(%s)\n"
7413 "{\n", genname_str
, full_formal_par_list
);
7414 str
= mputprintf(str
, "return new %s_Default(%s);\n"
7415 "}\n\n", genname_str
, actual_par_list
);
7416 target
->source
.function_bodies
= mputstr(target
->source
.function_bodies
,
7420 Free(full_formal_par_list
);
7421 Free(actual_par_list
);
7423 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
7424 "%s.add_altstep(\"%s\", (genericfunc_t)&%s_instance, (genericfunc_t )&activate_%s, "
7425 "(genericfunc_t )&%s);\n", get_module_object_name(), dispname_str
, genname_str
,
7426 genname_str
, genname_str
);
7429 void Def_Altstep::generate_code(CodeGenHelper
& cgh
) {
7430 generate_code(cgh
.get_current_outputstruct());
7433 void Def_Altstep::dump_internal(unsigned level
) const
7435 DEBUG(level
, "Altstep: %s", id
->get_dispname().c_str());
7436 DEBUG(level
+ 1, "Parameters:");
7437 fp_list
->dump(level
+ 1);
7439 DEBUG(level
+ 1, "Runs on clause:");
7440 runs_on_ref
->dump(level
+ 2);
7443 DEBUG(level + 1, "Local definitions:");
7444 sb->dump(level + 2);
7446 DEBUG(level
+ 1, "Guards:");
7447 ags
->dump(level
+ 2);
7450 void Def_Altstep::set_parent_path(WithAttribPath
* p_path
) {
7451 Definition::set_parent_path(p_path
);
7452 sb
->set_parent_path(w_attrib_path
);
7455 // =================================
7456 // ===== Def_Testcase
7457 // =================================
7459 Def_Testcase::Def_Testcase(Identifier
*p_id
, FormalParList
*p_fpl
,
7460 Reference
*p_runs_on_ref
, Reference
*p_system_ref
,
7461 StatementBlock
*p_block
)
7462 : Definition(A_TESTCASE
, p_id
), fp_list(p_fpl
), runs_on_ref(p_runs_on_ref
),
7463 runs_on_type(0), system_ref(p_system_ref
), system_type(0), block(p_block
)
7465 if (!p_fpl
|| !p_runs_on_ref
|| !p_block
)
7466 FATAL_ERROR("Def_Testcase::Def_Testcase()");
7467 fp_list
->set_my_def(this);
7468 block
->set_my_def(this);
7471 Def_Testcase::~Def_Testcase()
7479 Def_Testcase
*Def_Testcase::clone() const
7481 FATAL_ERROR("Def_Testcase::clone");
7484 void Def_Testcase::set_fullname(const string
& p_fullname
)
7486 Definition::set_fullname(p_fullname
);
7487 fp_list
->set_fullname(p_fullname
+ ".<formal_par_list>");
7488 runs_on_ref
->set_fullname(p_fullname
+ ".<runs_on_type>");
7489 if (system_ref
) system_ref
->set_fullname(p_fullname
+ ".<system_type>");
7490 block
->set_fullname(p_fullname
+ ".<statement_block>");
7493 void Def_Testcase::set_my_scope(Scope
*p_scope
)
7495 bridgeScope
.set_parent_scope(p_scope
);
7496 bridgeScope
.set_scopeMacro_name(id
->get_dispname());
7498 Definition::set_my_scope(&bridgeScope
);
7499 // the scope of the parameter list is set during checking
7500 runs_on_ref
->set_my_scope(&bridgeScope
);
7501 if (system_ref
) system_ref
->set_my_scope(&bridgeScope
);
7502 block
->set_my_scope(fp_list
);
7505 Type
*Def_Testcase::get_RunsOnType()
7507 if (!checked
) chk();
7508 return runs_on_type
;
7511 Type
*Def_Testcase::get_SystemType()
7513 if (!checked
) chk();
7517 FormalParList
*Def_Testcase::get_FormalParList()
7519 if (!checked
) chk();
7523 RunsOnScope
*Def_Testcase::get_runs_on_scope(Type
*comptype
)
7525 Module
*my_module
= dynamic_cast<Module
*>(my_scope
->get_scope_mod());
7526 if (!my_module
) FATAL_ERROR("Def_Testcase::get_runs_on_scope()");
7527 return my_module
->get_runs_on_scope(comptype
);
7530 void Def_Testcase::chk()
7532 if (checked
) return;
7534 Error_Context
cntxt(this, "In testcase definition `%s'",
7535 id
->get_dispname().c_str());
7536 Scope
*parlist_scope
= my_scope
;
7538 Error_Context
cntxt2(runs_on_ref
, "In `runs on' clause");
7539 runs_on_type
= runs_on_ref
->chk_comptype_ref();
7541 Scope
*runs_on_scope
= get_runs_on_scope(runs_on_type
);
7542 runs_on_scope
->set_parent_scope(my_scope
);
7543 parlist_scope
= runs_on_scope
;
7547 Error_Context
cntxt2(system_ref
, "In `system' clause");
7548 system_type
= system_ref
->chk_comptype_ref();;
7550 fp_list
->set_my_scope(parlist_scope
);
7551 fp_list
->chk(asstype
);
7553 if (!semantic_check_only
) {
7554 fp_list
->set_genname(get_genname());
7555 block
->set_code_section(GovernedSimple::CS_INLINE
);
7557 if (w_attrib_path
) {
7558 w_attrib_path
->chk_global_attrib();
7559 w_attrib_path
->chk_no_qualif();
7563 void Def_Testcase::generate_code(output_struct
*target
, bool)
7565 const string
& t_genname
= get_genname();
7566 const char *genname_str
= t_genname
.c_str();
7567 const char *dispname_str
= id
->get_dispname().c_str();
7569 // assemble the function body first (this also determines which parameters
7572 // Checking whether the testcase was invoked from another one.
7573 // At this point the location information should refer to the execute()
7574 // statement rather than this testcase.
7575 char* body
= mputstr(memptystr(), "TTCN_Runtime::check_begin_testcase(has_timer, "
7577 body
= create_location_object(body
, "TESTCASE", dispname_str
);
7578 body
= fp_list
->generate_shadow_objects(body
);
7579 if (debugger_active
) {
7580 body
= generate_code_debugger_function_init(body
, this);
7582 body
= mputprintf(body
, "try {\n"
7583 "TTCN_Runtime::begin_testcase(\"%s\", \"%s\", ",
7584 my_scope
->get_scope_mod()->get_modid().get_dispname().c_str(),
7586 ComponentTypeBody
*runs_on_body
= runs_on_type
->get_CompBody();
7587 body
= runs_on_body
->generate_code_comptype_name(body
);
7588 body
= mputstr(body
, ", ");
7590 body
= system_type
->get_CompBody()->generate_code_comptype_name(body
);
7591 else body
= runs_on_body
->generate_code_comptype_name(body
);
7592 body
= mputstr(body
, ", has_timer, timer_value);\n");
7593 body
= block
->generate_code(body
);
7594 body
= mputprintf(body
,
7595 "} catch (const TC_Error& tc_error) {\n"
7596 "} catch (const TC_End& tc_end) {\n"
7597 "TTCN_Logger::log_str(TTCN_FUNCTION, \"Test case %s was stopped.\");\n"
7598 "}\n", dispname_str
);
7599 body
= mputstr(body
, "return TTCN_Runtime::end_testcase();\n");
7601 // smart formal parameter list (names of unused parameters are omitted)
7602 char *formal_par_list
= fp_list
->generate_code(memptystr());
7603 fp_list
->generate_code_defval(target
);
7604 if (fp_list
->get_nof_fps() > 0)
7605 formal_par_list
= mputstr(formal_par_list
, ", ");
7606 formal_par_list
= mputstr(formal_par_list
,
7607 "boolean has_timer, double timer_value");
7609 // function prototype
7610 target
->header
.function_prototypes
=
7611 mputprintf(target
->header
.function_prototypes
,
7612 "extern verdicttype testcase_%s(%s);\n", genname_str
, formal_par_list
);
7615 target
->source
.function_bodies
= mputprintf(target
->source
.function_bodies
,
7616 "verdicttype testcase_%s(%s)\n"
7619 "}\n\n", genname_str
, formal_par_list
, body
);
7620 Free(formal_par_list
);
7623 if (fp_list
->get_nof_fps() == 0) {
7624 // adding to the list of startable testcases
7625 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
7626 "%s.add_testcase_nonpard(\"%s\", testcase_%s);\n",
7627 get_module_object_name(), dispname_str
, genname_str
);
7629 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
7630 "%s.add_testcase_pard(\"%s\", (genericfunc_t)&testcase_%s);\n",
7631 get_module_object_name(), dispname_str
, genname_str
);
7633 // If every formal parameter has a default value, the testcase
7634 // might be callable after all.
7635 bool callable
= true;
7636 for (size_t i
= 0; i
< fp_list
->get_nof_fps(); ++i
) {
7637 FormalPar
*fp
= fp_list
->get_fp_byIndex(i
);
7638 if (!fp
->has_defval()) {
7645 // Write a wrapper, which acts as a no-param testcase
7646 // by calling the parameterized testcase with the default values.
7647 target
->header
.function_prototypes
=
7648 mputprintf(target
->header
.function_prototypes
,
7649 "extern verdicttype testcase_%s_defparams(boolean has_timer, double timer_value);\n",
7651 target
->source
.function_bodies
= mputprintf(target
->source
.function_bodies
,
7652 "verdicttype testcase_%s_defparams(boolean has_timer, double timer_value) {\n"
7653 " return testcase_%s(",
7654 genname_str
, genname_str
);
7656 for (size_t i
= 0; i
< fp_list
->get_nof_fps(); ++i
) {
7657 FormalPar
*fp
= fp_list
->get_fp_byIndex(i
);
7658 ActualPar
*ap
= fp
->get_defval();
7659 switch (ap
->get_selection()) {
7660 case ActualPar::AP_VALUE
:
7661 target
->source
.function_bodies
= mputstr(target
->source
.function_bodies
,
7662 ap
->get_Value()->get_genname_own(my_scope
).c_str());
7664 case ActualPar::AP_TEMPLATE
:
7665 target
->source
.function_bodies
= mputstr(target
->source
.function_bodies
,
7666 ap
->get_TemplateInstance()->get_Template()->get_genname_own(my_scope
).c_str());
7668 case ActualPar::AP_REF
:
7669 target
->source
.function_bodies
= mputstr(target
->source
.function_bodies
,
7670 ap
->get_Ref()->get_refd_assignment()->get_genname_from_scope(my_scope
).c_str());
7672 case ActualPar::AP_DEFAULT
:
7673 // Can't happen. This ActualPar was created by
7674 // Ttcn::FormalPar::chk_actual_par as the default value for
7675 // a FormalPar, and it only ever creates vale, template or ref.
7678 FATAL_ERROR("Def_Testcase::generate_code()");
7681 // always append a comma, because has_timer and timer_value follows
7682 target
->source
.function_bodies
= mputstrn(target
->source
.function_bodies
,
7686 target
->source
.function_bodies
= mputstr(target
->source
.function_bodies
,
7687 "has_timer, timer_value);\n"
7689 // Add the non-parameterized wrapper *after* the parameterized one,
7690 // with the same name. Linear search will always find the first
7691 // (user-visible, parameterized) testcase.
7692 // TTCN_Module::execute_testcase knows that if after a parameterized
7693 // testcase another testcase with the same name follows,
7694 // it's the callable, non-parameterized wrapper.
7696 // TTCN_Module::list_testcases skips parameterized testcases;
7697 // it will now list the non-parameterized wrapper.
7698 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
7699 "%s.add_testcase_nonpard(\"%s\", testcase_%s_defparams);\n",
7700 get_module_object_name(), dispname_str
, genname_str
);
7702 } // has formal parameters
7705 void Def_Testcase::generate_code(CodeGenHelper
& cgh
) {
7706 generate_code(cgh
.get_current_outputstruct());
7709 void Def_Testcase::dump_internal(unsigned level
) const
7711 DEBUG(level
, "Testcase: %s", id
->get_dispname().c_str());
7712 DEBUG(level
+ 1, "Parameters:");
7713 fp_list
->dump(level
+ 1);
7714 DEBUG(level
+ 1, "Runs on clause:");
7715 runs_on_ref
->dump(level
+ 2);
7717 DEBUG(level
+ 1, "System clause:");
7718 system_ref
->dump(level
+ 2);
7720 DEBUG(level
+ 1, "Statement block:");
7721 block
->dump(level
+ 2);
7724 void Def_Testcase::set_parent_path(WithAttribPath
* p_path
) {
7725 Definition::set_parent_path(p_path
);
7727 block
->set_parent_path(w_attrib_path
);
7730 // =================================
7732 // =================================
7734 FormalPar::FormalPar(asstype_t p_asstype
, Type
*p_type
, Identifier
* p_name
,
7735 TemplateInstance
*p_defval
, bool p_lazy_eval
)
7736 : Definition(p_asstype
, p_name
), type(p_type
), my_parlist(0),
7737 used_as_lvalue(false), template_restriction(TR_NONE
),
7738 lazy_eval(p_lazy_eval
), defval_generated(false), usage_found(false)
7740 switch (p_asstype
) {
7744 case A_PAR_VAL_INOUT
:
7745 case A_PAR_TEMPL_IN
:
7746 case A_PAR_TEMPL_OUT
:
7747 case A_PAR_TEMPL_INOUT
:
7751 FATAL_ERROR("Ttcn::FormalPar::FormalPar(): invalid parameter type");
7754 FATAL_ERROR("Ttcn::FormalPar::FormalPar(): NULL pointer");
7755 type
->set_ownertype(Type::OT_FORMAL_PAR
, this);
7756 defval
.ti
= p_defval
;
7759 FormalPar::FormalPar(asstype_t p_asstype
,
7760 template_restriction_t p_template_restriction
, Type
*p_type
,
7761 Identifier
* p_name
, TemplateInstance
*p_defval
, bool p_lazy_eval
)
7762 : Definition(p_asstype
, p_name
), type(p_type
), my_parlist(0),
7763 used_as_lvalue(false), template_restriction(p_template_restriction
),
7764 lazy_eval(p_lazy_eval
), defval_generated(false), usage_found(false)
7766 switch (p_asstype
) {
7767 case A_PAR_TEMPL_IN
:
7768 case A_PAR_TEMPL_OUT
:
7769 case A_PAR_TEMPL_INOUT
:
7772 FATAL_ERROR("Ttcn::FormalPar::FormalPar(): parameter not template");
7775 FATAL_ERROR("Ttcn::FormalPar::FormalPar(): NULL pointer");
7776 type
->set_ownertype(Type::OT_FORMAL_PAR
, this);
7777 defval
.ti
= p_defval
;
7780 FormalPar::FormalPar(asstype_t p_asstype
, Identifier
* p_name
,
7781 TemplateInstance
*p_defval
)
7782 : Definition(p_asstype
, p_name
), type(0), my_parlist(0),
7783 used_as_lvalue(false), template_restriction(TR_NONE
), lazy_eval(false),
7784 defval_generated(false), usage_found(false)
7786 if (p_asstype
!= A_PAR_TIMER
)
7787 FATAL_ERROR("Ttcn::FormalPar::FormalPar(): invalid parameter type");
7788 defval
.ti
= p_defval
;
7791 FormalPar::~FormalPar()
7794 if (checked
) delete defval
.ap
;
7795 else delete defval
.ti
;
7798 FormalPar
* FormalPar::clone() const
7800 FATAL_ERROR("FormalPar::clone");
7803 void FormalPar::set_fullname(const string
& p_fullname
)
7805 Definition::set_fullname(p_fullname
);
7806 if (type
) type
->set_fullname(p_fullname
+ ".<type>");
7808 if (defval
.ap
) defval
.ap
->set_fullname(p_fullname
+ ".<default_value>");
7810 if (defval
.ti
) defval
.ti
->set_fullname(p_fullname
+ ".<default_value>");
7814 void FormalPar::set_my_scope(Scope
*p_scope
)
7816 Definition::set_my_scope(p_scope
);
7817 if (type
) type
->set_my_scope(p_scope
);
7819 if (defval
.ap
) defval
.ap
->set_my_scope(p_scope
);
7821 if (defval
.ti
) defval
.ti
->set_my_scope(p_scope
);
7825 bool FormalPar::is_local() const
7830 Type
*FormalPar::get_Type()
7832 if (!checked
) chk();
7833 if (!type
) FATAL_ERROR("FormalPar::get_Type()");
7837 void FormalPar::chk()
7839 if (checked
) return;
7841 TemplateInstance
*default_value
= defval
.ti
;
7845 Type
*t
= type
->get_type_refd_last();
7846 // checks for forbidden type <-> parameter combinations
7847 switch (t
->get_typetype()) {
7851 case A_PAR_VAL_INOUT
:
7852 asstype
= A_PAR_PORT
;
7855 error("Port type `%s' cannot be used as %s",
7856 t
->get_fullname().c_str(), get_assname());
7859 case Type::T_SIGNATURE
:
7861 case A_PAR_TEMPL_IN
:
7862 case A_PAR_TEMPL_OUT
:
7863 case A_PAR_TEMPL_INOUT
:
7866 error("Signature `%s' cannot be used as %s",
7867 t
->get_fullname().c_str(), get_assname());
7874 FATAL_ERROR("FormalPar::chk()");
7876 asstype
= A_PAR_VAL_IN
;
7881 } else if (asstype
!= A_PAR_TIMER
) FATAL_ERROR("FormalPar::chk()");
7883 if (default_value
) {
7884 Error_Context
cntxt(default_value
, "In default value");
7885 defval
.ap
= chk_actual_par(default_value
, Type::EXPECTED_STATIC_VALUE
);
7886 delete default_value
;
7887 if (!semantic_check_only
)
7888 defval
.ap
->set_code_section(GovernedSimple::CS_POST_INIT
);
7892 bool FormalPar::has_defval() const
7894 if (checked
) return defval
.ap
!= 0;
7895 else return defval
.ti
!= 0;
7898 bool FormalPar::has_notused_defval() const
7900 if (checked
) FATAL_ERROR("FormalPar::has_notused_defval");
7901 if (!defval
.ti
|| !defval
.ti
->get_Template())
7903 return defval
.ti
->get_Template()->get_templatetype()
7904 == Template::TEMPLATE_NOTUSED
;
7907 ActualPar
*FormalPar::get_defval() const
7909 if (!checked
) FATAL_ERROR("FormalPar::get_defval()");
7913 // Extract the TemplateInstance from an ActualPar.
7914 void FormalPar::set_defval(ActualPar
*defpar
)
7916 // ActualPar::clone() is not implemented, since we need such a function
7917 // only here only for AP_{VALUE,TEMPLATE} parameters. AP_ERROR can also
7918 // happen for Def_Template nodes, but they will be errors later.
7919 // FIXME: This function is Def_Template specific.
7920 if (!defval
.ti
->get_Template() || defval
.ti
->get_Template()
7921 ->get_templatetype() != Template::TEMPLATE_NOTUSED
)
7922 FATAL_ERROR("FormalPar::set_defval()");
7923 TemplateInstance
*reversed_ti
= 0;
7924 switch (defpar
->get_selection()) {
7925 case ActualPar::AP_VALUE
:
7926 reversed_ti
= new TemplateInstance(type
->clone(), 0, new Template
7927 (defpar
->get_Value()->clone())); // Trust the clone().
7929 case ActualPar::AP_TEMPLATE
:
7930 reversed_ti
= defpar
->get_TemplateInstance()->clone();
7932 case ActualPar::AP_ERROR
:
7933 break; // Can happen, but let it go.
7934 case ActualPar::AP_REF
:
7935 case ActualPar::AP_DEFAULT
:
7937 FATAL_ERROR("FormalPar::set_defval()");
7941 reversed_ti
->set_my_scope(get_my_scope());
7942 defval
.ti
= reversed_ti
;
7946 ActualPar
*FormalPar::chk_actual_par(TemplateInstance
*actual_par
,
7947 Type::expected_value_t exp_val
)
7949 if (!checked
) chk();
7953 return chk_actual_par_value(actual_par
, exp_val
);
7955 case A_PAR_VAL_INOUT
:
7956 return chk_actual_par_by_ref(actual_par
, false, exp_val
);
7957 case A_PAR_TEMPL_IN
:
7958 return chk_actual_par_template(actual_par
, exp_val
);
7959 case A_PAR_TEMPL_OUT
:
7960 case A_PAR_TEMPL_INOUT
:
7961 return chk_actual_par_by_ref(actual_par
, true, exp_val
);
7963 return chk_actual_par_timer(actual_par
, exp_val
);
7965 return chk_actual_par_port(actual_par
, exp_val
);
7967 FATAL_ERROR("FormalPar::chk_actual_par()");
7969 return 0; // to avoid warnings
7972 ActualPar
*FormalPar::chk_actual_par_value(TemplateInstance
*actual_par
,
7973 Type::expected_value_t exp_val
)
7975 actual_par
->chk_Type(type
);
7976 Ref_base
*derived_ref
= actual_par
->get_DerivedRef();
7978 derived_ref
->error("An in-line modified template cannot be used as %s",
7980 actual_par
->chk_DerivedRef(type
);
7982 Template
*ap_template
= actual_par
->get_Template();
7983 if (ap_template
->is_Value()) {
7984 Value
*v
= ap_template
->get_Value();
7985 v
->set_my_governor(type
);
7986 type
->chk_this_value_ref(v
);
7987 type
->chk_this_value(v
, 0, exp_val
, INCOMPLETE_NOT_ALLOWED
,
7988 OMIT_NOT_ALLOWED
, SUB_CHK
);
7989 return new ActualPar(v
);
7991 actual_par
->error("A specific value without matching symbols "
7992 "was expected for a %s", get_assname());
7993 return new ActualPar();
7997 static void chk_defpar_value(const Value
* v
)
7999 Common::Reference
*vref
= v
->get_reference();
8000 Common::Assignment
*ass2
= vref
->get_refd_assignment();
8002 Scope
*scope
= ass2
->get_my_scope();
8003 ComponentTypeBody
*ctb
= dynamic_cast<ComponentTypeBody
*>(scope
);
8004 if (ctb
) { // this is a component variable
8005 v
->error("default value cannot refer to"
8006 " a template field of the component in the `runs on' clause");
8010 static void chk_defpar_template(const Template
*body
,
8011 Type::expected_value_t exp_val
)
8013 switch (body
->get_templatetype()) {
8014 case Template::TEMPLATE_ERROR
:
8015 break; // could be erroneous in the source; skip it
8016 case Template::TEMPLATE_NOTUSED
:
8017 case Template::OMIT_VALUE
:
8018 case Template::ANY_VALUE
:
8019 case Template::ANY_OR_OMIT
:
8020 break; // acceptable (?)
8021 case Template::TEMPLATE_INVOKE
: // calling a function is not acceptable
8022 body
->error("default value can not be a function invocation");
8024 case Template::VALUE_RANGE
: {
8025 ValueRange
*range
= body
->get_value_range();
8026 Value
*low
= range
->get_min_v();
8027 Type::typetype_t tt_low
= low
->get_expr_returntype(exp_val
);
8028 Value
*high
= range
->get_max_v();
8029 Type::typetype_t tt_high
= high
->get_expr_returntype(exp_val
);
8030 if (tt_low
== tt_high
) break;
8033 case Template::BSTR_PATTERN
:
8034 case Template::HSTR_PATTERN
:
8035 case Template::OSTR_PATTERN
:
8036 case Template::CSTR_PATTERN
:
8037 case Template::USTR_PATTERN
:
8038 break; // should be acceptable in all cases (if only fixed strings possible)
8040 case Template::SPECIFIC_VALUE
: {
8041 Common::Value
*v
= body
->get_specific_value();
8042 if (v
->get_valuetype() == Value::V_REFD
) chk_defpar_value(v
);
8045 case Template::ALL_FROM
:
8046 case Template::VALUE_LIST_ALL_FROM
:
8047 FATAL_ERROR("should have been flattened");
8049 case Template::SUPERSET_MATCH
:
8050 case Template::SUBSET_MATCH
:
8051 case Template::PERMUTATION_MATCH
:
8052 case Template::TEMPLATE_LIST
:
8053 case Template::COMPLEMENTED_LIST
:
8054 case Template::VALUE_LIST
: {
8055 // in template charstring par := charstring : ("foo", "bar", "baz")
8056 size_t num
= body
->get_nof_comps();
8057 for (size_t i
= 0; i
< num
; ++i
) {
8058 const Template
*tpl
= body
->get_temp_byIndex(i
);
8059 chk_defpar_template(tpl
, exp_val
);
8063 case Template::NAMED_TEMPLATE_LIST
: {
8064 size_t num
= body
->get_nof_comps();
8065 for (size_t i
= 0; i
< num
; ++i
) {
8066 const NamedTemplate
*nt
= body
->get_namedtemp_byIndex(i
);
8067 const Template
*tpl
= nt
->get_template();
8068 chk_defpar_template(tpl
, exp_val
);
8072 case Template::INDEXED_TEMPLATE_LIST
: {
8073 size_t num
= body
->get_nof_comps();
8074 for (size_t i
= 0; i
< num
; ++i
) {
8075 const IndexedTemplate
*it
= body
->get_indexedtemp_byIndex(i
);
8076 const Template
*tpl
= it
->get_template();
8077 chk_defpar_template(tpl
, exp_val
);
8081 case Template::TEMPLATE_REFD
: {
8082 Ref_base
*ref
= body
->get_reference();
8084 Ttcn::ActualParList
*aplist
= ref
->get_parlist();
8086 size_t num
= aplist
->get_nof_pars();
8087 for (size_t i
= 0; i
< num
; ++i
) {
8088 const Ttcn::ActualPar
*ap
= aplist
->get_par(i
);
8090 switch (ap
->get_selection()) {
8091 case ActualPar::AP_ERROR
: {
8093 case ActualPar::AP_VALUE
: {
8094 Value
*v
= ap
->get_Value(); // "v_variable" as the parameter of the template
8096 switch (v
->get_valuetype()) {
8097 case Value::V_REFD
: {
8098 chk_defpar_value(v
);
8104 case ActualPar::AP_TEMPLATE
: {
8105 // A component cannot contain a template definition, parameterized or not.
8106 // Therefore the template this actual par references, cannot be
8107 // a field of a component => no error possible, nothing to do.
8109 case ActualPar::AP_REF
: {
8110 // A template cannot have an out/inout parameter
8111 FATAL_ERROR("Template with out parameter?");
8113 case ActualPar::AP_DEFAULT
: {
8114 ap
= ap
->get_ActualPar();
8118 } // switch actual par selection
8122 } // switch templatetype
8126 // This function is called in two situations:
8127 // 1. FormalParList::chk calls FormalPar::chk to compute the default value
8128 // (make an ActualPar from a TemplateInstance).
8129 // In this case, defval.ti==0, and actual_par contains its old value.
8130 // This case is called only if the formal par has a default value.
8131 // 2. FormalParList::chk_actual_parlist calls FormalPar::chk_actual_par
8132 // to check the parameters supplied by the execute statement to the tc.
8133 // In this case, defval.ap has the value computed in case 1.
8134 ActualPar
*FormalPar::chk_actual_par_template(TemplateInstance
*actual_par
,
8135 Type::expected_value_t exp_val
)
8137 actual_par
->chk(type
);
8138 // actual_par->template_body may change: SPECIFIC_VALUE to TEMPLATE_REFD
8139 Definition
*fplist_def
= my_parlist
->get_my_def();
8140 // The parameter list belongs to this definition. If it's a function
8141 // or testcase, it may have a "runs on" clause.
8142 Def_Function
*parent_fn
= dynamic_cast<Def_Function
*>(fplist_def
);
8143 Type
*runs_on_type
= 0;
8144 if (parent_fn
) runs_on_type
= parent_fn
->get_RunsOnType();
8145 else { // not a function; maybe a testcase
8146 Def_Testcase
*parent_tc
= dynamic_cast<Def_Testcase
*>(fplist_def
);
8147 if (parent_tc
) runs_on_type
= parent_tc
->get_RunsOnType();
8150 // If it _has_ a runs on clause, the type must be a component.
8151 if (runs_on_type
->get_typetype() != Type::T_COMPONENT
) FATAL_ERROR("not component?");
8152 // The default value "shall not refer to elements of the component type
8153 // in the runs on clause"
8154 ComponentTypeBody
*runs_on_component
= runs_on_type
->get_CompBody();
8155 size_t compass
= runs_on_component
->get_nof_asss();
8156 for (size_t c
= 0; c
< compass
; c
++) {
8157 Assignment
*ass
= runs_on_component
->get_ass_byIndex(c
);
8162 Ttcn::Template
* body
= actual_par
->get_Template();
8163 if (exp_val
== Type::EXPECTED_STATIC_VALUE
8164 ||exp_val
== Type::EXPECTED_CONSTANT
) {
8165 chk_defpar_template(body
, exp_val
);
8167 // Rip out the type, derived ref and template from actual_par
8168 // (which may come from a function invocation or the definition
8169 // of the default value) and give it to the new ActualPar.
8170 ActualPar
*ret_val
= new ActualPar(
8171 new TemplateInstance(actual_par
->get_Type(),
8172 actual_par
->get_DerivedRef(), actual_par
->get_Template()));
8173 // Zero out these members because the caller will soon call delete
8174 // on actual_par, but they now belong to ret_val.
8175 // FIXME: should this really be in here, or outside in the caller before the delete ?
8176 actual_par
->release();
8178 if (template_restriction
!=TR_NONE
) {
8179 bool needs_runtime_check
=
8180 ret_val
->get_TemplateInstance()->chk_restriction(
8181 "template formal parameter", template_restriction
,
8182 ret_val
->get_TemplateInstance());
8183 if (needs_runtime_check
)
8184 ret_val
->set_gen_restriction_check(template_restriction
);
8189 ActualPar
*FormalPar::chk_actual_par_by_ref(TemplateInstance
*actual_par
,
8190 bool is_template
, Type::expected_value_t exp_val
)
8192 Type
*ap_type
= actual_par
->get_Type();
8194 ap_type
->warning("Explicit type specification is useless for an %s",
8196 actual_par
->chk_Type(type
);
8198 Ref_base
*derived_ref
= actual_par
->get_DerivedRef();
8200 derived_ref
->error("An in-line modified template cannot be used as %s",
8202 actual_par
->chk_DerivedRef(type
);
8204 // needed for the error messages
8205 const char *expected_string
= is_template
?
8206 "template variable or template parameter" :
8207 "variable or value parameter";
8208 Template
*ap_template
= actual_par
->get_Template();
8209 if (ap_template
->is_Ref()) {
8210 Ref_base
*ref
= ap_template
->get_Ref();
8211 Common::Assignment
*ass
= ref
->get_refd_assignment();
8214 return new ActualPar();
8216 bool asstype_correct
= false;
8217 switch (ass
->get_asstype()) {
8219 ass
->use_as_lvalue(*ref
);
8220 if (get_asstype() == A_PAR_VAL_OUT
|| get_asstype() == A_PAR_TEMPL_OUT
) {
8221 ass
->warning("Passing an `in' parameter as another function's `out' parameter");
8226 case A_PAR_VAL_INOUT
:
8227 if (!is_template
) asstype_correct
= true;
8229 case A_PAR_TEMPL_IN
:
8230 ass
->use_as_lvalue(*ref
);
8231 if (get_asstype() == A_PAR_VAL_OUT
|| get_asstype() == A_PAR_TEMPL_OUT
) {
8232 ass
->warning("Passing an `in' parameter as another function's `out' parameter");
8235 case A_VAR_TEMPLATE
:
8236 case A_PAR_TEMPL_OUT
:
8237 case A_PAR_TEMPL_INOUT
:
8238 if (is_template
) asstype_correct
= true;
8243 if (asstype_correct
) {
8244 FieldOrArrayRefs
*t_subrefs
= ref
->get_subrefs();
8245 Type
*ref_type
= ass
->get_Type()->get_field_type(t_subrefs
, exp_val
);
8247 if (!type
->is_identical(ref_type
)) {
8248 ref
->error("Type mismatch: Reference to a %s of type "
8249 "`%s' was expected instead of `%s'", expected_string
,
8250 type
->get_typename().c_str(), ref_type
->get_typename().c_str());
8251 } else if (type
->get_sub_type() && ref_type
->get_sub_type() &&
8252 (type
->get_sub_type()->get_subtypetype()==ref_type
->get_sub_type()->get_subtypetype()) &&
8253 (!type
->get_sub_type()->is_compatible(ref_type
->get_sub_type()))) {
8254 ref
->error("Subtype mismatch: subtype %s has no common value with subtype %s",
8255 type
->get_sub_type()->to_string().c_str(),
8256 ref_type
->get_sub_type()->to_string().c_str());
8258 if (t_subrefs
&& t_subrefs
->refers_to_string_element()) {
8259 ref
->error("Reference to a string element of type `%s' cannot be "
8260 "used in this context", ref_type
->get_typename().c_str());
8264 ref
->error("Reference to a %s was expected for an %s instead of %s",
8265 expected_string
, get_assname(), ass
->get_description().c_str());
8267 ActualPar
* ret_val_ap
= new ActualPar(ref
);
8268 // restriction checking if this is a reference to a template variable
8269 // this is an 'out' or 'inout' template parameter
8270 if (is_template
&& asstype_correct
) {
8271 template_restriction_t refd_tr
;
8272 switch (ass
->get_asstype()) {
8273 case A_VAR_TEMPLATE
: {
8274 Def_Var_Template
* dvt
= dynamic_cast<Def_Var_Template
*>(ass
);
8275 if (!dvt
) FATAL_ERROR("FormalPar::chk_actual_par_by_ref()");
8276 refd_tr
= dvt
->get_template_restriction();
8278 case A_PAR_TEMPL_IN
:
8279 case A_PAR_TEMPL_OUT
:
8280 case A_PAR_TEMPL_INOUT
: {
8281 FormalPar
* fp
= dynamic_cast<FormalPar
*>(ass
);
8282 if (!fp
) FATAL_ERROR("FormalPar::chk_actual_par_by_ref()");
8283 refd_tr
= fp
->get_template_restriction();
8286 FATAL_ERROR("FormalPar::chk_actual_par_by_ref()");
8289 refd_tr
= Template::get_sub_restriction(refd_tr
, ref
);
8290 if (template_restriction
!=refd_tr
) {
8291 bool pre_call_check
=
8292 Template::is_less_restrictive(template_restriction
, refd_tr
);
8293 bool post_call_check
=
8294 Template::is_less_restrictive(refd_tr
, template_restriction
);
8295 if (pre_call_check
|| post_call_check
) {
8296 ref
->warning("Inadequate restriction on the referenced %s `%s', "
8297 "this may cause a dynamic test case error at runtime",
8298 ass
->get_assname(), ref
->get_dispname().c_str());
8299 ass
->note("Referenced %s is here", ass
->get_assname());
8302 ret_val_ap
->set_gen_restriction_check(template_restriction
);
8303 if (post_call_check
)
8304 ret_val_ap
->set_gen_post_restriction_check(refd_tr
);
8306 // for out and inout template parameters of external functions
8307 // always check because we do not trust user written C++ code
8308 if (refd_tr
!=TR_NONE
) {
8309 switch (my_parlist
->get_my_def()->get_asstype()) {
8310 case A_EXT_FUNCTION
:
8311 case A_EXT_FUNCTION_RVAL
:
8312 case A_EXT_FUNCTION_RTEMP
:
8313 ret_val_ap
->set_gen_post_restriction_check(refd_tr
);
8322 actual_par
->error("Reference to a %s was expected for an %s",
8323 expected_string
, get_assname());
8324 return new ActualPar();
8328 ActualPar
*FormalPar::chk_actual_par_timer(TemplateInstance
*actual_par
,
8329 Type::expected_value_t exp_val
)
8331 Type
*ap_type
= actual_par
->get_Type();
8333 ap_type
->error("Explicit type specification cannot be used for a "
8335 actual_par
->chk_Type(0);
8337 Ref_base
*derived_ref
= actual_par
->get_DerivedRef();
8339 derived_ref
->error("An in-line modified template cannot be used as "
8341 actual_par
->chk_DerivedRef(0);
8343 Template
*ap_template
= actual_par
->get_Template();
8344 if (ap_template
->is_Ref()) {
8345 Ref_base
*ref
= ap_template
->get_Ref();
8346 Common::Assignment
*ass
= ref
->get_refd_assignment();
8349 return new ActualPar();
8351 switch (ass
->get_asstype()) {
8353 ArrayDimensions
*dims
= ass
->get_Dimensions();
8354 if (dims
) dims
->chk_indices(ref
, "timer", false, exp_val
);
8355 else if (ref
->get_subrefs()) ref
->error("Reference to single %s "
8356 "cannot have field or array sub-references",
8357 ass
->get_description().c_str());
8360 if (ref
->get_subrefs()) ref
->error("Reference to %s cannot have "
8361 "field or array sub-references", ass
->get_description().c_str());
8364 ref
->error("Reference to a timer or timer parameter was expected for "
8365 "a timer parameter instead of %s", ass
->get_description().c_str());
8367 return new ActualPar(ref
);
8369 actual_par
->error("Reference to a timer or timer parameter was "
8370 "expected for a timer parameter");
8371 return new ActualPar();
8375 ActualPar
*FormalPar::chk_actual_par_port(TemplateInstance
*actual_par
,
8376 Type::expected_value_t exp_val
)
8378 Type
*ap_type
= actual_par
->get_Type();
8380 ap_type
->warning("Explicit type specification is useless for a port "
8382 actual_par
->chk_Type(type
);
8384 Ref_base
*derived_ref
= actual_par
->get_DerivedRef();
8386 derived_ref
->error("An in-line modified template cannot be used as "
8388 actual_par
->chk_DerivedRef(type
);
8390 Template
*ap_template
= actual_par
->get_Template();
8391 if (ap_template
->is_Ref()) {
8392 Ref_base
*ref
= ap_template
->get_Ref();
8393 Common::Assignment
*ass
= ref
->get_refd_assignment();
8396 return new ActualPar();
8398 bool asstype_correct
= false;
8399 switch (ass
->get_asstype()) {
8401 ArrayDimensions
*dims
= ass
->get_Dimensions();
8402 if (dims
) dims
->chk_indices(ref
, "port", false, exp_val
);
8403 else if (ref
->get_subrefs()) ref
->error("Reference to single %s "
8404 "cannot have field or array sub-references",
8405 ass
->get_description().c_str());
8406 asstype_correct
= true;
8409 if (ref
->get_subrefs()) ref
->error("Reference to %s cannot have "
8410 "field or array sub-references", ass
->get_description().c_str());
8411 asstype_correct
= true;
8414 ref
->error("Reference to a port or port parameter was expected for a "
8415 "port parameter instead of %s", ass
->get_description().c_str());
8417 if (asstype_correct
) {
8418 Type
*ref_type
= ass
->get_Type();
8419 if (ref_type
&& !type
->is_identical(ref_type
))
8420 ref
->error("Type mismatch: Reference to a port or port parameter "
8421 "of type `%s' was expected instead of `%s'",
8422 type
->get_typename().c_str(), ref_type
->get_typename().c_str());
8424 return new ActualPar(ref
);
8426 actual_par
->error("Reference to a port or port parameter was expected "
8427 "for a port parameter");
8428 return new ActualPar();
8432 void FormalPar::use_as_lvalue(const Location
& p_loc
)
8436 case A_PAR_TEMPL_IN
:
8439 FATAL_ERROR("FormalPar::use_as_lvalue()");
8441 if (!used_as_lvalue
) {
8442 Definition
*my_def
= my_parlist
->get_my_def();
8443 if (!my_def
) FATAL_ERROR("FormalPar::use_as_lvalue()");
8444 if (my_def
->get_asstype() == A_TEMPLATE
)
8445 p_loc
.error("Parameter `%s' of the template cannot be passed further "
8446 "as `out' or `inout' parameter", id
->get_dispname().c_str());
8448 // update the genname so that all references in the generated code
8449 // will point to the shadow object
8451 set_genname(id
->get_name() + "_shadow");
8453 used_as_lvalue
= true;
8458 char* FormalPar::generate_code_defval(char* str
)
8460 if (!defval
.ap
|| defval_generated
) return str
;
8461 defval_generated
= true;
8462 switch (defval
.ap
->get_selection()) {
8463 case ActualPar::AP_VALUE
: {
8464 Value
*val
= defval
.ap
->get_Value();
8465 if (use_runtime_2
&& TypeConv::needs_conv_refd(val
)) {
8466 str
= TypeConv::gen_conv_code_refd(str
, val
->get_lhs_name().c_str(), val
);
8468 str
= val
->generate_code_init(str
, val
->get_lhs_name().c_str());
8471 case ActualPar::AP_TEMPLATE
: {
8472 TemplateInstance
*ti
= defval
.ap
->get_TemplateInstance();
8473 Template
*temp
= ti
->get_Template();
8474 Ref_base
*dref
= ti
->get_DerivedRef();
8476 expression_struct expr
;
8477 Code::init_expr(&expr
);
8478 expr
.expr
= mputprintf(expr
.expr
, "%s = ",
8479 temp
->get_lhs_name().c_str());
8480 dref
->generate_code(&expr
);
8481 str
= Code::merge_free_expr(str
, &expr
, false);
8483 if (use_runtime_2
&& TypeConv::needs_conv_refd(temp
)) {
8484 str
= TypeConv::gen_conv_code_refd(str
, temp
->get_lhs_name().c_str(), temp
);
8486 str
= temp
->generate_code_init(str
, temp
->get_lhs_name().c_str());
8488 if (defval
.ap
->get_gen_restriction_check() != TR_NONE
) {
8489 str
= Template::generate_restriction_check_code(str
,
8490 temp
->get_lhs_name().c_str(), defval
.ap
->get_gen_restriction_check());
8493 case ActualPar::AP_REF
:
8496 FATAL_ERROR("FormalPar::generate_code()");
8501 void FormalPar::generate_code_defval(output_struct
*target
, bool)
8503 if (!defval
.ap
) return;
8504 switch (defval
.ap
->get_selection()) {
8505 case ActualPar::AP_VALUE
: {
8506 Value
*val
= defval
.ap
->get_Value();
8508 Code::init_cdef(&cdef
);
8509 type
->generate_code_object(&cdef
, val
);
8510 Code::merge_cdef(target
, &cdef
);
8511 Code::free_cdef(&cdef
);
8513 case ActualPar::AP_TEMPLATE
: {
8514 TemplateInstance
*ti
= defval
.ap
->get_TemplateInstance();
8515 Template
*temp
= ti
->get_Template();
8517 Code::init_cdef(&cdef
);
8518 type
->generate_code_object(&cdef
, temp
);
8519 Code::merge_cdef(target
, &cdef
);
8520 Code::free_cdef(&cdef
);
8522 case ActualPar::AP_REF
:
8525 FATAL_ERROR("FormalPar::generate_code()");
8527 target
->functions
.post_init
= generate_code_defval(target
->functions
.post_init
);
8530 char *FormalPar::generate_code_fpar(char *str
, bool display_unused
/* = false */)
8532 // the name of the parameter should not be displayed if the parameter is not
8533 // used (to avoid a compiler warning)
8534 bool display_name
= (usage_found
|| display_unused
|| debugger_active
||
8535 (!enable_set_bound_out_param
&& (asstype
== A_PAR_VAL_OUT
|| asstype
== A_PAR_TEMPL_OUT
)));
8536 const char *name_str
= display_name
? id
->get_name().c_str() : "";
8540 str
= mputprintf(str
, "Lazy_Param<%s>& %s", type
->get_genname_value(my_scope
).c_str(), name_str
);
8542 str
= mputprintf(str
, "const %s& %s", type
->get_genname_value(my_scope
).c_str(), name_str
);
8546 case A_PAR_VAL_INOUT
:
8548 str
= mputprintf(str
, "%s& %s", type
->get_genname_value(my_scope
).c_str(),
8551 case A_PAR_TEMPL_IN
:
8553 str
= mputprintf(str
, "Lazy_Param<%s>& %s", type
->get_genname_template(my_scope
).c_str(), name_str
);
8555 str
= mputprintf(str
, "const %s& %s", type
->get_genname_template(my_scope
).c_str(), name_str
);
8558 case A_PAR_TEMPL_OUT
:
8559 case A_PAR_TEMPL_INOUT
:
8560 str
= mputprintf(str
, "%s& %s",
8561 type
->get_genname_template(my_scope
).c_str(), name_str
);
8564 str
= mputprintf(str
, "TIMER& %s", name_str
);
8567 FATAL_ERROR("FormalPar::generate_code()");
8572 string
FormalPar::get_reference_name(Scope
* scope
) const
8578 case A_PAR_TEMPL_IN
:
8579 ret_val
+= type
->get_genname_template(scope
);
8582 ret_val
+= type
->get_genname_value(scope
);
8587 ret_val
+= get_id().get_name();
8594 char *FormalPar::generate_code_object(char *str
, const char *p_prefix
, char refch
)
8596 const char *name_str
= id
->get_name().c_str();
8600 str
= mputprintf(str
, "Lazy_Param<%s> %s%s;\n", type
->get_genname_value(my_scope
).c_str(), p_prefix
, name_str
);
8602 str
= mputprintf(str
, "%s %s%s;\n", type
->get_genname_value(my_scope
).c_str(), p_prefix
, name_str
);
8606 case A_PAR_VAL_INOUT
:
8608 str
= mputprintf(str
, "%s%c %s%s;\n",
8609 type
->get_genname_value(my_scope
).c_str(), refch
, p_prefix
, name_str
);
8611 case A_PAR_TEMPL_IN
:
8613 str
= mputprintf(str
, "Lazy_Param<%s> %s%s;\n", type
->get_genname_template(my_scope
).c_str(), p_prefix
, name_str
);
8615 str
= mputprintf(str
, "%s %s%s;\n", type
->get_genname_template(my_scope
).c_str(), p_prefix
, name_str
);
8618 case A_PAR_TEMPL_OUT
:
8619 case A_PAR_TEMPL_INOUT
:
8620 str
= mputprintf(str
, "%s%c %s%s;\n",
8621 type
->get_genname_template(my_scope
).c_str(), refch
, p_prefix
, name_str
);
8624 str
= mputprintf(str
, "TIMER& %s%s;\n", p_prefix
, name_str
);
8627 FATAL_ERROR("FormalPar::generate_code_object()");
8632 char *FormalPar::generate_shadow_object(char *str
) const
8634 if (used_as_lvalue
&& !lazy_eval
) {
8635 const string
& t_genname
= get_genname();
8636 const char *genname_str
= t_genname
.c_str();
8637 const char *name_str
= id
->get_name().c_str();
8640 str
= mputprintf(str
, "%s %s(%s);\n",
8641 type
->get_genname_value(my_scope
).c_str(), genname_str
, name_str
);
8643 case A_PAR_TEMPL_IN
:
8644 str
= mputprintf(str
, "%s %s(%s);\n",
8645 type
->get_genname_template(my_scope
).c_str(), genname_str
, name_str
);
8648 FATAL_ERROR("FormalPar::generate_shadow_object()");
8654 char *FormalPar::generate_code_set_unbound(char *str
) const
8657 case A_PAR_TEMPL_OUT
:
8659 str
= mputprintf(str
, "%s.clean_up();\n", id
->get_name().c_str());
8667 void FormalPar::dump_internal(unsigned level
) const
8669 DEBUG(level
, "%s: %s", get_assname(), id
->get_dispname().c_str());
8670 if (type
) type
->dump(level
+ 1);
8673 DEBUG(level
+ 1, "default value:");
8674 defval
.ap
->dump(level
+ 2);
8678 DEBUG(level
+ 1, "default value:");
8679 defval
.ti
->dump(level
+ 2);
8684 // =================================
8685 // ===== FormalParList
8686 // =================================
8688 FormalParList::~FormalParList()
8690 size_t nof_pars
= pars_v
.size();
8691 for (size_t i
= 0; i
< nof_pars
; i
++) delete pars_v
[i
];
8696 FormalParList
*FormalParList::clone() const
8698 FATAL_ERROR("FormalParList::clone");
8701 void FormalParList::set_fullname(const string
& p_fullname
)
8703 Node::set_fullname(p_fullname
);
8704 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
8705 FormalPar
*par
= pars_v
[i
];
8706 par
->set_fullname(p_fullname
+ "." + par
->get_id().get_dispname());
8710 void FormalParList::set_my_scope(Scope
*p_scope
)
8712 set_parent_scope(p_scope
);
8713 Node::set_my_scope(p_scope
);
8714 // the scope of parameters is set to the parent scope instead of this
8715 // because they cannot refer to each other
8716 for (size_t i
= 0; i
< pars_v
.size(); i
++) pars_v
[i
]->set_my_scope(p_scope
);
8719 void FormalParList::add_fp(FormalPar
*p_fp
)
8721 if (!p_fp
) FATAL_ERROR("NULL parameter: Ttcn::FormalParList::add_fp()");
8723 p_fp
->set_my_parlist(this);
8727 bool FormalParList::has_notused_defval() const
8729 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
8730 if (pars_v
[i
]->has_notused_defval())
8736 bool FormalParList::has_only_default_values() const
8738 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
8739 if (!pars_v
[i
]->has_defval()) {
8747 bool FormalParList::has_fp_withName(const Identifier
& p_name
)
8749 if (!checked
) chk(Definition::A_UNDEF
);
8750 return pars_m
.has_key(p_name
.get_name());
8753 FormalPar
*FormalParList::get_fp_byName(const Identifier
& p_name
)
8755 if (!checked
) chk(Definition::A_UNDEF
);
8756 return pars_m
[p_name
.get_name()];
8759 bool FormalParList::get_startability()
8761 if(!checked
) FATAL_ERROR("FormalParList::get_startability()");
8762 return is_startable
;
8765 Common::Assignment
*FormalParList::get_ass_bySRef(Common::Ref_simple
*p_ref
)
8767 if (!p_ref
|| !checked
) FATAL_ERROR("FormalParList::get_ass_bySRef()");
8768 if (p_ref
->get_modid()) return parent_scope
->get_ass_bySRef(p_ref
);
8770 const string
& name
= p_ref
->get_id()->get_name();
8771 if (pars_m
.has_key(name
)) return pars_m
[name
];
8772 else return parent_scope
->get_ass_bySRef(p_ref
);
8776 bool FormalParList::has_ass_withId(const Identifier
& p_id
)
8778 if (!checked
) FATAL_ERROR("Ttcn::FormalParList::has_ass_withId()");
8779 return pars_m
.has_key(p_id
.get_name())
8780 || parent_scope
->has_ass_withId(p_id
);
8783 void FormalParList::set_genname(const string
& p_prefix
)
8785 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
8786 FormalPar
*par
= pars_v
[i
];
8787 const string
& par_name
= par
->get_id().get_name();
8788 if (par
->get_asstype() != Definition::A_PAR_TIMER
)
8789 par
->get_Type()->set_genname(p_prefix
, par_name
);
8790 if (par
->has_defval()) {
8791 string
embedded_genname(p_prefix
);
8792 embedded_genname
+= '_';
8793 embedded_genname
+= par_name
;
8794 embedded_genname
+= "_defval";
8795 ActualPar
*defval
= par
->get_defval();
8796 switch (defval
->get_selection()) {
8797 case ActualPar::AP_ERROR
:
8798 case ActualPar::AP_REF
:
8800 case ActualPar::AP_VALUE
: {
8801 Value
*v
= defval
->get_Value();
8802 v
->set_genname_prefix("const_");
8803 v
->set_genname_recursive(embedded_genname
);
8805 case ActualPar::AP_TEMPLATE
: {
8806 Template
*t
= defval
->get_TemplateInstance()->get_Template();
8807 t
->set_genname_prefix("template_");
8808 t
->set_genname_recursive(embedded_genname
);
8811 FATAL_ERROR("FormalParList::set_genname()");
8817 void FormalParList::chk(Definition::asstype_t deftype
)
8819 if (checked
) return;
8822 is_startable
= true;
8823 Error_Context
cntxt(this, "In formal parameter list");
8824 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
8825 FormalPar
*par
= pars_v
[i
];
8826 const Identifier
& id
= par
->get_id();
8827 const string
& name
= id
.get_name();
8828 const char *dispname
= id
.get_dispname().c_str();
8829 if (pars_m
.has_key(name
)) {
8830 par
->error("Duplicate parameter with name `%s'", dispname
);
8831 pars_m
[name
]->note("Previous definition of `%s' is here", dispname
);
8833 pars_m
.add(name
, par
);
8834 if (parent_scope
&& parent_scope
->has_ass_withId(id
)) {
8835 par
->error("Parameter name `%s' is not unique in the scope "
8836 "hierarchy", dispname
);
8837 Reference
ref(0, id
.clone());
8838 Common::Assignment
*ass
= parent_scope
->get_ass_bySRef(&ref
);
8839 if (!ass
) FATAL_ERROR("FormalParList::chk()");
8840 ass
->note("Symbol `%s' is already defined here in a higher scope "
8844 Error_Context
cntxt2(par
, "In parameter `%s'", dispname
);
8846 // check whether the parameter type is allowed
8848 case Definition::A_TEMPLATE
:
8849 switch (par
->get_asstype()) {
8850 case Definition::A_PAR_VAL_IN
:
8851 case Definition::A_PAR_TEMPL_IN
:
8852 // these are allowed
8855 par
->error("A template cannot have %s", par
->get_assname());
8858 case Definition::A_TESTCASE
:
8859 switch (par
->get_asstype()) {
8860 case Definition::A_PAR_TIMER
:
8861 case Definition::A_PAR_PORT
:
8862 // these are forbidden
8863 par
->error("A testcase cannot have %s", par
->get_assname());
8868 // everything is allowed for functions and altsteps
8872 switch(par
->get_asstype()) {
8873 case Common::Assignment::A_PAR_VAL_IN
:
8874 case Common::Assignment::A_PAR_TEMPL_IN
:
8875 case Common::Assignment::A_PAR_VAL_INOUT
:
8876 case Common::Assignment::A_PAR_TEMPL_INOUT
:
8877 if (is_startable
&& par
->get_Type()->is_component_internal())
8878 is_startable
= false;
8881 is_startable
= false;
8884 if (!par
->has_defval()) min_nof_pars
= i
+ 1;
8885 // the last parameter without a default value determines the minimum
8889 // check that @lazy paramterization not used in cases currently unsupported
8890 void FormalParList::chk_noLazyParams() {
8891 Error_Context
cntxt(this, "In formal parameter list");
8892 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
8893 FormalPar
*par
= pars_v
[i
];
8894 if (par
->get_lazy_eval()) {
8895 par
->error("Formal parameter `%s' cannot be @lazy, not supported in this case.",
8896 par
->get_id().get_dispname().c_str());
8901 void FormalParList::chk_startability(const char *p_what
, const char *p_name
)
8903 if(!checked
) FATAL_ERROR("FormalParList::chk_startability()");
8904 if (is_startable
) return;
8905 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
8906 FormalPar
*par
= pars_v
[i
];
8907 switch (par
->get_asstype()) {
8908 case Common::Assignment::A_PAR_VAL_IN
:
8909 case Common::Assignment::A_PAR_TEMPL_IN
:
8910 case Common::Assignment::A_PAR_VAL_INOUT
:
8911 case Common::Assignment::A_PAR_TEMPL_INOUT
:
8912 if (par
->get_Type()->is_component_internal()) {
8913 map
<Type
*,void> type_chain
;
8914 char* err_str
= mprintf("a parameter or embedded in a parameter of "
8915 "a function used in a start operation. "
8916 "%s `%s' cannot be started on a parallel test component "
8917 "because of `%s'", p_what
, p_name
, par
->get_description().c_str());
8918 par
->get_Type()->chk_component_internal(type_chain
, err_str
);
8923 par
->error("%s `%s' cannot be started on a parallel test component "
8924 "because it has %s", p_what
, p_name
, par
->get_description().c_str());
8929 void FormalParList::chk_compatibility(FormalParList
* p_fp_list
,
8932 size_t nof_type_pars
= pars_v
.size();
8933 size_t nof_function_pars
= p_fp_list
->pars_v
.size();
8934 // check for the number of parameters
8935 if (nof_type_pars
!= nof_function_pars
) {
8936 p_fp_list
->error("Too %s parameters: %lu was expected instead of %lu",
8937 nof_type_pars
< nof_function_pars
? "many" : "few",
8938 (unsigned long) nof_type_pars
, (unsigned long) nof_function_pars
);
8940 size_t upper_limit
=
8941 nof_type_pars
< nof_function_pars
? nof_type_pars
: nof_function_pars
;
8942 for (size_t i
= 0; i
< upper_limit
; i
++) {
8943 FormalPar
*type_par
= pars_v
[i
];
8944 FormalPar
*function_par
= p_fp_list
->pars_v
[i
];
8945 Error_Context
cntxt(function_par
, "In parameter #%lu",
8946 (unsigned long) (i
+ 1));
8947 FormalPar::asstype_t type_par_asstype
= type_par
->get_asstype();
8948 FormalPar::asstype_t function_par_asstype
= function_par
->get_asstype();
8949 // check for parameter kind equivalence
8950 // (in, out or inout / value or template)
8951 if (type_par_asstype
!= function_par_asstype
) {
8952 function_par
->error("The kind of the parameter is not the same as in "
8953 "type `%s': %s was expected instead of %s", where
,
8954 type_par
->get_assname(), function_par
->get_assname());
8956 // check for type equivalence
8957 if (type_par_asstype
!= FormalPar::A_PAR_TIMER
&&
8958 function_par_asstype
!= FormalPar::A_PAR_TIMER
) {
8959 Type
*type_par_type
= type_par
->get_Type();
8960 Type
*function_par_type
= function_par
->get_Type();
8961 if (!type_par_type
->is_identical(function_par_type
)) {
8962 function_par_type
->error("The type of the parameter is not the same "
8963 "as in type `%s': `%s' was expected instead of `%s'", where
,
8964 type_par_type
->get_typename().c_str(),
8965 function_par_type
->get_typename().c_str());
8966 } else if (type_par_type
->get_sub_type() && function_par_type
->get_sub_type() &&
8967 (type_par_type
->get_sub_type()->get_subtypetype()==function_par_type
->get_sub_type()->get_subtypetype()) &&
8968 (!type_par_type
->get_sub_type()->is_compatible(function_par_type
->get_sub_type()))) {
8969 // TODO: maybe equivalence should be checked, or maybe that is too strict
8970 function_par_type
->error(
8971 "Subtype mismatch: subtype %s has no common value with subtype %s",
8972 type_par_type
->get_sub_type()->to_string().c_str(),
8973 function_par_type
->get_sub_type()->to_string().c_str());
8976 // check for template restriction equivalence
8977 if (type_par
->get_template_restriction()!=
8978 function_par
->get_template_restriction()) {
8979 function_par
->error("The template restriction of the parameter is "
8980 "not the same as in type `%s': %s restriction was expected instead "
8981 "of %s restriction", where
,
8982 type_par
->get_template_restriction()==TR_NONE
? "no" :
8983 Template::get_restriction_name(type_par
->get_template_restriction()),
8984 function_par
->get_template_restriction()==TR_NONE
? "no" :
8985 Template::get_restriction_name(function_par
->
8986 get_template_restriction()));
8988 // check for @lazy equivalence
8989 if (type_par
->get_lazy_eval()!=function_par
->get_lazy_eval()) {
8990 function_par
->error("Parameter @lazy-ness mismatch");
8992 // check for name equivalence
8993 const Identifier
& type_par_id
= type_par
->get_id();
8994 const Identifier
& function_par_id
= function_par
->get_id();
8995 if (type_par_id
!= function_par_id
) {
8996 function_par
->warning("The name of the parameter is not the same "
8997 "as in type `%s': `%s' was expected instead of `%s'", where
,
8998 type_par_id
.get_dispname().c_str(),
8999 function_par_id
.get_dispname().c_str());
9004 bool FormalParList::fold_named_and_chk(ParsedActualParameters
*p_paps
,
9005 ActualParList
*p_aplist
)
9007 const size_t num_named
= p_paps
->get_nof_nps();
9008 const size_t num_unnamed
= p_paps
->get_nof_tis();
9009 size_t num_actual
= num_unnamed
;
9011 // Construct a map to tell us what index a FormalPar has
9012 typedef map
<FormalPar
*, size_t> formalpar_map_t
;
9013 formalpar_map_t formalpar_map
;
9015 size_t num_fp
= get_nof_fps();
9016 for (size_t fpx
= 0; fpx
< num_fp
; ++fpx
) {
9017 FormalPar
*fp
= get_fp_byIndex(fpx
);
9018 formalpar_map
.add(fp
, new size_t(fpx
));
9021 // Go through the named parameters
9022 for (size_t i
= 0; i
< num_named
; ++i
) {
9023 NamedParam
*np
= p_paps
->extract_np_byIndex(i
);
9024 // We are now responsible for np.
9026 if (has_fp_withName(*np
->get_name())) {
9027 // there is a formal parameter with that name
9028 FormalPar
*fp
= get_fp_byName(*np
->get_name());
9029 const size_t is_at
= *formalpar_map
[fp
]; // the index of the formal par
9030 if (is_at
>= num_actual
) {
9031 // There is no actual par in the unnamed part.
9032 // Create one from the named param.
9034 // First, pad the gap with '-'
9035 for (; num_actual
< is_at
; ++num_actual
) {
9037 if (pars_v
[num_actual
]->has_defval()) {
9038 not_used
= new Template(Template::TEMPLATE_NOTUSED
);
9040 else { // cannot use '-' if no default value
9041 not_used
= new Template(Template::TEMPLATE_ERROR
);
9043 TemplateInstance
*new_ti
= new TemplateInstance(0, 0, not_used
);
9044 // Conjure a location info at the beginning of the unnamed part
9045 // (that is, the beginning of the actual parameter list)
9046 new_ti
->set_location(p_paps
->get_tis()->get_filename(),
9047 p_paps
->get_tis()->get_first_line(),
9048 p_paps
->get_tis()->get_first_column(), 0, 0);
9049 p_paps
->get_tis()->add_ti(new_ti
);
9051 TemplateInstance
* namedti
= np
->extract_ti();
9052 p_paps
->get_tis()->add_ti(namedti
);
9055 // There is already an actual par at that position, fetch it
9056 TemplateInstance
* ti
= p_paps
->get_tis()->get_ti_byIndex(is_at
);
9057 Template::templatetype_t tt
= ti
->get_Template()->get_templatetype();
9059 if (is_at
>= num_unnamed
&& !ti
->get_Type() && !ti
->get_DerivedRef()
9060 && (tt
== Template::TEMPLATE_NOTUSED
|| tt
== Template::TEMPLATE_ERROR
)) {
9061 // NotUsed in the named part => padding
9062 np
->error("Named parameter `%s' out of order",
9063 np
->get_name()->get_dispname().c_str());
9065 // attempt to override an original unnamed param with a named one
9066 np
->error("Formal parameter `%s' assigned more than once",
9067 np
->get_name()->get_dispname().c_str());
9071 else { // no formal parameter with that name
9073 switch (my_def
->get_asstype()) {
9074 case Common::Assignment::A_TYPE
: {
9075 Type
*t
= my_def
->get_Type();
9077 switch (t
? t
->get_typetype() : 0) {
9078 case Type::T_FUNCTION
:
9079 nam
= mcopystr("Function reference");
9081 case Type::T_ALTSTEP
:
9082 nam
= mcopystr("Altstep reference");
9084 case Type::T_TESTCASE
:
9085 nam
= mcopystr("Testcase reference");
9088 FATAL_ERROR("FormalParList::chk_actual_parlist() "
9089 "Unexpected type %s", t
->get_typename().c_str());
9090 } // switch(typetype)
9093 nam
= mcopystr(my_def
->get_assname());
9095 } // switch(asstype)
9097 *nam
&= ~('a'-'A'); // Make the first letter uppercase
9098 p_paps
->get_tis()->error("%s `%s' has no formal parameter `%s'",
9100 my_def
->get_fullname().c_str(),
9101 np
->get_name()->get_dispname().c_str());
9108 for (size_t fpx
= 0; fpx
< num_fp
; ++fpx
) {
9109 delete formalpar_map
.get_nth_elem(fpx
);
9111 formalpar_map
.clear();
9113 return chk_actual_parlist(p_paps
->get_tis(), p_aplist
);
9116 bool FormalParList::chk_actual_parlist(TemplateInstances
*p_tis
,
9117 ActualParList
*p_aplist
)
9119 size_t formal_pars
= pars_v
.size();
9120 size_t actual_pars
= p_tis
->get_nof_tis();
9121 // p_aplist->get_nof_pars() is usually 0 on entry
9122 bool error_flag
= false;
9124 if (min_nof_pars
== formal_pars
) {
9125 // none of the parameters have default value
9126 if (actual_pars
!= formal_pars
) {
9127 p_tis
->error("Too %s parameters: %lu was expected "
9128 "instead of %lu", actual_pars
< formal_pars
? "few" : "many",
9129 (unsigned long) formal_pars
, (unsigned long) actual_pars
);
9133 // some parameters have default value
9134 if (actual_pars
< min_nof_pars
) {
9135 p_tis
->error("Too few parameters: at least %lu "
9136 "was expected instead of %lu",
9137 (unsigned long) min_nof_pars
, (unsigned long) actual_pars
);
9139 } else if (actual_pars
> formal_pars
) {
9140 p_tis
->error("Too many parameters: at most %lu "
9141 "was expected instead of %lu",
9142 (unsigned long) formal_pars
, (unsigned long) actual_pars
);
9147 // Do not check actual parameters in excess of the formal ones
9148 size_t upper_limit
= actual_pars
< formal_pars
? actual_pars
: formal_pars
;
9149 for (size_t i
= 0; i
< upper_limit
; i
++) {
9150 TemplateInstance
*ti
= p_tis
->get_ti_byIndex(i
);
9152 // the formal parameter for the current actual parameter
9153 FormalPar
*fp
= pars_v
[i
];
9154 Error_Context
cntxt(ti
, "In parameter #%lu for `%s'",
9155 (unsigned long) (i
+ 1), fp
->get_id().get_dispname().c_str());
9156 if (!ti
->get_Type() && !ti
->get_DerivedRef() && ti
->get_Template()
9157 ->get_templatetype() == Template::TEMPLATE_NOTUSED
) {
9158 if (fp
->has_defval()) {
9159 ActualPar
*defval
= fp
->get_defval();
9160 p_aplist
->add(new ActualPar(defval
));
9161 if (defval
->is_erroneous()) error_flag
= true;
9163 ti
->error("Not used symbol (`-') cannot be used for parameter "
9164 "that does not have default value");
9165 p_aplist
->add(new ActualPar());
9168 } else if (!ti
->get_Type() && !ti
->get_DerivedRef() && ti
->get_Template()
9169 ->get_templatetype() == Template::TEMPLATE_ERROR
) {
9170 ti
->error("Parameter not specified");
9172 ActualPar
*ap
= fp
->chk_actual_par(ti
, Type::EXPECTED_DYNAMIC_VALUE
);
9174 if (ap
->is_erroneous()) error_flag
= true;
9178 // The rest of formal parameters have no corresponding actual parameters.
9179 // Create actual parameters for them based on their default values
9180 // (which must exist).
9181 for (size_t i
= upper_limit
; i
< formal_pars
; i
++) {
9182 FormalPar
*fp
= pars_v
[i
];
9183 if (fp
->has_defval()) {
9184 ActualPar
*defval
= fp
->get_defval();
9185 p_aplist
->add(new ActualPar(defval
));
9186 if (defval
->is_erroneous()) error_flag
= true;
9188 p_aplist
->add(new ActualPar()); // erroneous
9195 bool FormalParList::chk_activate_argument(ActualParList
*p_aplist
,
9196 const char* p_description
)
9198 bool ret_val
= true;
9199 for(size_t i
= 0; i
< p_aplist
->get_nof_pars(); i
++) {
9200 ActualPar
*t_ap
= p_aplist
->get_par(i
);
9201 if(t_ap
->get_selection() != ActualPar::AP_REF
) continue;
9202 FormalPar
*t_fp
= pars_v
[i
];
9203 switch(t_fp
->get_asstype()) {
9204 case Common::Assignment::A_PAR_VAL_OUT
:
9205 case Common::Assignment::A_PAR_VAL_INOUT
:
9206 case Common::Assignment::A_PAR_TEMPL_OUT
:
9207 case Common::Assignment::A_PAR_TEMPL_INOUT
:
9208 case Common::Assignment::A_PAR_TIMER
:
9209 //the checking shall be performed for these parameter types
9211 case Common::Assignment::A_PAR_PORT
:
9212 // port parameters are always correct because ports can be defined
9213 // only in component types
9216 FATAL_ERROR("FormalParList::chk_activate_argument()");
9218 Ref_base
*t_ref
= t_ap
->get_Ref();
9219 Common::Assignment
*t_par_ass
= t_ref
->get_refd_assignment();
9220 if(!t_par_ass
) FATAL_ERROR("FormalParList::chk_activate_argument()");
9221 switch (t_par_ass
->get_asstype()) {
9222 case Common::Assignment::A_VAR
:
9223 case Common::Assignment::A_VAR_TEMPLATE
:
9224 case Common::Assignment::A_TIMER
:
9225 // it is not allowed to pass references of local variables or timers
9226 if (t_par_ass
->is_local()) {
9227 t_ref
->error("Parameter #%lu of %s refers to %s, which is a local "
9228 "definition within a statement block and may have shorter "
9229 "lifespan than the activated default. Only references to "
9230 "variables and timers defined in the component type can be passed "
9231 "to activated defaults", (unsigned long) (i
+ 1), p_description
,
9232 t_par_ass
->get_description().c_str());
9236 case Common::Assignment::A_PAR_VAL_IN
:
9237 case Common::Assignment::A_PAR_VAL_OUT
:
9238 case Common::Assignment::A_PAR_VAL_INOUT
:
9239 case Common::Assignment::A_PAR_TEMPL_IN
:
9240 case Common::Assignment::A_PAR_TEMPL_OUT
:
9241 case Common::Assignment::A_PAR_TEMPL_INOUT
:
9242 case Common::Assignment::A_PAR_TIMER
: {
9243 // it is not allowed to pass references pointing to formal parameters
9244 // except for activate() statements within testcases
9245 // note: all defaults are deactivated at the end of the testcase
9246 FormalPar
*t_refd_fp
= dynamic_cast<FormalPar
*>(t_par_ass
);
9247 if (!t_refd_fp
) FATAL_ERROR("FormalParList::chk_activate_argument()");
9248 FormalParList
*t_fpl
= t_refd_fp
->get_my_parlist();
9249 if (!t_fpl
|| !t_fpl
->my_def
)
9250 FATAL_ERROR("FormalParList::chk_activate_argument()");
9251 if (t_fpl
->my_def
->get_asstype() != Common::Assignment::A_TESTCASE
) {
9252 t_ref
->error("Parameter #%lu of %s refers to %s, which may have "
9253 "shorter lifespan than the activated default. Only references to "
9254 "variables and timers defined in the component type can be passed "
9255 "to activated defaults", (unsigned long) (i
+ 1), p_description
,
9256 t_par_ass
->get_description().c_str());
9266 char *FormalParList::generate_code(char *str
, size_t display_unused
/* = 0 */)
9268 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
9269 if (i
> 0) str
= mputstr(str
, ", ");
9270 str
= pars_v
[i
]->generate_code_fpar(str
, i
< display_unused
);
9275 char* FormalParList::generate_code_defval(char* str
)
9277 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
9278 str
= pars_v
[i
]->generate_code_defval(str
);
9283 void FormalParList::generate_code_defval(output_struct
*target
)
9285 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
9286 pars_v
[i
]->generate_code_defval(target
);
9290 char *FormalParList::generate_code_actual_parlist(char *str
,
9291 const char *p_prefix
)
9293 for (size_t i
= 0; i
< pars_v
.size(); i
++) {
9294 if (i
> 0) str
= mputstr(str
, ", ");
9295 str
= mputstr(str
, p_prefix
);
9296 str
= mputstr(str
, pars_v
[i
]->get_id().get_name().c_str());
9301 char *FormalParList::generate_code_object(char *str
, const char *p_prefix
, char refch
)
9303 for (size_t i
= 0; i
< pars_v
.size(); i
++)
9304 str
= pars_v
[i
]->generate_code_object(str
, p_prefix
, refch
);
9308 char *FormalParList::generate_shadow_objects(char *str
) const
9310 for (size_t i
= 0; i
< pars_v
.size(); i
++)
9311 str
= pars_v
[i
]->generate_shadow_object(str
);
9315 char *FormalParList::generate_code_set_unbound(char *str
) const
9317 if (enable_set_bound_out_param
) return str
;
9318 for (size_t i
= 0; i
< pars_v
.size(); i
++)
9319 str
= pars_v
[i
]->generate_code_set_unbound(str
);
9324 void FormalParList::dump(unsigned level
) const
9326 size_t nof_pars
= pars_v
.size();
9327 DEBUG(level
, "formal parameters: %lu pcs.", (unsigned long) nof_pars
);
9328 for(size_t i
= 0; i
< nof_pars
; i
++) pars_v
[i
]->dump(level
+ 1);
9331 // =================================
9333 // =================================
9335 ActualPar::ActualPar(Value
*v
)
9336 : Node(), selection(AP_VALUE
), my_scope(0), gen_restriction_check(TR_NONE
),
9337 gen_post_restriction_check(TR_NONE
)
9339 if (!v
) FATAL_ERROR("ActualPar::ActualPar()");
9343 ActualPar::ActualPar(TemplateInstance
*t
)
9344 : Node(), selection(AP_TEMPLATE
), my_scope(0),
9345 gen_restriction_check(TR_NONE
), gen_post_restriction_check(TR_NONE
)
9347 if (!t
) FATAL_ERROR("ActualPar::ActualPar()");
9351 ActualPar::ActualPar(Ref_base
*r
)
9352 : Node(), selection(AP_REF
), my_scope(0), gen_restriction_check(TR_NONE
),
9353 gen_post_restriction_check(TR_NONE
)
9355 if (!r
) FATAL_ERROR("ActualPar::ActualPar()");
9359 ActualPar::ActualPar(ActualPar
*a
)
9360 : Node(), selection(AP_DEFAULT
), my_scope(0),
9361 gen_restriction_check(TR_NONE
), gen_post_restriction_check(TR_NONE
)
9363 if (!a
) FATAL_ERROR("ActualPar::ActualPar()");
9367 ActualPar::~ActualPar()
9382 break; // nothing to do with act
9384 FATAL_ERROR("ActualPar::~ActualPar()");
9388 ActualPar
*ActualPar::clone() const
9390 FATAL_ERROR("ActualPar::clone");
9393 void ActualPar::set_fullname(const string
& p_fullname
)
9395 Node::set_fullname(p_fullname
);
9400 val
->set_fullname(p_fullname
);
9403 temp
->set_fullname(p_fullname
);
9406 ref
->set_fullname(p_fullname
);
9411 FATAL_ERROR("ActualPar::set_fullname()");
9415 void ActualPar::set_my_scope(Scope
*p_scope
)
9422 val
->set_my_scope(p_scope
);
9425 temp
->set_my_scope(p_scope
);
9428 ref
->set_my_scope(p_scope
);
9431 switch (act
->selection
) {
9433 ref
->set_my_scope(p_scope
);
9440 FATAL_ERROR("ActualPar::set_my_scope()");
9444 FATAL_ERROR("ActualPar::set_my_scope()");
9448 Value
*ActualPar::get_Value() const
9450 if (selection
!= AP_VALUE
) FATAL_ERROR("ActualPar::get_Value()");
9454 TemplateInstance
*ActualPar::get_TemplateInstance() const
9456 if (selection
!= AP_TEMPLATE
)
9457 FATAL_ERROR("ActualPar::get_TemplateInstance()");
9461 Ref_base
*ActualPar::get_Ref() const
9463 if (selection
!= AP_REF
) FATAL_ERROR("ActualPar::get_Ref()");
9467 ActualPar
*ActualPar::get_ActualPar() const
9469 if (selection
!= AP_DEFAULT
) FATAL_ERROR("ActualPar::get_ActualPar()");
9473 void ActualPar::chk_recursions(ReferenceChain
& refch
)
9475 switch (selection
) {
9478 val
->chk_recursions(refch
);
9482 Ref_base
*derived_ref
= temp
->get_DerivedRef();
9484 ActualParList
*parlist
= derived_ref
->get_parlist();
9487 parlist
->chk_recursions(refch
);
9492 Ttcn::Def_Template
* defTemp
= temp
->get_Referenced_Base_Template();
9495 refch
.add(defTemp
->get_fullname());
9499 temp
->get_Template()->chk_recursions(refch
);
9507 bool ActualPar::has_single_expr()
9509 switch (selection
) {
9511 return val
->has_single_expr();
9513 if (gen_restriction_check
!=TR_NONE
||
9514 gen_post_restriction_check
!=TR_NONE
) return false;
9515 return temp
->has_single_expr();
9517 if (gen_restriction_check
!=TR_NONE
||
9518 gen_post_restriction_check
!=TR_NONE
) return false;
9519 if (use_runtime_2
&& ref
->get_subrefs() != NULL
) {
9520 FieldOrArrayRefs
* subrefs
= ref
->get_subrefs();
9521 for (size_t i
= 0; i
< subrefs
->get_nof_refs(); ++i
) {
9522 if (FieldOrArrayRef::ARRAY_REF
== subrefs
->get_ref(i
)->get_type()) {
9527 return ref
->has_single_expr();
9531 FATAL_ERROR("ActualPar::has_single_expr()");
9536 void ActualPar::set_code_section(
9537 GovernedSimple::code_section_t p_code_section
)
9539 switch (selection
) {
9541 val
->set_code_section(p_code_section
);
9544 temp
->set_code_section(p_code_section
);
9547 ref
->set_code_section(p_code_section
);
9553 void ActualPar::generate_code(expression_struct
*expr
, bool copy_needed
, bool lazy_param
, bool used_as_lvalue
) const
9555 switch (selection
) {
9557 if (lazy_param
) { // copy_needed doesn't matter in this case
9558 LazyParamData::init(used_as_lvalue
);
9559 LazyParamData::generate_code(expr
, val
, my_scope
);
9560 LazyParamData::clean();
9561 if (val
->get_valuetype() == Value::V_REFD
) {
9562 // check if the reference is a parameter, mark it as used if it is
9563 Reference
* ref
= dynamic_cast<Reference
*>(val
->get_reference());
9565 ref
->ref_usage_found();
9569 if (copy_needed
) expr
->expr
= mputprintf(expr
->expr
, "%s(",
9570 val
->get_my_governor()->get_genname_value(my_scope
).c_str());
9571 if (use_runtime_2
&& TypeConv::needs_conv_refd(val
)) {
9572 // Generate everything to preamble to be able to tackle the wrapper
9573 // constructor call. TODO: Reduce the number of temporaries created.
9574 const string
& tmp_id
= val
->get_temporary_id();
9575 const char *tmp_id_str
= tmp_id
.c_str();
9576 expr
->preamble
= mputprintf(expr
->preamble
, "%s %s;\n",
9577 val
->get_my_governor()->get_genname_value(my_scope
).c_str(),
9579 expr
->preamble
= TypeConv::gen_conv_code_refd(expr
->preamble
,
9581 expr
->expr
= mputstr(expr
->expr
, tmp_id_str
);
9582 } else val
->generate_code_expr(expr
);
9583 if (copy_needed
) expr
->expr
= mputc(expr
->expr
, ')');
9587 if (lazy_param
) { // copy_needed doesn't matter in this case
9588 LazyParamData::init(used_as_lvalue
);
9589 LazyParamData::generate_code(expr
, temp
, gen_restriction_check
, my_scope
);
9590 LazyParamData::clean();
9591 if (temp
->get_DerivedRef() != NULL
||
9592 temp
->get_Template()->get_templatetype() == Template::TEMPLATE_REFD
) {
9593 // check if the reference is a parameter, mark it as used if it is
9594 Reference
* ref
= dynamic_cast<Reference
*>(temp
->get_DerivedRef() != NULL
?
9595 temp
->get_DerivedRef() : temp
->get_Template()->get_reference());
9597 ref
->ref_usage_found();
9602 expr
->expr
= mputprintf(expr
->expr
, "%s(", temp
->get_Template()
9603 ->get_my_governor()->get_genname_template(my_scope
).c_str());
9604 if (use_runtime_2
&& TypeConv::needs_conv_refd(temp
->get_Template())) {
9605 const string
& tmp_id
= temp
->get_Template()->get_temporary_id();
9606 const char *tmp_id_str
= tmp_id
.c_str();
9607 expr
->preamble
= mputprintf(expr
->preamble
, "%s %s;\n",
9608 temp
->get_Template()->get_my_governor()
9609 ->get_genname_template(my_scope
).c_str(), tmp_id_str
);
9610 expr
->preamble
= TypeConv::gen_conv_code_refd(expr
->preamble
,
9611 tmp_id_str
, temp
->get_Template());
9612 // Not incorporated into gen_conv_code() yet.
9613 if (gen_restriction_check
!= TR_NONE
)
9614 expr
->preamble
= Template::generate_restriction_check_code(
9615 expr
->preamble
, tmp_id_str
, gen_restriction_check
);
9616 expr
->expr
= mputstr(expr
->expr
, tmp_id_str
);
9617 } else temp
->generate_code(expr
, gen_restriction_check
);
9618 if (copy_needed
) expr
->expr
= mputc(expr
->expr
, ')');
9622 if (lazy_param
) FATAL_ERROR("ActualPar::generate_code()"); // syntax error should have already happened
9623 if (copy_needed
) FATAL_ERROR("ActualPar::generate_code()");
9624 if (gen_restriction_check
!= TR_NONE
||
9625 gen_post_restriction_check
!= TR_NONE
) {
9626 // generate runtime check for restricted templates
9627 // code for reference + restriction check
9628 Common::Assignment
*ass
= ref
->get_refd_assignment();
9629 const string
& tmp_id
= my_scope
->get_scope_mod_gen()->get_temporary_id();
9630 const char *tmp_id_str
= tmp_id
.c_str();
9631 expression_struct ref_expr
;
9632 Code::init_expr(&ref_expr
);
9633 ref
->generate_code_const_ref(&ref_expr
);
9634 ref_expr
.preamble
= mputprintf(ref_expr
.preamble
, "%s& %s = %s;\n",
9635 ass
->get_Type()->get_genname_template(ref
->get_my_scope()).c_str(),
9636 tmp_id_str
, ref_expr
.expr
);
9637 if (gen_restriction_check
!= TR_NONE
) {
9638 ref_expr
.preamble
= Template::generate_restriction_check_code(
9639 ref_expr
.preamble
, tmp_id_str
, gen_restriction_check
);
9641 if (gen_post_restriction_check
!= TR_NONE
) {
9642 ref_expr
.postamble
= Template::generate_restriction_check_code(
9643 ref_expr
.postamble
, tmp_id_str
, gen_post_restriction_check
);
9645 // copy content of ref_expr to expr
9646 expr
->preamble
= mputstr(expr
->preamble
, ref_expr
.preamble
);
9647 expr
->expr
= mputprintf(expr
->expr
, "%s", tmp_id_str
);
9648 expr
->postamble
= mputstr(expr
->postamble
, ref_expr
.postamble
);
9649 Code::free_expr(&ref_expr
);
9651 ref
->generate_code(expr
);
9655 if (copy_needed
) FATAL_ERROR("ActualPar::generate_code()");
9656 switch (act
->selection
) {
9659 LazyParamData::generate_code_ap_default_ref(expr
, act
->ref
, my_scope
);
9661 act
->ref
->generate_code(expr
);
9666 LazyParamData::generate_code_ap_default_value(expr
, act
->val
, my_scope
);
9668 expr
->expr
= mputstr(expr
->expr
, act
->val
->get_genname_own(my_scope
).c_str());
9673 LazyParamData::generate_code_ap_default_ti(expr
, act
->temp
, my_scope
);
9675 expr
->expr
= mputstr(expr
->expr
, act
->temp
->get_Template()->get_genname_own(my_scope
).c_str());
9679 FATAL_ERROR("ActualPar::generate_code()");
9683 FATAL_ERROR("ActualPar::generate_code()");
9687 char *ActualPar::rearrange_init_code(char *str
, Common::Module
* usage_mod
)
9689 switch (selection
) {
9691 str
= val
->rearrange_init_code(str
, usage_mod
);
9694 str
= temp
->rearrange_init_code(str
, usage_mod
);
9698 str
= act
->rearrange_init_code_defval(str
, usage_mod
);
9701 FATAL_ERROR("ActualPar::rearrange_init_code()");
9706 char *ActualPar::rearrange_init_code_defval(char *str
, Common::Module
* usage_mod
)
9708 switch (selection
) {
9710 if (val
->get_my_scope()->get_scope_mod_gen() == usage_mod
) {
9711 str
= val
->generate_code_init(str
, val
->get_lhs_name().c_str());
9715 str
= temp
->rearrange_init_code(str
, usage_mod
);
9716 Template
*t
= temp
->get_Template();
9717 if (t
->get_my_scope()->get_scope_mod_gen() == usage_mod
) {
9718 Ref_base
*dref
= temp
->get_DerivedRef();
9720 expression_struct expr
;
9721 Code::init_expr(&expr
);
9722 expr
.expr
= mputprintf(expr
.expr
, "%s = ", t
->get_lhs_name().c_str());
9723 dref
->generate_code(&expr
);
9724 str
= Code::merge_free_expr(str
, &expr
, false);
9726 str
= t
->generate_code_init(str
, t
->get_lhs_name().c_str());
9730 FATAL_ERROR("ActualPar::rearrange_init_code_defval()");
9735 void ActualPar::append_stringRepr(string
& str
) const
9737 switch (selection
) {
9739 str
+= val
->get_stringRepr();
9742 temp
->append_stringRepr(str
);
9745 str
+= ref
->get_dispname();
9751 str
+= "<erroneous actual parameter>";
9755 void ActualPar::dump(unsigned level
) const
9757 switch (selection
) {
9759 DEBUG(level
, "actual parameter: value");
9760 val
->dump(level
+ 1);
9763 DEBUG(level
, "actual parameter: template");
9764 temp
->dump(level
+ 1);
9767 DEBUG(level
, "actual parameter: reference");
9768 ref
->dump(level
+ 1);
9771 DEBUG(level
, "actual parameter: default");
9774 DEBUG(level
, "actual parameter: erroneous");
9778 // =================================
9779 // ===== ActualParList
9780 // =================================
9782 ActualParList::ActualParList(const ActualParList
& p
)
9785 size_t nof_pars
= p
.params
.size();
9786 for (size_t i
= 0; i
< nof_pars
; i
++) params
.add(p
.params
[i
]->clone());
9789 ActualParList::~ActualParList()
9791 size_t nof_pars
= params
.size();
9792 for (size_t i
= 0; i
< nof_pars
; i
++) delete params
[i
];
9796 ActualParList
*ActualParList::clone() const
9798 return new ActualParList(*this);
9801 void ActualParList::set_fullname(const string
& p_fullname
)
9803 Node::set_fullname(p_fullname
);
9804 size_t nof_pars
= params
.size();
9805 for(size_t i
= 0; i
< nof_pars
; i
++)
9806 params
[i
]->set_fullname(p_fullname
+
9807 ".<parameter" + Int2string(i
+ 1) + ">");
9810 void ActualParList::set_my_scope(Scope
*p_scope
)
9812 size_t nof_pars
= params
.size();
9813 for (size_t i
= 0; i
< nof_pars
; i
++) params
[i
]->set_my_scope(p_scope
);
9816 void ActualParList::chk_recursions(ReferenceChain
& refch
)
9818 size_t nof_pars
= params
.size();
9819 for (size_t i
= 0; i
< nof_pars
; i
++)
9820 params
[i
]->chk_recursions(refch
);
9823 void ActualParList::generate_code_noalias(expression_struct
*expr
, FormalParList
*p_fpl
)
9825 size_t nof_pars
= params
.size();
9826 for (size_t i
= 0; i
< nof_pars
; i
++) {
9827 if (i
> 0) expr
->expr
= mputstr(expr
->expr
, ", ");
9828 params
[i
]->generate_code(expr
, false, p_fpl
&& p_fpl
->get_fp_byIndex(i
)->get_lazy_eval(), p_fpl
&& p_fpl
->get_fp_byIndex(i
)->get_used_as_lvalue());
9832 void ActualParList::generate_code_alias(expression_struct
*expr
,
9833 FormalParList
*p_fpl
, Type
*p_comptype
, bool p_compself
)
9835 size_t nof_pars
= params
.size();
9836 // collect all value and template definitions that are passed by reference
9837 map
<Common::Assignment
*, void> value_refs
, template_refs
;
9838 for (size_t i
= 0; i
< nof_pars
; i
++) {
9839 ActualPar
*par
= params
[i
];
9840 if (par
->get_selection() == ActualPar::AP_DEFAULT
)
9841 par
= par
->get_ActualPar();
9842 if (par
->get_selection() == ActualPar::AP_REF
) {
9843 Common::Assignment
*ass
= par
->get_Ref()->get_refd_assignment();
9844 switch (ass
->get_asstype()) {
9845 case Common::Assignment::A_VAR
:
9846 case Common::Assignment::A_PAR_VAL_IN
:
9847 case Common::Assignment::A_PAR_VAL_OUT
:
9848 case Common::Assignment::A_PAR_VAL_INOUT
:
9849 if (!value_refs
.has_key(ass
)) value_refs
.add(ass
, 0);
9851 case Common::Assignment::A_VAR_TEMPLATE
:
9852 case Common::Assignment::A_PAR_TEMPL_IN
:
9853 case Common::Assignment::A_PAR_TEMPL_OUT
:
9854 case Common::Assignment::A_PAR_TEMPL_INOUT
:
9855 if (!template_refs
.has_key(ass
)) template_refs
.add(ass
, 0);
9861 // walk through the parameter list and generate the code
9862 // add an extra copy constructor call to the referenced value and template
9863 // parameters if the referred definition is also passed by reference to
9864 // another parameter
9865 for (size_t i
= 0; i
< nof_pars
; i
++) {
9866 if (i
> 0) expr
->expr
= mputstr(expr
->expr
, ", ");
9867 ActualPar
*par
= params
[i
];
9868 bool copy_needed
= false;
9869 // the copy constructor call is not needed if the parameter is copied
9870 // into a shadow object in the body of the called function
9871 if (!p_fpl
|| !p_fpl
->get_fp_byIndex(i
)->get_used_as_lvalue()) {
9872 switch (par
->get_selection()) {
9873 case ActualPar::AP_VALUE
: {
9874 Value
*v
= par
->get_Value();
9875 if (v
->get_valuetype() == Value::V_REFD
) {
9876 Common::Assignment
*t_ass
=
9877 v
->get_reference()->get_refd_assignment();
9878 if (value_refs
.has_key(t_ass
)) {
9879 // a reference to the same variable is also passed to the called
9882 } else if (p_comptype
|| p_compself
) {
9883 // the called definition has a 'runs on' clause so it can access
9884 // component variables
9885 switch (t_ass
->get_asstype()) {
9886 case Common::Assignment::A_PAR_VAL_OUT
:
9887 case Common::Assignment::A_PAR_VAL_INOUT
:
9888 // the parameter may be an alias of a component variable
9891 case Common::Assignment::A_VAR
:
9892 // copy is needed if t_ass is a component variable that is
9893 // visible by the called definition
9894 if (!t_ass
->is_local()) copy_needed
= true;
9895 /** \todo component type compatibility: check whether t_ass is
9896 * visible from p_comptype (otherwise copy is not needed) */
9903 case ActualPar::AP_TEMPLATE
: {
9904 TemplateInstance
*ti
= par
->get_TemplateInstance();
9905 if (!ti
->get_DerivedRef()) {
9906 Template
*t
= ti
->get_Template();
9907 if (t
->get_templatetype() == Template::TEMPLATE_REFD
) {
9908 Common::Assignment
*t_ass
=
9909 t
->get_reference()->get_refd_assignment();
9910 if (template_refs
.has_key(t_ass
)) {
9911 // a reference to the same variable is also passed to the called
9914 } else if (p_comptype
|| p_compself
) {
9915 // the called definition has a 'runs on' clause so it can access
9916 // component variables
9917 switch (t_ass
->get_asstype()) {
9918 case Common::Assignment::A_PAR_TEMPL_OUT
:
9919 case Common::Assignment::A_PAR_TEMPL_INOUT
:
9920 // the parameter may be an alias of a component variable
9923 case Common::Assignment::A_VAR_TEMPLATE
:
9924 // copy is needed if t_ass is a component variable that is
9925 // visible by the called definition
9926 if (!t_ass
->is_local()) copy_needed
= true;
9927 /** \todo component type compatibility: check whether t_ass is
9928 * visible from p_comptype (otherwise copy is not needed) */
9940 if (use_runtime_2
&& ActualPar::AP_REF
== par
->get_selection()) {
9941 // if the parameter references an element of a record of/set of, then
9942 // the record of object needs to know, so it doesn't delete the referenced
9944 Ref_base
* ref
= par
->get_Ref();
9945 FieldOrArrayRefs
* subrefs
= ref
->get_subrefs();
9946 if (subrefs
!= NULL
) {
9947 Common::Assignment
* ass
= ref
->get_refd_assignment();
9949 for (ref_i
= 0; ref_i
< subrefs
->get_nof_refs(); ++ref_i
) {
9950 FieldOrArrayRef
* subref
= subrefs
->get_ref(ref_i
);
9951 if (FieldOrArrayRef::ARRAY_REF
== subref
->get_type()) {
9952 // set the referenced index in each array in the subrefs
9953 expression_struct array_expr
;
9954 Code::init_expr(&array_expr
);
9955 // the array object's name contains the reference, followed by
9956 // the subrefs before the current array ref
9957 array_expr
.expr
= mcopystr(LazyParamData::in_lazy() ?
9958 LazyParamData::add_ref_genname(ass
, ref
->get_my_scope()).c_str() :
9959 ass
->get_genname_from_scope(ref
->get_my_scope()).c_str());
9961 subrefs
->generate_code(&array_expr
, ass
, ref_i
);
9963 expression_struct index_expr
;
9964 Code::init_expr(&index_expr
);
9965 subrefs
->get_ref(ref_i
)->get_val()->generate_code_expr(&index_expr
);
9966 // insert any preambles the array object or the index might have
9967 if (array_expr
.preamble
!= NULL
) {
9968 expr
->preamble
= mputstr(expr
->preamble
, array_expr
.preamble
);
9969 expr
->postamble
= mputstr(expr
->postamble
, array_expr
.preamble
);
9971 if (index_expr
.preamble
!= NULL
) {
9972 expr
->preamble
= mputstr(expr
->preamble
, index_expr
.preamble
);
9973 expr
->postamble
= mputstr(expr
->postamble
, index_expr
.preamble
);
9975 // let the array object know that the index is referenced before
9976 // calling the function, and let it know that it's now longer
9977 // referenced after the function call (this is done with the help
9978 // of the RefdIndexHandler's constructor and destructor)
9979 string tmp_id
= ref
->get_my_scope()->get_scope_mod_gen()->get_temporary_id();
9980 expr
->preamble
= mputprintf(expr
->preamble
,
9981 "RefdIndexHandler %s(&%s, %s);\n",
9982 tmp_id
.c_str(), array_expr
.expr
, index_expr
.expr
);
9983 // insert any postambles the array object or the index might have
9984 if (array_expr
.postamble
!= NULL
) {
9985 expr
->preamble
= mputstr(expr
->preamble
, array_expr
.postamble
);
9986 expr
->postamble
= mputstr(expr
->postamble
, array_expr
.postamble
);
9988 if (index_expr
.postamble
!= NULL
) {
9989 expr
->preamble
= mputstr(expr
->preamble
, index_expr
.postamble
);
9990 expr
->postamble
= mputstr(expr
->postamble
, index_expr
.postamble
);
9992 Code::free_expr(&array_expr
);
9993 Code::free_expr(&index_expr
);
9994 } // if (FieldOrArrayRef::ARRAY_REF == subref->get_type())
9996 } // if (subrefs != NULL)
9997 } // if (ActualPar::AP_REF == par->get_selection())
9999 par
->generate_code(expr
, copy_needed
, p_fpl
&& p_fpl
->get_fp_byIndex(i
)->get_lazy_eval(), p_fpl
&& p_fpl
->get_fp_byIndex(i
)->get_used_as_lvalue());
10001 value_refs
.clear();
10002 template_refs
.clear();
10005 char *ActualParList::rearrange_init_code(char *str
, Common::Module
* usage_mod
)
10007 for (size_t i
= 0; i
< params
.size(); i
++)
10008 str
= params
[i
]->rearrange_init_code(str
, usage_mod
);
10012 void ActualParList::dump(unsigned level
) const
10014 DEBUG(level
, "actual parameter list: %lu parameters",
10015 (unsigned long) params
.size());
10016 for (size_t i
= 0; i
< params
.size(); i
++)
10017 params
[i
]->dump(level
+ 1);