ifr_adding_visitor_operation.cpp

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 // ifr_adding_visitor_operation.cpp,v 1.19 2006/06/16 20:32:33 parsons Exp
00003 
00004 #include "ast_argument.h"
00005 #include "ast_exception.h"
00006 #include "ast_expression.h"
00007 #include "ast_operation.h"
00008 #include "utl_identifier.h"
00009 #include "utl_string.h"
00010 
00011 #include "ifr_adding_visitor_operation.h"
00012 #include "utl_exceptlist.h"
00013 #include "utl_strlist.h"
00014 #include "nr_extern.h"
00015 
00016 ACE_RCSID (IFR_Service,
00017            ifr_adding_visitor_operation,
00018            "ifr_adding_visitor_operation.cpp,v 1.19 2006/06/16 20:32:33 parsons Exp")
00019 
00020 ifr_adding_visitor_operation::ifr_adding_visitor_operation (AST_Decl *scope)
00021   : ifr_adding_visitor (scope),
00022     index_ (0)
00023 {
00024 }
00025 
00026 ifr_adding_visitor_operation::~ifr_adding_visitor_operation (void)
00027 {
00028 }
00029 
00030 int
00031 ifr_adding_visitor_operation::visit_operation (AST_Operation *node)
00032 {
00033   ACE_DECLARE_NEW_CORBA_ENV;
00034   ACE_TRY
00035     {
00036       // If this operation is already in the repository (for example, if
00037       // we are processing the IDL file a second time inadvertently), we
00038       // just return 0. The IDL file must be legal, otherwise the IDL
00039       // compiler front end would have told us.
00040 
00041       CORBA::Contained_var prev_def =
00042         be_global->repository ()->lookup_id (node->repoID ()
00043                                              ACE_ENV_ARG_PARAMETER);
00044       ACE_TRY_CHECK;
00045 
00046       if (!CORBA::is_nil (prev_def.in ()))
00047         {
00048           return 0;
00049         }
00050 
00051       // Build the parameter list. Our overridden version of visit_argument
00052       // will look up each parameter and add its repository entry to
00053       // our params_ member.
00054 
00055       CORBA::ULong length = static_cast<CORBA::ULong> (node->argument_count ());
00056 
00057       this->params_.length (length);
00058 
00059       if (this->visit_scope (node) == -1)
00060         {
00061           ACE_ERROR_RETURN ((
00062               LM_ERROR,
00063               ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::")
00064               ACE_TEXT ("visit_operation -")
00065               ACE_TEXT (" visit_scope failed\n")
00066             ),
00067             -1
00068           );
00069         }
00070 
00071       this->index_ = 0;
00072 
00073       // Build the exception list.
00074 
00075       UTL_ExceptList *excepts = node->exceptions ();
00076 
00077       if (excepts != 0)
00078         {
00079           length = static_cast<CORBA::ULong> (excepts->length ());
00080         }
00081       else
00082         {
00083           length = 0;
00084         }
00085 
00086       CORBA::ExceptionDefSeq exceptions (length);
00087       exceptions.length (length);
00088 
00089       AST_Exception *ex = 0;
00090       CORBA::ULong i = 0;
00091 
00092       for (UTL_ExceptlistActiveIterator ex_iter (excepts);
00093            !ex_iter.is_done ();
00094            ex_iter.next (), ++i)
00095         {
00096           ex = ex_iter.item ();
00097 
00098           prev_def =
00099             be_global->repository ()->lookup_id (ex->repoID ()
00100                                                  ACE_ENV_ARG_PARAMETER);
00101           ACE_TRY_CHECK;
00102 
00103           exceptions[i] = 
00104             CORBA::ExceptionDef::_narrow (prev_def.in ()
00105                                           ACE_ENV_ARG_PARAMETER);
00106           ACE_TRY_CHECK;
00107         }
00108 
00109       // Build the context list.
00110 
00111       UTL_StrList *ctx_list = node->context ();
00112 
00113       if (ctx_list != 0)
00114         {
00115           length = static_cast<CORBA::ULong> (ctx_list->length ());
00116         }
00117       else
00118         {
00119           length = 0;
00120         }
00121 
00122       CORBA::ContextIdSeq contexts (length);
00123       contexts.length (length);
00124 
00125       UTL_StrlistActiveIterator ctx_iter (ctx_list);
00126       UTL_String *str = 0;
00127       i = 0;
00128 
00129       while (!ctx_iter.is_done ())
00130         {
00131           str = ctx_iter.item ();
00132 
00133           contexts[i++] = str->get_string ();
00134 
00135           ctx_iter.next ();
00136         }
00137 
00138       // Get the return type.
00139 
00140       AST_Type *return_type = node->return_type ();
00141 
00142       // Updates ir_current_.
00143       this->get_referenced_type (return_type
00144                                  ACE_ENV_ARG_PARAMETER);
00145       ACE_TRY_CHECK;
00146 
00147       // Is the operation oneway?
00148       CORBA::OperationMode mode = node->flags () == AST_Operation::OP_oneway
00149                                  ? CORBA::OP_ONEWAY
00150                                  : CORBA::OP_NORMAL;
00151 
00152       // Create the repository entry.
00153 
00154       CORBA::Container_ptr current_scope =
00155         CORBA::Container::_nil ();
00156 
00157       if (be_global->ifr_scopes ().top (current_scope) == 0)
00158         {
00159           AST_Decl *op_scope = ScopeAsDecl (node->defined_in ());
00160           AST_Decl::NodeType nt = op_scope->node_type ();
00161 
00162           if (nt == AST_Decl::NT_interface)
00163             {
00164               CORBA::InterfaceDef_var iface =
00165                 CORBA::InterfaceDef::_narrow (current_scope
00166                                               ACE_ENV_ARG_PARAMETER);
00167               ACE_TRY_CHECK;
00168 
00169               CORBA::OperationDef_var new_def =
00170                 iface->create_operation (node->repoID (),
00171                                          node->local_name ()->get_string (),
00172                                          node->version (),
00173                                          this->ir_current_.in (),
00174                                          mode,
00175                                          this->params_,
00176                                          exceptions,
00177                                          contexts
00178                                          ACE_ENV_ARG_PARAMETER);
00179               ACE_TRY_CHECK;
00180             }
00181           else
00182             {
00183               CORBA::ValueDef_var vtype =
00184                 CORBA::ValueDef::_narrow (current_scope
00185                                           ACE_ENV_ARG_PARAMETER);
00186               ACE_TRY_CHECK;
00187 
00188               CORBA::OperationDef_var new_def =
00189                 vtype->create_operation (node->repoID (),
00190                                          node->local_name ()->get_string (),
00191                                          node->version (),
00192                                          this->ir_current_.in (),
00193                                          mode,
00194                                          this->params_,
00195                                          exceptions,
00196                                          contexts
00197                                          ACE_ENV_ARG_PARAMETER);
00198               ACE_TRY_CHECK;
00199             }
00200         }
00201       else
00202         {
00203           ACE_ERROR_RETURN ((
00204               LM_ERROR,
00205               ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::")
00206               ACE_TEXT ("visit_operation -")
00207               ACE_TEXT (" scope stack is empty\n")
00208             ),
00209             -1
00210           );
00211         }
00212     }
00213   ACE_CATCHANY
00214     {
00215       ACE_PRINT_EXCEPTION (
00216           ACE_ANY_EXCEPTION,
00217           ACE_TEXT ("ifr_adding_visitor_operation::visit_operation")
00218         );
00219 
00220       return -1;
00221     }
00222   ACE_ENDTRY;
00223 
00224   return 0;
00225 }
00226 
00227 int
00228 ifr_adding_visitor_operation::visit_argument (AST_Argument *node)
00229 {
00230   // Get the parameter's name.
00231   this->params_[this->index_].name =
00232     CORBA::string_dup (node->local_name ()->get_string ());
00233 
00234   AST_Type *arg_type = node->field_type ();
00235 
00236   ACE_DECLARE_NEW_CORBA_ENV;
00237   ACE_TRY
00238     {
00239       // Updates ir_current_.
00240       this->get_referenced_type (arg_type
00241                                  ACE_ENV_ARG_PARAMETER);
00242       ACE_TRY_CHECK;
00243 
00244       this->params_[this->index_].type_def =
00245         CORBA::IDLType::_duplicate (this->ir_current_.in ());
00246 
00247 
00248       switch (node->direction ())
00249       {
00250         case AST_Argument::dir_IN:
00251           this->params_[this->index_].mode = CORBA::PARAM_IN;
00252           break;
00253         case AST_Argument::dir_OUT:
00254           this->params_[this->index_].mode = CORBA::PARAM_OUT;
00255           break;
00256         case AST_Argument::dir_INOUT:
00257           this->params_[this->index_].mode = CORBA::PARAM_INOUT;
00258           break;
00259       }
00260 
00261       // IfR method create_operation does not use this - it just needs
00262       // to be non-zero for marshaling.
00263       this->params_[this->index_].type =
00264         CORBA::TypeCode::_duplicate (CORBA::_tc_void);
00265 
00266       ++this->index_;
00267     }
00268   ACE_CATCHANY
00269     {
00270       ACE_PRINT_EXCEPTION (
00271           ACE_ANY_EXCEPTION,
00272           ACE_TEXT ("ifr_adding_visitor_operation::visit_argument")
00273         );
00274 
00275       return -1;
00276     }
00277   ACE_ENDTRY;
00278 
00279   return 0;
00280 }

Generated on Thu Nov 9 14:11:50 2006 for TAO_IFR by doxygen 1.3.6