Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_ami_pre_proc.cpp
blob5b37f293a44936795acbc69d2c878af6387658c9
2 /* -*- c++ -*- */
3 //=============================================================================
4 /**
5 * @file be_visitor_ami_pre_proc.cpp
7 * This visitor creates for AMI implied IDL constructs
8 * the appropriate AST (Abstract Syntax Tree) node,
9 * sets the corresponding interface or operation strategy
10 * on it and enteres the nodes into the AST.
12 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
14 //=============================================================================
16 #include "be_visitor_ami_pre_proc.h"
17 #include "be_visitor_context.h"
18 #include "be_root.h"
19 #include "be_module.h"
20 #include "be_interface.h"
21 #include "be_valuetype.h"
22 #include "be_operation.h"
23 #include "be_attribute.h"
24 #include "be_predefined_type.h"
25 #include "be_argument.h"
27 #include "be_global.h"
28 #include "be_extern.h"
30 #include "utl_identifier.h"
31 #include "utl_exceptlist.h"
33 #include "nr_extern.h"
34 #include "global_extern.h"
36 #include "ace/Log_Msg.h"
38 be_visitor_ami_pre_proc::be_visitor_ami_pre_proc (be_visitor_context *ctx)
39 : be_visitor_scope (ctx)
43 be_visitor_ami_pre_proc::~be_visitor_ami_pre_proc ()
47 int
48 be_visitor_ami_pre_proc::visit_root (be_root *node)
50 if (this->visit_scope (node) == -1)
52 ACE_ERROR_RETURN ((LM_ERROR,
53 ACE_TEXT ("be_visitor_ami_pre_proc::")
54 ACE_TEXT ("visit_root - ")
55 ACE_TEXT ("visit scope failed\n")),
56 -1);
59 if (be_global->ami4ccm_call_back ())
61 /// Generate the *A.idl file containing AMI4CCM-related
62 /// interfaces and connector.
63 int status = this->generate_ami4ccm_idl ();
65 if (status == -1)
67 ACE_ERROR_RETURN ((LM_ERROR,
68 ACE_TEXT ("be_visitor_ami_pre_proc::")
69 ACE_TEXT ("visit_root - ")
70 ACE_TEXT ("generate_ami4ccm_idl() ")
71 ACE_TEXT ("failed\n")),
72 -1);
76 return 0;
79 int
80 be_visitor_ami_pre_proc::visit_module (be_module *node)
82 // Skip this for now until we get AMI integrated with
83 // CIAO.
84 if (0 == ACE_OS::strcmp (node->local_name ()->get_string (), "Components"))
86 return 0;
89 if (this->visit_scope (node) == -1)
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "(%N:%l) be_visitor_ami_pre_proc::"
93 "visit_module - "
94 "visit scope failed\n"),
95 -1);
98 return 0;
102 be_visitor_ami_pre_proc::visit_interface (be_interface *node)
104 // We check for an imported node after generating the reply handler.
105 if (node->is_local () || node->is_abstract ())
107 return 0;
110 // The following 3 IF blocks are checks for CCM-related nodes, which
111 // we want to skip until we get AMI integrated with CIAO.
113 // Skip the *EventConsumer added for each eventtype.
114 if (node->is_event_consumer ())
116 return 0;
119 // Check for home equivalent interface. The lookup will find the
120 // home itself, which was declared first.
121 Identifier *node_lname = node->AST_Decl::local_name ();
122 AST_Decl *first_stored =
123 node->defined_in ()->lookup_by_name_local (node_lname, false);
125 if (nullptr != first_stored && first_stored->node_type () == AST_Decl::NT_home)
127 return 0;
130 ACE_CString lname (node_lname->get_string ());
132 // Skip the *Explict and *Implicit interfaces added for a home.
133 if (lname.substr (lname.length () - 6) == "plicit")
135 UTL_Scope *s = node->defined_in ();
136 Identifier local_id (lname.substr (0, lname.length () - 8).c_str ());
137 AST_Decl *d = s->lookup_by_name_local (&local_id, false);
138 local_id.destroy ();
140 if (nullptr != d)
142 return 0;
146 AST_Module *module =
147 dynamic_cast<AST_Module*> (node->defined_in ());
149 if (!module)
151 ACE_ERROR_RETURN ((LM_ERROR,
152 "(%N:%l) be_visitor_ami_pre_proc::"
153 "visit_interface - "
154 "module is null\n"),
155 -1);
158 be_interface *reply_handler = this->create_reply_handler (node);
160 if (reply_handler)
162 reply_handler->set_defined_in (node->defined_in ());
164 // Insert the ami handler after the node, the
165 // exception holder will be placed between these two later.
166 module->be_add_interface (reply_handler, node);
168 // Remember from whom we were cloned
169 reply_handler->original_interface (node);
171 // If this was created for an imported node, it will be wrong
172 // unless we set it.
173 reply_handler->set_imported (node->imported ());
175 else
177 ACE_ERROR_RETURN ((LM_ERROR,
178 "(%N:%l) be_visitor_ami_pre_proc::"
179 "visit_interface - "
180 "creating the reply handler failed\n"),
181 -1);
184 if (this->visit_scope (node) == -1)
186 ACE_ERROR_RETURN ((LM_ERROR,
187 "(%N:%l) be_visitor_ami_pre_proc::"
188 "visit_interface - "
189 "visit scope failed\n"),
190 -1);
193 return 0;
197 be_visitor_ami_pre_proc::visit_operation (be_operation *node)
199 if (node->flags () == AST_Operation::OP_oneway)
201 // We do nothing for oneways!
202 return 0;
205 be_interface *parent =
206 dynamic_cast<be_interface*> (node->defined_in ());
208 // If we're here, we're sure that the arg traits specialization
209 // for this will be needed.
210 be_global->messaging_exceptionholder ()->seen_in_operation (true);
212 be_operation *sendc_op =
213 this->create_sendc_operation (node); // for arguments = TRUE
215 parent->be_add_operation (sendc_op);
217 return 0;
221 be_visitor_ami_pre_proc::visit_attribute (be_attribute *node)
223 if (! node->readonly ())
225 /// Temporarily generate the set operation.
226 be_operation *set_operation =
227 this->generate_set_operation (node);
228 set_operation->set_defined_in (node->defined_in ());
230 this->visit_operation (set_operation);
232 set_operation->destroy ();
233 delete set_operation;
234 set_operation = nullptr;
237 /// Temporarily generate the get operation.
238 be_operation *get_operation =
239 this->generate_get_operation (node);
240 get_operation->set_defined_in (node->defined_in ());
242 this->visit_operation (get_operation);
244 get_operation->destroy ();
245 delete get_operation;
246 get_operation = nullptr;
248 return 0;
251 be_interface *
252 be_visitor_ami_pre_proc::create_reply_handler (be_interface *node)
254 // We're at global scope here so we need to fool the scope stack
255 // for a minute so the correct repo id can be calculated at
256 // interface construction time.
257 UTL_Scope *s = node->defined_in ();
258 idl_global->scopes ().push (s);
260 // Create the reply handler name.
261 ACE_CString reply_handler_local_name;
263 this->generate_name (reply_handler_local_name,
264 "AMI_",
265 node->name ()->last_component ()->get_string(),
266 "Handler");
268 UTL_ScopedName *reply_handler_name =
269 static_cast<UTL_ScopedName *> (node->name ()->copy ());
271 reply_handler_name->last_component ()->replace_string (
272 reply_handler_local_name.c_str ());
274 long n_parents = 0;
275 AST_Type **p_intf =
276 this->create_inheritance_list (node, n_parents);
278 if (p_intf == nullptr)
280 ACE_ERROR_RETURN ((LM_ERROR,
281 "(%N:%l) be_visitor_ami_pre_proc::visit_interface - "
282 "bad inheritance list\n"),
286 be_interface *reply_handler = nullptr;
287 ACE_NEW_RETURN (reply_handler,
288 be_interface (reply_handler_name, // name
289 p_intf, // list of inherited
290 n_parents, // number of inherited
291 nullptr, // list of all ancestors
292 0, // number of ancestors
293 0, // non-local
294 0), // non-abstract
295 nullptr);
297 // Back to reality.
298 idl_global->scopes ().pop ();
300 reply_handler->set_name (reply_handler_name);
301 reply_handler->set_defined_in (s);
303 /// Store here for convenient retrieval later.
304 node->ami_handler (reply_handler);
306 // Set repo id to 0, so it will be recomputed on the next access,
307 // and set the prefix to the node's prefix. All this is
308 // necessary in case the node's prefix was modified after
309 // its declaration.
310 reply_handler->AST_Decl::repoID (nullptr);
311 reply_handler->prefix (const_cast<char*> (node->prefix ()));
313 reply_handler->gen_fwd_helper_name ();
315 // Now our customized reply handler is created, we have to
316 // add the operations and attributes to the scope.
317 // Imported nodes get admitted here, so they can get
318 // the reply handler operations added, in case they are
319 // needed in the inheritance graph traversal for a
320 // child reply handler. However, no exception holder
321 // stuff is executed for an imported node.
322 if (node->nmembers () > 0)
324 this->elem_number_ = 0;
325 // Initialize an iterator to iterate thru our scope.
327 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
328 !si.is_done ();
329 si.next ())
331 AST_Decl *d = si.item ();
333 if (!d)
335 ACE_ERROR_RETURN ((LM_ERROR,
336 "(%N:%l) be_visitor_ami_pre_proc::visit_interface - "
337 "bad node in this scope\n"),
341 if (d->node_type () == AST_Decl::NT_attr)
343 be_attribute *attribute = dynamic_cast<be_attribute*> (d);
345 if (attribute)
347 be_operation *get_operation =
348 this->generate_get_operation (attribute);
350 this->create_reply_handler_operation (get_operation,
351 reply_handler);
353 this->create_excep_operation (get_operation,
354 reply_handler);
356 get_operation->destroy ();
357 delete get_operation;
358 get_operation = nullptr;
360 if (!attribute->readonly ())
362 be_operation *set_operation =
363 this->generate_set_operation (attribute);
365 this->create_reply_handler_operation (set_operation,
366 reply_handler);
368 this->create_excep_operation (set_operation,
369 reply_handler);
371 set_operation->destroy ();
372 delete set_operation;
373 set_operation = nullptr;
377 else
379 be_operation* operation = dynamic_cast<be_operation*> (d);
381 if (operation)
383 this->create_reply_handler_operation (operation,
384 reply_handler);
386 this->create_excep_operation (operation,
387 reply_handler);
390 } // end of while loop
391 } // end of if
393 reply_handler->is_ami_rh (true);
394 reply_handler->is_ami4ccm_rh (true);
396 return reply_handler;
399 be_operation *
400 be_visitor_ami_pre_proc::create_sendc_operation (be_operation *node)
402 if (node->flags () == AST_Operation::OP_oneway)
404 // We do nothing for oneways!
405 return nullptr;
408 Identifier *id = nullptr;
409 UTL_ScopedName *sn = nullptr;
411 // Create the new name
412 // Prepend "sendc_" to the name of the operation
413 ACE_CString original_op_name (
414 node->name ()->last_component ()->get_string ());
415 ACE_CString new_op_name =
416 ACE_CString ("sendc_") + original_op_name;
418 UTL_ScopedName *op_name =
419 static_cast<UTL_ScopedName *> (node->name ()->copy ());
420 op_name->last_component ()->replace_string (new_op_name.c_str ());
422 idl_global->scopes ().push (node->defined_in ());
424 // Create the operation
425 be_operation *op = nullptr;
426 ACE_NEW_RETURN (op,
427 be_operation (be_global->void_type (),
428 AST_Operation::OP_noflags,
429 op_name,
430 false,
431 false),
432 nullptr);
434 idl_global->scopes ().pop ();
436 op->set_name (op_name);
438 // Create the first argument, which is a Reply Handler
440 // Look up the field type.
441 UTL_Scope *s = node->defined_in ();
442 be_interface *parent = dynamic_cast<be_interface*> (s);
444 // Add the pre- and suffix
445 ACE_CString handler_local_name;
447 this->generate_name (
448 handler_local_name,
449 "AMI_",
450 parent->name ()->last_component ()->get_string (),
451 "Handler");
453 AST_Interface *handler = parent->ami_handler ();
455 if (nullptr == handler)
457 op->destroy ();
458 delete op;
459 op = nullptr;
461 ACE_ERROR_RETURN ((LM_ERROR,
462 ACE_TEXT ("be_visitor_ami_pre_proc::")
463 ACE_TEXT ("create_sendc_operation - ")
464 ACE_TEXT ("null reply ")
465 ACE_TEXT ("handler found\n")),
469 be_interface *field_type =
470 dynamic_cast<be_interface*> (handler);
472 ACE_NEW_RETURN (id,
473 Identifier ("ami_handler"),
474 nullptr);
476 UTL_ScopedName *tmp = nullptr;
478 ACE_NEW_RETURN (tmp,
479 UTL_ScopedName (id,
480 nullptr),
481 nullptr);
483 sn = (UTL_ScopedName *)op->name ()->copy ();
484 sn->nconc (tmp);
486 be_argument *arg = nullptr;
487 ACE_NEW_RETURN (arg,
488 be_argument (AST_Argument::dir_IN,
489 field_type, // is also a valuetype
490 sn),
491 nullptr);
493 arg->set_defined_in (op);
494 arg->set_name (sn);
495 op->be_add_argument (arg);
497 if (field_type->imported ())
499 field_type->seen_in_operation (false);
502 // Iterate over the arguments and put all the in and inout
503 // into the new method.
504 if (node->nmembers () > 0)
506 // initialize an iterator to iterate thru our scope
507 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
508 !si.is_done ();
509 si.next ())
511 AST_Decl *d = si.item ();
513 if (!d)
515 ACE_ERROR_RETURN ((
516 LM_ERROR,
517 "(%N:%l) be_visitor_ami_pre_proc::create_sendc_method - "
518 "bad node in this scope\n"
524 AST_Argument *original_arg = dynamic_cast<AST_Argument*> (d);
526 if (original_arg->direction () == AST_Argument::dir_IN ||
527 original_arg->direction () == AST_Argument::dir_INOUT)
529 // Create the argument.
530 be_argument *arg = nullptr;
531 UTL_ScopedName *new_name =
532 (UTL_ScopedName *)original_arg->name ()->copy ();
533 ACE_NEW_RETURN (arg,
534 be_argument (AST_Argument::dir_IN,
535 original_arg->field_type (),
536 new_name),
537 nullptr);
539 arg->set_defined_in (op);
540 arg->set_name (new_name);
541 op->be_add_argument (arg);
543 } // end of while loop
544 } // end of if
546 op->is_sendc_ami (true);
547 op->is_attr_op (node->is_attr_op ());
548 return op;
552 be_visitor_ami_pre_proc::create_reply_handler_operation (
553 be_operation *node,
554 be_interface *reply_handler)
556 if (!node)
558 return -1;
561 if (node->flags () == AST_Operation::OP_oneway)
563 // We do nothing for oneways!
564 return 0;
567 Identifier *id = nullptr;
568 UTL_ScopedName *sn = nullptr;
570 ACE_CString original_op_name (
571 node->name ()->last_component ()->get_string ()
574 UTL_ScopedName *op_name =
575 static_cast<UTL_ScopedName *> (reply_handler->name ()-> copy ());
577 ACE_NEW_RETURN (id,
578 Identifier (original_op_name.c_str ()),
579 -1);
581 ACE_NEW_RETURN (sn,
582 UTL_ScopedName (id,
583 nullptr),
584 -1);
586 op_name->nconc (sn);
588 // Create the operation.
589 be_operation *operation = nullptr;
590 ACE_NEW_RETURN (operation,
591 be_operation (be_global->void_type (),
592 AST_Operation::OP_noflags,
593 op_name,
596 -1);
598 operation->set_name (op_name);
600 // If return type is non-void add it as first argument.
602 if (!node->void_return_type ())
604 ACE_NEW_RETURN (id,
605 Identifier ("ami_return_val"),
606 -1);
608 UTL_ScopedName *tmp = nullptr;
610 ACE_NEW_RETURN (tmp,
611 UTL_ScopedName (id,
612 nullptr),
613 -1);
615 sn = (UTL_ScopedName *)operation->name ()->copy ();
616 sn->nconc (tmp);
618 // Create the argument.
619 be_argument *arg = nullptr;
620 ACE_NEW_RETURN (arg,
621 be_argument (AST_Argument::dir_IN,
622 node->return_type (),
623 sn),
624 -1);
626 arg->set_defined_in (operation);
627 arg->set_name (sn);
629 // Add the reply handler to the argument list.
630 operation->be_add_argument (arg);
633 // Iterate over the arguments and put all the in and inout
634 // into the new method.
635 if (node->nmembers () > 0)
637 // Initialize an iterator to iterate thru our scope.
638 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
639 !si.is_done ();
640 si.next ())
642 AST_Decl *d = si.item ();
644 if (d == nullptr)
646 operation->destroy ();
647 delete operation;
648 operation = nullptr;
650 ACE_ERROR_RETURN ((LM_ERROR,
651 ACE_TEXT ("be_visitor_ami_pre_proc::")
652 ACE_TEXT ("create_reply_handler_operation - ")
653 ACE_TEXT ("bad node in this scope\n")),
654 -1);
657 AST_Argument *original_arg = dynamic_cast<AST_Argument*> (d);
659 if (original_arg->direction () == AST_Argument::dir_INOUT ||
660 original_arg->direction () == AST_Argument::dir_OUT)
662 // Create the argument.
663 be_argument *arg = nullptr;
664 UTL_ScopedName *new_name =
665 (UTL_ScopedName *)original_arg->name ()->copy ();
666 ACE_NEW_RETURN (arg,
667 be_argument (AST_Argument::dir_IN,
668 original_arg->field_type (),
669 new_name),
670 -1);
672 arg->set_defined_in (operation);
673 arg->set_name (new_name);
674 operation->be_add_argument (arg);
676 } // end of while loop
677 } // end of if
679 operation->set_defined_in (reply_handler);
681 // Copy the exceptions.
682 if (node->exceptions ())
684 UTL_ExceptList *exceptions = node->exceptions ();
686 if (nullptr != exceptions)
688 operation->be_add_exceptions (exceptions->copy ());
692 // After having generated the operation we insert it into the
693 // reply handler interface.
694 if (nullptr == reply_handler->be_add_operation (operation))
696 return -1;
699 operation->is_attr_op (node->is_attr_op ());
700 return 0;
704 be_visitor_ami_pre_proc::create_excep_operation (be_operation *node,
705 be_interface *reply_handler)
707 if (node->flags () == AST_Operation::OP_oneway)
709 // We do nothing for oneways!
710 return 0;
713 // Create the return type, which is "void".
714 Identifier *id = nullptr;
715 UTL_ScopedName *sn = nullptr;
717 // Create the argument.
718 ACE_NEW_RETURN (id,
719 Identifier ("excep_holder"),
720 -1);
722 ACE_NEW_RETURN (sn,
723 UTL_ScopedName (id,
724 nullptr),
725 -1);
727 be_valuetype *excep_holder = be_global->messaging_exceptionholder ();
728 be_argument *arg = nullptr;
729 ACE_NEW_RETURN (arg,
730 be_argument (AST_Argument::dir_IN,
731 excep_holder, // is also a valuetype
732 sn),
733 -1);
735 arg->set_name (sn);
737 UTL_ScopedName *tmp = (UTL_ScopedName *)sn->copy ();
739 // Create the new name
740 // Append _excep to the name of the operation
741 ACE_CString original_op_name (
742 node->name ()->last_component ()->get_string ()
744 ACE_CString new_op_name = original_op_name + ACE_CString ("_excep");
746 UTL_ScopedName *op_name =
747 static_cast<UTL_ScopedName *> (reply_handler->name ()->copy ());
749 ACE_NEW_RETURN (id,
750 Identifier (new_op_name.c_str ()),
751 -1);
753 ACE_NEW_RETURN (sn,
754 UTL_ScopedName (id,
755 nullptr),
756 -1);
758 op_name->nconc (sn);
760 AST_PredefinedType *rt = be_global->void_type ();
762 // Create the operation.
763 be_operation *operation = nullptr;
764 ACE_NEW_RETURN (operation,
765 be_operation (rt,
766 AST_Operation::OP_noflags,
767 op_name,
768 false,
769 false),
770 -1);
772 operation->set_name (op_name);
773 operation->be_add_argument (arg);
774 operation->set_defined_in (reply_handler);
776 UTL_ScopedName *arg_name =
777 dynamic_cast<UTL_ScopedName *> (op_name->copy ());
778 arg_name->nconc (tmp);
779 arg->set_name (arg_name);
780 arg->set_defined_in (operation);
782 // Copy the exceptions since the user exception information may
783 // be needed when collocation is disabled.
784 UTL_ExceptList *exceptions = node->exceptions ();
786 if (nullptr != exceptions)
788 operation->be_add_exceptions (exceptions->copy ());
791 reply_handler->be_add_operation (operation);
793 operation->is_excep_ami (true);
794 return 0;
797 // Visit the scope and its elements.
799 be_visitor_ami_pre_proc::visit_scope (be_scope *node)
801 // proceed if the number of members in our scope is greater than 0
802 if (node->nmembers () > 0)
804 int number_of_elements = 0;
807 // initialize an iterator to iterate thru our scope
808 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
809 !si.is_done ();
810 si.next ())
812 ++number_of_elements;
816 AST_Decl **elements = nullptr;
817 ACE_NEW_RETURN (elements,
818 AST_Decl *[number_of_elements],
819 -1);
822 int position = 0;
824 // Initialize an iterator to iterate thru our scope.
825 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
826 !si.is_done ();
827 si.next ())
829 elements[position++] = si.item ();
833 int elem_number = 0;
835 // Continue until each element is visited.
836 while (elem_number < number_of_elements)
838 AST_Decl *d = elements[elem_number++];
840 if (!d)
842 delete [] elements;
843 elements = nullptr;
844 ACE_ERROR_RETURN ((LM_ERROR,
845 "(%N:%l) be_visitor_scope::visit_scope - "
846 "bad node in this scope\n"),
847 -1);
850 if (!d->ami_visit())
852 continue;
855 be_decl *bd = dynamic_cast<be_decl*> (d);
857 // Set the scope node as "node" in which the code is being
858 // generated so that elements in the node's scope can use it
859 // for code generation.
860 this->ctx_->scope (node);
862 // Set the node to be visited.
863 this->ctx_->node (bd);
865 // Send the visitor.
866 if (bd == nullptr || bd->accept (this) == -1)
868 delete [] elements;
869 elements = nullptr;
870 ACE_ERROR_RETURN ((LM_ERROR,
871 "(%N:%l) be_visitor_scope::visit_scope - "
872 "codegen for scope failed\n"),
873 -1);
875 } // end of while loop
877 delete [] elements;
878 elements = nullptr;
879 } // end of if
881 return 0;
884 // Helper methods
887 be_visitor_ami_pre_proc::generate_name (ACE_CString &destination,
888 const char *prefix,
889 const char *middle_name,
890 const char *suffix)
892 destination = prefix;
893 destination += middle_name;
894 destination += suffix;
895 return 0;
898 be_operation *
899 be_visitor_ami_pre_proc::generate_get_operation (be_attribute *node)
901 ACE_CString original_op_name (
902 node->name ()->last_component ()->get_string ()
904 ACE_CString new_op_name = ACE_CString ("get_") + original_op_name;
906 UTL_ScopedName *get_name =
907 static_cast<UTL_ScopedName *> (node->name ()->copy ());
908 get_name->last_component ()->replace_string (new_op_name.c_str ());
910 be_operation *operation = nullptr;
911 ACE_NEW_RETURN (operation,
912 be_operation (node->field_type (),
913 AST_Operation::OP_noflags,
914 get_name,
915 false,
916 false),
917 nullptr);
919 operation->set_name (get_name);
920 operation->set_defined_in (node->defined_in ());
922 // Copy the exceptions since the user exception information may
923 // be needed when collocation is disabled.
924 UTL_ExceptList *exceptions = node->get_get_exceptions ();
926 if (nullptr != exceptions)
928 operation->be_add_exceptions (exceptions->copy ());
931 operation->is_attr_op (true);
932 return operation;
935 be_operation *
936 be_visitor_ami_pre_proc::generate_set_operation (be_attribute *node)
938 ACE_CString original_op_name (
939 node->name ()->last_component ()->get_string ()
941 ACE_CString new_op_name = ACE_CString ("set_") + original_op_name;
943 UTL_ScopedName *set_name =
944 static_cast<UTL_ScopedName *> (node->name ()-> copy ());
945 set_name->last_component ()->replace_string (new_op_name.c_str ());
947 // Argument type is the same as the attribute type.
948 be_argument *arg = nullptr;
949 ACE_NEW_RETURN (arg,
950 be_argument (AST_Argument::dir_IN,
951 node->field_type (),
952 set_name),
953 nullptr);
955 arg->set_name ((UTL_ScopedName *) node->name ()->copy ());
957 // Create the operation.
958 be_operation *operation = nullptr;
959 ACE_NEW_RETURN (operation,
960 be_operation (be_global->void_type (),
961 AST_Operation::OP_noflags,
962 set_name,
963 false,
964 false),
965 nullptr);
967 operation->set_name (set_name);
968 operation->set_defined_in (node->defined_in ());
969 operation->be_add_argument (arg);
971 // Copy the exceptions since the user exception information may
972 // be needed when collocation is disabled.
973 UTL_ExceptList *exceptions = node->get_set_exceptions ();
975 if (nullptr != exceptions)
977 operation->be_add_exceptions (exceptions->copy ());
980 operation->is_attr_op (true);
981 return operation;
984 AST_Type **
985 be_visitor_ami_pre_proc::create_inheritance_list (be_interface *node,
986 long &n_rh_parents)
988 AST_Type **retval = nullptr;
990 long const n_parents = node->n_inherits ();
991 AST_Type **parents = node->inherits ();
992 AST_Type *parent = nullptr;
994 for (long i = 0; i < n_parents; ++i)
996 parent = parents[i];
998 if (parent->is_abstract ())
1000 continue;
1003 ++n_rh_parents;
1006 if (n_rh_parents == 0)
1008 be_interface *inherit_intf = be_global->messaging_replyhandler ();
1010 ACE_NEW_RETURN (retval,
1011 AST_Type *[1],
1012 nullptr);
1014 retval[0] = inherit_intf;
1015 n_rh_parents = 1;
1017 else
1019 ACE_NEW_RETURN (retval,
1020 AST_Type *[n_rh_parents],
1021 nullptr);
1023 ACE_CString prefix ("AMI_");
1025 ACE_CString suffix ("Handler");
1026 long index = 0;
1028 for (long j = 0; j < n_parents; ++j)
1030 parent = parents[j];
1032 if (parent->is_abstract ())
1034 continue;
1037 ACE_CString rh_local_name =
1038 prefix + parent->local_name ()->get_string () + suffix;
1040 UTL_ScopedName *rh_parent_name =
1041 static_cast<UTL_ScopedName *> (parent->name ()->copy ());
1043 rh_parent_name->last_component ()->replace_string (
1044 rh_local_name.c_str ()
1047 AST_Decl *d =
1048 node->defined_in ()->lookup_by_name (rh_parent_name,
1049 true);
1051 if (d != nullptr)
1053 retval[index] = dynamic_cast<AST_Interface*> (d);
1054 retval[index++]->set_prefix_with_typeprefix (parent->prefix () ?
1055 const_cast<char*> (parent->prefix()) :
1056 const_cast<char*> (""));
1059 rh_parent_name->destroy ();
1060 delete rh_parent_name;
1061 rh_parent_name = nullptr;
1064 // Just a sanity check until we're sure this works in all use cases.
1065 if (n_rh_parents != index)
1067 delete [] retval;
1068 ACE_ERROR_RETURN ((LM_ERROR,
1069 "reply handler parent iteration mismatch\n"),
1074 return retval;
1078 be_visitor_ami_pre_proc::generate_ami4ccm_idl ()
1080 /// The interfaces in the list below are from this IDL file,
1081 /// which then must be processed with the -GC option, so we
1082 /// know we'll get here - a good place to generate the *A.idl
1083 /// file containing the local interfaces and connector
1084 /// associated with each interface in the list.
1086 ACE_Unbounded_Queue<char *> &ccm_ami_ifaces =
1087 idl_global->ciao_ami_iface_names ();
1089 /// If the queue is empty, we're done.
1090 if (ccm_ami_ifaces.size () == 0)
1092 return 0;
1095 /// Open the *A.idl file and create the file stream.
1096 int status =
1097 tao_cg->start_ciao_ami_conn_idl (
1098 be_global->be_get_ciao_ami_conn_idl_fname ());
1100 if (status == -1)
1102 ACE_ERROR_RETURN ((LM_ERROR,
1103 ACE_TEXT ("be_visitor_ami_pre_proc")
1104 ACE_TEXT ("::generate_ami4ccm_idl - ")
1105 ACE_TEXT ("Error opening CIAO AMI ")
1106 ACE_TEXT ("connector IDL file\n")),
1107 -1);
1110 for (ACE_Unbounded_Queue<char *>::CONST_ITERATOR i (
1111 ccm_ami_ifaces);
1112 ! i.done ();
1113 i.advance ())
1115 char **item = nullptr;
1116 i.next (item);
1118 UTL_ScopedName *sn =
1119 FE_Utils::string_to_scoped_name (*item);
1121 UTL_Scope *s =
1122 idl_global->scopes ().top_non_null ();
1124 AST_Decl *d = s->lookup_by_name (sn, true);
1126 if (d == nullptr)
1128 idl_global->err ()->lookup_error (sn);
1130 sn->destroy ();
1131 delete sn;
1132 sn = nullptr;
1134 continue;
1137 sn->destroy ();
1138 delete sn;
1139 sn = nullptr;
1141 be_interface *iface =
1142 dynamic_cast<be_interface*> (d);
1144 if (iface == nullptr)
1146 idl_global->err ()->interface_expected (d);
1147 continue;
1150 /// The interface's method encapsulates the code that
1151 /// spawns the appropriate visitors. We just pass it
1152 /// the file stream.
1153 iface->gen_ami4ccm_idl (tao_cg->ciao_ami_conn_idl ());
1156 tao_cg->end_ciao_ami_conn_idl ();
1158 return 0;