2 //=============================================================================
6 * Visitor generating code for Unions in the client header
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 be_visitor_union_ch::be_visitor_union_ch (be_visitor_context
*ctx
)
15 : be_visitor_union (ctx
)
19 be_visitor_union_ch::~be_visitor_union_ch ()
23 int be_visitor_union_ch::visit_union (be_union
*node
)
25 if (node
->cli_hdr_gen () || node
->imported ())
30 // Evaluate the member in time for the decision to generate
31 // the recursive typecode include in the stub source file.
32 ACE_Unbounded_Queue
<AST_Type
*> list
;
33 (void) node
->in_recursion (list
);
35 // Instantiate a visitor context with a copy of our context. This info
36 // will be modified based on what type of node we are visiting.
37 be_visitor_context
ctx (*this->ctx_
);
40 TAO_OutStream
*os
= this->ctx_
->stream ();
42 // Generate _var and _out class typedefs.
43 node
->gen_common_varout (os
);
46 << "class " << be_global
->stub_export_macro () << " "
47 << node
->local_name () << be_nl
49 << "public:" << be_idt_nl
51 // Generate default and copy constructors.
52 << node
->local_name () << " (void);" << be_nl
53 << node
->local_name () << " (const " << node
->local_name ()
55 // Generate destructor.
56 << "~" << node
->local_name () << " (void);";
58 // Generate assignment operator.
60 << node
->local_name () << " &operator= (const "
61 << node
->local_name () << " &);";
63 // Retrieve the disriminant type.
64 be_type
*bt
= dynamic_cast<be_type
*> (node
->disc_type ());
68 ACE_ERROR_RETURN ((LM_ERROR
,
69 "(%N:%l) be_visitor_union_ch::"
71 "bad disciminant type\n"),
75 // The discriminant type may have to be defined here if it was an enum
76 // declaration inside of the union statement.
78 be_visitor_union_discriminant_ch
ud_visitor (&ctx
);
80 if (bt
->accept (&ud_visitor
) == -1)
82 ACE_ERROR_RETURN ((LM_ERROR
,
83 ACE_TEXT ("be_visitor_union_ch::")
84 ACE_TEXT (" visit_union - ")
85 ACE_TEXT ("codegen for discriminant failed\n")),
89 node
->gen_stub_decls (os
);
91 // Now generate the public defn for the union branch members. For this,
92 // set our state to reflect what we are aiming to do.
93 this->ctx_
->state (TAO_CodeGen::TAO_UNION_PUBLIC_CH
);
95 if (this->visit_scope (node
) == -1)
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 ACE_TEXT ("be_visitor_union_ch::")
99 ACE_TEXT ("visit_union - ")
100 ACE_TEXT ("codegen for public ")
101 ACE_TEXT ("defn of union members\n")),
105 // Now check if we need to generate the _default () method.
106 be_union::DefaultValue dv
;
108 if (node
->default_value (dv
) == -1)
110 ACE_ERROR_RETURN ((LM_ERROR
,
111 ACE_TEXT ("be_visitor_union_ch::")
112 ACE_TEXT ("visit_union - ")
113 ACE_TEXT ("computing default ")
114 ACE_TEXT ("value failed\n")),
118 if ((dv
.computed_
!= 0) && (node
->default_index () == -1))
120 TAO_INSERT_COMMENT (os
);
122 // Only if all cases are not covered AND there is no explicit
123 // default, we get the _default () method.
125 << "void _default (void);";
130 // Now generate the private data members of the union.
131 *os
<< "private:" << be_idt_nl
;
132 *os
<< bt
->nested_type_name (node
) << " disc_;" << be_nl_2
;
134 // The members are inside of a union.
135 *os
<< "union" << be_nl
;
136 *os
<< "{" << be_idt
;
138 this->ctx_
->state (TAO_CodeGen::TAO_UNION_PRIVATE_CH
);
140 if (this->visit_scope (node
) == -1)
142 ACE_ERROR_RETURN ((LM_ERROR
,
143 ACE_TEXT ("be_visitor_union_ch::")
144 ACE_TEXT ("visit_union - ")
145 ACE_TEXT ("codegen for private")
146 ACE_TEXT (" members of union\n")),
153 // The reset method (TAO extension).
155 << "/// TAO extension - frees any allocated storage." << be_nl
;
156 *os
<< "void _reset (void);";
158 *os
<< be_uidt_nl
<< "};";
160 if (be_global
->tc_support ())
163 be_visitor_typecode_decl
tc_visitor (&ctx
);
165 if (node
->accept (&tc_visitor
) == -1)
167 ACE_ERROR_RETURN ((LM_ERROR
,
168 ACE_TEXT ("be_visitor_union_ch::")
169 ACE_TEXT ("visit_union - ")
170 ACE_TEXT ("TypeCode declaration failed\n")),
175 node
->cli_hdr_gen (true);