2 //=============================================================================
6 * Visitor for the Valuebox class.
7 * This one generates code for accessor and modifier functions of
8 * for valuebox struct members.
12 //=============================================================================
16 be_visitor_valuebox_field_ci::be_visitor_valuebox_field_ci (
17 be_visitor_context
*ctx
19 : be_visitor_decl (ctx
),
24 be_visitor_valuebox_field_ci::~be_visitor_valuebox_field_ci ()
29 be_visitor_valuebox_field_ci::visit_field (be_field
*node
)
31 be_type
*bt
= dynamic_cast<be_type
*> (node
->field_type ());
35 ACE_ERROR_RETURN ((LM_ERROR
,
36 "(%N:%l) be_visitor_valuebox_field_ci::"
42 // Store the valuebox in the visitor member, then replace the
43 // context value with the field node.
45 dynamic_cast<be_valuebox
*> (this->ctx_
->node ());
46 this->ctx_
->node (node
);
48 if (bt
->accept (this) == -1)
50 ACE_ERROR_RETURN ((LM_ERROR
,
51 "(%N:%l) be_visitor_valuebox_field_ci::"
53 "codegen for field type failed\n"),
60 // Visit operations on all possible data types that a field can be
63 be_visitor_valuebox_field_ci::visit_array (be_array
*node
)
65 be_decl
*field
= this->ctx_
->node ();
66 be_type
*bt
= nullptr;
68 // Check if we are visiting this node via a visit to a typedef node.
69 if (this->ctx_
->alias ())
71 bt
= this->ctx_
->alias ();
78 if (!field
|| !vb_node_
)
80 ACE_ERROR_RETURN ((LM_ERROR
,
81 "(%N:%l) be_visitor_valuebox_field_ci::"
83 "bad context information\n"),
87 TAO_OutStream
*os
= this->ctx_
->stream ();
89 char fname
[NAMEBUFSIZE
];
90 ACE_OS::memset (fname
,
94 if (bt
->node_type () != AST_Decl::NT_typedef
)
96 // For anonymous arrays ...
97 // We have to generate a name for us that has an underscope prepended to
98 // our local name. This needs to be inserted after the parent's name.
102 dynamic_cast<be_scope
*> (bt
->defined_in ())->decl ();
103 ACE_OS::sprintf (fname
,
105 parent
->full_name (),
106 bt
->local_name ()->get_string ());
110 ACE_OS::sprintf (fname
,
118 ACE_OS::sprintf (fname
,
123 TAO_INSERT_COMMENT (os
);
125 *os
<< "/// Modifier to set the member." << be_nl
;
127 *os
<< "ACE_INLINE void" << be_nl
128 << vb_node_
->name () << "::" << field
->local_name ()
129 << " (" << fname
<< " val)" << be_nl
131 << fname
<< "_copy ("
132 << "this->_pd_value->" << field
->local_name ()
133 << ", val);" << be_uidt_nl
136 *os
<< "/// Accessor to retrieve the member." << be_nl
;
138 *os
<< "ACE_INLINE const " << fname
<< "_slice *" << be_nl
139 << vb_node_
->name () << "::" << field
->local_name ()
140 << " () const" << be_nl
142 << "return this->_pd_value->" << field
->local_name ()
150 be_visitor_valuebox_field_ci::visit_enum (be_enum
*node
)
152 be_decl
*field
= this->ctx_
->node ();
153 be_type
*bt
= nullptr;
155 // Check if we are visiting this node via a visit to a typedef node.
156 if (this->ctx_
->alias ())
158 bt
= this->ctx_
->alias ();
165 if (!field
|| !vb_node_
)
167 ACE_ERROR_RETURN ((LM_ERROR
,
168 "(%N:%l) be_visitor_valuebox_field_ci::"
170 "bad context information\n"),
174 TAO_OutStream
*os
= this->ctx_
->stream ();
176 TAO_INSERT_COMMENT (os
);
178 this->emit_member_set (field
, bt
, "", "");
179 this->emit_member_get (field
, bt
, "", "", "const", "");
185 be_visitor_valuebox_field_ci::visit_interface (be_interface
*node
)
187 be_decl
*field
= this->ctx_
->node ();
188 be_type
*bt
= nullptr;
190 // Check if we are visiting this node via a visit to a typedef node.
191 if (this->ctx_
->alias ())
193 bt
= this->ctx_
->alias ();
200 if (!field
|| !vb_node_
)
202 ACE_ERROR_RETURN ((LM_ERROR
,
203 "(%N:%l) be_visitor_valuebox_field_ci::"
205 "bad context information\n"),
209 TAO_OutStream
*os
= this->ctx_
->stream ();
211 TAO_INSERT_COMMENT (os
);
213 *os
<< "// Modifier to set the member." << be_nl
;
215 *os
<< "ACE_INLINE void" << be_nl
216 << vb_node_
->name () << "::" << field
->local_name ()
217 << " (" << bt
->name () << "_ptr val)"
218 << be_nl
<< "{" << be_idt_nl
219 << "this->_pd_value->" << field
->local_name ()
220 << " = " << "TAO::Objref_Traits< ::" << bt
->name ()
221 << ">::duplicate (val);" << be_uidt
<< be_uidt_nl
224 this->emit_member_get (field
, bt
, "", "_ptr", "const", ".in ()");
230 be_visitor_valuebox_field_ci::visit_interface_fwd (be_interface_fwd
*node
)
232 be_decl
*field
= this->ctx_
->node ();
233 be_type
*bt
= nullptr;
235 // Check if we are visiting this node via a visit to a typedef node.
236 if (this->ctx_
->alias ())
238 bt
= this->ctx_
->alias ();
245 if (!field
|| !vb_node_
)
247 ACE_ERROR_RETURN ((LM_ERROR
,
248 "(%N:%l) be_visitor_valuebox_field_ci::"
249 "visit_interface_fwd - "
250 "bad context information\n"),
254 TAO_OutStream
*os
= this->ctx_
->stream ();
256 TAO_INSERT_COMMENT (os
);
258 *os
<< "// Modifier to set the member." << be_nl
;
260 *os
<< "ACE_INLINE void" << be_nl
261 << vb_node_
->name () << "::" << field
->local_name ()
262 << " (" << bt
->name () << "_ptr val)"
263 << be_nl
<< "{" << be_idt_nl
264 << "this->_pd_value->" << field
->local_name ()
265 << " = " << "TAO::Objref_Traits< ::" << bt
->name ()
266 << ">::duplicate (val);" << be_uidt
<< be_uidt_nl
269 this->emit_member_get (field
, bt
, "", "_ptr", "const", ".in ()");
275 be_visitor_valuebox_field_ci::visit_valuetype (be_valuetype
*)
277 // Valuetype is not a valid component of a valuebox
282 be_visitor_valuebox_field_ci::visit_eventtype (be_eventtype
*)
284 // Valuetype is not a valid component of a valuebox
289 be_visitor_valuebox_field_ci::visit_valuetype_fwd (be_valuetype_fwd
*)
291 // Valuetype is not a valid component of a valuebox
296 be_visitor_valuebox_field_ci::visit_eventtype_fwd (be_eventtype_fwd
*)
298 // Valuetype is not a valid component of a valuebox
303 be_visitor_valuebox_field_ci::visit_predefined_type (be_predefined_type
*node
)
305 be_decl
*field
= this->ctx_
->node ();
306 be_type
*bt
= nullptr;
308 // Check if we are visiting this node via a visit to a typedef node.
309 if (this->ctx_
->alias ())
311 bt
= this->ctx_
->alias ();
318 if (!field
|| !vb_node_
)
320 ACE_ERROR_RETURN ((LM_ERROR
,
321 "(%N:%l) be_visitor_valuebox_field_ci::"
322 "visit_predefined_type - "
323 "bad context information\n"),
327 TAO_OutStream
*os
= this->ctx_
->stream ();
329 TAO_INSERT_COMMENT (os
);
333 case AST_PredefinedType::PT_pseudo
:
334 case AST_PredefinedType::PT_object
:
335 *os
<< "// Modifier to set the member." << be_nl
;
337 *os
<< "ACE_INLINE void" << be_nl
338 << vb_node_
->name () << "::" << field
->local_name ()
339 << " (::" << bt
->name () << "_ptr val)"
340 << be_nl
<< "{" << be_idt_nl
341 << "this->_pd_value->" << field
->local_name ()
342 << " = ::" << bt
->name() << "::_duplicate (val);" << be_uidt_nl
345 this->emit_member_get (field
, bt
, " ::", "_ptr", "const", ".in ()");
347 case AST_PredefinedType::PT_any
:
348 this->emit_member_set (field
, bt
, "const ::", " &");
349 this->emit_member_get (field
, bt
, "const ::", " &", "const", "");
350 this->emit_member_get (field
, bt
, " ::", " &", "", "");
352 case AST_PredefinedType::PT_void
:
355 this->emit_member_set (field
, bt
, " ::", "");
356 this->emit_member_get (field
, bt
, " ::", "", "const", "");
364 be_visitor_valuebox_field_ci::visit_sequence (be_sequence
*node
)
366 be_decl
*field
= this->ctx_
->node ();
367 be_type
*bt
= nullptr;
369 // Check if we are visiting this node via a visit to a typedef node.
370 if (this->ctx_
->alias ())
372 bt
= this->ctx_
->alias ();
379 if (!field
|| !vb_node_
)
381 ACE_ERROR_RETURN ((LM_ERROR
,
382 "(%N:%l) be_visitor_valuebox_field_ci::"
384 "bad context information\n"),
388 TAO_OutStream
*os
= this->ctx_
->stream ();
390 TAO_INSERT_COMMENT (os
);
392 this->emit_member_set (field
, bt
, "const ", " &");
393 this->emit_member_get (field
, bt
, "const ", " &", "const", "");
394 this->emit_member_get (field
, bt
, "", " &", "", "");
400 be_visitor_valuebox_field_ci::visit_string (be_string
*node
)
402 be_decl
*field
= this->ctx_
->node ();
403 be_type
*bt
= nullptr;
405 // Check if we are visiting this node via a visit to a typedef node.
406 if (this->ctx_
->alias ())
408 bt
= this->ctx_
->alias ();
415 if (!field
|| !vb_node_
)
417 ACE_ERROR_RETURN ((LM_ERROR
,
418 "(%N:%l) be_visitor_valuebox_field_ci::"
419 "visit_predefined_type - "
420 "bad context information\n"),
424 TAO_OutStream
*os
= this->ctx_
->stream ();
426 TAO_INSERT_COMMENT (os
);
428 this->emit_member_set (field
, bt
, "", "");
429 this->emit_member_set (field
, bt
, "const ", "");
431 *os
<< "// Modifier to set the member." << be_nl
;
433 const char *string_type
= "";
434 if (node
->node_type () == AST_Decl::NT_string
)
436 string_type
= "String";
438 else if (node
->node_type () == AST_Decl::NT_wstring
)
440 string_type
= "WString";
443 *os
<< "ACE_INLINE void" << be_nl
444 << vb_node_
->name () << "::" << field
->local_name ()
445 << " (const ::CORBA::" << string_type
<< "_var & val)"
446 << be_nl
<< "{" << be_idt_nl
447 << "this->_pd_value->" << field
->local_name ()
448 << " = val;" << be_uidt_nl
451 this->emit_member_get (field
, bt
, "const ", "", "const", "");
457 be_visitor_valuebox_field_ci::visit_structure (be_structure
*node
)
459 be_decl
*field
= this->ctx_
->node ();
460 be_type
*bt
= nullptr;
462 // Check if we are visiting this node via a visit to a typedef node.
463 if (this->ctx_
->alias ())
465 bt
= this->ctx_
->alias ();
472 if (!field
|| !vb_node_
)
474 ACE_ERROR_RETURN ((LM_ERROR
,
475 "(%N:%l) be_visitor_valuebox_field_ci::"
477 "bad context information\n"),
481 TAO_OutStream
*os
= this->ctx_
->stream ();
483 TAO_INSERT_COMMENT (os
);
485 this->emit_member_set (field
, bt
, "const ", " &");
486 this->emit_member_get (field
, bt
, "const ", " &", "const", "");
487 this->emit_member_get (field
, bt
, "", " &", "", "");
493 be_visitor_valuebox_field_ci::visit_typedef (be_typedef
*node
)
495 this->ctx_
->alias (node
);
496 be_type
*bt
= node
->primitive_base_type ();
498 if (!bt
|| (bt
->accept (this) == -1))
500 ACE_ERROR_RETURN ((LM_ERROR
,
501 "(%N:%l) be_visitor_valuebox_field_ci::"
503 "Bad primitive type\n"),
507 this->ctx_
->alias (nullptr);
512 be_visitor_valuebox_field_ci::visit_union (be_union
*node
)
514 be_decl
*field
= this->ctx_
->node ();
515 be_type
*bt
= nullptr;
517 // Check if we are visiting this node via a visit to a typedef node.
518 if (this->ctx_
->alias ())
520 bt
= this->ctx_
->alias ();
527 if (!field
|| !vb_node_
)
529 ACE_ERROR_RETURN ((LM_ERROR
,
530 "(%N:%l) be_visitor_valuebox_field_ci::"
532 "bad context information\n"),
536 TAO_OutStream
*os
= this->ctx_
->stream ();
538 TAO_INSERT_COMMENT (os
);
540 this->emit_member_set (field
, bt
, "const ", " &");
541 this->emit_member_get (field
, bt
, "const ", " &", "const", "");
542 this->emit_member_get (field
, bt
, "", " &", "", "");
548 be_visitor_valuebox_field_ci::emit_member_set (be_decl
*field
,
550 const char *const_arg
,
551 const char *arg_modifier
)
553 TAO_OutStream
*os
= this->ctx_
->stream ();
555 *os
<< "// Modifier to set the member." << be_nl
;
557 *os
<< "ACE_INLINE void" << be_nl
558 << vb_node_
->name () << "::" << field
->local_name ()
559 << " (" << const_arg
<< field_type
->name () << arg_modifier
<< " val)"
560 << be_nl
<< "{" << be_idt_nl
561 << "this->_pd_value->" << field
->local_name ()
562 << " = val;" << be_uidt_nl
567 be_visitor_valuebox_field_ci::emit_member_get (be_decl
*field
,
569 const char *const_prefix
,
570 const char *type_suffix
,
571 const char *const_method
,
572 const char *access_modifier
)
574 TAO_OutStream
*os
= this->ctx_
->stream ();
576 *os
<< "/// Accessor to retrieve the member." << be_nl
;
578 *os
<< "ACE_INLINE " << const_prefix
<< field_type
->name () << type_suffix
580 << vb_node_
->name () << "::" << field
->local_name ()
581 << " () " << const_method
<< be_nl
583 << "return this->_pd_value->" << field
->local_name () << access_modifier