2 //=============================================================================
6 * Visitor generating code for Components. This is a generic visitor.
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 ()
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_
);
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
:
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")),
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_
);
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
);
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
);
86 case TAO_CodeGen::TAO_ROOT_SH
:
88 be_visitor_operation_sh
visitor (&ctx
);
89 status
= node
->accept (&visitor
);
92 case TAO_CodeGen::TAO_ROOT_IH
:
94 be_visitor_operation_ih
visitor (&ctx
);
95 status
= node
->accept (&visitor
);
98 case TAO_CodeGen::TAO_ROOT_SS
:
100 be_visitor_operation_ss
visitor (&ctx
);
101 status
= node
->accept (&visitor
);
104 case TAO_CodeGen::TAO_ROOT_IS
:
106 be_visitor_operation_is
visitor (&ctx
);
107 status
= node
->accept (&visitor
);
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
125 ACE_ERROR_RETURN ((LM_ERROR
,
126 ACE_TEXT ("be_visitor_component::")
127 ACE_TEXT ("visit_operation - ")
128 ACE_TEXT ("Bad context state\n")),
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")),
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_
);
158 switch (this->ctx_
->state ())
160 case TAO_CodeGen::TAO_INTERFACE_CH
:
162 be_visitor_structure_ch
visitor (&ctx
);
163 status
= node
->accept (&visitor
);
166 case TAO_CodeGen::TAO_ROOT_CI
:
168 be_visitor_structure_ci
visitor (&ctx
);
169 status
= node
->accept (&visitor
);
172 case TAO_CodeGen::TAO_ROOT_CS
:
174 be_visitor_structure_cs
visitor (&ctx
);
175 status
= node
->accept (&visitor
);
178 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
180 be_visitor_structure_any_op_ch
visitor (&ctx
);
181 status
= node
->accept (&visitor
);
184 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
186 be_visitor_structure_any_op_cs
visitor (&ctx
);
187 status
= node
->accept (&visitor
);
190 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
192 be_visitor_structure_cdr_op_ch
visitor (&ctx
);
193 status
= node
->accept (&visitor
);
196 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
198 be_visitor_structure_cdr_op_cs
visitor (&ctx
);
199 status
= node
->accept (&visitor
);
203 return 0; // nothing to be done
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")),
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_
);
227 switch (this->ctx_
->state ())
229 case TAO_CodeGen::TAO_INTERFACE_CH
:
231 be_visitor_typedef_ch
visitor (&ctx
);
232 status
= node
->accept (&visitor
);
235 case TAO_CodeGen::TAO_ROOT_CI
:
237 be_visitor_typedef_ci
visitor (&ctx
);
238 status
= node
->accept (&visitor
);
241 case TAO_CodeGen::TAO_ROOT_CS
:
243 be_visitor_typedef_cs
visitor (&ctx
);
244 status
= node
->accept (&visitor
);
247 case TAO_CodeGen::TAO_ROOT_ANY_OP_CH
:
249 be_visitor_typedef_any_op_ch
visitor (&ctx
);
250 status
= node
->accept (&visitor
);
253 case TAO_CodeGen::TAO_ROOT_ANY_OP_CS
:
255 be_visitor_typedef_any_op_cs
visitor (&ctx
);
256 status
= node
->accept (&visitor
);
259 case TAO_CodeGen::TAO_ROOT_CDR_OP_CH
:
261 be_visitor_typedef_cdr_op_ch
visitor (&ctx
);
262 status
= node
->accept (&visitor
);
265 case TAO_CodeGen::TAO_ROOT_CDR_OP_CS
:
267 be_visitor_typedef_cdr_op_cs
visitor (&ctx
);
268 status
= node
->accept (&visitor
);
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
287 ACE_ERROR_RETURN ((LM_ERROR
,
288 ACE_TEXT ("be_visitor_component::")
289 ACE_TEXT ("visit_typedef - ")
290 ACE_TEXT ("Bad context state\n")),
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")),
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")),
332 this->ctx_
->port_prefix () = "";
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")),
361 this->ctx_
->port_prefix () = "";