ifr_removing_visitor.cpp

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 // $Id: ifr_removing_visitor.cpp 76589 2007-01-25 18:04:11Z elliott_c $
00003 
00004 #include "ifr_removing_visitor.h"
00005 #include "utl_scope.h"
00006 #include "ast_root.h"
00007 
00008 ACE_RCSID (IFR_Service,
00009            ifr_removing_visitor,
00010            "$Id: ifr_removing_visitor.cpp 76589 2007-01-25 18:04:11Z elliott_c $")
00011 
00012 ifr_removing_visitor::ifr_removing_visitor (void)
00013 {
00014 }
00015 
00016 ifr_removing_visitor::~ifr_removing_visitor (void)
00017 {
00018 }
00019 
00020 int
00021 ifr_removing_visitor::visit_scope (UTL_Scope *node)
00022 {
00023   // Proceed if the number of members in our scope is greater than 0.
00024   if (node->nmembers () > 0)
00025     {
00026       // Initialize an iterator to iterate over our scope.
00027       UTL_ScopeActiveIterator si (node,
00028                                   UTL_Scope::IK_decls);
00029 
00030       AST_Decl *d = 0;
00031 
00032       try
00033         {
00034           // Continue until each element is visited.
00035           while (!si.is_done ())
00036             {
00037               d = si.item ();
00038 
00039               if (d == 0)
00040                 {
00041                   ACE_ERROR_RETURN ((
00042                       LM_ERROR,
00043                       ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_scope -")
00044                       ACE_TEXT (" bad node in this scope\n")
00045                     ),
00046                     -1
00047                   );
00048                 }
00049 
00050               if (d->node_type () == AST_Decl::NT_pre_defined)
00051                 {
00052                   // We can skip these - they don't get destroyed in the IfR.
00053                   si.next ();
00054                   continue;
00055                 }
00056 
00057               CORBA::Contained_var top_level =
00058                 be_global->repository ()->lookup_id (d->repoID ());
00059 
00060               if (!CORBA::is_nil (top_level.in ()))
00061                 {
00062                   // All we have to do is call destroy() on each IR object
00063                   // in the global scope, because destroy() works on all
00064                   // the contents recursively.
00065                   top_level->destroy ();
00066                 }
00067 
00068               si.next ();
00069             }
00070         }
00071       catch (const CORBA::Exception& ex)
00072         {
00073           ex._tao_print_exception (
00074             ACE_TEXT (
00075               "ifr_removing_visitor::visit_scope"));
00076 
00077           return -1;
00078         }
00079     }
00080 
00081   return 0;
00082 }
00083 
00084 int
00085 ifr_removing_visitor::visit_root (AST_Root *node)
00086 {
00087   try
00088     {
00089       CORBA::Container_var new_scope =
00090         CORBA::Container::_narrow (be_global->repository ());
00091 
00092       if (be_global->ifr_scopes ().push (new_scope.in ()) != 0)
00093         {
00094           ACE_ERROR_RETURN ((
00095               LM_ERROR,
00096               ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_root -")
00097               ACE_TEXT (" scope push failed\n")
00098             ),
00099             -1
00100           );
00101         }
00102 
00103       if (this->visit_scope (node) == -1)
00104         {
00105           ACE_ERROR_RETURN ((
00106               LM_ERROR,
00107               ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_root -")
00108               ACE_TEXT (" visit_scope failed\n")
00109             ),
00110             -1
00111           );
00112         }
00113 
00114       CORBA::Container_ptr tmp = CORBA::Container::_nil ();
00115 
00116       if (be_global->ifr_scopes ().pop (tmp) != 0)
00117         {
00118           ACE_ERROR_RETURN ((
00119               LM_ERROR,
00120               ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_root -")
00121               ACE_TEXT (" scope pop failed\n")
00122             ),
00123             -1
00124           );
00125         }
00126     }
00127   catch (const CORBA::Exception& ex)
00128     {
00129       ex._tao_print_exception (ACE_TEXT ("visit_root"));
00130 
00131       return -1;
00132     }
00133 
00134   return 0;
00135 }
00136 

Generated on Tue Feb 2 17:50:49 2010 for TAO_IFR by  doxygen 1.4.7