2 * @file be_visitor_xplicit_pre_proc.cpp
6 //=============================================================================
8 #include "be_visitor_xplicit_pre_proc.h"
10 #include "be_component.h"
11 #include "be_interface.h"
12 #include "be_operation.h"
13 #include "be_argument.h"
14 #include "be_finder.h"
15 #include "be_exception.h"
17 #include "be_valuebox.h"
18 #include "be_eventtype.h"
19 #include "be_typedef.h"
20 #include "be_predefined_type.h"
22 #include "be_enum_val.h"
24 #include "be_union_fwd.h"
25 #include "be_union_branch.h"
26 #include "be_attribute.h"
27 #include "be_constant.h"
29 #include "be_sequence.h"
30 #include "be_string.h"
31 #include "be_native.h"
33 #include "ast_module.h"
35 #include "utl_namelist.h"
36 #include "utl_labellist.h"
37 #include "utl_exprlist.h"
38 #include "utl_exceptlist.h"
40 #include "fe_obv_header.h"
41 #include "nr_extern.h"
42 #include "global_extern.h"
44 be_visitor_xplicit_pre_proc::be_visitor_xplicit_pre_proc (
45 be_visitor_context
*ctx
)
46 : be_visitor_ccm_pre_proc (ctx
),
48 type_holder_ (nullptr),
53 be_visitor_xplicit_pre_proc::~be_visitor_xplicit_pre_proc ()
58 be_visitor_xplicit_pre_proc::visit_home (be_home
*node
)
60 UTL_NameList
*parent_list
= this->compute_inheritance (node
);
62 FE_InterfaceHeader
header (nullptr,
68 // We're at global scope here so we need to fool the scope stack
69 // for a minute so the correct repo id can be calculated at
70 // interface construction time.
72 dynamic_cast<AST_Module
*> (node
->defined_in ());
74 idl_global
->scopes ().push (m
);
76 UTL_ScopedName
*explicit_name
=
77 this->create_scoped_name (
79 node
->original_local_name ()->get_string (),
83 be_interface
*i
= nullptr;
85 be_interface (explicit_name
,
88 header
.inherits_flat (),
89 header
.n_inherits_flat (),
94 (void) m
->be_add_interface (i
);
96 i
->original_interface (node
);
97 i
->set_imported (node
->imported ());
99 // So we can generate the proper typecode.
100 i
->home_equiv (true);
102 idl_global
->scopes ().push (i
);
104 if (this->visit_scope (node
) != 0)
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
108 ACE_TEXT ("visit_home - code generation ")
109 ACE_TEXT ("for home scope failed\n")),
113 // Through with the explicit interface scope
114 idl_global
->scopes ().pop ();
116 explicit_name
->destroy ();
117 delete explicit_name
;
118 explicit_name
= nullptr;
122 parent_list
->destroy ();
124 parent_list
= nullptr;
126 // Through with the scope containing the home.
127 idl_global
->scopes ().pop ();
135 be_visitor_xplicit_pre_proc::visit_operation (be_operation
*node
)
137 UTL_ScopedName
sn (node
->local_name (), nullptr);
139 be_operation
*home_op
= nullptr;
140 ACE_NEW_RETURN (home_op
,
141 be_operation (node
->return_type (),
148 UTL_ExceptList
*excep_list
= node
->exceptions ();
149 if (nullptr != excep_list
)
151 home_op
->be_add_exceptions (excep_list
->copy ());
154 idl_global
->scopes ().top ()->add_to_scope (home_op
);
155 idl_global
->scopes ().push (home_op
);
157 if (this->visit_scope (node
) != 0)
159 ACE_ERROR_RETURN ((LM_ERROR
,
160 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
161 ACE_TEXT ("visit_operation - code generation ")
162 ACE_TEXT ("for scope failed\n")),
166 idl_global
->scopes ().pop ();
172 be_visitor_xplicit_pre_proc::visit_argument (be_argument
*node
)
174 UTL_ScopedName
sn (node
->local_name (), nullptr);
176 this->ref_type_
= true;
179 dynamic_cast<be_type
*> (node
->field_type ());
181 if (ft
->accept (this) != 0)
183 ACE_ERROR_RETURN ((LM_ERROR
,
184 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
185 ACE_TEXT ("visit_argument - code generation ")
186 ACE_TEXT ("for arg type failed\n")),
190 this->ref_type_
= false;
193 dynamic_cast<AST_Type
*> (this->type_holder_
);
195 be_argument
*added_arg
= nullptr;
196 ACE_NEW_RETURN (added_arg
,
197 be_argument (node
->direction (),
202 idl_global
->scopes ().top ()->add_to_scope (added_arg
);
208 be_visitor_xplicit_pre_proc::visit_factory (be_factory
*node
)
210 UTL_ScopedName
sn (node
->local_name (), nullptr);
213 dynamic_cast<AST_Home
*> (node
->defined_in ());
215 be_operation
*added_factory
= nullptr;
216 ACE_NEW_RETURN (added_factory
,
217 be_operation (f_home
->managed_component (),
218 AST_Operation::OP_noflags
,
224 idl_global
->scopes ().top ()->add_to_scope (added_factory
);
225 idl_global
->scopes ().push (added_factory
);
227 if (this->visit_scope (node
) != 0)
229 ACE_ERROR_RETURN ((LM_ERROR
,
230 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
231 ACE_TEXT ("visit_factory - code generation ")
232 ACE_TEXT ("for scope failed\n")),
236 idl_global
->scopes ().pop ();
242 be_visitor_xplicit_pre_proc::visit_finder (be_finder
*node
)
244 UTL_ScopedName
sn (node
->local_name (), nullptr);
247 dynamic_cast<AST_Home
*> (node
->defined_in ());
249 be_operation
*added_finder
= nullptr;
250 ACE_NEW_RETURN (added_finder
,
251 be_operation (f_home
->managed_component (),
252 AST_Operation::OP_noflags
,
258 idl_global
->scopes ().top ()->add_to_scope (added_finder
);
259 idl_global
->scopes ().push (added_finder
);
261 if (this->visit_scope (node
) != 0)
263 ACE_ERROR_RETURN ((LM_ERROR
,
264 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
265 ACE_TEXT ("visit_finder - code generation ")
266 ACE_TEXT ("for scope failed\n")),
270 idl_global
->scopes ().pop ();
276 be_visitor_xplicit_pre_proc::visit_interface (be_interface
*node
)
278 // Interface can't be declared inside a home, no need to call
279 // check_and_store().
280 this->type_holder_
= node
;
286 be_visitor_xplicit_pre_proc::visit_valuebox (be_valuebox
*node
)
288 // Valuebox can't be declared inside a home, no need to call
289 // check_and_store().
290 this->type_holder_
= node
;
296 be_visitor_xplicit_pre_proc::visit_valuetype (be_valuetype
*node
)
298 // Valuetype can't be declared inside a home, no need to call
299 // check_and_store().
300 this->type_holder_
= node
;
306 be_visitor_xplicit_pre_proc::visit_eventtype (be_eventtype
*node
)
308 // Eventtype can't be declared inside a home, no need to call
309 // check_and_store().
310 this->type_holder_
= node
;
316 be_visitor_xplicit_pre_proc::visit_structure (be_structure
*node
)
320 this->check_and_store (node
);
324 UTL_ScopedName
sn (node
->local_name (), nullptr);
326 be_structure
*added_struct
= nullptr;
327 ACE_NEW_RETURN (added_struct
,
333 idl_global
->scopes ().top ()->add_to_scope (added_struct
);
334 idl_global
->scopes ().push (added_struct
);
336 if (this->visit_scope (node
) != 0)
338 ACE_ERROR_RETURN ((LM_ERROR
,
339 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
340 ACE_TEXT ("visit_structure - code generation ")
341 ACE_TEXT ("for scope failed\n")),
349 be_visitor_xplicit_pre_proc::visit_structure_fwd (
350 be_structure_fwd
*node
)
352 UTL_ScopedName
sn (node
->local_name (), nullptr);
354 be_structure
*dummy
= nullptr;
355 ACE_NEW_RETURN (dummy
,
361 be_structure_fwd
*added_struct_fwd
= nullptr;
362 ACE_NEW_RETURN (added_struct_fwd
,
363 be_structure_fwd (dummy
,
367 dummy
->fwd_decl (added_struct_fwd
);
369 idl_global
->scopes ().top ()->add_to_scope (added_struct_fwd
);
375 be_visitor_xplicit_pre_proc::visit_exception (be_exception
*node
)
377 UTL_ScopedName
sn (node
->local_name (), nullptr);
379 be_exception
*added_excep
= nullptr;
380 ACE_NEW_RETURN (added_excep
,
386 idl_global
->scopes ().top ()->add_to_scope (added_excep
);
387 idl_global
->scopes ().push (added_excep
);
389 if (this->visit_scope (node
) != 0)
391 ACE_ERROR_RETURN ((LM_ERROR
,
392 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
393 ACE_TEXT ("visit_exception - code generation ")
394 ACE_TEXT ("for scope failed\n")),
398 idl_global
->scopes ().pop ();
404 be_visitor_xplicit_pre_proc::visit_enum (be_enum
*node
)
408 this->check_and_store (node
);
412 UTL_ScopedName
sn (node
->local_name (), nullptr);
414 be_enum
*added_enum
= nullptr;
415 ACE_NEW_RETURN (added_enum
,
421 idl_global
->scopes ().top ()->add_to_scope (added_enum
);
422 idl_global
->scopes ().push (added_enum
);
424 if (this->visit_scope (node
) != 0)
426 ACE_ERROR_RETURN ((LM_ERROR
,
427 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
428 ACE_TEXT ("visit_enum - code generation ")
429 ACE_TEXT ("for scope failed\n")),
437 be_visitor_xplicit_pre_proc::visit_field (be_field
*node
)
439 this->ref_type_
= true;
442 dynamic_cast<be_type
*> (node
->field_type ());
444 if (ft
->accept (this) != 0)
446 ACE_ERROR_RETURN ((LM_ERROR
,
447 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
448 ACE_TEXT ("visit_field - code generation ")
449 ACE_TEXT ("for field type failed\n")),
453 this->ref_type_
= false;
455 UTL_ScopedName
sn (node
->local_name (), nullptr);
456 AST_Type
*field_type
=
457 dynamic_cast<AST_Type
*> (this->type_holder_
);
459 be_field
*added_field
= nullptr;
460 ACE_NEW_RETURN (added_field
,
461 be_field (field_type
,
463 node
->visibility ()),
466 idl_global
->scopes ().top ()->add_to_scope (added_field
);
472 be_visitor_xplicit_pre_proc::visit_attribute (be_attribute
*node
)
475 dynamic_cast<be_type
*> (node
->field_type ());
477 this->ref_type_
= true;
479 if (ft
->accept (this) != 0)
481 ACE_ERROR_RETURN ((LM_ERROR
,
482 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
483 ACE_TEXT ("visit_attribute - code generation ")
484 ACE_TEXT ("for attribute type failed\n")),
488 this->ref_type_
= false;
490 AST_Type
*attr_type
=
491 dynamic_cast<AST_Type
*> (this->type_holder_
);
493 UTL_ScopedName
sn (node
->local_name (), nullptr);
495 be_attribute
*added_attr
= nullptr;
496 ACE_NEW_RETURN (added_attr
,
497 be_attribute (node
->readonly (),
504 idl_global
->scopes ().top ()->add_to_scope (added_attr
);
510 be_visitor_xplicit_pre_proc::visit_union (be_union
*node
)
514 this->check_and_store (node
);
519 dynamic_cast<be_type
*> (node
->disc_type ());
521 this->ref_type_
= true;
523 if (ud
->accept (this) != 0)
525 ACE_ERROR_RETURN ((LM_ERROR
,
526 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
527 ACE_TEXT ("visit_union - code generation ")
528 ACE_TEXT ("for discriminator type failed\n")),
532 this->ref_type_
= false;
534 AST_ConcreteType
*disc
=
535 dynamic_cast<AST_ConcreteType
*> (this->type_holder_
);
537 UTL_ScopedName
sn (node
->local_name (), nullptr);
539 be_union
*added_union
= nullptr;
540 ACE_NEW_RETURN (added_union
,
547 idl_global
->scopes ().top ()->add_to_scope (added_union
);
548 idl_global
->scopes ().push (added_union
);
550 if (this->visit_scope (node
) != 0)
552 ACE_ERROR_RETURN ((LM_ERROR
,
553 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
554 ACE_TEXT ("visit_union - code generation ")
555 ACE_TEXT ("for scope failed\n")),
563 be_visitor_xplicit_pre_proc::visit_union_fwd (be_union_fwd
*node
)
565 UTL_ScopedName
sn (node
->local_name (), nullptr);
567 be_union
*dummy
= nullptr;
568 ACE_NEW_RETURN (dummy
,
575 be_union_fwd
*added_union_fwd
= nullptr;
576 ACE_NEW_RETURN (added_union_fwd
,
581 dummy
->fwd_decl (added_union_fwd
);
583 idl_global
->scopes ().top ()->add_to_scope (added_union_fwd
);
589 be_visitor_xplicit_pre_proc::visit_union_branch (
590 be_union_branch
*node
)
593 dynamic_cast<be_type
*> (node
->field_type ());
595 this->ref_type_
= true;
597 if (ft
->accept (this) != 0)
599 ACE_ERROR_RETURN ((LM_ERROR
,
600 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
601 ACE_TEXT ("visit_union_branch - code generation ")
602 ACE_TEXT ("for branch type failed\n")),
606 this->ref_type_
= false;
609 dynamic_cast<AST_Type
*> (this->type_holder_
);
611 UTL_ScopedName
sn (node
->local_name (), nullptr);
613 // The union branch owns its label list so we have to copy it.
614 UTL_LabelList
*ll
= node
->labels ()->copy ();
616 be_union_branch
*added_branch
= nullptr;
617 ACE_NEW_RETURN (added_branch
,
618 be_union_branch (ll
, bt
, &sn
),
621 // fe_add_union_branch() does necessary things besides calling
622 // add_to_scope() so we need to reuse it.
625 dynamic_cast<be_union
*> (idl_global
->scopes ().top ());
627 u
->be_add_union_branch (added_branch
);
633 be_visitor_xplicit_pre_proc::visit_union_label (be_union_label
*)
639 be_visitor_xplicit_pre_proc::visit_constant (be_constant
*node
)
643 this->check_and_store (node
);
647 AST_Expression
*new_v
= nullptr;
648 ACE_NEW_RETURN (new_v
,
649 AST_Expression (node
->constant_value (),
653 UTL_ScopedName
sn (node
->local_name (), nullptr);
655 be_constant
*added_const
= nullptr;
656 ACE_NEW_RETURN (added_const
,
657 be_constant (node
->et (),
662 idl_global
->scopes ().top ()->add_to_scope (added_const
);
668 be_visitor_xplicit_pre_proc::visit_enum_val (be_enum_val
*node
)
672 this->type_holder_
= node
;
676 UTL_ScopedName
sn (node
->local_name (), nullptr);
678 be_enum_val
*added_enum_val
= nullptr;
679 ACE_NEW_RETURN (added_enum_val
,
680 be_enum_val (node
->constant_value ()->ev ()->u
.ulval
,
684 idl_global
->scopes ().top ()->add_to_scope (added_enum_val
);
690 be_visitor_xplicit_pre_proc::visit_array (be_array
*node
)
693 dynamic_cast<be_type
*> (node
->base_type ());
695 bool tmp
= this->ref_type_
;
696 this->ref_type_
= true;
698 if (bt
->accept (this) != 0)
700 ACE_ERROR_RETURN ((LM_ERROR
,
701 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
702 ACE_TEXT ("visit_array - code generation ")
703 ACE_TEXT ("for base type failed\n")),
707 this->ref_type_
= tmp
;
709 AST_Expression
*v
= nullptr;
710 UTL_ExprList
*v_list
= nullptr;
712 for (ACE_CDR::ULong i
= 0; i
< node
->n_dims (); ++i
)
715 AST_Expression (node
->dims ()[i
],
716 AST_Expression::EV_ulong
),
719 UTL_ExprList
*el
= nullptr;
721 UTL_ExprList (v
, nullptr),
724 if (v_list
== nullptr)
734 UTL_ScopedName
sn (node
->local_name (), nullptr);
736 be_array
*added_array
= nullptr;
737 ACE_NEW_RETURN (added_array
,
745 // No need to add this new node to any scope - it's anonymous
746 // and owned by the node that references it.
748 if (v_list
!= nullptr)
755 AST_Type
*base_type
=
756 dynamic_cast<AST_Type
*> (this->type_holder_
);
758 added_array
->set_base_type (base_type
);
760 this->type_holder_
= added_array
;
766 be_visitor_xplicit_pre_proc::visit_sequence (be_sequence
*node
)
769 dynamic_cast<be_type
*> (node
->base_type ());
771 bool tmp
= this->ref_type_
;
772 this->ref_type_
= true;
774 if (bt
->accept (this) != 0)
776 ACE_ERROR_RETURN ((LM_ERROR
,
777 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
778 ACE_TEXT ("visit_sequence - code generation ")
779 ACE_TEXT ("for element type failed\n")),
783 this->ref_type_
= tmp
;
785 AST_Expression
*v
= node
->max_size ();
787 AST_Expression
*bound
= nullptr;
788 ACE_NEW_RETURN (bound
,
790 AST_Expression::EV_ulong
),
793 Identifier
id ("sequence");
794 UTL_ScopedName
sn (&id
, nullptr);
797 dynamic_cast<AST_Type
*> (this->type_holder_
);
799 ACE_NEW_RETURN (this->type_holder_
,
807 // No need to add this new node to any scope - it's anonymous
808 // and owned by the node that references it.
814 be_visitor_xplicit_pre_proc::visit_string (be_string
*node
)
818 this->check_and_store (node
);
822 AST_Expression
*b
= node
->max_size ();
824 if (b
->ev ()->u
.ulval
== 0)
826 this->type_holder_
= node
;
830 AST_Expression
*bound
= nullptr;
831 ACE_NEW_RETURN (bound
,
833 AST_Expression::EV_ulong
),
836 Identifier
id ("string");
837 UTL_ScopedName
sn (&id
, nullptr);
839 ACE_NEW_RETURN (this->type_holder_
,
840 be_string (AST_Decl::NT_string
,
850 be_visitor_xplicit_pre_proc::visit_typedef (be_typedef
*node
)
854 this->check_and_store (node
);
859 dynamic_cast<be_type
*> (node
->field_type ());
861 this->ref_type_
= true;
863 if (t
->accept (this) != 0)
865 ACE_ERROR_RETURN ((LM_ERROR
,
866 ACE_TEXT ("be_visitor_xplicit_pre_proc::")
867 ACE_TEXT ("visit_typedef - code generation ")
868 ACE_TEXT ("for base type failed\n")),
872 this->ref_type_
= false;
874 UTL_ScopedName
sn (node
->local_name (), nullptr);
876 dynamic_cast<AST_Type
*> (this->type_holder_
);
878 be_typedef
*added_typedef
= nullptr;
879 ACE_NEW_RETURN (added_typedef
,
886 idl_global
->scopes ().top ()->add_to_scope (added_typedef
);
892 be_visitor_xplicit_pre_proc::visit_native (be_native
*node
)
896 this->check_and_store (node
);
900 UTL_ScopedName
sn (node
->local_name (), nullptr);
902 be_native
*added_native
= nullptr;
903 ACE_NEW_RETURN (added_native
,
907 idl_global
->scopes ().top ()->add_to_scope (added_native
);
913 be_visitor_xplicit_pre_proc::visit_predefined_type (
914 be_predefined_type
*node
)
916 this->type_holder_
= node
;
922 be_visitor_xplicit_pre_proc::xplicit () const
924 return this->xplicit_
;
928 be_visitor_xplicit_pre_proc::check_and_store (AST_Decl
*node
)
930 UTL_ScopedName
*tmpl_tail
=
931 this->xplicit_iface_rel_name (node
);
933 if (tmpl_tail
!= nullptr)
936 idl_global
->scopes ().top ()->lookup_by_name (
940 this->type_holder_
= d
;
942 tmpl_tail
->destroy ();
948 this->type_holder_
= node
;
953 be_visitor_xplicit_pre_proc::xplicit_iface_rel_name (AST_Decl
*d
)
956 ACE_CString
name (d
->full_name ());
958 while (tmp
!= nullptr)
960 if (dynamic_cast<be_home
*> (tmp
) != nullptr)
962 ACE_CString
head (tmp
->local_name ()->get_string ());
964 ACE_CString::size_type start
= name
.find (head
) + 2;
966 ACE_CString
tail (name
.substr (start
+ head
.length ()));
968 return FE_Utils::string_to_scoped_name (tail
.c_str ());
971 tmp
= ScopeAsDecl (tmp
->defined_in ());