Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / orbsvcs / IFR_Service / ifr_adding_visitor_operation.cpp
blob9411447ca73cbb4b5c88b4b264971c953ef5a0ab
1 /* -*- c++ -*- */
2 #include "orbsvcs/Log_Macros.h"
3 #include "ast_argument.h"
4 #include "ast_exception.h"
5 #include "ast_expression.h"
6 #include "ast_operation.h"
7 #include "utl_identifier.h"
8 #include "utl_string.h"
10 #include "ifr_adding_visitor_operation.h"
11 #include "utl_exceptlist.h"
12 #include "utl_strlist.h"
13 #include "nr_extern.h"
15 ifr_adding_visitor_operation::ifr_adding_visitor_operation (AST_Decl *scope)
16 : ifr_adding_visitor (scope),
17 index_ (0)
21 ifr_adding_visitor_operation::~ifr_adding_visitor_operation ()
25 int
26 ifr_adding_visitor_operation::visit_operation (AST_Operation *node)
28 try
30 // If this operation is already in the repository (for example, if
31 // we are processing the IDL file a second time inadvertently), we
32 // just return 0. The IDL file must be legal, otherwise the IDL
33 // compiler front end would have told us.
35 CORBA::Contained_var prev_def =
36 be_global->repository ()->lookup_id (node->repoID ());
38 if (!CORBA::is_nil (prev_def.in ()))
40 return 0;
43 // Build the parameter list. Our overridden version of visit_argument
44 // will look up each parameter and add its repository entry to
45 // our params_ member.
47 CORBA::ULong length = static_cast<CORBA::ULong> (node->argument_count ());
49 this->params_.length (length);
51 if (this->visit_scope (node) == -1)
53 ORBSVCS_ERROR_RETURN ((
54 LM_ERROR,
55 ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::")
56 ACE_TEXT ("visit_operation -")
57 ACE_TEXT (" visit_scope failed\n")
63 this->index_ = 0;
65 // Build the exception list.
67 UTL_ExceptList *excepts = node->exceptions ();
69 if (excepts != 0)
71 length = static_cast<CORBA::ULong> (excepts->length ());
73 else
75 length = 0;
78 CORBA::ExceptionDefSeq exceptions (length);
79 exceptions.length (length);
81 AST_Type *ex = 0;
82 CORBA::ULong i = 0;
84 for (UTL_ExceptlistActiveIterator ex_iter (excepts);
85 !ex_iter.is_done ();
86 ex_iter.next (), ++i)
88 ex = ex_iter.item ();
90 prev_def =
91 be_global->repository ()->lookup_id (ex->repoID ());
93 exceptions[i] =
94 CORBA::ExceptionDef::_narrow (prev_def.in ());
97 // Build the context list.
99 UTL_StrList *ctx_list = node->context ();
101 if (ctx_list != 0)
103 length = static_cast<CORBA::ULong> (ctx_list->length ());
105 else
107 length = 0;
110 CORBA::ContextIdSeq contexts (length);
111 contexts.length (length);
113 UTL_StrlistActiveIterator ctx_iter (ctx_list);
114 UTL_String *str = 0;
115 i = 0;
117 while (!ctx_iter.is_done ())
119 str = ctx_iter.item ();
121 contexts[i++] = str->get_string ();
123 ctx_iter.next ();
126 // Get the return type.
128 AST_Type *return_type = node->return_type ();
130 // Updates ir_current_.
131 this->get_referenced_type (return_type);
133 // Is the operation oneway?
134 CORBA::OperationMode mode = node->flags () == AST_Operation::OP_oneway
135 ? CORBA::OP_ONEWAY
136 : CORBA::OP_NORMAL;
138 // Create the repository entry.
140 CORBA::Container_ptr current_scope =
141 CORBA::Container::_nil ();
143 if (be_global->ifr_scopes ().top (current_scope) == 0)
145 AST_Decl *op_scope = ScopeAsDecl (node->defined_in ());
146 AST_Decl::NodeType nt = op_scope->node_type ();
148 if (nt == AST_Decl::NT_interface)
150 CORBA::InterfaceDef_var iface =
151 CORBA::InterfaceDef::_narrow (current_scope);
153 CORBA::OperationDef_var new_def =
154 iface->create_operation (node->repoID (),
155 node->local_name ()->get_string (),
156 node->version (),
157 this->ir_current_.in (),
158 mode,
159 this->params_,
160 exceptions,
161 contexts);
163 else
165 CORBA::ValueDef_var vtype =
166 CORBA::ValueDef::_narrow (current_scope);
168 CORBA::OperationDef_var new_def =
169 vtype->create_operation (node->repoID (),
170 node->local_name ()->get_string (),
171 node->version (),
172 this->ir_current_.in (),
173 mode,
174 this->params_,
175 exceptions,
176 contexts);
179 else
181 ORBSVCS_ERROR_RETURN ((
182 LM_ERROR,
183 ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::")
184 ACE_TEXT ("visit_operation -")
185 ACE_TEXT (" scope stack is empty\n")
191 catch (const CORBA::Exception& ex)
193 ex._tao_print_exception (
194 ACE_TEXT (
195 "ifr_adding_visitor_operation::visit_operation"));
197 return -1;
200 return 0;
204 ifr_adding_visitor_operation::visit_argument (AST_Argument *node)
206 // Get the parameter's name.
207 this->params_[this->index_].name =
208 CORBA::string_dup (node->local_name ()->get_string ());
210 AST_Type *arg_type = node->field_type ();
214 // Updates ir_current_.
215 this->get_referenced_type (arg_type);
217 this->params_[this->index_].type_def =
218 CORBA::IDLType::_duplicate (this->ir_current_.in ());
221 switch (node->direction ())
223 case AST_Argument::dir_IN:
224 this->params_[this->index_].mode = CORBA::PARAM_IN;
225 break;
226 case AST_Argument::dir_OUT:
227 this->params_[this->index_].mode = CORBA::PARAM_OUT;
228 break;
229 case AST_Argument::dir_INOUT:
230 this->params_[this->index_].mode = CORBA::PARAM_INOUT;
231 break;
234 // IfR method create_operation does not use this - it just needs
235 // to be non-zero for marshaling.
236 this->params_[this->index_].type =
237 CORBA::TypeCode::_duplicate (CORBA::_tc_void);
239 ++this->index_;
241 catch (const CORBA::Exception& ex)
243 ex._tao_print_exception (
244 ACE_TEXT (
245 "ifr_adding_visitor_operation::visit_argument"));
247 return -1;
250 return 0;