00001
00002
00003
00004 #include "ast_argument.h"
00005 #include "ast_array.h"
00006 #include "ast_attribute.h"
00007 #include "ast_component.h"
00008 #include "ast_component_fwd.h"
00009 #include "ast_constant.h"
00010 #include "ast_enum.h"
00011 #include "ast_eventtype.h"
00012 #include "ast_eventtype_fwd.h"
00013 #include "ast_exception.h"
00014 #include "ast_expression.h"
00015 #include "ast_factory.h"
00016 #include "ast_field.h"
00017 #include "ast_home.h"
00018 #include "ast_interface.h"
00019 #include "ast_interface_fwd.h"
00020 #include "ast_module.h"
00021 #include "ast_native.h"
00022 #include "ast_operation.h"
00023 #include "ast_predefined_type.h"
00024 #include "ast_root.h"
00025 #include "ast_sequence.h"
00026 #include "ast_string.h"
00027 #include "ast_structure.h"
00028 #include "ast_union.h"
00029 #include "ast_union_fwd.h"
00030 #include "ast_valuebox.h"
00031 #include "ast_valuetype.h"
00032 #include "ast_valuetype_fwd.h"
00033 #include "utl_identifier.h"
00034 #include "utl_string.h"
00035 #include "utl_exceptlist.h"
00036 #include "fe_extern.h"
00037 #include "nr_extern.h"
00038
00039 #include "ifr_adding_visitor.h"
00040 #include "ifr_adding_visitor_operation.h"
00041 #include "ifr_adding_visitor_structure.h"
00042 #include "ifr_adding_visitor_exception.h"
00043 #include "ifr_adding_visitor_union.h"
00044
00045 #include "tao/IFR_Client/IFR_ComponentsC.h"
00046
00047 #include "ace/Vector_T.h"
00048
00049 ACE_RCSID (IFR_Service,
00050 ifr_adding_visitor,
00051 "$Id: ifr_adding_visitor.cpp 80536 2008-01-31 19:38:14Z cleeland $")
00052
00053 ifr_adding_visitor::ifr_adding_visitor (AST_Decl *scope,
00054 bool in_reopened,
00055 bool allow_duplicate_typedefs)
00056 : scope_ (scope),
00057 in_reopened_ (in_reopened),
00058 allow_duplicate_typedefs_ (allow_duplicate_typedefs)
00059 {
00060 }
00061
00062 ifr_adding_visitor::~ifr_adding_visitor (void)
00063 {
00064 }
00065
00066 int
00067 ifr_adding_visitor::visit_scope (UTL_Scope *node)
00068 {
00069
00070 if (node->nmembers () > 0)
00071 {
00072
00073 UTL_ScopeActiveIterator si (node,
00074 UTL_Scope::IK_decls);
00075
00076 AST_Decl *d = 0;
00077
00078
00079 while (!si.is_done ())
00080 {
00081 d = si.item ();
00082
00083 if (d == 0)
00084 {
00085 ACE_ERROR_RETURN ((
00086 LM_ERROR,
00087 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_scope -")
00088 ACE_TEXT (" bad node in this scope\n")
00089 ),
00090 -1
00091 );
00092 }
00093
00094
00095
00096 if (d->node_type () == AST_Decl::NT_pre_defined)
00097 {
00098 si.next ();
00099 continue;
00100 }
00101
00102 if (d->ast_accept (this) == -1)
00103 {
00104 ACE_ERROR_RETURN ((
00105 LM_ERROR,
00106 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_scope -")
00107 ACE_TEXT (" failed to accept visitor\n")
00108 ),
00109 -1
00110 );
00111 }
00112
00113 si.next ();
00114 }
00115 }
00116
00117 return 0;
00118 }
00119
00120 int
00121 ifr_adding_visitor::visit_predefined_type (AST_PredefinedType *node)
00122 {
00123 try
00124 {
00125 this->ir_current_ =
00126 be_global->repository ()->get_primitive (
00127 this->predefined_type_to_pkind (node)
00128 );
00129 }
00130 catch (const CORBA::Exception& ex)
00131 {
00132 ex._tao_print_exception (ACE_TEXT ("visit_predefined_type"));
00133
00134 return -1;
00135 }
00136
00137 return 0;
00138 }
00139
00140 int
00141 ifr_adding_visitor::visit_module (AST_Module *node)
00142 {
00143 if (node->imported () && !be_global->do_included_files ())
00144 {
00145 return 0;
00146 }
00147
00148 CORBA::Container_var new_def;
00149
00150 try
00151 {
00152
00153
00154 CORBA::Contained_var prev_def =
00155 be_global->repository ()->lookup_id (node->repoID ());
00156
00157 if (CORBA::is_nil (prev_def.in ()))
00158 {
00159
00160 CORBA::Container_ptr container =
00161 CORBA::Container::_nil ();
00162
00163 if (be_global->ifr_scopes ().top (container) == 0)
00164 {
00165 new_def = container->create_module (
00166 node->repoID (),
00167 node->local_name ()->get_string (),
00168 node->version ()
00169 );
00170 }
00171 else
00172 {
00173 ACE_ERROR_RETURN ((
00174 LM_ERROR,
00175 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_module -")
00176 ACE_TEXT (" scope stack is empty\n")
00177 ),
00178 -1
00179 );
00180 }
00181 }
00182 else
00183 {
00184 CORBA::DefinitionKind kind =
00185 prev_def->def_kind ();
00186
00187 if (kind == CORBA::dk_Module)
00188 {
00189
00190
00191
00192
00193
00194
00195 this->in_reopened_ = true;
00196
00197 new_def =
00198 CORBA::ComponentIR::Container::_narrow (prev_def.in ());
00199 }
00200 }
00201
00202 if (be_global->ifr_scopes ().push (new_def.in ()) != 0)
00203 {
00204 ACE_ERROR_RETURN ((
00205 LM_ERROR,
00206 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_module -")
00207 ACE_TEXT (" scope push failed\n")
00208 ),
00209 -1
00210 );
00211 }
00212
00213 if (this->visit_scope (node) == -1)
00214 {
00215 ACE_ERROR_RETURN ((
00216 LM_ERROR,
00217 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_module -")
00218 ACE_TEXT (" visit_scope failed\n")
00219 ),
00220 -1
00221 );
00222 }
00223
00224 this->in_reopened_ = false;
00225 CORBA::Container_ptr tmp =
00226 CORBA::Container::_nil ();
00227
00228 if (be_global->ifr_scopes ().pop (tmp) != 0)
00229 {
00230 ACE_ERROR_RETURN ((
00231 LM_ERROR,
00232 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_module -")
00233 ACE_TEXT (" scope pop failed\n")
00234 ),
00235 -1
00236 );
00237 }
00238 }
00239 catch (const CORBA::Exception& ex)
00240 {
00241 ex._tao_print_exception (ACE_TEXT ("visit_module"));
00242
00243 return -1;
00244 }
00245
00246 return 0;
00247 }
00248
00249 int
00250 ifr_adding_visitor::visit_interface (AST_Interface *node)
00251 {
00252 if (node->imported () && !be_global->do_included_files ())
00253 {
00254 return 0;
00255 }
00256
00257 try
00258 {
00259
00260 CORBA::Contained_var prev_def =
00261 be_global->repository ()->lookup_id (node->repoID ());
00262
00263
00264 if (CORBA::is_nil (prev_def.in ()))
00265 {
00266 int status = this->create_interface_def (node);
00267
00268 return status;
00269 }
00270 else
00271 {
00272
00273
00274
00275
00276
00277 if (node->is_defined () && !node->ifr_added ())
00278 {
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 if (!node->ifr_fwd_added () && !node->imported ())
00294 {
00295 CORBA::DefinitionKind kind = prev_def->def_kind ();
00296
00297 if (kind == CORBA::dk_Interface)
00298 {
00299 CORBA::InterfaceDef_var iface =
00300 CORBA::InterfaceDef::_narrow (prev_def.in ());
00301
00302 CORBA::ContainedSeq_var contents =
00303 iface->contents (CORBA::dk_all, true);
00304
00305 for (CORBA::ULong i = 0; i < contents->length (); ++i)
00306 {
00307 contents[i]->destroy ();
00308 }
00309 }
00310 else
00311 {
00312
00313
00314 return this->create_interface_def (node);
00315 }
00316 }
00317
00318 CORBA::ULong n_parents = static_cast<CORBA::ULong> (node->n_inherits ());
00319
00320 CORBA::InterfaceDefSeq bases (n_parents);
00321 bases.length (n_parents);
00322 CORBA::Contained_var result;
00323
00324 AST_Interface **parents = node->inherits ();
00325
00326
00327 for (CORBA::ULong i = 0; i < n_parents; ++i)
00328 {
00329 result =
00330 be_global->repository ()->lookup_id (parents[i]->repoID ());
00331
00332
00333
00334
00335
00336
00337 if (CORBA::is_nil (result.in ()))
00338 {
00339 this->ir_current_ =
00340 CORBA::IDLType::_narrow (prev_def.in ());
00341
00342 return 0;
00343 }
00344
00345 bases[i] =
00346 CORBA::InterfaceDef::_narrow (result.in ());
00347
00348 if (CORBA::is_nil (bases[i]))
00349 {
00350 ACE_ERROR_RETURN ((
00351 LM_ERROR,
00352 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00353 ACE_TEXT ("visit_interface -")
00354 ACE_TEXT (" CORBA::InterfaceDef::_narrow failed\n")
00355 ),
00356 -1
00357 );
00358 }
00359 }
00360
00361 CORBA::InterfaceDef_var extant_def =
00362 CORBA::InterfaceDef::_narrow (prev_def. in ());
00363
00364 extant_def->base_interfaces (bases);
00365
00366 node->ifr_added (true);
00367
00368
00369 if (be_global->ifr_scopes ().push (extant_def.in ()) != 0)
00370 {
00371 ACE_ERROR_RETURN ((
00372 LM_ERROR,
00373 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00374 ACE_TEXT ("visit_interface -")
00375 ACE_TEXT (" scope push failed\n")
00376 ),
00377 -1
00378 );
00379 }
00380
00381
00382 if (this->visit_scope (node) == -1)
00383 {
00384 ACE_ERROR_RETURN ((
00385 LM_ERROR,
00386 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00387 ACE_TEXT ("visit_interface -")
00388 ACE_TEXT (" visit_scope failed\n")
00389 ),
00390 -1
00391 );
00392 }
00393
00394
00395
00396
00397
00398
00399 this->ir_current_ =
00400 CORBA::IDLType::_duplicate (extant_def.in ());
00401
00402 CORBA::Container_ptr used_scope =
00403 CORBA::Container::_nil ();
00404
00405
00406 if (be_global->ifr_scopes ().pop (used_scope) != 0)
00407 {
00408 ACE_ERROR_RETURN ((
00409 LM_ERROR,
00410 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00411 ACE_TEXT ("visit_interface -")
00412 ACE_TEXT (" scope pop failed\n")
00413 ),
00414 -1
00415 );
00416 }
00417 }
00418 else
00419 {
00420
00421
00422
00423
00424
00425
00426 this->ir_current_ =
00427 CORBA::IDLType::_narrow (prev_def.in ());
00428 }
00429 }
00430 }
00431 catch (const CORBA::Exception& ex)
00432 {
00433 ex._tao_print_exception (ACE_TEXT ("visit_interface"));
00434
00435 return -1;
00436 }
00437
00438 return 0;
00439 }
00440
00441 int
00442 ifr_adding_visitor::visit_interface_fwd (AST_InterfaceFwd *node)
00443 {
00444 if (node->imported () && !be_global->do_included_files ())
00445 {
00446 return 0;
00447 }
00448
00449 AST_Interface *i = node->full_definition ();
00450
00451 try
00452 {
00453
00454 CORBA::Contained_var prev_def =
00455 be_global->repository ()->lookup_id (i->repoID ());
00456
00457 if (CORBA::is_nil (prev_def.in ()))
00458 {
00459
00460
00461
00462
00463
00464 CORBA::InterfaceDefSeq bases (0);
00465 bases.length (0);
00466
00467 CORBA::Container_ptr current_scope =
00468 CORBA::Container::_nil ();
00469
00470 if (be_global->ifr_scopes ().top (current_scope) == 0)
00471 {
00472 if (i->is_local ())
00473 {
00474 this->ir_current_ =
00475 current_scope->create_local_interface (
00476 i->repoID (),
00477 i->local_name ()->get_string (),
00478 i->version (),
00479 bases
00480 );
00481 }
00482 else
00483 {
00484 this->ir_current_ =
00485 current_scope->create_interface (
00486 i->repoID (),
00487 i->local_name ()->get_string (),
00488 i->version (),
00489 bases
00490 );
00491 }
00492
00493 }
00494 else
00495 {
00496 ACE_ERROR_RETURN ((
00497 LM_ERROR,
00498 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00499 ACE_TEXT ("visit_interface_fwd -")
00500 ACE_TEXT (" scope stack is empty\n")
00501 ),
00502 -1
00503 );
00504 }
00505
00506 node->ifr_added (true);
00507 i->ifr_fwd_added (true);
00508 }
00509
00510 }
00511 catch (const CORBA::Exception& ex)
00512 {
00513 ex._tao_print_exception (ACE_TEXT ("visit_interface_fwd"));
00514
00515 return -1;
00516 }
00517
00518 return 0;
00519 }
00520
00521 int
00522 ifr_adding_visitor::visit_valuebox (AST_ValueBox *node)
00523 {
00524 if (node->imported () && !be_global->do_included_files ())
00525 {
00526 return 0;
00527 }
00528
00529 try
00530 {
00531 this->element_type (node->boxed_type ());
00532
00533 CORBA::Container_ptr current_scope =
00534 CORBA::Container::_nil ();
00535
00536 if (be_global->ifr_scopes ().top (current_scope) == 0)
00537 {
00538 this->ir_current_ =
00539 current_scope->create_value_box (
00540 node->repoID (),
00541 node->local_name ()->get_string (),
00542 node->version (),
00543 this->ir_current_.in ()
00544 );
00545 }
00546 else
00547 {
00548 ACE_ERROR_RETURN ((
00549 LM_ERROR,
00550 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_valuebox -")
00551 ACE_TEXT (" scope stack is empty\n")
00552 ),
00553 -1
00554 );
00555 }
00556
00557 node->ifr_added (true);
00558 }
00559 catch (const CORBA::Exception& ex)
00560 {
00561 ex._tao_print_exception (ACE_TEXT ("visit_valuebox"));
00562
00563 return -1;
00564 }
00565
00566 return 0;
00567 }
00568
00569 int
00570 ifr_adding_visitor::visit_valuetype (AST_ValueType *node)
00571 {
00572 if (node->imported () && !be_global->do_included_files ())
00573 {
00574 return 0;
00575 }
00576
00577 try
00578 {
00579
00580 CORBA::Contained_var prev_def =
00581 be_global->repository ()->lookup_id (node->repoID ());
00582
00583
00584 if (CORBA::is_nil (prev_def.in ()))
00585 {
00586 int status = this->create_value_def (node);
00587
00588 return status;
00589 }
00590 else
00591 {
00592
00593
00594
00595
00596
00597 if (node->is_defined () && !node->ifr_added ())
00598 {
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613 if (!node->ifr_fwd_added ())
00614 {
00615 CORBA::DefinitionKind kind =
00616 prev_def->def_kind ();
00617
00618 if (kind == CORBA::dk_Value)
00619 {
00620 CORBA::ValueDef_var value =
00621 CORBA::ValueDef::_narrow (prev_def.in ());
00622
00623 CORBA::ContainedSeq_var contents =
00624 value->contents (CORBA::dk_all,
00625 1);
00626
00627 CORBA::ULong length = contents->length ();
00628
00629 for (CORBA::ULong i = 0; i < length; ++i)
00630 {
00631 contents[i]->destroy ();
00632 }
00633 }
00634 else
00635 {
00636 prev_def->destroy ();
00637
00638 int status =
00639 this->create_value_def (node);
00640
00641 return status;
00642 }
00643 }
00644
00645
00646
00647 CORBA::ExtValueDef_var extant_def =
00648 CORBA::ExtValueDef::_narrow (prev_def. in ());
00649
00650
00651
00652 CORBA::ValueDef_var base_vt;
00653 this->fill_base_value (base_vt.out (),
00654 node);
00655
00656 extant_def->base_value (base_vt.in ());
00657
00658
00659
00660 CORBA::ValueDefSeq abstract_base_values;
00661 this->fill_abstract_base_values (abstract_base_values,
00662 node);
00663
00664 extant_def->abstract_base_values (abstract_base_values);
00665
00666
00667
00668 CORBA::InterfaceDefSeq supported;
00669 this->fill_supported_interfaces (supported,
00670 node);
00671
00672 extant_def->supported_interfaces (supported);
00673
00674
00675
00676 CORBA::ExtInitializerSeq initializers;
00677 this->fill_initializers (initializers,
00678 node);
00679
00680 extant_def->ext_initializers (initializers);
00681
00682
00683
00684 extant_def->is_abstract (static_cast<CORBA::Boolean> (node->is_abstract ()));
00685
00686 extant_def->is_truncatable (static_cast<CORBA::Boolean> (node->truncatable ()));
00687
00688 extant_def->is_custom (static_cast<CORBA::Boolean> (node->custom ()));
00689
00690 node->ifr_added (true);
00691
00692
00693
00694 if (be_global->ifr_scopes ().push (extant_def.in ()) != 0)
00695 {
00696 ACE_ERROR_RETURN ((
00697 LM_ERROR,
00698 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00699 ACE_TEXT ("visit_valuetype -")
00700 ACE_TEXT (" scope push failed\n")
00701 ),
00702 -1
00703 );
00704 }
00705
00706
00707 if (this->visit_scope (node) == -1)
00708 {
00709 ACE_ERROR_RETURN ((
00710 LM_ERROR,
00711 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00712 ACE_TEXT ("visit_valuetype -")
00713 ACE_TEXT (" visit_scope failed\n")
00714 ),
00715 -1
00716 );
00717 }
00718
00719
00720
00721
00722
00723
00724 this->ir_current_ =
00725 CORBA::IDLType::_duplicate (extant_def.in ());
00726
00727 CORBA::Container_ptr used_scope =
00728 CORBA::Container::_nil ();
00729
00730
00731 if (be_global->ifr_scopes ().pop (used_scope) != 0)
00732 {
00733 ACE_ERROR_RETURN ((
00734 LM_ERROR,
00735 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00736 ACE_TEXT ("visit_valuetype -")
00737 ACE_TEXT (" scope pop failed\n")
00738 ),
00739 -1
00740 );
00741 }
00742 }
00743 else
00744 {
00745
00746
00747
00748
00749
00750
00751 this->ir_current_ =
00752 CORBA::IDLType::_narrow (prev_def.in ());
00753 }
00754 }
00755 }
00756 catch (const CORBA::Exception& ex)
00757 {
00758 ex._tao_print_exception (ACE_TEXT ("visit_valuetype"));
00759
00760 return -1;
00761 }
00762
00763 return 0;
00764 }
00765
00766 int
00767 ifr_adding_visitor::visit_valuetype_fwd (AST_ValueTypeFwd *node)
00768 {
00769 if (node->imported () && !be_global->do_included_files ())
00770 {
00771 return 0;
00772 }
00773
00774 AST_Interface *v = node->full_definition ();
00775
00776 try
00777 {
00778
00779 CORBA::Contained_var prev_def =
00780 be_global->repository ()->lookup_id (v->repoID ());
00781
00782 if (CORBA::is_nil (prev_def.in ()))
00783 {
00784
00785
00786
00787
00788
00789 CORBA::ValueDefSeq abstract_bases (0);
00790 abstract_bases.length (0);
00791 CORBA::InterfaceDefSeq supported (0);
00792 supported.length (0);
00793 CORBA::InitializerSeq initializers (0);
00794 initializers.length (0);
00795
00796 CORBA::Container_ptr current_scope =
00797 CORBA::Container::_nil ();
00798
00799 CORBA::Boolean abstract =
00800 static_cast<CORBA::Boolean> (v->is_abstract ());
00801
00802 if (be_global->ifr_scopes ().top (current_scope) == 0)
00803 {
00804 this->ir_current_ =
00805 current_scope->create_value (
00806 v->repoID (),
00807 v->local_name ()->get_string (),
00808 v->version (),
00809 0,
00810 abstract,
00811 CORBA::ValueDef::_nil (),
00812 0,
00813 abstract_bases,
00814 supported,
00815 initializers
00816 );
00817 }
00818 else
00819 {
00820 ACE_ERROR_RETURN ((
00821 LM_ERROR,
00822 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00823 ACE_TEXT ("visit_valuetype_fwd -")
00824 ACE_TEXT (" scope stack is empty\n")
00825 ),
00826 -1
00827 );
00828 }
00829
00830 node->ifr_added (true);
00831 v->ifr_fwd_added (true);
00832 }
00833 }
00834 catch (const CORBA::Exception& ex)
00835 {
00836 ex._tao_print_exception (ACE_TEXT ("visit_valuetype_fwd"));
00837
00838 return -1;
00839 }
00840
00841 return 0;
00842 }
00843
00844 int
00845 ifr_adding_visitor::visit_component (AST_Component *node)
00846 {
00847 if (node->imported () && !be_global->do_included_files ())
00848 {
00849 return 0;
00850 }
00851
00852 try
00853 {
00854
00855 CORBA::Contained_var prev_def =
00856 be_global->repository ()->lookup_id (node->repoID ());
00857
00858
00859 if (CORBA::is_nil (prev_def.in ()))
00860 {
00861 int status = this->create_component_def (node);
00862
00863 return status;
00864 }
00865 else
00866 {
00867
00868
00869
00870
00871
00872 if (node->is_defined () && !node->ifr_added ())
00873 {
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888 if (!node->ifr_fwd_added ())
00889 {
00890 CORBA::DefinitionKind kind =
00891 prev_def->def_kind ();
00892
00893 if (kind == CORBA::dk_Component)
00894 {
00895 CORBA::ComponentIR::ComponentDef_var value =
00896 CORBA::ComponentIR::ComponentDef::_narrow (
00897 prev_def.in ()
00898 );
00899
00900 CORBA::ContainedSeq_var contents =
00901 value->contents (CORBA::dk_all,
00902 1);
00903
00904 CORBA::ULong length = contents->length ();
00905
00906 for (CORBA::ULong i = 0; i < length; ++i)
00907 {
00908 contents[i]->destroy ();
00909 }
00910 }
00911 else
00912 {
00913 prev_def->destroy ();
00914
00915 int status =
00916 this->create_component_def (node);
00917
00918 return status;
00919 }
00920 }
00921
00922
00923
00924 CORBA::ComponentIR::ComponentDef_var extant_def =
00925 CORBA::ComponentIR::ComponentDef::_narrow (
00926 prev_def.in ()
00927 );
00928
00929 CORBA::InterfaceDefSeq supported_interfaces;
00930 this->fill_supported_interfaces (supported_interfaces,
00931 node);
00932
00933 extant_def->supported_interfaces (supported_interfaces);
00934
00935 CORBA::ComponentIR::ComponentDef_var base_component;
00936 this->fill_base_component (base_component.out (),
00937 node);
00938
00939 extant_def->base_component (base_component.in ());
00940
00941 this->visit_all_provides (node,
00942 extant_def.in ());
00943
00944 this->visit_all_uses (node,
00945 extant_def.in ());
00946
00947 this->visit_all_emits (node,
00948 extant_def.in ());
00949
00950 this->visit_all_publishes (node,
00951 extant_def.in ());
00952
00953 this->visit_all_consumes (node,
00954 extant_def.in ());
00955
00956 node->ifr_added (true);
00957
00958
00959
00960 if (be_global->ifr_scopes ().push (extant_def.in ()) != 0)
00961 {
00962 ACE_ERROR_RETURN ((
00963 LM_ERROR,
00964 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00965 ACE_TEXT ("visit_component -")
00966 ACE_TEXT (" scope push failed\n")
00967 ),
00968 -1
00969 );
00970 }
00971
00972
00973 if (this->visit_scope (node) == -1)
00974 {
00975 ACE_ERROR_RETURN ((
00976 LM_ERROR,
00977 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
00978 ACE_TEXT ("visit_component -")
00979 ACE_TEXT (" visit_scope failed\n")
00980 ),
00981 -1
00982 );
00983 }
00984
00985
00986
00987
00988
00989
00990 this->ir_current_ =
00991 CORBA::IDLType::_duplicate (extant_def.in ());
00992
00993 CORBA::Container_ptr used_scope =
00994 CORBA::Container::_nil ();
00995
00996
00997 if (be_global->ifr_scopes ().pop (used_scope) != 0)
00998 {
00999 ACE_ERROR_RETURN ((
01000 LM_ERROR,
01001 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01002 ACE_TEXT ("visit_interface -")
01003 ACE_TEXT (" scope pop failed\n")
01004 ),
01005 -1
01006 );
01007 }
01008 }
01009 else
01010 {
01011
01012
01013
01014
01015
01016
01017 this->ir_current_ =
01018 CORBA::IDLType::_narrow (prev_def.in ());
01019 }
01020 }
01021 }
01022 catch (const CORBA::Exception& ex)
01023 {
01024 ex._tao_print_exception (ACE_TEXT ("visit_component"));
01025
01026 return -1;
01027 }
01028
01029 return 0;
01030 }
01031
01032 int
01033 ifr_adding_visitor::visit_component_fwd (AST_ComponentFwd *node)
01034 {
01035 if (node->imported () && !be_global->do_included_files ())
01036 {
01037 return 0;
01038 }
01039
01040 AST_Component *c =
01041 AST_Component::narrow_from_decl (node->full_definition ());
01042
01043 try
01044 {
01045
01046 CORBA::Contained_var prev_def =
01047 be_global->repository ()->lookup_id (c->repoID ());
01048
01049 if (CORBA::is_nil (prev_def.in ()))
01050 {
01051 CORBA::Container_ptr current_scope =
01052 CORBA::Container::_nil ();
01053
01054 if (be_global->ifr_scopes ().top (current_scope) == 0)
01055 {
01056 CORBA::ComponentIR::Container_var ccm_scope =
01057 CORBA::ComponentIR::Container::_narrow (
01058 current_scope
01059 );
01060
01061
01062
01063
01064
01065
01066 CORBA::InterfaceDefSeq supported_interfaces;
01067 supported_interfaces.length (0);
01068 CORBA::ComponentIR::ComponentDef_var base_component;
01069
01070
01071 if (node->is_defined ())
01072 {
01073 this->fill_supported_interfaces (supported_interfaces,
01074 c);
01075
01076 this->fill_base_component (base_component.out (),
01077 c);
01078 }
01079
01080 this->ir_current_ =
01081 ccm_scope->create_component (
01082 c->repoID (),
01083 c->local_name ()->get_string (),
01084 c->version (),
01085 base_component.in (),
01086 supported_interfaces
01087 );
01088
01089
01090
01091 if (node->is_defined ())
01092 {
01093 CORBA::ComponentIR::ComponentDef_var new_def =
01094 CORBA::ComponentIR::ComponentDef::_narrow (
01095 this->ir_current_.in ()
01096 );
01097
01098 this->visit_all_provides (c,
01099 new_def.in ());
01100
01101 this->visit_all_uses (c,
01102 new_def.in ());
01103
01104 this->visit_all_emits (c,
01105 new_def.in ());
01106
01107 this->visit_all_publishes (c,
01108 new_def.in ());
01109
01110 this->visit_all_consumes (c,
01111 new_def.in ());
01112 }
01113 }
01114 else
01115 {
01116 ACE_ERROR_RETURN ((
01117 LM_ERROR,
01118 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01119 ACE_TEXT ("visit_component_fwd -")
01120 ACE_TEXT (" scope stack is empty\n")
01121 ),
01122 -1
01123 );
01124 }
01125
01126 node->ifr_added (true);
01127 c->ifr_fwd_added (true);
01128 }
01129 }
01130 catch (const CORBA::Exception& ex)
01131 {
01132 ex._tao_print_exception (ACE_TEXT ("visit_component_fwd"));
01133
01134 return -1;
01135 }
01136
01137 return 0;
01138 }
01139
01140 int
01141 ifr_adding_visitor::visit_eventtype (AST_EventType *node)
01142 {
01143 if (node->imported () && !be_global->do_included_files ())
01144 {
01145 return 0;
01146 }
01147
01148 try
01149 {
01150
01151 CORBA::Contained_var prev_def =
01152 be_global->repository ()->lookup_id (node->repoID ());
01153
01154
01155 if (CORBA::is_nil (prev_def.in ()))
01156 {
01157 int status = this->create_event_def (node);
01158
01159 return status;
01160 }
01161 else
01162 {
01163
01164
01165
01166
01167
01168 if (node->is_defined () && !node->ifr_added ())
01169 {
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184 if (!node->ifr_fwd_added ())
01185 {
01186 CORBA::DefinitionKind kind =
01187 prev_def->def_kind ();
01188
01189 if (kind == CORBA::dk_Value)
01190 {
01191 CORBA::ComponentIR::EventDef_var event =
01192 CORBA::ComponentIR::EventDef::_narrow (
01193 prev_def.in ()
01194 );
01195
01196 CORBA::ContainedSeq_var contents =
01197 event->contents (CORBA::dk_all,
01198 1);
01199
01200 CORBA::ULong length = contents->length ();
01201
01202 for (CORBA::ULong i = 0; i < length; ++i)
01203 {
01204 contents[i]->destroy ();
01205 }
01206 }
01207 else
01208 {
01209 prev_def->destroy ();
01210
01211 int status =
01212 this->create_event_def (node);
01213
01214 return status;
01215 }
01216 }
01217
01218
01219
01220 CORBA::ComponentIR::EventDef_var extant_def =
01221 CORBA::ComponentIR::EventDef::_narrow (prev_def. in ());
01222
01223
01224
01225 CORBA::ValueDef_var base_vt;
01226 this->fill_base_value (base_vt.out (),
01227 node);
01228
01229 extant_def->base_value (base_vt.in ());
01230
01231
01232
01233 CORBA::ValueDefSeq abstract_base_values;
01234 this->fill_abstract_base_values (abstract_base_values,
01235 node);
01236
01237 extant_def->abstract_base_values (abstract_base_values);
01238
01239
01240
01241 CORBA::InterfaceDefSeq supported;
01242 this->fill_supported_interfaces (supported,
01243 node);
01244
01245 extant_def->supported_interfaces (supported);
01246
01247
01248
01249 CORBA::ExtInitializerSeq initializers;
01250 this->fill_initializers (initializers,
01251 node);
01252
01253 extant_def->ext_initializers (initializers);
01254
01255
01256
01257 extant_def->is_abstract (static_cast<CORBA::Boolean> (node->is_abstract ()));
01258
01259 extant_def->is_truncatable (static_cast<CORBA::Boolean> (node->truncatable ()));
01260
01261 extant_def->is_custom (static_cast<CORBA::Boolean> (node->custom ()));
01262
01263 node->ifr_added (true);
01264
01265
01266
01267 if (be_global->ifr_scopes ().push (extant_def.in ()) != 0)
01268 {
01269 ACE_ERROR_RETURN ((
01270 LM_ERROR,
01271 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01272 ACE_TEXT ("visit_eventtype -")
01273 ACE_TEXT (" scope push failed\n")
01274 ),
01275 -1
01276 );
01277 }
01278
01279
01280 if (this->visit_scope (node) == -1)
01281 {
01282 ACE_ERROR_RETURN ((
01283 LM_ERROR,
01284 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01285 ACE_TEXT ("visit_eventtype -")
01286 ACE_TEXT (" visit_scope failed\n")
01287 ),
01288 -1
01289 );
01290 }
01291
01292
01293
01294
01295
01296
01297 this->ir_current_ =
01298 CORBA::IDLType::_duplicate (extant_def.in ());
01299
01300 CORBA::Container_ptr used_scope =
01301 CORBA::Container::_nil ();
01302
01303
01304 if (be_global->ifr_scopes ().pop (used_scope) != 0)
01305 {
01306 ACE_ERROR_RETURN ((
01307 LM_ERROR,
01308 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01309 ACE_TEXT ("visit_eventtype -")
01310 ACE_TEXT (" scope pop failed\n")
01311 ),
01312 -1
01313 );
01314 }
01315 }
01316 else
01317 {
01318
01319
01320
01321
01322
01323
01324 this->ir_current_ =
01325 CORBA::IDLType::_narrow (prev_def.in ());
01326 }
01327 }
01328 }
01329 catch (const CORBA::Exception& ex)
01330 {
01331 ex._tao_print_exception (ACE_TEXT ("visit_eventtype"));
01332
01333 return -1;
01334 }
01335
01336 return 0;
01337 }
01338
01339 int
01340 ifr_adding_visitor::visit_eventtype_fwd (AST_EventTypeFwd *node)
01341 {
01342 if (node->imported () && !be_global->do_included_files ())
01343 {
01344 return 0;
01345 }
01346
01347 AST_Interface *v = node->full_definition ();
01348
01349 try
01350 {
01351
01352 CORBA::Contained_var prev_def =
01353 be_global->repository ()->lookup_id (v->repoID ());
01354
01355 if (CORBA::is_nil (prev_def.in ()))
01356 {
01357
01358
01359
01360
01361
01362 CORBA::ValueDefSeq abstract_bases (0);
01363 abstract_bases.length (0);
01364 CORBA::InterfaceDefSeq supported (0);
01365 supported.length (0);
01366 CORBA::ExtInitializerSeq initializers (0);
01367 initializers.length (0);
01368
01369 CORBA::Container_ptr current_scope =
01370 CORBA::Container::_nil ();
01371
01372 if (be_global->ifr_scopes ().top (current_scope) == 0)
01373 {
01374 CORBA::ComponentIR::Container_var ccm_scope =
01375 CORBA::ComponentIR::Container::_narrow (
01376 current_scope
01377 );
01378
01379 CORBA::Boolean abstract =
01380 static_cast<CORBA::Boolean> (v->is_abstract ());
01381
01382 this->ir_current_ =
01383 ccm_scope->create_event (
01384 v->repoID (),
01385 v->local_name ()->get_string (),
01386 v->version (),
01387 0,
01388 abstract,
01389 CORBA::ValueDef::_nil (),
01390 0,
01391 abstract_bases,
01392 supported,
01393 initializers
01394 );
01395 }
01396 else
01397 {
01398 ACE_ERROR_RETURN ((
01399 LM_ERROR,
01400 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01401 ACE_TEXT ("visit_eventtype_fwd -")
01402 ACE_TEXT (" scope stack is empty\n")
01403 ),
01404 -1
01405 );
01406 }
01407
01408 node->ifr_added (true);
01409 v->ifr_fwd_added (true);
01410 }
01411 }
01412 catch (const CORBA::Exception& ex)
01413 {
01414 ex._tao_print_exception (ACE_TEXT ("visit_eventtype_fwd"));
01415
01416 return -1;
01417 }
01418
01419 return 0;
01420 }
01421
01422 int
01423 ifr_adding_visitor::visit_home (AST_Home *node)
01424 {
01425 if (node->imported () && !be_global->do_included_files ())
01426 {
01427 return 0;
01428 }
01429
01430 try
01431 {
01432
01433 CORBA::Contained_var prev_def =
01434 be_global->repository ()->lookup_id (node->repoID ());
01435
01436
01437 if (CORBA::is_nil (prev_def.in ()))
01438 {
01439 int status = this->create_home_def (node);
01440
01441 return status;
01442 }
01443 else
01444 {
01445
01446
01447
01448
01449
01450 if (node->is_defined () && !node->ifr_added ())
01451 {
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466 if (!node->ifr_fwd_added ())
01467 {
01468 CORBA::DefinitionKind kind =
01469 prev_def->def_kind ();
01470
01471 if (kind == CORBA::dk_Component)
01472 {
01473 CORBA::ComponentIR::HomeDef_var value =
01474 CORBA::ComponentIR::HomeDef::_narrow (
01475 prev_def.in ()
01476 );
01477
01478 CORBA::ContainedSeq_var contents =
01479 value->contents (CORBA::dk_all,
01480 1);
01481
01482 CORBA::ULong length = contents->length ();
01483
01484 for (CORBA::ULong i = 0; i < length; ++i)
01485 {
01486 contents[i]->destroy ();
01487 }
01488 }
01489 else
01490 {
01491 prev_def->destroy ();
01492
01493 int status =
01494 this->create_home_def (node);
01495
01496 return status;
01497 }
01498 }
01499
01500
01501
01502 }
01503 else
01504 {
01505
01506
01507
01508
01509
01510
01511 this->ir_current_ =
01512 CORBA::IDLType::_narrow (prev_def.in ());
01513 }
01514 }
01515 }
01516 catch (const CORBA::Exception& ex)
01517 {
01518 ex._tao_print_exception (ACE_TEXT ("visit_home"));
01519
01520 return -1;
01521 }
01522
01523 return 0;
01524 }
01525
01526 int
01527 ifr_adding_visitor::visit_factory (AST_Factory *)
01528 {
01529 return 0;
01530 }
01531
01532 int
01533 ifr_adding_visitor::visit_structure (AST_Structure *node)
01534 {
01535 if (node->imported () && !be_global->do_included_files ())
01536 {
01537 return 0;
01538 }
01539
01540 try
01541 {
01542 CORBA::Contained_var prev_def =
01543 be_global->repository ()->lookup_id (node->repoID ());
01544
01545 if (CORBA::is_nil (prev_def.in ()))
01546 {
01547 ifr_adding_visitor_structure visitor (node, false);
01548 int retval = visitor.visit_structure (node);
01549
01550 if (retval == 0)
01551 {
01552 this->ir_current_ =
01553 CORBA::IDLType::_duplicate (visitor.ir_current ());
01554 }
01555
01556 return retval;
01557 }
01558 else
01559 {
01560
01561
01562
01563
01564 if (!node->ifr_added ())
01565 {
01566 prev_def->destroy ();
01567
01568 return this->visit_structure (node);
01569 }
01570
01571 this->ir_current_ =
01572 CORBA::IDLType::_narrow (prev_def.in ());
01573 }
01574 }
01575 catch (const CORBA::Exception& ex)
01576 {
01577 ex._tao_print_exception (
01578 ACE_TEXT (
01579 "ifr_adding_visitor::visit_structure"));
01580
01581 return -1;
01582 }
01583
01584 return 0;
01585 }
01586
01587 int
01588 ifr_adding_visitor::visit_structure_fwd (AST_StructureFwd *node)
01589 {
01590 if (node->imported () && !be_global->do_included_files ())
01591 {
01592 return 0;
01593 }
01594
01595 try
01596 {
01597 CORBA::Contained_var prev_def =
01598 be_global->repository ()->lookup_id (node->repoID ());
01599
01600 if (CORBA::is_nil (prev_def.in ()))
01601 {
01602 CORBA::StructMemberSeq dummyMembers;
01603 dummyMembers.length (0);
01604 CORBA::Container_ptr current_scope = CORBA::Container::_nil ();
01605
01606 if (be_global->ifr_scopes ().top (current_scope) != 0)
01607 {
01608 ACE_ERROR_RETURN ((
01609 LM_ERROR,
01610 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01611 ACE_TEXT ("visit_structure_fwd -")
01612 ACE_TEXT (" scope stack is empty\n")
01613 ),
01614 -1
01615 );
01616 }
01617
01618 CORBA::StructDef_var struct_def =
01619 current_scope->create_struct (
01620 node->repoID (),
01621 node->local_name ()->get_string (),
01622 node->version (),
01623 dummyMembers
01624 );
01625
01626 node->full_definition ()->ifr_fwd_added (true);
01627 }
01628 }
01629 catch (const CORBA::Exception& ex)
01630 {
01631 ex._tao_print_exception (ACE_TEXT ("ifr_adding_visitor::")
01632 ACE_TEXT ("visit_structure_fwd"));
01633
01634 return -1;
01635 }
01636
01637 return 0;
01638 }
01639
01640 int
01641 ifr_adding_visitor::visit_exception (AST_Exception *node)
01642 {
01643 if (node->imported () && !be_global->do_included_files ())
01644 {
01645 return 0;
01646 }
01647
01648 ifr_adding_visitor_exception visitor (node,
01649 this->in_reopened_);
01650
01651
01652
01653
01654 return visitor.visit_exception (node);
01655 }
01656
01657 int
01658 ifr_adding_visitor::visit_enum (AST_Enum *node)
01659 {
01660 if (node->imported () && !be_global->do_included_files ())
01661 {
01662 return 0;
01663 }
01664
01665 try
01666 {
01667
01668 CORBA::Contained_var prev_def =
01669 be_global->repository ()->lookup_id (node->repoID ());
01670
01671
01672 if (CORBA::is_nil (prev_def.in ()))
01673 {
01674 CORBA::ULong member_count =
01675 static_cast<CORBA::ULong> (node->member_count ());
01676
01677 CORBA::EnumMemberSeq members (member_count);
01678 members.length (member_count);
01679
01680 UTL_ScopedName *member_name = 0;
01681
01682
01683 for (CORBA::ULong i = 0; i < member_count; ++i)
01684 {
01685 member_name = node->value_to_name (i);
01686
01687 members[i] =
01688 CORBA::string_dup (
01689 member_name->last_component ()->get_string ()
01690 );
01691 }
01692
01693 CORBA::Container_ptr current_scope =
01694 CORBA::Container::_nil ();
01695
01696 if (be_global->ifr_scopes ().top (current_scope) == 0)
01697 {
01698 this->ir_current_ =
01699 current_scope->create_enum (
01700 node->repoID (),
01701 node->local_name ()->get_string (),
01702 node->version (),
01703 members
01704 );
01705 }
01706 else
01707 {
01708 ACE_ERROR_RETURN ((
01709 LM_ERROR,
01710 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_enum -")
01711 ACE_TEXT (" scope stack is empty\n")
01712 ),
01713 -1
01714 );
01715 }
01716
01717 node->ifr_added (true);
01718 }
01719 else
01720 {
01721
01722
01723
01724
01725 if (!node->ifr_added ())
01726 {
01727 prev_def->destroy ();
01728
01729 return this->visit_enum (node);
01730 }
01731
01732
01733
01734 this->ir_current_ =
01735 CORBA::EnumDef::_narrow (prev_def.in ());
01736 }
01737 }
01738 catch (const CORBA::Exception& ex)
01739 {
01740 ex._tao_print_exception (ACE_TEXT ("ifr_adding_visitor::visit_enum"));
01741
01742 return -1;
01743 }
01744
01745 return 0;
01746 }
01747
01748 int
01749 ifr_adding_visitor::visit_operation (AST_Operation *node)
01750 {
01751 ifr_adding_visitor_operation visitor (node);
01752
01753 return visitor.visit_operation (node);
01754 }
01755
01756 int
01757 ifr_adding_visitor::visit_field (AST_Field *node)
01758 {
01759 AST_Decl *scope = ScopeAsDecl (node->defined_in ());
01760 AST_Decl::NodeType nt = scope->node_type ();
01761
01762 if (nt == AST_Decl::NT_valuetype || nt == AST_Decl::NT_eventtype)
01763 {
01764 return this->create_value_member (node);
01765 }
01766
01767 AST_Type *ft = AST_Type::narrow_from_decl (node->field_type ());
01768
01769 if (ft == 0)
01770 {
01771 ACE_ERROR_RETURN ((
01772 LM_ERROR,
01773 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01774 ACE_TEXT ("visit_field - ")
01775 ACE_TEXT ("Bad field type\n")
01776 ),
01777 -1
01778 );
01779 }
01780
01781 if (ft->ast_accept (this) == -1)
01782 {
01783 ACE_ERROR_RETURN ((
01784 LM_ERROR,
01785 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01786 ACE_TEXT ("visit_field - ")
01787 ACE_TEXT ("failed to accept visitor\n")
01788 ),
01789 -1
01790 );
01791 }
01792
01793 return 0;
01794 }
01795
01796 int
01797 ifr_adding_visitor::visit_attribute (AST_Attribute *node)
01798 {
01799 try
01800 {
01801 AST_Type *type = node->field_type ();
01802
01803
01804 this->get_referenced_type (type);
01805
01806 CORBA::AttributeMode mode =
01807 node->readonly () ? CORBA::ATTR_READONLY : CORBA::ATTR_NORMAL;
01808
01809 CORBA::ExceptionDefSeq get_exceptions;
01810 this->fill_get_exceptions (get_exceptions,
01811 node);
01812
01813 CORBA::ExceptionDefSeq set_exceptions;
01814 this->fill_set_exceptions (set_exceptions,
01815 node);
01816
01817 CORBA::Container_ptr current_scope =
01818 CORBA::Container::_nil ();
01819
01820 if (be_global->ifr_scopes ().top (current_scope) == 0)
01821 {
01822 CORBA::DefinitionKind kind =
01823 current_scope->def_kind ();
01824
01825 if (kind == CORBA::dk_Value || kind == CORBA::dk_Event)
01826 {
01827 CORBA::ExtValueDef_var value =
01828 CORBA::ExtValueDef::_narrow (current_scope);
01829
01830 CORBA::ExtAttributeDef_var new_def =
01831 value->create_ext_attribute (
01832 node->repoID (),
01833 node->local_name ()->get_string (),
01834 node->version (),
01835 this->ir_current_.in (),
01836 mode,
01837 get_exceptions,
01838 set_exceptions
01839 );
01840 }
01841 else
01842 {
01843
01844
01845 CORBA::InterfaceAttrExtension_var iface =
01846 CORBA::InterfaceAttrExtension::_narrow (current_scope);
01847
01848 CORBA::ExtAttributeDef_var new_def =
01849 iface->create_ext_attribute (
01850 node->repoID (),
01851 node->local_name ()->get_string (),
01852 node->version (),
01853 this->ir_current_.in (),
01854 mode,
01855 get_exceptions,
01856 set_exceptions
01857 );
01858 }
01859 }
01860 else
01861 {
01862 ACE_ERROR_RETURN ((
01863 LM_ERROR,
01864 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_attribute -")
01865 ACE_TEXT (" scope stack is empty\n")
01866 ),
01867 -1
01868 );
01869 }
01870 }
01871 catch (const CORBA::Exception& ex)
01872 {
01873 ex._tao_print_exception (ACE_TEXT ("visit_attribute"));
01874
01875 return -1;
01876 }
01877
01878 return 0;
01879 }
01880
01881 int
01882 ifr_adding_visitor::visit_union (AST_Union *node)
01883 {
01884 if (node->imported () && !be_global->do_included_files ())
01885 {
01886 return 0;
01887 }
01888
01889 try
01890 {
01891 CORBA::Contained_var prev_def =
01892 be_global->repository ()->lookup_id (node->repoID ());
01893
01894 if (CORBA::is_nil (prev_def.in ()))
01895 {
01896 ifr_adding_visitor_union visitor (node,
01897 0);
01898
01899 int retval = visitor.visit_union (node);
01900
01901 if (retval == 0)
01902 {
01903 this->ir_current_ =
01904 CORBA::IDLType::_duplicate (visitor.ir_current ());
01905 }
01906
01907 return retval;
01908 }
01909 else
01910 {
01911
01912
01913
01914
01915 if (!node->ifr_added ())
01916 {
01917 prev_def->destroy ();
01918
01919 return this->visit_union (node);
01920 }
01921
01922 this->ir_current_ =
01923 CORBA::UnionDef::_narrow (prev_def.in ());
01924 }
01925 }
01926 catch (const CORBA::Exception& ex)
01927 {
01928 ex._tao_print_exception (ACE_TEXT ("ifr_adding_visitor::visit_union"));
01929
01930 return -1;
01931 }
01932
01933 return 0;
01934 }
01935
01936 int
01937 ifr_adding_visitor::visit_union_fwd (AST_UnionFwd *node)
01938 {
01939 if (node->imported () && !be_global->do_included_files ())
01940 {
01941 return 0;
01942 }
01943
01944 try
01945 {
01946 CORBA::Contained_var prev_def =
01947 be_global->repository ()->lookup_id (node->repoID ());
01948
01949 if (CORBA::is_nil (prev_def.in ()))
01950 {
01951 CORBA::UnionMemberSeq dummyMembers;
01952 dummyMembers.length (0);
01953 CORBA::Container_ptr current_scope = CORBA::Container::_nil ();
01954
01955 if (be_global->ifr_scopes ().top (current_scope) != 0)
01956 {
01957 ACE_ERROR_RETURN ((
01958 LM_ERROR,
01959 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
01960 ACE_TEXT ("visit_union_fwd -")
01961 ACE_TEXT (" scope stack is empty\n")
01962 ),
01963 -1
01964 );
01965 }
01966
01967 CORBA::UnionDef_var union_def =
01968 current_scope->create_union (
01969 node->repoID (),
01970 node->local_name ()->get_string (),
01971 node->version (),
01972 CORBA::IDLType::_nil (),
01973 dummyMembers
01974 );
01975
01976 node->full_definition ()->ifr_fwd_added (true);
01977 }
01978 }
01979 catch (const CORBA::Exception& ex)
01980 {
01981 ex._tao_print_exception (ACE_TEXT ("ifr_adding_visitor::")
01982 ACE_TEXT ("visit_union_fwd"));
01983
01984 return -1;
01985 }
01986
01987 return 0;
01988 }
01989
01990 int
01991 ifr_adding_visitor::visit_constant (AST_Constant *node)
01992 {
01993 if (node->imported () && !be_global->do_included_files ())
01994 {
01995 return 0;
01996 }
01997
01998 const char *id = node->repoID ();
01999
02000 try
02001 {
02002 CORBA::Contained_var prev_def =
02003 be_global->repository ()->lookup_id (id);
02004
02005
02006
02007
02008
02009
02010 if (!CORBA::is_nil (prev_def.in ()))
02011 {
02012
02013
02014
02015
02016 if (!node->ifr_added ())
02017 {
02018 prev_def->destroy ();
02019 }
02020 else
02021 {
02022
02023
02024 return 0;
02025 }
02026 }
02027
02028 AST_Expression::ExprType et = node->et ();
02029 AST_Expression *cv = node->constant_value ();
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039 if (et == AST_Expression::EV_enum)
02040 {
02041
02042
02043
02044 AST_Decl *enum_val =
02045 node->defined_in ()->lookup_by_name (cv->n (), true);
02046 AST_Decl *d = ScopeAsDecl (enum_val->defined_in ());
02047
02048 CORBA::Contained_var contained =
02049 be_global->repository ()->lookup_id (d->repoID ());
02050
02051 this->ir_current_ = CORBA::IDLType::_narrow (contained.in ());
02052 }
02053 else
02054 {
02055
02056
02057 CORBA::PrimitiveKind pkind = this->expr_type_to_pkind (et);
02058
02059 this->ir_current_ =
02060 be_global->repository ()->get_primitive (pkind);
02061 }
02062
02063 CORBA::Any any;
02064 this->load_any (cv->ev (), any);
02065
02066 CORBA::Container_ptr current_scope = CORBA::Container::_nil ();
02067
02068 if (be_global->ifr_scopes ().top (current_scope) == 0)
02069 {
02070 CORBA::ConstantDef_var new_def =
02071 current_scope->create_constant (
02072 id,
02073 node->local_name ()->get_string (),
02074 node->version (),
02075 this->ir_current_.in (),
02076 any
02077 );
02078 }
02079 else
02080 {
02081 ACE_ERROR_RETURN ((
02082 LM_ERROR,
02083 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_constant -")
02084 ACE_TEXT (" scope stack is empty\n")
02085 ),
02086 -1
02087 );
02088 }
02089 }
02090 catch (const CORBA::Exception& ex)
02091 {
02092 ex._tao_print_exception (ACE_TEXT ("visit_constant"));
02093
02094 return -1;
02095 }
02096
02097 return 0;
02098 }
02099
02100 int
02101 ifr_adding_visitor::visit_array (AST_Array *node)
02102 {
02103 try
02104 {
02105 bool owned = false;
02106 AST_Type *bt = node->base_type ();
02107 UTL_Scope *bts = bt->defined_in ();
02108 UTL_Scope *ns = node->defined_in ();
02109
02110 if (bts == ns && !bt->ifr_added ())
02111 {
02112
02113
02114
02115
02116
02117
02118
02119 owned = true;
02120 }
02121
02122 this->element_type (bt, owned);
02123
02124 AST_Expression **dims = node->dims ();
02125
02126 for (unsigned long i = node->n_dims (); i > 0; --i)
02127 {
02128 this->ir_current_ =
02129 be_global->repository ()->create_array (
02130 dims[i - 1]->ev ()->u.ulval,
02131 this->ir_current_.in ()
02132 );
02133 }
02134 }
02135 catch (const CORBA::Exception& ex)
02136 {
02137 ex._tao_print_exception (ACE_TEXT ("visit_array"));
02138
02139 return -1;
02140 }
02141
02142 return 0;
02143 }
02144
02145 int
02146 ifr_adding_visitor::visit_sequence (AST_Sequence *node)
02147 {
02148 try
02149 {
02150 this->element_type (node->base_type ());
02151
02152 this->ir_current_ =
02153 be_global->repository ()->create_sequence (
02154 node->max_size ()->ev ()->u.ulval,
02155 this->ir_current_.in ()
02156 );
02157 }
02158 catch (const CORBA::Exception& ex)
02159 {
02160 ex._tao_print_exception (ACE_TEXT ("visit_sequence"));
02161
02162 return -1;
02163 }
02164
02165 return 0;
02166 }
02167
02168 int
02169 ifr_adding_visitor::visit_string (AST_String *node)
02170 {
02171 AST_Expression *ex = node->max_size ();
02172
02173 AST_Expression::AST_ExprValue *ev = ex->ev ();
02174
02175 CORBA::ULong bound = static_cast<CORBA::ULong> (ev->u.ulval);
02176
02177 try
02178 {
02179 if (node->node_type () == AST_Decl::NT_string)
02180 {
02181 this->ir_current_ =
02182 be_global->repository ()->create_string (bound);
02183 }
02184 else
02185 {
02186 this->ir_current_ =
02187 be_global->repository ()->create_wstring (bound);
02188 }
02189
02190 }
02191 catch (const CORBA::Exception& ex)
02192 {
02193 ex._tao_print_exception (ACE_TEXT ("visit_string"));
02194
02195 return -1;
02196 }
02197
02198 return 0;
02199 }
02200
02201 int
02202 ifr_adding_visitor::visit_typedef (AST_Typedef *node)
02203 {
02204 if (node->imported () && !be_global->do_included_files ())
02205 {
02206 return 0;
02207 }
02208
02209 try
02210 {
02211 this->element_type (node->base_type (), node->owns_base_type ());
02212
02213 CORBA::Container_ptr current_scope =
02214 CORBA::Container::_nil ();
02215
02216 if (be_global->ifr_scopes ().top (current_scope) == 0)
02217 {
02218 this->ir_current_ =
02219 current_scope->create_alias (
02220 node->repoID (),
02221 node->local_name ()->get_string (),
02222 node->version (),
02223 this->ir_current_.in ()
02224 );
02225 }
02226 else
02227 {
02228 ACE_ERROR_RETURN ((
02229 LM_ERROR,
02230 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_typedef -")
02231 ACE_TEXT (" scope stack is empty\n")
02232 ),
02233 -1
02234 );
02235 }
02236
02237 node->ifr_added (true);
02238 }
02239 catch (const CORBA::Exception& ex)
02240 {
02241 if (!this->allow_duplicate_typedefs_)
02242 {
02243 ex._tao_print_exception (ACE_TEXT ("visit_typedef"));
02244
02245 return -1;
02246 }
02247 else
02248 {
02249 ACE_DEBUG ((LM_DEBUG,
02250 "%s %s\n",
02251 ACE_TEXT ("ifr_adding_visitor::visit_typedef - ignoring duplicate typedef"),
02252 node->local_name ()->get_string ()));
02253 }
02254 }
02255
02256 return 0;
02257 }
02258
02259 int
02260 ifr_adding_visitor::visit_root (AST_Root *node)
02261 {
02262 if (be_global->ifr_scopes ().push (be_global->repository ()) != 0)
02263 {
02264 ACE_ERROR_RETURN ((
02265 LM_ERROR,
02266 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_root -")
02267 ACE_TEXT (" scope push failed\n")
02268 ),
02269 -1
02270 );
02271 }
02272
02273 if (this->visit_scope (node) == -1)
02274 {
02275 ACE_ERROR_RETURN ((
02276 LM_ERROR,
02277 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_root -")
02278 ACE_TEXT (" visit_scope failed\n")
02279 ),
02280 -1
02281 );
02282 }
02283
02284 CORBA::Container_ptr tmp =
02285 CORBA::Container::_nil ();
02286
02287 if (be_global->ifr_scopes ().pop (tmp) != 0)
02288 {
02289 ACE_ERROR_RETURN ((
02290 LM_ERROR,
02291 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_root -")
02292 ACE_TEXT (" scope pop failed\n")
02293 ),
02294 -1
02295 );
02296 }
02297
02298 return 0;
02299 }
02300
02301 int
02302 ifr_adding_visitor::visit_native (AST_Native *node)
02303 {
02304 if (node->imported () && !be_global->do_included_files ())
02305 {
02306 return 0;
02307 }
02308
02309 try
02310 {
02311 CORBA::Contained_var prev_def =
02312 be_global->repository ()->lookup_id (node->repoID ());
02313
02314 if (CORBA::is_nil (prev_def.in ()))
02315 {
02316 CORBA::Container_ptr current_scope =
02317 CORBA::Container::_nil ();
02318
02319 if (be_global->ifr_scopes ().top (current_scope) == 0)
02320 {
02321 this->ir_current_ =
02322 current_scope->create_native (
02323 node->repoID (),
02324 node->local_name ()->get_string (),
02325 node->version ()
02326 );
02327 }
02328 else
02329 {
02330 ACE_ERROR_RETURN ((
02331 LM_ERROR,
02332 ACE_TEXT ("(%N:%l) ifr_adding_visitor::visit_native -")
02333 ACE_TEXT (" scope stack is empty\n")
02334 ),
02335 -1
02336 );
02337 }
02338
02339 node->ifr_added (true);
02340 }
02341 else
02342 {
02343
02344
02345
02346
02347 if (!node->ifr_added ())
02348 {
02349 prev_def->destroy ();
02350
02351
02352 return this->visit_native (node);
02353 }
02354
02355 this->ir_current_ =
02356 CORBA::NativeDef::_narrow (prev_def.in ());
02357 }
02358 }
02359 catch (const CORBA::Exception& ex)
02360 {
02361 ex._tao_print_exception (ACE_TEXT ("visit_native"));
02362
02363 return -1;
02364 }
02365
02366 return 0;
02367 }
02368
02369 CORBA::PrimitiveKind
02370 ifr_adding_visitor::expr_type_to_pkind (AST_Expression::ExprType et)
02371 {
02372 switch (et)
02373 {
02374 case AST_Expression::EV_short:
02375 return CORBA::pk_short;
02376 case AST_Expression::EV_ushort:
02377 return CORBA::pk_ushort;
02378 case AST_Expression::EV_long:
02379 return CORBA::pk_long;
02380 case AST_Expression::EV_ulong:
02381 return CORBA::pk_ulong;
02382 case AST_Expression::EV_longlong:
02383 return CORBA::pk_longlong;
02384 case AST_Expression::EV_ulonglong:
02385 return CORBA::pk_ulonglong;
02386 case AST_Expression::EV_float:
02387 return CORBA::pk_float;
02388 case AST_Expression::EV_double:
02389 return CORBA::pk_double;
02390 case AST_Expression::EV_longdouble:
02391 return CORBA::pk_longdouble;
02392 case AST_Expression::EV_char:
02393 return CORBA::pk_char;
02394 case AST_Expression::EV_wchar:
02395 return CORBA::pk_wchar;
02396 case AST_Expression::EV_octet:
02397 return CORBA::pk_octet;
02398 case AST_Expression::EV_bool:
02399 return CORBA::pk_boolean;
02400 case AST_Expression::EV_string:
02401 return CORBA::pk_string;
02402 case AST_Expression::EV_wstring:
02403 return CORBA::pk_wstring;
02404 case AST_Expression::EV_any:
02405 return CORBA::pk_any;
02406 case AST_Expression::EV_void:
02407 return CORBA::pk_void;
02408 case AST_Expression::EV_none:
02409 return CORBA::pk_null;
02410 default:
02411 return CORBA::pk_null;
02412 }
02413 }
02414
02415 CORBA::PrimitiveKind
02416 ifr_adding_visitor::predefined_type_to_pkind (AST_PredefinedType *node)
02417 {
02418 switch (node->pt ())
02419 {
02420 case AST_PredefinedType::PT_short:
02421 return CORBA::pk_short;
02422 case AST_PredefinedType::PT_ushort:
02423 return CORBA::pk_ushort;
02424 case AST_PredefinedType::PT_long:
02425 return CORBA::pk_long;
02426 case AST_PredefinedType::PT_ulong:
02427 return CORBA::pk_ulong;
02428 case AST_PredefinedType::PT_longlong:
02429 return CORBA::pk_longlong;
02430 case AST_PredefinedType::PT_ulonglong:
02431 return CORBA::pk_ulonglong;
02432 case AST_PredefinedType::PT_float:
02433 return CORBA::pk_float;
02434 case AST_PredefinedType::PT_double:
02435 return CORBA::pk_double;
02436 case AST_PredefinedType::PT_longdouble:
02437 return CORBA::pk_longdouble;
02438 case AST_PredefinedType::PT_char:
02439 return CORBA::pk_char;
02440 case AST_PredefinedType::PT_wchar:
02441 return CORBA::pk_wchar;
02442 case AST_PredefinedType::PT_octet:
02443 return CORBA::pk_octet;
02444 case AST_PredefinedType::PT_boolean:
02445 return CORBA::pk_boolean;
02446 case AST_PredefinedType::PT_any:
02447 return CORBA::pk_any;
02448 case AST_PredefinedType::PT_void:
02449 return CORBA::pk_void;
02450 case AST_PredefinedType::PT_object:
02451 return CORBA::pk_objref;
02452 case AST_PredefinedType::PT_pseudo:
02453 {
02454 const char *local_name = node->local_name ()->get_string ();
02455
02456 if (!ACE_OS::strcmp (local_name, "Principal"))
02457 {
02458 return CORBA::pk_Principal;
02459 }
02460 else
02461 {
02462 return CORBA::pk_TypeCode;
02463 }
02464 }
02465 default:
02466 return CORBA::pk_null;
02467 }
02468 }
02469
02470 void
02471 ifr_adding_visitor::load_any (AST_Expression::AST_ExprValue *ev,
02472 CORBA::Any &any)
02473 {
02474 switch (ev->et)
02475 {
02476 case AST_Expression::EV_short:
02477 any <<= ev->u.sval;
02478 break;
02479 case AST_Expression::EV_ushort:
02480 any <<= ev->u.usval;
02481 break;
02482 case AST_Expression::EV_long:
02483 any <<= static_cast<CORBA::Long> (ev->u.lval);
02484 break;
02485 case AST_Expression::EV_ulong:
02486 any <<= static_cast<CORBA::ULong> (ev->u.ulval);
02487 break;
02488 #if !defined (ACE_LACKS_LONGLONG_T)
02489 case AST_Expression::EV_longlong:
02490 any <<= ev->u.llval;
02491 break;
02492 case AST_Expression::EV_ulonglong:
02493 any <<= ev->u.ullval;
02494 break;
02495 #endif
02496 case AST_Expression::EV_float:
02497 any <<= ev->u.fval;
02498 break;
02499 case AST_Expression::EV_double:
02500 any <<= ev->u.dval;
02501 break;
02502 #if 0
02503 case AST_Expression::EV_longdouble:
02504
02505 #endif
02506 case AST_Expression::EV_char:
02507 any <<= CORBA::Any::from_char (ev->u.cval);
02508 break;
02509 case AST_Expression::EV_wchar:
02510 any <<= CORBA::Any::from_wchar (ev->u.wcval);
02511 break;
02512 case AST_Expression::EV_octet:
02513 any <<= CORBA::Any::from_octet (ev->u.oval);
02514 break;
02515 case AST_Expression::EV_bool:
02516 any <<= CORBA::Any::from_boolean ((CORBA::Boolean) ev->u.bval);
02517 break;
02518 case AST_Expression::EV_string:
02519 any <<= ev->u.strval->get_string ();
02520 break;
02521 case AST_Expression::EV_wstring:
02522 {
02523 char *str = ev->u.wstrval;
02524 size_t len = ACE_OS::strlen (str);
02525 CORBA::WChar *wstr = 0;
02526 ACE_NEW (wstr,
02527 CORBA::WChar[len + 1]);
02528
02529 for (size_t i = 0; i < len; ++i)
02530 {
02531 wstr[i] = static_cast<CORBA::WChar> (str[i]);
02532 }
02533
02534 wstr[len] = 0;
02535 any <<= wstr;
02536 delete wstr;
02537 break;
02538 }
02539 case AST_Expression::EV_enum:
02540 any <<= static_cast<CORBA::ULong> (ev->u.eval);
02541 break;
02542 default:
02543 break;
02544 }
02545 }
02546
02547 void
02548 ifr_adding_visitor::element_type (AST_Type *base_type, bool owned)
02549 {
02550 AST_Decl::NodeType nt = base_type->node_type ();
02551 bool no_repo_id = nt == AST_Decl::NT_array
02552 || nt == AST_Decl::NT_sequence
02553 || base_type->anonymous ();
02554
02555 if (no_repo_id || owned)
02556 {
02557 if (base_type->ast_accept (this) == -1)
02558 {
02559 ACE_ERROR ((
02560 LM_ERROR,
02561 ACE_TEXT ("(%N:%l) ifr_adding_visitor::element_type -")
02562 ACE_TEXT (" failed to accept visitor\n")
02563 ));
02564
02565 throw Bailout ();
02566 }
02567 }
02568 else
02569 {
02570 CORBA::Contained_var contained =
02571 be_global->repository ()->lookup_id (base_type->repoID ());
02572
02573 if (CORBA::is_nil (contained.in ()))
02574 {
02575 ACE_ERROR ((
02576 LM_ERROR,
02577 ACE_TEXT ("(%N:%l) ifr_adding_visitor::element_type -")
02578 ACE_TEXT (" lookup_id failed\n")
02579 ));
02580
02581 throw Bailout ();
02582 }
02583
02584 this->ir_current_ = CORBA::IDLType::_narrow (contained.in ());
02585 }
02586 }
02587
02588 int
02589 ifr_adding_visitor::create_interface_def (AST_Interface *node)
02590 {
02591 CORBA::ULong n_parents = static_cast<CORBA::ULong> (node->n_inherits ());
02592 AST_Interface **parents = node->inherits ();
02593 CORBA::Contained_var result;
02594 CORBA::AbstractInterfaceDefSeq abs_bases;
02595 CORBA::InterfaceDefSeq bases;
02596
02597 if (node->is_abstract ())
02598 {
02599 abs_bases.length (n_parents);
02600
02601
02602 for (CORBA::ULong i = 0; i < n_parents; ++i)
02603 {
02604 result =
02605 be_global->repository ()->lookup_id (parents[i]->repoID ());
02606
02607
02608
02609 if (CORBA::is_nil (result.in ()))
02610 {
02611 int status = this->create_interface_def (parents[i]);
02612
02613 if (status != 0)
02614 {
02615 ACE_ERROR_RETURN ((
02616 LM_ERROR,
02617 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02618 ACE_TEXT ("create_interface_def -")
02619 ACE_TEXT (" parent interfacedef creation failed\n")
02620 ),
02621 -1
02622 );
02623 }
02624
02625 bases[i] =
02626 CORBA::AbstractInterfaceDef::_narrow (this->ir_current_.in ());
02627 }
02628 else
02629 {
02630 abs_bases[i] =
02631 CORBA::AbstractInterfaceDef::_narrow (result.in ());
02632 }
02633
02634 if (CORBA::is_nil (abs_bases[i]))
02635 {
02636 ACE_ERROR_RETURN ((
02637 LM_ERROR,
02638 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02639 ACE_TEXT ("create_interface_def -")
02640 ACE_TEXT (" CORBA::InterfaceDef::_narrow failed\n")
02641 ),
02642 -1
02643 );
02644 }
02645 }
02646 }
02647 else
02648 {
02649 bases.length (n_parents);
02650
02651
02652 for (CORBA::ULong i = 0; i < n_parents; ++i)
02653 {
02654 result =
02655 be_global->repository ()->lookup_id (parents[i]->repoID ());
02656
02657
02658
02659 if (CORBA::is_nil (result.in ()))
02660 {
02661 int status = this->create_interface_def (parents[i]);
02662
02663 if (status != 0)
02664 {
02665 ACE_ERROR_RETURN ((
02666 LM_ERROR,
02667 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02668 ACE_TEXT ("create_interface_def -")
02669 ACE_TEXT (" parent interfacedef creation failed\n")
02670 ),
02671 -1
02672 );
02673 }
02674
02675 bases[i] = CORBA::InterfaceDef::_narrow (this->ir_current_.in ());
02676 }
02677 else
02678 {
02679 bases[i] = CORBA::InterfaceDef::_narrow (result.in ());
02680 }
02681
02682 if (CORBA::is_nil (bases[i]))
02683 {
02684 ACE_ERROR_RETURN ((
02685 LM_ERROR,
02686 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02687 ACE_TEXT ("create_interface_def -")
02688 ACE_TEXT (" CORBA::InterfaceDef::_narrow failed\n")
02689 ),
02690 -1
02691 );
02692 }
02693 }
02694 }
02695
02696 CORBA::Container_ptr current_scope =
02697 CORBA::Container::_nil ();
02698
02699 if (be_global->ifr_scopes ().top (current_scope) == 0)
02700 {
02701 CORBA::InterfaceDef_var new_def;
02702
02703 if (node->is_local ())
02704 {
02705 new_def =
02706 current_scope->create_local_interface (
02707 node->repoID (),
02708 node->local_name ()->get_string (),
02709 node->version (),
02710 bases
02711 );
02712 }
02713 else if (node->is_abstract ())
02714 {
02715 new_def =
02716 current_scope->create_abstract_interface (
02717 node->repoID (),
02718 node->local_name ()->get_string (),
02719 node->version (),
02720 abs_bases
02721 );
02722 }
02723 else
02724 {
02725 new_def =
02726 current_scope->create_interface (
02727 node->repoID (),
02728 node->local_name ()->get_string (),
02729 node->version (),
02730 bases
02731 );
02732 }
02733
02734
02735 node->ifr_added (true);
02736
02737
02738 CORBA::Container_var new_scope =
02739 CORBA::Container::_narrow (new_def.in ());
02740
02741 if (be_global->ifr_scopes ().push (new_scope.in ()) != 0)
02742 {
02743 ACE_ERROR_RETURN ((
02744 LM_ERROR,
02745 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02746 ACE_TEXT ("create_interface_def -")
02747 ACE_TEXT (" scope push failed\n")
02748 ),
02749 -1
02750 );
02751 }
02752
02753
02754 if (this->visit_scope (node) == -1)
02755 {
02756 ACE_ERROR_RETURN ((
02757 LM_ERROR,
02758 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02759 ACE_TEXT ("create_interface_def -")
02760 ACE_TEXT (" visit_scope failed\n")
02761 ),
02762 -1
02763 );
02764 }
02765
02766
02767
02768
02769
02770
02771
02772 this->ir_current_ =
02773 CORBA::IDLType::_duplicate (new_def.in ());
02774
02775 CORBA::Container_ptr used_scope =
02776 CORBA::Container::_nil ();
02777
02778
02779 if (be_global->ifr_scopes ().pop (used_scope) != 0)
02780 {
02781 ACE_ERROR_RETURN ((
02782 LM_ERROR,
02783 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02784 ACE_TEXT ("create_interface_def -")
02785 ACE_TEXT (" scope pop failed\n")
02786 ),
02787 -1
02788 );
02789 }
02790 }
02791 else
02792 {
02793 ACE_ERROR_RETURN ((
02794 LM_ERROR,
02795 ACE_TEXT ("(%N:%l) ifr_adding_visitor::create_interface_def -")
02796 ACE_TEXT (" scope stack is empty\n")
02797 ),
02798 -1
02799 );
02800 }
02801
02802 return 0;
02803 }
02804
02805 int
02806 ifr_adding_visitor::create_value_def (AST_ValueType *node)
02807 {
02808 CORBA::Container_ptr current_scope =
02809 CORBA::Container::_nil ();
02810
02811 if (be_global->ifr_scopes ().top (current_scope) == 0)
02812 {
02813 CORBA::ValueDef_var base_value;
02814 this->fill_base_value (base_value.out (),
02815 node);
02816
02817 CORBA::ValueDefSeq abstract_base_values;
02818 this->fill_abstract_base_values (abstract_base_values,
02819 node);
02820
02821 CORBA::InterfaceDefSeq supported_interfaces;
02822 this->fill_supported_interfaces (supported_interfaces,
02823 node);
02824
02825 CORBA::ExtInitializerSeq initializers;
02826 this->fill_initializers (initializers,
02827 node);
02828
02829 CORBA::ExtValueDef_var new_def =
02830 current_scope->create_ext_value (
02831 node->repoID (),
02832 node->local_name ()->get_string (),
02833 node->version (),
02834 static_cast<CORBA::Boolean> (node->custom ()),
02835 static_cast<CORBA::Boolean> (node->is_abstract ()),
02836 base_value.in (),
02837 static_cast<CORBA::Boolean> (node->truncatable ()),
02838 abstract_base_values,
02839 supported_interfaces,
02840 initializers
02841 );
02842
02843 node->ifr_added (true);
02844
02845
02846 CORBA::Container_var new_scope =
02847 CORBA::Container::_narrow (new_def.in ());
02848
02849 if (be_global->ifr_scopes ().push (new_scope.in ()) != 0)
02850 {
02851 ACE_ERROR_RETURN ((
02852 LM_ERROR,
02853 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02854 ACE_TEXT ("create_value_def -")
02855 ACE_TEXT (" scope push failed\n")
02856 ),
02857 -1
02858 );
02859 }
02860
02861
02862 if (this->visit_scope (node) == -1)
02863 {
02864 ACE_ERROR_RETURN ((
02865 LM_ERROR,
02866 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02867 ACE_TEXT ("create_value_def -")
02868 ACE_TEXT (" visit_scope failed\n")
02869 ),
02870 -1
02871 );
02872 }
02873
02874
02875
02876
02877
02878
02879
02880 this->ir_current_ =
02881 CORBA::IDLType::_duplicate (new_def.in ());
02882
02883 CORBA::Container_ptr used_scope =
02884 CORBA::Container::_nil ();
02885
02886
02887 if (be_global->ifr_scopes ().pop (used_scope) != 0)
02888 {
02889 ACE_ERROR_RETURN ((
02890 LM_ERROR,
02891 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02892 ACE_TEXT ("create_value_def -")
02893 ACE_TEXT (" scope pop failed\n")
02894 ),
02895 -1
02896 );
02897 }
02898 }
02899 else
02900 {
02901 ACE_ERROR_RETURN ((
02902 LM_ERROR,
02903 ACE_TEXT ("(%N:%l) ifr_adding_visitor::create_value_def -")
02904 ACE_TEXT (" scope stack is empty\n")
02905 ),
02906 -1
02907 );
02908 }
02909
02910 return 0;
02911 }
02912
02913 int
02914 ifr_adding_visitor::create_component_def (AST_Component *node)
02915 {
02916 CORBA::Container_ptr current_scope =
02917 CORBA::Container::_nil ();
02918
02919 if (be_global->ifr_scopes ().top (current_scope) == 0)
02920 {
02921 CORBA::ComponentIR::ComponentDef_var base_component;
02922 this->fill_base_component (base_component.out (),
02923 node);
02924
02925 CORBA::InterfaceDefSeq supported_interfaces;
02926 this->fill_supported_interfaces (supported_interfaces,
02927 node);
02928
02929 CORBA::ComponentIR::Container_var ccm_scope =
02930 CORBA::ComponentIR::Container::_narrow (current_scope);
02931
02932 CORBA::ComponentIR::ComponentDef_var new_def =
02933 ccm_scope->create_component (node->repoID (),
02934 node->local_name ()->get_string (),
02935 node->version (),
02936 base_component.in (),
02937 supported_interfaces);
02938
02939 node->ifr_added (true);
02940
02941 if (be_global->ifr_scopes ().push (new_def.in ()) != 0)
02942 {
02943 ACE_ERROR_RETURN ((
02944 LM_ERROR,
02945 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02946 ACE_TEXT ("create_component_def -")
02947 ACE_TEXT (" scope push failed\n")
02948 ),
02949 -1
02950 );
02951 }
02952
02953
02954 if (this->visit_scope (node) == -1)
02955 {
02956 ACE_ERROR_RETURN ((
02957 LM_ERROR,
02958 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02959 ACE_TEXT ("create_component_def -")
02960 ACE_TEXT (" visit_scope failed\n")
02961 ),
02962 -1
02963 );
02964 }
02965
02966 this->visit_all_provides (node,
02967 new_def.in ());
02968
02969 this->visit_all_uses (node,
02970 new_def.in ());
02971
02972 this->visit_all_emits (node,
02973 new_def.in ());
02974
02975 this->visit_all_publishes (node,
02976 new_def.in ());
02977
02978 this->visit_all_consumes (node,
02979 new_def.in ());
02980
02981
02982
02983
02984
02985
02986
02987 this->ir_current_ =
02988 CORBA::IDLType::_duplicate (new_def.in ());
02989
02990 CORBA::Container_ptr used_scope =
02991 CORBA::Container::_nil ();
02992
02993
02994 if (be_global->ifr_scopes ().pop (used_scope) != 0)
02995 {
02996 ACE_ERROR_RETURN ((
02997 LM_ERROR,
02998 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
02999 ACE_TEXT ("create_component_def -")
03000 ACE_TEXT (" scope pop failed\n")
03001 ),
03002 -1
03003 );
03004 }
03005 }
03006 else
03007 {
03008 ACE_ERROR_RETURN ((
03009 LM_ERROR,
03010 ACE_TEXT ("(%N:%l) ifr_adding_visitor::create_component_def -")
03011 ACE_TEXT (" scope stack is empty\n")
03012 ),
03013 -1
03014 );
03015 }
03016
03017 return 0;
03018 }
03019
03020 int
03021 ifr_adding_visitor::create_home_def (AST_Home *node)
03022 {
03023 CORBA::Container_ptr current_scope =
03024 CORBA::Container::_nil ();
03025
03026 if (be_global->ifr_scopes ().top (current_scope) == 0)
03027 {
03028 CORBA::ComponentIR::HomeDef_var base_home;
03029 this->fill_base_home (base_home.out (),
03030 node);
03031
03032 CORBA::ComponentIR::ComponentDef_var managed_component;
03033 this->fill_managed_component (managed_component.out (),
03034 node);
03035
03036 CORBA::InterfaceDefSeq supported_interfaces;
03037 this->fill_supported_interfaces (supported_interfaces,
03038 node);
03039
03040 CORBA::ValueDef_var primary_key;
03041 this->fill_primary_key (primary_key.out (),
03042 node);
03043
03044 CORBA::ComponentIR::Container_var ccm_scope =
03045 CORBA::ComponentIR::Container::_narrow (current_scope);
03046
03047 CORBA::ComponentIR::HomeDef_var new_def =
03048 ccm_scope->create_home (node->repoID (),
03049 node->local_name ()->get_string (),
03050 node->version (),
03051 base_home.in (),
03052 managed_component.in (),
03053 supported_interfaces,
03054 primary_key.in ());
03055
03056 node->ifr_added (true);
03057
03058
03059 CORBA::Container_var new_scope =
03060 CORBA::Container::_narrow (new_def.in ());
03061
03062 if (be_global->ifr_scopes ().push (new_scope.in ()) != 0)
03063 {
03064 ACE_ERROR_RETURN ((
03065 LM_ERROR,
03066 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03067 ACE_TEXT ("create_home_def -")
03068 ACE_TEXT (" scope push failed\n")
03069 ),
03070 -1
03071 );
03072 }
03073
03074
03075 if (this->visit_scope (node) == -1)
03076 {
03077 ACE_ERROR_RETURN ((
03078 LM_ERROR,
03079 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03080 ACE_TEXT ("create_home_def -")
03081 ACE_TEXT (" visit_scope failed\n")
03082 ),
03083 -1
03084 );
03085 }
03086
03087
03088
03089 this->visit_all_factories (node,
03090 new_def.in ());
03091
03092 this->visit_all_finders (node,
03093 new_def.in ());
03094
03095
03096
03097
03098
03099
03100
03101 this->ir_current_ =
03102 CORBA::IDLType::_duplicate (new_def.in ());
03103
03104 CORBA::Container_ptr used_scope =
03105 CORBA::Container::_nil ();
03106
03107
03108 if (be_global->ifr_scopes ().pop (used_scope) != 0)
03109 {
03110 ACE_ERROR_RETURN ((
03111 LM_ERROR,
03112 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03113 ACE_TEXT ("create_home_def -")
03114 ACE_TEXT (" scope pop failed\n")
03115 ),
03116 -1
03117 );
03118 }
03119 }
03120 else
03121 {
03122 ACE_ERROR_RETURN ((
03123 LM_ERROR,
03124 ACE_TEXT ("(%N:%l) ifr_adding_visitor::create_home_def -")
03125 ACE_TEXT (" scope stack is empty\n")
03126 ),
03127 -1
03128 );
03129 }
03130
03131 return 0;
03132 }
03133
03134 int
03135 ifr_adding_visitor::create_event_def (AST_EventType *node)
03136 {
03137 CORBA::Container_ptr current_scope =
03138 CORBA::Container::_nil ();
03139
03140 if (be_global->ifr_scopes ().top (current_scope) == 0)
03141 {
03142 CORBA::ValueDef_var base_value;
03143 this->fill_base_value (base_value.out (),
03144 node);
03145
03146 CORBA::ValueDefSeq abstract_base_values;
03147 this->fill_abstract_base_values (abstract_base_values,
03148 node);
03149
03150 CORBA::InterfaceDefSeq supported_interfaces;
03151 this->fill_supported_interfaces (supported_interfaces,
03152 node);
03153
03154 CORBA::ExtInitializerSeq initializers;
03155 this->fill_initializers (initializers,
03156 node);
03157
03158 CORBA::ComponentIR::Container_var ccm_scope =
03159 CORBA::ComponentIR::Container::_narrow (current_scope);
03160
03161 CORBA::ExtValueDef_var new_def =
03162 ccm_scope->create_event (
03163 node->repoID (),
03164 node->local_name ()->get_string (),
03165 node->version (),
03166 static_cast<CORBA::Boolean> (node->custom ()),
03167 static_cast<CORBA::Boolean> (node->is_abstract ()),
03168 base_value.in (),
03169 static_cast<CORBA::Boolean> (node->truncatable ()),
03170 abstract_base_values,
03171 supported_interfaces,
03172 initializers
03173 );
03174
03175 node->ifr_added (true);
03176
03177
03178 CORBA::Container_var new_scope =
03179 CORBA::Container::_narrow (new_def.in ());
03180
03181 if (be_global->ifr_scopes ().push (new_scope.in ()) != 0)
03182 {
03183 ACE_ERROR_RETURN ((
03184 LM_ERROR,
03185 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03186 ACE_TEXT ("create_event_def -")
03187 ACE_TEXT (" scope push failed\n")
03188 ),
03189 -1
03190 );
03191 }
03192
03193
03194 if (this->visit_scope (node) == -1)
03195 {
03196 ACE_ERROR_RETURN ((
03197 LM_ERROR,
03198 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03199 ACE_TEXT ("create_event_def -")
03200 ACE_TEXT (" visit_scope failed\n")
03201 ),
03202 -1
03203 );
03204 }
03205
03206
03207
03208
03209
03210
03211
03212 this->ir_current_ =
03213 CORBA::IDLType::_duplicate (new_def.in ());
03214
03215 CORBA::Container_ptr used_scope =
03216 CORBA::Container::_nil ();
03217
03218
03219 if (be_global->ifr_scopes ().pop (used_scope) != 0)
03220 {
03221 ACE_ERROR_RETURN ((
03222 LM_ERROR,
03223 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03224 ACE_TEXT ("create_event_def -")
03225 ACE_TEXT (" scope pop failed\n")
03226 ),
03227 -1
03228 );
03229 }
03230 }
03231 else
03232 {
03233 ACE_ERROR_RETURN ((
03234 LM_ERROR,
03235 ACE_TEXT ("(%N:%l) ifr_adding_visitor::create_event_def -")
03236 ACE_TEXT (" scope stack is empty\n")
03237 ),
03238 -1
03239 );
03240 }
03241
03242 return 0;
03243 }
03244
03245 int
03246 ifr_adding_visitor::create_value_member (AST_Field *node)
03247 {
03248 try
03249 {
03250 AST_Type *bt = node->field_type ();
03251 AST_Decl::NodeType nt = bt->node_type ();
03252
03253
03254
03255 if (nt == AST_Decl::NT_pre_defined
03256 || nt == AST_Decl::NT_string
03257 || nt == AST_Decl::NT_wstring
03258 || nt == AST_Decl::NT_array
03259 || nt == AST_Decl::NT_sequence)
03260 {
03261
03262 if (bt->ast_accept (this) != 0)
03263 {
03264 ACE_ERROR_RETURN ((
03265 LM_ERROR,
03266 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03267 ACE_TEXT ("create_value_member -")
03268 ACE_TEXT (" visit base type failed\n")
03269 ),
03270 -1
03271 );
03272 }
03273 }
03274 else
03275 {
03276
03277 CORBA::Contained_var holder =
03278 be_global->repository ()->lookup_id (bt->repoID ());
03279
03280 this->ir_current_ =
03281 CORBA::IDLType::_narrow (holder.in ());
03282 }
03283
03284 CORBA::Visibility vis = CORBA::PUBLIC_MEMBER;
03285
03286 switch (node->visibility ())
03287 {
03288 case AST_Field::vis_PUBLIC:
03289 break;
03290 case AST_Field::vis_PRIVATE:
03291 vis = CORBA::PRIVATE_MEMBER;
03292 break;
03293 default:
03294 ACE_ERROR_RETURN ((
03295 LM_ERROR,
03296 ACE_TEXT ("(%N:%l) ifr_adding_visitor::create_value_member -")
03297 ACE_TEXT (" bad visibility value in node\n")
03298 ),
03299 -1
03300 );
03301 };
03302
03303 CORBA::Container_ptr current_scope = CORBA::Container::_nil ();
03304
03305 if (be_global->ifr_scopes ().top (current_scope) != 0)
03306 {
03307 ACE_ERROR_RETURN ((
03308 LM_ERROR,
03309 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03310 ACE_TEXT ("create_value_member -")
03311 ACE_TEXT (" scope stack empty\n")
03312 ),
03313 -1
03314 );
03315 }
03316
03317 CORBA::ValueDef_var vt =
03318 CORBA::ValueDef::_narrow (current_scope);
03319
03320 CORBA::ValueMemberDef_var vm =
03321 vt->create_value_member (node->repoID (),
03322 node->local_name ()->get_string (),
03323 node->version (),
03324 this->ir_current_.in (),
03325 vis);
03326 }
03327 catch (const CORBA::Exception& ex)
03328 {
03329 ex._tao_print_exception (ACE_TEXT ("create_value_member"));
03330
03331 return -1;
03332 }
03333
03334 return 0;
03335 }
03336
03337 void
03338 ifr_adding_visitor::get_referenced_type (AST_Type *node)
03339 {
03340 switch (node->node_type ())
03341 {
03342
03343
03344
03345 case AST_Decl::NT_pre_defined:
03346 case AST_Decl::NT_string:
03347 case AST_Decl::NT_wstring:
03348 case AST_Decl::NT_array:
03349 case AST_Decl::NT_sequence:
03350 if (node->ast_accept (this) == -1)
03351 {
03352 ACE_ERROR ((
03353 LM_ERROR,
03354 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03355 ACE_TEXT ("get_scope_member -")
03356 ACE_TEXT (" failed to accept visitor\n")
03357 ));
03358 }
03359
03360 break;
03361
03362
03363 default:
03364 {
03365 CORBA::Contained_var prev_def =
03366 be_global->repository ()->lookup_id (node->repoID ());
03367
03368 this->ir_current_ =
03369 CORBA::IDLType::_narrow (prev_def.in ());
03370 break;
03371 }
03372 }
03373 }
03374
03375 void
03376 ifr_adding_visitor::fill_base_value (CORBA::ValueDef_ptr &result,
03377 AST_ValueType *node)
03378 {
03379 result = CORBA::ValueDef::_nil ();
03380 AST_ValueType *base_value = node->inherits_concrete ();
03381
03382 if (base_value == 0)
03383 {
03384 return;
03385 }
03386
03387 CORBA::Contained_var holder =
03388 be_global->repository ()->lookup_id (
03389 base_value->repoID ()
03390 );
03391
03392 if (!CORBA::is_nil (holder.in ()))
03393 {
03394 result =
03395 CORBA::ValueDef::_narrow (holder.in ());
03396 }
03397 }
03398
03399 void
03400 ifr_adding_visitor::fill_base_component (
03401 CORBA::ComponentIR::ComponentDef_ptr &result,
03402 AST_Component *node
03403 )
03404 {
03405 result = CORBA::ComponentIR::ComponentDef::_nil ();
03406 AST_Component *base_component = node->base_component ();
03407
03408 if (base_component == 0)
03409 {
03410 return;
03411 }
03412
03413 CORBA::Contained_var holder =
03414 be_global->repository ()->lookup_id (
03415 base_component->repoID ()
03416 );
03417
03418 if (!CORBA::is_nil (holder.in ()))
03419 {
03420 result =
03421 CORBA::ComponentIR::ComponentDef::_narrow (holder.in ());
03422 }
03423 }
03424
03425 void
03426 ifr_adding_visitor::fill_base_home (CORBA::ComponentIR::HomeDef_ptr &result,
03427 AST_Home *node)
03428 {
03429 result = CORBA::ComponentIR::HomeDef::_nil ();
03430 AST_Home *base_home = node->base_home ();
03431
03432 if (base_home == 0)
03433 {
03434 return;
03435 }
03436
03437 CORBA::Contained_var holder =
03438 be_global->repository ()->lookup_id (
03439 base_home->repoID ()
03440 );
03441
03442 if (!CORBA::is_nil (holder.in ()))
03443 {
03444 result =
03445 CORBA::ComponentIR::HomeDef::_narrow (holder.in ());
03446 }
03447 else
03448 {
03449
03450
03451 (void) base_home->ast_accept (this);
03452 this->fill_base_home (result,
03453 node);
03454 }
03455 }
03456
03457 void
03458 ifr_adding_visitor::fill_managed_component (
03459 CORBA::ComponentIR::ComponentDef_ptr &result,
03460 AST_Home *node
03461 )
03462 {
03463 result = CORBA::ComponentIR::ComponentDef::_nil ();
03464 AST_Component *managed_component = node->managed_component ();
03465
03466 if (managed_component == 0)
03467 {
03468 return;
03469 }
03470
03471 CORBA::Contained_var holder =
03472 be_global->repository ()->lookup_id (managed_component->repoID ());
03473
03474 if (!CORBA::is_nil (holder.in ()))
03475 {
03476 result =
03477 CORBA::ComponentIR::ComponentDef::_narrow (holder.in ());
03478 }
03479 else
03480 {
03481
03482
03483 (void) managed_component->ast_accept (this);
03484 this->fill_managed_component (result,
03485 node);
03486 }
03487 }
03488
03489 void
03490 ifr_adding_visitor::fill_primary_key (CORBA::ValueDef_ptr &result,
03491 AST_Home *node)
03492 {
03493 result = CORBA::ValueDef::_nil ();
03494 AST_ValueType *primary_key = node->primary_key ();
03495
03496 if (primary_key == 0)
03497 {
03498 return;
03499 }
03500
03501 CORBA::Contained_var holder =
03502 be_global->repository ()->lookup_id (primary_key->repoID ());
03503
03504 if (!CORBA::is_nil (holder.in ()))
03505 {
03506 result =
03507 CORBA::ValueDef::_narrow (holder.in ());
03508 }
03509 else
03510 {
03511
03512
03513 (void) primary_key->ast_accept (this);
03514 this->fill_primary_key (result,
03515 node);
03516 }
03517 }
03518
03519 void
03520 ifr_adding_visitor::fill_abstract_base_values (CORBA::ValueDefSeq &result,
03521 AST_ValueType *node)
03522 {
03523 CORBA::Long s_length = node->n_inherits ();
03524 result.length (0);
03525
03526
03527
03528
03529 if (s_length > 0)
03530 {
03531 AST_Interface **list = node->inherits ();
03532 CORBA::ULong u_length = static_cast<CORBA::ULong> (s_length);
03533 bool first_abs = list[0]->is_abstract ();
03534 result.length (first_abs ? u_length : u_length - 1);
03535
03536 for (CORBA::ULong i = 0; i < u_length; ++i)
03537 {
03538 if (i == 0 && ! first_abs)
03539 {
03540 continue;
03541 }
03542
03543
03544 (void) list[i]->ast_accept (this);
03545
03546 result[first_abs ? i : i - 1] =
03547 CORBA::ValueDef::_narrow (this->ir_current_.in ());
03548 }
03549 }
03550 }
03551
03552 void
03553 ifr_adding_visitor::fill_inherited_interfaces (CORBA::InterfaceDefSeq &result,
03554 AST_Interface *node)
03555 {
03556 result.length (0);
03557 this->fill_interfaces (result,
03558 node->inherits (),
03559 node->n_inherits ());
03560 }
03561
03562 void
03563 ifr_adding_visitor::fill_supported_interfaces (CORBA::InterfaceDefSeq &result,
03564 AST_Interface *node)
03565 {
03566 result.length (0);
03567 CORBA::Long s_length = 0;
03568 AST_Interface **list = 0;
03569
03570 switch (node->node_type ())
03571 {
03572 case AST_Decl::NT_valuetype:
03573 case AST_Decl::NT_eventtype:
03574 {
03575 AST_ValueType *v = AST_ValueType::narrow_from_decl (node);
03576 s_length = v->n_supports ();
03577 list = v->supports ();
03578 break;
03579 }
03580 case AST_Decl::NT_component:
03581 {
03582 AST_Component *c = AST_Component::narrow_from_decl (node);
03583 s_length = c->n_supports ();
03584 list = c->supports ();
03585 break;
03586 }
03587 case AST_Decl::NT_home:
03588 {
03589 AST_Home *h = AST_Home::narrow_from_decl (node);
03590 s_length = h->n_supports ();
03591 list = h->supports ();
03592 break;
03593 }
03594 default:
03595 return;
03596 }
03597
03598 this->fill_interfaces (result,
03599 list,
03600 s_length);
03601 }
03602
03603 void
03604 ifr_adding_visitor::fill_interfaces (CORBA::InterfaceDefSeq &result,
03605 AST_Interface **list,
03606 CORBA::Long length)
03607 {
03608
03609
03610
03611 if (length > 0)
03612 {
03613 CORBA::ULong u_length = static_cast<CORBA::ULong> (length);
03614 result.length (u_length);
03615
03616 for (CORBA::ULong i = 0; i < u_length; ++i)
03617 {
03618
03619 (void) list[i]->ast_accept (this);
03620
03621 result[i] =
03622 CORBA::InterfaceDef::_narrow (this->ir_current_.in ());
03623 }
03624 }
03625 }
03626
03627 void
03628 ifr_adding_visitor::fill_initializers (CORBA::ExtInitializerSeq &result,
03629 AST_ValueType *node)
03630 {
03631 result.length (0);
03632 AST_Decl *item = 0;
03633 ACE_Vector<AST_Factory *> factories;
03634
03635 for (UTL_ScopeActiveIterator v_iter (node,
03636 UTL_Scope::IK_decls);
03637 !v_iter.is_done ();
03638 v_iter.next ())
03639 {
03640 item = v_iter.item ();
03641
03642 if (item->node_type () == AST_Decl::NT_factory)
03643 {
03644 factories.push_back (AST_Factory::narrow_from_decl (item));
03645 }
03646 }
03647
03648 CORBA::ULong n_factories = factories.size ();
03649
03650 if (n_factories == 0)
03651 {
03652 return;
03653 }
03654
03655 result.length (n_factories);
03656 CORBA::ULong n_args = 0;
03657 AST_Argument *arg = 0;
03658 CORBA::ULong index = 0;
03659 AST_Exception *excp = 0;
03660 CORBA::Contained_var holder;
03661
03662 for (CORBA::ULong i = 0; i < n_factories; ++i)
03663 {
03664 result[i].name =
03665 CORBA::string_dup (factories[i]->local_name ()->get_string ());
03666 n_args = static_cast<CORBA::ULong> (factories[i]->argument_count ());
03667 result[i].members.length (n_args);
03668
03669
03670 for (UTL_ScopeActiveIterator f_iter (factories[i],
03671 UTL_Scope::IK_decls);
03672 !f_iter.is_done ();
03673 f_iter.next (), ++index)
03674 {
03675 arg = AST_Argument::narrow_from_decl (f_iter.item ());
03676 result[i].members[index].name =
03677 CORBA::string_dup (arg->local_name ()->get_string ());
03678 result[i].members[index].type =
03679 CORBA::TypeCode::_duplicate (CORBA::_tc_void);
03680
03681
03682
03683 if (arg->field_type ()->ast_accept (this) != 0)
03684 {
03685 ACE_ERROR ((
03686 LM_ERROR,
03687 ACE_TEXT ("(%N:%l) ifr_adding_visitor::")
03688 ACE_TEXT ("fill_initializers -")
03689 ACE_TEXT (" failed to accept arg type visitor\n")
03690 ));
03691 }
03692
03693 result[i].members[index].type_def =
03694 CORBA::IDLType::_duplicate (this->ir_current_.in ());
03695 }
03696
03697 CORBA::ULong n_exceptions =
03698 static_cast<CORBA::ULong> (factories[i]->n_exceptions ());
03699 result[i].exceptions.length (n_exceptions);
03700 index = 0;
03701
03702 for (UTL_ExceptlistActiveIterator ei (factories[i]->exceptions ());
03703 !ei.is_done ();
03704 ei.next ())
03705 {
03706 excp = AST_Exception::narrow_from_decl (ei.item ());
03707 result[i].exceptions[index].name =
03708 CORBA::string_dup (excp->local_name ()->get_string ());
03709 result[i].exceptions[index].id = excp->repoID ();
03710 result[i].exceptions[index].defined_in =
03711 ScopeAsDecl (excp->defined_in ())->repoID ();
03712 result[i].exceptions[index].version = excp->version ();
03713 result[i].exceptions[index++].type =
03714 CORBA::TypeCode::_duplicate (CORBA::_tc_void);
03715 }
03716 }
03717 }
03718
03719 void
03720 ifr_adding_visitor::fill_get_exceptions (CORBA::ExceptionDefSeq &result,
03721 AST_Attribute *node)
03722 {
03723 this->fill_exceptions (result,
03724 node->get_get_exceptions ());
03725 }
03726
03727 void
03728 ifr_adding_visitor::fill_set_exceptions (CORBA::ExceptionDefSeq &result,
03729 AST_Attribute *node)
03730 {
03731 this->fill_exceptions (result,
03732 node->get_set_exceptions ());
03733 }
03734
03735 void
03736 ifr_adding_visitor::fill_exceptions (CORBA::ExceptionDefSeq &result,
03737 AST_Decl *node)
03738 {
03739 switch (node->node_type ())
03740 {
03741 case AST_Decl::NT_op:
03742 {
03743 AST_Operation *op = AST_Operation::narrow_from_decl (node);
03744 this->fill_exceptions (result,
03745 op->exceptions ());
03746 return;
03747 }
03748 case AST_Decl::NT_factory:
03749 {
03750 AST_Factory *f = AST_Factory::narrow_from_decl (node);
03751 this->fill_exceptions (result,
03752 f->exceptions ());
03753 return;
03754 }
03755 default:
03756 result.length (0);
03757 return;
03758 }
03759 }
03760
03761 void
03762 ifr_adding_visitor::fill_exceptions (CORBA::ExceptionDefSeq &result,
03763 UTL_ExceptList *list)
03764 {
03765 if (list == 0)
03766 {
03767 result.length (0);
03768 return;
03769 }
03770
03771 result.length (static_cast<CORBA::ULong> (list->length ()));
03772 CORBA::ULong index = 0;
03773 AST_Decl *d = 0;
03774 CORBA::Contained_var holder;
03775
03776 for (UTL_ExceptlistActiveIterator ei (list);
03777 !ei.is_done ();
03778 ei.next (), ++index)
03779 {
03780 d = ei.item ();
03781
03782
03783
03784
03785 (void) d->ast_accept (this);
03786
03787 holder = be_global->repository ()->lookup_id (d->repoID ());
03788
03789 result[index] =
03790 CORBA::ExceptionDef::_narrow (holder.in ());
03791 }
03792 }
03793
03794 void
03795 ifr_adding_visitor::fill_params (CORBA::ParDescriptionSeq &result,
03796 AST_Operation *node)
03797 {
03798 AST_Argument *arg = 0;
03799 CORBA::ULong n_args = static_cast<CORBA::ULong> (node->argument_count ());
03800 result.length (n_args);
03801 CORBA::ULong index = 0;
03802 CORBA::Contained_var holder;
03803
03804 for (UTL_ScopeActiveIterator iter (node,
03805 UTL_Scope::IK_decls);
03806 ! iter.is_done ();
03807 iter.next (), ++index)
03808 {
03809 arg = AST_Argument::narrow_from_decl (iter.item ());
03810 result[index].name =
03811 CORBA::string_dup (arg->local_name ()->get_string ());
03812 result[index].type = CORBA::TypeCode::_duplicate (CORBA::_tc_void);
03813
03814
03815 (void) arg->ast_accept (this);
03816
03817 result[index].type_def =
03818 CORBA::IDLType::_duplicate (this->ir_current_.in ());
03819
03820 result[index].mode = CORBA::PARAM_IN;
03821 }
03822 }
03823
03824 void
03825 ifr_adding_visitor::visit_all_provides (AST_Component *node,
03826 CORBA::ComponentIR::ComponentDef_ptr c)
03827 {
03828 AST_Component::port_description *tmp = 0;
03829 CORBA::Contained_var contained;
03830 CORBA::InterfaceDef_var interface_type;
03831 CORBA::ComponentIR::ProvidesDef_var new_def;
03832 char *local_name = 0;
03833
03834 for (ACE_Unbounded_Queue_Iterator<AST_Component::port_description> i (
03835 node->provides ()
03836 );
03837 ! i.done ();
03838 i.advance ())
03839 {
03840 i.next (tmp);
03841 contained = be_global->repository ()->lookup_id (tmp->impl->repoID ());
03842
03843 interface_type = CORBA::InterfaceDef::_narrow (contained.in ());
03844
03845 ACE_CString str (node->repoID ());
03846 local_name = tmp->id->get_string ();
03847 this->expand_id (str, local_name);
03848 new_def = c->create_provides (str.fast_rep (),
03849 local_name,
03850 tmp->impl->version (),
03851 interface_type.in ());
03852 }
03853 }
03854
03855 void
03856 ifr_adding_visitor::visit_all_uses (AST_Component *node,
03857 CORBA::ComponentIR::ComponentDef_ptr c)
03858 {
03859 AST_Component::port_description *tmp = 0;
03860 CORBA::Contained_var contained;
03861 CORBA::InterfaceDef_var interface_type;
03862 CORBA::ComponentIR::UsesDef_var new_def;
03863 char *local_name = 0;
03864
03865 for (ACE_Unbounded_Queue_Iterator<AST_Component::port_description> i (
03866 node->uses ()
03867 );
03868 ! i.done ();
03869 i.advance ())
03870 {
03871 i.next (tmp);
03872 contained = be_global->repository ()->lookup_id (tmp->impl->repoID ());
03873
03874 interface_type = CORBA::InterfaceDef::_narrow (contained.in ());
03875
03876 ACE_CString str (node->repoID ());
03877 local_name = tmp->id->get_string ();
03878 this->expand_id (str, local_name);
03879 new_def = c->create_uses (str.fast_rep (),
03880 local_name,
03881 tmp->impl->version (),
03882 interface_type.in (),
03883 static_cast<CORBA::Boolean> (tmp->is_multiple));
03884 }
03885 }
03886
03887 void
03888 ifr_adding_visitor::visit_all_emits (AST_Component *node,
03889 CORBA::ComponentIR::ComponentDef_ptr c)
03890 {
03891 AST_Component::port_description *tmp = 0;
03892 CORBA::Contained_var contained;
03893 CORBA::ComponentIR::EventDef_var event_type;
03894 CORBA::ComponentIR::EmitsDef_var new_def;
03895 char *local_name = 0;
03896
03897 for (ACE_Unbounded_Queue_Iterator<AST_Component::port_description> i (
03898 node->emits ()
03899 );
03900 ! i.done ();
03901 i.advance ())
03902 {
03903 i.next (tmp);
03904 contained = be_global->repository ()->lookup_id (tmp->impl->repoID ());
03905
03906 event_type =
03907 CORBA::ComponentIR::EventDef::_narrow (contained.in ());
03908
03909 ACE_CString str (node->repoID ());
03910 local_name = tmp->id->get_string ();
03911 this->expand_id (str, local_name);
03912 new_def = c->create_emits (str.fast_rep (),
03913 local_name,
03914 tmp->impl->version (),
03915 event_type.in ());
03916 }
03917 }
03918
03919 void
03920 ifr_adding_visitor::visit_all_publishes (AST_Component *node,
03921 CORBA::ComponentIR::ComponentDef_ptr c)
03922 {
03923 AST_Component::port_description *tmp = 0;
03924 CORBA::Contained_var contained;
03925 CORBA::ComponentIR::EventDef_var event_type;
03926 CORBA::ComponentIR::PublishesDef_var new_def;
03927 char *local_name = 0;
03928
03929 for (ACE_Unbounded_Queue_Iterator<AST_Component::port_description> i (
03930 node->publishes ()
03931 );
03932 ! i.done ();
03933 i.advance ())
03934 {
03935 i.next (tmp);
03936 contained = be_global->repository ()->lookup_id (tmp->impl->repoID ());
03937
03938 event_type =
03939 CORBA::ComponentIR::EventDef::_narrow (contained.in ());
03940
03941 ACE_CString str (node->repoID ());
03942 local_name = tmp->id->get_string ();
03943 this->expand_id (str, local_name);
03944 new_def = c->create_publishes (str.fast_rep (),
03945 local_name,
03946 tmp->impl->version (),
03947 event_type.in ());
03948 }
03949 }
03950
03951 void
03952 ifr_adding_visitor::visit_all_consumes (AST_Component *node,
03953 CORBA::ComponentIR::ComponentDef_ptr c)
03954 {
03955 AST_Component::port_description *tmp = 0;
03956 CORBA::Contained_var contained;
03957 CORBA::ComponentIR::EventDef_var event_type;
03958 CORBA::ComponentIR::ConsumesDef_var new_def;
03959 char *local_name = 0;
03960
03961 for (ACE_Unbounded_Queue_Iterator<AST_Component::port_description> i (
03962 node->consumes ()
03963 );
03964 ! i.done ();
03965 i.advance ())
03966 {
03967 i.next (tmp);
03968 contained = be_global->repository ()->lookup_id (tmp->impl->repoID ());
03969
03970 event_type =
03971 CORBA::ComponentIR::EventDef::_narrow (contained.in ());
03972
03973 ACE_CString str (node->repoID ());
03974 local_name = tmp->id->get_string ();
03975 this->expand_id (str, local_name);
03976 new_def = c->create_consumes (str.fast_rep (),
03977 local_name,
03978 tmp->impl->version (),
03979 event_type.in ());
03980 }
03981 }
03982
03983 void
03984 ifr_adding_visitor::visit_all_factories (AST_Home *node,
03985 CORBA::ComponentIR::HomeDef_ptr h)
03986 {
03987 AST_Operation **tmp = 0;
03988 CORBA::Contained_var contained;
03989 CORBA::ComponentIR::FactoryDef_var new_def;
03990
03991 for (ACE_Unbounded_Queue_Iterator<AST_Operation *> i (node->factories ());
03992 ! i.done ();
03993 i.advance ())
03994 {
03995 i.next (tmp);
03996 CORBA::ParDescriptionSeq params;
03997 this->fill_params (params,
03998 *tmp);
03999
04000 CORBA::ExceptionDefSeq exceptions;
04001 this->fill_exceptions (exceptions,
04002 *tmp);
04003
04004 new_def = h->create_factory ((*tmp)->repoID (),
04005 (*tmp)->local_name ()->get_string (),
04006 (*tmp)->version (),
04007 params,
04008 exceptions);
04009 }
04010 }
04011
04012 void
04013 ifr_adding_visitor::visit_all_finders (AST_Home *node,
04014 CORBA::ComponentIR::HomeDef_ptr h)
04015 {
04016 AST_Operation **tmp = 0;
04017 CORBA::Contained_var contained;
04018 CORBA::ComponentIR::FinderDef_var new_def;
04019
04020 for (ACE_Unbounded_Queue_Iterator<AST_Operation *> i (node->finders ());
04021 ! i.done ();
04022 i.advance ())
04023 {
04024 i.next (tmp);
04025 CORBA::ParDescriptionSeq params;
04026 this->fill_params (params,
04027 *tmp);
04028
04029 CORBA::ExceptionDefSeq exceptions;
04030 this->fill_exceptions (exceptions,
04031 *tmp);
04032
04033 new_def = h->create_finder ((*tmp)->repoID (),
04034 (*tmp)->local_name ()->get_string (),
04035 (*tmp)->version (),
04036 params,
04037 exceptions);
04038 }
04039 }
04040
04041 void
04042 ifr_adding_visitor::expand_id (ACE_CString &str,
04043 const char *local_name)
04044 {
04045 ssize_t pos = str.rfind (':');
04046 str = str.substr (0, pos) + '/' + local_name + str.substr (pos);
04047 }