Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_xplicit_pre_proc.cpp
blob10e49e6f12a48f0009bc20b4137c85e438e77077
1 /**
2 * @file be_visitor_xplicit_pre_proc.cpp
4 * @author Jeff Parsons
5 */
6 //=============================================================================
8 #include "be_visitor_xplicit_pre_proc.h"
9 #include "be_home.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"
16 #include "be_field.h"
17 #include "be_valuebox.h"
18 #include "be_eventtype.h"
19 #include "be_typedef.h"
20 #include "be_predefined_type.h"
21 #include "be_enum.h"
22 #include "be_enum_val.h"
23 #include "be_union.h"
24 #include "be_union_fwd.h"
25 #include "be_union_branch.h"
26 #include "be_attribute.h"
27 #include "be_constant.h"
28 #include "be_array.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),
47 xplicit_ (0),
48 type_holder_ (0),
49 ref_type_ (false)
53 be_visitor_xplicit_pre_proc::~be_visitor_xplicit_pre_proc (void)
57 int
58 be_visitor_xplicit_pre_proc::visit_home (be_home *node)
60 UTL_NameList *parent_list = this->compute_inheritance (node);
62 FE_InterfaceHeader header (0,
63 parent_list,
64 false,
65 false,
66 true);
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.
71 AST_Module *m =
72 dynamic_cast<AST_Module*> (node->defined_in ());
74 idl_global->scopes ().push (m);
76 UTL_ScopedName *explicit_name =
77 this->create_scoped_name (
78 "",
79 node->original_local_name ()->get_string (),
80 "Explicit",
81 m);
83 be_interface *i = 0;
84 ACE_NEW_RETURN (i,
85 be_interface (explicit_name,
86 header.inherits (),
87 header.n_inherits (),
88 header.inherits_flat (),
89 header.n_inherits_flat (),
90 false,
91 false),
92 0);
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 = 0;
120 header.destroy ();
122 parent_list->destroy ();
123 delete parent_list;
124 parent_list = 0;
126 // Through with the scope containing the home.
127 idl_global->scopes ().pop ();
129 this->xplicit_ = i;
131 return 0;
135 be_visitor_xplicit_pre_proc::visit_operation (be_operation *node)
137 UTL_ScopedName sn (node->local_name (), 0);
139 be_operation *home_op = 0;
140 ACE_NEW_RETURN (home_op,
141 be_operation (node->return_type (),
142 node->flags (),
143 &sn,
144 false,
145 false),
146 -1);
148 UTL_ExceptList *excep_list = node->exceptions ();
149 if (0 != 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")),
163 -1);
166 idl_global->scopes ().pop ();
168 return 0;
172 be_visitor_xplicit_pre_proc::visit_argument (be_argument *node)
174 UTL_ScopedName sn (node->local_name (), 0);
176 this->ref_type_ = true;
178 be_type *ft =
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")),
187 -1);
190 this->ref_type_ = false;
192 AST_Type *arg_type =
193 dynamic_cast<AST_Type*> (this->type_holder_);
195 be_argument *added_arg = 0;
196 ACE_NEW_RETURN (added_arg,
197 be_argument (node->direction (),
198 arg_type,
199 &sn),
200 -1);
202 idl_global->scopes ().top ()->add_to_scope (added_arg);
204 return 0;
208 be_visitor_xplicit_pre_proc::visit_factory (be_factory *node)
210 UTL_ScopedName sn (node->local_name (), 0);
212 AST_Home *f_home =
213 dynamic_cast<AST_Home*> (node->defined_in ());
215 be_operation *added_factory = 0;
216 ACE_NEW_RETURN (added_factory,
217 be_operation (f_home->managed_component (),
218 AST_Operation::OP_noflags,
219 &sn,
220 false,
221 false),
222 -1);
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")),
233 -1);
236 idl_global->scopes ().pop ();
238 return 0;
242 be_visitor_xplicit_pre_proc::visit_finder (be_finder *node)
244 UTL_ScopedName sn (node->local_name (), 0);
246 AST_Home *f_home =
247 dynamic_cast<AST_Home*> (node->defined_in ());
249 be_operation *added_finder = 0;
250 ACE_NEW_RETURN (added_finder,
251 be_operation (f_home->managed_component (),
252 AST_Operation::OP_noflags,
253 &sn,
254 false,
255 false),
256 -1);
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")),
267 -1);
270 idl_global->scopes ().pop ();
272 return 0;
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;
282 return 0;
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;
292 return 0;
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;
302 return 0;
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;
312 return 0;
316 be_visitor_xplicit_pre_proc::visit_structure (be_structure *node)
318 if (this->ref_type_)
320 this->check_and_store (node);
321 return 0;
324 UTL_ScopedName sn (node->local_name (), 0);
326 be_structure *added_struct = 0;
327 ACE_NEW_RETURN (added_struct,
328 be_structure (&sn,
329 false,
330 false),
331 -1);
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")),
342 -1);
345 return 0;
349 be_visitor_xplicit_pre_proc::visit_structure_fwd (
350 be_structure_fwd *node)
352 UTL_ScopedName sn (node->local_name (), 0);
354 be_structure *dummy = 0;
355 ACE_NEW_RETURN (dummy,
356 be_structure (&sn,
357 false,
358 false),
359 -1);
361 be_structure_fwd *added_struct_fwd = 0;
362 ACE_NEW_RETURN (added_struct_fwd,
363 be_structure_fwd (dummy,
364 &sn),
365 -1);
367 dummy->fwd_decl (added_struct_fwd);
369 idl_global->scopes ().top ()->add_to_scope (added_struct_fwd);
371 return 0;
375 be_visitor_xplicit_pre_proc::visit_exception (be_exception *node)
377 UTL_ScopedName sn (node->local_name (), 0);
379 be_exception *added_excep = 0;
380 ACE_NEW_RETURN (added_excep,
381 be_exception (&sn,
382 false,
383 false),
384 -1);
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")),
395 -1);
398 idl_global->scopes ().pop ();
400 return 0;
404 be_visitor_xplicit_pre_proc::visit_enum (be_enum *node)
406 if (this->ref_type_)
408 this->check_and_store (node);
409 return 0;
412 UTL_ScopedName sn (node->local_name (), 0);
414 be_enum *added_enum = 0;
415 ACE_NEW_RETURN (added_enum,
416 be_enum (&sn,
417 false,
418 false),
419 -1);
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")),
430 -1);
433 return 0;
437 be_visitor_xplicit_pre_proc::visit_field (be_field *node)
439 this->ref_type_ = true;
441 be_type *ft =
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")),
450 -1);
453 this->ref_type_ = false;
455 UTL_ScopedName sn (node->local_name (), 0);
456 AST_Type *field_type =
457 dynamic_cast<AST_Type*> (this->type_holder_);
459 be_field *added_field = 0;
460 ACE_NEW_RETURN (added_field,
461 be_field (field_type,
462 &sn,
463 node->visibility ()),
464 -1);
466 idl_global->scopes ().top ()->add_to_scope (added_field);
468 return 0;
472 be_visitor_xplicit_pre_proc::visit_attribute (be_attribute *node)
474 be_type *ft =
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")),
485 -1);
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 (), 0);
495 be_attribute *added_attr = 0;
496 ACE_NEW_RETURN (added_attr,
497 be_attribute (node->readonly (),
498 attr_type,
499 &sn,
500 false,
501 false),
502 -1);
504 idl_global->scopes ().top ()->add_to_scope (added_attr);
506 return 0;
510 be_visitor_xplicit_pre_proc::visit_union (be_union *node)
512 if (this->ref_type_)
514 this->check_and_store (node);
515 return 0;
518 be_type *ud =
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")),
529 -1);
532 this->ref_type_ = false;
534 AST_ConcreteType *disc =
535 dynamic_cast<AST_ConcreteType*> (this->type_holder_);
537 UTL_ScopedName sn (node->local_name (), 0);
539 be_union *added_union = 0;
540 ACE_NEW_RETURN (added_union,
541 be_union (disc,
542 &sn,
543 false,
544 false),
545 -1);
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")),
556 -1);
559 return 0;
563 be_visitor_xplicit_pre_proc::visit_union_fwd (be_union_fwd *node)
565 UTL_ScopedName sn (node->local_name (), 0);
567 be_union *dummy = 0;
568 ACE_NEW_RETURN (dummy,
569 be_union (0,
570 &sn,
571 false,
572 false),
573 -1);
575 be_union_fwd *added_union_fwd = 0;
576 ACE_NEW_RETURN (added_union_fwd,
577 be_union_fwd (dummy,
578 &sn),
579 -1);
581 dummy->fwd_decl (added_union_fwd);
583 idl_global->scopes ().top ()->add_to_scope (added_union_fwd);
585 return 0;
589 be_visitor_xplicit_pre_proc::visit_union_branch (
590 be_union_branch *node)
592 be_type *ft =
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")),
603 -1);
606 this->ref_type_ = false;
608 AST_Type *bt =
609 dynamic_cast<AST_Type*> (this->type_holder_);
611 UTL_ScopedName sn (node->local_name (), 0);
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 = 0;
617 ACE_NEW_RETURN (added_branch,
618 be_union_branch (ll, bt, &sn),
619 -1);
621 // fe_add_union_branch() does necessary things besides calling
622 // add_to_scope() so we need to reuse it.
624 be_union *u =
625 dynamic_cast<be_union*> (idl_global->scopes ().top ());
627 u->be_add_union_branch (added_branch);
629 return 0;
633 be_visitor_xplicit_pre_proc::visit_union_label (be_union_label *)
635 return 0;
639 be_visitor_xplicit_pre_proc::visit_constant (be_constant *node)
641 if (this->ref_type_)
643 this->check_and_store (node);
644 return 0;
647 AST_Expression *new_v = 0;
648 ACE_NEW_RETURN (new_v,
649 AST_Expression (node->constant_value (),
650 node->et ()),
651 -1);
653 UTL_ScopedName sn (node->local_name (), 0);
655 be_constant *added_const = 0;
656 ACE_NEW_RETURN (added_const,
657 be_constant (node->et (),
658 new_v,
659 &sn),
660 -1);
662 idl_global->scopes ().top ()->add_to_scope (added_const);
664 return 0;
668 be_visitor_xplicit_pre_proc::visit_enum_val (be_enum_val *node)
670 if (this->ref_type_)
672 this->type_holder_ = node;
673 return 0;
676 UTL_ScopedName sn (node->local_name (), 0);
678 be_enum_val *added_enum_val = 0;
679 ACE_NEW_RETURN (added_enum_val,
680 be_enum_val (node->constant_value ()->ev ()->u.ulval,
681 &sn),
682 -1);
684 idl_global->scopes ().top ()->add_to_scope (added_enum_val);
686 return 0;
690 be_visitor_xplicit_pre_proc::visit_array (be_array *node)
692 be_type *bt =
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")),
704 -1);
707 this->ref_type_ = tmp;
709 AST_Expression *v = 0;
710 UTL_ExprList *v_list = 0;
712 for (ACE_CDR::ULong i = 0; i < node->n_dims (); ++i)
714 ACE_NEW_RETURN (v,
715 AST_Expression (node->dims ()[i],
716 AST_Expression::EV_ulong),
717 -1);
719 UTL_ExprList *el = 0;
720 ACE_NEW_RETURN (el,
721 UTL_ExprList (v, 0),
722 -1);
724 if (v_list == 0)
726 v_list = el;
728 else
730 v_list->nconc (el);
734 UTL_ScopedName sn (node->local_name (), 0);
736 be_array *added_array = 0;
737 ACE_NEW_RETURN (added_array,
738 be_array (&sn,
739 node->n_dims (),
740 v_list,
741 false,
742 false),
743 -1);
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 != 0)
750 v_list->destroy ();
751 delete v_list;
752 v_list = 0;
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;
762 return 0;
766 be_visitor_xplicit_pre_proc::visit_sequence (be_sequence *node)
768 be_type *bt =
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")),
780 -1);
783 this->ref_type_ = tmp;
785 AST_Expression *v = node->max_size ();
787 AST_Expression *bound = 0;
788 ACE_NEW_RETURN (bound,
789 AST_Expression (v,
790 AST_Expression::EV_ulong),
791 -1);
793 Identifier id ("sequence");
794 UTL_ScopedName sn (&id, 0);
796 AST_Type *ft =
797 dynamic_cast<AST_Type*> (this->type_holder_);
799 ACE_NEW_RETURN (this->type_holder_,
800 be_sequence (bound,
802 &sn,
803 false,
804 false),
805 -1);
807 // No need to add this new node to any scope - it's anonymous
808 // and owned by the node that references it.
810 return 0;
814 be_visitor_xplicit_pre_proc::visit_string (be_string *node)
816 if (this->ref_type_)
818 this->check_and_store (node);
819 return 0;
822 AST_Expression *b = node->max_size ();
824 if (b->ev ()->u.ulval == 0)
826 this->type_holder_ = node;
827 return 0;
830 AST_Expression *bound = 0;
831 ACE_NEW_RETURN (bound,
832 AST_Expression (b,
833 AST_Expression::EV_ulong),
834 -1);
836 Identifier id ("string");
837 UTL_ScopedName sn (&id, 0);
839 ACE_NEW_RETURN (this->type_holder_,
840 be_string (AST_Decl::NT_string,
841 &sn,
842 bound,
843 node->width ()),
844 -1);
846 return 0;
850 be_visitor_xplicit_pre_proc::visit_typedef (be_typedef *node)
852 if (this->ref_type_)
854 this->check_and_store (node);
855 return 0;
858 be_type *t =
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")),
869 -1);
872 this->ref_type_ = false;
874 UTL_ScopedName sn (node->local_name (), 0);
875 AST_Type *bt =
876 dynamic_cast<AST_Type*> (this->type_holder_);
878 be_typedef *added_typedef = 0;
879 ACE_NEW_RETURN (added_typedef,
880 be_typedef (bt,
881 &sn,
882 false,
883 false),
884 -1);
886 idl_global->scopes ().top ()->add_to_scope (added_typedef);
888 return 0;
892 be_visitor_xplicit_pre_proc::visit_native (be_native *node)
894 if (this->ref_type_)
896 this->check_and_store (node);
897 return 0;
900 UTL_ScopedName sn (node->local_name (), 0);
902 be_native *added_native = 0;
903 ACE_NEW_RETURN (added_native,
904 be_native (&sn),
905 -1);
907 idl_global->scopes ().top ()->add_to_scope (added_native);
909 return 0;
913 be_visitor_xplicit_pre_proc::visit_predefined_type (
914 be_predefined_type *node)
916 this->type_holder_ = node;
918 return 0;
921 be_interface *
922 be_visitor_xplicit_pre_proc::xplicit (void) const
924 return this->xplicit_;
927 void
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 != 0)
935 AST_Decl *d =
936 idl_global->scopes ().top ()->lookup_by_name (
937 tmpl_tail,
938 true);
940 this->type_holder_ = d;
942 tmpl_tail->destroy ();
943 delete tmpl_tail;
944 tmpl_tail = 0;
946 else
948 this->type_holder_ = node;
952 UTL_ScopedName *
953 be_visitor_xplicit_pre_proc::xplicit_iface_rel_name (AST_Decl *d)
955 AST_Decl *tmp = d;
956 ACE_CString name (d->full_name ());
958 while (tmp != 0)
960 if (dynamic_cast<be_home*> (tmp) != 0)
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 ());
974 return 0;