Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / IFR_Service / ifr_removing_visitor.cpp
blob8c9c04bb1e887fc870d24a8c52f10987de941f47
1 /* -*- c++ -*- */
2 #include "orbsvcs/Log_Macros.h"
3 #include "ifr_removing_visitor.h"
4 #include "utl_scope.h"
5 #include "ast_root.h"
7 ifr_removing_visitor::ifr_removing_visitor (void)
11 ifr_removing_visitor::~ifr_removing_visitor (void)
15 int
16 ifr_removing_visitor::visit_scope (UTL_Scope *node)
18 // Proceed if the number of members in our scope is greater than 0.
19 if (node->nmembers () > 0)
21 // Initialize an iterator to iterate over our scope.
22 UTL_ScopeActiveIterator si (node,
23 UTL_Scope::IK_decls);
25 AST_Decl *d = 0;
27 try
29 // Continue until each element is visited.
30 while (!si.is_done ())
32 d = si.item ();
34 if (d == 0)
36 ORBSVCS_ERROR_RETURN ((
37 LM_ERROR,
38 ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_scope -")
39 ACE_TEXT (" bad node in this scope\n")
45 if (d->node_type () == AST_Decl::NT_pre_defined)
47 // We can skip these - they don't get destroyed in the IfR.
48 si.next ();
49 continue;
52 CORBA::Contained_var top_level =
53 be_global->repository ()->lookup_id (d->repoID ());
55 if (!CORBA::is_nil (top_level.in ()))
57 // All we have to do is call destroy() on each IR object
58 // in the global scope, because destroy() works on all
59 // the contents recursively.
60 top_level->destroy ();
63 si.next ();
66 catch (const CORBA::Exception& ex)
68 ex._tao_print_exception (
69 ACE_TEXT (
70 "ifr_removing_visitor::visit_scope"));
72 return -1;
76 return 0;
79 int
80 ifr_removing_visitor::visit_root (AST_Root *node)
82 try
84 CORBA::Container_var new_scope =
85 CORBA::Container::_narrow (be_global->repository ());
87 if (be_global->ifr_scopes ().push (new_scope.in ()) != 0)
89 ORBSVCS_ERROR_RETURN ((
90 LM_ERROR,
91 ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_root -")
92 ACE_TEXT (" scope push failed\n")
98 if (this->visit_scope (node) == -1)
100 ORBSVCS_ERROR_RETURN ((
101 LM_ERROR,
102 ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_root -")
103 ACE_TEXT (" visit_scope failed\n")
109 CORBA::Container_ptr tmp = CORBA::Container::_nil ();
111 if (be_global->ifr_scopes ().pop (tmp) != 0)
113 ORBSVCS_ERROR_RETURN ((
114 LM_ERROR,
115 ACE_TEXT ("(%N:%l) ifr_removing_visitor::visit_root -")
116 ACE_TEXT (" scope pop failed\n")
122 catch (const CORBA::Exception& ex)
124 ex._tao_print_exception (ACE_TEXT ("visit_root"));
126 return -1;
129 return 0;