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
17 * Szabo, Janos Zoltan – initial implementation
20 * Zalanyi, Balazs Andor
22 ******************************************************************************/
23 #include "Typestuff.hh"
24 #include "CompField.hh"
25 #include "asn1/Tag.hh"
30 using Asn::TagDefault
;
32 // =================================
34 // =================================
36 ExcSpec::ExcSpec(Type
*p_type
, Value
*p_value
)
40 FATAL_ERROR("NULL parameter: Asn::ExcSpec::ExcSpec()");
41 type
=p_type
?p_type
:new Type(Type::T_INT
);
42 type
->set_ownertype(Type::OT_EXC_SPEC
, this);
46 ExcSpec::ExcSpec(const ExcSpec
& p
)
50 value
=p
.value
->clone();
59 ExcSpec
*ExcSpec::clone() const
61 return new ExcSpec(*this);
64 void ExcSpec::set_my_scope(Scope
*p_scope
)
66 type
->set_my_scope(p_scope
);
67 value
->set_my_scope(p_scope
);
70 void ExcSpec::set_fullname(const string
& p_fullname
)
72 Node::set_fullname(p_fullname
);
73 type
->set_fullname(p_fullname
);
74 value
->set_fullname(p_fullname
);
77 // =================================
79 // =================================
83 for(size_t i
=0; i
<cts
.size(); i
++) delete cts
[i
];
87 CTs::CTs(const CTs
& p
)
90 for(size_t i
=0; i
<p
.cts
.size(); i
++)
91 cts
.add(p
.cts
[i
]->clone());
94 CTs
*CTs::clone() const
96 return new CTs(*this);
99 void CTs::set_fullname(const string
& p_fullname
)
101 Node::set_fullname(p_fullname
);
102 for(size_t i
=0; i
<cts
.size(); i
++)
103 // cts[i]->set_fullname(get_fullname()+"."+Int2string(i+1));
104 cts
[i
]->set_fullname(get_fullname());
107 void CTs::set_my_scope(Scope
*p_scope
)
109 for(size_t i
=0; i
<cts
.size(); i
++)
110 cts
[i
]->set_my_scope(p_scope
);
113 size_t CTs::get_nof_comps() const
116 for(size_t i
=0; i
<cts
.size(); i
++)
117 n
+=cts
[i
]->get_nof_comps();
121 CompField
* CTs::get_comp_byIndex(size_t n
) const
124 for(size_t i
= 0; i
< cts
.size(); i
++) {
125 size_t size
= cts
[i
]->get_nof_comps();
126 if (offset
< size
) return cts
[i
]->get_comp_byIndex(offset
);
129 FATAL_ERROR("%s: Requested index %lu does not exist.", \
130 get_fullname().c_str(), (unsigned long) n
);
134 bool CTs::has_comp_withName(const Identifier
& p_name
) const
136 for(size_t i
=0; i
<cts
.size(); i
++)
137 if(cts
[i
]->has_comp_withName(p_name
)) return true;
141 CompField
* CTs::get_comp_byName(const Identifier
& p_name
) const
143 for(size_t i
=0; i
<cts
.size(); i
++)
144 if(cts
[i
]->has_comp_withName(p_name
))
145 return cts
[i
]->get_comp_byName(p_name
);
146 FATAL_ERROR("`%s': No component with name `%s'", \
147 get_fullname().c_str(), p_name
.get_dispname().c_str());
151 void CTs::tr_compsof(ReferenceChain
*refch
, bool is_set
)
153 for(size_t i
= 0; i
< cts
.size(); i
++)
154 cts
[i
]->tr_compsof(refch
, is_set
);
157 void CTs::add_ct(CT
* p_ct
)
160 FATAL_ERROR("NULL parameter: Asn::CTs::add_ct()");
164 void CTs::dump(unsigned level
) const
166 for(size_t i
=0; i
<cts
.size(); i
++)
170 // =================================
172 // =================================
174 CTs_EE_CTs::CTs_EE_CTs(CTs
*p_cts1
, ExtAndExc
*p_ee
, CTs
*p_cts2
)
175 : Node(), my_type(0), checked(false)
177 cts1
= p_cts1
? p_cts1
: new CTs
;
179 cts2
= p_cts2
? p_cts2
: new CTs
;
182 CTs_EE_CTs::~CTs_EE_CTs()
191 CTs_EE_CTs::CTs_EE_CTs(const CTs_EE_CTs
& p
)
192 : Node(p
), my_type(p
.my_type
), checked(false)
194 cts1
= p
.cts1
->clone();
195 ee
= p
.ee
? p
.ee
->clone() : 0;
196 cts2
= p
.cts2
->clone();
199 CTs_EE_CTs
*CTs_EE_CTs::clone() const
201 return new CTs_EE_CTs(*this);
204 void CTs_EE_CTs::set_fullname(const string
& p_fullname
)
206 Node::set_fullname(p_fullname
);
207 cts1
->set_fullname(p_fullname
);
208 if (ee
) ee
->set_fullname(p_fullname
);
209 cts2
->set_fullname(p_fullname
);
212 void CTs_EE_CTs::set_my_scope(Scope
*p_scope
)
214 cts1
->set_my_scope(p_scope
);
215 if (ee
) ee
->set_my_scope(p_scope
);
216 cts2
->set_my_scope(p_scope
);
219 size_t CTs_EE_CTs::get_nof_comps()
222 return comps_v
.size();
225 size_t CTs_EE_CTs::get_nof_root_comps()
227 return cts1
->get_nof_comps() + cts2
->get_nof_comps();
230 CompField
* CTs_EE_CTs::get_comp_byIndex(size_t n
)
236 CompField
* CTs_EE_CTs::get_root_comp_byIndex(size_t n
)
238 size_t cts1_size
= cts1
->get_nof_comps();
239 if (n
< cts1_size
) return cts1
->get_comp_byIndex(n
);
240 else return cts2
->get_comp_byIndex(n
- cts1_size
);
243 bool CTs_EE_CTs::has_comp_withName(const Identifier
& p_name
)
246 return comps_m
.has_key(p_name
.get_name());
249 CompField
* CTs_EE_CTs::get_comp_byName(const Identifier
& p_name
)
252 return comps_m
[p_name
.get_name()];
255 void CTs_EE_CTs::tr_compsof(ReferenceChain
*refch
, bool in_ellipsis
)
257 if (!my_type
) FATAL_ERROR("NULL parameter: CTs_EE_CTs::tr_compsof()");
258 bool is_set
= my_type
->get_typetype() == Type::T_SET_A
;
260 if (ee
) ee
->tr_compsof(refch
, is_set
);
262 cts1
->tr_compsof(refch
, is_set
);
263 cts2
->tr_compsof(refch
, is_set
);
267 bool CTs_EE_CTs::needs_auto_tags()
269 if (!my_type
) FATAL_ERROR("NULL parameter: CTs_EE_CTs::needs_auto_tags()");
270 Asn::Module
*m
= dynamic_cast<Asn::Module
*>
271 (my_type
->get_my_scope()->get_scope_mod());
272 if (!m
) FATAL_ERROR("CTs_EE_CTs::needs_auto_tags()");
273 if (m
->get_tagdef() != TagDefault::AUTOMATIC
) return false;
274 for (size_t i
= 0; i
< cts1
->get_nof_comps(); i
++) {
275 if (cts1
->get_comp_byIndex(i
)->get_type()->is_tagged())
278 for (size_t i
= 0; i
< cts2
->get_nof_comps(); i
++) {
279 if (cts2
->get_comp_byIndex(i
)->get_type()->is_tagged())
283 bool error_flag
= false;
284 for (size_t i
= 0; i
< ee
->get_nof_comps(); i
++) {
285 CompField
*cf
= ee
->get_comp_byIndex(i
);
286 Type
*type
= cf
->get_type();
287 if (type
->is_tagged()) {
288 type
->error("Extension addition `%s' cannot have tags because "
289 "the extension root has no tags",
290 cf
->get_name().get_dispname().c_str());
294 if (error_flag
) return false;
299 void CTs_EE_CTs::add_auto_tags()
302 for (size_t i
= 0; i
< cts1
->get_nof_comps(); i
++) {
303 Tag
*tag
= new Tag(Tag::TAG_DEFPLICIT
, Tag::TAG_CONTEXT
, tagvalue
++);
304 tag
->set_automatic();
305 cts1
->get_comp_byIndex(i
)->get_type()->add_tag(tag
);
307 for (size_t i
= 0; i
< cts2
->get_nof_comps(); i
++) {
308 Tag
*tag
= new Tag(Tag::TAG_DEFPLICIT
, Tag::TAG_CONTEXT
, tagvalue
++);
309 tag
->set_automatic();
310 cts2
->get_comp_byIndex(i
)->get_type()->add_tag(tag
);
313 for (size_t i
= 0; i
< ee
->get_nof_comps(); i
++) {
314 Tag
*tag
= new Tag(Tag::TAG_DEFPLICIT
, Tag::TAG_CONTEXT
, tagvalue
++);
315 tag
->set_automatic();
316 ee
->get_comp_byIndex(i
)->get_type()->add_tag(tag
);
321 void CTs_EE_CTs::chk()
323 // Hack: for COMPONENTS OF transformation
324 // Type::chk() should not be called until the transformation is finished,
325 // but Type::get_type_refd() calls it from CT_CompsOf::tr_compsof().
326 // if (checked) return;
327 if (!my_type
) FATAL_ERROR("CTs_EE_CTs::chk()");
331 const char *type_name
;
332 const char *comp_name
;
333 switch (my_type
->get_typetype()) {
335 type_name
= "SEQUENCE";
336 comp_name
= "component";
340 comp_name
= "component";
342 case Type::T_CHOICE_A
:
343 type_name
= "CHOICE";
344 comp_name
= "alternative";
347 type_name
= "<unknown>";
348 comp_name
= "component";
351 size_t cts1_size
= cts1
->get_nof_comps();
352 for (size_t i
= 0; i
< cts1_size
; i
++) {
353 chk_comp_field(cts1
->get_comp_byIndex(i
), type_name
, comp_name
);
356 size_t ee_size
= ee
->get_nof_comps();
357 for (size_t i
= 0; i
< ee_size
; i
++) {
358 chk_comp_field(ee
->get_comp_byIndex(i
), type_name
, comp_name
);
361 size_t cts2_size
= cts2
->get_nof_comps();
362 for (size_t i
= 0; i
< cts2_size
; i
++) {
363 chk_comp_field(cts2
->get_comp_byIndex(i
), type_name
, comp_name
);
365 for (size_t i
=0; i
<comps_v
.size(); i
++) {
366 CompField
*cf
=comps_v
[i
];
367 const Identifier
& id
= cf
->get_name();
368 const char *dispname
= id
.get_dispname().c_str();
369 Type
*type
=cf
->get_type();
370 type
->set_genname(my_type
->get_genname_own(), id
.get_name());
371 type
->set_parent_type(my_type
);
373 Error_Context
cntxt(cf
, "In type of %s %s `%s'",
374 type_name
, comp_name
, dispname
);
377 if(cf
->has_default()) {
378 Value
* defval
=cf
->get_defval();
379 defval
->set_my_governor(type
);
380 Error_Context
cntxt(cf
, "In default value of %s %s `%s'", type_name
,
381 comp_name
, dispname
);
382 type
->chk_this_value_ref(defval
);
383 type
->chk_this_value(defval
, 0, Type::EXPECTED_CONSTANT
,
384 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
385 if (!semantic_check_only
) {
386 defval
->set_genname_prefix("const_");
387 defval
->set_genname_recursive(string(type
->get_genname_own()) +
389 defval
->set_code_section(GovernedSimple::CS_PRE_INIT
);
395 void CTs_EE_CTs::chk_tags()
397 if (!my_type
) FATAL_ERROR("NULL parameter: CTs_EE_CTs::chk_tags()");
398 switch (my_type
->get_typetype()) {
399 case Type::T_CHOICE_A
:
411 FATAL_ERROR("CTs_EE_CTs::chk_tags(): invalid typetype");
415 void CTs_EE_CTs::chk_comp_field(CompField
*cf
,
416 const char *type_name
,
417 const char *comp_name
)
419 const Identifier
& id
= cf
->get_name();
420 const string
& name
= id
.get_name();
421 if(comps_m
.has_key(name
)) {
422 const char *dispname_str
= id
.get_dispname().c_str();
423 cf
->error("Duplicate %s identifier in %s: `%s'", comp_name
, type_name
,
425 comps_m
[name
]->note("%s `%s' is already defined here", comp_name
,
428 comps_m
.add(name
, cf
);
430 if(!id
.get_has_valid(Identifier::ID_TTCN
))
431 cf
->warning("The identifier `%s' is not reachable from TTCN-3",
432 id
.get_dispname().c_str());
437 void CTs_EE_CTs::chk_tags_choice()
439 TagCollection collection
;
440 collection
.set_location(*my_type
);
441 for (size_t i
= 0; i
< cts1
->get_nof_comps(); i
++) {
442 CompField
*cf
= cts1
->get_comp_byIndex(i
);
443 Type
*type
= cf
->get_type();
444 if (type
->has_multiple_tags()) {
445 Error_Context
cntxt(type
, "In tags of alternative `%s'",
446 cf
->get_name().get_dispname().c_str());
447 get_multiple_tags(collection
, type
);
450 const Tag
*tag
= type
->get_tag();
451 if (collection
.hasTag(tag
))
452 type
->error("Alternative `%s' in CHOICE has non-distinct tag",
453 cf
->get_name().get_dispname().c_str());
454 else collection
.addTag(tag
);
457 if (cts2
->get_nof_comps() > 0)
458 FATAL_ERROR("CTs_EE_CTs::chk_tags_choice(): cts2 is not empty");
460 collection
.setExtensible();
461 Tag
greatest_tag(Tag::TAG_EXPLICIT
, Tag::TAG_NONE
, (Int
)0);
462 for (size_t i
= 0; i
< ee
->get_nof_comps(); i
++) {
463 CompField
*cf
= ee
->get_comp_byIndex(i
);
464 Type
*type
= cf
->get_type();
465 if (type
->has_multiple_tags()) {
467 coll2
.set_location(*type
);
468 get_multiple_tags(coll2
, type
);
469 if (!coll2
.isEmpty()) {
470 if (collection
.hasTags(&coll2
))
472 ("Alternative `%s' in CHOICE has non-distinct tag(s)",
473 cf
->get_name().get_dispname().c_str());
474 else collection
.addTags(&coll2
);
475 if (greatest_tag
< *coll2
.getSmallestTag())
476 greatest_tag
= *coll2
.getGreatestTag();
478 ("Alternative `%s' must have canonically greater tag(s)"
479 " than all previously added extension alternatives",
480 cf
->get_name().get_dispname().c_str());
483 const Tag
*tag
= type
->get_tag();
484 if (collection
.hasTag(tag
))
485 type
->error("Alternative `%s' in CHOICE has non-distinct tag",
486 cf
->get_name().get_dispname().c_str());
487 else collection
.addTag(tag
);
488 if (greatest_tag
< *tag
) greatest_tag
= *tag
;
490 ("Alternative `%s' must have canonically greater tag"
491 " than all previously added extension alternatives",
492 cf
->get_name().get_dispname().c_str());
498 void CTs_EE_CTs::chk_tags_seq()
500 TagCollection forbidden_tags
;
501 forbidden_tags
.set_location(*my_type
);
502 for (size_t i
= 0; i
< cts1
->get_nof_comps(); i
++) {
503 CompField
*cf
= cts1
->get_comp_byIndex(i
);
504 bool mandatory
= !cf
->get_is_optional() && !cf
->has_default();
505 chk_tags_seq_comp(forbidden_tags
, cf
, mandatory
);
509 forbidden_tags
.setExtensible();
510 TagCollection forbidden_tags2
;
511 forbidden_tags2
.set_location(*my_type
);
512 forbidden_tags2
.setExtensible();
513 for ( ; j
< cts2
->get_nof_comps(); j
++) {
514 CompField
*cf
= cts2
->get_comp_byIndex(j
);
515 bool mandatory
= !cf
->get_is_optional() && !cf
->has_default();
516 chk_tags_seq_comp(forbidden_tags
, cf
, false);
517 chk_tags_seq_comp(forbidden_tags2
, cf
, false);
523 for (size_t i
= 0; i
< ee
->get_nof_comps(); i
++) {
524 CompField
*cf
= ee
->get_comp_byIndex(i
);
525 bool mandatory
= !cf
->get_is_optional() && !cf
->has_default();
526 chk_tags_seq_comp(forbidden_tags
, cf
, mandatory
);
528 forbidden_tags
.clear();
529 forbidden_tags
.addTags(&forbidden_tags2
);
533 forbidden_tags
.clear();
534 for ( ; j
< cts2
->get_nof_comps(); j
++) {
535 CompField
*cf
= cts2
->get_comp_byIndex(j
);
536 bool mandatory
= !cf
->get_is_optional() && !cf
->has_default();
537 chk_tags_seq_comp(forbidden_tags
, cf
, mandatory
);
541 void CTs_EE_CTs::chk_tags_seq_comp(TagCollection
& coll
, CompField
*cf
,
544 Type
*type
= cf
->get_type();
545 bool is_empty
= coll
.isEmpty();
546 if (!is_mandatory
|| !is_empty
) {
547 if (type
->has_multiple_tags()) {
548 Error_Context
cntxt(type
, "While checking tags of component `%s'",
549 cf
->get_name().get_dispname().c_str());
550 get_multiple_tags(coll
, type
);
553 const Tag
*tag
= type
->get_tag();
555 type
->error("Tag of component `%s' is not allowed "
556 "in this context of SEQUENCE type",
557 cf
->get_name().get_dispname().c_str());
558 else coll
.addTag(tag
);
561 if (is_mandatory
&& !is_empty
) coll
.clear();
564 void CTs_EE_CTs::chk_tags_set()
566 TagCollection collection
;
567 collection
.set_location(*my_type
);
568 for (size_t i
= 0; i
< cts1
->get_nof_comps(); i
++) {
569 CompField
*cf
= cts1
->get_comp_byIndex(i
);
570 Type
*type
= cf
->get_type();
571 if (type
->has_multiple_tags()) {
572 Error_Context
cntxt(type
, "While checking tags of component `%s'",
573 cf
->get_name().get_dispname().c_str());
574 get_multiple_tags(collection
, type
);
577 const Tag
*tag
= type
->get_tag();
578 if (collection
.hasTag(tag
))
579 type
->error("Component `%s' in SET has non-distinct tag",
580 cf
->get_name().get_dispname().c_str());
581 else collection
.addTag(tag
);
584 for (size_t i
= 0; i
< cts2
->get_nof_comps(); i
++) {
585 CompField
*cf
= cts2
->get_comp_byIndex(i
);
586 Type
*type
= cf
->get_type();
587 if (type
->has_multiple_tags()) {
588 Error_Context
cntxt(type
, "While checking tags of component `%s'",
589 cf
->get_name().get_dispname().c_str());
590 get_multiple_tags(collection
, type
);
593 const Tag
*tag
= type
->get_tag();
594 if (collection
.hasTag(tag
))
595 type
->error("Component `%s' in SET has non-distinct tag",
596 cf
->get_name().get_dispname().c_str());
597 else collection
.addTag(tag
);
601 collection
.setExtensible();
602 Tag
greatest_tag(Tag::TAG_EXPLICIT
, Tag::TAG_NONE
, (Int
)0);
603 for (size_t i
= 0; i
< ee
->get_nof_comps(); i
++) {
604 CompField
*cf
= ee
->get_comp_byIndex(i
);
605 Type
*type
= cf
->get_type();
606 if (type
->has_multiple_tags()) {
608 coll2
.set_location(*type
);
609 get_multiple_tags(coll2
, type
);
610 if (!coll2
.isEmpty()) {
611 if (collection
.hasTags(&coll2
))
612 type
->error("Component `%s' in SET has non-distinct tag(s)",
613 cf
->get_name().get_dispname().c_str());
614 else collection
.addTags(&coll2
);
615 if (greatest_tag
< *coll2
.getSmallestTag())
616 greatest_tag
= *coll2
.getGreatestTag();
618 ("Component `%s' must have "
619 "canonically greater tag(s) than all previously added "
620 "extension components",
621 cf
->get_name().get_dispname().c_str());
624 const Tag
*tag
= type
->get_tag();
625 if (collection
.hasTag(tag
))
626 type
->error("Component `%s' in SET has non-distinct tag",
627 cf
->get_name().get_dispname().c_str());
628 else collection
.addTag(tag
);
629 if (greatest_tag
< *tag
) greatest_tag
= *tag
;
631 ("Component `%s' must have canonically greater "
632 "tag than all previously added extension components",
633 cf
->get_name().get_dispname().c_str());
640 void CTs_EE_CTs::get_multiple_tags(TagCollection
& coll
, Type
*type
)
642 Type
*t
=type
->get_type_refd_last();
643 if(t
->get_typetype()!=Type::T_CHOICE_A
)
644 FATAL_ERROR("CTs_EE_CTs::get_multiple_tags()");
645 map
<Type
*, void> chain
;
646 if(my_type
->get_typetype()==Type::T_CHOICE_A
)
647 chain
.add(my_type
, 0);
648 t
->get_tags(coll
, chain
);
652 void CTs_EE_CTs::dump(unsigned level
) const
654 if(cts1
) cts1
->dump(level
);
655 if(ee
) ee
->dump(level
);
656 if(cts2
) cts2
->dump(level
);
659 // =================================
661 // =================================
663 // =================================
665 // =================================
669 for(size_t i
=0; i
<eas
.size(); i
++) delete eas
[i
];
673 ExtAdds
*ExtAdds::clone() const
675 FATAL_ERROR("ExtAdds::clone");
678 void ExtAdds::set_fullname(const string
& p_fullname
)
680 Node::set_fullname(p_fullname
);
681 for(size_t i
=0; i
<eas
.size(); i
++)
682 // eas[i]->set_fullname(get_fullname()+"."+Int2string(i+1));
683 eas
[i
]->set_fullname(get_fullname());
686 void ExtAdds::set_my_scope(Scope
*p_scope
)
688 for(size_t i
=0; i
<eas
.size(); i
++)
689 eas
[i
]->set_my_scope(p_scope
);
692 size_t ExtAdds::get_nof_comps() const
695 for(size_t i
=0; i
<eas
.size(); i
++)
696 n
+=eas
[i
]->get_nof_comps();
700 CompField
* ExtAdds::get_comp_byIndex(size_t n
) const
703 for(size_t i
= 0; i
< eas
.size(); i
++) {
704 size_t size
= eas
[i
]->get_nof_comps();
705 if (offset
< size
) return eas
[i
]->get_comp_byIndex(offset
);
708 FATAL_ERROR("%s: Requested index %lu does not exist.", \
709 get_fullname().c_str(), (unsigned long) n
);
713 bool ExtAdds::has_comp_withName(const Identifier
& p_name
) const
715 for(size_t i
=0; i
<eas
.size(); i
++)
716 if(eas
[i
]->has_comp_withName(p_name
)) return true;
720 CompField
* ExtAdds::get_comp_byName(const Identifier
& p_name
) const
722 for(size_t i
=0; i
<eas
.size(); i
++)
723 if(eas
[i
]->has_comp_withName(p_name
))
724 return eas
[i
]->get_comp_byName(p_name
);
725 FATAL_ERROR("%s: No component with name `%s'", \
726 get_fullname().c_str(), p_name
.get_dispname().c_str());
730 void ExtAdds::tr_compsof(ReferenceChain
*refch
, bool is_set
)
732 for(size_t i
= 0; i
< eas
.size(); i
++)
733 eas
[i
]->tr_compsof(refch
, is_set
);
736 void ExtAdds::add_ea(ExtAdd
* p_ea
)
739 FATAL_ERROR("NULL parameter: Asn::ExtAdds::add_ea()");
743 void ExtAdds::dump(unsigned level
) const
745 for(size_t i
=0; i
<eas
.size(); i
++)
749 // =================================
751 // =================================
753 ExtAndExc::ExtAndExc(ExcSpec
*p_excSpec
, ExtAdds
*p_eas
)
757 eas
=p_eas
?p_eas
:new ExtAdds();
760 ExtAndExc::~ExtAndExc()
766 ExtAndExc
*ExtAndExc::clone() const
768 FATAL_ERROR("ExtAndExc::clone");
771 void ExtAndExc::set_fullname(const string
& p_fullname
)
773 Node::set_fullname(p_fullname
);
774 if(excSpec
) excSpec
->set_fullname(p_fullname
+".<exc>");
775 // eas->set_fullname(p_fullname+".<ext>");
776 eas
->set_fullname(p_fullname
);
779 void ExtAndExc::set_my_scope(Scope
*p_scope
)
781 if(excSpec
) excSpec
->set_my_scope(p_scope
);
782 eas
->set_my_scope(p_scope
);
785 void ExtAndExc::set_eas(ExtAdds
*p_eas
)
791 void ExtAndExc::dump(unsigned level
) const
793 DEBUG(level
, "...%s", excSpec
?" !":"");
794 if(eas
) eas
->dump(level
);
798 // =================================
800 // =================================
802 ExtAddGrp::ExtAddGrp(Value
* p_versionnumber
, CTs
*p_cts
)
806 FATAL_ERROR("NULL parameter: Asn::ExtAddGrp::ExtAddGrp()");
807 versionnumber
=p_versionnumber
;
811 ExtAddGrp::~ExtAddGrp()
813 delete versionnumber
;
817 ExtAddGrp
*ExtAddGrp::clone() const
819 FATAL_ERROR("ExtAddGrp::clone");
822 void ExtAddGrp::set_fullname(const string
& p_fullname
)
824 ExtAdd::set_fullname(p_fullname
);
825 if(versionnumber
) versionnumber
->set_fullname(p_fullname
826 +".<versionnumber>");
827 cts
->set_fullname(p_fullname
);
830 void ExtAddGrp::set_my_scope(Scope
*p_scope
)
832 if(versionnumber
) versionnumber
->set_my_scope(p_scope
);
833 cts
->set_my_scope(p_scope
);
836 size_t ExtAddGrp::get_nof_comps() const
838 return cts
->get_nof_comps();
841 CompField
* ExtAddGrp::get_comp_byIndex(size_t n
) const
843 return cts
->get_comp_byIndex(n
);
846 bool ExtAddGrp::has_comp_withName(const Identifier
& p_name
) const
848 return cts
->has_comp_withName(p_name
);
851 CompField
* ExtAddGrp::get_comp_byName(const Identifier
& p_name
) const
853 return cts
->get_comp_byName(p_name
);
856 void ExtAddGrp::tr_compsof(ReferenceChain
*refch
, bool is_set
)
858 cts
->tr_compsof(refch
, is_set
);
861 void ExtAddGrp::dump(unsigned level
) const
868 // =================================
870 // =================================
872 // =================================
874 // =================================
876 CT_reg::CT_reg(CompField
*p_comp
)
880 FATAL_ERROR("NULL parameter: Asn::CT_reg::CT_reg()");
889 CT_reg
*CT_reg::clone() const
891 FATAL_ERROR("CT_reg::clone");
894 void CT_reg::set_fullname(const string
& p_fullname
)
896 comp
->set_fullname(p_fullname
);
899 void CT_reg::set_my_scope(Scope
*p_scope
)
901 comp
->set_my_scope(p_scope
);
904 size_t CT_reg::get_nof_comps() const
909 CompField
*CT_reg::get_comp_byIndex(size_t n
) const
911 if (n
== 0) return comp
;
912 FATAL_ERROR("%s: Requested index %lu does not exist.", \
913 get_fullname().c_str(), (unsigned long) n
);
917 bool CT_reg::has_comp_withName(const Identifier
& p_name
) const
919 return comp
->get_name() == p_name
;
922 CompField
*CT_reg::get_comp_byName(const Identifier
& p_name
) const
924 if (comp
->get_name() == p_name
)
926 FATAL_ERROR("`%s': No component with name `%s'", \
927 get_fullname().c_str(), p_name
.get_dispname().c_str());
931 void CT_reg::tr_compsof(ReferenceChain
*, bool)
935 void CT_reg::dump(unsigned level
) const
941 // =================================
943 // =================================
945 CT_CompsOf::CT_CompsOf(Type
*p_compsoftype
)
946 : CT(), compsoftype(p_compsoftype
), tr_compsof_ready(false), cts(0)
949 FATAL_ERROR("NULL parameter: Asn::CT_CompsOf::CT_CompsOf()");
950 compsoftype
->set_ownertype(Type::OT_COMPS_OF
, this);
953 CT_CompsOf::~CT_CompsOf()
959 CT_CompsOf
*CT_CompsOf::clone() const
961 FATAL_ERROR("CT_CompsOf::clone");
964 void CT_CompsOf::set_fullname(const string
& p_fullname
)
966 ExtAdd::set_fullname(p_fullname
);
967 if(compsoftype
) compsoftype
->set_fullname(p_fullname
+".<CompsOfType>");
968 if(cts
) cts
->set_fullname(p_fullname
);
971 void CT_CompsOf::set_my_scope(Scope
*p_scope
)
973 if (compsoftype
) compsoftype
->set_my_scope(p_scope
);
974 if (cts
) cts
->set_my_scope(p_scope
);
977 size_t CT_CompsOf::get_nof_comps() const
979 if (cts
) return cts
->get_nof_comps();
983 CompField
* CT_CompsOf::get_comp_byIndex(size_t n
) const
985 if (!cts
) FATAL_ERROR("CT_CompsOf::get_comp_byIndex()");
986 return cts
->get_comp_byIndex(n
);
989 bool CT_CompsOf::has_comp_withName(const Identifier
& p_name
) const
991 if (cts
) return cts
->has_comp_withName(p_name
);
995 CompField
* CT_CompsOf::get_comp_byName(const Identifier
& p_name
) const
997 if (!cts
) FATAL_ERROR("CT_CompsOf::get_comp_byName()");
998 return cts
->get_comp_byName(p_name
);
1001 void CT_CompsOf::tr_compsof(ReferenceChain
*refch
, bool is_set
)
1003 if (tr_compsof_ready
) return;
1004 compsoftype
->set_genname(string("<dummy>"));
1005 Type
*t
=compsoftype
->get_type_refd_last();
1006 // to avoid re-entering in case of infinite recursion
1007 if (tr_compsof_ready
) return;
1008 bool error_flag
= true;
1010 switch (t
->get_typetype()) {
1020 t
->error("COMPONENTS OF in a SET type shall refer to another SET type"
1021 " instead of `%s'", t
->get_fullname().c_str());
1025 switch (t
->get_typetype()) {
1035 t
->error("COMPONENTS OF in a SEQUENCE type shall refer to another"
1036 " SEQUENCE type instead of `%s'", t
->get_fullname().c_str());
1041 tr_compsof_ready
= true;
1044 t
->tr_compsof(refch
);
1045 // another emergency exit for the case of infinite recursion
1046 if (tr_compsof_ready
) return;
1048 size_t n_comps
=t
->get_nof_root_comps();
1049 for(size_t i
=0; i
<n_comps
; i
++) {
1050 CompField
*cf
=t
->get_root_comp_byIndex(i
)->clone();
1051 cf
->get_type()->cut_auto_tags();
1052 cf
->set_location(*this);
1053 cts
->add_ct(new CT_reg(cf
));
1055 cts
->set_my_scope(compsoftype
->get_my_scope());
1056 cts
->set_fullname(get_fullname());
1057 tr_compsof_ready
=true;
1058 // compsoftype must not be deleted because the above t->get_type_refd()
1059 // call may modify it in case of infinite recursion
1062 void CT_CompsOf::dump(unsigned level
) const
1065 DEBUG(level
, "COMPONENTS OF");
1066 compsoftype
->dump(level
+1);
1068 if(cts
) cts
->dump(level
);
1071 } // namespace Common