Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_valuebox / field_ci.cpp
blob0251e6e9b86741212da5e2e996945543ec7b4d02
2 //=============================================================================
3 /**
4 * @file field_ci.cpp
6 * Visitor for the Valuebox class.
7 * This one generates code for accessor and modifier functions of
8 * for valuebox struct members.
10 * @author Gary Maxey
12 //=============================================================================
14 #include "valuebox.h"
16 be_visitor_valuebox_field_ci::be_visitor_valuebox_field_ci (
17 be_visitor_context *ctx
19 : be_visitor_decl (ctx),
20 vb_node_ (nullptr)
24 be_visitor_valuebox_field_ci::~be_visitor_valuebox_field_ci ()
28 int
29 be_visitor_valuebox_field_ci::visit_field (be_field *node)
31 be_type *bt = dynamic_cast<be_type*> (node->field_type ());
33 if (!bt)
35 ACE_ERROR_RETURN ((LM_ERROR,
36 "(%N:%l) be_visitor_valuebox_field_ci::"
37 "visit_field - "
38 "Bad field type\n"),
39 -1);
42 // Store the valuebox in the visitor member, then replace the
43 // context value with the field node.
44 this->vb_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::"
52 "visit_field - "
53 "codegen for field type failed\n"),
54 -1);
57 return 0;
60 // Visit operations on all possible data types that a field can be
62 int
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 ();
73 else
75 bt = node;
78 if (!field || !vb_node_)
80 ACE_ERROR_RETURN ((LM_ERROR,
81 "(%N:%l) be_visitor_valuebox_field_ci::"
82 "visit_array - "
83 "bad context information\n"),
84 -1);
87 TAO_OutStream *os = this->ctx_->stream ();
89 char fname [NAMEBUFSIZE];
90 ACE_OS::memset (fname,
91 '\0',
92 NAMEBUFSIZE);
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.
99 if (bt->is_nested ())
101 be_decl *parent =
102 dynamic_cast<be_scope*> (bt->defined_in ())->decl ();
103 ACE_OS::sprintf (fname,
104 "%s::_%s",
105 parent->full_name (),
106 bt->local_name ()->get_string ());
108 else
110 ACE_OS::sprintf (fname,
111 "_%s",
112 bt->full_name ());
115 else
117 // Typedefed node.
118 ACE_OS::sprintf (fname,
119 "%s",
120 bt->full_name ());
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
130 << "{" << be_idt_nl
131 << fname << "_copy ("
132 << "this->_pd_value->" << field->local_name ()
133 << ", val);" << be_uidt_nl
134 << "}" << be_nl_2;
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
141 << "{" << be_idt_nl
142 << "return this->_pd_value->" << field->local_name ()
143 << ";" << be_uidt_nl
144 << "}" << be_nl_2;
146 return 0;
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 ();
160 else
162 bt = node;
165 if (!field || !vb_node_)
167 ACE_ERROR_RETURN ((LM_ERROR,
168 "(%N:%l) be_visitor_valuebox_field_ci::"
169 "visit_enum - "
170 "bad context information\n"),
171 -1);
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", "");
181 return 0;
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 ();
195 else
197 bt = node;
200 if (!field || !vb_node_)
202 ACE_ERROR_RETURN ((LM_ERROR,
203 "(%N:%l) be_visitor_valuebox_field_ci::"
204 "visit_interface - "
205 "bad context information\n"),
206 -1);
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
222 << "}" << be_nl_2;
224 this->emit_member_get (field, bt, "", "_ptr", "const", ".in ()");
226 return 0;
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 ();
240 else
242 bt = node;
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"),
251 -1);
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
267 << "}" << be_nl_2;
269 this->emit_member_get (field, bt, "", "_ptr", "const", ".in ()");
271 return 0;
275 be_visitor_valuebox_field_ci::visit_valuetype (be_valuetype *)
277 // Valuetype is not a valid component of a valuebox
278 return 0;
282 be_visitor_valuebox_field_ci::visit_eventtype (be_eventtype *)
284 // Valuetype is not a valid component of a valuebox
285 return 0;
289 be_visitor_valuebox_field_ci::visit_valuetype_fwd (be_valuetype_fwd *)
291 // Valuetype is not a valid component of a valuebox
292 return 0;
296 be_visitor_valuebox_field_ci::visit_eventtype_fwd (be_eventtype_fwd *)
298 // Valuetype is not a valid component of a valuebox
299 return 0;
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 ();
313 else
315 bt = node;
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"),
324 -1);
327 TAO_OutStream *os = this->ctx_->stream ();
329 TAO_INSERT_COMMENT (os);
331 switch (node->pt ())
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
343 << "}" << be_nl_2;
345 this->emit_member_get (field, bt, " ::", "_ptr", "const", ".in ()");
346 break;
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, " ::", " &", "", "");
351 break;
352 case AST_PredefinedType::PT_void:
353 break;
354 default:
355 this->emit_member_set (field, bt, " ::", "");
356 this->emit_member_get (field, bt, " ::", "", "const", "");
357 break;
360 return 0;
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 ();
374 else
376 bt = node;
379 if (!field || !vb_node_)
381 ACE_ERROR_RETURN ((LM_ERROR,
382 "(%N:%l) be_visitor_valuebox_field_ci::"
383 "visit_sequence - "
384 "bad context information\n"),
385 -1);
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, "", " &", "", "");
396 return 0;
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 ();
410 else
412 bt = node;
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"),
421 -1);
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
449 << "}" << be_nl_2;
451 this->emit_member_get (field, bt, "const ", "", "const", "");
453 return 0;
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 ();
467 else
469 bt = node;
472 if (!field || !vb_node_)
474 ACE_ERROR_RETURN ((LM_ERROR,
475 "(%N:%l) be_visitor_valuebox_field_ci::"
476 "visit_structure - "
477 "bad context information\n"),
478 -1);
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, "", " &", "", "");
489 return 0;
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::"
502 "visit_typedef - "
503 "Bad primitive type\n"),
504 -1);
507 this->ctx_->alias (nullptr);
508 return 0;
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 ();
522 else
524 bt = node;
527 if (!field || !vb_node_)
529 ACE_ERROR_RETURN ((LM_ERROR,
530 "(%N:%l) be_visitor_valuebox_field_ci::"
531 "visit_union - "
532 "bad context information\n"),
533 -1);
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, "", " &", "", "");
544 return 0;
547 void
548 be_visitor_valuebox_field_ci::emit_member_set (be_decl *field,
549 be_type *field_type,
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
563 << "}" << be_nl_2;
566 void
567 be_visitor_valuebox_field_ci::emit_member_get (be_decl *field,
568 be_type *field_type,
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
579 << be_nl
580 << vb_node_->name () << "::" << field->local_name ()
581 << " () " << const_method << be_nl
582 << "{" << be_idt_nl
583 << "return this->_pd_value->" << field->local_name () << access_modifier
584 << ";" << be_uidt_nl
585 << "}" << be_nl_2;