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 ///////////////////////////////////////////////////////////////////////////////
9 #include "../Identifier.hh"
11 #include "TokenBuf.hh"
13 #include "../Value.hh"
19 // =================================
21 // =================================
23 // =================================
25 // =================================
28 : ObjectClass(), block_fs(0), block_ws(0), fss(0),
29 ocs(0), is_erroneous(true), is_generated(false)
33 OC_defn::OC_defn(Block
*p_block_fs
, Block
*p_block_ws
)
34 : ObjectClass(), block_fs(p_block_fs
), block_ws(p_block_ws
), fss(0),
35 ocs(0), is_erroneous(false), is_generated(false)
38 FATAL_ERROR("NULL parameter: Asn::OC_defn::OC_defn()");
41 OC_defn::OC_defn(const OC_defn
& p
)
42 : ObjectClass(p
), is_erroneous(p
.is_erroneous
),
45 block_fs
=p
.block_fs
?p
.block_fs
->clone():0;
46 block_ws
=p
.block_ws
?p
.block_ws
->clone():0;
47 fss
=p
.fss
?p
.fss
->clone():0;
48 if(fss
) fss
->set_my_oc(this);
49 /* warning: this is not implemented */
50 // ocs=p.ocs?p.ocs->clone():0;
62 void OC_defn::set_fullname(const string
& p_fullname
)
64 ObjectClass::set_fullname(p_fullname
);
65 if(fss
) fss
->set_fullname(p_fullname
);
74 TokenBuf
*t_tb
=block_ws
?block_ws
->get_TokenBuf():0;
76 Error_Context
ec(this, "In syntax of ObjectClass `%s'",
77 this->get_fullname().c_str());
78 OCSV_Builder
*ocsv_builder
=new OCSV_Builder(t_tb
, fss
);
79 ocs
->accept(*ocsv_builder
);
81 delete block_ws
; block_ws
=0;
86 void OC_defn::chk_this_obj(Object
*p_obj
)
89 FATAL_ERROR("NULL parameter: Asn::OC_defn::chk_this_obj()");
90 if(is_erroneous
) return;
91 Obj_defn
*obj
=p_obj
->get_refd_last();
92 Error_Context
ec(obj
, "In object definition `%s'",
93 obj
->get_fullname().c_str());
94 for(size_t i
=0; i
<fss
->get_nof_fss(); i
++) {
95 FieldSpec
*fspec
=fss
->get_fs_byIndex(i
)->get_last();
96 if(!obj
->has_fs_withName(fspec
->get_id())) {
97 if(!(fspec
->get_is_optional() || fspec
->has_default())
98 && !(obj
->get_is_erroneous())) {
99 obj
->error("Missing setting for `%s'",
100 fspec
->get_id().get_dispname().c_str());
101 obj
->set_is_erroneous();
105 FieldSetting
*fset
=obj
->get_fs_byName(fspec
->get_id());
107 Error_Context
ec2(fset
, "In setting for `%s'",
108 fspec
->get_id().get_dispname().c_str());
109 fset
->set_genname(obj
->get_genname_own(), fspec
->get_id().get_name());
114 void OC_defn::parse_block_fs()
118 if(!is_erroneous
) FATAL_ERROR("Asn::OC_defn::parse_block_fs()");
121 Node
*node
=block_fs
->parse(KW_Block_FieldSpecList
);
122 delete block_fs
; block_fs
=0;
123 fss
=dynamic_cast<FieldSpecs
*>(node
);
125 if(!fss
) fss
=new FieldSpecs();
126 fss
->set_fullname(get_fullname());
127 fss
->set_my_oc(this);
130 OCS_root
* OC_defn::get_ocs()
136 FieldSpecs
* OC_defn::get_fss()
142 void OC_defn::generate_code(output_struct
*target
)
144 if(is_generated
) return;
146 fss
->generate_code(target
);
149 void OC_defn::dump(unsigned level
) const
151 DEBUG(level
, "ObjectClass definition");
153 DEBUG(level
, "with unparsed block");
155 DEBUG(level
, "with fieldspecs (%lu pcs):",
156 (unsigned long) fss
->get_nof_fss());
160 DEBUG(level
, "with syntax definition:");
165 // =================================
167 // =================================
169 OC_refd::OC_refd(Reference
*p_ref
)
170 : ObjectClass(), ref(p_ref
), oc_error(0), oc_refd(0), oc_defn(0)
173 FATAL_ERROR("NULL parameter: Asn::OC_refd::OC_refd()");
176 OC_refd::OC_refd(const OC_refd
& p
)
177 : ObjectClass(p
), oc_error(0), oc_refd(0), oc_defn(0)
188 void OC_refd::set_my_scope(Scope
*p_scope
)
190 ObjectClass::set_my_scope(p_scope
);
191 ref
->set_my_scope(p_scope
);
194 void OC_refd::set_fullname(const string
& p_fullname
)
196 ObjectClass::set_fullname(p_fullname
);
197 ref
->set_fullname(p_fullname
);
200 OC_defn
* OC_refd::get_refd_last(ReferenceChain
*refch
)
203 bool destroy_refch
=false;
205 refch
=new ReferenceChain
206 (ref
, "While searching referenced ObjectClass");
209 oc_defn
=get_refd(refch
)->get_refd_last(refch
);
210 if(destroy_refch
) delete refch
;
215 ObjectClass
* OC_refd::get_refd(ReferenceChain
*refch
)
217 if(refch
) refch
->add(get_fullname());
220 Common::Assignment
*ass
=ref
->get_refd_assignment();
222 setting
=ref
->get_refd_setting();
223 if(setting
->get_st()==Setting::S_ERROR
) goto error
;
224 oc_refd
=dynamic_cast<ObjectClass
*>(setting
);
226 error("This is not an objectclassreference: `%s'",
227 ref
->get_dispname().c_str());
232 oc_error
=new OC_defn();
246 void OC_refd::chk_this_obj(Object
*obj
)
248 get_refd_last()->chk_this_obj(obj
);
251 OCS_root
* OC_refd::get_ocs()
254 return get_refd_last()->get_ocs();
257 FieldSpecs
* OC_refd::get_fss()
260 return get_refd_last()->get_fss();
263 void OC_refd::generate_code(output_struct
*target
)
265 OC_defn
*refd_last
= get_refd_last();
266 if(my_scope
->get_scope_mod_gen() ==
267 refd_last
->get_my_scope()->get_scope_mod_gen())
268 refd_last
->generate_code(target
);
271 void OC_refd::dump(unsigned level
) const
273 DEBUG(level
, "objectclassreference");
278 // =================================
280 // =================================
282 FieldSpec::FieldSpec(fstype_t p_fstype
, Identifier
*p_id
,
283 bool p_is_optional
=false)
284 : Node(), Location(), fstype(p_fstype
), id(p_id
),
285 is_optional(p_is_optional
), my_oc(0), checked(false)
288 FATAL_ERROR("NULL parameter: Asn::FieldSpec::FieldSpec()");
291 FieldSpec::FieldSpec(const FieldSpec
& p
)
292 : Node(p
), Location(p
), fstype(p
.fstype
), is_optional(p
.is_optional
),
293 my_oc(0), checked(false)
298 FieldSpec::~FieldSpec()
303 void FieldSpec::set_fullname(const string
& p_fullname
)
305 Node::set_fullname(p_fullname
);
308 void FieldSpec::set_my_oc(OC_defn
*p_oc
)
313 // =================================
314 // ===== FieldSpec_Undef
315 // =================================
317 FieldSpec_Undef::FieldSpec_Undef(Identifier
*p_id
, Ref_defd
*p_govref
,
318 bool p_is_optional
, Node
*p_defsetting
)
319 : FieldSpec(FS_UNDEF
, p_id
, p_is_optional
),
320 govref(p_govref
), defsetting(p_defsetting
), fs(0)
323 FATAL_ERROR("FieldSpec_Undef::FieldSpec_Undef()");
326 FieldSpec_Undef::FieldSpec_Undef(const FieldSpec_Undef
& p
)
329 govref
=p
.govref
?p
.govref
->clone():0;
330 defsetting
=p
.defsetting
?p
.defsetting
->clone():0;
331 fs
=p
.fs
?p
.fs
->clone():0;
334 FieldSpec_Undef::~FieldSpec_Undef()
341 /** \todo Enhance! (FS_VS_FT + refch!) */
342 void FieldSpec_Undef::classify_fs(ReferenceChain
*refch
)
344 if(fstype
!=FS_UNDEF
) return;
345 bool destroy_refch
=false;
347 refch
=new ReferenceChain(this, "While examining kind of fieldspec");
350 else refch
->mark_state();
352 if(is_optional
&& defsetting
) {
353 error("OPTIONAL and DEFAULT are mutual exclusive");
357 /* temporary pointers */
362 if(!refch
->add(get_fullname()))
365 if((t_ref
=dynamic_cast<Reference
*>(govref
))) {
366 t_ref
->set_my_scope(my_oc
->get_my_scope());
367 if(t_ref
->refers_to_st(Setting::S_ERROR
, refch
))
370 if((t_ref
=dynamic_cast<Reference
*>(defsetting
)))
371 t_ref
->set_my_scope(my_oc
->get_my_scope());
372 govref
->set_fullname(get_fullname());
373 if(defsetting
) defsetting
->set_fullname(get_fullname());
375 if(id
->isvalid_asn_objsetfieldref()
376 && (t_ref
=dynamic_cast<Ref_defd_simple
*>(govref
))
377 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
379 ObjectSet
*defobjset
=0;
381 if((t_block
=dynamic_cast<Block
*>(defsetting
))) {
382 defobjset
=new OS_defn(t_block
);
385 error("Cannot recognize DEFAULT setting"
386 " for this ObjectSetFieldSpec");
388 defobjset
=new OS_defn();
391 fs
=new FieldSpec_OS(id
->clone(), new OC_refd(t_ref
),
392 is_optional
, defobjset
);
397 else if(id
->isvalid_asn_objfieldref()
398 && (t_ref
=dynamic_cast<Ref_defd_simple
*>(govref
))
399 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
403 if((t_block
=dynamic_cast<Block
*>(defsetting
))) {
404 defobj
=new Obj_defn(t_block
);
406 else if((t_ref2
=dynamic_cast<Reference
*>(defsetting
))) {
407 defobj
=new Obj_refd(t_ref2
);
410 error("Cannot recognize DEFAULT setting"
411 " for this ObjectFieldSpec");
413 defobj
=new Obj_defn();
416 fs
=new FieldSpec_O(id
->clone(), new OC_refd(t_ref
),
417 is_optional
, defobj
);
422 else if(id
->isvalid_asn_valfieldref()
423 && (t_ref
=dynamic_cast<Ref_defd
*>(govref
))
424 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
425 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
429 if((t_block
=dynamic_cast<Block
*>(defsetting
))) {
430 defval
=new Value(Value::V_UNDEF_BLOCK
, t_block
);
432 else if((t_ref2
=dynamic_cast<Reference
*>(defsetting
))) {
433 Ref_defd_simple
*t_ref3
=dynamic_cast<Ref_defd_simple
*>(t_ref2
);
434 if(t_ref3
&& !t_ref3
->get_modid()) {
435 defval
=new Value(Value::V_UNDEF_LOWERID
,
436 t_ref3
->get_id()->clone());
440 defval
=new Value(Value::V_REFD
, t_ref2
);
444 error("Cannot recognize DEFAULT setting"
445 " for this FixedTypeValueFieldSpec");
447 defval
=new Value(Value::V_ERROR
);
450 fs
=new FieldSpec_V_FT(id
->clone(), new Type(Type::T_REFD
, t_ref
),
451 false, is_optional
, defval
);
462 error("Cannot recognize fieldspec");
463 fs
=new FieldSpec_Error(id
->clone(), is_optional
, defsetting
!=0);
464 delete defsetting
; defsetting
=0;
466 fs
->set_fullname(get_fullname());
467 if(my_oc
) fs
->set_my_oc(my_oc
);
468 fs
->set_location(*this);
469 if(destroy_refch
) delete refch
;
470 else refch
->prev_state();
473 FieldSpec
* FieldSpec_Undef::clone() const
475 if(fs
) return fs
->clone();
476 else return new FieldSpec_Undef(*this);
479 void FieldSpec_Undef::set_fullname(const string
& p_fullname
)
481 FieldSpec::set_fullname(p_fullname
);
482 if(fs
) fs
->set_fullname(p_fullname
);
485 FieldSpec::fstype_t
FieldSpec_Undef::get_fstype()
491 void FieldSpec_Undef::set_my_oc(OC_defn
*p_oc
)
493 FieldSpec::set_my_oc(p_oc
);
494 if(fs
) fs
->set_my_oc(p_oc
);
497 bool FieldSpec_Undef::has_default()
499 if(fs
) return fs
->has_default();
500 else return defsetting
;
503 void FieldSpec_Undef::chk()
511 Setting
* FieldSpec_Undef::get_default()
514 return fs
->get_default();
517 FieldSpec
* FieldSpec_Undef::get_last()
520 return fs
->get_last();
523 void FieldSpec_Undef::generate_code(output_struct
*target
)
526 fs
->generate_code(target
);
529 // =================================
530 // ===== FieldSpec_Error
531 // =================================
533 FieldSpec_Error::FieldSpec_Error(Identifier
*p_id
, bool p_is_optional
,
535 : FieldSpec(FS_ERROR
, p_id
, p_is_optional
), setting_error(0),
536 has_default_flag(p_has_default
)
540 FieldSpec_Error::FieldSpec_Error(const FieldSpec_Error
& p
)
541 : FieldSpec(p
), setting_error(0), has_default_flag(p
.has_default_flag
)
545 FieldSpec_Error::~FieldSpec_Error()
547 delete setting_error
;
550 FieldSpec_Error
*FieldSpec_Error::clone() const
552 return new FieldSpec_Error(*this);
555 bool FieldSpec_Error::has_default()
557 return has_default_flag
;
560 Setting
* FieldSpec_Error::get_default()
562 if(!setting_error
&& has_default_flag
)
563 setting_error
=new Common::Setting_Error();
564 return setting_error
;
567 void FieldSpec_Error::chk()
572 void FieldSpec_Error::generate_code(output_struct
*)
577 // =================================
579 // =================================
581 FieldSpec_T::FieldSpec_T(Identifier
*p_id
, bool p_is_optional
,
583 : FieldSpec(FS_T
, p_id
, p_is_optional
), deftype(p_deftype
)
585 if(is_optional
&& deftype
) {
586 error("OPTIONAL and DEFAULT are mutual exclusive");
589 if (deftype
) deftype
->set_ownertype(Type::OT_TYPE_FLD
, this);
592 FieldSpec_T::FieldSpec_T(const FieldSpec_T
& p
)
595 deftype
=p
.deftype
?p
.deftype
->clone():0;
598 FieldSpec_T::~FieldSpec_T()
603 void FieldSpec_T::set_fullname(const string
& p_fullname
)
605 FieldSpec::set_fullname(p_fullname
);
606 if(deftype
) deftype
->set_fullname(p_fullname
);
609 void FieldSpec_T::set_my_oc(OC_defn
*p_oc
)
611 FieldSpec::set_my_oc(p_oc
);
612 if(deftype
) deftype
->set_my_scope(my_oc
->get_my_scope());
615 Type
* FieldSpec_T::get_default()
620 void FieldSpec_T::chk()
624 deftype
->set_genname(my_oc
->get_genname_own(), id
->get_name());
630 void FieldSpec_T::generate_code(output_struct
*target
)
632 if (deftype
) deftype
->generate_code(target
);
635 // =================================
636 // ===== FieldSpec_V_FT
637 // =================================
639 FieldSpec_V_FT::FieldSpec_V_FT(Identifier
*p_id
, Type
*p_fixtype
,
640 bool p_is_unique
, bool p_is_optional
,
642 : FieldSpec(FS_V_FT
, p_id
, p_is_optional
),
643 fixtype(p_fixtype
), is_unique(p_is_unique
), defval(p_defval
)
646 FATAL_ERROR("NULL parameter: FieldSpec_V_FT::FieldSpec_V_FT()");
647 fixtype
->set_ownertype(Type::OT_FT_V_FLD
, this);
648 if(is_optional
&& defval
) {
649 error("OPTIONAL and DEFAULT are mutual exclusive");
652 if(is_unique
&& defval
)
653 error("UNIQUE and DEFAULT are mutual exclusive");
656 FieldSpec_V_FT::FieldSpec_V_FT(const FieldSpec_V_FT
& p
)
657 : FieldSpec(p
), is_unique(p
.is_unique
)
659 fixtype
=p
.fixtype
->clone();
660 defval
=p
.defval
?p
.defval
->clone():0;
663 FieldSpec_V_FT::~FieldSpec_V_FT()
669 void FieldSpec_V_FT::set_fullname(const string
& p_fullname
)
671 FieldSpec::set_fullname(p_fullname
);
672 fixtype
->set_fullname(p_fullname
);
673 if(defval
) defval
->set_fullname(p_fullname
);
676 void FieldSpec_V_FT::set_my_oc(OC_defn
*p_oc
)
678 FieldSpec::set_my_oc(p_oc
);
679 Scope
*scope
=my_oc
->get_my_scope();
680 fixtype
->set_my_scope(scope
);
681 if(defval
) defval
->set_my_scope(scope
);
684 Value
* FieldSpec_V_FT::get_default()
689 void FieldSpec_V_FT::chk()
692 fixtype
->set_genname(my_oc
->get_genname_own(), id
->get_name());
695 defval
->set_my_governor(fixtype
);
696 fixtype
->chk_this_value_ref(defval
);
697 fixtype
->chk_this_value(defval
, 0, Type::EXPECTED_CONSTANT
,
698 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
699 if (!semantic_check_only
) {
700 defval
->set_genname_prefix("const_");
701 defval
->set_genname_recursive(string(fixtype
->get_genname_own()) +
703 defval
->set_code_section(GovernedSimple::CS_PRE_INIT
);
709 void FieldSpec_V_FT::generate_code(output_struct
*target
)
711 fixtype
->generate_code(target
);
714 Code::init_cdef(&cdef
);
715 fixtype
->generate_code_object(&cdef
, defval
);
716 cdef
.init
= defval
->generate_code_init(cdef
.init
,
717 defval
->get_lhs_name().c_str());
718 Code::merge_cdef(target
, &cdef
);
719 Code::free_cdef(&cdef
);
723 // =================================
724 // ===== FieldSpec_V_VT
725 // =================================
727 // =================================
728 // ===== FieldSpec_VS_FT
729 // =================================
731 // =================================
732 // ===== FieldSpec_VS_VT
733 // =================================
735 // =================================
737 // =================================
739 FieldSpec_O::FieldSpec_O(Identifier
*p_id
, ObjectClass
*p_oc
,
740 bool p_is_optional
, Object
*p_defobj
)
741 : FieldSpec(FS_O
, p_id
, p_is_optional
),
742 oc(p_oc
), defobj(p_defobj
)
745 FATAL_ERROR("NULL parameter: FieldSpec_O::FieldSpec_O()");
746 if(is_optional
&& defobj
) {
747 error("OPTIONAL and DEFAULT are mutual exclusive");
752 FieldSpec_O::FieldSpec_O(const FieldSpec_O
& p
)
756 defobj
=p
.defobj
?p
.defobj
->clone():0;
759 FieldSpec_O::~FieldSpec_O()
765 void FieldSpec_O::set_fullname(const string
& p_fullname
)
767 FieldSpec::set_fullname(p_fullname
);
768 oc
->set_fullname(p_fullname
);
769 if(defobj
) defobj
->set_fullname(p_fullname
);
772 void FieldSpec_O::set_my_oc(OC_defn
*p_oc
)
774 FieldSpec::set_my_oc(p_oc
);
775 Scope
*scope
=my_oc
->get_my_scope();
776 oc
->set_my_scope(scope
);
777 if(defobj
) defobj
->set_my_scope(scope
);
780 void FieldSpec_O::chk()
783 oc
->set_genname(my_oc
->get_genname_own(), id
->get_name());
786 defobj
->set_my_governor(oc
);
787 defobj
->set_genname(oc
->get_genname_own(), string("_defobj_"));
793 void FieldSpec_O::generate_code(output_struct
*target
)
795 oc
->generate_code(target
);
796 if (defobj
) defobj
->generate_code(target
);
799 // =================================
800 // ===== FieldSpec_OS
801 // =================================
803 FieldSpec_OS::FieldSpec_OS(Identifier
*p_id
, ObjectClass
*p_oc
,
804 bool p_is_optional
, ObjectSet
*p_defobjset
)
805 : FieldSpec(FS_OS
, p_id
, p_is_optional
),
806 oc(p_oc
), defobjset(p_defobjset
)
809 FATAL_ERROR("NULL parameter: FieldSpec_OS::FieldSpec_OS()");
810 if(is_optional
&& defobjset
) {
811 error("OPTIONAL and DEFAULT are mutual exclusive");
816 FieldSpec_OS::FieldSpec_OS(const FieldSpec_OS
& p
)
820 defobjset
=p
.defobjset
?p
.defobjset
->clone():0;
823 FieldSpec_OS::~FieldSpec_OS()
829 void FieldSpec_OS::set_fullname(const string
& p_fullname
)
831 FieldSpec::set_fullname(p_fullname
);
832 oc
->set_fullname(p_fullname
);
833 if(defobjset
) defobjset
->set_fullname(p_fullname
);
836 void FieldSpec_OS::set_my_oc(OC_defn
*p_oc
)
838 FieldSpec::set_my_oc(p_oc
);
839 Scope
*scope
=my_oc
->get_my_scope();
840 oc
->set_my_scope(scope
);
841 if(defobjset
) defobjset
->set_my_scope(scope
);
844 void FieldSpec_OS::chk()
847 oc
->set_genname(my_oc
->get_genname_own(), id
->get_name());
850 defobjset
->set_my_governor(oc
);
851 defobjset
->set_genname(oc
->get_genname_own(), string("_defobj_"));
857 void FieldSpec_OS::generate_code(output_struct
*target
)
859 oc
->generate_code(target
);
860 if (defobjset
) defobjset
->generate_code(target
);
863 // =================================
865 // =================================
867 FieldSpecs::FieldSpecs()
868 : Node(), fs_error(0), my_oc(0)
872 FieldSpecs::FieldSpecs(const FieldSpecs
& p
)
873 : Node(p
), fs_error(0), my_oc(0)
875 for(size_t i
=0; i
<p
.fss_v
.size(); i
++)
876 add_fs(p
.fss_v
[i
]->clone());
879 FieldSpecs::~FieldSpecs()
881 for(size_t i
=0; i
<fss_v
.size(); i
++)
888 void FieldSpecs::set_fullname(const string
& p_fullname
)
890 Node::set_fullname(p_fullname
);
891 for(size_t i
=0; i
<fss_v
.size(); i
++) {
892 FieldSpec
*fs
=fss_v
[i
];
893 fs
->set_fullname(p_fullname
+"."+fs
->get_id().get_dispname());
897 void FieldSpecs::set_my_oc(OC_defn
*p_oc
)
900 for(size_t i
=0; i
<fss_v
.size(); i
++)
901 fss_v
[i
]->set_my_oc(p_oc
);
904 void FieldSpecs::add_fs(FieldSpec
*p_fs
)
907 FATAL_ERROR("NULL parameter: Asn::FieldSpecs::add_fs()");
908 if(fss
.has_key(p_fs
->get_id().get_name())) {
909 p_fs
->error("A fieldspec with identifier `%s' already exists",
910 p_fs
->get_id().get_dispname().c_str());
914 fss
.add(p_fs
->get_id().get_name(), p_fs
);
916 p_fs
->set_fullname(get_fullname()+"."+p_fs
->get_id().get_dispname());
917 if(my_oc
) p_fs
->set_my_oc(my_oc
);
920 bool FieldSpecs::has_fs_withId(const Identifier
& p_id
)
922 return fss
.has_key(p_id
.get_name());
925 FieldSpec
* FieldSpecs::get_fs_byId(const Identifier
& p_id
)
927 if(fss
.has_key(p_id
.get_name()))
928 return fss
[p_id
.get_name()];
929 my_oc
->error("No fieldspec with name `%s'", p_id
.get_dispname().c_str());
930 return get_fs_error();
933 FieldSpec
* FieldSpecs::get_fs_byIndex(size_t p_i
)
935 if(p_i
<fss_v
.size())
937 my_oc
->error("No fieldspec at index %s", Int2string(p_i
).c_str());
938 return get_fs_error();
941 FieldSpec
* FieldSpecs::get_fs_error()
944 fs_error
=new FieldSpec_Error
945 (new Identifier(Identifier::ID_NAME
, string("<error>")), true, false);
949 void FieldSpecs::chk()
951 for(size_t i
=0; i
<fss_v
.size(); i
++) {
952 FieldSpec
*fs
=fss_v
[i
];
953 Error_Context
ec(fs
, "In fieldspec `%s'",
954 fs
->get_id().get_dispname().c_str());
959 void FieldSpecs::generate_code(output_struct
*target
)
961 for(size_t i
=0; i
<fss_v
.size(); i
++)
962 fss_v
[i
]->generate_code(target
);
965 void FieldSpecs::dump(unsigned level
) const
967 DEBUG(level
, "Fieldspecs (%lu pcs.)", (unsigned long) fss
.size());
969 for(size_t i
=0; i
<fss_v
.size(); i
++)
970 fss_v
[i
]->dump(level
);
973 // =================================
975 // =================================
977 OCS_Visitor
* OCS_Visitor::clone() const
979 FATAL_ERROR("Asn::OCS_Visitor::clone()");
983 // =================================
985 // =================================
987 OCS_Node
* OCS_Node::clone() const
989 FATAL_ERROR("Asn::OCS_Node::clone()");
993 void OCS_Node::dump(unsigned level
) const
995 DEBUG(level
, "OCS_Node");
998 // =================================
1000 // =================================
1004 for(size_t i
=0; i
<ocss
.size(); i
++)
1009 void OCS_seq::add_node(OCS_Node
*p_node
)
1012 FATAL_ERROR("NULL parameter: Asn::OCS_seq::add_node()");
1016 OCS_Node
* OCS_seq::get_nth_node(size_t p_i
)
1018 if(ocss
.size()<=p_i
)
1019 FATAL_ERROR("Asn::OCS_seq::get_nth_node()");
1023 string
OCS_seq::get_dispname() const
1027 for(size_t i
=0; i
<ocss
.size(); i
++) {
1029 s
+=ocss
[i
]->get_dispname();
1035 void OCS_seq::dump(unsigned level
) const
1037 DEBUG(level
, "%soptional sequence of tokens:", is_opt
?"":"not ");
1040 DEBUG(level
, "[,]");
1041 for(size_t i
=0; i
<ocss
.size(); i
++)
1042 ocss
[i
]->dump(level
);
1045 // =================================
1047 // =================================
1049 string
OCS_root::get_dispname() const
1051 return seq
.get_dispname();
1054 void OCS_root::dump(unsigned level
) const
1059 // =================================
1060 // ===== OCS_literal
1061 // =================================
1063 OCS_literal::OCS_literal(Identifier
*p_word
)
1064 : OCS_Node(), word(p_word
)
1067 FATAL_ERROR("NULL parameter: Asn::OCS_literal::OCS_literal()");
1070 OCS_literal::~OCS_literal()
1075 string
OCS_literal::get_dispname() const
1078 if(word
) s
+=word
->get_dispname().c_str();
1079 else s
+=Token::get_token_name(keyword
);
1084 void OCS_literal::dump(unsigned level
) const
1086 DEBUG(level
, "literal: %s", get_dispname().c_str());
1089 // =================================
1090 // ===== OCS_setting
1091 // =================================
1093 OCS_setting::OCS_setting(settingtype_t p_st
, Identifier
*p_id
)
1094 : OCS_Node(), st(p_st
), id(p_id
)
1097 FATAL_ERROR("NULL parameter: Asn::OCS_setting::OCS_setting()");
1100 OCS_setting::~OCS_setting()
1105 string
OCS_setting::get_dispname() const
1109 case S_T
: s
+="Type"; break;
1110 case S_V
: s
+="Value"; break;
1111 case S_VS
: s
+="ValueSet"; break;
1112 case S_O
: s
+="Object"; break;
1113 case S_OS
: s
+="ObjectSet"; break;
1120 void OCS_setting::dump(unsigned level
) const
1122 DEBUG(level
, "%s (setting for `%s')",
1123 get_dispname().c_str(),
1124 id
->get_dispname().c_str());
1127 // =================================
1129 // =================================
1131 OS_Element::~OS_Element()
1136 // =================================
1138 // =================================
1140 void Object::set_my_governor(ObjectClass
*p_gov
)
1143 FATAL_ERROR("NULL parameter: Asn::Object::set_my_governor()");
1147 OS_Element
*Object::clone_ose() const
1152 void Object::set_fullname_ose(const string
& p_fullname
)
1154 set_fullname(p_fullname
);
1157 void Object::set_genname_ose(const string
& p_prefix
, const string
& p_suffix
)
1159 set_genname(p_prefix
, p_suffix
);
1162 void Object::set_my_scope_ose(Scope
*p_scope
)
1164 set_my_scope(p_scope
);
1167 // =================================
1168 // ===== FieldSetting
1169 // =================================
1171 FieldSetting::FieldSetting(Identifier
*p_name
)
1172 : Node(), Location(), name(p_name
), checked(false)
1175 FATAL_ERROR("NULL parameter: Asn::FieldSetting::FieldSetting()");
1178 FieldSetting::FieldSetting(const FieldSetting
& p
)
1179 : Node(p
), Location(p
), checked(false)
1181 name
=p
.name
->clone();
1184 FieldSetting::~FieldSetting()
1189 void FieldSetting::set_fullname(const string
& p_fullname
)
1191 Node::set_fullname(p_fullname
);
1192 get_setting()->set_fullname(p_fullname
);
1195 void FieldSetting::set_my_scope(Scope
*p_scope
)
1197 get_setting()->set_my_scope(p_scope
);
1200 void FieldSetting::set_genname(const string
& p_prefix
,
1201 const string
& p_suffix
)
1203 get_setting()->set_genname(p_prefix
, p_suffix
);
1206 // =================================
1207 // ===== FieldSetting_Type
1208 // =================================
1210 FieldSetting_Type::FieldSetting_Type(Identifier
*p_name
, Type
*p_setting
)
1211 : FieldSetting(p_name
), setting(p_setting
)
1215 ("NULL parameter: Asn::FieldSetting_Type::FieldSetting_Type()");
1216 setting
->set_ownertype(Type::OT_FIELDSETTING
, this);
1219 FieldSetting_Type::FieldSetting_Type(const FieldSetting_Type
& p
)
1222 setting
=p
.setting
->clone();
1225 FieldSetting_Type::~FieldSetting_Type()
1230 void FieldSetting_Type::chk(FieldSpec
*p_fspec
)
1233 if(p_fspec
->get_fstype()!=FieldSpec::FS_T
) {
1234 error("Type setting was expected");
1236 setting
=new Type(Type::T_ERROR
);
1240 ReferenceChain
refch(setting
, "While checking embedded recursions");
1241 setting
->chk_recursions(refch
);
1244 void FieldSetting_Type::generate_code(output_struct
*target
)
1246 setting
->generate_code(target
);
1249 void FieldSetting_Type::dump(unsigned level
) const
1251 DEBUG(level
, "field setting (type): %s", name
->get_dispname().c_str());
1253 setting
->dump(level
);
1256 // =================================
1257 // ===== FieldSetting_Value
1258 // =================================
1260 FieldSetting_Value::FieldSetting_Value(Identifier
*p_name
, Value
*p_setting
)
1261 : FieldSetting(p_name
), setting(p_setting
)
1265 ("NULL parameter: Asn::FieldSetting_Value::FieldSetting_Value()");
1268 FieldSetting_Value::FieldSetting_Value(const FieldSetting_Value
& p
)
1271 setting
=p
.setting
->clone();
1274 FieldSetting_Value::~FieldSetting_Value()
1279 void FieldSetting_Value::chk(FieldSpec
*p_fspec
)
1282 if(p_fspec
->get_fstype()!=FieldSpec::FS_V_FT
) {
1283 error("Value setting was expected");
1284 setting
->set_valuetype(Value::V_ERROR
);
1286 FieldSpec_V_FT
*fs
=dynamic_cast<FieldSpec_V_FT
*>(p_fspec
);
1287 Type
*type
=fs
->get_type();
1288 setting
->set_my_governor(type
);
1289 type
->chk_this_value_ref(setting
);
1291 type
->chk_this_value(setting
, 0, Type::EXPECTED_CONSTANT
,
1292 INCOMPLETE_NOT_ALLOWED
, OMIT_NOT_ALLOWED
, SUB_CHK
);
1294 ReferenceChain
refch(setting
, "While checking embedded recursions");
1295 setting
->chk_recursions(refch
);
1297 if (!semantic_check_only
) {
1298 setting
->set_genname_prefix("const_");
1299 setting
->set_genname_recursive(setting
->get_genname_own());
1300 setting
->set_code_section(GovernedSimple::CS_PRE_INIT
);
1304 void FieldSetting_Value::generate_code(output_struct
*target
)
1307 Code::init_cdef(&cdef
);
1308 Type
*type
= setting
->get_my_governor();
1309 type
->generate_code_object(&cdef
, setting
);
1310 cdef
.init
= setting
->generate_code_init(cdef
.init
,
1311 setting
->get_lhs_name().c_str());
1312 Code::merge_cdef(target
, &cdef
);
1313 Code::free_cdef(&cdef
);
1316 void FieldSetting_Value::dump(unsigned level
) const
1318 DEBUG(level
, "field setting (value): %s", name
->get_dispname().c_str());
1320 setting
->dump(level
);
1323 // =================================
1324 // ===== FieldSetting_O
1325 // =================================
1327 FieldSetting_O::FieldSetting_O(Identifier
*p_name
, Object
*p_setting
)
1328 : FieldSetting(p_name
), setting(p_setting
)
1332 ("NULL parameter: Asn::FieldSetting_O::FieldSetting_O()");
1335 FieldSetting_O::FieldSetting_O(const FieldSetting_O
& p
)
1338 setting
=p
.setting
->clone();
1341 FieldSetting_O::~FieldSetting_O()
1346 void FieldSetting_O::chk(FieldSpec
*p_fspec
)
1349 if(p_fspec
->get_fstype()!=FieldSpec::FS_O
) {
1350 error("Object setting was expected");
1352 setting
=new Obj_defn();
1354 FieldSpec_O
*fs
=dynamic_cast<FieldSpec_O
*>(p_fspec
);
1355 ObjectClass
*oc
=fs
->get_oc();
1356 setting
->set_my_governor(oc
);
1361 void FieldSetting_O::generate_code(output_struct
*target
)
1363 setting
->generate_code(target
);
1366 void FieldSetting_O::dump(unsigned level
) const
1368 DEBUG(level
, "field setting (object): %s", name
->get_dispname().c_str());
1370 setting
->dump(level
);
1373 // =================================
1374 // ===== FieldSetting_OS
1375 // =================================
1377 FieldSetting_OS::FieldSetting_OS(Identifier
*p_name
, ObjectSet
*p_setting
)
1378 : FieldSetting(p_name
), setting(p_setting
)
1382 ("NULL parameter: Asn::FieldSetting_OS::FieldSetting_OS()");
1385 FieldSetting_OS::FieldSetting_OS(const FieldSetting_OS
& p
)
1388 setting
=p
.setting
->clone();
1391 FieldSetting_OS::~FieldSetting_OS()
1396 void FieldSetting_OS::chk(FieldSpec
*p_fspec
)
1399 if(p_fspec
->get_fstype()!=FieldSpec::FS_OS
) {
1400 error("ObjectSet setting was expected");
1402 setting
=new OS_defn();
1404 FieldSpec_OS
*fs
=dynamic_cast<FieldSpec_OS
*>(p_fspec
);
1405 ObjectClass
*oc
=fs
->get_oc();
1406 setting
->set_my_governor(oc
);
1411 void FieldSetting_OS::generate_code(output_struct
*target
)
1413 setting
->generate_code(target
);
1416 void FieldSetting_OS::dump(unsigned level
) const
1418 DEBUG(level
, "field setting (objectset): %s",
1419 name
->get_dispname().c_str());
1421 setting
->dump(level
);
1424 // =================================
1426 // =================================
1428 Obj_defn::Obj_defn(Block
*p_block
)
1429 : Object(), block(p_block
), is_generated(false)
1432 FATAL_ERROR("NULL parameter: Asn::Obj_defn::Obj_defn()");
1435 Obj_defn::Obj_defn()
1436 : Object(), block(0), is_generated(false)
1441 Obj_defn::Obj_defn(const Obj_defn
& p
)
1442 : Object(p
), is_generated(false)
1444 block
=p
.block
?p
.block
->clone():0;
1445 for(size_t i
=0; i
<p
.fss
.size(); i
++)
1446 add_fs(p
.fss
.get_nth_elem(i
)->clone());
1449 Obj_defn::~Obj_defn()
1452 for(size_t i
=0; i
<fss
.size(); i
++)
1453 delete fss
.get_nth_elem(i
);
1457 void Obj_defn::set_fullname(const string
& p_fullname
)
1459 Object::set_fullname(p_fullname
);
1460 for(size_t i
=0; i
<fss
.size(); i
++) {
1461 FieldSetting
*fs
=fss
.get_nth_elem(i
);
1462 fs
->set_fullname(p_fullname
+"."+fs
->get_name().get_dispname());
1466 void Obj_defn::set_my_scope(Scope
*p_scope
)
1468 Object::set_my_scope(p_scope
);
1469 for(size_t i
=0; i
<fss
.size(); i
++)
1470 fss
.get_nth_elem(i
)->set_my_scope(p_scope
);
1473 void Obj_defn::chk()
1476 if(block
) parse_block();
1478 FATAL_ERROR("Asn::Obj_defn::chk()");
1479 my_governor
->chk_this_obj(this);
1483 void Obj_defn::add_fs(FieldSetting
*p_fs
)
1486 FATAL_ERROR("NULL parameter: Asn::Obj_defn::add_fs()");
1487 if(fss
.has_key(p_fs
->get_name().get_name())) {
1488 error("This object already has a field setting with name `%s'",
1489 p_fs
->get_name().get_dispname().c_str());
1493 fss
.add(p_fs
->get_name().get_name(), p_fs
);
1494 p_fs
->set_my_scope(my_scope
);
1495 p_fs
->set_fullname(get_fullname()+"."+p_fs
->get_name().get_dispname());
1498 bool Obj_defn::has_fs_withName(const Identifier
& p_name
)
1500 if(block
) parse_block();
1501 return fss
.has_key(p_name
.get_name());
1504 FieldSetting
* Obj_defn::get_fs_byName(const Identifier
& p_name
)
1506 if(block
) parse_block();
1507 const string
& s
=p_name
.get_name();
1511 error("No field setting with identifier `%s' in object `%s'",
1512 p_name
.get_dispname().c_str(), get_fullname().c_str());
1516 bool Obj_defn::has_fs_withName_dflt(const Identifier
& p_name
)
1519 if(is_erroneous
) return true;
1520 if(fss
.has_key(p_name
.get_name())) return true;
1521 if(my_governor
->get_fss()->has_fs_withId(p_name
)
1522 && my_governor
->get_fss()->get_fs_byId(p_name
)->has_default())
1527 Setting
* Obj_defn::get_setting_byName_dflt(const Identifier
& p_name
)
1530 const string
& s
=p_name
.get_name();
1532 return fss
[s
]->get_setting();
1533 if(my_governor
->get_fss()->has_fs_withId(p_name
)) {
1534 FieldSpec
*fs
=my_governor
->get_fss()->get_fs_byId(p_name
);
1535 if(fs
->has_default())
1536 return fs
->get_default();
1539 error("No field setting or default with identifier `%s' in object `%s'",
1540 p_name
.get_dispname().c_str(), get_fullname().c_str());
1544 void Obj_defn::parse_block()
1548 FATAL_ERROR("Asn::Obj_defn::parse_block():"
1549 " my_governor not set");
1550 OCSV_Parser
*ocsv_parser
=new OCSV_Parser(block
->get_TokenBuf(), this);
1551 my_governor
->get_ocs()->accept(*ocsv_parser
);
1553 delete block
; block
=0;
1556 void Obj_defn::generate_code(output_struct
*target
)
1558 if(is_generated
) return;
1560 for(size_t i
=0; i
<fss
.size(); i
++)
1561 fss
.get_nth_elem(i
)->generate_code(target
);
1564 void Obj_defn::dump(unsigned level
) const
1566 DEBUG(level
, "Object definition");
1568 DEBUG(level
, "with unparsed block");
1570 DEBUG(level
, "with field settings:");
1572 for(size_t i
=0; i
<fss
.size(); i
++)
1573 fss
.get_nth_elem(i
)->dump(level
);
1577 // =================================
1579 // =================================
1581 Obj_refd::Obj_refd(Reference
*p_ref
)
1582 : Object(), ref(p_ref
), o_error(0), o_refd(0), o_defn(0)
1585 FATAL_ERROR("NULL parameter: Asn::Obj_refd::Obj_refd()");
1588 Obj_refd::Obj_refd(const Obj_refd
& p
)
1589 : Object(p
), o_error(0), o_refd(0), o_defn(0)
1594 Obj_refd::~Obj_refd()
1600 void Obj_refd::set_my_scope(Scope
*p_scope
)
1602 Object::set_my_scope(p_scope
);
1603 ref
->set_my_scope(p_scope
);
1606 void Obj_refd::set_fullname(const string
& p_fullname
)
1608 Object::set_fullname(p_fullname
);
1609 ref
->set_fullname(p_fullname
);
1612 Obj_defn
* Obj_refd::get_refd_last(ReferenceChain
*refch
)
1615 bool destroy_refch
=false;
1617 refch
=new ReferenceChain(ref
, "While searching referenced Object");
1620 o_defn
=get_refd(refch
)->get_refd_last(refch
);
1621 if(destroy_refch
) delete refch
;
1626 Object
* Obj_refd::get_refd(ReferenceChain
*refch
)
1628 if(refch
&& !refch
->add(get_fullname())) goto error
;
1630 Common::Assignment
*ass
=ref
->get_refd_assignment();
1631 if(!ass
) goto error
;
1632 Setting
*setting
=ref
->get_refd_setting();
1633 if (!setting
|| setting
->get_st()==Setting::S_ERROR
) goto error
;
1634 o_refd
=dynamic_cast<Object
*>(setting
);
1636 error("This is not an objectreference: `%s'",
1637 ref
->get_dispname().c_str());
1643 o_error
=new Obj_defn();
1644 o_error
->set_my_governor(my_governor
);
1650 void Obj_refd::chk()
1655 FATAL_ERROR("Asn::Obj_refd::chk()");
1656 if(get_refd_last()->get_my_governor()->get_refd_last()
1657 !=my_governor
->get_refd_last()) {
1658 error("ObjectClass mismatch: Object of class `%s' was expected"
1660 my_governor
->get_refd_last()->get_fullname().c_str(),
1661 get_refd_last()->get_my_governor()->get_refd_last()
1662 ->get_fullname().c_str());
1663 o_error
=new Obj_defn();
1664 o_error
->set_is_erroneous();
1665 o_error
->set_my_governor(my_governor
);
1670 void Obj_refd::generate_code(output_struct
*target
)
1672 Obj_defn
*refd_last
= get_refd_last();
1673 if (my_scope
->get_scope_mod_gen() ==
1674 refd_last
->get_my_scope()->get_scope_mod_gen())
1675 refd_last
->generate_code(target
);
1678 void Obj_refd::dump(unsigned level
) const
1680 DEBUG(level
, "objectreference");
1685 // =================================
1686 // ===== OSE_Visitor
1687 // =================================
1689 OSE_Visitor
*OSE_Visitor::clone() const
1691 FATAL_ERROR("Asn::OSE_Visitor::clone()");
1695 // =================================
1697 // =================================
1699 void ObjectSet::set_my_governor(ObjectClass
*p_gov
)
1702 FATAL_ERROR("NULL parameter: Asn::ObjectSet::set_my_governor()");
1706 // =================================
1708 // =================================
1710 Objects::Objects(const Objects
& p
)
1713 objs
.replace(0, 0, &p
.objs
);
1721 void Objects::add_objs(Objects
*p_objs
)
1724 FATAL_ERROR("NULL parameter: Asn::Objects::add_objs()");
1725 objs
.replace(objs
.size(), 0, &p_objs
->objs
);
1728 void Objects::dump(unsigned level
) const
1730 for(size_t i
=0; i
<objs
.size(); i
++)
1731 objs
[i
]->dump(level
);
1734 // =================================
1735 // ===== OSEV_objcollctr
1736 // =================================
1738 OSEV_objcollctr::OSEV_objcollctr(ObjectSet
& parent
)
1741 governor
=parent
.get_my_governor()->get_refd_last();
1744 visdes
.add(parent
.get_refd_last(), 0);
1747 OSEV_objcollctr::OSEV_objcollctr(const Location
*p_loc
,
1748 ObjectClass
*p_governor
)
1749 : OSE_Visitor(p_loc
)
1752 FATAL_ERROR("Asn::OSEV_objcollctr::OSEV_objcollctr()");
1753 governor
=p_governor
->get_refd_last();
1757 OSEV_objcollctr::~OSEV_objcollctr()
1763 void OSEV_objcollctr::visit_Object(Object
& p
)
1765 Obj_defn
*o
= p
.get_refd_last();
1766 if(o
->get_is_erroneous()) return;
1767 if(visdes
.has_key(o
)) return;
1768 if(o
->get_my_governor()->get_refd_last()!=governor
) {
1769 loc
->error("Objects of objectclass `%s' are expected; "
1770 "`%s' is object of class `%s'",
1771 governor
->get_fullname().c_str(),
1772 p
.get_fullname().c_str(),
1773 p
.get_my_governor()->get_refd_last()->get_fullname().c_str());
1780 void OSEV_objcollctr::visit_OS_refd(OS_refd
& p
)
1785 void OSEV_objcollctr::visit_ObjectSet(ObjectSet
& p
, bool force
)
1787 OS_defn
& os
=*p
.get_refd_last();
1788 if(os
.get_my_governor()->get_refd_last()!=governor
) {
1789 loc
->error("Objects of objectclass `%s' are expected; "
1790 "`%s' is objectset of class `%s'",
1791 governor
->get_fullname().c_str(),
1792 p
.get_fullname().c_str(),
1793 os
.get_my_governor()->get_refd_last()->get_fullname().c_str());
1796 if(visdes
.has_key(&os
)) {
1799 else visdes
.add(&os
, 0);
1800 Objects
*other_objs
=os
.get_objs();
1801 for(size_t i
=0; i
<other_objs
->get_nof_objs(); i
++)
1802 visit_Object(*other_objs
->get_obj_byIndex(i
));
1805 Objects
* OSEV_objcollctr::give_objs()
1807 Objects
*tmp_objs
=objs
;
1812 // =================================
1813 // ===== OSEV_checker
1814 // =================================
1816 OSEV_checker::OSEV_checker(const Location
*p_loc
, ObjectClass
*p_governor
)
1817 : OSE_Visitor(p_loc
), governor(p_governor
)
1820 FATAL_ERROR("NULL parameter: Asn::OSEV_checker::OSEV_checker()");
1821 gov_defn
=p_governor
->get_refd_last();
1824 void OSEV_checker::visit_Object(Object
& p
)
1826 p
.set_my_governor(governor
);
1830 void OSEV_checker::visit_OS_refd(OS_refd
& p
)
1832 p
.set_my_governor(governor
);
1836 // =================================
1837 // ===== OSEV_codegen
1838 // =================================
1840 void OSEV_codegen::visit_Object(Object
& p
)
1842 p
.generate_code(target
);
1845 void OSEV_codegen::visit_OS_refd(OS_refd
& p
)
1847 p
.generate_code(target
);
1850 // =================================
1852 // =================================
1855 : ObjectSet(), block(0), objs(0), is_generated(false)
1857 oses
=new vector
<OS_Element
>();
1860 OS_defn::OS_defn(Block
*p_block
)
1861 : ObjectSet(), block(p_block
), objs(0), is_generated(false)
1864 FATAL_ERROR("NULL parameter: Asn::OS_defn::OS_defn()");
1865 oses
=new vector
<OS_Element
>();
1868 OS_defn::OS_defn(Objects
*p_objs
)
1869 : ObjectSet(), block(0), objs(p_objs
), is_generated(false)
1872 FATAL_ERROR("NULL parameter: Asn::OS_defn::OS_defn()");
1873 oses
=new vector
<OS_Element
>();
1876 OS_defn::OS_defn(const OS_defn
& p
)
1877 : ObjectSet(p
), objs(0), is_generated(false)
1879 block
=p
.block
?p
.block
->clone():0;
1880 oses
=new vector
<OS_Element
>();
1881 for(size_t i
=0; i
<p
.oses
->size(); i
++)
1882 oses
->add((*p
.oses
)[i
]->clone_ose());
1889 for(size_t i
=0; i
<oses
->size(); i
++)
1895 void OS_defn::steal_oses(OS_defn
*other_os
)
1897 if(!oses
|| objs
|| !other_os
|| !other_os
->oses
|| other_os
->objs
)
1898 FATAL_ERROR("Asn::OS_defn::steal_oses()");
1899 oses
->replace(oses
->size(), 0, other_os
->oses
);
1900 other_os
->oses
->clear();
1904 OS_defn
* OS_defn::get_refd_last(ReferenceChain
*refch
)
1906 if(oses
->size()!=1) return this;
1907 OS_refd
* ref
=dynamic_cast<OS_refd
*>((*oses
)[0]);
1908 if(!ref
) return this;
1910 bool destroy_refch
=false;
1912 refch
=new ReferenceChain
1913 (this, "While searching quasi-referenced ObjectSet");
1916 refch
->add(get_fullname());
1917 reflast
=ref
->get_refd_last(refch
);
1918 if(destroy_refch
) delete refch
;
1922 void OS_defn::set_fullname(const string
& p_fullname
)
1924 ObjectSet::set_fullname(p_fullname
);
1925 for(size_t i
=0; i
<oses
->size(); i
++)
1926 (*oses
)[i
]->set_fullname_ose(p_fullname
+"."+Int2string(i
+1));
1929 void OS_defn::set_my_scope(Scope
*p_scope
)
1931 ObjectSet::set_my_scope(p_scope
);
1932 for(size_t i
=0; i
<oses
->size(); i
++)
1933 (*oses
)[i
]->set_my_scope_ose(p_scope
);
1936 void OS_defn::add_ose(OS_Element
*p_ose
)
1939 FATAL_ERROR("NULL parameter: Asn::OS_defn::add_ose");
1943 size_t OS_defn::get_nof_objs()
1945 if(!objs
) create_objs();
1946 return objs
->get_nof_objs();
1949 Object
* OS_defn::get_obj_byIndex(size_t p_i
)
1951 if(!objs
) create_objs();
1952 return objs
->get_obj_byIndex(p_i
);
1955 Objects
* OS_defn::get_objs()
1957 if(!objs
) create_objs();
1961 void OS_defn::parse_block()
1964 Node
*node
=block
->parse(KW_Block_ObjectSetSpec
);
1965 OS_defn
*tmp
=dynamic_cast<OS_defn
*>(node
);
1968 delete block
; block
=0;
1971 tmp
->oses
=new vector
<OS_Element
>();
1974 delete block
; block
=0;
1976 oses
= new vector
<OS_Element
>();
1978 set_fullname(get_fullname());
1979 set_my_scope(get_my_scope());
1985 if(block
) parse_block();
1987 FATAL_ERROR("Asn::OS_defn::chk()");
1988 Error_Context
cntxt(this, "In objectset definition `%s'",
1989 get_fullname().c_str());
1990 OSEV_checker
osev(this, my_governor
);
1991 for(size_t i
=0; i
<oses
->size(); i
++) {
1992 OS_Element
*ose
=(*oses
)[i
];
1993 ose
->set_genname_ose(get_genname_own(), Int2string(i
+ 1));
2000 void OS_defn::create_objs()
2004 FATAL_ERROR("Asn::OS_defn::create_objs()");
2006 Error_Context
cntxt(this, "While exploring objectset definition `%s'",
2007 get_fullname().c_str());
2008 OSEV_objcollctr
osev(*this);
2009 for(size_t i
=0; i
<oses
->size(); i
++)
2010 (*oses
)[i
]->accept(osev
);
2011 objs
=osev
.give_objs();
2014 void OS_defn::generate_code(output_struct
*target
)
2016 if (is_generated
) return;
2017 is_generated
= true;
2018 OSEV_codegen
osev(this, target
);
2019 for(size_t i
=0; i
<oses
->size(); i
++)
2020 (*oses
)[i
]->accept(osev
);
2023 void OS_defn::dump(unsigned level
) const
2025 DEBUG(level
, "ObjectSet definition");
2026 if(block
) DEBUG(level
, "with unparsed block");
2028 DEBUG(level
, "with collected objects (%lu pcs)",
2029 (unsigned long) objs
->get_nof_objs());
2030 objs
->dump(level
+1);
2032 else DEBUG(level
, "with uncollected objects");
2035 // =================================
2037 // =================================
2039 OS_refd::OS_refd(Reference
*p_ref
)
2040 : ObjectSet(), OS_Element(), ref(p_ref
), os_error(0),
2041 os_refd(0), os_defn(0)
2044 FATAL_ERROR("NULL parameter: Asn::OS_refd::OS_refd()");
2047 OS_refd::OS_refd(const OS_refd
& p
)
2048 : ObjectSet(p
), OS_Element(p
), os_error(0), os_refd(0), os_defn(0)
2053 string
OS_refd::create_stringRepr()
2055 return get_refd_last()->get_stringRepr();
2064 void OS_refd::set_my_scope(Scope
*p_scope
)
2066 ObjectSet::set_my_scope(p_scope
);
2067 ref
->set_my_scope(p_scope
);
2070 ObjectSet
* OS_refd::get_refd(ReferenceChain
*refch
)
2072 if(refch
) refch
->add(get_fullname());
2075 Common::Assignment
*ass
=ref
->get_refd_assignment();
2076 if(!ass
) goto error
;
2077 setting
=ref
->get_refd_setting();
2078 if(setting
->get_st()==Setting::S_ERROR
) goto error
;
2079 os_refd
=dynamic_cast<ObjectSet
*>(setting
);
2081 error("This is not an objectsetreference: `%s'",
2082 ref
->get_dispname().c_str());
2087 /* create an empty ObjectSet */
2088 os_error
=new OS_defn();
2089 os_error
->set_my_governor(my_governor
);
2096 OS_defn
* OS_refd::get_refd_last(ReferenceChain
*refch
)
2099 bool destroy_refch
=false;
2101 refch
=new ReferenceChain(ref
, "While searching referenced ObjectSet");
2104 ObjectSet
*t_os
= get_refd(refch
);
2105 os_defn
= t_os
->get_refd_last(refch
);
2106 if(destroy_refch
) delete refch
;
2111 size_t OS_refd::get_nof_objs()
2113 return get_refd_last()->get_nof_objs();
2116 Object
* OS_refd::get_obj_byIndex(size_t p_i
)
2118 return get_refd_last()->get_obj_byIndex(p_i
);
2126 FATAL_ERROR("Asn::OS_refd::chk()");
2127 ObjectClass
*my_class
= my_governor
->get_refd_last();
2128 ObjectClass
*refd_class
=
2129 get_refd_last()->get_my_governor()->get_refd_last();
2130 if (my_class
!= refd_class
) {
2131 error("ObjectClass mismatch: ObjectSet of class `%s' was expected "
2132 "instead of `%s'", my_class
->get_fullname().c_str(),
2133 refd_class
->get_fullname().c_str());
2134 os_error
=new OS_defn();
2135 os_error
->set_my_governor(my_governor
);
2140 void OS_refd::generate_code(output_struct
*target
)
2142 OS_defn
*refd_last
= get_refd_last();
2143 if(my_scope
->get_scope_mod_gen() ==
2144 refd_last
->get_my_scope()->get_scope_mod_gen())
2145 refd_last
->generate_code(target
);
2148 void OS_refd::dump(unsigned level
) const
2150 DEBUG(level
, "objectsetreference");
2155 OS_Element
*OS_refd::clone_ose() const
2160 void OS_refd::set_fullname_ose(const string
& p_fullname
)
2162 set_fullname(p_fullname
);
2165 void OS_refd::set_genname_ose(const string
& p_prefix
, const string
& p_suffix
)
2167 set_genname(p_prefix
, p_suffix
);
2170 void OS_refd::set_my_scope_ose(Scope
*p_scope
)
2172 set_my_scope(p_scope
);
This page took 0.13319 seconds and 5 git commands to generate.