2 //=============================================================================
4 * @file be_union_branch.cpp
6 * Extension of class AST_UnionBranch that provides additional means for C++
9 * @author Copyright 1994-1995 by Sun Microsystems
10 * @author Inc. and Aniruddha Gokhale
12 //=============================================================================
14 #include "be_union_branch.h"
18 #include "be_visitor.h"
19 #include "be_helper.h"
20 #include "ast_union_label.h"
21 #include "ace/Log_Msg.h"
23 be_union_branch::be_union_branch (UTL_LabelList
*ll
,
26 : COMMON_Base (ft
->is_local (),
28 AST_Decl (AST_Decl::NT_union_branch
,
30 AST_Field (AST_Decl::NT_union_branch
,
36 be_decl (AST_Decl::NT_union_branch
,
44 be_union_branch::gen_label_value (TAO_OutStream
*os
, unsigned long index
)
46 AST_Expression
*e
= this->label (index
)->label_val ();
48 if (e
->ec () != AST_Expression::EC_symbol
)
50 // Easy, just a number...
55 // If the enum is not in the global scope we have to prefix it.
57 dynamic_cast<be_union
*> (this->defined_in ());
65 dynamic_cast<be_type
*> (u
->disc_type ());
72 // Check if discriminator is a typedef of an integer. If so, and the
73 // first IF block in this function didn't catch it, then we
74 // are a constant of this type. We can't generate the constant's name,
75 // we must generate the underlying integer value for the
77 if (dt
->node_type () == AST_Decl::NT_pre_defined
)
83 // Find where was the enum defined, if it was defined in the globa
84 // scope, then it is easy to generate the enum values....
86 dynamic_cast<be_scope
*> (dt
->defined_in ());
94 // But if it was generated inside a module or something similar then
95 // we must prefix the enum value with something...
96 be_decl
* decl
= scope
->decl ();
98 *os
<< decl
->full_name () << "::" << e
->n ()->last_component ();
104 be_union_branch::gen_default_label_value (TAO_OutStream
*os
,
107 be_union::DefaultValue dv
;
109 if (bu
->default_value (dv
) == -1)
111 ACE_ERROR_RETURN ((LM_ERROR
,
112 "(%N:%l) be_visitor_union_branch::"
113 "gen_default_label_value - "
114 "computing default value failed\n"),
118 switch (bu
->udisc_type ())
120 case AST_Expression::EV_short
:
121 *os
<< dv
.u
.short_val
;
123 case AST_Expression::EV_ushort
:
124 *os
<< dv
.u
.ushort_val
;
126 case AST_Expression::EV_long
:
127 *os
<< dv
.u
.long_val
;
129 case AST_Expression::EV_ulong
:
130 *os
<< dv
.u
.ulong_val
;
132 case AST_Expression::EV_octet
:
133 case AST_Expression::EV_char
:
134 case AST_Expression::EV_int8
:
135 case AST_Expression::EV_uint8
:
136 os
->print ("'\\%o'", dv
.u
.char_val
);
138 case AST_Expression::EV_bool
:
139 *os
<< (dv
.u
.bool_val
== 0 ? "false" : "true");
141 case AST_Expression::EV_enum
:
142 // The discriminant is an enum. Some compilers will
143 // not accept a numeric value assigned to this
144 // discriminant, so we must generate the string name.
146 AST_ConcreteType
*act
= bu
->disc_type ();
147 be_enum
*be
= dynamic_cast<be_enum
*> (act
);
149 UTL_ScopedName
*sn
= be
->value_to_name (dv
.u
.enum_val
);
152 // The function value_to_name() takes care of adding
153 // any necessary scoping to the output.
154 *os
<< be
->value_to_name (dv
.u
.enum_val
);
158 // Since CORBA defines enums to be 32bits, use -1 as the
159 // out-of-bounds value for the _default() function.
160 *os
<< "(" << be
->name () << ") -1";
164 case AST_Expression::EV_longlong
:
165 *os
<< dv
.u
.longlong_val
;
167 case AST_Expression::EV_ulonglong
:
168 *os
<< dv
.u
.ulonglong_val
;
171 // Error caught earlier.
172 ACE_ERROR_RETURN ((LM_ERROR
,
173 "(%N:%l) be_visitor_union_branch::"
174 "gen_default_label_value - "
175 "bad or unimplemented discriminant type\n"),
183 be_union_branch::accept (be_visitor
*visitor
)
185 return visitor
->visit_union_branch (this);
189 be_union_branch::destroy (void)
191 this->be_decl::destroy ();
192 this->AST_UnionBranch::destroy ();
197 IMPL_NARROW_FROM_DECL (be_union_branch
)