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"
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 target
->header
.includes
= mputstr(target
->header
.includes
,
302 "#include <TTCN3.hh>\n");
303 for (size_t i
= 0; i
< impmods_v
.size(); i
++) {
304 ImpMod
*im
= impmods_v
[i
];
305 Common::Module
*m
= im
->get_mod();
306 // inclusion of m's header file can be eliminated if we find another
307 // imported module that imports m
308 bool covered
= false;
309 for (size_t j
= 0; j
< impmods_v
.size(); j
++) {
310 // skip over the same import definition
311 if (j
== i
) continue;
312 Common::Module
*m2
= impmods_v
[j
]->get_mod();
313 // a module that is equivalent to the current module due to
314 // circular imports cannot be used to cover anything
315 if (m2
->is_visible(my_mod
)) continue;
316 if (m2
->is_visible(m
) && !m
->is_visible(m2
)) {
317 // m2 covers m (i.e. m is visible from m2)
318 // and they are not in the same import loop
323 // do not generate the #include if a covering module is found
324 if (!covered
) im
->generate_code(target
);
328 // =================================
330 // =================================
332 Module::Module(Identifier
*p_modid
, TagDefault::tagdef_t p_tagdef
,
333 bool p_extens_impl
, Exports
*p_exp
, Imports
*p_imp
,
335 : Common::Module(MOD_ASN
, p_modid
), tagdef(p_tagdef
),
336 extens_impl(p_extens_impl
), exp(p_exp
), imp(p_imp
), asss(p_asss
)
338 if (!p_exp
|| !p_imp
|| !p_asss
)
339 FATAL_ERROR("NULL parameter: Asn::Module::Module()");
340 if(!p_modid
->isvalid_asn_modref()
341 && p_modid
->get_dispname()!="<internal>")
342 error("`%s' is not a valid module identifier",
343 p_modid
->get_dispname().c_str());
344 asss
->set_parent_scope(this);
345 exp
->set_my_mod(this);
346 imp
->set_my_mod(this);
356 Module
*Module::clone() const
358 FATAL_ERROR("Asn::Module::clone");
362 Common::Assignment
*Module::importAssignment(
363 const Identifier
& p_source_modid
, const Identifier
& p_id
) const
365 (void)p_source_modid
;
366 if (asss
->has_local_ass_withId(p_id
)) {
367 return asss
->get_local_ass_byId(p_id
);
371 void Module::set_fullname(const string
& p_fullname
)
373 Common::Module::set_fullname(p_fullname
);
374 exp
->set_fullname(p_fullname
+".<exports>");
375 imp
->set_fullname(p_fullname
+".<imports>");
376 asss
->set_fullname(p_fullname
);
379 Common::Assignments
*Module::get_scope_asss()
384 bool Module::has_imported_ass_withId(const Identifier
& p_id
)
386 return imp
->has_impsym_withId(p_id
);
389 Common::Assignment
* Module::get_ass_bySRef(Ref_simple
*p_ref
)
391 const Identifier
*r_modid
= p_ref
->get_modid();
392 const Identifier
*r_id
= p_ref
->get_id();
394 // return NULL if the reference is erroneous
397 Common::Module
*r_mod
=0;
399 if(!r_modid
|| *r_modid
==*modid
) {
400 if(asss
->has_local_ass_withId(*r_id
))
401 return asss
->get_local_ass_byId(*r_id
);
403 p_ref
->error("There is no assignment with name `%s'"
404 " in module `%s'", r_id
->get_dispname().c_str(),
405 modid
->get_dispname().c_str());
408 if(imp
->impsyms_1
.has_key(r_id
->get_name()))
409 r_mod
=imp
->impsyms_1
[r_id
->get_name()];
410 else if(imp
->impsyms_m
.has_key(r_id
->get_name())) {
411 p_ref
->error("There are more imported symbols with name `%s'"
412 " in module `%s'", r_id
->get_dispname().c_str(),
413 modid
->get_dispname().c_str());
417 p_ref
->error("There is no assignment or imported symbol"
418 " with name `%s' in module `%s'",
419 r_id
->get_dispname().c_str(),
420 modid
->get_dispname().c_str());
425 if(!imp
->has_impmod_withId(*r_modid
)) {
426 p_ref
->error("There is no imported module with name `%s'",
427 r_modid
->get_dispname().c_str());
430 if(!imp
->get_impmod_byId(*r_modid
)->has_sym(*r_id
)) {
431 p_ref
->error("There is no symbol with name `%s'"
432 " imported from module `%s'",
433 r_id
->get_dispname().c_str(),
434 r_modid
->get_dispname().c_str());
437 r_mod
=modules
->get_mod_byId(*r_modid
);
439 Ref_defd_simple
t_ref(0, r_id
->clone());
440 return r_mod
->get_ass_bySRef(&t_ref
);
443 Assignments
*Module::get_asss()
448 bool Module::exports_sym(const Identifier
& p_id
)
450 return exp
->exports_sym(p_id
);
453 void Module::chk_imp(ReferenceChain
& refch
, vector
<Common::Module
>& /*moduleStack*/)
455 if (imp_checked
) return;
456 const string
& module_name
= modid
->get_dispname();
457 if (refch
.exists(module_name
)) {
458 // Do not warning for circular import in ASN.1 module. It is legal
459 // warning("Circular import chain is not recommended: %s",
460 // refch.get_dispstr(module_name).c_str());
463 refch
.add(module_name
);
464 Error_Context backup
;
465 Error_Context
cntxt(this, "In ASN.1 module `%s'", module_name
.c_str());
469 collect_visible_mods();
474 DEBUG(1, "Checking ASN.1 module `%s'", modid
->get_dispname().c_str());
475 Error_Context
cntxt(this, "In ASN.1 module `%s'",
476 modid
->get_dispname().c_str());
482 void Module::get_imported_mods(module_set_t
& p_imported_mods
)
484 imp
->get_imported_mods(p_imported_mods
);
487 bool Module::has_circular_import()
489 return imp
->get_is_circular();
492 void Module::generate_code_internal(CodeGenHelper
& cgh
) {
493 imp
->generate_code(cgh
.get_current_outputstruct());
494 asss
->generate_code(cgh
);
497 void Module::dump(unsigned level
) const
499 DEBUG(level
, "ASN.1 module: %s", modid
->get_dispname().c_str());
500 asss
->dump(level
+ 1);
503 void Module::add_ass(Assignment
*p_ass
)
505 asss
->add_ass(p_ass
);
508 void Module::generate_json_schema(JSON_Tokenizer
& json
, map
<Type
*, JSON_Tokenizer
>& json_refs
)
510 // add a new property for this module
511 json
.put_next_token(JSON_TOKEN_NAME
, modid
->get_ttcnname().c_str());
513 // add type definitions into an object
514 json
.put_next_token(JSON_TOKEN_OBJECT_START
);
516 // cycle through all type assignments, insert schema segments and references
518 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
519 Common::Assignment
* ass
= asss
->get_ass_byIndex(i
);
520 if (Common::Assignment::A_TYPE
== ass
->get_asstype()) {
521 Asn::Assignment
* asn_ass
= dynamic_cast<Asn::Assignment
*>(ass
);
522 // skip parameterized types and their instances
523 if (NULL
== asn_ass
|| NULL
== asn_ass
->get_ass_pard()) {
524 Type
* t
= ass
->get_Type();
525 if (!t
->is_pard_type_instance() && t
->has_encoding(Type::CT_JSON
)) {
526 // insert type's schema segment
527 t
->generate_json_schema(json
, false, false);
529 if (json_refs_for_all_types
&& !json_refs
.has_key(t
)) {
530 // create JSON schema reference for the type
531 JSON_Tokenizer
* json_ref
= new JSON_Tokenizer
;
532 json_refs
.add(t
, json_ref
);
533 t
->generate_json_schema_ref(*json_ref
);
540 // end of type definitions
541 json
.put_next_token(JSON_TOKEN_OBJECT_END
);
544 // =================================
546 // =================================
548 Assignments::Assignments(const Assignments
& p
)
549 : Common::Assignments(p
), checked(false)
551 for(size_t i
= 0; i
< p
.asss_v
.size(); i
++)
552 add_ass(p
.asss_v
[i
]->clone());
555 Assignments::~Assignments()
557 for (size_t i
= 0; i
< asss_v
.size(); i
++) delete asss_v
[i
];
562 Assignments
*Assignments::clone() const
564 return new Assignments(*this);
567 void Assignments::set_fullname(const string
& p_fullname
)
569 Common::Assignments::set_fullname(p_fullname
);
570 string
s(p_fullname
);
571 if (s
!= "@") s
+= '.';
572 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
573 Assignment
*ass
= asss_v
[i
];
574 ass
->set_fullname(s
+ass
->get_id().get_dispname());
578 bool Assignments::has_local_ass_withId(const Identifier
& p_id
)
580 if (!checked
) chk_uniq();
581 if (asss_m
.has_key(p_id
.get_name())) return true;
582 Assignments
*spec_asss
= _spec_asss
->get_asss();
583 if (spec_asss
!= this) return spec_asss
->has_ass_withId(p_id
);
587 Assignment
* Assignments::get_local_ass_byId(const Identifier
& p_id
)
589 if (!checked
) chk_uniq();
590 const string
& name
= p_id
.get_name();
591 if (asss_m
.has_key(name
)) return asss_m
[name
];
592 Assignments
*spec_asss
= _spec_asss
->get_asss();
593 if (spec_asss
!= this) return spec_asss
->get_local_ass_byId(p_id
);
597 size_t Assignments::get_nof_asss()
599 if (!checked
) chk_uniq();
600 return asss_m
.size();
603 Common::Assignment
* Assignments::get_ass_byIndex(size_t p_i
)
605 if (!checked
) chk_uniq();
606 return asss_m
.get_nth_elem(p_i
);
609 void Assignments::add_ass(Assignment
*p_ass
)
611 if (!p_ass
) FATAL_ERROR("Asn::Assignments::add_ass()");
613 p_ass
->set_my_scope(this);
615 const Identifier
& id
= p_ass
->get_id();
616 const string
& name
= id
.get_name();
617 if(asss_m
.has_key(name
)) {
618 const char *dispname_str
= id
.get_dispname().c_str();
619 p_ass
->error("Duplicate assignment with identifier `%s'", dispname_str
);
620 asss_m
[name
]->note("Previous assignment with identifier `%s' is here",
622 } else asss_m
.add(name
, p_ass
);
626 void Assignments::chk()
628 for(size_t i
= 0; i
< asss_v
.size(); i
++) asss_v
[i
]->chk();
631 void Assignments::chk_uniq()
635 Assignments
*spec_asss
= _spec_asss
->get_asss();
636 for(size_t i
= 0; i
< asss_v
.size(); i
++) {
637 Assignment
*ass
= asss_v
[i
];
638 const Identifier
& id
= ass
->get_id();
639 const string
& name
= id
.get_name();
640 if (this != spec_asss
&& spec_asss
->has_ass_withId(id
)) {
641 ass
->error("`%s' is a reserved identifier", id
.get_dispname().c_str());
642 } else if (asss_m
.has_key(name
)) {
643 const char *dispname_str
= id
.get_dispname().c_str();
644 ass
->error("Duplicate assignment with identifier `%s'", dispname_str
);
645 asss_m
[name
]->note("Previous assignment with identifier `%s' is here",
647 } else asss_m
.add(name
, ass
);
652 void Assignments::set_right_scope(Scope
*p_scope
)
654 for(size_t i
= 0; i
< asss_v
.size(); i
++)
655 asss_v
[i
]->set_right_scope(p_scope
);
658 void Assignments::create_spec_asss()
661 FATAL_ERROR("Assignments::create_spec_asss(): duplicate initialization");
663 const char *s_asss
= "$#&&&(#TITAN$#&&^#% Assignments\n"
664 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"EXTERNAL\""
665 " ::= [UNIVERSAL 8] IMPLICIT SEQUENCE {\n"
666 " identification CHOICE {\n"
667 " syntaxes SEQUENCE {\n"
668 " abstract OBJECT IDENTIFIER,\n"
669 " transfer OBJECT IDENTIFIER\n"
671 " syntax OBJECT IDENTIFIER,\n"
672 " presentation-context-id INTEGER,\n"
673 " context-negotiation SEQUENCE {\n"
674 " presentation-context-id INTEGER,\n"
675 " transfer-syntax OBJECT IDENTIFIER\n"
677 " transfer-syntax OBJECT IDENTIFIER,\n"
680 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
681 " data-value OCTET STRING\n"
682 "} (WITH COMPONENTS {\n"
684 " identification (WITH COMPONENTS {\n"
686 " syntaxes ABSENT,\n"
687 " transfer-syntax ABSENT,\n"
692 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"EMBEDDED PDV\""
693 " ::= [UNIVERSAL 11] IMPLICIT SEQUENCE {\n"
694 " identification CHOICE {\n"
695 " syntaxes SEQUENCE {\n"
696 " abstract OBJECT IDENTIFIER,\n"
697 " transfer OBJECT IDENTIFIER\n"
699 " syntax OBJECT IDENTIFIER,\n"
700 " presentation-context-id INTEGER,\n"
701 " context-negotiation SEQUENCE {\n"
702 " presentation-context-id INTEGER,\n"
703 " transfer-syntax OBJECT IDENTIFIER\n"
705 " transfer-syntax OBJECT IDENTIFIER,\n"
708 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
709 " data-value OCTET STRING\n"
710 "} (WITH COMPONENTS {\n"
712 " data-value-descriptor ABSENT\n"
715 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"CHARACTER STRING\""
716 " ::= [UNIVERSAL 29] IMPLICIT SEQUENCE {\n"
717 " identification CHOICE {\n"
718 " syntaxes SEQUENCE {\n"
719 " abstract OBJECT IDENTIFIER,\n"
720 " transfer OBJECT IDENTIFIER\n"
722 " syntax OBJECT IDENTIFIER,\n"
723 " presentation-context-id INTEGER,\n"
724 " context-negotiation SEQUENCE {\n"
725 " presentation-context-id INTEGER,\n"
726 " transfer-syntax OBJECT IDENTIFIER\n"
728 " transfer-syntax OBJECT IDENTIFIER,\n"
731 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
732 " string-value OCTET STRING\n"
733 "} (WITH COMPONENTS {\n"
735 " data-value-descriptor ABSENT\n"
738 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"REAL\""
739 " ::= [UNIVERSAL 9] IMPLICIT SEQUENCE {\n"
740 " mantissa INTEGER,\n"
741 " base INTEGER (2|10),\n"
742 " exponent INTEGER\n"
745 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"TYPE-IDENTIFIER\"\n"
748 " &id OBJECT IDENTIFIER UNIQUE,\n"
752 " &Type IDENTIFIED BY &id\n"
755 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"ABSTRACT-SYNTAX\""
757 " &id OBJECT IDENTIFIER UNIQUE,\n"
759 " &property BIT STRING {handles-invalid-encodings(0)} DEFAULT {}\n"
762 " &Type IDENTIFIED BY &id [HAS PROPERTY &property]\n"
766 if(asn1_parse_string(s_asss
) || !parsed_assignments
)
767 FATAL_ERROR("special assignments");
768 _spec_asss
=new Module
769 (new Identifier(Identifier::ID_ASN
, string("<internal>")),
770 TagDefault::AUTOMATIC
, false, new Exports(true), new Imports(),
772 _spec_asss
->set_location("<internal>");
773 _spec_asss
->set_scope_name(_spec_asss
->get_modid().get_dispname());
775 parsed_assignments
->set_fullname(string('@'));
779 // this is used to generate the files which are then
780 // included/copied/edited in core library
781 _spec_asss->set_gen_code();
782 _spec_asss->generate_code();
786 void Assignments::destroy_spec_asss()
789 FATAL_ERROR("Assignments::destroy_spec_asss(): duplicate cleanup");
795 bool Assignments::is_spec_asss(Common::Module
*p_mod
)
797 if (!p_mod
) FATAL_ERROR("Assignments::is_spec_asss()");
798 if (_spec_asss
) return p_mod
== static_cast<Common::Module
*>(_spec_asss
);
802 void Assignments::generate_code(output_struct
* target
)
804 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
805 Assignment
*ass
= asss_v
[i
];
806 if (!top_level_pdu
|| ass
->get_checked()) ass
->generate_code(target
);
810 void Assignments::generate_code(CodeGenHelper
& cgh
) {
811 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
812 Assignment
*ass
= asss_v
[i
];
813 if (!top_level_pdu
|| ass
->get_checked()) ass
->generate_code(cgh
);
817 void Assignments::dump(unsigned level
) const
819 DEBUG(level
, "Assignments (%lu pcs.)", (unsigned long) asss_v
.size());
820 for(size_t i
= 0; i
< asss_v
.size(); i
++) asss_v
[i
]->dump(level
+ 1);
823 // =================================
825 // =================================
827 Ass_pard::Ass_pard(Block
*p_parlist_block
)
828 : Common::Node(), parlist_block(p_parlist_block
)
831 FATAL_ERROR("NULL parameter: Asn::Ass_pard::Ass_pard()");
834 Ass_pard::Ass_pard(const Ass_pard
& p
)
837 parlist_block
=p
.parlist_block
?p
.parlist_block
->clone():0;
838 for(size_t i
=0; i
<p
.dummyrefs
.size(); i
++)
839 dummyrefs
.add(p
.dummyrefs
[i
]->clone());
840 for(size_t i
=0; i
<p
.governors
.size(); i
++)
841 governors
.add(p
.governors
[i
]->clone());
844 Ass_pard::~Ass_pard()
846 delete parlist_block
;
847 for (size_t i
= 0; i
< dummyrefs
.size(); i
++) delete dummyrefs
[i
];
849 for (size_t i
= 0; i
< governors
.size(); i
++) delete governors
[i
];
851 for (size_t i
= 0; i
< inst_cnts
.size(); i
++)
852 delete inst_cnts
.get_nth_elem(i
);
856 void Ass_pard::preparse_pars()
858 if(!parlist_block
) return;
860 (my_ass
, "While checking formal parameters of parameterized"
861 " assignment `%s'", my_ass
->get_fullname().c_str());
862 TokenBuf
*parlist_tb
=parlist_block
->get_TokenBuf();
863 enum state_type
{S_START
, S_GOV
, S_DUMMYREF
, S_COMMA
, S_RDY
, S_ERR
};
865 for(state_type st
=S_START
; st
!=S_RDY
; ) {
868 gov_tb
=new TokenBuf();
869 switch(parlist_tb
->get_at(1)->get_token()) {
879 Token
*token
=parlist_tb
->pop_front_token();
880 switch(token
->get_token()) {
883 token
->error("Syntax error, premature end of parameter"
893 gov_tb
->push_back_token(token
);
897 Token
*token
=parlist_tb
->pop_front_token();
898 switch(token
->get_token()) {
899 case TOK_UpperIdentifier
:
900 case TOK_LowerIdentifier
:
901 dummyrefs
.add(token
->get_semval_id().clone());
902 gov_tb
->push_front_token(token
);
903 gov_tb
->push_back_kw_token(TOK_Assignment
);
904 governors
.add(gov_tb
);
911 token
->error("Syntax error, DummyReference was expected");
915 break;} // S_DUMMYREF
917 Token
*token
=parlist_tb
->pop_front_token();
918 switch(token
->get_token()) {
926 token
->error("Syntax error, `,' was expected");
933 for (size_t i
= 0; i
< dummyrefs
.size(); i
++) delete dummyrefs
[i
];
935 for (size_t i
= 0; i
< governors
.size(); i
++) delete governors
[i
];
941 FATAL_ERROR("Ass_pard::preparse_pars()");
944 delete parlist_block
;
948 size_t Ass_pard::get_nof_pars()
950 if (parlist_block
) preparse_pars();
951 return dummyrefs
.size();
954 const Identifier
& Ass_pard::get_nth_dummyref(size_t i
)
956 if (parlist_block
) preparse_pars();
957 return *(dummyrefs
[i
]);
960 TokenBuf
* Ass_pard::clone_nth_governor(size_t i
)
962 if (parlist_block
) preparse_pars();
963 return governors
[i
]->clone();
966 size_t Ass_pard::new_instnum(Common::Module
*p_mod
)
968 if (!p_mod
) FATAL_ERROR("Ass_pard::new_instnum()");
969 if (inst_cnts
.has_key(p_mod
)) return ++(*inst_cnts
[p_mod
]);
971 inst_cnts
.add(p_mod
, new size_t(1));
976 // =================================
978 // =================================
980 Assignment::Assignment(const Assignment
& p
)
981 : Common::Assignment(p
), dontgen(false)
984 ass_pard
=p
.ass_pard
->clone();
985 ass_pard
->set_my_ass(this);
990 string
Assignment::get_genname() const
993 my_scope
->get_parent_scope() == my_scope
->get_scope_mod()) {
994 // use the simple identifier if the assignment does not have scope
995 // or it is a simple assignment at module scope
996 return id
->get_name();
998 // this assignment belongs to an instantiation of a parameterized
999 // assignment: use the name of the parent scope to obtain genname
1000 string
genname_asn("@");
1001 genname_asn
+= my_scope
->get_scope_name();
1002 const string
& id_dispname
= id
->get_dispname();
1003 bool is_parass
= id_dispname
.find('.') == id_dispname
.size();
1005 // the assignment has a normal identifier:
1006 // it represents a formal parameter -> actual parameter binding
1007 // the id (which is the dummy reference) must be used to get a
1010 genname_asn
+= id_dispname
;
1012 // otherwise the assignment represents an instance of the parameterized
1013 // assignment itself: the scope name can be used alone as genname
1014 string
ret_val(Identifier::asn_2_name(genname_asn
));
1015 // in case of parameter assignments a suffix is appended to avoid name
1016 // clash with the embedded settings of the same instantiation
1017 if (is_parass
) ret_val
+= "_par_";
1022 Assignment
* Assignment::new_instance0()
1024 // Classes derived from Assignment must implement new_instance0.
1025 // See Asn::Ass_*::new_instance0
1026 FATAL_ERROR("Asn::Assignment::new_instance0()");
1030 Assignment::Assignment(asstype_t p_asstype
, Identifier
*p_id
,
1031 Ass_pard
*p_ass_pard
)
1032 : Common::Assignment(p_asstype
, p_id
),
1033 ass_pard(p_ass_pard
), dontgen(false)
1035 if(ass_pard
) ass_pard
->set_my_ass(this);
1038 Assignment::~Assignment()
1043 bool Assignment::is_asstype(asstype_t p_asstype
, ReferenceChain
* refch
)
1045 bool destroy_refch
=false;
1047 refch
=new ReferenceChain(this, "While examining kind of assignment");
1049 } else refch
->mark_state();
1050 bool b
=(p_asstype
==asstype
);
1051 if(!refch
->add(get_fullname())) b
=p_asstype
==A_ERROR
;
1052 if(destroy_refch
) delete refch
;
1053 else refch
->prev_state();
1057 Assignment
* Assignment::new_instance(Common::Module
*p_mod
)
1060 error("`%s' is not a parameterized assignment",
1061 get_fullname().c_str());
1064 Assignment
*new_ass
=new_instance0();
1065 delete new_ass
->id
; // it was just a temporary, containing "<error>"
1066 string
new_name(id
->get_asnname());
1068 new_name
+= p_mod
->get_modid().get_asnname();
1069 new_name
+= ".inst";
1070 new_name
+= Int2string(ass_pard
->new_instnum(p_mod
));
1071 new_ass
->id
=new Identifier(Identifier::ID_ASN
, new_name
);
1075 Type
* Assignment::get_Type()
1077 error("`%s' is not a type assignment", get_fullname().c_str());
1081 Value
* Assignment::get_Value()
1083 error("`%s' is not a value assignment", get_fullname().c_str());
1087 ValueSet
* Assignment::get_ValueSet()
1089 error("`%s' is not a valueset assignment", get_fullname().c_str());
1093 ObjectClass
* Assignment::get_ObjectClass()
1095 error("`%s' is not a objectclass assignment", get_fullname().c_str());
1099 Object
* Assignment::get_Object()
1101 error("`%s' is not a object assignment", get_fullname().c_str());
1105 ObjectSet
* Assignment::get_ObjectSet()
1107 error("`%s' is not a objectset assignment", get_fullname().c_str());
1111 void Assignment::chk()
1114 ass_pard
->get_nof_pars();
1118 DEBUG(7, "`%s' assignment not checked.", get_fullname().c_str());
1121 void Assignment::dump(unsigned level
) const
1123 DEBUG(level
, "Assignment(%d): %s%s", get_asstype(),
1124 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1127 // =================================
1129 // =================================
1131 Ass_Undef::Ass_Undef(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1132 Node
*p_left
, Node
*p_right
)
1133 : Assignment(A_UNDEF
, p_id
, p_ass_pard
),
1134 left(p_left
), right(p_right
), right_scope(0), ass(0)
1137 FATAL_ERROR("NULL parameter: Asn::Ass_Undef::Ass_Undef()");
1140 Ass_Undef::Ass_Undef(const Ass_Undef
& p
)
1141 : Assignment(p
), right_scope(0)
1143 left
=p
.left
?p
.left
->clone():0;
1144 right
=p
.right
?p
.right
->clone():0;
1145 ass
=p
.ass
?p
.ass
->clone():0;
1148 Ass_Undef::~Ass_Undef()
1155 Assignment
* Ass_Undef::clone() const
1157 if(ass
) return ass
->clone();
1158 else return new Ass_Undef(*this);
1161 Assignment
* Ass_Undef::new_instance0()
1163 if(ass
) FATAL_ERROR("Asn::Ass_Undef::new_instance0()");
1164 return new Ass_Undef
1165 (new Identifier(Identifier::ID_ASN
, string("<error>")),
1166 0, left
?left
->clone():0, right
->clone());
1169 Assignment::asstype_t
Ass_Undef::get_asstype() const
1171 const_cast<Ass_Undef
*>(this)->classify_ass();
1175 void Ass_Undef::set_fullname(const string
& p_fullname
)
1177 Assignment::set_fullname(p_fullname
);
1178 if (left
) left
->set_fullname(p_fullname
);
1179 if (right
) right
->set_fullname(p_fullname
);
1180 if (ass
) ass
->set_fullname(p_fullname
);
1183 void Ass_Undef::set_my_scope(Scope
*p_scope
)
1185 Assignment::set_my_scope(p_scope
);
1186 if(ass
) ass
->set_my_scope(p_scope
);
1187 right_scope
=p_scope
;
1190 void Ass_Undef::set_right_scope(Scope
*p_scope
)
1192 if(ass
) ass
->set_right_scope(p_scope
);
1193 right_scope
=p_scope
;
1196 bool Ass_Undef::is_asstype(asstype_t p_asstype
, ReferenceChain
* refch
)
1198 classify_ass(refch
);
1199 return asstype
!= A_ERROR
? ass
->is_asstype(p_asstype
, refch
) : false;
1202 Ass_pard
* Ass_Undef::get_ass_pard() const
1205 return ass
->get_ass_pard();
1210 bool Ass_Undef::_error_if_pard()
1213 error("`%s' is a parameterized assignment", get_fullname().c_str());
1219 Setting
* Ass_Undef::get_Setting()
1221 if(_error_if_pard()) return 0;
1223 return ass
->get_Setting();
1226 Type
* Ass_Undef::get_Type()
1228 if(_error_if_pard()) return 0;
1230 return ass
->get_Type();
1233 Value
* Ass_Undef::get_Value()
1235 if(_error_if_pard()) return 0;
1237 return ass
->get_Value();
1240 ValueSet
* Ass_Undef::get_ValueSet()
1242 if(_error_if_pard()) return 0;
1244 return ass
->get_ValueSet();
1247 ObjectClass
* Ass_Undef::get_ObjectClass()
1249 if(_error_if_pard()) return 0;
1251 return ass
->get_ObjectClass();
1254 Object
* Ass_Undef::get_Object()
1256 if(_error_if_pard()) return 0;
1258 return ass
->get_Object();
1261 ObjectSet
* Ass_Undef::get_ObjectSet()
1263 if(_error_if_pard()) return 0;
1265 return ass
->get_ObjectSet();
1268 void Ass_Undef::chk()
1272 ass_pard
->get_nof_pars();
1281 void Ass_Undef::generate_code(output_struct
*target
, bool)
1283 if (ass_pard
|| dontgen
) return;
1285 ass
->generate_code(target
);
1288 void Ass_Undef::generate_code(CodeGenHelper
& cgh
) {
1289 if (ass_pard
|| dontgen
) return;
1291 ass
->generate_code(cgh
);
1294 void Ass_Undef::dump(unsigned level
) const
1299 DEBUG(level
, "Undef assignment: %s%s",
1300 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1304 void Ass_Undef::classify_ass(ReferenceChain
*refch
)
1306 if(asstype
!=A_UNDEF
) return;
1307 bool destroy_refch
=false;
1309 refch
=new ReferenceChain(this, "While examining kind of assignment");
1311 } else refch
->mark_state();
1313 Error_Context
ec_backup(1);
1314 Error_Context
cntxt(this, "In assignment `%s'",
1315 id
->get_dispname().c_str());
1317 /* temporary pointers */
1319 Reference
*t_ref2
=0;
1322 if(!refch
->add(get_fullname()))
1324 if((t_ref
=dynamic_cast<Reference
*>(left
))) {
1325 t_ref
->set_my_scope(my_scope
);
1326 if(t_ref
->refers_to_st(Setting::S_ERROR
, refch
))
1329 if((t_ref
=dynamic_cast<Reference
*>(right
))) {
1330 t_ref
->set_my_scope(right_scope
);
1332 if(t_ref->refers_to_st(Setting::S_ERROR, refch))
1333 t_ref->error("Cannot recognize assignment `%s'",
1334 t_ref->get_dispname().c_str());
1338 if(id
->isvalid_asn_objclassref()
1340 && (t_ref
=dynamic_cast<Ref_defd
*>(right
))
1341 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1343 ass
=new Ass_OC(id
->clone(), ass_pard
, new OC_refd(t_ref
));
1348 else if(id
->isvalid_asn_typeref()
1350 && (t_ref
=dynamic_cast<Ref_defd
*>(right
))
1351 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1352 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1354 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1355 t_type
->set_location(*t_ref
);
1356 ass
=new Ass_T(id
->clone(), ass_pard
, t_type
);
1361 else if(id
->isvalid_asn_objsetref()
1362 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1363 && (t_block
=dynamic_cast<Block
*>(right
))
1364 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1366 ass
=new Ass_OS(id
->clone(), ass_pard
,
1367 new OC_refd(t_ref
), new OS_defn(t_block
));
1373 else if(id
->isvalid_asn_valsetref()
1374 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1375 && (t_block
=dynamic_cast<Block
*>(right
))
1376 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1377 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1379 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1380 t_type
->set_location(*t_ref
);
1381 ass
=new Ass_VS(id
->clone(), ass_pard
, t_type
, t_block
);
1387 else if(id
->isvalid_asn_objref()
1388 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1389 && ((t_block
=dynamic_cast<Block
*>(right
))
1390 || (t_ref2
=dynamic_cast<Reference
*>(right
)))
1391 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1393 OC_refd
*t_oc
=new OC_refd(t_ref
);
1394 t_oc
->set_location(*t_ref
);
1396 Obj_defn
*t_obj
=new Obj_defn(t_block
);
1397 t_obj
->set_location(*t_block
);
1398 ass
=new Ass_O(id
->clone(), ass_pard
, t_oc
, t_obj
);
1401 Obj_refd
*t_obj
=new Obj_refd(t_ref2
);
1402 t_obj
->set_location(*t_ref2
);
1403 ass
=new Ass_O(id
->clone(), ass_pard
, t_oc
, t_obj
);
1410 else if(id
->isvalid_asn_valref()
1411 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1412 && ((t_block
=dynamic_cast<Block
*>(right
))
1413 || (t_ref2
=dynamic_cast<Reference
*>(right
)))
1414 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1415 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1417 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1418 t_type
->set_location(*t_ref
);
1420 Value
*t_value
=new Value(Value::V_UNDEF_BLOCK
, t_block
);
1421 t_value
->set_location(*t_block
);
1422 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_value
);
1425 Ref_defd_simple
*t_ref3
=dynamic_cast<Ref_defd_simple
*>(t_ref2
);
1426 if(t_ref3
&& !t_ref3
->get_modid()) {
1427 Value
*t_val
=new Value(Value::V_UNDEF_LOWERID
,
1428 t_ref3
->get_id()->clone());
1429 t_val
->set_location(*t_ref3
);
1430 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_val
);
1434 Value
*t_val
=new Value(Value::V_REFD
, t_ref2
);
1435 t_val
->set_location(*t_ref2
);
1436 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_val
);
1449 error("Cannot recognize assignment");
1450 ass
= new Ass_Error(id
->clone(), ass_pard
);
1453 ass
->set_location(*this);
1454 ass
->set_my_scope(my_scope
);
1455 ass
->set_right_scope(right_scope
);
1456 ass
->set_fullname(get_fullname());
1457 if(destroy_refch
) delete refch
;
1458 else refch
->prev_state();
1461 // =================================
1463 // =================================
1465 Ass_Error::Ass_Error(Identifier
*p_id
, Ass_pard
*p_ass_pard
)
1466 : Assignment(A_ERROR
, p_id
, p_ass_pard
),
1467 setting_error(0), type_error(0), value_error(0)
1471 Ass_Error::~Ass_Error()
1473 delete setting_error
;
1478 Assignment
* Ass_Error::clone() const
1480 return new Ass_Error(id
->clone(), ass_pard
);
1483 Assignment
* Ass_Error::new_instance0()
1485 return new Ass_Error
1486 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0);
1489 bool Ass_Error::is_asstype(asstype_t p_asstype
, ReferenceChain
*)
1491 return p_asstype
==A_ERROR
;
1494 Setting
* Ass_Error::get_Setting()
1497 setting_error
= new Common::Setting_Error();
1498 return setting_error
;
1501 Type
* Ass_Error::get_Type()
1504 type_error
= new Type(Type::T_ERROR
);
1508 Value
* Ass_Error::get_Value()
1511 value_error
= new Value(Value::V_ERROR
);
1515 ValueSet
* Ass_Error::get_ValueSet()
1517 FATAL_ERROR("Ass_Error::get_ValueSet()");
1521 ObjectClass
* Ass_Error::get_ObjectClass()
1523 FATAL_ERROR("Ass_Error::get_ObjectClass()");
1527 Object
* Ass_Error::get_Object()
1529 FATAL_ERROR("Ass_Error::get_Object()");
1533 ObjectSet
* Ass_Error::get_ObjectSet()
1535 FATAL_ERROR("Ass_Error::get_ObjectSet()");
1539 void Ass_Error::chk()
1544 void Ass_Error::dump(unsigned level
) const
1546 DEBUG(level
, "Erroneous assignment: %s%s",
1547 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1550 // =================================
1552 // =================================
1554 Ass_T::Ass_T(Identifier
*p_id
, Ass_pard
*p_ass_pard
, Type
*p_right
)
1555 : Assignment(A_TYPE
, p_id
, p_ass_pard
)
1558 FATAL_ERROR("NULL parameter: Asn::Ass_T::Ass_T()");
1559 p_right
->set_ownertype(Type::OT_TYPE_ASS
, this);
1563 Ass_T::Ass_T(const Ass_T
& p
)
1566 right
=p
.right
->clone();
1574 Assignment
* Ass_T::new_instance0()
1577 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0, right
->clone());
1580 void Ass_T::set_fullname(const string
& p_fullname
)
1582 Assignment::set_fullname(p_fullname
);
1583 right
->set_fullname(p_fullname
);
1586 void Ass_T::set_my_scope(Scope
*p_scope
)
1588 Assignment::set_my_scope(p_scope
);
1589 right
->set_my_scope(p_scope
);
1592 void Ass_T::set_right_scope(Scope
*p_scope
)
1594 right
->set_my_scope(p_scope
);
1597 Type
* Ass_T::get_Type()
1600 error("`%s' is a parameterized type assignment",
1601 get_fullname().c_str());
1610 if (checked
) return;
1612 Error_Context
cntxt(this, "In type assignment `%s'",
1613 id
->get_dispname().c_str());
1615 ass_pard
->get_nof_pars();
1619 right
->set_genname(get_genname());
1621 ReferenceChain
refch(right
, "While checking embedded recursions");
1622 right
->chk_recursions(refch
);
1625 void Ass_T::generate_code(output_struct
*target
, bool)
1627 right
->generate_code(target
);
1630 void Ass_T::generate_code(CodeGenHelper
& cgh
) {
1631 if (ass_pard
|| dontgen
) return;
1632 generate_code(cgh
.get_outputstruct(right
));
1633 cgh
.finalize_generation(right
);
1636 void Ass_T::dump(unsigned level
) const
1638 DEBUG(level
, "Type assignment: %s%s",
1639 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1646 // =================================
1648 // =================================
1650 Ass_V::Ass_V(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1651 Type
*p_left
, Value
*p_right
)
1652 : Assignment(A_CONST
, p_id
, p_ass_pard
)
1654 if(!p_left
|| !p_right
)
1655 FATAL_ERROR("NULL parameter: Asn::Ass_V::Ass_V()");
1657 left
->set_ownertype(Type::OT_VAR_ASS
, this);
1661 Ass_V::Ass_V(const Ass_V
& p
)
1664 left
=p
.left
->clone();
1665 right
=p
.right
->clone();
1674 Assignment
* Ass_V::new_instance0()
1677 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
1678 left
->clone(), right
->clone());
1681 void Ass_V::set_fullname(const string
& p_fullname
)
1683 Assignment::set_fullname(p_fullname
);
1684 left
->set_fullname(p_fullname
+ ".<type>");
1685 right
->set_fullname(p_fullname
);
1688 void Ass_V::set_my_scope(Scope
*p_scope
)
1690 Assignment::set_my_scope(p_scope
);
1691 left
->set_my_scope(p_scope
);
1692 right
->set_my_scope(p_scope
);
1695 void Ass_V::set_right_scope(Scope
*p_scope
)
1697 right
->set_my_scope(p_scope
);
1701 Type
* Ass_V::get_Type()
1707 Value
* Ass_V::get_Value()
1710 error("`%s' is a parameterized value assignment",
1711 get_fullname().c_str());
1721 Error_Context
cntxt(this, "In value assignment `%s'",
1722 id
->get_dispname().c_str());
1724 ass_pard
->get_nof_pars();
1729 static const string
_T_("_T_");
1730 left
->set_genname(_T_
, get_genname());
1732 right
->set_my_governor(left
);
1733 left
->chk_this_value_ref(right
);
1735 left
->chk_this_value(right
, 0, Type::EXPECTED_CONSTANT
, INCOMPLETE_NOT_ALLOWED
,
1736 OMIT_NOT_ALLOWED
, SUB_CHK
, IMPLICIT_OMIT
);
1738 ReferenceChain
refch(right
, "While checking embedded recursions");
1739 right
->chk_recursions(refch
);
1741 if (!semantic_check_only
) {
1742 right
->set_genname_prefix("const_");
1743 right
->set_genname_recursive(get_genname());
1744 right
->set_code_section(GovernedSimple::CS_PRE_INIT
);
1748 void Ass_V::generate_code(output_struct
*target
, bool)
1750 if (ass_pard
|| dontgen
) return;
1751 left
->generate_code(target
);
1753 Code::init_cdef(&cdef
);
1754 left
->generate_code_object(&cdef
, right
);
1755 cdef
.init
= right
->generate_code_init(cdef
.init
,
1756 right
->get_lhs_name().c_str());
1757 Code::merge_cdef(target
, &cdef
);
1758 Code::free_cdef(&cdef
);
1761 void Ass_V::generate_code(CodeGenHelper
& cgh
) {
1762 generate_code(cgh
.get_current_outputstruct());
1765 void Ass_V::dump(unsigned level
) const
1767 DEBUG(level
, "Value assignment: %s%s",
1768 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1775 // =================================
1777 // =================================
1779 Ass_VS::Ass_VS(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1780 Type
*p_left
, Block
*p_right
)
1781 : Assignment(A_VS
, p_id
, p_ass_pard
), right_scope(0)
1783 if(!p_left
|| !p_right
)
1784 FATAL_ERROR("NULL parameter: Asn::Ass_VS::Ass_VS()");
1786 left
->set_ownertype(Type::OT_VSET_ASS
, this);
1790 Ass_VS::Ass_VS(const Ass_VS
& p
)
1791 : Assignment(p
), right_scope(0)
1793 left
=p
.left
->clone();
1794 right
=p
.right
->clone();
1803 Assignment
* Ass_VS::new_instance0()
1806 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
1807 left
->clone(), right
->clone());
1810 void Ass_VS::set_fullname(const string
& p_fullname
)
1812 Assignment::set_fullname(p_fullname
);
1813 left
->set_fullname(p_fullname
);
1814 right
->set_fullname(p_fullname
);
1817 void Ass_VS::set_my_scope(Scope
*p_scope
)
1819 Assignment::set_my_scope(p_scope
);
1820 left
->set_my_scope(p_scope
);
1823 void Ass_VS::set_right_scope(Scope
*p_scope
)
1825 right_scope
=p_scope
;
1828 Type
* Ass_VS::get_Type()
1831 error("`%s' is a parameterized value set assignment",
1832 get_fullname().c_str());
1841 if (checked
) return;
1843 Error_Context
cntxt(this, "In value set assignment `%s'",
1844 id
->get_dispname().c_str());
1846 ass_pard
->get_nof_pars();
1850 // parse the content of right and add it to left as one more constraint
1851 Node
*node
= right
->parse(KW_Block_ValueSet
);
1852 Constraint
* vs_constr
= dynamic_cast<Constraint
*>(node
);
1853 if (vs_constr
) { // if we have a constraint add it to the type
1854 if (right_scope
) { // if this is a parameter of a pard type
1855 vs_constr
->set_my_scope(right_scope
);
1857 if (!left
->get_constraints()) left
->add_constraints(new Constraints());
1858 left
->get_constraints()->add_con(vs_constr
);
1862 left
->set_genname(get_genname());
1864 ReferenceChain
refch(left
, "While checking embedded recursions");
1865 left
->chk_recursions(refch
);
1868 void Ass_VS::generate_code(output_struct
*target
, bool)
1870 left
->generate_code(target
);
1873 void Ass_VS::generate_code(CodeGenHelper
& cgh
) {
1874 if (ass_pard
|| dontgen
) return;
1875 generate_code(cgh
.get_outputstruct(left
));
1876 cgh
.finalize_generation(left
);
1879 void Ass_VS::dump(unsigned level
) const
1881 DEBUG(level
, "Value set assignment: %s%s",
1882 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1891 // =================================
1893 // =================================
1895 Ass_OC::Ass_OC(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1896 ObjectClass
*p_right
)
1897 : Assignment(A_OC
, p_id
, p_ass_pard
)
1900 FATAL_ERROR("NULL parameter: Asn::Ass_OC::Ass_OC()");
1904 Ass_OC::Ass_OC(const Ass_OC
& p
)
1907 right
=p
.right
->clone();
1915 Assignment
* Ass_OC::new_instance0()
1918 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0, right
->clone());
1921 void Ass_OC::set_fullname(const string
& p_fullname
)
1923 Assignment::set_fullname(p_fullname
);
1924 right
->set_fullname(p_fullname
);
1927 void Ass_OC::set_my_scope(Scope
*p_scope
)
1929 Assignment::set_my_scope(p_scope
);
1930 right
->set_my_scope(p_scope
);
1933 void Ass_OC::set_right_scope(Scope
*p_scope
)
1935 right
->set_my_scope(p_scope
);
1941 Error_Context
cntxt(this, "In information object class assignment `%s'",
1942 id
->get_dispname().c_str());
1944 ass_pard
->get_nof_pars();
1948 right
->set_genname(get_genname());
1953 ObjectClass
* Ass_OC::get_ObjectClass()
1956 error("`%s' is a parameterized objectclass assignment",
1957 get_fullname().c_str());
1964 void Ass_OC::generate_code(output_struct
*target
, bool)
1966 if (ass_pard
|| dontgen
) return;
1967 right
->generate_code(target
);
1970 void Ass_OC::generate_code(CodeGenHelper
& cgh
) {
1971 generate_code(cgh
.get_current_outputstruct());
1974 void Ass_OC::dump(unsigned level
) const
1976 DEBUG(level
, "ObjectClass assignment: %s%s",
1977 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1983 // =================================
1985 // =================================
1987 Ass_O::Ass_O(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1988 ObjectClass
*p_left
, Object
*p_right
)
1989 : Assignment(A_OBJECT
, p_id
, p_ass_pard
)
1991 if(!p_left
|| !p_right
)
1992 FATAL_ERROR("NULL parameter: Asn::Ass_O::Ass_O()");
1997 Ass_O::Ass_O(const Ass_O
& p
)
2000 left
=p
.left
->clone();
2001 right
=p
.right
->clone();
2010 Assignment
* Ass_O::new_instance0()
2013 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
2014 left
->clone(), right
->clone());
2017 void Ass_O::set_fullname(const string
& p_fullname
)
2019 Assignment::set_fullname(p_fullname
);
2020 left
->set_fullname(p_fullname
);
2021 right
->set_fullname(p_fullname
);
2024 void Ass_O::set_my_scope(Scope
*p_scope
)
2026 Assignment::set_my_scope(p_scope
);
2027 left
->set_my_scope(p_scope
);
2028 right
->set_my_scope(p_scope
);
2031 void Ass_O::set_right_scope(Scope
*p_scope
)
2033 right
->set_my_scope(p_scope
);
2037 ObjectClass* Ass_O::get_ObjectClass()
2043 Object
* Ass_O::get_Object()
2046 error("`%s' is a parameterized object assignment",
2047 get_fullname().c_str());
2057 Error_Context
cntxt(this, "In information object assignment `%s'",
2058 id
->get_dispname().c_str());
2060 ass_pard
->get_nof_pars();
2065 right
->set_my_governor(left
);
2066 right
->set_genname(get_genname());
2071 void Ass_O::generate_code(output_struct
*target
, bool)
2073 if (ass_pard
|| dontgen
) return;
2074 left
->generate_code(target
);
2075 right
->generate_code(target
);
2078 void Ass_O::generate_code(CodeGenHelper
& cgh
) {
2079 generate_code(cgh
.get_current_outputstruct());
2082 void Ass_O::dump(unsigned level
) const
2084 DEBUG(level
, "Object assignment: %s%s",
2085 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2092 // =================================
2094 // =================================
2096 Ass_OS::Ass_OS(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
2097 ObjectClass
*p_left
, ObjectSet
*p_right
)
2098 : Assignment(A_OS
, p_id
, p_ass_pard
)
2100 if(!p_left
|| !p_right
)
2101 FATAL_ERROR("NULL parameter: Asn::Ass_OS::Ass_OS()");
2106 Ass_OS::Ass_OS(const Ass_OS
& p
)
2109 left
=p
.left
->clone();
2110 right
=p
.right
->clone();
2119 Assignment
* Ass_OS::new_instance0()
2122 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
2123 left
->clone(), right
->clone());
2126 void Ass_OS::set_fullname(const string
& p_fullname
)
2128 Assignment::set_fullname(p_fullname
);
2129 left
->set_fullname(p_fullname
);
2130 right
->set_fullname(p_fullname
);
2133 void Ass_OS::set_my_scope(Scope
*p_scope
)
2135 Assignment::set_my_scope(p_scope
);
2136 left
->set_my_scope(p_scope
);
2137 right
->set_my_scope(p_scope
);
2140 void Ass_OS::set_right_scope(Scope
*p_scope
)
2142 right
->set_my_scope(p_scope
);
2146 ObjectClass* Ass_OS::get_ObjectClass()
2152 ObjectSet
* Ass_OS::get_ObjectSet()
2155 error("`%s' is a parameterized objectset assignment",
2156 get_fullname().c_str());
2166 Error_Context
cntxt(this, "In information object set assignment `%s'",
2167 id
->get_dispname().c_str());
2169 ass_pard
->get_nof_pars();
2174 right
->set_my_governor(left
);
2175 right
->set_genname(get_genname());
2180 void Ass_OS::generate_code(output_struct
*target
, bool)
2182 if (ass_pard
|| dontgen
) return;
2183 left
->generate_code(target
);
2184 right
->generate_code(target
);
2187 void Ass_OS::generate_code(CodeGenHelper
& cgh
) {
2188 generate_code(cgh
.get_current_outputstruct());
2191 void Ass_OS::dump(unsigned level
) const
2193 DEBUG(level
, "ObjectSet assignment: %s%s",
2194 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2201 // =================================
2203 // =================================
2205 // =================================
2207 // =================================
2209 const Identifier
* Ref_defd::get_modid()
2211 Ref_defd_simple
*t_ref
= get_ref_defd_simple();
2212 if (t_ref
) return t_ref
->get_modid();
2216 const Identifier
* Ref_defd::get_id()
2218 Ref_defd_simple
*t_ref
= get_ref_defd_simple();
2219 if (t_ref
) return t_ref
->get_id();
2223 bool Ref_defd::refers_to_st(Setting::settingtype_t p_st
,
2224 ReferenceChain
* refch
)
2226 if(get_is_erroneous()) return p_st
==Setting::S_ERROR
;
2228 Error_Context
cntxt(this, "In reference `%s'", get_dispname().c_str());
2230 FATAL_ERROR("NULL parameter");
2231 Common::Assignment
* c_ass
=my_scope
->get_ass_bySRef(this);
2236 Assignment
* ass
=dynamic_cast<Assignment
*>(c_ass
);
2238 error("Reference to a non-ASN setting");
2244 b
=ass
->is_asstype(Assignment::A_OC
, refch
);
2247 b
=ass
->is_asstype(Assignment::A_TYPE
, refch
);
2250 b
=ass
->is_asstype(Assignment::A_OBJECT
, refch
);
2253 b
=ass
->is_asstype(Assignment::A_CONST
, refch
);
2256 b
=ass
->is_asstype(Assignment::A_OS
, refch
);
2259 b
=ass
->is_asstype(Assignment::A_VS
, refch
);
2261 case Setting::S_ERROR
:
2262 b
=ass
->is_asstype(Assignment::A_ERROR
, refch
);
2265 FATAL_ERROR("Asn::Ref_defd::refers_to_st()");
2270 void Ref_defd::generate_code(expression_struct_t
*)
2272 FATAL_ERROR("Ref_defd::generate_code()");
2275 void Ref_defd::generate_code_const_ref(expression_struct */
*expr*/
)
2277 FATAL_ERROR("Ref_defd::generate_code_const_ref()");
2280 // =================================
2281 // ===== Ref_defd_simple
2282 // =================================
2284 Ref_defd_simple::Ref_defd_simple(Identifier
*p_modid
,
2286 : Ref_defd(), modid(p_modid
), id(p_id
)
2289 FATAL_ERROR("NULL parameter: Asn::Ref_defd_simple::Ref_defd_simple()");
2292 Ref_defd_simple::Ref_defd_simple(const Ref_defd_simple
& p
)
2295 modid
=p
.modid
?p
.modid
->clone():0;
2299 Ref_defd_simple::~Ref_defd_simple()
2305 Assignment
* Ref_defd_simple::get_refd_ass()
2307 if(get_is_erroneous()) return 0;
2308 Error_Context
cntxt(this, "In reference `%s'", get_dispname().c_str());
2310 FATAL_ERROR("NULL parameter: Asn::Ref_defd_simple::get_refd_ass():"
2311 " my_scope is not set");
2312 Common::Assignment
* c_ass
=my_scope
->get_ass_bySRef(this);
2313 if(!c_ass
) return 0;
2314 Assignment
* ass
=dynamic_cast<Assignment
*>(c_ass
);
2316 this->error("Reference to a non-ASN assignment");
This page took 0.083732 seconds and 5 git commands to generate.