Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_valuebox / field_ch.cpp
blob356e1d18e577b872fbaa5c922c4ad9268b2c06e5
2 //=============================================================================
3 /**
4 * @file field_ch.cpp
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.
15 * @author Gary Maxey
17 //=============================================================================
19 #include "valuebox.h"
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)
32 int
33 be_visitor_valuebox_field_ch::visit_field (be_field *node)
35 be_type *bt = dynamic_cast<be_type*> (node->field_type ());
37 if (!bt)
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "(%N:%l) be_visitor_valuebox_field_ch::"
41 "visit_field - "
42 "Bad field type\n"
44 -1);
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"),
55 -1);
58 return 0;
61 // Visit operations on all possible data types that a union_branch can be.
63 int
64 be_visitor_valuebox_field_ch::visit_array (be_array *node)
66 be_decl *field = this->ctx_->node ();
67 be_type *bt = 0;
69 // Check if we are visiting this via a visit to a typedef node.
70 if (this->ctx_->alias ())
72 bt = this->ctx_->alias ();
74 else
76 bt = node;
79 if (!field)
81 ACE_ERROR_RETURN ((LM_ERROR,
82 "(%N:%l) be_visitor_valuebox_field_ch::"
83 "visit_array - "
84 "bad context information\n"),
85 -1);
88 TAO_OutStream *os = this->ctx_->stream ();
91 char fname [NAMEBUFSIZE];
92 ACE_OS::memset (fname,
93 '\0',
94 NAMEBUFSIZE);
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 ())
103 be_decl *parent =
104 dynamic_cast<be_scope*> (bt->defined_in ())->decl ();
105 ACE_OS::sprintf (fname,
106 "%s::_%s",
107 parent->full_name (),
108 bt->local_name ()->get_string ());
110 else
112 ACE_OS::sprintf (fname,
113 "_%s",
114 bt->full_name ());
117 else
118 { // Typedefed node.
119 ACE_OS::sprintf (fname,
120 "%s",
121 bt->full_name ());
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;
132 return 0;
136 be_visitor_valuebox_field_ch::visit_enum (be_enum *node)
138 be_decl *field = this->ctx_->node ();
139 be_type *bt = 0;
141 // Check if we are visiting this via a visit to a typedef node.
142 if (this->ctx_->alias ())
144 bt = this->ctx_->alias ();
146 else
148 bt = node;
151 if (!field)
153 ACE_ERROR_RETURN ((LM_ERROR,
154 "(%N:%l) be_visitor_valuebox_field_ch::"
155 "visit_enum - "
156 "bad context information\n"),
157 -1);
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");
167 return 0;
171 be_visitor_valuebox_field_ch::visit_interface (be_interface *node)
173 be_decl *field = this->ctx_->node ();
174 be_type *bt = 0;
176 // Check if we are visiting this via a visit to a typedef node.
177 if (this->ctx_->alias ())
179 bt = this->ctx_->alias ();
181 else
183 bt = node;
186 if (!field)
188 ACE_ERROR_RETURN ((LM_ERROR,
189 "(%N:%l) be_visitor_valuebox_field_ch::"
190 "visit_interface - "
191 "bad context information\n"),
192 -1);
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");
202 return 0;
206 be_visitor_valuebox_field_ch::visit_interface_fwd (be_interface_fwd *node)
208 be_decl *field = this->ctx_->node ();
209 be_type *bt = 0;
211 // Check if we are visiting this via a visit to a typedef node.
212 if (this->ctx_->alias ())
214 bt = this->ctx_->alias ();
216 else
218 bt = node;
221 if (!field)
223 ACE_ERROR_RETURN ((LM_ERROR,
224 "(%N:%l) be_visitor_valuebox_field_ch::"
225 "visit_interface_fwd - "
226 "bad context information\n"),
227 -1);
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");
237 return 0;
241 be_visitor_valuebox_field_ch::visit_valuetype (be_valuetype *)
243 // Valuetype is not a valid component of a valuebox
244 return 0;
248 be_visitor_valuebox_field_ch::visit_valuetype_fwd (be_valuetype_fwd *)
250 // Valuetype is not a valid component of a valuebox
251 return 0;
255 be_visitor_valuebox_field_ch::visit_predefined_type (be_predefined_type *node)
257 be_decl *field = this->ctx_->node ();
258 be_type *bt = 0;
260 // Check if we are visiting this via a visit to a typedef node.
261 if (this->ctx_->alias ())
263 bt = this->ctx_->alias ();
265 else
267 bt = node;
270 if (!field)
272 ACE_ERROR_RETURN ((LM_ERROR,
273 "(%N:%l) be_visitor_valuebox_field_ch::"
274 "visit_predefined_type - "
275 "bad context information\n"),
276 -1);
279 TAO_OutStream *os = this->ctx_->stream ();
281 TAO_INSERT_COMMENT (os);
283 switch (node->pt ())
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");
290 break;
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, " ::", " &", "");
295 break;
296 case AST_PredefinedType::PT_void:
297 break;
298 default:
299 this->emit_member_set (field, bt, " ::", "");
300 this->emit_member_get (field, bt, " ::", "", "const");
303 return 0;
307 be_visitor_valuebox_field_ch::visit_sequence (be_sequence *node)
309 be_decl *field = this->ctx_->node ();
310 be_type *bt = 0;
312 // Check if we are visiting this via a visit to a typedef node.
313 if (this->ctx_->alias ())
315 bt = this->ctx_->alias ();
317 else
319 bt = node;
322 if (!field)
324 ACE_ERROR_RETURN ((LM_ERROR,
325 "(%N:%l) be_visitor_valuebox_field_ch::"
326 "visit_sequence - "
327 "bad context information\n"),
328 -1);
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, "", " &", "");
340 return 0;
344 be_visitor_valuebox_field_ch::visit_string (be_string *node)
346 be_decl *field = this->ctx_->node ();
347 be_type *bt = 0;
349 // Check if we are visiting this via a visit to a typedef node.
350 if (this->ctx_->alias ())
352 bt = this->ctx_->alias ();
354 else
356 bt = node;
359 if (!field)
361 ACE_ERROR_RETURN ((LM_ERROR,
362 "(%N:%l) be_visitor_valuebox_field_ch::"
363 "visit_string - "
364 "bad context information\n"),
365 -1);
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");
390 return 0;
394 be_visitor_valuebox_field_ch::visit_structure (be_structure *node)
396 be_decl *field = this->ctx_->node ();
397 be_type *bt = 0;
399 // Check if we are visiting this via a visit to a typedef node.
400 if (this->ctx_->alias ())
402 bt = this->ctx_->alias ();
404 else
406 bt = node;
409 if (!field)
411 ACE_ERROR_RETURN ((LM_ERROR,
412 "(%N:%l) be_visitor_valuebox_field_ch::"
413 "visit_structure - "
414 "bad context information\n"),
415 -1);
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, "", " &", "");
426 return 0;
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::"
441 "visit_typedef - "
442 "Bad primitive type\n"),
443 -1);
446 this->ctx_->alias (0);
447 return 0;
451 be_visitor_valuebox_field_ch::visit_union (be_union *node)
453 be_decl *field = this->ctx_->node ();
454 be_type *bt = 0;
456 // Check if we are visiting this via a visit to a typedef node.
457 if (this->ctx_->alias ())
459 bt = this->ctx_->alias ();
461 else
463 bt = node;
466 if (!field)
468 ACE_ERROR_RETURN ((LM_ERROR,
469 "(%N:%l) be_visitor_valuebox_field_ch::"
470 "visit_union - "
471 "bad context information\n"
473 -1);
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, "", " &", "");
485 return 0;
489 void
490 be_visitor_valuebox_field_ch::emit_member_set (be_decl *field,
491 be_type *field_type,
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 << ");"
499 << be_nl;
504 void
505 be_visitor_valuebox_field_ch::emit_member_get (be_decl *field,
506 be_type *field_type,
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;