1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
17 * Zalanyi, Balazs Andor
20 ******************************************************************************/
21 #include "AST_asn1.hh"
22 #include "../Identifier.hh"
23 #include "../CompilerError.hh"
25 #include "TokenBuf.hh" // Ass_pard needs that
26 #include "../Value.hh"
29 #include "../CodeGenHelper.hh"
30 #include "../../common/JSON_Tokenizer.hh"
31 #include "../DebuggerStuff.hh"
33 /* defined in asn1p.y */
34 extern int asn1_parse_string(const char* p_str
);
36 extern Common::Modules
*modules
; // in main.cc
40 Module
*Assignments::_spec_asss
=0;
41 Assignments
*parsed_assignments
;
43 // =================================
45 // =================================
48 for (size_t i
= 0; i
< syms_v
.size(); i
++) delete syms_v
[i
];
53 Symbols
* Symbols::clone() const
55 FATAL_ERROR("Asn::Symbols::clone()");
59 void Symbols::add_sym(Identifier
*p_id
)
62 FATAL_ERROR("NULL parameter: Asn::Symbols::add_sym()");
66 void Symbols::chk_uniq(const Location
& p_loc
)
68 for(size_t i
=0; i
<syms_v
.size(); i
++) {
69 Identifier
*id
= syms_v
[i
];
70 const string
& name
= id
->get_name();
71 if (syms_m
.has_key(name
)) {
72 p_loc
.error("Duplicate identifier in SymbolList: `%s'",
73 id
->get_dispname().c_str());
74 } else syms_m
.add(name
, id
);
78 // =================================
80 // =================================
82 Exports::Exports(bool p_expall
)
83 : Node(), Location(), checked(false), my_mod(0), expall(p_expall
),
84 symbols(expall
? 0 : new Symbols())
87 Exports::Exports(Symbols
*p_symlist
)
88 : Node(), Location(), checked(false), my_mod(0), expall(false),
89 symbols(p_symlist
? p_symlist
: new Symbols())
97 Exports
* Exports::clone() const
99 FATAL_ERROR("Asn::Exports::clone()");
103 bool Exports::exports_sym(const Identifier
& p_id
)
105 if(!checked
) chk_exp();
106 if (expall
) return true;
107 else return symbols
->syms_m
.has_key(p_id
.get_name());
110 void Exports::chk_exp()
114 Ref_defd_simple
*ref
=0;
115 Error_Context
cntxt(this, "In EXPORTS of module `%s'",
116 my_mod
->get_modid().get_dispname().c_str());
117 symbols
->chk_uniq(*this);
118 for(size_t i
=0; i
<symbols
->syms_m
.size(); i
++) {
119 ref
=new Ref_defd_simple(0, symbols
->syms_m
.get_nth_elem(i
)->clone());
120 /* check whether exists or not */
121 my_mod
->get_ass_bySRef(ref
);
127 // =================================
129 // =================================
131 ImpMod::ImpMod(Identifier
*p_modid
, Symbols
*p_symlist
)
132 : Node(), Location(), my_mod(0), modid(p_modid
), mod(0)
135 FATAL_ERROR("NULL parameter: Asn::ImpMod::ImpMod()");
136 set_fullname("<imports>."+modid
->get_dispname());
137 symbols
= p_symlist
? p_symlist
: new Symbols();
146 ImpMod
* ImpMod::clone() const
148 FATAL_ERROR("Asn::ImpMod::clone()");
152 bool ImpMod::has_sym(const Identifier
& p_id
) const
154 return symbols
->syms_m
.has_key(p_id
.get_name());
157 void ImpMod::chk_imp(ReferenceChain
& refch
)
160 FATAL_ERROR("Asn::ImpMod::chk_imp(): my_mod is NULL");
161 Common::Module
*m
=modules
->get_mod_byId(*modid
);
162 symbols
->chk_uniq(*this);
163 vector
<Common::Module
> modules
;
164 m
->chk_imp(refch
, modules
);
166 if(m
->get_gen_code()) my_mod
->set_gen_code();
167 for(size_t i
=0; i
<symbols
->syms_m
.size(); i
++) {
168 const Identifier
*id
=symbols
->syms_m
.get_nth_elem(i
);
169 Ref_defd_simple
ref(0, new Identifier(*id
));
170 ref
.set_location(*this);
172 if(!m
->get_ass_bySRef(&ref
)) err
=true;
173 if(!err
&& !m
->exports_sym(*id
)) {
174 error("Symbol `%s' is not exported from module `%s'",
175 id
->get_dispname().c_str(),
176 m
->get_modid().get_dispname().c_str());
177 /* to avoid more error messages do not set err to true */
181 symbols
->syms_m
.erase(symbols
->syms_m
.get_nth_key(i
));
182 // do not delete id; it is stored in the vector
188 void ImpMod::generate_code(output_struct
*target
)
190 const char *module_name
= modid
->get_name().c_str();
192 target
->header
.includes
= mputprintf(target
->header
.includes
,
193 "#include \"%s.hh\"\n",
194 duplicate_underscores
? module_name
: modid
->get_ttcnname().c_str());
196 target
->functions
.pre_init
= mputprintf(target
->functions
.pre_init
,
197 "%s%s.pre_init_module();\n", module_name
,
201 // =================================
203 // =================================
207 for(size_t i
=0; i
<impmods_v
.size(); i
++)
215 Imports
* Imports::clone() const
217 FATAL_ERROR("Asn::Imports::clone()");
221 void Imports::add_impmod(ImpMod
*p_impmod
)
224 FATAL_ERROR("NULL parameter: Asn::Imports::add_impmod(): my_mod is NULL");
225 impmods_v
.add(p_impmod
);
226 p_impmod
->set_my_mod(my_mod
);
229 void Imports::set_my_mod(Module
*p_mod
)
232 for(size_t i
=0; i
<impmods_v
.size(); i
++)
233 impmods_v
[i
]->set_my_mod(my_mod
);
236 void Imports::chk_imp(ReferenceChain
& refch
)
240 if (impmods_v
.size() <= 0) return;
242 if (!my_mod
) FATAL_ERROR("Asn::Imports::chk_imp()");
244 for (size_t n
= 0; n
< impmods_v
.size(); n
++) {
245 ImpMod
*im
= impmods_v
[n
];
246 const Identifier
& im_id
= im
->get_modid();
247 Error_Context
cntxt(this, "In IMPORTS FROM `%s'",
248 im_id
.get_dispname().c_str());
249 if (!modules
->has_mod_withId(im_id
)) {
250 im
->error("There is no module with identifier `%s'",
251 im_id
.get_dispname().c_str());
254 Common::Module
*m
= modules
->get_mod_byId(im_id
);
256 if (m
->get_moduletype() != Module::MOD_ASN
) {
257 im
->error("An ASN.1 module cannot import from a TTCN-3 module");
260 else if (m
== my_mod
) {
261 im
->error("A module cannot import from itself");
264 // check the imports recursively
268 // detect circular imports
269 if (!is_circular
&& m
->is_visible(my_mod
)) is_circular
= true;
270 const string
& im_name
= im_id
.get_name();
271 if (impmods
.has_key(im_name
)) {
272 const char *dispname_str
= im_id
.get_dispname().c_str();
273 im
->error("Duplicate import from module `%s'", dispname_str
);
274 impmods
[im_name
]->note("Previous import from `%s' is here",
276 } else impmods
.add(im_name
, im
);
277 Symbols
*syms
= im
->symbols
;
278 for (size_t i
=0; i
<syms
->syms_m
.size(); i
++) {
279 const Identifier
*id
= syms
->syms_m
.get_nth_elem(i
);
280 const string
& key
= id
->get_name();
281 if(impsyms_1
.has_key(key
)) {
282 if(impsyms_1
[key
]!=m
) {
283 impsyms_1
.erase(key
);
284 impsyms_m
.add(key
, 0);
287 else if(!impsyms_m
.has_key(key
)) {
288 impsyms_1
.add(key
, m
);
294 bool Imports::has_impsym_withId(const Identifier
& p_id
) const
296 if (!checked
) FATAL_ERROR("Imports::has_impsym_withId()");
297 const string
& name
= p_id
.get_name();
298 return impsyms_1
.has_key(name
) || impsyms_m
.has_key(name
);
301 void Imports::get_imported_mods(Module::module_set_t
& p_imported_mods
)
303 for (size_t i
= 0; i
< impmods_v
.size(); i
++) {
304 Common::Module
*m
= impmods_v
[i
]->get_mod();
306 if (!p_imported_mods
.has_key(m
)) {
307 p_imported_mods
.add(m
, 0);
308 m
->get_visible_mods(p_imported_mods
);
313 void Imports::generate_code(output_struct
*target
)
315 target
->header
.includes
= mputstr(target
->header
.includes
,
316 "#include <TTCN3.hh>\n");
317 for (size_t i
= 0; i
< impmods_v
.size(); i
++) {
318 ImpMod
*im
= impmods_v
[i
];
319 Common::Module
*m
= im
->get_mod();
320 // inclusion of m's header file can be eliminated if we find another
321 // imported module that imports m
322 bool covered
= false;
323 for (size_t j
= 0; j
< impmods_v
.size(); j
++) {
324 // skip over the same import definition
325 if (j
== i
) continue;
326 Common::Module
*m2
= impmods_v
[j
]->get_mod();
327 // a module that is equivalent to the current module due to
328 // circular imports cannot be used to cover anything
329 if (m2
->is_visible(my_mod
)) continue;
330 if (m2
->is_visible(m
) && !m
->is_visible(m2
)) {
331 // m2 covers m (i.e. m is visible from m2)
332 // and they are not in the same import loop
337 // do not generate the #include if a covering module is found
338 if (!covered
) im
->generate_code(target
);
342 // =================================
344 // =================================
346 Module::Module(Identifier
*p_modid
, TagDefault::tagdef_t p_tagdef
,
347 bool p_extens_impl
, Exports
*p_exp
, Imports
*p_imp
,
349 : Common::Module(MOD_ASN
, p_modid
), tagdef(p_tagdef
),
350 extens_impl(p_extens_impl
), exp(p_exp
), imp(p_imp
), asss(p_asss
)
352 if (!p_exp
|| !p_imp
|| !p_asss
)
353 FATAL_ERROR("NULL parameter: Asn::Module::Module()");
354 if(!p_modid
->isvalid_asn_modref()
355 && p_modid
->get_dispname()!="<internal>")
356 error("`%s' is not a valid module identifier",
357 p_modid
->get_dispname().c_str());
358 asss
->set_parent_scope(this);
359 exp
->set_my_mod(this);
360 imp
->set_my_mod(this);
370 Module
*Module::clone() const
372 FATAL_ERROR("Asn::Module::clone");
376 Common::Assignment
*Module::importAssignment(
377 const Identifier
& p_source_modid
, const Identifier
& p_id
) const
379 (void)p_source_modid
;
380 if (asss
->has_local_ass_withId(p_id
)) {
381 return asss
->get_local_ass_byId(p_id
);
385 void Module::set_fullname(const string
& p_fullname
)
387 Common::Module::set_fullname(p_fullname
);
388 exp
->set_fullname(p_fullname
+".<exports>");
389 imp
->set_fullname(p_fullname
+".<imports>");
390 asss
->set_fullname(p_fullname
);
393 Common::Assignments
*Module::get_scope_asss()
398 bool Module::has_imported_ass_withId(const Identifier
& p_id
)
400 return imp
->has_impsym_withId(p_id
);
403 Common::Assignment
* Module::get_ass_bySRef(Ref_simple
*p_ref
)
405 const Identifier
*r_modid
= p_ref
->get_modid();
406 const Identifier
*r_id
= p_ref
->get_id();
408 // return NULL if the reference is erroneous
411 Common::Module
*r_mod
=0;
413 if(!r_modid
|| *r_modid
==*modid
) {
414 if(asss
->has_local_ass_withId(*r_id
))
415 return asss
->get_local_ass_byId(*r_id
);
417 p_ref
->error("There is no assignment with name `%s'"
418 " in module `%s'", r_id
->get_dispname().c_str(),
419 modid
->get_dispname().c_str());
422 if(imp
->impsyms_1
.has_key(r_id
->get_name()))
423 r_mod
=imp
->impsyms_1
[r_id
->get_name()];
424 else if(imp
->impsyms_m
.has_key(r_id
->get_name())) {
425 p_ref
->error("There are more imported symbols with name `%s'"
426 " in module `%s'", r_id
->get_dispname().c_str(),
427 modid
->get_dispname().c_str());
431 p_ref
->error("There is no assignment or imported symbol"
432 " with name `%s' in module `%s'",
433 r_id
->get_dispname().c_str(),
434 modid
->get_dispname().c_str());
439 if(!imp
->has_impmod_withId(*r_modid
)) {
440 p_ref
->error("There is no imported module with name `%s'",
441 r_modid
->get_dispname().c_str());
444 if(!imp
->get_impmod_byId(*r_modid
)->has_sym(*r_id
)) {
445 p_ref
->error("There is no symbol with name `%s'"
446 " imported from module `%s'",
447 r_id
->get_dispname().c_str(),
448 r_modid
->get_dispname().c_str());
451 r_mod
=modules
->get_mod_byId(*r_modid
);
453 Ref_defd_simple
t_ref(0, r_id
->clone());
454 return r_mod
->get_ass_bySRef(&t_ref
);
457 Assignments
*Module::get_asss()
462 bool Module::exports_sym(const Identifier
& p_id
)
464 return exp
->exports_sym(p_id
);
467 void Module::chk_imp(ReferenceChain
& refch
, vector
<Common::Module
>& /*moduleStack*/)
469 if (imp_checked
) return;
470 const string
& module_name
= modid
->get_dispname();
471 if (refch
.exists(module_name
)) {
472 // Do not warning for circular import in ASN.1 module. It is legal
473 // warning("Circular import chain is not recommended: %s",
474 // refch.get_dispstr(module_name).c_str());
477 refch
.add(module_name
);
478 Error_Context backup
;
479 Error_Context
cntxt(this, "In ASN.1 module `%s'", module_name
.c_str());
483 collect_visible_mods();
488 DEBUG(1, "Checking ASN.1 module `%s'", modid
->get_dispname().c_str());
489 Error_Context
cntxt(this, "In ASN.1 module `%s'",
490 modid
->get_dispname().c_str());
496 void Module::get_imported_mods(module_set_t
& p_imported_mods
)
498 imp
->get_imported_mods(p_imported_mods
);
501 bool Module::has_circular_import()
503 return imp
->get_is_circular();
506 void Module::generate_code_internal(CodeGenHelper
& cgh
) {
507 imp
->generate_code(cgh
.get_current_outputstruct());
508 asss
->generate_code(cgh
);
511 void Module::dump(unsigned level
) const
513 DEBUG(level
, "ASN.1 module: %s", modid
->get_dispname().c_str());
514 asss
->dump(level
+ 1);
517 void Module::add_ass(Assignment
*p_ass
)
519 asss
->add_ass(p_ass
);
522 void Module::generate_json_schema(JSON_Tokenizer
& json
, map
<Type
*, JSON_Tokenizer
>& json_refs
)
524 // add a new property for this module
525 json
.put_next_token(JSON_TOKEN_NAME
, modid
->get_ttcnname().c_str());
527 // add type definitions into an object
528 json
.put_next_token(JSON_TOKEN_OBJECT_START
);
530 // cycle through all type assignments, insert schema segments and references
532 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
533 Asn::Assignment
* asn_ass
= dynamic_cast<Asn::Assignment
*>(asss
->get_ass_byIndex(i
));
534 if (asn_ass
== NULL
|| asn_ass
->get_ass_pard() != NULL
) {
535 // skip parameterized types
538 if (Common::Assignment::A_TYPE
== asn_ass
->get_asstype()) {
539 Type
* t
= asn_ass
->get_Type();
540 // skip instances of parameterized types
541 if (!t
->is_pard_type_instance() && t
->has_encoding(Type::CT_JSON
)) {
542 // insert type's schema segment
543 t
->generate_json_schema(json
, false, false);
545 if (json_refs_for_all_types
&& !json_refs
.has_key(t
)) {
546 // create JSON schema reference for the type
547 JSON_Tokenizer
* json_ref
= new JSON_Tokenizer
;
548 json_refs
.add(t
, json_ref
);
549 t
->generate_json_schema_ref(*json_ref
);
555 // end of type definitions
556 json
.put_next_token(JSON_TOKEN_OBJECT_END
);
559 void Module::generate_debugger_init(output_struct
*output
)
561 // no debugging in ASN.1 modules
564 char* Module::generate_debugger_global_vars(char* str
, Common::Module
* current_mod
)
566 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
567 Asn::Assignment
* asn_ass
= dynamic_cast<Asn::Assignment
*>(asss
->get_ass_byIndex(i
));
568 if (asn_ass
->get_ass_pard() != NULL
) {
569 // this check must be done before get_asstype() is called
572 if (asn_ass
->get_asstype() == Common::Assignment::A_CONST
) {
573 str
= generate_code_debugger_add_var(str
, asn_ass
, current_mod
, "global");
579 void Module::generate_debugger_functions(output_struct
*output
)
581 char* print_str
= NULL
;
582 char* overwrite_str
= NULL
;
583 for (size_t i
= 0; i
< asss
->get_nof_asss(); ++i
) {
584 Asn::Assignment
* asn_ass
= dynamic_cast<Asn::Assignment
*>(asss
->get_ass_byIndex(i
));
585 if (asn_ass
->get_ass_pard() != NULL
) {
586 // skip parameterized types
587 // this check must be done before get_asstype() is called
590 if (Common::Assignment::A_TYPE
== asn_ass
->get_asstype()) {
591 Type
* t
= asn_ass
->get_Type();
592 if (!t
->is_pard_type_instance() && (t
->is_structured_type() ||
593 t
->get_typetype() == Type::T_ENUM_A
||
594 (t
->is_ref() && t
->get_type_refd()->is_pard_type_instance()))) {
595 // only structured types and enums are needed
596 // for instances of parameterized types, the last reference, which is
597 // not itself an instance of a parameterized type, holds the type's display name
598 print_str
= mputprintf(print_str
,
599 " %sif (!strcmp(p_var.type_name, \"%s\")) {\n"
600 " ((const %s*)ptr)->log();\n"
602 " else if (!strcmp(p_var.type_name, \"%s template\")) {\n"
603 " ((const %s_template*)ptr)->log();\n"
605 , (print_str
!= NULL
) ? "else " : ""
606 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str()
607 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str());
608 overwrite_str
= mputprintf(overwrite_str
,
609 " %sif (!strcmp(p_var.type_name, \"%s\")) {\n"
610 " ((%s*)p_var.value)->set_param(p_new_value);\n"
612 " else if (!strcmp(p_var.type_name, \"%s template\")) {\n"
613 " ((%s_template*)p_var.value)->set_param(p_new_value);\n"
615 , (overwrite_str
!= NULL
) ? "else " : ""
616 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str()
617 , t
->get_dispname().c_str(), t
->get_genname_value(this).c_str());
621 if (print_str
!= NULL
) {
622 // don't generate an empty printing function
623 output
->header
.class_defs
= mputprintf(output
->header
.class_defs
,
624 "/* Debugger printing and overwriting functions for types declared in this module */\n\n"
625 "extern CHARSTRING print_var_%s(const TTCN3_Debugger::variable_t& p_var);\n"
626 "extern boolean set_var_%s(TTCN3_Debugger::variable_t& p_var, Module_Param& p_new_value);\n",
627 get_modid().get_ttcnname().c_str(), get_modid().get_ttcnname().c_str());
628 output
->source
.global_vars
= mputprintf(output
->source
.global_vars
,
629 "\n/* Debugger printing function for types declared in this module */\n"
630 "CHARSTRING print_var_%s(const TTCN3_Debugger::variable_t& p_var)\n"
632 " const void* ptr = p_var.set_function != NULL ? p_var.value : p_var.cvalue;\n"
633 " TTCN_Logger::begin_event_log2str();\n"
636 " TTCN_Logger::log_event_str(\"<unrecognized value or template>\");\n"
638 " return TTCN_Logger::end_event_log2str();\n"
640 "/* Debugger overwriting function for types declared in this module */\n"
641 "boolean set_var_%s(TTCN3_Debugger::variable_t& p_var, Module_Param& p_new_value)\n"
648 "}\n", get_modid().get_ttcnname().c_str(), print_str
,
649 get_modid().get_ttcnname().c_str(), overwrite_str
);
653 // =================================
655 // =================================
657 Assignments::Assignments(const Assignments
& p
)
658 : Common::Assignments(p
), checked(false)
660 for(size_t i
= 0; i
< p
.asss_v
.size(); i
++)
661 add_ass(p
.asss_v
[i
]->clone());
664 Assignments::~Assignments()
666 for (size_t i
= 0; i
< asss_v
.size(); i
++) delete asss_v
[i
];
671 Assignments
*Assignments::clone() const
673 return new Assignments(*this);
676 void Assignments::set_fullname(const string
& p_fullname
)
678 Common::Assignments::set_fullname(p_fullname
);
679 string
s(p_fullname
);
680 if (s
!= "@") s
+= '.';
681 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
682 Assignment
*ass
= asss_v
[i
];
683 ass
->set_fullname(s
+ass
->get_id().get_dispname());
687 bool Assignments::has_local_ass_withId(const Identifier
& p_id
)
689 if (!checked
) chk_uniq();
690 if (asss_m
.has_key(p_id
.get_name())) return true;
691 Assignments
*spec_asss
= _spec_asss
->get_asss();
692 if (spec_asss
!= this) return spec_asss
->has_ass_withId(p_id
);
696 Assignment
* Assignments::get_local_ass_byId(const Identifier
& p_id
)
698 if (!checked
) chk_uniq();
699 const string
& name
= p_id
.get_name();
700 if (asss_m
.has_key(name
)) return asss_m
[name
];
701 Assignments
*spec_asss
= _spec_asss
->get_asss();
702 if (spec_asss
!= this) return spec_asss
->get_local_ass_byId(p_id
);
706 size_t Assignments::get_nof_asss()
708 if (!checked
) chk_uniq();
709 return asss_m
.size();
712 Common::Assignment
* Assignments::get_ass_byIndex(size_t p_i
)
714 if (!checked
) chk_uniq();
715 return asss_m
.get_nth_elem(p_i
);
718 void Assignments::add_ass(Assignment
*p_ass
)
720 if (!p_ass
) FATAL_ERROR("Asn::Assignments::add_ass()");
722 p_ass
->set_my_scope(this);
724 const Identifier
& id
= p_ass
->get_id();
725 const string
& name
= id
.get_name();
726 if(asss_m
.has_key(name
)) {
727 const char *dispname_str
= id
.get_dispname().c_str();
728 p_ass
->error("Duplicate assignment with identifier `%s'", dispname_str
);
729 asss_m
[name
]->note("Previous assignment with identifier `%s' is here",
731 } else asss_m
.add(name
, p_ass
);
735 void Assignments::chk()
737 for(size_t i
= 0; i
< asss_v
.size(); i
++) asss_v
[i
]->chk();
740 void Assignments::chk_uniq()
744 Assignments
*spec_asss
= _spec_asss
->get_asss();
745 for(size_t i
= 0; i
< asss_v
.size(); i
++) {
746 Assignment
*ass
= asss_v
[i
];
747 const Identifier
& id
= ass
->get_id();
748 const string
& name
= id
.get_name();
749 if (this != spec_asss
&& spec_asss
->has_ass_withId(id
)) {
750 ass
->error("`%s' is a reserved identifier", id
.get_dispname().c_str());
751 } else if (asss_m
.has_key(name
)) {
752 const char *dispname_str
= id
.get_dispname().c_str();
753 ass
->error("Duplicate assignment with identifier `%s'", dispname_str
);
754 asss_m
[name
]->note("Previous assignment with identifier `%s' is here",
756 } else asss_m
.add(name
, ass
);
761 void Assignments::set_right_scope(Scope
*p_scope
)
763 for(size_t i
= 0; i
< asss_v
.size(); i
++)
764 asss_v
[i
]->set_right_scope(p_scope
);
767 void Assignments::create_spec_asss()
770 FATAL_ERROR("Assignments::create_spec_asss(): duplicate initialization");
772 const char *s_asss
= "$#&&&(#TITAN$#&&^#% Assignments\n"
773 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"EXTERNAL\""
774 " ::= [UNIVERSAL 8] IMPLICIT SEQUENCE {\n"
775 " identification CHOICE {\n"
776 " syntaxes SEQUENCE {\n"
777 " abstract OBJECT IDENTIFIER,\n"
778 " transfer OBJECT IDENTIFIER\n"
780 " syntax OBJECT IDENTIFIER,\n"
781 " presentation-context-id INTEGER,\n"
782 " context-negotiation SEQUENCE {\n"
783 " presentation-context-id INTEGER,\n"
784 " transfer-syntax OBJECT IDENTIFIER\n"
786 " transfer-syntax OBJECT IDENTIFIER,\n"
789 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
790 " data-value OCTET STRING\n"
791 "} (WITH COMPONENTS {\n"
793 " identification (WITH COMPONENTS {\n"
795 " syntaxes ABSENT,\n"
796 " transfer-syntax ABSENT,\n"
801 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"EMBEDDED PDV\""
802 " ::= [UNIVERSAL 11] IMPLICIT SEQUENCE {\n"
803 " identification CHOICE {\n"
804 " syntaxes SEQUENCE {\n"
805 " abstract OBJECT IDENTIFIER,\n"
806 " transfer OBJECT IDENTIFIER\n"
808 " syntax OBJECT IDENTIFIER,\n"
809 " presentation-context-id INTEGER,\n"
810 " context-negotiation SEQUENCE {\n"
811 " presentation-context-id INTEGER,\n"
812 " transfer-syntax OBJECT IDENTIFIER\n"
814 " transfer-syntax OBJECT IDENTIFIER,\n"
817 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
818 " data-value OCTET STRING\n"
819 "} (WITH COMPONENTS {\n"
821 " data-value-descriptor ABSENT\n"
824 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"CHARACTER STRING\""
825 " ::= [UNIVERSAL 29] IMPLICIT SEQUENCE {\n"
826 " identification CHOICE {\n"
827 " syntaxes SEQUENCE {\n"
828 " abstract OBJECT IDENTIFIER,\n"
829 " transfer OBJECT IDENTIFIER\n"
831 " syntax OBJECT IDENTIFIER,\n"
832 " presentation-context-id INTEGER,\n"
833 " context-negotiation SEQUENCE {\n"
834 " presentation-context-id INTEGER,\n"
835 " transfer-syntax OBJECT IDENTIFIER\n"
837 " transfer-syntax OBJECT IDENTIFIER,\n"
840 " data-value-descriptor ObjectDescriptor OPTIONAL,\n"
841 " string-value OCTET STRING\n"
842 "} (WITH COMPONENTS {\n"
844 " data-value-descriptor ABSENT\n"
847 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"REAL\""
848 " ::= [UNIVERSAL 9] IMPLICIT SEQUENCE {\n"
849 " mantissa INTEGER,\n"
850 " base INTEGER (2|10),\n"
851 " exponent INTEGER\n"
854 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"TYPE-IDENTIFIER\"\n"
857 " &id OBJECT IDENTIFIER UNIQUE,\n"
861 " &Type IDENTIFIED BY &id\n"
864 "$#&&&(#TITAN$#&&^#% UpperIdentifier\"ABSTRACT-SYNTAX\""
866 " &id OBJECT IDENTIFIER UNIQUE,\n"
868 " &property BIT STRING {handles-invalid-encodings(0)} DEFAULT {}\n"
871 " &Type IDENTIFIED BY &id [HAS PROPERTY &property]\n"
875 if(asn1_parse_string(s_asss
) || !parsed_assignments
)
876 FATAL_ERROR("special assignments");
877 _spec_asss
=new Module
878 (new Identifier(Identifier::ID_ASN
, string("<internal>")),
879 TagDefault::AUTOMATIC
, false, new Exports(true), new Imports(),
881 _spec_asss
->set_location("<internal>");
882 _spec_asss
->set_scope_name(_spec_asss
->get_modid().get_dispname());
884 parsed_assignments
->set_fullname(string('@'));
888 // this is used to generate the files which are then
889 // included/copied/edited in core library
890 _spec_asss->set_gen_code();
891 _spec_asss->generate_code();
895 void Assignments::destroy_spec_asss()
898 FATAL_ERROR("Assignments::destroy_spec_asss(): duplicate cleanup");
904 bool Assignments::is_spec_asss(Common::Module
*p_mod
)
906 if (!p_mod
) FATAL_ERROR("Assignments::is_spec_asss()");
907 if (_spec_asss
) return p_mod
== static_cast<Common::Module
*>(_spec_asss
);
911 void Assignments::generate_code(output_struct
* target
)
913 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
914 Assignment
*ass
= asss_v
[i
];
915 if (!top_level_pdu
|| ass
->get_checked()) ass
->generate_code(target
);
919 void Assignments::generate_code(CodeGenHelper
& cgh
) {
920 for (size_t i
= 0; i
< asss_v
.size(); i
++) {
921 Assignment
*ass
= asss_v
[i
];
922 if (!top_level_pdu
|| ass
->get_checked()) ass
->generate_code(cgh
);
926 void Assignments::dump(unsigned level
) const
928 DEBUG(level
, "Assignments (%lu pcs.)", (unsigned long) asss_v
.size());
929 for(size_t i
= 0; i
< asss_v
.size(); i
++) asss_v
[i
]->dump(level
+ 1);
932 // =================================
934 // =================================
936 Ass_pard::Ass_pard(Block
*p_parlist_block
)
937 : Common::Node(), parlist_block(p_parlist_block
)
940 FATAL_ERROR("NULL parameter: Asn::Ass_pard::Ass_pard()");
943 Ass_pard::Ass_pard(const Ass_pard
& p
)
946 parlist_block
=p
.parlist_block
?p
.parlist_block
->clone():0;
947 for(size_t i
=0; i
<p
.dummyrefs
.size(); i
++)
948 dummyrefs
.add(p
.dummyrefs
[i
]->clone());
949 for(size_t i
=0; i
<p
.governors
.size(); i
++)
950 governors
.add(p
.governors
[i
]->clone());
953 Ass_pard::~Ass_pard()
955 delete parlist_block
;
956 for (size_t i
= 0; i
< dummyrefs
.size(); i
++) delete dummyrefs
[i
];
958 for (size_t i
= 0; i
< governors
.size(); i
++) delete governors
[i
];
960 for (size_t i
= 0; i
< inst_cnts
.size(); i
++)
961 delete inst_cnts
.get_nth_elem(i
);
965 void Ass_pard::preparse_pars()
967 if(!parlist_block
) return;
969 (my_ass
, "While checking formal parameters of parameterized"
970 " assignment `%s'", my_ass
->get_fullname().c_str());
971 TokenBuf
*parlist_tb
=parlist_block
->get_TokenBuf();
972 enum state_type
{S_START
, S_GOV
, S_DUMMYREF
, S_COMMA
, S_RDY
, S_ERR
};
974 for(state_type st
=S_START
; st
!=S_RDY
; ) {
977 gov_tb
=new TokenBuf();
978 switch(parlist_tb
->get_at(1)->get_token()) {
988 Token
*token
=parlist_tb
->pop_front_token();
989 switch(token
->get_token()) {
992 token
->error("Syntax error, premature end of parameter"
1002 gov_tb
->push_back_token(token
);
1006 Token
*token
=parlist_tb
->pop_front_token();
1007 switch(token
->get_token()) {
1008 case TOK_UpperIdentifier
:
1009 case TOK_LowerIdentifier
:
1010 dummyrefs
.add(token
->get_semval_id().clone());
1011 gov_tb
->push_front_token(token
);
1012 gov_tb
->push_back_kw_token(TOK_Assignment
);
1013 governors
.add(gov_tb
);
1020 token
->error("Syntax error, DummyReference was expected");
1024 break;} // S_DUMMYREF
1026 Token
*token
=parlist_tb
->pop_front_token();
1027 switch(token
->get_token()) {
1035 token
->error("Syntax error, `,' was expected");
1042 for (size_t i
= 0; i
< dummyrefs
.size(); i
++) delete dummyrefs
[i
];
1044 for (size_t i
= 0; i
< governors
.size(); i
++) delete governors
[i
];
1050 FATAL_ERROR("Ass_pard::preparse_pars()");
1053 delete parlist_block
;
1057 size_t Ass_pard::get_nof_pars()
1059 if (parlist_block
) preparse_pars();
1060 return dummyrefs
.size();
1063 const Identifier
& Ass_pard::get_nth_dummyref(size_t i
)
1065 if (parlist_block
) preparse_pars();
1066 return *(dummyrefs
[i
]);
1069 TokenBuf
* Ass_pard::clone_nth_governor(size_t i
)
1071 if (parlist_block
) preparse_pars();
1072 return governors
[i
]->clone();
1075 size_t Ass_pard::new_instnum(Common::Module
*p_mod
)
1077 if (!p_mod
) FATAL_ERROR("Ass_pard::new_instnum()");
1078 if (inst_cnts
.has_key(p_mod
)) return ++(*inst_cnts
[p_mod
]);
1080 inst_cnts
.add(p_mod
, new size_t(1));
1085 // =================================
1087 // =================================
1089 Assignment::Assignment(const Assignment
& p
)
1090 : Common::Assignment(p
), dontgen(false)
1093 ass_pard
=p
.ass_pard
->clone();
1094 ass_pard
->set_my_ass(this);
1099 string
Assignment::get_genname() const
1102 my_scope
->get_parent_scope() == my_scope
->get_scope_mod()) {
1103 // use the simple identifier if the assignment does not have scope
1104 // or it is a simple assignment at module scope
1105 return id
->get_name();
1107 // this assignment belongs to an instantiation of a parameterized
1108 // assignment: use the name of the parent scope to obtain genname
1109 string
genname_asn("@");
1110 genname_asn
+= my_scope
->get_scope_name();
1111 const string
& id_dispname
= id
->get_dispname();
1112 bool is_parass
= id_dispname
.find('.') == id_dispname
.size();
1114 // the assignment has a normal identifier:
1115 // it represents a formal parameter -> actual parameter binding
1116 // the id (which is the dummy reference) must be used to get a
1119 genname_asn
+= id_dispname
;
1121 // otherwise the assignment represents an instance of the parameterized
1122 // assignment itself: the scope name can be used alone as genname
1123 string
ret_val(Identifier::asn_2_name(genname_asn
));
1124 // in case of parameter assignments a suffix is appended to avoid name
1125 // clash with the embedded settings of the same instantiation
1126 if (is_parass
) ret_val
+= "_par_";
1131 Assignment
* Assignment::new_instance0()
1133 // Classes derived from Assignment must implement new_instance0.
1134 // See Asn::Ass_*::new_instance0
1135 FATAL_ERROR("Asn::Assignment::new_instance0()");
1139 Assignment::Assignment(asstype_t p_asstype
, Identifier
*p_id
,
1140 Ass_pard
*p_ass_pard
)
1141 : Common::Assignment(p_asstype
, p_id
),
1142 ass_pard(p_ass_pard
), dontgen(false)
1144 if(ass_pard
) ass_pard
->set_my_ass(this);
1147 Assignment::~Assignment()
1152 bool Assignment::is_asstype(asstype_t p_asstype
, ReferenceChain
* refch
)
1154 bool destroy_refch
=false;
1156 refch
=new ReferenceChain(this, "While examining kind of assignment");
1158 } else refch
->mark_state();
1159 bool b
=(p_asstype
==asstype
);
1160 if(!refch
->add(get_fullname())) b
=p_asstype
==A_ERROR
;
1161 if(destroy_refch
) delete refch
;
1162 else refch
->prev_state();
1166 Assignment
* Assignment::new_instance(Common::Module
*p_mod
)
1169 error("`%s' is not a parameterized assignment",
1170 get_fullname().c_str());
1173 Assignment
*new_ass
=new_instance0();
1174 delete new_ass
->id
; // it was just a temporary, containing "<error>"
1175 string
new_name(id
->get_asnname());
1177 new_name
+= p_mod
->get_modid().get_asnname();
1178 new_name
+= ".inst";
1179 new_name
+= Int2string(ass_pard
->new_instnum(p_mod
));
1180 new_ass
->id
=new Identifier(Identifier::ID_ASN
, new_name
);
1184 Type
* Assignment::get_Type()
1186 error("`%s' is not a type assignment", get_fullname().c_str());
1190 Value
* Assignment::get_Value()
1192 error("`%s' is not a value assignment", get_fullname().c_str());
1196 ValueSet
* Assignment::get_ValueSet()
1198 error("`%s' is not a valueset assignment", get_fullname().c_str());
1202 ObjectClass
* Assignment::get_ObjectClass()
1204 error("`%s' is not a objectclass assignment", get_fullname().c_str());
1208 Object
* Assignment::get_Object()
1210 error("`%s' is not a object assignment", get_fullname().c_str());
1214 ObjectSet
* Assignment::get_ObjectSet()
1216 error("`%s' is not a objectset assignment", get_fullname().c_str());
1220 void Assignment::chk()
1223 ass_pard
->get_nof_pars();
1227 DEBUG(7, "`%s' assignment not checked.", get_fullname().c_str());
1230 void Assignment::dump(unsigned level
) const
1232 DEBUG(level
, "Assignment(%d): %s%s", get_asstype(),
1233 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1236 // =================================
1238 // =================================
1240 Ass_Undef::Ass_Undef(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1241 Node
*p_left
, Node
*p_right
)
1242 : Assignment(A_UNDEF
, p_id
, p_ass_pard
),
1243 left(p_left
), right(p_right
), right_scope(0), ass(0)
1246 FATAL_ERROR("NULL parameter: Asn::Ass_Undef::Ass_Undef()");
1249 Ass_Undef::Ass_Undef(const Ass_Undef
& p
)
1250 : Assignment(p
), right_scope(0)
1252 left
=p
.left
?p
.left
->clone():0;
1253 right
=p
.right
?p
.right
->clone():0;
1254 ass
=p
.ass
?p
.ass
->clone():0;
1257 Ass_Undef::~Ass_Undef()
1264 Assignment
* Ass_Undef::clone() const
1266 if(ass
) return ass
->clone();
1267 else return new Ass_Undef(*this);
1270 Assignment
* Ass_Undef::new_instance0()
1272 if(ass
) FATAL_ERROR("Asn::Ass_Undef::new_instance0()");
1273 return new Ass_Undef
1274 (new Identifier(Identifier::ID_ASN
, string("<error>")),
1275 0, left
?left
->clone():0, right
->clone());
1278 Assignment::asstype_t
Ass_Undef::get_asstype() const
1280 const_cast<Ass_Undef
*>(this)->classify_ass();
1284 void Ass_Undef::set_fullname(const string
& p_fullname
)
1286 Assignment::set_fullname(p_fullname
);
1287 if (left
) left
->set_fullname(p_fullname
);
1288 if (right
) right
->set_fullname(p_fullname
);
1289 if (ass
) ass
->set_fullname(p_fullname
);
1292 void Ass_Undef::set_my_scope(Scope
*p_scope
)
1294 Assignment::set_my_scope(p_scope
);
1295 if(ass
) ass
->set_my_scope(p_scope
);
1296 right_scope
=p_scope
;
1299 void Ass_Undef::set_right_scope(Scope
*p_scope
)
1301 if(ass
) ass
->set_right_scope(p_scope
);
1302 right_scope
=p_scope
;
1305 bool Ass_Undef::is_asstype(asstype_t p_asstype
, ReferenceChain
* refch
)
1307 classify_ass(refch
);
1308 return asstype
!= A_ERROR
? ass
->is_asstype(p_asstype
, refch
) : false;
1311 Ass_pard
* Ass_Undef::get_ass_pard() const
1314 return ass
->get_ass_pard();
1319 bool Ass_Undef::_error_if_pard()
1322 error("`%s' is a parameterized assignment", get_fullname().c_str());
1328 Setting
* Ass_Undef::get_Setting()
1330 if(_error_if_pard()) return 0;
1332 return ass
->get_Setting();
1335 Type
* Ass_Undef::get_Type()
1337 if(_error_if_pard()) return 0;
1339 return ass
->get_Type();
1342 Value
* Ass_Undef::get_Value()
1344 if(_error_if_pard()) return 0;
1346 return ass
->get_Value();
1349 ValueSet
* Ass_Undef::get_ValueSet()
1351 if(_error_if_pard()) return 0;
1353 return ass
->get_ValueSet();
1356 ObjectClass
* Ass_Undef::get_ObjectClass()
1358 if(_error_if_pard()) return 0;
1360 return ass
->get_ObjectClass();
1363 Object
* Ass_Undef::get_Object()
1365 if(_error_if_pard()) return 0;
1367 return ass
->get_Object();
1370 ObjectSet
* Ass_Undef::get_ObjectSet()
1372 if(_error_if_pard()) return 0;
1374 return ass
->get_ObjectSet();
1377 void Ass_Undef::chk()
1381 ass_pard
->get_nof_pars();
1390 void Ass_Undef::generate_code(output_struct
*target
, bool)
1392 if (ass_pard
|| dontgen
) return;
1394 ass
->generate_code(target
);
1397 void Ass_Undef::generate_code(CodeGenHelper
& cgh
) {
1398 if (ass_pard
|| dontgen
) return;
1400 ass
->generate_code(cgh
);
1403 void Ass_Undef::dump(unsigned level
) const
1408 DEBUG(level
, "Undef assignment: %s%s",
1409 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1413 void Ass_Undef::classify_ass(ReferenceChain
*refch
)
1415 if(asstype
!=A_UNDEF
) return;
1416 bool destroy_refch
=false;
1418 refch
=new ReferenceChain(this, "While examining kind of assignment");
1420 } else refch
->mark_state();
1422 Error_Context
ec_backup(1);
1423 Error_Context
cntxt(this, "In assignment `%s'",
1424 id
->get_dispname().c_str());
1426 /* temporary pointers */
1428 Reference
*t_ref2
=0;
1431 if(!refch
->add(get_fullname()))
1433 if((t_ref
=dynamic_cast<Reference
*>(left
))) {
1434 t_ref
->set_my_scope(my_scope
);
1435 if(t_ref
->refers_to_st(Setting::S_ERROR
, refch
))
1438 if((t_ref
=dynamic_cast<Reference
*>(right
))) {
1439 t_ref
->set_my_scope(right_scope
);
1441 if(t_ref->refers_to_st(Setting::S_ERROR, refch))
1442 t_ref->error("Cannot recognize assignment `%s'",
1443 t_ref->get_dispname().c_str());
1447 if(id
->isvalid_asn_objclassref()
1449 && (t_ref
=dynamic_cast<Ref_defd
*>(right
))
1450 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1452 ass
=new Ass_OC(id
->clone(), ass_pard
, new OC_refd(t_ref
));
1457 else if(id
->isvalid_asn_typeref()
1459 && (t_ref
=dynamic_cast<Ref_defd
*>(right
))
1460 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1461 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1463 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1464 t_type
->set_location(*t_ref
);
1465 ass
=new Ass_T(id
->clone(), ass_pard
, t_type
);
1470 else if(id
->isvalid_asn_objsetref()
1471 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1472 && (t_block
=dynamic_cast<Block
*>(right
))
1473 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1475 ass
=new Ass_OS(id
->clone(), ass_pard
,
1476 new OC_refd(t_ref
), new OS_defn(t_block
));
1482 else if(id
->isvalid_asn_valsetref()
1483 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1484 && (t_block
=dynamic_cast<Block
*>(right
))
1485 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1486 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1488 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1489 t_type
->set_location(*t_ref
);
1490 ass
=new Ass_VS(id
->clone(), ass_pard
, t_type
, t_block
);
1496 else if(id
->isvalid_asn_objref()
1497 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1498 && ((t_block
=dynamic_cast<Block
*>(right
))
1499 || (t_ref2
=dynamic_cast<Reference
*>(right
)))
1500 && t_ref
->refers_to_st(Setting::S_OC
, refch
)
1502 OC_refd
*t_oc
=new OC_refd(t_ref
);
1503 t_oc
->set_location(*t_ref
);
1505 Obj_defn
*t_obj
=new Obj_defn(t_block
);
1506 t_obj
->set_location(*t_block
);
1507 ass
=new Ass_O(id
->clone(), ass_pard
, t_oc
, t_obj
);
1510 Obj_refd
*t_obj
=new Obj_refd(t_ref2
);
1511 t_obj
->set_location(*t_ref2
);
1512 ass
=new Ass_O(id
->clone(), ass_pard
, t_oc
, t_obj
);
1519 else if(id
->isvalid_asn_valref()
1520 && (t_ref
=dynamic_cast<Ref_simple
*>(left
))
1521 && ((t_block
=dynamic_cast<Block
*>(right
))
1522 || (t_ref2
=dynamic_cast<Reference
*>(right
)))
1523 && (t_ref
->refers_to_st(Setting::S_T
, refch
)
1524 || t_ref
->refers_to_st(Setting::S_VS
, refch
))
1526 Type
*t_type
=new Type(Type::T_REFD
, t_ref
);
1527 t_type
->set_location(*t_ref
);
1529 Value
*t_value
=new Value(Value::V_UNDEF_BLOCK
, t_block
);
1530 t_value
->set_location(*t_block
);
1531 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_value
);
1534 Ref_defd_simple
*t_ref3
=dynamic_cast<Ref_defd_simple
*>(t_ref2
);
1535 if(t_ref3
&& !t_ref3
->get_modid()) {
1536 Value
*t_val
=new Value(Value::V_UNDEF_LOWERID
,
1537 t_ref3
->get_id()->clone());
1538 t_val
->set_location(*t_ref3
);
1539 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_val
);
1543 Value
*t_val
=new Value(Value::V_REFD
, t_ref2
);
1544 t_val
->set_location(*t_ref2
);
1545 ass
=new Ass_V(id
->clone(), ass_pard
, t_type
, t_val
);
1558 error("Cannot recognize assignment");
1559 ass
= new Ass_Error(id
->clone(), ass_pard
);
1562 ass
->set_location(*this);
1563 ass
->set_my_scope(my_scope
);
1564 ass
->set_right_scope(right_scope
);
1565 ass
->set_fullname(get_fullname());
1566 if(destroy_refch
) delete refch
;
1567 else refch
->prev_state();
1570 // =================================
1572 // =================================
1574 Ass_Error::Ass_Error(Identifier
*p_id
, Ass_pard
*p_ass_pard
)
1575 : Assignment(A_ERROR
, p_id
, p_ass_pard
),
1576 setting_error(0), type_error(0), value_error(0)
1580 Ass_Error::~Ass_Error()
1582 delete setting_error
;
1587 Assignment
* Ass_Error::clone() const
1589 return new Ass_Error(id
->clone(), ass_pard
);
1592 Assignment
* Ass_Error::new_instance0()
1594 return new Ass_Error
1595 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0);
1598 bool Ass_Error::is_asstype(asstype_t p_asstype
, ReferenceChain
*)
1600 return p_asstype
==A_ERROR
;
1603 Setting
* Ass_Error::get_Setting()
1606 setting_error
= new Common::Setting_Error();
1607 return setting_error
;
1610 Type
* Ass_Error::get_Type()
1613 type_error
= new Type(Type::T_ERROR
);
1617 Value
* Ass_Error::get_Value()
1620 value_error
= new Value(Value::V_ERROR
);
1624 ValueSet
* Ass_Error::get_ValueSet()
1626 FATAL_ERROR("Ass_Error::get_ValueSet()");
1630 ObjectClass
* Ass_Error::get_ObjectClass()
1632 FATAL_ERROR("Ass_Error::get_ObjectClass()");
1636 Object
* Ass_Error::get_Object()
1638 FATAL_ERROR("Ass_Error::get_Object()");
1642 ObjectSet
* Ass_Error::get_ObjectSet()
1644 FATAL_ERROR("Ass_Error::get_ObjectSet()");
1648 void Ass_Error::chk()
1653 void Ass_Error::dump(unsigned level
) const
1655 DEBUG(level
, "Erroneous assignment: %s%s",
1656 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1659 // =================================
1661 // =================================
1663 Ass_T::Ass_T(Identifier
*p_id
, Ass_pard
*p_ass_pard
, Type
*p_right
)
1664 : Assignment(A_TYPE
, p_id
, p_ass_pard
)
1667 FATAL_ERROR("NULL parameter: Asn::Ass_T::Ass_T()");
1668 p_right
->set_ownertype(Type::OT_TYPE_ASS
, this);
1672 Ass_T::Ass_T(const Ass_T
& p
)
1675 right
=p
.right
->clone();
1683 Assignment
* Ass_T::new_instance0()
1686 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0, right
->clone());
1689 void Ass_T::set_fullname(const string
& p_fullname
)
1691 Assignment::set_fullname(p_fullname
);
1692 right
->set_fullname(p_fullname
);
1695 void Ass_T::set_my_scope(Scope
*p_scope
)
1697 Assignment::set_my_scope(p_scope
);
1698 right
->set_my_scope(p_scope
);
1701 void Ass_T::set_right_scope(Scope
*p_scope
)
1703 right
->set_my_scope(p_scope
);
1706 Type
* Ass_T::get_Type()
1709 error("`%s' is a parameterized type assignment",
1710 get_fullname().c_str());
1719 if (checked
) return;
1721 Error_Context
cntxt(this, "In type assignment `%s'",
1722 id
->get_dispname().c_str());
1724 ass_pard
->get_nof_pars();
1728 right
->set_genname(get_genname());
1730 ReferenceChain
refch(right
, "While checking embedded recursions");
1731 right
->chk_recursions(refch
);
1734 void Ass_T::generate_code(output_struct
*target
, bool)
1736 right
->generate_code(target
);
1739 void Ass_T::generate_code(CodeGenHelper
& cgh
) {
1740 if (ass_pard
|| dontgen
) return;
1741 generate_code(cgh
.get_outputstruct(right
));
1742 cgh
.finalize_generation(right
);
1745 void Ass_T::dump(unsigned level
) const
1747 DEBUG(level
, "Type assignment: %s%s",
1748 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1755 // =================================
1757 // =================================
1759 Ass_V::Ass_V(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1760 Type
*p_left
, Value
*p_right
)
1761 : Assignment(A_CONST
, p_id
, p_ass_pard
)
1763 if(!p_left
|| !p_right
)
1764 FATAL_ERROR("NULL parameter: Asn::Ass_V::Ass_V()");
1766 left
->set_ownertype(Type::OT_VAR_ASS
, this);
1770 Ass_V::Ass_V(const Ass_V
& p
)
1773 left
=p
.left
->clone();
1774 right
=p
.right
->clone();
1783 Assignment
* Ass_V::new_instance0()
1786 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
1787 left
->clone(), right
->clone());
1790 void Ass_V::set_fullname(const string
& p_fullname
)
1792 Assignment::set_fullname(p_fullname
);
1793 left
->set_fullname(p_fullname
+ ".<type>");
1794 right
->set_fullname(p_fullname
);
1797 void Ass_V::set_my_scope(Scope
*p_scope
)
1799 Assignment::set_my_scope(p_scope
);
1800 left
->set_my_scope(p_scope
);
1801 right
->set_my_scope(p_scope
);
1804 void Ass_V::set_right_scope(Scope
*p_scope
)
1806 right
->set_my_scope(p_scope
);
1810 Type
* Ass_V::get_Type()
1816 Value
* Ass_V::get_Value()
1819 error("`%s' is a parameterized value assignment",
1820 get_fullname().c_str());
1830 Error_Context
cntxt(this, "In value assignment `%s'",
1831 id
->get_dispname().c_str());
1833 ass_pard
->get_nof_pars();
1838 static const string
_T_("_T_");
1839 left
->set_genname(_T_
, get_genname());
1841 right
->set_my_governor(left
);
1842 left
->chk_this_value_ref(right
);
1844 left
->chk_this_value(right
, 0, Type::EXPECTED_CONSTANT
, INCOMPLETE_NOT_ALLOWED
,
1845 OMIT_NOT_ALLOWED
, SUB_CHK
, IMPLICIT_OMIT
);
1847 ReferenceChain
refch(right
, "While checking embedded recursions");
1848 right
->chk_recursions(refch
);
1850 if (!semantic_check_only
) {
1851 right
->set_genname_prefix("const_");
1852 right
->set_genname_recursive(get_genname());
1853 right
->set_code_section(GovernedSimple::CS_PRE_INIT
);
1857 void Ass_V::generate_code(output_struct
*target
, bool)
1859 if (ass_pard
|| dontgen
) return;
1860 left
->generate_code(target
);
1862 Code::init_cdef(&cdef
);
1863 left
->generate_code_object(&cdef
, right
);
1864 cdef
.init
= right
->generate_code_init(cdef
.init
,
1865 right
->get_lhs_name().c_str());
1866 Code::merge_cdef(target
, &cdef
);
1867 Code::free_cdef(&cdef
);
1870 void Ass_V::generate_code(CodeGenHelper
& cgh
) {
1871 generate_code(cgh
.get_current_outputstruct());
1874 void Ass_V::dump(unsigned level
) const
1876 DEBUG(level
, "Value assignment: %s%s",
1877 id
->get_dispname().c_str(), ass_pard
?"{}":"");
1884 // =================================
1886 // =================================
1888 Ass_VS::Ass_VS(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
1889 Type
*p_left
, Block
*p_right
)
1890 : Assignment(A_VS
, p_id
, p_ass_pard
), right_scope(0)
1892 if(!p_left
|| !p_right
)
1893 FATAL_ERROR("NULL parameter: Asn::Ass_VS::Ass_VS()");
1895 left
->set_ownertype(Type::OT_VSET_ASS
, this);
1899 Ass_VS::Ass_VS(const Ass_VS
& p
)
1900 : Assignment(p
), right_scope(0)
1902 left
=p
.left
->clone();
1903 right
=p
.right
->clone();
1912 Assignment
* Ass_VS::new_instance0()
1915 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
1916 left
->clone(), right
->clone());
1919 void Ass_VS::set_fullname(const string
& p_fullname
)
1921 Assignment::set_fullname(p_fullname
);
1922 left
->set_fullname(p_fullname
);
1923 right
->set_fullname(p_fullname
);
1926 void Ass_VS::set_my_scope(Scope
*p_scope
)
1928 Assignment::set_my_scope(p_scope
);
1929 left
->set_my_scope(p_scope
);
1932 void Ass_VS::set_right_scope(Scope
*p_scope
)
1934 right_scope
=p_scope
;
1937 Type
* Ass_VS::get_Type()
1940 error("`%s' is a parameterized value set assignment",
1941 get_fullname().c_str());
1950 if (checked
) return;
1952 Error_Context
cntxt(this, "In value set assignment `%s'",
1953 id
->get_dispname().c_str());
1955 ass_pard
->get_nof_pars();
1959 // parse the content of right and add it to left as one more constraint
1960 Node
*node
= right
->parse(KW_Block_ValueSet
);
1961 Constraint
* vs_constr
= dynamic_cast<Constraint
*>(node
);
1962 if (vs_constr
) { // if we have a constraint add it to the type
1963 if (right_scope
) { // if this is a parameter of a pard type
1964 vs_constr
->set_my_scope(right_scope
);
1966 if (!left
->get_constraints()) left
->add_constraints(new Constraints());
1967 left
->get_constraints()->add_con(vs_constr
);
1971 left
->set_genname(get_genname());
1973 ReferenceChain
refch(left
, "While checking embedded recursions");
1974 left
->chk_recursions(refch
);
1977 void Ass_VS::generate_code(output_struct
*target
, bool)
1979 left
->generate_code(target
);
1982 void Ass_VS::generate_code(CodeGenHelper
& cgh
) {
1983 if (ass_pard
|| dontgen
) return;
1984 generate_code(cgh
.get_outputstruct(left
));
1985 cgh
.finalize_generation(left
);
1988 void Ass_VS::dump(unsigned level
) const
1990 DEBUG(level
, "Value set assignment: %s%s",
1991 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2000 // =================================
2002 // =================================
2004 Ass_OC::Ass_OC(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
2005 ObjectClass
*p_right
)
2006 : Assignment(A_OC
, p_id
, p_ass_pard
)
2009 FATAL_ERROR("NULL parameter: Asn::Ass_OC::Ass_OC()");
2013 Ass_OC::Ass_OC(const Ass_OC
& p
)
2016 right
=p
.right
->clone();
2024 Assignment
* Ass_OC::new_instance0()
2027 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0, right
->clone());
2030 void Ass_OC::set_fullname(const string
& p_fullname
)
2032 Assignment::set_fullname(p_fullname
);
2033 right
->set_fullname(p_fullname
);
2036 void Ass_OC::set_my_scope(Scope
*p_scope
)
2038 Assignment::set_my_scope(p_scope
);
2039 right
->set_my_scope(p_scope
);
2042 void Ass_OC::set_right_scope(Scope
*p_scope
)
2044 right
->set_my_scope(p_scope
);
2050 Error_Context
cntxt(this, "In information object class assignment `%s'",
2051 id
->get_dispname().c_str());
2053 ass_pard
->get_nof_pars();
2057 right
->set_genname(get_genname());
2062 ObjectClass
* Ass_OC::get_ObjectClass()
2065 error("`%s' is a parameterized objectclass assignment",
2066 get_fullname().c_str());
2073 void Ass_OC::generate_code(output_struct
*target
, bool)
2075 if (ass_pard
|| dontgen
) return;
2076 right
->generate_code(target
);
2079 void Ass_OC::generate_code(CodeGenHelper
& cgh
) {
2080 generate_code(cgh
.get_current_outputstruct());
2083 void Ass_OC::dump(unsigned level
) const
2085 DEBUG(level
, "ObjectClass assignment: %s%s",
2086 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2092 // =================================
2094 // =================================
2096 Ass_O::Ass_O(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
2097 ObjectClass
*p_left
, Object
*p_right
)
2098 : Assignment(A_OBJECT
, p_id
, p_ass_pard
)
2100 if(!p_left
|| !p_right
)
2101 FATAL_ERROR("NULL parameter: Asn::Ass_O::Ass_O()");
2106 Ass_O::Ass_O(const Ass_O
& p
)
2109 left
=p
.left
->clone();
2110 right
=p
.right
->clone();
2119 Assignment
* Ass_O::new_instance0()
2122 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
2123 left
->clone(), right
->clone());
2126 void Ass_O::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_O::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_O::set_right_scope(Scope
*p_scope
)
2142 right
->set_my_scope(p_scope
);
2146 ObjectClass* Ass_O::get_ObjectClass()
2152 Object
* Ass_O::get_Object()
2155 error("`%s' is a parameterized object assignment",
2156 get_fullname().c_str());
2166 Error_Context
cntxt(this, "In information object 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_O::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_O::generate_code(CodeGenHelper
& cgh
) {
2188 generate_code(cgh
.get_current_outputstruct());
2191 void Ass_O::dump(unsigned level
) const
2193 DEBUG(level
, "Object assignment: %s%s",
2194 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2201 // =================================
2203 // =================================
2205 Ass_OS::Ass_OS(Identifier
*p_id
, Ass_pard
*p_ass_pard
,
2206 ObjectClass
*p_left
, ObjectSet
*p_right
)
2207 : Assignment(A_OS
, p_id
, p_ass_pard
)
2209 if(!p_left
|| !p_right
)
2210 FATAL_ERROR("NULL parameter: Asn::Ass_OS::Ass_OS()");
2215 Ass_OS::Ass_OS(const Ass_OS
& p
)
2218 left
=p
.left
->clone();
2219 right
=p
.right
->clone();
2228 Assignment
* Ass_OS::new_instance0()
2231 (new Identifier(Identifier::ID_ASN
, string("<error>")), 0,
2232 left
->clone(), right
->clone());
2235 void Ass_OS::set_fullname(const string
& p_fullname
)
2237 Assignment::set_fullname(p_fullname
);
2238 left
->set_fullname(p_fullname
);
2239 right
->set_fullname(p_fullname
);
2242 void Ass_OS::set_my_scope(Scope
*p_scope
)
2244 Assignment::set_my_scope(p_scope
);
2245 left
->set_my_scope(p_scope
);
2246 right
->set_my_scope(p_scope
);
2249 void Ass_OS::set_right_scope(Scope
*p_scope
)
2251 right
->set_my_scope(p_scope
);
2255 ObjectClass* Ass_OS::get_ObjectClass()
2261 ObjectSet
* Ass_OS::get_ObjectSet()
2264 error("`%s' is a parameterized objectset assignment",
2265 get_fullname().c_str());
2275 Error_Context
cntxt(this, "In information object set assignment `%s'",
2276 id
->get_dispname().c_str());
2278 ass_pard
->get_nof_pars();
2283 right
->set_my_governor(left
);
2284 right
->set_genname(get_genname());
2289 void Ass_OS::generate_code(output_struct
*target
, bool)
2291 if (ass_pard
|| dontgen
) return;
2292 left
->generate_code(target
);
2293 right
->generate_code(target
);
2296 void Ass_OS::generate_code(CodeGenHelper
& cgh
) {
2297 generate_code(cgh
.get_current_outputstruct());
2300 void Ass_OS::dump(unsigned level
) const
2302 DEBUG(level
, "ObjectSet assignment: %s%s",
2303 id
->get_dispname().c_str(), ass_pard
?"{}":"");
2310 // =================================
2312 // =================================
2314 // =================================
2316 // =================================
2318 const Identifier
* Ref_defd::get_modid()
2320 Ref_defd_simple
*t_ref
= get_ref_defd_simple();
2321 if (t_ref
) return t_ref
->get_modid();
2325 const Identifier
* Ref_defd::get_id()
2327 Ref_defd_simple
*t_ref
= get_ref_defd_simple();
2328 if (t_ref
) return t_ref
->get_id();
2332 bool Ref_defd::refers_to_st(Setting::settingtype_t p_st
,
2333 ReferenceChain
* refch
)
2335 if(get_is_erroneous()) return p_st
==Setting::S_ERROR
;
2337 Error_Context
cntxt(this, "In reference `%s'", get_dispname().c_str());
2339 FATAL_ERROR("NULL parameter");
2340 Common::Assignment
* c_ass
=my_scope
->get_ass_bySRef(this);
2345 Assignment
* ass
=dynamic_cast<Assignment
*>(c_ass
);
2347 error("Reference to a non-ASN setting");
2353 b
=ass
->is_asstype(Assignment::A_OC
, refch
);
2356 b
=ass
->is_asstype(Assignment::A_TYPE
, refch
);
2359 b
=ass
->is_asstype(Assignment::A_OBJECT
, refch
);
2362 b
=ass
->is_asstype(Assignment::A_CONST
, refch
);
2365 b
=ass
->is_asstype(Assignment::A_OS
, refch
);
2368 b
=ass
->is_asstype(Assignment::A_VS
, refch
);
2370 case Setting::S_ERROR
:
2371 b
=ass
->is_asstype(Assignment::A_ERROR
, refch
);
2374 FATAL_ERROR("Asn::Ref_defd::refers_to_st()");
2379 void Ref_defd::generate_code(expression_struct_t
*)
2381 FATAL_ERROR("Ref_defd::generate_code()");
2384 void Ref_defd::generate_code_const_ref(expression_struct */
*expr*/
)
2386 FATAL_ERROR("Ref_defd::generate_code_const_ref()");
2389 // =================================
2390 // ===== Ref_defd_simple
2391 // =================================
2393 Ref_defd_simple::Ref_defd_simple(Identifier
*p_modid
,
2395 : Ref_defd(), modid(p_modid
), id(p_id
)
2398 FATAL_ERROR("NULL parameter: Asn::Ref_defd_simple::Ref_defd_simple()");
2401 Ref_defd_simple::Ref_defd_simple(const Ref_defd_simple
& p
)
2404 modid
=p
.modid
?p
.modid
->clone():0;
2408 Ref_defd_simple::~Ref_defd_simple()
2414 Assignment
* Ref_defd_simple::get_refd_ass()
2416 if(get_is_erroneous()) return 0;
2417 Error_Context
cntxt(this, "In reference `%s'", get_dispname().c_str());
2419 FATAL_ERROR("NULL parameter: Asn::Ref_defd_simple::get_refd_ass():"
2420 " my_scope is not set");
2421 Common::Assignment
* c_ass
=my_scope
->get_ass_bySRef(this);
2422 if(!c_ass
) return 0;
2423 Assignment
* ass
=dynamic_cast<Assignment
*>(c_ass
);
2425 this->error("Reference to a non-ASN assignment");
This page took 0.127322 seconds and 5 git commands to generate.