d286ad3051c030ccdbfbb543942eaeafddf8b79e
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 ///////////////////////////////////////////////////////////////////////////////
9 #include "../Identifier.hh"
10 #include "../CompilerError.hh"
12 #include "TokenBuf.hh" // Ass_pard needs that
13 #include "../Value.hh"
16 #include "../CodeGenHelper.hh"
17 #include "../../common/JSON_Tokenizer.hh"
19 /* defined in asn1p.y */
20 extern int asn1_parse_string(const char* p_str
);
22 extern Common::Modules
*modules
; // in main.cc
26 Module
*Assignments::_spec_asss
=0;
27 Assignments
*parsed_assignments
;
29 // =================================
31 // =================================
34 for (size_t i
= 0; i
< syms_v
.size(); i
++) delete syms_v
[i
];
39 Symbols
* Symbols::clone() const
41 FATAL_ERROR("Asn::Symbols::clone()");
45 void Symbols::add_sym(Identifier
*p_id
)
48 FATAL_ERROR("NULL parameter: Asn::Symbols::add_sym()");
52 void Symbols::chk_uniq(const Location
& p_loc
)
54 for(size_t i
=0; i
<syms_v
.size(); i
++) {
55 Identifier
*id
= syms_v
[i
];
56 const string
& name
= id
->get_name();
57 if (syms_m
.has_key(name
)) {
58 p_loc
.error("Duplicate identifier in SymbolList: `%s'",
59 id
->get_dispname().c_str());
60 } else syms_m
.add(name
, id
);
64 // =================================
66 // =================================
68 Exports::Exports(bool p_expall
)
69 : Node(), Location(), checked(false), my_mod(0), expall(p_expall
),
70 symbols(expall
? 0 : new Symbols())
73 Exports::Exports(Symbols
*p_symlist
)
74 : Node(), Location(), checked(false), my_mod(0), expall(false),
75 symbols(p_symlist
? p_symlist
: new Symbols())
83 Exports
* Exports::clone() const
85 FATAL_ERROR("Asn::Exports::clone()");
89 bool Exports::exports_sym(const Identifier
& p_id
)
91 if(!checked
) chk_exp();
92 if (expall
) return true;
93 else return symbols
->syms_m
.has_key(p_id
.get_name());
96 void Exports::chk_exp()
100 Ref_defd_simple
*ref
=0;
101 Error_Context
cntxt(this, "In EXPORTS of module `%s'",
102 my_mod
->get_modid().get_dispname().c_str());
103 symbols
->chk_uniq(*this);
104 for(size_t i
=0; i
<symbols
->syms_m
.size(); i
++) {
105 ref
=new Ref_defd_simple(0, symbols
->syms_m
.get_nth_elem(i
)->clone());
106 /* check whether exists or not */
107 my_mod
->get_ass_bySRef(ref
);
113 // =================================
115 // =================================
117 ImpMod::ImpMod(Identifier
*p_modid
, Symbols
*p_symlist
)
118 : Node(), Location(), my_mod(0), modid(p_modid
), mod(0)
121 FATAL_ERROR("NULL parameter: Asn::ImpMod::ImpMod()");
122 set_fullname("<imports>."+modid
->get_dispname());
123 symbols
= p_symlist
? p_symlist
: new Symbols();
132 ImpMod
* ImpMod::clone() const
134 FATAL_ERROR("Asn::ImpMod::clone()");
138 bool ImpMod::has_sym(const Identifier
& p_id
) const
140 return symbols
->syms_m
.has_key(p_id
.get_name());
143 void ImpMod::chk_imp(ReferenceChain
& refch
)
146 FATAL_ERROR("Asn::ImpMod::chk_imp(): my_mod is NULL");
147 Common::Module
*m
=modules
->get_mod_byId(*modid
);
148 symbols
->chk_uniq(*this);
149 vector
<Common::Module
> modules
;
150 m
->chk_imp(refch
, modules
);
152 if(m
->get_gen_code()) my_mod
->set_gen_code();
153 for(size_t i
=0; i
<symbols
->syms_m
.size(); i
++) {
154 const Identifier
*id
=symbols
->syms_m
.get_nth_elem(i
);
155 Ref_defd_simple
ref(0, new Identifier(*id
));
156 ref
.set_location(*this);
158 if(!m
->get_ass_bySRef(&ref
)) err
=true;
159 if(!err
&& !m
->exports_sym(*id
)) {
160 error("Symbol `%s' is not exported from module `%s'",
161 id
->get_dispname().c_str(),
162 m
->get_modid().get_dispname().c_str());
163 /* to avoid more error messages do not set err to true */
167 symbols
->syms_m
.erase(symbols
->syms_m
.get_nth_key(i
));
168 // do not delete id; it is stored in the vector
174 void ImpMod::generate_code(output_struct
*target
)
176 const char *module_name
= modid
->get_name().c_str();
178 target
->header
.includes
= mputprintf(target
->header
.includes
,
179 "#include \"%s.hh\"\n",
180 duplicate_underscores
? module_name
: modid
->get_ttcnname().c_str());
182 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
183 "%s%s.pre_init_module();\n", module_name
,
187 // =================================
189 // =================================
193 for(size_t i
=0; i
<impmods_v
.size(); i
++)
201 Imports
* Imports::clone() const
203 FATAL_ERROR("Asn::Imports::clone()");
207 void Imports::add_impmod(ImpMod
*p_impmod
)
210 FATAL_ERROR("NULL parameter: Asn::Imports::add_impmod(): my_mod is NULL");
211 impmods_v
.add(p_impmod
);
212 p_impmod
->set_my_mod(my_mod
);
215 void Imports::set_my_mod(Module
*p_mod
)
218 for(size_t i
=0; i
<impmods_v
.size(); i
++)
219 impmods_v
[i
]->set_my_mod(my_mod
);
222 void Imports::chk_imp(ReferenceChain
& refch
)
226 if (impmods_v
.size() <= 0) return;
228 if (!my_mod
) FATAL_ERROR("Asn::Imports::chk_imp()");
230 for (size_t n
= 0; n
< impmods_v
.size(); n
++) {
231 ImpMod
*im
= impmods_v
[n
];
232 const Identifier
& im_id
= im
->get_modid();
233 Error_Context
cntxt(this, "In IMPORTS FROM `%s'",
234 im_id
.get_dispname().c_str());
235 if (!modules
->has_mod_withId(im_id
)) {
236 im
->error("There is no module with identifier `%s'",
237 im_id
.get_dispname().c_str());
240 Common::Module
*m
= modules
->get_mod_byId(im_id
);
242 if (m
->get_moduletype() != Module::MOD_ASN
) {
243 im
->error("An ASN.1 module cannot import from a TTCN-3 module");
246 else if (m
== my_mod
) {
247 im
->error("A module cannot import from itself");
250 // check the imports recursively
254 // detect circular imports
255 if (!is_circular
&& m
->is_visible(my_mod
)) is_circular
= true;
256 const string
& im_name
= im_id
.get_name();
257 if (impmods
.has_key(im_name
)) {
258 const char *dispname_str
= im_id
.get_dispname().c_str();
259 im
->error("Duplicate import from module `%s'", dispname_str
);
260 impmods
[im_name
]->note("Previous import from `%s' is here",
262 } else impmods
.add(im_name
, im
);
263 Symbols
*syms
= im
->symbols
;
264 for (size_t i
=0; i
<syms
->syms_m
.size(); i
++) {
265 const Identifier
*id
= syms
->syms_m
.get_nth_elem(i
);
266 const string
& key
= id
->get_name();
267 if(impsyms_1
.has_key(key
)) {
268 if(impsyms_1
[key
]!=m
) {
269 impsyms_1
.erase(key
);
270 impsyms_m
.add(key
, 0);
273 else if(!impsyms_m
.has_key(key
)) {
274 impsyms_1
.add(key
, m
);
280 bool Imports::has_impsym_withId(const Identifier
& p_id
) const
282 if (!checked
) FATAL_ERROR("Imports::has_impsym_withId()");
283 const string
& name
= p_id
.get_name();
284 return impsyms_1
.has_key(name
) || impsyms_m
.has_key(name
);
287 void Imports::get_imported_mods(Module::module_set_t
& p_imported_mods
)
289 for (size_t i
= 0; i
< impmods_v
.size(); i
++) {
290 Common::Module
*m
= impmods_v
[i
]->get_mod();
292 if (!p_imported_mods
.has_key(m
)) {
293 p_imported_mods
.add(m
, 0);
294 m
->get_visible_mods(p_imported_mods
);
299 void Imports::generate_code(output_struct
*target
)
301 bool base_lib_needed
= true;
302 for (size_t i
= 0; i
< impmods_v
.size(); i
++) {
303 ImpMod
*im
= impmods_v
[i
];
304 Common::Module
*m
= im
->get_mod();
305 // do not include the header file of the base library if a real
306 // (not circular) imported module is found
307 if (base_lib_needed
&& !m
->is_visible(my_mod
)) base_lib_needed
= false;
308 // inclusion of m's header file can be eliminated if we find another
309 // imported module that imports m
310 bool covered
= false;
311 for (size_t j
= 0; j
< impmods_v
.size(); j
++) {
312 // skip over the same import definition
313 if (j
== i
) continue;
314 Common::Module
*m2
= impmods_v
[j
]->get_mod();
315 // a module that is equivalent to the current module due to
316 // circular imports cannot be used to cover anything
317 if (m2
->is_visible(my_mod
)) continue;
318 if (m2
->is_visible(m
) && !m
->is_visible(m2
)) {
319 // m2 covers m (i.e. m is visible from m2)
320 // and they are not in the same import loop
325 // do not generate the #include if a covering module is found
326 if (!covered
) im
->generate_code(target
);
328 if (base_lib_needed
) {
329 // if no real import was found the base library definitions has to be
331 target
->header
.includes
= mputstr(target
->header
.includes
,
332 "#include <TTCN3.hh>\n");
336 // =================================
338 // =================================
340 Module::Module(Identifier
*p_modid
, TagDefault::tagdef_t p_tagdef
,
341 bool p_extens_impl
, Exports
*p_exp
, Imports
*p_imp
,
343 : Common::Module(MOD_ASN
, p_modid
), tagdef(p_tagdef
),
344 extens_impl(p_extens_impl
), exp(p_exp
), imp(p_imp
), asss(p_asss
)
346 if (!p_exp
|| !p_imp
|| !p_asss
)
347 FATAL_ERROR("NULL parameter: Asn::Module::Module()");
348 if(!p_modid
->isvalid_asn_modref()
349 && p_modid
->get_dispname()!="<internal>")
350 error("`%s' is not a valid module identifier",
351 p_modid
->get_dispname().c_str());
352 asss
->set_parent_scope(this);
353 exp
->set_my_mod(this);
354 imp
->set_my_mod(this);
364 Module
*Module::clone() const
366 FATAL_ERROR("Asn::Module::clone");
370 Common::Assignment
*Module::importAssignment(
371 const Identifier
& p_source_modid
, const Identifier
& p_id
) const
373 (void)p_source_modid
;
374 if (asss
->has_local_ass_withId(p_id
)) {
375 return asss
->get_local_ass_byId(p_id
);
379 void Module::set_fullname(const string
& p_fullname
)
381 Common::Module::set_fullname(p_fullname
);
382 exp
->set_fullname(p_fullname
+".<exports>");
383 imp
->set_fullname(p_fullname
+".<imports>");
384 asss
->set_fullname(p_fullname
);
387 Common::Assignments
*Module::get_scope_asss()
392 bool Module::has_imported_ass_withId(const Identifier
& p_id
)
394 return imp
->has_impsym_withId(p_id
);
397 Common::Assignment
* Module::get_ass_bySRef(Ref_simple
*p_ref
)
399 const Identifier
*r_modid
= p_ref
->get_modid();
400 const Identifier
*r_id
= p_ref
->get_id();
402 // return NULL if the reference is erroneous
405 Common::Module
*r_mod
=0;
407 if(!r_modid
|| *r_modid
==*modid
) {
408 if(asss
->has_local_ass_withId(*r_id
))
409 return asss
->get_local_ass_byId(*r_id
);
411 p_ref
->error("There is no assignment with name `%s'"
412 " in module `%s'", r_id
->get_dispname().c_str(),
413 modid
->get_dispname().c_str());
416 if(imp
->impsyms_1
.has_key(r_id
->get_name()))
417 r_mod
=imp
->impsyms_1
[r_id
->get_name()];
418 else if(imp
->impsyms_m
.has_key(r_id
->get_name())) {
419 p_ref
->error("There are more imported symbols with name `%s'"
420 " in module `%s'", r_id
->get_dispname().c_str(),
421 modid
->get_dispname().c_str());
425 p_ref
->error("There is no assignment or imported symbol"
426 " with name `%s' in module `%s'",
427 r_id
->get_dispname().c_str(),
428 modid
->get_dispname().c_str());
433 if(!imp
->has_impmod_withId(*r_modid
)) {
434 p_ref
->error("There is no imported module with name `%s'",
435 r_modid
->get_dispname().c_str());
438 if(!imp
->get_impmod_byId(*r_modid
)->has_sym(*r_id
)) {
439 p_ref
->error("There is no symbol with name `%s'"
440 " imported from module `%s'",
441 r_id
->get_dispname().c_str(),
442 r_modid
->get_dispname().c_str());
445 r_mod
=modules
->get_mod_byId(*r_modid
);
447 Ref_defd_simple
t_ref(0, r_id
->clone());
448 return r_mod
->get_ass_bySRef(&t_ref
);
451 Assignments
*Module::get_asss()
456 bool Module::exports_sym(const Identifier
& p_id
)
458 return exp
->exports_sym(p_id
);
461 void Module::chk_imp(ReferenceChain
& refch
, vector
<Common::Module
>& /*moduleStack*/)
463 if (imp_checked
) return;
464 const string
& module_name
= modid
->get_dispname();
465 if (refch
.exists(module_name
)) {
466 // Do not warning for circular import in ASN.1 module. It is legal
467 // warning("Circular import chain is not recommended: %s",
468 // refch.get_dispstr(module_name).c_str());
471 refch
.add(module_name
);
472 Error_Context backup
;
473 Error_Context
cntxt(this, "In ASN.1 module `%s'", module_name
.c_str());
477 collect_visible_mods();
482 DEBUG(1, "Checking ASN.1 module `%s'", modid
->get_dispname().c_str());
483 Error_Context
cntxt(this, "In ASN.1 module `%s'",
484 modid
->get_dispname().c_str());
490 void Module::get_imported_mods(module_set_t
& p_imported_mods
)
492 imp
->get_imported_mods(p_imported_mods
);
495 bool Module::has_circular_import()
497 return imp
->get_is_circular();
500 void Module::generate_code_internal(CodeGenHelper
& cgh
) {
501 imp
->generate_code(cgh
.get_current_outputstruct());
502 asss
->generate_code(cgh
);
505 void Module::dump(unsigned level
) const
507 DEBUG(level
, "ASN.1 module: %s", modid
->get_dispname().c_str());
508 asss
->dump(level
+ 1);
511 void Module::add_ass(Assignment
*p_ass
)
513 asss
->add_ass(p_ass
);
516 void Module::add_types_to_json_schema(JSON_Tokenizer
& json
)
518 // add a new property for this module
519 json
.put_next_token(JSON_TOKEN_NAME
, modid
->get_dispname().c_str());
521 // add type definitions into an object
522 json
.put_next_token(JSON_TOKEN_OBJECT_START
);
524 // pass the JSON tokenizer onto each type definition
525 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
526 Common::Assignment
* ass
= asss
->get_ass_byIndex(i
);
527 if (Common::Assignment::A_TYPE
== ass
->get_asstype()) {
528 Type
* t
= ass
->get_Type();
529 if (t
->has_encoding(Type::CT_JSON
)) {
530 t
->generate_json_schema(json
, false, false);
535 // end of type definitions
536 json
.put_next_token(JSON_TOKEN_OBJECT_END
);
539 // =================================
541 // =================================
543 Assignments::Assignments(const Assignments
& p
)
544 : Common::Assignments(p
), checked(false)
546 for(size_t i
= 0; i
< p
.asss_v
.size(); i
++)
547 add_ass(p
.asss_v
[i
]->clone());
550 Assignments::~Assignments()
552 for (size_t i
= 0; i
< asss_v
.size(); i
++) delete asss_v
[i
];
557 Assignments
*Assignments::clone() const
559 return new Assignments(*this);
562 void Assignments::set_fullname(const string
& p_fullname
)
564 Common::Assignments::set_fullname(p_fullname
);
565 string
s(p_fullname
);
566 if (s
!= "@") s
+= '.';
567 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
568 Assignment
*ass
= asss_v
[i
];
569 ass
->set_fullname(s
+ass
->get_id().get_dispname());
573 bool Assignments::has_local_ass_withId(const Identifier
& p_id
)
575 if (!checked
) chk_uniq();
576 if (asss_m
.has_key(p_id
.get_name())) return true;
577 Assignments
*spec_asss
= _spec_asss
->get_asss();
578 if (spec_asss
!= this) return spec_asss
->has_ass_withId(p_id
);
582 Assignment
* Assignments::get_local_ass_byId(const Identifier
& p_id
)
584 if (!checked
) chk_uniq();
585 const string
& name
= p_id
.get_name();
586 if (asss_m
.has_key(name
)) return asss_m
[name
];
587 Assignments
*spec_asss
= _spec_asss
->get_asss();
588 if (spec_asss
!= this) return spec_asss
->get_local_ass_byId(p_id
);
592 size_t Assignments::get_nof_asss()
594 if (!checked
) chk_uniq();
595 return asss_m
.size();
598 Common::Assignment
* Assignments::get_ass_byIndex(size_t p_i
)
600 if (!checked
) chk_uniq();
601 return asss_m
.get_nth_elem(p_i
);
604 void Assignments::add_ass(Assignment
*p_ass
)
606 if (!p_ass
) FATAL_ERROR("Asn::Assignments::add_ass()");
608 p_ass
->set_my_scope(this);
610 const Identifier
& id
= p_ass
->get_id();
611 const string
& name
= id
.get_name();
612 if(asss_m
.has_key(name
)) {
613 const char *dispname_str
= id
.get_dispname().c_str();
614 p_ass
->error("Duplicate assignment with identifier `%s'", dispname_str
);
615 asss_m
[name
]->note("Previous assignment with identifier `%s' is here",
617 } else asss_m
.add(name
, p_ass
);
621 void Assignments::chk()
623 for(size_t i
= 0; i
< asss_v
.size(); i
++) asss_v
[i
]->chk();
626 void Assignments::chk_uniq()
630 Assignments
*spec_asss
= _spec_asss
->get_asss();
631 for(size_t i
= 0; i
< asss_v
.size(); i
++) {
632 Assignment
*ass
= asss_v
[i
];
633 const Identifier
& id
= ass
->get_id();
634 const string
& name
= id
.get_name();
635 if (this != spec_asss
&& spec_asss
->has_ass_withId(id
)) {
636 ass
->error("`%s' is a reserved identifier", id
.get_dispname().c_str());
637 } else if (asss_m
.has_key(name
)) {
638 const char *dispname_str
= id
.get_dispname().c_str();
639 ass
->error("Duplicate assignment with identifier `%s'", dispname_str
);
640 asss_m
[name
]->note("Previous assignment with identifier `%s' is here",
642 } else asss_m
.add(name
, ass
);
647 void Assignments::set_right_scope(Scope
*p_scope
)
649 for(size_t i
= 0; i
< asss_v
.size(); i
++)
650 asss_v
[i
]->set_right_scope(p_scope
);
653 void Assignments::create_spec_asss()
656 FATAL_ERROR("Assignments::create_spec_asss(): duplicate initialization");
658 const char *s_asss
= "$#&&&(#TITAN$#&&^#% Assignments\n"
659 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"EXTERNAL\""
660 " ::= [UNIVERSAL 8] IMPLICIT SEQUENCE {\n"
661 " identification CHOICE {\n"
662 " syntaxes SEQUENCE {\n"
663 " abstract OBJECT IDENTIFIER,\n"
664 " transfer OBJECT IDENTIFIER\n"
666 " syntax OBJECT IDENTIFIER,\n"
667 " presentation-context-id INTEGER,\n"
668 " context-negotiation SEQUENCE {\n"
669 " presentation-context-id INTEGER,\n"
670 " transfer-syntax OBJECT IDENTIFIER\n"
672 " transfer-syntax OBJECT IDENTIFIER,\n"
675 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
676 " data-value OCTET STRING\n"
677 "} (WITH COMPONENTS {\n"
679 " identification (WITH COMPONENTS {\n"
681 " syntaxes ABSENT,\n"
682 " transfer-syntax ABSENT,\n"
687 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"EMBEDDED PDV\""
688 " ::= [UNIVERSAL 11] IMPLICIT SEQUENCE {\n"
689 " identification CHOICE {\n"
690 " syntaxes SEQUENCE {\n"
691 " abstract OBJECT IDENTIFIER,\n"
692 " transfer OBJECT IDENTIFIER\n"
694 " syntax OBJECT IDENTIFIER,\n"
695 " presentation-context-id INTEGER,\n"
696 " context-negotiation SEQUENCE {\n"
697 " presentation-context-id INTEGER,\n"
698 " transfer-syntax OBJECT IDENTIFIER\n"
700 " transfer-syntax OBJECT IDENTIFIER,\n"
703 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
704 " data-value OCTET STRING\n"
705 "} (WITH COMPONENTS {\n"
707 " data-value-descriptor ABSENT\n"
710 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"CHARACTER STRING\""
711 " ::= [UNIVERSAL 29] IMPLICIT SEQUENCE {\n"
712 " identification CHOICE {\n"
713 " syntaxes SEQUENCE {\n"
714 " abstract OBJECT IDENTIFIER,\n"
715 " transfer OBJECT IDENTIFIER\n"
717 " syntax OBJECT IDENTIFIER,\n"
718 " presentation-context-id INTEGER,\n"
719 " context-negotiation SEQUENCE {\n"
720 " presentation-context-id INTEGER,\n"
721 " transfer-syntax OBJECT IDENTIFIER\n"
723 " transfer-syntax OBJECT IDENTIFIER,\n"
726 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
727 " string-value OCTET STRING\n"
728 "} (WITH COMPONENTS {\n"
730 " data-value-descriptor ABSENT\n"
733 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"REAL\""
734 " ::= [UNIVERSAL 9] IMPLICIT SEQUENCE {\n"
735 " mantissa INTEGER,\n"
736 " base INTEGER (2|10),\n"
737 " exponent INTEGER\n"
740 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"TYPE-IDENTIFIER\"\n"
743 " &id OBJECT IDENTIFIER UNIQUE,\n"
747 " &Type IDENTIFIED BY &id\n"
750 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"ABSTRACT-SYNTAX\""
752 " &id OBJECT IDENTIFIER UNIQUE,\n"
754 " &property BIT STRING {handles-invalid-encodings(0)} DEFAULT {}\n"
757 " &Type IDENTIFIED BY &id [HAS PROPERTY &property]\n"
761 if(asn1_parse_string(s_asss
) || !parsed_assignments
)
762 FATAL_ERROR("special assignments");
763 _spec_asss
=new Module
764 (new Identifier(Identifier::ID_ASN
, string("<internal>")),
765 TagDefault::AUTOMATIC
, false, new Exports(true), new Imports(),
767 _spec_asss
->set_location("<internal>");
768 _spec_asss
->set_scope_name(_spec_asss
->get_modid().get_dispname());
770 parsed_assignments
->set_fullname(string('@'));
774 // this is used to generate the files which are then
775 // included/copied/edited in core library
776 _spec_asss->set_gen_code();
777 _spec_asss->generate_code();
781 void Assignments::destroy_spec_asss()
784 FATAL_ERROR("Assignments::destroy_spec_asss(): duplicate cleanup");
790 bool Assignments::is_spec_asss(Common::Module
*p_mod
)
792 if (!p_mod
) FATAL_ERROR("Assignments::is_spec_asss()");
793 if (_spec_asss
) return p_mod
== static_cast<Common::Module
*>(_spec_asss
);
797 void Assignments::generate_code(output_struct
* target
)
799 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
800 Assignment
*ass
= asss_v
[i
];
801 if (!top_level_pdu
|| ass
->get_checked()) ass
->generate_code(target
);
805 void Assignments::generate_code(CodeGenHelper
& cgh
) {
806 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
807 Assignment
*ass
= asss_v
[i
];
808 if (!top_level_pdu
|| ass
->get_checked()) ass
->generate_code(cgh
);
812 void Assignments::dump(unsigned level
) const
814 DEBUG(level
, "Assignments (%lu pcs.)", (unsigned long) asss_v
.size());
815 for(size_t i
= 0; i
< asss_v
.size(); i
++) asss_v
[i
]->dump(level
+ 1);
818 // =================================
820 // =================================
822 Ass_pard::Ass_pard(Block
*p_parlist_block
)
823 : Common::Node(), parlist_block(p_parlist_block
)
826 FATAL_ERROR("NULL parameter: Asn::Ass_pard::Ass_pard()");
829 Ass_pard::Ass_pard(const Ass_pard
& p
)
832 parlist_block
=p
.parlist_block
?p
.parlist_block
->clone():0;
833 for(size_t i
=0; i
<p
.dummyrefs
.size(); i
++)
834 dummyrefs
.add(p
.dummyrefs
[i
]->clone());
835 for(size_t i
=0; i
<p
.governors
.size(); i
++)
836 governors
.add(p
.governors
[i
]->clone());
839 Ass_pard::~Ass_pard()
841 delete parlist_block
;
842 for (size_t i
= 0; i
< dummyrefs
.size(); i
++) delete dummyrefs
[i
];
844 for (size_t i
= 0; i
< governors
.size(); i
++) delete governors
[i
];
846 for (size_t i
= 0; i
< inst_cnts
.size(); i
++)
847 delete inst_cnts
.get_nth_elem(i
);
851 void Ass_pard::preparse_pars()
853 if(!parlist_block
) return;
855 (my_ass
, "While checking formal parameters of parameterized"
856 " assignment `%s'", my_ass
->get_fullname().c_str());
857 TokenBuf
*parlist_tb
=parlist_block
->get_TokenBuf();
858 enum state_type
{S_START
, S_GOV
, S_DUMMYREF
, S_COMMA
, S_RDY
, S_ERR
};
860 for(state_type st
=S_START
; st
!=S_RDY
; ) {
863 gov_tb
=new TokenBuf();
864 switch(parlist_tb
->get_at(1)->get_token()) {
874 Token
*token
=parlist_tb
->pop_front_token();
875 switch(token
->get_token()) {
878 token
->error("Syntax error, premature end of parameter"
888 gov_tb
->push_back_token(token
);
892 Token
*token
=parlist_tb
->pop_front_token();
893 switch(token
->get_token()) {
894 case TOK_UpperIdentifier
:
895 case TOK_LowerIdentifier
:
896 dummyrefs
.add(token
->get_semval_id().clone());
897 gov_tb
->push_front_token(token
);
898 gov_tb
->push_back_kw_token(TOK_Assignment
);
899 governors
.add(gov_tb
);
906 token
->error("Syntax error, DummyReference was expected");
910 break;} // S_DUMMYREF
912 Token
*token
=parlist_tb
->pop_front_token();
913 switch(token
->get_token()) {
921 token
->error("Syntax error, `,' was expected");
928 for (size_t i
= 0; i
< dummyrefs
.size(); i
++) delete dummyrefs
[i
];
930 for (size_t i
= 0; i
< governors
.size(); i
++) delete governors
[i
];
936 FATAL_ERROR("Ass_pard::preparse_pars()");
939 delete parlist_block
;
943 size_t Ass_pard::get_nof_pars()
945 if (parlist_block
) preparse_pars();
946 return dummyrefs
.size();
949 const Identifier
& Ass_pard::get_nth_dummyref(size_t i
)
951 if (parlist_block
) preparse_pars();
952 return *(dummyrefs
[i
]);
955 TokenBuf
* Ass_pard::clone_nth_governor(size_t i
)
957 if (parlist_block
) preparse_pars();
958 return governors
[i
]->clone();
961 size_t Ass_pard::new_instnum(Common::Module
*p_mod
)
963 if (!p_mod
) FATAL_ERROR("Ass_pard::new_instnum()");
964 if (inst_cnts
.has_key(p_mod
)) return ++(*inst_cnts
[p_mod
]);
966 inst_cnts
.add(p_mod
, new size_t(1));
971 // =================================
973 // =================================
975 Assignment::Assignment(const Assignment
& p
)
976 : Common::Assignment(p
), dontgen(false)
979 ass_pard
=p
.ass_pard
->clone();
980 ass_pard
->set_my_ass(this);
985 string
Assignment::get_genname() const
988 my_scope
->get_parent_scope() == my_scope
->get_scope_mod()) {
989 // use the simple identifier if the assignment does not have scope
990 // or it is a simple assignment at module scope
991 return id
->get_name();
993 // this assignment belongs to an instantiation of a parameterized
994 // assignment: use the name of the parent scope to obtain genname
995 string
genname_asn("@");
996 genname_asn
+= my_scope
->get_scope_name();
997 const string
& id_dispname
= id
->get_dispname();
998 bool is_parass
= id_dispname
.find('.') == id_dispname
.size();
1000 // the assignment has a normal identifier:
1001 // it represents a formal parameter -> actual parameter binding
1002 // the id (which is the dummy reference) must be used to get a
1005 genname_asn
+= id_dispname
;
1007 // otherwise the assignment represents an instance of the parameterized
1008 // assignment itself: the scope name can be used alone as genname
1009 string
ret_val(Identifier::asn_2_name(genname_asn
));
1010 // in case of parameter assignments a suffix is appended to avoid name
1011 // clash with the embedded settings of the same instantiation
1012 if (is_parass
) ret_val
+= "_par_";
1017 Assignment
* Assignment::new_instance0()
1019 // Classes derived from Assignment must implement new_instance0.
1020 // See Asn::Ass_*::new_instance0
1021 FATAL_ERROR("Asn::Assignment::new_instance0()");
1025 Assignment::Assignment(asstype_t p_asstype
, Identifier
*p_id
,
1026 Ass_pard
*p_ass_pard
)
1027 : Common::Assignment(p_asstype
, p_id
),
1028 ass_pard(p_ass_pard
), dontgen(false)
1030 if(ass_pard
) ass_pard
->set_my_ass(this);
1033 Assignment::~Assignment()
1038 bool Assignment::is_asstype(asstype_t p_asstype
, ReferenceChain
* refch
)
1040 bool destroy_refch
=false;
1042 refch
=new ReferenceChain(this, "While examining kind of assignment");
1044 } else refch
->mark_state();
1045 bool b
=(p_asstype
==asstype
);
1046 if(!refch
->add(get_fullname())) b
=p_asstype
==A_ERROR
;
1047 if(destroy_refch
) delete refch
;
1048 else refch
->prev_state();
1052 Assignment
* Assignment::new_instance(Common::Module
*p_mod
)
1055 error("`%s' is not a parameterized assignment",
1056 get_fullname().c_str());
1059 Assignment
*new_ass
=new_instance0();
1060 delete new_ass
->id
; // it was just a temporary, containing "<error>"
1061 string
new_name(id
->get_asnname());
1063 new_name
+= p_mod
->get_modid().get_asnname();
1064 new_name
+= ".inst";
1065 new_name
+= Int2string(ass_pard
->new_instnum(p_mod
));
1066 new_ass
->id
=new Identifier(Identifier::ID_ASN
, new_name
);
1070 Type
* Assignment::get_Type()
1072 error("`%s' is not a type assignment", get_fullname().c_str());
1076 Value
* Assignment::get_Value()
1078 error("`%s' is not a value assignment", get_fullname().c_str());
1082 ValueSet
* Assignment::get_ValueSet()
1084 error("`%s' is not a valueset assignment", get_fullname().c_str());
1088 ObjectClass
* Assignment::get_ObjectClass()
1090 error("`%s' is not a objectclass assignment", get_fullname().c_str());
1094 Object
* Assignment::get_Object()
1096 error("`%s' is not a object assignment", get_fullname().c_str());
1100 ObjectSet
* Assignment::get_ObjectSet()
1102 error("`%s' is not a objectset assignment", get_fullname().c_str());
1106 void Assignment::chk()
1109 ass_pard
->get_nof_pars();
1113 DEBUG(7, "`%s' assignment not checked.", get_fullname().c_str());
1116 void Assignment::dump(unsigned level
) const
1118 DEBUG(level
, "Assignment(%d): %s%s", get_asstype(),
1119 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1122 // =================================
1124 // =================================
1126 Ass_Undef::Ass_Undef(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1127 Node
*p_left
, Node
*p_right
)
1128 : Assignment(A_UNDEF
, p_id
, p_ass_pard
),
1129 left(p_left
), right(p_right
), right_scope(0), ass(0)
1132 FATAL_ERROR("NULL parameter: Asn::Ass_Undef::Ass_Undef()");
1135 Ass_Undef::Ass_Undef(const Ass_Undef
& p
)
1136 : Assignment(p
), right_scope(0)
1138 left
=p
.left
?p
.left
->clone():0;
1139 right
=p
.right
?p
.right
->clone():0;
1140 ass
=p
.ass
?p
.ass
->clone():0;
1143 Ass_Undef::~Ass_Undef()
1150 Assignment
* Ass_Undef::clone() const
1152 if(ass
) return ass
->clone();
1153 else return new Ass_Undef(*this);
1156 Assignment
* Ass_Undef::new_instance0()
1158 if(ass
) FATAL_ERROR("Asn::Ass_Undef::new_instance0()");
1159 return new Ass_Undef
1160 (new Identifier(Identifier::ID_ASN
, string("<error>")),
1161 0, left
?left
->clone():0, right
->clone());
1164 Assignment::asstype_t
Ass_Undef::get_asstype() const
1166 const_cast<Ass_Undef
*>(this)->classify_ass();
1170 void Ass_Undef::set_fullname(const string
& p_fullname
)
1172 Assignment::set_fullname(p_fullname
);
1173 if (left
) left
->set_fullname(p_fullname
);
1174 if (right
) right
->set_fullname(p_fullname
);
1175 if (ass
) ass
->set_fullname(p_fullname
);
1178 void Ass_Undef::set_my_scope(Scope
*p_scope
)
1180 Assignment::set_my_scope(p_scope
);
1181 if(ass
) ass
->set_my_scope(p_scope
);
1182 right_scope
=p_scope
;
1185 void Ass_Undef::set_right_scope(Scope
*p_scope
)
1187 if(ass
) ass
->set_right_scope(p_scope
);
1188 right_scope
=p_scope
;
1191 bool Ass_Undef::is_asstype(asstype_t p_asstype
, ReferenceChain
* refch
)
1193 classify_ass(refch
);
1194 return asstype
!= A_ERROR
? ass
->is_asstype(p_asstype
, refch
) : false;
1197 bool Ass_Undef::_error_if_pard()
1200 error("`%s' is a parameterized assignment", get_fullname().c_str());
1206 Setting
* Ass_Undef::get_Setting()
1208 if(_error_if_pard()) return 0;
1210 return ass
->get_Setting();
1213 Type
* Ass_Undef::get_Type()
1215 if(_error_if_pard()) return 0;
1217 return ass
->get_Type();
1220 Value
* Ass_Undef::get_Value()
1222 if(_error_if_pard()) return 0;
1224 return ass
->get_Value();
1227 ValueSet
* Ass_Undef::get_ValueSet()
1229 if(_error_if_pard()) return 0;
1231 return ass
->get_ValueSet();
1234 ObjectClass
* Ass_Undef::get_ObjectClass()
1236 if(_error_if_pard()) return 0;
1238 return ass
->get_ObjectClass();
1241 Object
* Ass_Undef::get_Object()
1243 if(_error_if_pard()) return 0;
1245 return ass
->get_Object();
1248 ObjectSet
* Ass_Undef::get_ObjectSet()
1250 if(_error_if_pard()) return 0;
1252 return ass
->get_ObjectSet();
1255 void Ass_Undef::chk()
1259 ass_pard
->get_nof_pars();
1268 void Ass_Undef::generate_code(output_struct
*target
, bool)
1270 if (ass_pard
|| dontgen
) return;
1272 ass
->generate_code(target
);
1275 void Ass_Undef::generate_code(CodeGenHelper
& cgh
) {
1276 if (ass_pard
|| dontgen
) return;
1278 ass
->generate_code(cgh
);
1281 void Ass_Undef::dump(unsigned level
) const
1286 DEBUG(level
, "Undef assignment: %s%s",
1287 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1291 void Ass_Undef::classify_ass(ReferenceChain
*refch
)
1293 if(asstype
!=A_UNDEF
) return;
1294 bool destroy_refch
=false;
1296 refch
=new ReferenceChain(this, "While examining kind of assignment");
1298 } else refch
->mark_state();
1300 Error_Context
ec_backup(1);
1301 Error_Context
cntxt(this, "In assignment `%s'",
1302 id
->get_dispname().c_str());
1304 /* temporary pointers */
1306 Reference
*t_ref2
=0;
1309 if(!refch
->add(get_fullname()))
1311 if((t_ref
=dynamic_cast<Reference
*>(left
))) {
1312 t_ref
->set_my_scope(my_scope
);
1313 if(t_ref
->refers_to_st(Setting::S_ERROR
, refch
))
1316 if((t_ref
=dynamic_cast<Reference
*>(right
))) {
1317 t_ref
->set_my_scope(right_scope
);
1319 if(t_ref->refers_to_st(Setting::S_ERROR, refch))
1320 t_ref->error("Cannot recognize assignment `%s'",
1321 t_ref->get_dispname().c_str());
1325 if(id
->isvalid_asn_objclassref()
1327 && (t_ref
=dynamic_cast<Ref_defd
*>(right
))
1328 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1330 ass
=new Ass_OC(id
->clone(), ass_pard
, new OC_refd(t_ref
));
1335 else if(id
->isvalid_asn_typeref()
1337 && (t_ref
=dynamic_cast<Ref_defd
*>(right
))
1338 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1339 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1341 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1342 t_type
->set_location(*t_ref
);
1343 ass
=new Ass_T(id
->clone(), ass_pard
, t_type
);
1348 else if(id
->isvalid_asn_objsetref()
1349 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1350 && (t_block
=dynamic_cast<Block
*>(right
))
1351 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1353 ass
=new Ass_OS(id
->clone(), ass_pard
,
1354 new OC_refd(t_ref
), new OS_defn(t_block
));
1360 else if(id
->isvalid_asn_valsetref()
1361 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1362 && (t_block
=dynamic_cast<Block
*>(right
))
1363 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1364 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1366 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1367 t_type
->set_location(*t_ref
);
1368 ass
=new Ass_VS(id
->clone(), ass_pard
, t_type
, t_block
);
1374 else if(id
->isvalid_asn_objref()
1375 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1376 && ((t_block
=dynamic_cast<Block
*>(right
))
1377 || (t_ref2
=dynamic_cast<Reference
*>(right
)))
1378 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1380 OC_refd
*t_oc
=new OC_refd(t_ref
);
1381 t_oc
->set_location(*t_ref
);
1383 Obj_defn
*t_obj
=new Obj_defn(t_block
);
1384 t_obj
->set_location(*t_block
);
1385 ass
=new Ass_O(id
->clone(), ass_pard
, t_oc
, t_obj
);
1388 Obj_refd
*t_obj
=new Obj_refd(t_ref2
);
1389 t_obj
->set_location(*t_ref2
);
1390 ass
=new Ass_O(id
->clone(), ass_pard
, t_oc
, t_obj
);
1397 else if(id
->isvalid_asn_valref()
1398 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1399 && ((t_block
=dynamic_cast<Block
*>(right
))
1400 || (t_ref2
=dynamic_cast<Reference
*>(right
)))
1401 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1402 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1404 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1405 t_type
->set_location(*t_ref
);
1407 Value
*t_value
=new Value(Value::V_UNDEF_BLOCK
, t_block
);
1408 t_value
->set_location(*t_block
);
1409 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_value
);
1412 Ref_defd_simple
*t_ref3
=dynamic_cast<Ref_defd_simple
*>(t_ref2
);
1413 if(t_ref3
&& !t_ref3
->get_modid()) {
1414 Value
*t_val
=new Value(Value::V_UNDEF_LOWERID
,
1415 t_ref3
->get_id()->clone());
1416 t_val
->set_location(*t_ref3
);
1417 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_val
);
1421 Value
*t_val
=new Value(Value::V_REFD
, t_ref2
);
1422 t_val
->set_location(*t_ref2
);
1423 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_val
);
1436 error("Cannot recognize assignment");
1437 ass
= new Ass_Error(id
->clone(), ass_pard
);
1440 ass
->set_location(*this);
1441 ass
->set_my_scope(my_scope
);
1442 ass
->set_right_scope(right_scope
);
1443 ass
->set_fullname(get_fullname());
1444 if(destroy_refch
) delete refch
;
1445 else refch
->prev_state();
1448 // =================================
1450 // =================================
1452 Ass_Error::Ass_Error(Identifier
*p_id
, Ass_pard
*p_ass_pard
)
1453 : Assignment(A_ERROR
, p_id
, p_ass_pard
),
1454 setting_error(0), type_error(0), value_error(0)
1458 Ass_Error::~Ass_Error()
1460 delete setting_error
;
1465 Assignment
* Ass_Error::clone() const
1467 return new Ass_Error(id
->clone(), ass_pard
);
1470 Assignment
* Ass_Error::new_instance0()
1472 return new Ass_Error
1473 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0);
1476 bool Ass_Error::is_asstype(asstype_t p_asstype
, ReferenceChain
*)
1478 return p_asstype
==A_ERROR
;
1481 Setting
* Ass_Error::get_Setting()
1484 setting_error
= new Common::Setting_Error();
1485 return setting_error
;
1488 Type
* Ass_Error::get_Type()
1491 type_error
= new Type(Type::T_ERROR
);
1495 Value
* Ass_Error::get_Value()
1498 value_error
= new Value(Value::V_ERROR
);
1502 ValueSet
* Ass_Error::get_ValueSet()
1504 FATAL_ERROR("Ass_Error::get_ValueSet()");
1508 ObjectClass
* Ass_Error::get_ObjectClass()
1510 FATAL_ERROR("Ass_Error::get_ObjectClass()");
1514 Object
* Ass_Error::get_Object()
1516 FATAL_ERROR("Ass_Error::get_Object()");
1520 ObjectSet
* Ass_Error::get_ObjectSet()
1522 FATAL_ERROR("Ass_Error::get_ObjectSet()");
1526 void Ass_Error::chk()
1531 void Ass_Error::dump(unsigned level
) const
1533 DEBUG(level
, "Erroneous assignment: %s%s",
1534 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1537 // =================================
1539 // =================================
1541 Ass_T::Ass_T(Identifier
*p_id
, Ass_pard
*p_ass_pard
, Type
*p_right
)
1542 : Assignment(A_TYPE
, p_id
, p_ass_pard
)
1545 FATAL_ERROR("NULL parameter: Asn::Ass_T::Ass_T()");
1546 p_right
->set_ownertype(Type::OT_TYPE_ASS
, this);
1550 Ass_T::Ass_T(const Ass_T
& p
)
1553 right
=p
.right
->clone();
1561 Assignment
* Ass_T::new_instance0()
1564 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0, right
->clone());
1567 void Ass_T::set_fullname(const string
& p_fullname
)
1569 Assignment::set_fullname(p_fullname
);
1570 right
->set_fullname(p_fullname
);
1573 void Ass_T::set_my_scope(Scope
*p_scope
)
1575 Assignment::set_my_scope(p_scope
);
1576 right
->set_my_scope(p_scope
);
1579 void Ass_T::set_right_scope(Scope
*p_scope
)
1581 right
->set_my_scope(p_scope
);
1584 Type
* Ass_T::get_Type()
1587 error("`%s' is a parameterized type assignment",
1588 get_fullname().c_str());
1597 if (checked
) return;
1599 Error_Context
cntxt(this, "In type assignment `%s'",
1600 id
->get_dispname().c_str());
1602 ass_pard
->get_nof_pars();
1606 right
->set_genname(get_genname());
1608 ReferenceChain
refch(right
, "While checking embedded recursions");
1609 right
->chk_recursions(refch
);
1612 void Ass_T::generate_code(output_struct
*target
, bool)
1614 right
->generate_code(target
);
1617 void Ass_T::generate_code(CodeGenHelper
& cgh
) {
1618 if (ass_pard
|| dontgen
) return;
1619 generate_code(cgh
.get_outputstruct(right
));
1620 cgh
.finalize_generation(right
);
1623 void Ass_T::dump(unsigned level
) const
1625 DEBUG(level
, "Type assignment: %s%s",
1626 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1633 // =================================
1635 // =================================
1637 Ass_V::Ass_V(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1638 Type
*p_left
, Value
*p_right
)
1639 : Assignment(A_CONST
, p_id
, p_ass_pard
)
1641 if(!p_left
|| !p_right
)
1642 FATAL_ERROR("NULL parameter: Asn::Ass_V::Ass_V()");
1644 left
->set_ownertype(Type::OT_VAR_ASS
, this);
1648 Ass_V::Ass_V(const Ass_V
& p
)
1651 left
=p
.left
->clone();
1652 right
=p
.right
->clone();
1661 Assignment
* Ass_V::new_instance0()
1664 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
1665 left
->clone(), right
->clone());
1668 void Ass_V::set_fullname(const string
& p_fullname
)
1670 Assignment::set_fullname(p_fullname
);
1671 left
->set_fullname(p_fullname
+ ".<type>");
1672 right
->set_fullname(p_fullname
);
1675 void Ass_V::set_my_scope(Scope
*p_scope
)
1677 Assignment::set_my_scope(p_scope
);
1678 left
->set_my_scope(p_scope
);
1679 right
->set_my_scope(p_scope
);
1682 void Ass_V::set_right_scope(Scope
*p_scope
)
1684 right
->set_my_scope(p_scope
);
1688 Type
* Ass_V::get_Type()
1694 Value
* Ass_V::get_Value()
1697 error("`%s' is a parameterized value assignment",
1698 get_fullname().c_str());
1708 Error_Context
cntxt(this, "In value assignment `%s'",
1709 id
->get_dispname().c_str());
1711 ass_pard
->get_nof_pars();
1716 static const string
_T_("_T_");
1717 left
->set_genname(_T_
, get_genname());
1719 right
->set_my_governor(left
);
1720 left
->chk_this_value_ref(right
);
1722 left
->chk_this_value(right
, 0, Type::EXPECTED_CONSTANT
, INCOMPLETE_NOT_ALLOWED
,
1723 OMIT_NOT_ALLOWED
, SUB_CHK
, IMPLICIT_OMIT
);
1725 ReferenceChain
refch(right
, "While checking embedded recursions");
1726 right
->chk_recursions(refch
);
1728 if (!semantic_check_only
) {
1729 right
->set_genname_prefix("const_");
1730 right
->set_genname_recursive(get_genname());
1731 right
->set_code_section(GovernedSimple::CS_PRE_INIT
);
1735 void Ass_V::generate_code(output_struct
*target
, bool)
1737 if (ass_pard
|| dontgen
) return;
1738 left
->generate_code(target
);
1740 Code::init_cdef(&cdef
);
1741 left
->generate_code_object(&cdef
, right
);
1742 cdef
.init
= right
->generate_code_init(cdef
.init
,
1743 right
->get_lhs_name().c_str());
1744 Code::merge_cdef(target
, &cdef
);
1745 Code::free_cdef(&cdef
);
1748 void Ass_V::generate_code(CodeGenHelper
& cgh
) {
1749 generate_code(cgh
.get_current_outputstruct());
1752 void Ass_V::dump(unsigned level
) const
1754 DEBUG(level
, "Value assignment: %s%s",
1755 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1762 // =================================
1764 // =================================
1766 Ass_VS::Ass_VS(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1767 Type
*p_left
, Block
*p_right
)
1768 : Assignment(A_VS
, p_id
, p_ass_pard
), right_scope(0)
1770 if(!p_left
|| !p_right
)
1771 FATAL_ERROR("NULL parameter: Asn::Ass_VS::Ass_VS()");
1773 left
->set_ownertype(Type::OT_VSET_ASS
, this);
1777 Ass_VS::Ass_VS(const Ass_VS
& p
)
1778 : Assignment(p
), right_scope(0)
1780 left
=p
.left
->clone();
1781 right
=p
.right
->clone();
1790 Assignment
* Ass_VS::new_instance0()
1793 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
1794 left
->clone(), right
->clone());
1797 void Ass_VS::set_fullname(const string
& p_fullname
)
1799 Assignment::set_fullname(p_fullname
);
1800 left
->set_fullname(p_fullname
);
1801 right
->set_fullname(p_fullname
);
1804 void Ass_VS::set_my_scope(Scope
*p_scope
)
1806 Assignment::set_my_scope(p_scope
);
1807 left
->set_my_scope(p_scope
);
1810 void Ass_VS::set_right_scope(Scope
*p_scope
)
1812 right_scope
=p_scope
;
1815 Type
* Ass_VS::get_Type()
1818 error("`%s' is a parameterized value set assignment",
1819 get_fullname().c_str());
1828 if (checked
) return;
1830 Error_Context
cntxt(this, "In value set assignment `%s'",
1831 id
->get_dispname().c_str());
1833 ass_pard
->get_nof_pars();
1837 // parse the content of right and add it to left as one more constraint
1838 Node
*node
= right
->parse(KW_Block_ValueSet
);
1839 Constraint
* vs_constr
= dynamic_cast<Constraint
*>(node
);
1840 if (vs_constr
) { // if we have a constraint add it to the type
1841 if (right_scope
) { // if this is a parameter of a pard type
1842 vs_constr
->set_my_scope(right_scope
);
1844 if (!left
->get_constraints()) left
->add_constraints(new Constraints());
1845 left
->get_constraints()->add_con(vs_constr
);
1849 left
->set_genname(get_genname());
1851 ReferenceChain
refch(left
, "While checking embedded recursions");
1852 left
->chk_recursions(refch
);
1855 void Ass_VS::generate_code(output_struct
*target
, bool)
1857 left
->generate_code(target
);
1860 void Ass_VS::generate_code(CodeGenHelper
& cgh
) {
1861 if (ass_pard
|| dontgen
) return;
1862 generate_code(cgh
.get_outputstruct(left
));
1863 cgh
.finalize_generation(left
);
1866 void Ass_VS::dump(unsigned level
) const
1868 DEBUG(level
, "Value set assignment: %s%s",
1869 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1878 // =================================
1880 // =================================
1882 Ass_OC::Ass_OC(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1883 ObjectClass
*p_right
)
1884 : Assignment(A_OC
, p_id
, p_ass_pard
)
1887 FATAL_ERROR("NULL parameter: Asn::Ass_OC::Ass_OC()");
1891 Ass_OC::Ass_OC(const Ass_OC
& p
)
1894 right
=p
.right
->clone();
1902 Assignment
* Ass_OC::new_instance0()
1905 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0, right
->clone());
1908 void Ass_OC::set_fullname(const string
& p_fullname
)
1910 Assignment::set_fullname(p_fullname
);
1911 right
->set_fullname(p_fullname
);
1914 void Ass_OC::set_my_scope(Scope
*p_scope
)
1916 Assignment::set_my_scope(p_scope
);
1917 right
->set_my_scope(p_scope
);
1920 void Ass_OC::set_right_scope(Scope
*p_scope
)
1922 right
->set_my_scope(p_scope
);
1928 Error_Context
cntxt(this, "In information object class assignment `%s'",
1929 id
->get_dispname().c_str());
1931 ass_pard
->get_nof_pars();
1935 right
->set_genname(get_genname());
1940 ObjectClass
* Ass_OC::get_ObjectClass()
1943 error("`%s' is a parameterized objectclass assignment",
1944 get_fullname().c_str());
1951 void Ass_OC::generate_code(output_struct
*target
, bool)
1953 if (ass_pard
|| dontgen
) return;
1954 right
->generate_code(target
);
1957 void Ass_OC::generate_code(CodeGenHelper
& cgh
) {
1958 generate_code(cgh
.get_current_outputstruct());
1961 void Ass_OC::dump(unsigned level
) const
1963 DEBUG(level
, "ObjectClass assignment: %s%s",
1964 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1970 // =================================
1972 // =================================
1974 Ass_O::Ass_O(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1975 ObjectClass
*p_left
, Object
*p_right
)
1976 : Assignment(A_OBJECT
, p_id
, p_ass_pard
)
1978 if(!p_left
|| !p_right
)
1979 FATAL_ERROR("NULL parameter: Asn::Ass_O::Ass_O()");
1984 Ass_O::Ass_O(const Ass_O
& p
)
1987 left
=p
.left
->clone();
1988 right
=p
.right
->clone();
1997 Assignment
* Ass_O::new_instance0()
2000 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
2001 left
->clone(), right
->clone());
2004 void Ass_O::set_fullname(const string
& p_fullname
)
2006 Assignment::set_fullname(p_fullname
);
2007 left
->set_fullname(p_fullname
);
2008 right
->set_fullname(p_fullname
);
2011 void Ass_O::set_my_scope(Scope
*p_scope
)
2013 Assignment::set_my_scope(p_scope
);
2014 left
->set_my_scope(p_scope
);
2015 right
->set_my_scope(p_scope
);
2018 void Ass_O::set_right_scope(Scope
*p_scope
)
2020 right
->set_my_scope(p_scope
);
2024 ObjectClass* Ass_O::get_ObjectClass()
2030 Object
* Ass_O::get_Object()
2033 error("`%s' is a parameterized object assignment",
2034 get_fullname().c_str());
2044 Error_Context
cntxt(this, "In information object assignment `%s'",
2045 id
->get_dispname().c_str());
2047 ass_pard
->get_nof_pars();
2052 right
->set_my_governor(left
);
2053 right
->set_genname(get_genname());
2058 void Ass_O::generate_code(output_struct
*target
, bool)
2060 if (ass_pard
|| dontgen
) return;
2061 left
->generate_code(target
);
2062 right
->generate_code(target
);
2065 void Ass_O::generate_code(CodeGenHelper
& cgh
) {
2066 generate_code(cgh
.get_current_outputstruct());
2069 void Ass_O::dump(unsigned level
) const
2071 DEBUG(level
, "Object assignment: %s%s",
2072 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2079 // =================================
2081 // =================================
2083 Ass_OS::Ass_OS(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
2084 ObjectClass
*p_left
, ObjectSet
*p_right
)
2085 : Assignment(A_OS
, p_id
, p_ass_pard
)
2087 if(!p_left
|| !p_right
)
2088 FATAL_ERROR("NULL parameter: Asn::Ass_OS::Ass_OS()");
2093 Ass_OS::Ass_OS(const Ass_OS
& p
)
2096 left
=p
.left
->clone();
2097 right
=p
.right
->clone();
2106 Assignment
* Ass_OS::new_instance0()
2109 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
2110 left
->clone(), right
->clone());
2113 void Ass_OS::set_fullname(const string
& p_fullname
)
2115 Assignment::set_fullname(p_fullname
);
2116 left
->set_fullname(p_fullname
);
2117 right
->set_fullname(p_fullname
);
2120 void Ass_OS::set_my_scope(Scope
*p_scope
)
2122 Assignment::set_my_scope(p_scope
);
2123 left
->set_my_scope(p_scope
);
2124 right
->set_my_scope(p_scope
);
2127 void Ass_OS::set_right_scope(Scope
*p_scope
)
2129 right
->set_my_scope(p_scope
);
2133 ObjectClass* Ass_OS::get_ObjectClass()
2139 ObjectSet
* Ass_OS::get_ObjectSet()
2142 error("`%s' is a parameterized objectset assignment",
2143 get_fullname().c_str());
2153 Error_Context
cntxt(this, "In information object set assignment `%s'",
2154 id
->get_dispname().c_str());
2156 ass_pard
->get_nof_pars();
2161 right
->set_my_governor(left
);
2162 right
->set_genname(get_genname());
2167 void Ass_OS::generate_code(output_struct
*target
, bool)
2169 if (ass_pard
|| dontgen
) return;
2170 left
->generate_code(target
);
2171 right
->generate_code(target
);
2174 void Ass_OS::generate_code(CodeGenHelper
& cgh
) {
2175 generate_code(cgh
.get_current_outputstruct());
2178 void Ass_OS::dump(unsigned level
) const
2180 DEBUG(level
, "ObjectSet assignment: %s%s",
2181 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2188 // =================================
2190 // =================================
2192 // =================================
2194 // =================================
2196 const Identifier
* Ref_defd::get_modid()
2198 Ref_defd_simple
*t_ref
= get_ref_defd_simple();
2199 if (t_ref
) return t_ref
->get_modid();
2203 const Identifier
* Ref_defd::get_id()
2205 Ref_defd_simple
*t_ref
= get_ref_defd_simple();
2206 if (t_ref
) return t_ref
->get_id();
2210 bool Ref_defd::refers_to_st(Setting::settingtype_t p_st
,
2211 ReferenceChain
* refch
)
2213 if(get_is_erroneous()) return p_st
==Setting::S_ERROR
;
2215 Error_Context
cntxt(this, "In reference `%s'", get_dispname().c_str());
2217 FATAL_ERROR("NULL parameter");
2218 Common::Assignment
* c_ass
=my_scope
->get_ass_bySRef(this);
2223 Assignment
* ass
=dynamic_cast<Assignment
*>(c_ass
);
2225 error("Reference to a non-ASN setting");
2231 b
=ass
->is_asstype(Assignment::A_OC
, refch
);
2234 b
=ass
->is_asstype(Assignment::A_TYPE
, refch
);
2237 b
=ass
->is_asstype(Assignment::A_OBJECT
, refch
);
2240 b
=ass
->is_asstype(Assignment::A_CONST
, refch
);
2243 b
=ass
->is_asstype(Assignment::A_OS
, refch
);
2246 b
=ass
->is_asstype(Assignment::A_VS
, refch
);
2248 case Setting::S_ERROR
:
2249 b
=ass
->is_asstype(Assignment::A_ERROR
, refch
);
2252 FATAL_ERROR("Asn::Ref_defd::refers_to_st()");
2257 void Ref_defd::generate_code(expression_struct_t
*)
2259 FATAL_ERROR("Ref_defd::generate_code()");
2262 void Ref_defd::generate_code_const_ref(expression_struct */
*expr*/
)
2264 FATAL_ERROR("Ref_defd::generate_code_const_ref()");
2267 // =================================
2268 // ===== Ref_defd_simple
2269 // =================================
2271 Ref_defd_simple::Ref_defd_simple(Identifier
*p_modid
,
2273 : Ref_defd(), modid(p_modid
), id(p_id
)
2276 FATAL_ERROR("NULL parameter: Asn::Ref_defd_simple::Ref_defd_simple()");
2279 Ref_defd_simple::Ref_defd_simple(const Ref_defd_simple
& p
)
2282 modid
=p
.modid
?p
.modid
->clone():0;
2286 Ref_defd_simple::~Ref_defd_simple()
2292 Assignment
* Ref_defd_simple::get_refd_ass()
2294 if(get_is_erroneous()) return 0;
2295 Error_Context
cntxt(this, "In reference `%s'", get_dispname().c_str());
2297 FATAL_ERROR("NULL parameter: Asn::Ref_defd_simple::get_refd_ass():"
2298 " my_scope is not set");
2299 Common::Assignment
* c_ass
=my_scope
->get_ass_bySRef(this);
2300 if(!c_ass
) return 0;
2301 Assignment
* ass
=dynamic_cast<Assignment
*>(c_ass
);
2303 this->error("Reference to a non-ASN assignment");
This page took 0.122007 seconds and 4 git commands to generate.