2 //=============================================================================
6 * Visitor for the structure fields in valuebox class.
7 * This one generates code for access to structure members
8 * in the client header.
10 * Based on be_visitor_union_branch/public_ch. In general we
11 * generate the same method signatures as that visitor but cannot
12 * use it directly because a valuebox is not a scope and because
13 * the structure is visited prior to visiting the valuebox.
17 //=============================================================================
21 be_visitor_valuebox_field_ch::be_visitor_valuebox_field_ch (
22 be_visitor_context
*ctx
24 : be_visitor_decl (ctx
)
28 be_visitor_valuebox_field_ch::~be_visitor_valuebox_field_ch (void)
33 be_visitor_valuebox_field_ch::visit_field (be_field
*node
)
35 be_type
*bt
= dynamic_cast<be_type
*> (node
->field_type ());
39 ACE_ERROR_RETURN ((LM_ERROR
,
40 "(%N:%l) be_visitor_valuebox_field_ch::"
47 this->ctx_
->node (node
);
49 if (bt
->accept (this) == -1)
51 ACE_ERROR_RETURN ((LM_ERROR
,
52 "(%N:%l) be_visitor_valuebox_field_ch::"
53 "visit_union_branch - "
54 "codegen for valuebox field failed\n"),
61 // Visit operations on all possible data types that a union_branch can be.
64 be_visitor_valuebox_field_ch::visit_array (be_array
*node
)
66 be_decl
*field
= this->ctx_
->node ();
69 // Check if we are visiting this via a visit to a typedef node.
70 if (this->ctx_
->alias ())
72 bt
= this->ctx_
->alias ();
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 "(%N:%l) be_visitor_valuebox_field_ch::"
84 "bad context information\n"),
88 TAO_OutStream
*os
= this->ctx_
->stream ();
91 char fname
[NAMEBUFSIZE
];
92 ACE_OS::memset (fname
,
96 if (bt
->node_type () != AST_Decl::NT_typedef
)
98 // For anonymous arrays ...
99 // We have to generate a name for us that has an underscope prepended to
100 // our local name. This needs to be inserted after the parent's name.
101 if (bt
->is_nested ())
104 dynamic_cast<be_scope
*> (bt
->defined_in ())->decl ();
105 ACE_OS::sprintf (fname
,
107 parent
->full_name (),
108 bt
->local_name ()->get_string ());
112 ACE_OS::sprintf (fname
,
119 ACE_OS::sprintf (fname
,
125 TAO_INSERT_COMMENT (os
);
127 *os
<< "void " << field
->local_name () << " (" << fname
<< ");" << be_nl
;
129 *os
<< "const " << fname
<< "_slice *" << field
->local_name ()
130 << " (void) const;" << be_nl
;
136 be_visitor_valuebox_field_ch::visit_enum (be_enum
*node
)
138 be_decl
*field
= this->ctx_
->node ();
141 // Check if we are visiting this via a visit to a typedef node.
142 if (this->ctx_
->alias ())
144 bt
= this->ctx_
->alias ();
153 ACE_ERROR_RETURN ((LM_ERROR
,
154 "(%N:%l) be_visitor_valuebox_field_ch::"
156 "bad context information\n"),
160 TAO_OutStream
*os
= this->ctx_
->stream ();
162 TAO_INSERT_COMMENT (os
);
164 this->emit_member_set (field
, bt
, "", "");
165 this->emit_member_get (field
, bt
, "", "", "const");
171 be_visitor_valuebox_field_ch::visit_interface (be_interface
*node
)
173 be_decl
*field
= this->ctx_
->node ();
176 // Check if we are visiting this via a visit to a typedef node.
177 if (this->ctx_
->alias ())
179 bt
= this->ctx_
->alias ();
188 ACE_ERROR_RETURN ((LM_ERROR
,
189 "(%N:%l) be_visitor_valuebox_field_ch::"
191 "bad context information\n"),
195 TAO_OutStream
*os
= this->ctx_
->stream ();
197 TAO_INSERT_COMMENT (os
);
199 this->emit_member_set (field
, bt
, "", "_ptr");
200 this->emit_member_get (field
, bt
, "", "_ptr", "const");
206 be_visitor_valuebox_field_ch::visit_interface_fwd (be_interface_fwd
*node
)
208 be_decl
*field
= this->ctx_
->node ();
211 // Check if we are visiting this via a visit to a typedef node.
212 if (this->ctx_
->alias ())
214 bt
= this->ctx_
->alias ();
223 ACE_ERROR_RETURN ((LM_ERROR
,
224 "(%N:%l) be_visitor_valuebox_field_ch::"
225 "visit_interface_fwd - "
226 "bad context information\n"),
230 TAO_OutStream
*os
= this->ctx_
->stream ();
232 TAO_INSERT_COMMENT (os
);
234 this->emit_member_set (field
, bt
, "", "_ptr");
235 this->emit_member_get (field
, bt
, "", "_ptr", "const");
241 be_visitor_valuebox_field_ch::visit_valuetype (be_valuetype
*)
243 // Valuetype is not a valid component of a valuebox
248 be_visitor_valuebox_field_ch::visit_valuetype_fwd (be_valuetype_fwd
*)
250 // Valuetype is not a valid component of a valuebox
255 be_visitor_valuebox_field_ch::visit_predefined_type (be_predefined_type
*node
)
257 be_decl
*field
= this->ctx_
->node ();
260 // Check if we are visiting this via a visit to a typedef node.
261 if (this->ctx_
->alias ())
263 bt
= this->ctx_
->alias ();
272 ACE_ERROR_RETURN ((LM_ERROR
,
273 "(%N:%l) be_visitor_valuebox_field_ch::"
274 "visit_predefined_type - "
275 "bad context information\n"),
279 TAO_OutStream
*os
= this->ctx_
->stream ();
281 TAO_INSERT_COMMENT (os
);
285 case AST_PredefinedType::PT_pseudo
:
286 case AST_PredefinedType::PT_object
:
287 this->emit_member_set (field
, bt
, " ::", "_ptr");
288 this->emit_member_get (field
, bt
, " ::", "_ptr", "const");
291 case AST_PredefinedType::PT_any
:
292 this->emit_member_set (field
, bt
, "const ::", " &");
293 this->emit_member_get (field
, bt
, "const ::", " &", "const");
294 this->emit_member_get (field
, bt
, " ::", " &", "");
296 case AST_PredefinedType::PT_void
:
299 this->emit_member_set (field
, bt
, " ::", "");
300 this->emit_member_get (field
, bt
, " ::", "", "const");
307 be_visitor_valuebox_field_ch::visit_sequence (be_sequence
*node
)
309 be_decl
*field
= this->ctx_
->node ();
312 // Check if we are visiting this via a visit to a typedef node.
313 if (this->ctx_
->alias ())
315 bt
= this->ctx_
->alias ();
324 ACE_ERROR_RETURN ((LM_ERROR
,
325 "(%N:%l) be_visitor_valuebox_field_ch::"
327 "bad context information\n"),
331 TAO_OutStream
*os
= this->ctx_
->stream ();
333 TAO_INSERT_COMMENT (os
);
335 this->emit_member_set (field
, bt
, "const ", " &");
336 this->emit_member_get (field
, bt
, "const ", " &", "const");
337 this->emit_member_get (field
, bt
, "", " &", "");
344 be_visitor_valuebox_field_ch::visit_string (be_string
*node
)
346 be_decl
*field
= this->ctx_
->node ();
349 // Check if we are visiting this via a visit to a typedef node.
350 if (this->ctx_
->alias ())
352 bt
= this->ctx_
->alias ();
361 ACE_ERROR_RETURN ((LM_ERROR
,
362 "(%N:%l) be_visitor_valuebox_field_ch::"
364 "bad context information\n"),
368 TAO_OutStream
*os
= this->ctx_
->stream ();
370 TAO_INSERT_COMMENT (os
);
372 this->emit_member_set (field
, bt
, "", "");
373 this->emit_member_set (field
, bt
, "const ", "");
375 const char *string_type
= "";
376 if (node
->node_type () == AST_Decl::NT_string
)
378 string_type
= "String";
380 else if (node
->node_type () == AST_Decl::NT_wstring
)
382 string_type
= "WString";
385 *os
<< "void " << field
->local_name ()
386 << " (const ::CORBA::" << string_type
<< "_var &);" << be_nl
;
388 this->emit_member_get (field
, bt
, "const ", "", "const");
394 be_visitor_valuebox_field_ch::visit_structure (be_structure
*node
)
396 be_decl
*field
= this->ctx_
->node ();
399 // Check if we are visiting this via a visit to a typedef node.
400 if (this->ctx_
->alias ())
402 bt
= this->ctx_
->alias ();
411 ACE_ERROR_RETURN ((LM_ERROR
,
412 "(%N:%l) be_visitor_valuebox_field_ch::"
414 "bad context information\n"),
418 TAO_OutStream
*os
= this->ctx_
->stream ();
420 TAO_INSERT_COMMENT (os
);
422 this->emit_member_set (field
, bt
, "const ", " &");
423 this->emit_member_get (field
, bt
, "const ", " &", "const");
424 this->emit_member_get (field
, bt
, "", " &", "");
430 be_visitor_valuebox_field_ch::visit_typedef (be_typedef
*node
)
432 this->ctx_
->alias (node
);
434 // Make a decision based on the primitive base type.
435 be_type
*bt
= node
->primitive_base_type ();
437 if (!bt
|| (bt
->accept (this) == -1))
439 ACE_ERROR_RETURN ((LM_ERROR
,
440 "(%N:%l) be_visitor_union_branch_spec_ch::"
442 "Bad primitive type\n"),
446 this->ctx_
->alias (0);
451 be_visitor_valuebox_field_ch::visit_union (be_union
*node
)
453 be_decl
*field
= this->ctx_
->node ();
456 // Check if we are visiting this via a visit to a typedef node.
457 if (this->ctx_
->alias ())
459 bt
= this->ctx_
->alias ();
468 ACE_ERROR_RETURN ((LM_ERROR
,
469 "(%N:%l) be_visitor_valuebox_field_ch::"
471 "bad context information\n"
476 TAO_OutStream
*os
= this->ctx_
->stream ();
479 TAO_INSERT_COMMENT (os
);
481 this->emit_member_set (field
, bt
, "const ", " &");
482 this->emit_member_get (field
, bt
, "const ", " &", "const");
483 this->emit_member_get (field
, bt
, "", " &", "");
490 be_visitor_valuebox_field_ch::emit_member_set (be_decl
*field
,
492 const char *const_arg
,
493 const char *arg_modifier
)
495 TAO_OutStream
*os
= this->ctx_
->stream ();
497 *os
<< "void " << field
->local_name ()
498 << " (" << const_arg
<< field_type
->name () << arg_modifier
<< ");"
505 be_visitor_valuebox_field_ch::emit_member_get (be_decl
*field
,
507 const char *const_prefix
,
508 const char *type_suffix
,
509 const char *const_method
)
511 TAO_OutStream
*os
= this->ctx_
->stream ();
513 *os
<< const_prefix
<< field_type
->name () << type_suffix
<< " "
514 << field
->local_name () << " (void) " << const_method
<< ";" << be_nl
;