b933ea174f9220433dd5e6315410ee7f138f489f
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
9 #include "../Identifier.hh"
10 #include "AST_asn1.hh"
12 #include "TokenBuf.hh"
16 // =================================
18 // =================================
20 Ref_pard::Ref_pard(Ref_defd_simple
*p_refds
, Block
*p_block
)
21 : Ref_defd(), ref_parass(p_refds
), block(p_block
),
22 refd_ass_is_not_pard(false), asss(0), ref_ds(0)
24 if (!p_refds
|| !p_block
)
25 FATAL_ERROR("NULL parameter: Asn::Ref_pard::Ref_pard()");
28 Ref_pard::Ref_pard(const Ref_pard
& p
)
29 : Ref_defd(p
), refd_ass_is_not_pard(p
.refd_ass_is_not_pard
),
32 ref_parass
= p
.ref_parass
->clone();
33 block
=p
.block
?p
.block
->clone():0;
34 asss
=p
.asss
?p
.asss
->clone():0;
45 Ref_pard
*Ref_pard::clone() const
47 return new Ref_pard(*this);
50 void Ref_pard::set_fullname(const string
& p_fullname
)
52 Ref_defd::set_fullname(p_fullname
);
53 ref_parass
->set_fullname(p_fullname
);
54 if (block
) block
->set_fullname(p_fullname
+ ".<block>");
55 if (asss
) asss
->set_fullname(p_fullname
+ "." +
56 ref_parass
->get_dispname() + "{}");
57 if (ref_ds
) ref_ds
->set_fullname(p_fullname
);
60 void Ref_pard::set_my_scope(Scope
*p_scope
)
62 Ref_defd::set_my_scope(p_scope
);
63 ref_parass
->set_my_scope(p_scope
);
64 if (ref_ds
) ref_ds
->set_my_scope(p_scope
);
67 bool Ref_pard::get_is_erroneous()
69 get_ref_defd_simple();
73 string
Ref_pard::get_dispname()
75 if (ref_ds
) return ref_ds
->get_dispname();
76 else return ref_parass
->get_dispname()+"{}";
79 Ref_defd_simple
* Ref_pard::get_ref_defd_simple()
81 if(ref_ds
) return ref_ds
;
82 if(is_erroneous
) return 0;
83 if(refd_ass_is_not_pard
) return ref_parass
;
84 Module
*my_mod
= dynamic_cast<Module
*>(my_scope
->get_scope_mod());
85 if(!my_mod
) FATAL_ERROR("Asn::Ref_pard::get_ref_defd_simple()");
87 /* search the referenced parameterized assignment */
88 Assignment
*parass
=ref_parass
->get_refd_ass();
95 Ass_pard
*ass_pard
=parass
->get_ass_pard();
97 /* error: this is not a parameterized assignment */
98 refd_ass_is_not_pard
=true;
103 size_t nof_formal_pars
=ass_pard
->get_nof_pars();
104 if(nof_formal_pars
==0) {
105 /* error in parameterized assignment */
111 (this, "While instantiating parameterized reference `%s'",
112 ref_parass
->get_dispname().c_str());
115 /* splitting the actual parameterlist */
116 vector
<TokenBuf
> act_pars
; // actual parameters
118 TokenBuf
*act_pars_tb
=block
->get_TokenBuf();
119 TokenBuf
*tmp_tb
=new TokenBuf();
120 for(bool ok
=false; !ok
; ) {
121 Token
*token
=act_pars_tb
->pop_front_token();
122 switch(token
->get_token()) {
127 token
->set_token('\0');
128 tmp_tb
->push_back_token(token
);
129 act_pars
.add(tmp_tb
);
130 tmp_tb
=new TokenBuf();
133 tmp_tb
->push_back_token(token
);
134 } // switch(token->token)
141 /* checking the number of parameters */
142 size_t nof_act_pars
=act_pars
.size();
143 if(nof_act_pars
!= nof_formal_pars
)
144 error("Too %s parameters: %lu was expected instead of %lu",
145 nof_act_pars
<nof_formal_pars
?"few":"many",
146 (unsigned long) nof_formal_pars
, (unsigned long) nof_act_pars
);
148 /* building the new assignments */
149 asss
=new Assignments();
150 for(size_t i
=0; i
<nof_formal_pars
; i
++) {
151 const Identifier
& tmp_id
=ass_pard
->get_nth_dummyref(i
);
152 Error_Context
cntxt2(this, "While examining parameter `%s'",
153 tmp_id
.get_dispname().c_str());
154 Assignment
*tmp_ass
=0;
156 TokenBuf
*tmp_tb
=ass_pard
->clone_nth_governor(i
);
157 tmp_tb
->move_tokens_from(act_pars
[i
]);
158 tmp_tb
->push_back_kw_token('\0');
159 Block
*tmp_block
=new Block(tmp_tb
);
160 Node
*tmp_node
=tmp_block
->parse(KW_Block_Assignment
);
162 tmp_ass
=dynamic_cast<Assignment
*>(tmp_node
);
163 if(!tmp_ass
) delete tmp_node
;
165 // substitution of missing parameters (for error recovery)
166 if(!tmp_ass
) tmp_ass
=new Ass_Error(tmp_id
.clone(), 0);
167 tmp_ass
->set_location(*this);
168 asss
->add_ass(tmp_ass
);
171 for(size_t i
=0; i
<nof_act_pars
; i
++) delete act_pars
[i
];
175 Assignment
*new_ass
= parass
->new_instance(my_scope
->get_scope_mod_gen());
176 my_mod
->add_ass(new_ass
);
177 const Identifier
& new_ass_id
= new_ass
->get_id();
178 const string
& new_ass_dispname
= new_ass_id
.get_dispname();
180 asss
->set_right_scope(my_scope
);
181 asss
->set_parent_scope(parass
->get_my_scope());
182 asss
->set_parent_scope_gen(my_scope
);
183 asss
->set_scope_name(new_ass_dispname
);
184 asss
->set_fullname(get_fullname() + "." + ref_parass
->get_dispname() +
188 new_ass
->set_fullname(my_mod
->get_fullname() + "." + new_ass_dispname
);
189 new_ass
->set_my_scope(asss
);
190 new_ass
->set_location(*this);
191 new_ass
->set_dontgen();
194 ref_ds
=new Ref_defd_simple(new Identifier(my_mod
->get_modid()),
195 new Identifier(new_ass_id
));
196 ref_ds
->set_fullname(get_fullname());
197 ref_ds
->set_my_scope(my_mod
);
201 void Ref_pard::dump(unsigned level
) const
203 DEBUG(level
, "Parameterized reference: %s", const_cast<Ref_pard
*>(this)->get_dispname().c_str());
205 DEBUG(level
, "with parameters");
211 // =================================
213 // =================================
215 FieldName::FieldName(const FieldName
& p
)
218 for(size_t i
=0; i
<p
.fields
.size(); i
++)
219 add_field(p
.fields
[i
]->clone());
222 FieldName::~FieldName()
224 for(size_t i
=0; i
<fields
.size(); i
++) delete fields
[i
];
228 FieldName
*FieldName::clone() const
230 return new FieldName(*this);
233 void FieldName::add_field(Identifier
*p_id
)
236 FATAL_ERROR("NULL parameter: Asn::FieldName::add_field()");
240 string
FieldName::get_dispname() const
243 size_t nof_fields
= fields
.size();
244 for (size_t i
= 0; i
< nof_fields
; i
++) {
246 s
+= fields
[i
]->get_dispname();
251 // =================================
253 // =================================
255 FromObj::FromObj(Ref_defd
*p_ref_defd
, FieldName
*p_fn
)
256 : Common::Reference(), setting(0), setting_cache(0)
258 if (!p_ref_defd
|| !p_fn
)
259 FATAL_ERROR("NULL parameter: Asn::FromObj::FromObj()");
264 FromObj::FromObj(const FromObj
& p
)
265 : Common::Reference(p
), setting(0), setting_cache(0)
267 ref_defd
=p
.ref_defd
->clone();
278 FromObj
*FromObj::clone() const
280 return new FromObj(*this);
283 void FromObj::set_fullname(const string
& p_fullname
)
285 Common::Reference::set_fullname(p_fullname
);
286 ref_defd
->set_fullname(p_fullname
);
287 fn
->set_fullname(p_fullname
+ ".<fieldnames>");
290 void FromObj::set_my_scope(Scope
*p_scope
)
292 Common::Reference::set_my_scope(p_scope
);
293 ref_defd
->set_my_scope(p_scope
);
296 string
FromObj::get_dispname()
298 return ref_defd
->get_dispname()+fn
->get_dispname();
301 bool FromObj::get_is_erroneous()
308 Setting
* FromObj::get_refd_setting()
310 if(setting_cache
) return setting_cache
;
312 (this, "In InformationFromObjects construct `%s'",
313 get_dispname().c_str());
314 enum { UNKNOWN
, OC
, OS
, O
} curr
= UNKNOWN
;
318 OS_defn
*fromobjs
= 0; // temporary storage
319 size_t nof_fields
= fn
->get_nof_fields();
320 Setting
*t_setting
= ref_defd
->get_refd_setting();
321 if(!t_setting
) goto error
;
324 switch(t_setting
->get_st()) {
325 case Setting::S_OS
: {
327 t_os
=dynamic_cast<ObjectSet
*>(t_setting
)->get_refd_last();
328 t_oc
=t_os
->get_my_governor()->get_refd_last();
329 OSEV_objcollctr
objcoll(t_os
, t_oc
);
330 objcoll
.visit_ObjectSet(*t_os
);
331 fromobjs
=new OS_defn(objcoll
.give_objs());
332 fromobjs
->set_my_governor(t_oc
);
336 t_o
=dynamic_cast<Object
*>(t_setting
)->get_refd_last();
337 t_oc
=t_o
->get_my_governor()->get_refd_last();
341 t_oc
=dynamic_cast<ObjectClass
*>(t_setting
)->get_refd_last();
343 case Setting::S_ERROR
:
346 error("Invalid reference `%s' "
347 "(ObjectClass, ObjectSet or Object reference was expected)",
348 get_dispname().c_str());
352 /* the middle part */
353 for(size_t i
=0; i
<nof_fields
-1; i
++) {
354 Identifier
*curr_fn
= fn
->get_field_byIndex(i
);
355 Error_Context
ec_1(this, "While examining part #%lu (`%s') of FieldName",
356 (unsigned long) (i
+ 1), curr_fn
->get_dispname().c_str());
357 FieldSpec
*curr_fspec
=
358 t_oc
->get_fss()->get_fs_byId(*curr_fn
)->get_last();
359 if(curr_fspec
->get_fstype()==FieldSpec::FS_ERROR
) goto error
;
362 switch(curr_fspec
->get_fstype()) {
363 case FieldSpec::FS_O
: {
364 FieldSpec_O
*tmp_fspec
=
365 dynamic_cast<FieldSpec_O
*>(curr_fspec
);
366 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
368 case FieldSpec::FS_OS
: {
369 FieldSpec_OS
*tmp_fspec
=
370 dynamic_cast<FieldSpec_OS
*>(curr_fspec
);
371 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
373 case FieldSpec::FS_ERROR
:
376 error("This notation is not permitted (object or objectset"
377 " fieldreference was expected)");
379 } // switch fspec.fstype
382 switch(curr_fspec
->get_fstype()) {
383 case FieldSpec::FS_O
: {
384 FieldSpec_O
*tmp_fspec
=
385 dynamic_cast<FieldSpec_O
*>(curr_fspec
);
386 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
387 OSEV_objcollctr
objcoll(this, t_oc
);
388 Objects
*t_objs
= fromobjs
->get_objs();
389 for(size_t j
=0; j
<t_objs
->get_nof_objs(); j
++) {
390 t_o
=t_objs
->get_obj_byIndex(j
)->get_refd_last();
391 if(!t_o
->has_fs_withName_dflt(*curr_fn
)) continue;
392 t_setting
=t_o
->get_setting_byName_dflt(*curr_fn
);
393 t_o
=dynamic_cast<Object
*>(t_setting
)->get_refd_last();
394 objcoll
.visit_Object(*t_o
);
397 fromobjs
=new OS_defn(objcoll
.give_objs());
398 fromobjs
->set_location(*this);
399 fromobjs
->set_my_governor(t_oc
);
401 case FieldSpec::FS_OS
: {
402 FieldSpec_OS
*tmp_fspec
=
403 dynamic_cast<FieldSpec_OS
*>(curr_fspec
);
404 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
405 OSEV_objcollctr
objcoll(this, t_oc
);
406 Objects
*t_objs
= fromobjs
->get_objs();
407 for(size_t j
=0; j
<t_objs
->get_nof_objs(); j
++) {
408 t_o
=t_objs
->get_obj_byIndex(j
)->get_refd_last();
409 if(!t_o
->has_fs_withName_dflt(*curr_fn
)) continue;
410 t_setting
=t_o
->get_setting_byName_dflt(*curr_fn
);
411 t_os
=dynamic_cast<ObjectSet
*>(t_setting
)->get_refd_last();
412 objcoll
.visit_ObjectSet(*t_os
);
415 fromobjs
=new OS_defn(objcoll
.give_objs());
416 fromobjs
->set_location(*this);
417 fromobjs
->set_my_governor(t_oc
);
419 case FieldSpec::FS_ERROR
:
422 error("This notation is not permitted (object or objectset"
423 " fieldreference was expected)");
425 } // switch fspec.fstype
428 switch(curr_fspec
->get_fstype()) {
429 case FieldSpec::FS_O
: {
430 FieldSpec_O
*tmp_fspec
=
431 dynamic_cast<FieldSpec_O
*>(curr_fspec
);
432 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
433 t_setting
=t_o
->get_setting_byName_dflt(*curr_fn
);
434 t_o
=dynamic_cast<Object
*>(t_setting
)->get_refd_last();
436 case FieldSpec::FS_OS
: {
438 FieldSpec_OS
*tmp_fspec
=
439 dynamic_cast<FieldSpec_OS
*>(curr_fspec
);
440 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
441 OSEV_objcollctr
objcoll(*fromobjs
);
442 Objects
*t_objs
= fromobjs
->get_objs();
443 for(size_t j
=0; j
<t_objs
->get_nof_objs(); j
++) {
444 t_o
=t_objs
->get_obj_byIndex(j
)->get_refd_last();
445 if(!t_o
->has_fs_withName_dflt(*curr_fn
)) continue;
446 t_setting
=t_o
->get_setting_byName_dflt(*curr_fn
);
447 t_os
=dynamic_cast<ObjectSet
*>(t_setting
)->get_refd_last();
448 objcoll
.visit_ObjectSet(*t_os
);
451 fromobjs
=new OS_defn(objcoll
.give_objs());
452 fromobjs
->set_location(*this);
453 fromobjs
->set_my_governor(t_oc
);
455 case FieldSpec::FS_ERROR
:
458 error("This notation is not permitted (object or objectset"
459 " fieldreference was expected)");
461 } // switch fspec.fstype
464 FATAL_ERROR("Asn::FromObj::get_refd_setting()");
468 /* and the last part... */
470 Identifier
*curr_fn
= fn
->get_field_byIndex(nof_fields
-1);
473 "While examining last part (`%s') of FieldName",
474 curr_fn
->get_dispname().c_str());
475 FieldSpec
*curr_fspec
=
476 t_oc
->get_fss()->get_fs_byId(*curr_fn
)->get_last();
479 switch(curr_fspec
->get_fstype()) {
480 case FieldSpec::FS_T
: {
481 Type
*opentype
= new Type(Type::T_OPENTYPE
, t_oc
, curr_fn
);
482 opentype
->set_location(*this);
485 case FieldSpec::FS_V_FT
: {
486 FieldSpec_V_FT
*tmp_fspec
=
487 dynamic_cast<FieldSpec_V_FT
*>(curr_fspec
);
489 new Type(Type::T_OCFT
, tmp_fspec
->get_type(), t_oc
, curr_fn
);
490 ocft
->set_location(*this);
493 case FieldSpec::FS_V_VT
:
494 case FieldSpec::FS_VS_FT
:
495 case FieldSpec::FS_VS_VT
:
496 error("Sorry, this construct is not supported");
498 case FieldSpec::FS_O
:
499 case FieldSpec::FS_OS
:
500 error("This notation is not permitted (type, (fixed- or"
501 " variabletype) value or valueset fieldreference was"
504 case FieldSpec::FS_ERROR
:
507 FATAL_ERROR("Unhandled fieldspec type");
508 } // switch fspec.fstype
511 switch(curr_fspec
->get_fstype()) {
512 case FieldSpec::FS_O
: {
513 FieldSpec_O
*tmp_fspec
=
514 dynamic_cast<FieldSpec_O
*>(curr_fspec
);
515 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
516 OSEV_objcollctr
objcoll(this, t_oc
);
517 Objects
*t_objs
= fromobjs
->get_objs();
518 for(size_t j
=0; j
<t_objs
->get_nof_objs(); j
++) {
519 t_o
=t_objs
->get_obj_byIndex(j
)->get_refd_last();
520 if(!t_o
->has_fs_withName_dflt(*curr_fn
)) continue;
521 t_setting
=t_o
->get_setting_byName_dflt(*curr_fn
);
522 t_o
=dynamic_cast<Object
*>(t_setting
)->get_refd_last();
523 objcoll
.visit_Object(*t_o
);
526 fromobjs
=new OS_defn(objcoll
.give_objs());
527 fromobjs
->set_location(*this);
528 fromobjs
->set_my_governor(t_oc
);
529 fromobjs
->set_my_scope(my_scope
);
532 case FieldSpec::FS_OS
: {
533 FieldSpec_OS
*tmp_fspec
=
534 dynamic_cast<FieldSpec_OS
*>(curr_fspec
);
535 t_oc
=tmp_fspec
->get_oc()->get_refd_last();
536 OSEV_objcollctr
objcoll(this, t_oc
);
537 Objects
*t_objs
= fromobjs
->get_objs();
538 for(size_t j
=0; j
<t_objs
->get_nof_objs(); j
++) {
539 t_o
=t_objs
->get_obj_byIndex(j
)->get_refd_last();
540 if(!t_o
->has_fs_withName_dflt(*curr_fn
)) continue;
541 t_setting
=t_o
->get_setting_byName_dflt(*curr_fn
);
542 t_os
=dynamic_cast<ObjectSet
*>(t_setting
)->get_refd_last();
543 objcoll
.visit_ObjectSet(*t_os
);
546 fromobjs
=new OS_defn(objcoll
.give_objs());
547 fromobjs
->set_location(*this);
548 fromobjs
->set_my_governor(t_oc
);
549 fromobjs
->set_my_scope(my_scope
);
552 case FieldSpec::FS_V_FT
:
553 case FieldSpec::FS_VS_FT
:
554 error("Sorry, ValueSetFromObjects not supported");
556 case FieldSpec::FS_ERROR
:
559 error("This notation is not permitted (object, objectset,"
560 " (fixed type) value or valueset fieldreference was"
563 } // switch fspec.fstype
566 setting_cache
= t_o
->get_setting_byName_dflt(*curr_fn
);
569 FATAL_ERROR("Asn::FromObj::get_refd_setting()");
571 } // errorcontext-block
572 if (!setting_cache
) setting_cache
= setting
;
577 setting_cache
=get_refd_setting_error();
579 return setting_cache
;
582 Common::Assignment
* FromObj::get_refd_assignment(bool check_parlist
)
584 return ref_defd
->get_refd_assignment(check_parlist
);
587 bool FromObj::has_single_expr()
589 FATAL_ERROR("FromObj::has_single_expr()");
593 void FromObj::generate_code(expression_struct_t
*)
595 FATAL_ERROR("FromObj::generate_code()");
598 void FromObj::generate_code_const_ref(expression_struct_t */
*expr*/
)
600 FATAL_ERROR("FromObj::generate_code_const_ref()");
This page took 0.080586 seconds and 4 git commands to generate.