1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 #include "../../common/dbgnew.hh"
9 #include "Templatestuff.hh"
10 #include "../Identifier.hh"
11 #include "TtcnTemplate.hh"
12 #include "ArrayDimensions.hh"
18 // =================================
20 // =================================
22 ValueRange::~ValueRange()
28 ValueRange
*ValueRange::clone() const
30 return new ValueRange(*this);
33 ValueRange::ValueRange(const ValueRange
& other
)
35 , min_v(other
.min_v
? other
.min_v
->clone() : 0)
36 , max_v(other
.max_v
? other
.max_v
->clone() : 0)
39 void ValueRange::set_fullname(const string
& p_fullname
)
41 Node::set_fullname(p_fullname
);
42 if (min_v
) min_v
->set_fullname(p_fullname
+ ".<lower_bound>");
43 if (max_v
) max_v
->set_fullname(p_fullname
+ ".<upper_bound>");
46 void ValueRange::set_my_scope(Scope
*p_scope
)
48 Node::set_my_scope(p_scope
);
49 if (min_v
) min_v
->set_my_scope(p_scope
);
50 if (max_v
) max_v
->set_my_scope(p_scope
);
53 void ValueRange::set_lowerid_to_ref()
55 if (min_v
) min_v
->set_lowerid_to_ref();
56 if (max_v
) max_v
->set_lowerid_to_ref();
59 Type::typetype_t
ValueRange::get_expr_returntype(
60 Type::expected_value_t exp_val
)
63 Type::typetype_t tt
= min_v
->get_expr_returntype(exp_val
);
64 if (tt
!= Type::T_UNDEF
) return tt
;
67 Type::typetype_t tt
= max_v
->get_expr_returntype(exp_val
);
68 if (tt
!= Type::T_UNDEF
) return tt
;
73 Type
*ValueRange::get_expr_governor(Type::expected_value_t exp_val
)
76 Type
*t
= min_v
->get_expr_governor(exp_val
);
80 Type
*t
= max_v
->get_expr_governor(exp_val
);
86 void ValueRange::set_code_section
87 (GovernedSimple::code_section_t p_code_section
)
89 if (min_v
) min_v
->set_code_section(p_code_section
);
90 if (max_v
) max_v
->set_code_section(p_code_section
);
93 char *ValueRange::generate_code_init(char *str
, const char *name
)
95 expression_struct expr
;
96 Code::init_expr(&expr
);
97 char *init_stmt
= mprintf("%s.set_type(VALUE_RANGE);\n", name
);
99 min_v
->generate_code_expr(&expr
);
100 init_stmt
= mputprintf(init_stmt
, "%s.set_min(%s);\n", name
, expr
.expr
);
103 Code::clean_expr(&expr
);
104 max_v
->generate_code_expr(&expr
);
105 init_stmt
= mputprintf(init_stmt
, "%s.set_max(%s);\n", name
, expr
.expr
);
107 if (expr
.preamble
|| expr
.postamble
) {
108 str
= mputstr(str
, "{\n");
109 str
= mputstr(str
, expr
.preamble
);
110 str
= mputstr(str
, init_stmt
);
111 str
= mputstr(str
, expr
.postamble
);
112 str
= mputstr(str
, "}\n");
113 } else str
= mputstr(str
, init_stmt
);
114 Code::free_expr(&expr
);
119 char *ValueRange::rearrange_init_code(char *str
)
121 if (min_v
) str
= min_v
->rearrange_init_code(str
);
122 if (max_v
) str
= max_v
->rearrange_init_code(str
);
126 void ValueRange::append_stringRepr(string
& str
) const
129 if (min_v
) str
+= min_v
->get_stringRepr();
130 else str
+= "-infinity";
132 if (max_v
) str
+= max_v
->get_stringRepr();
133 else str
+= "infinity";
137 void ValueRange::dump(unsigned level
) const
140 if (min_v
) min_v
->dump(level
+ 1);
141 else DEBUG(level
+ 1, "-infinity");
142 DEBUG(level
+ 1, "..");
143 if (max_v
) max_v
->dump(level
+ 1);
144 else DEBUG(level
+ 1, "infinity");
148 // =================================
150 // =================================
152 Templates::~Templates()
154 for (size_t i
= 0; i
< ts
.size(); i
++) delete ts
[i
];
158 Templates::Templates(const Templates
& other
)
161 for (size_t i
= 0, lim
= other
.ts
.size(); i
< lim
; ++i
) {
162 ts
.add(other
.ts
[i
]->clone());
166 Templates
*Templates::clone() const
168 return new Templates(*this);
171 void Templates::set_my_scope(Scope
*p_scope
)
173 for (size_t i
= 0; i
< ts
.size(); i
++) ts
[i
]->set_my_scope(p_scope
);
176 void Templates::add_t(Template
*p_t
)
178 if (!p_t
) FATAL_ERROR("NULL pointer:Templates::add_t()");
182 void Templates::add_front_t(Template
*p_t
)
184 if (!p_t
) FATAL_ERROR("NULL pointer:Templates::add_front_t()");
188 void Templates::append_stringRepr(string
& str
) const
190 for (size_t i
= 0; i
< ts
.size(); i
++) {
191 if (i
> 0) str
+= ", ";
192 str
+= ts
[i
]->get_stringRepr();
196 // =================================
197 // ===== IndexedTemplate
198 // =================================
200 IndexedTemplate::IndexedTemplate(FieldOrArrayRef
*p_i
, Template
*p_t
)
202 if (!p_i
|| !p_t
) FATAL_ERROR("IndexedTemplate::IndexedTemplate()");
207 IndexedTemplate::~IndexedTemplate()
213 IndexedTemplate
*IndexedTemplate::clone() const
215 FATAL_ERROR("IndexedTemplate::clone");
218 void IndexedTemplate::set_fullname(const string
& p_fullname
)
220 Node::set_fullname(p_fullname
);
221 temp
->set_fullname(p_fullname
);
222 index
->set_fullname(p_fullname
);
225 void IndexedTemplate::set_my_scope(Scope
*p_scope
)
227 Node::set_my_scope(p_scope
);
228 temp
->set_my_scope(p_scope
);
229 index
->set_my_scope(p_scope
);
232 void IndexedTemplate::set_code_section
233 (GovernedSimple::code_section_t p_code_section
)
235 index
->get_val()->set_code_section(p_code_section
);
236 temp
->set_code_section(p_code_section
);
239 void IndexedTemplate::dump(unsigned level
) const
245 // =================================
246 // ===== IndexedTemplates
247 // =================================
249 IndexedTemplates::~IndexedTemplates()
251 for (size_t i
= 0; i
< its_v
.size(); i
++) delete its_v
[i
];
255 IndexedTemplates
*IndexedTemplates::clone() const
257 FATAL_ERROR("IndexedTemplates::clone");
260 void IndexedTemplates::set_fullname(const string
& p_fullname
)
262 Node::set_fullname(p_fullname
);
263 for(size_t i
= 0; i
< its_v
.size(); i
++) {
264 IndexedTemplate
*it
= its_v
[i
];
265 string t_fullname
= p_fullname
;
266 (it
->get_index()).append_stringRepr(t_fullname
);
267 it
->set_fullname(t_fullname
);
271 void IndexedTemplates::set_my_scope(Scope
*p_scope
)
273 Node::set_my_scope(p_scope
);
274 for (size_t i
= 0; i
< its_v
.size(); i
++)
275 its_v
[i
]->set_my_scope(p_scope
);
278 void IndexedTemplates::add_it(IndexedTemplate
*p_it
)
280 if (!p_it
) FATAL_ERROR("NULL pointer: IndexedTemplates::add_it()");
284 IndexedTemplate
*IndexedTemplates::get_it_byIndex(size_t p_i
)
289 // =================================
290 // ===== NamedTemplate
291 // =================================
293 NamedTemplate::NamedTemplate(Identifier
*p_n
, Template
*p_t
)
295 if (!p_n
|| !p_t
) FATAL_ERROR("NamedTemplate::NamedTemplate()");
300 NamedTemplate::~NamedTemplate()
306 NamedTemplate
*NamedTemplate::clone() const
308 FATAL_ERROR("NamedTemplate::clone");
311 void NamedTemplate::set_fullname(const string
& p_fullname
)
313 Node::set_fullname(p_fullname
);
314 temp
->set_fullname(p_fullname
);
317 void NamedTemplate::set_my_scope(Scope
*p_scope
)
319 Node::set_my_scope(p_scope
);
320 temp
->set_my_scope(p_scope
);
323 void NamedTemplate::set_name_to_lowercase()
325 string new_name
= name
->get_name();
326 if (isupper(new_name
[0])) {
327 new_name
[0] = tolower(new_name
[0]);
328 if (new_name
[new_name
.size() - 1] == '_') {
329 // an underscore is inserted at the end of the alternative name if it's
330 // a basic type's name (since it would conflict with the class generated
332 // remove the underscore, it won't conflict with anything if its name
333 // starts with a lowercase letter
334 new_name
.replace(new_name
.size() - 1, 1, "");
337 name
= new Identifier(Identifier::ID_NAME
, new_name
);
341 Template
* NamedTemplate::extract_template()
343 Template
* ret
= temp
;
348 void NamedTemplate::dump(unsigned level
) const
354 // =================================
355 // ===== NamedTemplates
356 // =================================
358 NamedTemplates::~NamedTemplates()
360 for (size_t i
= 0; i
< nts_v
.size(); i
++) delete nts_v
[i
];
365 NamedTemplates
*NamedTemplates::clone() const
367 FATAL_ERROR("NamedTemplates::clone");
370 void NamedTemplates::set_fullname(const string
& p_fullname
)
372 Node::set_fullname(p_fullname
);
373 for(size_t i
= 0; i
< nts_v
.size(); i
++) {
374 NamedTemplate
*nt
= nts_v
[i
];
375 nt
->set_fullname(p_fullname
+ "." + nt
->get_name().get_dispname());
379 void NamedTemplates::set_my_scope(Scope
*p_scope
)
381 Node::set_my_scope(p_scope
);
382 for(size_t i
= 0; i
< nts_v
.size(); i
++) nts_v
[i
]->set_my_scope(p_scope
);
385 void NamedTemplates::add_nt(NamedTemplate
*p_nt
)
387 if (!p_nt
) FATAL_ERROR("NULL pointer:NamedTemplates::add_nt()");
390 const string
& name
= p_nt
->get_name().get_name();
391 if (!nts_m
.has_key(name
)) nts_m
.add(name
, p_nt
);
395 bool NamedTemplates::has_nt_withName(const Identifier
& p_name
)
397 if (!checked
) chk_dupl_id(false);
398 return nts_m
.has_key(p_name
.get_name());
401 NamedTemplate
*NamedTemplates::get_nt_byName(const Identifier
& p_name
)
403 if (!checked
) chk_dupl_id(false);
404 return nts_m
[p_name
.get_name()];
407 void NamedTemplates::chk_dupl_id(bool report_errors
)
409 if (checked
) nts_m
.clear();
410 for (size_t i
= 0; i
< nts_v
.size(); i
++) {
411 NamedTemplate
*nt
= nts_v
[i
];
412 const Identifier
& id
= nt
->get_name();
413 const string
& name
= id
.get_name();
414 if (!nts_m
.has_key(name
)) nts_m
.add(name
, nt
);
415 else if (report_errors
) {
416 const char *disp_name
= id
.get_dispname().c_str();
417 nt
->error("Duplicate field name `%s'", disp_name
);
418 nts_m
[name
]->note("Field `%s' is already given here", disp_name
);
424 // =================================
425 // ===== LengthRestriction
426 // =================================
428 LengthRestriction::LengthRestriction(Value
* p_val
)
429 : Node(), checked(false), is_range(false)
432 FATAL_ERROR("LengthRestriction::LengthRestriction()");
436 LengthRestriction::LengthRestriction(Value
* p_lower
, Value
* p_upper
)
437 : Node(), checked(false), is_range(true)
440 FATAL_ERROR("LengthRestriction::LengthRestriction()");
441 range
.lower
= p_lower
;
442 range
.upper
= p_upper
;
445 LengthRestriction::~LengthRestriction()
450 } else delete single
;
453 LengthRestriction
*LengthRestriction::clone() const
455 FATAL_ERROR("LengthRestriction::clone");
458 void LengthRestriction::set_fullname(const string
& p_fullname
)
460 Node::set_fullname(p_fullname
);
462 range
.lower
->set_fullname(p_fullname
+ ".<lower>");
463 if (range
.upper
) range
.upper
->set_fullname(p_fullname
+ ".<upper>");
464 } else single
->set_fullname(p_fullname
);
467 void LengthRestriction::set_my_scope(Scope
*p_scope
)
470 range
.lower
->set_my_scope(p_scope
);
471 if (range
.upper
) range
.upper
->set_my_scope(p_scope
);
472 } else single
->set_my_scope(p_scope
);
475 void LengthRestriction::chk(Type::expected_value_t expected_value
)
479 Type
*pool_int
= Type::get_pooltype(Type::T_INT
);
481 range
.lower
->set_my_governor(pool_int
);
483 Error_Context
cntxt(range
.lower
, "In lower boundary of the length "
485 pool_int
->chk_this_value_ref(range
.lower
);
486 pool_int
->chk_this_value(range
.lower
, 0, expected_value
,
487 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
489 Value
*v_lower
= range
.lower
->get_value_refd_last();
490 int_val_t v_int_lower_int
;
491 if (v_lower
->get_valuetype() == Value::V_INT
) {
492 v_int_lower_int
= *(v_lower
->get_val_Int());
493 if (v_int_lower_int
< 0) {
494 range
.lower
->error("The lower boundary of the length restriction "
495 "must be a non-negative integer value instead of %s",
496 v_int_lower_int
.t_str().c_str());
497 range
.lower
->set_valuetype(Value::V_ERROR
);
498 v_int_lower_int
= int_val_t((Int
)0);
501 v_int_lower_int
= int_val_t((Int
)0);
504 range
.upper
->set_my_governor(pool_int
);
506 Error_Context
cntxt(range
.lower
, "In upper boundary of the length "
508 pool_int
->chk_this_value_ref(range
.upper
);
509 pool_int
->chk_this_value(range
.upper
, 0, expected_value
,
510 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
512 Value
*v_upper
= range
.upper
->get_value_refd_last();
513 if (v_upper
->get_valuetype() == Value::V_INT
) {
514 int_val_t
v_int_upper_int(*(v_upper
->get_val_Int()));
515 if (v_int_upper_int
< 0) {
516 range
.upper
->error("The upper boundary of the length "
517 "restriction must be a non-negative integer value instead "
518 "of %s", v_int_upper_int
.t_str().c_str());
519 range
.upper
->set_valuetype(Value::V_ERROR
);
520 } else if (v_int_upper_int
< v_int_lower_int
) {
521 error("The upper boundary of the length restriction (%s) "
522 "cannot be smaller than the lower boundary (%s)",
523 v_int_upper_int
.t_str().c_str(),
524 v_int_lower_int
.t_str().c_str());
525 range
.upper
->set_valuetype(Value::V_ERROR
);
530 single
->set_my_governor(pool_int
);
532 Error_Context
cntxt(single
, "In length restriction");
533 pool_int
->chk_this_value_ref(single
);
534 pool_int
->chk_this_value(single
, 0, expected_value
,
535 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
537 Value
*v_single
= single
->get_value_refd_last();
538 if (v_single
->get_valuetype() == Value::V_INT
) {
539 const int_val_t
*v_int_int
= v_single
->get_val_Int();
540 if (*v_int_int
< 0) {
541 single
->error("The length restriction must be a non-negative "
542 "integer value instead of %s", (v_int_int
->t_str()).c_str());
543 single
->set_valuetype(Value::V_ERROR
);
549 void LengthRestriction::chk_array_size(ArrayDimension
*p_dim
)
551 if (!checked
) FATAL_ERROR("LengthRestriction::chk_array_size()");
552 bool error_flag
= false;
553 if (!p_dim
->get_has_error()) {
554 size_t array_size
= p_dim
->get_size();
556 Value
*v_lower_last
= range
.lower
->get_value_refd_last();
557 if (v_lower_last
->get_valuetype() == Value::V_INT
) {
558 const int_val_t
*lower_len_int
= v_lower_last
->get_val_Int();
559 if (*lower_len_int
> INT_MAX
) {
560 range
.lower
->error("An integer value less than `%d' was expected "
561 "as the lower boundary of the length restriction instead of "
562 "`%s'", INT_MAX
, (lower_len_int
->t_str()).c_str());
565 Int lower_len
= lower_len_int
->get_val();
566 if (lower_len
> static_cast<Int
>(array_size
)) {
567 range
.lower
->error("The number of elements allowed by the "
568 "length restriction (at least %s) contradicts the array size "
569 "(%lu)", Int2string(lower_len
).c_str(),
570 (unsigned long)array_size
);
576 Value
*v_upper_last
= range
.upper
->get_value_refd_last();
577 if (v_upper_last
->get_valuetype() == Value::V_INT
) {
578 const int_val_t
*upper_len_int
= v_upper_last
->get_val_Int();
579 if (*upper_len_int
> INT_MAX
) {
580 range
.upper
->error("An integer value less than `%d' was "
581 "expected as the upper boundary of the length restriction "
582 "instead of `%s'", INT_MAX
, (upper_len_int
->t_str()).c_str());
585 Int upper_len
= upper_len_int
->get_val();
586 if (upper_len
< static_cast<Int
>(array_size
)) {
587 range
.upper
->error("The number of elements allowed by the "
588 "length restriction (at most %s) contradicts the array "
589 "size (%lu)", Int2string(upper_len
).c_str(),
590 (unsigned long)array_size
);
597 Value
*v_last
= single
->get_value_refd_last();
598 if (v_last
->get_valuetype() == Value::V_INT
) {
599 int_val_t
single_len_int(*(v_last
->get_val_Int()));
600 if (single_len_int
!= static_cast<Int
>(array_size
)) {
601 single
->error("The number of elements allowed by the length "
602 "restriction (%s) contradicts the array size (%lu)",
603 single_len_int
.t_str().c_str(), (unsigned long)array_size
);
610 warning("Length restriction is useless for an array template");
613 void LengthRestriction::chk_nof_elements(size_t nof_elements
,
614 bool has_anyornone
, const Location
& p_loc
, const char *p_what
)
616 if (!checked
) FATAL_ERROR("LengthRestriction::chk_nof_elements()");
618 if (!has_anyornone
) {
619 Value
*v_lower_last
= range
.lower
->get_value_refd_last();
620 if (v_lower_last
->get_valuetype() == Value::V_INT
) {
621 const int_val_t
*lower_len_int
= v_lower_last
->get_val_Int();
622 if (*lower_len_int
> static_cast<Int
>(nof_elements
)) {
623 p_loc
.error("There are fewer (%lu) elements in the %s than it "
624 "is allowed by the length restriction (at least %s)",
625 (unsigned long)nof_elements
, p_what
,
626 (lower_len_int
->t_str()).c_str());
631 Value
*v_upper_last
= range
.upper
->get_value_refd_last();
632 if (v_upper_last
->get_valuetype() == Value::V_INT
) {
633 const int_val_t
*upper_len_int
= v_upper_last
->get_val_Int();
634 if (*upper_len_int
< static_cast<Int
>(nof_elements
)) {
635 p_loc
.error("There are more (%s%lu) elements in the %s than it "
636 "is allowed by the length restriction (at most %s)",
637 has_anyornone
? "at least " : "", (unsigned long)nof_elements
,
638 p_what
, (upper_len_int
->t_str()).c_str());
643 Value
*v_last
= single
->get_value_refd_last();
644 if (v_last
->get_valuetype() == Value::V_INT
) {
645 // Cheaper than creating a local variable?
646 const int_val_t
*single_len_int
= v_last
->get_val_Int();
647 if (*single_len_int
< static_cast<Int
>(nof_elements
)) {
648 p_loc
.error("There are more (%s%lu) elements in the %s than it "
649 "is allowed by the length restriction (%s)", has_anyornone
?
650 "at least " : "", (unsigned long)nof_elements
, p_what
,
651 (single_len_int
->t_str()).c_str());
652 } else if (*single_len_int
> static_cast<Int
>(nof_elements
) &&
654 p_loc
.error("There are fewer (%lu) elements in the %s than it "
655 "is allowed by the length restriction (%s)",
656 (unsigned long)nof_elements
, p_what
,
657 (single_len_int
->t_str()).c_str());
663 Value
* LengthRestriction::get_single_value()
665 if (is_range
) FATAL_ERROR("LengthRestriction::get_single_value()");
666 if (!checked
) FATAL_ERROR("LengthRestriction::get_single_value()");
667 return single
->get_value_refd_last();
670 Value
*LengthRestriction::get_lower_value()
672 if (!is_range
) FATAL_ERROR("LengthRestriction::get_lower_value()");
673 if (!checked
) FATAL_ERROR("LengthRestriction::get_lower_value()");
674 return range
.lower
->get_value_refd_last();
677 Value
*LengthRestriction::get_upper_value()
679 if (!is_range
) FATAL_ERROR("LengthRestriction::get_upper_value()");
680 if (!checked
) FATAL_ERROR("LengthRestriction::get_upper_value()");
681 return range
.upper
? range
.upper
->get_value_refd_last() : 0;
684 void LengthRestriction::set_code_section
685 (GovernedSimple::code_section_t p_code_section
)
688 range
.lower
->set_code_section(p_code_section
);
689 if (range
.upper
) range
.upper
->set_code_section(p_code_section
);
690 } else single
->set_code_section(p_code_section
);
693 char *LengthRestriction::generate_code_init(char *str
, const char *name
)
695 expression_struct expr
;
696 Code::init_expr(&expr
);
699 range
.lower
->generate_code_expr(&expr
);
700 init_stmt
= mprintf("%s.set_min_length(%s);\n", name
, expr
.expr
);
702 Code::clean_expr(&expr
);
703 range
.upper
->generate_code_expr(&expr
);
704 init_stmt
= mputprintf(init_stmt
, "%s.set_max_length(%s);\n", name
,
708 single
->generate_code_expr(&expr
);
709 init_stmt
= mprintf("%s.set_single_length(%s);\n", name
, expr
.expr
);
711 if (expr
.preamble
|| expr
.postamble
) {
712 str
= mputstr(str
, "{\n");
713 str
= mputstr(str
, expr
.preamble
);
714 str
= mputstr(str
, init_stmt
);
715 str
= mputstr(str
, expr
.postamble
);
716 str
= mputstr(str
, "}\n");
717 } else str
= mputstr(str
, init_stmt
);
718 Code::free_expr(&expr
);
723 char *LengthRestriction::rearrange_init_code(char *str
)
726 str
= range
.lower
->rearrange_init_code(str
);
727 if (range
.upper
) str
= range
.upper
->rearrange_init_code(str
);
728 } else str
= single
->rearrange_init_code(str
);
732 void LengthRestriction::append_stringRepr(string
& str
) const
736 str
+= range
.lower
->get_stringRepr();
738 if (range
.upper
) str
+= range
.upper
->get_stringRepr();
739 else str
+= "infinity";
740 } else str
+= single
->get_stringRepr();
744 void LengthRestriction::dump(unsigned level
) const
746 DEBUG(level
, "length restriction:");
748 range
.lower
->dump(level
+ 1);
750 if (range
.upper
) range
.upper
->dump(level
+ 1);
751 else DEBUG(level
+ 1, "infinity");
752 } else single
->dump(level
+ 1);
755 // =================================
756 // ===== TemplateInstances
757 // =================================
759 TemplateInstances::TemplateInstances(const TemplateInstances
& p
)
760 : Node(p
), Location(p
), tis()
762 for (size_t i
= 0; i
< p
.tis
.size(); i
++)
763 tis
.add(p
.tis
[i
]->clone());
766 TemplateInstances::~TemplateInstances()
768 for (size_t i
= 0; i
< tis
.size(); i
++) delete tis
[i
];
772 TemplateInstances
*TemplateInstances::clone() const
774 return new TemplateInstances(*this);
777 void TemplateInstances::set_fullname(const string
& p_fullname
)
779 Node::set_fullname(p_fullname
);
780 for (size_t i
= 0; i
< tis
.size(); i
++)
781 tis
[i
]->set_fullname(p_fullname
+ "[" + Int2string(i
+ 1) + "]");
784 void TemplateInstances::set_my_scope(Scope
*p_scope
)
786 for (size_t i
= 0; i
< tis
.size(); i
++)
788 TemplateInstance
*& tir
= tis
[i
];
789 tir
->set_my_scope(p_scope
);
793 void TemplateInstances::add_ti(TemplateInstance
*p_ti
)
795 if (!p_ti
) FATAL_ERROR("NULL pointer:TemplateInstances::add_ti()");
799 void TemplateInstances::set_code_section
800 (GovernedSimple::code_section_t p_code_section
)
802 for (size_t i
=0; i
<tis
.size(); i
++)
803 tis
[i
]->set_code_section(p_code_section
);
806 void TemplateInstances::dump(unsigned level
) const
808 DEBUG(level
, "TemplateInstances %p, has %lu", (const void*)this,
809 (unsigned long) tis
.size());
810 for (size_t i
= 0; i
< tis
.size(); ++i
) {
811 tis
[i
]->dump(level
+1);
814 // =================================
816 // =================================
818 NamedParam::NamedParam(Identifier
*id
, TemplateInstance
*t
)
819 : Node(), Location(), name(id
), tmpl(t
)
823 NamedParam::NamedParam(const NamedParam
& p
)
824 : Node(p
), Location(p
), name(p
.name
->clone()), tmpl(p
.tmpl
->clone())
828 NamedParam::~NamedParam()
834 NamedParam
* NamedParam::clone() const {
835 return new NamedParam(*this);
838 void NamedParam::set_my_scope(Scope
*p_scope
)
840 tmpl
->set_my_scope(p_scope
);
843 void NamedParam::set_fullname(const string
& p_fullname
)
845 Node::set_fullname(p_fullname
);
846 tmpl
->set_fullname(p_fullname
);
849 TemplateInstance
* NamedParam::extract_ti()
851 TemplateInstance
*retval
= tmpl
;
856 void NamedParam::dump(unsigned int level
) const
861 // =================================
863 // =================================
865 NamedParams::NamedParams()
866 : Node(), Location(), nps()
870 NamedParams
* NamedParams::clone() const
872 FATAL_ERROR("NamedParams::clone");
875 NamedParams::~NamedParams()
877 for (size_t i
= 0; i
< nps
.size(); i
++) delete nps
[i
];
881 void NamedParams::set_my_scope(Scope
*p_scope
)
883 for (size_t i
= 0; i
< nps
.size(); i
++) nps
[i
]->set_my_scope(p_scope
);
886 void NamedParams::set_fullname(const string
& p_fullname
)
888 for (size_t i
= 0; i
< nps
.size(); i
++) nps
[i
]->set_fullname(p_fullname
);
891 void NamedParams::add_np(NamedParam
*p
)
893 if (!p
) FATAL_ERROR("NULL pointer: NamedParams::add_np()");
897 size_t NamedParams::get_nof_nps() const
902 NamedParam
*NamedParams::extract_np_byIndex(size_t p_i
)
904 NamedParam
* retval
= nps
[p_i
];
909 void NamedParams::dump(unsigned int level
) const
911 DEBUG(level
, "NamedParams %p, has %lu", (const void*)this,
912 (unsigned long) nps
.size());
913 for (unsigned int i
= 0; i
< nps
.size(); ++i
) {
915 nps
[i
]->dump(level
+1);
917 DEBUG(level
+1, "NULL");
921 // =================================
922 // ===== ParsedActualParameters
923 // =================================
925 ParsedActualParameters::ParsedActualParameters(TemplateInstances
*p_ti
,
927 : Node(), Location(), unnamedpart(p_ti
? p_ti
: new TemplateInstances
), namedpart(p_np
)
931 ParsedActualParameters::ParsedActualParameters(const ParsedActualParameters
& p
)
932 : Node(p
), Location(p
), unnamedpart(p
.unnamedpart
->clone()),
933 namedpart (p
.namedpart
? p
.namedpart
->clone() : 0)
937 ParsedActualParameters
* ParsedActualParameters::clone() const
939 return new ParsedActualParameters(*this);
942 ParsedActualParameters::~ParsedActualParameters()
948 void ParsedActualParameters::add_np(NamedParam
*np
)
950 if (!namedpart
) // we got away without one until now
952 namedpart
= new NamedParams
;
954 namedpart
->add_np(np
);
957 TemplateInstances
* ParsedActualParameters::steal_tis()
959 TemplateInstances
* temp
= unnamedpart
;
960 unnamedpart
= new TemplateInstances
;
964 size_t ParsedActualParameters::get_nof_nps() const
966 return namedpart
? namedpart
->get_nof_nps() : 0;
969 void ParsedActualParameters::set_my_scope(Common::Scope
*p_scope
)
971 unnamedpart
->set_my_scope(p_scope
);
973 namedpart
->set_my_scope(p_scope
);
977 void ParsedActualParameters::set_fullname(const string
& p_fullname
)
979 unnamedpart
->set_fullname(p_fullname
);
981 namedpart
->set_fullname(p_fullname
);
985 void ParsedActualParameters::set_location(const char *p_filename
, int p_lineno
)
987 Location ::set_location(p_filename
, p_lineno
);
989 namedpart
->set_location(p_filename
, p_lineno
);
990 unnamedpart
->set_location(p_filename
, p_lineno
);
993 void ParsedActualParameters::set_location(const char *p_filename
,
994 const YYLTYPE
& p_yyloc
)
996 Location ::set_location(p_filename
, p_yyloc
);
998 namedpart
->set_location(p_filename
, p_yyloc
);
999 unnamedpart
->set_location(p_filename
, p_yyloc
);
1002 void ParsedActualParameters::set_location(const char *p_filename
,
1003 const YYLTYPE
& p_firstloc
,
1004 const YYLTYPE
& p_lastloc
)
1006 Location ::set_location(p_filename
, p_firstloc
, p_lastloc
);
1008 namedpart
->set_location(p_filename
, p_firstloc
, p_lastloc
);
1009 unnamedpart
->set_location(p_filename
, p_firstloc
, p_lastloc
);
1012 void ParsedActualParameters::set_location(const char *p_filename
, int p_first_line
,
1013 int p_first_column
, int p_last_line
, int p_last_column
)
1015 Location ::set_location(p_filename
, p_first_line
, p_first_column
,
1016 p_last_line
, p_last_column
);
1018 namedpart
->set_location(p_filename
, p_first_line
, p_first_column
,
1019 p_last_line
, p_last_column
);
1020 unnamedpart
->set_location(p_filename
, p_first_line
, p_first_column
,
1021 p_last_line
, p_last_column
);
1025 void ParsedActualParameters::dump(unsigned int level
) const
1027 DEBUG(level
, "ParsedActualParameters at %p", (const void*)this);
1028 unnamedpart
->dump(level
+1);
1030 namedpart
->dump(level
+1);