2 //=============================================================================
4 * @file discriminant_ci.cpp
6 * Visitor generating code for discriminant of the union.
8 * @author Aniruddha Gokhale
10 //=============================================================================
14 be_visitor_union_discriminant_ci::be_visitor_union_discriminant_ci (
15 be_visitor_context
*ctx
)
16 : be_visitor_decl (ctx
)
20 be_visitor_union_discriminant_ci::~be_visitor_union_discriminant_ci ()
25 be_visitor_union_discriminant_ci::visit_enum (be_enum
*node
)
28 dynamic_cast<be_union
*> (this->ctx_
->node ());
29 be_type
*bt
= nullptr;
31 if (this->ctx_
->alias ())
33 bt
= this->ctx_
->alias ();
40 TAO_OutStream
*os
= this->ctx_
->stream ();
42 // now check if we need to generate the _default () method
43 be_union::DefaultValue dv
;
45 if (bu
->default_value (dv
) == -1)
47 ACE_ERROR_RETURN ((LM_ERROR
,
48 ACE_TEXT ("be_visitor_union_discriminant_ci::")
49 ACE_TEXT ("visit_enum - ")
50 ACE_TEXT ("computing default value failed\n")),
54 TAO_INSERT_COMMENT (os
);
56 if ((dv
.computed_
!= 0) && (bu
->default_index () == -1))
58 // Only if all cases are not covered AND there is no explicit
59 // default, we get the _default () method.
60 *os
<< "ACE_INLINE" << be_nl
62 << bu
->name () << "::_default ()" << be_nl
64 << "this->_reset ();" << be_nl
67 // We use one of the enum values that isn't used in this
68 // union if one is available.
69 UTL_ScopedName
*sn
= node
->value_to_name (dv
.u
.enum_val
);
73 // The function value_to_name() takes care of adding
74 // any necessary scoping to the output.
79 // Since CORBA defines enums to be 32bits, use -1 as the
80 // out-of-bounds value for the _default() function.
81 *os
<< "static_cast <" << bt
->name () << "> (-1)";
84 *os
<< ";" << be_uidt_nl
89 *os
<< "// Accessor to set the discriminant." << be_nl
90 << "ACE_INLINE" << be_nl
92 << bu
->name () << "::_d (" << bt
->name ()
93 << " discval)" << be_nl
95 << "this->disc_ = discval;" << be_uidt_nl
99 *os
<< "// Accessor to get the discriminant." << be_nl
100 << "ACE_INLINE" << be_nl
101 << bt
->name () << be_nl
102 << bu
->name () << "::_d () const" << be_nl
104 << "return this->disc_;" << be_uidt_nl
111 be_visitor_union_discriminant_ci::visit_predefined_type (
112 be_predefined_type
*node
116 dynamic_cast<be_union
*> (this->ctx_
->node ());
118 be_type
*bt
= nullptr;
120 if (this->ctx_
->alias ())
122 bt
= this->ctx_
->alias ();
129 TAO_OutStream
*os
= this->ctx_
->stream ();
131 // Now check if we need to generate the _default () method.
132 be_union::DefaultValue dv
;
134 if (bu
->default_value (dv
) == -1)
136 ACE_ERROR_RETURN ((LM_ERROR
,
137 ACE_TEXT ("be_visitor_union_discriminant_ci::")
138 ACE_TEXT ("visit_enum - ")
139 ACE_TEXT ("computing default value failed\n")),
143 TAO_INSERT_COMMENT (os
);
145 if ((dv
.computed_
!= 0) && (bu
->default_index () == -1))
147 // Only if all cases are not covered AND there is no explicit
148 // default, we get the _default () method.
150 *os
<< "ACE_INLINE" << be_nl
152 << bu
->name () << "::_default ()" << be_nl
154 << "this->_reset ();" << be_nl
157 switch (bu
->udisc_type ())
159 case AST_Expression::EV_short
:
160 *os
<< dv
.u
.short_val
;
162 case AST_Expression::EV_ushort
:
163 *os
<< dv
.u
.ushort_val
;
165 case AST_Expression::EV_long
:
166 *os
<< dv
.u
.long_val
;
168 case AST_Expression::EV_ulong
:
169 *os
<< dv
.u
.ulong_val
;
171 case AST_Expression::EV_char
:
172 case AST_Expression::EV_octet
:
173 case AST_Expression::EV_int8
:
174 case AST_Expression::EV_uint8
:
175 os
->print ("'\\%o'", dv
.u
.char_val
);
177 case AST_Expression::EV_bool
:
178 *os
<< (dv
.u
.bool_val
== 0 ? "false" : "true");
180 case AST_Expression::EV_longlong
:
181 *os
<< dv
.u
.longlong_val
;
183 case AST_Expression::EV_ulonglong
:
184 *os
<< dv
.u
.ulonglong_val
;
187 // Error caught earlier.
188 ACE_ERROR_RETURN ((LM_ERROR
,
189 ACE_TEXT ("be_visitor_union_discriminant_ci::")
190 ACE_TEXT ("visit_predefined_type - ")
191 ACE_TEXT ("bad or unimplemented ")
192 ACE_TEXT ("discriminant type\n")),
196 *os
<< ";" << be_uidt_nl
<< "}";
201 << "// Accessor to set the discriminant." << be_nl
202 << "ACE_INLINE" << be_nl
204 << bu
->name () << "::_d (::" << bt
->name ()
205 << " discval)" << be_nl
207 << "this->disc_ = discval;" << be_uidt_nl
211 *os
<< "// Accessor to get the discriminant." << be_nl
212 << "ACE_INLINE" << be_nl
213 << "::" << bt
->name () << be_nl
214 << bu
->name () << "::_d () const" << be_nl
216 << "return this->disc_;" << be_uidt_nl
223 be_visitor_union_discriminant_ci::visit_typedef (be_typedef
*node
)
225 this->ctx_
->alias (node
);
227 // The node to be visited in the base primitve type that gets typedefed.
228 be_type
*bt
= node
->primitive_base_type ();
230 if (!bt
|| (bt
->accept (this) == -1))
232 ACE_ERROR_RETURN ((LM_ERROR
,
233 ACE_TEXT ("be_visitor_union_discriminant_ci::")
234 ACE_TEXT ("visit_typedef - ")
235 ACE_TEXT ("Bad primitive type\n")),
239 this->ctx_
->alias (nullptr);