Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_union / discriminant_ci.cpp
blob96a77ccb6863dfa2104859aac7475ce923ce0da3
2 //=============================================================================
3 /**
4 * @file discriminant_ci.cpp
6 * Visitor generating code for discriminant of the union.
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "union.h"
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 ()
24 int
25 be_visitor_union_discriminant_ci::visit_enum (be_enum *node)
27 be_union *bu =
28 dynamic_cast<be_union*> (this->ctx_->node ());
29 be_type *bt = nullptr;
31 if (this->ctx_->alias ())
33 bt = this->ctx_->alias ();
35 else
37 bt = node;
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")),
51 -1);
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
61 << "void" << be_nl
62 << bu->name () << "::_default ()" << be_nl
63 << "{" << be_idt_nl
64 << "this->_reset ();" << be_nl
65 << "this->disc_ = ";
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);
71 if (sn)
73 // The function value_to_name() takes care of adding
74 // any necessary scoping to the output.
75 *os << sn;
77 else
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
85 << "}" << be_nl_2;
88 // the set method
89 *os << "// Accessor to set the discriminant." << be_nl
90 << "ACE_INLINE" << be_nl
91 << "void" << be_nl
92 << bu->name () << "::_d (" << bt->name ()
93 << " discval)" << be_nl
94 << "{" << be_idt_nl
95 << "this->disc_ = discval;" << be_uidt_nl
96 << "}" << be_nl_2;
98 // the get method
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
103 << "{" << be_idt_nl
104 << "return this->disc_;" << be_uidt_nl
105 << "}";
107 return 0;
111 be_visitor_union_discriminant_ci::visit_predefined_type (
112 be_predefined_type *node
115 be_union *bu =
116 dynamic_cast<be_union*> (this->ctx_->node ());
118 be_type *bt = nullptr;
120 if (this->ctx_->alias ())
122 bt = this->ctx_->alias ();
124 else
126 bt = node;
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")),
140 -1);
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
151 << "void" << be_nl
152 << bu->name () << "::_default ()" << be_nl
153 << "{" << be_idt_nl
154 << "this->_reset ();" << be_nl
155 << "this->disc_ = ";
157 switch (bu->udisc_type ())
159 case AST_Expression::EV_short:
160 *os << dv.u.short_val;
161 break;
162 case AST_Expression::EV_ushort:
163 *os << dv.u.ushort_val;
164 break;
165 case AST_Expression::EV_long:
166 *os << dv.u.long_val;
167 break;
168 case AST_Expression::EV_ulong:
169 *os << dv.u.ulong_val;
170 break;
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);
176 break;
177 case AST_Expression::EV_bool:
178 *os << (dv.u.bool_val == 0 ? "false" : "true");
179 break;
180 case AST_Expression::EV_longlong:
181 *os << dv.u.longlong_val;
182 break;
183 case AST_Expression::EV_ulonglong:
184 *os << dv.u.ulonglong_val;
185 break;
186 default:
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")),
193 -1);
196 *os << ";" << be_uidt_nl << "}";
199 // The set method.
200 *os << be_nl_2
201 << "// Accessor to set the discriminant." << be_nl
202 << "ACE_INLINE" << be_nl
203 << "void" << be_nl
204 << bu->name () << "::_d (::" << bt->name ()
205 << " discval)" << be_nl
206 << "{" << be_idt_nl
207 << "this->disc_ = discval;" << be_uidt_nl
208 << "}" << be_nl_2;
210 // The get method.
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
215 << "{" << be_idt_nl
216 << "return this->disc_;" << be_uidt_nl
217 << "}";
219 return 0;
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")),
236 -1);
239 this->ctx_->alias (nullptr);
240 return 0;