00001
00002
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 "$Id: ifr_adding_visitor_operation.cpp 76589 2007-01-25 18:04:11Z elliott_c $")
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 try
00034 {
00035
00036
00037
00038
00039
00040 CORBA::Contained_var prev_def =
00041 be_global->repository ()->lookup_id (node->repoID ());
00042
00043 if (!CORBA::is_nil (prev_def.in ()))
00044 {
00045 return 0;
00046 }
00047
00048
00049
00050
00051
00052 CORBA::ULong length = static_cast<CORBA::ULong> (node->argument_count ());
00053
00054 this->params_.length (length);
00055
00056 if (this->visit_scope (node) == -1)
00057 {
00058 ACE_ERROR_RETURN ((
00059 LM_ERROR,
00060 ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::")
00061 ACE_TEXT ("visit_operation -")
00062 ACE_TEXT (" visit_scope failed\n")
00063 ),
00064 -1
00065 );
00066 }
00067
00068 this->index_ = 0;
00069
00070
00071
00072 UTL_ExceptList *excepts = node->exceptions ();
00073
00074 if (excepts != 0)
00075 {
00076 length = static_cast<CORBA::ULong> (excepts->length ());
00077 }
00078 else
00079 {
00080 length = 0;
00081 }
00082
00083 CORBA::ExceptionDefSeq exceptions (length);
00084 exceptions.length (length);
00085
00086 AST_Exception *ex = 0;
00087 CORBA::ULong i = 0;
00088
00089 for (UTL_ExceptlistActiveIterator ex_iter (excepts);
00090 !ex_iter.is_done ();
00091 ex_iter.next (), ++i)
00092 {
00093 ex = ex_iter.item ();
00094
00095 prev_def =
00096 be_global->repository ()->lookup_id (ex->repoID ());
00097
00098 exceptions[i] =
00099 CORBA::ExceptionDef::_narrow (prev_def.in ());
00100 }
00101
00102
00103
00104 UTL_StrList *ctx_list = node->context ();
00105
00106 if (ctx_list != 0)
00107 {
00108 length = static_cast<CORBA::ULong> (ctx_list->length ());
00109 }
00110 else
00111 {
00112 length = 0;
00113 }
00114
00115 CORBA::ContextIdSeq contexts (length);
00116 contexts.length (length);
00117
00118 UTL_StrlistActiveIterator ctx_iter (ctx_list);
00119 UTL_String *str = 0;
00120 i = 0;
00121
00122 while (!ctx_iter.is_done ())
00123 {
00124 str = ctx_iter.item ();
00125
00126 contexts[i++] = str->get_string ();
00127
00128 ctx_iter.next ();
00129 }
00130
00131
00132
00133 AST_Type *return_type = node->return_type ();
00134
00135
00136 this->get_referenced_type (return_type);
00137
00138
00139 CORBA::OperationMode mode = node->flags () == AST_Operation::OP_oneway
00140 ? CORBA::OP_ONEWAY
00141 : CORBA::OP_NORMAL;
00142
00143
00144
00145 CORBA::Container_ptr current_scope =
00146 CORBA::Container::_nil ();
00147
00148 if (be_global->ifr_scopes ().top (current_scope) == 0)
00149 {
00150 AST_Decl *op_scope = ScopeAsDecl (node->defined_in ());
00151 AST_Decl::NodeType nt = op_scope->node_type ();
00152
00153 if (nt == AST_Decl::NT_interface)
00154 {
00155 CORBA::InterfaceDef_var iface =
00156 CORBA::InterfaceDef::_narrow (current_scope);
00157
00158 CORBA::OperationDef_var new_def =
00159 iface->create_operation (node->repoID (),
00160 node->local_name ()->get_string (),
00161 node->version (),
00162 this->ir_current_.in (),
00163 mode,
00164 this->params_,
00165 exceptions,
00166 contexts);
00167 }
00168 else
00169 {
00170 CORBA::ValueDef_var vtype =
00171 CORBA::ValueDef::_narrow (current_scope);
00172
00173 CORBA::OperationDef_var new_def =
00174 vtype->create_operation (node->repoID (),
00175 node->local_name ()->get_string (),
00176 node->version (),
00177 this->ir_current_.in (),
00178 mode,
00179 this->params_,
00180 exceptions,
00181 contexts);
00182 }
00183 }
00184 else
00185 {
00186 ACE_ERROR_RETURN ((
00187 LM_ERROR,
00188 ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::")
00189 ACE_TEXT ("visit_operation -")
00190 ACE_TEXT (" scope stack is empty\n")
00191 ),
00192 -1
00193 );
00194 }
00195 }
00196 catch (const CORBA::Exception& ex)
00197 {
00198 ex._tao_print_exception (
00199 ACE_TEXT (
00200 "ifr_adding_visitor_operation::visit_operation"));
00201
00202 return -1;
00203 }
00204
00205 return 0;
00206 }
00207
00208 int
00209 ifr_adding_visitor_operation::visit_argument (AST_Argument *node)
00210 {
00211
00212 this->params_[this->index_].name =
00213 CORBA::string_dup (node->local_name ()->get_string ());
00214
00215 AST_Type *arg_type = node->field_type ();
00216
00217 try
00218 {
00219
00220 this->get_referenced_type (arg_type);
00221
00222 this->params_[this->index_].type_def =
00223 CORBA::IDLType::_duplicate (this->ir_current_.in ());
00224
00225
00226 switch (node->direction ())
00227 {
00228 case AST_Argument::dir_IN:
00229 this->params_[this->index_].mode = CORBA::PARAM_IN;
00230 break;
00231 case AST_Argument::dir_OUT:
00232 this->params_[this->index_].mode = CORBA::PARAM_OUT;
00233 break;
00234 case AST_Argument::dir_INOUT:
00235 this->params_[this->index_].mode = CORBA::PARAM_INOUT;
00236 break;
00237 }
00238
00239
00240
00241 this->params_[this->index_].type =
00242 CORBA::TypeCode::_duplicate (CORBA::_tc_void);
00243
00244 ++this->index_;
00245 }
00246 catch (const CORBA::Exception& ex)
00247 {
00248 ex._tao_print_exception (
00249 ACE_TEXT (
00250 "ifr_adding_visitor_operation::visit_argument"));
00251
00252 return -1;
00253 }
00254
00255 return 0;
00256 }