1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
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 Template
* NamedTemplate::extract_template()
325 Template
* ret
= temp
;
330 void NamedTemplate::dump(unsigned level
) const
336 // =================================
337 // ===== NamedTemplates
338 // =================================
340 NamedTemplates::~NamedTemplates()
342 for (size_t i
= 0; i
< nts_v
.size(); i
++) delete nts_v
[i
];
347 NamedTemplates
*NamedTemplates::clone() const
349 FATAL_ERROR("NamedTemplates::clone");
352 void NamedTemplates::set_fullname(const string
& p_fullname
)
354 Node::set_fullname(p_fullname
);
355 for(size_t i
= 0; i
< nts_v
.size(); i
++) {
356 NamedTemplate
*nt
= nts_v
[i
];
357 nt
->set_fullname(p_fullname
+ "." + nt
->get_name().get_dispname());
361 void NamedTemplates::set_my_scope(Scope
*p_scope
)
363 Node::set_my_scope(p_scope
);
364 for(size_t i
= 0; i
< nts_v
.size(); i
++) nts_v
[i
]->set_my_scope(p_scope
);
367 void NamedTemplates::add_nt(NamedTemplate
*p_nt
)
369 if (!p_nt
) FATAL_ERROR("NULL pointer:NamedTemplates::add_nt()");
372 const string
& name
= p_nt
->get_name().get_name();
373 if (!nts_m
.has_key(name
)) nts_m
.add(name
, p_nt
);
377 bool NamedTemplates::has_nt_withName(const Identifier
& p_name
)
379 if (!checked
) chk_dupl_id(false);
380 return nts_m
.has_key(p_name
.get_name());
383 NamedTemplate
*NamedTemplates::get_nt_byName(const Identifier
& p_name
)
385 if (!checked
) chk_dupl_id(false);
386 return nts_m
[p_name
.get_name()];
389 void NamedTemplates::chk_dupl_id(bool report_errors
)
391 if (checked
) nts_m
.clear();
392 for (size_t i
= 0; i
< nts_v
.size(); i
++) {
393 NamedTemplate
*nt
= nts_v
[i
];
394 const Identifier
& id
= nt
->get_name();
395 const string
& name
= id
.get_name();
396 if (!nts_m
.has_key(name
)) nts_m
.add(name
, nt
);
397 else if (report_errors
) {
398 const char *disp_name
= id
.get_dispname().c_str();
399 nt
->error("Duplicate field name `%s'", disp_name
);
400 nts_m
[name
]->note("Field `%s' is already given here", disp_name
);
406 // =================================
407 // ===== LengthRestriction
408 // =================================
410 LengthRestriction::LengthRestriction(Value
* p_val
)
411 : Node(), checked(false), is_range(false)
414 FATAL_ERROR("LengthRestriction::LengthRestriction()");
418 LengthRestriction::LengthRestriction(Value
* p_lower
, Value
* p_upper
)
419 : Node(), checked(false), is_range(true)
422 FATAL_ERROR("LengthRestriction::LengthRestriction()");
423 range
.lower
= p_lower
;
424 range
.upper
= p_upper
;
427 LengthRestriction::~LengthRestriction()
432 } else delete single
;
435 LengthRestriction
*LengthRestriction::clone() const
437 FATAL_ERROR("LengthRestriction::clone");
440 void LengthRestriction::set_fullname(const string
& p_fullname
)
442 Node::set_fullname(p_fullname
);
444 range
.lower
->set_fullname(p_fullname
+ ".<lower>");
445 if (range
.upper
) range
.upper
->set_fullname(p_fullname
+ ".<upper>");
446 } else single
->set_fullname(p_fullname
);
449 void LengthRestriction::set_my_scope(Scope
*p_scope
)
452 range
.lower
->set_my_scope(p_scope
);
453 if (range
.upper
) range
.upper
->set_my_scope(p_scope
);
454 } else single
->set_my_scope(p_scope
);
457 void LengthRestriction::chk(Type::expected_value_t expected_value
)
461 Type
*pool_int
= Type::get_pooltype(Type::T_INT
);
463 range
.lower
->set_my_governor(pool_int
);
465 Error_Context
cntxt(range
.lower
, "In lower boundary of the length "
467 pool_int
->chk_this_value_ref(range
.lower
);
468 pool_int
->chk_this_value(range
.lower
, 0, expected_value
,
469 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
471 Value
*v_lower
= range
.lower
->get_value_refd_last();
472 int_val_t v_int_lower_int
;
473 if (v_lower
->get_valuetype() == Value::V_INT
) {
474 v_int_lower_int
= *(v_lower
->get_val_Int());
475 if (v_int_lower_int
< 0) {
476 range
.lower
->error("The lower boundary of the length restriction "
477 "must be a non-negative integer value instead of %s",
478 v_int_lower_int
.t_str().c_str());
479 range
.lower
->set_valuetype(Value::V_ERROR
);
480 v_int_lower_int
= int_val_t((Int
)0);
483 v_int_lower_int
= int_val_t((Int
)0);
486 range
.upper
->set_my_governor(pool_int
);
488 Error_Context
cntxt(range
.lower
, "In upper boundary of the length "
490 pool_int
->chk_this_value_ref(range
.upper
);
491 pool_int
->chk_this_value(range
.upper
, 0, expected_value
,
492 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
494 Value
*v_upper
= range
.upper
->get_value_refd_last();
495 if (v_upper
->get_valuetype() == Value::V_INT
) {
496 int_val_t
v_int_upper_int(*(v_upper
->get_val_Int()));
497 if (v_int_upper_int
< 0) {
498 range
.upper
->error("The upper boundary of the length "
499 "restriction must be a non-negative integer value instead "
500 "of %s", v_int_upper_int
.t_str().c_str());
501 range
.upper
->set_valuetype(Value::V_ERROR
);
502 } else if (v_int_upper_int
< v_int_lower_int
) {
503 error("The upper boundary of the length restriction (%s) "
504 "cannot be smaller than the lower boundary (%s)",
505 v_int_upper_int
.t_str().c_str(),
506 v_int_lower_int
.t_str().c_str());
507 range
.upper
->set_valuetype(Value::V_ERROR
);
512 single
->set_my_governor(pool_int
);
514 Error_Context
cntxt(single
, "In length restriction");
515 pool_int
->chk_this_value_ref(single
);
516 pool_int
->chk_this_value(single
, 0, expected_value
,
517 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
519 Value
*v_single
= single
->get_value_refd_last();
520 if (v_single
->get_valuetype() == Value::V_INT
) {
521 const int_val_t
*v_int_int
= v_single
->get_val_Int();
522 if (*v_int_int
< 0) {
523 single
->error("The length restriction must be a non-negative "
524 "integer value instead of %s", (v_int_int
->t_str()).c_str());
525 single
->set_valuetype(Value::V_ERROR
);
531 void LengthRestriction::chk_array_size(ArrayDimension
*p_dim
)
533 if (!checked
) FATAL_ERROR("LengthRestriction::chk_array_size()");
534 bool error_flag
= false;
535 if (!p_dim
->get_has_error()) {
536 size_t array_size
= p_dim
->get_size();
538 Value
*v_lower_last
= range
.lower
->get_value_refd_last();
539 if (v_lower_last
->get_valuetype() == Value::V_INT
) {
540 const int_val_t
*lower_len_int
= v_lower_last
->get_val_Int();
541 if (*lower_len_int
> INT_MAX
) {
542 range
.lower
->error("An integer value less than `%d' was expected "
543 "as the lower boundary of the length restriction instead of "
544 "`%s'", INT_MAX
, (lower_len_int
->t_str()).c_str());
547 Int lower_len
= lower_len_int
->get_val();
548 if (lower_len
> static_cast<Int
>(array_size
)) {
549 range
.lower
->error("The number of elements allowed by the "
550 "length restriction (at least %s) contradicts the array size "
551 "(%lu)", Int2string(lower_len
).c_str(),
552 (unsigned long)array_size
);
558 Value
*v_upper_last
= range
.upper
->get_value_refd_last();
559 if (v_upper_last
->get_valuetype() == Value::V_INT
) {
560 const int_val_t
*upper_len_int
= v_upper_last
->get_val_Int();
561 if (*upper_len_int
> INT_MAX
) {
562 range
.upper
->error("An integer value less than `%d' was "
563 "expected as the upper boundary of the length restriction "
564 "instead of `%s'", INT_MAX
, (upper_len_int
->t_str()).c_str());
567 Int upper_len
= upper_len_int
->get_val();
568 if (upper_len
< static_cast<Int
>(array_size
)) {
569 range
.upper
->error("The number of elements allowed by the "
570 "length restriction (at most %s) contradicts the array "
571 "size (%lu)", Int2string(upper_len
).c_str(),
572 (unsigned long)array_size
);
579 Value
*v_last
= single
->get_value_refd_last();
580 if (v_last
->get_valuetype() == Value::V_INT
) {
581 int_val_t
single_len_int(*(v_last
->get_val_Int()));
582 if (single_len_int
!= static_cast<Int
>(array_size
)) {
583 single
->error("The number of elements allowed by the length "
584 "restriction (%s) contradicts the array size (%lu)",
585 single_len_int
.t_str().c_str(), (unsigned long)array_size
);
592 warning("Length restriction is useless for an array template");
595 void LengthRestriction::chk_nof_elements(size_t nof_elements
,
596 bool has_anyornone
, const Location
& p_loc
, const char *p_what
)
598 if (!checked
) FATAL_ERROR("LengthRestriction::chk_nof_elements()");
600 if (!has_anyornone
) {
601 Value
*v_lower_last
= range
.lower
->get_value_refd_last();
602 if (v_lower_last
->get_valuetype() == Value::V_INT
) {
603 const int_val_t
*lower_len_int
= v_lower_last
->get_val_Int();
604 if (*lower_len_int
> static_cast<Int
>(nof_elements
)) {
605 p_loc
.error("There are fewer (%lu) elements in the %s than it "
606 "is allowed by the length restriction (at least %s)",
607 (unsigned long)nof_elements
, p_what
,
608 (lower_len_int
->t_str()).c_str());
613 Value
*v_upper_last
= range
.upper
->get_value_refd_last();
614 if (v_upper_last
->get_valuetype() == Value::V_INT
) {
615 const int_val_t
*upper_len_int
= v_upper_last
->get_val_Int();
616 if (*upper_len_int
< static_cast<Int
>(nof_elements
)) {
617 p_loc
.error("There are more (%s%lu) elements in the %s than it "
618 "is allowed by the length restriction (at most %s)",
619 has_anyornone
? "at least " : "", (unsigned long)nof_elements
,
620 p_what
, (upper_len_int
->t_str()).c_str());
625 Value
*v_last
= single
->get_value_refd_last();
626 if (v_last
->get_valuetype() == Value::V_INT
) {
627 // Cheaper than creating a local variable?
628 const int_val_t
*single_len_int
= v_last
->get_val_Int();
629 if (*single_len_int
< static_cast<Int
>(nof_elements
)) {
630 p_loc
.error("There are more (%s%lu) elements in the %s than it "
631 "is allowed by the length restriction (%s)", has_anyornone
?
632 "at least " : "", (unsigned long)nof_elements
, p_what
,
633 (single_len_int
->t_str()).c_str());
634 } else if (*single_len_int
> static_cast<Int
>(nof_elements
) &&
636 p_loc
.error("There are fewer (%lu) elements in the %s than it "
637 "is allowed by the length restriction (%s)",
638 (unsigned long)nof_elements
, p_what
,
639 (single_len_int
->t_str()).c_str());
645 Value
* LengthRestriction::get_single_value()
647 if (is_range
) FATAL_ERROR("LengthRestriction::get_single_value()");
648 if (!checked
) FATAL_ERROR("LengthRestriction::get_single_value()");
649 return single
->get_value_refd_last();
652 Value
*LengthRestriction::get_lower_value()
654 if (!is_range
) FATAL_ERROR("LengthRestriction::get_lower_value()");
655 if (!checked
) FATAL_ERROR("LengthRestriction::get_lower_value()");
656 return range
.lower
->get_value_refd_last();
659 Value
*LengthRestriction::get_upper_value()
661 if (!is_range
) FATAL_ERROR("LengthRestriction::get_upper_value()");
662 if (!checked
) FATAL_ERROR("LengthRestriction::get_upper_value()");
663 return range
.upper
? range
.upper
->get_value_refd_last() : 0;
666 void LengthRestriction::set_code_section
667 (GovernedSimple::code_section_t p_code_section
)
670 range
.lower
->set_code_section(p_code_section
);
671 if (range
.upper
) range
.upper
->set_code_section(p_code_section
);
672 } else single
->set_code_section(p_code_section
);
675 char *LengthRestriction::generate_code_init(char *str
, const char *name
)
677 expression_struct expr
;
678 Code::init_expr(&expr
);
681 range
.lower
->generate_code_expr(&expr
);
682 init_stmt
= mprintf("%s.set_min_length(%s);\n", name
, expr
.expr
);
684 Code::clean_expr(&expr
);
685 range
.upper
->generate_code_expr(&expr
);
686 init_stmt
= mputprintf(init_stmt
, "%s.set_max_length(%s);\n", name
,
690 single
->generate_code_expr(&expr
);
691 init_stmt
= mprintf("%s.set_single_length(%s);\n", name
, expr
.expr
);
693 if (expr
.preamble
|| expr
.postamble
) {
694 str
= mputstr(str
, "{\n");
695 str
= mputstr(str
, expr
.preamble
);
696 str
= mputstr(str
, init_stmt
);
697 str
= mputstr(str
, expr
.postamble
);
698 str
= mputstr(str
, "}\n");
699 } else str
= mputstr(str
, init_stmt
);
700 Code::free_expr(&expr
);
705 char *LengthRestriction::rearrange_init_code(char *str
)
708 str
= range
.lower
->rearrange_init_code(str
);
709 if (range
.upper
) str
= range
.upper
->rearrange_init_code(str
);
710 } else str
= single
->rearrange_init_code(str
);
714 void LengthRestriction::append_stringRepr(string
& str
) const
718 str
+= range
.lower
->get_stringRepr();
720 if (range
.upper
) str
+= range
.upper
->get_stringRepr();
721 else str
+= "infinity";
722 } else str
+= single
->get_stringRepr();
726 void LengthRestriction::dump(unsigned level
) const
728 DEBUG(level
, "length restriction:");
730 range
.lower
->dump(level
+ 1);
732 if (range
.upper
) range
.upper
->dump(level
+ 1);
733 else DEBUG(level
+ 1, "infinity");
734 } else single
->dump(level
+ 1);
737 // =================================
738 // ===== TemplateInstances
739 // =================================
741 TemplateInstances::TemplateInstances(const TemplateInstances
& p
)
742 : Node(p
), Location(p
), tis()
744 for (size_t i
= 0; i
< p
.tis
.size(); i
++)
745 tis
.add(p
.tis
[i
]->clone());
748 TemplateInstances::~TemplateInstances()
750 for (size_t i
= 0; i
< tis
.size(); i
++) delete tis
[i
];
754 TemplateInstances
*TemplateInstances::clone() const
756 return new TemplateInstances(*this);
759 void TemplateInstances::set_fullname(const string
& p_fullname
)
761 Node::set_fullname(p_fullname
);
762 for (size_t i
= 0; i
< tis
.size(); i
++)
763 tis
[i
]->set_fullname(p_fullname
+ "[" + Int2string(i
+ 1) + "]");
766 void TemplateInstances::set_my_scope(Scope
*p_scope
)
768 for (size_t i
= 0; i
< tis
.size(); i
++)
770 TemplateInstance
*& tir
= tis
[i
];
771 tir
->set_my_scope(p_scope
);
775 void TemplateInstances::add_ti(TemplateInstance
*p_ti
)
777 if (!p_ti
) FATAL_ERROR("NULL pointer:TemplateInstances::add_ti()");
781 void TemplateInstances::set_code_section
782 (GovernedSimple::code_section_t p_code_section
)
784 for (size_t i
=0; i
<tis
.size(); i
++)
785 tis
[i
]->set_code_section(p_code_section
);
788 void TemplateInstances::dump(unsigned level
) const
790 DEBUG(level
, "TemplateInstances %p, has %lu", (const void*)this,
791 (unsigned long) tis
.size());
792 for (size_t i
= 0; i
< tis
.size(); ++i
) {
793 tis
[i
]->dump(level
+1);
796 // =================================
798 // =================================
800 NamedParam::NamedParam(Identifier
*id
, TemplateInstance
*t
)
801 : Node(), Location(), name(id
), tmpl(t
)
805 NamedParam::NamedParam(const NamedParam
& p
)
806 : Node(p
), Location(p
), name(p
.name
->clone()), tmpl(p
.tmpl
->clone())
810 NamedParam::~NamedParam()
816 NamedParam
* NamedParam::clone() const {
817 return new NamedParam(*this);
820 void NamedParam::set_my_scope(Scope
*p_scope
)
822 tmpl
->set_my_scope(p_scope
);
825 void NamedParam::set_fullname(const string
& p_fullname
)
827 Node::set_fullname(p_fullname
);
828 tmpl
->set_fullname(p_fullname
);
831 TemplateInstance
* NamedParam::extract_ti()
833 TemplateInstance
*retval
= tmpl
;
838 void NamedParam::dump(unsigned int level
) const
843 // =================================
845 // =================================
847 NamedParams::NamedParams()
848 : Node(), Location(), nps()
852 NamedParams
* NamedParams::clone() const
854 FATAL_ERROR("NamedParams::clone");
857 NamedParams::~NamedParams()
859 for (size_t i
= 0; i
< nps
.size(); i
++) delete nps
[i
];
863 void NamedParams::set_my_scope(Scope
*p_scope
)
865 for (size_t i
= 0; i
< nps
.size(); i
++) nps
[i
]->set_my_scope(p_scope
);
868 void NamedParams::set_fullname(const string
& p_fullname
)
870 for (size_t i
= 0; i
< nps
.size(); i
++) nps
[i
]->set_fullname(p_fullname
);
873 void NamedParams::add_np(NamedParam
*p
)
875 if (!p
) FATAL_ERROR("NULL pointer: NamedParams::add_np()");
879 size_t NamedParams::get_nof_nps() const
884 NamedParam
*NamedParams::extract_np_byIndex(size_t p_i
)
886 NamedParam
* retval
= nps
[p_i
];
891 void NamedParams::dump(unsigned int level
) const
893 DEBUG(level
, "NamedParams %p, has %lu", (const void*)this,
894 (unsigned long) nps
.size());
895 for (unsigned int i
= 0; i
< nps
.size(); ++i
) {
897 nps
[i
]->dump(level
+1);
899 DEBUG(level
+1, "NULL");
903 // =================================
904 // ===== ParsedActualParameters
905 // =================================
907 ParsedActualParameters::ParsedActualParameters(TemplateInstances
*p_ti
,
909 : Node(), Location(), unnamedpart(p_ti
? p_ti
: new TemplateInstances
), namedpart(p_np
)
913 ParsedActualParameters::ParsedActualParameters(const ParsedActualParameters
& p
)
914 : Node(p
), Location(p
), unnamedpart(p
.unnamedpart
->clone()),
915 namedpart (p
.namedpart
? p
.namedpart
->clone() : 0)
919 ParsedActualParameters
* ParsedActualParameters::clone() const
921 return new ParsedActualParameters(*this);
924 ParsedActualParameters::~ParsedActualParameters()
930 void ParsedActualParameters::add_np(NamedParam
*np
)
932 if (!namedpart
) // we got away without one until now
934 namedpart
= new NamedParams
;
936 namedpart
->add_np(np
);
939 TemplateInstances
* ParsedActualParameters::steal_tis()
941 TemplateInstances
* temp
= unnamedpart
;
942 unnamedpart
= new TemplateInstances
;
946 size_t ParsedActualParameters::get_nof_nps() const
948 return namedpart
? namedpart
->get_nof_nps() : 0;
951 void ParsedActualParameters::set_my_scope(Common::Scope
*p_scope
)
953 unnamedpart
->set_my_scope(p_scope
);
955 namedpart
->set_my_scope(p_scope
);
959 void ParsedActualParameters::set_fullname(const string
& p_fullname
)
961 unnamedpart
->set_fullname(p_fullname
);
963 namedpart
->set_fullname(p_fullname
);
967 void ParsedActualParameters::set_location(const char *p_filename
, int p_lineno
)
969 Location ::set_location(p_filename
, p_lineno
);
971 namedpart
->set_location(p_filename
, p_lineno
);
972 unnamedpart
->set_location(p_filename
, p_lineno
);
975 void ParsedActualParameters::set_location(const char *p_filename
,
976 const YYLTYPE
& p_yyloc
)
978 Location ::set_location(p_filename
, p_yyloc
);
980 namedpart
->set_location(p_filename
, p_yyloc
);
981 unnamedpart
->set_location(p_filename
, p_yyloc
);
984 void ParsedActualParameters::set_location(const char *p_filename
,
985 const YYLTYPE
& p_firstloc
,
986 const YYLTYPE
& p_lastloc
)
988 Location ::set_location(p_filename
, p_firstloc
, p_lastloc
);
990 namedpart
->set_location(p_filename
, p_firstloc
, p_lastloc
);
991 unnamedpart
->set_location(p_filename
, p_firstloc
, p_lastloc
);
994 void ParsedActualParameters::set_location(const char *p_filename
, int p_first_line
,
995 int p_first_column
, int p_last_line
, int p_last_column
)
997 Location ::set_location(p_filename
, p_first_line
, p_first_column
,
998 p_last_line
, p_last_column
);
1000 namedpart
->set_location(p_filename
, p_first_line
, p_first_column
,
1001 p_last_line
, p_last_column
);
1002 unnamedpart
->set_location(p_filename
, p_first_line
, p_first_column
,
1003 p_last_line
, p_last_column
);
1007 void ParsedActualParameters::dump(unsigned int level
) const
1009 DEBUG(level
, "ParsedActualParameters at %p", (const void*)this);
1010 unnamedpart
->dump(level
+1);
1012 namedpart
->dump(level
+1);