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