Go to the documentation of this file.00001
00002
00003
00004 #include "ast_enum.h"
00005 #include "ast_exception.h"
00006 #include "ast_expression.h"
00007 #include "ast_field.h"
00008 #include "ast_union.h"
00009 #include "utl_identifier.h"
00010
00011 #include "ifr_adding_visitor_exception.h"
00012 #include "ifr_adding_visitor_structure.h"
00013 #include "ifr_adding_visitor_union.h"
00014
00015 ACE_RCSID (IFR_Service,
00016 ifr_adding_visitor_exception,
00017 "$Id: ifr_adding_visitor_exception.cpp 83731 2008-11-13 21:54:42Z fields_t $")
00018
00019 ifr_adding_visitor_exception::ifr_adding_visitor_exception (
00020 AST_Decl *scope,
00021 bool in_reopened
00022 )
00023 : ifr_adding_visitor (scope,
00024 in_reopened)
00025 {
00026 }
00027
00028 ifr_adding_visitor_exception::~ifr_adding_visitor_exception (void)
00029 {
00030 }
00031
00032
00033 int
00034 ifr_adding_visitor_exception::visit_scope (UTL_Scope *node)
00035 {
00036
00037
00038 if (node->scope_node_type () != AST_Decl::NT_except)
00039 {
00040 return ifr_adding_visitor::visit_scope (node);
00041 }
00042
00043 AST_Exception *e = AST_Exception::narrow_from_scope (node);
00044
00045 CORBA::ULong nfields = static_cast<CORBA::ULong> (e->nfields ());
00046
00047 this->members_.length (nfields);
00048
00049 AST_Field **f = 0;
00050
00051 try
00052 {
00053
00054 for (CORBA::ULong i = 0; i < nfields; ++i)
00055 {
00056 if (e->field (f, i) != 0)
00057 {
00058 ACE_ERROR_RETURN ((
00059 LM_ERROR,
00060 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00061 ACE_TEXT ("visit_scope -")
00062 ACE_TEXT (" field node access failed\n")
00063 ),
00064 -1
00065 );
00066 }
00067
00068 AST_Type *ft = (*f)->field_type ();
00069
00070 bool defined_here = ft->is_child (this->scope_);
00071
00072
00073
00074 if (defined_here)
00075 {
00076 if (ft->ast_accept (this) == -1)
00077 {
00078 ACE_ERROR_RETURN ((
00079 LM_ERROR,
00080 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00081 ACE_TEXT ("visit_scope -")
00082 ACE_TEXT (" failed to accept visitor\n")
00083 ),
00084 -1
00085 );
00086 }
00087 }
00088 else
00089 {
00090
00091 this->get_referenced_type (ft);
00092 }
00093
00094 this->members_[i].name =
00095 CORBA::string_dup ((*f)->local_name ()->get_string ());
00096
00097
00098
00099 this->members_[i].type =
00100 CORBA::TypeCode::_duplicate (CORBA::_tc_void);
00101
00102 this->members_[i].type_def =
00103 CORBA::IDLType::_duplicate (this->ir_current_.in ());
00104 }
00105 }
00106 catch (const CORBA::Exception& ex)
00107 {
00108 ex._tao_print_exception (
00109 ACE_TEXT (
00110 "ifr_adding_visitor_structure::visit_scope"));
00111
00112 return -1;
00113 }
00114
00115 return 0;
00116 }
00117
00118 int
00119 ifr_adding_visitor_exception::visit_structure (AST_Structure *node)
00120 {
00121 try
00122 {
00123
00124 CORBA::Contained_var prev_def =
00125 be_global->repository ()->lookup_id (node->repoID ());
00126
00127
00128 if (CORBA::is_nil (prev_def.in ()))
00129 {
00130 ifr_adding_visitor_structure visitor (node);
00131 int retval = visitor.visit_structure (node);
00132
00133 if (retval == 0)
00134 {
00135
00136 this->ir_current_ =
00137 CORBA::IDLType::_duplicate (visitor.ir_current ());
00138 }
00139
00140 return retval;
00141 }
00142 else
00143 {
00144
00145
00146
00147
00148 if (!node->ifr_added ())
00149 {
00150 prev_def->destroy ();
00151
00152
00153 return this->visit_structure (node);
00154 }
00155
00156 this->ir_current_ =
00157 CORBA::IDLType::_narrow (prev_def.in ());
00158 }
00159 }
00160 catch (const CORBA::Exception& ex)
00161 {
00162 ex._tao_print_exception (
00163 ACE_TEXT (
00164 "ifr_adding_visitor_exception::visit_structure"));
00165
00166 return -1;
00167 }
00168
00169 return 0;
00170 }
00171
00172 int
00173 ifr_adding_visitor_exception::visit_exception (AST_Exception *node)
00174 {
00175 try
00176 {
00177 CORBA::ExceptionDef_var new_def;
00178 CORBA::Contained_var prev_def =
00179 be_global->repository ()->lookup_id (node->repoID ());
00180
00181 if (CORBA::is_nil (prev_def.in ()))
00182 {
00183 CORBA::StructMemberSeq dummyMembers;
00184 dummyMembers.length (0);
00185 CORBA::Container_ptr current_scope =
00186 CORBA::Container::_nil ();
00187
00188 if (be_global->ifr_scopes ().top (current_scope) != 0)
00189 {
00190 ACE_ERROR_RETURN ((
00191 LM_ERROR,
00192 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00193 ACE_TEXT ("visit_exception -")
00194 ACE_TEXT (" scope stack is empty\n")
00195 ),
00196 -1
00197 );
00198 }
00199
00200 new_def =
00201 current_scope->create_exception (node->repoID (),
00202 node->local_name ()->get_string (),
00203 node->version (),
00204 dummyMembers);
00205
00206 if (be_global->ifr_scopes ().push (new_def.in ()) != 0)
00207 {
00208 ACE_ERROR_RETURN ((
00209 LM_ERROR,
00210 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00211 ACE_TEXT ("visit_exception -")
00212 ACE_TEXT (" scope push failed\n")
00213 ),
00214 -1
00215 );
00216 }
00217
00218
00219 if (this->add_members (node, new_def.in ()) == -1)
00220 {
00221 ACE_ERROR_RETURN ((
00222 LM_ERROR,
00223 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00224 ACE_TEXT ("visit_exception -")
00225 ACE_TEXT (" visit_scope failed\n")),
00226 -1);
00227 }
00228
00229 CORBA::Container_ptr used_scope =
00230 CORBA::Container::_nil ();
00231
00232
00233 if (be_global->ifr_scopes ().pop (used_scope) != 0)
00234 {
00235 ACE_ERROR_RETURN ((
00236 LM_ERROR,
00237 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00238 ACE_TEXT ("visit_exception -")
00239 ACE_TEXT (" scope pop failed\n")
00240 ),
00241 -1
00242 );
00243 }
00244 }
00245 else
00246 {
00247 new_def = CORBA::ExceptionDef::_narrow (prev_def.in ());
00248
00249 if (be_global->ifr_scopes ().push (new_def.in ()) != 0)
00250 {
00251 ACE_ERROR_RETURN ((
00252 LM_ERROR,
00253 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00254 ACE_TEXT ("visit_exception -")
00255 ACE_TEXT (" scope push failed\n")
00256 ),
00257 -1
00258 );
00259 }
00260
00261
00262 if (this->add_members (node, new_def.in ()) == -1)
00263 {
00264 ACE_ERROR_RETURN ((
00265 LM_ERROR,
00266 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00267 ACE_TEXT ("visit_exception -")
00268 ACE_TEXT (" visit_scope failed\n")),
00269 -1);
00270 }
00271
00272 CORBA::Container_ptr used_scope =
00273 CORBA::Container::_nil ();
00274
00275
00276 if (be_global->ifr_scopes ().pop (used_scope) != 0)
00277 {
00278 ACE_ERROR_RETURN ((
00279 LM_ERROR,
00280 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00281 ACE_TEXT ("visit_exception -")
00282 ACE_TEXT (" scope pop failed\n")
00283 ),
00284 -1
00285 );
00286 }
00287 }
00288 }
00289 catch (const CORBA::Exception& ex)
00290 {
00291 ex._tao_print_exception (
00292 ACE_TEXT (
00293 "ifr_adding_visitor_exception::visit_exception"));
00294
00295 return -1;
00296 }
00297
00298 return 0;
00299 }
00300
00301 int
00302 ifr_adding_visitor_exception::visit_enum (AST_Enum *node)
00303 {
00304 try
00305 {
00306
00307 CORBA::Contained_var prev_def =
00308 be_global->repository ()->lookup_id (node->repoID ());
00309
00310
00311 if (CORBA::is_nil (prev_def.in ()))
00312 {
00313 CORBA::ULong member_count = static_cast<CORBA::ULong> (node->member_count ());
00314
00315 CORBA::EnumMemberSeq members (member_count);
00316 members.length (member_count);
00317
00318 UTL_ScopedName *member_name = 0;
00319
00320
00321 for (CORBA::ULong i = 0; i < member_count; ++i)
00322 {
00323 member_name = node->value_to_name (i);
00324
00325 members[i] =
00326 CORBA::string_dup (
00327 member_name->last_component ()->get_string ()
00328 );
00329 }
00330
00331 this->ir_current_ =
00332 be_global->repository ()->create_enum (
00333 node->repoID (),
00334 node->local_name ()->get_string (),
00335 node->version (),
00336 members
00337 );
00338
00339 node->ifr_added (true);
00340 }
00341 else
00342 {
00343
00344
00345
00346
00347 if (!node->ifr_added ())
00348 {
00349 prev_def->destroy ();
00350
00351
00352 return this->visit_enum (node);
00353 }
00354
00355 this->ir_current_ =
00356 CORBA::IDLType::_narrow (prev_def.in ());
00357 }
00358 }
00359 catch (const CORBA::Exception& ex)
00360 {
00361 ex._tao_print_exception (
00362 ACE_TEXT (
00363 "ifr_adding_visitor_exception::visit_enum"));
00364
00365 return -1;
00366 }
00367
00368 return 0;
00369 }
00370
00371 int
00372 ifr_adding_visitor_exception::visit_union (AST_Union *node)
00373 {
00374 try
00375 {
00376
00377 CORBA::Contained_var prev_def =
00378 be_global->repository ()->lookup_id (node->repoID ());
00379
00380
00381 if (CORBA::is_nil (prev_def.in ()))
00382 {
00383 ifr_adding_visitor_union visitor (node);
00384 int retval = visitor.visit_union (node);
00385
00386 if (retval == 0)
00387 {
00388
00389 this->ir_current_ =
00390 CORBA::IDLType::_duplicate (visitor.ir_current ());
00391 }
00392
00393 return retval;
00394 }
00395 else
00396 {
00397
00398
00399
00400
00401 if (!node->ifr_added ())
00402 {
00403 prev_def->destroy ();
00404
00405
00406 return this->visit_union (node);
00407 }
00408
00409 this->ir_current_ =
00410 CORBA::IDLType::_narrow (prev_def.in ());
00411 }
00412 }
00413 catch (const CORBA::Exception& ex)
00414 {
00415 ex._tao_print_exception (
00416 ACE_TEXT (
00417 "ifr_adding_visitor_exception::visit_union"));
00418
00419 return -1;
00420 }
00421
00422 return 0;
00423 }
00424
00425 CORBA::IDLType_ptr
00426 ifr_adding_visitor_exception::ir_current (void) const
00427 {
00428 return this->ir_current_.in ();
00429 }
00430
00431 int
00432 ifr_adding_visitor_exception::add_members (AST_Exception *node,
00433 CORBA::ExceptionDef_ptr except_def)
00434 {
00435 if (this->visit_scope (node) == -1)
00436 {
00437 ACE_ERROR_RETURN ((
00438 LM_ERROR,
00439 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
00440 ACE_TEXT ("visit_exception -")
00441 ACE_TEXT (" visit_scope failed\n")
00442 ),
00443 -1
00444 );
00445 }
00446
00447 except_def->members (this->members_);
00448
00449 node->ifr_added (true);
00450 return 0;
00451 }