2 #include "orbsvcs/Log_Macros.h"
4 #include "ast_exception.h"
5 #include "ast_expression.h"
8 #include "utl_identifier.h"
10 #include "ifr_adding_visitor_exception.h"
11 #include "ifr_adding_visitor_structure.h"
12 #include "ifr_adding_visitor_union.h"
14 ifr_adding_visitor_exception::ifr_adding_visitor_exception (
18 : ifr_adding_visitor (scope
,
23 ifr_adding_visitor_exception::~ifr_adding_visitor_exception ()
27 // Specialized visit_scope method for exceptions only.
29 ifr_adding_visitor_exception::visit_scope (UTL_Scope
*node
)
31 // If the exception has members that are scopes but not exceptions,
32 // the regular visit_scope method should be called instead.
33 if (node
->scope_node_type () != AST_Decl::NT_except
)
35 return ifr_adding_visitor::visit_scope (node
);
38 AST_Exception
*e
= dynamic_cast<AST_Exception
*> (node
);
40 CORBA::ULong
const nfields
= static_cast<CORBA::ULong
> (e
->nfields ());
42 this->members_
.length (nfields
);
49 for (CORBA::ULong i
= 0; i
< nfields
; ++i
)
51 if (e
->field (f
, i
) != 0)
53 ORBSVCS_ERROR_RETURN ((
55 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
56 ACE_TEXT ("visit_scope -")
57 ACE_TEXT (" field node access failed\n")
63 AST_Type
*ft
= (*f
)->field_type ();
65 bool defined_here
= ft
->is_child (this->scope_
);
67 // If the struct member is defined in the struct, we have to
68 // do some visiting - otherwise we can just look up the entry.
71 if (ft
->ast_accept (this) == -1)
73 ORBSVCS_ERROR_RETURN ((
75 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
76 ACE_TEXT ("visit_scope -")
77 ACE_TEXT (" failed to accept visitor\n")
85 // Updates ir_current_.
86 this->get_referenced_type (ft
);
89 this->members_
[i
].name
=
90 CORBA::string_dup ((*f
)->local_name ()->get_string ());
92 // IfR method create_exception does not use this - it just needs
93 // to be non-zero for marshaling.
94 this->members_
[i
].type
=
95 CORBA::TypeCode::_duplicate (CORBA::_tc_void
);
97 this->members_
[i
].type_def
=
98 CORBA::IDLType::_duplicate (this->ir_current_
.in ());
101 catch (const CORBA::Exception
& ex
)
103 ex
._tao_print_exception (
105 "ifr_adding_visitor_structure::visit_scope"));
114 ifr_adding_visitor_exception::visit_structure (AST_Structure
*node
)
118 // Is this union already in the respository?
119 CORBA::Contained_var prev_def
=
120 be_global
->repository ()->lookup_id (node
->repoID ());
122 // If not, create a new entry.
123 if (CORBA::is_nil (prev_def
.in ()))
125 ifr_adding_visitor_structure
visitor (node
);
126 int retval
= visitor
.visit_structure (node
);
130 // Get the result of the visit.
132 CORBA::IDLType::_duplicate (visitor
.ir_current ());
139 // If the line below is true, we are clobbering a previous
140 // entry (from another IDL file) of another type. In that
141 // case we do what other ORB vendors do, and destroy the
142 // original entry, create the new one, and let the user beware.
143 if (!node
->ifr_added ())
145 prev_def
->destroy ();
147 // This call will take the other branch.
148 return this->visit_structure (node
);
152 CORBA::IDLType::_narrow (prev_def
.in ());
155 catch (const CORBA::Exception
& ex
)
157 ex
._tao_print_exception (
159 "ifr_adding_visitor_exception::visit_structure"));
168 ifr_adding_visitor_exception::visit_exception (AST_Exception
*node
)
172 CORBA::ExceptionDef_var new_def
;
173 CORBA::Contained_var prev_def
=
174 be_global
->repository ()->lookup_id (node
->repoID ());
176 if (CORBA::is_nil (prev_def
.in ()))
178 CORBA::StructMemberSeq dummyMembers
;
179 dummyMembers
.length (0);
180 CORBA::Container_ptr current_scope
=
181 CORBA::Container::_nil ();
183 if (be_global
->ifr_scopes ().top (current_scope
) != 0)
185 ORBSVCS_ERROR_RETURN ((
187 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
188 ACE_TEXT ("visit_exception -")
189 ACE_TEXT (" scope stack is empty\n")
196 current_scope
->create_exception (node
->repoID (),
197 node
->local_name ()->get_string (),
201 if (be_global
->ifr_scopes ().push (new_def
.in ()) != 0)
203 ORBSVCS_ERROR_RETURN ((
205 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
206 ACE_TEXT ("visit_exception -")
207 ACE_TEXT (" scope push failed\n")
213 // Then add the real exception members.
214 if (this->add_members (node
, new_def
.in ()) == -1)
216 ORBSVCS_ERROR_RETURN ((
218 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
219 ACE_TEXT ("visit_exception -")
220 ACE_TEXT (" visit_scope failed\n")),
224 CORBA::Container_ptr used_scope
=
225 CORBA::Container::_nil ();
227 // Pop the new IR object back off the scope stack.
228 if (be_global
->ifr_scopes ().pop (used_scope
) != 0)
230 ORBSVCS_ERROR_RETURN ((
232 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
233 ACE_TEXT ("visit_exception -")
234 ACE_TEXT (" scope pop failed\n")
242 new_def
= CORBA::ExceptionDef::_narrow (prev_def
.in ());
244 if (be_global
->ifr_scopes ().push (new_def
.in ()) != 0)
246 ORBSVCS_ERROR_RETURN ((
248 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
249 ACE_TEXT ("visit_exception -")
250 ACE_TEXT (" scope push failed\n")
256 // Then add the real exception members.
257 if (this->add_members (node
, new_def
.in ()) == -1)
259 ORBSVCS_ERROR_RETURN ((
261 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
262 ACE_TEXT ("visit_exception -")
263 ACE_TEXT (" visit_scope failed\n")),
267 CORBA::Container_ptr used_scope
=
268 CORBA::Container::_nil ();
270 // Pop the new IR object back off the scope stack.
271 if (be_global
->ifr_scopes ().pop (used_scope
) != 0)
273 ORBSVCS_ERROR_RETURN ((
275 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
276 ACE_TEXT ("visit_exception -")
277 ACE_TEXT (" scope pop failed\n")
284 catch (const CORBA::Exception
& ex
)
286 ex
._tao_print_exception (
288 "ifr_adding_visitor_exception::visit_exception"));
297 ifr_adding_visitor_exception::visit_enum (AST_Enum
*node
)
301 // Is this enum already in the respository?
302 CORBA::Contained_var prev_def
=
303 be_global
->repository ()->lookup_id (node
->repoID ());
305 // If not, create a new entry.
306 if (CORBA::is_nil (prev_def
.in ()))
308 CORBA::ULong member_count
= static_cast<CORBA::ULong
> (node
->member_count ());
310 CORBA::EnumMemberSeq
members (member_count
);
311 members
.length (member_count
);
313 UTL_ScopedName
*member_name
= 0;
315 // Get a list of the member names.
316 for (CORBA::ULong i
= 0; i
< member_count
; ++i
)
318 member_name
= node
->value_to_name (i
);
322 member_name
->last_component ()->get_string ()
327 be_global
->repository ()->create_enum (
329 node
->local_name ()->get_string (),
334 node
->ifr_added (true);
338 // If the line below is true, we are clobbering a previous
339 // entry (from another IDL file) of another type. In that
340 // case we do what other ORB vendors do, and destroy the
341 // original entry, create the new one, and let the user beware.
342 if (!node
->ifr_added ())
344 prev_def
->destroy ();
346 // This call will take the other branch.
347 return this->visit_enum (node
);
351 CORBA::IDLType::_narrow (prev_def
.in ());
354 catch (const CORBA::Exception
& ex
)
356 ex
._tao_print_exception (
358 "ifr_adding_visitor_exception::visit_enum"));
367 ifr_adding_visitor_exception::visit_union (AST_Union
*node
)
371 // Is this union already in the respository?
372 CORBA::Contained_var prev_def
=
373 be_global
->repository ()->lookup_id (node
->repoID ());
375 // If not, create a new entry.
376 if (CORBA::is_nil (prev_def
.in ()))
378 ifr_adding_visitor_union
visitor (node
);
379 int retval
= visitor
.visit_union (node
);
383 // Get the result of the visit.
385 CORBA::IDLType::_duplicate (visitor
.ir_current ());
392 // If the line below is true, we are clobbering a previous
393 // entry (from another IDL file) of another type. In that
394 // case we do what other ORB vendors do, and destroy the
395 // original entry, create the new one, and let the user beware.
396 if (!node
->ifr_added ())
398 prev_def
->destroy ();
400 // This call will take the other branch.
401 return this->visit_union (node
);
405 CORBA::IDLType::_narrow (prev_def
.in ());
408 catch (const CORBA::Exception
& ex
)
410 ex
._tao_print_exception (
412 "ifr_adding_visitor_exception::visit_union"));
421 ifr_adding_visitor_exception::ir_current () const
423 return this->ir_current_
.in ();
427 ifr_adding_visitor_exception::add_members (AST_Exception
*node
,
428 CORBA::ExceptionDef_ptr except_def
)
430 if (this->visit_scope (node
) == -1)
432 ORBSVCS_ERROR_RETURN ((
434 ACE_TEXT ("(%N:%l) ifr_adding_visitor_exception::")
435 ACE_TEXT ("visit_exception -")
436 ACE_TEXT (" visit_scope failed\n")
442 except_def
->members (this->members_
);
444 node
->ifr_added (true);