2 //=============================================================================
6 * Visitor generating code for Field node in the client header
8 * @author Aniruddha Gokhale
10 //=============================================================================
13 #include "be_visitor_enum/enum_ch.h"
14 #include "be_visitor_sequence/sequence_ch.h"
15 #include "be_visitor_map/map_ch.h"
16 #include "nr_extern.h"
18 // **********************************************
19 // Visitor for field in the client header file.
20 // **********************************************
22 be_visitor_field_ch::be_visitor_field_ch (be_visitor_context
*ctx
)
23 : be_visitor_decl (ctx
)
27 be_visitor_field_ch::~be_visitor_field_ch ()
32 be_visitor_field_ch::visit_field (be_field
*node
)
34 TAO_OutStream
*os
= this->ctx_
->stream ();
35 be_type
*bt
= dynamic_cast<be_type
*> (node
->field_type ());
39 ACE_ERROR_RETURN ((LM_ERROR
,
40 "(%N:%l) be_visitor_field_ch::"
46 this->ctx_
->node (node
);
50 if (bt
->accept (this) == -1)
52 ACE_ERROR_RETURN ((LM_ERROR
,
53 "(%N:%l) be_visitor_field_ch::"
55 "codegen for field type failed\n"),
59 // Now output the field name.
60 *os
<< " " << node
->local_name () << ";";
65 // Visit operations on all possible data types that a field can be.
68 be_visitor_field_ch::visit_array (be_array
*node
)
70 TAO_OutStream
*os
= this->ctx_
->stream ();
71 be_type
*bt
= nullptr;
73 if (this->ctx_
->alias ())
75 bt
= this->ctx_
->alias ();
82 // If not a typedef and we are defined in the use scope, we must be defined.
83 if (!this->ctx_
->alias ()
84 && node
->is_child (this->ctx_
->scope ()->decl ()))
86 // This is the case for anonymous arrays.
88 // Instantiate a visitor context with a copy of our context. This info
89 // will be modified based on what type of node we are visiting
90 be_visitor_context
ctx (*this->ctx_
);
91 ctx
.node (node
); // set the node to be the node being visited. The scope
94 // First generate the array declaration
95 ctx
.state (TAO_CodeGen::TAO_ARRAY_CH
);
96 be_visitor_array_ch
visitor (&ctx
);
98 if (node
->accept (&visitor
) == -1)
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 "(%N:%l) be_visitor_field_ch::"
107 ctx
.state (TAO_CodeGen::TAO_ROOT_CH
);
109 // Having defined all array type and its supporting operations, now
110 // generate the actual variable that is a field of the structure.
111 *os
<< be_nl_2
<< "_" << bt
->local_name ();
115 // This was a typedefed array.
116 UTL_Scope
*holds_container
=
117 this->ctx_
->scope ()->decl ()->defined_in ();
118 AST_Decl
*hc_decl
= ScopeAsDecl (holds_container
);
120 if (hc_decl
->node_type () != AST_Decl::NT_module
)
122 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
134 be_visitor_field_ch::visit_enum (be_enum
*node
)
136 TAO_OutStream
*os
= this->ctx_
->stream ();
137 be_type
*bt
= nullptr;
139 if (this->ctx_
->alias ())
141 bt
= this->ctx_
->alias ();
148 // If not a typedef and we are defined in the use scope, we must be defined.
149 if (!this->ctx_
->alias () // not a typedef
150 && node
->is_child (this->ctx_
->scope ()->decl ()))
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_
);
157 // First generate the enum declaration.
158 be_visitor_enum_ch
visitor (&ctx
);
160 if (node
->accept (&visitor
) == -1)
162 ACE_ERROR_RETURN ((LM_ERROR
,
163 "(%N:%l) be_visitor_field_ch::"
170 // This was a typedefed array.
171 UTL_Scope
*holds_container
=
172 this->ctx_
->scope ()->decl ()->defined_in ();
173 AST_Decl
*hc_decl
= ScopeAsDecl (holds_container
);
175 if (hc_decl
->node_type () != AST_Decl::NT_module
)
177 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
188 be_visitor_field_ch::visit_interface (be_interface
*node
)
190 return this->emit_common (node
);
194 be_visitor_field_ch::visit_interface_fwd (be_interface_fwd
*node
)
196 return this->emit_common (node
);
200 be_visitor_field_ch::visit_valuebox (be_valuebox
*node
)
202 return this->emit_common (node
);
206 be_visitor_field_ch::visit_valuetype (be_valuetype
*node
)
208 return this->emit_common (node
);
212 be_visitor_field_ch::visit_valuetype_fwd (be_valuetype_fwd
*node
)
214 return this->emit_common (node
);
219 be_visitor_field_ch::emit_common (be_type
*node
)
221 TAO_OutStream
*os
= this->ctx_
->stream ();
222 be_type
*bt
= nullptr;
224 if (this->ctx_
->alias ())
226 bt
= this->ctx_
->alias ();
233 UTL_Scope
*holds_container
=
234 this->ctx_
->scope ()->decl ()->defined_in ();
235 AST_Decl
*hc_decl
= ScopeAsDecl (holds_container
);
237 if (hc_decl
->node_type () != AST_Decl::NT_module
)
239 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl (), "_var");
243 *os
<< bt
->name () << "_var";
250 be_visitor_field_ch::visit_predefined_type (be_predefined_type
*node
)
252 TAO_OutStream
*os
= this->ctx_
->stream ();
253 be_type
*bt
= nullptr;
254 be_typedef
*td
= this->ctx_
->alias ();
265 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
269 case AST_PredefinedType::PT_object
:
270 case AST_PredefinedType::PT_abstract
:
271 case AST_PredefinedType::PT_pseudo
:
274 case AST_PredefinedType::PT_value
:
285 be_visitor_field_ch::visit_sequence (be_sequence
*node
)
287 TAO_OutStream
*os
= this->ctx_
->stream ();
288 be_type
*bt
= nullptr;
290 if (this->ctx_
->alias ())
292 bt
= this->ctx_
->alias ();
299 if (!this->ctx_
->alias ()
300 && node
->is_child (this->ctx_
->scope ()->decl ()))
302 // Put the field node into the (anonymous) sequence node, to be
303 // used later for unique name generation.
304 be_field
*member_node
=
305 dynamic_cast<be_field
*> (this->ctx_
->node ());
306 node
->field_node (member_node
);
308 // This was already generated in the corresponding valuetype class.
309 if (this->ctx_
->state () != TAO_CodeGen::TAO_VALUETYPE_OBV_CH
)
311 be_visitor_context
ctx (*this->ctx_
);
314 // First generate the sequence declaration.
315 be_visitor_sequence_ch
visitor (&ctx
);
317 if (node
->accept (&visitor
) == -1)
319 ACE_ERROR_RETURN ((LM_ERROR
,
320 "(%N:%l) be_visitor_field_ch::"
327 // If we are being reused by valutype, this would get generated
328 // in the private section of the OBV_xx class, so we must
329 // generate the typedef for that case elsewhere.
330 AST_Decl::NodeType snt
=
331 this->ctx_
->scope ()->decl ()->node_type ();
333 if (snt
!= AST_Decl::NT_valuetype
&& snt
!= AST_Decl::NT_eventtype
)
335 // Generate the anonymous sequence member typedef.
336 be_decl
*bs
= this->ctx_
->scope ()->decl ();
338 TAO_INSERT_COMMENT (os
);
340 *os
<< "typedef " << bt
->nested_type_name (bs
)
341 << " _" << this->ctx_
->node ()->local_name ()
346 be_typedef
*tdef
= dynamic_cast<be_typedef
*> (bt
);
348 // This was a typedefed array.
349 UTL_Scope
*holds_container
=
350 this->ctx_
->scope ()->decl ()->defined_in ();
351 AST_Decl
*hc_decl
= ScopeAsDecl (holds_container
);
353 if (hc_decl
->node_type () != AST_Decl::NT_module
356 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
367 be_visitor_field_ch::visit_map (be_map
*node
)
369 TAO_OutStream
*os
= this->ctx_
->stream ();
370 be_type
*bt
= nullptr;
371 if (this->ctx_
->alias ())
373 bt
= this->ctx_
->alias ();
380 if (!this->ctx_
->alias ()
381 && node
->is_child (this->ctx_
->scope ()->decl ()))
383 // Put the field node into the (anonymous) sequence node, to be
384 // used later for unique name generation.
385 be_field
*member_node
=
386 dynamic_cast<be_field
*> (this->ctx_
->node ());
387 node
->field_node (member_node
);
389 // This was already generated in the corresponding valuetype class.
390 if (this->ctx_
->state () != TAO_CodeGen::TAO_VALUETYPE_OBV_CH
)
392 be_visitor_context
ctx (*this->ctx_
);
395 // First generate the map declaration.
396 be_visitor_map_ch
visitor (&ctx
);
397 if (node
->accept (&visitor
) == -1)
399 ACE_ERROR_RETURN ((LM_ERROR
,
400 "(%N:%l) be_visitor_field_ch::"
407 // If we are being reused by valutype, this would get generated
408 // in the private section of the OBV_xx class, so we must
409 // generate the typedef for that case elsewhere.
410 AST_Decl::NodeType snt
=
411 this->ctx_
->scope ()->decl ()->node_type ();
413 if (snt
!= AST_Decl::NT_valuetype
&& snt
!= AST_Decl::NT_eventtype
)
415 // Generate the anonymous sequence member typedef.
416 be_decl
*bs
= this->ctx_
->scope ()->decl ();
418 TAO_INSERT_COMMENT (os
);
420 *os
<< "typedef " << bt
->nested_type_name (bs
)
421 << " _" << this->ctx_
->node ()->local_name ()
426 be_typedef
*tdef
= dynamic_cast<be_typedef
*> (bt
);
428 UTL_Scope
*holds_container
=
429 this->ctx_
->scope ()->decl ()->defined_in ();
430 AST_Decl
*hc_decl
= ScopeAsDecl (holds_container
);
432 if (hc_decl
->node_type () != AST_Decl::NT_module
435 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
446 be_visitor_field_ch::visit_string (be_string
*node
)
448 TAO_OutStream
*os
= this->ctx_
->stream ();
450 if (node
->width () == (long) sizeof (char))
452 *os
<< "::TAO::String_Manager";
456 *os
<< "::TAO::WString_Manager";
463 be_visitor_field_ch::visit_structure (be_structure
*node
)
465 TAO_OutStream
*os
= this->ctx_
->stream ();
466 be_type
*bt
= nullptr;
468 if (this->ctx_
->alias ())
470 bt
= this->ctx_
->alias ();
477 if (!this->ctx_
->alias () // not a typedef
478 && node
->is_child (this->ctx_
->scope ()->decl ()))
480 be_visitor_context
ctx (*this->ctx_
);
483 be_visitor_structure_ch
visitor (&ctx
);
485 if (node
->accept (&visitor
) == -1)
487 ACE_ERROR_RETURN ((LM_ERROR
,
488 "(%N:%l) be_visitor_field_ch::"
495 // This was a typedefed array.
496 UTL_Scope
*holds_container
=
497 this->ctx_
->scope ()->decl ()->defined_in ();
498 AST_Decl
*hc_decl
= ScopeAsDecl (holds_container
);
500 if (hc_decl
->node_type () != AST_Decl::NT_module
)
502 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
513 be_visitor_field_ch::visit_structure_fwd (be_structure_fwd
*node
)
516 dynamic_cast<be_structure
*> (node
->full_definition ());
518 return this->visit_structure (s
);
522 be_visitor_field_ch::visit_typedef (be_typedef
*node
)
524 this->ctx_
->alias (node
);
526 // Make a decision based on the primitive base type.
527 be_type
*bt
= node
->primitive_base_type ();
529 if (!bt
|| (bt
->accept (this) == -1))
531 ACE_ERROR_RETURN ((LM_ERROR
,
532 "(%N:%l) be_visitor_field_ch::"
534 "Bad primitive type\n"),
539 this->ctx_
->alias (nullptr);
544 be_visitor_field_ch::visit_union (be_union
*node
)
546 TAO_OutStream
*os
= this->ctx_
->stream ();
547 be_type
*bt
= nullptr;
549 if (this->ctx_
->alias ())
551 bt
= this->ctx_
->alias ();
558 if (!this->ctx_
->alias ()
559 && node
->is_child (this->ctx_
->scope ()->decl ()))
561 be_visitor_context
ctx (*this->ctx_
);
564 be_visitor_union_ch
visitor (&ctx
);
566 if (node
->accept (&visitor
) == -1)
568 ACE_ERROR_RETURN ((LM_ERROR
,
569 "(%N:%l) be_visitor_field_ch::"
578 // This was a typedefed array.
579 UTL_Scope
*holds_container
=\
580 this->ctx_
->scope ()->decl ()->defined_in ();
581 AST_Decl
*hc_decl
= ScopeAsDecl (holds_container
);
583 if (hc_decl
->node_type () != AST_Decl::NT_module
)
585 *os
<< bt
->nested_type_name (this->ctx_
->scope ()->decl ());
596 be_visitor_field_ch::visit_union_fwd (be_union_fwd
*node
)
599 dynamic_cast<be_union
*> (node
->full_definition ());
601 return this->visit_union (u
);
605 be_visitor_field_ch::visit_component (
609 return this->visit_interface (node
);
613 be_visitor_field_ch::visit_component_fwd (
614 be_component_fwd
*node
617 return this->visit_interface_fwd (node
);
621 be_visitor_field_ch::visit_eventtype (
625 return this->visit_valuetype (node
);
629 be_visitor_field_ch::visit_eventtype_fwd (
630 be_eventtype_fwd
*node
633 return this->visit_valuetype_fwd (node
);