Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_component / component.cpp
blob72050e8148e08c14b1b56f30e8db37ad65171e66
2 //=============================================================================
3 /**
4 * @file component.cpp
6 * Visitor generating code for Components. This is a generic visitor.
8 * @author Jeff Parsons
9 */
10 //=============================================================================
12 #include "component.h"
14 be_visitor_component::be_visitor_component (be_visitor_context *ctx)
15 : be_visitor_interface (ctx)
19 be_visitor_component::~be_visitor_component ()
23 int
24 be_visitor_component::visit_attribute (be_attribute *node)
26 // Instantiate a visitor context with a copy of our context. This info
27 // will be modified based on what type of node we are visiting.
28 be_visitor_context ctx (*this->ctx_);
29 ctx.node (node);
31 switch (this->ctx_->state ())
33 case TAO_CodeGen::TAO_INTERFACE_CH:
34 case TAO_CodeGen::TAO_ROOT_CS:
35 case TAO_CodeGen::TAO_ROOT_SH:
36 case TAO_CodeGen::TAO_ROOT_IH:
37 case TAO_CodeGen::TAO_ROOT_SS:
38 case TAO_CodeGen::TAO_ROOT_IS:
39 break;
40 default:
41 return 0; // nothing to be done
44 // Same visitor for all the above cases where an action is taken.
45 be_visitor_attribute visitor (&ctx);
47 if (node->accept (&visitor) == -1)
49 ACE_ERROR_RETURN ((LM_ERROR,
50 ACE_TEXT ("be_visitor_component::")
51 ACE_TEXT ("visit_attribute - ")
52 ACE_TEXT ("failed to accept visitor\n")),
53 -1);
56 return 0;
59 int
60 be_visitor_component::visit_operation (be_operation *node)
62 // Instantiate a visitor context with a copy of our context. This info
63 // will be modified ased on what type of node we are visiting
64 be_visitor_context ctx (*this->ctx_);
65 ctx.node (node);
66 int status = 1;
68 switch (this->ctx_->state ())
70 // These first two cases may have the context state changed
71 // by a strategy, so we use the visitor factory below.
72 case TAO_CodeGen::TAO_INTERFACE_CH:
74 ctx.state (TAO_CodeGen::TAO_OPERATION_CH);
75 be_visitor_operation_ch visitor (&ctx);
76 status = node->accept (&visitor);
77 break;
79 case TAO_CodeGen::TAO_ROOT_CS:
81 ctx.state (TAO_CodeGen::TAO_OPERATION_CS);
82 be_visitor_operation_cs visitor (&ctx);
83 status = node->accept (&visitor);
84 break;
86 case TAO_CodeGen::TAO_ROOT_SH:
88 be_visitor_operation_sh visitor (&ctx);
89 status = node->accept (&visitor);
90 break;
92 case TAO_CodeGen::TAO_ROOT_IH:
94 be_visitor_operation_ih visitor (&ctx);
95 status = node->accept (&visitor);
96 break;
98 case TAO_CodeGen::TAO_ROOT_SS:
100 be_visitor_operation_ss visitor (&ctx);
101 status = node->accept (&visitor);
102 break;
104 case TAO_CodeGen::TAO_ROOT_IS:
106 be_visitor_operation_is visitor (&ctx);
107 status = node->accept (&visitor);
108 break;
110 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
111 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
112 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
113 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
114 case TAO_CodeGen::TAO_ROOT_CI:
115 case TAO_CodeGen::TAO_ROOT_SVH:
116 case TAO_CodeGen::TAO_ROOT_SVS:
117 case TAO_CodeGen::TAO_ROOT_EXH:
118 case TAO_CodeGen::TAO_ROOT_EXS:
119 case TAO_CodeGen::TAO_ROOT_CNH:
120 case TAO_CodeGen::TAO_ROOT_CNS:
121 case TAO_CodeGen::TAO_ROOT_EX_IDL:
122 return 0; // nothing to be done
123 default:
125 ACE_ERROR_RETURN ((LM_ERROR,
126 ACE_TEXT ("be_visitor_component::")
127 ACE_TEXT ("visit_operation - ")
128 ACE_TEXT ("Bad context state\n")),
129 -1);
133 if (status == 0)
135 return 0;
137 else if (status == -1)
139 ACE_ERROR_RETURN ((LM_ERROR,
140 ACE_TEXT ("be_visitor_component::")
141 ACE_TEXT ("visit_operation - ")
142 ACE_TEXT ("failed to accept visitor\n")),
143 -1);
146 return 0;
150 be_visitor_component::visit_structure (be_structure *node)
152 // Instantiate a visitor context with a copy of our context. This info
153 // will be modified based on what type of node we are visiting.
154 be_visitor_context ctx (*this->ctx_);
155 ctx.node (node);
156 int status = 0;
158 switch (this->ctx_->state ())
160 case TAO_CodeGen::TAO_INTERFACE_CH:
162 be_visitor_structure_ch visitor (&ctx);
163 status = node->accept (&visitor);
164 break;
166 case TAO_CodeGen::TAO_ROOT_CI:
168 be_visitor_structure_ci visitor (&ctx);
169 status = node->accept (&visitor);
170 break;
172 case TAO_CodeGen::TAO_ROOT_CS:
174 be_visitor_structure_cs visitor (&ctx);
175 status = node->accept (&visitor);
176 break;
178 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
180 be_visitor_structure_any_op_ch visitor (&ctx);
181 status = node->accept (&visitor);
182 break;
184 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
186 be_visitor_structure_any_op_cs visitor (&ctx);
187 status = node->accept (&visitor);
188 break;
190 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
192 be_visitor_structure_cdr_op_ch visitor (&ctx);
193 status = node->accept (&visitor);
194 break;
196 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
198 be_visitor_structure_cdr_op_cs visitor (&ctx);
199 status = node->accept (&visitor);
200 break;
202 default:
203 return 0; // nothing to be done
206 if (status == -1)
208 ACE_ERROR_RETURN ((LM_ERROR,
209 ACE_TEXT ("be_visitor_component::")
210 ACE_TEXT ("visit_structure - ")
211 ACE_TEXT ("failed to accept visitor\n")),
212 -1);
215 return 0;
219 be_visitor_component::visit_typedef (be_typedef *node)
221 // Instantiate a visitor context with a copy of our context. This info
222 // will be modified based on what type of node we are visiting.
223 be_visitor_context ctx (*this->ctx_);
224 ctx.node (node);
225 int status = 0;
227 switch (this->ctx_->state ())
229 case TAO_CodeGen::TAO_INTERFACE_CH:
231 be_visitor_typedef_ch visitor (&ctx);
232 status = node->accept (&visitor);
233 break;
235 case TAO_CodeGen::TAO_ROOT_CI:
237 be_visitor_typedef_ci visitor (&ctx);
238 status = node->accept (&visitor);
239 break;
241 case TAO_CodeGen::TAO_ROOT_CS:
243 be_visitor_typedef_cs visitor (&ctx);
244 status = node->accept (&visitor);
245 break;
247 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH:
249 be_visitor_typedef_any_op_ch visitor (&ctx);
250 status = node->accept (&visitor);
251 break;
253 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS:
255 be_visitor_typedef_any_op_cs visitor (&ctx);
256 status = node->accept (&visitor);
257 break;
259 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH:
261 be_visitor_typedef_cdr_op_ch visitor (&ctx);
262 status = node->accept (&visitor);
263 break;
265 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS:
267 be_visitor_typedef_cdr_op_cs visitor (&ctx);
268 status = node->accept (&visitor);
269 break;
271 case TAO_CodeGen::TAO_ROOT_SH:
272 case TAO_CodeGen::TAO_ROOT_IH:
273 case TAO_CodeGen::TAO_ROOT_IS:
274 case TAO_CodeGen::TAO_ROOT_SS:
275 case TAO_CodeGen::TAO_ROOT_SVH:
276 case TAO_CodeGen::TAO_ROOT_SVS:
277 case TAO_CodeGen::TAO_ROOT_SVTH:
278 case TAO_CodeGen::TAO_ROOT_SVTS:
279 case TAO_CodeGen::TAO_ROOT_EXH:
280 case TAO_CodeGen::TAO_ROOT_EXS:
281 case TAO_CodeGen::TAO_ROOT_CNH:
282 case TAO_CodeGen::TAO_ROOT_CNS:
283 case TAO_CodeGen::TAO_ROOT_EX_IDL:
284 return 0; // nothing to be done
285 default:
287 ACE_ERROR_RETURN ((LM_ERROR,
288 ACE_TEXT ("be_visitor_component::")
289 ACE_TEXT ("visit_typedef - ")
290 ACE_TEXT ("Bad context state\n")),
291 -1);
295 if (status == -1)
297 ACE_ERROR_RETURN ((LM_ERROR,
298 ACE_TEXT ("be_visitor_component::")
299 ACE_TEXT ("visit_typedef - ")
300 ACE_TEXT ("failed to accept visitor\n")),
301 -1);
304 return 0;
308 be_visitor_component::visit_extended_port (
309 be_extended_port *node)
311 this->ctx_->port_prefix () =
312 node->local_name ()->get_string ();
313 this->ctx_->port_prefix () += '_';
315 /// If the port visit traverses any attributes defined in the
316 /// original porttype, this is a way for visitors down the
317 /// line to tell what scope we are actually in.
318 this->ctx_->interface (
319 dynamic_cast<be_interface*> (node->defined_in ()));
321 be_porttype *pt = node->port_type ();
323 if (this->visit_scope (pt) == -1)
325 ACE_ERROR_RETURN ((LM_ERROR,
326 ACE_TEXT ("be_visitor_component::")
327 ACE_TEXT ("visit_extended_port - ")
328 ACE_TEXT ("visit_scope () failed\n")),
329 -1);
332 this->ctx_->port_prefix () = "";
334 return 0;
338 be_visitor_component::visit_mirror_port (be_mirror_port *node)
340 this->ctx_->port_prefix () =
341 node->local_name ()->get_string ();
342 this->ctx_->port_prefix () += '_';
344 /// If the port visit traverses any attributes defined in the
345 /// original porttype, this is a way for visitors down the
346 /// line to tell what scope we are actually in.
347 this->ctx_->interface (
348 dynamic_cast<be_interface*> (node->defined_in ()));
350 be_porttype *pt = node->port_type ();
352 if (this->visit_scope (pt) == -1)
354 ACE_ERROR_RETURN ((LM_ERROR,
355 ACE_TEXT ("be_visitor_component::")
356 ACE_TEXT ("visit_extended_port - ")
357 ACE_TEXT ("visit_scope () failed\n")),
358 -1);
361 this->ctx_->port_prefix () = "";
363 return 0;